diff options
author | Rangi <remy.oukaour+rangi@gmail.com> | 2018-06-01 13:24:42 -0400 |
---|---|---|
committer | Rangi <remy.oukaour+rangi@gmail.com> | 2018-06-01 13:24:42 -0400 |
commit | c8e99019471f5f7b5e1824687043ac92bc7a424b (patch) | |
tree | ebd15a637250451f6ebcf7bde702c19df4926100 | |
parent | 05350cd17ddd5d087146ef59720fb881ebda75e0 (diff) |
Code conventions:
- Lowercase hex literals
- Lowercase rgbasm keywords (rept, endr)
- Use decimal literals by default, binary when bits are meaningful; hex indicates that it needs further review, e.g. to define a constant
- Tabs, not spaces
- Newline at end of file (rgbds sometimes complains otherwise)
- Doc comments underneath function names
-rw-r--r-- | engine/link/place_waiting_text.asm | 2 | ||||
-rw-r--r-- | engine/menu/main_menu.asm | 2 | ||||
-rw-r--r-- | home/audio.asm | 247 | ||||
-rw-r--r-- | home/bankswitch.asm | 6 | ||||
-rw-r--r-- | home/clear_sprites.asm | 32 | ||||
-rw-r--r-- | home/copy.asm | 166 | ||||
-rw-r--r-- | home/copy2.asm | 28 | ||||
-rw-r--r-- | home/delay.asm | 28 | ||||
-rw-r--r-- | home/farcall.asm | 62 | ||||
-rw-r--r-- | home/init.asm | 223 | ||||
-rw-r--r-- | home/interrupts.asm | 14 | ||||
-rwxr-xr-x | home/items.asm | 185 | ||||
-rw-r--r-- | home/joypad.asm | 2 | ||||
-rw-r--r-- | home/lcd.asm | 120 | ||||
-rw-r--r-- | home/oam_dma.asm | 30 | ||||
-rw-r--r-- | home/pic.asm | 40 | ||||
-rw-r--r-- | home/pokemon.asm | 35 | ||||
-rw-r--r-- | home/predef.asm | 72 | ||||
-rw-r--r-- | home/serial.asm | 87 | ||||
-rw-r--r-- | home/sram.asm | 28 | ||||
-rw-r--r-- | home/unknown.asm | 38 | ||||
-rw-r--r-- | home/vblank.asm | 48 | ||||
-rw-r--r-- | home/vcopy.asm | 27 |
23 files changed, 756 insertions, 766 deletions
diff --git a/engine/link/place_waiting_text.asm b/engine/link/place_waiting_text.asm index c617dec..bfe9d7e 100644 --- a/engine/link/place_waiting_text.asm +++ b/engine/link/place_waiting_text.asm @@ -15,7 +15,7 @@ PlaceWaitingText:: ; 1:4000 .link_textbox ; TODO ; predef Predef_LinkTextbox - ld a, $1C + ld a, $1c call Predef .textbox_done hlcoord 4, 11 diff --git a/engine/menu/main_menu.asm b/engine/menu/main_menu.asm index 5701eba..536123f 100644 --- a/engine/menu/main_menu.asm +++ b/engine/menu/main_menu.asm @@ -4,7 +4,7 @@ SECTION "Main Menu Definition", ROMX[$5418], BANK[$01] MainMenuHeader: db $40 - db 0, 0, 7, 13 + db $00, $00, $07, $0d dw .data db 1 ; default option diff --git a/home/audio.asm b/home/audio.asm index a983bf3..5104582 100644 --- a/home/audio.asm +++ b/home/audio.asm @@ -3,143 +3,136 @@ INCLUDE "constants.asm" SECTION "Audio interface", ROM0[$3CBF] DisableAudio:: ; 3cbf - push hl - push de - push bc - push af - ldh a, [hROMBank] - push af - ld a, BANK(_DisableAudio) - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - call _DisableAudio - pop af - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - pop af - pop bc - pop de - pop hl - ret - + push hl + push de + push bc + push af + ldh a, [hROMBank] + push af + ld a, BANK(_DisableAudio) + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + call _DisableAudio + pop af + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + pop af + pop bc + pop de + pop hl + ret UpdateSound:: ; 3cdb - push hl - push de - push bc - push af - ldh a, [hROMBank] - push af - ld a, BANK(_UpdateSound) - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - call _UpdateSound - pop af - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - pop af - pop bc - pop de - pop hl - ret - + push hl + push de + push bc + push af + ldh a, [hROMBank] + push af + ld a, BANK(_UpdateSound) + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + call _UpdateSound + pop af + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + pop af + pop bc + pop de + pop hl + ret _LoadMusicByte:: ; 3cf7 - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - ld a, [de] - push af - ld a, BANK(_UpdateSound) - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - pop af - ret - + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + ld a, [de] + push af + ld a, BANK(_UpdateSound) + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + pop af + ret PlayMusic:: ; 3d07 - push hl - push de - push bc - push af - ldh a, [hROMBank] - push af - ld a, BANK(_PlayMusic) - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - call _PlayMusic - pop af - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - pop af - pop bc - pop de - pop hl - ret - + push hl + push de + push bc + push af + ldh a, [hROMBank] + push af + ld a, BANK(_PlayMusic) + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + call _PlayMusic + pop af + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + pop af + pop bc + pop de + pop hl + ret PlayCryHeader:: ; 3d23 - push hl - push de - push bc - push af - ldh a, [hROMBank] - push af - - ld a, BANK(CryHeaders) - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - ld hl, CryHeaders -REPT 6 - add hl, de -ENDR - ld e, [hl] - inc hl - ld d, [hl] - inc hl - ld a, [hli] - ld [wCryPitch], a - ld a, [hli] - ld [wCryPitch + 1], a - ld a, [hli] - ld [wCryLength], a - ld a, [hl] - ld [wCryLength + 1], a - - ld a, BANK(_PlayCryHeader) - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - call _PlayCryHeader + push hl + push de + push bc + push af + ldh a, [hROMBank] + push af + + ld a, BANK(CryHeaders) + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + ld hl, CryHeaders +rept 6 + add hl, de +endr + ld e, [hl] + inc hl + ld d, [hl] + inc hl + ld a, [hli] + ld [wCryPitch], a + ld a, [hli] + ld [wCryPitch + 1], a + ld a, [hli] + ld [wCryLength], a + ld a, [hl] + ld [wCryLength + 1], a + + ld a, BANK(_PlayCryHeader) + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + call _PlayCryHeader - pop af - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - pop af - pop bc - pop de - pop hl - ret - - - + pop af + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + pop af + pop bc + pop de + pop hl + ret PlaySFX:: ; 3d63 - push hl - push de - push bc - push af - ldh a, [hROMBank] - push af - ld a, BANK(_PlaySFX) - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - call _PlaySFX - pop af - ld [MBC3RomBank], a ; Unsafe - ldh [hROMBank], a - pop af - pop bc - pop de - pop hl - ret + push hl + push de + push bc + push af + ldh a, [hROMBank] + push af + ld a, BANK(_PlaySFX) + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + call _PlaySFX + pop af + ld [MBC3RomBank], a ; Unsafe + ldh [hROMBank], a + pop af + pop bc + pop de + pop hl + ret WaitPlaySFX:: ; 3d7f diff --git a/home/bankswitch.asm b/home/bankswitch.asm index b8549bc..1ad45f1 100644 --- a/home/bankswitch.asm +++ b/home/bankswitch.asm @@ -5,6 +5,6 @@ SECTION "Bankswitch", ROM0[$32C2] ; Moved to a rst vector in final US releases (not sure about JP) ; All rst vectors are unused at this point in development Bankswitch:: ; 32c2 - ldh [hROMBank], a - ld [MBC3RomBank], a - ret + ldh [hROMBank], a + ld [MBC3RomBank], a + ret diff --git a/home/clear_sprites.asm b/home/clear_sprites.asm index c6ac3aa..40f187a 100644 --- a/home/clear_sprites.asm +++ b/home/clear_sprites.asm @@ -3,23 +3,23 @@ INCLUDE "constants.asm" SECTION "Sprite clearing", ROM0[$32DC] ClearSprites:: ; 32dc - ld hl, wVirtualOAM - ld b, wVirtualOAMEnd - wVirtualOAM - xor a + ld hl, wVirtualOAM + ld b, wVirtualOAMEnd - wVirtualOAM + xor a .loop - ld [hli], a - dec b - jr nz, .loop - ret + ld [hli], a + dec b + jr nz, .loop + ret HideSprites:: ; 32e7 - ld hl, wVirtualOAM - ld de, SPRITEOAMSTRUCT_LENGTH - ld b, NUM_SPRITE_OAM_STRUCTS - ld a, $A0 + ld hl, wVirtualOAM + ld de, SPRITEOAMSTRUCT_LENGTH + ld b, NUM_SPRITE_OAM_STRUCTS + ld a, SPRITEOAMSTRUCT_LENGTH * NUM_SPRITE_OAM_STRUCTS .loop - ld [hl], a - add hl, de - dec b - jr nz, .loop - ret + ld [hl], a + add hl, de + dec b + jr nz, .loop + ret diff --git a/home/copy.asm b/home/copy.asm index 5a73efd..dfb35ef 100644 --- a/home/copy.asm +++ b/home/copy.asm @@ -2,111 +2,109 @@ INCLUDE "constants.asm" SECTION "Copy functions", ROM0[$32F7] -; Copy bc bytes from a:hl to de. FarCopyBytes:: ; 32f7 - ld [wBuffer], a - ldh a, [hROMBank] - push af - ld a, [wBuffer] - call Bankswitch - call CopyBytes - pop af - jp Bankswitch +; Copy bc bytes from a:hl to de. + ld [wBuffer], a + ldh a, [hROMBank] + push af + ld a, [wBuffer] + call Bankswitch + call CopyBytes + pop af + jp Bankswitch -; Copy bc bytes from hl to de CopyBytes:: ; 330a - ld a, b - and a - jr z, CopyBytesSmall - ld a, c - and a - jr z, .next - inc b +; Copy bc bytes from hl to de + ld a, b + and a + jr z, CopyBytesSmall + ld a, c + and a + jr z, .next + inc b .next - call CopyBytesSmall - dec b - jr nz, .next - ret + call CopyBytesSmall + dec b + jr nz, .next + ret -; Copy c bytes from hl to de CopyBytesSmall:: ; 331a - ld a, [hli] - ld [de], a - inc de - dec c - jr nz, CopyBytesSmall - ret - +; Copy c bytes from hl to de + ld a, [hli] + ld [de], a + inc de + dec c + jr nz, CopyBytesSmall + ret GetFarByte:: ; 3321 - ld [wBuffer], a - ldh a, [hROMBank] - push af - ld a, [wBuffer] - call Bankswitch - ld a, [hl] - ld [wBuffer], a - pop af - call Bankswitch - ld a, [wBuffer] - ret - + ld [wBuffer], a + ldh a, [hROMBank] + push af + ld a, [wBuffer] + call Bankswitch + ld a, [hl] + ld [wBuffer], a + pop af + call Bankswitch + ld a, [wBuffer] + ret ByteFill:: ; 3339 - push af - ld a, b - and a - jr z, .small_fill - ld a, c - and a - jr z, .start_filling + push af + ld a, b + and a + jr z, .small_fill + ld a, c + and a + jr z, .start_filling .small_fill - inc b + inc b .start_filling - pop af + pop af .loop - ld [hli], a - dec c - jr nz, .loop - dec b - jr nz, .loop - ret + ld [hli], a + dec c + jr nz, .loop + dec b + jr nz, .loop + ret UncompressSpriteFromDE:: ; Decompress pic at a:de. - ld hl, wSpriteInputPtr - ld [hl], e - inc hl - ld [hl], d - jp UncompressSpriteData + ld hl, wSpriteInputPtr + ld [hl], e + inc hl + ld [hl], d + jp UncompressSpriteData BackUpTilesToBuffer:: ; 3355 - hlcoord 0, 0 - decoord 0, 0, wTileMapBackup - ld bc, SCREEN_HEIGHT * SCREEN_WIDTH - jp CopyBytes + hlcoord 0, 0 + decoord 0, 0, wTileMapBackup + ld bc, SCREEN_HEIGHT * SCREEN_WIDTH + jp CopyBytes ReloadTilesFromBuffer:: ; 3361 - xor a - ldh [hBGMapMode], a - hlcoord 0, 0, wTileMapBackup - decoord 0, 0 - ld bc, SCREEN_HEIGHT * SCREEN_WIDTH - call CopyBytes - ld a, 1 - ldh [hBGMapMode], a - ret + xor a + ldh [hBGMapMode], a + hlcoord 0, 0, wTileMapBackup + decoord 0, 0 + ld bc, SCREEN_HEIGHT * SCREEN_WIDTH + call CopyBytes + ld a, 1 + ldh [hBGMapMode], a + ret -; copies a string from [de] to [wcd31] CopyStringToCD31:: - ld hl, wcd31 - ; fall through +; copies a string from [de] to [wcd31] + ld hl, wcd31 + ; fallthrough -; copies a string from [de] to [hl] CopyString:: - ld a, [de] - inc de - ld [hli], a - cp "@" - jr nz, CopyString - ret
\ No newline at end of file +; copies a string from [de] to [hl] + ld a, [de] + inc de + ld [hli], a + cp "@" + jr nz, CopyString + ret diff --git a/home/copy2.asm b/home/copy2.asm index 27abf08..0a0ee54 100644 --- a/home/copy2.asm +++ b/home/copy2.asm @@ -2,9 +2,9 @@ INCLUDE "constants.asm" SECTION "Video Copy functions", ROM0[$0D2A] +FarCopyData: ; d2a (0:d2a) ; Identical to FarCopyBytes except for tail call optimization ; Copy bc 2bpp bytes from a:hl to de. -FarCopyData: ; d2a (0:d2a) ld [wBuffer], a ldh a, [hROMBank] push af @@ -15,8 +15,8 @@ FarCopyData: ; d2a (0:d2a) call Bankswitch ret -; Copy and expand bc 1bpp bytes from a:hl to de. FarCopyDataDouble: ; d3e (0:d3e) +; Copy and expand bc 1bpp bytes from a:hl to de. ld [wBuffer], a ldh a, [hROMBank] push af @@ -49,10 +49,10 @@ FarCopyDataDouble: ; d3e (0:d3e) call Bankswitch ret +CopyVideoData:: ; d68 (0:d68) ; Wait for the next VBlank, then copy c 2bpp ; tiles from b:de to hl, 8 tiles at a time. ; This takes c/8 frames. -CopyVideoData:: ; d68 (0:d68) ldh a, [hBGMapMode] push af xor a ; disable auto-transfer while copying @@ -71,7 +71,7 @@ CopyVideoData:: ; d68 (0:d68) ld [wVBCopyDst + 1], a .loop ld a, c - cp $08 + cp $8 jr nc, .keepgoing ld [wVBCopySize], a call DelayFrame @@ -81,18 +81,18 @@ CopyVideoData:: ; d68 (0:d68) ldh [hBGMapMode], a ret .keepgoing - ld a, $08 + ld a, $8 ld [wVBCopySize], a call DelayFrame ld a, c - sub $08 + sub $8 ld c, a jr .loop +CopyVideoDataDouble:: ; da6 (0:da6) ; Wait for the next VBlank, then copy c 1bpp ; tiles from b:de to hl, 8 tiles at a time. ; This takes c/8 frames. -CopyVideoDataDouble:: ; da6 (0:da6) ldh a, [hBGMapMode] push af xor a @@ -111,7 +111,7 @@ CopyVideoDataDouble:: ; da6 (0:da6) ld [wVBCopyDoubleDst + 1], a .loop ld a, c - cp $08 + cp $8 jr nc, .keepgoing ld [wVBCopyDoubleSize], a call DelayFrame @@ -121,18 +121,18 @@ CopyVideoDataDouble:: ; da6 (0:da6) ldh [hBGMapMode], a ret .keepgoing - ld a, $08 + ld a, $8 ld [wVBCopyDoubleSize], a call DelayFrame ld a, c - sub $08 + sub $8 ld c, a jr .loop +CopyVideoDataOptimized:: ; de4 (0:de4) ; Copy c 2bpp tiles from b:de to hl in VRAM ; using VBlank service or direct copy in ; case LCD is off -CopyVideoDataOptimized:: ; de4 (0:de4) ldh a, [rLCDC] bit rLCDC_ENABLE, a jp nz, CopyVideoData ; copy video data during vblank while screen is on @@ -152,10 +152,10 @@ CopyVideoDataOptimized:: ; de4 (0:de4) pop af jp FarCopyData +CopyVideoDataDoubleOptimized: ; dff (0:dff) ; Copy c 1bpp tiles from b:de to hl in VRAM ; using VBlank service or direct copy in ; case LCD is off -CopyVideoDataDoubleOptimized: ; dff (0:dff) ldh a, [rLCDC] bit rLCDC_ENABLE, a jp nz, CopyVideoDataDouble @@ -164,7 +164,7 @@ CopyVideoDataDoubleOptimized: ; dff (0:dff) ld e, l ld a, b push af - ld h, $00 + ld h, 0 ld l, c add hl, hl add hl, hl @@ -174,4 +174,4 @@ CopyVideoDataDoubleOptimized: ; dff (0:dff) pop af pop hl jp FarCopyDataDouble -; 0xe18
\ No newline at end of file +; 0xe18 diff --git a/home/delay.asm b/home/delay.asm index dc3ad40..286cc0c 100644 --- a/home/delay.asm +++ b/home/delay.asm @@ -4,23 +4,19 @@ SECTION "Delay", ROM0[$0317] DelayFrame:: ; Wait for one frame - ld a, 1 - ld [wVBlankOccurred], a - -; Wait for the next VBlank, halting to conserve battery + ld a, 1 + ld [wVBlankOccurred], a .halt - halt ; rgbasm adds a nop after this instruction by default - ld a, [wVBlankOccurred] - and a - jr nz, .halt - - ret - +; Wait for the next VBlank, halting to conserve battery + halt ; rgbasm adds a nop after this instruction by default + ld a, [wVBlankOccurred] + and a + jr nz, .halt + ret DelayFrames:: ; Wait c frames - call DelayFrame - dec c - jr nz, DelayFrames - - ret + call DelayFrame + dec c + jr nz, DelayFrames + ret diff --git a/home/farcall.asm b/home/farcall.asm index f7a97d0..106ca28 100644 --- a/home/farcall.asm +++ b/home/farcall.asm @@ -3,36 +3,36 @@ INCLUDE "constants.asm" SECTION "Farcall", ROM0[$2FA8] FarCall_hl:: ; 2fa8 - push af - ld a, b - ld [wFarCallBCBuffer], a - ld a, c - ld [wFarCallBCBuffer + 1], a - pop af - ld b, a - ldh a, [hROMBank] - push af - ld a, b - call Bankswitch - ld bc, .return - push bc - push hl - ld a, [wFarCallBCBuffer] - ld b, a - ld a, [wFarCallBCBuffer + 1] - ld c, a - ret + push af + ld a, b + ld [wFarCallBCBuffer], a + ld a, c + ld [wFarCallBCBuffer + 1], a + pop af + ld b, a + ldh a, [hROMBank] + push af + ld a, b + call Bankswitch + ld bc, .return + push bc + push hl + ld a, [wFarCallBCBuffer] + ld b, a + ld a, [wFarCallBCBuffer + 1] + ld c, a + ret .return - ld a, b - ld [wFarCallBCBuffer], a - ld a, c - ld [wFarCallBCBuffer + 1], a - pop bc - ld a, b - call Bankswitch - ld a, [wFarCallBCBuffer] - ld b, a - ld a, [wFarCallBCBuffer + 1] - ld c, a - ret + ld a, b + ld [wFarCallBCBuffer], a + ld a, c + ld [wFarCallBCBuffer + 1], a + pop bc + ld a, b + call Bankswitch + ld a, [wFarCallBCBuffer] + ld b, a + ld a, [wFarCallBCBuffer + 1] + ld c, a + ret diff --git a/home/init.asm b/home/init.asm index 0a31e69..38c2a31 100644 --- a/home/init.asm +++ b/home/init.asm @@ -1,133 +1,134 @@ INCLUDE "constants.asm" SECTION "Entry point", ROM0[$100] - nop - jp Init + nop + jp Init SECTION "Global check value", ROM0[$14E] ; The ROM has an incorrect global check, so set it here ; It is not corrected by RGBFIX - db $21, $C6 + db $21, $C6 SECTION "Init", ROM0[$52F] Init: ; 052f - di - xor a - ld [rIF], a - ld [rIE], a - ld [rSCX], a - ld [rSCY], a - ld [rSB], a - ld [rSC], a - ld [rWX], a - ld [rWY], a - ld [rBGP], a - ld [rOBP0], a - ld [rOBP1], a - ld [rTMA], a - ld [rTAC], a - ld [wcc38], a ; Useless, since WRAM gets cleared right after - ld a, 1 << rTAC_ON | rTAC_4096_HZ - ld [rTAC], a - ld a, 1 << rLCDC_ENABLE - ld [rLCDC], a - call DisableLCD - - ld sp, wStackBottom - call ClearVRAM - ld hl, WRAM0_Begin - ld bc, WRAM1_End - WRAM0_Begin + di + xor a + ld [rIF], a + ld [rIE], a + ld [rSCX], a + ld [rSCY], a + ld [rSB], a + ld [rSC], a + ld [rWX], a + ld [rWY], a + ld [rBGP], a + ld [rOBP0], a + ld [rOBP1], a + ld [rTMA], a + ld [rTAC], a + ld [wcc38], a ; Useless, since WRAM gets cleared right after + ld a, 1 << rTAC_ON | rTAC_4096_HZ + ld [rTAC], a + ld a, 1 << rLCDC_ENABLE + ld [rLCDC], a + call DisableLCD + + ld sp, wStackBottom + call ClearVRAM + ld hl, WRAM0_Begin + ld bc, WRAM1_End - WRAM0_Begin .ByteFill ; 0565 - ld [hl], 0 - inc hl - dec bc - ld a, b - or c - jr nz, .ByteFill - ld hl, HRAM_Begin - ld bc, HRAM_End - HRAM_Begin - call ByteFill - call ClearSprites - - ld a, BANK(WriteOAMDMACodeToHRAM) - call Bankswitch - call WriteOAMDMACodeToHRAM - - xor a - ldh [hMapAnims], a - ldh [hSCX], a - ldh [hSCY], a - ldh [rJOYP], a - ld a, 1 << rSTAT_HBLANK - ld [rSTAT], a - ld a, SCREEN_HEIGHT_PX - ldh [hWY], a - ld [rWY], a - ld a, 7 - ldh [hWX], a - ld [rWX], a - - ld a, $FF - ldh [hLinkPlayerNumber], a - ld h, HIGH($9800) - call BlankBGMap - ld h, HIGH($9C00) - call BlankBGMap - ld a, LCDC_DEFAULT - ld [rLCDC], a - - call DisableAudio - call _2007 - ; predef ??? - ld a, $4B ; TODO: add predefs so the line above can be uncommented - call Predef - ld a, $1F - ld [rIE], a - ld a, HIGH($9C00) - ldh [hBGMapAddress + 1], a - xor a - ldh [hBGMapAddress], a - - call DisableLCD - call ClearVRAM - ld a, LCDC_DEFAULT - ld [rLCDC], a - ei - - ld a, SRAM_ENABLE - ld [MBC3SRamEnable], a - ld a, RTC_DH - ld [MBC3SRamBank], a - xor a - ld [SRAM_Begin], a - ld a, 0 ; Useless - ld [MBC3LatchClock], a - ld [MBC3SRamEnable], a - jp GameInit + ld [hl], 0 + inc hl + dec bc + ld a, b + or c + jr nz, .ByteFill + ld hl, HRAM_Begin + ld bc, HRAM_End - HRAM_Begin + call ByteFill + call ClearSprites + + ld a, BANK(WriteOAMDMACodeToHRAM) + call Bankswitch + call WriteOAMDMACodeToHRAM + + xor a + ldh [hMapAnims], a + ldh [hSCX], a + ldh [hSCY], a + ldh [rJOYP], a + ld a, 1 << rSTAT_HBLANK + ld [rSTAT], a + ld a, SCREEN_HEIGHT_PX + ldh [hWY], a + ld [rWY], a + ld a, 7 + ldh [hWX], a + ld [rWX], a + + ld a, $ff + ldh [hLinkPlayerNumber], a + ld h, HIGH($9800) + call BlankBGMap + ld h, HIGH($9C00) + call BlankBGMap + ld a, LCDC_DEFAULT + ld [rLCDC], a + + call DisableAudio + call _2007 + ; predef ??? + ld a, $4B ; TODO: add predefs so the line above can be uncommented + call Predef + ld a, $1F + ld [rIE], a + ld a, HIGH($9C00) + ldh [hBGMapAddress + 1], a + xor a + ldh [hBGMapAddress], a + + call DisableLCD + call ClearVRAM + ld a, LCDC_DEFAULT + ld [rLCDC], a + ei + + ld a, SRAM_ENABLE + ld [MBC3SRamEnable], a + ld a, RTC_DH + ld [MBC3SRamBank], a + xor a + ld [SRAM_Begin], a + ld a, 0 ; Useless + ld [MBC3LatchClock], a + ld [MBC3SRamEnable], a + jp GameInit ClearVRAM: ; 05e6 - ld hl, VRAM_Begin - ld bc, VRAM_End - VRAM_Begin - xor a - call ByteFill - ret + ld hl, VRAM_Begin + ld bc, VRAM_End - VRAM_Begin + xor a + call ByteFill + ret BlankBGMap: - ld a, $7F - jr _FillBGMap + ld a, $7f + jr _FillBGMap FillBGMap: - ld a, l + ld a, l + ; fallthrough _FillBGMap: - ld de, $400 - ld l, e + ld de, BG_MAP_WIDTH * BG_MAP_HEIGHT + ld l, e .loop - ld [hli], a - dec e - jr nz, .loop - dec d - jr nz, .loop - ret + ld [hli], a + dec e + jr nz, .loop + dec d + jr nz, .loop + ret diff --git a/home/interrupts.asm b/home/interrupts.asm index b7800f1..f9d8ba1 100644 --- a/home/interrupts.asm +++ b/home/interrupts.asm @@ -1,28 +1,28 @@ INCLUDE "constants.asm" SECTION "VBlank interrupt vector", ROM0[$040] - jp VBlank + jp VBlank SECTION "LCD interrupt vector", ROM0[$048] - jp LCD + jp LCD SECTION "Timer interrupt vector", ROM0[$050] - jp TimerDummy + jp TimerDummy SECTION "Serial interrupt vector", ROM0[$058] - jp Serial + jp Serial SECTION "Joypad interrupt vector", ROM0[$060] - jp JoypadDummy + jp JoypadDummy SECTION "Timer dummy interrupt", ROM0[$42A] TimerDummy: ; 042a - reti + reti SECTION "Joypad dummy interrupt", ROM0[$7F7] JoypadDummy: ; 07f7 - reti + reti diff --git a/home/items.asm b/home/items.asm index dd9c3b3..d5303c3 100755 --- a/home/items.asm +++ b/home/items.asm @@ -2,28 +2,28 @@ INCLUDE "constants.asm" SECTION "AddItemToInventory", ROM0[$3259]
+AddItemToInventory:: ; 3259
; function to add an item (in varying quantities) to the player's bag or PC box
; INPUT:
; HL = address of inventory (either wNumBagItems or wNumBoxItems)
; [wcd76] = item ID
; [wItemQuantity] = item quantity
; sets carry flag if successful, unsets carry flag if unsuccessful
-AddItemToInventory:: ; 3259
- push bc
- ldh a, [hROMBank]
- push af
- ld a, BANK(AddItemToInventory_)
- call Bankswitch
- push hl
- push de
- call AddItemToInventory_
- pop de
- pop hl
- pop bc
- ld a, b
- call Bankswitch
- pop bc
- ret
+ push bc
+ ldh a, [hROMBank]
+ push af
+ ld a, BANK(AddItemToInventory_)
+ call Bankswitch
+ push hl
+ push de
+ call AddItemToInventory_
+ pop de
+ pop hl
+ pop bc
+ ld a, b
+ call Bankswitch
+ pop bc
+ ret
SECTION "GiveItem", ROM0[$366C]
@@ -31,100 +31,99 @@ GiveItem:: ; Give player quantity c of item b,
; and copy the item's name to wcf4b.
; Return carry on success.
- ld a, b
- ld [wce37], a
- ld [wcd76], a
- ld a, c
- ld [wItemQuantity], a
- ld hl, wNumBagItems
- call AddItemToInventory
- ret nc
- call GetItemName
- call CopyStringToCD31
- scf
- ret
-
+ ld a, b
+ ld [wce37], a
+ ld [wcd76], a
+ ld a, c
+ ld [wItemQuantity], a
+ ld hl, wNumBagItems
+ call AddItemToInventory
+ ret nc
+ call GetItemName
+ call CopyStringToCD31
+ scf
+ ret
+
SECTION "GetItemName", ROM0[$376F]
GetItemName:: ; 376F
; given an item ID at [wce37], store the name of the item into a string
-; starting at wcd26
- push hl
- push bc
- ld a, [wce37]
- cp ITEM_HM01_RED
- jr nc, .Machine
+; starting at wcd26
+ push hl
+ push bc
+ ld a, [wce37]
+ cp ITEM_HM01_RED
+ jr nc, .machine
- ld [wcb5b], a
- ld a, ITEM_NAME
- ld [wNameCategory], a
- call GetName
- jr .Finish
+ ld [wcb5b], a
+ ld a, ITEM_NAME
+ ld [wNameCategory], a
+ call GetName
+ jr .finish
-.Machine
+.machine
call GetMachineName
-.Finish
- ld de, wcd26 ; pointer to where item name is stored in RAM
- pop bc
- pop hl
- ret
-
+.finish
+ ld de, wcd26 ; pointer to where item name is stored in RAM
+ pop bc
+ pop hl
+ ret
+
SECTION "GetMachineName", ROM0[$378E]
GetMachineName::
; copies the name of the TM/HM in [wce37] to wcd26
- push hl
- push de
- push bc
- ld a, [wce37]
- push af
- cp ITEM_TM01_RED
- jr nc, .WriteTM
+ push hl
+ push de
+ push bc
+ ld a, [wce37]
+ push af
+ cp ITEM_TM01_RED
+ jr nc, .WriteTM
; if HM, then write "HM" and add 5 to the item ID, so we can reuse the
; TM printing code
- add 5
- ld [wce37], a
- ld hl, HiddenPrefix
- ld bc, 6
- jr .WriteMachinePrefix
+ add 5
+ ld [wce37], a
+ ld hl, HiddenPrefix
+ ld bc, 6
+ jr .WriteMachinePrefix
.WriteTM
- ld hl, TechnicalPrefix
- ld bc, 5
+ ld hl, TechnicalPrefix
+ ld bc, 5
.WriteMachinePrefix
- ld de, wcd26
- call CopyBytes
-
+ ld de, wcd26
+ call CopyBytes
; now get the machine number and convert it to text
- ld a, [wce37]
- sub ITEM_TM01_RED - 1
- ld b, "0"
+ ld a, [wce37]
+ sub ITEM_TM01_RED - 1
+ ld b, "0"
.FirstDigit
- sub 10
- jr c, .SecondDigit
- inc b
- jr .FirstDigit
+ sub 10
+ jr c, .SecondDigit
+ inc b
+ jr .FirstDigit
.SecondDigit
- add 10
- push af
- ld a, b
- ld [de], a
- inc de
- pop af
- ld b, "0"
- add b
- ld [de], a
- inc de
- ld a, "@"
- ld [de], a
- pop af
- ld [wce37], a
- pop bc
- pop de
- pop hl
- ret
-
+ add 10
+ push af
+ ld a, b
+ ld [de], a
+ inc de
+ pop af
+ ld b, "0"
+ add b
+ ld [de], a
+ inc de
+ ld a, "@"
+ ld [de], a
+ pop af
+ ld [wce37], a
+ pop bc
+ pop de
+ pop hl
+ ret
+
TechnicalPrefix:
- db "わざマシン@"
-
+ db "わざマシン@"
+
HiddenPrefix:
- db "ひでんマシン@"
\ No newline at end of file + db "ひでんマシン@"
diff --git a/home/joypad.asm b/home/joypad.asm index 35e8086..8f8e7e6 100644 --- a/home/joypad.asm +++ b/home/joypad.asm @@ -58,4 +58,4 @@ Joypad:: ; 7fe (0:7fe) cp $0f jp z, Reset ret -; 0x84a
\ No newline at end of file +; 0x84a diff --git a/home/lcd.asm b/home/lcd.asm index 6641f05..e915806 100644 --- a/home/lcd.asm +++ b/home/lcd.asm @@ -3,78 +3,78 @@ INCLUDE "constants.asm" SECTION "LCD functions", ROM0[$3AE] LCD:: ; 03ae - push af - ldh a, [hLCDCPointer] - and a - jr z, .done - push hl - rla - jr c, .try_hide_sprites - ld a, [rLY] - ld l, a - ld h, HIGH(wLYOverrides) - ld h, [hl] - ldh a, [hLCDCPointer] - ld l, a - ld a, h - ld h, $FF - ld [hl], a - pop hl - pop af - reti + push af + ldh a, [hLCDCPointer] + and a + jr z, .done + push hl + rla + jr c, .try_hide_sprites + ld a, [rLY] + ld l, a + ld h, HIGH(wLYOverrides) + ld h, [hl] + ldh a, [hLCDCPointer] + ld l, a + ld a, h + ld h, $FF + ld [hl], a + pop hl + pop af + reti .try_hide_sprites - ld a, [rLY] - cp $80 - jr nz, .dont_hide - ld hl, rLCDC - res 1, [hl] + ld a, [rLY] + cp $80 + jr nz, .dont_hide + ld hl, rLCDC + res 1, [hl] .dont_hide - pop hl - pop af - reti + pop hl + pop af + reti - ; Seems unused? - ldh a, [hSCX] - ld [rSCX], a - ldh a, [hSCY] - ld [rSCY], a - pop hl + ; Seems unused? + ldh a, [hSCX] + ld [rSCX], a + ldh a, [hSCY] + ld [rSCY], a + pop hl .done - pop af - reti + pop af + reti ; 0:3e1 ; TODO: can this be done using `sine_table`? - db 0, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 0, -1, -2, -2, -3, -3, -4, -4, -4, -4, -4, -3, -3, -2, -2, -1 + db 0, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 0, -1, -2, -2, -3, -3, -4, -4, -4, -4, -4, -3, -3, -2, -2, -1 DisableLCD:: ; 0401 - ld a, [rLCDC] - bit 7, a - ret z - xor a - ld [rIF], a - ld a, [rIE] - ld b, a - res 0, a - ld [rIE], a + ld a, [rLCDC] + bit 7, a + ret z + xor a + ld [rIF], a + ld a, [rIE] + ld b, a + res 0, a + ld [rIE], a .wait - ld a, [rLY] - cp LY_VBLANK + 1 - jr nz, .wait - ld a, [rLCDC] - and $7F ; Shut LCD down - ld [rLCDC], a - xor a - ld [rIF], a - ld a, b - ld [rIE], a - ret + ld a, [rLY] + cp LY_VBLANK + 1 + jr nz, .wait + ld a, [rLCDC] + and $7f ; Shut LCD down + ld [rLCDC], a + xor a + ld [rIF], a + ld a, b + ld [rIE], a + ret EnableLCD:: ; 0423 - ld a, [rLCDC] - set 7, a - ld [rLCDC], a - ret + ld a, [rLCDC] + set 7, a + ld [rLCDC], a + ret diff --git a/home/oam_dma.asm b/home/oam_dma.asm index d76df89..42ecaaf 100644 --- a/home/oam_dma.asm +++ b/home/oam_dma.asm @@ -3,23 +3,23 @@ INCLUDE "constants.asm" SECTION "OAM DMA", ROMX[$4153],BANK[1] WriteOAMDMACodeToHRAM:: ; 4153 - ld c, LOW(hOAMDMA) - ld b, .OAMDMAEnd - .OAMDMA - ld hl, .OAMDMA + ld c, LOW(hOAMDMA) + ld b, .OAMDMAEnd - .OAMDMA + ld hl, .OAMDMA .loop - ld a, [hli] - ld [$ff00+c], a - inc c - dec b - jr nz, .loop - ret + ld a, [hli] + ld [$ff00+c], a + inc c + dec b + jr nz, .loop + ret .OAMDMA ; 4161 - ld a, HIGH(wVirtualOAM) - ldh [rDMA], a - ld a, $28 + ld a, HIGH(wVirtualOAM) + ldh [rDMA], a + ld a, $28 .wait - dec a - jr nz, .wait - ret + dec a + jr nz, .wait + ret .OAMDMAEnd ; 416b diff --git a/home/pic.asm b/home/pic.asm index 60dd6a3..04cf7bb 100644 --- a/home/pic.asm +++ b/home/pic.asm @@ -2,9 +2,9 @@ INCLUDE "constants.asm" SECTION "Decompression Functions", ROM0[$095E] +UncompressSpriteData:: ; 95e (0:95e) ; bankswitches and runs _UncompressSpriteData ; bank is given in a, sprite input stream is pointed to in wSpriteInputPtr -UncompressSpriteData:: ; 95e (0:95e) ld b, a ldh a, [hROMBank] push af @@ -18,11 +18,11 @@ UncompressSpriteData:: ; 95e (0:95e) call Bankswitch ret -; initializes necessary data to load a sprite and runs UncompressSpriteDataLoop _UncompressSpriteData:: ; 976 (0:976) +; initializes necessary data to load a sprite and runs UncompressSpriteDataLoop ld hl, sSpriteBuffer1 - ld c, (2*SPRITEBUFFERSIZE) % $100 - ld b, (2*SPRITEBUFFERSIZE) / $100 + ld c, (2 * SPRITEBUFFERSIZE) % $100 + ld b, (2 * SPRITEBUFFERSIZE) / $100 xor a call ByteFill ld a, $01 ; next call to ReadNextInputBit will read byte @@ -51,12 +51,12 @@ _UncompressSpriteData:: ; 976 (0:976) ld [wSpriteLoadFlags], a ; initialite bit1 to 0 and bit0 to the first input bit ; this will load two chunks of data to sSpriteBuffer1 and sSpriteBuffer2 ; bit 0 decides in which one the first chunk is placed - ; fall through + ; fallthrough +UncompressSpriteDataLoop:: ; uncompresses a chunk from the sprite input data stream (pointed to at wSpriteInputPtr) into sSpriteBuffer1 or sSpriteBuffer2 ; each chunk is a 1bpp sprite. A 2bpp sprite consist of two chunks which are merged afterwards ; note that this is an endless loop which is terminated during a call to MoveToNextBufferPosition by manipulating the stack -UncompressSpriteDataLoop:: ld hl, sSpriteBuffer1 ld a, [wSpriteLoadFlags] bit 0, a @@ -143,10 +143,10 @@ UncompressSpriteDataLoop:: jr nz, .writeZerosLoop jr .readNextInput +MoveToNextBufferPosition:: ; a34 (0:a34) ; moves output pointer to next position ; also cancels the calling function if the all output is done (by removing the return pointer from stack) ; and calls postprocessing functions according to the unpack mode -MoveToNextBufferPosition:: ; a34 (0:a34) ld a, [wSpriteHeight] ld b, a ld a, [wSpriteCurPosY] @@ -206,8 +206,8 @@ MoveToNextBufferPosition:: ; a34 (0:a34) .done jp UnpackSprite -; writes 2 bits (from a) to the output buffer (pointed to from wSpriteOutputPtr) WriteSpriteBitsToBuffer:: ; aa5 (0:aa5) +; writes 2 bits (from a) to the output buffer (pointed to from wSpriteOutputPtr) ld e, a ld a, [wSpriteOutputBitOffset] and a @@ -234,8 +234,8 @@ WriteSpriteBitsToBuffer:: ; aa5 (0:aa5) ld [hl], a ret -; reads next bit from input stream and returns it in a ReadNextInputBit:: ; acc (0:acc) +; reads next bit from input stream and returns it in a ld a, [wSpriteInputBitCounter] dec a jr nz, .curByteHasMoreBitsToRead @@ -250,8 +250,8 @@ ReadNextInputBit:: ; acc (0:acc) and $01 ret -; reads next byte from input stream and returns it in a ReadNextInputByte: ; ae7 (0:ae7) +; reads next byte from input stream and returns it in a ld a, [wSpriteInputPtr] ld l, a ld a, [wSpriteInputPtr + 1] @@ -265,8 +265,8 @@ ReadNextInputByte: ; ae7 (0:ae7) ld a, b ret -; the nth item is 2^n - 1 LengthEncodingOffsetList:: +; the nth item is 2^n - 1 dw %0000000000000001 dw %0000000000000011 dw %0000000000000111 @@ -284,8 +284,8 @@ LengthEncodingOffsetList:: dw %0111111111111111 dw %1111111111111111 -; unpacks the sprite data depending on the unpack mode UnpackSprite:: ; b1b (0:b1b) +; unpacks the sprite data depending on the unpack mode ld a, [wSpriteUnpackMode] cp $02 jp z, UnpackSpriteMode2 @@ -294,11 +294,11 @@ UnpackSprite:: ; b1b (0:b1b) ld hl, sSpriteBuffer1 call SpriteDifferentialDecode ld hl, sSpriteBuffer2 - ; fall through + ; fallthrough +SpriteDifferentialDecode:: ; decodes differential encoded sprite data ; input bit value 0 preserves the current bit value and input bit value 1 toggles it (starting from initial value 0). -SpriteDifferentialDecode:: xor a ld [wSpriteCurPosX], a ld [wSpriteCurPosY], a @@ -382,8 +382,8 @@ SpriteDifferentialDecode:: ld [wSpriteCurPosY], a ret -; decodes the nybble stored in a. Last decoded data is assumed to be in e (needed to determine if initial value is 0 or 1) DifferentialDecodeNybble:: ; bc9 (0:bc9) +; decodes the nybble stored in a. Last decoded data is assumed to be in e (needed to determine if initial value is 0 or 1) srl a ; c=a%2, a/=2 ld c, $00 jr nc, .evenNumber @@ -462,8 +462,8 @@ DecodeNybble1TableFlipped:: dn $e, $6 dn $2, $a -; combines the two loaded chunks with xor (the chunk loaded second is the destination). The source chunk is differentially decoded beforehand. XorSpriteChunks:: ; c23 (0:c23) +; combines the two loaded chunks with xor (the chunk loaded second is the destination). The source chunk is differentially decoded beforehand. xor a ld [wSpriteCurPosX], a ld [wSpriteCurPosY], a @@ -527,8 +527,8 @@ XorSpriteChunks:: ; c23 (0:c23) ld [wSpriteCurPosX], a ret -; reverses the bits in the nybble given in register a ReverseNybble:: ; c93 (0:c93) +; reverses the bits in the nybble given in register a ld de, NybbleReverseTable add e ld e, a @@ -538,8 +538,8 @@ ReverseNybble:: ; c93 (0:c93) ld a, [de] ret -; resets sprite buffer pointers to buffer 1 and 2, depending on wSpriteLoadFlags ResetSpriteBufferPointers:: ; c9d (0:c9d) +; resets sprite buffer pointers to buffer 1 and 2, depending on wSpriteLoadFlags ld a, [wSpriteLoadFlags] bit 0, a jr nz, .buffer2Selected @@ -564,8 +564,8 @@ ResetSpriteBufferPointers:: ; c9d (0:c9d) NybbleReverseTable:: db $0, $8, $4, $c, $2, $a, $6 ,$e, $1, $9, $5, $d, $3, $b, $7 ,$f -; combines the two loaded chunks with xor (the chunk loaded second is the destination). Both chunks are differentially decoded beforehand. UnpackSpriteMode2:: ; cd3 (0:cd3) +; combines the two loaded chunks with xor (the chunk loaded second is the destination). Both chunks are differentially decoded beforehand. call ResetSpriteBufferPointers ld a, [wSpriteFlipped] push af @@ -581,8 +581,8 @@ UnpackSpriteMode2:: ; cd3 (0:cd3) ld [wSpriteFlipped], a jp XorSpriteChunks -; stores hl into the output pointers StoreSpriteOutputPointer:: ; cf3 (0:cf3) +; stores hl into the output pointers ld a, l ld [wSpriteOutputPtr], a ld [wSpriteOutputPtrCached], a diff --git a/home/pokemon.asm b/home/pokemon.asm index 9b1eec2..35f12e3 100644 --- a/home/pokemon.asm +++ b/home/pokemon.asm @@ -1,10 +1,12 @@ INCLUDE "constants.asm" -SECTION "3A4B", ROM0[$3a4b] + +SECTION "3A4B", ROM0[$3A4B] + +GetMonHeader:: ; 3a4b (0:3a4b) ; copies the base stat data of a pokemon to wMonHeader ; INPUT: ; [wcb5b] = pokemon ID in dex order -GetMonHeader:: ; 3a4b (0:3a4b) push bc push de push hl @@ -25,7 +27,7 @@ GetMonHeader:: ; 3a4b (0:3a4b) jr .done .egg ld de, EggPicFront - ld b, $55 ; egg sprite dimension + ln b, 5, 5 ; egg sprite dimension ld hl, wMonHSpriteDim ld [hl], b ld hl, wMonHFrontSprite @@ -43,12 +45,13 @@ GetMonHeader:: ; 3a4b (0:3a4b) pop bc ret -SECTION "3AED", ROM0[$3aed] +SECTION "3AED", ROM0[$3AED] + +UncompressMonSprite:: ; 3aed (0:3aed) ; Uncompresses the front or back sprite of the specified mon ; assumes the corresponding mon header is already loaded ; hl contains offset to sprite pointer ($b for front or $d for back) -UncompressMonSprite:: ; 3aed (0:3aed) ld a, [wMonDexIndex] and a ret z @@ -96,12 +99,12 @@ UncompressMonSprite:: ; 3aed (0:3aed) ld a, BANK(AnnonPics) jp UncompressSpriteData -; Uncompress Pokémon Front Srite for +LoadMonFrontSprite:: ; 3b3f +; Uncompress Pokémon Front Sprite for ; mon currently loaded in wMonHeader ; to 0x9000 ; de: destination location ; returns the sprite dimension in c -LoadMonFrontSprite:: ; 3b3f push de ld hl, wMonHFrontSprite - wMonHeader call UncompressMonSprite @@ -109,13 +112,13 @@ LoadMonFrontSprite:: ; 3b3f ld a, [hl] ld c, a pop de - ; fall through - + ; fallthrough + +LoadUncompressedSpriteData:: ; 3b4c (0:3b4c) ; postprocesses uncompressed sprite chunks to a 2bpp sprite and loads it into video ram ; calculates alignment parameters to place both sprite chunks in the center of the 7*7 tile sprite buffers ; de: destination location ; a,c: sprite dimensions (in tiles of 8x8 each) -LoadUncompressedSpriteData:: ; 3b4c (0:3b4c) push de and $0f ldh [hSpriteWidth], a ; each byte contains 8 pixels (in 1bpp), so tiles=bytes for width @@ -164,15 +167,15 @@ LoadUncompressedSpriteData:: ; 3b4c (0:3b4c) call InterlaceMergeSpriteBuffers ret -; fills the sprite buffer (pointed to in hl) with zeros ZeroSpriteBuffer:: ; 3ba1 (0:3ba1) +; fills the sprite buffer (pointed to in hl) with zeros ld bc, SPRITEBUFFERSIZE xor a jp ByteFill +AlignSpriteDataCentered:: ; 3ba8 (0:3ba8) ; copies and aligns the sprite data properly inside the sprite buffer ; sprite buffers are 7*7 tiles in size, the loaded sprite is centered within this area -AlignSpriteDataCentered:: ; 3ba8 (0:3ba8) ldh a, [hSpriteOffset] ld c, a ld b, $00 @@ -198,28 +201,28 @@ AlignSpriteDataCentered:: ; 3ba8 (0:3ba8) jr nz, .columnLoop ret +InterlaceMergeSpriteBuffers:: ; 3bc6 (0:3bc6) ; combines the (7*7 tiles, 1bpp) sprite chunks in buffer 0 and 1 into a 2bpp sprite located in buffer 1 through 2 ; in the resulting sprite, the rows of the two source sprites are interlaced ; de: output address -InterlaceMergeSpriteBuffers:: ; 3bc6 (0:3bc6) ld a, $00 call OpenSRAM push de call _InterlaceMergeSpriteBuffers pop hl ld de, sSpriteBuffer1 - ld c, (2*SPRITEBUFFERSIZE)/16 ; $31, number of 16 byte chunks to be copied + ld c, (2 * SPRITEBUFFERSIZE) / 16 ; $31, number of 16 byte chunks to be copied ldh a, [hROMBank] ld b, a call CopyVideoDataOptimized call CloseSRAM ret +_InterlaceMergeSpriteBuffers:: ; 3bdf (0:3bdf) ; actual implementation of InterlaceMergeSpriteBuffers ; sprite flipping is now done during interlace merge loop ; and not as second loop after regular interlace merge ; to save time -_InterlaceMergeSpriteBuffers:: ; 3bdf (0:3bdf) ld a, [wSpriteFlipped] and a jr nz, .flipped @@ -263,7 +266,7 @@ _InterlaceMergeSpriteBuffers:: ; 3bdf (0:3bdf) ld hl, sSpriteBuffer2 + (SPRITEBUFFERSIZE - 1) ; destination: end of buffer 2 ld de, sSpriteBuffer1 + (SPRITEBUFFERSIZE - 1) ; source 2: end of buffer 1 ld bc, sSpriteBuffer0 + (SPRITEBUFFERSIZE - 1) ; source 1: end of buffer 0 - ld a, SPRITEBUFFERSIZE/2 ; $c4 + ld a, SPRITEBUFFERSIZE / 2 ; $c4 ldh [hSpriteInterlaceCounter], a .interlaceLoopFlipped ld a, [de] diff --git a/home/predef.asm b/home/predef.asm index 69620ce..92f8903 100644 --- a/home/predef.asm +++ b/home/predef.asm @@ -3,43 +3,43 @@ INCLUDE "constants.asm" SECTION "Predef", ROM0[$2FDE] Predef:: ; 2fde - ld [wPredefID], a - ldh a, [hROMBank] - push af - ld a, BANK(GetPredefPointer) - call Bankswitch - call GetPredefPointer - call Bankswitch - ld hl, .return - push hl - push de - jr .get_regs + ld [wPredefID], a + ldh a, [hROMBank] + push af + ld a, BANK(GetPredefPointer) + call Bankswitch + call GetPredefPointer + call Bankswitch + ld hl, .return + push hl + push de + jr .get_regs .return - ld a, h - ld [wPredefHL], a - ld a, l - ld [wPredefHL + 1], a - pop hl - ld a, h ; Could have used `pop af` instead - call Bankswitch - ld a, [wPredefHL] - ld h, a - ld a, [wPredefHL + 1] - ld l, a - ret + ld a, h + ld [wPredefHL], a + ld a, l + ld [wPredefHL + 1], a + pop hl + ld a, h ; Could have used `pop af` instead + call Bankswitch + ld a, [wPredefHL] + ld h, a + ld a, [wPredefHL + 1] + ld l, a + ret .get_regs - ld a, [wPredefHL] - ld h, a - ld a, [wPredefHL + 1] - ld l, a - ld a, [wPredefDE] - ld d, a - ld a, [wPredefDE + 1] - ld e, a - ld a, [wPredefBC] - ld b, a - ld a, [wPredefBC + 1] - ld c, a - ret + ld a, [wPredefHL] + ld h, a + ld a, [wPredefHL + 1] + ld l, a + ld a, [wPredefDE] + ld d, a + ld a, [wPredefDE + 1] + ld e, a + ld a, [wPredefBC] + ld b, a + ld a, [wPredefBC + 1] + ld c, a + ret diff --git a/home/serial.asm b/home/serial.asm index 61510b0..48d6832 100644 --- a/home/serial.asm +++ b/home/serial.asm @@ -3,53 +3,52 @@ INCLUDE "constants.asm" SECTION "Serial handler", ROM0[$602] Serial:: - push af - push bc - push de - push hl - ldh a, [hLinkPlayerNumber] - inc a - jr z, .init_player_number + push af + push bc + push de + push hl + ldh a, [hLinkPlayerNumber] + inc a + jr z, .init_player_number - ld a, [rSB] - ldh [hSerialReceive], a - ldh a, [hSerialSend] - ld [rSB], a - ldh a, [hLinkPlayerNumber] - cp 2 - jr z, .done - ld a, 1 << rSC_ON - ld [rSC], a - jr .done + ld a, [rSB] + ldh [hSerialReceive], a + ldh a, [hSerialSend] + ld [rSB], a + ldh a, [hLinkPlayerNumber] + cp 2 + jr z, .done + ld a, 1 << rSC_ON + ld [rSC], a + jr .done .init_player_number - ld a, [rSB] - ldh [hSerialReceive], a - ldh [hLinkPlayerNumber], a - cp 2 - jr z, .master - xor a - ld [rSB], a - ld a, 3 - ld [rDIV], a + ld a, [rSB] + ldh [hSerialReceive], a + ldh [hLinkPlayerNumber], a + cp 2 + jr z, .master + xor a + ld [rSB], a + ld a, 3 + ld [rDIV], a .wait - ld a, [rDIV] - bit 7, a - jr nz, .wait - ld a, 1 << rSC_ON - ld [rSC], a - jr .done + ld a, [rDIV] + bit 7, a + jr nz, .wait + ld a, 1 << rSC_ON + ld [rSC], a + jr .done .master - xor a - ld [rSB], a - + xor a + ld [rSB], a .done - ld a, 1 - ldh [hSerialReceived], a - ld a, SERIAL_NO_DATA_BYTE - ldh [hSerialSend], a - pop hl - pop de - pop bc - pop af - reti + ld a, 1 + ldh [hSerialReceived], a + ld a, SERIAL_NO_DATA_BYTE + ldh [hSerialSend], a + pop hl + pop de + pop bc + pop af + reti diff --git a/home/sram.asm b/home/sram.asm index 5f9cfe2..9c15145 100644 --- a/home/sram.asm +++ b/home/sram.asm @@ -3,19 +3,19 @@ INCLUDE "constants.asm" SECTION "SRAM functions", ROM0[$32A7] OpenSRAM:: ; 32a7 - push af - ld a, 1 - ld [MBC3LatchClock], a - ld a, SRAM_ENABLE - ld [MBC3SRamEnable], a - pop af - ld [MBC3SRamBank], a - ret + push af + ld a, 1 + ld [MBC3LatchClock], a + ld a, SRAM_ENABLE + ld [MBC3SRamEnable], a + pop af + ld [MBC3SRamBank], a + ret CloseSRAM:: ; 32b7 - push af - ld a, SRAM_DISABLE - ld [MBC3LatchClock], a - ld [MBC3SRamEnable], a - pop af - ret + push af + ld a, SRAM_DISABLE + ld [MBC3LatchClock], a + ld [MBC3SRamEnable], a + pop af + ret diff --git a/home/unknown.asm b/home/unknown.asm index e2046e3..de0d21c 100644 --- a/home/unknown.asm +++ b/home/unknown.asm @@ -3,10 +3,10 @@ INCLUDE "constants.asm" SECTION "Empty function", ROM0[$2F97] InexplicablyEmptyFunction:: ; 2f97 -REPT 16 - nop -ENDR - ret +rept 16 + nop +endr + ret ; TODO: @@ -17,20 +17,20 @@ ENDR SECTION "Unknown functions", ROM0[$1FF4] _1FF4:: ; 1ff4 - ld a, BANK(s0_a600) - call OpenSRAM - ld hl, s0_a600 ; TODO: label this. - ld bc, 7 - xor a - call ByteFill - call CloseSRAM - ret + ld a, BANK(s0_a600) + call OpenSRAM + ld hl, s0_a600 ; TODO: label this. + ld bc, 7 + xor a + call ByteFill + call CloseSRAM + ret _2007:: ; 2007 - ld a, BANK(s0_a600) - call OpenSRAM - ld a, [s0_a600] - and 8 - ld [wce5f], a - call CloseSRAM - ret + ld a, BANK(s0_a600) + call OpenSRAM + ld a, [s0_a600] + and 8 + ld [wce5f], a + call CloseSRAM + ret diff --git a/home/vblank.asm b/home/vblank.asm index 8d9fb25..05e9f7b 100644 --- a/home/vblank.asm +++ b/home/vblank.asm @@ -3,29 +3,29 @@ INCLUDE "constants.asm" SECTION "VBlank handler", ROM0[$150] VBlank:: ; 0150 - push af - push bc - push de - push hl - ldh a, [hVBlank] - and 3 - ld e, a - ld d, 0 - ld hl, .blanks - add hl, de - add hl, de - ld a, [hli] - ld h, [hl] - ld l, a - ld de, .return - push de - jp hl + push af + push bc + push de + push hl + ldh a, [hVBlank] + and 3 + ld e, a + ld d, 0 + ld hl, .blanks + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + ld de, .return + push de + jp hl .return - pop hl - pop de - pop bc - pop af - reti + pop hl + pop de + pop bc + pop af + reti .blanks dw VBlank0 @@ -117,7 +117,7 @@ VBlank0:: ; 175 (0:175) VBlank1:: ; 1f6 (0:1f6) ; Simple VBlank -; +; ; scx, scy ; dmg pals ; bg map @@ -297,4 +297,4 @@ VBlank3:: ; 2a0 (0:2a0) ld a, (1 << JOYPAD | 1 << SERIAL | 1 << TIMER | 1 << LCD_STAT | 1 << VBLANK) ldh [rIE], a ret -; 0x317
\ No newline at end of file +; 0x317 diff --git a/home/vcopy.asm b/home/vcopy.asm index bfcaa7c..a453da5 100644 --- a/home/vcopy.asm +++ b/home/vcopy.asm @@ -3,6 +3,7 @@ INCLUDE "vram.asm" SECTION "Copy Routines used by VBlank ISR", ROM0[$123a] +RedrawRowOrColumn:: ; 123a (0:123a) ; This function redraws a BG row of height 2 or a BG column of width 2. ; One of its main uses is redrawing the row or column that will be exposed upon ; scrolling the BG when the player takes a step. Redrawing only the exposed @@ -11,7 +12,6 @@ SECTION "Copy Routines used by VBlank ISR", ROM0[$123a] ; when necessary. It is also used in trade animation and elevator code. ; This also implements the flashlight drawing distance effect, which takes ; multiple frames in either direction to complete -RedrawRowOrColumn:: ; 123a (0:123a) ldh a, [hRedrawRowOrColumnMode] and a ret z @@ -63,8 +63,8 @@ RedrawRowOrColumn:: ; 123a (0:123a) ld a, BG_MAP_WIDTH ; width of VRAM background map add e ld e, a - ; fall through and draw lower half - + ; fallthrough (draw lower half) + .DrawHalf ld c, SCREEN_WIDTH / 2 .row_loop @@ -98,6 +98,7 @@ RedrawRowOrColumn:: ; 123a (0:123a) ld h, [hl] ld l, a jp hl + .flashlight_effect_table dw RedrawFlashlightRow0 ; $1310 dw RedrawFlashlightRow0 ; $1310 @@ -115,7 +116,7 @@ RedrawRowOrColumn:: ; 123a (0:123a) dw RedrawFlashlightRow3 ; $134E dw RedrawFlashlightColumn3 ; $1301 dw RedrawFlashlightColumn3 ; $1301 - + RedrawFlashlightColumn0:: ; 12c3 (0:12c3) ldh a, [hSCX] and $07 @@ -384,8 +385,8 @@ AutoBgMapTransfer:: ; 13ee (0:13ee) .doTransfer ldh [hBGMapTransferPosition], a ld a, $06 ; 6 rows of SCREEN_WIDTH each - ; fall through - + ; fallthrough + TransferBgRows:: ; 1430 (0:1430) ld bc, BG_MAP_WIDTH - SCREEN_WIDTH + 1 .loop @@ -397,7 +398,7 @@ TransferBgRows:: ; 1430 (0:1430) ld [hl], d inc l endr - + pop de ld [hl], e inc l @@ -412,6 +413,7 @@ TransferBgRows:: ; 1430 (0:1430) ld sp, hl ret +VBlankCopyDouble:: ; 1470 (0:1470) ; Copy [wVBCopyDoubleSize] 1bpp tiles ; from wVBCopyDoubleSrc to wVBCopyDoubleDst. ; wVBCopyDoubleDst must be aligned to 0x10 bytes. @@ -419,7 +421,6 @@ TransferBgRows:: ; 1430 (0:1430) ; While we're here, convert to 2bpp. ; The process is straightforward: ; copy each byte twice. -VBlankCopyDouble:: ; 1470 (0:1470) ld a, [wVBCopyDoubleSize] and a ret z @@ -439,7 +440,7 @@ VBlankCopyDouble:: ; 1470 (0:1470) ld [wVBCopyDoubleSize], a .loop - rept 16/4 - 1 ; 16 bytes per 2bpp tile at 2 bytes per pop + rept 16/4 - 1 ; 16 bytes per 2bpp tile at 2 bytes per pop pop de ; copied twice minus last block ld [hl], e inc l @@ -450,7 +451,7 @@ VBlankCopyDouble:: ; 1470 (0:1470) ld [hl], d inc l endr - + pop de ld [hl], e inc l @@ -474,13 +475,13 @@ VBlankCopyDouble:: ; 1470 (0:1470) ld sp, hl ret +VBlankCopy:: ; 14c7 (0:14c7) ; Copy 16 * [wVBCopySize] bytes ; from wVBCopySrc to wVBCopyDst. ; wVBCopyDst must be aligned to 0x10 bytes. ; Source and destination addresses are updated, ; so transfer can continue in subsequent calls. -VBlankCopy:: ; 14c7 (0:14c7) ld a, [wVBCopySize] and a ret z @@ -561,13 +562,13 @@ Function_1538: ; 1538 (0:1538) ld a, $01 jp TransferBgRows +VBlankCopyFar:: ; 1558 (0:1558) ; Copy 0x10 * [wVBCopyFarSize] bytes ; from wVBCopyFarSrcBank::wVBCopyFarSrc to wVBCopyFarDst. ; wVBCopyFarDst must be aligned to 0x10 bytes. ; Source and destination addresses are updated, ; so transfer can continue in subsequent calls. -VBlankCopyFar:: ; 1558 (0:1558) ld a, [wVBCopyFarSize] and a ret z @@ -595,7 +596,7 @@ VBlankCopyFar:: ; 1558 (0:1558) ld [hl], d inc l endr - + pop de ld [hl], e inc l |