diff options
-rw-r--r-- | 319timer.subx | 13 | ||||
-rw-r--r-- | 400.mu | 3 | ||||
-rw-r--r-- | boot.subx | 19 | ||||
-rw-r--r-- | ex12.mu | 28 |
4 files changed, 46 insertions, 17 deletions
diff --git a/319timer.subx b/319timer.subx new file mode 100644 index 00000000..a88af39e --- /dev/null +++ b/319timer.subx @@ -0,0 +1,13 @@ +== code + +timer-counter: # -> _/eax: int + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # + 8b/-> *Timer-counter 0/r32/eax +$timer-counter:end: + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return diff --git a/400.mu b/400.mu index 05a5463f..ab1c6dc0 100644 --- a/400.mu +++ b/400.mu @@ -7,6 +7,9 @@ sig set-cursor-position-on-real-screen x: int, y: int sig draw-cursor-on-real-screen g: grapheme sig color-rgb color: int -> _/ecx: int, _/edx: int, _/ebx: int +# timer +sig timer-counter -> _/eax: int + # keyboard sig read-key kbd: (addr keyboard) -> _/eax: byte diff --git a/boot.subx b/boot.subx index 2a896a97..6e622a03 100644 --- a/boot.subx +++ b/boot.subx @@ -351,23 +351,8 @@ timer-interrupt-handler: b0/copy-to-al 0x20/imm8 e6/write-al-into-port 0x20/imm8 31/xor %eax 0/r32/eax - # ecx = *Timer-current-color - 8b/-> *Timer-current-color 1/r32/ecx # update *Timer-current-color - 81 0/subop/add *Timer-current-color 0x01010101/imm32 - # eax = *Video-memory + 0x1200 (a few rows down from top, around middle of screen) - 8b/-> *Video-memory-addr 0/r32/eax - 05/add-to-eax 0x1200/imm32 - 89/copy *eax 1/r32/ecx - # eax += 0x400 - 05/add-to-eax 0x400/imm32 - 89/copy *eax 1/r32/ecx - # eax += 0x400 - 05/add-to-eax 0x400/imm32 - 89/copy *eax 1/r32/ecx - # eax += 0x400 - 05/add-to-eax 0x400/imm32 - 89/copy *eax 1/r32/ecx + ff 0/subop/increment *Timer-counter $timer-interrupt-handler:epilogue: # epilogue 9d/pop-flags @@ -376,7 +361,7 @@ $timer-interrupt-handler:epilogue: cf/return-from-interrupt == data -Timer-current-color: +Timer-counter: 0/imm32 == code diff --git a/ex12.mu b/ex12.mu new file mode 100644 index 00000000..fe97daa9 --- /dev/null +++ b/ex12.mu @@ -0,0 +1,28 @@ +# Checking the timer. +# +# To build a disk image: +# ./translate ex12.mu # emits code.img +# To run: +# qemu-system-i386 code.img +# Or: +# bochs -f bochsrc # bochsrc loads code.img +# +# Expected output: text with slowly updating colors + +fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) { + var fg/ecx: int <- copy 0 + var prev-timer-counter/edx: int <- copy 0 + { + var dummy/eax: int <- draw-text-rightward screen, "hello from baremetal Mu!", 0x10/x, 0x400/xmax, 0x10/y, fg, 0/bg + # wait for timer to bump + { + var curr-timer-counter/eax: int <- timer-counter + compare curr-timer-counter, prev-timer-counter + loop-if-= + prev-timer-counter <- copy curr-timer-counter + } + # switch color + fg <- increment + loop + } +} |