Adds use of USE standard; Adds example file for object interaction.
This commit is contained in:
parent
8339b7e8e6
commit
40baa407a2
3 changed files with 80 additions and 7 deletions
64
keyboard-to-input.cu
Normal file
64
keyboard-to-input.cu
Normal file
|
@ -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
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue