At long last, I am finally able to load and run a program from a binary file. A surprising amount of the file system had to be implemented in order to be able to do that. I am very thankful to be developing this using emulation. Using real hardware will have taken much, much longer.
It is often said that code on a 6502 tends to be faster but bigger.
The following subroutine in the FLEX file system copies an 8.3 file name to a temporary save area in a file control block.
The original 6809 code:
Code:
D540 BE D413 [6] 00177 MOVNAM LDX CURFCB MOVE FILE NAME TO TEMP
D543 C6 0B [2] 00178 LDB #$0B
D545 A6 04 [5] 00179 MOVNM1 LDA $04,X
D547 A7 88 24 [5] 00180 STA $24,X
D54A 30 01 [5] 00181 LEAX $01,X
D54C 5A [2] 00182 DECB
D54D 26 F6 (D545) [3] 00183 BNE MOVNM1
D54F 39 [5] 00184 RTS
The 6502 code:
Code:
.C57A 01901 MOVNAM
.C57A 18 [2] 01902 clc ; Copy file name to temp
.C57B A5 04 [3] 01903 lda FCBPtr
.C57D 69 20 [3] 01904 adc #FCBWrk-FCBNam ; Offset to temp area
.C57F 85 06 [3] 01905 sta FMSPtr
.C581 A5 05 [3] 01906 lda FCBPtr+1
.C583 69 00 [2] 01907 adc #0
.C585 85 07 [3] 01908 sta FMSPtr+1
. 01909
.C587 A2 0B [2] 01910 ldx #8+3
.C589 A0 04 [2] 01911 ldy #FCBNam
. 01912
.C58B B1 04 [5/6] 01913 MOVNM1 lda (FCBPtr),Y
.C58D 91 06 [6] 01914 sta (FMSPtr),Y
. 01915
.C58F C8 [2] 01916 iny
.C590 CA [2] 01917 dex
.C591 D0 F8 (C58B)[2/3] 01918 bne MOVNM1
. 01919
.C593 60 [6] 01920 rts
In this example, the 6502 code is 20 cycles faster, but 10 bytes bigger.