This is a particularly egregious subroutine for the 6502.
I'm tired, so I'll have to double check the code later, but the 6502's 48 instructions are reduced to just 19 on the 6803.
The 16 bit X index register, 16 bit D register, and not having to write the contents of HL until we need to change X makes a huge difference. The 6502 has to store pointers on the direct page, and they are updated a byte at a time. The 65816 supports 16 bits, so it should be more like the 6803 here. The mode switching between 8 & 16 bit registers that can kill it's performance shouldn't be much of an issue.
;----------------------------------------------------
; Explosion shrapnel.
;----------------------------------------------------
shrap:
; ldy #1
; lda (z80_ix),y ; get the angle.
; clc
; adc #<shrsin ; shrapnel sine table.
; sta z80_l
; lda #>shrsin
; adc #0
; sta z80_h
ldx z80_ix
ldab 1,x ; get the angle
ldx #shrsin ; shrapnel sign table
abx ; X now contains z80_hl
; ldy #0
; lda (z80_hl),y ; fetch value from table.
; sta z80_e
; inc z80_l ; next byte of table.
; bne :+
; inc z80_h
;:
; ldy #0
; lda (z80_hl),y ; fetch value from table.
; sta z80_d
; inc z80_l ; next byte of table.
; bne :+
; inc z80_h
;:
; ldy #0
; lda (z80_hl),y ; fetch value from table.
; sta z80_c
; inc z80_l ; next byte of table.
; bne :+
; inc z80_h
;:
;
; ldy #0
; lda (z80_hl),y ; fetch value from table.
; sta z80_b
ldd 2,x ; fetch value from table
std z80_bc
;order changed because we use de below
ldd ,x ; fetch value from table
std z80_de
stx z80_hl ; still need to add 4 to hl, wait until done with de
; ldy #2
; lda (z80_ix),y ; x coordinate in hl.
; clc
; adc z80_e ; add sine lb
; sta (z80_ix),y ; store new coordinate lb.
; ldy #3
; lda (z80_ix),y
; adc z80_d ; add sine hb
; sta (z80_ix),y ; store new coordinate hb.
ldx z80_ix
; D still contains z80_de
add 2,x ; x coordinate,
std 2,x ; store new coordinate
; ldy #4
; lda (z80_ix),y ; y coordinate in hl.
; clc
; adc z80_c ; add cosine lb
; sta (z80_ix),y ; store new coordinate lb.
; ldy #5
; lda (z80_ix),y
; adc z80_b ; add cosine lb
; sta (z80_ix),y ; store new coordinate hb.
ldd 4,x ; y coordinate
add z80_bc ; add cosine
std 4,x ; store new coordinate
ldd z80_hl ; add 4 to hl
addd #4
std z80_hl
rts
I'm tired, so I'll have to double check the code later, but the 6502's 48 instructions are reduced to just 19 on the 6803.
The 16 bit X index register, 16 bit D register, and not having to write the contents of HL until we need to change X makes a huge difference. The 6502 has to store pointers on the direct page, and they are updated a byte at a time. The 65816 supports 16 bits, so it should be more like the 6803 here. The mode switching between 8 & 16 bit registers that can kill it's performance shouldn't be much of an issue.
;----------------------------------------------------
; Explosion shrapnel.
;----------------------------------------------------
shrap:
; ldy #1
; lda (z80_ix),y ; get the angle.
; clc
; adc #<shrsin ; shrapnel sine table.
; sta z80_l
; lda #>shrsin
; adc #0
; sta z80_h
ldx z80_ix
ldab 1,x ; get the angle
ldx #shrsin ; shrapnel sign table
abx ; X now contains z80_hl
; ldy #0
; lda (z80_hl),y ; fetch value from table.
; sta z80_e
; inc z80_l ; next byte of table.
; bne :+
; inc z80_h
;:
; ldy #0
; lda (z80_hl),y ; fetch value from table.
; sta z80_d
; inc z80_l ; next byte of table.
; bne :+
; inc z80_h
;:
; ldy #0
; lda (z80_hl),y ; fetch value from table.
; sta z80_c
; inc z80_l ; next byte of table.
; bne :+
; inc z80_h
;:
;
; ldy #0
; lda (z80_hl),y ; fetch value from table.
; sta z80_b
ldd 2,x ; fetch value from table
std z80_bc
;order changed because we use de below
ldd ,x ; fetch value from table
std z80_de
stx z80_hl ; still need to add 4 to hl, wait until done with de
; ldy #2
; lda (z80_ix),y ; x coordinate in hl.
; clc
; adc z80_e ; add sine lb
; sta (z80_ix),y ; store new coordinate lb.
; ldy #3
; lda (z80_ix),y
; adc z80_d ; add sine hb
; sta (z80_ix),y ; store new coordinate hb.
ldx z80_ix
; D still contains z80_de
add 2,x ; x coordinate,
std 2,x ; store new coordinate
; ldy #4
; lda (z80_ix),y ; y coordinate in hl.
; clc
; adc z80_c ; add cosine lb
; sta (z80_ix),y ; store new coordinate lb.
; ldy #5
; lda (z80_ix),y
; adc z80_b ; add cosine lb
; sta (z80_ix),y ; store new coordinate hb.
ldd 4,x ; y coordinate
add z80_bc ; add cosine
std 4,x ; store new coordinate
ldd z80_hl ; add 4 to hl
addd #4
std z80_hl
rts
If I don't have to update HL, I can ditch 4 more instructions, cutting the 6803 down to 15
ReplyDelete