Hi Dominique,
You wrote:
"It seems that ROM already includes the fix (your test only go wrong when I do POKE &H4000,1 )."
That is what I would expect if the BASIC ROM does not include the fix. The example with "POKE &H4000,2" works okay, but the example with "POKE &H4000,1" waits for a key press. Both versions should work. Neither should hang waiting for a key press.
The bug in the ROM is the first two lines of this code:
JR Z, CKINCHARB
LD A,(serBufUsed)
CP $0
RET
and also this code:
RXA: CP 1 ; is A==1 ?
JR Z, RXB
waitForChar: LD A,(serBufUsed)
CP $00
JR Z, waitForChar
If the A register happens to contain the value 1, when CKINCHAR is called to see if a key has been pressed then the port A code is skipped and the port B code is run instead.
This is the code in the BASIC interpreter used to test for a key press. RST 18H simply calls CKINCHAR. Note that register A is not set before RST 18H so its value is unknown. Sometimes it will be 1 other times it will be some other value.
TSTBRK: RST 18H ; Check input status
RET Z ; No key, go back
RST 10H ; Get the key into A
CP ESC ; Escape key?
JR Z,BRK ; Yes, break
CP CTRLC ; <Ctrl-C>
JR Z,BRK ; Yes, break
CP CTRLS ; Stop scrolling?
RET NZ ; Other key, ignore
Steve