home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
SCREEN.ASM
/
WRT.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
3KB
|
116 lines
;void wrt(strg,color);
; unsigned char *strg,color;
EXTRN _memory_model:byte
EXTRN _video_buffer:word
EXTRN _video_page:byte
EXTRN _snow_protect:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _wrt
_wrt proc near
push bp ;
mov bp,sp ;set stack frame
push di ;
push si ;
cmp _memory_model,0 ;near or far?
jle begin ;jump if near
inc bp ;else add 2 to BP
inc bp ;
begin: push ds ;DS changed
cld ;direction flag forward
mov ax,_video_buffer ;fetch _video_buffer
mov es,ax ;place in ES
mov bh,_video_page ;set the cursor page
mov bl,_snow_protect ;get _snow_protect
mov ah,3 ;BIOS func for cursor pos
int 10h ;now DH-DL holds row-col
cmp _memory_model,2 ;data near or far?
jb L0 ;jump if near
lds si,dword ptr[bp+4] ;DS:SI pts to Strg
inc bp ;add 2 to BP since dword ptr
inc bp ;
jmp short L00 ;
L0: mov si,[bp+4] ;near case
L00: mov [bp+4],bx ;save page number and snow_protect
sub cx,cx ;clear CX
push si ;keep initial pointer position
L000: cmp byte ptr[si],0 ;end of string?
je L0000 ;jump if so
inc si ;inc ptr
inc cx ;inc counter
jmp short L000 ;loop till end
L0000: pop si ;restore Ptr
jcxz L9 ;quit if null string
mov ax,160 ;byte per row
mul dh ;multiply by num rows
sub dh,dh ;now DX holds num cols
shl dx,1 ;double for attri bytes
add ax,dx ;cursor offset in buffer
mov di,ax ;now ES:DI pts to pos
mov bx,3998 ;scroll if won't fit...
sub bx,di ;space left
mov ax,cx ;chars to be printed
shl ax,1 ;double for attributes
cmp bx,ax ;enough room?
jge L3 ;jump ahead if so
sub ax,bx ;amount space required
mov bl,160 ;byte per row
div bl ;divide
cmp ah,0 ;any remainder?
je L1 ;if not, jump ahead
inc al ;else, scroll 1 more line
L1: push cx ;save string length
push bp ;scrolling changes BP
push ax ;save num lines scrolled
mov bh,[bp+6] ;attribute of new lines
mov cx,0000h ;top left row-col
mov dx,184Fh ;bottom right row-col
mov ah,6 ;upwards scroll function
int 10h ;make the scroll
pop cx ;num lines scrolled in CL
sub ch,ch ;clear CH, use CX counter
L2: sub di,160 ;screen ptr back 1 line
loop L2 ;repeat for ea ln of scrl
pop bp ;restore BP
pop cx ;restore string length
L3: mov ah,[bp+6] ;get attribute
L4: lodsb ;get a character
mov dx,es ;get video buffer address
cmp byte ptr[bp+4],0 ;protect against show?
je L7 ;jump ahead if not
mov dx,3dah ;status byte address
mov bx,ax ;save AX contents
L5: in al,dx ;get status byte
test al,1 ;test bit
jnz L5 ;loop till 0
cli ;disable interrupts
L6: in al,dx ;get status byte
test al,1 ;test bit
jz L6 ;loop till 1
mov ax,bx ;restore AX contents
L7: stosw ;write char and attri
loop L4 ;go do next char
L8: sti ;reenable interrupts
mov ax,di ;now set new cursor pos
mov dl,160 ;chars in a row
div dl ;divide scrn ptr
shr ah,1 ;div remainder by 2
mov dl,ah ;BIOS: col in DL
mov dh,al ;row in DH
mov bh,[bp+5] ;page number
mov ah,2 ;function number
int 10h ;set the cursor
L9: pop ds ;
pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_wrt endp
_TEXT ENDS
END