pt3: start implementing things

This commit is contained in:
Vince Weaver 2019-05-07 00:28:42 -04:00
parent a4699be604
commit 39b68db975
10 changed files with 382 additions and 246 deletions

Binary file not shown.

View File

@ -11,7 +11,7 @@ $(DOS33):
pt3_player.dsk: PT3_PLAYER HELLO
cp empty.dsk pt3_player.dsk
$(DOS33) -y pt3_player.dsk SAVE A HELLO
$(DOS33) -y pt3_player.dsk BSAVE -a 0x0800 PT3_PLAYER
$(DOS33) -y pt3_player.dsk BSAVE -a 0x1000 PT3_PLAYER
$(DOS33) -y pt3_player.dsk BSAVE -a 0x2000 EA.PT3
# $(DOS33) -y chiptune_player.dsk BSAVE -a 0x1c00 ./krw/CHRISTMAS.KRW
# $(DOS33) -y chiptune_player.dsk BSAVE -a 0x1c00 ./krw/CRMOROS.KRW
@ -36,9 +36,10 @@ HELLO: hello.bas
../asoft_basic-utils/tokenize_asoft < hello.bas > HELLO
PT3_PLAYER: pt3_player.o
ld65 -o PT3_PLAYER pt3_player.o -C ../linker_scripts/apple2_800.inc
ld65 -o PT3_PLAYER pt3_player.o -C ../linker_scripts/apple2_1000.inc
pt3_player.o: pt3_player.s
pt3_player.o: pt3_player.s \
gr_fast_clear.s pt3.s
# mockingboard.s \
# keypress_minimal.s \
# qkumba_rts.s \

14
pt3_player/TODO Normal file
View File

@ -0,0 +1,14 @@
Notes into background?
Colored, octave is color?
AA
AA 5555
A A 5
AAAA 555
A A 5
A A 555

193
pt3_player/gr_fast_clear.s Normal file
View File

@ -0,0 +1,193 @@
clear_screens:
;===================================
; Clear top/bottom of page 0
;===================================
lda #$0
sta DRAW_PAGE
jsr clear_top
jsr clear_bottom
;===================================
; Clear top/bottom of page 1
;===================================
lda #$4
sta DRAW_PAGE
jsr clear_top
jsr clear_bottom
rts
clear_bottoms:
;===================================
; Clear bottom of page 0
;===================================
lda #$0
sta DRAW_PAGE
jsr clear_bottom
;===================================
; Clear bottom of page 1
;===================================
lda #$4
sta DRAW_PAGE
jsr clear_bottom
rts
;=========================================================
; clear_top
;=========================================================
; clear DRAW_PAGE
; original = 14,558 cycles(?) 15ms, 70Hz
; OPTIMIZED MAX (page0,48rows): 45*120+4+6 = 5410 = 5.4ms 185Hz
; (pageX,40rows): 50*120+4+6 = 6010 = 6.0ms 166Hz
; 50*120+4+6+37 = 6055 = 6.0ms 166Hz
clear_top:
lda #0 ; 2
clear_top_a:
sta COLOR ; 3
clc ; 2
lda DRAW_PAGE ; 3
adc #4 ; 2
sta __ctf+2 ; 3
sta __ctf+5 ; 3
adc #1 ; 2
sta __ctf+8 ; 3
sta __ctf+11 ; 3
adc #1 ; 2
sta __ctf2+2 ; 3
sta __ctf2+5 ; 3
adc #1 ; 2
sta __ctf2+8 ; 3
sta __ctf2+11 ; 3
ldy #120 ; 2
lda COLOR ; 3
clear_top_fast_loop:
__ctf:
sta $400,Y ; 5
sta $480,Y ; 5
sta $500,Y ; 5
sta $580,Y ; 5
cpy #80 ; 2
bpl no_draw_bottom ; 2nt/3
__ctf2:
sta $600,Y ; 5
sta $680,Y ; 5
sta $700,Y ; 5
sta $780,Y ; 5
no_draw_bottom:
dey ; 2
bpl clear_top_fast_loop ; 2nt/3
rts ; 6
;=========================================================
; clear_bottom
;=========================================================
; clear bottom of draw page
clear_bottom:
clc ; 2
lda DRAW_PAGE ; 3
adc #6 ; 2
sta __cbf2+2 ; 3
sta __cbf2+5 ; 3
adc #1 ; 2
sta __cbf2+8 ; 3
sta __cbf2+11 ; 3
ldy #119 ; 2
lda #$a0 ; Normal Space ; 2
clear_bottom_fast_loop:
__cbf2:
sta $600,Y ; 5
sta $680,Y ; 5
sta $700,Y ; 5
sta $780,Y ; 5
dey ; 2
cpy #80 ; 2
bpl clear_bottom_fast_loop ; 2nt/3
rts ; 6
clear_screens_notext:
;===================================
; Clear top/bottom of page 0
;===================================
lda #$0
sta DRAW_PAGE
jsr clear_all
;===================================
; Clear top/bottom of page 1
;===================================
lda #$4
sta DRAW_PAGE
jsr clear_all
rts
;=========================================================
; clear_all
;=========================================================
; clear 48 rows
; clear color: clear_all_color+1
clear_all:
clc ; 2
lda DRAW_PAGE ; 3
adc #4 ; 2
sta __caf+2 ; 3
sta __caf+5 ; 3
adc #1 ; 2
sta __caf+8 ; 3
sta __caf+11 ; 3
adc #1 ; 2
sta __caf2+2 ; 3
sta __caf2+5 ; 3
adc #1 ; 2
sta __caf2+8 ; 3
sta __caf2+11 ; 3
ldy #120 ; 2
clear_all_color:
lda #0 ; 2
clear_all_fast_loop:
__caf:
sta $400,Y ; 5
sta $480,Y ; 5
sta $500,Y ; 5
sta $580,Y ; 5
__caf2:
sta $600,Y ; 5
sta $680,Y ; 5
sta $700,Y ; 5
sta $780,Y ; 5
dey ; 2
bpl clear_all_fast_loop ; 2nt/3
rts ; 6

View File

@ -291,13 +291,13 @@ done_time:
; Visualization
;============================
jsr clear_top
lda RASTERBARS_ON
beq skip_rasters
jsr draw_rasters
skip_rasters:
jsr volume_bars
jsr page_flip
; jsr clear_top
; lda RASTERBARS_ON
; beq skip_rasters
; jsr draw_rasters
;skip_rasters:
; jsr volume_bars
; jsr page_flip
check_keyboard:

93
pt3_player/pt3.s Normal file
View File

@ -0,0 +1,93 @@
; TODO
; move some of these flags to be bits rather than bytes?
; enabled could be bit 6 or 7 for fast checking
;
; Use memset to set things to 0?
NOTE_WHICH=0
NOTE_VOLUME=1
NOTE_TONE_SLIDING=2
NOTE_ENABLED=3
NOTE_ENVELOPE_ENABLED=4
NOTE_SAMPLE_POINTER=5
NOTE_SAMPLE_LOOP=7
NOTE_SAMPLE_LENGTH=8
note_a:
.byte 'A' ; NOTE_WHICH
.byte $0 ; NOTE_VOLUME
.byte $0 ; NOTE_TONE_SLIDING
.byte $0 ; NOTE_ENABLED
.byte $0 ; NOTE_ENVELOPE_ENABLED
.word $0 ; NOTE_SAMPLE_POINTER
.byte $0 ; NOTE_SAMPLE_LOOP
.byte $0 ; NOTE_SAMPLE_LENGTH
note_b:
.byte 'B' ; NOTE_WHICH
.byte $0 ; NOTE_VOLUME
.byte $0 ; NOTE_TONE_SLIDING
.byte $0 ; NOTE_ENABLED
.byte $0 ; NOTE_ENVELOPE_ENABLED
.word $0 ; NOTE_SAMPLE_POINTER
.byte $0 ; NOTE_SAMPLE_LOOP
.byte $0 ; NOTE_SAMPLE_LENGTH
note_c:
.byte 'C' ; NOTE_WHICH
.byte $0 ; NOTE_VOLUME
.byte $0 ; NOTE_TONE_SLIDING
.byte $0 ; NOTE_ENABLED
.byte $0 ; NOTE_ENVELOPE_ENABLED
.word $0 ; NOTE_SAMPLE_POINTER
.byte $0 ; NOTE_SAMPLE_LOOP
.byte $0 ; NOTE_SAMPLE_LENGTH
pt3_noise_period: .byte $0
pt3_noise_add: .byte $0
pt3_envelope_period: .byte $0
pt3_envelope_type: .byte $0
pt3_current_pattern: .byte $0
load_ornament:
rts
load_sample:
rts
pt3_init_song:
lda #$f
sta note_a+NOTE_VOLUME
sta note_b+NOTE_VOLUME
sta note_c+NOTE_VOLUME
lda #$0
sta note_a+NOTE_TONE_SLIDING
sta note_b+NOTE_TONE_SLIDING
sta note_c+NOTE_TONE_SLIDING
sta note_a+NOTE_ENABLED
sta note_b+NOTE_ENABLED
sta note_c+NOTE_ENABLED
sta note_a+NOTE_ENVELOPE_ENABLED
sta note_b+NOTE_ENVELOPE_ENABLED
sta note_c+NOTE_ENVELOPE_ENABLED
lda #'A'
jsr load_ornament
lda #'A'
jsr load_sample
lda #'B'
jsr load_ornament
lda #'B'
jsr load_sample
lda #'C'
jsr load_ornament
lda #'C'
jsr load_sample
lda #$0
sta pt3_noise_period
sta pt3_noise_add
sta pt3_envelope_period
sta pt3_envelope_type
sta pt3_current_pattern
rts

Binary file not shown.

View File

@ -1,33 +1,20 @@
; VMW Chiptune Player
.include "zp.inc"
; program is ~4k, so from 0xc00 to 0x1C00
LZ4_BUFFER EQU $1C00 ; $1C00 - $5C00, 16k for now
DISK_BUFFER EQU $5D00 ; for disk loading
PT3_LOC = $2000
UNPACK_BUFFER EQU $6000 ; $6000 - $9800, 14k, $3800
; by using qkumba's RTS code
; no need for DOS, so we actually
; are free the whole way to $C000
; instead of stopping at $9600
; $6000 - $C000 = 24k
NUM_FILES EQU 15
jmp chiptune_setup
.include "chip_title_uncompressed.inc"
.align $400
;=============================
; Setup
;=============================
chiptune_setup:
; jsr HOME
; jsr TEXT
pt3_setup:
jsr HOME
jsr TEXT
; Init disk code
@ -36,22 +23,16 @@ chiptune_setup:
; init variables
lda #0
sta DRAW_PAGE
sta CH
sta CV
sta DONE_PLAYING
sta MB_CHUNK_OFFSET
sta DECODE_ERROR
; lda #0
; lda #4 ; start at DEMO4
; lda #7 ; start at LYRA
; lda #10 ; start at SDEMO
; sta DRAW_PAGE
; sta CH
; sta CV
; sta DONE_PLAYING
; sta MB_CHUNK_OFFSET
; sta DECODE_ERROR
sta WHICH_FILE
lda #$ff
sta RASTERBARS_ON
; lda #$ff
; sta RASTERBARS_ON
; print detection message
@ -96,10 +77,10 @@ mockingboard_found:
; Vector address goes to 0x3fe/0x3ff
; FIXME: should chain any existing handler
lda #<interrupt_handler
sta $03fe
lda #>interrupt_handler
sta $03ff
; lda #<interrupt_handler
; sta $03fe
; lda #>interrupt_handler
; sta $03ff
;============================
; Enable 50Hz clock on 6522
@ -161,65 +142,26 @@ mockingboard_found:
;============================
; Init Background
;============================
jsr set_gr_page0
; jsr set_gr_page0
lda #0
sta DRAW_PAGE
sta SCREEN_Y
; lda #0
; sta DRAW_PAGE
; sta SCREEN_Y
;============================
; Enable 6502 interrupts
;============================
cli ; clear interrupt mask
; cli ; clear interrupt mask
;============================
; Loop forever
;============================
main_loop:
lda DECODE_ERROR
beq check_copy
sei
brk
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
;============================
; visualization
;============================
; jsr clear_top
; jsr draw_rasters
; jsr volume_bars
; jsr page_flip
jmp main_loop
check_done:
lda #$ff
@ -271,19 +213,19 @@ new_song:
; Init Variables
;=========================
lda #$0
sta FRAME_COUNT
sta A_VOLUME
sta B_VOLUME
sta C_VOLUME
sta COPY_OFFSET
sta DECOMPRESS_TIME
sta COPY_TIME
sta MB_CHUNK_OFFSET
lda #$20
sta DECODER_STATE
lda #3
sta CHUNKSIZE
; lda #$0
; sta FRAME_COUNT
; sta A_VOLUME
; sta B_VOLUME
; sta C_VOLUME
; sta COPY_OFFSET
; sta DECOMPRESS_TIME
; sta COPY_TIME
; sta MB_CHUNK_OFFSET
; lda #$20
; sta DECODER_STATE
; lda #3
; sta CHUNKSIZE
;===========================
; Print loading message
@ -304,7 +246,7 @@ new_song:
;===========================
; Load in KRW file
; Load in PT3 file
;===========================
jsr get_filename
@ -349,9 +291,9 @@ space_loop:
done_name_loop:
; open and read a file
; loads to whatever it was BSAVED at (default is $1C00)
; loads to whatever it was BSAVED at (default is $2000)
jsr read_file ; read KRW file from disk
jsr read_file ; read PT3 file from disk
;=========================
@ -360,24 +302,34 @@ done_name_loop:
jsr clear_bottoms ; clear bottom of page 0/1
lda #>LZ4_BUFFER ; point to LZ4 data
sta OUTH
lda #<LZ4_BUFFER
sta OUTL
ldy #3 ; skip KRW magic at front
; NUL terminate the strings we want to print
lda #0
sta PT3_LOC+$3E
sta PT3_LOC+$62
; print title
lda #>(PT3_LOC+$1E) ; point to header title
sta OUTH
lda #<(PT3_LOC+$1E)
sta OUTL
lda #20 ; VTAB 20: HTAB from file
jsr print_header_info
; Print Author
lda #>(PT3_LOC+$42) ; point to header title
sta OUTH
lda #<(PT3_LOC+$42)
sta OUTL
lda #21 ; VTAB 21: HTAB from file
jsr print_header_info
; Print clock
lda #23 ; VTAB 23: HTAB from file
jsr print_header_info
; lda #23 ; VTAB 23: HTAB from file
; jsr print_header_info
; Print Left Arrow (INVERSE)
lda #'<'
@ -397,74 +349,10 @@ done_name_loop:
sta $777
sta $B77
; 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
jsr pt3_init_song
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
;===================
; print header info
@ -475,63 +363,11 @@ setup_next_subsong:
print_header_info:
sta CV
iny ; adjust pointer
tya
ldy #0
clc
adc OUTL
sta OUTL
lda OUTH
adc #$0
sta OUTH
lda (OUTL),Y ; get HTAB value
lda #4
sta CH
inc OUTL ; increment 16-bits
bne bloop22
inc OUTH
bloop22:
jmp print_both_pages ; print, tail call
;==============================================
; 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
;==================
@ -546,9 +382,9 @@ get_filename:
ldy #0
ldx WHICH_FILE
lda #<krw_file ; point to filename
lda #<song_list ; point to filename
sta INL
lda #>krw_file
lda #>song_list
sta INH
get_filename_loop:
@ -604,7 +440,7 @@ done_decrement:
; filenames
;==========
krw_file:
song_list:
.include "song_list.inc"
@ -614,7 +450,7 @@ krw_file:
.include "../asm_routines/gr_offsets.s"
.include "text_print.s"
.include "../asm_routines/mockingboard_a.s"
.include "../asm_routines/gr_fast_clear.s"
.include "gr_fast_clear.s"
.include "../asm_routines/pageflip.s"
;.include "../asm_routines/gr_unrle.s"
.include "../asm_routines/gr_setpage.s"
@ -622,13 +458,11 @@ krw_file:
.include "../asm_routines/gr_hlin.s"
.include "../asm_routines/lz4_decode.s"
.include "../asm_routines/keypress_minimal.s"
.include "rasterbars.s"
.include "volume_bars.s"
.if .def(UNROLLED)
.include "interrupt_handler_unrolled.s"
.else
;.include "rasterbars.s"
;.include "volume_bars.s"
.include "interrupt_handler.s"
.endif
.include "pt3.s"
;=========
; strings
;=========

View File

@ -19,8 +19,7 @@
; tmptrk = $f9 ; temporary copy of current track
; phase = $fa ; current phase for /seek
dirbuf = $5d00
;$1e00 ; note, don't put this immediately below
dirbuf = $c00 ; note, don't put this immediately below
; the value being read as destaddr-4
; is temporarily overwritten during read
; process

2
pt3_player/song_list.inc Normal file
View File

@ -0,0 +1,2 @@
.asciiz "EA.PT3"