From 8b809ef2def08a284f93516ea3760482ebebbf4f Mon Sep 17 00:00:00 2001 From: Sergei Panarin Date: Sat, 28 Aug 2021 19:57:00 +0300 Subject: [PATCH] Keyboard Driver Update to v.1.1 (auto mode, bug fix) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - auto mode: we added auto mode to send F000R command when PS/2 keyboard is not connected. It could be useful to test Terminal (the first major step) and when SmartyKit 1 is assembled but you don't have PS/2 keyboard available - bug fix: we made uppercase not just small caps lettes but all symbols with ASCII codes greater than 0x60. Now we capitalize only 'a' to 'z' (ASCII codes 0x61–0x7A) --- .../SmartyKit1_KeyboardDriverBasic.ino | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/SmartyKit 1 basic drivers/SmartyKit1_KeyboardDriverBasic/SmartyKit1_KeyboardDriverBasic.ino b/SmartyKit 1 basic drivers/SmartyKit1_KeyboardDriverBasic/SmartyKit1_KeyboardDriverBasic.ino index 7b24273..7408ab3 100644 --- a/SmartyKit 1 basic drivers/SmartyKit1_KeyboardDriverBasic/SmartyKit1_KeyboardDriverBasic.ino +++ b/SmartyKit 1 basic drivers/SmartyKit1_KeyboardDriverBasic/SmartyKit1_KeyboardDriverBasic.ino @@ -1,4 +1,5 @@ - /* SmartyKit 1 - PS/2 keyboard driver + /* SmartyKit 1 - PS/2 keyboard driver v.1.1 + * (with automatic mode if no PS/2 keyboard is connected) * http://www.smartykit.io/ * Copyright (C) 2020, Sergey Panarin * @@ -34,6 +35,8 @@ const int PS2Socket_Clk = 4; const int KeyboardBIT7pin = 5; // const int DataBus[8] = {6, 7, 8, 9, 10, 11, 12, 13}; static boolean BIT7flag = false; +static boolean autoMode = true; //run pre-set command or wait for user input from PS/2 keyboard +static boolean autoCommandSent = false; // run pre-set command only once after reboot of Keyboard controller //low-rate clock for tests on A4-A5 #define CLOCK A4 @@ -60,7 +63,10 @@ void setup() pinMode(KeyboardBIT7pin, OUTPUT); KeyboardBIT7_Disable(); - delay(500); //7500 for debug without Keyboard connected + if (autoMode) + delay(7500); //for start without Keyboard connected + else + delay(500); #ifdef _WITH_PS2_ keyboard.begin(PS2Socket_Clk, PS2Socket_Data); @@ -107,6 +113,13 @@ void sendCharToKeyboardPort(char c) void loop() { + //run pre-set command in auto-mode when PS/2 keyboard is not connected + //only once after reboot of Keyboard controller + if (autoMode && !autoCommandSent) + { + autoCommandSent = true; + runAutoModeCommand(); + } #ifdef _WITH_PS2_ //check PS2 input @@ -114,7 +127,7 @@ void loop() { char c = keyboard.read(); if (c == PS2_TAB) - preLoadTest(); + runCommand(); //process Backspace, Left Arrow, Delete as Apple I backspace '_' if (c == PS2_BACKSPACE) { @@ -126,8 +139,9 @@ void loop() { } int scan_code = (int)c; - //make all symbols uppercase - if (scan_code >= 0x60) + //make all symbols uppercase (from 'a' (ASCII code 0x61) to 'z' (ASCII code 0x7A)) + //as in original Apple-1 + if (scan_code >= 0x61 && scan_code <= 0x7A) scan_code -= 0x20; c = (char) scan_code; //print c to Keyboard Port to be read by CPU @@ -149,7 +163,21 @@ void loop() { delay(lowRateClockPeriod); // wait for a lowRateClockPeriod } -void preLoadTest() +//running pre-set Woz OS command for auto mode +void runAutoModeCommand() +{ + const int CMD_COUNT = 1; + String cmd1 = String("F000R\r"); // Woz face demo program at $F000 + String commands[] = {cmd1}; + for (int i = 0; i < CMD_COUNT; i++) + for (int j = 0; j < commands[i].length(); j++) + { + char c = commands[i].charAt(j); + sendCharToKeyboardPort(c); + } +} +//running pre-set Woz OS command (drawing 8x8 pixel art) +void runCommand() { const int CMD_COUNT = 4; String cmd1 = String("1111: 88 A8 50\r");