2021-01-09 18:39:12 +00:00
|
|
|
# Draw pixels in response to keyboard events, starting from the top-left
|
|
|
|
# and in raster order.
|
|
|
|
#
|
|
|
|
# To build a disk image:
|
2021-04-17 03:26:42 +00:00
|
|
|
# ./translate ex3.mu # emits code.img
|
2021-01-09 18:39:12 +00:00
|
|
|
# To run:
|
2021-04-17 03:26:42 +00:00
|
|
|
# qemu-system-i386 code.img
|
2021-01-09 18:39:12 +00:00
|
|
|
# Or:
|
2021-04-17 03:26:42 +00:00
|
|
|
# bochs -f bochsrc # bochsrc loads code.img
|
2021-01-09 18:39:12 +00:00
|
|
|
#
|
|
|
|
# Expected output: a new green pixel starting from the top left corner of the
|
|
|
|
# screen every time you press a key (letter or digit)
|
|
|
|
|
2021-03-28 00:47:23 +00:00
|
|
|
fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
|
2021-01-09 18:39:12 +00:00
|
|
|
var x/ecx: int <- copy 0
|
|
|
|
var y/edx: int <- copy 0
|
|
|
|
{
|
2021-03-27 05:47:44 +00:00
|
|
|
var key/eax: byte <- read-key keyboard
|
2021-01-09 18:39:12 +00:00
|
|
|
compare key, 0
|
|
|
|
loop-if-= # busy wait
|
2021-02-07 08:17:17 +00:00
|
|
|
pixel-on-real-screen x, y, 0x31/green
|
2021-01-09 18:39:12 +00:00
|
|
|
x <- increment
|
2021-02-07 08:17:17 +00:00
|
|
|
compare x, 0x400/screen-width=1024
|
2021-01-09 18:39:12 +00:00
|
|
|
{
|
|
|
|
break-if-<
|
|
|
|
y <- increment
|
|
|
|
x <- copy 0
|
|
|
|
}
|
|
|
|
loop
|
|
|
|
}
|
|
|
|
}
|