home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CPROG
/
CEXPRESS.ZIP
/
SCREEN.ASM
/
WRAPLNB.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-03
|
6KB
|
191 lines
;void wrapln_b(strg,col,row,left,right,color);
; unsigned char *strg,*col,*row,left,right,color;
EXTRN _memory_model:byte
EXTRN _video_page:byte
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _wrapln_b
_wrapln_b proc near
cld ;direction flag forward
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 ;save Turbo's DS
jmp short start ;jump over local data
strg dd ? ;
row dd ? ;
col dd ? ;
start: mov bh,_video_page ;set the video page
cmp _memory_model,2 ;data near or far?
jb A0 ;jump if near
lds si,dword ptr[bp+4] ;point DS:SI to Strg
mov word ptr cs:strg,si
mov word ptr cs:strg+2,ds
lds si,dword ptr[bp+8] ;point DS:SI to Col
mov word ptr cs:col,si
mov word ptr cs:col+2,ds
lds si,dword ptr[bp+12];point DS:SI to Row
mov word ptr cs:row,si
mov word ptr cs:row+2,ds
add bp,6 ;additional offset since dword ptrs
jmp short A00 ;
A0: mov si,[bp+4] ;Strg
mov word ptr cs:strg,si
mov word ptr cs:strg+2,ds
mov si,[bp+6] ;Col
mov word ptr cs:col,si
mov word ptr cs:col+2,ds
mov si,[bp+8] ;Row
mov word ptr cs:row,si
mov word ptr cs:row+2,ds
A00: mov bl,[bp+14] ;set the attribute
mov dh,[si] ;row in DH
dec dh ;count from 0
cmp dh,24 ;in range?
jna B1 ;jump ahead if not
A1: jmp P1 ;quit routine
B1: lds si,cs:dword ptr col ;point DS:SI to Col
mov dl,[si] ;col in DL
dec dl ;count from 0
cmp dl,79 ;in range?
ja A1 ;quit if not
mov ch,[bp+10] ;Left border col to CH
dec ch ;count from 0
cmp ch,79 ;in range?
ja A1 ;quit if not
mov cl,[bp+12] ;Right border col to CL
dec cl ;count from 0
cmp cl,79 ;in range?
ja A1 ;quit if not
cmp cl,ch ;margins OK?
jbe A1 ;quit routine if not
cmp dl,cl ;wrapcol left of margin?
ja A1 ;quit if not
cmp dl,ch ;wrapcol right of margin?
jb A1 ;quit if not
lds si,cs:dword ptr strg ;point DS:SI to strg
sub ax,ax ;clear AX
push si ;figure string length
B2: cmp byte ptr[si],0 ;end of string?
je B3 ;
inc ax ;inc counter
inc si ;inc strg ptr
jmp short B2 ;
B3: pop si ;
or ax,ax ;test for null
jz A1 ;quit if null
add ax,si ;AX=SI at last char
mov di,ax ;keep stop point in DI
push si ;save string ptr
push dx ;save cursor position
C1: lodsb ;get a char
cmp al,32 ;a space?
jne F1 ;skip ahead if not
add sp,4 ;balance stack
push si ;save new string ptr
push dx ;save cursor position
cmp dl,ch ;start of row?
jne F1 ;jmp ahead if not
inc si ;inc SI for test
cmp si,di ;cmp to EOL value
jg D1 ;skip if end of string
dec si ;readjust SI
cmp [si],al ;next char a space?
jne E1 ;jump ahead if not
cmp [si+1],al ;next char a space?
jne E1 ;jump ahead if not
jmp short F1 ;else write initial spcs
D1: dec si ;readjust SI
E1: cmp si,di ;end of string?
jnae C1 ;continue if not
dec dl ;adjust column position
jmp L1 ;go to exit code
F1: push ax ;save char in AL
mov ah,2 ;func to set cursor
int 10h ;set the cursor
pop ax ;restore character
push cx ;save margin positions
mov ah,9 ;func to write char
mov cx,1 ;number chars to write
int 10h ;write it
pop cx ;restore margin positions
cmp si,di ;end of string yet?
je L1 ;jump ahead if so
cmp dl,cl ;right margin?
je G1 ;jump ahead if so
inc dl ;forward Col
jmp C1 ;go do next char
G1: mov al,32 ;clear EOL with spc char
cmp [si-1],al ;current char a space?
je K1 ;suitable end of line
cmp [si],al ;is next char a space?
je K1 ;suitable end of line
pop ax ;get prior cursor pos
cmp al,ch ;no spc in line?
jne H1 ;jump if not the case
add sp,2 ;balance stack
jmp short J1 ;jump, don't backtrack
H1: pop si ;prior string position
mov dl,al ;prior cursor col
push ax ;function changes AL
mov ah,2 ;func to set cursor
int 10h ;reset the cursor
pop ax ;restore AL
mov ah,cl ;right margin pos
sub ah,al ;minus current pos
push cx ;save margin positions
sub cx,cx ;clear cx
mov cl,ah ;number chars to write
inc cx ;plus one
jcxz I1 ;jump if none
mov ah,9 ;func to write chars
mov al,32 ;write space chars
int 10h ;clear to eol
I1: pop cx ;restore margin pos
J1: inc dh ;forward to next row
cmp dh,25 ;off screen?
je M1 ;jump if so
mov dl,ch ;leftmost column
push si ;save string ptr
push dx ;save cursor position
jmp C1 ;continue
K1: inc dh ;point to next row
mov dl,ch ;back to left margin
cmp dh,24 ;off screen?
ja L1 ;quit if so
add sp,4 ;take values off stack
push si ;save string position
push dx ;save cursor position
jmp C1 ;go do next char
L1: add sp,4 ;balance stack
M1: cmp dl,cl ;ending on right margin?
jne N1 ;jump ahead if not
inc dh ;forward to next row
mov dl,ch ;new Col at left margin
jmp short O1 ;jump ahead
N1: inc dl ;adjust column position
O1: inc dh ;count rows from 1
inc dl ;count cols from 1
lds si,cs:dword ptr row ;point DS:SI to row
mov [si],dh ;save new row position
lds si,cs:dword ptr col ;point DS:SI to col
mov [si],dl ;save new col position
P1: pop ds ;
pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_wrapln_b endp
_TEXT ENDS
END