ca65 V2.17 - Git 582aa41 Main file : decimal_to_hex.ca65 Current file: decimal_to_hex.ca65 000000r 1 ; 000000r 1 ; ACORN System 1 Applications: Decimal To Hexadecimal 000000r 1 ; 000000r 1 ; From the Acorn System 1 User's Manual 000000r 1 ; 000000r 1 ; (Chris Oddy January 2022) 000000r 1 ; 000000r 1 ; entry point $0200 000000r 1 ; 000000r 1 .setcpu "6502" 000000r 1 .listbytes unlimited 000000r 1 ; 000000r 1 D := $10 000000r 1 DECL := $20 000000r 1 DECH := $21 000000r 1 DECVH := $22 000000r 1 DISPLAY := $FE0C ; scan the display 000000r 1 QHEXTD1 := $FE64 ; quad hex to display 1 000000r 1 HEXTD := $FE7A ; hex to display 000000r 1 QDATFET := $FE88 ; quad data fetch 000000r 1 RESTART := $FF04 ; Monitor reentry point 000000r 1 ; 000000r 1 .org $0200 000200 1 ; 000200 1 98 DECHEX: tya ; clear A 000201 1 85 20 sta DECL ; clear No 000203 1 85 21 sta DECH 000205 1 A2 20 ldx #DECL 000207 1 85 22 AGAIN: sta DECVH ; fetch the first digit 000209 1 20 7A FE jsr HEXTD 00020C 1 20 0C FE jsr DISPLAY 00020F 1 90 F6 bcc AGAIN 000211 1 20 88 FE jsr QDATFET ; and then the last four digits 000214 1 F8 sed ; decimal mode 000215 1 84 10 sty D ; clear left display 000217 1 A6 21 ldx DECH ; X & Y as double accumulator 000219 1 98 tya 00021A 1 85 21 sta DECH 00021C 1 A4 20 ldy DECL 00021E 1 85 20 sta DECL 000220 1 38 NEXT: sec ; do a decimal subtract, double byte 000221 1 98 ALSO: tya 000222 1 E9 01 sbc #$01 000224 1 A8 tay 000225 1 8A txa 000226 1 E9 00 sbc #$00 000228 1 AA tax 000229 1 B0 04 bcs NODEC 00022B 1 C6 22 dec DECVH ; last of the decimal subtract, to do 5 digits 00022D 1 30 09 bmi RESLT ; if minus then finished 00022F 1 E6 20 NODEC: inc DECL ; double hex increment 000231 1 D0 ED bne NEXT 000233 1 E6 21 inc DECH 000235 1 38 sec ; create branch always, but don't bother to set the carry twice 000236 1 B0 E9 bcs ALSO 000238 1 A2 20 RESLT: ldx #$20 00023A 1 20 64 FE jsr QHEXTD1 ; display result 00023D 1 4C 04 FF jmp RESTART 00023D 1