Saturday, February 29, 2020

code update

The egregious 6502 vs 6803 code comparison has been updated.  Yup, I was tired.  The 6803 code should be okay now.  While fixing the 6803 code, I also noticed the 6502 code looked like it could be improved.

The 6502 code from the shrapnel routine looks like it can be optimized as shown below.  Instead of incrementing z80_hl for every byte, use different y offsets, and then update z80_hl once.  The comparison is a little less lopsided with this change.

;----------------------------------------------------
; 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

    ldy #0
    lda (z80_hl),y         ; fetch value from table.
    sta z80_e

    iny          ;#1
    lda (z80_hl),y        ; fetch value from table.
    sta z80_d

    iny          ;#2
    lda (z80_hl),y         ; fetch value from table.
    sta z80_c

    iny          ;#3
    lda (z80_hl),y         ; fetch value from table.
    sta z80_b


    lda    z80_l            ; add 4 to hl to advance pointer
    clc
    adc    #4

    sta    z80_l
    bcc    :+
    inc    z80_h
:


    ldy  #2
    lda (z80_ix),y         ; y coordinate in hl.
    clc
    adc z80_c        ; add cosine lb
    sta (z80_ix),y        ; store new coordinate lb.
    iny
    lda (z80_ix),y
    adc z80_b        ; add cosine lb
    sta (z80_ix),y        ; store new coordinate hb.

 

...

2 comments:

  1. I changed several of the LDY instructions to INY. I *think* they are the same # of clock cycles, but each INY takes one less byte.

    ReplyDelete
  2. This change drops the # of instructions from 48 to 36

    ReplyDelete