summaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/bank03.asm2
-rw-r--r--src/engine/bank1c.asm116
-rw-r--r--src/engine/bank20.asm2
-rw-r--r--src/engine/home.asm121
4 files changed, 147 insertions, 94 deletions
diff --git a/src/engine/bank03.asm b/src/engine/bank03.asm
index 3657fb5..700ebb4 100644
--- a/src/engine/bank03.asm
+++ b/src/engine/bank03.asm
@@ -496,7 +496,7 @@ Func_c38f: ; c38f (3:438f)
jr z, .skip
push hl
- ld b, HIGH(wc000)
+ ld b, HIGH(wDecompressionSecondaryBuffer)
call InitDataDecompression
ld a, [wd23d]
ld [wTempPointerBank], a
diff --git a/src/engine/bank1c.asm b/src/engine/bank1c.asm
index 1408f18..2207d2e 100644
--- a/src/engine/bank1c.asm
+++ b/src/engine/bank1c.asm
@@ -260,7 +260,7 @@ Func_701e9: ; 701e9 (1c:41e9)
push bc
ld e, l
ld d, h
- ld b, HIGH(wc000)
+ ld b, HIGH(wDecompressionSecondaryBuffer)
call InitDataDecompression
pop bc
pop de
@@ -377,17 +377,17 @@ SetSGB2AndSGB3MapPalette: ; 7036a (1c:436a)
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
+ dw SGBData_MapPals1 ; unused
+ dw SGBData_MapPals1 ; MAP_SGB_PALS_1
+ dw SGBData_MapPals2 ; MAP_SGB_PALS_2
+ dw SGBData_MapPals3 ; MAP_SGB_PALS_3
+ dw SGBData_MapPals4 ; MAP_SGB_PALS_4
+ dw SGBData_MapPals5 ; MAP_SGB_PALS_5
+ dw SGBData_MapPals6 ; MAP_SGB_PALS_6
+ dw SGBData_MapPals7 ; MAP_SGB_PALS_7
+ dw SGBData_MapPals8 ; MAP_SGB_PALS_8
+ dw SGBData_MapPals9 ; MAP_SGB_PALS_9
+ dw SGBData_MapPals10 ; MAP_SGB_PALS_10
; 0x703cb
Func_703cb: ; 703cb (1c:43cb)
@@ -429,7 +429,7 @@ DecompressSGBPalette: ; 70403 (1c:4403)
push bc
ld e, l
ld d, h
- ld b, HIGH(wc000)
+ ld b, HIGH(wDecompressionSecondaryBuffer)
call InitDataDecompression
pop bc
ld de, wDecompressionBuffer
@@ -502,48 +502,92 @@ Func_704c7: ; 704c7 (1c:44c7)
ret
; 0x704d3
- INCROM $704d3, $73393
+ INCROM $704d3, $7322f
+
+SGBData_MapPals1: ; 7322f (1c:722f)
+ dw $20 ; length
+ INCBIN "data/sgb_data/map_pals_1.bin"
+
+SGBData_MapPals2: ; 73253 (1c:7253)
+ dw $20 ; length
+ INCBIN "data/sgb_data/map_pals_2.bin"
+
+SGBData_MapPals3: ; 73277 (1c:7277)
+ dw $20 ; length
+ INCBIN "data/sgb_data/map_pals_3.bin"
+
+SGBData_MapPals4: ; 7329a (1c:729a)
+ dw $20 ; length
+ INCBIN "data/sgb_data/map_pals_4.bin"
+
+SGBData_MapPals5: ; 732bd (1c:72bd)
+ dw $20 ; length
+ INCBIN "data/sgb_data/map_pals_5.bin"
+
+SGBData_MapPals6: ; 732e0 (1c:72e0)
+ dw $20 ; length
+ INCBIN "data/sgb_data/map_pals_6.bin"
+
+SGBData_MapPals7: ; 73304 (1c:7304)
+ dw $20 ; length
+ INCBIN "data/sgb_data/map_pals_7.bin"
+
+SGBData_MapPals8: ; 73328 (1c:7328)
+ dw $20 ; length
+ INCBIN "data/sgb_data/map_pals_8.bin"
+
+SGBData_MapPals9: ; 7334b (1c:734b)
+ dw $20 ; length
+ INCBIN "data/sgb_data/map_pals_9.bin"
+
+SGBData_MapPals10: ; 7336f (1c:736f)
+ dw $20 ; length
+ INCBIN "data/sgb_data/map_pals_10.bin"
SGBData_CharizardIntro: ; 73393 (1c:7393)
- dw $20 ; width
- INCROM $73395, $733b8
+ dw $20 ; length
+ INCBIN "data/sgb_data/charizard_intro_pals.bin"
SGBData_ScytherIntro: ; 733b8 (1c:73b8)
- dw $20 ; width
- INCROM $733ba, $733dd
+ dw $20 ; length
+ INCBIN "data/sgb_data/scyther_intro_pals.bin"
SGBData_AerodactylIntro: ; 733dd (1c:73dd)
- dw $20 ; width
- INCROM $733df, $73402
+ dw $20 ; length
+ INCBIN "data/sgb_data/aerodactyl_intro_pals.bin"
SGBData_ColosseumBooster: ; 73402 (1c:7402)
- dw $20 ; width
- INCROM $73404, $73427
+ dw $20 ; length
+ INCBIN "data/sgb_data/colosseum_booster_pals.bin"
SGBData_EvolutionBooster: ; 73427 (1c:7427)
- dw $20 ; width
- INCROM $73429, $7344c
+ dw $20 ; length
+ INCBIN "data/sgb_data/evolution_booster_pals.bin"
SGBData_MysteryBooster: ; 7344c (1c:744c)
- dw $20 ; width
- INCROM $7344e, $73471
+ dw $20 ; length
+ INCBIN "data/sgb_data/mystery_booster_pals.bin"
SGBData_LaboratoryBooster: ; 73471 (1c:7471)
- dw $20 ; width
- INCROM $73473, $73aa8
+ dw $20 ; length
+ INCBIN "data/sgb_data/laboratory_booster_pals.bin"
+
+ INCROM $73496, $73aa8
SGBData_GameBoyLink: ; 73aa8 (1c:7aa8)
- dw $40 ; width
- INCROM $73aaa, $73ad8
+ dw $40 ; length
+ INCBIN "data/sgb_data/gameboy_link_pals.bin"
SGBData_CardPop: ; 73ad8 (1c:7ad8)
- dw $40 ; width
- INCROM $73ada, $73b05
+ dw $40 ; length
+ INCBIN "data/sgb_data/card_pop_pals.bin"
SGBData_GameBoyPrinter: ; 73b05 (1c:7b05)
- dw $40 ; width
- INCROM $73b07, $73b33
+ dw $40 ; length
+ INCBIN "data/sgb_data/gameboy_printer_pals.bin"
SGBData_TitleScreen: ; 73b33 (1c:7b33)
- dw $40 ; width
- INCROM $73b35, $74000
+ dw $40 ; length
+ INCBIN "data/sgb_data/title_screen_pals.bin"
+
+ INCROM $73b63, $74000
diff --git a/src/engine/bank20.asm b/src/engine/bank20.asm
index 0d79171..d6a7ac0 100644
--- a/src/engine/bank20.asm
+++ b/src/engine/bank20.asm
@@ -109,7 +109,7 @@ Func_800bd: ; 800bd (20:40bd)
ld a, [wTempPointer + 1]
adc $00
ld d, a
- ld b, HIGH(wc000)
+ ld b, HIGH(wDecompressionSecondaryBuffer)
call InitDataDecompression
ld a, [wVRAMPointer]
ld e, a
diff --git a/src/engine/home.asm b/src/engine/home.asm
index c23b544..5a8c822 100644
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -1534,33 +1534,31 @@ UpdateRNGSources: ; 089b (0:089b)
pop hl
ret
-; initilizes variables used to decompress
-; data in DecompressData
-; de points to the source of compressed data
-; b is used as the HIGH byte of the
-; WRAM address to write to ($100 bytes of buffer space)
+; initilizes variables used to decompress data in DecompressData
+; de = source of compressed data
+; b = HIGH byte of secondary buffer ($100 bytes of buffer space)
; also clears this $100 byte space
InitDataDecompression: ; 08bf (0:08bf)
- ld hl, wcad6
+ ld hl, wDecompSourcePosPtr
ld [hl], e
inc hl
ld [hl], d
- ld hl, wcad8
- ld [hl], $1
+ ld hl, wDecompNumCommandBitsLeft
+ ld [hl], 1
inc hl
xor a
- ld [hli], a ; wcad9
- ld [hli], a ; wcada
- ld [hli], a ; wcadb
- ld [hli], a ; wcadc
- ld [hl], b ; wcadd
+ ld [hli], a ; wDecompCommandByte
+ ld [hli], a ; wDecompRepeatModeToggle
+ ld [hli], a ; wDecompRepeatLengths
+ ld [hli], a ; wDecompNumBytesToRepeat
+ ld [hl], b ; wDecompSecondaryBufferPtrHigh
inc hl
- ld [hli], a ; wcade
- ld [hl], $ef ; wcadf
+ ld [hli], a ; wDecompRepeatSeqOffset
+ ld [hl], LOW(wDecompressionSecondaryBufferStart) ; wDecompSecondaryBufferPtrLow
; clear buffer
ld h, b
- ld l, LOW(wc000)
+ ld l, LOW(wDecompressionSecondaryBuffer)
xor a
.loop
ld [hl], a
@@ -1570,7 +1568,7 @@ InitDataDecompression: ; 08bf (0:08bf)
; decompresses data
; uses values initialized by InitDataDecompression
-; wcad6 holds the pointer for compressed source
+; wDecompSourcePosPtr holds the pointer for compressed source
; input:
; bc = row width
; de = buffer to place decompressed data
@@ -1591,99 +1589,110 @@ DecompressData: ; 08de (0:08de)
pop hl
ret
-; instructions start with a byte stored in wcad9
-; its bits are read from higher to lower bit
-; wcad8 stores the current bit being read
-; bit set:
-; - 1 byte read and copied literally
-; bit not set:
-; - 2 bytes read WW XY ZZ, byte in pos WW
-; copied (X + 1) times, then in pos ZZ
-; copied (Y + 1) times
+; decompression works as follows:
+; first a command byte is read that will dictate how the
+; following bytes will be copied
+; the position will then move to the next byte (0xXY), and
+; the command byte's bits are read from higher to lower bit
+; - if command bit is set, then copy 0xXY to buffer;
+; - if command bit is not set, then decompression enters "repeat mode,"
+; which means it stores 0xXY in memory as number of bytes to repeat
+; from a given offset. This offset is in the next byte in the data,
+; 0xZZ, which tells the offset to start repeating. A toggle is switched
+; each time the algorithm hits "repeat mode":
+; - if off -> on it reads 0xXY and stores it,
+; then repeats (0x0X + 2) bytes from the offset starting at 0xZZ;
+; - if on -> off, then the data only provides the offset,
+; and the previous byte read for number of bytes to repeat, 0xXY, is reused
+; in which case (0x0Y + 2) bytes are repeated starting from the offset.
.Decompress: ; 08ef (0:08ef)
- ld hl, wcadc
+ ld hl, wDecompNumBytesToRepeat
ld a, [hl]
or a
- jr z, .read_instruction
+ jr z, .read_command
-; still repeating byte
+; still repeating sequence
dec [hl]
inc hl
.repeat_byte
- ld b, [hl] ; wcadd
+ ld b, [hl] ; wDecompSecondaryBufferPtrHigh
inc hl
- ld c, [hl] ; wcade
+ ld c, [hl] ; wDecompRepeatSeqOffset
inc [hl]
inc hl
ld a, [bc]
- ld c, [hl] ; wcadf
+ ld c, [hl] ; wDecompSecondaryBufferPtrLow
inc [hl]
ld [bc], a
ret
-.read_instruction
- ld hl, wcad6
+.read_command
+ ld hl, wDecompSourcePosPtr
ld c, [hl]
inc hl
ld b, [hl]
- inc hl ; wcad8
+ inc hl ; wDecompNumCommandBitsLeft
dec [hl]
- inc hl ; wcad9
- jr nz, .asm_914
- dec hl ; wcad8
- ld [hl], $8 ; number of bits
- inc hl ; wcad9
+ inc hl ; wDecompCommandByte
+ jr nz, .read_command_bit
+ dec hl ; wDecompNumCommandBitsLeft
+ ld [hl], 8 ; number of bits
+ inc hl ; wDecompCommandByte
ld a, [bc]
inc bc
ld [hl], a
-.asm_914
+.read_command_bit
rl [hl]
ld a, [bc]
inc bc
- jr nc, .asm_92a
+ jr nc, .repeat_command
; copy 1 byte literally
- ld hl, wcad6
+ ld hl, wDecompSourcePosPtr
ld [hl], c
inc hl
ld [hl], b
- ld hl, wcadd
+ ld hl, wDecompSecondaryBufferPtrHigh
ld b, [hl]
inc hl
inc hl
- ld c, [hl] ; wcadf
+ ld c, [hl] ; wDecompSecondaryBufferPtrLow
inc [hl]
ld [bc], a
ret
-.asm_92a
- ld [wcade], a
- ld hl, wcada
+.repeat_command
+ ld [wDecompRepeatSeqOffset], a ; save the offset to repeat from
+ ld hl, wDecompRepeatModeToggle
bit 0, [hl]
- jr nz, .asm_94a
+ jr nz, .repeat_mode_toggle_on
set 0, [hl]
inc hl
+; read byte for num of bytes to read
+; and use its higher nybble
ld a, [bc]
inc bc
- ld [hli], a ; wcadb
+ ld [hli], a ; wDecompRepeatLengths
swap a
-.asm_93c
+.get_sequence_len
and $f
inc a ; number of times to repeat
- ld [hli], a ; wcadc
+ ld [hli], a ; wDecompNumBytesToRepeat
push hl
- ld hl, wcad6
+ ld hl, wDecompSourcePosPtr
ld [hl], c
inc hl
ld [hl], b
pop hl
jr .repeat_byte
-.asm_94a
+.repeat_mode_toggle_on
+; get the previous byte (num of bytes to repeat)
+; and use its lower nybble
res 0, [hl]
inc hl
- ld a, [hli] ; wcadb
- jr .asm_93c
+ ld a, [hli] ; wDecompRepeatLengths
+ jr .get_sequence_len
; set attributes for [hl] sprites starting from wOAM + [wOAMOffset] / 4
; return carry if reached end of wOAM before finishing