Trying optimizing terminal to stay under 600nS per clock cycle (not working ATM)
This commit is contained in:
parent
4dcbfa8668
commit
e79ed4fa86
@ -5,58 +5,55 @@
|
|||||||
* The Arduino IDE serial monitor is used to send and receive commands to the Z80.
|
* The Arduino IDE serial monitor is used to send and receive commands to the Z80.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define EN 2 // Active low
|
// EN 2 // Active low
|
||||||
#define WR 11 // Active low
|
// WR 11 // Active low
|
||||||
// DATA BUS IS: 3, 4, 5, 6, 7, 8, 9, 10;
|
// DATA BUS IS: 3, 4, 5, 6, 7, 8, 9, 10;
|
||||||
|
|
||||||
|
byte incomingBuffer = 0; // Incoming from computer, to the Pat80
|
||||||
|
byte outgoingBuffer = 0; // Outgoing to computer, from the Pat80
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(2000000);
|
||||||
Serial.println("Pat80 terminal");
|
Serial.println("Pat80 terminal");
|
||||||
|
|
||||||
pinMode(EN, INPUT);
|
DDRD = B00000010; // Port D (used arduino pins 2 (EN) and 3 to 7 (DATA)) is input. Avoid changing serial pins.
|
||||||
pinMode(WR, INPUT);
|
DDRB = B00000000; // Port B (used arduino pins 8 to 10 (DATA) and 11 (WR)) is input
|
||||||
DDRD = B00000010; // Port D (used arduino pins 2 to 7) is input. Avoid changing serial pins.
|
attachInterrupt(digitalPinToInterrupt(2), onClk, CHANGE);
|
||||||
DDRB = B00000000; // Port B (used arduino pins 8 and 9) is input
|
|
||||||
attachInterrupt(digitalPinToInterrupt(EN), onClk, CHANGE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {}
|
void loop() {
|
||||||
|
if (Serial.available() > 0) {
|
||||||
|
incomingBuffer = Serial.read();
|
||||||
|
}
|
||||||
|
if (outgoingBuffer != 0) {
|
||||||
|
if ((outgoingBuffer >= 8 && outgoingBuffer <= 13) || (outgoingBuffer >= 32 && outgoingBuffer <= 127)) {
|
||||||
|
// Printable character
|
||||||
|
Serial.print((char)outgoingBuffer);
|
||||||
|
} else {
|
||||||
|
// Non-printable character
|
||||||
|
Serial.print("[0x");
|
||||||
|
Serial.print(outgoingBuffer, HEX);
|
||||||
|
Serial.print("]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void onClk() {
|
void onClk() {
|
||||||
if (digitalRead(EN)) {
|
if (PINB & B00000100 == B00000100) { // If EN is HIGH (clock pulse finished)
|
||||||
// Clock pulse finished, return to high impedance state
|
// Clock pulse finished, return to high impedance state
|
||||||
DDRD = B00000010;
|
DDRD = B00000010;
|
||||||
DDRB = B00000000;
|
DDRB = B00000000;
|
||||||
} else {
|
} else {
|
||||||
// Clock pulse started
|
// EN is LOW: Clock pulse started
|
||||||
if (digitalRead(WR)) {
|
if (PIND & B00001000 == B00001000) { // WR is HIGH (Pat80 wants to Read (we send data))
|
||||||
// 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
|
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
|
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
|
// Split byte to two parts
|
||||||
byte wbPortD = incomingByte << 3;
|
PORTD = incomingBuffer << 3;
|
||||||
byte wbPortB = incomingByte >> 5;
|
PORTB = incomingBuffer >> 5;
|
||||||
PORTD = wbPortD;
|
|
||||||
PORTB = wbPortB;
|
|
||||||
} else {
|
} else {
|
||||||
// Pat80 wants to Write (we receive data)
|
// Pat80 wants to Write (we receive data)
|
||||||
byte rb = (PIND >> 3) | (PINB << 5); // Compose the final byte from the two parts
|
outgoingBuffer = (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("]");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user