From 40baa407a2fccdf3dded009df009611dd2cd223d Mon Sep 17 00:00:00 2001 From: Felix Queissner Date: Sat, 17 Oct 2015 10:36:46 +0200 Subject: [PATCH] Adds use of USE standard; Adds example file for object interaction. --- keyboard-to-input.cu | 64 +++++++++++++++++++++++++++++++++++++++ scripts/keyboard.cu | 5 ++- scripts/keyboard.cu.spark | 18 ++++++++--- 3 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 keyboard-to-input.cu diff --git a/keyboard-to-input.cu b/keyboard-to-input.cu new file mode 100644 index 0000000..fbe419a --- /dev/null +++ b/keyboard-to-input.cu @@ -0,0 +1,64 @@ +== main.cu, /os/main == + +OBJ keyboard : "/io/keyboard"; +OBJ console : "/io/console"; + +PUB main() | c : TEXT +BEGIN + keyboard.waitForDriver(); + + # selects the current thread for reading keyboard input + keyboard.setFocus(); + WHILE TRUE DO + keyboard.getChar() → c; + console.put(c); + END +END + +== keyboard.cu, /io/keyboard == + +TYPE KeyData IS + … +END + +SHARED VAR buffer : KeyData; + +SHARED PRI init() +BEGIN + # Initialize shared data with necessary non-nil pointer + [KeyData] → buffer; +NED + +PUB sendKeyHit(keycode : INT) +BEGIN + … +END + +PUB sendKeyRelease(keycode : INT) +BEGIN + … +END + +PUB getChar() → c : TEXT +BEGIN + # We just always send a nice little k instead of reading actual key pressed... :P + "k" → c; +END + +== keyboard.driver.cu, /drv/keyboard == +OBJ interrupts : "/sys/interrupts"; +OBJ keyboard : "/io/keyboard"; + +PRI irq(id : INT, cpu : CPUSTATE) | breakcode : BOOL, key : INT +BEGIN + IF id =/= 0x21 THEN + RETURN; + END + # Code that reads scancodes and translates them to keycodes. + … + IF breakcode THEN + keyboard.sendKeyRelease(key); + ELSE + keyboard.sendKeyHit(key); + END +END \ No newline at end of file diff --git a/scripts/keyboard.cu b/scripts/keyboard.cu index 8b1de09..bdbecd8 100644 --- a/scripts/keyboard.cu +++ b/scripts/keyboard.cu @@ -2,14 +2,13 @@ .asmtype DRIVER .name KEYBOARDDRIVER +USE standard; + NATIVE print(...); NATIVE outb(port : UINT16, value : UINT8); NATIVE inb(port : UINT16) → UINT8; -NATIVE toInt32(…) → INT32; -NATIVE toUInt16(…) → UINT16; - TYPE CpuState IS eax : UINT32; ebx : UINT32; diff --git a/scripts/keyboard.cu.spark b/scripts/keyboard.cu.spark index 85713b2..a9c866b 100644 --- a/scripts/keyboard.cu.spark +++ b/scripts/keyboard.cu.spark @@ -1,15 +1,26 @@ ; ============================================= ; compiled with Copper 1.0 -; 2015-10-16 13:36:11 +; 2015-10-17 10:35:30 ; ============================================= +; USE /home/felix/projects/Electronics/libs/standard.cul +; native method: toInt8(…) → INT8 +; native method: toInt16(…) → INT16 +; native method: toInt32(…) → INT32 +; native method: toUInt8(…) → UINT8 +; native method: toUInt16(…) → UINT16 +; native method: toUInt32(…) → UINT32 + + + + + + .asmtype DRIVER .name KEYBOARDDRIVER ; native method: print(…) ; native method: outb(…) ; native method: inb(…) → UINT8 -; native method: toInt32(…) → INT32 -; native method: toUInt16(…) → UINT16 .type CpuState { eax : UINT32; ebx : UINT32; @@ -25,7 +36,6 @@ - ; 0, sendCommand sendCommand: pushnil ; return value