wip lzss player......

This commit is contained in:
2024-08-15 01:53:37 -04:00
parent dbd1fa46d6
commit ce17fbd285
6 changed files with 265 additions and 86 deletions
+2 -2
View File
@@ -13,7 +13,7 @@
icl '../lib/MACRO.ASM'
;---------------------------------------------------
; BASIC off
ORG $2700
ORG $2c00
mva #$ff portb
mwa #DL_pre dlptrs
lda #@dmactl(narrow|dma) ; narrow screen width, DL on
@@ -119,7 +119,7 @@ leet_speek1
leet_speek2
dta "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
leet_speek3
dta "4&[)eF9-|jk_mn0p@r57uvw*y2"
dta "48[)eF9-|jk_mn0p@r57uvw*y2"
leet_speek4
dta "^b(>",$5b,$41,"gh1",$4c+$80,"k",$4b+$80,"M\",$54,$49+$80,"q",$51,"5",$57,"uvwxy/"
+39 -39
View File
@@ -577,48 +577,48 @@ FFFD 0000 @KBCODE
00 0082 TEMP_B
00 0083 TEMP_W2
00 0085 TEMP_W3
00 2724 LEET_ANIM
00 274D 0@
00 2771 NEXT_LETTER
00 2790 LEET_END
00 2794 WAIT_FOR_RELEASING_KEYZ
00 2794 WAIT_FOR_RELEASING_KEYZ.1@
00 279B WAIT_FOR_RELEASING_KEYZ.2@
00 27A6 WAIT_FOR_RELEASING_KEYZ.3@
00 27AC DL_PRE
00 27CC PRE_SCREEN
00 28EC PRE_SCREEN_END
00 28EC LEET_SPEEK1
00 2906 LEET_SPEEK2
00 2920 LEET_SPEEK3
00 293A LEET_SPEEK4
00 2954 LEET_SPEEKS_L
00 2958 LEET_SPEEKS_H
00 295C LEET_SCREEN
00 2A7C LEET_SCREEN_END
00 2C24 LEET_ANIM
00 2C4D 0@
00 2C71 NEXT_LETTER
00 2C90 LEET_END
00 2C94 WAIT_FOR_RELEASING_KEYZ
00 2C94 WAIT_FOR_RELEASING_KEYZ.1@
00 2C9B WAIT_FOR_RELEASING_KEYZ.2@
00 2CA6 WAIT_FOR_RELEASING_KEYZ.3@
00 2CAC DL_PRE
00 2CCC PRE_SCREEN
00 2DEC PRE_SCREEN_END
00 2DEC LEET_SPEEK1
00 2E06 LEET_SPEEK2
00 2E20 LEET_SPEEK3
00 2E3A LEET_SPEEK4
00 2E54 LEET_SPEEKS_L
00 2E58 LEET_SPEEKS_H
00 2E5C LEET_SCREEN
00 2F7C LEET_SCREEN_END
00 3000 SCREEN
00 3410 DL
00 343C START
00 3482 PLEASE_WAIT_LOOP
00 3498 4@
00 3499 SAMPLE_LOAD
00 3510 5@
00 351A EXIT_TECH_DIFF
00 351A 6@
00 3521 7@
00 352C 8@
00 3540 SAMPLE1
00 48AC SAMPLE_END1
00 48AC SAMPLE2
00 6B91 SAMPLE_END2
00 6B91 SAMPLE3
00 6E2B SAMPLE_END3
00 6E2B SAMPLE4
00 70C5 SAMPLE_END4
00 70C5 SAMPLE5
00 98DF SAMPLE_END5
00 98DF SAMPLES_L
00 98EA SAMPLES_H
00 98F5 SAMPLES_END_L
00 9900 SAMPLES_END_H
00 990B FINITO
00 34FA 5@
00 3504 EXIT_TECH_DIFF
00 3504 6@
00 350B 7@
00 3516 8@
00 352A SAMPLE1
00 4896 SAMPLE_END1
00 4896 SAMPLE2
00 6B7B SAMPLE_END2
00 6B7B SAMPLE3
00 6E15 SAMPLE_END3
00 6E15 SAMPLE4
00 70AF SAMPLE_END4
00 70AF SAMPLE5
00 98C9 SAMPLE_END5
00 98C9 SAMPLES_L
00 98D4 SAMPLES_H
00 98DF SAMPLES_END_L
00 98EA SAMPLES_END_H
00 98F5 FINITO
Binary file not shown.
+53 -45
View File
@@ -20,48 +20,44 @@
; The plater needs 256 bytes of buffer for each pokey register stored, for a
; full SAP file this is 2304 bytes.
;
org $80
org $e0
song_start_ptr .ds 2
song_end_ptr .ds 2
chn_copy .ds 9
chn_pos .ds 9
bptr .ds 2
cur_pos .ds 1
chn_bits .ds 1
bit_data .byte 1
bit_data .ds 1
.proc get_byte
lda song_data+1
inc song_ptr
bne skip
inc song_ptr+1
skip
rts
.endp
song_ptr = get_byte + 1
POKEY = $D200
org $2000
buffers
.ds 256 * 9
song_data
ins 'test.lz16'
song_end
start
player
jmp play_frame
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Song Initialization - this runs in the first tick:
;
.proc init_song
; Example: here initializes song pointer:
; sta song_ptr
; stx song_ptr + 1
;clear buffers
lda #0
tax
@
:9 sta buffers+#*$100,x
inx
bne @-
mva #1 bit_data
; here initializes song pointer:
adw song_start_ptr #1 song_ptr
; Init all channels:
ldx #8
@@ -80,18 +76,9 @@ cbuf
; Initialize buffer pointer:
sty bptr
sty cur_pos
rts
.endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Wait for next frame
;
.proc wait_frame
lda 20
delay
cmp 20
beq delay
.endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Play one frame of the song
@@ -100,7 +87,8 @@ delay
lda #>buffers
sta bptr+1
lda song_data
ldy #0
lda (song_start_ptr),y
sta chn_bits
ldx #8
@@ -149,22 +137,42 @@ skip_chn:
bpl chn_loop ; Next channel
inc cur_pos
.endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Check for ending of song and jump to the next frame
;
.proc check_end_song
lda song_ptr + 1
cmp #>song_end
bne wait_frame
lda song_ptr
cmp #<song_end
bne wait_frame
.endp
end_loop
check_end_song
cpw song_ptr song_end_ptr
scc:jsr init_song
rts
.endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_byte
lda song_ptr: $ffff ;song_data+1
inc song_ptr
sne:inc song_ptr+1
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
start
mwa #song_data song_start_ptr
mwa #song_end song_end_ptr
jsr init_song
@
lda:cmp:req 20
jsr player
jmp @-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.align $100
buffers
.ds 256 * 9
song_data
ins 'ingame.lzss'
song_end
run start
Binary file not shown.
+171
View File
@@ -0,0 +1,171 @@
;
; LZSS Compressed SAP player for 16 match bits
; --------------------------------------------
;
; (c) 2020 DMSC
; Code under MIT license, see LICENSE file.
;
; This player uses:
; Match length: 8 bits (1 to 256)
; Match offset: 8 bits (1 to 256)
; Min length: 2
; Total match bits: 16 bits
;
; Compress using:
; lzss -b 16 -o 8 -m 1 input.rsap test.lz12
;
; Assemble this file with MADS assembler, the compressed song is expected in
; the `test.lz16` file at assembly time.
;
; The plater needs 256 bytes of buffer for each pokey register stored, for a
; full SAP file this is 2304 bytes.
;
org $80
chn_copy .ds 9
chn_pos .ds 9
bptr .ds 2
cur_pos .ds 1
chn_bits .ds 1
bit_data .byte 1
.proc get_byte
lda song_data+1
inc song_ptr
bne skip
inc song_ptr+1
skip
rts
.endp
song_ptr = get_byte + 1
POKEY = $D200
org $2000
buffers
.ds 256 * 9
song_data
ins 'test.lz16'
song_end
start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Song Initialization - this runs in the first tick:
;
.proc init_song
; Example: here initializes song pointer:
; sta song_ptr
; stx song_ptr + 1
; Init all channels:
ldx #8
ldy #0
clear
; Read just init value and store into buffer and POKEY
jsr get_byte
sta POKEY, x
sty chn_copy, x
cbuf
sta buffers + 255
inc cbuf + 2
dex
bpl clear
; Initialize buffer pointer:
sty bptr
sty cur_pos
.endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Wait for next frame
;
.proc wait_frame
lda 20
delay
cmp 20
beq delay
.endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Play one frame of the song
;
.proc play_frame
lda #>buffers
sta bptr+1
lda song_data
sta chn_bits
ldx #8
; Loop through all "channels", one for each POKEY register
chn_loop:
lsr chn_bits
bcs skip_chn ; C=1 : skip this channel
lda chn_copy, x ; Get status of this stream
bne do_copy_byte ; If > 0 we are copying bytes
; We are decoding a new match/literal
lsr bit_data ; Get next bit
bne got_bit
jsr get_byte ; Not enough bits, refill!
ror ; Extract a new bit and add a 1 at the high bit (from C set above)
sta bit_data ;
got_bit:
jsr get_byte ; Always read a byte, it could mean "match size/offset" or "literal byte"
bcs store ; Bit = 1 is "literal", bit = 0 is "match"
sta chn_pos, x ; Store in "copy pos"
jsr get_byte
sta chn_copy, x ; Store in "copy length"
; And start copying first byte
do_copy_byte:
dec chn_copy, x ; Decrease match length, increase match position
inc chn_pos, x
ldy chn_pos, x
; Now, read old data, jump to data store
lda (bptr), y
store:
ldy cur_pos
sta POKEY, x ; Store to output and buffer
sta (bptr), y
skip_chn:
; Increment channel buffer pointer
inc bptr+1
dex
bpl chn_loop ; Next channel
inc cur_pos
.endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Check for ending of song and jump to the next frame
;
.proc check_end_song
lda song_ptr + 1
cmp #>song_end
bne wait_frame
lda song_ptr
cmp #<song_end
bne wait_frame
.endp
end_loop
rts
run start