-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathKEYBOARD.ASM
More file actions
139 lines (96 loc) · 4.61 KB
/
Copy pathKEYBOARD.ASM
File metadata and controls
139 lines (96 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
$Title ('DTC/PC BIOS Keyboard Interface V1.0')
$Pagelength (80) Pagewidth (132) Debug Nogen
Name Keyboard
; Author: Don K. Harrison
; Start date: November 3, 1983 Last edit: December 17, 1983
; ************************
; * Module Description *
; ************************
; This module handles the keyboard interface through interrupt
; 16 (TrapKeyDrive).
; (c) Display Telecommunications Corporation, 1983
; All Rights Reserved
$Eject
; **********************
; * Revision History *
; **********************
$Eject
; ********************
; * Public Symbols *
; ********************
Public KeyboardDriver
$Eject
; *******************
; * Data Segments *
; *******************
BiosDataArea Segment Public
Extrn KeyboardFlag1:Byte
Extrn KeyBufHead:Word, KeyBufTail:Word
Extrn BufferStart:Word, BufferEnd:Word
BiosDataArea Ends
$Eject
; ******************
; * Code Segment *
; ******************
Bios Segment Common
Assume Cs:Bios, Ds:BiosDataArea
Org 0E82EH ;Align with PC and XT
KeyboardDriver Proc Far
Sti ;Restore interrupts
Push Ds ;Save Registers
Push Bx
Mov Bx,BiosDataArea ;Our data segment
Mov Ds,Bx ;...point to it
; Do Case Ah;
Or Ah,Ah ;Case = 0
Jz KeyRead ;...read ascii translation
Dec Ah ;Case = 1
Jz KeyStatus ;...read key status
Dec Ah ;Case = 2
Jz KeyShift ;...read shift status
KeyDrvReturn:
Pop Bx ;Case = ??? and general return
Pop Ds ;Restore registers
Iret ;...and return
; ************************
; * Read the character *
; ************************
KeyRead:
Cli ;No ints while reading pointer
Mov Bx,KeyBufHead ;If heads = tails, buffer
Cmp Bx,KeyBufTail ;...is empty
Jne KeyBufRdy ;Jump if buffer has data
Sti ;...else, restore ints and loop
Jmp Keyread ;...till something comes in
KeyBufRdy:
Mov Ax,[Bx] ;Get Ah=scan code Al=ascii
Inc Bx ;Remove char from buffer
Inc Bx ;...by adjusting pointers
Mov KeyBufHead,Bx ;...and
Cmp Bx,BufferEnd ;...circling
Jne KeyDrvReturn ;Jump and return if not at end
Mov Bx,BufferStart ;...else, move the pointer
Mov KeyBufHead,Bx ;...to the start
Jmp KeyDrvReturn ;...and return
; ***********************
; * Return the Status *
; ***********************
KeyStatus:
Cli ;No ints while reading pointer
Mov Bx,KeyBufHead ;If heads = tails, buffer
Cmp Bx,KeyBufTail ;...is empty
Mov Ax,[Bx] ;Get the data (if any)
Sti ;...restore interrupts
Pop Bx ;Restore registers, but
Pop Ds ;...keep the flags intact
Ret 2 ;(Like Iret, but flags not affected)
;..Note: Interrupts leave enabled!!
; **********************
; * Return the Shift *
; **********************
KeyShift:
Mov Al,KeyboardFlag1 ;Get shift state flag
Jmp KeyDrvReturn ;...and return with it
KeyboardDriver Endp
Bios Ends
End