From 3829a921bbb2d4ed43db1dac33c4d6e536121ab4 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 21 Feb 2018 22:50:34 -0500 Subject: [PATCH] chiptune_player: get the file format/loader working --- asm_routines/lz4_decode.s | 40 ++++------ chiptune_player/INTRO2.KRW | Bin 9356 -> 9362 bytes chiptune_player/chiptune_player.s | 128 ++++++++++++++++++++---------- 3 files changed, 102 insertions(+), 66 deletions(-) diff --git a/asm_routines/lz4_decode.s b/asm_routines/lz4_decode.s index 3ab8ebbc..c8a58afe 100644 --- a/asm_routines/lz4_decode.s +++ b/asm_routines/lz4_decode.s @@ -30,47 +30,37 @@ ; 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) -src EQU $00 +src EQU $FC dst EQU $02 end EQU $04 count EQU $06 delta EQU $08 -A1L EQU $3c -A1H EQU $3d -A2L EQU $3e -A2H EQU $3f -A4L EQU $42 -A4H EQU $43 -size EQU 794 orgoff EQU $6000 ; offset of first unpacked byte -paksize EQU size-$b-8 - ; size of packed data - ; minus 4 for checksum at end - ; not sure what other 4 is from? - ; block checksum? though had that disabled? - -pakoff EQU $400b ; 11 byte offset to data? + ;====================== + ; LZ4 decode + ;====================== + ; input buffer in INH:INL + ; output buffer hardcoded still + ; size in ENDH:ENDL lz4_decode: - lda #pakoff - sta src+1 - lda #>(pakoff+paksize) + lda INH +; sta src+1 + adc end+1 sta end+1 + lda #>orgoff ; original unpacked data offset sta dst+1 lda # 9:59 songs yet frame_good: @@ -301,6 +305,10 @@ chunk_good: done_interrupt: pla +; tax +; pla +; tay +; pla rti @@ -309,11 +317,16 @@ done_interrupt: ;================= new_song: - lda #0 + + ;========================= + ; Init Variables + ;========================= + + lda #$0 + sta MB_CHUNK + sta FRAME_COUNT sta A_VOLUME - lda #0 sta B_VOLUME - lda #0 sta C_VOLUME ;=========================== @@ -335,38 +348,30 @@ new_song: ;=========================== - ; init pointer to the music + ; Load in KRW file ;=========================== - lda #krw_file sta INH - jsr read_file + jsr read_file ; read KRW file from disk - jsr lz4_decode - - lda #>CHUNK_BUFFER - sta INH - lda #file_info -; sta OUTH -; ldy #0 + lda #>LZ4_BUFFER + sta OUTH + lda #(LZ4_BUFFER+3) + sta INH + lda #<(LZ4_BUFFER+3) + sta INL + + lda (INL),Y ; get header skip + clc + adc INL + sta INL + lda INH + adc #0 + sta INH + + lda (INL),Y + sta SIZEL + iny + lda (INL),Y + sta SIZEH + + lda #2 + clc + adc INL + sta INL + lda INH + adc #0 + sta INH + + jsr lz4_decode + + lda #CHUNK_BUFFER + sta INH rts