mu/ex10.mu

43 lines
1.2 KiB
Forth
Raw Normal View History

2021-03-28 04:52:16 +00:00
# Demo of mouse support.
2021-03-24 04:14:12 +00:00
#
# To build a disk image:
2021-04-17 03:26:42 +00:00
# ./translate ex10.mu # emits code.img
2021-03-24 04:14:12 +00:00
# To run:
2021-04-17 03:26:42 +00:00
# qemu-system-i386 code.img
2021-03-24 04:14:12 +00:00
# Or:
2021-04-17 03:26:42 +00:00
# bochs -f bochsrc # bochsrc loads code.img
2021-03-24 04:14:12 +00:00
#
# Expected output:
# Values between -256 and +255 as you move the mouse over the window.
# You might need to click on the window once.
2021-03-28 00:47:23 +00:00
fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
2021-03-24 04:14:12 +00:00
# repeatedly print out mouse driver results if non-zero
$main:event-loop: {
var dx/eax: int <- copy 0
var dy/ecx: int <- copy 0
dx, dy <- read-mouse-event
{
compare dx, 0
break-if-!=
compare dy, 0
break-if-!=
loop $main:event-loop
}
{
var dummy1/eax: int <- copy 0
var dummy2/ecx: int <- copy 0
dummy1, dummy2 <- draw-text-wrapping-right-then-down-over-full-screen screen, " ", 0/x, 0x10/y, 0x31/fg, 0/bg
2021-03-24 04:14:12 +00:00
}
{
var dummy/ecx: int <- copy 0
dx, dummy <- draw-int32-decimal-wrapping-right-then-down-over-full-screen screen, dx, 0/x, 0x10/y, 0x31/fg, 0/bg
2021-03-24 04:14:12 +00:00
}
{
var dummy/eax: int <- copy 0
dummy, dy <- draw-int32-decimal-wrapping-right-then-down-over-full-screen screen, dy, 5/x, 0x10/y, 0x31/fg, 0/bg
2021-03-24 04:14:12 +00:00
}
loop
}
}