The program displays the hex value of any character typed on the terminal keyboard.
On program restart, the value of the first character received from the terminal is 2x what it should be. Every subsequent character has the correct value.
Example:
Start program.
Type "A" on the terminal. Program displays "82".
Type "A" on the terminal. Program displays "41".
Type "A" on the terminal. Program displays "41".
Anyone know why this is happening? It's driving me crazy.
Code: Select all
processor 6502
org $1001 ; Unexpanded VIC
; BASIC stub (unexpanded vic)
dc.w $100b ; Pointer to next BASIC line
dc.w 1981 ; BASIC Line#
dc.b $9e ; BASIC SYS token
dc.b $34,$31,$30,$39 ; 4109 (ML start)
dc.b 0 ; End of BASIC line
dc.w 0 ; End of BASIC program
lda #$93 ; clear screen
jsr $ffd2
lda #<TEXT
ldy #>TEXT
jsr $cb1e ; print string
lda #1
ldx #<RS232FN
ldy #>RS232FN
jsr $ffbd ; SETNAM
lda #2 ; logical file number
ldx #2 ; device address (RS-232C device)
ldy #$ff ; no secondary address needed
jsr $ffba ; SETLFS
jsr $ffc0 ; OPEN
MAIN ldx #2 ; logical file number
jsr $ffc6 ; CHKIN
jsr $ffe4 ; GETIN, Z=1 if no char
cmp #$0 ; subtract 0 from A (why?)
beq MAIN ; branch on Z=1
pha
jsr PRTHEX
lda #$0d ; carriage return
jsr $ffd2
pla
cmp #$1b ; exit on esc pressed
bne MAIN
ldx #2 ; logical file number
jsr $ffc3 ; CLOSE
rts
PRTHEX SUBROUTINE ; print hex of char in A
pha
jsr $ffcc ; CLRCHN
pla
pha
lsr
lsr
lsr
lsr
jsr .1
pla
.1 and #$0f
cmp #$0a
bcc .2
adc #$06
.2 adc #$30
jsr $ffd2
rts
TEXT BYTE "RS232 TEST",$0d
BYTE "SEND CHAR FROM TERM",$0d
BYTE $00
RS232FN dc.b 8