Skip to content

Instantly share code, notes, and snippets.

@lhsazevedo
Last active January 23, 2021 05:39
Show Gist options
  • Save lhsazevedo/1f461d8e248c5a159063c4bee298765f to your computer and use it in GitHub Desktop.
Save lhsazevedo/1f461d8e248c5a159063c4bee298765f to your computer and use it in GitHub Desktop.
AKMW Phantasy Star RLE
; 0x293
decompressPhantasyStarRLEToVRAM:
ld b, $04
-:
push bc
push de
call decompressBitplaneToVRAM
pop de
inc de
pop bc
djnz -
ret
; Alex Kidd in Miracle World uses "Phantasy Star RLE" for tile data compression
; This function decompresses data from HL to VRAM DE.
;
; 0x2A0
decompressBitplaneToVRAM:
ld a, (hl)
inc hl
; Return if we hit $0000
or a
ret z
; b = Number of block bytes
ld b, a
; c = Run type control bit
ld c, a
res 7, b
-:
ld a, e
out (Port_VDPAddress), a
ld a, d
out (Port_VDPAddress), a
ld a, (hl)
out (Port_VDPData), a
bit 7, c
jp z, +
inc hl
+:
inc de
inc de
inc de
inc de
djnz -
jp nz, decompressBitplaneToVRAM
inc hl
jp decompressBitplaneToVRAM
bank prg @ 0x0000 : [constdata; 0x1000];
in prg @ 0x293 {
func decompressPhantasyStarRLEToVRAM(dest: *u8 in de, source: *u8 in hl) {
b = 4;
do {
push(bc);
push(dest);
decompressBitplaneToVram(dest, source);
dest = pop() as *u8;
dest++;
bc = pop();
} while --b != 0;
}
/**
* Alex Kidd in Miracle World uses "Phantasy Star RLE" for tile data
* compression. This function decompresses data from HL to VRAM DE.
*/
#[fallthrough]
func decompressBitplaneToVram(dest: *u8 in de, source: *u8 in hl) {
var current_byte: u8 in a;
var block_bytes_count: u8 in b;
var block_control_byte: u8 in c;
^do {
^do {
current_byte = *source;
source++;
return if current_byte == 0x00;
block_bytes_count = current_byte;
block_control_byte = current_byte;
// Reset run type bit
block_bytes_count$7 = false;
do {
io_write(0xBF, a = <:dest);
io_write(0xBF, a = >:dest);
io_write(0xBE, a = *source);
^if block_control_byte$7 {
source++;
}
inline for in 1..4 {
dest++;
}
} while --block_bytes_count != 0;
} while !zero;
source++;
} while true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment