Category : C Source Code
Archive   : CEXPRESS.ZIP
Filename : WRAPLN.ASM

 
Output of file : WRAPLN.ASM contained in archive : CEXPRESS.ZIP
;void wrapln(strg,col,row,left,right,color);
; unsigned char *strg,*col,*row,left,right,color;

EXTRN _memory_model:byte
EXTRN _video_buffer:word
EXTRN _snow_protect:byte

_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _wrapln
_wrapln 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: jmp short start ;jump over local data
strg dd ? ;
row dd ? ;
col dd ? ;
start: mov ax,_video_buffer ;get video address
mov es,ax ;move to ES
push ds ;DS changed for LODSB
cmp _memory_model,2 ;data near or far?
jb A1 ;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 B1 ;
A1: 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
B1: sub ax,ax ;
mov al,[si] ;place row in AX
dec ax ;count from 0
cmp ax,24 ;in range?
jna D1 ;jump ahead if not
C1: jmp Q1 ;quit routine
D1: mov dl,160 ;bytes in a row
mul dl ;times rows
mov cx,ax ;transfer offset to CX
lds si,cs:dword ptr col ;point DS:SI to Col
sub bx,bx ;
mov bl,[si] ;place in DI
mov di,bx ;
dec di ;count from 0
cmp di,79 ;in range?
ja C1 ;quit if not
shl di,1 ;double for attributes
add di,cx ;ES:DI pts to row,col
sub dx,dx ;
mov dl,[bp+10] ;Left border col to DX
sub bx,bx ;
mov bl,[bp+12] ;Right border col to BX
cmp bx,dx ;margins OK?
jbe C1 ;quit routine if not
dec dx ;count cols from 0
cmp dx,79 ;in range?
ja C1 ;quit if not
dec bx ;dec text
cmp bx,79 ;in range?
ja C1 ;quit if not
inc bx ;readjust
shl dx,1 ;double for attributes
shl bx,1 ;ditto
add dx,cx ;add row offset
add bx,cx ;ditto
cmp dx,di ;wrapcol rt of wrapleft?
ja C1 ;quit if not
cmp bx,di ;wrapcol left of wraprow?
jbe C1 ;quit if not
lds si,cs:dword ptr strg ;point DS:SI to Strg
sub cx,cx ;get string length
push si ;
E1: cmp byte ptr[si],0 ;end of string?
je F1 ;
inc cx ;inc counter
inc si ;inc strg ptr
jmp short E1 ;
F1: pop si ;
jcxz C1 ;quit if null
add cx,si ;CX=SI at last char
push si ;save string ptr
push di ;save screen ptr
mov ah,[bp+14] ;get color
G1: lodsb ;get a char
cmp al,32 ;a space?
jne J1 ;skip ahead if not
add sp,4 ;balance stack
push si ;save new string ptr
push di ;save new screen ptr
cmp di,dx ;start of row?
jne J1 ;jmp ahead if not
inc si ;inc SI for test
cmp si,cx ;cmp to EOL value
jg H1 ;skip if end of string
dec si ;readjust SI
cmp [si],al ;next char a space?
jne I1 ;jump ahead if not
cmp [si+1],al ;next char a space?
jne I1 ;jump ahead if not
jmp short J1 ;else write initial spcs
H1: dec si ;readjust SI
I1: cmp si,cx ;end of string?
jae N1 ;jump out of loop if so
jmp short G1 ;else delete initial spc
J1: call Writeit ;write a character
cmp si,cx ;end of string yet?
je N1 ;jump ahead if so
cmp di,bx ;right margin?
jne G1 ;if not, go do next char
mov al,32 ;clear EOL with spc char
cmp [si-1],al ;current char a space?
je M1 ;suitable end of line
cmp [si],al ;is next char a space?
je M1 ;suitable end of line
pop di ;scrn pos of prior space
cmp di,dx ;right col yet?
jne K1 ;jump is not
push di ;else save screen ptr
jmp short M1 ;go adjust for next line
K1: pop si ;string pos of prior space

push si ;save string ptr
push di ;save screen ptr
L1: mov al,32 ;write spc to end of line
call Writeit ;write a character
cmp di,bx ;end of line?
jne L1 ;write another spc if not
M1: add dx,160 ;left margin to next row
add bx,160 ;right margin to next row
cmp bx,4000 ;off screen?
ja N1 ;quit if so
pop di ;restore prior screen ptr
mov di,dx ;scrn ptr to left margin
push di ;save the position
jmp short G1 ;go do next char
N1: add sp,4 ;balance stack
sti ;reenable interrupts
cmp di,bx ;ending on right margin?
jne O1 ;jump ahead if not
mov ax,dx ;left margin value to AX
add ax,160 ;point 1 row below
jmp short P1 ;use value to set row-col
O1: mov ax,di ;screen pointer to AX
P1: shr ax,1 ;minus attri byte count
mov dl,80 ;columns in a row
div dl ;divide
sub bx,bx ;clear BX
mov bl,ah ;remainder in BX
sub ah,ah ;quotient in AX
inc ax ;count rows from 1
inc bx ;count cols from 1
mov dx,ax ;free AX
lds si,cs:dword ptr row ;point DS:SI to Row
mov [si],dl ;save new row position
lds si,cs:dword ptr col ;point DS:SI to Col
mov [si],bl ;save new col position
Q1: pop ds ;
pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_wrapln endp
Writeit PROC
push dx ;--------PROCEDURE BEGINS
push bx ;save DX and BX
mov dx,es ;get video buffer address
cmp dx,0b800h ;test for graphics card
jb T1 ;jump if not graphics
mov dx,3dah ;status byte address
mov bx,ax ;save char-attri in BX
R1: in al,dx ;get status byte
test al,1 ;test bit
jnz R1 ;loop till 0
cli ;disable interrupts
S1: in al,dx ;get status byte
test al,1 ;test bit
jz S1 ;loop till 1
mov ax,bx ;return char-attri to AX
T1: stosw ;write the character
pop bx ;restore BX
pop dx ;restore DX and return
ret ;
Writeit endp
_TEXT ENDS
END


  3 Responses to “Category : C Source Code
Archive   : CEXPRESS.ZIP
Filename : WRAPLN.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/