Skip to content

Commit

Permalink
Organize home and macro code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Nov 5, 2020
1 parent ed03fc4 commit 6fe56af
Show file tree
Hide file tree
Showing 36 changed files with 131 additions and 152 deletions.
2 changes: 1 addition & 1 deletion audio.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion audio/music/meetjessiejames.asm
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,3 @@ Music_MeetJessieJames_branch_83235::
note E_, 1
rest 1
sound_loop 0, Music_MeetJessieJames_branch_83235
sound_ret
12 changes: 0 additions & 12 deletions constants/gfx_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions constants/palette_constants.asm
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 4 additions & 4 deletions engine/battle/animations.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -91,18 +91,18 @@ 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
ld a, [hli] ; flags
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
Expand Down
2 changes: 1 addition & 1 deletion engine/battle/core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions engine/battle/effects.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion engine/gfx/sprite_oam.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion engine/items/inventory.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions engine/menus/pokedex.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion engine/movie/intro.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion engine/overworld/map_sprites.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion engine/overworld/specific_script_flags.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SetMapSpecificScriptFlagsOnMapReload::
ld a, [hli]
cp c
jr z, .in_list
cp a, $ff
cp $ff
jr nz, .search_loop
ret

Expand Down
2 changes: 1 addition & 1 deletion engine/pikachu/pikachu_pic_animation.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions engine/printer/printer2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
Binary file renamed audio/unknown_832b9.bin → garbage/bank20.bin
100755 → 100644
Binary file not shown.
1 change: 1 addition & 0 deletions home.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions home/cgb_palettes.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion home/hidden_objects.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion home/item_price.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions home/joypad.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Joypad::
homecall_jump _Joypad
homejp _Joypad

ReadJoypad::
homecall_jump ReadJoypad_
homejp ReadJoypad_
29 changes: 16 additions & 13 deletions home/overworld.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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::
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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?

Expand Down
Loading

0 comments on commit 6fe56af

Please sign in to comment.