taytyypa-menna-nopeasti/timer.asm
2025-10-26 13:12:04 +02:00

63 lines
No EOL
972 B
NASM

TIMER_INTERRUPT equ 0x1C
timer_init:
pusha
push ds
push es
mov ah, 0x35
mov al, TIMER_INTERRUPT
int 0x21
push cs
pop ds
mov [.saved_handler], bx
mov ax, es
mov [.saved_handler + 2], ax
mov ah, 0x25
mov al, TIMER_INTERRUPT
; ds is already set from earlier
mov dx, timer_tick
int 0x21
pop es
pop ds
popa
ret
section data
.saved_handler resw 2
section code
timer_deinit:
pusha
push ds
mov dx, [cs:timer_init.saved_handler]
mov ax, [cs:timer_init.saved_handler + 2]
mov ds, ax
mov ah, 0x25
mov al, TIMER_INTERRUPT
int 0x21
pop ds
popa
ret
timer_tick:
mov byte [cs:.done], 1
cmp byte [cs:.screenclear], 0
je .clear_timer_expired
dec byte [cs:.screenclear]
.clear_timer_expired:
cmp word [cs:.level_timer], 0
je .level_timer_expired
dec word [cs:.level_timer]
.level_timer_expired:
push word [cs:timer_init.saved_handler + 2]
push word [cs:timer_init.saved_handler]
retf
.done db 0
.screenclear db 0
.level_timer dw 0