Video and Keyboard drivers

Video and Keyboard drivers

Co-Authored-By: Computer construction kit SmartyKit <smartykit@users.noreply.github.com>
This commit is contained in:
Sergey Panarin 2019-09-08 16:30:54 +03:00
parent 948db435b4
commit 5b078bf742
2 changed files with 174 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -0,0 +1,90 @@
/* SmartyKit Apple I replica - video driver
* http://apple1.smartykit.org/
* Copyright (C) 2019, Sergey Panarin <contact@smartykit.org>
*
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 <https://www.gnu.org/licenses/>.
*/
#include <TVout.h>
#include <avr/pgmspace.h>
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);
}