This is not what I had in mind! I came across it looking for something else. It is from Jeff Duntemann - looks like it's half-converted from DOS to Linux. The comments are still mostly DOS. I don't know where I got it. It shows some of the vt100 escape sequences. The remaining DOS parts (int 10h) will not work! The 32-bit Linux parts (int 80h) will need work to convert to 64-bit... but should work as 32-bit code. It may serve as a partial answer to how to do clearscreen. I'm going to post it while I've got my finger on it, although it is not working code. Apologies to Jeff for posting stuff he obviously wasn't finished with.
; Source name : VIDLIB.ASM
; Compiled name : VIDLIB.OBJ
; Code model: : Real mode segmented model
; Version : 1.0
; Created date : 9/12/1999
; Last update : 9/12/1999
; Author : Jeff Duntemann
; Description : A simple example of a separately assembled module
; containing utility procedures for controlling the
; PC display. Assembled using NASM 0.98. DOS programs
; can link to these routines by declaring them EXTERN
; and then linking the program .OBJ to VIDLIB.OBJ using
; a linker like ALINK.
;----------------------------|
; BEGIN DATA SEGMENT |
;----------------------------|
SEGMENT .data
;Note that the following items are defined externally to this module, and
; for certain routines in this module to function these data items must
; be linked in from a properly assembled external module.
EXTERN CRLF,LRXY
;----------------------------|
; BEGIN CODE SEGMENT |
;----------------------------|
SEGMENT .text ; This segment may be accessed externally
; Note that the following items are GLOBAL, and may be accessed by
; external files that declare them EXTERN.
GLOBAL GotoXY,ClrScr,ClrWin,ScrlWin,VIDEO6
GLOBAL Write,Writeln
;---------------------------------------------------------------
; GOTOXY -- Positions the hardware cursor to X,Y
; Last update 9/12/99
;
; 1 entry point:
;
; GotoXY:
; Caller must pass:
; DL: X value These are both 0-based; i.e., they
; DH: Y value assume a screen 24 by 79, not 25 by 80
; Action: Moves the hardware cursor to the X,Y position
; loaded into DL and H.
;---------------------------------------------------------------
GotoXY:
sub esp, 16
mov edi, esp
mov byte [edi], 27 ; "ESC"
inc edi
mov byte [edi], '['
inc edi
mov al, dh
call al2dec
mov byte [edi], ';'
inc edi
mov al, dl
call al2dec
mov byte [edi], 'H'
inc edi
mov byte [edi], 0
mov edx, esp
call Write
add esp, 16
ret ; Return to the caller
al2dec:
xor ecx, ecx
mov bl, 10
.pushloop:
mov ah, 0
div bl
push eax
inc ecx
cmp al, 0
jnz .pushloop
.poploop:
pop eax
mov al, ah
add al, '0'
stosb
loop .poploop
ret
;---------------------------------------------------------------
; CLRSCR -- Clears or scrolls screens or windows
; Last update 9/12/99
;
; 4 entry points:
;
; ClrScr:
; No values expected from caller
; Action: Clears the entire screen to blanks with 07H as
; the display attribute
;
; ClrWin:
; Caller must pass:
; CH: Y coordinate, upper left corner of window
; CL: X coordinate, upper left corner of window
; DH: Y coordinate, lower right corner of window
; DL: X coordinate, lower right corner of window
; Action: Clears the window specified by the caller to
; blanks with 07H as the display attribute
;
; ScrlWin:
; Caller must pass:
; CH: Y coordinate, upper left corner of window
; CL: X coordinate, upper left corner of window
; DH: Y coordinate, lower right corner of window
; DL: X coordinate, lower right corner of window
; AL: number of lines to scroll window by (0 clears it)
; Action: Scrolls the window specified by the caller by
; the number of lines passed in AL. The blank
; lines inserted at screen bottom are cleared
; to blanks with 07H as the display attribute
;
; VIDEO6:
; Caller must pass:
; CH: Y coordinate, upper left corner of window
; CL: X coordinate, upper left corner of window
; DH: Y coordinate, lower right corner of window
; DL: X coordinate, lower right corner of window
; AL: number of lines to scroll window by (0 clears it)
; BH: display attribute for blanked lines (07H is "normal")
; Action: Generic access to BIOS VIDEO service 6. Caller
; must pass ALL register parameters as shown above
;---------------------------------------------------------------
ClrScr:
sub esp, 16
mov edi, esp
mov byte [edi], 27
inc edi
mov byte [edi], '['
inc edi
mov byte [edi], '2'
inc edi
mov byte [edi], 'J'
inc edi
mov byte [edi], 0
mov edx, esp
call Write
add esp, 16
ret
mov CX,0 ; Upper left corner of full screen
mov DX,word [LRXY] ; Load lower-right XY coordinates into DX
ClrWin: mov AL,0 ; 0 specifies clear entire region
ScrlWin: mov BH,07H ; Specify "normal" attribute for blanked line(s)
VIDEO6: mov AH,06H ; Select VIDEO service 6: Initialize/Scroll
int 10H ; Call VIDEO
ret ; Return to the caller
;---------------------------------------------------------------
; WRITE -- Displays information to the screen via DOS
; service 9: Print String
; Last update 9/12/99
;
; 1 entry point:
;
; Write:
; Caller must pass:
; DS: The segment of the string to be displayed
; DX: The offset of the string to be displayed
; String must be terminated by "$"
; Action: Displays the string at DS:DX up to the "$" marker
;---------------------------------------------------------------
Write:
mov ecx, edx
or edx, byte -1
.getlen:
inc edx
cmp byte [ecx + edx], 0
jnz .getlen
mov ebx, 1
mov eax, 4
int 80h
ret
;---------------------------------------------------------------
; WRITELN -- Displays information to the screen via DOS
; service 9 and issues a newline
; Last update 9/12/99
;
; 1 entry point:
;
; Writeln:
; Caller must pass:
; DS: The segment of the string to be displayed
; DX: The offset of the string to be displayed
; String must be terminated by "$"
; Action: Displays the string at DS:DX up to the "$" marker
; marker, then issues a newline. Hardware cursor
; will move to the left margin of the following
; line. If the display is to the bottom screen
; line, the screen will scroll.
; Calls: Write
;---------------------------------------------------------------
Writeln:
call Write ; Display the string proper through Write
mov eDX,CRLF ; Load address of newline string to DS:DX
call Write ; Display the newline string through Write
ret ; Return to the caller
Later,
Frank