about summary refs log tree commit diff stats
path: root/mu.arc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-22 18:01:45 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-22 18:01:45 -0800
commit009593c7c6463ec3d4873231da5231fa16d424e2 (patch)
treeb4018a317e09de7b7b7d3c1c1fe48c7376b8af19 /mu.arc
parent6275e978b465ad1f550c5b576c6a48dc9c6eaf69 (diff)
downloadmu-009593c7c6463ec3d4873231da5231fa16d424e2.tar.gz
600 - fake keyboard
Use asynchronous channels like 'stdin' for most tests.
Use the synchronous fakes for testing low-level stdin helpers.
Diffstat (limited to 'mu.arc')
-rw-r--r--mu.arc36
1 files changed, 30 insertions, 6 deletions
diff --git a/mu.arc b/mu.arc
index 14ed973d..21c4fb53 100644
--- a/mu.arc
+++ b/mu.arc
@@ -199,8 +199,12 @@
               line-address-address (obj size 1  address t  elem '(line-address))
               screen (obj array t  elem '(line-address))
               screen-address (obj size 1  address t  elem '(screen))
+              ; fake screen
               terminal (obj size 5  and-record t  elems '((integer) (integer) (integer) (integer) (string-address))  fields '(num-rows num-cols cursor-row cursor-col data))
               terminal-address (obj size 1  address t  elem '(terminal))
+              ; fake keyboard
+              keyboard (obj size 2  and-record t  elems '((integer) (string-address))  fields '(index data))
+              keyboard-address (obj size 1  address t  elem '(keyboard))
               )))
 
 ;; managing concurrent routines
@@ -662,16 +666,11 @@
 ;?                        (write (m arg.0))  (pr " => ")  (prn (type (m arg.0)))
                        ((if ($.current-charterm) $.charterm-display pr) (m arg.0))
                        )
-                read-key
+                read-key-from-host
                   (if ($.current-charterm)
                         (and ($.charterm-byte-ready?) ($.charterm-read-key))
                       ($.graphics-open?)
                         ($.ready-key-press Viewport))
-                wait-for-key
-                  (if ($.current-charterm)
-                        ($.charterm-read-key)
-                      ($.graphics-open?)
-                        ($.get-key-press Viewport))
 
                 ; graphics
                 window-on
@@ -1932,6 +1931,31 @@
   (reply result:string-address-array-address)
 )
 
+(init-fn init-keyboard
+  (default-space:space-address <- new space:literal 30:literal)
+  (result:keyboard-address <- new keyboard:literal)
+  (buf:string-address-address <- get-address result:keyboard-address/deref data:offset)
+  (buf:string-address-address/deref <- next-input)
+  (idx:integer-address <- get-address result:keyboard-address/deref index:offset)
+  (idx:integer-address/deref <- copy 0:literal)
+  (reply result:keyboard-address)
+)
+
+(init-fn read-key
+  (default-space:space-address <- new space:literal 30:literal)
+  (x:keyboard-address <- next-input)
+  { begin
+    (break-unless x:keyboard-address)
+    (idx:integer-address <- get-address x:keyboard-address/deref index:offset)
+    (buf:string-address <- get x:keyboard-address/deref data:offset)
+    (c:character <- index buf:string-address/deref idx:integer-address/deref)
+    (idx:integer-address/deref <- add idx:integer-address/deref 1:literal)
+    (reply c:character)
+  }
+  (c:character <- read-key-from-host)
+  (reply c:character)
+)
+
 (init-fn send-keys-to-stdin
   (default-space:space-address <- new space:literal 30:literal)
   (stdin:channel-address <- next-input)