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

What is ZX81 keyboard? #45

Closed twoporylyj closed 1 year ago

twoporylyj commented 1 year ago

Please tell me what is ZX81 keyboard in context of this interpreter? Is it a keyboard matrix wired like a real ZX81 keyboard? What are default pins for its connection? Can they be changed? Thanks.

slviajero commented 1 year ago

https://create.arduino.cc/projecthub/sl001/read-a-zx81-keyboard-with-arduinos-and-build-things-with-it-0189bd https://create.arduino.cc/projecthub/sl001/read-a-zx81-keyboard-with-arduinos-and-build-things-with-it-0189bd

https://create.arduino.cc/projecthub/sl001/build-a-64kb-home-computer-based-on-an-arduino-mega-256-4aa798 https://create.arduino.cc/projecthub/sl001/build-a-64kb-home-computer-based-on-an-arduino-mega-256-4aa798

A real ZX81 Keyboard ...

Am 28.12.2022 um 17:51 schrieb twoporylyj @.***>:

Please tell me what is ZX81 keyboard in context of this interpreter? Is it a keyboard matrix wired like a real ZX81 keyboard? What are default pins for its connection? Can they be changed? Thanks.

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

twoporylyj commented 1 year ago

Thanks. Are pins reassignable for nano, for example?

slviajero commented 1 year ago

Yes. It is the section

/*

in hardware-arduino.h that does it. Never use the LED pin as a keyboard pin. The LED circuitry interferes with the debouncing on some boards.

Am 28.12.2022 um 18:00 schrieb twoporylyj @.***>:

Thanks. Are pins reassignable for nano, for example?

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

twoporylyj commented 1 year ago

A really very reconfigurable intepreter. So after i SET output to display and input to keyboard, the "echo" of pressed keys will be also sent to display?

slviajero commented 1 year ago

Yes.

Am 28.12.2022 um 18:07 schrieb twoporylyj @.***>:

A really very reconfigurable interoreter. So after i SET output to display and input to keyboard, the "echo" of pressed keys will be also sent to display?

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

twoporylyj commented 1 year ago

Therefore a standalone modern DIY Elektronika MK-85 like device, but 8-bit instead of 16, and with EEPROM instead of battery backup CMOS static RAM, is possible.

slviajero commented 1 year ago

The interpreter can do 16 or 32 bit as well. Defining the address_t type to long will give an address space of 32 bit. I tried it on a Mac. If you have enough RAM like e.g. on an ESP32 or RP2040 you can build a 32bit BASIC computer. The memory access itself will be mapped to 8bit of course but all variables and arithmetic can be any type. You could also set number_t to a 64 bit type and the interpreter would adapt to this as well.

Am 28.12.2022 um 18:13 schrieb twoporylyj @.***>:

MK-85

twoporylyj commented 1 year ago

Compiler is even cooler, a similar feature exists in full version of Quick Basic (not Qbasic).

twoporylyj commented 1 year ago

And also, when keyboard is not connected, and terminal is used, can i get "echo" of characters typed on terminal also sent to HD44780?

slviajero commented 1 year ago

Yes. You can set the input stream to 1 i.e. the input characters of the terminal and the output stream to 2 i.e. the display. Then any typed character on the computer is echoed to the display and the computer acts as a keyboard.

Am 28.12.2022 um 18:33 schrieb twoporylyj @.***>:

And also, when keyboard is not connected, and terminal is used, can i get "echo" of characters typed on terminal also sent to HD44780?

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

twoporylyj commented 1 year ago

10 @i=1:@o=2:input a 20 print a run 32768 When i run this program, line 10 starts asking for number, and i type 32768 on terminal, characters appear on terminal, not echoed to HD44780. Then i press enter, line 20 prints 32768 on HD44780.

slviajero commented 1 year ago

Do you use the picoserial option?

Am 28.12.2022 um 19:34 schrieb twoporylyj @.***>:

10 @i @.*** https://github.com/o=2:input a 20 print a run 32768 When i run this program, line 10 starts asking for number, and i type 32768 on terminal, characters appear on terminal, not echoed to HD44780. Then i press enter, line 10 prints 32768 on HD44780.

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

twoporylyj commented 1 year ago

Yes, because without it i cannot type anything in the emulator i use (real hardware is not assembled yet because of lack of free time; i already have a real nano and a display). Without picoserial enabled, the virtual terminal in emulator only outputs text, but not inputs it (on emulated nano).

slviajero commented 1 year ago

Ok, that explains it. The Picoserial code cannot echo to a different device. This is because the picoserial is block oriented output and the echo needs to be done in an interrupt function.

You can try to change this. Look for this function:

void picogetchar(char c){ if (picob && (! picoa)) { picochar=c; if (picochar != '\n' && picochar != '\r' && picoi<picobsize-1) { if (c == 127 || c == 8) { if (picoi>1) picoi--; else return; } else picob[picoi++]=picochar; picowrite(picochar); } else { picoa = 1; picob[picoi]=0; picob[0]=picoi; z.a=picoi; picoi=1; } picochar=0; / every buffered byte is deleted / } else { if (c != 10) picochar=c; } }

Replace the picowrite(picochar) with outch(picochar). This may work on an LCD display but will certainly cause trouble on any slow display. picogetchar is the interrupt handler. Going to outch() here is stretching the timing to the limit. On an nano it may work as there is not much interrupt business going on.

Am 28.12.2022 um 19:46 schrieb twoporylyj @.***>:

Yes, because without it i cannot type anything in the emulator i use (real hardware is not assembled yet because of lack of free time; i already have a nano and a display). Without picoserial enabled, the virtual terminal in emulator only outputs text, but not inputs it (on emulated nano).

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

twoporylyj commented 1 year ago

Thanks, using outch made this work as expected. Set 3,1 and all i type appears on HD44780.

slviajero commented 1 year ago

Closed

twoporylyj commented 1 year ago

Even though issue is closed, thanks again. Tried this on real hardware, here is have i got it working:

  1. Using real nano also requires activating picoserial, otherwise it does not react to typing text (so this is not bug in emulator). Outch also works same way as on emulator.
  2. R/W line has to be grounded on real HD44780 unit i use; on emulator it does not matter.
  3. Maximum contrast is when corresponding line of the display is fully grounded by the potentiometer, do not know whether all such displays behave like this one.
  4. My display unit is 20x2, but i found that even this is configurable. Keyboard is not built yet. If being disconnected and then reconnected, nano (with CH340G) "jumps" either from /dev/ttyUSB0 to /dev/ttyUSB1, or back to /dev/ttyUSB0, depending on where it was previously. Baud rate is always 9600.
slviajero commented 1 year ago

Using real nano also requires activating picoserial, otherwise it does not react to typing text (so this is not bug in emulator). Outch also works same way as on emulator.

This is very strange. I just tested an LCD with an UNO and the hardware settings

undef USEPICOSERIAL

define DISPLAYCANSCROLL

define LCDSHIELD

Once I get the command prompt I use

SET 3,1

to set the default output stream to the display.

I then type on serial (using Coolterm and raw mode) and I get characters on the display.

You need a terminal with raw mode (i.e. one that sends every character on keystroke) and you need to use SET3,1 or compile stream 2 as standard output stream. The behaviour you observe may be related with the terminal program you use.

R/W line has to be grounded on real HD44780 unit i use; on emulator it does not matter.

Yes! They keep the display on Read mode as the good old LCD driver has no read feature.

Maximum contrast is when corresponding line of the display is fully grounded by the potentiometer, do not know whether all such displays behave like this one. I think this is normal.

My display unit is 20x4, but i found that even this is configurable.

Exactly! It is the same driver for all geometries.

Keyboard is not built yet. If being disconnected and then reconnected, nano (with CH340G) "jumps" either from /dev/ttyUSB0 to /dev/ttyUSB1, or back to /dev/ttyUSB0, depending on where it was previously. Baud rate is always 9600.

I have see things like this as well.

twoporylyj commented 1 year ago

I use minicom as terminal program, this may be the cause.