FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MS-DOS-kernel/kernel/console.asm at master · Programuserbash/MS-DOS-kernel · GitHub
Programuserbash
/
MS-DOS-kernel
Public
forked from
FDOS/kernel
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
MS-DOS-kernel
/
kernel
/
console.asm
Copy path
More file actions
More file actions
Latest commit
History
History
History
312 lines (272 loc) · 10.3 KB
Breadcrumbs
MS-DOS-kernel
/
kernel
/
console.asm
Copy path
File metadata and controls
312 lines (272 loc) · 10.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
;
; File:
; console.asm
; Description:
; Console device driver
;
; Copyright (c) 1998
; Pasquale J. Villani
; All Rights Reserved
;
; This file is part of DOS-C.
;
; DOS-C is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version
; 2, or (at your option) any later version.
;
; DOS-C is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
; the GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public
; License along with DOS-C; see the file COPYING. If not,
; write to the Free Software Foundation, 675 Mass Ave,
; Cambridge, MA 02139, USA.
;
; $Header$
;
%include
"io.inc"
segment _IO_FIXED_DATA
global
ConTable
ConTable db
0Ah
dw
ConInit
dw
_IOExit
dw
_IOExit
dw
_IOCommandError
dw
ConRead
dw
CommonNdRdExit
dw
CommonNdRdExit
dw
ConInpFlush
dw
ConWrite
dw
ConWrite
dw
_IOExit
CTL_PRT_SCREEN equ
7200h
CTL_P equ
10h
segment _LOWTEXT
uScanCode db
0
; Scan code for con: device
global
_kbdType
_kbdType db
0
; 00 for 84key, 10h for 102key
%IFDEF
DEBUG_PRINT_COMPORT
ASYNC_NEED_INIT db
1
%ENDIF
global
ConInit
ConInit:
xor
ax
,
ax
mov
ds
,
ax
mov
al
,[
496h
]
and
al
,
10h
mov
byte
[
cs
:_kbdType
],
al
; enhanced keyboard if bit 4 set
jmp
_IOExit
;
; Name:
; ConRead
;
; Function:
; Read to address in es:di characters from the keyboard. Cx contains
; a count of how many characters are to be transferred.
;
; Description:
; Calls KbdRdChar to read the characters. Destroys ax.
;
global
ConRead
ConRead:
jcxz
ConRead2
; Exit if read of zero
ConRead1:
call
KbdRdChar
; Get a char from kbd in al
stosb
; Store al to es:[di]
loop
ConRead1
; Loop until all are read
ConRead2:
jmp
_IOExit
readkey:
mov
ah
,[
cs
:_kbdType
]
int
16h
checke0:
cmp
al
,
0xe0
; must check for 0xe0 scan code
jne
.
ret
or
ah
,
ah
; check for Greek alpha
jz
.
ret
mov
al
,
0
; otherwise destroy the 0xe0
.
ret
: retn
;
; Name:
; KbdRdChar
;
; Function:
; Read a character from the keyboard.
;
; Description:
; This subroutine reads a character from the keyboard. It also handles
; a couple of special functions.
; It converts ctrl-printscreen to a control-P.
; It also accounts for extended scan codes by saving off
; the high byte of the return and returning it if it was non-zero on
; the previous read.
;
global
KbdRdChar
KbdRdChar:
xor
ax
,
ax
; Zero the scratch register
xchg
[
cs
:uScanCode
],
al
; and swap with scan code
; now AL is set if previous key was extended,
; and previous is erased in any case
or
al
,
al
; Test to see if it was set
jnz
KbdRdRtn
; Exit if it was, returning it
call
readkey
; get keybd char in al, ah=scan
or
ax
,
ax
; Zero ?
jz
KbdRdChar
; Loop if it is
cmp
ax
,
CTL_PRT_SCREEN
; Ctrl-Print screen?
jne
KbdRd1
; Nope, keep going
mov
al
,
CTL_P
; Yep, make it ^P
KbdRd1:
or
al
,
al
; Extended key?
jnz
KbdRdRtn
; Nope, just exit
mov
[
cs
:uScanCode
],
ah
; Yep, save the scan code
KbdRdRtn:
retn
;
; Name:
; CommonNdRdExit
;
; Function:
; Checks the keyboard input buffer.
;
; Description:
; Calls int 16 (get status). Sets Busy-Flag in status field. Destroys ax.
;
global
CommonNdRdExit
CommonNdRdExit:
; *** tell if key waiting and return its ASCII if yes
mov
al
,[
cs
:uScanCode
]
; Test for last scan code
; now AL is set if previous key was extended,
or
al
,
al
; Was it zero ?
jnz
ConNdRd2
; Jump if there's a char waiting
mov
ah
,
1
add
ah
,[
cs
:_kbdType
]
int
16h
; Get status, if zf=0 al=char
jz
ConNdRd4
; Jump if no char available
or
ax
,
ax
; Also check for ax=0 as apparently some
jz
ConNdRd4
; int16h handlers set ax=0 to indicate unsupported function
call
checke0
; check for e0 scancode
or
ax
,
ax
; Zero ?
jnz
ConNdRd1
; Jump if not zero
call
readkey
jmp
short CommonNdRdExit
; if char was there but 0, fetch and retry...
; (why do we check uScanCode here?)
ConNdRd1:
cmp
ax
,
CTL_PRT_SCREEN
; Was ctl+prntscrn key pressed?
jne
ConNdRd2
; Jump if not
mov
al
,
CTL_P
ConNdRd2:
lds
bx
,[
cs
:_ReqPktPtr
]
; Set the status
cmp
byte
[
bx
+
2
],
6
; input status call?
je
ConNdRd3
mov
[
bx
+
0Dh
],
al
; return the ASCII of that key
ConNdRd3:
jmp
_IOExit
ConNdRd4:
jmp
_IODone
global
ConInpFlush
ConInpFlush:
; *** flush that keyboard queue
call
KbdInpChar
; get all available keys
jmp
_IOExit
; do not even remember the last one
KbdInpChar:
; *** get ??00 or the last waiting key after flushing the queue
xor
ax
,
ax
mov
byte
[
cs
:uScanCode
],
al
KbdInpCh1:
mov
ah
,
1
add
ah
,[
cs
:_kbdType
]
int
16h
; get status, if zf=0 al=char
jz
KbdInpRtnZero
; Jump if zero
; returns 0 or the last key that was waiting in AL
call
readkey
jmp
short KbdInpCh1
; just read any key that is waiting, then check if
; more keys are waiting. if not, return AL of this
; key (which is its ASCII). AH (scan) discarded!
KbdInpRtnZero:
mov
ah
,
1
; if anybody wants "1 if no key was waiting"!
KbdInpRtn:
retn
global
ConWrite
ConWrite:
jcxz
ConNdRd3
; Exit if nothing to write
ConWr1:
mov
al
,[
es
:
di
]
inc
di
int
29h
; Do fast output call
loop
ConWr1
; Loop if more to output
jmp
_IOExit
CBreak:
mov
byte
[
cs
:uScanCode
],
3
; Put a ^C into the buffer
IntRetn:
iret
; global _cso
;_cso
; push bp
; mov bp,sp
; push ax
; mov ax,[bp+4]
; int 29h
; pop ax
; pop bp
; retn
global
_int29_handler
_int29_handler:
push
ax
push
si
push
di
push
bp
push
bx
%IFDEF
DEBUG_PRINT_COMPORT
cmp
bx
,
0xFD05
; magic value for COM print routine
je
.comprint
%ENDIF
mov
ah
,
0Eh
mov
bx
,
7
int
10h
; write char al, teletype mode
.int29hndlr_ret:
pop
bx
pop
bp
pop
di
pop
si
pop
ax
iret
%IFDEF
DEBUG_PRINT_COMPORT
%ifnum
DEBUG_PRINT_COMPORT
%define
DEBUG_USE_COMPORT DEBUG_PRINT_COMPORT
%else
%define
DEBUG_USE_COMPORT
1
; default to COM2 if not specified
%endif
.comprint:
push
dx
mov
dx
,
DEBUG_USE_COMPORT
; 0=COM1,1=COM2,2=COM3,3=COM4
mov
ah
,
[
cs
:ASYNC_NEED_INIT
]
or
ah
,
ah
jz
.skip_init
push
ax
; preserve char (AL) to print
; initialize serial port using BIOS to DOS default
; of 2400 bps, 8 data bits, 1 stop bit, and no parity
mov
ax
,
0x00A3
int
14h
; BIOS initialize serial port
mov
ax
,
0x011B
; clear the remote screen (ESC[2J)
int
14h
; BIOS write character to serial port
mov
ax
,
0x015B
; '['
int
14h
; BIOS write character to serial port
mov
ax
,
0x0132
; '2'
int
14h
; BIOS write character to serial port
mov
ax
,
0x014A
; 'J'
int
14h
; BIOS write character to serial port
; mark initialization complete
mov
byte
[
cs
:ASYNC_NEED_INIT
],
0
pop
ax
; restore char to print
.skip_init:
cmp
al
,
0x0A
; do we need to add a carriage return?
jne
.print_it
mov
ax
,
0x010D
; print as \r\n
int
14h
mov
al
,
0x0A
.print_it:
mov
ah
,
0x01
int
14h
; BIOS write character to serial port
pop
dx
jmp
.int29hndlr_ret
%ENDIF
; DEBUG_PRINT_COMPORT
Back
|
FazBrowse Home
|
New Git URL