From dd18ecd1d97a3aac1eb9f1c7a9b713a47f1e6b70 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Sat, 25 May 2019 16:18:35 -0700 Subject: [PATCH] cut some bytes and cycles - fire_r_same/up are now 10/12 instead of 8/15 cycles some jmps can probably be replaced with appropriate branches instead --- pt3_player/fire.s | 60 +++--- pt3_player/gr_putsprite.s | 22 +- pt3_player/interrupt_handler.s | 28 ++- pt3_player/keypress_minimal.s | 14 +- pt3_player/mockingboard_a.s | 36 ++++ pt3_player/pt3_lib.s | 370 ++++++++++++++------------------- 6 files changed, 250 insertions(+), 280 deletions(-) diff --git a/pt3_player/fire.s b/pt3_player/fire.s index 1daa0dae..6ff591fa 100644 --- a/pt3_player/fire.s +++ b/pt3_player/fire.s @@ -33,9 +33,9 @@ done_fire_line_loop: lda FIRE_FB_L adc #40 sta FIRE_FB_L - lda FIRE_FB_H - adc #0 - sta FIRE_FB_H + bcc skip_inc_hi + inc FIRE_FB_H +skip_inc_hi: dex bne clear_fire_loop @@ -142,18 +142,18 @@ fire_low: ; Q=1 3/4 of time lda FIRE_Q ; 3 bne fire_one ; 0-3, is not 0 3/4 of time ; 2/3 - beq fire_zero ; 3 + beq fire_set ; 3 fire_medium: cmp #$d ; 2 + lda FIRE_Q ; 3 bcs fire_high ; bge ; 2/3 ; Q=1 1/2 of time - lda FIRE_Q ; 3 and #$1 ; 2 - jmp fire_set ; 3 + bcc fire_set ; branch always ; 3 fire_high: ; Q=1 1/4 of time - lda FIRE_Q ; is 0 1/4 of time ; 3 + ;;lda FIRE_Q ; is 0 1/4 of time ; 3 bne fire_zero ; 2/3 fire_one: lda #1 ; 2 @@ -174,7 +174,7 @@ fire_set: ; bounds check ; on edges, don't wrap - cpy #0 ; 2 + tya ; 2 beq fire_r_same ; 2/3 cpy #39 ; 2 beq fire_r_same ; 2/3 @@ -184,15 +184,14 @@ fire_set: ; 25% chance comes from right ; 25% change comes from left - lda #$2 ; 2 - bit SEEDH ; 3 - bne fire_r_same ; 2/3 lda SEEDH ; 3 + lsr ; 2 and #$1 ; 2 - beq r_up ; 2/3 + bne fire_r_same ; 2/3 + bcc r_up ; 2/3 r_down: dey ; 2 - jmp fire_r_same ; 3 + .byte $a9 ; 2 r_up: iny ; 2 fire_r_same: @@ -232,17 +231,17 @@ done_fire_fb_update_loop: lda fire_smc5_fb+1 ; 4 adc #40 ; 2 sta fire_smc5_fb+1 ; 4 - lda fire_smc5_fb+2 ; 4 - adc #0 ; 2 - sta fire_smc5_fb+2 ; 4 - + bcc skip_fb_inc1 ; 2/3 + inc fire_smc5_fb+2 ; 4 clc ; 2 +skip_fb_inc1: + lda fire_smc5_fb2+1 ; 4 adc #40 ; 2 sta fire_smc5_fb2+1 ; 4 - lda fire_smc5_fb2+2 ; 4 - adc #0 ; 2 - sta fire_smc5_fb2+2 ; 4 + bcc skip_fb2_inc1 ; 2/3 + inc fire_smc5_fb2+2 ; 4 +skip_fb2_inc1: inx ; 2 cpx #(FIRE_YSIZE-1) ; 2 @@ -259,11 +258,12 @@ fire_update_done: lda #fire_framebuffer ; 2 - sta fire_smc_fb+2 ; 5 - lda #<(fire_framebuffer+40) ; 2 sta fire_smc_fb2+1 ; 5 + + lda #>fire_framebuffer ; 2 + sta fire_smc_fb+2 ; 5 + ;this lda could be omitted if values match lda #>(fire_framebuffer+40) ; 2 sta fire_smc_fb2+2 ; 5 @@ -323,17 +323,17 @@ done_fire_fb_copy_loop: lda fire_smc_fb+1 ; 4 adc #80 ; 2 sta fire_smc_fb+1 ; 5 - lda fire_smc_fb+2 ; 4 - adc #0 ; 2 - sta fire_smc_fb+2 ; 5 - + bcc skip_fb_inc2 ; 2/3 + inc fire_smc_fb+2 ; 5 clc ; 2 +skip_fb_inc2: + lda fire_smc_fb2+1 ; 4 adc #80 ; 2 sta fire_smc_fb2+1 ; 5 - lda fire_smc_fb2+2 ; 4 - adc #0 ; 2 - sta fire_smc_fb2+2 ; 5 + bcc skip_fb2_inc2 ; 2/3 + inc fire_smc_fb2+2 ; 5 +skip_fb2_inc2: dex ; 2 bne fire_fb_copy ; 2/3 diff --git a/pt3_player/gr_putsprite.s b/pt3_player/gr_putsprite.s index ef31df4f..0b0b343f 100644 --- a/pt3_player/gr_putsprite.s +++ b/pt3_player/gr_putsprite.s @@ -21,27 +21,24 @@ put_sprite: sta CV ; ysize is in CV ; 3 iny ; 2 - lda YPOS ; make a copy of ypos ; 3 - sta TEMPY ; as we modify it ; 3 + ldx YPOS ; make a copy of ypos ; 3 ;=========== - ; 28 + ; 25 put_sprite_loop: - sty TEMP ; save sprite pointer ; 3 - ldy TEMPY ; 3 - lda gr_offsets,Y ; lookup low-res memory address ; 4 + stx TEMPY ; as we modify it ; 3 + lda gr_offsets,X ; lookup low-res memory address ; 4 clc ; 2 adc XPOS ; add in xpos ; 3 sta OUTL ; store out low byte of addy ; 3 - lda gr_offsets+1,Y ; look up high byte ; 4 + lda gr_offsets+1,X ; look up high byte ; 4 adc DRAW_PAGE ; ; 3 sta OUTH ; and store it out ; 3 - ldy TEMP ; restore sprite pointer ; 3 ; OUTH:OUTL now points at right place ldx CH ; load xsize into x ; 3 ;=========== - ; 34 + ; 28 put_sprite_pixel: lda (INL),Y ; get sprite colors ; 5 iny ; increment sprite pointer ; 2 @@ -88,12 +85,13 @@ put_sprite_done_draw: ;============== ; 12/13 - inc TEMPY ; each line has two y vars ; 5 - inc TEMPY ; 5 + ldx TEMPY ; 3 + inx ; each line has two y vars ; 2 + inx ; 2 dec CV ; decemenet total y count ; 5 bne put_sprite_loop ; loop if not done ; 2nt/3 ;============== - ; 17/18 + ; 14/15 rts ; return ; 6 diff --git a/pt3_player/interrupt_handler.s b/pt3_player/interrupt_handler.s index 6255e61f..63bfef92 100644 --- a/pt3_player/interrupt_handler.s +++ b/pt3_player/interrupt_handler.s @@ -52,7 +52,7 @@ pt3_play_music: sta current_subframe sta DONE_SONG ; undo the next song - jmp done_interrupt + beq done_interrupt ; branch always move_to_next: ; same as "press right" @@ -68,7 +68,7 @@ move_to_next: mb_write_frame: - ldx #0 ; set up reg count ; 2 + tax ; set up reg count ; 2 ;============ ; 2 @@ -138,10 +138,9 @@ update_time: inc frame_count_smc+1 ; 5 frame_count_smc: lda #$0 ; 2 - cmp #50 ; 3 + eor #50 ; 3 bne done_time ; 3/2nt - lda #$0 ; 2 sta frame_count_smc+1 ; 3 update_second_ones: @@ -168,7 +167,7 @@ update_minutes: ; we don't handle > 9:59 songs yet done_time: ;============= - ; 89 worst + ; 87 worst ;================================= @@ -184,7 +183,7 @@ check_keyboard: ;==================== ; space pauses - cmp #(' '+$80) + cmp #(' '+$80) ; set carry if true bne key_M key_space: lda #$80 @@ -195,7 +194,7 @@ key_space: sta DONE_PLAYING beq yes_bar lda #0 - jmp lowbar + beq lowbar ; branch always yes_bar: lda #7 lowbar: @@ -203,7 +202,7 @@ lowbar: lda DONE_PLAYING - jmp quiet_exit + bcs quiet_exit ; branch always ;=========================== ; M key switches MHz mode @@ -222,14 +221,14 @@ key_M: lda #'7'+$80 sta $7F4 sta $BF4 - jmp done_key + bne done_key ; branch always at_1MHz: lda #'0'+$80 sta $7F4 sta $BF4 - jmp done_key + bne done_key ; branch always ;=========================== @@ -249,14 +248,14 @@ key_L: lda #'L'+$80 sta $7D0+18 sta $BD0+18 - jmp done_key + bne done_key ; branch always music_looping: lda #'/'+$80 sta $7D0+18 sta $BD0+18 - jmp done_key + bne done_key ; branch always ;====================== @@ -277,10 +276,6 @@ key_right: bne done_key lda #$20 - bne quiet_exit - -done_key: - jmp exit_interrupt ;======================== ; stop playing for now @@ -294,6 +289,7 @@ quiet_exit: lda #$ff ; also mute the channel sta AY_REGISTERS+7 ; just in case +done_key: exit_interrupt: ; pla ; restore a ; 4 diff --git a/pt3_player/keypress_minimal.s b/pt3_player/keypress_minimal.s index f2e9a27e..16d7c815 100644 --- a/pt3_player/keypress_minimal.s +++ b/pt3_player/keypress_minimal.s @@ -7,40 +7,40 @@ get_key: lda KEYPRESS ; 3 bpl no_key ; 2nt/3 + bit KEYRESET ; clear the keyboard buffer ; 4 figure_out_key: cmp #' '+128 ; the mask destroys space ; 2 beq save_key ; so handle it specially ; 2nt/3 - and #$5f ; mask, to make upper-case ; 2 check_right_arrow: - cmp #$15 ; 2 + cmp #$95 ; 2 bne check_left_arrow ; 2nt/3 lda #'D' ; 2 check_left_arrow: - cmp #$08 ; 2 + cmp #$88 ; 2 bne check_up_arrow ; 2nt/3 lda #'A' ; 2 check_up_arrow: - cmp #$0B ; 2 + cmp #$8B ; 2 bne check_down_arrow ; 2nt/3 lda #'W' ; 2 check_down_arrow: - cmp #$0A ; 2 + cmp #$8A ; 2 bne check_escape ; 2nt/3 lda #'S' ; 2 check_escape: + and #$5f ; mask, to make upper-case ; 2 cmp #$1B ; 2 bne save_key ; 2nt/3 lda #'Q' ; 2 - jmp save_key ; 3 + bne save_key ; branch always ; 3 no_key: lda #0 ; no key, so save a zero ; 2 save_key: sta LASTKEY ; save the key to our buffer ; 2 - bit KEYRESET ; clear the keyboard buffer ; 4 rts ; 6 ;============ diff --git a/pt3_player/mockingboard_a.s b/pt3_player/mockingboard_a.s index fff7ca78..67ddca70 100644 --- a/pt3_player/mockingboard_a.s +++ b/pt3_player/mockingboard_a.s @@ -66,6 +66,7 @@ reset_ay_both: ; Reset Right AY-3-8910 ;====================== ;reset_ay_right: +;could be merged with both lda #MOCK_AY_RESET sta MOCK_6522_ORB2 lda #MOCK_AY_INACTIVE @@ -164,6 +165,41 @@ mb_not_in_this_slot: ldx #00 beq done_mb_detect +;alternative MB detection from Nox Archaist +; lda #$04 +; sta MB_ADDRL +; ldx #$c7 +; +;find_mb: +; stx MB_ADDRH +; +; ;detect sound I +; +; sec +; ldy #$00 +; lda (MB_ADDRL), y +; sbc (MB_ADDRL), y +; cmp #$05 +; beq found_mb +; dex +; cpx #$c0 +; bne find_mb +; ldx #$00 ;no mockingboard found +; rts +; +;found_mb: +; ldx #$01 ;mockingboard found +; rts +; +; ;optionally detect sound II +; +; sec +; ldy #$80 +; lda (MB_ADDRL), y +; sbc (MB_ADDRL), y +; cmp #$05 +; beq found_mb + ;======================================= ; Detect a Mockingboard card in Slot4 diff --git a/pt3_player/pt3_lib.s b/pt3_player/pt3_lib.s index 7872b9af..de091f02 100644 --- a/pt3_player/pt3_lib.s +++ b/pt3_player/pt3_lib.s @@ -277,7 +277,6 @@ load_ornament: ;pt3->ornament_patterns[i]= ; (pt3->data[0xaa+(i*2)]<<8)|pt3->data[0xa9+(i*2)]; - clc ; 2 asl ; A*2 ; 2 adc #PT3_ORNAMENT_LOC_L ; 2 tay ; 2 @@ -289,7 +288,6 @@ load_ornament: iny ; 2 lda PT3_LOC,Y ; 4+ - clc ; 2 ; we're assuming PT3 is loaded to a page boundary @@ -314,7 +312,6 @@ load_ornament: ; Set the pointer to the value past the length - clc ; 2 lda ORNAMENT_L ; 3 adc #$2 ; 2 sta note_a+NOTE_ORNAMENT_POINTER_L,X ; 5 @@ -327,7 +324,7 @@ load_ornament: rts ; 6 ;============ - ; 93 + ; 87 ;=========================== ; Load Sample @@ -353,7 +350,6 @@ load_sample: ;pt3->ornament_patterns[i]= ; (pt3->data[0x6a+(i*2)]<<8)|pt3->data[0x69+(i*2)]; - clc ; 2 asl ; A*2 ; 2 adc #PT3_SAMPLE_LOC_L ; 2 tay ; 2 @@ -366,7 +362,6 @@ load_sample: iny ; 2 lda PT3_LOC,Y ; 4+ - clc ; 2 ; assume pt3 file is at page boundary adc #>PT3_LOC ; 2 @@ -388,7 +383,6 @@ load_sample: ; Set pointer to beginning of samples - clc ; 2 lda SAMPLE_L ; 3 adc #$2 ; 2 sta note_a+NOTE_SAMPLE_POINTER_L,X ; 5 @@ -400,14 +394,15 @@ load_sample: rts ; 6 ;============ - ; 86 + ; 80 ;==================================== ; pt3_init_song ;==================================== ; ; TODO: change to a memset type instruction? - + ; it will save bytes only if the labels are adjacent + ; it will add a lot more cycles, though pt3_init_song: lda #$f ; 2 sta note_a+NOTE_VOLUME ; 4 @@ -436,7 +431,6 @@ pt3_init_song: sta pt3_envelope_type ; 4 ; default ornament/sample in A - lda #0 ; 2 ldx #(NOTE_STRUCT_SIZE*0) ; 2 jsr load_ornament ; 6+93 lda #1 ; 2 @@ -473,26 +467,23 @@ pt3_init_song: ;====================== ; calculate version - lda #6 ; 2 - sta pt3_version ; 3 + ldx #6 ; 2 lda PT3_LOC+PT3_VERSION ; 4 - cmp #'0' ; 2 - bcc not_ascii_number ; blt ; 2/3 - cmp #'9' ; 2 - bcs not_ascii_number ; bge ; 2/3 sec ; 2 sbc #'0' ; 2 - sta pt3_version ; 4 + cmp #9 ; 2 + bcs not_ascii_number ; bge ; 2/3 + tax ; 2 not_ascii_number: + stx pt3_version ; 3 ;======================= ; Pick which volume number, based on version ; if (PlParams.PT3.PT3_Version <= 4) - lda pt3_version ; 4 - cmp #5 ; 2 + cpx #5 ; 2 ; carry clear = 3.3/3.4 table ; carry set = 3.5 table @@ -519,7 +510,6 @@ calculate_note: lda note_a+NOTE_ENABLED,X ; 4+ bne note_enabled ; 2/3 - lda #0 ; 2 sta note_a+NOTE_AMPLITUDE,X ; 5 jmp done_note ; 3 @@ -552,44 +542,36 @@ note_enabled: ; a->tone = pt3->data[a->sample_pointer + a->sample_position*4+2]; ; a->tone+=(pt3->data[a->sample_pointer + a->sample_position*4+3])<<8; + ; a->tone += a->tone_accumulator; iny ; 2 + clc ; 2 lda (SAMPLE_L),Y ; 5+ + adc note_a+NOTE_TONE_ACCUMULATOR_L,X ; 4+ sta note_a+NOTE_TONE_L,X ; 4 iny ; 2 lda (SAMPLE_L),Y ; 5+ - sta note_a+NOTE_TONE_H,X ; 4 - - ; a->tone += a->tone_accumulator; - clc ; 2 - lda note_a+NOTE_TONE_L,X ; 4+ - adc note_a+NOTE_TONE_ACCUMULATOR_L,X ; 4+ - sta note_a+NOTE_TONE_L,X ; 4+ - lda note_a+NOTE_TONE_H,X ; 4+ adc note_a+NOTE_TONE_ACCUMULATOR_H,X ; 4+ - sta note_a+NOTE_TONE_H,X ; 4+ + sta note_a+NOTE_TONE_H,X ; 4 ;============================= ; Accumulate tone if set ; (if sample_b1 & $40) - lda #$40 ; if (b1&0x40) bit sample_b1 - beq no_accum ; (so, if b1&0x40 is zero, skip it) + bvc no_accum ; (so, if b1&0x40 is zero, skip it) + sta note_a+NOTE_TONE_ACCUMULATOR_H,X lda note_a+NOTE_TONE_L,X ; tone_accumulator=tone sta note_a+NOTE_TONE_ACCUMULATOR_L,X - lda note_a+NOTE_TONE_H,X - sta note_a+NOTE_TONE_ACCUMULATOR_H,X no_accum: ;============================ ; Calculate tone ; j = a->note + (pt3->data[a->ornament_pointer + a->ornament_position] - clc - lda note_a+NOTE_ORNAMENT_POSITION,X - tay + clc ;;can be removed if ADC ACCUMULATOR_H cannot overflow + ldy note_a+NOTE_ORNAMENT_POSITION,X lda (ORNAMENT_L),Y adc note_a+NOTE_NOTE,X @@ -620,7 +602,7 @@ note_not_too_high: adc note_a+NOTE_TONE_SLIDING_H,X sta note_a+NOTE_TONE_H,X - clc + clc ;;can be removed if ADC SLIDING_H cannot overflow lda note_a+NOTE_TONE_L,X adc freq_l sta note_a+NOTE_TONE_L,X @@ -641,7 +623,7 @@ note_not_too_high: ; a->tone_sliding+=a->tone_slide_step - clc + clc ;;can be removed if ADC freq_h cannot overflow lda note_a+NOTE_TONE_SLIDING_L,X adc note_a+NOTE_TONE_SLIDE_STEP_L,X sta note_a+NOTE_TONE_SLIDING_L,X @@ -725,17 +707,15 @@ calc_amplitude: ; adjust amplitude sliding - lda sample_b0 ; if ((b0 & 0x80)!=0) { - and #$80 - beq done_amp_sliding ; so if top bit not set, skip + bit sample_b0 ; if ((b0 & 0x80)!=0) { + bpl done_amp_sliding ; so if top bit not set, skip ;================================ ; if top bits 0b11 then slide up ; if top buts 0b10 then slide down - lda sample_b0 ; if ((b0&0x40)!=0) { - and #$40 - beq amp_slide_down + ; if ((b0 & 0x40)!=0) { + bvc amp_slide_down amp_slide_up: ; if (a->amplitude_sliding < 15) { @@ -748,7 +728,7 @@ amp_slide_up: asu_signed: bpl done_amp_sliding ; skip if A>=15 inc note_a+NOTE_AMPLITUDE_SLIDING,X ; a->amplitude_sliding++; - jmp done_amp_sliding + bne done_amp_sliding amp_slide_down: ; if (a->amplitude_sliding > -15) { @@ -777,7 +757,7 @@ done_amp_sliding: check_amp_lo: bpl check_amp_hi lda #0 - jmp write_clamp_amplitude + beq write_clamp_amplitude check_amp_hi: cmp #16 @@ -830,15 +810,23 @@ check_envelope_enable: envelope_slide: + lda sample_b0 + lsr + tay + ; Envelope slide ; If b1 top bits are 10 or 11 - lda #$80 - bit sample_b1 - beq else_noise_slide ; if ((b1 & 0x80) != 0) { - lda #$20 bit sample_b0 + php + + bit sample_b1 + bpl else_noise_slide ; if ((b1 & 0x80) != 0) { + + plp + php +;;bug? always falls through beq envelope_slide_down ; if ((b0 & 0x20) != 0) { ; FIXME: this can be optimized @@ -846,17 +834,16 @@ envelope_slide: envelope_slide_down: ; j = ((b0>>1)|0xF0) + a->envelope_sliding - lda sample_b0 - lsr + tya ora #$f0 clc adc note_a+NOTE_ENVELOPE_SLIDING,X sta e_slide_amount ; j +;;+jmp envelope_slide_done? envelope_slide_up: ; j = ((b0>>1)&0xF) + a->envelope_sliding; - lda sample_b0 - lsr + tya and #$0f clc adc note_a+NOTE_ENVELOPE_SLIDING,X @@ -864,12 +851,10 @@ envelope_slide_up: envelope_slide_done: - lda #$20 - bit sample_b1 + plp beq last_envelope ; if (( b1 & 0x20) != 0) { ; a->envelope_sliding = j; - lda e_slide_amount sta note_a+NOTE_ENVELOPE_SLIDING,X last_envelope: @@ -888,18 +873,15 @@ else_noise_slide: ; else { ; pt3->noise_add = (b0>>1) + a->noise_sliding; - lda sample_b0 - lsr + tya clc adc note_a+NOTE_NOISE_SLIDING,X sta pt3_noise_add - lda #$20 - bit sample_b1 + plp beq noise_slide_done ; if ((b1 & 0x20) != 0) { ; noise_sliding = pt3_noise_add - lda pt3_noise_add sta note_a+NOTE_NOISE_SLIDING,X noise_slide_done: @@ -946,9 +928,7 @@ done_note: ; set mixer value ; this is a bit complex (from original code) ; after 3 calls it is set up properly - lda pt3_mixer_value - lsr - sta pt3_mixer_value + lsr pt3_mixer_value handle_onoff: lda note_a+NOTE_ONOFF,X ;if (a->onoff>0) { @@ -1188,16 +1168,7 @@ decode_case_bX: and #$f beq decode_case_b0 cmp #1 - beq decode_case_b1 - jmp decode_case_bx_higher - -decode_case_b0: - ; Disable envelope - lda #0 - sta note_a+NOTE_ENVELOPE_ENABLED,X - sta note_a+NOTE_ORNAMENT_POSITION,X - jmp done_decode - + bne decode_case_bx_higher decode_case_b1: ; Set Length @@ -1210,6 +1181,13 @@ decode_case_b1: sta note_a+NOTE_LEN_COUNT,X jmp done_decode +decode_case_b0: + ; Disable envelope + sta note_a+NOTE_ENVELOPE_ENABLED,X + sta note_a+NOTE_ORNAMENT_POSITION,X + jmp done_decode + + decode_case_bx_higher: sec @@ -1233,7 +1211,6 @@ decode_case_cX: decode_case_c0: ; special case $C0 means shut down the note - lda #0 sta note_a+NOTE_ENABLED,X ; enabled=0 jsr reset_note ; 6+69 @@ -1263,11 +1240,6 @@ decode_case_dX: lda #1 sta decode_done - jmp done_decode -decode_case_dx_not_d0: - - jsr load_sample ; load sample in bottom nybble - jmp done_decode decode_case_eX: ;============================== @@ -1279,10 +1251,13 @@ decode_case_eX: lda note_command sec sbc #$d0 - jsr load_sample + ;fall through + +decode_case_dx_not_d0: + + jsr load_sample ; load sample in bottom nybble jmp done_decode - decode_case_fX: ;============================== ; $FX - change ornament/sample @@ -1333,6 +1308,10 @@ effect_1: cmp #$1 bne effect_2 + sta note_a+NOTE_SIMPLE_GLISS,X + lsr + sta note_a+NOTE_ONOFF,X + lda (PATTERN_L),Y ; load byte, set as slide delay iny @@ -1347,11 +1326,6 @@ effect_1: iny sta note_a+NOTE_TONE_SLIDE_STEP_H,X - lda #0 - sta note_a+NOTE_ONOFF,X - lda #1 - sta note_a+NOTE_SIMPLE_GLISS,X - jmp no_effect ;============================== @@ -1389,12 +1363,11 @@ effect_2_small: ; FIXME: make smaller sta note_a+NOTE_TONE_SLIDE_STEP_H,X lda note_a+NOTE_TONE_SLIDE_STEP_L,X eor #$ff - clc - adc #$1 + adc #$0 ;+carry set by earlier CMP sta note_a+NOTE_TONE_SLIDE_STEP_L,X - lda note_a+NOTE_TONE_SLIDE_STEP_H,X - adc #$0 - sta note_a+NOTE_TONE_SLIDE_STEP_H,X + bcc skip_step_inc1 + inc note_a+NOTE_TONE_SLIDE_STEP_H,X +skip_step_inc1: slide_step_positive: @@ -1460,9 +1433,9 @@ weird_version: clc adc #$1 sta note_a+NOTE_TONE_SLIDE_STEP_L,X - lda note_a+NOTE_TONE_SLIDE_STEP_H,X - adc #$0 - sta note_a+NOTE_TONE_SLIDE_STEP_H,X + bcc skip_step_inc2 + inc note_a+NOTE_TONE_SLIDE_STEP_H,X +skip_step_inc2: no_need: @@ -1597,13 +1570,13 @@ set_envelope: lda (PATTERN_L),Y ; 5+ sta pt3_envelope_period_l ; 4 - lda #0 ; 2 + lda #1 ; 2 + sta note_a+NOTE_ENVELOPE_ENABLED,X ; envelope_enabled=1 ; 5 + lsr ; 2 sta note_a+NOTE_ORNAMENT_POSITION,X ; ornament_position=0 ; 5 sta pt3_envelope_delay ; envelope_delay=0 ; 4 sta pt3_envelope_slide_l ; envelope_slide=0 ; 4 sta pt3_envelope_slide_h ; 4 - lda #1 ; 2 - sta note_a+NOTE_ENVELOPE_ENABLED,X ; envelope_enabled=1 ; 5 rts ; 6 ;=========== @@ -1750,13 +1723,15 @@ not_done: ; update pattern or line if necessary ; then calculate the values for the next frame + ;========================== + ; pattern done early! -pt3_make_frame: +early_end: + inc current_pattern ; increment pattern ; 6 + sta current_line ; 4 + sta current_subframe ; 4 - ; see if we need a new pattern - ; we do if line==0 and subframe==0 - lda current_line ; 4 - bne pattern_good ; 2/3 +check_subframe: lda current_subframe ; 4 bne pattern_good ; 2/3 @@ -1767,6 +1742,14 @@ pt3_make_frame: beq pattern_good ; 2/3 rts ; 6 +pt3_make_frame: + + ; see if we need a new pattern + ; we do if line==0 and subframe==0 + ; allow fallthrough where possible + lda current_line ; 4 + beq check_subframe ; 2/3 + pattern_good: ; see if we need a new line @@ -1779,16 +1762,7 @@ pattern_good: ; check if pattern done early lda pt3_pattern_done ; 4 - bne line_good ; 2/3 - - ;========================== - ; pattern done early! - - inc current_pattern ; increment pattern ; 6 - lda #0 ; 2 - sta current_line ; 4 - sta current_subframe ; 4 - jmp pt3_make_frame ; 3 + beq early_end ; 2/3 line_good: @@ -1798,22 +1772,20 @@ line_good: lda current_subframe ; 4 ; if we hit pt3_speed, move to next - cmp pt3_speed ; 4 + eor pt3_speed ; 4 bne do_frame ; 2/3 next_line: - lda #0 ; reset subframe to 0 ; 2 - sta current_subframe ; 4 + sta current_subframe ; reset subframe to 0 ; 4 inc current_line ; and increment line ; 6 lda current_line ; 4 - cmp #64 ; always end at 64. ; 2 + eor #64 ; always end at 64. ; 2 bne do_frame ; is this always needed? ; 2/3 next_pattern: - lda #0 ; reset line to 0 ; 2 - sta current_line ; 4 + sta current_line ; reset line to 0 ; 4 inc current_pattern ; increment pattern ; 6 @@ -1830,7 +1802,6 @@ do_frame: ; R13 = Envelope Shape, 0xff means don't write ; R14/R15 = I/O (ignored) - lda #0 ; 2 sta pt3_mixer_value ; 4 sta pt3_envelope_add ; 4 @@ -1841,133 +1812,124 @@ do_frame: ldx #(NOTE_STRUCT_SIZE*2) ; Note C ; 2 jsr calculate_note ; 6+? - ; Load up the Frequency Registers - - lda note_a+NOTE_TONE_L ; Note A Period L ; 4 - sta AY_REGISTERS+0 ; into R0 ; 3 - lda note_a+NOTE_TONE_H ; Note A Period H ; 4 - sta AY_REGISTERS+1 ; into R1 ; 3 - ; FIXME: make this self-modifying? lda convert_177 ; 4 - beq no_scale_a ; 2/3 + cmp #1 ; 2 + + ; Load up the Frequency Registers + + lda note_a+NOTE_TONE_H ; Note A Period H ; 4 + sta AY_REGISTERS+1 ; into R1 ; 3 + lda note_a+NOTE_TONE_L ; Note A Period L ; 4 + bcc no_scale_a ; 2/3 ; Convert from 1.77MHz to 1MHz by multiplying by 9/16 ; conversion costs 100 cycles! ; first multiply by 8 - asl AY_REGISTERS+0 ; 5 + asl ; 2 rol AY_REGISTERS+1 ; 5 - asl AY_REGISTERS+0 ; 5 + asl ; 2 rol AY_REGISTERS+1 ; 5 - asl AY_REGISTERS+0 ; 5 + asl ; 2 rol AY_REGISTERS+1 ; 5 ; add in original to get 9 clc ; 2 - lda note_a+NOTE_TONE_L ; 4 - adc AY_REGISTERS+0 ; 3 + adc note_a+NOTE_TONE_L ; 4 sta AY_REGISTERS+0 ; 3 lda note_a+NOTE_TONE_H ; 4 adc AY_REGISTERS+1 ; 3 - sta AY_REGISTERS+1 ; 3 ; divide by 16 to get proper value - ror AY_REGISTERS+1 ; 5 + ror ; 2 ror AY_REGISTERS+0 ; 5 - ror AY_REGISTERS+1 ; 5 + ror ; 2 ror AY_REGISTERS+0 ; 5 - ror AY_REGISTERS+1 ; 5 + ror ; 2 ror AY_REGISTERS+0 ; 5 - ror AY_REGISTERS+1 ; 5 + ror ; 2 ror AY_REGISTERS+0 ; 5 - lda AY_REGISTERS+1 ; 3 and #$0f ; 2 sta AY_REGISTERS+1 ; 3 no_scale_a: - lda note_b+NOTE_TONE_L ; Note B Period L ; 4 - sta AY_REGISTERS+2 ; into R2 ; 3 + lda convert_177 ; 4 + cmp #1 ; 2 + lda note_b+NOTE_TONE_H ; Note B Period H ; 4 sta AY_REGISTERS+3 ; into R3 ; 3 - - lda convert_177 ; 4 - beq no_scale_b ; 2/3 + lda note_b+NOTE_TONE_L ; Note B Period L ; 4 + bcc no_scale_b ; 2/3 ; Convert from 1.77MHz to 1MHz by multiplying by 9/16 ; first multiply by 8 - asl AY_REGISTERS+2 ; 5 + asl ; 2 rol AY_REGISTERS+3 ; 5 - asl AY_REGISTERS+2 ; 5 + asl ; 2 rol AY_REGISTERS+3 ; 5 - asl AY_REGISTERS+2 ; 5 + asl ; 2 rol AY_REGISTERS+3 ; 5 ; add in original to get 9 clc ; 2 - lda note_b+NOTE_TONE_L ; 4 - adc AY_REGISTERS+2 ; 3 + adc note_b+NOTE_TONE_L ; 4 sta AY_REGISTERS+2 ; 3 lda note_b+NOTE_TONE_H ; 4 adc AY_REGISTERS+3 ; 3 - sta AY_REGISTERS+3 ; 3 ; divide by 16 to get proper value - ror AY_REGISTERS+3 ; 5 + ror ; 2 ror AY_REGISTERS+2 ; 5 - ror AY_REGISTERS+3 ; 5 + ror ; 2 ror AY_REGISTERS+2 ; 5 - ror AY_REGISTERS+3 ; 5 + ror ; 2 ror AY_REGISTERS+2 ; 5 - ror AY_REGISTERS+3 ; 5 + ror ; 2 ror AY_REGISTERS+2 ; 5 - lda AY_REGISTERS+3 ; 3 and #$0f ; 2 sta AY_REGISTERS+3 ; 3 no_scale_b: - lda note_c+NOTE_TONE_L ; Note C Period L ; 4 - sta AY_REGISTERS+4 ; into R4 ; 3 + lda convert_177 ; 4 + cmp #1 ; 2 + lda note_c+NOTE_TONE_H ; Note C Period H ; 4 sta AY_REGISTERS+5 ; into R5 ; 3 - - lda convert_177 ; 4 - beq no_scale_c ; 2/3 + lda note_c+NOTE_TONE_L ; Note C Period L ; 4 + bcc no_scale_c ; 2/3 ; Convert from 1.77MHz to 1MHz by multiplying by 9/16 ; first multiply by 8 - asl AY_REGISTERS+4 ; 5 + asl ; 2 rol AY_REGISTERS+5 ; 5 - asl AY_REGISTERS+4 ; 5 + asl ; 2 rol AY_REGISTERS+5 ; 5 - asl AY_REGISTERS+4 ; 5 + asl ; 2 rol AY_REGISTERS+5 ; 5 ; add in original to get 9 clc ; 2 - lda note_c+NOTE_TONE_L ; 4 - adc AY_REGISTERS+4 ; 3 + adc note_c+NOTE_TONE_L ; 4 sta AY_REGISTERS+4 ; 3 lda note_c+NOTE_TONE_H ; 4 adc AY_REGISTERS+5 ; 3 - sta AY_REGISTERS+5 ; 3 ; divide by 16 to get proper value - ror AY_REGISTERS+5 ; 5 + ror ; 2 ror AY_REGISTERS+4 ; 5 - ror AY_REGISTERS+5 ; 5 + ror ; 2 ror AY_REGISTERS+4 ; 5 - ror AY_REGISTERS+5 ; 5 + ror ; 2 ror AY_REGISTERS+4 ; 5 - ror AY_REGISTERS+5 ; 5 + ror ; 2 ror AY_REGISTERS+4 ; 5 - lda AY_REGISTERS+5 ; 3 and #$0f ; 2 sta AY_REGISTERS+5 ; 3 @@ -1981,7 +1943,6 @@ no_scale_c: adc pt3_noise_add ; 4 and #$1f ; 2 sta AY_REGISTERS+6 ; 3 - sta temp_word_l ; 4 lda convert_177 ; 3 beq no_scale_n ; 2/3 @@ -1989,21 +1950,20 @@ no_scale_c: ; Convert from 1.77MHz to 1MHz by multiplying by 9/16 ; first multiply by 8 - asl AY_REGISTERS+6 ; 5 - asl AY_REGISTERS+6 ; 5 - asl AY_REGISTERS+6 ; 5 + lda AY_REGISTERS+6 ; 3 + asl ; 2 + asl ; 2 + asl ; 2 ; add in original to get 9 clc ; 2 - lda temp_word_l ; 4 - adc AY_REGISTERS+6 ; 3 + adc temp_word_l ; 4 ; divide by 16 to get proper value - ror AY_REGISTERS+6 ; 5 - ror AY_REGISTERS+6 ; 5 - ror AY_REGISTERS+6 ; 5 - ror AY_REGISTERS+6 ; 5 - lda AY_REGISTERS+6 ; 3 + ror ; 2 + ror ; 2 + ror ; 2 + ror ; 2 and #$1f ; 2 sta AY_REGISTERS+6 ; 3 @@ -2039,7 +1999,6 @@ no_scale_n: clc ; 2 lda pt3_envelope_slide_l ; 4 adc temp_word_l ; 4 - sta temp_word_l ; 4 sta AY_REGISTERS+11 ; 3 lda temp_word_h ; 4 adc pt3_envelope_slide_h ; 4 @@ -2052,32 +2011,30 @@ no_scale_n: ; Convert from 1.77MHz to 1MHz by multiplying by 9/16 ; first multiply by 8 - asl AY_REGISTERS+11 ; 5 + lda AY_REGISTERS+11 ; 3 + asl ; 2 rol AY_REGISTERS+12 ; 5 - asl AY_REGISTERS+11 ; 5 + asl ; 2 rol AY_REGISTERS+12 ; 5 - asl AY_REGISTERS+11 ; 5 + asl ; 2 rol AY_REGISTERS+12 ; 5 ; add in original to get 9 clc ; 2 - lda temp_word_l ; 4 adc AY_REGISTERS+11 ; 3 sta AY_REGISTERS+11 ; 3 lda temp_word_h ; 4 adc AY_REGISTERS+12 ; 3 - sta AY_REGISTERS+12 ; 3 ; divide by 16 to get proper value - ror AY_REGISTERS+12 ; 5 + ror ; 2 ror AY_REGISTERS+11 ; 5 - ror AY_REGISTERS+12 ; 5 + ror ; 2 ror AY_REGISTERS+11 ; 5 - ror AY_REGISTERS+12 ; 5 + ror ; 2 ror AY_REGISTERS+11 ; 5 - ror AY_REGISTERS+12 ; 5 + ror ; 2 ror AY_REGISTERS+11 ; 5 - lda AY_REGISTERS+12 ; 3 and #$0f ; 2 sta AY_REGISTERS+12 ; 3 @@ -2088,15 +2045,13 @@ no_scale_e: lda pt3_envelope_type ; 4 cmp pt3_envelope_type_old ; 4 + sta pt3_envelope_type_old ; copy old to new ; 4 bne envelope_diff ; 2/3 envelope_same: lda #$ff ; if same, store $ff ; 2 envelope_diff: sta AY_REGISTERS+13 ; 3 - lda pt3_envelope_type ; 4 - sta pt3_envelope_type_old ; copy old to new ; 4 - ;============================== @@ -2318,34 +2273,19 @@ vol_outer: pha ; save HL clc ; add HL,DE - lda z80_l adc z80_e - sta z80_l + sta z80_e lda z80_h adc z80_d - sta z80_h ; carry is important - - lda z80_h ; ex de,hl ; swap - pha - lda z80_l - pha - lda z80_d - sta z80_h - lda z80_e - sta z80_l - pla - sta z80_e - pla - sta z80_d + sta z80_d ; carry is important ; sbc hl,hl + lda #$ff bcs vol_ffs vol_zeros: lda #0 - beq vol_write vol_ffs: - lda #$ff vol_write: sta z80_h sta z80_l