diff --git a/demosplash/Makefile b/demosplash/Makefile index 07f71533..c0f059b0 100644 --- a/demosplash/Makefile +++ b/demosplash/Makefile @@ -51,7 +51,7 @@ musictest.o: musictest.s \ zp.inc hardware.inc \ appleII_intro.s font.s \ pt3_lib_init.s pt3_lib_core.s pt3_lib_mockingboard.s \ - pt3_lib_play_frame.s \ + pt3_lib_play_frame.s pt3_lib_write_frame.s \ interrupt_handler.s \ dya_space_demo2.pt3 ca65 -o musictest.o musictest.s -l musictest.lst diff --git a/demosplash/appleII_intro.s b/demosplash/appleII_intro.s index b196e947..63d24449 100644 --- a/demosplash/appleII_intro.s +++ b/demosplash/appleII_intro.s @@ -159,9 +159,9 @@ page1_loop: ; delay 115+(7 loop)+4 (bit)+4(extra) ; -1174 ; -7 (keypress) ; -3 (jump) - ; -1182 (play_music) + ; -1186 (play_music) ; ===== - ; 2183 + ; 2179 jsr do_nothing ; 6 @@ -414,7 +414,7 @@ intro_wipe_done: no_keypress2: - jsr play_frame_compressed ; 6+1176 + jsr play_frame_compressed ; 6+1180 jmp display_loop ; 3 @@ -426,13 +426,13 @@ appleii_done: ;================================= ; do nothing ;================================= - ; and take 2183-12 = 2171 cycles to do it + ; and take 2179-12 = 2167 cycles to do it do_nothing: - ; Try X=5 Y=70 cycles=2171 + ; Try X=71 Y=6 cycles=2167 - ldy #70 ; 2 -loop1: ldx #5 ; 2 + ldy #6 ; 2 +loop1: ldx #71 ; 2 loop2: dex ; 2 bne loop2 ; 2nt/3 dey ; 2 diff --git a/demosplash/musictest.s b/demosplash/musictest.s index 9ad136d0..14941872 100644 --- a/demosplash/musictest.s +++ b/demosplash/musictest.s @@ -23,7 +23,26 @@ demosplash2019: ; generate 4 patterns worth of music ; at address $9000 - + lda #0 + sta FRAME_PAGE + + lda #0 + sta FRAME_OFFSET + +frame_decode_loop: + jsr pt3_make_frame + + jsr pt3_write_frame + + inc FRAME_OFFSET + bne frame_decode_loop + + inc FRAME_PAGE + lda FRAME_PAGE + cmp #5 + bne frame_decode_loop + + ; lda #1 ; sta LOOP @@ -142,6 +161,7 @@ wait_until_keypressed: .include "pt3_lib_mockingboard.s" .include "interrupt_handler.s" .include "pt3_lib_play_frame.s" +.include "pt3_lib_write_frame.s" PT3_LOC = song diff --git a/demosplash/pt3_lib_play_frame.s b/demosplash/pt3_lib_play_frame.s index 1727afb9..49a680e6 100644 --- a/demosplash/pt3_lib_play_frame.s +++ b/demosplash/pt3_lib_play_frame.s @@ -2,19 +2,19 @@ ;0 $9000,$9100,$9200 = A Low (reg0) - ;1 $9300,$9400,$9500 = A high (reg1) B high (reg3) + ;1 $9300,$9400,$9500 = A high (reg1) [top], B high (reg3) [bottom] ;2 $9600,$9700,$9800 = B Low (reg2) ;3 $9900,$9A00,$9B00 = C Low (reg4) - ;4 $9C00,$9D00,$9E00 = C high (reg5), Envelope Shape (r13) + ;4 $9C00,$9D00,$9E00 = Envelope Shape (r13) [top], C high (reg5) [bot] ;5 $9F00,$A000,$A100 = Noise (r6), bit7 = don't change envelope ;6 $A200,$A300,$A400 = Enable (r7) ;7 $A500,$A600,$A700 = A amp (r8), bit 5 of r8,r9,r10 - ;8 $A800,$A900,$AA00 = B/C amp (r9/r10) + ;8 $A800,$A900,$AA00 = C amp (r10) [top], B amp (r9) [bottom] ;9 $AB00,$AC00,$AD00 = ENV low (r11) ;a $AE00,$AF00,$B000 = ENV high (r12) ; 3+ 72 + 72 + 83 + 74 + 72 + 77 + 19 + 70 + 74 + 72 + - ; 77 + 14 + 82 + 85 + 72 + 72 + 8 + 72 + 6 = 1176 + ; 77 + 18 + 82 + 85 + 72 + 72 + 8 + 72 + 6 = 1180 play_frame_compressed: @@ -132,14 +132,16 @@ r8_smc: ; 77 pla ; 4 + and #$e0 ; 2 lsr ; 2 sta AY_REGISTERS ; 3 lsr ; 2 + and #$10 ; 2 sta AY_REGISTERS+1 ; 3 ;==== - ; 14 + ; 18 - ; Register 9: b-amp + ; Register 9: b-amp (bottom) ldx #9 ; 2 r9_smc: lda $A800,Y ; 4+ @@ -151,7 +153,7 @@ r9_smc: ;======= ; 82 - ; Register 10: c-amp + ; Register 10: c-amp (top) ldx #10 ; 2 pla ; 4 lsr ; 2 diff --git a/demosplash/pt3_lib_write_frame.s b/demosplash/pt3_lib_write_frame.s new file mode 100644 index 00000000..43ef8d7f --- /dev/null +++ b/demosplash/pt3_lib_write_frame.s @@ -0,0 +1,186 @@ + ; ZZ points to offset from pointer + + + ;0 $9000,$9100,$9200 = A Low (reg0) + ;1 $9300,$9400,$9500 = A high (reg1) [top], B high (reg3) [bottom] + ;2 $9600,$9700,$9800 = B Low (reg2) + ;3 $9900,$9A00,$9B00 = C Low (reg4) + ;4 $9C00,$9D00,$9E00 = Envelope Shape (r13) [top], C high (reg5) [bot] + ;5 $9F00,$A000,$A100 = Noise (r6), bit7 = don't change envelope + ;6 $A200,$A300,$A400 = Enable (r7) + ;7 $A500,$A600,$A700 = A amp (r8), bit 5 of r8,r9,r10 + ;8 $A800,$A900,$AA00 = C amp (r10) [top], B amp (r9) [bottom] + ;9 $AB00,$AC00,$AD00 = ENV low (r11) + ;a $AE00,$AF00,$B000 = ENV high (r12) + + +pt3_write_frame: + + ldy FRAME_OFFSET ; 3 + + ;===================== + ; Register 0: A fine + lda A_FINE_TONE +r0_wrsmc: + sta $9000,Y + + ;========================== + ; Register 1/3: A/B coarse + lda A_COARSE_TONE + asl + asl + asl + asl + ora B_COARSE_TONE +r1_wrsmc: + sta $9300,Y + + ;==================== + ; Register 2: B fine + lda B_FINE_TONE +r2_wrsmc: + sta $9600,Y + + ;==================== + ; Register 3: B coarse already done + + + ;============================= + ; Register 4: C fine + lda C_FINE_TONE +r4_wrsmc: + sta $9900,Y + + ;======================================= + ; Register 5: Envelope Shape [top] / C coarse [bottom] + lda C_COARSE_TONE + and #$f + sta C_COARSE_TONE + + lda ENVELOPE_SHAPE + cmp #$ff + beq no_envelope +yes_envelope: + + lda ENVELOPE_SHAPE + asl + asl + asl + asl + ora C_COARSE_TONE + sta C_COARSE_TONE + + lda #0 + sta ENVELOPE_SHAPE + jmp done_envelope +no_envelope: + lda #$80 + sta ENVELOPE_SHAPE + +done_envelope: + + lda C_COARSE_TONE +r13_wrsmc: + sta $9C00,Y + + + ;===================== + ; Register 6: Noise + lda NOISE + and #$1f + ora ENVELOPE_SHAPE +r6_smcwr: + sta $9F00,Y + + ;===================== + ; Register 7: Enable + lda ENABLE +r7_smcwr: + sta $A200,Y + + ;===================== + ; Register 8: a-amp + + lda A_VOLUME + and #$1f + sta A_VOLUME + + lda B_VOLUME + and #$10 + asl + ora A_VOLUME + sta A_VOLUME + + lda C_VOLUME + and #$10 + asl + asl + ora A_VOLUME +r8_wrsmc: + sta $A500,Y + + ;============================ + ; Register 9/10: b-amp (bottom) , c-amp (top) + + lda B_VOLUME + and #$f + sta B_VOLUME + + lda C_VOLUME + asl + asl + asl + asl + ora B_VOLUME +r9_wrsmc: + sta $A800,Y + + ;===================== + ; Register 10: c-amp already handled + + + ;===================== + ; Register 11: E fine + lda ENVELOPE_FINE +r11_wrsmc: + sta $AB00,Y + + ;======================= + ; Register 12: E coarse + lda ENVELOPE_COARSE +r12_wrsmc: + sta $AE00,Y + + ;============================= + ; Register 13: already handled + + +.if 0 + +no_frame_wrap: + ; -1 + ; delay 72+1-3=70 + lda #43 ; 70-2-25=43 + jsr delay_a + + jmp done_frame_wrap ; 3 +frame_wrap: + inc r0_smc+2 ; 6 + inc r1_smc+2 ; 6 + inc r2_smc+2 ; 6 + inc r4_smc+2 ; 6 + inc r5_smc+2 ; 6 + inc r13_smc+2 ; 6 + inc r6_smc+2 ; 6 + inc r7_smc+2 ; 6 + inc r8_smc+2 ; 6 + inc r9_smc+2 ; 6 + inc r11_smc+2 ; 6 + inc r12_smc+2 ; 6 + ;===== + ; 72 +done_frame_wrap: + +.endif + rts ; 6 + diff --git a/demosplash/zp.inc b/demosplash/zp.inc index 2669d110..f87f6c6e 100644 --- a/demosplash/zp.inc +++ b/demosplash/zp.inc @@ -59,6 +59,7 @@ ZERO = $B0 WASTE_CYCLES = $B1 FOREVER_OFFSET = $B2 FRAME_OFFSET = $B3 +FRAME_PAGE = $B4 FRAMEL = $60 FRAMEH = $61