|
;; $Id: conio.inc,v 1.1 2007-09-01 22:44:04 niro Exp $ |
|
1 |
;; ----------------------------------------------------------------------- |
;; ----------------------------------------------------------------------- |
2 |
;; |
;; |
3 |
;; Copyright 1994-2005 H. Peter Anvin - All Rights Reserved |
;; Copyright 1994-2008 H. Peter Anvin - All Rights Reserved |
4 |
|
;; Copyright 2009 Intel Corporation; author: H. Peter Anvin |
5 |
;; |
;; |
6 |
;; This program is free software; you can redistribute it and/or modify |
;; This program is free software; you can redistribute it and/or modify |
7 |
;; it under the terms of the GNU General Public License as published by |
;; it under the terms of the GNU General Public License as published by |
15 |
;; conio.inc |
;; conio.inc |
16 |
;; |
;; |
17 |
;; Console I/O code, except: |
;; Console I/O code, except: |
18 |
;; writechr, writestr - module-dependent |
;; writechr, writestr_early - module-dependent |
19 |
;; cwritestr, crlf - writestr.inc |
;; writestr, crlf - writestr.inc |
20 |
;; writehex* - writehex.inc |
;; writehex* - writehex.inc |
21 |
;; |
;; |
22 |
|
|
23 |
; |
; |
24 |
; loadkeys: Load a LILO-style keymap; SI and DX:AX set by searchdir |
; loadkeys: Load a LILO-style keymap; file is open on the top of the |
25 |
|
; getc stack. |
26 |
; |
; |
27 |
section .text |
section .text |
28 |
|
|
29 |
loadkeys: |
loadkeys: |
30 |
and dx,dx ; Should be 256 bytes exactly |
mov cx,256 |
31 |
jne loadkeys_ret |
mov di,trackbuf |
32 |
cmp ax,256 |
call readc |
33 |
jne loadkeys_ret |
jc .done ; EOF already? |
34 |
|
|
35 |
mov bx,trackbuf |
; Make sure we are at EOF now... |
36 |
mov cx,1 ; 1 cluster should be >= 256 bytes |
call getc |
37 |
call getfssec |
jnc .done ; We should be at EOF now! |
38 |
|
|
39 |
|
; It was okay, we can now move it into the KbdMap |
40 |
mov si,trackbuf |
mov si,trackbuf |
41 |
mov di,KbdMap |
mov di,KbdMap |
42 |
mov cx,256 >> 2 |
mov cx,256 >> 2 |
43 |
rep movsd |
rep movsd |
44 |
|
|
45 |
loadkeys_ret: ret |
.done: |
46 |
|
call close |
47 |
|
ret |
48 |
|
|
49 |
; |
; |
50 |
; get_msg_file: Load a text file and write its contents to the screen, |
; get_msg_file: Load a text file and write its contents to the screen, |
51 |
; interpreting color codes. Is called with SI and DX:AX |
; interpreting color codes. Call with the file already |
52 |
; set by routine searchdir |
; on the top of the open/getc stack. |
53 |
|
; |
54 |
|
; Assumes CS == DS == ES. |
55 |
; |
; |
56 |
get_msg_file: |
get_msg_file: |
|
push es |
|
|
shl edx,16 ; EDX <- DX:AX (length of file) |
|
|
mov dx,ax |
|
|
mov ax,xfer_buf_seg ; Use for temporary storage |
|
|
mov es,ax |
|
|
|
|
57 |
mov byte [TextAttribute],07h ; Default grey on white |
mov byte [TextAttribute],07h ; Default grey on white |
58 |
mov byte [DisplayMask],07h ; Display text in all modes |
mov byte [DisplayMask],07h ; Display text in all modes |
59 |
call msg_initvars |
call msg_initvars |
60 |
|
|
|
get_msg_chunk: push edx ; EDX = length of file |
|
|
xor bx,bx ; == xbs_textbuf |
|
|
mov cx,[BufSafe] |
|
|
call getfssec |
|
|
pop edx |
|
|
push si ; Save current cluster |
|
|
xor si,si ; == xbs_textbuf |
|
|
mov cx,[BufSafeBytes] ; Number of bytes left in chunk |
|
61 |
print_msg_file: |
print_msg_file: |
62 |
push cx |
.getc: |
63 |
push edx |
call getc |
64 |
es lodsb |
jc .done |
65 |
cmp al,1Ah ; DOS EOF? |
cmp al,1Ah ; DOS EOF? |
66 |
je msg_done_pop |
je .done |
67 |
push si |
movzx cx,byte [UsingVGA] |
68 |
mov cl,[UsingVGA] |
and cl,01h |
69 |
inc cl ; 01h = text mode, 02h = graphics |
inc cx ; CL <- 01h = text mode, |
70 |
|
; 02h = graphics mode |
71 |
call [NextCharJump] ; Do what shall be done |
call [NextCharJump] ; Do what shall be done |
72 |
pop si |
jmp .getc |
73 |
pop edx |
.done: |
74 |
pop cx |
jmp close ; Tailcall! |
75 |
dec edx |
|
|
jz msg_done |
|
|
loop print_msg_file |
|
|
pop si |
|
|
jmp short get_msg_chunk |
|
|
msg_done_pop: |
|
|
add sp,byte 6 ; Drop pushed EDX, CX |
|
|
msg_done: |
|
|
pop si |
|
|
pop es |
|
|
ret |
|
76 |
msg_putchar: ; Normal character |
msg_putchar: ; Normal character |
77 |
cmp al,0Fh ; ^O = color code follows |
cmp al,0Fh ; ^O = color code follows |
78 |
je msg_ctrl_o |
je msg_ctrl_o |
203 |
jmp short msg_initvars |
jmp short msg_initvars |
204 |
|
|
205 |
msg_viewimage: |
msg_viewimage: |
|
push es |
|
|
push ds |
|
|
pop es ; ES <- DS |
|
206 |
mov si,[VGAFilePtr] |
mov si,[VGAFilePtr] |
207 |
mov byte [si],0 ; Zero-terminate filename |
mov byte [si],0 ; Zero-terminate filename |
208 |
mov si,VGAFileBuf |
mov si,VGAFileBuf |
209 |
mov di,VGAFileMBuf |
mov di,VGAFileMBuf |
|
push di |
|
210 |
call mangle_name |
call mangle_name |
211 |
pop di |
call open |
|
call searchdir |
|
|
pop es |
|
212 |
jz msg_putcharnext ; Not there |
jz msg_putcharnext ; Not there |
213 |
call vgadisplayfile |
call vgadisplayfile |
214 |
; Fall through |
; Fall through |
256 |
in al,dx |
in al,dx |
257 |
and al,ah |
and al,ah |
258 |
cmp al,ah |
cmp al,ah |
259 |
jne .waitspace |
jne .waitspace |
260 |
.no_flow: |
.no_flow: |
261 |
|
|
262 |
xchg dx,bx ; DX -> THR |
xchg dx,bx ; DX -> THR |
263 |
pop ax |
pop ax |
264 |
call slow_out ; Send data |
slow_out dx,al ; Send data |
265 |
.noserial: popad |
.noserial: popad |
266 |
popfd |
popfd |
267 |
.end: ret |
.end: ret |
293 |
mov dx,[SerialPort] |
mov dx,[SerialPort] |
294 |
and dx,dx |
and dx,dx |
295 |
jz .done ; No serial port -> no input |
jz .done ; No serial port -> no input |
296 |
add dx,byte 5 ; DX -> LSR |
mov ax,[SerialTail] ; Already-queued input? |
297 |
|
cli |
298 |
|
cmp ax,[SerialHead] |
299 |
|
jne .done_sti ; If so, return ZF = 0 |
300 |
|
add dx,5 ; DX -> LSR |
301 |
in al,dx |
in al,dx |
302 |
test al,1 ; ZF = 0 if data pending |
test al,1 ; ZF = 0 if data pending |
303 |
jz .done |
jz .done_sti |
304 |
inc dx ; DX -> MSR |
inc dx ; DX -> MSR |
305 |
mov ah,[FlowIgnore] ; Required status bits |
mov ah,[FlowIgnore] ; Required status bits |
306 |
in al,dx |
in al,dx |
308 |
cmp al,ah |
cmp al,ah |
309 |
setne al |
setne al |
310 |
dec al ; Set ZF = 0 if equal |
dec al ; Set ZF = 0 if equal |
311 |
|
.done_sti: sti |
312 |
.done: popad |
.done: popad |
313 |
ret |
ret |
314 |
|
|
315 |
; |
; |
316 |
; getchar: Read a character from keyboard or serial port |
; getchar: Read a character from keyboard or serial port |
317 |
; |
; |
318 |
|
getchar.sti_again: |
319 |
|
sti |
320 |
getchar: |
getchar: |
|
RESET_IDLE |
|
321 |
.again: |
.again: |
322 |
DO_IDLE |
call do_idle |
323 |
mov ah,11h ; Poll keyboard |
mov ah,11h ; Poll keyboard |
324 |
int 16h |
int 16h |
325 |
jnz .kbd ; Keyboard input? |
jnz .kbd ; Keyboard input? |
326 |
mov bx,[SerialPort] |
mov bx,[SerialPort] |
327 |
and bx,bx |
and bx,bx |
328 |
jz .again |
jz .again |
329 |
|
mov ax,[SerialTail] |
330 |
|
cli |
331 |
|
cmp ax,[SerialHead] |
332 |
|
jne .serial_queued |
333 |
lea dx,[bx+5] ; DX -> LSR |
lea dx,[bx+5] ; DX -> LSR |
334 |
in al,dx |
in al,dx |
335 |
test al,1 |
test al,1 |
336 |
jz .again |
jz .sti_again |
337 |
inc dx ; DX -> MSR |
inc dx ; DX -> MSR |
338 |
mov ah,[FlowIgnore] |
mov ah,[FlowIgnore] |
339 |
in al,dx |
in al,dx |
340 |
and al,ah |
and al,ah |
341 |
cmp al,ah |
cmp al,ah |
342 |
jne .again |
jne .sti_again |
343 |
.serial: xor ah,ah ; Avoid confusion |
.serial: xor ah,ah ; Avoid confusion |
344 |
xchg dx,bx ; Data port |
mov dx,bx ; Data port |
345 |
in al,dx |
in al,dx ; Read data |
346 |
ret |
sti |
347 |
|
jmp .done |
348 |
|
.serial_queued: |
349 |
|
sti ; We already know we'll consume data |
350 |
|
xchg bx,ax |
351 |
|
push ds |
352 |
|
mov ax,aux_seg + (aux.serial >> 4) |
353 |
|
mov ds,ax |
354 |
|
mov al,[bx] |
355 |
|
pop ds |
356 |
|
inc bx |
357 |
|
and bx,serial_buf_size-1 |
358 |
|
mov [SerialTail],bx |
359 |
|
jmp .done |
360 |
|
|
361 |
.kbd: mov ah,10h ; Get keyboard input |
.kbd: mov ah,10h ; Get keyboard input |
362 |
int 16h |
int 16h |
363 |
cmp al,0E0h |
cmp al,0E0h |
368 |
jz .func_key |
jz .func_key |
369 |
mov bx,KbdMap ; Convert character sets |
mov bx,KbdMap ; Convert character sets |
370 |
xlatb |
xlatb |
371 |
.func_key: ret |
.func_key: |
372 |
|
.done: |
373 |
|
jmp reset_idle ; Character received |
374 |
|
|
375 |
%ifdef DEBUG_TRACERS |
%ifdef DEBUG_TRACERS |
376 |
; |
; |
389 |
%endif ; DEBUG_TRACERS |
%endif ; DEBUG_TRACERS |
390 |
|
|
391 |
section .data |
section .data |
392 |
|
%if IS_ISOLINUX == 0 ; Defined elsewhere for ISOLINUX |
393 |
|
crlf_msg db CR, LF |
394 |
|
null_msg db 0 |
395 |
|
%endif |
396 |
|
crff_msg db CR, FF, 0 |
397 |
|
|
398 |
|
section .config |
399 |
; This is a word to pc_setint16 can set it |
; This is a word to pc_setint16 can set it |
400 |
DisplayCon dw 01h ; Console display enabled |
DisplayCon dw 01h ; Console display enabled |
401 |
|
|
411 |
VidCols resb 1 ; Columns on screen-1 |
VidCols resb 1 ; Columns on screen-1 |
412 |
VidRows resb 1 ; Rows on screen-1 |
VidRows resb 1 ; Rows on screen-1 |
413 |
|
|
414 |
; Serial console stuff... |
; Serial console stuff; don't put this in .config becasue we don't want |
415 |
BaudDivisor resw 1 ; Baud rate divisor |
; loading a new config file to undo this setting. |
416 |
|
section .data |
417 |
|
alignz 4 |
418 |
|
SerialPort dw 0 ; Serial port base (or 0 for no serial port) |
419 |
|
BaudDivisor dw 115200/9600 ; Baud rate divisor |
420 |
FlowControl equ $ |
FlowControl equ $ |
421 |
FlowOutput resb 1 ; Outputs to assert for serial flow |
FlowOutput db 0 ; Outputs to assert for serial flow |
422 |
FlowInput resb 1 ; Input bits for serial flow |
FlowInput db 0 ; Input bits for serial flow |
423 |
FlowIgnore resb 1 ; Ignore input unless these bits set |
FlowIgnore db 0 ; Ignore input unless these bits set |
424 |
|
FlowDummy db 0 ; Unused |
425 |
|
|
426 |
|
section .bss |
427 |
TextAttribute resb 1 ; Text attribute for message file |
TextAttribute resb 1 ; Text attribute for message file |
428 |
DisplayMask resb 1 ; Display modes mask |
DisplayMask resb 1 ; Display modes mask |
429 |
|
|
430 |
|
%include "serirq.inc" |