summaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/bank07.asm5
-rw-r--r--src/engine/bank1c.asm102
-rw-r--r--src/engine/bank20.asm52
3 files changed, 137 insertions, 22 deletions
diff --git a/src/engine/bank07.asm b/src/engine/bank07.asm
index e2922bb..ed87acc 100644
--- a/src/engine/bank07.asm
+++ b/src/engine/bank07.asm
@@ -50,7 +50,8 @@ Func_1c056: ; 1c056 (7:4056)
INCLUDE "data/warps.asm"
-Func_1c33b: ; 1c33b (7:433b)
+; loads data from the map header of wCurMap
+LoadCurMapHeaderData: ; 1c33b (7:433b)
push hl
push bc
push de
@@ -66,7 +67,7 @@ Func_1c33b: ; 1c33b (7:433b)
ld a, [hli]
ld [wCurTilemap], a
ld a, [hli]
- ld c, a
+ ld c, a ; CGB tilemap variant
ld a, [hli]
ld [wd28f], a
ld a, [hli]
diff --git a/src/engine/bank1c.asm b/src/engine/bank1c.asm
index 15a4647..b94729a 100644
--- a/src/engine/bank1c.asm
+++ b/src/engine/bank1c.asm
@@ -330,5 +330,103 @@ Func_70214: ; 70214 (1c:4214)
Unknown_7024a: ; 7024a (1c:424a)
INCROM $7024a, $7036a
-Func_7036a: ; 7036a (1c:436a)
- INCROM $7036a, $74000
+; decompresses palette data depending on wd132
+; then sends it as SGB packet
+SetSGB2AndSGB3MapPalette: ; 7036a (1c:436a)
+ ld a, [wConsole]
+ cp CONSOLE_SGB
+ ret nz ; return if not SGB
+ ld a, [wd132]
+ or a
+ ret z ; not valid
+
+ push hl
+ push bc
+ push de
+ ld a, [wd132]
+ add a
+ ld c, a
+ ld b, $0
+ ld hl, .pal_data_pointers
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call DecompressSGBPalette
+
+ ; load palettes to wTempSGBPacket
+ ld hl, wBGMapBuffer
+ ld de, wTempSGBPacket + 1 ; PAL Packet color #0 (PAL23's SGB2)
+ ld bc, 8 ; pal size
+ call CopyDataHLtoDE
+ ld hl, wBGMapBuffer + 34
+ ld de, wTempSGBPacket + 9 ; PAL Packet color #4 (PAL23's SGB3)
+ ld bc, 6
+ call CopyDataHLtoDE
+
+ xor a
+ ld [wTempSGBPacket + 15], a
+ ld hl, wTempSGBPacket
+ ld a, $1
+ ld [hl], a
+ call Func_704c7
+ call SendSGB
+ pop de
+ pop bc
+ pop hl
+ ret
+
+.pal_data_pointers
+ dw $722f ; unused
+ dw $722f ; MAP_SGB_PALETTE_1
+ dw $7253 ; MAP_SGB_PALETTE_2
+ dw $7277 ; MAP_SGB_PALETTE_3
+ dw $729a ; MAP_SGB_PALETTE_4
+ dw $72bd ; MAP_SGB_PALETTE_5
+ dw $72e0 ; MAP_SGB_PALETTE_6
+ dw $7304 ; MAP_SGB_PALETTE_7
+ dw $7328 ; MAP_SGB_PALETTE_8
+ dw $734b ; MAP_SGB_PALETTE_9
+ dw $736f ; MAP_SGB_PALETTE_10
+
+ INCROM $703cb, $70403
+
+DecompressSGBPalette: ; 70403 (1c:4403)
+ push hl
+ push bc
+ push de
+ ld c, [hl]
+ inc hl
+ ld b, [hl]
+ inc hl
+ push bc
+ ld e, l
+ ld d, h
+ ld b, HIGH(wc000)
+ call InitBGMapDecompression
+ pop bc
+ ld de, wBGMapBuffer
+ call DecompressBGMap
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x7041d
+
+ INCROM $7041d, $704c7
+
+; load some values to wTempSGBPacket
+Func_704c7: ; 704c7 (1c:44c7)
+ push af
+ push hl
+ inc hl
+ ld a, $9c
+ ld [hli], a
+ ld a, $63
+ ld [hl], a
+ pop hl
+ pop af
+ ret
+; 0x704d3
+
+ INCROM $704d3, $74000
diff --git a/src/engine/bank20.asm b/src/engine/bank20.asm
index 5b4de83..639f31a 100644
--- a/src/engine/bank20.asm
+++ b/src/engine/bank20.asm
@@ -1,8 +1,22 @@
Func_80000: ; 80000 (20:4000)
- INCROM $80000, $80028
+ call ClearSRAMBGMaps
+ xor a
+ ld [wTextBoxFrameType], a
+ call Func_8003d
+ farcall Func_c37a
+ farcall Func_c9c7
+ call Func_801a1
+ farcall Func_c3ff
+ ld a, [wCurMap]
+ cp $00
+ ret nz
+ farcall Func_10f2e
+ farcall Func_10fbc
+ ret
+; 0x80028
Func_80028: ; 80028 (20:4028)
- call Func_801f1
+ call ClearSRAMBGMaps
ld bc, $0000
call Func_80077
farcall Func_c9c7
@@ -12,8 +26,8 @@ Func_80028: ; 80028 (20:4028)
; 0x8003d
Func_8003d: ; 8003d (20:403d)
- farcall Func_1c33b
- farcall Func_7036a
+ farcall LoadCurMapHeaderData
+ farcall SetSGB2AndSGB3MapPalette
ld bc, $0
call Func_80077
ld a, $80
@@ -38,12 +52,12 @@ Func_8003d: ; 8003d (20:403d)
; 0x80077
Func_80077: ; 80077 (20:4077)
- ld a, $1
- ld [wBGMapCopyMode], a
+ ld a, TRUE
+ ld [wWriteBGMapToSRAM], a
jr Func_80082
xor a
- ld [wBGMapCopyMode], a
+ ld [wWriteBGMapToSRAM], a
; fallthrough
Func_80082: ; 80082 (20:4082)
@@ -213,13 +227,13 @@ Func_80148: ; 80148 (20:4148)
ret
; copies BG Map data pointed by hl
-; to either VRAM or SRAM, depending on wBGMapCopyMode
+; 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 s0BGMap or s1BGMap
; for VRAM0 or VRAM1 respectively
CopyBGDataToVRAMOrSRAM: ; 8016e (20:416e)
- ld a, [wBGMapCopyMode]
+ ld a, [wWriteBGMapToSRAM]
or a
jp z, SafeCopyDataHLtoDE
@@ -307,16 +321,16 @@ Func_801a1: ; 801a1 (20:41a1)
pop hl
ret
-; Clears the first x800 bytes of S1:a000
-Func_801f1: ; 801f1 (20:41f1)
+; clears s0BGMap and s1BGMap
+ClearSRAMBGMaps: ; 801f1 (20:41f1)
push hl
push bc
ldh a, [hBankSRAM]
push af
- ld a, $1
+ ld a, BANK(s0BGMap) ; SRAM 1
call BankswitchSRAM
- ld hl, $a000
- ld bc, $0800
+ ld hl, s0BGMap
+ ld bc, $800 ; s0BGMap + s1BGMap
xor a
call FillMemoryWithA
pop af
@@ -1110,8 +1124,8 @@ Func_80b89: ; 80b89 (20:4b89)
push bc
push af
ld c, a
- ld a, $01
- ld [wBGMapCopyMode], a
+ ld a, TRUE
+ ld [wWriteBGMapToSRAM], a
ld b, $00
ld hl, wd323
add hl, bc
@@ -1129,9 +1143,9 @@ Func_80b89: ; 80b89 (20:4b89)
Func_80ba4: ; 80ba4 (20:4ba4)
push af
xor a
- ld [wBGMapCopyMode], a
+ ld [wWriteBGMapToSRAM], a
pop af
-; Fallthrough
+; fallthrough
Func_80baa: ; 80baa (20:4baa)
push hl
@@ -1150,11 +1164,13 @@ Func_80baa: ; 80baa (20:4baa)
push af
ld a, [wd23a + 1]
push af
+
ld b, $0
ld hl, wd323
add hl, bc
ld a, $1
ld [hl], a
+
ld a, c
add a
ld c, a