-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUSEFUL.ASM
345 lines (289 loc) · 14.4 KB
/
USEFUL.ASM
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
$Title ('DTC/PC BIOS Useful Procedures V1.0')
$Pagelength (80) Pagewidth (132) Debug Nogen
Name Useful
; Author: Don K. Harrison
; Start date: December 14, 1983 Last edit: December 27, 1983
;
;
; ************************
; * Module Description *
; ************************
; This module contains some useful subroutines, including:
; Beep Beeps the bell
; PrintMessage Prints a message ending in 0
; WordOut Outputs a word value from Ax
; ByteOut Outputs a byte value from Al
; CharOut Outputs a character in Al
; NibbleOut Outputs a single nibble from Al
; CrtCrlf Outputs a carriage return line feed
; KeyIn Gets character from keyboard
; VideoInit Initialize video from switches
; ROMCheck8K Rom checksum procedure
; MemoryTest Ram memory test
; ClearScreen Clear screen
; PositionCursor Position cursor from Ax
; (c) Display Telecommunications Corporation, 1983
; All Rights Reserved
$Eject
; **********************
; * Revision History *
; **********************
$Eject
; ********************
; * Public Symbols *
; ********************
Public ByteOut, WordOut, CharOut, NibbleOut, KeyIn
Public PrintMessage, Beep, VideoInit, CrtCrLf
Public ROMCheck8K, MemoryTest, ROMCheckCx
Public ClearScreen, PositionCursor
; *************
; * Equates *
; *************
AsciiCarriage Equ 0DH ;Carriage return
AsciiLineFeed Equ 0AH ;Line feed
$Include (IbmInc)
$Eject
; *******************
; * Data Segments *
; *******************
BiosDataArea Segment Public
Extrn EquipFlag:Word
BiosDataArea Ends
$Eject
; ******************
; * Code Segment *
; ******************
Bios Segment Common
Extrn NMIInt:Near
Assume Cs:Bios, Ds:BiosDataArea
Org 0F950H ;Available spot in ROM
; *************************
; * Output a Byte Value *
; *************************
ByteOut Proc Near
Push Ax ;Save low nibble
Mov Cl,4 ;...Shift it to lower nibble
Shr Al,Cl ;...and
Call NibbleOut ;...output it
Pop Ax ;Restore lower nibble
Call NibbleOut ;...and output it
Ret ;...then return
ByteOut Endp
; *************************
; * Output a Word Value *
; *************************
WordOut Proc Near
Push Ax ;Save Lo byte
Mov Al,Ah ;Get Hi byte first
Call ByteOut ;...and output it
Pop Ax ;Get lo byte
Call ByteOut ;...and output it
Ret ;...then return
WordOut Endp
; ************************
; * Output a Character *
; ************************
CharOut Proc Near
Push Bx ;Save Bx
Push Ax ;...and Ax
Mov Ah,VidCmdWrTTY ;Command = Write TTY
Mov Bl,7 ;Foreground color if in graph.
Int TrapVideo ;Send char TTY style
Pop Ax ;Restore
Pop Bx ;...registers
Ret ;...and return
CharOut Endp
; *********************
; * Output a Nibble *
; *********************
NibbleOut Proc Near
Push Ax ;Save Ax
And Al,0FH ;Strip upper, just in case
Cmp Al,9 ;Is it greater than 9?
Jbe LessEqu9 ;...jump if it isn't
Add Al,7 ;...else add diff from 9 to A
LessEqu9:
Add Al,'0' ;Add ascii offset
Call CharOut ;...output it
Pop Ax ;Restore Ax
Ret ;...and return
NibbleOut Endp
; *******************************
; * Carriage Return Line Feed *
; *******************************
CrtCrlf Proc Near
Mov Al,AsciiCarriage
Call CharOut
Mov Al,AsciiLineFeed
Call CharOut
Ret
CrtCrlf Endp
; ****************************
; * Get Keyboard Character *
; ****************************
KeyIn Proc Near
Mov Ah,0 ;Character command
Int TrapKeyDrive ;...do procedure
Ret ;...and return
KeyIn Endp
; *********************
; * Print a Message *
; *********************
PrintMessage Proc Near
Lodsb ;Get a character
Or Al,Al ;...is it 0?
Jnz PrintMsgCont ;...jump if not
Ret ;...else return
PrintMsgCont:
Call CharOut ;...output it
Jmp PrintMessage ;...and loop till 0 found
PrintMessage Endp
; **********
; * Beep *
; **********
Beep Proc Near
Push Ax ;Save Ax
Push Cx ;...and Cx
Mov Al,10110110B ;Setup timer
Out PortCTCMode,Al ;...2
Mov Ax,1320 ;Save freq as IBM
Out PortCTCLoadCh2,Al ;...Lo byte
Mov Al,Ah ;...Hi
Out PortCTCLoadCh2,Al ;...byte
In Al,PortPPIPortB ;Get current value of ctl port
Push Ax ;...save it
Or Al,00000011B ;Turn on the speaker
Out PortPPIPortB,Al ;...during the beep
Xor Cx,Cx ;Long count in Cx
BeepLoop:
Loop BeepLoop ;Wait
Dec Bl ;...decrement user supplied
Jnz BeepLoop ;...variable and loop till done
Pop Ax ;Restore port value prior to
Out PortPPIPortB,Al ;...beep and restore it
Pop Cx ;Restore used registers
Pop Ax ;...and
Ret ;...return
Beep Endp
; ********************************************
; * Video Default Initialization Procedure *
; ********************************************
VideoInit Proc Near
Mov Ah,Byte Ptr EquipFlag ;Which card to init?
And Ah,30H ;Isolate display bits
Mov Al,0 ;Mode = Monochrome
Cmp Ah,30H ;Is monochrome selected?
Je InitVidJmp ;...jump if so
Mov Al,1 ;Mode = 40x25
Cmp Ah,10H ;Is color 40x25?
Je InitVidJmp ;...jump if so
Mov Al,3 ;Mode = 80x25
InitVidJmp:
Mov Ah,VidCmdInit ;Command = initialize
Int TrapVideo ;...Al = target mode
Ret
VideoInit Endp
; ******************
; * Clear Screen *
; ******************
ClearScreen Proc Near
Mov Dx,184FH ;Clear screen
Xor Cx,Cx ;...
Mov Ax,0600H ;...
Mov Bh,7 ;...
Int TrapVideo ;...
Mov Ah,VidCmdCurPos ;Home the cursor
Mov Dx,0 ;...
Mov Bh,0 ;...
Int TrapVideo ;...
Ret ;Return
ClearScreen Endp
; *********************
; * Position Cursor *
; *********************
PositionCursor Proc Near
Push Dx ;Save Dx
Push Bx ;...and Bx
Mov Dx,Ax ;Position from Ax
Mov Ah,VidCmdCurPos ;Load the command
Mov Bh,0 ;...page 0
Int TrapVideo ;...Do-it
Pop Bx ;Restore
Pop Dx ;...registers
Ret ;Return
PositionCursor Endp
; ****************************************************************
; * ROM Checksum Procedure: Entry 1 = 8K, Entry 2 = (Cx)K *
; ****************************************************************
ROMCheck8K Proc Near
Mov Cx,8192 ;Length of ROM = 8k
ROMCheckCx:
Mov Al,0 ;Zero the checksum
ROMCheckLoop:
Add Al,DS:[Bx] ;Bx holds the offset
Inc Bx ;...inc it
Loop ROMCheckLoop ;...and loop till all added
Or Al,Al ;Affect Z flag with Al
Ret ;...and return, if z=1, rom=ok
ROMCheck8k Endp
; ****************************
; * Memory Test *
; *--------------------------*
; * Es:00 = Start Address *
; * Returns: *
; * If Cy = 0, NO ERROR *
; * else Es:Di = addr. *
; ****************************
MemoryTest Proc Near
Mov Bx,1024 ;Do a 1k Block
Mov Al,055H ;Start with 55H
Xor Di,Di ;Re-load pointer
Mov Cx,Bx ;Re-load count
Rep Stosb ;Write it
Xor Di,Di ;Re-load pointer
Mov Cx,Bx ;Re-load count
Repe Scasb ;Test memory with accum
Jcxz TestAA ;...jump if no error
Stc ;Carry set indicates error
Ret ;...return
TestAA:
Xor Di,Di ;Re-load pointer
Mov Cx,Bx ;Re-load count
Not Al ;Next is 55H
Rep Stosb ;Write it
Xor Di,Di ;Re-load pointer
Mov Cx,Bx ;Re-load count
Repe Scasb ;Test memory with accum
Jcxz Test01 ;...jump if no error
Stc ;Carry set indicates error
Ret ;...return
Test01:
Xor Di,Di ;Re-load pointer
Mov Cx,Bx ;Re-load count
Mov Al,1 ;Next is 1 (tests parity)
Rep Stosb ;Write it
Xor Di,Di ;Re-load pointer
Mov Cx,Bx ;Re-load count
Repe Scasb ;Test memory with accum
Jcxz Test00 ;...jump if no error
Stc ;Carry set indicates error
Ret ;...return
Test00:
Xor Di,Di ;Re-load pointer
Mov Cx,Bx ;Re-load count
Dec Al ;Clear memory to zero & test
Rep Stosb ;Write it
Xor Di,Di ;Re-load pointer
Mov Cx,Bx ;Re-load count
Repe Scasb ;Test memory with accum
Jcxz NoMemError ;...jump if no error
Stc ;Carry set indicates error
Ret ;...return
NoMemError:
Mov Ax,Es ;Add 2K to segment register
Add Ax,1024 / 16 ;...using paragraphs
Mov Es,Ax ;...put it back
Ret ;Return carry clear if no error
MemoryTest Endp
Bios Ends
End