Read hex routines

Subroutines read hex coded address and byte.

0729   73A4             ;
0730   73A4             ; READ HEX ADR; RETURN HO IN TMP0; LO IN TMP0+1 AND CY=1
0731   73A4             ;    IF SP CY=0
0732   73A4             ;
0733   73A4 20 B3 73    RDOA   JSR RDOB          ; READ 2 CHAR BYTE
0734   73A7 90 02              BCC RDOA2         ; SPACE
0735   73A9             ;
0736   73A9 85 EF              STA TMP0+1
0737   73AB 20 B3 73    RDOA2  JSR RDOB
0738   73AE 90 02              BCC RDEXIT        ; SP
0739   73B0 85 EE              STA TMP0
0740   73B2 60          RDEXIT RTS
0741   73B3             ;
0742   73B3             ;  READ HEX BYTE AND RETURN IN A, AND CY=1
0743   73B3             ;    IF SP CY=0
0744   73B3             ;    Y REG IS PRESERVED
0745   73B3             ;
0746   73B3 98          RDOB   TYA               ; SAVE Y
0747   73B4 48                 PHA
0748   73B5 A9 00              LDA #0            ; SET DATA = 0
0749   73B7 85 EC              STA ACMD
0750   73B9 20 E9 72           JSR RDOC
0751   73BC C9 0D              CMP #$0D          ; CR?
0752   73BE D0 06              BNE RDOB1
0753   73C0 68                 PLA               ;YES - GO TO START
0754   73C1 68                 PLA               ;CLEANING STACK UP FIRST
0755   73C2 68                 PLA
0756   73C3 4C 86 70           JMP START
0757   73C6             ;
0758   73C6 C9 20       RDOB1  CMP #' '           ; SPACE
0759   73C8 D0 0A              BNE RDOB2
0760   73CA 20 E9 72           JSR RDOC          ; READ NEXT CHAR
0761   73CD C9 20              CMP #' '
0762   73CF D0 0F              BNE RDOB3
0763   73D1 18                 CLC               ; CY=0
0764   73D2 90 12              BCC RDOB4
0765   73D4             ;
0766   73D4 20 EB 73    RDOB2  JSR HEXIT         ; TO HEX
0767   73D7 0A                 ASL A
0768   73D8 0A                 ASL A
0769   73D9 0A                 ASL A
0770   73DA 0A                 ASL A
0771   73DB 85 EC              STA ACMD
0772   73DD 20 E9 72           JSR RDOC          ; 2ND CHAR ASSUMED HEX
0773   73E0 20 EB 73    RDOB3  JSR HEXIT
0774   73E3 05 EC              ORA ACMD
0775   73E5 38                 SEC               ; CY=1
0776   73E6 AA          RDOB4  TAX
0777   73E7 68                 PLA               ; RESTORE Y
0778   73E8 A8                 TAY
0779   73E9 8A                 TXA               ;SET Z & N FLAGS FOR RETURN
0780   73EA 60                 RTS
0781   73EB             ;
0782   73EB C9 3A       HEXIT  CMP #$3A
0783   73ED 08                 PHP               ; SAVE FLAGS
0784   73EE 29 0F              AND #$0F
0785   73F0 28                 PLP
0786   73F1 90 02              BCC HEX09         ; 0-9
0787   73F3 69 08              ADC #8            ; ALPHA ADD 8+CY=9
0788   73F5 60          HEX09  RTS

RDOA read address as hex coded ASCII characters
Returns with address in TMP0

  • Read high part of address 2 hex byte and store in TMP0
  • Read high part of address 2 hex byte and store in TMP0
  • return with Carry set if if valid address

RDOB
Read hex byte from serial input.
Either two hex characters or CR.
Return with Carry clear if space found in second character.
Note if invalid characters are entered only pressing Enter will get you out of this mesh!
Entering non-hex characters is accepted, and some address is returned.

  • Save Y on stack (746-747)
  • ACMD is used for building up hex value (748-749)
  • read character (750)
  • if CR (ENTER) then clean up stack from RTS return address and saved Y and jump to start (751-756)
  • if space handle as zero and clear carry (758-764)
  • HEXIT and shift to upper nibble (766-771)
  • get second character (772)
  • HEXIT and or in lower nibble (773-775)
  • return in A and restore Y (776-780)

HEXIT
Convert from ASCII character to byte
Examples:

  • 31 mask off upper nibble 01, delivers 1
  • 42 mask of upper nibble 0010, add 9 delivers B

Note no check is made if this is actually hex ASCII 0-..9 or A..F. So any other character delivers nonsense.

What is happening here?

  • is it above 3A? must be A..F, set carry 1
  • mask off upper nibble
  • if A..F add 8+ carry
  • return A with byte