diff --git a/split_screen/Makefile b/split_screen/Makefile index f95c4999..bf131236 100644 --- a/split_screen/Makefile +++ b/split_screen/Makefile @@ -10,7 +10,7 @@ split.dsk: BISHOP BISHOP.BAS RAINBOW.BAS RAINBOW KATC.BIN CREDITS $(DOS33) -y split.dsk SAVE A BISHOP.BAS $(DOS33) -y split.dsk SAVE A RAINBOW.BAS $(DOS33) -y split.dsk BSAVE -a 0x0c00 RAINBOW - $(DOS33) -y split.dsk BSAVE -a 0x1000 CREDITS + $(DOS33) -y split.dsk BSAVE -a 0x4000 CREDITS # $(DOS33) -y split.dsk BSAVE -a 0x2000 LENNA.BIN $(DOS33) -y split.dsk BSAVE -a 0x2000 KATC.BIN @@ -32,13 +32,17 @@ RAINBOW: rainbow.o RAINBOW.BAS: rainbow.bas $(TOKENIZE) < rainbow.bas > RAINBOW.BAS -credits.o: credits.s tfv_sprites.inc mockingboard.s +credits.o: credits.s tfv_sprites.inc mockingboard.s \ + lz4_decode.s \ + KATC.BIN.lz4 ca65 -o credits.o credits.s -l credits.lst CREDITS: credits.o - ld65 -o CREDITS credits.o -C ../linker_scripts/apple2_1000.inc + ld65 -o CREDITS credits.o -C ../linker_scripts/apple2_4000.inc +KATC.BIN.lz4: KATC.BIN + lz4 -f -16 KATC.BIN KATC.BIN: kat.bmp ../bmp2dhr/b2d kat.bmp hgr dither diff --git a/split_screen/credits.s b/split_screen/credits.s index 306485bc..5e8fedde 100644 --- a/split_screen/credits.s +++ b/split_screen/credits.s @@ -62,6 +62,26 @@ no_init_mb: + ;========================== + ; Load the background image + + lda #katahdin + sta LZ4_SRC+1 + + lda #<(katahdin_end-8) ; skip checksum at end + sta LZ4_END + lda #>(katahdin_end-8) ; skip checksum at end + sta LZ4_END+1 + + lda #<$2000 ; Destination is HGR page0 + sta LZ4_DST + lda #>$2000 + sta LZ4_DST+1 + + jsr lz4_decode + ;========================== ; setup text screen @@ -954,10 +974,14 @@ line6:.asciiz " . " .include "../asm_routines/gr_offsets.s" .include "tfv_sprites.inc" -.align $1000 +.include "lz4_decode.s" -graphics: -.incbin "KATC.BIN" +;.align $1000 +katahdin: +.incbin "KATC.BIN.lz4",11 ; skip the header +katahdin_end: + +.align $100 music: .incbin "music.tfv" diff --git a/split_screen/lz4_decode.s b/split_screen/lz4_decode.s new file mode 100644 index 00000000..4355da11 --- /dev/null +++ b/split_screen/lz4_decode.s @@ -0,0 +1,213 @@ +; LZ4 data decompressor for Apple II + +; Code by Peter Ferrie (qkumba) (peter.ferrie@gmail.com) +; "LZ4 unpacker in 143 bytes (6502 version) (2013)" +; http://pferrie.host22.com/misc/appleii.htm +; This is that code, but with comments and labels added for clarity. +; I also found a bug when decoding with runs of multiples of 256 +; which has since been fixed upstream. + +; For LZ4 reference see +; https://github.com/lz4/lz4/wiki/lz4_Frame_format.md + +; LZ4 summary: +; +; HEADER: +; Should: check for magic number 04 22 4d 18 +; FLG: 64 in our case (01=version, block.index=1, block.checksum=0 +; size=0, checksum=1, reserved +; MAX Blocksize: 40 (64kB) +; HEADER CHECKSUM: a7 +; BLOCK HEADER: 4 bytes (le) length If highest bit set, uncompressed! +; data (see below), followed by checksum? +; BLOCKS: +; Token byte. High 4-bits literal length, low 4-bits copy length +; + If literal length==15, then following byte gets added to length +; If that byte was 255, then keep adding bytes until not 255 +; + The literal bytes follow. There may be zero of them +; + Next is block copy info. little-endian 2-byte offset to +; be subtracted from current read position indicating source +; + The low 4-bits of the token are the copy length, which needs +; 4 added to it. As with the literal length, if it is 15 then +; you read a byte and add (and if that byte is 255, keep adding) + +; At end you have 4 byte end-of-block marker (all zeros?) then +; 4 bytes of checksum (if marked in flags) +; our code does that, so be sure to set end -8 + + +;LZ4_SRC EQU $00 +;LZ4_DST EQU $02 +;LZ4_END EQU $04 +;COUNT EQU $06 +;DELTA EQU $08 + +;UNPACK_BUFFER EQU $5E00 ; offset of first unpacked byte + + + ;====================== + ; LZ4 decode + ;====================== + ; input buffer in LZ4_SRC + ; output buffer hardcoded still + ; size in ENDH:ENDL + +lz4_decode: +; lda LZ4_SRC ; packed data offset +; clc +; adc LZ4_END +; sta LZ4_END +; lda LZ4_SRC+1 +; adc LZ4_END+1 +; sta LZ4_END+1 + +; lda #>UNPACK_BUFFER ; original unpacked data offset +; sta LZ4_DST+1 +; lda #