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

 
Output of file : WRAPLINE.ASM contained in archive : CEXPRESS.ZIP
;void wrap_line(input_strg,return_string,remainder,line_len)
; char *input_strg,*return_string,*remainder;
; int line_len;

EXTRN _memory_model:byte
EXTRN _remainder:byte

_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _wrap_line
_wrap_line proc near
push bp ;
mov bp,sp ;
push di ;
push si ;
push ds ;
cmp _memory_model,0 ;near or far?
jle begin ;jump if near
inc bp ;else add 2 to BP
inc bp ;
begin: jmp short Z1 ;jump over data
remainder_seg dw ?
remainder_ofs dw ?
return_seg dw ?
return_ofs dw ?
Z1: cmp _memory_model,2 ;data near or far?
jb Y1 ;jump if near
les di,dword ptr[bp+8] ;ES:DI pts to return string
lds bx,dword ptr[bp+12] ;point DS:BX to remainder
mov cs:remainder_seg,ds ;save for later
mov cs:remainder_ofs,bx ;
mov byte ptr ds:[bx],0 ;return null in remainder if error
lds si,dword ptr[bp+4] ;point DS:SI to Strg
mov ax,[bp+16] ;line_len value to AX
jmp short X1 ;jump ahead
Y1: mov ax,ds ;NEAR case
mov es,ax ;
mov di,[bp+6] ;
mov bx,[bp+8] ;
mov cs:remainder_seg,ds ;save for later
mov cs:remainder_ofs,bx ;
mov byte ptr ds:[bx],0 ;return null in remainder if error
mov si,[bp+4] ;
mov ax,[bp+10] ;
X1: mov byte ptr es:[di],0 ;return null in return_strg if error
mov cs:return_seg,es ;keep address for later
mov cs:return_ofs,di ;
or ax,ax ;test for null line_length
jz U1 ;quit if null
push si ;get length of input string
sub cx,cx ;clear CX
W1: cmp byte ptr[si],0 ;
je V1 ;
inc cx ;
inc si ;
jmp short W1 ;
V1: pop si ;
dec si ;
or cx,cx ;test if null input
jnz A1 ;
U1: jmp O1 ;quit if null
A1: cmp byte ptr[si+1],32 ;nxt char a space?
jne C1 ;jump ahead if not
cmp byte ptr[si+3],32 ;3rd char a space?
jne B1 ;jump ahead if not
cmp byte ptr[si+2],32 ;2nd char a space?
je C1 ;don't del spcs if so
B1: dec cl ;dec string len ctr
inc si ;forward si to eliminate char
jmp short A1 ;go check for another spc
C1: mov dx,cx ;copy strg len to DX
sub bx,bx ;use BX as ptr to Strg
D1: inc bx ;forward string pointer
cmp byte ptr[si][bx],128 ;low end of codes
jb E1 ;jump if not ctrl code
cmp byte ptr[si][bx],159 ;high end of codes
ja E1 ;jump if not ctrl code
dec dx ;dec string length ctr
E1: loop D1 ;go count next char
push bx ;save pointer
cmp dx,ax ;cmp strg len to linelen
ja F1 ;jump ahead if longer
pop cx ;balance stack for jmp
mov cx,bx ;mov string len to CX
jmp short M1 ;go set string for return
F1: mov cx,ax ;linelen to CX
sub ax,ax ;AX holds spc positions
inc cx ;count one further
sub bx,bx ;pt SI to start of strg
G1: inc bx ;forward string pointer
cmp byte ptr[bx][si],128 ;low end of codes
jb H1 ;jump ahead if below
cmp byte ptr[bx][si],159 ;high end of codes
ja H1 ;jump ahead if above
jmp short G1 ;else don't count it
H1: cmp byte ptr[bx][si],32 ;spc char?
jne I1 ;jump ahead if not
mov ax,bx ;else save spc position
I1: loop G1 ;go do next char in strg
cmp ax,0 ;no spaces at all?
je J1 ;jump ahead if so
mov bx,ax ;point SI to last spc
jmp short K1 ;jump ahead
J1: mov ax,bx ;set string pointer
dec bx ;set back 1
K1: pop cx ;string length to CX
sub cx,bx ;remainder length
push ax ;point ES:DI to remainder
mov ax,cs:remainder_seg ;point to remainder
mov es,ax ;
mov di,cs:remainder_ofs ;
pop ax ;
dec di ;adjust for loop below
inc bx ;forward Strg ptr
L1: inc di ;forward remainder ptr
mov dl,[bx][si] ;get char from end of Strg
mov es:[di],dl ;place in remainder
inc bx ;forward string ptr
loop L1 ;go get next char
mov byte ptr es:[di+1],0 ;set terminator
mov cx,ax ;return string length
dec cx ;adjust
M1: sub bx,bx ;clear string pointer
mov ax,cs:return_seg ;point ES:DI back to return string
mov es,ax ;
mov di,cs:return_ofs ;
N1: inc bx ;forward string ptr
mov dl,[bx][si] ;get char from string
mov es:[di],dl ;write a char
inc di ;forward return strg ptr
loop N1 ;go do next char
mov byte ptr es:[di],0 ;set terminating null
O1: pop ds ;
pop si ;
pop di ;
pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_wrap_line endp
_TEXT ENDS
END


  3 Responses to “Category : C Source Code
Archive   : CEXPRESS.ZIP
Filename : WRAPLINE.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/