From 5b078bf7427af00c3b4d56ae28658cbd7b1b391c Mon Sep 17 00:00:00 2001 From: Sergey Panarin Date: Sun, 8 Sep 2019 16:30:54 +0300 Subject: [PATCH] Video and Keyboard drivers Video and Keyboard drivers Co-Authored-By: Computer construction kit SmartyKit --- .../SmartyKitApple1_KeyboardDriver.ino | 84 +++++++++++++++++ .../SmartyKitApple1_VideoTerminal.ino | 90 +++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 SmartyKitApple1_KeyboardDriver/SmartyKitApple1_KeyboardDriver.ino create mode 100644 SmartyKitApple1_VideoTerminal/SmartyKitApple1_VideoTerminal.ino diff --git a/SmartyKitApple1_KeyboardDriver/SmartyKitApple1_KeyboardDriver.ino b/SmartyKitApple1_KeyboardDriver/SmartyKitApple1_KeyboardDriver.ino new file mode 100644 index 0000000..05734d9 --- /dev/null +++ b/SmartyKitApple1_KeyboardDriver/SmartyKitApple1_KeyboardDriver.ino @@ -0,0 +1,84 @@ +#include "PS2Keyboard.h" + +const int DataPin = 3; +const int IRQpin = 2; + + +const int pinKBDCR = 12; // + +int DataBus[8] = {4, 5, 6, 7, 8, 9, 10, 11}; + +PS2Keyboard keyboard; + +void setup() +{ + for (int count = 1; count <= 8; count++) { + pinMode(DataBus[count-1], OUTPUT); + }; + pinMode(pinKBDCR, OUTPUT); + KBDCR_Disable(); + + delay(1000); + keyboard.begin(DataPin, IRQpin); + Serial.begin(9600); + Serial.println("Keyboard:"); + +} + +void KBDCR_Enable() +{ + digitalWrite(pinKBDCR, HIGH); +} +void KBDCR_Disable() +{ + digitalWrite(pinKBDCR, LOW); +} + +void loop() { + KBDCR_Disable(); + + if (keyboard.available()) { + + // read the next key + char c = keyboard.read(); + + // check for some of the special keys + if (c == PS2_ENTER) { + Serial.println(); + } else if (c == PS2_TAB) { + Serial.print("[Tab]"); + } else if (c == PS2_ESC) { + Serial.print("[ESC]"); + } else if (c == PS2_PAGEDOWN) { + Serial.print("[PgDn]"); + } else if (c == PS2_PAGEUP) { + Serial.print("[PgUp]"); + } else if (c == PS2_LEFTARROW) { + Serial.print("[Left]"); + } else if (c == PS2_RIGHTARROW) { + Serial.print("[Right]"); + } else if (c == PS2_UPARROW) { + Serial.print("[Up]"); + } else if (c == PS2_DOWNARROW) { + Serial.print("[Down]"); + } else if (c == PS2_DELETE) { + Serial.print("[Del]"); + } else { + + // otherwise, just print all normal characters + Serial.print(c); + } + + //print c to register + for (int count = 1; count <= 8 ; count++) + { + if ((int)c & (1 << (count-1))) + digitalWrite(DataBus[count-1], HIGH); + else + digitalWrite(DataBus[count-1], LOW); + } + digitalWrite(DataBus[7], HIGH); + KBDCR_Enable(); + delay(20); + } +} diff --git a/SmartyKitApple1_VideoTerminal/SmartyKitApple1_VideoTerminal.ino b/SmartyKitApple1_VideoTerminal/SmartyKitApple1_VideoTerminal.ino new file mode 100644 index 0000000..d5a2538 --- /dev/null +++ b/SmartyKitApple1_VideoTerminal/SmartyKitApple1_VideoTerminal.ino @@ -0,0 +1,90 @@ +/* SmartyKit Apple I replica - video driver + * http://apple1.smartykit.org/ + * Copyright (C) 2019, Sergey Panarin + * + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include + +const int IRQpin = 2; // write to display + +const int pinDA = 12; // read + +//int DataBus[8] = {4, 5, 6, 7, 8, 9, 10, 11}; +//TV uses pin 7 and pin 9 +int DataBus[8] = {4, 5, 6, 3, 8, 13, 10, 11}; + + +int bitDA = 0; + +byte scan_code=0; + +TVout TV; + +void setup() { + TV.begin(PAL, 128, 96); + TV.selectFont(font6x8); + TV.println("Hello!\r\nI am SmartyKit Apple I replica\n"); + + delay(1000); + for (int count = 1; count <= 8; count++) { + pinMode(DataBus[count-1], INPUT); + }; + pinMode(IRQpin, INPUT); + pinMode(pinDA, OUTPUT); + + //attaching an IRQ to IRQpin + attachInterrupt(0, videoCharInterrupt, RISING); + Serial.begin(9600); +} + +void loop() { + delay(100); +} + + +//interruption service routine (ISR) +void videoCharInterrupt(void) { + + scan_code = 0; + for (int count = 1; count <= 8 ; count++) { + int pinValue = digitalRead(DataBus[count-1]); + scan_code |= pinValue << (count-1); + }; + + if (scan_code == 0x7F) + return; //skip initial setup value + + bitDA = 1; + digitalWrite(pinDA, HIGH); + + if (scan_code != 127) + scan_code -= 128; + + if (scan_code == 0xD) + { + Serial.println(); + TV.println(""); + } + else + { + Serial.print((char)scan_code); + TV.print((char)scan_code); + } + + bitDA = 0; + digitalWrite(pinDA, LOW); +}