I am developing a simple snake game in real mode (for fun and educational purposes). I need to run main game loop periodically. I am using following code to set timer frequency to 1000hz.
Code: Select all
# setup timer freq (once per milliseconds)
mov $1193,%bx
mov $0x36,%al
out %al,$0x43
mov %bl,%al
out %al,$0x40
mov %bh,%al
out %al,$0x40
Code: Select all
/* put milliseconds to sleep in %ax, %ax trashed */
sleep:
push %bx
mov timer_ticks,%bx
add %bx,%ax
sleep0:
mov timer_ticks,%bx
cmp %bx,%ax
jle sleep1
hlt
jmp sleep0
sleep1:
pop %bx
ret
Complete code is accessible here: https://github.com/yasar11732/snakeos/b ... 54/snake.s
Edit:
My interrupt handler:
Code: Select all
irq_return:
mov $0x20,%al
out %al,$0x20
popa
iret
timer_handler:
pusha
incw timer_ticks
jmp irq_return