Working echo test for arduino terminal

This commit is contained in:
Daniele Verducci su MatissePenguin 2020-11-22 22:06:45 +01:00
parent 3b7647634d
commit a5e7962eb0
2 changed files with 80 additions and 7 deletions

View File

@ -0,0 +1,62 @@
/**
* Terminal interface.
* This sketch allow an Arduino to be used as a terminal to log into Pat80.
* The Arduino is connected to the Pat80 I/O bus and to the terminal computer via USB.
* The Arduino IDE serial monitor is used to send and receive commands to the Z80.
*/
#define EN 2 // Active low
#define WR 11 // Active low
// DATA BUS IS: 3, 4, 5, 6, 7, 8, 9, 10;
void setup() {
Serial.begin(115200);
Serial.println("Pat80 terminal");
pinMode(EN, INPUT);
pinMode(WR, INPUT);
DDRD = B00000010; // Port D (used arduino pins 2 to 7) is input. Avoid changing serial pins.
DDRB = B00000000; // Port B (used arduino pins 8 and 9) is input
attachInterrupt(digitalPinToInterrupt(EN), onClk, CHANGE);
}
void loop() {}
void onClk() {
if (digitalRead(EN)) {
// Clock pulse finished, return to high impedance state
DDRD = B00000010;
DDRB = B00000000;
} else {
// Clock pulse started
if (digitalRead(WR)) {
// Pat80 wants to Read (we send data)
DDRD = DDRD | B11111000; // Port D (arduino pins 3 to 7) is output. In or to preserve serial pins and interrupt pin
DDRB = B00000111; // Port B (0,1,2) = pins 8,9,10 output
byte incomingByte = 0; // Defaults to NULL
// Check if serial data available
if (Serial.available() > 0) {
incomingByte = Serial.read();
}
// Split byte to two parts
byte wbPortD = incomingByte << 3;
byte wbPortB = incomingByte >> 5;
PORTD = wbPortD;
PORTB = wbPortB;
} else {
// Pat80 wants to Write (we receive data)
byte rb = (PIND >> 3) | (PINB << 5); // Compose the final byte from the two parts
if (rb == 0)
return; // NULL
if ((rb >= 8 && rb <= 13) || (rb >= 32 && rb <= 127)) {
// Printable character
Serial.print((char)rb);
} else {
// Non-printable character
Serial.print("[0x");
Serial.print(rb, HEX);
Serial.print("]");
}
}
}
}

View File

@ -49,30 +49,41 @@ KEYB_A4_REG: EQU IO_1 + %00010000
; CONSTANTS
SYSINIT_GREETING:
DB "Pat80",0 ; null terminated string
DB "Pat80",10,0 ; null terminated string
include 'driver_hd44780.asm'
include 'driver_keyboard.asm'
;include 'driver_keyboard.asm'
; System initialization
Sysinit:
call Lcd_init
;call Lcd_init
; position to line 2 char 3
;ld b, 1
;ld c, 1
;call Lcd_locate
; I/O TEST
; write characters to display
ld bc, SYSINIT_GREETING
call Lcd_print ; write string to screen
_io_test_loop:
in a, (IO_0) ; legge dal terminale
cp 0
jp z, _io_test_loop
;sub a, 32 ; trasforma in maiuscola (ascii - 32)
out (IO_0), a ; scrive la lettera trasformata
jp _io_test_loop
halt
; poll keyboard
_poll_keyb:
call Keyb_read
jp _poll_keyb
;_poll_keyb:
;call Keyb_read
;jp _poll_keyb