unit usebios; {allows use of clrscr and gotoXY without messing up file redirection} {Author: Lin Jensen, Date : October 6, 1996 } interface const {your program can CHANGE these global variables} TextAttr : byte = $07; {black with white chars, used by ClrScr } PromptAttr : byte = $0E; {black with yellow chars - for PROMPTs} PressAttr : byte = $CE; {red with blinking yellow chars, for Press a Key message} procedure ClrScr; { clears the screen, stores page # and screen width} procedure gotoXY (x,y:integer); procedure WaitKeyPress; {writes "Press a key" and waits until } procedure Prompt (please:string); {write a 'prompt' suitable for user input, stays to screen even if output redirected, otherwise same as WRITE(please) } IMPLEMENTATION type char11 = array [0..10] of char; var screen_page : byte; screen_width: byte; const press : char11 = 'Press a key'; blank : char11 = ' '; procedure gotoXY (x,y:integer); begin ASM {GOTORC proc ;position cursor according to DH, DL} DEC X {Pascal from 1, bios from 0} DEC Y MOV AH, $02 { ;BIOS service "position cursor"} MOV BH, screen_page { ;page 0 or as set by clearscreen} MOV DH, BYTE PTR Y { ;row and column are passed by caller } MOV DL, BYTE PTR X INT $10 {;call BIOS video services} END; {asm} end;{gotoRC endp} procedure clrScr; { proc ;clear screen, store page and segment address} label done; begin {;Test video mode, change pageseg for colour if necessary} ASM MOV AH, $0F { ;read video mode } INT $10 { ;Call BIOS } mov Screen_page, bh { information enabling us to write directly} mov Screen_width,ah { ; to video memory} CMP AL,7 {AL is mode, is it monochrome?} JA DONE {probably graphics, do nothing } MOV AX, $0600 { CLEAR SCREEN function, all lines} MOV BH,TextAttr {black bkgd, white chars unless changed} MOV CX, 0 {;upper left } MOV DH,24 {;assume 25 lines } MOV DL,screen_width dec dl INT $10 { call BIOS video services} end; {asm} {; position cursor at upper left} GotoXY(1,1); done: END; {clearScreen endp} procedure WaitKeyPress; {writes "Press a key" and waits until } begin asm mov ah,03h {read cursor position} mov bh, screen_page int 10h mov ah, $13 {bios write string} mov al, $00 {dont move cursor} mov bl, PressAttr {blinking yellow on red} mov cx, 11 {length of string} push bp {es:bp holds full address of string} mov bp, ds mov es, bp mov bp, offset press int 10h {-------------------- wait for key _______} mov ah, $00 int $16 { -------------------- blank out message -} mov ah, $13 {bios write string} mov al, $00 {dont move cursor} mov bl, TextAttr {attribute back to normal} mov bp, offset blank int $10 pop bp end; end; procedure Prompt (please:string); {write a 'prompt' suitable for user input, stays to screen even if output redirected, otherwise same as WRITE(please) } begin asm mov ah,03h {read cursor position - to DX} mov bh, screen_page int 10h les si, [bp+6] {address of please from stack} mov cl, es:[si] {length byte} mov ch, 0 {pad cx} inc si {first char of string} mov ah, $13 {bios write string} mov al, $01 {do move cursor} mov bl, PromptAttr {yellow on black} push bp {es:bp holds full address of string} mov bp, si int 10h pop bp end; end; {prompt} begin screen_page := 0; {default page no. until ClrScr called} end.