about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-12-28 00:12:06 -0800
committerKartik Agaram <vc@akkartik.com>2020-12-28 00:12:06 -0800
commit437fa654cbba0f29c0a73754803aa00404f0f3a2 (patch)
tree648e13ccd1187fcb493c4ad291b286b49942acb1
parent5d2f1c57a58341ee5c793c2eb445159813e37160 (diff)
downloadmu-437fa654cbba0f29c0a73754803aa00404f0f3a2.tar.gz
7437 - baremetal: draw pixel on keyboard event
It's now clear that our keyboard handler doesn't trigger after the first
event.
-rw-r--r--baremetal/boot.hex18
-rw-r--r--baremetal/ex3.hex57
2 files changed, 68 insertions, 7 deletions
diff --git a/baremetal/boot.hex b/baremetal/boot.hex
index 6090eef3..cae8b456 100644
--- a/baremetal/boot.hex
+++ b/baremetal/boot.hex
@@ -240,7 +240,7 @@ e9 fb ff  # loop forever
   # . var index/ecx: byte
   8a  # copy m8 at r32 to r8
     0d  # 00/mod/indirect 001/r8/cl 101/rm32/use-disp32
-    cf 7d 00 00  # disp32 [label]
+    ce 7d 00 00  # disp32 [label]
   # . al = *(keyboard buffer + index)
   8a  # copy m8 at r32 to r8
     81  # 10/mod/*+disp32 000/r8/al 001/rm32/ecx
@@ -263,12 +263,12 @@ e9 fb ff  # loop forever
   # increment index
   fe  # increment byte
     05  # 00/mod/indirect 000/subop/increment 101/rm32/use-disp32
-    cf 7d 00 00  # disp32 [label]
+    ce 7d 00 00  # disp32 [label]
   # clear top nibble of index (keyboard buffer is circular)
   80  # and byte
     25  # 00/mod/indirect 100/subop/and 101/rm32/use-disp32
-    cf 7d 00 00  # disp32 [label]
-    f0  # imm8
+    ce 7d 00 00  # disp32 [label]
+    0f  # imm8
 # 14d:
   # epilogue
   61  # pop all registers
@@ -284,12 +284,16 @@ e9 fb ff  # loop forever
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+00 00 00 00 00 00 00 00 00 00 00 00 00 00
 
+# 1ce:
+# var keyboard circular buffer
+# write index: nibble
+00
 # 1cf:
-# var keyboard circular buffer index: nibble
+# read index: nibble
 00
-# var keyboard circular buffer: byte[16]
+# circular buffer: byte[16]
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 
 # padding
diff --git a/baremetal/ex3.hex b/baremetal/ex3.hex
new file mode 100644
index 00000000..79fe8cf8
--- /dev/null
+++ b/baremetal/ex3.hex
@@ -0,0 +1,57 @@
+# Draw pixels in response to keyboard events.
+#
+# To run, first prepare a realistically sized disk image:
+#   dd if=/dev/zero of=disk.img count=20160  # 512-byte sectors, so 10MB
+# Load the program on the disk image:
+#   cat baremetal/boot.hex baremetal/ex3.hex  |./bootstrap run apps/hex  > a.bin
+#   dd if=a.bin of=disk.img conv=notrunc
+# To run:
+#   qemu-system-i386 disk.img
+# Or:
+#   bochs -f apps/boot.bochsrc  # boot.bochsrc loads disk.img
+
+# main:  (address 0x8800)
+
+# eax <- LFB
+8b  # copy *rm32 to r32
+  05  # 00/mod/indirect 000/r32/eax 101/rm32/use-disp32
+  28 7f 00 00 # disp32 [label]
+
+# var read index/ecx: byte = 0
+31 c9  # ecx <- xor ecx;  11/direct 001/r32/ecx 001/rm32/ecx
+
+# $loop:
+  # CL = *read index
+  8a  # copy m8 at r32 to r8
+    0d  # 00/mod/indirect 001/r8/cl 101/rm32/use-disp32
+    cf 7d 00 00  # disp32 [label]
+  # CL = *(keyboard buffer + ecx)
+  8a  # copy m8 at r32 to r8
+    89  # 10/mod/*+disp32 001/r8/cl 001/rm32/ecx
+    d0 7d 00 00  # disp32 [label]
+  # if (CL == 0) loop (spin loop)
+  80
+    f9  # 11/mod/direct 111/subop/compare 001/rm8/CL
+    00  # imm8
+  74 ef  # loop -17 [label]
+# offset 0x19:
+  # otherwise increment read index
+  fe  # increment byte
+    05  # 00/mod/indirect 000/subop/increment 101/rm32/use-disp32
+    cf 7d 00 00  # disp32 [label]
+  # clear top nibble of index (keyboard buffer is circular)
+  80  # and byte
+    25  # 00/mod/indirect 100/subop/and 101/rm32/use-disp32
+    cf 7d 00 00  # disp32 [label]
+    0f  # imm8
+  # print a pixel in fluorescent green
+  c6  # copy imm8 to m8 at rm32
+    00  # 00/mod/indirect 000/subop 000/rm32/eax
+    31  # imm32
+  40  # increment eax
+  eb dc # loop -36 [label]
+
+# $break:
+e9 fb ff ff ff  # hang indefinitely
+
+# vim:ft=subx
eme support' href='/akspecs/ranger/commit/code/draw.rb?h=v0.2.4&id=14ae8304cd976a6ecf55fe5f5c53ef513278da4b'>14ae8304 ^
8f8b66aa ^

34bfb32e ^
a0de7f95 ^
8f8b66aa ^


14ae8304 ^

8f8b66aa ^











14ae8304 ^
8f8b66aa ^

14ae8304 ^
8f8b66aa ^
14ae8304 ^
8f8b66aa ^


14ae8304 ^
8f8b66aa ^
14ae8304 ^
8f8b66aa ^
14ae8304 ^
8f8b66aa ^
14ae8304 ^
8f8b66aa ^


14ae8304 ^

8f8b66aa ^


d52cc245 ^
8f8b66aa ^
d52cc245 ^

8f8b66aa ^



14ae8304 ^
d52cc245 ^
8f8b66aa ^
14ae8304 ^
8f8b66aa ^

14ae8304 ^
34bfb32e ^
14ae8304 ^

34bfb32e ^


8f8b66aa ^
34bfb32e ^



















8a6f5eab ^
34bfb32e ^





















8f8b66aa ^
34bfb32e ^

a0de7f95 ^


34bfb32e ^



































a0de7f95 ^






34bfb32e ^

34bfb32e ^

a0de7f95 ^




34bfb32e ^

8f8b66aa ^



34bfb32e ^
8f8b66aa ^
34bfb32e ^
























8f8b66aa ^


34bfb32e ^








a0de7f95 ^
34bfb32e ^






8f8b66aa ^
34bfb32e ^
8f8b66aa ^
34bfb32e ^






ccd1fe0e ^
34bfb32e ^










8f8b66aa ^
34bfb32e ^

8f8b66aa ^
34bfb32e ^



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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302