about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--mu.arc36
-rw-r--r--mu.arc.t34
2 files changed, 61 insertions, 9 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)
diff --git a/mu.arc.t b/mu.arc.t
index a617ec3a..0e8d31a8 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -4087,10 +4087,9 @@
 
 ; fake screen for tests; prints go to a string
 (reset)
-(new-trace "fake-screen-initial")
-(add-code:readfile "chessboard-cursor.mu")
+(new-trace "fake-screen-empty")
 (add-code
-  '((function! main [
+  '((function main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
       (screen:terminal-address <- init-fake-terminal 20:literal 10:literal)
       (5:string-address/raw <- get screen:terminal-address/deref data:offset)
@@ -4112,6 +4111,35 @@
              "                    "))
   (prn "F - fake screen starts out with all spaces"))
 
+; fake keyboard for tests; must initialize keys in advance
+(reset)
+(new-trace "fake-keyboard")
+(add-code
+  '((function main [
+      (default-space:space-address <- new space:literal 30:literal)
+      (s:string-address <- new "foo")
+      (x:keyboard-address <- init-keyboard s:string-address)
+      (1:character-address/raw <- read-key x:keyboard-address)
+     ])))
+(run 'main)
+(when (~is memory*.1 #\f)
+  (prn "F - 'read-key' reads character from provided 'fake keyboard' string"))
+
+; fake keyboard for tests; must initialize keys in advance
+(reset)
+(new-trace "fake-keyboard2")
+(add-code
+  '((function main [
+      (default-space:space-address <- new space:literal 30:literal)
+      (s:string-address <- new "foo")
+      (x:keyboard-address <- init-keyboard s:string-address)
+      (1:character-address/raw <- read-key x:keyboard-address)
+      (1:character-address/raw <- read-key x:keyboard-address)
+     ])))
+(run 'main)
+(when (~is memory*.1 #\o)
+  (prn "F - 'read-key' advances cursor in provided string"))
+
 )  ; section 100
 
 (reset)
261b1b80 ^
6030d7e2 ^
ee9a9237 ^
5e27c7f1 ^
6030d7e2 ^



dd9ba09a ^
6030d7e2 ^




9d27e966 ^
dd9ba09a ^
9d27e966 ^
6030d7e2 ^

9d27e966 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^


ee9a9237 ^
6030d7e2 ^


5e27c7f1 ^
b8475380 ^
ee9a9237 ^
6030d7e2 ^


3d6450f2 ^
3d6450f2 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^

9d27e966 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^


3d6450f2 ^

6030d7e2 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^

9d27e966 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^


b31455f8 ^



6030d7e2 ^
9b16f190 ^
6030d7e2 ^
9b16f190 ^


6030d7e2 ^

6ee77ba7 ^
ee9a9237 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158