Clean up card gfx

This commit is contained in:
earthoul
2026-06-27 18:31:03 +09:00
parent 8f6ecf1844
commit 76aa0e2923
21 changed files with 6248 additions and 5656 deletions

View File

@@ -29,11 +29,6 @@ DEF MAX_UNNAMED_DECK_NUM EQU 999
DEF MAX_NUM_AUTO_DECK_LIST_DIFFERENT_CARDS EQU 43
DEF AUTO_DECK_LIST_BUFFER_SIZE EQU 3 * MAX_NUM_AUTO_DECK_LIST_DIFFERENT_CARDS + 1
; card gfx: a 72-byte header (3 palettes + a CARD_TILE_COUNT-entry attribute
; map, one byte per tile) followed by CARD_TILE_COUNT uncompressed tiles.
; see LoadCardGfx / CardGraphics.
DEF CARD_TILE_COUNT EQU $30 ; 48
; card data offsets (data/cards.asm and card_data_struct)
RSRESET

View File

@@ -5,6 +5,7 @@
; ascii half-width font
charmap "\n", $0a
DEF HALFWIDTH_CHAR_START EQU $20
charmap " ", $20
charmap "!", $21
charmap "”", $22
@@ -293,6 +294,7 @@ ENDM
fwcharmap TX_HIRAGANA, "っ", $5f
; TX_KATAKANA, TX_HIRAGANA, and TX_FULLWIDTH0
DEF FULLWIDTH0_CHAR_START EQU $60
fwcharmap TX_FULLWIDTH0, "0", $60
fwcharmap TX_FULLWIDTH0, "1", $61
fwcharmap TX_FULLWIDTH0, "2", $62

View File

@@ -26,3 +26,26 @@ DEF ICON_TILE_FIGHTING EQU $f0
DEF ICON_TILE_PSYCHIC EQU $f4
DEF ICON_TILE_COLORLESS EQU $f8
DEF ICON_TILE_ENERGY EQU $fc
; card gfx
; see LoadCardGfx, CardGraphics
DEF CARD_GFX_WIDTH EQU 8 ; in tiles
DEF CARD_GFX_HEIGHT EQU 6 ; in tiles
DEF NUM_CARD_GFX_TILES EQU CARD_GFX_WIDTH * CARD_GFX_HEIGHT ; 48
RSRESET
DEF CARDGFXSTRUCT_PALS RB 3 palettes ; $000
DEF CARDGFXSTRUCT_PALS_SIZE EQU _RS ; 24
DEF CARDGFXSTRUCT_TILE_ATTRMAP RB NUM_CARD_GFX_TILES ; $018
DEF CARDGFXSTRUCT_TILE_ATTRMAP_SIZE EQU _RS - CARDGFXSTRUCT_TILE_ATTRMAP ; 48
DEF CARD_GFX_TILE_ATTRMAP_PAL_INDEX EQU %11_000000
; offset = 48 + (cur alt tile idx) - (cur tile idx)
; 0 if no alt
DEF CARD_GFX_TILE_ATTRMAP_ALT_OFFSET EQU %00_111111
DEF CARDGFXSTRUCT_TILES RB NUM_CARD_GFX_TILES tiles ; $048
DEF CARDGFXSTRUCT_TILES_SIZE EQU _RS - CARDGFXSTRUCT_TILES ; 768
; printer-only (grayscale) alt tiles, of variable length from 0 to 48
DEF CARDGFXSTRUCT_ALT_TILES_START EQU _RS ; $348

View File

@@ -3414,55 +3414,57 @@ LoadLoadedCard1Gfx:
ld a, [hli]
ld h, [hl]
ld l, a
lb bc, CARD_TILE_COUNT, TILE_SIZE
lb bc, NUM_CARD_GFX_TILES, TILE_SIZE
call LoadCardGfx
ret
; applies the tilemap of the loaded card gfx
; to coordinates in de, and loads its palette
; to coordinates in de, and loads its palettes
; starting from BG pal 2
DrawCardGfxToDE_BGPalIndex2:
ld a, [wConsole]
or a
ret z
ld a, $02
call LoadCardPalettesAndAttributes
ld a, 2
call LoadCardPalettesAndBGPAttributes
ret
; applies the tilemap of the loaded card gfx
; to coordinates in de, and loads its palette
; to coordinates in de, and loads its palettes
; starting from BG pal 5
DrawCardGfxToDE_BGPalIndex5:
ld a, [wConsole]
or a
ret z
ld a, $5
call LoadCardPalettesAndAttributes
ld a, 5
call LoadCardPalettesAndBGPAttributes
ret
SetOBPToCardPalette:
; unreferenced
SetOBP5ToCardPalette:
ldgbpal a, SHADE_WHITE, SHADE_LIGHT, SHADE_DARK, SHADE_BLACK
ld [wOBP0], a
ld a, [wConsole]
or a
ret z
ld a, $0d
jr CopyCGBCardPalette
ld a, 8 + 5 ; CGB Object Palette 5 (to 7)
jr CopyCGBCardPalettes_UpdatePalIndex
; de = coordinates
LoadCardPalettesAndAttributes:
LoadCardPalettesAndBGPAttributes:
push de
call CopyCGBCardPalette
call CopyCGBCardPalettes_UpdatePalIndex
pop bc
; copy attributes
; hl = wCardAttrMap holding bg pal index
; copy attributes
push hl
call BCCoordToBGMap0Address
pop hl
call BankswitchVRAM1
ld c, $06
ld c, CARD_GFX_HEIGHT
.loop_copy_attr
ld b, $08
ld b, CARD_GFX_WIDTH
push de
call SafeCopyDataHLtoDE
pop de
@@ -3477,18 +3479,21 @@ LoadCardPalettesAndAttributes:
call BankswitchVRAM0
ret
; a = starting BG palette index to copy to
CopyCGBCardPalette:
; for a = starting BG palette index,
; copy wCardPalettes to bgpal[a, a+1, a+2], and
; update wCardAttrMap with a + (each tile's pal index)
; also return hl = wCardAttrMap
CopyCGBCardPalettes_UpdatePalIndex:
ld c, a
REPT 3 ; *= PAL_SIZE
add a
add a
add a ; *8
ENDR
ld e, a
ld d, $00
ld hl, wBackgroundPalettesCGB
add hl, de
ld de, wCardPalettes
ld b, 3 palettes
ld b, CARDGFXSTRUCT_PALS_SIZE
.loop_copy_pal
ld a, [de]
inc de
@@ -3496,10 +3501,12 @@ CopyCGBCardPalette:
dec b
jr nz, .loop_copy_pal
; de = wCardAttrMap
; de = wCardAttrMap
; overwrite each tile's value with
; (starting BG palette index) + its CARD_GFX_TILE_ATTRMAP_PAL_INDEX (0, 1, 2)
push de
ld b, $30
.asm_56e4
ld b, CARDGFXSTRUCT_TILE_ATTRMAP_SIZE
.loop_load_pal_index
ld a, [de]
rlca
rlca
@@ -3508,7 +3515,7 @@ CopyCGBCardPalette:
ld [de], a
inc de
dec b
jr nz, .asm_56e4
jr nz, .loop_load_pal_index
pop hl
ret

View File

@@ -750,7 +750,7 @@ DrawYourOrOppPlayArea_ActiveCardGfx:
ld a, [hli]
ld h, [hl]
ld l, a
lb bc, CARD_TILE_COUNT, TILE_SIZE
lb bc, NUM_CARD_GFX_TILES, TILE_SIZE
call LoadCardGfx
pop de
push de
@@ -796,7 +796,7 @@ DrawInPlayArea_ActiveCardGfx:
ld a, [hli]
ld h, [hl]
ld l, a
lb bc, CARD_TILE_COUNT, TILE_SIZE
lb bc, NUM_CARD_GFX_TILES, TILE_SIZE
call LoadCardGfx
lb de, 6, 9
bank1call DrawCardGfxToDE_BGPalIndex5
@@ -820,7 +820,7 @@ DrawInPlayArea_ActiveCardGfx:
ld a, [hli]
ld h, [hl]
ld l, a
lb bc, CARD_TILE_COUNT, TILE_SIZE
lb bc, NUM_CARD_GFX_TILES, TILE_SIZE
call LoadCardGfx
lb de, 6, 2
bank1call DrawCardGfxToDE_BGPalIndex2

View File

@@ -5853,14 +5853,10 @@ LoadCardGfx_FromCardID:
add c
ld c, a
ld b, $00
REPT 4 ; *TILE_SIZE
sla c
rl b
sla c
rl b
sla c
rl b
sla c
rl b ; *TILE_SIZE
ENDR
ld hl, v0Tiles1
add hl, bc
ld d, h
@@ -5868,7 +5864,7 @@ LoadCardGfx_FromCardID:
pop hl
xor a
call BankswitchVRAM
lb bc, CARD_TILE_COUNT, TILE_SIZE
lb bc, NUM_CARD_GFX_TILES, TILE_SIZE
call LoadCardGfx
pop hl
pop de
@@ -5883,9 +5879,9 @@ CopyCardPalettesToBGPals:
push de
push hl
ld b, $00
REPT 3 ; *PAL_SIZE
sla c
sla c
sla c ; *PAL_SIZE
ENDR
ld hl, wBackgroundPalettesCGB
add hl, bc
ld d, h
@@ -5930,7 +5926,7 @@ DrawLoadedCard:
ld de, wCardTilemap
ld a, [wCardTilemapOffset]
ld c, a
ld b, $30 ; card size in tiles
ld b, NUM_CARD_GFX_TILES
.loop_copy
ld a, [hli]
add c
@@ -5954,7 +5950,7 @@ DrawLoadedCard:
ld de, wddc4
ld a, [wddf5]
ld c, a
ld b, $30 ; card size in tiles
ld b, NUM_CARD_GFX_TILES
.asm_134f8
ld a, [hli]
rlca
@@ -6002,7 +5998,7 @@ DebugCardViewer:
push bc
push de
push hl
call .asm_1358a
call .DrawBox
ld hl, $0
REPT 2
ld a, (NUM_CARDS - 1) / 2
@@ -6014,47 +6010,51 @@ ENDR
ld d, h
ld e, l
call .Draw
.asm_1354b
.wait_input
call DoFrame
ldh a, [hKeysPressed]
and PAD_A | PAD_B
jr nz, .asm_13559
call .asm_13561
jr .asm_1354b
.asm_13559
call .asm_135ac
jr nz, .exit
call .Scroll
jr .wait_input
.exit
call .ResumeSprites
pop hl
pop de
pop bc
pop af
ret
.asm_13561:
.Scroll:
ldh a, [hDPadHeld]
and $10
jr nz, .asm_1357c
and PAD_RIGHT
jr nz, .handle_forward
ldh a, [hDPadHeld]
and $20
jr nz, .asm_1356e
and PAD_LEFT
jr nz, .handle_backward
ret
.asm_1356e
.handle_backward
ld bc, GRASS_ENERGY
call CompareBCAndDE
jr c, .asm_13579
jr c, .scroll_backward
ld de, NUM_CARDS + 1
.asm_13579
.scroll_backward
dec de
jr .Draw
.asm_1357c
.handle_forward
ld bc, NUM_CARDS - 1
call CompareBCAndDE
jr nc, .asm_13587
jr nc, .scroll_forward
ld de, 0
.asm_13587
.scroll_forward
inc de
jr .Draw
.asm_1358a:
.DrawBox:
lb de, 5, 4
lb bc, 10, 8
call AdjustDECoordByhSC
@@ -6068,7 +6068,7 @@ ENDR
call FillBoxInBGMap
ret
.asm_135ac:
.ResumeSprites:
call CopyBGMapFromWRAMToVRAM
call SetActiveSpriteAnimFlag6WithinArea
ret

View File

@@ -4238,18 +4238,18 @@ PrintCardInfoFooterStripAndFeed:
call SendPrinterInstructionPacket_1Sheet_3LineFeeds
ret
; calls setup text and sets wTilePatternSelector
; calls setup text and sets wTextTileBaseAddressHi to SRAM
SetupPrinterText:
lb de, $40, $bf
call SetupText
ld a, $a4
ld [wTilePatternSelector], a
ld a, HIGH(sGfxBuffer1)
ld [wTextTileBaseAddressHi], a
xor a
ld [wTilePatternSelectorCorrection], a
ld [wTextTileIndexSignednessAdjust], a
ret
; switches to CGB normal speed, resets serial
; enables SRAM and switches to SRAM1
; enables SRAM and switches to SRAM3
; and clears sGfxBuffer0
PrepareForPrinterCommunications:
call SwitchToCGBNormalSpeed
@@ -4385,10 +4385,9 @@ SendTilesToPrinter:
push bc
ld l, a
ld h, $00
REPT 4 ; *TILE_SIZE
add hl, hl
add hl, hl
add hl, hl
add hl, hl ; *TILE_SIZE
ENDR
ld bc, sGfxBuffer1
add hl, bc
ld c, TILE_SIZE
@@ -5468,74 +5467,80 @@ DisplayBoosterContent:
bank1call DisplayCardList
ret
; builds the card's picture for the Game Boy Printer into the buffer at de.
; loads the card's tiles (LoadCardGfxRemapped) into wc000, then walks the
; 8x6-tile portrait in column-major order and repacks each tile's pixel rows
; (through the rr/rra/sra bit sequence) into the print-buffer layout. The
; per-tile palette is dropped, so the printout is a flat grayscale of the card.
; builds at de the 2x scaled card gfx for the Game Boy Printer,
; using printer-only alt tiles where appropriate
; input:
; hl = card gfx index
; de = destination
BuildPrintableCardPic:
push de
ld de, wc000
lb bc, CARD_TILE_COUNT, TILE_SIZE
call LoadCardGfxRemapped ; load the 48 (remapped) card tiles into wc000
pop de ; de = output buffer
ld hl, wc000 ; hl = loaded tiles
ld c, $08 ; 8 tile columns
.col
ld b, $06 ; 6 tile rows (8x6 = 48 tiles)
.row
ld de, wTempPrintableCardPic
lb bc, NUM_CARD_GFX_TILES, TILE_SIZE
call LoadCardGfx_PrinterAlt
pop de
ld hl, wTempPrintableCardPic
ld c, CARD_GFX_WIDTH
.loop_columns
ld b, CARD_GFX_HEIGHT
.loop_rows
push bc
ld c, $08 ; 8 pixel rows per tile
.pixel_row
ld b, $02 ; 2 bytes (bitplanes) per pixel row
.plane
ld c, 8 ; lines per tile
.loop_pixel_rows
; abcdefgh ijklmnop
; -> aabbccdd iijjkkll aabbccdd iijjkkll at (offset)
; eeffgghh mmnnoopp eeffgghh mmnnoopp at (offset + 2*6 tiles)
ld b, 2 ; bytes per line
.loop_bitplanes
push bc
push hl
ld c, [hl] ; c = one bitplane byte (8 pixels)
ld b, $04
.repack_lo
rr c ; pull a source pixel bit...
rra
sra a ; ...and pack it into a
dec b
jr nz, .repack_lo ; the low 4 bits of the byte
ld hl, $c0
add hl, de
ld [hli], a
inc hl
ld [hl], a ; write the packed value to de+$c0 and de+$c0+2
ld b, $04
.repack_hi
ld c, [hl]
; efgh -> eeffgghh
ld b, 4
.loop_right_half
rr c
rra
sra a
dec b
jr nz, .repack_hi ; the high 4 bits of the byte
ld [de], a
ld hl, $2
jr nz, .loop_right_half
ld hl, 2 * CARD_GFX_HEIGHT tiles
add hl, de
ld [hl], a ; write the packed value to de and de+2
ld [hli], a
inc hl
ld [hl], a
; abcd -> aabbccdd
ld b, 4
.loop_left_half
rr c
rra
sra a
dec b
jr nz, .loop_left_half
ld [de], a
ld hl, 2
add hl, de
ld [hl], a
pop hl
pop bc
inc de
inc hl
dec b
jr nz, .plane
jr nz, .loop_bitplanes
inc de
inc de
dec c
jr nz, .pixel_row
jr nz, .loop_pixel_rows
pop bc
dec b
jr nz, .row
ld a, $c0
jr nz, .loop_rows
ld a, 2 * CARD_GFX_HEIGHT tiles
add e
ld e, a
ld a, $00
ld a, 0
adc d
ld d, a ; advance de by $c0 to the next tile-column block
ld d, a
dec c
jr nz, .col
jr nz, .loop_columns
ret
LoadHandCardsIcon:

View File

@@ -2022,7 +2022,7 @@ DrawColorChangeScreen:
ld a, [hli]
ld h, [hl]
ld l, a
lb bc, CARD_TILE_COUNT, TILE_SIZE
lb bc, NUM_CARD_GFX_TILES, TILE_SIZE
call LoadCardGfx
lb de, 9, 2
bank1call DrawCardGfxToDE_BGPalIndex5

View File

@@ -90,7 +90,7 @@ _BillsPC:
ld a, [hli]
ld h, [hl]
ld l, a
lb bc, CARD_TILE_COUNT, TILE_SIZE
lb bc, NUM_CARD_GFX_TILES, TILE_SIZE
ld de, v0Tiles1 + $20 tiles
call LoadCardGfx
ld a, $a0 ; v0Tiles1 + $20 tiles
@@ -112,7 +112,7 @@ _BillsPC:
ld a, [hli]
ld h, [hl]
ld l, a
lb bc, CARD_TILE_COUNT, TILE_SIZE
lb bc, NUM_CARD_GFX_TILES, TILE_SIZE
ld de, v0Tiles1 + $50 tiles
call LoadCardGfx
ld a, $d0 ; v0Tiles1 + $50 tiles
@@ -122,7 +122,7 @@ _BillsPC:
call FillRectangle
bank1call DrawCardGfxToDE_BGPalIndex2
ld de, v0Tiles1 + $10 tiles
ld hl, $36d0
ld hl, DuelCardHeaderGraphics + $20 tiles - $4000
ld b, $10
call CopyFontsOrDuelGraphicsTiles
ld a, $90 ; v0Tiles1 + $10 tiles

View File

@@ -76,7 +76,6 @@ Pals_6f0f0::
rgb 0, 0, 0
rgb 28, 12, 0
rgb 13, 9, 0
; 0x6f108
Pals_6f108::
rgb 31, 31, 31
@@ -84,6 +83,7 @@ Pals_6f108::
rgb 0, 0, 0
rgb 0, 10, 28
Pals_6f110::
rgb 31, 31, 31
rgb 31, 22, 9
rgb 27, 9, 4
@@ -119,17 +119,44 @@ Pals_6f108::
rgb 8, 20, 27
rgb 0, 7, 14
Pals_6f148::
rgb 31, 31, 31
rgb 0, 0, 31
rgb 31, 0, 0
rgb 0, 0, 0
; 0x6f150
SECTION "Gfx 1@7150", ROMX[$7150], BANK[$1b]
SymbolsFont::
INCBIN "gfx/fonts/symbols.2bpp"
DuelGraphics::
DuelCardHeaderGraphics::
INCBIN "gfx/duel/card_type_headers.2bpp"
DuelCgbSymbolGraphics::
INCBIN "gfx/duel/cgb_card_symbols.2bpp"
DuelDmgSgbSymbolGraphics::
INCBIN "gfx/duel/dmg_sgb_card_symbols.2bpp"
DuelOtherGraphics::
INCBIN "gfx/duel/duel_other_gfx.2bpp"
SECTION "Gfx 2", ROMX
DuelCheckPokemonScreenGfx::
INCBIN "gfx/duel/check_pokemon_screen.2bpp"
DuelPlayAreaScreenGfx::
INCBIN "gfx/duel/play_area_screen.2bpp"
DuelPlayAreaScreenGfxDMG::
INCBIN "gfx/duel/play_area_screen_dmg.2bpp"
DuelDeckAndDiscardPileIcons::
INCBIN "gfx/duel/deck_discard_icons.2bpp"
DuelCoinTossResultTiles::
INCBIN "gfx/duel/coin_toss_result_symbols.2bpp"
DuelMenuAndCardPicBorderTiles::
INCBIN "gfx/duel/menu_card_pic_border.2bpp"
DuelDrawCardsScreenIcons::
INCBIN "gfx/duel/draw_cards_icons.2bpp"
DuelBoxMessages::
INCBIN "gfx/duel/box_messages.2bpp"
INCLUDE "gfx/card_graphics.asm"
SECTION "Bank 4b", ROMX

File diff suppressed because it is too large Load Diff

View File

@@ -193,87 +193,95 @@ GetCardPointer:
ret
; input:
; hl = card_gfx_index
; de = where to load the card gfx to
; bc are supposed to be CARD_TILE_COUNT (number of tiles of a card gfx) and TILE_SIZE respectively
; card_gfx_index = (<Name>CardGfx - CardGraphics) / 8 (using absolute ROM addresses)
; also copies the card's palette to wCardPalette
; hl = card gfx index
; de = destination
; b = NUM_CARD_GFX_TILES
; c = TILE_SIZE
; also update wCardPalette and wCardAttrMap
LoadCardGfx::
ldh a, [hBankROM]
push af
call LoadCardPalettes
call LoadCardPalettesAndAttrMap
call CopyGfxData
pop af
call BankswitchROM
ret
; like LoadCardGfx, but reconstructs the 48 card tiles through the card's
; attribute map instead of copying them 1:1. The low 6 bits of each attribute-
; map byte are a tile index relative to that tile's position, so output tile i
; comes from source tile ((wCardAttrMap[i] & $3f) + i) -- identity (= the plain
; portrait) for most cards, but some (e.g. Energy cards) point at extra tiles
; stored right after their portrait. The palette bits (high 2 of each map byte)
; are stripped, leaving just the indices in wCardAttrMap. Used to build the card
; picture for the Game Boy Printer (see BuildPrintableCardPic /
; DrawCardPicInSRAMGfxBuffer2).
; input: hl = card_gfx_index, de = destination, bc = CARD_TILE_COUNT (tiles), TILE_SIZE
LoadCardGfxRemapped::
; LoadCardGfx but with printer-only alt tiles where appropriate
; based on CARD_GFX_TILE_ATTRMAP_ALT_OFFSET
; see BuildPrintableCardPic
; input:
; hl = card gfx index
; de = destination
; b = NUM_CARD_GFX_TILES
; c = TILE_SIZE
LoadCardGfx_PrinterAlt::
ldh a, [hBankROM]
push af
call LoadCardPalettes ; loads palettes + attr map; returns hl = card's tile base
call LoadCardPalettesAndAttrMap
ld a, l
ld [wCardGfxTileBase + 0], a
ld a, h
ld [wCardGfxTileBase + 1], a ; wCardGfxTileBase = base address of the card's tiles
ld [wCardGfxTileBase + 1], a
ld hl, wCardAttrMap
lb bc, CARD_TILE_COUNT, 0 ; b = tiles to emit, c = output position (0..47)
lb bc, NUM_CARD_GFX_TILES, 0
.loop_copy
; mask offset
; offset = 48 + (cur alt tile idx) - (cur tile idx) if has alt,
; 0 otherwise
ld a, [hl]
and $3f ; keep the relative tile index, drop the palette bits
ld [hli], a ; store the stripped index back into wCardAttrMap
and CARD_GFX_TILE_ATTRMAP_ALT_OFFSET
ld [hli], a
push hl
push bc
add c ; relative index + position = absolute source tile number
add c ; += (cur tile idx)
; a = 48 + (cur alt tile idx) if has alt,
; (cur tile idx) otherwise
; get source tile addr
ld l, a
ld h, $00
REPT 4 ; *= TILE_SIZE
add hl, hl
add hl, hl
add hl, hl
add hl, hl ; *TILE_SIZE
ENDR
ld a, [wCardGfxTileBase + 0]
add l
ld l, a
ld a, [wCardGfxTileBase + 1]
adc h
ld h, a ; hl = tile base + tile number * TILE_SIZE = source tile address
ld h, a
; copy tile
ld b, TILE_SIZE
call SafeCopyDataHLtoDE ; copy this tile to de, advancing de
call SafeCopyDataHLtoDE
pop bc
pop hl
inc c ; advance output position
inc c
dec b
jr nz, .loop_copy
pop af
call BankswitchROM
ret
LoadCardPalettes:
; hl = card gfx index
; store into wCardPalettes and wCardAttrMap
; also return hl = card tile address
LoadCardPalettesAndAttrMap:
push bc
push de
push hl
ld a, h
REPT 3 ; /= 8
srl a
srl a
srl a ; /8
ENDR
add BANK(CardGraphics)
call BankswitchROM
pop hl
REPT 3 ; *= 8
add hl, hl
add hl, hl
add hl, hl ; *8
ENDR
res 7, h
set 6, h ; $4000 ≤ hl ≤ $7fff
ld b, 3 palettes + CARD_TILE_COUNT ; palettes + 1 attribute byte per tile
ld b, CARDGFXSTRUCT_PALS_SIZE + CARDGFXSTRUCT_TILE_ATTRMAP_SIZE
ld de, wCardPalettes
.loop_copy
ld a, [hli]

View File

@@ -11,11 +11,9 @@ EmptyScreen::
BCCoordToBGMap0Address::
ld l, c
ld h, $0
REPT 5 ; *TILEMAP_WIDTH
add hl, hl
add hl, hl
add hl, hl
add hl, hl
add hl, hl
ENDR
ld c, b
ld b, HIGH(v0BGMap0)
add hl, bc

View File

@@ -148,10 +148,10 @@ SetupText::
xor a
ldh [hffbb], a
ldh [hTextTileCacheHead], a
ld a, $88
ld [wTilePatternSelector], a
ld a, HIGH(v0Tiles1)
ld [wTextTileBaseAddressHi], a
ld a, $80
ld [wTilePatternSelectorCorrection], a
ld [wTextTileIndexSignednessAdjust], a
ld hl, wc600
.clear_loop
xor a
@@ -207,9 +207,9 @@ InitTextPrinting::
; requests a text tile to be generated and prints it in the screen
; different modes depending on hffbb:
; hffbb == $0: generate and place text tile
; hffbb == $2 (bit 1 set): only generate text tile?
; hffbb == $1 (bit 0 set): not even generate it, but just update text buffers?
; hffbb == $0: generate and place text tile
; hffbb == $2 (bit 1 set): only generate text tile?
; hffbb == $1 (bit 0 set): not even generate it, but just update text buffers?
GenerateAndPlaceTextTile::
push hl
push de
@@ -594,12 +594,12 @@ CreateHalfWidthFontTile::
; the ascii value of the character to copy is provided in a.
; assumes BANK(HalfWidthFont) is already loaded.
CopyHalfWidthCharacterToDE::
sub $20 ; HalfWidthFont begins at ascii $20
sub HALFWIDTH_CHAR_START
ld l, a
ld h, $0
REPT 3 ; *TILE_SIZE_1BPP
add hl, hl
add hl, hl
add hl, hl
ENDR
ld bc, HalfWidthFont
add hl, bc
ld b, TILE_SIZE_1BPP
@@ -622,21 +622,19 @@ CreateFullWidthFontTile_ConvertToTileDataAddress::
pop bc
; fallthrough
; given a tile number in b, return its v*Tiles address in hl, and return c = TILE_SIZE
; wTilePatternSelector and wTilePatternSelectorCorrection are used to select the source:
; - if wTilePatternSelector == $80 and wTilePatternSelectorCorrection == $00 -> $8000-$8FFF
; - if wTilePatternSelector == $88 and wTilePatternSelectorCorrection == $80 -> $8800-$97FF
; given a tile number in b, return its tile address in hl, and return c = TILE_SIZE
; default: VRAM, LCDC_BLOCK21
; printer: SRAM, as if LCDC_BLOCK01
ConvertTileNumberToTileDataAddress::
ld hl, wTilePatternSelectorCorrection
ld hl, wTextTileIndexSignednessAdjust
ld a, b
xor [hl]
ld h, $0
ld l, a
REPT 4 ; *TILE_SIZE
add hl, hl
add hl, hl
add hl, hl
add hl, hl
ld a, [wTilePatternSelector]
ENDR
ld a, [wTextTileBaseAddressHi]
ld b, a
ld c, $0
add hl, bc
@@ -673,7 +671,7 @@ ClassifyTextCharacterPair::
ld a, e
cp TX_CTRL_END
jr c, .continue_check
cp $60
cp FULLWIDTH0_CHAR_START
jr nc, .not_katakana
ldh a, [hJapaneseSyllabary]
cp TX_KATAKANA
@@ -754,18 +752,18 @@ PromoteTextTileCacheEntry::
ldh a, [hTextTileCacheHead]
ld l, a ; l ← [hTextTileCacheHead]; index to to linked-list head
.asm_237d
ld h, $c6 ;
ld h, HIGH(wc600) ;
ld a, [hl] ; a ← key1[l] ;
or a ;
ret z ; if NULL, return a = 0 ;
cp e ; loop for e/d key in
jr nz, .asm_238a ; ; linked list
inc h ; $c7 ; ;
inc h ; HIGH(wc700) ; ;
ld a, [hl] ; if key1[l] == e and ;
cp d ; key2[l] == d: ;
jr z, .asm_238f ; break ;
.asm_238a
ld h, $c8 ; ;
ld h, HIGH(wc800) ; ;
ld l, [hl] ; l ← next[l] ;
jr .asm_237d
.asm_238f
@@ -773,20 +771,20 @@ PromoteTextTileCacheEntry::
cp l
jr z, .asm_23af ; assert at least one iteration
ld c, a
ld b, $c9
ld b, HIGH(wc900)
ld a, l
ld [bc], a ; prev[i0] ← i
ldh [hTextTileCacheHead], a ; [hTextTileCacheHead] ← i (update linked-list head)
ld h, $c9
ld h, HIGH(wc900)
ld b, [hl]
ld [hl], $0 ; prev[i] ← 0
ld h, $c8
ld h, HIGH(wc800)
ld a, c
ld c, [hl]
ld [hl], a ; next[i] ← i0
ld l, b
ld [hl], c ; next[prev[i]] ← next[i]
ld h, $c9
ld h, HIGH(wc900)
inc c
dec c
jr z, .asm_23af ; if next[i] != NULL:
@@ -802,9 +800,9 @@ CaseHalfWidthLetter::
or a
ret z
ld a, e
cp $60
cp 'a' - 1
ret c
cp $7b
cp 'z' + 1
ret nc
sub 'a' - 'A'
ld e, a

View File

@@ -28,5 +28,5 @@ Start:
call ValidateSRAM
ld a, BANK(GameLoop)
call BankswitchROM
ld sp, $d000
ld sp, wStackTop
jp GameLoop

View File

@@ -20,11 +20,9 @@ SafeCopyDataDEtoHL:
DECoordToBGMap0Address:
ld l, e
ld h, $0
REPT 5 ; *TILEMAP_WIDTH
add hl, hl
add hl, hl
add hl, hl
add hl, hl
add hl, hl
ENDR
ld a, l
add d
ld l, a

View File

@@ -60,10 +60,9 @@ LoadCardSet2Tiles::
ret z
ld l, a
ld h, 0
REPT 4 ; *TILE_SIZE
add hl, hl
add hl, hl
add hl, hl
add hl, hl
ENDR
ld de, DuelOtherGraphics + $1d tiles - $4000 ; card set 2 icons
add hl, de
ld de, v0Tiles1 + $7c tiles
@@ -146,14 +145,16 @@ LoadDuelCardSymbolTiles2::
; load the Deck and the Discard Pile icons
LoadDeckAndDiscardPileIcons::
ld hl, $3148
ld de, $cb16
ld c, $08
ld hl, Pals_6f148 - $4000
ld de, wBackgroundPalettesCGB + 5 palettes
ld c, PAL_SIZE
call CopyFontsOrDuelGraphicsBytes
ld hl, DuelDeckAndDiscardPileIcons
ld de, $8a00
ld de, v0Tiles1 + $20 tiles
ld b, $0d
call CopyFontsOrDuelGraphicsTiles
; fallthrough
; load the tiles for the player's / opponent's Play Area screen
; (uses a separate set of tiles on CGB vs DMG/SGB)
LoadDuelPlayAreaScreenTiles::
@@ -169,9 +170,9 @@ LoadDuelPlayAreaScreenTiles::
; load the tiles for the [O] and [X] symbols used to display the results of a coin toss
LoadDuelCoinTossResultTiles::
ld hl, $3108
ld de, $cafe
ld c, $08
ld hl, Pals_6f108 - $4000
ld de, wBackgroundPalettesCGB + 2 palettes
ld c, PAL_SIZE
call CopyFontsOrDuelGraphicsBytes
ld hl, DuelCoinTossResultTiles
ld de, v0Tiles2 + $30 tiles
@@ -215,10 +216,9 @@ LoadCardSymbolFontTilesToSRAM::
sub $d0
ld l, a
ld h, $00
REPT 4 ; *TILE_SIZE
add hl, hl
add hl, hl
add hl, hl
add hl, hl ; *16
ENDR
ld de, DuelDmgSgbSymbolGraphics - $4000
add hl, de
ld de, sGfxBuffer1 + $38 tiles
@@ -237,10 +237,10 @@ DrawDuelBoxMessage::
add a
ld e, a
ld d, 0
ld hl, $3110
ld hl, Pals_6f110 - $4000
add hl, de
ld de, $cafe
ld c, 8
ld de, wBackgroundPalettesCGB + 2 palettes
ld c, PAL_SIZE
call CopyFontsOrDuelGraphicsBytes
call BankswitchVRAM1
ld a, 2
@@ -259,7 +259,7 @@ DrawDuelBoxMessage::
ld de, v0Tiles1 + $20 tiles
ld b, 40
call CopyFontsOrDuelGraphicsTiles
ld a, $a0
ld a, $a0 ; v0Tiles1 + $20 tiles
lb hl, 1, 10
; fallthrough
@@ -305,6 +305,7 @@ Copy1bppTiles::
jr nz, .tile_loop
ret
; copy c bytes from BANK(Fonts):hl to de
CopyFontsOrDuelGraphicsBytes::
ld a, BANK(Fonts) ; BANK(DuelGraphics)
call BankpushROM

View File

@@ -84,8 +84,60 @@ ROMX $1a
"Effect Functions 1"
ROMX $1b
"Gfx 1"
; Card graphics ($1b:74d0-$36) are pinned via BANK[]/ROMX[] in
; gfx/card_graphics.asm, so they are not assigned here.
ROMX $1c
"Gfx 2"
ROMX $1d
"Card Gfx 1"
ROMX $1e
"Card Gfx 2"
ROMX $1f
"Card Gfx 3"
ROMX $20
"Card Gfx 4"
ROMX $21
"Card Gfx 5"
ROMX $22
"Card Gfx 6"
ROMX $23
"Card Gfx 7"
ROMX $24
"Card Gfx 8"
ROMX $25
"Card Gfx 9"
ROMX $26
"Card Gfx 10"
ROMX $27
"Card Gfx 11"
ROMX $28
"Card Gfx 12"
ROMX $29
"Card Gfx 13"
ROMX $2a
"Card Gfx 14"
ROMX $2b
"Card Gfx 15"
ROMX $2c
"Card Gfx 16"
ROMX $2d
"Card Gfx 17"
ROMX $2e
"Card Gfx 18"
ROMX $2f
"Card Gfx 19"
ROMX $30
"Card Gfx 20"
ROMX $31
"Card Gfx 21"
ROMX $32
"Card Gfx 22"
ROMX $33
"Card Gfx 23"
ROMX $34
"Card Gfx 24"
ROMX $35
"Card Gfx 25"
ROMX $36
"Card Gfx 26"
ROMX $37
"Text Offsets"
ROMX $38

View File

@@ -103,6 +103,23 @@ MACRO? gfx
dw ($4000 * (BANK(\1) - BANK(CardGraphics)) + ((\1) - $4000)) / 8
ENDM
; card gfx tile attrmap
MACRO? gfx_attrmap_start
DEF _current_card_tile_idx = 0
DEF _current_alt_card_tile_idx = 0
ENDM
; \1 = palette index
; \2 = has-alt flag (TRUE/FALSE)
MACRO? gfx_attrmap
IF \2 > 0 ; TRUE
db \1 << 6 | (48 + _current_alt_card_tile_idx - _current_card_tile_idx)
DEF _current_alt_card_tile_idx += 1
ELSE ; FALSE
db \1 << 6
ENDC
DEF _current_card_tile_idx += 1
ENDM
; \1 = y offset
; \2 = x offset
; \3 = vtile

View File

@@ -17,6 +17,12 @@ wc000:: ; c000
NEXTU
; actually $300 bytes, extending into WRAM0 Duels 1
wTempPrintableCardPic:: ; c000
; ds CARDGFXSTRUCT_TILES_SIZE
NEXTU
; aside from wDecompressionBuffer, which stores the
; de facto final decompressed data after decompression,
; this buffer stores a secondary buffer that is used
@@ -1073,15 +1079,18 @@ wcd04:: ; cd6d
wCurTextTile:: ; cd6e
ds $1
; VRAM tile patterns selector for text tiles
; if wTilePatternSelector == $80 and wTilePatternSelectorCorrection == $00 -> select tiles at $8000-$8FFF
; if wTilePatternSelector == $88 and wTilePatternSelectorCorrection == $80 -> select tiles at $8800-$97FF
wTilePatternSelector:: ; cd6f
; text tile location
; must use the same mode as wTextTileIndexSignednessAdjust
; HIGH(v*Tiles1) = default (LCDC_BLOCK21)
; HIGH(sGfxBuffer1) = printer
wTextTileBaseAddressHi:: ; cd6f
ds $1
; complements wTilePatternSelector by correcting the VRAM tile order when $8800-$97FF is selected
; a value of $80 in wTilePatternSelectorCorrection reflects tiles $00-$7f being located after tiles $80-$ff
wTilePatternSelectorCorrection:: ; cd70
; VRAM tile index converter (xor) for LCDC_BLOCK21 signed addressing
; must use the same mode as wTextTileBaseAddressHi
; $80 (signed) = default (LCDC_BLOCK21)
; $00 (unsigned) = printer, as if LCDC_BLOCK01
wTextTileIndexSignednessAdjust:: ; cd70
ds $1
; if 0, text lines are separated by a blank line
@@ -1127,10 +1136,10 @@ wEffectFunctionsBank:: ; cd79
ds $1
wCardPalettes:: ; cd7a
ds 3 palettes
ds CARDGFXSTRUCT_PALS_SIZE
wCardAttrMap:: ; cd92
ds $30
ds CARDGFXSTRUCT_TILE_ATTRMAP_SIZE
; information about the text being currently processed, including font width,
; the rom bank, and the memory address of the next character to be printed.
@@ -1187,7 +1196,7 @@ wIsTextBoxLabeled:: ; cde2
wTextBoxLabel:: ; cde3
ds $2
; base address of the card's tiles, set up by LoadCardGfxRemapped
; base address of the card's tiles, set up by LoadCardGfx_PrinterAlt
wCardGfxTileBase:: ; cde5
ds $2
@@ -1395,6 +1404,13 @@ wBGColorFadeConfigList:: ; cece
wOBColorFadeConfigList:: ; ceee
ds (NUM_OBJECT_PALETTES palettes) / 2
; stack occupies the remainder of WRAM0
SECTION "Stack", WRAM0
wStackBottom::
ds $f2
wStackTop:: ; d000
SECTION "WRAM1", WRAMX
; stores a pointer to a temporary list of elements (e.g. pointer to wDuelTempList)

View File

@@ -5,7 +5,7 @@ baserom overlay into per-card sources + an asm layout.
Card format (uncompressed, fixed 840 B), starting at CardGraphics + index*8:
72-byte header = 3 GBC palettes (24 B) + a 48-entry attribute map.
Each map byte's high 2 bits pick that tile's palette; the
low 6 bits are a tile index used by the alternate (LoadCardGfxRemapped)
low 6 bits are a tile index used by the alternate (LoadCardGfx_PrinterAlt)
renderer. The portrait loader copies the 48 tiles 1:1, so for
the portrait each tile uses exactly one palette.
768-byte tiles = 48 stored tiles x TILE_SIZE (column-major).
@@ -98,7 +98,7 @@ def header_asm(hdr):
def extra_tile_bytes(rom, a):
"""bytes of printer tiles a card references past its 48-tile portrait.
LoadCardGfxRemapped reads source tile (attr[i]&$3f)+i; anything above 47
LoadCardGfx_PrinterAlt reads source tile (attr[i]&$3f)+i; anything above 47
lives in the card's extra tiles right after the portrait."""
attr = rom[a+24:a+72]
return max(0, max((b & 0x3f) + j for j, b in enumerate(attr)) - 47) * 16
@@ -121,7 +121,7 @@ def build_segments(rom, byaddr):
"""Walk the region into typed segments:
pre - un-indexed gfx before CardGraphics ($1b tail, $1c)
card - the 840-byte portrait blob
extra - the card's printer tiles (read by LoadCardGfxRemapped)
extra - the card's printer tiles (read by LoadCardGfx_PrinterAlt)
pad - 0x00/0xff alignment between cards
Misc/pad are split at 0x4000 bank boundaries."""
starts = sorted(byaddr)
@@ -251,7 +251,7 @@ def main():
header = (
"; Card graphics. Each \"<Name>CardGfx\": 3 GBC palettes (rgb) + a 48-entry\n"
"; attribute map (db; high 2 bits = each tile's palette, low 6 = a tile index\n"
"; for the alternate LoadCardGfxRemapped renderer), then INCBIN of the 48\n"
"; for the alternate LoadCardGfx_PrinterAlt renderer), then INCBIN of the 48\n"
"; portrait tiles (built from gfx/cards/<name>.png, 4-shade grayscale, column-\n"
"; major). A \"<Name>CardGfxExtra\" + INCBIN follows for cards whose printer\n"
"; rendering pulls in extra tiles past the portrait; `ds` runs are inter-card\n"