mirror of
https://github.com/tebl/RC6502-Apple-1-Replica.git
synced 2024-12-22 12:29:45 +00:00
Non-functional version of serial communications
This commit is contained in:
parent
995945b217
commit
ac3dd4da15
@ -217,7 +217,7 @@ NoConn ~ 3900 4150
|
||||
Text GLabel 2650 2850 0 60 Input ~ 0
|
||||
VCC
|
||||
Text GLabel 3950 950 2 60 Input ~ 0
|
||||
KBD_DA
|
||||
KBD_STROBE
|
||||
Text GLabel 3950 1050 2 60 Output ~ 0
|
||||
KBD_READY
|
||||
NoConn ~ 3950 1150
|
||||
@ -302,8 +302,6 @@ F 3 "" H 5950 2800 50 0001 C CNN
|
||||
1 5700 1800
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Text GLabel 2650 1750 0 60 Output ~ 0
|
||||
KBD_D7
|
||||
Text GLabel 5200 1900 0 60 Input ~ 0
|
||||
OUT_D0
|
||||
Text GLabel 5200 2000 0 60 Input ~ 0
|
||||
@ -463,12 +461,10 @@ Wire Wire Line
|
||||
8350 1450 8350 1300
|
||||
Wire Wire Line
|
||||
8350 1300 8100 1300
|
||||
Text GLabel 5200 2600 0 60 Output ~ 0
|
||||
OUT_D7
|
||||
Text GLabel 7400 1400 0 60 Input ~ 0
|
||||
KBD_READY
|
||||
Text GLabel 7400 1600 0 60 Output ~ 0
|
||||
KBD_DA
|
||||
KBD_STROBE
|
||||
Text GLabel 7400 1700 0 60 Output ~ 0
|
||||
OUT_READY
|
||||
Text GLabel 7400 1500 0 60 Input ~ 0
|
||||
@ -617,4 +613,11 @@ NoConn ~ 7400 1200
|
||||
NoConn ~ 7400 1100
|
||||
NoConn ~ 7400 1000
|
||||
NoConn ~ 7400 1300
|
||||
NoConn ~ 5200 2600
|
||||
Text GLabel 2025 1600 1 60 Input ~ 0
|
||||
VCC
|
||||
Wire Wire Line
|
||||
2025 1600 2025 1750
|
||||
Wire Wire Line
|
||||
2025 1750 2650 1750
|
||||
$EndSCHEMATC
|
||||
|
117
RC6502 Serial IO/pia_bridge/pia_bridge.ino
Normal file
117
RC6502 Serial IO/pia_bridge/pia_bridge.ino
Normal file
@ -0,0 +1,117 @@
|
||||
#include <SPI.h>
|
||||
#include <MCP23S17.h>
|
||||
|
||||
#define IO_SS 10
|
||||
#define IO_KBD_D0 8
|
||||
#define IO_KBD_D6 14
|
||||
#define IO_KBD_DA 15
|
||||
|
||||
#define IO_VIDEO_D0 0
|
||||
#define IO_VIDEO_D6 6
|
||||
#define IO_VIDEO_DA 7
|
||||
|
||||
#define KBD_READY 2
|
||||
#define KBD_STROBE 4
|
||||
|
||||
#define VIDEO_RDA 5
|
||||
#define VIDEO_DA 3
|
||||
|
||||
MCP23S17 bridge(&SPI, IO_SS, 0);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Initializing...");
|
||||
configure_pins();
|
||||
configure_bridge();
|
||||
Serial.println("Initialization done!");
|
||||
}
|
||||
|
||||
void configure_pins() {
|
||||
pinMode(KBD_READY, INPUT);
|
||||
pinMode(VIDEO_DA, INPUT);
|
||||
pinMode(KBD_STROBE, OUTPUT);
|
||||
pinMode(VIDEO_RDA, OUTPUT);
|
||||
}
|
||||
|
||||
void configure_bridge() {
|
||||
bridge.begin();
|
||||
|
||||
/* Configure video section */
|
||||
for (int i = 0; i <= 6; i++) {
|
||||
bridge.pinMode(i, INPUT);
|
||||
}
|
||||
bridge.pinMode(7, OUTPUT);
|
||||
|
||||
/* Configure keyboard section */
|
||||
for (int i = 8; i <= 15; i++) {
|
||||
bridge.pinMode(i, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
byte incomingByte;
|
||||
void handle_input() {
|
||||
if (Serial.available() > 0) {
|
||||
digitalWrite(KBD_STROBE, LOW);
|
||||
incomingByte = Serial.read();
|
||||
|
||||
/* Convert ESC key */
|
||||
if (incomingByte == 203) {
|
||||
incomingByte = 27;
|
||||
}
|
||||
|
||||
/* Convert lowercase keys to UPPERCASE */
|
||||
if (incomingByte > 96 && incomingByte < 123) {
|
||||
incomingByte -= 32;
|
||||
}
|
||||
|
||||
if (incomingByte == 65) {
|
||||
incomingByte = 10;
|
||||
}
|
||||
if (incomingByte == 66) {
|
||||
incomingByte = 13;
|
||||
}
|
||||
|
||||
/* Output the actual keys as long as it's supported */
|
||||
if (incomingByte < 96) {
|
||||
bridge.writePort(1, reverse(incomingByte));
|
||||
digitalWrite(KBD_STROBE, HIGH);
|
||||
delay(20);
|
||||
digitalWrite(KBD_STROBE, LOW);
|
||||
//Serial.print("TX ");
|
||||
//print_chr(incomingByte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char reverse( unsigned char x )
|
||||
{
|
||||
x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
|
||||
x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
|
||||
x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
|
||||
return x;
|
||||
}
|
||||
|
||||
void handle_output() {
|
||||
digitalWrite(VIDEO_RDA, HIGH);
|
||||
|
||||
if (digitalRead(VIDEO_DA) == HIGH) {
|
||||
char incomingByte = bridge.readPort(0) & 127;
|
||||
digitalWrite(VIDEO_RDA, LOW);
|
||||
delay(12);
|
||||
|
||||
Serial.print("RX ");
|
||||
print_chr(incomingByte);
|
||||
}
|
||||
}
|
||||
|
||||
void print_chr(char c) {
|
||||
Serial.print((char) c);
|
||||
Serial.print(" (0x");
|
||||
Serial.print(c, HEX);
|
||||
Serial.println(")");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
handle_input();
|
||||
handle_output();
|
||||
}
|
Loading…
Reference in New Issue
Block a user