;=========== BEGIN kbsvc ============= ;-- kbsvc.asm ;-- Keyboard service. ;-- getc: get one char of kb input in R0. ;-- kb_int: handle keyboard interrupts. ;-- kb_init: Set up IVT slot, turn on interrupts. ;------------------------------------- ;------------------------------------- ;;;------------------------------------------------ ;;;-- getc ;;;-- Get the next char from the keyboard buffer. ;;;-- Returns it in R0. If none is available, waits. ;;;-- Simple waiting: loop until ready. ;;;-- Real waiting: return to OS, which suspends current ;;;-- process and does other work. Interrupt handler, kb_int ;;;-- will ;-------------------------------------------------- getc_BEGIN: ;-------------------------------------- push__( r1 ) ;-- save reg pop__( r1 ) ;-- unsave reg getc_END: ret ;------------------------------------ ;;;------------------------------------------------ ;;;-- kb_int ;;;-- Get char from keyboard, store in buffer. ;-------------------------------------------------- kb_int_BEGIN: ;-------------------------------------- push__( r0 ) ;-- save reg ldi r0, KBDR ;-- get char st r0, kb_buf ;-- put it in buffer. pop__( r0 ) ;-- unsave reg kb_int_END: rti ;------------------------------- ;;;------------------------------------------------ ;;;-- kb_init ;;;-- Sets IVT slot at x0180 to kb_int_BEGIN. ;-------------------------------------------------- kb_init_BEGIN: ;--------------------------------- push__( r0 ) ;-- save reg push__( r1 ) ;-- save reg ld r0, KB_IVT_LOC ;-- r0 <== vector slot addr lea r1, kb_int_BEGIN ;-- r1 <== svc routine addr str r1, r0, 0 ;-- IVT[r0] <== routine addr pop__( r1 ) ;-- unsave reg pop__( r0 ) ;-- unsave reg kb_init_END: ret ;------------------------------- ;;;------------------------------------------------ ;;;-- KB Data area ;-------------------------------------------------- KB_IVT_LOC: .FILL x0180 ;-- kb IVT slot. GETC_IVT_LOC: .FILL x0020 ;-- getc TVT slot. KBSR: .FILL xFE00 ;-- address of KBSR. KBDR: .FILL xFE02 ;-- address of KBDR. kb_ENmask: .FILL x4000 ;-- ENmask[14] = 1 kb_buf: .STRINGZ "*" ;-- one-char buffer. ;=========== END kbsvc =============