Wednesday, February 26, 2020

6502 vs 6803 code size example

Okay, who enabled auto completion by default on Notepad++?  This should be associate with the language rather than a global setting.  Now I have to turn it off, and on when I switch between C, and assembly.  😈

Since nobody's getting circuit boards out of China before CoCoFest, I don't feel a lot of pressure to write some code for a couple hardware projects I promised to help with.  So, I'm translating more code from 6502 to 6803 for the Teaser project.

Just to give you an idea of the difference in code size, I've commented out the 6502 instructions, and placed the equivalent 6803 ones after each section.  Notice how 8 instructions become 2 after iniob0, and 4 of the 6502 instructions are some of the slowest on that CPU?  It's like this everywhere.

The Z80 references are due to the original code the 6502 is ported from coming from the Z80, and they are duplicating the register use with memory variables.  Since the 6803's index register X is 16 bit, and can index anywhere in a 256 byte range off of X, we don't need to even change X here.  The 16 bit D register even lets us load, and save two bytes at once even though they are separate variables.
The 6803 is far superior for accessing data structures, and this project uses a lot of them.

The on significant difference vs the 6502, is the 8 bit loop counter is placed in memory, and decremented there.  Too bad Motorola didn't offer a direct addressing version of DEC, and INC instructions.  The dearth of registers on the 6803 makes the direct page an obvious place for loop counters.

Sorry, if Blogger does bad things to the code formatting.  I need to look up the page I was using to format, and colorize the code with off of my old computer.

;-------------------------------------------------------------
; Initialise all objects.
;
; Reset current room,y,x to start room,y,x for all objects
;-------------------------------------------------------------

iniob:
;    lda #<objdta         ; objects table.
;    sta z80_x
;    lda #>objdta
;    sta z80_i
;
;    ldx numob         ; number of objects in the game.

    ldx        #objdta        ; object table
    stx        z80_ix
    ;*************** use memory to hold loop counter
    ldaa    numob    ; number of objects in the game
    staa    loopcounter
   
iniob0:
;    ldy #35
;    lda (z80_ix),y         ; start screen.
;    ldy #32
;    sta (z80_ix),y         ; set start screen.
;    ldy #36
;    lda (z80_ix),y         ; find start y.
;    ldy #33
;    sta (z80_ix),y         ; set start y.

    ldd        35,x        ; start screen, find start y
    std        32,x        ; set start screen, start y

;    ldy #37
;    lda (z80_ix),y         ; get initial x.
;    ldy #34
;    sta (z80_ix),y         ; set x coord.

    ldaa    37,x        ; get initial x.
    staa    34,x        ; set x coord.

;    clc             ; point to next object.
;    lda z80_x
;    adc #38            ; distance between objects.
;    sta z80_x
;    bcc :+
;    inc z80_i
;:
    ldaa    #38        ; distance between objects.
    abx                ; point to next objects.

;    dex             ; repeat.
;    bne iniob0
   
    dec        loopcounter
    bne        iniob0
   
    rts

No comments:

Post a Comment