Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 553 lines (463 sloc) 9.006 kb
45b2713 Andrew Jenner Added mandel_quadtree
authored
1 %include "../defaults_bin.asm"
04a48a6 Andrew Jenner XT OS kernel
authored
2
45b2713 Andrew Jenner Added mandel_quadtree
authored
3 jmp codeStart
4
fa5399b Andrew Jenner XT Server reliability improvements
authored
5 db '20131215a-com1-115200',0
45b2713 Andrew Jenner Added mandel_quadtree
authored
6
7 codeStart:
9695c70 Andrew Jenner XTServer improvements
authored
8 sub di,0x500
9 cmp di,kernelEnd
10 jne lengthOk1
11 or byte[cs:flags],1
12 lengthOk1:
13
564a3b9 Andrew Jenner Quickboot without serial
authored
14 call findIP
15 findIP:
9695c70 Andrew Jenner XTServer improvements
authored
16 pop si
564a3b9 Andrew Jenner Quickboot without serial
authored
17 sub si,findIP
fa5399b Andrew Jenner XT Server reliability improvements
authored
18
9695c70 Andrew Jenner XTServer improvements
authored
19 mov ah,0
fa5399b Andrew Jenner XT Server reliability improvements
authored
20 mov cx,checkSum
9695c70 Andrew Jenner XTServer improvements
authored
21 checksumLoop:
22 lodsb
23 add ah,al
24 loop checksumLoop
fa5399b Andrew Jenner XT Server reliability improvements
authored
25 cmp ah,[cs:checkSum]
9695c70 Andrew Jenner XTServer improvements
authored
26 je checksumOk1
27 or byte[cs:flags],2
28 checksumOk1:
29
5db066b Andrew Jenner CGA timings
authored
30 ; Don't want any stray interrupts interfering with the serial port accesses.
04a48a6 Andrew Jenner XT OS kernel
authored
31 cli
32
45b2713 Andrew Jenner Added mandel_quadtree
authored
33 ; Set 40-column text mode
34 initCGA 8
de617d8 Andrew Jenner XT OS kernel
authored
35
25eea58 Andrew Jenner XT OS Kernel
authored
36 ; Clear the video memory
37 mov ax,0xb800
38 mov es,ax
39 mov cx,40*25
40 mov ax,0x0700
41 xor di,di
42 cld
43 rep stosw
de617d8 Andrew Jenner XT OS kernel
authored
44
82cafd8 Andrew Jenner XT OS kernel
authored
45 ; Set up the timer interrupt
0b1f245 Andrew Jenner Oscilloscope demo effect
authored
46 mov al,TIMER0 | BOTH | MODE3 | BINARY
82cafd8 Andrew Jenner XT OS kernel
authored
47 out 0x43,al
17bc32f Andrew Jenner XT Hard disk reading
authored
48 mov al,0 ; rate = 13125000/11/2^16 ~= 18.2Hz
82cafd8 Andrew Jenner XT OS kernel
authored
49 out 0x40,al
50 out 0x40,al
51
52 ; Set up interrupt masks.
53 mov al,0xbc ; Enable IRQs 0 (timer), 1 (keyboard) and 6 (floppy disk).
54 out 0x21,al ; Leave disabled 2 (EGA/VGA/slave 8259) 3 (COM2/COM4), 4 (COM1/COM3), 5 (hard drive, LPT2) and 7 (LPT1)
55
56 ; Set up interrupt table
57 xor ax,ax
58 mov es,ax
59 mov ax,0xf000
60 mov ds,ax
61 mov cx,8
62 mov si,0xfef3
63 mov di,0x20
64 interruptSetupLoop:
65 movsw
66 inc di
67 inc di
68 loop interruptSetupLoop
4d82a9a Andrew Jenner XTServer improvements
authored
69 mov word[0x02*4], 0xf85f ; nmi_int
70 mov word[0x05*4], 0xff54 ; print_screen
71 mov word[0x18*4 + 2], 0xf600 ; segment for BASIC
82cafd8 Andrew Jenner XT OS kernel
authored
72
539cb9a Andrew Jenner XT OS kernel
authored
73 ; Disable NMI
17bc32f Andrew Jenner XT Hard disk reading
authored
74 xor al,al
75 out 0xa0,al
8740169 Andrew Jenner Instruction timings
authored
76
04a48a6 Andrew Jenner XT OS kernel
authored
77 ; Move the stack right at the end of main RAM.
8740169 Andrew Jenner Instruction timings
authored
78 mov ax,0x9000
04a48a6 Andrew Jenner XT OS kernel
authored
79 mov ss,ax
80 xor sp,sp
81
966f2f9 Andrew Jenner XT OS kernel
authored
82 mov di,0x50 ;Target segment (TODO: make this 0060:0000 as FreeDOS does?)
539cb9a Andrew Jenner XT OS kernel
authored
83 mov bx,cs
2749222 Andrew Jenner XT OS kernel
authored
84 call main
85 main:
966f2f9 Andrew Jenner XT OS kernel
authored
86 pop si
87 sub si,main ; Offset of our start within CS
2749222 Andrew Jenner XT OS kernel
authored
88 jnz checkDestinationClear
966f2f9 Andrew Jenner XT OS kernel
authored
89 cmp bx,di
2749222 Andrew Jenner XT OS kernel
authored
90 jz noRelocationNeeded
91 checkDestinationClear:
92 ; Check that (start of our code) >= (end of destination code)
966f2f9 Andrew Jenner XT OS kernel
authored
93 ; Normalize our address
2749222 Andrew Jenner XT OS kernel
authored
94 mov cl,4
966f2f9 Andrew Jenner XT OS kernel
authored
95 mov ax,si
2749222 Andrew Jenner XT OS kernel
authored
96 shr ax,cl
966f2f9 Andrew Jenner XT OS kernel
authored
97 add ax,bx
98 and si,0x0f ; Our start address in normalized xxxx:000x form is now in AX:SI
2749222 Andrew Jenner XT OS kernel
authored
99 ; compute end of destination as a physical address
966f2f9 Andrew Jenner XT OS kernel
authored
100 mov dx,di
e3884b1 Andrew Jenner XT OS kernel
authored
101 add dx,(kernelEnd + 15) >> 4 ; end of destination segment
7575440 Andrew Jenner XT OS kernel
authored
102 cmp ax,dx
103 jge doMove
104 ; We can't relocate to the final destination directly, since our code
105 ; overlaps that space. We need to move to a point that is higher than both
4ea1690 Andrew Jenner XT OS kernel
authored
106 ; the end of our code and the end of the final destination.
7e22fda Andrew Jenner Virtual keyboard
authored
107 mov di,ax
108 add di,(kernelEnd + 15) >> 4 ; end of current code
109 cmp di,dx
4ea1690 Andrew Jenner XT OS kernel
authored
110 jge doMove
111 ; We are overlapping the start of the final destination - relocate to after
112 ; the end of the final destination.
113 mov di,dx
7575440 Andrew Jenner XT OS kernel
authored
114 doMove:
115 push di ; Push return segment
116 ; Move kernelEnd bytes from AX:SI to DI:0
117 mov cx,kernelEnd
118 mov ds,ax
119 mov es,di
120 xor di,di
121 push di ; Push return offset
122 rep movsb
123 retf
2749222 Andrew Jenner XT OS kernel
authored
124
125 noRelocationNeeded:
539cb9a Andrew Jenner XT OS kernel
authored
126 ; Set up some interrupts
4d82a9a Andrew Jenner XTServer improvements
authored
127 ; int 0x60 == capture screen
128 ; int 0x61 == start audio recording
129 ; int 0x62 == stop audio recording
45b2713 Andrew Jenner Added mandel_quadtree
authored
130 ; int 0x63 == print AX as a 4-digit hex number
131 ; int 0x64 == print CX bytes from DS:SI
132 ; int 0x65 == print AL as a character
4d82a9a Andrew Jenner XTServer improvements
authored
133 ; int 0x66 == send file
b4a2c4c Andrew Jenner XT Serial kernel
authored
134 ; int 0x67 == finish
45b2713 Andrew Jenner Added mandel_quadtree
authored
135 ; int 0x68 == load data from serial port at ES:DI. On completion, ES:DI points to end of loaded data.
4d82a9a Andrew Jenner XTServer improvements
authored
136 ; int 0x69 == stop screen output
137 ; int 0x6a == start screen output
539cb9a Andrew Jenner XT OS kernel
authored
138 xor ax,ax
139 mov ds,ax
4d82a9a Andrew Jenner XTServer improvements
authored
140 setInterrupt 0x60, captureScreenRoutine
141 setInterrupt 0x61, startAudioRoutine
142 setInterrupt 0x62, stopAudioRoutine
45b2713 Andrew Jenner Added mandel_quadtree
authored
143 setInterrupt 0x63, printHexRoutine
144 setInterrupt 0x64, printStringRoutine
145 setInterrupt 0x65, printCharacterRoutine
4d82a9a Andrew Jenner XTServer improvements
authored
146 setInterrupt 0x66, sendFileRoutine
45b2713 Andrew Jenner Added mandel_quadtree
authored
147 setInterrupt 0x67, completeRoutine
148 setInterrupt 0x68, loadSerialDataRoutine
4d82a9a Andrew Jenner XTServer improvements
authored
149 setInterrupt 0x69, stopScreenRoutine
150 setInterrupt 0x6a, resumeScreenRoutine
45b2713 Andrew Jenner Added mandel_quadtree
authored
151
152 ; Reset video variables
153 mov ax,cs
154 mov ds,ax
155 xor ax,ax
156 mov [column],al
157 mov [startAddress],ax
17bc32f Andrew Jenner XT Hard disk reading
authored
158
9695c70 Andrew Jenner XTServer improvements
authored
159 test byte[flags],1
160 jz lengthOk
161
162 mov si,lengthWrong
163 mov cx,lengthWrongEnd - lengthWrong
164 printString
165
166 lengthOk:
167 test byte[flags],2
168 jz checksumOk
169
170 mov si,checksumWrong
171 mov cx,checksumWrongEnd - checksumWrong
172 printString
fa5399b Andrew Jenner XT Server reliability improvements
authored
173
174 ; mov ax,[cs:computedChecksum]
175 ; printHex
176 ; mov ax,[cs:kernelOffset]
177 ; printHex
178 ; mov ax,[cs:kernelLength]
179 ; printHex
180
9695c70 Andrew Jenner XTServer improvements
authored
181 checksumOk:
182
45b2713 Andrew Jenner Added mandel_quadtree
authored
183 ; Print the boot message
fa5399b Andrew Jenner XT Server reliability improvements
authored
184 ; mov si,bootMessage
185 ; mov cx,bootMessageEnd - bootMessage
186 ; printString
17bc32f Andrew Jenner XT Hard disk reading
authored
187
04a48a6 Andrew Jenner XT OS kernel
authored
188 ; Push the cleanup address for the program to retf back to.
2749222 Andrew Jenner XT OS kernel
authored
189 mov bx,cs
190 push bx
45b2713 Andrew Jenner Added mandel_quadtree
authored
191 mov ax,completeRoutine
04a48a6 Andrew Jenner XT OS kernel
authored
192 push ax
193
194 ; Find the next segment after the end of the kernel. This is where we'll
195 ; load our program.
e3884b1 Andrew Jenner XT OS kernel
authored
196 mov ax,(kernelEnd + 15) >> 4
2749222 Andrew Jenner XT OS kernel
authored
197 add ax,bx
45b2713 Andrew Jenner Added mandel_quadtree
authored
198 mov es,ax
61b7163 Andrew Jenner Floppy image writing
authored
199 xor di,di
200
45b2713 Andrew Jenner Added mandel_quadtree
authored
201 ; Push the address so we can just retf to it after the load
202 push es
04a48a6 Andrew Jenner XT OS kernel
authored
203 push di
204
45b2713 Andrew Jenner Added mandel_quadtree
authored
205 loadSerialData
17bc32f Andrew Jenner XT Hard disk reading
authored
206
45b2713 Andrew Jenner Added mandel_quadtree
authored
207 ; Print the OK message
208 mov si,okMessage
209 mov cx,okMessageEnd - okMessage
210 printString
17bc32f Andrew Jenner XT Hard disk reading
authored
211
04a48a6 Andrew Jenner XT OS kernel
authored
212 retf
213
214
45b2713 Andrew Jenner Added mandel_quadtree
authored
215 loadSerialDataRoutine:
216 initSerial
217
fcfe280 Andrew Jenner XT Server improvements
authored
218 inc dx ; 5
219 mov al,'R'
220 sendByte
221 dec dx
222
45b2713 Andrew Jenner Added mandel_quadtree
authored
223 packetLoop:
224 ; Activate DTR
225 mov al,1
226 out dx,al
227 inc dx ; 5
228
229 ; Receive packet size in bytes
230 receiveByte
07cd670 Andrew Jenner Bits and pieces from Sundown 2013
authored
231
45b2713 Andrew Jenner Added mandel_quadtree
authored
232 mov cl,al
233 mov ch,0
234
235 ; Push a copy to check when we're done and adjust DI for retries
236 push cx
237
07cd670 Andrew Jenner Bits and pieces from Sundown 2013
authored
238 ; call printCharNoSerial
239
45b2713 Andrew Jenner Added mandel_quadtree
authored
240 ; Init checksum
241 mov ah,0
242
243 ; Receive CX bytes and store them at ES:DI
244 jcxz noBytes
245 byteLoop:
246 receiveByte
247 add ah,al
248 stosb
249 loop byteLoop
250 noBytes:
251
252 ; Receive checksum
253 receiveByte
254 sub ah,al
255
256 ; Deactivate DTR
257 dec dx ; 4
258 mov al,0
259 out dx,al
260
261 cmp ah,0
262 jne checkSumFailed
263
264 ; Send success byte
265 inc dx ; 5
266 mov al,'K'
267 sendByte
268 dec dx ; 4
269
270
271 ; Normalize ES:DI
272 mov ax,di
273 mov cl,4
274 shr ax,cl
275 mov bx,es
276 add bx,ax
277 mov es,bx
278 and di,0xf
279
280 pop cx
281 jcxz transferComplete
282 jmp packetLoop
283
284 checkSumFailed:
285 ; Send fail byte
286 inc dx ; 5
287 mov al,'F'
288 sendByte
289 dec dx ; 4
290
291 pop cx
292 sub di,cx
293 jmp packetLoop
294
295 transferComplete:
296 iret
297
298
299 completeRoutine:
527530d Andrew Jenner 765
authored
300 disconnect
04a48a6 Andrew Jenner XT OS kernel
authored
301 jmp 0 ; Restart the kernel
302
303
45b2713 Andrew Jenner Added mandel_quadtree
authored
304 printNybble:
305 cmp al,10
306 jge printAlphabetic
307 add al,'0'
308 jmp printGotCharacter
309 printAlphabetic:
310 add al,'A' - 10
311 printGotCharacter:
312 jmp printChar
313
314
315 printHexRoutine:
316 push bx
317 push cx
318 mov bx,ax
319 mov al,bh
320 mov cl,4
321 shr al,cl
322 call printNybble
323 mov al,bh
324 and al,0xf
325 call printNybble
326 mov al,bl
327 shr al,cl
328 call printNybble
329 mov al,bl
330 and al,0xf
331 call printNybble
332 pop cx
333 pop bx
334 iret
335
336
337 printStringRoutine:
338 lodsb
339 call printChar
340 loop printStringRoutine
341 iret
342
343
344 printCharacterRoutine:
345 call printChar
346 iret
347
348
4d82a9a Andrew Jenner XTServer improvements
authored
349 printCharNoScreen:
350 push dx
351 mov dx,0x3f8 + 5
352 sendByte
353 pop dx
354 ret
355
356
07cd670 Andrew Jenner Bits and pieces from Sundown 2013
authored
357 printCharNoSerial:
358 push dx
359 jmp printCharCommon
360
361
45b2713 Andrew Jenner Added mandel_quadtree
authored
362 printChar:
363 push dx
527530d Andrew Jenner 765
authored
364
365 ; Output the character over serial as well
366 mov dx,0x3f8 + 5
367 sendByte
368
07cd670 Andrew Jenner Bits and pieces from Sundown 2013
authored
369 printCharCommon:
4d82a9a Andrew Jenner XTServer improvements
authored
370 cmp word[cs:screenCounter],0
371 jne .complete
372
373 push bx
374 push cx
375 push es
376 push di
377
45b2713 Andrew Jenner Added mandel_quadtree
authored
378 mov dx,0xb800
379 mov es,dx
380 mov dx,0x3d4
381 mov cx,[cs:startAddress]
382 cmp al,10
4d82a9a Andrew Jenner XTServer improvements
authored
383 je .newLine
45b2713 Andrew Jenner Added mandel_quadtree
authored
384 mov di,cx
385 add di,cx
386 mov bl,[cs:column]
387 xor bh,bh
388 mov [es:bx+di+24*40*2],al
389 inc bx
390 inc bx
391 cmp bx,80
4d82a9a Andrew Jenner XTServer improvements
authored
392 jne .done
393 .newLine:
45b2713 Andrew Jenner Added mandel_quadtree
authored
394 add cx,40
395 and cx,0x1fff
396 mov [cs:startAddress],cx
397
398 ; Scroll screen
399 mov ah,ch
400 mov al,0x0c
401 out dx,ax
402 mov ah,cl
403 inc ax
404 out dx,ax
405 ; Clear the newly scrolled area
406 mov di,cx
407 add di,cx
408 add di,24*40*2
409 mov cx,40
410 mov ax,0x0700
411 rep stosw
412 mov cx,[cs:startAddress]
413
414 xor bx,bx
4d82a9a Andrew Jenner XTServer improvements
authored
415 .done:
45b2713 Andrew Jenner Added mandel_quadtree
authored
416 mov [cs:column],bl
417
418 ; Move cursor
419 shr bx,1
420 add bx,cx
421 add bx,24*40
422 and bx,0x1fff
423 mov ah,bh
424 mov al,0x0e
425 out dx,ax
426 mov ah,bl
427 inc ax
428 out dx,ax
429
430 pop di
431 pop es
432 pop cx
433 pop bx
4d82a9a Andrew Jenner XTServer improvements
authored
434 .complete:
435 pop dx
436 ret
437
438 captureScreenRoutine:
439 push ax
440 mov al,1
441 call printCharNoScreen
442 pop ax
443 iret
444
445 startAudioRoutine:
446 push ax
447 mov al,2
448 call printCharNoScreen
449 pop ax
450 iret
451
452 stopAudioRoutine:
453 push ax
454 mov al,3
455 call printCharNoScreen
456 pop ax
457 iret
458
459 printCharEscaped:
460 cmp al,0x5
461 ja .checkForComplete
462 .escapeNeeded:
463 push ax
464 mov al,0
465 call printCharNoScreen
466 pop ax
467 .noEscapeNeeded:
468 call printCharNoScreen
45b2713 Andrew Jenner Added mandel_quadtree
authored
469 ret
4d82a9a Andrew Jenner XTServer improvements
authored
470 .checkForComplete:
471 cmp al,0x1a
472 je .escapeNeeded
473 jmp .noEscapeNeeded
474
475
476 sendFileRoutine:
477 cld
478 mov al,4
479 call printCharNoScreen
480 mov al,cl
481 call printCharEscaped
482 mov al,ch
483 call printCharEscaped
484 mov al,dl
485 call printCharEscaped
486 .loopTop:
487 cmp cx,0
488 jne .doByte
489 cmp dl,0
490 je .done
491 .doByte:
492 cmp si,0xffff
493 jne .normalized
494 mov si,0x000f
495 mov ax,ds
496 add ax,0xfff
497 mov ds,ax
498 .normalized:
499 lodsb
500 call printCharEscaped
501 dec cx
502 cmp cx,0xffff
503 jne .loopTop
504 dec dl
505 jmp .loopTop
506 .done:
507 iret
508
509
510 stopScreenRoutine:
511 inc word[cs:screenCounter]
512 iret
513
514
515 resumeScreenRoutine:
516 dec word[cs:screenCounter]
517 iret
45b2713 Andrew Jenner Added mandel_quadtree
authored
518
519
520 column:
521 db 0
522 startAddress:
523 dw 0
fa5399b Andrew Jenner XT Server reliability improvements
authored
524 ;bootMessage:
525 ; db 'XT Serial Kernel',10
526 ;bootMessageEnd:
9695c70 Andrew Jenner XTServer improvements
authored
527 lengthWrong:
528 db 'Length incorrect',10
529 lengthWrongEnd:
530 checksumWrong:
531 db 'Checksum incorrect',10
532 checksumWrongEnd:
45b2713 Andrew Jenner Added mandel_quadtree
authored
533 okMessage:
534 db 'OK',10
535 okMessageEnd:
4d82a9a Andrew Jenner XTServer improvements
authored
536 screenCounter:
537 dw 0
45b2713 Andrew Jenner Added mandel_quadtree
authored
538
9695c70 Andrew Jenner XTServer improvements
authored
539 flags:
540 db 0
541
fa5399b Andrew Jenner XT Server reliability improvements
authored
542 ;kernelLength:
543 ; dw 0
544 ;kernelOffset:
545 ; dw 0
546 ;computedChecksum:
547 ; db 0
548
9695c70 Andrew Jenner XTServer improvements
authored
549 checkSum:
550 db 0 ; This will be overwritten by quickboot
45b2713 Andrew Jenner Added mandel_quadtree
authored
551
04a48a6 Andrew Jenner XT OS kernel
authored
552 kernelEnd:
Something went wrong with that request. Please try again.