-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc.asm
374 lines (335 loc) · 10.4 KB
/
misc.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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
comment |*******************************************************************
* Copyright (c) 1984-2024 Forever Young Software Benjamin David Lunt *
* *
* i440FX BIOS ROM v1.0 *
* FILE: misc.asm *
* *
* This code is freeware, not public domain. Please use respectfully. *
* *
* You may: *
* - use this code for learning purposes only. *
* - use this code in your own Operating System development. *
* - distribute any code that you produce pertaining to this code *
* as long as it is for learning purposes only, not for profit, *
* and you give credit where credit is due. *
* *
* You may NOT: *
* - distribute this code for any purpose other than listed above. *
* - distribute this code for profit. *
* *
* You MUST: *
* - include this whole comment block at the top of this file. *
* - include contact information to where the original source is located. *
* https://github.com/fysnet/i440fx *
* *
* DESCRIPTION: *
* misc include file *
* *
* BUILT WITH: NewBasic Assembler *
* http://www.fysnet/newbasic.htm *
* NBASM ver 00.27.14 *
* Command line: nbasm i440fx /z<enter> *
* *
* Last Updated: 25 Oct 2024 *
* *
****************************************************************************
* Notes: *
* *
***************************************************************************|
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; freeze the system
; on entry:
; nothing
; on return
; does not return
freeze proc near
@@: hlt
jmp short @b
.noret
freeze endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; on entry:
; al = byte to convert
; on return
; al = byte converted
bcd_to_bin proc near uses bx
mov bl,al
and bl,0x0F ; bl has low digit
shr al,4 ; al has high digit
mov bh,10
mul bh ; multiply high digit by 10 (result in AX)
add al,bl ; then add low digit
ret
bcd_to_bin endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; on entry:
; al = byte to convert
; on return
; al = byte converted
bin_to_bcd proc near uses bx
mov bh,ah ; preserved ah
xor ah,ah
mov bl,10
div bl
shl al,4
add al,ah
mov ah,bh ; restore ah
ret
bin_to_bcd endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; compare two strings
; on entry:
; stack contains: (cdecl)
; t_off, t_seg, s_off, s_seg, count
; [bp+4], [bp+6], [bp+8], [bp+10], [bp+12]
; on return
; ax = 0 = match
strncmp proc near ; don't add anything here
push bp
mov bp,sp
push cx
push si
push di
push ds
push es
mov si,[bp+8]
mov ax,[bp+10]
mov ds,ax
mov di,[bp+4]
mov ax,[bp+6]
mov es,ax
mov cx,[bp+12]
mov ax,1 ; assume no match
repe
cmpsb
jnz short @f
xor ax,ax ; is a match
@@: pop es
pop ds
pop di
pop si
pop cx
mov sp,bp
pop bp
ret
strncmp endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; clears a buffer
; on entry:
; stack contains: (cdecl)
; t_off, t_seg, count
; [bp+4], [bp+6], [bp+8]
; on return
; ax = 0 = match
misc_clear_buffer proc near ; don't add anything here
push bp
mov bp,sp
push es
push di
push cx
push ax
xor al,al
mov di,[bp+4]
mov es,[bp+6]
mov cx,[bp+8]
rep
stosb
pop ax
pop cx
pop di
pop es
mov sp,bp
pop bp
ret
misc_clear_buffer endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; standard memory copy (16-bit using segmentation)
; on entry:
; stack contains: (cdecl)
; t_off, t_seg, s_off, s_seg, count
; [bp+4], [bp+6], [bp+8], [bp+10], [bp+12]
; on return
; nothing
memcpy16 proc near ; don't add anything here
push bp
mov bp,sp
push cx
push si
push di
push ds
push es
mov si,[bp+8]
mov ax,[bp+10]
mov ds,ax
mov di,[bp+4]
mov ax,[bp+6]
mov es,ax
mov cx,[bp+12]
rep
movsb
pop es
pop ds
pop di
pop si
pop cx
mov sp,bp
pop bp
ret
memcpy16 endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; standard memory copy (32-bit using flat address space)
; on entry:
; stack contains: (cdecl)
; t_addr, s_addr, count
; [bp+4], [bp+8], [bp+12]
; on return
; nothing
memcpy32 proc near ; don't add anything here
push bp
mov bp,sp
push ecx
push esi
push edi
push ax
mov esi,[bp+8]
mov edi,[bp+4]
mov ecx,[bp+12]
@@: mov al,fs:[esi]
inc esi
mov fs:[edi],al
inc edi
.adsize
loop @b
pop ax
pop edi
pop esi
pop ecx
mov sp,bp
pop bp
ret
memcpy32 endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; standard memory compare (32-bit using flat address space)
; on entry:
; stack contains: (cdecl)
; t_addr, s_addr, count
; [bp+4], [bp+8], [bp+12]
; on return
; ax = 0 = memory is equal
memcmp32 proc near ; don't add anything here
push bp
mov bp,sp
push ecx
push esi
push edi
mov esi,[bp+8]
mov edi,[bp+4]
mov ecx,[bp+12]
dec edi
@@: inc edi
mov al,fs:[esi]
inc esi
cmp fs:[edi],al
.adsize
loope @b
; was the last one a match
;cmp fs:[edi],al
mov ax,1
jne short @f
xor ax,ax
@@: pop edi
pop esi
pop ecx
mov sp,bp
pop bp
ret
memcmp32 endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; clear a buffer (32-bit using flat address space)
; on entry:
; ax = size of buffer
; fs:edi-> buffer to clear
; on return
; nothing
memset32 proc near uses ax cx edi
mov cx,ax
xor al,al
@@: mov fs:[edi],al
inc edi
loop @b
ret
memset32 endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; calculate the crc of a 'table'
; on entry:
; fs:edi-> table
; ax = size of 'table'
; on return
; al = crc
; destroys none
calc_checksum proc near uses cx edi
mov cx,ax
xor al,al
@@: add al,fs:[edi]
inc edi
loop @b
neg al
ret
calc_checksum endp
.if (!DO_INIT_BIOS32)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; bswap a 32-bit (eax) from little-endian to big-endian (or visa-versa)
; this is used if we don't have a 486+
; on entry:
; eax = value to bswap
; on return
; eax = bswapped value
; destroys none
_bswap proc near
;11 22 33 44
ror eax,8
;44 11 22 33
xchg ah,al
;44 11 33 22
ror eax,16
;33 22 44 11
xchg ah,al
;33 22 11 44
ror eax,8
;44 33 22 11
ret
_bswap endp
.endif
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; delays count milliseconds
; on entry:
; eax = count of ms
; (if eax > 0x003FFFFF, this will not work correctly)
; on return
; nothing
; destroys none
mdelay proc near uses eax cx dx
shl eax,10 ; convert from mS to uS
mov dx,ax ; cx:dx = uS
shr eax,16
mov cx,ax
mov ah,0x86
int 15h
ret
mdelay endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; delays count microseconds
; on entry:
; eax = count of us
; on return
; nothing
; destroys none
udelay proc near uses eax cx dx
mov dx,ax ; cx:dx = uS
shr eax,16
mov cx,ax
mov ah,0x86
int 15h
ret
udelay endp
.end