69 lines
1.3 KiB
Plaintext
69 lines
1.3 KiB
Plaintext
|
:asm intvect@ ( int -- seg off )
|
||
|
XOR BX BX
|
||
|
MOV ES BX
|
||
|
POP BX
|
||
|
SHL BX 1 #
|
||
|
SHL BX 1 #
|
||
|
PUSH @[ 2 @+ ES: BX]
|
||
|
PUSH @[ ES: BX]
|
||
|
NEXT
|
||
|
|
||
|
:asm intvect! ( seg off int -- )
|
||
|
XOR BX BX
|
||
|
MOV ES BX
|
||
|
POP BX
|
||
|
SHL BX 1 #
|
||
|
SHL BX 1 #
|
||
|
CLI
|
||
|
POP @[ ES: BX]
|
||
|
POP @[ 2 @+ ES: BX]
|
||
|
STI
|
||
|
NEXT
|
||
|
|
||
|
: irq 8 + ;
|
||
|
|
||
|
{ :timm :asmisr ( int -- ) ARRAY 4 ALLOT w>t CLI PUSH AX ;
|
||
|
:timm ISR-DONE MOV AL 0x20 # OUT 0x20 # AL POP AX STI IRET ;
|
||
|
:timm CHAIN-ISR ( isr -- )
|
||
|
POP AX
|
||
|
STI
|
||
|
JMP FAR CS: @+ ; }
|
||
|
|
||
|
:asm get-cseg
|
||
|
PUSH CS
|
||
|
NEXT
|
||
|
|
||
|
: isr>int ( isr -- int ) 2 cells + @ ;
|
||
|
: isr>code ( isr -- p ) 3 cells + ;
|
||
|
: uninstall-isr ( isr -- )
|
||
|
>r r@ cell + @ r@ @ <r isr>int intvect! ;
|
||
|
: install-isr ( isr -- )
|
||
|
>r r@ isr>int intvect@ r@ ! r@ cell + !
|
||
|
get-cseg r@ isr>code <r isr>int intvect! ;
|
||
|
|
||
|
var timer
|
||
|
0 irq :asmisr timer-isr
|
||
|
MOV AX CS: timer @+
|
||
|
INC AX
|
||
|
MOV CS: timer @+ AX
|
||
|
AND AX 0x03 #
|
||
|
JZ 0 @>
|
||
|
ISR-DONE
|
||
|
0 <:
|
||
|
timer-isr CHAIN-ISR
|
||
|
|
||
|
:asm set-timer-div ( div -- )
|
||
|
MOV AL 0x36 #
|
||
|
OUT 0x43 # AL
|
||
|
POP AX
|
||
|
OUT 0x40 # AL
|
||
|
MOV AL AH
|
||
|
OUT 0x40 # AL
|
||
|
NEXT
|
||
|
|
||
|
: sleep-csec ( cs -- )
|
||
|
timer @ + begin dup timer @ <= until drop ;
|
||
|
: install-timer 0xffff 2 >> set-timer-div timer-isr install-isr ;
|
||
|
: uninstall-timer 0xffff set-timer-div timer-isr uninstall-isr ;
|
||
|
|