slviajero / tinybasic

A BASIC interpreter for Arduino, ESP, RP2040, STM32, Infineon XMC and POSIX with IoT and microcontroller features.
GNU General Public License v3.0
203 stars 31 forks source link

GET broken (when using fabgl) #21

Closed pgrobelniak closed 2 years ago

pgrobelniak commented 2 years ago

Checking for break character seems to be messing with GET which always returns. Disabling it seem to help, but i can no longer stop my programs :)

https://github.com/slviajero/tinybasic/commit/de132c87c8f9e9c8f5518a44cd1f0ec39c7f34d7

slviajero commented 2 years ago

Actually, on Arduino GET is meant to return. This is done by design. It is a non blocking stream input that will return 0 if no character is there.

The way to do blocking single character return from the serial stream is to write

100 IF AVAIL(1) THEN GET A ELSE 100

i.e. you can check AVAIL on the stream if there is a character. AVAIL works for any input stream that supports it low level.

An elegant way to do it could be to use the special variables. So, equivalently you can write

100 IF @A THEN @.*** ELSE 100

@A is AVAIL on the default stream and @C is GET on the default stream.

On Posix GET will block because there it is build on getchar which blocks. There is no simple portable non blocking IO on POSIX.

Am 26.06.2022 um 18:51 schrieb Paweł Grobelniak @.***>:

Checking for break character seems to be messing with GET which always returns. Disabling it seem to help, but i can no longer stop my programs :)

de132c8 https://github.com/slviajero/tinybasic/commit/de132c87c8f9e9c8f5518a44cd1f0ec39c7f34d7 — Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/21, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56BOGZKK55YJDGOWX6DVRCDANANCNFSM5Z4GTY4Q. You are receiving this because you are subscribed to this thread.

pgrobelniak commented 2 years ago

Wow, thanks for such quick response :) I'm trying to get a character from ps2 keyboard using fabgl lib on esp32. Using this

10 if avail(2) then get a else 10

results in "10: Syntax error" for some reason.

Also i have to press a key few times to make it work for some reason.

Great project btw :)

slviajero commented 2 years ago

Too bad, you found an else bug. I added this only recently and it still has some flaws

Use this instead

10 if avail(2) then get a: goto 30 20 goto 10 30 print a

Tried this on an ESP32 right now (I actually work on MQTT at the moment). I will check to ELSE thing later.

Am 26.06.2022 um 20:12 schrieb Paweł Grobelniak @.***>:

Wow, thanks for such quick response :) I'm trying to get a character from ps2 keyboard using fabgl lib on esp32. Using this

10 if avail(2) then get a else 10

results in "10: Syntax error" for some reason.

Also i have to press a key few times to make it work for some reason.

Great project btw :)

— Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/21#issuecomment-1166605590, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56FBQZ4NAXAPH4MYK7TVRCMSDANCNFSM5Z4GTY4Q. You are receiving this because you commented.

slviajero commented 2 years ago

Bug is fixed now. Please download the newest code basic.c or TinybasicArduino.ino file. This was a bug in the token stream handling of GET which only matters if it comes with ELSE. I switched to strict syntax checking a week ago which uncovers a few hidden bugs.

Am 26.06.2022 um 20:12 schrieb Paweł Grobelniak @.***>:

Wow, thanks for such quick response :) I'm trying to get a character from ps2 keyboard using fabgl lib on esp32. Using this

10 if avail(2) then get a else 10

results in "10: Syntax error" for some reason.

Also i have to press a key few times to make it work for some reason.

Great project btw :)

— Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/21#issuecomment-1166605590, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56FBQZ4NAXAPH4MYK7TVRCMSDANCNFSM5Z4GTY4Q. You are receiving this because you commented.

pgrobelniak commented 2 years ago

The code works now but i always get 0. My theory is that kbdcheckch with PS2FABLIB "consumes" the character before i can get it

slviajero commented 2 years ago

Ok, I check this later in the evening. Got a fab32 in my office.

Am 26.06.2022 um 20:41 schrieb Paweł Grobelniak @.***>:

The code works now but i always get 0. My theory is that kbdcheckch with PS2FABLIB "consumes" the character before i can get it

— Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/21#issuecomment-1166612516, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56DSTOXO7FSWH4BEPSLVRCP6TANCNFSM5Z4GTY4Q. You are receiving this because you commented.

slviajero commented 2 years ago

I checked it again and you were of course right. The way kbdcheckch() is implemented it swallows characters every time a BREAKCHAR is checked. Unfortunately Terminal.peek() doesn’t seem to work. I tried it right now and there seems to be an issue. It always returns 255 and cannot be used to check the stream. This may be connected to the VT52 terminal used in BASIC.

I implemented a workaround in hardware-arduino.h that can do BREAKCHAR and GET. Characters checked are put into a one character buffer and are then reinserted into the stream.

It has the same weakness as the serial code. If you send some characters and then BREAKCHAR the program does not stop.

Am 26.06.2022 um 20:41 schrieb Paweł Grobelniak @.***>:

The code works now but i always get 0. My theory is that kbdcheckch with PS2FABLIB "consumes" the character before i can get it

— Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/21#issuecomment-1166612516, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56DSTOXO7FSWH4BEPSLVRCP6TANCNFSM5Z4GTY4Q. You are receiving this because you commented.

pgrobelniak commented 2 years ago

Fantastic, it works now. Thanks!

slviajero commented 1 year ago

PS: there are a few examples here: https://github.com/slviajero/tinybasic/tree/main/examples/04communication https://github.com/slviajero/tinybasic/tree/main/examples/04communication on AVAIL and GET

Am 26.06.2022 um 18:51 schrieb Paweł Grobelniak @.***>:

Checking for break character seems to be messing with GET which always returns. Disabling it seem to help, but i can no longer stop my programs :)

de132c8 https://github.com/slviajero/tinybasic/commit/de132c87c8f9e9c8f5518a44cd1f0ec39c7f34d7 — Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/21, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56BOGZKK55YJDGOWX6DVRCDANANCNFSM5Z4GTY4Q. You are receiving this because you are subscribed to this thread.