Organize home and macro code

This commit is contained in:
Rangi 2020-11-05 10:51:02 -05:00
parent ed03fc4f4a
commit 6fe56af2cd
36 changed files with 133 additions and 154 deletions

View File

@ -539,7 +539,7 @@ INCLUDE "audio/music/surfingpikachu.asm"
INCLUDE "audio/music/yellowunusedsong.asm"
INCLUDE "audio/music/meetjessiejames.asm"
INCBIN "audio/unknown_832b9.bin"
INCBIN "garbage/bank20.bin"
; Pikachu cries are in different banks

View File

@ -306,4 +306,3 @@ Music_MeetJessieJames_branch_83235::
note E_, 1
rest 1
sound_loop 0, Music_MeetJessieJames_branch_83235
sound_ret

View File

@ -2,18 +2,6 @@ TILE_WIDTH EQU 8 ; pixels
LEN_1BPP_TILE EQU 1 * TILE_WIDTH ; bytes
LEN_2BPP_TILE EQU 2 * TILE_WIDTH ; bytes
const_def
const SHADE_WHITE ; %00
const SHADE_LIGHT ; %01
const SHADE_DARK ; %10
const SHADE_BLACK ; %11
NUM_PAL_COLORS EQU const_value
PAL_COLOR_SIZE EQU 2
PALETTE_SIZE EQU NUM_PAL_COLORS * PAL_COLOR_SIZE
NUM_ACTIVE_PALS EQU 4
SCREEN_WIDTH EQU 20
SCREEN_HEIGHT EQU 18
SCREEN_WIDTH_PX EQU SCREEN_WIDTH * TILE_WIDTH ; pixels

View File

@ -1,9 +1,15 @@
; monochrome palette color ids
const_def
const WHITE
const LIGHT_GRAY
const DARK_GRAY
const BLACK
const SHADE_WHITE ; %00
const SHADE_LIGHT ; %01
const SHADE_DARK ; %10
const SHADE_BLACK ; %11
NUM_PAL_COLORS EQU const_value
PAL_COLOR_SIZE EQU 2
PALETTE_SIZE EQU NUM_PAL_COLORS * PAL_COLOR_SIZE
NUM_ACTIVE_PALS EQU 4
; pal/blk packets
; SetPalFunctions indexes (see engine/gfx/palettes.asm)

View File

@ -57,7 +57,7 @@ DrawFrameBlock:
inc hl
inc de
ld a, [hli]
add a, $31 ; base tile ID for battle animations
add $31 ; base tile ID for battle animations
ld [de], a ; store tile ID
inc de
ld a, [hli]
@ -91,7 +91,7 @@ DrawFrameBlock:
inc hl
inc de
ld a, [hli]
add a, $31 ; base tile ID for battle animations
add $31 ; base tile ID for battle animations
ld [de], a ; store tile ID
inc de
; toggle horizontal and vertical flip
@ -99,10 +99,10 @@ DrawFrameBlock:
and a
ld b, OAM_VFLIP | OAM_HFLIP
jr z, .storeFlags1
cp a, OAM_HFLIP
cp OAM_HFLIP
ld b, OAM_VFLIP
jr z, .storeFlags1
cp a, OAM_VFLIP
cp OAM_VFLIP
ld b, OAM_HFLIP
jr z, .storeFlags1
ld b, 0

View File

@ -902,7 +902,7 @@ ReplaceFaintedEnemyMon:
ld hl, wEnemyHPBarColor
ld e, $30
call GetBattleHealthBarColor
setpal SHADE_BLACK, SHADE_DARK, SHADE_LIGHT, SHADE_WHITE
ldpal a, SHADE_BLACK, SHADE_DARK, SHADE_LIGHT, SHADE_WHITE
ldh [rOBP0], a
ldh [rOBP1], a
call UpdateGBCPal_OBP0

View File

@ -231,7 +231,7 @@ FreezeBurnParalyzeEffect:
ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance
jr .next1
.asm_3f2c7
cp a, PARALYZE_SIDE_EFFECT1 + 1 ; 10% status effects are 04, 05, 06 so 07 will set carry for those
cp PARALYZE_SIDE_EFFECT1 + 1 ; 10% status effects are 04, 05, 06 so 07 will set carry for those
ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance
jr c, .next1 ; branch ahead if this is a 10% chance effect..
ld b, $4d ; else use 0x4D/0x100 or 77/256 = 30.1%~ chance
@ -293,7 +293,7 @@ FreezeBurnParalyzeEffect:
ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance
jr .next2
.asm_3f341
cp a, PARALYZE_SIDE_EFFECT1 + 1
cp PARALYZE_SIDE_EFFECT1 + 1
ld b, $1a
jr c, .next2
ld b, $4d

View File

@ -219,7 +219,7 @@ _IsTilePassable::
ld l, a ; hl now points to passable tiles
.loop
ld a, [hli]
cp a, $ff
cp $ff
jr z, .tileNotPassable
cp c
jr nz, .loop

View File

@ -36,7 +36,7 @@ AddItemToInventory_::
inc hl
.loop
ld a, [hl]
cp a, $ff ; is it the end of the table?
cp $ff ; is it the end of the table?
jr nz, .notAtEndOfInventory
.addNewItem ; add an item not yet in the inventory
pop hl

View File

@ -205,9 +205,9 @@ HandlePokedexListMenu:
jr z, .checkIfRightPressed
.downPressed ; scroll down one row
ld a, [wDexMaxSeenMon]
cp a, 7
cp 7
jp c, .loop ; can't if the list is shorter than 7
sub a, 7
sub 7
ld b, a
ld a, [wListScrollOffset]
cp b
@ -221,12 +221,12 @@ HandlePokedexListMenu:
jr z, .checkIfLeftPressed
.rightPressed ; scroll down 7 rows
ld a, [wDexMaxSeenMon]
cp a, 7
cp 7
jp c, .loop ; can't if the list is shorter than 7
sub a, 6
sub 6
ld b, a
ld a, [wListScrollOffset]
add a, 7
add 7
ld [wListScrollOffset], a
cp b
jp c, .loop
@ -240,7 +240,7 @@ HandlePokedexListMenu:
jr z, .buttonAPressed
.leftPressed
ld a, [wListScrollOffset]
sub a, 7
sub 7
ld [wListScrollOffset], a
jp nc, .loop
xor a
@ -324,7 +324,7 @@ DrawPokedexVerticalLine:
.loop
ld [hl], a
add hl, de
xor a, 1 ; toggle between vertical line tile and box tile
xor 1 ; toggle between vertical line tile and box tile
dec c
jr nz, .loop
ret
@ -459,7 +459,7 @@ ShowPokedexDataInternal:
.waitForButtonPress
call JoypadLowSensitivity
ldh a, [hJoy5]
and a, A_BUTTON | B_BUTTON
and A_BUTTON | B_BUTTON
jr z, .waitForButtonPress
pop af
ldh [hTilesetType], a

View File

@ -83,7 +83,7 @@ PlayShootingStar:
ld b, SET_PAL_GAME_FREAK_INTRO
call RunPaletteCommand
farcall LoadCopyrightAndTextBoxTiles
ldPal a, BLACK, DARK_GRAY, LIGHT_GRAY, WHITE
ldpal a, SHADE_BLACK, SHADE_DARK, SHADE_LIGHT, SHADE_WHITE
ldh [rBGP], a
call UpdateGBCPal_BGP
ld c, 180

View File

@ -304,7 +304,7 @@ GetSplitMapSpriteSetID:
ld hl, MapSpriteSets
add hl, de
ld a, [hl] ; a = spriteSetID
cp a, $f0 ; does the map have 2 sprite sets?
cp $f0 ; does the map have 2 sprite sets?
ret c
; Chooses the correct sprite set ID depending on the player's position within
; the map for maps with two sprite sets.

View File

@ -8,7 +8,7 @@ SetMapSpecificScriptFlagsOnMapReload::
ld a, [hli]
cp c
jr z, .in_list
cp a, $ff
cp $ff
jr nz, .search_loop
ret

View File

@ -625,7 +625,7 @@ PikaPicAnimCommand_loadgfx:
ld a, [wPikaPicAnimCurGraphicID]
call LoadPikaPicAnimGFXHeader
ld a, c
cp a, $ff
cp $ff
jr z, .compressed
call RequestPikaPicAnimGFX
jr .done

View File

@ -356,7 +356,7 @@ Func_ea6af:
ld hl, wPrinterSerialFrameDelay
inc [hl]
ld a, [hl]
cp a, $6
cp $6
ret c
xor a
ld [hl], a
@ -381,17 +381,17 @@ Func_ea6d2:
call Func_ea742
ret c
ld a, [wPrinterHandshake]
cp a, $ff
cp $ff
jr nz, .asm_ea6e4
ld a, [wPrinterStatusFlags]
cp a, $ff
cp $ff
jr z, .asm_ea6fb
.asm_ea6e4
ld a, [wPrinterHandshake]
cp a, $81
cp $81
jr nz, .asm_ea6fb
ld a, [wPrinterStatusFlags]
cp a, $0
cp $0
jr nz, .asm_ea6fb
ld hl, wPrinterConnectionOpen
set 1, [hl]

BIN
audio/unknown_832b9.bin → garbage/bank20.bin Executable file → Normal file

Binary file not shown.

View File

@ -50,6 +50,7 @@ INCLUDE "home/inventory.asm"
INCLUDE "home/list_menu.asm"
INCLUDE "home/names.asm"
INCLUDE "home/reload_tiles.asm"
INCLUDE "home/printer.asm"
INCLUDE "home/item.asm"
INCLUDE "home/textbox.asm"
INCLUDE "home/cgb_palettes.asm"

View File

@ -74,8 +74,12 @@ Func_3082::
ldh a, [hLoadedROMBank]
push af
call FadeOutAudio
callbs Music_DoLowHealthAlarm
callbs Audio1_UpdateMusic
ld a, BANK(Music_DoLowHealthAlarm)
call BankswitchCommon
call Music_DoLowHealthAlarm
ld a, BANK(Audio1_UpdateMusic)
call BankswitchCommon
call Audio1_UpdateMusic
pop af
call BankswitchCommon
ret

View File

@ -9,7 +9,9 @@ CheckForHiddenObjectOrBookshelfOrCardKeyDoor::
bit 0, a ; A button
jr z, .nothingFound
; A button is pressed
callbs CheckForHiddenObject
ld a, BANK(CheckForHiddenObject)
call BankswitchCommon
call CheckForHiddenObject
ldh a, [hDidntFindAnyHiddenObject]
and a
jr nz, .hiddenObjectNotFound

View File

@ -31,7 +31,9 @@ GetItemPrice::
ldh [hItemPrice], a
jr .done
.getTMPrice
callbs GetMachinePrice
ld a, BANK(GetMachinePrice)
call BankswitchCommon
call GetMachinePrice
.done
ld de, hItemPrice
pop af

View File

@ -1,5 +1,5 @@
Joypad::
homecall_jump _Joypad
homejp _Joypad
ReadJoypad::
homecall_jump ReadJoypad_
homejp ReadJoypad_

View File

@ -743,7 +743,8 @@ HandleBlackOut::
call StopMusic
ld hl, wd72e
res 5, [hl]
switchbank SpecialWarpIn ; also Bank(SpecialEnterMap)
ld a, BANK(SpecialWarpIn) ; also BANK(SpecialEnterMap)
call BankswitchCommon
callfar ResetStatusAndHalveMoneyOnBlackout
call SpecialWarpIn
call PlayDefaultMusicFadeOutCurrent
@ -770,7 +771,9 @@ HandleFlyWarpOrDungeonWarp::
res 5, [hl] ; forced to ride bike
call LeaveMapAnim
call Func_07c4
callbs SpecialWarpIn
ld a, BANK(SpecialWarpIn)
call BankswitchCommon
call SpecialWarpIn
jp SpecialEnterMap
LeaveMapAnim::
@ -1439,9 +1442,7 @@ AdvancePlayerSprite::
push af
ld a, $FF
ld [wUpdateSpritesEnabled], a
ld hl, _AdvancePlayerSprite
ld b, BANK(_AdvancePlayerSprite)
call Bankswitch
callfar _AdvancePlayerSprite
pop af
ld [wUpdateSpritesEnabled], a
ret
@ -1914,7 +1915,8 @@ asm_0dbd:
ld b, $00
ldh a, [hLoadedROMBank]
push af
switchbank MapSongBanks
ld a, BANK(MapSongBanks)
call BankswitchCommon
ld hl, MapSongBanks
add hl, bc
add hl, bc
@ -2041,16 +2043,16 @@ CopyMapViewToVRAM::
ld de, vBGMap0
CopyMapViewToVRAM2:
ld hl, wTileMap
ld b, 18
ld b, SCREEN_HEIGHT
.vramCopyLoop
ld c, 20
ld c, SCREEN_WIDTH
.vramCopyInnerLoop
ld a, [hli]
ld [de], a
inc e
dec c
jr nz, .vramCopyInnerLoop
ld a, 32 - 20 ; total vram map width in tiles - screen width in tiles
ld a, BG_MAP_WIDTH - SCREEN_WIDTH
add e
ld e, a
jr nc, .noCarry
@ -2068,11 +2070,11 @@ SwitchToMapRomBank::
ld c, a
ld b, $00
ld a, BANK(MapHeaderBanks)
call BankswitchHome ; switch to ROM bank 3F
call BankswitchHome
ld hl, MapHeaderBanks
add hl, bc
ld a, [hl]
ldh [hMapROMBank], a ; save map ROM bank
ldh [hMapROMBank], a
call BankswitchBack
ldh a, [hMapROMBank]
call BankswitchCommon
@ -2083,7 +2085,8 @@ SwitchToMapRomBank::
GetMapHeaderPointer::
ldh a, [hLoadedROMBank]
push af
switchbank MapHeaderPointers
ld a, BANK(MapHeaderPointers)
call BankswitchCommon
push de
ld a, [wCurMap]
ld e, a
@ -2114,7 +2117,7 @@ ResetUsingStrengthOutOfBattleBit:
ForceBikeOrSurf::
ld b, BANK(RedSprite)
ld hl, LoadPlayerSpriteGraphics
ld hl, LoadPlayerSpriteGraphics ; in bank 0
call Bankswitch
jp PlayDefaultMusic ; update map/player state?

View File

@ -18,10 +18,6 @@ UncompressMonSprite::
; $99 ≤ index, bank $D
ld a, [wcf91] ; XXX name for this ram location
ld b, a
;cp MEW
;ld a, BANK(MewPicFront)
;jr z, .GotBank
;ld a, b
cp FOSSIL_KABUTOPS
ld a, BANK(FossilKabutopsPic)
jr z, .GotBank

View File

@ -108,7 +108,9 @@ ApplyPikachuMovementData::
ldh a, [hLoadedROMBank]
ld b, a
push af
callbs ApplyPikachuMovementData_
ld a, BANK(ApplyPikachuMovementData_)
call BankswitchCommon
call ApplyPikachuMovementData_
pop af
call BankswitchCommon
ret

View File

@ -5,7 +5,6 @@ DrawHPBar::
push hl
push de
;push bc
; Left
ld a, $71 ; "HP:"
@ -61,7 +60,6 @@ DrawHPBar::
add e
ld [hl], a
.done
;pop bc
pop de
pop hl
ret
@ -124,7 +122,8 @@ LoadFrontSpriteByMonIndex::
pop hl
ldh a, [hLoadedROMBank]
push af
switchbank CopyUncompressedPicToHL
ld a, BANK(CopyUncompressedPicToHL)
call BankswitchCommon
xor a
ldh [hStartTileID], a
call CopyUncompressedPicToHL
@ -355,7 +354,7 @@ PrintStatusCondition::
ret
PrintStatusConditionNotFainted::
homecall_jump_sf PrintStatusAilment
homejp_sf PrintStatusAilment
; function to print pokemon level, leaving off the ":L" if the level is at least 100
; INPUT:
@ -404,7 +403,8 @@ GetwMoves::
GetMonHeader::
ldh a, [hLoadedROMBank]
push af
switchbank BaseStats
ld a, BANK(BaseStats)
call BankswitchCommon
push bc
push de
push hl
@ -423,8 +423,6 @@ GetMonHeader::
ld b, $77 ; size of Aerodactyl fossil sprite
cp FOSSIL_AERODACTYL ; Aerodactyl fossil
jr z, .specialID
;cp MEW
;jr z, .mew
predef IndexToPokedex ; convert pokemon ID in [wd11e] to pokedex number
ld a, [wd11e]
dec a

34
home/printer.asm Normal file
View File

@ -0,0 +1,34 @@
PrinterSerial::
homecall PrinterSerial_
ret
SerialFunction::
ld a, [wPrinterConnectionOpen]
bit 0, a
ret z
ld a, [wPrinterOpcode]
and a
ret nz
ld hl, wOverworldMap + 650
inc [hl]
ld a, [hl]
cp $6
ret c
xor a
ld [hl], a
ld a, $0c
ld [wPrinterOpcode], a
ld a, $88
ldh [rSB], a
ld a, $1
ldh [rSC], a
ld a, START_TRANSFER_INTERNAL_CLOCK
ldh [rSC], a
ret
; causes the text box to close without waiting for a button press after displaying text
DisableWaitingAfterTextDisplay::
ld a, $01
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
ret

View File

@ -31,37 +31,3 @@ ChooseFlyDestination::
ld hl, wd72e
res 4, [hl]
farjp LoadTownMap_Fly
PrinterSerial::
homecall PrinterSerial_
ret
SerialFunction::
ld a, [wPrinterConnectionOpen]
bit 0, a
ret z
ld a, [wPrinterOpcode]
and a
ret nz
ld hl, wOverworldMap + 650
inc [hl]
ld a, [hl]
cp $6
ret c
xor a
ld [hl], a
ld a, $0c
ld [wPrinterOpcode], a
ld a, $88
ldh [rSB], a
ld a, $1
ldh [rSC], a
ld a, START_TRANSFER_INTERNAL_CLOCK
ldh [rSC], a
ret
; causes the text box to close without waiting for a button press after displaying text
DisableWaitingAfterTextDisplay::
ld a, $01
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
ret

View File

@ -4,7 +4,7 @@ _Start::
xor a
jr .ok
.gbc
ld a, 1
ld a, TRUE
.ok
ldh [hGBC], a
jp Init

View File

@ -1,5 +1,6 @@
DisplayStartMenu::
switchbank StartMenu_Pokedex ; also bank for other functions
ld a, BANK(StartMenu_Pokedex) ; also bank for other functions
call BankswitchCommon
ld a, [wWalkBikeSurfState] ; walking/biking/surfing
ld [wWalkBikeSurfStateCopy], a
ld a, SFX_START_MENU

View File

@ -554,8 +554,8 @@ TextCommandSounds::
db TX_SOUND_GET_KEY_ITEM, SFX_GET_KEY_ITEM
db TX_SOUND_DEX_PAGE_ADDED, SFX_DEX_PAGE_ADDED
db TX_SOUND_CRY_PIKACHU, PIKACHU ; used in OakSpeech
db TX_SOUND_CRY_PIDGEOT, PIDGEOT ; used in SaffronCityText12
db TX_SOUND_CRY_DEWGONG, DEWGONG ; unused
db TX_SOUND_CRY_PIDGEOT, PIDGEOT ; used in SaffronCityText12
db TX_SOUND_CRY_DEWGONG, DEWGONG ; unused
TextCommand_DOTS::
; wait for button press or 30 frames while printing "…"s

View File

@ -41,17 +41,12 @@ DisplayTextID::
.spriteHandling
; get the text ID of the sprite
push hl
;push de
;push bc
;farcall UpdateSpriteFacingOffsetAndDelayMovement ; update the graphics of the sprite the player is talking to (to face the right direction)
;pop bc
;pop de
ld hl, wMapSpriteData ; NPC text entries
ldh a, [hSpriteIndexOrTextID]
dec a
add a
ld e, a
ld d, $0
ld d, 0
add hl, de
inc hl
ld a, [hl] ; a = text ID of the sprite
@ -60,7 +55,7 @@ DisplayTextID::
; look up the address of the text in the map's text entries
dec a
ld e, a
ld d, $0
ld d, 0
add hl, de
add hl, de
ld a, [hli]

View File

@ -4,7 +4,8 @@ UpdateSprites::
ret nz
ldh a, [hLoadedROMBank]
push af
switchbank _UpdateSprites
ld a, BANK(_UpdateSprites)
call BankswitchCommon
ld a, $ff
ld [wUpdateSpritesEnabled], a
call _UpdateSprites

View File

@ -59,8 +59,12 @@ VBlank::
.skipDec
call FadeOutAudio
callbs Music_DoLowHealthAlarm
callbs Audio1_UpdateMusic
ld a, BANK(Music_DoLowHealthAlarm)
call BankswitchCommon
call Music_DoLowHealthAlarm
ld a, BANK(Audio1_UpdateMusic)
call BankswitchCommon
call Audio1_UpdateMusic
call SerialFunction

View File

@ -4,7 +4,7 @@ lb: MACRO ; r, hi, lo
ld \1, ((\2) & $ff) << 8 + ((\3) & $ff)
ENDM
ldPal: MACRO
ldpal: MACRO
ld \1, \2 << 6 | \3 << 4 | \4 << 2 | \5
ENDM

View File

@ -32,7 +32,7 @@ homecall: MACRO
call BankswitchCommon
ENDM
homecall_jump: MACRO
homejp: MACRO
ldh a, [hLoadedROMBank]
push af
ld a, BANK(\1)
@ -42,17 +42,6 @@ homecall_jump: MACRO
jp BankswitchCommon
ENDM
homecall_jump_sf: MACRO
ldh a, [hLoadedROMBank]
push af
ld a, BANK(\1)
call BankswitchCommon
call \1
pop bc
ld a, b
jp BankswitchCommon
ENDM
homecall_sf: MACRO ; homecall but save flags by popping into bc instead of af
ldh a, [hLoadedROMBank]
push af
@ -64,15 +53,15 @@ homecall_sf: MACRO ; homecall but save flags by popping into bc instead of af
call BankswitchCommon
ENDM
switchbank: MACRO
ld a, BANK(\1)
call BankswitchCommon
ENDM
callbs: MACRO
homejp_sf: MACRO ; homejp but save flags by popping into bc instead of af
ldh a, [hLoadedROMBank]
push af
ld a, BANK(\1)
call BankswitchCommon
call \1
pop bc
ld a, b
jp BankswitchCommon
ENDM
calladb_ModifyPikachuHappiness: MACRO

View File

@ -16,18 +16,6 @@ color EQUS "+ PAL_COLOR_SIZE *"
tiles EQUS "* LEN_2BPP_TILE"
tile EQUS "+ LEN_2BPP_TILE *"
setpal: MACRO
ld a, \1 << 6 | \2 << 4 | \3 << 2 | \4
ENDM
setpalBGP: MACRO
setpal SHADE_BLACK, SHADE_DARK, SHADE_LIGHT, SHADE_WHITE
ENDM
setpalOBP: MACRO
setpal SHADE_BLACK, SHADE_DARK, SHADE_WHITE, SHADE_WHITE
ENDM
dbsprite: MACRO
; x tile, y tile, x pixel, y pixel, vtile offset, attributes
db (\2 * TILE_WIDTH) % $100 + \4, (\1 * TILE_WIDTH) % $100 + \3, \5, \6