2018-04-28 01:24:57 +00:00
|
|
|
; And Believe Me, I'm Still Alive
|
|
|
|
|
|
|
|
.include "zp.inc"
|
2018-05-21 17:33:08 +00:00
|
|
|
; program is ~16k, so from 0xc00 to 0x4C00
|
2018-04-28 01:24:57 +00:00
|
|
|
UNPACK_BUFFER EQU $5E00 ; $5E00 - $9600, 14k, $3800
|
|
|
|
; trying not to hit DOS at $9600
|
|
|
|
; Reserve 3 chunks plus spare (14k)
|
|
|
|
|
|
|
|
;=============================
|
|
|
|
; Setup
|
|
|
|
;=============================
|
|
|
|
jsr HOME
|
|
|
|
jsr TEXT
|
|
|
|
|
|
|
|
; init variables
|
|
|
|
|
|
|
|
lda #0
|
|
|
|
sta DONE_PLAYING
|
|
|
|
sta MB_CHUNK_OFFSET
|
|
|
|
sta DECODE_ERROR
|
2018-05-22 16:02:18 +00:00
|
|
|
sta LYRICS_ACTIVE
|
2018-04-28 01:24:57 +00:00
|
|
|
|
2018-05-23 16:50:12 +00:00
|
|
|
; Testing, let's get 40col working first
|
2018-05-24 16:42:27 +00:00
|
|
|
lda #0
|
2018-05-23 16:50:12 +00:00
|
|
|
sta FORTYCOL
|
|
|
|
|
2018-04-28 01:24:57 +00:00
|
|
|
jsr mockingboard_detect_slot4 ; call detection routine
|
|
|
|
cpx #$1
|
|
|
|
beq mockingboard_found
|
|
|
|
|
2018-05-24 18:47:49 +00:00
|
|
|
; Not found.
|
|
|
|
; Print a message for debugging?
|
2018-04-28 01:24:57 +00:00
|
|
|
jmp forever_loop ; and wait forever
|
|
|
|
|
|
|
|
mockingboard_found:
|
|
|
|
|
|
|
|
;============================
|
|
|
|
; Init the Mockingboard
|
|
|
|
;============================
|
|
|
|
|
|
|
|
jsr mockingboard_init
|
|
|
|
jsr reset_ay_both
|
|
|
|
jsr clear_ay_both
|
|
|
|
|
|
|
|
;=========================
|
|
|
|
; Setup Interrupt Handler
|
|
|
|
;=========================
|
|
|
|
; Vector address goes to 0x3fe/0x3ff
|
|
|
|
; FIXME: should chain any existing handler
|
|
|
|
|
|
|
|
lda #<interrupt_handler
|
|
|
|
sta $03fe
|
|
|
|
lda #>interrupt_handler
|
|
|
|
sta $03ff
|
|
|
|
|
|
|
|
;============================
|
|
|
|
; Enable 50Hz clock on 6522
|
|
|
|
;============================
|
|
|
|
|
|
|
|
sei ; disable interrupts just in case
|
|
|
|
|
|
|
|
lda #$40 ; Continuous interrupts, don't touch PB7
|
|
|
|
sta $C40B ; ACR register
|
|
|
|
lda #$7F ; clear all interrupt flags
|
|
|
|
sta $C40E ; IER register (interrupt enable)
|
|
|
|
|
|
|
|
lda #$C0
|
|
|
|
sta $C40D ; IFR: 1100, enable interrupt on timer one oflow
|
|
|
|
sta $C40E ; IER: 1100, enable timer one interrupt
|
|
|
|
|
|
|
|
lda #$E7
|
|
|
|
sta $C404 ; write into low-order latch
|
|
|
|
lda #$4f
|
|
|
|
sta $C405 ; write into high-order latch,
|
|
|
|
; load both values into counter
|
|
|
|
; clear interrupt and start counting
|
|
|
|
|
|
|
|
; 4fe7 / 1e6 = .020s, 50Hz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-21 16:56:02 +00:00
|
|
|
;===========================
|
|
|
|
; clear both screens
|
|
|
|
;===========================
|
|
|
|
|
2018-05-24 16:42:27 +00:00
|
|
|
lda FORTYCOL
|
|
|
|
bne only_forty
|
|
|
|
|
|
|
|
switch_to_80:
|
|
|
|
|
|
|
|
; Initialize 80 column firmware
|
|
|
|
jsr $C300 ; same as PR#3
|
2018-05-24 17:25:35 +00:00
|
|
|
sta SET80COL ; 80store C001
|
|
|
|
; makes pageflip switch between
|
|
|
|
; regular/aux memory
|
2018-05-24 16:42:27 +00:00
|
|
|
|
|
|
|
only_forty:
|
|
|
|
|
2018-05-21 16:56:02 +00:00
|
|
|
; Clear text page0
|
2018-04-28 01:24:57 +00:00
|
|
|
|
2018-05-24 16:42:27 +00:00
|
|
|
jsr HOME
|
2018-04-28 01:24:57 +00:00
|
|
|
|
2018-05-21 17:33:08 +00:00
|
|
|
|
|
|
|
;============================
|
2018-05-23 16:50:12 +00:00
|
|
|
; Draw Lineart around edges
|
2018-05-21 17:33:08 +00:00
|
|
|
;============================
|
|
|
|
|
2018-05-23 18:07:19 +00:00
|
|
|
jsr setup_edges
|
2018-05-21 17:33:08 +00:00
|
|
|
|
2018-05-21 18:32:12 +00:00
|
|
|
jsr HOME
|
|
|
|
|
|
|
|
;==============================
|
|
|
|
; Setup lyrics
|
|
|
|
;==============================
|
2018-05-21 17:33:08 +00:00
|
|
|
|
2018-05-21 18:32:12 +00:00
|
|
|
lda #<(lyrics)
|
|
|
|
sta LYRICSL
|
|
|
|
lda #>(lyrics)
|
|
|
|
sta LYRICSH
|
2018-05-21 17:33:08 +00:00
|
|
|
|
|
|
|
|
2018-04-28 01:24:57 +00:00
|
|
|
;==================
|
2018-05-21 16:56:02 +00:00
|
|
|
; load song
|
2018-04-28 01:24:57 +00:00
|
|
|
;==================
|
|
|
|
|
2018-05-21 16:56:02 +00:00
|
|
|
jsr load_song
|
2018-04-28 01:24:57 +00:00
|
|
|
|
|
|
|
;============================
|
|
|
|
; Enable 6502 interrupts
|
|
|
|
;============================
|
|
|
|
|
|
|
|
cli ; clear interrupt mask
|
|
|
|
|
|
|
|
|
|
|
|
;============================
|
|
|
|
; Loop forever
|
|
|
|
;============================
|
|
|
|
main_loop:
|
|
|
|
lda DECODE_ERROR
|
|
|
|
beq check_copy
|
|
|
|
sei
|
2018-05-21 14:57:38 +00:00
|
|
|
brk ; panic if we had an error
|
|
|
|
|
2018-04-28 01:24:57 +00:00
|
|
|
|
|
|
|
check_copy:
|
|
|
|
lda COPY_TIME
|
|
|
|
beq check_decompress ; if zero, skip
|
|
|
|
|
|
|
|
lda #0
|
|
|
|
sta COPY_OFFSET
|
|
|
|
check_copy_loop:
|
|
|
|
jsr page_copy ;6+3621
|
|
|
|
|
|
|
|
inc COPY_OFFSET ; (opt: make subtract?) ; 5
|
|
|
|
|
|
|
|
lda #14 ; NOT HEX URGH!
|
|
|
|
cmp COPY_OFFSET
|
|
|
|
bne check_copy_loop
|
|
|
|
|
|
|
|
lda #0 ; we are done
|
|
|
|
sta COPY_TIME
|
|
|
|
|
|
|
|
check_decompress:
|
|
|
|
lda DECOMPRESS_TIME
|
|
|
|
beq check_done ; if zero, skip
|
|
|
|
|
|
|
|
jsr setup_next_subsong ; decompress
|
|
|
|
|
|
|
|
lda MB_CHUNK_OFFSET
|
|
|
|
sta TIME_TAKEN
|
|
|
|
|
|
|
|
lda #0
|
|
|
|
sta DECOMPRESS_TIME
|
|
|
|
|
|
|
|
|
|
|
|
check_done:
|
2018-05-22 03:46:47 +00:00
|
|
|
lda DONE_PLAYING
|
|
|
|
beq main_loop
|
2018-04-28 01:24:57 +00:00
|
|
|
|
|
|
|
forever_loop:
|
|
|
|
jmp forever_loop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;=================
|
2018-05-21 16:56:02 +00:00
|
|
|
; load our song
|
2018-04-28 01:24:57 +00:00
|
|
|
;=================
|
|
|
|
|
2018-05-21 16:56:02 +00:00
|
|
|
load_song:
|
2018-04-28 01:24:57 +00:00
|
|
|
|
|
|
|
;=========================
|
|
|
|
; Init Variables
|
|
|
|
;=========================
|
|
|
|
|
|
|
|
lda #$0
|
|
|
|
sta COPY_OFFSET
|
|
|
|
sta DECOMPRESS_TIME
|
|
|
|
sta COPY_TIME
|
|
|
|
sta MB_CHUNK_OFFSET
|
|
|
|
lda #$20
|
|
|
|
sta DECODER_STATE
|
|
|
|
lda #3
|
|
|
|
sta CHUNKSIZE
|
|
|
|
|
2018-05-21 19:12:53 +00:00
|
|
|
; We buffer one frame so start out one frame behind
|
|
|
|
lda #$ff
|
|
|
|
sta FRAME_COUNT
|
|
|
|
|
|
|
|
|
2018-04-28 01:24:57 +00:00
|
|
|
;===========================
|
2018-05-21 17:33:08 +00:00
|
|
|
; Setup KRW file
|
2018-04-28 01:24:57 +00:00
|
|
|
;===========================
|
|
|
|
|
|
|
|
; Point LZ4 src at proper place
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
lda #>(LZ4_BUFFER+3)
|
|
|
|
sta LZ4_SRC+1
|
|
|
|
lda #<(LZ4_BUFFER+3)
|
|
|
|
sta LZ4_SRC
|
|
|
|
|
|
|
|
lda (LZ4_SRC),Y ; get header skip
|
|
|
|
clc
|
|
|
|
adc LZ4_SRC
|
|
|
|
sta LZ4_SRC
|
|
|
|
lda LZ4_SRC+1
|
|
|
|
adc #0
|
|
|
|
sta LZ4_SRC+1
|
|
|
|
|
|
|
|
lda #<UNPACK_BUFFER ; set input pointer
|
|
|
|
sta INL
|
|
|
|
lda #>UNPACK_BUFFER
|
|
|
|
sta INH
|
|
|
|
|
|
|
|
; Decompress first chunks
|
|
|
|
|
|
|
|
lda #$0
|
|
|
|
sta COPY_OFFSET
|
|
|
|
sta DECOMPRESS_TIME
|
|
|
|
lda #$3
|
|
|
|
sta CHUNKSIZE
|
|
|
|
lda #$20
|
|
|
|
sta DECODER_STATE
|
|
|
|
sta COPY_TIME
|
|
|
|
|
|
|
|
jsr setup_next_subsong
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
;=================
|
|
|
|
; next sub-song
|
|
|
|
;=================
|
|
|
|
setup_next_subsong:
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
lda (LZ4_SRC),Y ; get next size value
|
|
|
|
sta LZ4_END
|
|
|
|
iny
|
|
|
|
lda (LZ4_SRC),Y
|
|
|
|
sta LZ4_END+1
|
|
|
|
|
|
|
|
lda #2 ; increment pointer
|
|
|
|
clc
|
|
|
|
adc LZ4_SRC
|
|
|
|
sta LZ4_SRC
|
|
|
|
lda LZ4_SRC+1
|
|
|
|
adc #0
|
|
|
|
sta LZ4_SRC+1
|
|
|
|
|
|
|
|
jsr lz4_decode ; decode
|
|
|
|
|
|
|
|
; tail-call?
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
;==============================================
|
|
|
|
; plan: takes 256 50Hz to play a chunk
|
|
|
|
; need to copy 14 256-byte blocks
|
|
|
|
; PLAY A (copying C)
|
|
|
|
; PLAY B (copying C)
|
|
|
|
; PLAY D (decompressing A/B/C)
|
|
|
|
|
|
|
|
|
|
|
|
;========================
|
|
|
|
; page copy
|
|
|
|
;========================
|
|
|
|
; want to copy:
|
|
|
|
; SRC: chunk_buffer+(2*256)+(COPY_OFFSET*3*256)
|
|
|
|
; DST: chunk_buffer+$2A00+(COPY_OFFSET*256)
|
|
|
|
page_copy:
|
|
|
|
clc ; 2
|
|
|
|
lda #>(UNPACK_BUFFER+512) ; 3
|
|
|
|
adc COPY_OFFSET ; 3
|
|
|
|
adc COPY_OFFSET ; 3
|
|
|
|
adc COPY_OFFSET ; 3
|
|
|
|
sta page_copy_loop+2 ; self modify ; 5
|
|
|
|
|
|
|
|
lda #>(UNPACK_BUFFER+$2A00) ; 2
|
|
|
|
adc COPY_OFFSET ; 3
|
|
|
|
sta page_copy_loop+5 ; self modify ; 5
|
|
|
|
|
|
|
|
ldx #$00 ; 2
|
|
|
|
page_copy_loop:
|
|
|
|
lda $1000,x ; 4
|
|
|
|
sta $1000,X ; 5
|
|
|
|
inx ; 2
|
|
|
|
bne page_copy_loop ; 2nt/3
|
|
|
|
rts ; 6
|
|
|
|
;======================
|
|
|
|
; 2+14*256+6+29= 3621
|
|
|
|
|
|
|
|
|
|
|
|
;=========
|
|
|
|
;routines
|
|
|
|
;=========
|
|
|
|
.include "../asm_routines/gr_offsets.s"
|
|
|
|
.include "../asm_routines/mockingboard_a.s"
|
|
|
|
.include "../asm_routines/lz4_decode.s"
|
|
|
|
|
2018-05-23 18:07:19 +00:00
|
|
|
.include "display_art.s"
|
|
|
|
.include "display_lyrics.s"
|
|
|
|
|
2018-04-28 01:24:57 +00:00
|
|
|
.include "interrupt_handler.s"
|
|
|
|
|
|
|
|
;=========
|
|
|
|
; strings
|
|
|
|
;=========
|
|
|
|
|
2018-05-21 17:33:08 +00:00
|
|
|
|
2018-05-21 18:32:12 +00:00
|
|
|
lyrics:
|
|
|
|
.include "lyrics.inc"
|
|
|
|
|
2018-05-23 20:09:44 +00:00
|
|
|
.include "ascii_art.inc"
|
2018-05-21 17:33:08 +00:00
|
|
|
|
|
|
|
LZ4_BUFFER:
|
2018-05-24 03:49:18 +00:00
|
|
|
.incbin "SA.KR4"
|
2018-05-21 17:33:08 +00:00
|
|
|
|