Permalink
Browse files

let processes read the keyboard

  • Loading branch information...
1 parent c5b08ff commit 9d468b343183bb09ac6101532a38741f93d807a1 @fhars committed Apr 14, 2012
Showing with 39 additions and 5 deletions.
  1. +27 −3 kernel.dasm16
  2. +12 −2 readme.md
View
@@ -571,7 +571,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
-;; KEYBOARD HANDLING
+;; KEYBOARD AND SCREEN HANDLING
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -590,6 +590,13 @@
IFE A, 0
SET PC, POP
+ ; store the character in the buffer for the displayed
+ ; process if it is empty (otherwise discard the key)
+ SET B, [_pc_screen_proc]
+ IFN [_pc_kbd_buf + B], 0
+ SET PC, _pc_kbd_1
+ SET [_pc_kbd_buf + B], A
+:_pc_kbd_1
SET PUSH, A
SET B, [_pc_cycle_count]
JSR _pc_update_entropy
@@ -689,18 +696,29 @@
; the PID of the process currently holding the screen
:_pc_screen_proc DAT 0
:_pc_cycle_count DAT 0
+
+; one character keyboard buffer for each process
+:_pc_kbd_buf RESERVE 0x10
+
:_pc_vidbase DAT 0x8040
:_pc_vidmem DAT 0x8040
:_pc_vidend DAT 0x8200
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
-;; OUTPUT FUNCTIONS
+;; INPUT AND OUTPUT FUNCTIONS
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; return the last key for this process, or 0 if there is none
+:getch
+ SET B, [_pc_curr_proc]
+ SET A, [_pc_kbd_buf + B]
+ SET [_pc_kbd_buf + B], 0
+ SET PC, POP
+
:println ; shortcut
jsr print
jsr newline
@@ -1081,17 +1099,23 @@
SET PC, loop4
; the end is an endless loop
+ SET A, type_text
+ JSR println
SET I, 0
:crash SET A, I
JSR yield
+ JSR getch
+ IFN A, 0
+ JSR printchar
SET B, I
AND B, 0x0fff
SET A, 1
IFE B, 0
JSR status_blink
ADD I, 1
SET PC, crash
-
+:type_text
+ DAT "Type something here",0
:show_foobar
SET A, 1
JSR set_interactive
View
@@ -183,8 +183,8 @@ with a pregenerated random number, and the state is updated on every
keypress (as that is currently the only source of nondeterminism in
the system).
-Screen output
-=============
+Input and output
+================
One of the processes is always considered as being the one that is
displayed on the screen below the status lines. That process is also
@@ -195,6 +195,10 @@ The current implementation is quite primitive: everytime the user
switches to the next process, the screen is cleared and output starts
on the top of the screen.
+Key presses will be deliverd to the process that has the focus. dcos16
+stores one key per process, additional keys pressed before the
+last key has been read are discarded.
+
The current set of output functions has been adapted from <a
href="https://github.com/jdiez17/0x42c">0x42c</a> and currently
clobber more registers than they probabaly should. They set the
@@ -205,6 +209,12 @@ containing the characters in their lower seven bits.
The output functions have no effect if the process does not have
focus.
+getch
+-----
+
+```getch``` performs a nonblocking read of the keyboard, returning
+either the last key pressed for the current process, or 0.
+
println
-------

0 comments on commit 9d468b3

Please sign in to comment.