Article View: comp.lang.asm.x86
Article #114Re: Thick
From: Jesus Reina Carvajal
Date: Thu, 11 Mar 1999 00:00
Date: Thu, 11 Mar 1999 00:00
267 lines
6808 bytes
6808 bytes
This is a multi-part message in MIME format.
--------------43B02FC7BBB9CDD4A8EFA626
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi assembler users,
Assembler is power! Borland's compilers are fantastic!
Here I attached a program that clears the screen in text mode.
It can be used without parameters to clear screen through INT 10h or
with parameter /M or /m clearing the screen using direct access to video
memory. Last method is much faster.
CLRSCR.ASM should be compiled and linked with Borland Turbo Assembler.
tasm /ml clrscr.asm
tlink clrscr.obj /t
/t - gernerate .COM file
The function 0Ah of INT 21h is called "Buffered Keyboard Input" and is used
as follows:
AH = 0A
DS:DX = pointer to input buffer of the format:
max | count | BUFFER (N bytes)
BUFFER is the input buffer
count is the number of characters returned (byte)
max is the maximum number of characters to read (byte)
returns nothing
- since strings can be pre-loaded, it is recommended that the
default string be terminated with a CR
- N bytes of data are read from STDIN into buffer+2
- max buffer size is 255, minimum buffer size is 1 byte
- chars up to and including a CR are placed into the buffer
beginning at byte 2; Byte 1 returns the number of chars
placed into the buffer (extended codes take 2 characters)
- DOS editing keys are active during this call
- INT 23 is called if Ctrl-Break or Ctrl-C detected
Best wishes,
Jesus
tunney wrote:
> I know that this is a thick question, but could someone explain to me
> how to clear the screen in text and video mode, can't for the life of me
> figure out how. Please help me I have an exam in this soon.
> Also could someone explain int 21h service 0Ah
>
> Thanks a million.
--------------43B02FC7BBB9CDD4A8EFA626
Content-Type: text/plain; charset=us-ascii; name="clrscr.ASM"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="clrscr.ASM"
.model TINY
.code
org 100h
;----------------- Program Entry point --------------------------
Entry:
jmp Init ; go to initialization
;--- switch stack and set memory allocation
useMem db 0
include video.inc
Start:
call videoInit
or al, al ; use memory? (AX is preserved in videoInt)
jne Use_Mem
mov bh, 07h ; gray chars on black background
xor ax, ax
mov cx, ax ; upper row and column (0,0)
mov dl, video_Cols
mov dh, video_Rows
call videoCpag
jmp Finish
Use_Mem:
call clearScrMem
Finish:
mov ah, 4Ch
int 21h
Init:
xor ax, ax
mov si, 80h ; command tail
lodsb ; get the length
or al, al ; check if none
jz Init_X
mov cl, al
sub ch, ch ; put count in cx
;--- loop through characters in command tail
Init_C:
lodsb ; load next byte
cmp al, '/' ; check if switch
je Init_F ; jump if so
Init_L:
loop Init_C ; otherwise loop back
Init_X:
jmp Start
;--- found slash
Init_F:
dec cx ; reduce count
jz Init_X ; jump if no more bytes
lodsb ; load command character
sub al, 'a'-'A' ; convert to upper-case
cmp al, 'M' ; check if M
jne Init_N
inc ah
Init_N:
xchg al, ah
jmp Start
mov ax, 4cffh ; exit function
int 21h ; execute
END Entry
--------------43B02FC7BBB9CDD4A8EFA626
Content-Type: text/plain; charset=us-ascii; name="video.inc"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="video.inc"
video_Mode db ? ; present mode
video_Page db ? ; active page
video_Seg dw 0B800h ; video segment (for direct memory access), color by default
video_Cols db ? ; screen columns
video_Rows db ? ; screen rows
video_Size dw ? ; video page size in bytes
MONO equ 7 ; monochrome video mode
videoInt proc near
push di
push si
push bp
int 10h ; call video
pop bp
pop si
pop di
ret
endp ; videoInt
videoInit proc near
push es
push ax
push bx
mov ah, 0Fh ; function
call videoInt ; interrupt 10H
mov video_Mode, al ; save mode
dec ah ; screen columns 0-79, not in 1-80 format
mov video_Cols, ah ; save columns
mov video_Page, bh ; save page
mov ax, 0040h
mov es, ax
mov ax, es:[004Ch] ; size of one video page in current mode (4096)
shr ax, 10
mov bx, 03E8h ; 1000
imul bx
mov video_Size, ax ; we get exact 4000
mov al, es:[0084h] ; rows on the screen -1 (0-24, not 1-25)
mov video_Rows, al
mov ax, video_Seg
cmp video_Mode, MONO
jne vInit_X
mov ax, 0B000h
mov video_Seg, ax
vInit_X:
pop bx
pop ax
pop es
ret
endp ; videoInit
;================================================
; Scroll a portion of the screen up.
;
; In: DH= upper left hand row; DL= upper left
; hand column; CH= lower left hand row; cl= lower
; left hand column; AL= lines to scroll (0 means
; clear instead of scroll); BL= attribute to use.
;=================================================
;
video_Spag proc near
push ax
mov ah, 6 ; function
call videoInt ; interrupt 10H
pop ax
ret
endp ; video_Spag
;================================================
; Clear a portion of the screen.
;
; In: DH= upper left hand row; DL= upper left
; hand column; CH= lower left hand row; cl= lower
; left hand column; BL= attribute to use.
;================================================
;
videoCpag proc near
push ax
sub al, al ; scroll lines zero (blank window)
call video_Spag ; clear screen
pop ax
ret
endp ; video_Cpag
clearScrMem proc near
mov ax, video_Seg
mov es, ax
xor di, di
mov cx, video_Size
shr cx, 1
mov ax, 0720h
rep stosw
ret
endp ; clearScrMem
--------------43B02FC7BBB9CDD4A8EFA626--
Technical Details
Message-ID:
<7c8ocb$ar1$14@winter.news.rcn.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7c6u0d$cue$1@winter.news.rcn.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: feaef,be6aba38dbcf8999 X-Google-Attributes: gidfeaef,public X-Google-Thread: f7d8d,be6aba38dbcf8999 X-Google-Attributes: gidf7d8d,public X-Google-Thread: 10bb54,be6aba38dbcf8999 X-Google-Attributes: gid10bb54,public X-Google-Thread: 114917,be6aba38dbcf8999 X-Google-Attributes: gid114917,public From: Jesus Reina Carvajal <jreina@sw.seisy.abb.se> Subject: Re: Thick Date: 1999/03/11 Message-ID: <7c8ocb$ar1$14@winter.news.rcn.net> X-Deja-AN: 453827916 Approved: <johnfine@erols.com> References: <7c6u0d$cue$1@winter.news.rcn.net> Content-Type: multipart/mixed; boundary="------------43B02FC7BBB9CDD4A8EFA626" X-Complaints-To: abuse@rcn.com X-Trace: GPjQJCrFOwfpkvbOD1LuhZs9X8idy6bErYzGoaFiVPc= Organization: ABB Automation Products Mime-Version: 1.0 NNTP-Posting-Date: 11 Mar 1999 15:44:11 GMT Newsgroups: comp.lang.asm.x86,borland.public.tasm,alt.lang.asm,alt.2600