From c4ccba52d2fc55fb95b866d275981edae31b1ad6 Mon Sep 17 00:00:00 2001 From: tA Date: Mon, 25 May 2020 15:49:17 +1200 Subject: [PATCH 1/9] fixed scanline bug + removed old code --- .gitignore | 1 + src/actor.asm | 1 - src/animation.asm | 54 +++++++++++----------- src/defines.asm | 11 ----- src/entry.asm | 9 ++-- src/misc.asm | 113 ++++++---------------------------------------- 6 files changed, 47 insertions(+), 142 deletions(-) diff --git a/.gitignore b/.gitignore index 89efb0f..65ba2cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build *.swp +*.swo diff --git a/src/actor.asm b/src/actor.asm index d25d022..4d71f1d 100644 --- a/src/actor.asm +++ b/src/actor.asm @@ -7,7 +7,6 @@ SECTION "Actor", ROM0 ActorROM:: .structs: dw ActorIdle -.tiles: ActorIdle:: db 60 db 15 diff --git a/src/animation.asm b/src/animation.asm index ff75495..9683e09 100644 --- a/src/animation.asm +++ b/src/animation.asm @@ -15,20 +15,20 @@ SECTION "Actor STructs", WRAM0 dstruct Actor, Player -SECTION "Animation Variables", WRAM0 +SECTION "Animation Variables", HRAM -wCameraX: dw -wCameraY: dw +hCameraX: dw +hCameraY: dw -wWorkingX: dw -wWorkingY: dw -wWorkingScreenX: db -wWorkingScreenY: db -wWorkingState: db -wWorkingCounter: db -wWorkingData: dw -wWorkingTile: db -wWorkingEnd: +hWorkingX: dw +hWorkingY: dw +hWorkingScreenX: db +hWorkingScreenY: db +hWorkingState: db +hWorkingCounter: db +hWorkingData: dw +hWorkingTile: db +hWorkingEnd: SECTION "Animations Subs", ROM0 @@ -48,27 +48,27 @@ RenderActor:: ; @input: hl <- Player ; @input: de <- ShadowOAM place ld a, [hli] ; a <- YPos - ld [wWorkingScreenY], a + ldh [hWorkingScreenY], a ld a, [hli] ; a <- XPos - ld [wWorkingScreenX], a + ldh [hWorkingScreenX], a push hl ld a, [hli] ; a <- GFXCounter - ld [wWorkingCounter], a + ldh [hWorkingCounter], a ld a, [hli] ; a <- GFXState - ld [wWorkingState], a + ldh [hWorkingState], a ld a, [hli] ; a <- GFXData(Low) - ld [wWorkingData+1], a + ldh [hWorkingData+1], a ld a, [hli] ; a <- GFXData (High) - ld [wWorkingData], a + ldh [hWorkingData], a ld a, [hl] ; a <- TileData - ld [wWorkingTile], a + ldh [hWorkingTile], a ; fin loading data - ld a, [wWorkingData] + ld a, [hWorkingData] ld l, a - ld a, [wWorkingData+1] + ld a, [hWorkingData+1] ld h, a ; add actor struct offset saved in wWorkingState - ld a, [wWorkingState] + ld a, [hWorkingState] rlca ; double state offset because of word length add a, l ld l, a @@ -82,7 +82,7 @@ RenderActor:: ld h, a ld a, [hli] ; a <- state frame limit ld b, a - ld a, [wWorkingCounter] + ld a, [hWorkingCounter] inc a ld c, a ld a, b @@ -93,7 +93,7 @@ RenderActor:: xor a .continueAnimation ; TODO: make counter 0 indexed so doesnt skip first frame - ld [wWorkingCounter], a + ldh [hWorkingCounter], a ld b, h ld c, l pop hl @@ -124,7 +124,7 @@ RenderActor:: ; load Y position, then offset by -16 ld a, [hli] ld c, a - ld a, [wWorkingScreenY] + ld a, [hWorkingScreenY] add c ld c, 16 add c @@ -133,7 +133,7 @@ RenderActor:: ; load X position, then offset by -8 ld a, [hli] ld c, a - ld a, [wWorkingScreenX] + ld a, [hWorkingScreenX] add c ld c, 8 add c @@ -142,7 +142,7 @@ RenderActor:: ; load tile offset, and add to base tile pointer ld a, [hli] ld c, a - ld a, [wWorkingTile] + ld a, [hWorkingTile] add c ld [de], a inc de diff --git a/src/defines.asm b/src/defines.asm index 665352f..28323c3 100644 --- a/src/defines.asm +++ b/src/defines.asm @@ -12,19 +12,8 @@ P1F_DPAD EQU $20 SECTION "ROM Vars", ROM0 -dPlayerWidth: db 2 -dPlayerHeight: db 2 -dPlayerSpriteTiles: db $01, $02, $09, $0A - SECTION "WRAM Vars", WRAM0[$C000] -X: dw -N: dw -ANS: db - -rPlayerX: db -rPlayerY: db - SECTION "HRAM Vars", HRAM hVBlankFlag: db diff --git a/src/entry.asm b/src/entry.asm index 185cd8a..5be7906 100644 --- a/src/entry.asm +++ b/src/entry.asm @@ -25,8 +25,6 @@ Start: ld [rSCY], a ld [rSCX], a ld [rNR52], a - ld a, LCDCF_ON | LCDCF_OBJON | LCDCF_BGON - ld [rLCDC], a call CopyDMARoutine @@ -43,11 +41,14 @@ Start: ld a, LOW(ActorROM) ld [Player_GFXData + 1], a + ld a, LCDCF_ON | LCDCF_OBJON | LCDCF_BGON + ld [rLCDC], a + game_loop: - call Wait_VBlank + call Hide_OAM call Read_Pad call PC_Update - call Clear_OAM + call Wait_VBlank ld de, wShadowOAM ld hl, Player call RenderActor diff --git a/src/misc.asm b/src/misc.asm index 4edbb4e..e2c3a1b 100644 --- a/src/misc.asm +++ b/src/misc.asm @@ -1,102 +1,3 @@ -Player_To_OAM: -; -- first loop -- - ld hl, wShadowOAM - ld a, [dPlayerHeight] - ld b, a - ld d, 16 - ld a, [rPlayerY] - add d ; d has the base Y value (counting offsets) - ld d, a -.fouter - ld a, [dPlayerWidth] - ld c, a ; c is finner counter -.finner - ld a, d - ld [hl], a - ld a, 4 - call .add4hl -; end of finner loop - dec c - jr nz, .finner - ld a, d - ld d, 8 - add d - ld d, a -; end of fouter loop - dec b - jr nz, .fouter -; -- second loop -- - ld hl, wShadowOAM+1 - ld a, [dPlayerHeight] - ld b, a -.souter - ld d, 8 - ld a, [rPlayerX] - add d - ld d, a - ld a, [dPlayerWidth] - ld c, a -.sinner - ld a, d - ld [hl], a - add 8 - ld d, a - ld a, 4 - call .add4hl - dec c - jr nz, .sinner - dec b - jr nz, .souter -; -- third loop -- - ld hl, wShadowOAM+2 - ld de, dPlayerSpriteTiles - ld a, [dPlayerHeight] - ld b, a - ld a, [dPlayerWidth] - ld c, a - xor a -.tloop1 - add b - dec c - jr nz, .tloop1 - ld c, a -.tloop2 - ld a, [de] - ld [hl], a - ld a, 4 - call .add4hl - inc de - dec c - jr nz, .tloop2 -; -- fourth loop -- - ld hl, wShadowOAM+3 - ld a, [dPlayerHeight] - ld b, a - ld a, [dPlayerWidth] - ld c, a - xor a -.lloop1 - add b - dec c - jr nz, .lloop1 - ld c, a -.lloop2 - xor a - ld [hl], a - ld a, 4 - call .add4hl - dec c - jr nz, .lloop2 - ret - -.add4hl: - add a, l ; a = low + old_l - ld l, a ; a = low + old_l = new_l - adc a, h ; a = new_l + old_h + carry - sub l ; a = old_h + carry - ld h, a - ret - PC_Update: ld b, 0 ld c, 0 @@ -146,6 +47,20 @@ Clear_OAM: jr nz, .loop ret +Hide_OAM: + ld hl, wShadowOAM + ld c, wShadowOAMEnd - wShadowOAM +.loop: + xor a + ld [hl], a + ld a, l + or 3 + inc a + ld l, a + dec c + jr nz, .loop + ret + Clear_Map: ld hl, _SCRN0 ld bc, _SCRN0_END - _SCRN0 From fa65a2b0b27abbbb9958352ed73e16fefd85ba38 Mon Sep 17 00:00:00 2001 From: tA Date: Mon, 25 May 2020 17:10:59 +1200 Subject: [PATCH 2/9] cleaned up header --- Makefile | 11 ++++++++++- src/entry.asm | 3 ++- src/header.asm | 43 ++++--------------------------------------- src/misc.asm | 3 +-- 4 files changed, 17 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index b49a37a..443de8f 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,16 @@ ROM_OUTPUT=${BUILD}/${NAME}.gb OBJECT_OUTPUT=${BUILD}/${NAME}.o SYMFILE_OUTPUT=${BUILD}/${NAME}.sym +LICENSEE="tA" +OLDLIC="0x33" +MBC="0x00" +VERSION="0" +PAD="0xFF" +RAM="0x00" + +PP_FLAGS=-c -f lhg -j -t ${NAME} -k ${LICENSEE} -l ${OLDLIC} -m ${MBC} -n ${VERSION} -p ${PAD} -r ${RAM} + all : ${ENTRY} ${ASSEMBLER} -o ${OBJECT_OUTPUT} ${ENTRY} \ && ${LINKER} -o ${ROM_OUTPUT} -n ${SYMFILE_OUTPUT} ${OBJECT_OUTPUT} \ - && ${POSTPROC} -v -p 0 ${ROM_OUTPUT} + && ${POSTPROC} -v ${PP_FLAGS} ${ROM_OUTPUT} diff --git a/src/entry.asm b/src/entry.asm index 5be7906..01cf543 100644 --- a/src/entry.asm +++ b/src/entry.asm @@ -6,9 +6,9 @@ INCLUDE "src/actor.asm" SECTION "Program Start", ROM0[$150] Start: - ei ld a, IEF_VBLANK ld [rIE], a + ei xor a ld [hVBlankFlag], a call Wait_VBlank @@ -21,6 +21,7 @@ Start: ld a, %11100100 ld [rBGP], a ld [rOBP0], a + ld [rOBP1], a xor a ld [rSCY], a ld [rSCX], a diff --git a/src/header.asm b/src/header.asm index 1ee56d4..fc3680a 100644 --- a/src/header.asm +++ b/src/header.asm @@ -2,44 +2,9 @@ ; Gameboy Header ;----------------- -SECTION "Header", ROM0[$100] - -; Jump to the "Start" label -; which we must define ourselves - -EntryPoint: - nop +SECTION "Entry", ROM0[$100] + di jp Start; -; ROM Header $104 to $150 -RomHeader: -; Nintendo Logo $104-$133 - db $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D - db $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99 - db $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E -; Title (11 characters) $134-$13E - db "ANIMATION",$00,$00 -; Manufacturer Code (4 characters) $13F-$142 - db "LATA" -; CGB Flag $143 - db $00 -; Licensee Code (2 characters) $144-$145 - db "00" -; SGB Flag $146 - db $00 -; Cartridge Type $147 - db $00 -; ROM Size $148 - db $00 -; RAM Size $149 - db $00 -; Destination Code $14A - db $01 -; Depreciated Licensee Code $14B - db $33 -; Version Number $14C - db $00 -; Header Checksum $14D - db $00 -; Global Checksum $14E-$14F - db $00, $00 + ; Reserve space for header + ds $150 - @, 0 diff --git a/src/misc.asm b/src/misc.asm index e2c3a1b..0911276 100644 --- a/src/misc.asm +++ b/src/misc.asm @@ -49,7 +49,7 @@ Clear_OAM: Hide_OAM: ld hl, wShadowOAM - ld c, wShadowOAMEnd - wShadowOAM + ld c, (wShadowOAMEnd - wShadowOAM) / 4 .loop: xor a ld [hl], a @@ -91,4 +91,3 @@ Load_Map: call MemCpy ret - From 88ad5534c3668635d020af294db260f9d80f3bc5 Mon Sep 17 00:00:00 2001 From: tA Date: Thu, 28 May 2020 15:12:01 +1200 Subject: [PATCH 3/9] cleaned up animation code + fixed frame 0 bug --- src/animation.asm | 123 +++++++++++++++++++++------------------------- src/entry.asm | 7 +-- 2 files changed, 59 insertions(+), 71 deletions(-) diff --git a/src/animation.asm b/src/animation.asm index 9683e09..1746ef8 100644 --- a/src/animation.asm +++ b/src/animation.asm @@ -7,8 +7,8 @@ bytes 1, XPos bytes 1, GFXCounter bytes 1, GFXState - words 1, GFXData bytes 1, TileData + words 1, GFXData end_struct SECTION "Actor STructs", WRAM0 @@ -28,7 +28,6 @@ hWorkingState: db hWorkingCounter: db hWorkingData: dw hWorkingTile: db -hWorkingEnd: SECTION "Animations Subs", ROM0 @@ -47,117 +46,105 @@ SECTION "Animations Subs", ROM0 RenderActor:: ; @input: hl <- Player ; @input: de <- ShadowOAM place - ld a, [hli] ; a <- YPos + ; clobbers af, bc, de, hl + + ld a, [hli] ; a <- YPos ldh [hWorkingScreenY], a - ld a, [hli] ; a <- XPos + ld a, [hli] ; a <- XPos ldh [hWorkingScreenX], a - push hl - ld a, [hli] ; a <- GFXCounter + push hl ; save counter pointer on stack + ld a, [hli] ; a <- GFXCounter ldh [hWorkingCounter], a - ld a, [hli] ; a <- GFXState + ld a, [hli] ; a <- GFXState ldh [hWorkingState], a - ld a, [hli] ; a <- GFXData(Low) - ldh [hWorkingData+1], a - ld a, [hli] ; a <- GFXData (High) - ldh [hWorkingData], a - ld a, [hl] ; a <- TileData + ld a, [hli] ; a <- TileData ldh [hWorkingTile], a -; fin loading data - ld a, [hWorkingData] + ld a, [hli] ; a <- GFXData(Low) + ld h, [hl] ; a <- GFXData (High) ld l, a - ld a, [hWorkingData+1] - ld h, a -; add actor struct offset saved in wWorkingState - ld a, [hWorkingState] - rlca ; double state offset because of word length + + ld a, [hWorkingState] ; add actor struct offset saved in wWorkingState + rlca ; double state offset because of word length add a, l ld l, a adc a, h sub l - ld h, a ; hl contains state struct pointer - ld a, [hli] - ld b, a - ld a, [hl] - ld l, b - ld h, a - ld a, [hli] ; a <- state frame limit - ld b, a + ld h, a ; hl contains state struct pointer + + ld a, [hli] ; + ld h, [hl] ; derefence [hl] + ld l, a ; + ld a, [hWorkingCounter] inc a - ld c, a - ld a, b - ld b, c + ld b, a + ld a, [hli] ; a <- state frame limit cp b ld a, b jr nc, .continueAnimation xor a .continueAnimation - ; TODO: make counter 0 indexed so doesnt skip first frame ldh [hWorkingCounter], a - ld b, h - ld c, l - pop hl - ld [hl], a - ld h, b - ld l, c -.loopFrameFind - ld b, a ; b <- current frame count - ld a, [hli] ; a <- next frame block - ld c, a - ld a, b - ld b, c - sub b - jr z, .foundFrame - jr c, .foundFrame + ld b, h ; + ld c, l ; save current hl + pop hl ; restore counter wram pointer + ld [hl], a ; + ld h, b ; restore hl + ld l, c ; + + ld c, a ; save current frame in c + xor a ; set a = 0 +.loopFrameFind ; + ld b, a ; b <- current total + ld a, [hli] ; a <- next frame tick limit + add b ; add to limit + cp c ; compare to limit + jr nc, .foundFrame ; if no carry, cum total > current frame inc hl inc hl jr .loopFrameFind + .foundFrame ld a, [hli] - ld b, a - ld a, [hl] - ld h, a - ld l, b ; hl <- pointer to frame data + ld h, [hl] + ld l, a ; hl <- pointer to frame data ld a, [hli] - ld b, a ; b <- sprite counter + ld b, a ; b <- sprite counter + .spriteLoop - ; load Y position, then offset by -16 - ld a, [hli] + + ld a, [hli] ; load Y position, then offset by -16 ld c, a ld a, [hWorkingScreenY] add c ld c, 16 add c - ld [de], a ; store YPos in shadowOAM + ld [de], a ; store YPos in shadowOAM inc de - ; load X position, then offset by -8 - ld a, [hli] + + ld a, [hli] ; load X position, then offset by -8 ld c, a ld a, [hWorkingScreenX] add c ld c, 8 add c - ld [de], a ; store YPos in shadowOAM + ld [de], a ; store XPos in shadowOAM inc de - ; load tile offset, and add to base tile pointer - ld a, [hli] + + ld a, [hli] ; load tile offset, and add to base tile pointer ld c, a ld a, [hWorkingTile] add c ld [de], a inc de - ; load attributes and xor them - ld a, [hli] + + ld a, [hli] ; load attributes and xor them ld c, a - ld a, 0 ; TO DO: set base attributes + ld a, 0 ; TO DO: set base attributes xor c ld [de], a inc de - ; end of single sprite - dec b + + dec b ; end of single sprite jr nz, .spriteLoop ret - -BUFFER EQU 160 -TRUE EQU $42 -FALSE EQU $69 diff --git a/src/entry.asm b/src/entry.asm index 01cf543..2379e8d 100644 --- a/src/entry.asm +++ b/src/entry.asm @@ -33,14 +33,15 @@ Start: ld [Player_YPos], a ld a, 80 ld [Player_XPos], a - xor a + ld a, $FF ld [Player_GFXCounter], a + xor a ld [Player_GFXState], a ld [Player_TileData], a ld a, HIGH(ActorROM) - ld [Player_GFXData], a + ld [Player_GFXData+1], a ld a, LOW(ActorROM) - ld [Player_GFXData + 1], a + ld [Player_GFXData], a ld a, LCDCF_ON | LCDCF_OBJON | LCDCF_BGON ld [rLCDC], a From 31327d35ee99ea26f5621d3ad88e64a1bc925d1f Mon Sep 17 00:00:00 2001 From: tA Date: Thu, 28 May 2020 15:21:34 +1200 Subject: [PATCH 4/9] added more actors to demonstrate --- src/animation.asm | 5 +++ src/entry.asm | 82 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/animation.asm b/src/animation.asm index 1746ef8..3b1f88b 100644 --- a/src/animation.asm +++ b/src/animation.asm @@ -14,6 +14,11 @@ SECTION "Actor STructs", WRAM0 dstruct Actor, Player + dstruct Actor, NPC01 + dstruct Actor, NPC02 + dstruct Actor, NPC03 + dstruct Actor, NPC04 + dstruct Actor, NPC05 SECTION "Animation Variables", HRAM diff --git a/src/entry.asm b/src/entry.asm index 2379e8d..4093e88 100644 --- a/src/entry.asm +++ b/src/entry.asm @@ -43,6 +43,76 @@ Start: ld a, LOW(ActorROM) ld [Player_GFXData], a + ld a, 24 + ld [NPC01_YPos], a + ld a, 24 + ld [NPC01_XPos], a + ld a, 20 + ld [NPC01_GFXCounter], a + xor a + ld [NPC01_GFXState], a + ld [NPC01_TileData], a + ld a, HIGH(ActorROM) + ld [NPC01_GFXData+1], a + ld a, LOW(ActorROM) + ld [NPC01_GFXData], a + + ld a, 24 + ld [NPC02_YPos], a + ld a, 48 + ld [NPC02_XPos], a + ld a, 30 + ld [NPC02_GFXCounter], a + xor a + ld [NPC02_GFXState], a + ld [NPC02_TileData], a + ld a, HIGH(ActorROM) + ld [NPC02_GFXData+1], a + ld a, LOW(ActorROM) + ld [NPC02_GFXData], a + + ld a, 48 + ld [NPC03_YPos], a + ld a, 48 + ld [NPC03_XPos], a + ld a, 40 + ld [NPC03_GFXCounter], a + xor a + ld [NPC03_GFXState], a + ld [NPC03_TileData], a + ld a, HIGH(ActorROM) + ld [NPC03_GFXData+1], a + ld a, LOW(ActorROM) + ld [NPC03_GFXData], a + + ld a, 48 + ld [NPC04_YPos], a + ld a, 24 + ld [NPC04_XPos], a + ld a, 50 + ld [NPC04_GFXCounter], a + xor a + ld [NPC04_GFXState], a + ld [NPC04_TileData], a + ld a, HIGH(ActorROM) + ld [NPC04_GFXData+1], a + ld a, LOW(ActorROM) + ld [NPC04_GFXData], a + + ld a, 64 + ld [NPC05_YPos], a + ld a, 64 + ld [NPC05_XPos], a + ld a, 10 + ld [NPC05_GFXCounter], a + xor a + ld [NPC05_GFXState], a + ld [NPC05_TileData], a + ld a, HIGH(ActorROM) + ld [NPC05_GFXData+1], a + ld a, LOW(ActorROM) + ld [NPC05_GFXData], a + ld a, LCDCF_ON | LCDCF_OBJON | LCDCF_BGON ld [rLCDC], a @@ -50,10 +120,20 @@ game_loop: call Hide_OAM call Read_Pad call PC_Update - call Wait_VBlank ld de, wShadowOAM ld hl, Player call RenderActor + ld hl, NPC01 + call RenderActor + ld hl, NPC02 + call RenderActor + ld hl, NPC03 + call RenderActor + ld hl, NPC04 + call RenderActor + ld hl, NPC05 + call RenderActor + call Wait_VBlank ld a, HIGH(wShadowOAM) call hOAMDMA jr game_loop From 52492799db4c65a8ec59ea186832d8ee7595e141 Mon Sep 17 00:00:00 2001 From: tA Date: Thu, 28 May 2020 15:25:27 +1200 Subject: [PATCH 5/9] fixed gbc compat flag --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 443de8f..5825962 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ VERSION="0" PAD="0xFF" RAM="0x00" -PP_FLAGS=-c -f lhg -j -t ${NAME} -k ${LICENSEE} -l ${OLDLIC} -m ${MBC} -n ${VERSION} -p ${PAD} -r ${RAM} +PP_FLAGS=-f lhg -j -t ${NAME} -k ${LICENSEE} -l ${OLDLIC} -m ${MBC} -n ${VERSION} -p ${PAD} -r ${RAM} all : ${ENTRY} ${ASSEMBLER} -o ${OBJECT_OUTPUT} ${ENTRY} \ From 5a14e2f17f9ab42c2249e981ae3085e8d72f9e5b Mon Sep 17 00:00:00 2001 From: tA Date: Fri, 29 May 2020 14:09:57 +1200 Subject: [PATCH 6/9] added second animation --- ass/villager.ass | 32 ++++++++++++++++++++ ass/villager.gbr | Bin 0 -> 10069 bytes src/actor.asm | 75 +++++++++++++++++++++++++++++++++++++++++++++++ src/entry.asm | 21 ++++++------- src/main.asm | 1 + src/misc.asm | 15 +++++++--- 6 files changed, 130 insertions(+), 14 deletions(-) create mode 100644 ass/villager.ass create mode 100644 ass/villager.gbr diff --git a/ass/villager.ass b/ass/villager.ass new file mode 100644 index 0000000..d088351 --- /dev/null +++ b/ass/villager.ass @@ -0,0 +1,32 @@ +SECTION "VillagerWaving", ROM0 + +VillagerTiles:: +DB $1F,$18,$3F,$20,$7F,$48,$74,$57 +DB $26,$25,$0E,$09,$0E,$0A,$1E,$12 +DB $F8,$18,$FC,$04,$FE,$12,$2E,$EA +DB $64,$A4,$70,$90,$70,$50,$78,$48 +DB $0F,$08,$1F,$12,$1D,$14,$1F,$10 +DB $0F,$09,$07,$04,$03,$02,$07,$04 +DB $F0,$10,$F8,$48,$B8,$28,$F8,$08 +DB $F0,$90,$E0,$20,$C0,$40,$E0,$20 +DB $00,$00,$00,$00,$00,$00,$00,$00 +DB $01,$01,$03,$02,$03,$02,$07,$04 +DB $00,$00,$00,$00,$00,$00,$00,$00 +DB $80,$80,$C0,$40,$C0,$40,$E0,$20 +DB $0F,$08,$1F,$10,$1F,$12,$1D,$14 +DB $0F,$08,$07,$05,$03,$02,$07,$04 +DB $F0,$10,$F8,$08,$F8,$48,$B8,$28 +DB $F0,$10,$E0,$A0,$C0,$40,$E0,$20 +DB $07,$04,$1F,$18,$3F,$20,$7C,$4F +DB $76,$55,$2E,$29,$0E,$0A,$1E,$12 +DB $E0,$20,$F8,$18,$FC,$04,$3E,$F2 +DB $6E,$AA,$74,$94,$70,$50,$78,$48 +DB $0F,$08,$1F,$12,$1D,$14,$1F,$10 +DB $0F,$09,$07,$04,$03,$02,$1F,$1C +DB $F0,$10,$F8,$48,$B8,$28,$F8,$08 +DB $F0,$90,$E0,$20,$C0,$40,$F8,$38 +DB $3F,$20,$7F,$48,$77,$54,$24,$27 +DB $06,$05,$0E,$09,$0E,$0A,$1E,$12 +DB $FC,$04,$FE,$12,$EE,$2A,$24,$E4 +DB $60,$A0,$70,$90,$70,$50,$78,$48 +VillagerTilesEnd:: diff --git a/ass/villager.gbr b/ass/villager.gbr new file mode 100644 index 0000000000000000000000000000000000000000..3f600ce5efb7d00ba6db7a72f64d0838512939b2 GIT binary patch literal 10069 zcmZ>F@;6{)U|^_VU|?`h%uP+ouT%)h%t=*nNiEJy&r2<0fB_>tBL)YChsq8N9{IVc zRtn|i<$B49#i_Z8dU>fO`gIuvxurQNNE%=o3DQgqj0_qIgp_eGa41CNeWJLTQjTuu29-Mn+~3j}Ziz8Nhr- zMrH;kCT6e^OpGA?3=B*lL5LwBW9 zSU`M`{~<~t?gS-SkT^5Q2B^0gu=pG7Ly(~$J7D1r76hdeMrLrj1^EV)R=}2k!XM;5 zusxu33rhcB>!9f#oBts$0FfX&Kp12MDE))74#@u?`@#MPF+h?K8s-!bZxoM)z-S1J zhQMeDjE2By2#kinXb6mkz-S1JhQMeDjE2By2#kinXb6mkz-S1JhQMeDjE2By2#kin zXb6mkz-S1Jh5*GOz|6qJAPkxh1x?*EFoGxE|APSo3j;I5VX#z`RZK>HZfZ<%Mq+7R zOhHk8dQ5s!Ok!SUZemGheqKysadC`mML~X1iC&e30mW{@Gyt@Uq8LpWB<7Qtl$wJq z4w@Hc;6)YzvsoEf82Z6p0dohMsE0a$mw}amjS;kHfrH_}drbz*olXo2rG^abmU?vO rvrud!)Kg?rd<<+1d@P{QXdv5+QH{eR1V&T9@Q6oBeDMHOU^4;$l&Nsl literal 0 HcmV?d00001 diff --git a/src/actor.asm b/src/actor.asm index 4d71f1d..7d2f125 100644 --- a/src/actor.asm +++ b/src/actor.asm @@ -7,6 +7,7 @@ SECTION "Actor", ROM0 ActorROM:: .structs: dw ActorIdle + dw VillagerWaving ActorIdle:: db 60 db 15 @@ -48,3 +49,77 @@ ActorIdle:: db 0, -8, 15, 0 db 0, 0, 16, 0 .frameVoEnd + +VillagerWaving:: + db 90 + db 15 + dw .vwFrame01 + db 15 + dw .vwFrame02 + db 15 + dw .vwFrame03 + db 15 + dw .vwFrame04 + db 15 + dw .vwFrame05 + db 15 + dw .vwFrame06 +.vwFrame01 + db (.vwFrame01End - @) / 4 + db 8, -16, 17, 0 + db 8, -8, 18, 0 + db 0, -16, 19, 0 + db 0, -8, 20, 0 + db -8, -16, 21, 0 + db -8, -8, 22, 0 +.vwFrame01End + +.vwFrame02 + db (.vwFrame02End - @) / 4 + db 8, -16, 17, 0 + db 8, -8, 18, 0 + db 0, -16, 23, 0 + db 0, -8, 24, 0 + db -8, -16, 21, 0 + db -8, -8, 22, 0 +.vwFrame02End + +.vwFrame03 + db (.vwFrame03End - @) / 4 + db 8, -16, 25, 0 + db 8, -8, 26, 0 + db 0, -16, 23, 0 + db 0, -8, 24, 0 + db -8, -16, 21, 0 + db -8, -8, 22, 0 +.vwFrame03End + +.vwFrame04 + db (.vwFrame04End - @) / 4 + db 8, -16, 17, 0 + db 8, -8, 18, 0 + db 0, -16, 23, 0 + db 0, -8, 24, 0 + db -8, -16, 21, 0 + db -8, -8, 22, 0 +.vwFrame04End + +.vwFrame05 + db (.vwFrame05End - @) / 4 + db 8, -16, 17, 0 + db 8, -8, 18, 0 + db 0, -16, 19, 0 + db 0, -8, 20, 0 + db -8, -16, 21, 0 + db -8, -8, 22, 0 +.vwFrame05End + +.vwFrame06 + db (.vwFrame06End - @) / 4 + db 8, -16, 29, 0 + db 8, -8, 30, 0 + db 0, -16, 27, 0 + db 0, -8, 28, 0 + db -8, -16, 21, 0 + db -8, -8, 22, 0 +.vwFrame06End diff --git a/src/entry.asm b/src/entry.asm index 4093e88..05e4c28 100644 --- a/src/entry.asm +++ b/src/entry.asm @@ -29,9 +29,9 @@ Start: call CopyDMARoutine - ld a, 72 + ld a, 100 ld [Player_YPos], a - ld a, 80 + ld a, 40 ld [Player_XPos], a ld a, $FF ld [Player_GFXCounter], a @@ -49,15 +49,16 @@ Start: ld [NPC01_XPos], a ld a, 20 ld [NPC01_GFXCounter], a - xor a + ld a, 1 ld [NPC01_GFXState], a + xor a ld [NPC01_TileData], a ld a, HIGH(ActorROM) ld [NPC01_GFXData+1], a ld a, LOW(ActorROM) ld [NPC01_GFXData], a - ld a, 24 + ld a, 48 ld [NPC02_YPos], a ld a, 48 ld [NPC02_XPos], a @@ -71,9 +72,9 @@ Start: ld a, LOW(ActorROM) ld [NPC02_GFXData], a - ld a, 48 + ld a, 72 ld [NPC03_YPos], a - ld a, 48 + ld a, 72 ld [NPC03_XPos], a ld a, 40 ld [NPC03_GFXCounter], a @@ -85,9 +86,9 @@ Start: ld a, LOW(ActorROM) ld [NPC03_GFXData], a - ld a, 48 + ld a, 96 ld [NPC04_YPos], a - ld a, 24 + ld a, 96 ld [NPC04_XPos], a ld a, 50 ld [NPC04_GFXCounter], a @@ -99,9 +100,9 @@ Start: ld a, LOW(ActorROM) ld [NPC04_GFXData], a - ld a, 64 + ld a, 130 ld [NPC05_YPos], a - ld a, 64 + ld a, 130 ld [NPC05_XPos], a ld a, 10 ld [NPC05_GFXCounter], a diff --git a/src/main.asm b/src/main.asm index ed34230..7254797 100644 --- a/src/main.asm +++ b/src/main.asm @@ -2,6 +2,7 @@ INCLUDE "inc/hardware.inc" INCLUDE "inc/structs.asm" INCLUDE "ass/parecivo.ass" INCLUDE "ass/tiles.ass" +INCLUDE "ass/villager.ass" INCLUDE "ass/map.ass" INCLUDE "src/animation.asm" INCLUDE "src/entry.asm" diff --git a/src/misc.asm b/src/misc.asm index 0911276..128bd65 100644 --- a/src/misc.asm +++ b/src/misc.asm @@ -31,6 +31,14 @@ PC_Update: ld a, [Player_YPos] add b ld [Player_YPos], a +.a: + ld a, [hNewKeys] + and %00000001 ; a pressed + cp %00000001 + jr nz, .end + ld a, [Player_GFXState] + xor %00000001 + ld [Player_GFXState], a .end: ret @@ -74,14 +82,13 @@ Clear_Map: ret Load_Tiles: - ld hl, _BGTILES - ld de, parecivo_tile_data - ld bc, parecivo_tile_data_size - call MemCpy ld hl, _VRAM ld de, parecivo_tile_data ld bc, parecivo_tile_data_size call MemCpy + ld de, VillagerTiles + ld bc, VillagerTilesEnd - VillagerTiles + call MemCpy ret Load_Map: From edfd4be25f4511ab68883bbdee1a48684b5734ab Mon Sep 17 00:00:00 2001 From: Thorn Avery Date: Thu, 28 May 2020 22:40:38 -0400 Subject: [PATCH 7/9] Delete 'src/.animation.asm.swo' whoops folgot to ignore this --- src/.animation.asm.swo | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/.animation.asm.swo diff --git a/src/.animation.asm.swo b/src/.animation.asm.swo deleted file mode 100644 index 3d68081beeb7de86a79a0fdd9464db49a86e7b15..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmYc?2=nw+u+TGNU|?VnU|_f~X>;6G@o9_)wHO$RGZIVlK;i^&W_erTySpWYWKLf*Eeg=lq{0t1I_!$_M@iQi%Fn>i!q31^%+J7(#LvLs z&CkGK!q31U&(FZX!Oy_(g^z*Z0UrayWj+RmOMDCroA?+QHu5nrEaGEesNrK^2;^g6 z(Bxxa5a45A;OApt_{Yn@aFv&V;WRG;!%SWVhEiSzh7w)|hBRIVhE!e#1{Yoi22)-J z1_fRQ20>m1hF?4k46k_@7_RX!FdXM$VA#OJz%Y}CfuV$lfgyv3fx(rBfkAK$!k&}Vp7AFJ4F-``CO`Hr2OF0=BmT)pKv~V&oG;=aAlyEXI_;E5YD04C} z{N`X_c*McL@Q{On;Q|K(!*UJ=hPfOJ4A~qE4DK8Z3~n3@3>F*=400R{4E!7n3_sZ! z7+$e6FkE40U^vRoz_6N~fnhc~14A7<14BML14A%71A_}Y1A{g@1A_uP1A`zt1H(5q z28P#c3=DVJ7#I$-F)(alV_=xc#=y|P#=ua@#=wxp#=sEB#=v03#=s!M#=!86m4V?L zD+9wiRtAQ}tPBjztPBh#tPBj9tPBj%tPBhRtPBjUtPBiRtPBjQtPBh)tV1x-k2-lY z1V{-11qB6bg^U~pTZQ71#FA8nl*E!m1_cF$oD_u|9ff2lGebuq3Cc{?QGh8()KQ4e z$ccqYB%w=Wf@Pql7vyK=m82Fal;mStlmXRQT$-eiqX2eMqJphLeojh!hJv<2a$-?Y zCCHM*lw^fO9fb@9YXy*eUTS%Kj)FF(I*8j7K|TYi%gHZ?ssecvtP5gV3dpn^sA)*5 zK(fU-i3*7jx1{8kCgr4}`Z_$nC_6JRJs1>bU~fX~L=P`(h19$hh2;E#N|49PA(}wO z=cHsPL}x%v3CYY!)i#WUhC&Y5SJT%=z?-aQHer+ngZBzh2WB+ z(&Q45?(iT-Uj}Q1%)HE!%)}gp%sjA8kXEoI5Q7to74lM3Q&Lm(KoTGe;mZ)ARwsfJ zV_q@X+|0amkUEf95!lDY3YjGcKPvb;`syeorj#Y-C1>U(gOrveW~UY_Bq|`~<-|ON zL{LB}K+I&YRzMCt28Li)=MYbSKLsU6*ow$vh2YYpVkI4gAb(#21_oFjaLr4x0%Z&s zACxDo6jI8O#Xw0JT@0E6trSwg1r$s>I02yxMxqNufCaEPQXwp{C^IoBCl%yS4^ZGU zSnHwz25SYlr@(%~qC`PK0ptN#QitYukektD(6~^AXrgFbQWRmaG90^cAeEqk8r9|a z)Pm&ninB8dAW;uWR}9E}Jp@2gWvu`YQ$#QsLYc6F3B(1}3`vmk+(s9gJ90DgN{bbo z6LV9GP%0#7utdO$WtcgzNPy^why~@RG=-9k%wmPiVujrNqEv;FjKn+zLxsfh#7Z57 zq@vWsYzAwEw9KO75{2aa+=9fSRE5%lg47~~q{@<1P(F=_h>T=F_610JdTCKAD0eGl zrYV$XmSkk+DHxfWfs`jh9BZwRlAo8VkdvR7l9`vT5TO9dgOMPA=A Date: Sun, 31 May 2020 16:08:57 +1200 Subject: [PATCH 8/9] cleaned up background, multiple palettes --- ass/grass.ass | 5 +++++ ass/villager.ass | 12 +++++----- ass/villager.gbr | Bin 10069 -> 10069 bytes src/actor.asm | 24 ++++++++++---------- src/entry.asm | 44 ++++++++++++++++++++---------------- src/main.asm | 1 + src/misc.asm | 14 ++++++++---- testing/ISSOtm.asm | 54 --------------------------------------------- 8 files changed, 59 insertions(+), 95 deletions(-) create mode 100644 ass/grass.ass delete mode 100644 testing/ISSOtm.asm diff --git a/ass/grass.ass b/ass/grass.ass new file mode 100644 index 0000000..476661f --- /dev/null +++ b/ass/grass.ass @@ -0,0 +1,5 @@ +SECTION "Grass Tile", ROM0 +grassTiles:: +DB $00,$00,$00,$00,$20,$00,$02,$00 +DB $04,$00,$44,$00,$20,$00,$00,$00 +grassTilesEnd:: diff --git a/ass/villager.ass b/ass/villager.ass index d088351..e7db7c0 100644 --- a/ass/villager.ass +++ b/ass/villager.ass @@ -5,25 +5,25 @@ DB $1F,$18,$3F,$20,$7F,$48,$74,$57 DB $26,$25,$0E,$09,$0E,$0A,$1E,$12 DB $F8,$18,$FC,$04,$FE,$12,$2E,$EA DB $64,$A4,$70,$90,$70,$50,$78,$48 -DB $0F,$08,$1F,$12,$1D,$14,$1F,$10 +DB $0F,$08,$1F,$12,$1D,$16,$1F,$10 DB $0F,$09,$07,$04,$03,$02,$07,$04 -DB $F0,$10,$F8,$48,$B8,$28,$F8,$08 +DB $F0,$10,$F8,$48,$B8,$68,$F8,$08 DB $F0,$90,$E0,$20,$C0,$40,$E0,$20 DB $00,$00,$00,$00,$00,$00,$00,$00 DB $01,$01,$03,$02,$03,$02,$07,$04 DB $00,$00,$00,$00,$00,$00,$00,$00 DB $80,$80,$C0,$40,$C0,$40,$E0,$20 -DB $0F,$08,$1F,$10,$1F,$12,$1D,$14 +DB $0F,$08,$1F,$10,$1F,$12,$1D,$16 DB $0F,$08,$07,$05,$03,$02,$07,$04 -DB $F0,$10,$F8,$08,$F8,$48,$B8,$28 +DB $F0,$10,$F8,$08,$F8,$48,$B8,$68 DB $F0,$10,$E0,$A0,$C0,$40,$E0,$20 DB $07,$04,$1F,$18,$3F,$20,$7C,$4F DB $76,$55,$2E,$29,$0E,$0A,$1E,$12 DB $E0,$20,$F8,$18,$FC,$04,$3E,$F2 DB $6E,$AA,$74,$94,$70,$50,$78,$48 -DB $0F,$08,$1F,$12,$1D,$14,$1F,$10 +DB $0F,$08,$1F,$12,$1D,$16,$1F,$10 DB $0F,$09,$07,$04,$03,$02,$1F,$1C -DB $F0,$10,$F8,$48,$B8,$28,$F8,$08 +DB $F0,$10,$F8,$48,$B8,$68,$F8,$08 DB $F0,$90,$E0,$20,$C0,$40,$F8,$38 DB $3F,$20,$7F,$48,$77,$54,$24,$27 DB $06,$05,$0E,$09,$0E,$0A,$1E,$12 diff --git a/ass/villager.gbr b/ass/villager.gbr index 3f600ce5efb7d00ba6db7a72f64d0838512939b2..f9e4ff170f22e8e490f3833da749533bc642e25d 100644 GIT binary patch delta 80 zcmccWchzr#9%~i@BLl-mV{t}CrpexnR*X!O+ZfL Date: Sun, 2 Aug 2020 11:19:30 +1200 Subject: [PATCH 9/9] updated readme --- README.md | 74 +++++++++++++++++++++++++++++++++++++++++++ src/textRendering.asm | 6 ++++ 2 files changed, 80 insertions(+) create mode 100644 src/textRendering.asm diff --git a/README.md b/README.md index ba72b1a..aa879d8 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,17 @@ just me messing about trying to learn gameboy assembly +currently have an animation engine supporting: + * arbitary sized frames + * multiple actors + * multiple animation states per actor (up to 128) + * arbitary number of frames + * arbitary time per frame of animation + * distinct animation timers per actor + * distinct colour palletes per tile in frame (limit 2 as per hardware) + * arbitary position of tiles in the tile bank per actor type + * arbitary positioning of tiles in each frame, including overlapping + == requisites == built using `rgbds`, will need to be installed for makefile to compile @@ -11,3 +22,66 @@ built using `rgbds`, will need to be installed for makefile to compile simply run `make` in the root directory to build the ROM will appear as a `.gb` file in `./build` + +== actor format == + +each actor has the following header: + +``` +ActorROM:: +.structs: + dw ActorIdle + dw VillagerWaving +``` + +where each pointer under `.structs` is another structure in memory. these pointers may be shared between different actor definitions, however the tilesets for each actor will need to be compatible with the same animation for this to work. + +each animation state has the following definition: + +``` +VillagerWaving:: + db 90 + db 15 + dw .vwFrame01 + db 15 + dw .vwFrame02 + db 15 + dw .vwFrame03 + db 15 + dw .vwFrame04 + db 15 + dw .vwFrame05 + db 15 + dw .vwFrame06 +``` + +the first byte contains the total number of frames this animation will run for, and then each following set of 3 bytes contains: + * the number of ticks this animation frame persists for + * a pointer to the frame data + +each frame has the following data: + +``` +.vwFrame01 + db (.vwFrame01End - @) / 4 + db 8, -16, 17, 0 + db 8, -8, 18, 0 + db 0, -16, 19, OAMF_PAL1 + db 0, -8, 20, OAMF_PAL1 + db -8, -16, 21, 0 + db -8, -8, 22, 0 +.vwFrame01End +``` + +the first byte is the number of tiles present in this frame of animation (analogous to the number of lines in the frame struct). + +each following line is 4 bytes, pertaining to (respectively): + + * the x offset of this tile + * the y offset of this tile + * the tile offset + * the attributes byte + +the position offsets do not need to take into account the gameboys blanket sprite offsets, and the tile offset is zero indexed, and will be added to another offset based on where this actors tiles lie in memory. + +the attribute byte is `xor`ed with the defaults in order to facilitate other pallettes or tile flips. diff --git a/src/textRendering.asm b/src/textRendering.asm new file mode 100644 index 0000000..4171cca --- /dev/null +++ b/src/textRendering.asm @@ -0,0 +1,6 @@ +;---------------- +; Text Rendering +;---------------- + +; Aims +; Get a renderable text to the graphics window,