Split bank20 into logical asm files (finally!)

This commit is contained in:
Electro 2026-02-06 17:06:23 +00:00
parent 696a23964f
commit bdb0a2aef6
26 changed files with 1660 additions and 1617 deletions

View File

@ -26,3 +26,12 @@ DEF ICON_TILE_FIGHTING EQU $f0
DEF ICON_TILE_PSYCHIC EQU $f4
DEF ICON_TILE_COLORLESS EQU $f8
DEF ICON_TILE_ENERGY EQU $fc
; graphics table constants
; (see src/engine/gfx/gfx_table_pointers.asm)
RSRESET
DEF GFXTABLE_TILEMAPS RW ; $0
DEF GFXTABLE_TILESETS RW ; $2
DEF GFXTABLE_SPRITES RW ; $4
DEF GFXTABLE_SPRITE_ANIMATIONS RW ; $6
DEF GFXTABLE_PALETTES RW ; $8

View File

@ -1,9 +1,9 @@
; palette data are read by LoadPaletteData, expected to be structured as so:
; palette data are read by LoadOBPalette, expected to be structured as so:
; the first byte has possible values of 0, 1 or 2
; - if 0, nothing is done;
; - if 1, then the next byte is written to OBP0 (or to OBP1 if wd4ca == $1);
; - if 1, then the next byte is written to OBP0 (or to OBP1 if wWhichOBP == $1);
; - if 2, then the next 2 bytes are written to OBP0 and OBP1 respectively
; (or only the first written to OBP1 if wd4ca == $1, skipping the second byte)
; (or only the first written to OBP1 if wWhichOBP == $1, skipping the second byte)
; next there is a byte declaring the size of the palette data
; indicating the number of palettes

File diff suppressed because it is too large Load Diff

View File

@ -122,13 +122,12 @@ PlayLoadedDuelAnimation::
ld [wAnimationQueue], a ; push an animation to the queue
xor a
ld [wVRAMTileOffset], a
ld [wd4cb], a
ld [wWhichOBP], a ; OBP0
ld [wWhichOBPalIndex], a ; palette index 0
ld a, [hli] ; ANIM_PALETTE_ID
farcall LoadPaletteData
ld a, [hli] ; ANIM_SPRITE_ANIM_ID
farcall LoadOBPalette
ld a, [hli] ; ANIM_SPRITE_ANIM_ID
push af
ld a, [hli] ; ANIM_SPRITE_ANIM_FLAGS
ld [wAnimFlags], a
@ -498,11 +497,10 @@ Func_1cb5e:
xor a
ld [wDamageCharAnimDelay], a
ld [wVRAMTileOffset], a
ld [wd4cb], a
ld [wWhichOBP], a ; OBP0
ld [wWhichOBPalIndex], a ; palette index 0
ld a, PALETTE_37
farcall LoadPaletteData
farcall LoadOBPalette
call DrawDamageAnimationNumbers
ld hl, wDuelAnimEffectiveness

262
src/engine/gfx/debug.asm Normal file
View File

@ -0,0 +1,262 @@
ret ; stray ret
Func_80c64: ; unreferenced
ld a, [wLineSeparation]
push af
ld a, SINGLE_SPACED
ld [wLineSeparation], a
; load opponent's name
ld a, [wOpponentName]
ld [wTxRam2], a
ld a, [wOpponentName + 1]
ld [wTxRam2 + 1], a
ld a, [wNPCDuelistCopy]
ld [wTxRam3_b], a
xor a
ld [wTxRam3_b + 1], a
; load number of duel prizes
ld a, [wNPCDuelPrizes]
ld [wTxRam3], a
xor a
ld [wTxRam3 + 1], a
lb de, 2, 13
call InitTextPrinting
ldtx hl, WinLosePrizesDuelWithText
call PrintTextNoDelay
ld a, [wNPCDuelDeckID]
ld [wTxRam3], a
xor a
ld [wTxRam3 + 1], a
lb de, 2, 15
call InitTextPrinting
ldtx hl, UseDuelistsDeckText
call PrintTextNoDelay
pop af
ld [wLineSeparation], a
xor a
ld hl, .menu_parameters
call InitializeMenuParameters
ret
.menu_parameters
db 1, 13 ; cursor x, cursor y
db 1 ; y displacement between items
db 2 ; number of items
db SYM_CURSOR_R ; cursor tile number
db SYM_SPACE ; tile behind cursor
dw NULL ; function pointer if non-0
; fills Tiles0 with random bytes
UnreferencedFillVRAMWithRandomData: ; unreferenced
call DisableLCD
ld hl, v0Tiles0
ld bc, $800
.loop
call UpdateRNGSources
ld [hli], a
dec bc
ld a, b
or c
jr nz, .loop
ret
_DebugVEffect:
ret
; seems to be used to look at each OW NPC sprites
; with functions to rotate NPC and animate them
_DebugLookAtSprite:
call DisableLCD
call EmptyScreen
call ClearSpriteAnimations
xor a
ld [wWhichOBP], a ; not used
ld [wWhichBGPalIndex], a ; palette index 0
ld a, PALETTE_0
farcall LoadBGPalette
xor a
ld [wWhichOBP], a ; OBP0
ld [wWhichOBPalIndex], a ; palette index 0
ld a, PALETTE_29
farcall LoadOBPalette
ld a, SOUTH
ld [wLoadNPCDirection], a
ld a, $01
ld [wLoadedNPCTempIndex], a
call .DrawNPCSprite
call .PrintNPCInfo
call EnableLCD
.loop
call DoFrameIfLCDEnabled
call .HandleInput
call HandleAllSpriteAnimations
ldh a, [hKeysPressed]
and PAD_SELECT ; if select is pressed, exit
jr z, .loop
ret
ret ; stray ret
; A button makes NPC rotate
; D-pad scrolls through the NPCs
; from $01 to $2c
; these are not aligned with the regular NPC indices
.HandleInput
ldh a, [hKeysPressed]
and PAD_A
jr z, .no_a_button
ld a, [wLoadNPCDirection]
inc a ; rotate NPC
and %11
ld [wLoadNPCDirection], a
call ClearSpriteAnimations
call .DrawNPCSprite
.no_a_button
ldh a, [hKeysPressed]
and PAD_CTRL_PAD
ret z
farcall GetDirectionFromDPad
ld hl, .func_table
jp JumpToFunctionInTable
.func_table
dw .up ; PAD_UP
dw .right ; PAD_RIGHT
dw .down ; PAD_DOWN
dw .left ; PAD_LEFT
.up
ld a, 10
jr .decr_npc_id
.down
ld a, 10
jr .incr_npc_id
.right
ld a, 1
jr .incr_npc_id
.left
ld a, 1
jr .decr_npc_id
.incr_npc_id
ld c, a
ld a, [wLoadedNPCTempIndex]
cp $2c
jr z, .load_first_npc
add c
jr c, .load_last_npc
cp $2c
jr nc, .load_last_npc
jr .got_npc
.decr_npc_id
ld c, a
ld a, [wLoadedNPCTempIndex]
cp $01
jr z, .load_last_npc
sub c
jr c, .load_first_npc
cp $01
jr c, .load_first_npc
jr .got_npc
.load_first_npc
ld a, $01
jr .got_npc
.load_last_npc
ld a, $2c
.got_npc
ld [wLoadedNPCTempIndex], a
call ClearSpriteAnimations
call .DrawNPCSprite
jr .PrintNPCInfo
.PrintNPCInfo
lb de, 0, 4
call InitTextPrinting
ldtx hl, SPRText
call ProcessTextFromID
ld bc, FlushAllPalettes
ld a, [wLoadedNPCTempIndex]
farcall WriteTwoByteNumberInTxSymbolFormat
ret
.DrawNPCSprite
ld a, [wLoadedNPCTempIndex]
ld c, a
add a
add c ; *3
ld c, a
ld b, $0
ld hl, .NPCSpriteAnimData - 3
add hl, bc
ld a, [hli]
cp $ff
jr z, .skip_draw_sprite
farcall CreateSpriteAndAnimBufferEntry
ld a, [wConsole]
cp CONSOLE_CGB
jr nz, .not_cgb
inc hl
.not_cgb
ld a, [wLoadNPCDirection]
add [hl]
farcall StartNewSpriteAnimation
ld c, SPRITE_ANIM_COORD_X
call GetSpriteAnimBufferProperty
ld a, $48
ld [hli], a
ld a, $40
ld [hl], a ; SPRITE_ANIM_COORD_Y
.skip_draw_sprite
ret
.NPCSpriteAnimData
db SPRITE_OW_PLAYER, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_RED_NPC_UP ; $01
db $ff, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_LIGHT_NPC_UP ; $02
db SPRITE_OW_RONALD, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_BLUE_NPC_UP ; $03
db $ff, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_LIGHT_NPC_UP ; $04
db SPRITE_OW_DRMASON, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_WHITE_NPC_UP ; $05
db SPRITE_OW_ISHIHARA, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_PURPLE_NPC_UP ; $06
db SPRITE_OW_IMAKUNI, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_BLUE_NPC_UP ; $07
db SPRITE_OW_NIKKI, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_GREEN_NPC_UP ; $08
db SPRITE_OW_RICK, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_BLUE_NPC_UP ; $09
db SPRITE_OW_KEN, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_RED_NPC_UP ; $0a
db SPRITE_OW_AMY, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_BLUE_NPC_UP ; $0b
db SPRITE_OW_ISAAC, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_YELLOW_NPC_UP ; $0c
db SPRITE_OW_MITCH, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_BLUE_NPC_UP ; $0d
db SPRITE_OW_GENE, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_PURPLE_NPC_UP ; $0e
db SPRITE_OW_MURRAY, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_PINK_NPC_UP ; $0f
db SPRITE_OW_COURTNEY, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_PINK_NPC_UP ; $10
db $ff, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_LIGHT_NPC_UP ; $11
db SPRITE_OW_STEVE, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_INDIGO_NPC_UP ; $12
db $ff, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_LIGHT_NPC_UP ; $13
db SPRITE_OW_JACK, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_WHITE_NPC_UP ; $14
db $ff, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_LIGHT_NPC_UP ; $15
db SPRITE_OW_ROD, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_BLUE_NPC_UP ; $16
db $ff, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_LIGHT_NPC_UP ; $17
db SPRITE_OW_BOY, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_YELLOW_NPC_UP ; $18
db SPRITE_OW_LAD, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_GREEN_NPC_UP ; $19
db SPRITE_OW_SPECS, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_PURPLE_NPC_UP ; $1a
db SPRITE_OW_BUTCH, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_YELLOW_NPC_UP ; $1b
db SPRITE_OW_MANIA, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_WHITE_NPC_UP ; $1c
db SPRITE_OW_JOSHUA, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_WHITE_NPC_UP ; $1d
db SPRITE_OW_HOOD, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_RED_NPC_UP ; $1e
db SPRITE_OW_TECH, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_BLUE_NPC_UP ; $1f
db SPRITE_OW_CHAP, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_GREEN_NPC_UP ; $20
db SPRITE_OW_MAN, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_YELLOW_NPC_UP ; $21
db SPRITE_OW_PAPPY, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_PURPLE_NPC_UP ; $22
db SPRITE_OW_GIRL, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_BLUE_NPC_UP ; $23
db SPRITE_OW_LASS1, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_PURPLE_NPC_UP ; $24
db SPRITE_OW_LASS2, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_RED_NPC_UP ; $25
db SPRITE_OW_LASS3, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_GREEN_NPC_UP ; $26
db SPRITE_OW_SWIMMER, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_YELLOW_NPC_UP ; $27
db SPRITE_OW_CLERK, SPRITE_ANIM_SGB_CLERK_NPC_UP, SPRITE_ANIM_CGB_CLERK_NPC_UP ; $28
db SPRITE_OW_GAL, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_YELLOW_NPC_UP ; $29
db SPRITE_OW_WOMAN, SPRITE_ANIM_DARK_NPC_UP, SPRITE_ANIM_RED_NPC_UP ; $2a
db SPRITE_OW_GRANNY, SPRITE_ANIM_LIGHT_NPC_UP, SPRITE_ANIM_YELLOW_NPC_UP ; $2b
db SPRITE_OW_AMY, SPRITE_ANIM_SGB_AMY_LAYING, SPRITE_ANIM_CGB_AMY_LAYING ; $2c

View File

@ -1,6 +1,6 @@
GfxTablePointers:
dw Tilemaps
dw Tilesets
dw Sprites
dw SpriteAnimations
dw Palettes
dw Tilemaps ; GFXTABLE_TILEMAPS
dw Tilesets ; GFXTABLE_TILESETS
dw Sprites ; GFXTABLE_SPRITES
dw SpriteAnimations ; GFXTABLE_SPRITE_ANIMATIONS
dw Palettes ; GFXTABLE_PALETTES

493
src/engine/gfx/load_gfx.asm Normal file
View File

@ -0,0 +1,493 @@
; l - GFXTABLE_* constant (banks 0,1,2,3,4)
; a - map index (inside of the given bank)
GetMapDataPointer:
push bc
push af
ld bc, GfxTablePointers
ld h, $0
add hl, bc
ld c, [hl]
inc hl
ld b, [hl]
pop af
ld l, a
ld h, $0
sla l
rl h
sla l
rl h
add hl, bc
pop bc
ret
; Loads a pointer from [hl] to wTempPointer. Adds the graphics bank offset ($20)
LoadGraphicsPointerFromHL:
ld a, [hli]
ld [wTempPointer], a
ld a, [hli]
ld [wTempPointer + 1], a
ld a, [hli]
add BANK(GfxTablePointers)
ld [wTempPointerBank], a
ret
Func_80238: ; unreferenced
push hl
ld l, GFXTABLE_TILESETS
ld a, [wCurTileset]
call GetMapDataPointer
call LoadGraphicsPointerFromHL
ld a, [hl]
ld [wTotalNumTiles], a
ld a, TILE_SIZE
ld [wCurSpriteTileSize], a
xor a
ld [wd4cb], a
ld a, $80
ld [wd4ca], a
call LoadGfxDataFromTempPointerToVRAMBank_Tiles0ToTiles2
pop hl
ret
; loads graphics data from third map data pointers
; input:
; a = sprite index within the data map
; output:
; a = number of tiles in sprite
LoadSpriteGfx:
push hl
ld l, GFXTABLE_SPRITES
call GetMapDataPointer
call LoadGraphicsPointerFromHL
ld a, [hl] ; sprite number of tiles
push af
ld [wTotalNumTiles], a
ld a, TILE_SIZE
ld [wCurSpriteTileSize], a
call LoadGfxDataFromTempPointerToVRAMBank
pop af
pop hl
ret
; loads graphics data pointed by wTempPointer in wTempPointerBank
; to the VRAM bank according to wd4cb, in address pointed by wVRAMPointer
LoadGfxDataFromTempPointerToVRAMBank:
call GetTileOffsetPointerAndSwitchVRAM
jr LoadGfxDataFromTempPointer
LoadGfxDataFromTempPointerToVRAMBank_Tiles0ToTiles2:
call GetTileOffsetPointerAndSwitchVRAM_Tiles0ToTiles2
; fallthrough
; loads graphics data pointed by wTempPointer in wTempPointerBank
; to wVRAMPointer
LoadGfxDataFromTempPointer:
push hl
push bc
push de
ld a, [wTotalNumTiles]
ld b, a
ld a, [wCurSpriteTileSize]
ld c, a
ld hl, wVRAMPointer
ld e, [hl]
inc hl
ld d, [hl]
ld hl, wTempPointer
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
inc hl
call CopyGfxDataFromTempBank
call BankswitchVRAM0
pop de
pop bc
pop hl
ret
; convert wVRAMTileOffset to address in VRAM
; and stores it in wVRAMPointer
; switches VRAM according to wd4cb
GetTileOffsetPointerAndSwitchVRAM:
; address of the tile offset is wVRAMTileOffset * $10 + $8000
ld a, [wVRAMTileOffset]
swap a
push af
and $f0
ld [wVRAMPointer], a
pop af
and $0f
add HIGH(v0Tiles0) ; $80
ld [wVRAMPointer + 1], a
; if bottom bit in wd4cb is not set = VRAM0
; if bottom bit in wd4cb is set = VRAM1
ld a, [wd4cb]
and $1
call BankswitchVRAM
ret
; converts wVRAMTileOffset to address in VRAM
; and stores it in wVRAMPointer
; switches VRAM according to wd4cb
; then changes wVRAMPointer such that
; addresses to Tiles0 is changed to Tiles2
GetTileOffsetPointerAndSwitchVRAM_Tiles0ToTiles2:
ld a, [wVRAMTileOffset]
push af
xor $80 ; toggle top bit
ld [wVRAMTileOffset], a
call GetTileOffsetPointerAndSwitchVRAM
ld a, [wVRAMPointer + 1]
add $8
ld [wVRAMPointer + 1], a
pop af
ld [wVRAMTileOffset], a
ret
; loads tileset gfx to VRAM corresponding to wCurTileset
LoadTilesetGfx:
push hl
ld l, GFXTABLE_TILESETS
ld a, [wCurTileset]
call GetMapDataPointer
call LoadGraphicsPointerFromHL
call .LoadTileGfx
call BankswitchVRAM0
pop hl
ret
; loads gfx data from wTempPointerBank:wTempPointer
.LoadTileGfx
push hl
push bc
push de
ld hl, wTempPointer
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wTempPointerBank]
call GetFarByte ; get number of tiles (low byte)
ld [wTotalNumTiles], a
inc hl
ld a, [wTempPointerBank]
call GetFarByte ; get number of tiles (high byte)
ld [wTotalNumTiles + 1], a
inc hl
ld a, l
ld [wTempPointer], a
ld a, h
ld [wTempPointer + 1], a
; used to sequentially copy gfx data in the order
; v0Tiles1 -> v0Tiles2 -> v1Tiles1 -> v1Tiles2
lb bc, $0, LOW(v0Tiles2 / TILE_SIZE) ; $00
call .CopyGfxData
jr z, .done
lb bc, $0, LOW(v0Tiles1 / TILE_SIZE) ; $80
call .CopyGfxData
jr z, .done
; VRAM1 only used in CGB console
ld a, [wConsole]
cp CONSOLE_CGB
jr nz, .done
lb bc, $1, LOW(v1Tiles2 / TILE_SIZE) ; $00
call .CopyGfxData
jr z, .done
lb bc, $1, LOW(v1Tiles1 / TILE_SIZE) ; $80
call .CopyGfxData
.done
pop de
pop bc
pop hl
ret
; copies gfx data from wTempPointer to VRAM
; c must match with wVRAMTileOffset
; if c = $00, copies it to Tiles2
; if c = $80, copies it to Tiles1
; b must match with VRAM bank in wd4cb
; prepares next call to this routine if data wasn't fully copied
; so that it copies to the right VRAM section
.CopyGfxData
push hl
push bc
push de
ld a, [wd4cb]
cp b
jr nz, .skip
ld a, [wVRAMTileOffset]
ld d, a
xor c
bit 7, a
jr nz, .skip
; (wd4cb == b) and
; bit 7 in c is same as bit 7 in wVRAMTileOffset
ld a, c
add $80
sub d
ld d, a ; total number of tiles
ld a, [wTotalNumTiles + 1]
or a
jr nz, .asm_8035a
; if d > wTotalNumTiles,
; overwrite it with wTotalNumTiles
ld a, [wTotalNumTiles]
cp d
jr nc, .asm_8035a
ld d, a
.asm_8035a
ld a, [wTotalNumTiles]
sub d
ld [wTotalNumTiles], a
ld a, [wTotalNumTiles + 1]
sbc $00
ld [wTotalNumTiles + 1], a
call GetTileOffsetPointerAndSwitchVRAM_Tiles0ToTiles2
ld b, d ; number of tiles
ld c, TILE_SIZE
ld hl, wVRAMPointer
ld e, [hl]
inc hl
ld d, [hl]
ld hl, wTempPointer
ld a, [hli]
ld h, [hl]
ld l, a
push bc
push hl
ldh a, [hBankVRAM]
push af
ld a, [wd4cb]
and $01
call BankswitchVRAM
call CopyGfxDataFromTempBank
pop af
call BankswitchVRAM
pop de
pop bc
; add number of tiles * TILE_SIZE
; to wVRAMPointer and store it in wTempPointer
ld l, b
ld h, $00
add hl, hl ; *2
add hl, hl ; *4
add hl, hl ; *8
add hl, hl ; *16 (TILE_SIZE)
add hl, de
ld a, l
ld [wTempPointer], a
ld a, h
ld [wTempPointer + 1], a
ld hl, wVRAMTileOffset
ld a, [hl]
add $80
push af
and $80 ; start of next group of tiles
ld [hli], a
pop af
; if it overflows
; (which means a tile group after Tiles2)
; then set wd4cb for VRAM1
ld a, [hl] ; wd4cb
adc $00
ld [hl], a
.skip
ld hl, wTotalNumTiles
ld a, [hli]
or [hl] ; wTotalNumTiles + 1
pop de
pop bc
pop hl
ret
; gets pointer to BG map with ID from wCurTilemap
Func_803b9:
ld l, GFXTABLE_TILEMAPS
ld a, [wCurTilemap]
call GetMapDataPointer
call LoadGraphicsPointerFromHL
ld a, [hl]
ld [wCurTileset], a
ret
; loads background palette (PALETTE_*) given in a
; each palette has data for DMG BGP and for CGB RGB palettes
; DMG:
; - if palette has BGP data, load it
; CGB:
; - load palette starting from background palette index [wWhichBGPalIndex]
LoadBGPalette:
push hl
push bc
push de
call LoadPaletteDataToBuffer
ld hl, wLoadedPalData
ld a, [hli]
or a
jr z, .skip_bgp
ld a, [hli]
push hl
call SetBGP
pop hl
.skip_bgp
ld a, [hli]
or a
jr z, .skip_pal
ld c, a
ld a, [wWhichBGPalIndex]
ld b, a
call LoadPaletteDataFromHL
.skip_pal
pop de
pop bc
pop hl
ret
; copies from palette data in hl c*8 bytes to palette index b
; in WRAM, starting from wBackgroundPalettesCGB
; b = palette index
; c = palette size
; hl = palette data to copy
LoadPaletteDataFromHL:
push hl
push bc
push de
ld a, b
cp NUM_BACKGROUND_PALETTES + NUM_OBJECT_PALETTES ; total palettes available
jr nc, .fail_return
add a ; 2 * index
add a ; 4 * index
add a ; 8 * index
add LOW(wBackgroundPalettesCGB)
ld e, a
ld a, HIGH(wBackgroundPalettesCGB)
adc 0
ld d, a
ld a, c
cp $09
jr nc, .fail_return
add a ; 2 * size
add a ; 4 * size
add a ; 8 * size
ld c, a
.loop
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .loop
call FlushAllPalettes
jr .success_return
.fail_return
debug_nop
.success_return
pop de
pop bc
pop hl
ret
; loads object palette (PALETTE_*) given in a
; each palette has data for DMG OBP and for CGB RGB palettes
; DMG:
; - if [wWhichOBP] is 1, then load to OBP1, otherwise start load to OBP0
; CGB:
; - load palette starting from object palette index [wWhichOBPalIndex]
LoadOBPalette:
push hl
push bc
push de
call LoadPaletteDataToBuffer
ld hl, wLoadedPalData
ld a, [hli] ; number palettes
ld c, a
or a
jr z, .check_palette_size
ld a, [wWhichOBP]
cp 1
jr z, .obp1
ld a, [hli] ; palette for OBP0
push hl
push bc
call SetOBP0
pop bc
pop hl
dec c
jr z, .check_palette_size
.obp1
ld a, [hli] ; palette for OBP1
push hl
push bc
call SetOBP1
pop bc
pop hl
dec c
jr z, .check_palette_size
inc hl
.check_palette_size
ld a, [hli]
or a
jr z, .done
; non-zero size, so load it from data
ld c, a
ld a, [wWhichOBPalIndex]
; ensure it's a palette index starting from wObjectPalettesCGB
or NUM_BACKGROUND_PALETTES
ld b, a
call LoadPaletteDataFromHL
.done
pop de
pop bc
pop hl
ret
; copies palette data of index in a to wLoadedPalData
LoadPaletteDataToBuffer:
push hl
push bc
push de
ld l, GFXTABLE_PALETTES
call GetMapDataPointer
call LoadGraphicsPointerFromHL
; size parameter
ld a, [hl]
ld b, a
and $0f
inc a
ld c, a
ld a, b
and $f0
srl a
inc a
add c
ld c, a
ld b, $00
ld de, wLoadedPalData
call CopyBankedDataToDE
pop de
pop bc
pop hl
ret

View File

@ -0,0 +1,309 @@
; loads the BG map corresponding to wCurTilemap to SRAM
; bc = starting coordinates
LoadTilemap_ToSRAM:
ld a, TRUE
ld [wWriteBGMapToSRAM], a
jr LoadTilemap
; loads the BG map corresponding to wCurTilemap to VRAM
; bc = starting coordinates
LoadTilemap_ToVRAM:
xor a ; FALSE
ld [wWriteBGMapToSRAM], a
; fallthrough
; loads the BG map corresponding to wCurTilemap
; either loads them in VRAM or SRAM,
; depending on wWriteBGMapToSRAM
; bc = starting coordinates
LoadTilemap:
push hl
push bc
push de
call BCCoordToBGMap0Address
ld hl, wVRAMPointer
ld [hl], e
inc hl
ld [hl], d
; get pointer and bank for BG Map
call Func_803b9
ld a, [wTempPointerBank]
ld [wBGMapBank], a
; store header data
ld de, wDecompressionBuffer
ld bc, $6 ; header + 1st instruction
call CopyBankedDataToDE
ld l, e
ld h, d
ld a, [hli]
ld [wBGMapWidth], a
ld a, [hli]
ld [wBGMapHeight], a
ld a, [hli]
ld [wBGMapPermissionDataPtr], a
ld a, [hli]
ld [wBGMapPermissionDataPtr + 1], a
ld a, [hli]
ld [wBGMapCGBMode], a
call .InitAndDecompressBGMap
pop de
pop bc
pop hl
ret
; prepares the pointers for decompressing BG Map
; and calls InitDataDecompression
; then decompresses the data
.InitAndDecompressBGMap
push hl
push bc
push de
ld a, [wTempPointer]
add $5 ; header
ld e, a
ld a, [wTempPointer + 1]
adc 0
ld d, a
ld b, HIGH(wDecompressionSecondaryBuffer)
call InitDataDecompression
ld a, [wVRAMPointer]
ld e, a
ld a, [wVRAMPointer + 1]
ld d, a
call .Decompress
pop de
pop bc
pop hl
ret
; wTempBank:wTempPointer = source of compressed data
; wVRAMPointer = destination of decompressed data
.Decompress
; if wBGMapCGBMode is true, then use double wBGMapWidth
; since one "width" length goes to VRAM0
; and the other "width" length goes to VRAM1
push hl
ld hl, wDecompressionRowWidth
ld a, [wBGMapWidth]
ld [hl], a
ld a, [wBGMapCGBMode]
or a
jr z, .skip_doubling_width
sla [hl]
.skip_doubling_width
; clear wDecompressionBuffer
ld c, $40
ld hl, wDecompressionBuffer
xor a
.loop_clear
ld [hli], a
dec c
jr nz, .loop_clear
; loop each row, up to the number of tiles in height
ld a, [wBGMapHeight]
ld c, a
.loop
push bc
push de
ld b, $00
ld a, [wDecompressionRowWidth]
ld c, a
ld de, wDecompressionBuffer
call DecompressDataFromBank
; copy to VRAM0
ld a, [wBGMapWidth]
ld b, a
pop de
push de
ld hl, wDecompressionBuffer
call CopyBGDataToVRAMOrSRAM
ld a, [wConsole]
cp CONSOLE_CGB
jr nz, .next_row
; cgb only
; copy the second "half" to VRAM1
call BankswitchVRAM1
ld a, [wBGMapWidth]
ld c, a
ld b, $0
ld hl, wDecompressionBuffer
add hl, bc
pop de
push de
ld a, [wBGMapWidth]
ld b, a
call Func_80148 ; adds some wd291 offset to tiles
call CopyBGDataToVRAMOrSRAM
call BankswitchVRAM0
.next_row
pop de
ld hl, TILEMAP_WIDTH
add hl, de
ld e, l
ld d, h
pop bc
dec c
jr nz, .loop
pop hl
ret
Func_80148:
ld a, [wd291]
or a
ret z
ld a, [wBGMapCGBMode]
or a
jr z, .asm_80162
; add wd291 to b bytes in hl
push hl
push bc
.loop_1
push bc
ld a, [wd291]
add [hl]
ld [hli], a
pop bc
dec b
jr nz, .loop_1
pop bc
pop hl
ret
; store wd291 to b bytes in hl
.asm_80162
push hl
push bc
ld a, [wd291]
.loop_2
ld [hli], a
dec b
jr nz, .loop_2
pop bc
pop hl
ret
; copies BG Map data pointed by hl
; to either VRAM or SRAM, depending on wWriteBGMapToSRAM
; de is the target address in VRAM,
; if SRAM is the target address to copy,
; copies data to sGfxBuffer0 or sGfxBuffer1
; for VRAM0 or VRAM1 respectively
CopyBGDataToVRAMOrSRAM:
ld a, [wWriteBGMapToSRAM]
or a
jp z, SafeCopyDataHLtoDE
; copies b bytes from hl to SRAM1
push hl
push bc
push de
ldh a, [hBankSRAM]
push af
ld a, BANK("SRAM1")
call BankswitchSRAM
push hl
ld hl, sGfxBuffer0 - v0BGMap0
ldh a, [hBankVRAM]
or a
jr z, .got_pointer
ld hl, sGfxBuffer1 - v1BGMap0
.got_pointer
add hl, de
ld e, l
ld d, h
pop hl
.loop
ld a, [hli]
ld [de], a
inc de
dec b
jr nz, .loop
pop af
call BankswitchSRAM
call DisableSRAM
pop de
pop bc
pop hl
ret
; safely copies $20 bytes at a time
; sGfxBuffer0 -> v0BGMap0
; sGfxBuffer1 -> v0BGMap1 (if in CGB)
SafelyCopyBGMapFromSRAMToVRAM:
push hl
push bc
push de
ldh a, [hBankSRAM]
push af
ld a, BANK("SRAM1")
call BankswitchSRAM
ld hl, sGfxBuffer0
ld de, v0BGMap0
ld c, $20
.loop
push bc
push hl
push de
ld b, $20
call SafeCopyDataHLtoDE
ld a, [wConsole]
cp CONSOLE_CGB
jr nz, .skip_vram1
pop de
pop hl
push hl
push de
ld bc, sGfxBuffer1 - sGfxBuffer0 ; $400
add hl, bc
call BankswitchVRAM1
ld b, $20
call SafeCopyDataHLtoDE
call BankswitchVRAM0
.skip_vram1
pop hl
ld de, $20
add hl, de
ld e, l
ld d, h
pop hl
ld bc, $20
add hl, bc
pop bc
dec c
jr nz, .loop
pop af
call BankswitchSRAM
call DisableSRAM
pop de
pop bc
pop hl
ret
; clears sGfxBuffer0 and sGfxBuffer1
ClearSRAMBGMaps:
push hl
push bc
ldh a, [hBankSRAM]
push af
ld a, BANK(sGfxBuffer0) ; SRAM 1
call BankswitchSRAM
ld hl, sGfxBuffer0
ld bc, $800 ; sGfxBuffer0 + sGfxBuffer1
xor a
call FillMemoryWithA
pop af
call BankswitchSRAM
call DisableSRAM
pop bc
pop hl
ret

View File

@ -294,7 +294,7 @@ LoadSpriteAnimPointers:
add hl, bc
ld [hli], a
push hl
ld l, 6 ; SpriteAnimations
ld l, GFXTABLE_SPRITE_ANIMATIONS
farcall GetMapDataPointer
farcall LoadGraphicsPointerFromHL
pop hl ; hl is animation bank
@ -572,7 +572,7 @@ Func_12c4f:
ld a, d
ld [wVRAMTileOffset], a
pop af
farcall Func_8025b
farcall LoadSpriteGfx
ret
Func_12c5e:

View File

@ -0,0 +1,7 @@
; in case GetAnimationFramePointer fails to get a valid pointer
; it defaults to this animation data
SpriteNullAnimationPointer::
dw SpriteNullAnimationFrame
SpriteNullAnimationFrame:
db 0

View File

@ -74,10 +74,10 @@ PlayIntroSequence:
LoadTitleScreenSprites:
xor a
ld [wd4ca], a
ld [wd4cb], a
ld [wWhichOBP], a ; OBP0
ld [wWhichOBPalIndex], a ; palette index 0
ld a, PALETTE_30
farcall LoadPaletteData
farcall LoadOBPalette
ld bc, 0
ld de, wTitleScreenSprites

View File

@ -1,10 +1,10 @@
DebugLookAtSprite:
farcall Func_80cd7
farcall _DebugLookAtSprite
scf
ret
DebugVEffect:
farcall Func_80cd6
farcall _DebugVEffect
scf
ret

View File

@ -54,11 +54,11 @@ LoadCollectedMedalTilemaps:
ld [wd4cb], a
farcall LoadTilesetGfx
xor a
ld [wd4ca], a
ld a, $01
ld [wd4cb], a
ld [wWhichOBP], a ; not used
ld a, 1 ; palette index
ld [wWhichBGPalIndex], a
ld a, PALETTE_118
farcall SetBGPAndLoadedPal
farcall LoadBGPalette
.done
ret

View File

@ -0,0 +1,282 @@
ClearNumLoadedFramesetSubgroups:
xor a
ld [wNumLoadedFramesetSubgroups], a
ret
; for the current map, process the animation
; data of its corresponding OW tiles
DoMapOWFrame:
push hl
push bc
ld a, [wCurMap]
add a
add a ; *4
ld c, a
ld a, [wConsole]
cp CONSOLE_CGB
jr nz, .not_cgb
ld a, c
add 2
ld c, a
.not_cgb
ld b, $0
ld hl, MapOWFramesetPointers
add hl, bc
; got pointer for current map's frameset data
ld a, [hli]
ld h, [hl]
ld l, a
call ProcessOWFrameset
pop bc
pop hl
ret
; processes the OW frameset pointed by hl
ProcessOWFrameset:
push hl
push bc
ld a, l
ld [wCurMapOWFrameset], a
ld a, h
ld [wCurMapOWFrameset + 1], a
xor a
ld [wNumLoadedFramesetSubgroups], a
call ClearOWFramesetSubgroups
ld c, 0
.loop_subgroups
call LoadOWFramesetSubgroup
call GetOWFramesetSubgroupData
ld a, [wCurOWFrameDataOffset]
cp -1
jr z, .next_subgroup
ld a, [wNumLoadedFramesetSubgroups]
inc a
ld [wNumLoadedFramesetSubgroups], a
call LoadOWFrameTiles
call StoreOWFramesetSubgroup
.next_subgroup
inc c
ld a, c
cp NUM_OW_FRAMESET_SUBGROUPS
jr c, .loop_subgroups
pop bc
pop hl
ret
; for each of the loaded frameset subgroups
; load their tiles and advance their durations
DoLoadedFramesetSubgroupsFrame::
ld a, [wNumLoadedFramesetSubgroups]
or a
ret z
ld c, 0
.loop_subgroups
call LoadOWFramesetSubgroup
cp -1
jr z, .next_subgroup
call LoadOWFrameTiles
call StoreOWFramesetSubgroup
.next_subgroup
inc c
ld a, c
cp NUM_OW_FRAMESET_SUBGROUPS
jr c, .loop_subgroups
ret
; from subgroup in register c, get
; from OW frameset in hl its corresponding
; data offset and duration
GetOWFramesetSubgroupData:
push hl
push bc
push hl
ld b, $0
add hl, bc
ld c, [hl]
pop hl
add hl, bc
ld a, [hl] ; beginning of OW_FRAME
cp -1
jr z, .end_of_list ; skip if it's end of list
ld a, c ; store its addr offset
ld [wCurOWFrameDataOffset], a
xor a
ld [wCurOWFrameDuration], a
.end_of_list
pop bc
pop hl
ret
; if wCurOWFrameDuration == 0, processes next frame for OW map
; by loading the tiles corresponding to current frame
; if wCurOWFrameDuration != 0, then simply decrements it and returns
LoadOWFrameTiles:
ld a, [wCurOWFrameDuration]
or a
jr z, .next_frame
dec a
ld [wCurOWFrameDuration], a
ret
.next_frame
push hl
push de
push bc
; add wCurOWFrameDataOffset to pointer in wCurMapOWFrameset
ld a, [wCurOWFrameDataOffset]
ld c, a
ld a, [wCurMapOWFrameset]
add c
ld l, a
ld a, [wCurMapOWFrameset + 1]
adc 0
ld h, a
ld a, [hl]
ld [wCurOWFrameDuration], a
.loop_ow_frames
call .LoadTile
ld de, OW_FRAME_STRUCT_SIZE
add hl, de ; next frame data
ld a, c
add e
ld c, a
; OW frames with 0 duration are processed
; at the same time as the previous frame data
ld a, [hl]
or a
jr z, .loop_ow_frames
cp -1
ld a, c
ld [wCurOWFrameDataOffset], a
jr nz, .done
; there's no more frames to process for this map
; reset the frame data offset
pop bc
push bc
ld a, [wCurOWFrameDuration]
push af
ld a, [wCurMapOWFrameset]
ld l, a
ld a, [wCurMapOWFrameset + 1]
ld h, a
call GetOWFramesetSubgroupData
pop af
ld [wCurOWFrameDuration], a
.done
pop bc
pop de
pop hl
ret
; load a single tile specified
; by the OW frame data pointed by hl
.LoadTile
push hl
push bc
push de
ldh a, [hBankVRAM]
push af
inc hl
ld a, [hli] ; tile number
xor $80
ld e, a
ld a, [hli] ; VRAM bank
; get tile offset of register e
; and load its address in de
push hl
call BankswitchVRAM
ld h, $00
ld l, e
add hl, hl ; *2
add hl, hl ; *4
add hl, hl ; *8
add hl, hl ; *16
ld de, v0Tiles1 ; or v1Tiles1
add hl, de
ld e, l
ld d, h
pop hl
ld a, [hli] ; bank of tileset
add BANK(MapOWFramesetPointers)
ld [wTempPointerBank], a
ld a, [hli] ; tileset addr lo byte
ld c, a
ld a, [hli] ; tileset addr hi byte
ld b, a
ld a, [hli] ; tile number lo byte
ld h, [hl] ; tile number hi byte
ld l, a
add hl, hl ; *2
add hl, hl ; *4
add hl, hl ; *8
add hl, hl ; *16
add hl, bc
; copy tile from the tileset to VRAM addr
lb bc, 1, TILE_SIZE
call CopyGfxDataFromTempBank
pop af
call BankswitchVRAM
pop de
pop bc
pop hl
ret
; fills wOWFramesetSubgroups with $ff
ClearOWFramesetSubgroups:
push hl
push bc
ld hl, wOWFramesetSubgroups
ld c, NUM_OW_FRAMESET_SUBGROUPS * 2
ld a, $ff
.loop
ld [hli], a
dec c
jr nz, .loop
pop bc
pop hl
ret
; copies wOWFramesetSubgroups + 2*c
; to wCurOWFrameDataOffset and wCurOWFrameDuration
; also returns its current duration
LoadOWFramesetSubgroup:
push hl
push bc
ld hl, wOWFramesetSubgroups
sla c
ld b, $00
add hl, bc
ld a, [hli]
ld [wCurOWFrameDataOffset], a
push af
ld a, [hl]
ld [wCurOWFrameDuration], a
pop af
pop bc
pop hl
ret
; copies wCurOWFrameDataOffset and wCurOWFrameDuration
; to wOWFramesetSubgroups + 2*c
StoreOWFramesetSubgroup:
push hl
push bc
ld hl, wOWFramesetSubgroups
sla c
ld b, $00
add hl, bc
ld a, [wCurOWFrameDataOffset]
ld [hli], a
ld a, [wCurOWFrameDuration]
ld [hl], a
pop bc
pop hl
ret
INCLUDE "data/map_ow_framesets.asm"

View File

@ -0,0 +1,57 @@
; loads the graphics and permissions for the current map
; according to its Map Header configurations
; if it's the Overworld Map, also prints the map name
; and sets up the volcano animation
LoadMapGfxAndPermissions:
call ClearSRAMBGMaps
xor a
ld [wTextBoxFrameType], a
call LoadMapTilesAndPals
farcall LoadPermissionMap
farcall Func_c9c7
call SafelyCopyBGMapFromSRAMToVRAM
farcall Func_c3ff
ld a, [wCurMap]
cp OVERWORLD_MAP
ret nz
farcall OverworldMap_PrintMapName
farcall OverworldMap_InitVolcanoSprite
ret
; reloads the map tiles and permissions
; after a textbox has been closed
ReloadMapAfterTextClose:
call ClearSRAMBGMaps
lb bc, 0, 0
call LoadTilemap_ToSRAM
farcall Func_c9c7
call SafelyCopyBGMapFromSRAMToVRAM
farcall Func_c3ee
ret
LoadMapTilesAndPals:
farcall LoadMapHeader
farcall SetSGB2AndSGB3MapPalette
lb bc, 0, 0
call LoadTilemap_ToSRAM
ld a, LOW(v0Tiles1 / TILE_SIZE)
ld [wVRAMTileOffset], a
xor a ; VRAM0
ld [wd4cb], a
call LoadTilesetGfx
xor a
ld [wWhichOBP], a ; not used
ld a, [wd291]
ld [wWhichBGPalIndex], a
ld a, [wCurMapInitialPalette]
call LoadBGPalette
ld a, [wd291]
ld [wWhichBGPalIndex], a
ld a, [wCurMapPalette]
or a
jr z, .asm_80076
call LoadBGPalette
.asm_80076
ret

View File

@ -0,0 +1,167 @@
; clears wOWMapEvents
ClearOWMapEvents:
push hl
push bc
ld c, NUM_MAP_EVENTS
ld hl, wOWMapEvents
xor a
.loop
ld [hli], a
dec c
jr nz, .loop
pop bc
pop hl
ret
; input:
; - a = MAP_EVENT_* constant
ApplyOWMapEventChangeIfEventSet:
push hl
push bc
push af
ld c, a
ld a, TRUE
ld [wWriteBGMapToSRAM], a
ld b, $0
ld hl, wOWMapEvents
add hl, bc
ld a, [hl]
or a
jr z, .false
ld a, c
call SetOWMapEvent_SRAMOrVRAM
.false
pop af
pop bc
pop hl
ret
; input:
; - a = MAP_EVENT_* constant
SetOWMapEvent:
push af
xor a
ld [wWriteBGMapToSRAM], a
pop af
; fallthrough
; set OWMapEvent given in a to TRUE
; and applies the corresponding map changes to that event
; (door permissions, and which tiles to overwrite)
; input:
; - a = MAP_EVENT_* constant
SetOWMapEvent_SRAMOrVRAM:
push hl
push bc
push de
ld c, a
ld a, [wCurTilemap]
push af
ld a, [wBGMapBank]
push af
ld a, [wBGMapWidth]
push af
ld a, [wBGMapHeight]
push af
ld a, [wBGMapPermissionDataPtr]
push af
ld a, [wBGMapPermissionDataPtr + 1]
push af
ld b, $0
ld hl, wOWMapEvents
add hl, bc
ld a, TRUE
ld [hl], a
ld a, c
add a
ld c, a
ld b, $0
ld hl, .TilemapPointers
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
ld b, [hl]
inc hl
ld c, [hl]
inc hl
ld a, [wConsole]
cp CONSOLE_CGB
jr nz, .got_tilemap
inc hl
.got_tilemap
ld a, [hl]
ld [wCurTilemap], a
push bc
farcall LoadTilemap ; unnecessary farcall
pop bc
srl b
ld a, c
rrca
and $0f
swap a ; * $10
add b
ld c, a
ld b, $0
ld hl, wPermissionMap
add hl, bc
farcall DecompressPermissionMap
pop af
ld [wBGMapPermissionDataPtr + 1], a
pop af
ld [wBGMapPermissionDataPtr], a
pop af
ld [wBGMapHeight], a
pop af
ld [wBGMapWidth], a
pop af
ld [wBGMapBank], a
pop af
ld [wCurTilemap], a
pop de
pop bc
pop hl
ret
.TilemapPointers
table_width 2
dw .PokemonDomeDoor ; MAP_EVENT_POKEMON_DOME_DOOR
dw .HallOfHonorDoor ; MAP_EVENT_HALL_OF_HONOR_DOOR
dw .FightingDeckMachine ; MAP_EVENT_FIGHTING_DECK_MACHINE
dw .RockDeckMachine ; MAP_EVENT_ROCK_DECK_MACHINE
dw .WaterDeckMachine ; MAP_EVENT_WATER_DECK_MACHINE
dw .LightningDeckMachine ; MAP_EVENT_LIGHTNING_DECK_MACHINE
dw .GrassDeckMachine ; MAP_EVENT_GRASS_DECK_MACHINE
dw .PsychicDeckMachine ; MAP_EVENT_PSYCHIC_DECK_MACHINE
dw .ScienceDeckMachine ; MAP_EVENT_SCIENCE_DECK_MACHINE
dw .FireDeckMachine ; MAP_EVENT_FIRE_DECK_MACHINE
dw .ChallengeMachine ; MAP_EVENT_CHALLENGE_MACHINE
assert_table_length NUM_MAP_EVENTS
; x coordinate, y coordinate, non-cgb tilemap, cgb tilemap
.PokemonDomeDoor
db $16, $00, TILEMAP_POKEMON_DOME_DOOR_MAP_EVENT, TILEMAP_POKEMON_DOME_DOOR_MAP_EVENT_CGB
.HallOfHonorDoor
db $0e, $00, TILEMAP_HALL_OF_HONOR_DOOR_MAP_EVENT, TILEMAP_HALL_OF_HONOR_DOOR_MAP_EVENT_CGB
.FightingDeckMachine
db $06, $02, TILEMAP_DECK_MACHINE_MAP_EVENT, TILEMAP_DECK_MACHINE_MAP_EVENT_CGB
.RockDeckMachine
db $0a, $02, TILEMAP_DECK_MACHINE_MAP_EVENT, TILEMAP_DECK_MACHINE_MAP_EVENT_CGB
.WaterDeckMachine
db $0e, $02, TILEMAP_DECK_MACHINE_MAP_EVENT, TILEMAP_DECK_MACHINE_MAP_EVENT_CGB
.LightningDeckMachine
db $12, $02, TILEMAP_DECK_MACHINE_MAP_EVENT, TILEMAP_DECK_MACHINE_MAP_EVENT_CGB
.GrassDeckMachine
db $0e, $0a, TILEMAP_DECK_MACHINE_MAP_EVENT, TILEMAP_DECK_MACHINE_MAP_EVENT_CGB
.PsychicDeckMachine
db $12, $0a, TILEMAP_DECK_MACHINE_MAP_EVENT, TILEMAP_DECK_MACHINE_MAP_EVENT_CGB
.ScienceDeckMachine
db $0e, $12, TILEMAP_DECK_MACHINE_MAP_EVENT, TILEMAP_DECK_MACHINE_MAP_EVENT_CGB
.FireDeckMachine
db $12, $12, TILEMAP_DECK_MACHINE_MAP_EVENT, TILEMAP_DECK_MACHINE_MAP_EVENT_CGB
.ChallengeMachine
db $0a, $00, TILEMAP_CHALLENGE_MACHINE_MAP_EVENT, TILEMAP_CHALLENGE_MACHINE_MAP_EVENT_CGB

View File

@ -240,7 +240,7 @@ Func_c1b1:
ld [wTempPlayerDirection], a
call ClearEvents
call DetermineImakuniAndChallengeHall
farcall Func_80b7a
farcall ClearOWMapEvents
farcall ClearMasterBeatenList
farcall ChallengeMachine_Reset
xor a
@ -698,10 +698,11 @@ Func_c49c:
Func_c4b9:
xor a
ld [wVRAMTileOffset], a
ld [wd4cb], a
ld [wWhichOBP], a ; OBP0
ld [wWhichOBPalIndex], a ; palette index 0
ld a, PALETTE_29
farcall LoadPaletteData
farcall LoadOBPalette
ld b, SPRITE_ANIM_LIGHT_NPC_UP
ld a, [wConsole]
cp CONSOLE_CGB

View File

@ -1565,7 +1565,7 @@ LegendaryCardEvents:
ScriptCommand_ReplaceMapBlocks:
ld a, c
farcall Func_80ba4
farcall SetOWMapEvent
jp IncreaseScriptPointerBy2
ScriptCommand_ChooseDeckToDuelAgainstMultichoice:

View File

@ -57,12 +57,12 @@ _LoadScene::
inc hl
push af ; palette
xor a
ld [wd4ca], a
ld [wWhichOBP], a ; not used
ld a, [hli]
ld [wd4cb], a ; palette offset
ld [wWhichBGPalIndex], a ; palette offset
ld [wd291], a ; palette offset
pop af ; palette
farcall SetBGPAndLoadedPal ; load palette
farcall LoadBGPalette ; load palette
ld a, [wConsole]
cp CONSOLE_CGB
ld a, [hli]
@ -91,15 +91,17 @@ _LoadScene::
ld a, [hli]
jr nz, .not_cgb_3
ld a, [hl]
.not_cgb_3
inc hl
push af ; sprite palette
xor a
ld [wd4ca], a
ld [wWhichOBP], a ; OBP0
ld a, [hli]
ld [wd4cb], a ; palette offset
ld [wWhichOBPalIndex], a ; palette index
pop af ; sprite palette
farcall LoadPaletteData
farcall LoadOBPalette
.next_animation
ld a, [hli]
or a
@ -276,12 +278,12 @@ _DrawPortrait::
farcall LoadTilesetGfx
pop hl
xor a
ld [wd4ca], a
ld [wWhichOBP], a ; not used
ld a, [wd291]
ld [wd4cb], a
ld [wWhichBGPalIndex], a
ld a, [hli]
push hl
farcall SetBGPAndLoadedPal
farcall LoadBGPalette
pop hl
ld a, [hli]
ld h, [hl]
@ -327,7 +329,7 @@ SetBoosterLogoOAM:
ld [wd4cb], a
ld [wd4ca], a
ld a, SPRITE_BOOSTER_PACK_OAM
farcall Func_8025b
farcall LoadSpriteGfx
pop bc
call ZeroObjectPositions
ld hl, BoosterLogoOAM

View File

@ -283,11 +283,12 @@ LoadOWMapForCreditsSequence:
farcall Func_c9c7
farcall SafelyCopyBGMapFromSRAMToVRAM
farcall DoMapOWFrame
xor a
ld [wd4ca], a
ld [wd4cb], a
ld [wWhichOBP], a ; OBP0
ld [wWhichOBPalIndex], a ; palette index 0
ld a, PALETTE_29
farcall LoadPaletteData
farcall LoadOBPalette
ret
CreditsSequenceCmd_LoadOWMap:

View File

@ -172,7 +172,13 @@ SECTION "SGB", ROMX
INCLUDE "engine/sgb.asm"
SECTION "Bank 20", ROMX
INCLUDE "engine/bank20.asm"
INCLUDE "engine/overworld/load_overworld.asm"
INCLUDE "engine/gfx/load_tilemap.asm"
INCLUDE "engine/gfx/load_gfx.asm"
INCLUDE "engine/overworld/animation.asm"
INCLUDE "engine/overworld/map_events.asm"
INCLUDE "engine/gfx/debug.asm"
INCLUDE "engine/gfx/sprite_null_animation.asm"
SECTION "Gfx", ROMX
INCLUDE "engine/gfx/gfx_table_pointers.asm"

View File

@ -14,7 +14,7 @@ DeckMachineRoomCloseTextBox:
ld a, MAP_EVENT_FIGHTING_DECK_MACHINE
.asm_d8af
push af
farcall Func_80b89
farcall ApplyOWMapEventChangeIfEventSet
pop af
inc a
cp MAP_EVENT_FIRE_DECK_MACHINE + 1

View File

@ -30,7 +30,7 @@ MasonLabLoadMap:
MasonLabCloseTextBox:
ld a, MAP_EVENT_CHALLENGE_MACHINE
farcall Func_80b89
farcall ApplyOWMapEventChangeIfEventSet
ret
; Lets you access the Challenge Machine if available
@ -270,7 +270,7 @@ Func_d703:
or a
ret z
ld a, MAP_EVENT_CHALLENGE_MACHINE
farcall Func_80ba4
farcall SetOWMapEvent
ret
Preload_DrMason:

View File

@ -55,7 +55,7 @@ PokemonDomeLoadMap:
PokemonDomeCloseTextBox:
ld a, MAP_EVENT_HALL_OF_HONOR_DOOR
farcall Func_80b89
farcall ApplyOWMapEventChangeIfEventSet
ret
Script_Courtney:

View File

@ -13,7 +13,7 @@ PokemonDomeEntranceLoadMap:
PokemonDomeEntranceCloseTextBox:
ld a, MAP_EVENT_POKEMON_DOME_DOOR
farcall Func_80b89
farcall ApplyOWMapEventChangeIfEventSet
ret
Script_f631:

View File

@ -2280,8 +2280,8 @@ wNumLoadedFramesetSubgroups:: ; d322
; holds the current state of each event
; each corresponding to a MAP_EVENT_* constant
; if $0, doors are closed / deck machines are deactivated
; if $1, doors are open / deck machines are activated
; if FALSE, doors are closed / deck machines are deactivated
; if TRUE, doors are open / deck machines are activated
wOWMapEvents:: ; d323
ds NUM_MAP_EVENTS
@ -2658,9 +2658,21 @@ wGeneralSaveDataByteCount:: ; d4c8
; stores tile offset in VRAM
wVRAMTileOffset:: ; d4ca
; for LoadOBPalette
; which object palette to load to (DMG)
wWhichOBP:: ; d4ca
wd4ca:: ; d4ca
ds $1
; for LoadOBPalette
; which object palette index to load to (CGB)
wWhichOBPalIndex:: ; d4cb
; for LoadBGPalette
; which background palette index to load to (CGB)
wWhichBGPalIndex:: ; d4cb
; bottom bit stores which VRAM bank to draw certain gfx
; $0 = VRAM0, $1 = VRAM1
wd4cb:: ; d4cb