chiptune_player: prepare for playing whole song

This commit is contained in:
Vince Weaver 2018-02-21 23:01:33 -05:00
parent daf51b5474
commit 6f13857beb
3 changed files with 64 additions and 63 deletions

View File

@ -30,36 +30,34 @@
; 4 added to it. As with the literal length, if it is 15 then ; 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) ; you read a byte and add (and if that byte is 255, keep adding)
src EQU $FC ;LZ4_SRC EQU $00
dst EQU $02 ;LZ4_DST EQU $02
end EQU $04 ;LZ4_END EQU $04
count EQU $06 ;COUNT EQU $06
delta EQU $08 ;DELTA EQU $08
orgoff EQU $6000 ; offset of first unpacked byte orgoff EQU $6000 ; offset of first unpacked byte
;====================== ;======================
; LZ4 decode ; LZ4 decode
;====================== ;======================
; input buffer in INH:INL ; input buffer in LZ4_SRC
; output buffer hardcoded still ; output buffer hardcoded still
; size in ENDH:ENDL ; size in ENDH:ENDL
lz4_decode: lz4_decode:
lda INL ; packed data offset lda LZ4_SRC ; packed data offset
; sta src
clc clc
adc end adc LZ4_END
sta end sta LZ4_END
lda INH lda LZ4_SRC+1
; sta src+1 adc LZ4_END+1
adc end+1 sta LZ4_END+1
sta end+1
lda #>orgoff ; original unpacked data offset lda #>orgoff ; original unpacked data offset
sta dst+1 sta LZ4_DST+1
lda #<orgoff lda #<orgoff
sta dst sta LZ4_DST
unpmain: unpmain:
ldy #0 ; used to index, always zero ldy #0 ; used to index, always zero
@ -80,17 +78,17 @@ parsetoken:
tax ; now in ram[count+1]-1:X tax ; now in ram[count+1]-1:X
jsr docopy ; copy the literals jsr docopy ; copy the literals
lda src ; 16-bit compare lda LZ4_SRC ; 16-bit compare
cmp end ; to see if we have reached the end cmp LZ4_END ; to see if we have reached the end
lda src+1 lda LZ4_SRC+1
sbc end+1 sbc LZ4_END+1
bcs done bcs done
copymatches: copymatches:
jsr getsrc ; get 16-bit delta value jsr getsrc ; get 16-bit delta value
sta delta sta DELTA
jsr getsrc jsr getsrc
sta delta+1 sta DELTA+1
pla ; restore token pla ; restore token
and #$0f ; get bottom 4 bits and #$0f ; get bottom 4 bits
@ -108,28 +106,28 @@ copymatches:
; exactly a multiple of 0x100 ; exactly a multiple of 0x100
bcc copy_no_adjust bcc copy_no_adjust
inc count+1 ; increment if we overflowed inc COUNT+1 ; increment if we overflowed
copy_no_adjust: copy_no_adjust:
lda src+1 ; save src on stack lda LZ4_SRC+1 ; save src on stack
pha pha
lda src lda LZ4_SRC
pha pha
sec ; subtract delta sec ; subtract delta
lda dst ; from destination, make new src lda LZ4_DST ; from destination, make new src
sbc delta sbc DELTA
sta src sta LZ4_SRC
lda dst+1 lda LZ4_DST+1
sbc delta+1 sbc DELTA+1
sta src+1 sta LZ4_SRC+1
jsr docopy ; do the copy jsr docopy ; do the copy
pla ; restore the src pla ; restore the src
sta src sta LZ4_SRC
pla pla
sta src+1 sta LZ4_SRC+1
jmp parsetoken ; back to parsing tokens jmp parsetoken ; back to parsing tokens
@ -142,10 +140,10 @@ done:
;========= ;=========
; gets byte from src into A, increments pointer ; gets byte from src into A, increments pointer
getsrc: getsrc:
lda (src), Y ; get a byte from src lda (LZ4_SRC), Y ; get a byte from src
inc src ; increment pointer inc LZ4_SRC ; increment pointer
bne done_getsrc ; update 16-bit pointer bne done_getsrc ; update 16-bit pointer
inc src+1 ; on 8-bit overflow inc LZ4_SRC+1 ; on 8-bit overflow
done_getsrc: done_getsrc:
rts rts
@ -154,17 +152,17 @@ done_getsrc:
;============ ;============
buildcount: buildcount:
ldx #1 ; high count starts at 1 ldx #1 ; high count starts at 1
stx count+1 ; (loops at zero?) stx COUNT+1 ; (loops at zero?)
cmp #$0f ; if LITERAL_COUNT < 15, we are done cmp #$0f ; if LITERAL_COUNT < 15, we are done
bne done_buildcount bne done_buildcount
buildcount_loop: buildcount_loop:
sta count ; save LITERAL_COUNT (15) sta COUNT ; save LITERAL_COUNT (15)
jsr getsrc ; get the next byte jsr getsrc ; get the next byte
tax ; put in X tax ; put in X
clc clc
adc count ; add new byte to old value adc COUNT ; add new byte to old value
bcc bc_8bit_oflow ; if overflow, increment high byte bcc bc_8bit_oflow ; if overflow, increment high byte
inc count+1 inc COUNT+1
bc_8bit_oflow: bc_8bit_oflow:
inx ; check if read value was 255 inx ; check if read value was 255
beq buildcount_loop ; if it was, keep looping and adding beq buildcount_loop ; if it was, keep looping and adding
@ -184,10 +182,10 @@ getput:
;============= ;=============
; store A into destination ; store A into destination
putdst: putdst:
sta (dst), Y ; store A into destination sta (LZ4_DST), Y ; store A into destination
inc dst ; increment 16-bit pointer inc LZ4_DST ; increment 16-bit pointer
bne putdst_end ; if overflow, increment top byte bne putdst_end ; if overflow, increment top byte
inc dst+1 inc LZ4_DST+1
putdst_end: putdst_end:
rts rts
@ -202,7 +200,7 @@ docopy_loop:
jsr getput ; get/put byte jsr getput ; get/put byte
dex ; decrement count dex ; decrement count
bne docopy_loop ; if not zero, loop bne docopy_loop ; if not zero, loop
dec count+1 ; if zero, decrement high byte dec COUNT+1 ; if zero, decrement high byte
bne docopy_loop ; if not zero, loop bne docopy_loop ; if not zero, loop
rts rts

View File

@ -433,37 +433,33 @@ bloop2:
bloop3: bloop3:
jsr print_both_pages jsr print_both_pages
SIZEL EQU $04
SIZEH EQU $05
ldy #0 ldy #0
lda #>(LZ4_BUFFER+3) lda #>(LZ4_BUFFER+3)
sta INH sta LZ4_SRC+1
lda #<(LZ4_BUFFER+3) lda #<(LZ4_BUFFER+3)
sta INL sta LZ4_SRC
lda (INL),Y ; get header skip lda (LZ4_SRC),Y ; get header skip
clc clc
adc INL adc LZ4_SRC
sta INL sta LZ4_SRC
lda INH lda LZ4_SRC+1
adc #0 adc #0
sta INH sta LZ4_SRC+1
lda (INL),Y lda (LZ4_SRC),Y
sta SIZEL sta LZ4_END
iny iny
lda (INL),Y lda (LZ4_SRC),Y
sta SIZEH sta LZ4_END+1
lda #2 lda #2
clc clc
adc INL adc LZ4_SRC
sta INL sta LZ4_SRC
lda INH lda LZ4_SRC+1
adc #0 adc #0
sta INH sta LZ4_SRC+1
jsr lz4_decode jsr lz4_decode

View File

@ -1,5 +1,12 @@
.define EQU = .define EQU =
LZ4_SRC EQU $00
LZ4_DST EQU $02
LZ4_END EQU $04
COUNT EQU $06
DELTA EQU $08
;; Zero page monitor routines addresses ;; Zero page monitor routines addresses
WNDLFT EQU $20 WNDLFT EQU $20