From b1ef46657afbea456c21ba8b9b1971c6f6904b89 Mon Sep 17 00:00:00 2001
From: "Daniele Verducci (ZenPenguin)" <danieleverducci@gmail.com>
Date: Thu, 19 Nov 2020 08:47:07 +0100
Subject: [PATCH] Untested char output for VGA adapter

---
 arduino/vga_adapter/vga_adapter.ino | 50 +++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 2 deletions(-)

diff --git a/arduino/vga_adapter/vga_adapter.ino b/arduino/vga_adapter/vga_adapter.ino
index c463080..e839386 100644
--- a/arduino/vga_adapter/vga_adapter.ino
+++ b/arduino/vga_adapter/vga_adapter.ino
@@ -105,14 +105,60 @@ VGAX vga;
 
 // Pins
 // VGA
-#define R 
-#define CLK 
+#define VGA_HSYNC 3
+#define VGA_VSYNC 9
+#define VGA_COLOR1 6
+#define VGA_COLOR2 7
+#define CLK 8
+#define RS 9
+const byte DATA [] = {10, 11, 12, 13, A3, A4, A5, A6};
+
+
+bool clkState = false;
 
 void setup() {
+  // Init comm pins
+  pinMode(CLK, INPUT_PULLUP);
+  for(int pin = 0; pin < 8; pin++) {
+    pinMode(DATA[pin], INPUT);
+  }
+
+  // Init VGA
   vga.begin();
   vga.clear(11);
 }
 
 void loop() {
+  bool newClkState = digitalRead(CLK);
+  if (newClkState = false && clkState == true) {
+    // Falling edge: read data from bus
+    onClk();
+  }
+  clkState = newClkState;
+}
+
+void onClk() {
+  bool isCommand = digitalRead(RS);
+  if (isCommand) {
+    onCommandReceived();
+    onDataReceived();
+  }
+}
+
+void onCommandReceived() {
   
 }
+
+void onDataReceived() {
+  char ch = readByte();
+  vga.printSRAM((byte*)fnt_nanofont_data, FNT_NANOFONT_SYMBOLS_COUNT, FNT_NANOFONT_HEIGHT, 3, 1, ch, 0, 0, 1);
+}
+
+byte readByte() {
+  unsigned int data = 0;
+  for(int pin=0; pin < 8; pin++) {
+    byte b = digitalRead(DATA[pin]) ? 1 : 0;
+    data = (data << 1) + b;   // Shifta di 1 e aggiunge il bit corrente. Serve per ricostruire il numero da binario
+  }
+  return data;
+}