Revert "cut some bytes and cycles"

This reverts commit dd18ecd1d9.
This commit is contained in:
Vince Weaver 2019-05-30 10:54:03 -04:00
parent 79b9b17bac
commit 2e4a237fff
6 changed files with 281 additions and 251 deletions

View File

@ -33,9 +33,9 @@ done_fire_line_loop:
lda FIRE_FB_L
adc #40
sta FIRE_FB_L
bcc skip_inc_hi
inc FIRE_FB_H
skip_inc_hi:
lda FIRE_FB_H
adc #0
sta FIRE_FB_H
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_set ; 3
beq fire_zero ; 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
bcc fire_set ; branch always ; 3
jmp fire_set ; 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
tya ; 2
cpy #0 ; 2
beq fire_r_same ; 2/3
cpy #39 ; 2
beq fire_r_same ; 2/3
@ -184,14 +184,15 @@ fire_set:
; 25% chance comes from right
; 25% change comes from left
lda SEEDH ; 3
lsr ; 2
and #$1 ; 2
lda #$2 ; 2
bit SEEDH ; 3
bne fire_r_same ; 2/3
bcc r_up ; 2/3
lda SEEDH ; 3
and #$1 ; 2
beq r_up ; 2/3
r_down:
dey ; 2
.byte $a9 ; 2
jmp fire_r_same ; 3
r_up:
iny ; 2
fire_r_same:
@ -231,17 +232,17 @@ done_fire_fb_update_loop:
lda fire_smc5_fb+1 ; 4
adc #40 ; 2
sta fire_smc5_fb+1 ; 4
bcc skip_fb_inc1 ; 2/3
inc fire_smc5_fb+2 ; 4
clc ; 2
skip_fb_inc1:
lda fire_smc5_fb+2 ; 4
adc #0 ; 2
sta fire_smc5_fb+2 ; 4
clc ; 2
lda fire_smc5_fb2+1 ; 4
adc #40 ; 2
sta fire_smc5_fb2+1 ; 4
bcc skip_fb2_inc1 ; 2/3
inc fire_smc5_fb2+2 ; 4
skip_fb2_inc1:
lda fire_smc5_fb2+2 ; 4
adc #0 ; 2
sta fire_smc5_fb2+2 ; 4
inx ; 2
cpx #(FIRE_YSIZE-1) ; 2
@ -258,12 +259,11 @@ fire_update_done:
lda #<fire_framebuffer ; 2
sta fire_smc_fb+1 ; 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+1 ; 5
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
bcc skip_fb_inc2 ; 2/3
inc fire_smc_fb+2 ; 5
clc ; 2
skip_fb_inc2:
lda fire_smc_fb+2 ; 4
adc #0 ; 2
sta fire_smc_fb+2 ; 5
clc ; 2
lda fire_smc_fb2+1 ; 4
adc #80 ; 2
sta fire_smc_fb2+1 ; 5
bcc skip_fb2_inc2 ; 2/3
inc fire_smc_fb2+2 ; 5
skip_fb2_inc2:
lda fire_smc_fb2+2 ; 4
adc #0 ; 2
sta fire_smc_fb2+2 ; 5
dex ; 2
bne fire_fb_copy ; 2/3

View File

@ -21,24 +21,27 @@ put_sprite:
sta CV ; ysize is in CV ; 3
iny ; 2
ldx YPOS ; make a copy of ypos ; 3
lda YPOS ; make a copy of ypos ; 3
sta TEMPY ; as we modify it ; 3
;===========
; 25
; 28
put_sprite_loop:
stx TEMPY ; as we modify it ; 3
lda gr_offsets,X ; lookup low-res memory address ; 4
sty TEMP ; save sprite pointer ; 3
ldy TEMPY ; 3
lda gr_offsets,Y ; 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,X ; look up high byte ; 4
lda gr_offsets+1,Y ; 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
;===========
; 28
; 34
put_sprite_pixel:
lda (INL),Y ; get sprite colors ; 5
iny ; increment sprite pointer ; 2
@ -85,13 +88,12 @@ put_sprite_done_draw:
;==============
; 12/13
ldx TEMPY ; 3
inx ; each line has two y vars ; 2
inx ; 2
inc TEMPY ; each line has two y vars ; 5
inc TEMPY ; 5
dec CV ; decemenet total y count ; 5
bne put_sprite_loop ; loop if not done ; 2nt/3
;==============
; 14/15
; 17/18
rts ; return ; 6

View File

@ -52,7 +52,7 @@ pt3_play_music:
sta current_subframe
sta DONE_SONG ; undo the next song
beq done_interrupt ; branch always
jmp done_interrupt
move_to_next:
; same as "press right"
@ -68,7 +68,7 @@ move_to_next:
mb_write_frame:
tax ; set up reg count ; 2
ldx #0 ; set up reg count ; 2
;============
; 2
@ -138,9 +138,10 @@ update_time:
inc frame_count_smc+1 ; 5
frame_count_smc:
lda #$0 ; 2
eor #50 ; 3
cmp #50 ; 3
bne done_time ; 3/2nt
lda #$0 ; 2
sta frame_count_smc+1 ; 3
update_second_ones:
@ -167,7 +168,7 @@ update_minutes:
; we don't handle > 9:59 songs yet
done_time:
;=============
; 87 worst
; 89 worst
;=================================
@ -183,7 +184,7 @@ check_keyboard:
;====================
; space pauses
cmp #(' '+$80) ; set carry if true
cmp #(' '+$80)
bne key_M
key_space:
lda #$80
@ -194,7 +195,7 @@ key_space:
sta DONE_PLAYING
beq yes_bar
lda #0
beq lowbar ; branch always
jmp lowbar
yes_bar:
lda #7
lowbar:
@ -202,7 +203,7 @@ lowbar:
lda DONE_PLAYING
bcs quiet_exit ; branch always
jmp quiet_exit
;===========================
; M key switches MHz mode
@ -221,14 +222,14 @@ key_M:
lda #'7'+$80
sta $7F4
sta $BF4
bne done_key ; branch always
jmp done_key
at_1MHz:
lda #'0'+$80
sta $7F4
sta $BF4
bne done_key ; branch always
jmp done_key
;===========================
@ -248,14 +249,14 @@ key_L:
lda #'L'+$80
sta $7D0+18
sta $BD0+18
bne done_key ; branch always
jmp done_key
music_looping:
lda #'/'+$80
sta $7D0+18
sta $BD0+18
bne done_key ; branch always
jmp done_key
;======================
@ -276,6 +277,10 @@ key_right:
bne done_key
lda #$20
bne quiet_exit
done_key:
jmp exit_interrupt
;========================
; stop playing for now
@ -289,7 +294,6 @@ quiet_exit:
lda #$ff ; also mute the channel
sta AY_REGISTERS+7 ; just in case
done_key:
exit_interrupt:
; pla ; restore a ; 4

View File

@ -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 #$95 ; 2
cmp #$15 ; 2
bne check_left_arrow ; 2nt/3
lda #'D' ; 2
check_left_arrow:
cmp #$88 ; 2
cmp #$08 ; 2
bne check_up_arrow ; 2nt/3
lda #'A' ; 2
check_up_arrow:
cmp #$8B ; 2
cmp #$0B ; 2
bne check_down_arrow ; 2nt/3
lda #'W' ; 2
check_down_arrow:
cmp #$8A ; 2
cmp #$0A ; 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
bne save_key ; branch always ; 3
jmp save_key ; 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
;============

View File

@ -66,7 +66,6 @@ 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
@ -165,41 +164,6 @@ 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

View File

@ -277,6 +277,7 @@ 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
@ -288,6 +289,7 @@ load_ornament:
iny ; 2
lda PT3_LOC,Y ; 4+
clc ; 2
; we're assuming PT3 is loaded to a page boundary
@ -312,6 +314,7 @@ 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
@ -324,7 +327,7 @@ load_ornament:
rts ; 6
;============
; 87
; 93
;===========================
; Load Sample
@ -350,6 +353,7 @@ 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
@ -362,6 +366,7 @@ load_sample:
iny ; 2
lda PT3_LOC,Y ; 4+
clc ; 2
; assume pt3 file is at page boundary
adc #>PT3_LOC ; 2
@ -383,6 +388,7 @@ 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
@ -394,15 +400,14 @@ load_sample:
rts ; 6
;============
; 80
; 86
;====================================
; 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
@ -431,6 +436,7 @@ 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
@ -467,23 +473,26 @@ pt3_init_song:
;======================
; calculate version
ldx #6 ; 2
lda #6 ; 2
sta pt3_version ; 3
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
cmp #9 ; 2
bcs not_ascii_number ; bge ; 2/3
tax ; 2
sta pt3_version ; 4
not_ascii_number:
stx pt3_version ; 3
;=======================
; Pick which volume number, based on version
; if (PlParams.PT3.PT3_Version <= 4)
cpx #5 ; 2
lda pt3_version ; 4
cmp #5 ; 2
; carry clear = 3.3/3.4 table
; carry set = 3.5 table
@ -510,6 +519,7 @@ 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
@ -542,36 +552,44 @@ 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+
adc note_a+NOTE_TONE_ACCUMULATOR_H,X ; 4+
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+
;=============================
; Accumulate tone if set
; (if sample_b1 & $40)
lda #$40 ; if (b1&0x40)
bit sample_b1
bvc no_accum ; (so, if b1&0x40 is zero, skip it)
beq 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 ;;can be removed if ADC ACCUMULATOR_H cannot overflow
ldy note_a+NOTE_ORNAMENT_POSITION,X
clc
lda note_a+NOTE_ORNAMENT_POSITION,X
tay
lda (ORNAMENT_L),Y
adc note_a+NOTE_NOTE,X
@ -602,7 +620,7 @@ note_not_too_high:
adc note_a+NOTE_TONE_SLIDING_H,X
sta note_a+NOTE_TONE_H,X
clc ;;can be removed if ADC SLIDING_H cannot overflow
clc
lda note_a+NOTE_TONE_L,X
adc freq_l
sta note_a+NOTE_TONE_L,X
@ -623,7 +641,7 @@ note_not_too_high:
; a->tone_sliding+=a->tone_slide_step
clc ;;can be removed if ADC freq_h cannot overflow
clc
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
@ -707,15 +725,17 @@ calc_amplitude:
; adjust amplitude sliding
bit sample_b0 ; if ((b0 & 0x80)!=0) {
bpl done_amp_sliding ; so if top bit not set, skip
lda sample_b0 ; if ((b0 & 0x80)!=0) {
and #$80
beq done_amp_sliding ; so if top bit not set, skip
;================================
; if top bits 0b11 then slide up
; if top buts 0b10 then slide down
; if ((b0 & 0x40)!=0) {
bvc amp_slide_down
lda sample_b0 ; if ((b0&0x40)!=0) {
and #$40
beq amp_slide_down
amp_slide_up:
; if (a->amplitude_sliding < 15) {
@ -728,7 +748,7 @@ amp_slide_up:
asu_signed:
bpl done_amp_sliding ; skip if A>=15
inc note_a+NOTE_AMPLITUDE_SLIDING,X ; a->amplitude_sliding++;
bne done_amp_sliding
jmp done_amp_sliding
amp_slide_down:
; if (a->amplitude_sliding > -15) {
@ -757,7 +777,7 @@ done_amp_sliding:
check_amp_lo:
bpl check_amp_hi
lda #0
beq write_clamp_amplitude
jmp write_clamp_amplitude
check_amp_hi:
cmp #16
@ -810,23 +830,15 @@ 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
@ -834,16 +846,17 @@ envelope_slide:
envelope_slide_down:
; j = ((b0>>1)|0xF0) + a->envelope_sliding
tya
lda sample_b0
lsr
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;
tya
lda sample_b0
lsr
and #$0f
clc
adc note_a+NOTE_ENVELOPE_SLIDING,X
@ -851,10 +864,12 @@ envelope_slide_up:
envelope_slide_done:
plp
lda #$20
bit sample_b1
beq last_envelope ; if (( b1 & 0x20) != 0) {
; a->envelope_sliding = j;
lda e_slide_amount
sta note_a+NOTE_ENVELOPE_SLIDING,X
last_envelope:
@ -873,15 +888,18 @@ else_noise_slide:
; else {
; pt3->noise_add = (b0>>1) + a->noise_sliding;
tya
lda sample_b0
lsr
clc
adc note_a+NOTE_NOISE_SLIDING,X
sta pt3_noise_add
plp
lda #$20
bit sample_b1
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:
@ -928,7 +946,9 @@ done_note:
; set mixer value
; this is a bit complex (from original code)
; after 3 calls it is set up properly
lsr pt3_mixer_value
lda pt3_mixer_value
lsr
sta pt3_mixer_value
handle_onoff:
lda note_a+NOTE_ONOFF,X ;if (a->onoff>0) {
@ -1168,7 +1188,16 @@ decode_case_bX:
and #$f
beq decode_case_b0
cmp #1
bne decode_case_bx_higher
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
decode_case_b1:
; Set Length
@ -1181,13 +1210,6 @@ 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
@ -1211,6 +1233,7 @@ 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
@ -1240,6 +1263,11 @@ 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:
;==============================
@ -1251,13 +1279,10 @@ decode_case_eX:
lda note_command
sec
sbc #$d0
;fall through
decode_case_dx_not_d0:
jsr load_sample ; load sample in bottom nybble
jsr load_sample
jmp done_decode
decode_case_fX:
;==============================
; $FX - change ornament/sample
@ -1308,10 +1333,6 @@ 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
@ -1326,6 +1347,11 @@ 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
;==============================
@ -1363,11 +1389,12 @@ 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
adc #$0 ;+carry set by earlier CMP
clc
adc #$1
sta note_a+NOTE_TONE_SLIDE_STEP_L,X
bcc skip_step_inc1
inc note_a+NOTE_TONE_SLIDE_STEP_H,X
skip_step_inc1:
lda note_a+NOTE_TONE_SLIDE_STEP_H,X
adc #$0
sta note_a+NOTE_TONE_SLIDE_STEP_H,X
slide_step_positive:
@ -1433,9 +1460,9 @@ weird_version:
clc
adc #$1
sta note_a+NOTE_TONE_SLIDE_STEP_L,X
bcc skip_step_inc2
inc note_a+NOTE_TONE_SLIDE_STEP_H,X
skip_step_inc2:
lda note_a+NOTE_TONE_SLIDE_STEP_H,X
adc #$0
sta note_a+NOTE_TONE_SLIDE_STEP_H,X
no_need:
@ -1570,13 +1597,13 @@ set_envelope:
lda (PATTERN_L),Y ; 5+
sta pt3_envelope_period_l ; 4
lda #1 ; 2
sta note_a+NOTE_ENVELOPE_ENABLED,X ; envelope_enabled=1 ; 5
lsr ; 2
lda #0 ; 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
;===========
@ -1723,15 +1750,13 @@ not_done:
; update pattern or line if necessary
; then calculate the values for the next frame
;==========================
; pattern done early!
early_end:
inc current_pattern ; increment pattern ; 6
sta current_line ; 4
sta current_subframe ; 4
pt3_make_frame:
check_subframe:
; see if we need a new pattern
; we do if line==0 and subframe==0
lda current_line ; 4
bne pattern_good ; 2/3
lda current_subframe ; 4
bne pattern_good ; 2/3
@ -1742,14 +1767,6 @@ check_subframe:
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
@ -1762,7 +1779,16 @@ pattern_good:
; check if pattern done early
lda pt3_pattern_done ; 4
beq early_end ; 2/3
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
line_good:
@ -1772,20 +1798,22 @@ line_good:
lda current_subframe ; 4
; if we hit pt3_speed, move to next
eor pt3_speed ; 4
cmp pt3_speed ; 4
bne do_frame ; 2/3
next_line:
sta current_subframe ; reset subframe to 0 ; 4
lda #0 ; reset subframe to 0 ; 2
sta current_subframe ; 4
inc current_line ; and increment line ; 6
lda current_line ; 4
eor #64 ; always end at 64. ; 2
cmp #64 ; always end at 64. ; 2
bne do_frame ; is this always needed? ; 2/3
next_pattern:
sta current_line ; reset line to 0 ; 4
lda #0 ; reset line to 0 ; 2
sta current_line ; 4
inc current_pattern ; increment pattern ; 6
@ -1802,6 +1830,7 @@ 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
@ -1812,124 +1841,133 @@ 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
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
beq 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 ; 2
asl AY_REGISTERS+0 ; 5
rol AY_REGISTERS+1 ; 5
asl ; 2
asl AY_REGISTERS+0 ; 5
rol AY_REGISTERS+1 ; 5
asl ; 2
asl AY_REGISTERS+0 ; 5
rol AY_REGISTERS+1 ; 5
; add in original to get 9
clc ; 2
adc note_a+NOTE_TONE_L ; 4
lda note_a+NOTE_TONE_L ; 4
adc AY_REGISTERS+0 ; 3
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 ; 2
ror AY_REGISTERS+1 ; 5
ror AY_REGISTERS+0 ; 5
ror ; 2
ror AY_REGISTERS+1 ; 5
ror AY_REGISTERS+0 ; 5
ror ; 2
ror AY_REGISTERS+1 ; 5
ror AY_REGISTERS+0 ; 5
ror ; 2
ror AY_REGISTERS+1 ; 5
ror AY_REGISTERS+0 ; 5
lda AY_REGISTERS+1 ; 3
and #$0f ; 2
sta AY_REGISTERS+1 ; 3
no_scale_a:
lda convert_177 ; 4
cmp #1 ; 2
lda note_b+NOTE_TONE_L ; Note B Period L ; 4
sta AY_REGISTERS+2 ; into R2 ; 3
lda note_b+NOTE_TONE_H ; Note B Period H ; 4
sta AY_REGISTERS+3 ; into R3 ; 3
lda note_b+NOTE_TONE_L ; Note B Period L ; 4
bcc no_scale_b ; 2/3
lda convert_177 ; 4
beq no_scale_b ; 2/3
; Convert from 1.77MHz to 1MHz by multiplying by 9/16
; first multiply by 8
asl ; 2
asl AY_REGISTERS+2 ; 5
rol AY_REGISTERS+3 ; 5
asl ; 2
asl AY_REGISTERS+2 ; 5
rol AY_REGISTERS+3 ; 5
asl ; 2
asl AY_REGISTERS+2 ; 5
rol AY_REGISTERS+3 ; 5
; add in original to get 9
clc ; 2
adc note_b+NOTE_TONE_L ; 4
lda note_b+NOTE_TONE_L ; 4
adc AY_REGISTERS+2 ; 3
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 ; 2
ror AY_REGISTERS+3 ; 5
ror AY_REGISTERS+2 ; 5
ror ; 2
ror AY_REGISTERS+3 ; 5
ror AY_REGISTERS+2 ; 5
ror ; 2
ror AY_REGISTERS+3 ; 5
ror AY_REGISTERS+2 ; 5
ror ; 2
ror AY_REGISTERS+3 ; 5
ror AY_REGISTERS+2 ; 5
lda AY_REGISTERS+3 ; 3
and #$0f ; 2
sta AY_REGISTERS+3 ; 3
no_scale_b:
lda convert_177 ; 4
cmp #1 ; 2
lda note_c+NOTE_TONE_L ; Note C Period L ; 4
sta AY_REGISTERS+4 ; into R4 ; 3
lda note_c+NOTE_TONE_H ; Note C Period H ; 4
sta AY_REGISTERS+5 ; into R5 ; 3
lda note_c+NOTE_TONE_L ; Note C Period L ; 4
bcc no_scale_c ; 2/3
lda convert_177 ; 4
beq no_scale_c ; 2/3
; Convert from 1.77MHz to 1MHz by multiplying by 9/16
; first multiply by 8
asl ; 2
asl AY_REGISTERS+4 ; 5
rol AY_REGISTERS+5 ; 5
asl ; 2
asl AY_REGISTERS+4 ; 5
rol AY_REGISTERS+5 ; 5
asl ; 2
asl AY_REGISTERS+4 ; 5
rol AY_REGISTERS+5 ; 5
; add in original to get 9
clc ; 2
adc note_c+NOTE_TONE_L ; 4
lda note_c+NOTE_TONE_L ; 4
adc AY_REGISTERS+4 ; 3
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 ; 2
ror AY_REGISTERS+5 ; 5
ror AY_REGISTERS+4 ; 5
ror ; 2
ror AY_REGISTERS+5 ; 5
ror AY_REGISTERS+4 ; 5
ror ; 2
ror AY_REGISTERS+5 ; 5
ror AY_REGISTERS+4 ; 5
ror ; 2
ror AY_REGISTERS+5 ; 5
ror AY_REGISTERS+4 ; 5
lda AY_REGISTERS+5 ; 3
and #$0f ; 2
sta AY_REGISTERS+5 ; 3
@ -1943,6 +1981,7 @@ 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
@ -1950,20 +1989,21 @@ no_scale_c:
; Convert from 1.77MHz to 1MHz by multiplying by 9/16
; first multiply by 8
lda AY_REGISTERS+6 ; 3
asl ; 2
asl ; 2
asl ; 2
asl AY_REGISTERS+6 ; 5
asl AY_REGISTERS+6 ; 5
asl AY_REGISTERS+6 ; 5
; add in original to get 9
clc ; 2
adc temp_word_l ; 4
lda temp_word_l ; 4
adc AY_REGISTERS+6 ; 3
; divide by 16 to get proper value
ror ; 2
ror ; 2
ror ; 2
ror ; 2
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
and #$1f ; 2
sta AY_REGISTERS+6 ; 3
@ -1999,6 +2039,7 @@ 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
@ -2011,30 +2052,32 @@ no_scale_n:
; Convert from 1.77MHz to 1MHz by multiplying by 9/16
; first multiply by 8
lda AY_REGISTERS+11 ; 3
asl ; 2
asl AY_REGISTERS+11 ; 5
rol AY_REGISTERS+12 ; 5
asl ; 2
asl AY_REGISTERS+11 ; 5
rol AY_REGISTERS+12 ; 5
asl ; 2
asl AY_REGISTERS+11 ; 5
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 ; 2
ror AY_REGISTERS+12 ; 5
ror AY_REGISTERS+11 ; 5
ror ; 2
ror AY_REGISTERS+12 ; 5
ror AY_REGISTERS+11 ; 5
ror ; 2
ror AY_REGISTERS+12 ; 5
ror AY_REGISTERS+11 ; 5
ror ; 2
ror AY_REGISTERS+12 ; 5
ror AY_REGISTERS+11 ; 5
lda AY_REGISTERS+12 ; 3
and #$0f ; 2
sta AY_REGISTERS+12 ; 3
@ -2045,13 +2088,15 @@ 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
;==============================
@ -2273,19 +2318,34 @@ vol_outer:
pha ; save HL
clc ; add HL,DE
lda z80_l
adc z80_e
sta z80_e
sta z80_l
lda z80_h
adc z80_d
sta z80_d ; carry is important
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
; 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