VetteGuy777 wrote:
When the automatic grader inputs the test numbers it not only enters the number but it enters the code for "enter" aka carriage return.
Dr Jefyll wrote:
Hm. What you're saying here isn't wrong, but let's take it apart. What's meant is:
- the first call to GetCharW returns the test number
- the following call to GetCharW returns the Enter
or, more simply,
- sometimes when you call GetCharW you get a test number. Other times when you call GetCharW you get something that isn't a test number.
I think what is being described suggests that the
GetCharW sub is collecting a data stream in a FIFO somewhere (IRQ-driven source, perhaps?) and each call to
GetCharW returns with the "oldest" byte in the FIFO. That's exactly how the
GETCHx subs in my POC's firmware behave (where the
x in
GETCHx refers to one of the TIA-232 channels).
GETCHx does no analysis of what it returns—the calling program has to look at the byte and decide what to do with it. I suspect
GetCharW works in similar fashion.
It sounds to me as though your program need to buffer the bytes retrieved from
GetCharW until the
<CR> is received and
then process the input. Think of
<CR> in this case as meaning "end of data—it's time to process the input."
Here's an example of how I did it in Supermon 816:
Code:
;================================================================================
;
;input: INTERACTIVE INPUT FROM CONSOLE CHANNEL
;
; ———————————————————————————————————————————————————————————
; Preparatory Ops: Zero IBUFIDX or load IBUFFER with default
; input & set IBUFIDX to the number of chars
; loaded into the buffer.
;
; Returned Values: .A: used
; .X: characters entered
; .Y: used
;
; Example: STZ IBUFIDX
; JSR INPUT
;
; Notes: Input is collected in IBUFFER & is null-terminated.
; IBUFIDX is reset to zero upon exit.
; ———————————————————————————————————————————————————————————
;
input ldx ibufidx ;current buffer index
stz ibuffer,x ;be sure buffer is terminated
jsr dpyibuf ;print default input if any
per dc_cn
jsr sprint ;enable cursor
ldx ibufidx ;starting buffer index
;
;
; main input loop...
;
.0000010 jsr getcha ;poll for input
bcs .0000060 ;nothing
;
cmp #a_del ;above ASCII range?
bcs .0000030 ;yes, not allowed
;
cmp #a_ht ;horizontal tab?
bne .0000020 ;no
;
lda #a_blank ;replace <HT> w/blank
;
.0000020 cmp #a_blank ;control char?
bcc .0000040 ;yes
;
;
; process QWERTY character...
;
cpx #s_ibuf ;room in buffer?
bcs .0000030 ;no
;
sta ibuffer,x ;store char
inx ;bump index
.byte bitabs ;echo char
;
.0000030 lda #a_bel ;alert user
jsr putcha
bra .0000010 ;get some more
;
;
; process carriage return...
;
.0000040 cmp #a_cr ;carriage return?
bne .0000050 ;no
;
phx ;protect input count
per dc_co
jsr sprint ;cursor off
plx ;recover input count
stz ibuffer,x ;terminate input
stz ibufidx ;reset buffer index
rts ;done, return to caller
;
;
; process backspace...
;
.0000050 cmp #a_bs ;backspace?
bne .0000010 ;no
;
txa
beq .0000010 ;no input, ignore <BS>
;
dex ;1 less char
phx ;preserve count
jsr gendbs ;generate destructive backspace
plx ;restore count
bra .0000010 ;get more input
;
;
; input waiting loop...
;
.0000060 wai ;wait for datum
bra .0000010
;