home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
SCREEN.ASM
/
WRTELN.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
4KB
|
136 lines
;void wrteln(strg);
; unsigned char *strg;
EXTRN _memory_model:byte
EXTRN _video_buffer:word
EXTRN _video_page:byte
EXTRN _snow_protect:byte
EXTRN _color:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _wrteln
_wrteln proc near
jmp short start ;
clr db ? ;
pg db ? ;
snow db ? ;
start: 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 ;
cld ;direction flag forward
mov ax,_video_buffer ;get video buffer address
mov es,ax ;place in ES
mov al,_color ;get Color value
mov ah,_snow_protect ;get _snow_protect
mov bh,_video_page ;set the cursor page
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 cs:clr,al ;save _color
mov cs:snow,ah ;save _snow_protect
mov cs:pg,bh ;save _video_page
mov ah,3 ;BIOS func for cursor pos
int 10h ;now DH-DL holds row-col
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
mov ax,160 ;cursor pos: bytes in 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,3840 ;scrl if won't fit row 24
sub bx,di ;space left
mov ax,cx ;chars to be printed
shl ax,1 ;double for attributes
or cx,cx ;test for null string
jnz L1 ;jump if not null
cmp di,3840 ;last row?
jnge L1 ;jump if not
mov al,1 ;scroll if null on Row 25
jmp short L2 ;jump ahead
L1: cmp bx,ax ;enough room?
jge L4 ;jump ahead if so
sub ax,bx ;amount space required
mov bl,160 ;bytes in a row
div bl ;divide
cmp ah,0 ;any remainder?
je L2 ;if not, jump ahead
inc al ;else, scroll 1 more line
L2: push cx ;save string length
push bp ;scrolling changes BP
push ax ;save num lines scrolled
mov bh,7 ;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
L3: sub di,160 ;screen ptr back 1 line
loop L3 ;repeat for ea ln of scrl
pop bp ;restore BP
pop cx ;restore string length
L4: or cx,cx ;test for null string
jnz L5 ;jump if not null
add di,160 ;increase screen ptr
jmp L9 ;jump and set cursor
L5: mov ah,cs:clr ;get attribute
lodsb ;get a character
cmp cs:snow,0 ;protect against snow?
je L8 ;jump ahead if not
mov dx,3dah ;status byte address
mov bx,ax ;save char-attri in BX
L6: in al,dx ;get status byte
test al,1 ;test bit
jnz L6 ;loop till 0
cli ;disable interrupts
L7: in al,dx ;get status byte
test al,1 ;test bit
jz L7 ;loop till 1
mov ax,bx ;char-attri back to AX
L8: stosw ;write it with attribute
loop L5 ;go do next
sti ;reenable interrupts
L9: 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 dh,al ;BIOS: row in DH
mov dl,ah ;col in DL
cmp dl,0 ;already at new line?
je L10 ;if so, jump ahead
inc dh ;else add 1 more line
mov dl,0 ;set cursor to col 0
L10: mov bh,cs:pg ;video page number
mov ah,2 ;function number
int 10h ;set the cursor
pop ds ;
pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_wrteln endp
_TEXT ENDS
END