more general timer interface
This commit is contained in:
parent
1083f2a400
commit
c76679dbff
|
@ -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
|
3
400.mu
3
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 draw-cursor-on-real-screen g: grapheme
|
||||||
sig color-rgb color: int -> _/ecx: int, _/edx: int, _/ebx: int
|
sig color-rgb color: int -> _/ecx: int, _/edx: int, _/ebx: int
|
||||||
|
|
||||||
|
# timer
|
||||||
|
sig timer-counter -> _/eax: int
|
||||||
|
|
||||||
# keyboard
|
# keyboard
|
||||||
sig read-key kbd: (addr keyboard) -> _/eax: byte
|
sig read-key kbd: (addr keyboard) -> _/eax: byte
|
||||||
|
|
||||||
|
|
19
boot.subx
19
boot.subx
|
@ -351,23 +351,8 @@ timer-interrupt-handler:
|
||||||
b0/copy-to-al 0x20/imm8
|
b0/copy-to-al 0x20/imm8
|
||||||
e6/write-al-into-port 0x20/imm8
|
e6/write-al-into-port 0x20/imm8
|
||||||
31/xor %eax 0/r32/eax
|
31/xor %eax 0/r32/eax
|
||||||
# ecx = *Timer-current-color
|
|
||||||
8b/-> *Timer-current-color 1/r32/ecx
|
|
||||||
# update *Timer-current-color
|
# update *Timer-current-color
|
||||||
81 0/subop/add *Timer-current-color 0x01010101/imm32
|
ff 0/subop/increment *Timer-counter
|
||||||
# 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
|
|
||||||
$timer-interrupt-handler:epilogue:
|
$timer-interrupt-handler:epilogue:
|
||||||
# epilogue
|
# epilogue
|
||||||
9d/pop-flags
|
9d/pop-flags
|
||||||
|
@ -376,7 +361,7 @@ $timer-interrupt-handler:epilogue:
|
||||||
cf/return-from-interrupt
|
cf/return-from-interrupt
|
||||||
|
|
||||||
== data
|
== data
|
||||||
Timer-current-color:
|
Timer-counter:
|
||||||
0/imm32
|
0/imm32
|
||||||
|
|
||||||
== code
|
== code
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue