RC2014 + Basic : Strange behaviour with FOR loop

183 views
Skip to first unread message

Dominique Meurisse (MCHobby)

unread,
Sep 26, 2022, 9:27:26 PM9/26/22
to RC2014-Z80
Hi There,
I'm experimenting a strange behaviour with my RC2014 Pro configured with basic (Nascom Basic).
The FOR loop doesn't start until I press an additional [RETURN] key on my keyboard to start it.
If I have two FOR loop in the program then I will need a [RETURN] to enter each of the for loops.

Here the simpliest example:

10 FOR Z=1 TO 100
20 PRINT Z
30 NEXT
RUN [RETURN]
[RETURN] <-- FOR loop will not start until I press the [Return].
1
2
3
...
100
OK

I have exactly the same behavior with Putty on Linux -OR- PicoTerm ( https://rc2014.co.uk/modules/pi-pico-vga-terminal/ ).


Steve Cousins

unread,
Sep 27, 2022, 4:43:12 AM9/27/22
to RC2014-Z80
There is a bug in the RC2014 implementation NASCOM BASIC for the Z80 SIO. The 6850 ACIA version works okay.

It isn't just FOR NEXT loops that do this. Try:

This works fine:
10 POKE &H4000,2
20 PRINT ".";
30 GOTO 10

But this does not:
10 POKE &H4000,1
20 PRINT ".";
30 GOTO 10

Here is the fix:
https://groups.google.com/g/rc2014-z80/c/8agdXTzp5Qw/m/xwImJf0EBQAJ

The above thread fully explains the bug, the history, and the fix.

Steve

Dominique Meurisse (MCHobby)

unread,
Sep 29, 2022, 6:06:07 PM9/29/22
to RC2014-Z80
Hi Steve,
It seems that ROM already includes the fix (your test only go wrong when I do POKE &H4000,1 ).

I created a second example with the Digital IO board https://rc2014.co.uk/modules/digital-io/
10 for i = 0 to 7
20 out 0, 2^I
30 next I

RUN [hit RETURN]
nothing happens, looks to be paused on the FOR instruction
[hit RETURN]
only the LED on bit 0 does light and everything stops! Looks to be paused on the NEXT instruction.
[hit RETURN]
Loop LED for bit 1 to 7 with the for loop. Now it looks to execute the remaining of the loop properly.

Could someone also tries it on its RC2014 setup? and confirm this?
I did also tried on the Basic 56K, it is the same.

Regards,
Dominique

Steve Cousins

unread,
Sep 29, 2022, 7:13:08 PM9/29/22
to RC2014-Z80
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:

CKINCHAR:      CP      1              ; is A==1
               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


Reply all
Reply to author
Forward
0 new messages