From 6e9bfd3febe03a53a56fbd4f7c830908b3fec7ce Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Fri, 21 Jun 2019 12:55:47 +0000 Subject: [PATCH] Implemented better game loop and shadow OAM/DMA --- game/game.asm | 30 +++++++++++++++++------ game/text.asm | 1 - main.asm | 26 ++++++++------------ main.o | Bin 10412 -> 11027 bytes test.gb | Bin 32768 -> 32768 bytes test.map | 64 ++++++++++++++++++++++++++++---------------------- test.sym | 44 +++++++++++++++++++--------------- tools.asm | 27 +++++++++++++++++++++ 8 files changed, 121 insertions(+), 71 deletions(-) diff --git a/game/game.asm b/game/game.asm index d99532b..3ac7762 100644 --- a/game/game.asm +++ b/game/game.asm @@ -1,23 +1,39 @@ INCLUDE "game/text.asm" INCLUDE "game/controller.asm" +; Shadow OAM, allows us to have a shadow copy of all sprites for +; editing whenever we want +SECTION "ram_shadowoam", WRAM0,ALIGN[8] +shadow_oam: + ds 160 +shadow_oam_inuse: + ds 1 + SECTION "Game Loop", ROM0 GameLoop: - ld de, HelloWorldStr + ld de, FirstCutScene call StartText -.mainloop - ; Start our game loop - call UpdateController - call DrawActiveText +.mainloop ; Our main game loop + call UpdateController ; Update our controller + + ; Reset our oam sprites in use + xor a + ld [shadow_oam_inuse], a + + ; Call sprite handlers + + ; Call other handlers call WaitVBlank + call DrawActiveText + call RunDMA jr .mainloop Section "Hello wrold string", ROM0 -HelloWorldStr: +FirstCutScene: ; [ ] db "...wake up...\n" - db "please wake up...#" + db "please wake up...", "#" db "...we don't have\n" db "time, wake up...", 0 diff --git a/game/text.asm b/game/text.asm index 7d1815c..216a2fd 100644 --- a/game/text.asm +++ b/game/text.asm @@ -114,7 +114,6 @@ StartText: ret ; Draw text if one is currently active -; @return a - 0 if not active, 1 if active DrawActiveText: ld a, [textwriter_active] ; Check if text is currently active and a diff --git a/main.asm b/main.asm index 3ddd4a5..4750d79 100644 --- a/main.asm +++ b/main.asm @@ -64,26 +64,20 @@ Start: ld a, SCRN_Y ld [rWY], a - ; Reset OAM memory with zeros - ld hl, _OAMRAM ; Set position of OAM Ram to hl - ld a, 0 ; Fill that memory space with zero - ld b, $FEA0 - _OAMRAM ; Get the full size of the fill - call Memfill - - ; Reset WRAM memory with zeros - ld hl, _RAM ; Set position of OAM Ram to hl - ld a, $01 ; Fill that memory space with zero - ld bc, $E000 - _RAM ; Get the full size of the fill - call Memfill16 - ld hl, _RAM ; Set position of OAM Ram to hl - ld a, $00 ; Fill that memory space with zero - ld bc, $E000 - _RAM ; Get the full size of the fill - call Memfill16 - ; Initialize other stuff + call InitTools call InitController call InitWindow + ; Reset OAM memory with zeros + ; First reset our shadow OAM + ld hl, shadow_oam ; Set position of OAM Ram to hl + ld a, 0 ; Fill that memory space with zero + ld b, shadow_oam_inuse - shadow_oam ; Get the full size of the fill + call Memfill + ; Then call our OAM guy + call RunDMA + ; Turn the screen on, display background ld a, LCDCF_ON|LCDCF_BGON|LCDCF_WINON|LCDCF_WIN9C00 ld [rLCDC], a ; Set the screen flags diff --git a/main.o b/main.o index 160cf5c2df1ae79a58912e6cfe2b9bb5c97026b3..da4470aa47dcda42d5d146e6bdd768e72e7ef6ff 100644 GIT binary patch delta 3205 zcmaJ@drVtZ7(bUjpu7itz;L4lWH1GUOcvs725eMtL}3oZ7pZWCDs5RGlc>qHF`CR6 zA34$Z*bHWxXtGGKK4Wx7XAH@j_>b`qjn+7$Su{SQW=7}ly9ZBuxt50Sa?bbr-sd}y zlVg0MZ9Fj0+r=2G0gbBR+d>Nqj3uJcg?MK$9%e0IJ3#K$wo{67lz*r6D#v+a(JseR z;1+>S^PdzCj~BU=xA@VbMP-$rFWRk~<~^2qk4p%Wb!`$LE8y(L1N3!SHk_ zl8l=qDO4M1nLlQ$cZ^^}950`<`F12RqJTMQJQ>+H+Ml1O9o!NS<7r#V)D{egLo^!> zPRF9jL@1(8#}mO=B42F`0_383gPPLI@goA6)YpLIw9vxA?ZvU3v$ zKLBr)`c9LBZ@}3u^=nP|7x2$K(f}P}#tc3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>P}fz!lW7(5q|-d^_j> 8 + ld [rDMA],a + ld a,40 +.loop: + dec a + jr nz,.loop + ret +dma_routine_end: