From 2d7a8d1374d879a0f8f4845b56ea56e2d2534318 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 4 Jun 2018 14:57:40 -0400 Subject: [PATCH] sa: merge MB and ED versions --- still_alive/Makefile | 16 +- still_alive/README.still_alive | 3 +- still_alive/sa_ed.s | 42 +---- still_alive/sa_mb.s | 317 ++++++++++++++++++++++++++++++++ still_alive/still_alive.s | 321 ++------------------------------- 5 files changed, 342 insertions(+), 357 deletions(-) create mode 100644 still_alive/sa_mb.s diff --git a/still_alive/Makefile b/still_alive/Makefile index ae3c999f..3143d486 100644 --- a/still_alive/Makefile +++ b/still_alive/Makefile @@ -5,11 +5,10 @@ TOKENIZE = ../asoft_basic-utils/tokenize_asoft all: still_alive.dsk -still_alive.dsk: STILL_ALIVE TITLE.BAS ENDING SA_ED +still_alive.dsk: STILL_ALIVE TITLE.BAS ENDING $(DOS33) -y still_alive.dsk BSAVE -a 0x0C00 STILL_ALIVE $(DOS33) -y still_alive.dsk BSAVE -a 0x2000 ENDING $(DOS33) -y still_alive.dsk SAVE A TITLE.BAS - $(DOS33) -y still_alive.dsk BSAVE -a 0x0C00 SA_ED # $(DOS33) -y still_alive.dsk SAVE B GLADOS.HGR STILL_ALIVE: still_alive.o @@ -19,21 +18,12 @@ still_alive.o: still_alive.s \ ../asm_routines/mockingboard.s \ ../asm_routines/lz4_decode.s \ display_art.s display_lyrics.s \ + sa_ed.s duet.s SA.ED \ + ascii_art.inc \ interrupt_handler.s \ ascii_art.inc ascii_art_lz4.inc lyrics.inc zp.inc ca65 -o still_alive.o still_alive.s -l still_alive.lst - -SA_ED: sa_ed.o - ld65 -o SA_ED sa_ed.o -C ../linker_scripts/apple2_c00.inc - -sa_ed.o: sa_ed.s \ - duet.s SA.ED \ - display_art.s display_lyrics.s \ - ascii_art.inc - ca65 -o sa_ed.o sa_ed.s -l sa_ed.lst - - ENDING: ending.o ld65 -o ENDING ending.o -C ../linker_scripts/apple2_2000.inc diff --git a/still_alive/README.still_alive b/still_alive/README.still_alive index e5f9a80d..f8019ba9 100644 --- a/still_alive/README.still_alive +++ b/still_alive/README.still_alive @@ -35,6 +35,7 @@ feature complete 40 col: 20180 intial 80 col support: 20191 80 col cursor: 20344 strip out some unneeded text printing: 19962 +merge ED and MB code 24993 Memory Map @@ -57,7 +58,7 @@ Code: c00 - 8c00 32k Sound buffers: 5e00-9600 = 14k Plan: - 16k compressed Load at 32k? 8000 + 16k compressed Load at 16k? 4000 20k decompressed Decompress from 0c00 - 6000 or so diff --git a/still_alive/sa_ed.s b/still_alive/sa_ed.s index 96f464b3..d5d6092a 100644 --- a/still_alive/sa_ed.s +++ b/still_alive/sa_ed.s @@ -1,12 +1,6 @@ -; And Believe Me, I'm Still Alive +; Electric Duet Code Path -.include "zp.inc" - - ;============================= - ; Setup - ;============================= - jsr HOME - jsr TEXT +still_alive_ed: ; init variables @@ -20,8 +14,6 @@ ; clear both screens ;=========================== -only_forty: - ; Clear text page0 ; jsr HOME @@ -59,34 +51,8 @@ only_forty: ; loop forever ;================== -forever_loop: - jmp forever_loop +forever_loop_ed: + jmp forever_loop_ed -;========= -;routines -;========= -.include "../asm_routines/gr_offsets.s" -;.include "../asm_routines/lz4_decode.s" - -.include "display_art.s" -.include "display_lyrics.s" - -;.include "interrupt_handler.s" - -.include "duet.s" - -;========= -; strings -;========= - - -lyrics: -.include "sa.edlyrics" - -.include "ascii_art.inc" - - -music_address: -.incbin "SA.ED" diff --git a/still_alive/sa_mb.s b/still_alive/sa_mb.s new file mode 100644 index 00000000..5c14053b --- /dev/null +++ b/still_alive/sa_mb.s @@ -0,0 +1,317 @@ + + ; program is ~16k, so from 0xc00 to 0x4C00 +UNPACK_BUFFER EQU $5E00 ; $5E00 - $9600, 14k, $3800 + ; trying not to hit DOS at $9600 + ; Reserve 3 chunks plus spare (14k) + + +still_alive_mb: + + ;============================= + ; Setup + ;============================= + jsr HOME + jsr TEXT + + ; init variables + + lda #0 + sta DONE_PLAYING + sta MB_CHUNK_OFFSET + sta DECODE_ERROR + sta LYRICS_ACTIVE + + ; Testing, let's get 40col working first + lda #0 + sta FORTYCOL + + jsr mockingboard_detect_slot4 ; call detection routine + cpx #$1 + beq mockingboard_found + + ; Not found. + ; Print a message for debugging? + 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 $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 + + + + + ;=========================== + ; clear both screens + ;=========================== + + lda FORTYCOL + bne only_forty + +switch_to_80: + + ; Initialize 80 column firmware + jsr $C300 ; same as PR#3 + sta SET80COL ; 80store C001 + ; makes pageflip switch between + ; regular/aux memory + +only_forty: + + ; Clear text page0 + + jsr HOME + + + ;============================ + ; Draw Lineart around edges + ;============================ + + jsr setup_edges + + jsr HOME + + ;============================== + ; Setup lyrics + ;============================== + + lda #<(lyrics) + sta LYRICSL + lda #>(lyrics) + sta LYRICSH + + + ;================== + ; load song + ;================== + + jsr load_song + + ;============================ + ; Enable 6502 interrupts + ;============================ + + cli ; clear interrupt mask + + + ;============================ + ; Loop forever + ;============================ +main_loop: + lda DECODE_ERROR + beq check_copy + sei + brk ; panic if we had an error + + +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: + lda DONE_PLAYING + beq main_loop + +forever_loop: + jmp forever_loop + + + + ;================= + ; load our song + ;================= + +load_song: + + ;========================= + ; 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 + + ; We buffer one frame so start out one frame behind + lda #$ff + sta FRAME_COUNT + + + ;=========================== + ; Setup KRW file + ;=========================== + + ; 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 + 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 + + + + diff --git a/still_alive/still_alive.s b/still_alive/still_alive.s index 76b5b752..d4747053 100644 --- a/still_alive/still_alive.s +++ b/still_alive/still_alive.s @@ -1,316 +1,19 @@ ; And Believe Me, I'm Still Alive .include "zp.inc" - ; program is ~16k, so from 0xc00 to 0x4C00 -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 +still_alive: + jsr still_alive_mb + jsr still_alive_ed - ; init variables - lda #0 - sta DONE_PLAYING - sta MB_CHUNK_OFFSET - sta DECODE_ERROR - sta LYRICS_ACTIVE - ; Testing, let's get 40col working first - lda #0 - sta FORTYCOL - - jsr mockingboard_detect_slot4 ; call detection routine - cpx #$1 - beq mockingboard_found - - ; Not found. - ; Print a message for debugging? - 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 $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 - - - - - ;=========================== - ; clear both screens - ;=========================== - - lda FORTYCOL - bne only_forty - -switch_to_80: - - ; Initialize 80 column firmware - jsr $C300 ; same as PR#3 - sta SET80COL ; 80store C001 - ; makes pageflip switch between - ; regular/aux memory - -only_forty: - - ; Clear text page0 - - jsr HOME - - - ;============================ - ; Draw Lineart around edges - ;============================ - - jsr setup_edges - - jsr HOME - - ;============================== - ; Setup lyrics - ;============================== - - lda #<(lyrics) - sta LYRICSL - lda #>(lyrics) - sta LYRICSH - - - ;================== - ; load song - ;================== - - jsr load_song - - ;============================ - ; Enable 6502 interrupts - ;============================ - - cli ; clear interrupt mask - - - ;============================ - ; Loop forever - ;============================ -main_loop: - lda DECODE_ERROR - beq check_copy - sei - brk ; panic if we had an error - - -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: - lda DONE_PLAYING - beq main_loop - -forever_loop: - jmp forever_loop - - - - ;================= - ; load our song - ;================= - -load_song: - - ;========================= - ; 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 - - ; We buffer one frame so start out one frame behind - lda #$ff - sta FRAME_COUNT - - - ;=========================== - ; Setup KRW file - ;=========================== - - ; 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 - 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 +;========== +; main code +;========== +.include "sa_mb.s" +.include "sa_ed.s" ;========= ;routines @@ -324,6 +27,8 @@ page_copy_loop: .include "interrupt_handler.s" +.include "duet.s" + ;========= ; strings ;========= @@ -332,8 +37,14 @@ page_copy_loop: lyrics: .include "lyrics.inc" +lyrics_ed: +.include "sa.edlyrics" + .include "ascii_art.inc" LZ4_BUFFER: .incbin "SA.KR4" +music_address: +.incbin "SA.ED" +