diff options
Diffstat (limited to 'engine')
-rw-r--r-- | engine/bg_map_attributes.asm | 219 | ||||
-rwxr-xr-x | engine/palettes.asm | 24 |
2 files changed, 238 insertions, 5 deletions
diff --git a/engine/bg_map_attributes.asm b/engine/bg_map_attributes.asm new file mode 100644 index 00000000..5adfd038 --- /dev/null +++ b/engine/bg_map_attributes.asm @@ -0,0 +1,219 @@ +INCLUDE "data/bg_map_attributes.asm" + +LoadBGMapAttributes:: ; bf450 (2f:7450) + ld hl, BGMapAttributesPointers + ld a, c ; c = which packet + push af ; save for later (to determine if we're handling the trainer card or party menu) + dec a ; read this code as: + add a ; dec a + ld e, a ; add a + xor a ; ld e, a + ld d, a ; ld d, 0 + add hl, de ; add hl, de + ld a, [hli] ; ld a, [hli] + ld e, a ; ld h, [hl] + ld a, [hl] ; ld l, a + ld h, a + ld a, e + ld l, a + + di + ld a, $1 + ld [rVBK], a + push hl + ld a, [hl] + ld c, a ; save attribute count for later + ld de, $10 + add hl, de + ld a, h + ld [rHDMA1], a + ld a, l + ld [rHDMA2], a + ld de, vBGMap0 + ld a, d + ld [rHDMA3], a + ld a, e + ld [rHDMA4], a + + ld a, [rLCDC] + and rLCDC_ENABLE_MASK ; is LCD off? + jr z, .lcdOff ; if off, transfer immediately +; wait for VBlank if LCD is on +.waitForVBlankLoop1 + ld a, [rLY] + cp $90 + jr nz, .waitForVBlankLoop1 +.waitForAccessibleVRAMLoop1 + ld a, [rSTAT] + and %10 ; are we in HBlank or VBlank? + jr nz, .waitForAccessibleVRAMLoop1 ; loop until we're in a safe period to transfer to VRAM +.lcdOff + ld a, c ; number of BG attributes to transfer, plus 1 times 16 + ld [rHDMA5], a ; initiate transfer + call Func_3082 ; update audio so it doesn't "lag" + pop hl + ld a, [hli] + ld c, a ; number of BG attributes to transfer, plus 1 times 16 + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a ; offset of the attributes + add hl, de ; hl = new pointer + ld a, h + ld [rHDMA1], a + ld a, l + ld [rHDMA2], a + ld de, vBGMap1 ; copy to vBGMap1 + ld a, d + ld [rHDMA3], a + ld a, e + ld [rHDMA4], a +; LCD check again + ld a, [rLCDC] + and rLCDC_ENABLE_MASK ; is LCD off? + jr z, .lcdOff2 ; if off, transfer immediately +; wait for VBlank if LCD is on +.waitForVBlankLoop2 + ld a, [rLY] + cp $90 + jr nz, .waitForVBlankLoop2 +.waitForAccessibleVRAMLoop2 + ld a, [rSTAT] + and %10 ; are we in HBlank or VBlank? + jr nz, .waitForAccessibleVRAMLoop2 ; loop until we're in a safe period to transfer to VRAM +.lcdOff2 + ld a, c + ld [rHDMA5], a + pop af + dec a + dec a + dec a + dec a + jr nz, .checkIfHandlingPartyMenu + call HandleBadgeFaceAttributes + jr .done +.checkIfHandlingPartyMenu + dec a + call z, HandlePartyHPBarAttributes +.done + call Func_3082 + ld a, [rIF] + res VBLANK, a + ld [rIF], a + xor a + ld [rVBK], a + ei + ret + +BGMapAttributesPointers: ; bf4de (2f:74de) + dw BGMapAttributes1 + dw BGMapAttributes2 + dw BGMapAttributes3 + dw BGMapAttributes4 + dw BGMapAttributes5 + dw BGMapAttributes6 + dw BGMapAttributes7 + dw BGMapAttributes8 + dw BGMapAttributes9 + dw BGMapAttributes10 + dw BGMapAttributes11 + dw BGMapAttributes12 + dw BGMapAttributes13 + +HandleBadgeFaceAttributes: ; bf4f8 (2f:74f8) +; zero out the attributes if the player doesn't have the respective badge +; BOULDERBADGE + ld hl, vBGMap1 + $183 + ld de, wTrainerCardBadgeAttributes + 6 * 0 + ld a, [de] + and a + call z, ZeroOutCurrentBadgeAttributes +; CASCADEBADGE + ld hl, vBGMap1 + $187 + ld de, wTrainerCardBadgeAttributes + 6 * 1 + ld a, [de] + and a + call z, ZeroOutCurrentBadgeAttributes +; THUNDERBADGE + ld hl, vBGMap1 + $18b + ld de, wTrainerCardBadgeAttributes + 6 * 2 + ld a, [de] + and a + call z, ZeroOutCurrentBadgeAttributes +; RAINBOWBADGE + ld hl, vBGMap1 + $18f + ld de, wTrainerCardBadgeAttributes + 6 * 3 + ld a, [de] + and a + call z, ZeroOutCurrentBadgeAttributes +; SOULBADGE + ld hl, vBGMap1 + $1e3 + ld de, wTrainerCardBadgeAttributes + 6 * 6 + ld a, [de] + and a + call z, ZeroOutCurrentBadgeAttributes +; MARSHBADGE + ld hl, vBGMap1 + $1e7 + ld de, wTrainerCardBadgeAttributes + 6 * 7 + ld a, [de] + and a + call z, ZeroOutCurrentBadgeAttributes +; VOLCANOBADGE + ld hl, vBGMap1 + $1eb + ld de, wTrainerCardBadgeAttributes + 6 * 8 + ld a, [de] + and a + call z, ZeroOutCurrentBadgeAttributes +; EARTHBADGE + ld hl, vBGMap1 + $1ef + ld de, wTrainerCardBadgeAttributes + 6 * 9 + ld a, [de] + and a + call z, ZeroOutCurrentBadgeAttributes + ret + +ZeroOutCurrentBadgeAttributes: ; bf551 (2f:7551) + push hl + xor a + ld [hli], a + ld [hl], a + ld bc, $1f + add hl, bc + ld [hli], a + ld [hl], a + pop hl + ret + +HandlePartyHPBarAttributes: ; bf55d (2f:755d) +; hp bars require 3 (green, orange, red) colours, when there are only 2 "free" colours per palette +; therefore, we must transfer individual bg attributes where the locations of the hp bars are in vram + ld hl, vBGMap1 + $25 ; location of start of the HP bar in vram + ld de, wPartyHPBarAttributes + ld c, PARTY_LENGTH +.loop + push bc + push hl + ld a, [de] + and $3 ; 4 possible palettes + rept 7 ; hp bar length in tiles + ld [hli], a + endr + pop hl + ld bc, $40 ; get 2nd party location + add hl, bc + push hl + + push de ; (inefficiently) copy de to hl + pop hl + + ld bc, $6 + add hl, bc ; get the next palette + + push hl + pop de ; copy back to de + + pop hl + pop bc + dec c + jr nz, .loop + ret
\ No newline at end of file diff --git a/engine/palettes.asm b/engine/palettes.asm index 94b20469..1b16f845 100755 --- a/engine/palettes.asm +++ b/engine/palettes.asm @@ -1116,9 +1116,10 @@ _UpdateGBCPal_OBP:: ; 7256c (1c:656c) ret Func_725be:: ; 725be (1c:65be) +; translate the sgb pal packets into something usable for the CGB push hl pop de - ld hl,Pointer_725e2 + ld hl,PalPacketPointers ld a,[hli] ld c,a .asm_725c5 @@ -1141,12 +1142,25 @@ Func_725be:: ; 725be (1c:65be) jr nz,.asm_725c5 ret .asm_725d9 - callba Func_bf450 ; 2f:7250 + callba LoadBGMapAttributes ; 2f:7250 ret -Pointer_725e2:: ; 725e2 (1c:65e2) - db $0c,$11,$66,$21,$66,$41,$66,$51,$66,$61,$66,$81,$66,$a1,$66,$2d - db $cf,$5b,$cc,$31,$67,$2c,$cf,$51,$67 +PalPacketPointers:: ; 725e2 (1c:65e2) + db (palPacketPointersEnd - palPacketPointers) / $2 +palPacketPointers + dw BlkPacket_WholeScreen + dw BlkPacket_Battle + dw BlkPacket_StatusScreen + dw BlkPacket_Pokedex + dw BlkPacket_Slots + dw BlkPacket_Titlescreen + dw BlkPacket_NidorinoIntro + dw wPartyMenuBlkPacket + dw wTrainerCardBlkPacket + dw BlkPacket_GameFreakIntro + dw wPalPacket + dw UnknownPacket_72751 +palPacketPointersEnd CopySGBBorderTiles: ; 725fb (1c:65fb) ; SGB tile data is stored in a 4BPP planar format. |