Category : Files from Magazines
Archive   : CLM89DEC.ZIP
Filename : THIELEN.LST

 
Output of file : THIELEN.LST contained in archive : CLM89DEC.ZIP
LIST1.ASM
;*****************************************************************
;
; Function: x_scale_asm
;
; Author: David Thielen
; Date: 14 July 1987
;
; Revisions: None
;
; Description: Constants for creating self-writing
; bit-scale code.
;
; Dependance: 8086 family ONLY
;
;*****************************************************************
;

CODE2 segment byte public 'CODE'
assume cs:CODE2
public xs_strt_func_, xs_strt_func_len_
public xs_new_byte_, xs_new_byte_len_, xs_new_add_, xs_new_msk_
public xs_new2_byte_, xs_new2_byte_len_, xs_new2_msk_
public xs_next_byte_, xs_next_byte_len_, xs_next_msk_
public xs_old_byte_, xs_old_byte_len_, xs_old_msk_
public xs_store_word_, xs_store_word_len_
public xs_end_, xs_end_len_, xs_end_add_
public xs_end2_, xs_end2_len_, xs_end2_add1_, xs_end2_add2_
public xs_fin_func_, xs_fin_func_len_, xs_max_func_len_

dum proc far

xs_strt_func_ label dword
push si
push di
push bp
mov bp, sp
push ds
push es
mov si, [bp+10]
mov ax, [bp+12]
mov ds, ax
mov di, [bp+14]
mov ax, [bp+16]
mov es, ax
xor dx, dx
lodsw
mov bx, ax
xs_strt_func_len_ dw $ - xs_strt_func_


xs_new_byte_ label dword
add si, 0100h

xs_new2_byte_ label dword
lodsw
mov bx, ax
dum1:
and al, 0FFh
add al, 0FFh
rcl dx, 1
dum2:
xs_new_byte_len_ dw $ - xs_new_byte_
xs_new2_byte_len_ dw dum2 - xs_new2_byte_
xs_new_add_ dw 2
xs_new_msk_ dw dum1 - xs_new_byte_ + 1
xs_new2_msk_ dw dum1 - xs_new2_byte_ + 1


xs_next_byte_ label dword
mov bl, bh
xs_old_byte_ label dword
mov al, bl
dum3:
and al, 0FFh
add al, 0FFh
rcl dx, 1
dum4:
xs_old_byte_len_ dw $ - xs_old_byte_
xs_next_byte_len_ dw dum4 - xs_next_byte_
xs_old_msk_ dw dum3 - xs_old_byte_ + 1
xs_next_msk_ dw dum3 - xs_next_byte_ + 1

xs_store_word_ label dword
mov ax, dx
xchg al, ah
stosw
xs_store_word_len_ dw $ - xs_store_word_

xs_end_ label dword
mov cx, 0100h
mov dx, es:[di]
shr dx, cl
xs_end_len_ dw $ - xs_end_
xs_end_add_ dw 1

xs_end2_ label dword
mov cx, 0100h
shl dx, cl
mov ax, es:[di]
dum5:
and ax, 0FFFFh
or ax, dx
xchg al, ah
stosw
xs_end2_len_ dw $ - xs_end2_
xs_end2_add1_ dw 1
xs_end2_add2_ dw dum5 - xs_end2_ + 1

xs_fin_func_ label dword
pop es
pop ds
pop bp
pop di
pop si
ret
xs_fin_func_len_ dw $ - xs_fin_func_

xs_max_func_len_ dw $

dum endp
CODE2 ends
end


LIST2.C
#include "libgen.h"

/*****************************************************************

Function: bit_scale

Author: David Thielen
Date: 20 April 1987

Revisions: None

Description: Does a bit block scaling. src and dest
point to the byte holding the first bit.
*_bit is the first bit to be copied.
n_bits is the number of bits to copy per
line. *_jmp is the number of bytes to
the start of the next line (ie, jump from
the passed src, not src + n_bits).

Dependance: None

*****************************************************************/

flag bit_scale (src,dest,src_jmp,dest_jmp,src_bit,dest_bit,
src_n_bits,dest_n_bits,src_lines,dest_lines)
byte *src, *dest;
unsigned src_jmp, dest_jmp, src_bit, dest_bit, src_n_bits;
unsigned dest_n_bits, src_lines, dest_lines;
{
BITBLT src_bb, dest_bb;
flag rtn;

/* see if a block transfer */
if ((src_n_bits == dest_n_bits) && (src_lines == dest_lines))
return (bit_blt (src,dest,src_jmp,dest_jmp,src_bit,dest_bit,
src_n_bits,src_lines));

/* init 1 line part */
if (x_init_bit_scale (&src_bb,&dest_bb,src,dest,src_bit,dest_bit,
src_n_bits,dest_n_bits,src_lines,dest_lines,src_jmp,dest_jmp))
return (true);

/* do it */
rtn = x_bit_scale (&src_bb,&dest_bb);
free_ptr ((byte*)src_bb.fn);
free_ptr ((byte *)src_bb.bit_jmp);
return (rtn);
}


LIST3.C
#include "libgen.h"

/*****************************************************************

Function: x_add_func


Author: David Thielen
Date: 17 July 1987

Revisions: None

Description: used in x_init_* funcs

Dependance: None

*****************************************************************/

byte *x_add_func (add_ptr,func,num)
byte *add_ptr, *func;
unsigned num;
{

move (add_ptr,func,num);
return (func + num);
}


LIST4.C
#include "libgen.h"

/*****************************************************************

Function: x_bit_scale

Author: David Thielen
Date: 20 April 1987

Revisions: None

Description: Does a bit block scaling. src and dest
point to the byte holding the first bit.
*_bit is the first bit to be copied.
n_bits is the number of bits to copy per
line. *_jmp is the number of bytes to
the start of the next line (ie, jump from
the passed src, not src + n_bits).

Dependance: None

*****************************************************************/

flag x_bit_scale (src_bbp,dest_bbp)
BITBLTPTR src_bbp, dest_bbp;
{
unsigned n_lines;
int (*fn) ();

n_lines = dest_bbp->lines;
fn = src_bbp->fn;

while (n_lines--)
{
/* transfer the line */
#if COMPUTER == 1
(*(fn)) (src_bbp->buf,dest_bbp->buf);
#else
xc_scale (src_bbp,src_bbp->buf,dest_bbp->buf);
#endif

/* inc dest to next line */
dest_bbp->buf += dest_bbp->jmp;

/* inc src to next wanted line */
src_bbp->lines_mod += src_bbp->lines;
src_bbp->buf += src_bbp->jmp * udiv_mod (&(src_bbp->lines_mod),
src_bbp->lines_mod,dest_bbp->lines);
}

return (false);
}


LIST5.C
#include "libgen.h"

/*****************************************************************

Function: x_init_bit_scale

Author: David Thielen
Date: 20 April 1987

Revisions: None

Description: Sets up for a bit_scale. Pass in src, dest
*_bit, and n_bits. Pass back src, dest to
use, n_bytes, shift, and masks

Dependance: None

*****************************************************************/

extern byte xs_strt_func;
extern unsigned xs_strt_func_len;
extern byte xs_new_byte;
extern unsigned xs_new_byte_len;
extern unsigned xs_new_add;
extern byte xs_new_msk;
extern byte xs_next_byte;
extern unsigned xs_next_byte_len;
extern byte xs_old_byte;
extern unsigned xs_old_byte_len;
extern byte xs_old_msk, xs_next_msk;
extern byte xs_store_word;
extern unsigned xs_store_word_len;
extern byte xs_fin_func;
extern unsigned xs_fin_func_len;
extern unsigned xs_max_func_len;
extern byte xs_new2_byte, xs_new2_msk;
extern unsigned xs_new2_byte_len;
extern byte xs_end, xs_end_add;
extern unsigned xs_end_len;
extern byte xs_end2;
extern unsigned xs_end2_len, xs_end2_add1, xs_end2_add2;

byte *do_bits ();
byte *do_bgn ();
byte *do_end ();

flag x_init_bit_scale (src_bbp,dest_bbp,src,dest,src_bit,dest_bit,
src_n_bits,dest_n_bits,src_lines,dest_lines,src_jmp,dest_jmp)
BITBLTPTR src_bbp, dest_bbp;
byte *src, *dest;
unsigned src_bit, dest_bit, src_n_bits, dest_n_bits, src_lines;
unsigned dest_lines, src_jmp, dest_jmp;
{
unsigned n_words, byte_inc, num, strt_bits, fin_bits, xtra, n;
byte *func;
int32 dl;
byte bit_msk;
flag did_next;

/* check num lines, bits, etc */
/* check params */
if ((! src_n_bits) || (! dest_n_bits) || (! src_lines) || (! dest_lines))
return (true);

/* check params */
if ((! src_bbp) || (! dest_bbp) || (! src) || (! dest))
return (true);

/* assign passed in params */
fill_char ((byte*)src_bbp,sizeof(BITBLT),0);
fill_char ((byte*)dest_bbp,sizeof(BITBLT),0);
src_bbp->buf = src;
dest_bbp->buf = dest;
src_bbp->xblt = false;

/* get start, fin bits, num words */
xtra = 0;
num = dest_n_bits;
if (! dest_bit)
strt_bits = 0;
else
{
strt_bits = 16 - dest_bit;
if (strt_bits > num)
{
xtra = strt_bits - num;
strt_bits = num;
}
num -= strt_bits;
}
fin_bits = num & 0x0F;
n_words = num >> 4;

/* alloc func space - make sure there is enough room */
dl = (int32)xs_max_func_len + (int32)(2 + n_words) *
(int32)xs_store_word_len + (int32)dest_n_bits *
(int32)xs_new_byte_len;
if (dl > 32000L)
return (true);
src_bbp->fn = (int *) func = zalloc ((unsigned) dl);
if (! func)
return (true);

/* put in push si, di, bp, mov bp,sp, push ds, es */
func = x_add_func (&xs_strt_func,func,xs_strt_func_len);

/* init vars for scaling */
num = - src_n_bits;
byte_inc = 0;
bit_msk = (byte) (128 >> src_bit);
did_next = false;

/* do first partial */
if (strt_bits)
{
if (! xtra)
func = do_bgn (strt_bits,src_n_bits,dest_n_bits,func,
&did_next,&num,&byte_inc,&bit_msk);
else
{
n = (0xFFFF << xtra) & (0xFFFF >> dest_bit);
func = do_end (strt_bits,src_n_bits,dest_n_bits,func,
&did_next,&num,&byte_inc,&bit_msk,xtra,~n);
}
}

/* loop for each dest word */
while (n_words--)
func = do_bits (16,src_n_bits,dest_n_bits,func,
&did_next,&num,&byte_inc,&bit_msk);

/* do last partial */
if (fin_bits)
func = do_end (fin_bits,src_n_bits,dest_n_bits,func,
&did_next,&num,&byte_inc,&bit_msk,16-fin_bits,0xFFFF>>fin_bits);

/* put in pops, ret */
func = x_add_func (&xs_fin_func,func,xs_fin_func_len);

/* init multi line part */
src_bbp->jmp = src_jmp;
dest_bbp->jmp = dest_jmp;
src_bbp->lines = src_lines;
dest_bbp->lines = dest_lines;
src_bbp->n_bits = src_n_bits;
dest_bbp->n_bits = dest_n_bits;

return (false);
}

static byte *do_bits (n_bits,src_n_bits,dest_n_bits,func,
did_next,num,byte_inc,bit_msk)
unsigned n_bits, src_n_bits, dest_n_bits, *num, *byte_inc;
byte *func, *bit_msk;
flag *did_next;
{
unsigned full_bit_inc, n;
byte *df;

/* loop for each bit in the word */
while (n_bits--)
{
/* figure the increase */
*num += src_n_bits;
full_bit_inc = udiv_mod (num,*num,dest_n_bits);
*byte_inc += full_bit_inc >> 3;
full_bit_inc &= 7;

/* get the new mask - check for wrap */
while (full_bit_inc--)
{
*bit_msk >>= 1;
if (! *bit_msk)
{
*bit_msk = 128;
(*byte_inc)++;
}
}

/* write the code */
df = func;
if ((! *byte_inc) || ((*did_next) && (*byte_inc == 1)))
{
func = x_add_func (&xs_old_byte,func,xs_old_byte_len);
*(df + xs_old_msk) = *bit_msk;
}
else
if (*byte_inc == 1)
{
func = x_add_func (&xs_next_byte,func,xs_next_byte_len);
*(df + xs_next_msk) = *bit_msk;
*did_next = true;
}
else
{
n = *byte_inc - 2;
if (n)
{
func = x_add_func (&xs_new_byte,func,xs_new_byte_len);
*(df + xs_new_msk) = *bit_msk;
*((int*)(df + xs_new_add)) = n;
}
else
{
func = x_add_func (&xs_new2_byte,func,xs_new2_byte_len);
*(df + xs_new2_msk) = *bit_msk;
}
*byte_inc = 0;
*did_next = false;
}

} /* end while (n_bits--) */

/* store the word */
return (x_add_func (&xs_store_word,func,xs_store_word_len));
}

static byte *do_bgn (n_bits,src_n_bits,dest_n_bits,func,
did_next,num,byte_inc,bit_msk)
unsigned n_bits, src_n_bits, dest_n_bits, *num, *byte_inc;
byte *func, *bit_msk;
flag *did_next;
{
byte *df;

df = func;
func = x_add_func (&xs_end,func,xs_end_len);
*((int*)(df + xs_end_add)) = n_bits;
return (do_bits (n_bits,src_n_bits,dest_n_bits,func,
did_next,num,byte_inc,bit_msk));
}

static byte *do_end (n_bits,src_n_bits,dest_n_bits,func,
did_next,num,byte_inc,bit_msk,shft_val,and_val)
unsigned n_bits, src_n_bits, dest_n_bits, *num, *byte_inc;
byte *func, *bit_msk;
flag *did_next;
unsigned shft_val, and_val;
{
byte *df;

func = do_bits (n_bits,src_n_bits,dest_n_bits,func,
did_next,num,byte_inc,bit_msk);
df = func = func - xs_store_word_len;
func = x_add_func (&xs_end2,func,xs_end2_len);
*((int*)(df + xs_end2_add1)) = shft_val;
*((int*)(df + xs_end2_add2)) = and_val;
return (func);
}


  3 Responses to “Category : Files from Magazines
Archive   : CLM89DEC.ZIP
Filename : THIELEN.LST

  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/