Index: lib700/aldiv.s
===================================================================
--- lib700/aldiv.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/aldiv.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,26 @@
+*
+* aldiv.s -- indirect long divide
+* Version 1 -- 1989-01-24 -- D.N. Lynx Crowe
+*
+	.text
+*
+	.xdef	aldiv
+	.xdef	_aldiv
+*
+	.xref	_ldiv
+*
+aldiv:
+_aldiv:
+*
+	link	a6,#-2
+	move.l	12(a6),-(a7)
+	movea.l	8(a6),a0
+	move.l	(a0),-(a7)
+	jsr	_ldiv
+	cmpm.l	(a7)+,(a7)+
+	movea.l	8(a6),a1
+	move.l	d0,(a1)
+	unlk	a6
+	rts
+*
+	.end
Index: lib700/almul.s
===================================================================
--- lib700/almul.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/almul.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,21 @@
+*
+* almul.s -- indirect long multiply
+* Version 1 -- 1989-01-24 -- D.N. Lynx Crowe
+*
+		.text
+*
+		.xdef	almul
+*
+		.xref	lmul
+*
+almul:		move.l	a5,-(a7)
+		movea.l	8(a7),a5
+		move.l	12(a7),-(a7)
+		move.l	(a5),-(a7)
+		jsr	lmul
+		addq.w	#8,a7
+		move.l	d0,(a5)
+		movea.l	(a7)+,a5
+		rts
+*
+		.end
Index: lib700/alrem.s
===================================================================
--- lib700/alrem.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/alrem.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,28 @@
+*
+* alrem.s -- indirect long modulus
+* Version 1 -- 1989-01-24 -- D.N. Lynx Crowe
+*
+		.text
+*
+		.xdef	alrem
+		.xdef	_alrem
+*
+		.xref	_ldiv
+		.xref	_ldivr
+*
+alrem:
+_alrem:
+*
+		link	a6,#-2
+		move.l	12(a6),-(a7)
+		movea.l	8(a6),a0
+		move.l	(a0),-(a7)
+		jsr	_ldiv
+		cmpm.l	(a7)+,(a7)+
+		move.l	_ldivr,d0
+		movea.l	8(a6),a1
+		move.l	d0,(a1)
+		unlk	a6
+		rts
+*
+		.end
Index: lib700/bitrev.c
===================================================================
--- lib700/bitrev.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/bitrev.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,38 @@
+/*
+   =============================================================================
+	bitrev.c -- bit reverse function
+	Version 1 -- 1987-03-24 -- D.N. Lynx Crowe
+   =============================================================================
+*/
+
+static int bitmask[] = {
+
+	0x0001, 0x0002, 0x0004, 0x0008,
+	0x0010, 0x0020, 0x0040, 0x0080,
+	0x0100, 0x0200, 0x0400, 0x0800,
+	0x1000, 0x2000, 0x4000, 0x8000
+};
+
+/*
+   =============================================================================
+	bitrev(bitsin, nbits) -- reverses the rightmost nbits of bitsin.
+
+	Any bits to the left of the reversed bits in the result will be zeros.
+   =============================================================================
+*/
+
+int
+bitrev(bitsin, nbits)
+int bitsin, nbits;
+{
+	int	m, n;
+
+	n = 0;
+
+	for (m = 0; m < nbits; m++)
+		if (bitsin & bitmask[m])
+			n |= bitmask[nbits-1-m];
+
+	return(n);
+}
+
Index: lib700/blkfill.s
===================================================================
--- lib700/blkfill.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/blkfill.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,36 @@
+* ------------------------------------------------------------------------------
+* blkfill.s -- block fill function
+* Version 1 -- 1987-08-28 -- D.N. Lynx Crowe
+*
+*	void
+*	blkfill(where, what, count)
+*	char *where;
+*	char what;
+*	short count;
+*
+*		Fills 'count' bytes at 'where' with 'what'.
+* ------------------------------------------------------------------------------
+		.text
+*
+		.xdef	_blkfill
+*
+_blkfill:	link	a6,#0
+		movem.l	d5-d7/a5-a5,-(a7)
+		movea.l	8(a6),a5
+		move.b	13(a6),d7
+		move.w	14(a6),d6
+		bra	blkf2
+*
+blkf1:		move.b	d7,(a5)+
+*
+blkf2:		move.w	d6,d0
+		subq.w	#1,d6
+		tst.w	d0
+		bgt	blkf1
+*
+		tst	(a7)+
+		movem.l	(a7)+,d6-d7/a5-a5
+		unlk	a6
+		rts
+*
+		.end
Index: lib700/blkmove.s
===================================================================
--- lib700/blkmove.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/blkmove.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,57 @@
+* ------------------------------------------------------------------------------
+* blkmove.s -- block move function
+* Version 1 -- 1987-08-28 -- D.N. Lynx Crowe
+*
+*	void
+*	blkmove(to, from, n)
+*	char *to, *from;
+*	short n;
+*
+*		Copies 'n' bytes from address 'from' to address 'to'.
+*		Treats overlaps of from and to areas intelligently.
+* ------------------------------------------------------------------------------
+		.text
+*
+		.xdef	_blkmove
+*
+_blkmove:	link	a6,#$FFFC
+		move.l	8(a6),d0
+		cmp.l	12(a6),d0
+		bcc	blkm3
+*
+		bra	blkm2
+*
+blkm1:		movea.l	8(a6),a0
+		movea.l	12(a6),a1
+		move.b	(a1),(a0)
+		addq.l	#1,8(a6)
+		addq.l	#1,12(a6)
+*
+blkm2:		move.w	16(a6),d0
+		subq.w	#1,16(a6)
+		tst.w	d0
+		bne	blkm1
+*
+		bra	blkm6
+*
+blkm3:		move.w	16(a6),d0
+		ext.l	d0
+		add.l	d0,8(a6)
+		add.l	d0,12(a6)
+		bra	blkm5
+*
+blkm4:		subq.l	#1,8(a6)
+		subq.l	#1,12(a6)
+		movea.l	8(a6),a0
+		movea.l	12(a6),a1
+		move.b	(a1),(a0)
+*
+blkm5:		move.w	16(a6),d0
+		subq.w	#1,16(a6)
+		tst.w	d0
+		bne	blkm4
+*
+blkm6:		unlk	a6
+		rts
+*
+		.end
Index: lib700/ctype.c
===================================================================
--- lib700/ctype.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/ctype.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,76 @@
+/*
+   ============================================================================
+	ctype.c -- extended character type table, ala' Unix(tm)
+	Version 8 -- 1987-06-16 -- D.N. Lynx Crowe
+
+	This character type table supports the extended ctype.h macros.
+	See the ctype.h header file for further notes.
+
+	WARNING:  SYS5CODE must be defined properly in ctype.h for the macros
+	to work with this table.
+   ============================================================================
+*/
+
+#define	_CTYPE_C
+
+#include "ctype.h"
+
+#define	_CS	_C|_S
+#define	_PS	_P|_S
+#define	_NX	_N|_X
+#define	_UX	_U|_X
+#define	_LX	_L|_X
+
+/* 
+
+*/
+
+#if	SYS5CODE
+char _ctype[] = {	/* this table handles EOF as a legal value */
+
+	/* -1   EOF */	 0,					/* -1 EOF */
+#else
+
+___atab() { return; }	/* dummy function to force the loader to see __atab */
+
+char __atab[] = {	/* EOF won't work properly with this table */
+#endif
+
+	/* Octal */						/* Hex */
+	/* 000..007 */	 _C, _C,  _C,  _C,  _C,  _C,  _C,  _C,	/* 00..07 */
+	/* 010..017 */	 _C, _CS, _CS, _CS, _CS, _CS, _C,  _C,	/* 08..0F */
+	/* 020..027 */	 _C, _C,  _C,  _C,  _C,  _C,  _C,  _C,	/* 10..17 */
+	/* 030..037 */	 _C, _C,  _C,  _C,  _C,  _C,  _C,  _C,	/* 18..1F */
+	/* 040..047 */	_PS, _P,  _P,  _P,  _P,  _P,  _P,  _P,	/* 20..27 */
+	/* 050..057 */	_P,  _P,  _P,  _P,  _P,  _P,  _P,  _P,	/* 28..2F */
+	/* 060..067 */	_NX, _NX, _NX, _NX, _NX, _NX, _NX, _NX,	/* 30..37 */
+	/* 070..077 */	_NX, _NX, _P,  _P,  _P,  _P,  _P,  _P,	/* 38..3F */ 
+
+	/* 100..107 */	_P,  _UX, _UX, _UX, _UX, _UX, _UX, _U,	/* 40..47 */
+	/* 110..117 */	_U,  _U,  _U,  _U,  _U,  _U,  _U,  _U,	/* 48..4F */
+	/* 120..127 */	_U,  _U,  _U,  _U,  _U,  _U,  _U,  _U,	/* 50..57 */
+	/* 130..137 */	_U,  _U,  _U,  _P,  _P,  _P,  _P,  _P,	/* 58..5F */
+	/* 140..147 */	_P,  _LX, _LX, _LX, _LX, _LX, _LX, _L,	/* 60..67 */
+	/* 150..157 */	_L,  _L,  _L,  _L,  _L,  _L,  _L,  _L,	/* 68..6F */
+	/* 160..167 */	_L,  _L,  _L,  _L,  _L,  _L,  _L,  _L,	/* 70..77 */
+	/* 170..177 */	_L,  _L,  _L,  _P,  _P,  _P,  _P,  _C,	/* 78..7F */
+
+	/* 200..207 */  _C,  _C,  _C,  _C,  _C,  _C,  _C,  _C,	/* 80..87 */
+	/* 210..217 */	_C,  _CS, _CS, _CS, _CS, _CS, _C,  _C,	/* 88..8F */
+	/* 220..227 */	_C,  _C,  _C,  _C,  _C,  _C,  _C,  _C,	/* 90..97 */
+	/* 230..237 */	_C,  _C,  _C,  _C,  _C,  _C,  _C,  _C,	/* 98..9F */
+	/* 240..247 */	_PS, _P,  _P,  _P,  _P,  _P,  _P,  _P,	/* A0..A7 */
+	/* 250..257 */	_P,  _P,  _P,  _P,  _P,  _P,  _P,  _P,	/* A8..AF */
+	/* 260..267 */	_NX, _NX, _NX, _NX, _NX, _NX, _NX, _NX,	/* B0..B7 */
+	/* 270..277 */	_NX, _NX, _P,  _P,  _P,  _P,  _P,  _P,	/* B8..BF */
+
+	/* 300..307 */	_P,  _UX, _UX, _UX, _UX, _UX, _UX, _U,	/* C0..C7 */
+	/* 310..317 */	_U,  _U,  _U,  _U,  _U,  _U,  _U,  _U,	/* C8..CF */
+	/* 320..327 */	_U,  _U,  _U,  _U,  _U,  _U,  _U,  _U,	/* D0..D7 */
+	/* 330..337 */	_U,  _U,  _U,  _P,  _P,  _P,  _P,  _P,	/* D8..DF */
+	/* 340..347 */	_P,  _LX, _LX, _LX, _LX, _LX, _LX, _L,	/* E0..E7 */
+	/* 350..357 */	_L,  _L,  _L,  _L,  _L,  _L,  _L,  _L,	/* E8..EF */
+	/* 360..367 */	_L,  _L,  _L,  _L,  _L,  _L,  _L,  _L,	/* F0..F7 */
+	/* 370..377 */	_L,  _L,  _L,  _P,  _P,  _P,  _P,  _C	/* F8..FF */
+};
+
Index: lib700/finalone.s
===================================================================
--- lib700/finalone.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/finalone.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,30 @@
+* ------------------------------------------------------------------------------
+* finalone.s -- the last stuff to get loaded
+* Version 4 -- 1987-06-30 -- D.N. Lynx Crowe
+*
+* This is so we can figure out where things got loaded.
+* ------------------------------------------------------------------------------
+*
+		.text
+*
+		.xdef	FinalOne
+		.xdef	The_Fini
+		.xdef	Text_End
+*
+*
+* This is the last piece of code in the 'text' segment.
+*
+FinalOne:	rts			* we just need the address here
+*
+Text_End:	rts			* we just need the address here
+*
+* ------------------------------------------------------------------------------
+*
+		.data
+		.even
+*
+The_Fini:	dc.w	$FFFF		* last thing in the 'data' segment
+*
+* ------------------------------------------------------------------------------
+*
+		.end
Index: lib700/ispow2.c
===================================================================
--- lib700/ispow2.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/ispow2.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,38 @@
+/*
+   =============================================================================
+	ispow2.c -- fast test to see if X is a power of 2
+	Version 2 -- 1989-01-24 -- D.N. Lynx Crowe
+
+	Returns:
+
+		TRUE if X is a power of 2,
+		FALSE otherwise.
+   =============================================================================
+*/
+
+#include "stddefs.h"
+
+short
+ispow2(x)
+register long x;
+{
+	register short i;
+	register long k;
+
+	k = 0x00000001L;		/* setup the bit mask in k */
+
+	for (i = 32; i--; ) {		/* check each bit in x ... */
+
+		if ((x & k) NE 0L) {	/* ... for the 1st 1 and ... */
+
+			if ((x & ~k) NE 0L)	/* ... if there are others ... */
+				return(FALSE);	/* ... it's not a power of 2 */
+			else			/* ... otherwise .. */
+				return(TRUE);	/* ... it is a power of 2 */
+		}
+
+		k = k << 1;		/* examine the next position */
+	}
+
+	return(FALSE);			/* no bits on isn't a power of 2 */
+}
Index: lib700/jumpto.s
===================================================================
--- lib700/jumpto.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/jumpto.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,63 @@
+* ------------------------------------------------------------------------------
+* jumpto.s -- miscellaneous ROMP support functions
+* Version 4 -- 1987-10-14 -- D.N. Lynx Crowe
+*
+*	WARNING:
+*	--------
+*		These functions, in general, assume supervisor mode and
+*		'sane' arguments, so no error checking is done.
+*
+*	halt()
+*
+*		Brings the processor to a grinding halt.  Requires external
+*		reset to restart things.  Use only for catastrophic hard halts.
+*
+*	jumpto(addr)
+*	long addr;
+*
+*		Jumps to 'addr'.  No error check is done on 'addr'.
+*
+*	rjumpto(addr)
+*	long addr;
+*
+*		Performs the 68000 'RESET' command, then jumps to 'addr'.
+*		No error check is made on 'addr'.
+*
+*	sjumpto(addr, stack)
+*	long addr, stack;
+*
+*		Sets a7 to 'stack', then jumps to 'addr'.
+*		No error check is done on 'addr'.
+*
+*	xreset()
+*
+*		Performs the 68000 'RESET' command.  This is very dangerous,
+*		and should be used with extreme care regarding such
+*		things as interrupts, device initialization, vectors,
+*		and sundry other reset-related things.
+*
+* ------------------------------------------------------------------------------
+		.text
+*
+		.xdef	_halt,_jumpto,_rjumpto,_sjumpto,_xreset
+*
+		.page
+*
+_halt:		stop	#$2700			* stop dead, interrupts disabled
+		jmp	_halt			* stay stopped if stepped thru
+*
+_jumpto:	movea.l	4(a7),a0		* get jump address
+		jmp	(a0)			* go to the jump address
+*
+_rjumpto:	reset				* reset external devices
+		movea.l	4(a7),a0		* get jump address
+		jmp	(a0)			* go to the jump address
+*
+_sjumpto:	movea.l	4(a7),a0		* get jump address
+		movea.l	8(a7),a7		* set stack pointer
+		jmp	(a0)			* go to the jump address
+*
+_xreset:	reset				* reset external devices
+		rts				* return to caller
+*
+		.end
Index: lib700/ldiv.s
===================================================================
--- lib700/ldiv.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/ldiv.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,101 @@
+* ------------------------------------------------------------------------------
+* ldiv.s -- long division
+* Version 1 -- 1988-01-22
+* ------------------------------------------------------------------------------
+		.text
+*
+		.xdef	_ldiv
+		.xdef	ldiv
+*
+		.xdef	_ldivr
+*
+ARG1		.equ	8
+ARG2		.equ	12
+*
+_ldiv:
+ldiv:		link	a6,#-2
+		movem.l	d2-d7,-(a7)
+		clr.w	d3
+		clr.l	d5
+		move.l	ARG1(a6),d7
+		move.l	ARG2(a6),d6
+		bne	ldiv1
+*
+		move.l	#$80000000,_ldivr
+		move.l	#$80000000,d0
+		divs	#0,d0
+		bra	ldiv11
+*
+ldiv1:		bge	ldiv2
+*
+		neg.l	d6
+		addq.w	#1,d3
+*
+ldiv2:		tst.l	d7
+		bge	ldiv3
+*
+		neg.l	d7
+		addq.w	#1,d3
+*
+ldiv3:		cmp.l	d7,d6
+		bgt	ldiv9
+*
+		bne	ldiv4
+*
+		moveq.l	#1,d5
+		clr.l	d7
+		bra	ldiv9
+*
+ldiv4:		cmp.l	#$10000,d7
+		bge	ldiv5
+*
+		divu	d6,d7
+		move.w	d7,d5
+		swap	d7
+		ext.l	d7
+		bra	ldiv9
+*
+ldiv5:		moveq.l	#1,d4
+*
+ldiv6:		cmp.l	d6,d7
+		bcs	ldiv7
+*
+		asl.l	#1,d6
+		asl.l	#1,d7
+		bra	ldiv6
+*
+ldiv7:		tst.l	d4
+		beq	ldiv9
+*
+		cmp.l	d6,d7
+		bcs	ldiv8
+*
+		or.l	d4,d5
+		sub.l	d6,d7
+*
+ldiv8:		lsr.l	#1,d4
+		lsr.l	#1,d6
+		bra	ldiv7
+*
+ldiv9:		cmp.w	#1,d3
+		bne	ldiv10
+*
+		neg.l	d7
+		move.l	d7,_ldivr
+		move.l	d5,d0
+		neg.l	d0
+		bra	ldiv11
+*
+ldiv10:		move.l	d7,_ldivr
+		move.l	d5,d0
+*
+ldiv11:		tst.l	(a7)+
+		movem.l	(a7)+,d3-d7
+		unlk	a6
+		rts
+*
+		.bss
+*
+_ldivr:		.ds.l	1
+*
+		.end
Index: lib700/lmul.s
===================================================================
--- lib700/lmul.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/lmul.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,47 @@
+* ------------------------------------------------------------------------------
+* lmul.s -- long multiply
+* Version 2 -- 1989-07-18
+* ------------------------------------------------------------------------------
+		.text
+*
+		.xdef	lmul
+*
+ARG1		.equ	8
+ARG2		.equ	12
+*
+TEMP		.equ	-4
+*
+lmul:		link	a6,#-4
+		clr.w	d2
+		tst.l	ARG1(a6)
+		bge	lmul1
+*
+		neg.l	ARG1(a6)
+		addq.w	#1,d2
+*
+lmul1:		tst.l	ARG2(a6)
+		bge	lmul2
+*
+		neg.l	ARG2(a6)
+		addq.w	#1,d2
+*
+lmul2:		move.w	ARG1+2(a6),d0
+		mulu	ARG2+2(a6),d0
+		move.l	d0,TEMP(a6)
+		move.w	ARG1(a6),d0
+		mulu	ARG2+2(a6),d0
+		move.w	ARG2(a6),d1
+		mulu	ARG1+2(a6),d1
+		add.w	d1,d0
+		add.w	TEMP(a6),d0
+		move.w	d0,TEMP(A6)
+		move.l	TEMP(a6),d0
+		btst	#0,d2
+		beq	lmul3
+*
+		neg.l	d0
+*
+lmul3:		unlk	a6
+		rts
+*
+		.end
Index: lib700/lrem.s
===================================================================
--- lib700/lrem.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/lrem.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,26 @@
+* ------------------------------------------------------------------------------
+* lrem.s -- long modulo
+* Version 1 -- 1988-01-22
+* ------------------------------------------------------------------------------
+		.text
+*
+		.xdef	_lrem
+		.xdef	lrem
+*
+		.xref	ldiv
+		.xref	_ldivr
+*
+ARG1		.equ	8
+ARG2		.equ	12
+*
+_lrem:
+lrem:		link	a6,#-2
+		move.l	ARG2(a6),-(a7)
+		move.l	ARG1(a6),-(a7)
+		jsr	ldiv
+		cmpm.l	(a7)+,(a7)+
+		move.l	_ldivr,d0
+		unlk	a6
+		rts
+*
+		.end
Index: lib700/mangle.c
===================================================================
--- lib700/mangle.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/mangle.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,44 @@
+/*
+   =============================================================================
+	mangle.c -- mangle a bit stream
+	Version 2 -- 1987-08-28 -- D.N. Lynx Crowe
+	(c) Copyright 1987 - D.N. Lynx Crowe
+   =============================================================================
+*/
+
+/*
+   =============================================================================
+	mangle(bitmap, nb, ib) -- reorder the 'nb' least significant bits
+	in 'ib' according to 'bitmap'.  Assumes that 'bitmap' is at least 'nb'
+	words long, and that nb <= 32.  The 'bitmap' translation table contains
+	an output word for each bit in the input word, with each 'bitmap' entry
+	corresponding to the bit number matching its index.  For example,
+	'bitmap[0]' contains the word which will be 'OR'ed into the output if
+	the least significant bit of the input word is set, while 'bitmap[31]'
+	corresponds to the most significant bit of the input word.
+   =============================================================================
+*/
+
+long
+mangle(bitmap, nb, ib)
+register long *bitmap;		/* bit map table pointer */
+register short nb;		/* number of least significant input bits */
+register long ib;		/* input data (in nb least significant bits) */
+{
+	register long	bm;			/* scan mask */
+	register long	rv;			/* result value */
+	register short	bn;			/* bit number (bitmap index) */
+
+	bm = 0x00000001L;			/* setup scan mask */
+	rv = 0x00000000L;			/* clear the output word */
+
+	for (bn = 0; bn < nb; bn++) {		/* scan across nb bits */
+
+		if (ib & bm)			/* if the input bit is 1 */
+			rv |= bitmap[bn];	/* 'OR' the bitmap into rv */
+
+		bm <<= 1;			/* shift the scan mask left */
+	}
+
+	return(rv);				/* return rv as the result */
+}
Index: lib700/micons.c
===================================================================
--- lib700/micons.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/micons.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,102 @@
+/*
+   =============================================================================
+	micons.c -- motorola / intel format conversion functions
+	Version 3 -- 1987-06-11 -- D.N. Lynx Crowe
+
+	short
+	micons(wi)
+	short wi;
+
+		Convert between motorola and intel format for a short.
+
+	int
+	miconi(wi)
+	int wi;
+
+		Convert between motorola and intel format for an int.
+
+	long
+	miconl(wi)
+	long wi;
+
+		Convert between motorola and intel format for a long.
+   =============================================================================
+*/
+
+#define	TESTER	0	/* define non-zero for a test program */
+
+/* 
+ */
+
+/*
+   =============================================================================
+	micons(wi) -- Convert between motorola and intel format for a short.
+   =============================================================================
+*/
+
+short
+micons(wi)
+short wi;
+{
+	return((short)( ((wi << 8) & 0xFF00) | ((wi >> 8) & 0x00FF) ) );
+}
+
+/*
+   =============================================================================
+	miconi(wi) -- Convert between motorola and intel format for an int.
+   =============================================================================
+*/
+
+int
+miconi(wi)
+int wi;
+{
+	if (sizeof (int) == 4)
+		return( ((wi << 24) & 0xFF000000L) | ((wi << 8) & 0x00FF0000L) |
+			((wi >> 8) & 0x0000FF00L) | ((wi >> 24) & 0x000000FFL) );
+	else
+		return(((wi << 8) & 0xFF00) | ((wi >> 8) & 0x00FF));
+}
+
+/*
+   =============================================================================
+	miconl(wi) -- Convert between motorola and intel format for a long.
+   =============================================================================
+*/
+
+long
+miconl(wi)
+long wi;
+{
+	return( ((wi << 24) & 0xFF000000L) | ((wi << 8) & 0x00FF0000L) |
+		((wi >> 8) & 0x0000FF00L) | ((wi >> 24) & 0x000000FFL) );
+}
+
+/* 
+ */
+
+#if	TESTER
+
+#include "stdio.h"
+
+/*
+   =============================================================================
+	test program for micon functions
+   =============================================================================
+*/
+
+main()
+{
+	printf("micons(0x1234) returned 0x%04x\n", micons(0x1234));
+
+	if (sizeof (int) == 4)
+		printf("miconi(0x1234) returned 0x%04x\n", miconi(0x1234));
+	else
+		printf("miconi(0x12345678L) returned 0x%08lx\n",
+			miconi(0x12345678L));
+
+	printf("miconl(0x12345678L) returned 0x%08lx\n",
+		miconl(0x12345678L));
+}
+
+#endif
Index: lib700/rand24.s
===================================================================
--- lib700/rand24.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/rand24.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,118 @@
+* ------------------------------------------------------------------------------
+* rand24.s -- generate a 24 bit random number
+* Version 3 -- 1988-04-29 -- D.N. Lynx Crowe
+* ------------------------------------------------------------------------------
+* Synopsis:
+*		long
+*		rand24()
+*
+* Based on:
+*		Knuth, Donald E.
+*		The Art of Computer Programming,
+*		Volume 2: Semi-Numerical Algorithms
+*
+* Computes:
+*		S = [S * C] + K
+*
+* Where:
+*		K = 1
+*		C = 3141592621
+*		S = the seed  (if zero, it gets set from the 200 Hz clock)
+*
+* Returns:
+*		S >> 8  (a 24 bit pseudo-random number)
+*
+* Note:  this function has an LSB with an exactly 50% distribution,  so using
+* individual bits is probably not a good idea.  Using more bits makes things
+* appear more random.
+* ------------------------------------------------------------------------------
+		.text
+*
+		.xdef	_rand24
+*
+		.xdef	_rseed
+*
+* equates for things in the BIOS
+*
+RCLOCK		.equ	$49E			* LONG - 200 Hz clock
+*
+* equates for stack offsets
+*
+ARG1		.equ	8			* LONG / WORD - arg1 / MS bits
+ARG1L		.equ	10			* WORD - arg1 LS bits
+ARG2		.equ	12			* LONG / WORD - arg2 / MS bits
+ARG2L		.equ	14			* WORD - arg2 LS bits
+*
+PART		.equ	-4			* LONG - partial product
+*
+PI		.equ	$BB40E62D		* LONG - PI as a hex value
+*
+		.page
+*
+* mult32 -- 32 bit signed multiply
+* ------    ----------------------
+mult32:		link	a6,#-4			* link stack frames
+		clr.w	d2			* clear sign flags
+		tst.l	ARG1(a6)		* check sign of 1st argument
+		bge	mult32a			* ...
+*
+		neg.l	ARG1(a6)		* make 1st argument positive
+		addq.w	#1,d2			* log its sign as negative
+*
+mult32a:	tst.l	ARG2(a6)		* check sign of 2nd argument
+		bge	mult32b			* ...
+*
+		neg.l	ARG2(a6)		* make 2nd argument positive
+		addq.w	#1,d2			* log its sign as negative
+*
+mult32b:	move.w	ARG1L(a6),d0		* generate 1st partial product
+		mulu	ARG2L(a6),d0		* ...
+		move.l	d0,PART(a6)		* ...
+		move.w	ARG1(a6),d0		* generate 2nd partial product
+		mulu	ARG2L(a6),d0		* ...
+		move.w	ARG2(a6),d1		* generate 3rd partial product
+		mulu	ARG1L(a6),d1		* ...
+		add.w	d1,d0			* add partial products
+		add.w	PART(a6),d0		* ...
+		move.w	d0,PART(a6)		* ...
+		move.l	PART(a6),d0		* ...
+		btst	#0,d2			* adjust sign of result
+		beq	mult32c			* ...
+*
+		neg.l	d0			* ...
+*
+mult32c:	unlk	a6			* unlink stack frames
+		rts				* return
+*
+		.page
+*
+* _rand24 -- Generate a random number
+* -------    ------------------------
+_rand24:	link	a6,#0			* Link stack frames
+		tst.l	_rseed			* See if the seed is zero
+		bne	rand01			* Jump if not
+*
+		move.l	RCLOCK,d0		* Pick up the 200 Hz clock
+		moveq.l	#16,d1			* Shift it left
+		asl.l	d1,d0			* ...
+		or.l	RCLOCK,d0		* OR in current 200 Hz clock
+		move.l	d0,_rseed		* Use that as the seed
+*
+rand01:		move.l	#PI,-(a7)		* Put PI on the stack
+		move.l	_rseed,-(a7)		* ... and _rseed, too
+		bsr	mult32			* Multiply them
+		addq.l	#8,a7			* Cleanup stack
+		addq.l	#1,d0			* Add 1 to the result
+		move.l	d0,_rseed		* Save as new seed
+		asr.l	#8,d0			* Make it a 24 bit number
+		and.l	#$00FFFFFF,d0		* ...
+		unlk	a6			* Unlink stack frames
+		rts				* Return to caller
+*
+* ------------------------------------------------------------------------------
+		.bss
+* ------------------------------------------------------------------------------
+*
+_rseed:		.ds.l	1			* random number seed
+*
+		.end
Index: lib700/setjmp.s
===================================================================
--- lib700/setjmp.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/setjmp.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,26 @@
+* ------------------------------------------------------------------------------
+* setjmp.s -- Unix(tm) compatible setjmp(env) and longjmp(env,ret)
+* Version 3 -- 1987-06-16 -- D.N. Lynx Crowe
+* ------------------------------------------------------------------------------
+*
+		.text
+*
+		.xdef	_setjmp,_longjmp
+*
+_setjmp:	movea.l	4(a7),a0		* Get env pointer
+		move.l	(a7),(a0)		* Put return address in env
+		movem.l	d1-d7/a1-a7,4(a0)	* Save registers in env
+		moveq.l	#0,d0			* Set return value to 0
+		rts				* Return to caller
+*
+_longjmp:	move.w	8(a7),d0		* Get ret value
+		bne	lj1			* Jump if non-zero
+*
+		moveq.l	#1,d0			* Force return value to 1
+*
+lj1:		movea.l	4(a7),a0		* Get env pointer
+		movem.l	4(a0),d1-d7/a1-a7	* Restore registers from env
+		move.l	(a0),(a7)		* Get return address from env
+		rts				* Return to caller
+*
+		.end
Index: lib700/tolower.c
===================================================================
--- lib700/tolower.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/tolower.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,36 @@
+/*
+   ============================================================================
+	tolower.c -- convert character to lower case ASCII
+	Version 1 -- 1987-09-11 -- D.N. Lynx Crowe
+   ============================================================================
+*/
+
+#include "ctype.h"
+
+/*
+   ============================================================================
+	tolower(c) -- convert c to lower case ASCII
+   ============================================================================
+*/
+
+int
+tolower(c)
+int c;
+{
+	int	x;
+
+	if (isascii(c)) {
+
+		if (isupper(c))
+			x = _tolower(c);
+		else
+			x = c;
+
+	} else {
+
+		x = c;
+	}
+
+	return(x);
+}
+
Index: lib700/toupper.c
===================================================================
--- lib700/toupper.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/toupper.c	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,34 @@
+/*
+   ============================================================================
+	toupper.c -- convert character to upper case ASCII
+	Version 1 -- 1987-06-11 -- D.N. Lynx Crowe
+   ============================================================================
+*/
+
+#include "ctype.h"
+
+/*
+   ============================================================================
+	toupper(c) -- convert c to upper case ASCII
+   ============================================================================
+*/
+
+int
+toupper(c)
+int c;
+{
+	int	x;
+
+	if (isascii(c)) {
+
+		if (islower(c))
+			x = _toupper(c);
+		else
+			x = c;
+	} else {
+
+		x = c;
+	}
+
+	return(x);
+}
Index: lib700/uldiv.s
===================================================================
--- lib700/uldiv.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
+++ lib700/uldiv.s	(revision 109c83b4de0a1be1740921110e1aab18add40866)
@@ -0,0 +1,96 @@
+* ------------------------------------------------------------------------------
+* uldiv.s -- unsigned long division, with remainder
+* Version 2 -- 1987-06-08 -- D.N. Lynx Crowe
+* Lifted from the Alcyon C library by disassembly so I could fix a bug -
+*	_uldivr must be in the bss segment so the code will work in PROM.
+*
+*	long
+*	uldiv(dividnd, divisor)
+*	long dividnd, divisor;
+*
+*	extern long uldivr;
+*
+*		Divides 'dividnd' by 'divisor', treating both as unsigned
+*		long integers.  Returns the quotient and leaves the
+*		remainder in 'uldivr'.  Produces a divide check on division
+*		by zero, with $80000000 returned for both quotient and
+*		remainder.
+* ------------------------------------------------------------------------------
+		.text
+*
+		.xdef	_uldiv,_uldivr
+*
+DIVIDEND	.equ	8
+DIVISOR		.equ	12
+*
+_uldiv:		link	a6,#0			* Link stack frames
+		movem.l	d3-d7,-(a7)		* Save registers
+		move.l	DIVIDEND(a6),d7		* d7 = DIVIDEND
+		move.l	DIVISOR(a6),d6		* d6 = DIVISOR
+		tst.l	d6			* Divide by zero ?
+		bne	notdzero		* Jump if not
+*
+		move.l	#$80000000,_uldivr	* Force error result
+		move.l	#$80000000,d0		* ... by dividing
+		divu	#0,d0			* ... by zero
+		bra	ulexit			* ... then exit
+*
+notdzero:	cmp.l	d7,d6			* Divide underflow ?
+		bls	notunflo		* Jump if not
+*
+		move.l	d7,_uldivr		* Remainder = dividend
+		clr.l	d0			* Quotient = 0
+		bra	ulexit			* Exit
+*
+notunflo:	cmp.l	d6,d7			* Is dividend = divisor ?
+		bne	startdiv		* Go start dividing if not
+*
+		moveq.l	#1,d5			* Quotient = 1
+		clr.l	d7			* Remainder = 0
+		bra	setreslt		* Go set result
+*
+		.page
+*
+startdiv:	moveq.l	#1,d4			* Set result bit in d4
+*
+divloop1:	cmp.l	d6,d7			* Divisor aligned OK ?
+		bcs	divloop2		* Jump if so
+*
+		move.l	d6,d0			* Can we align things better ?
+		asl.l	#1,d0			* ...
+		cmp.l	d0,d6			* ...
+		bhi	divloop2		* Jump if not
+*
+		asl.l	#1,d6			* Shift the divisor
+		asl.l	#1,d4			* Shift the result bit
+		bra	divloop1		* Loop for next bit
+*
+divloop2:	clr.l	d5			* Clear quotient
+*
+divloop3:	tst.l	d4			* More bits to do ?
+		beq	setreslt		* Go set result if not
+*
+		cmp.l	d6,d7			* Can we subtract ?
+		bcs	divloop4		* Jump if not
+*
+		or.l	d4,d5			* Set a bit in the quotient
+		sub.l	d6,d7			* Subtract divisor from dividend
+*
+divloop4:	lsr.l	#1,d4			* Shift the result bit
+		lsr.l	#1,d6			* Shift the divisor
+		bra	divloop3		* Loop for next bit
+*
+setreslt:	move.l	d7,_uldivr		* Store remainder
+		move.l	d5,d0			* Put quotient in d0
+*
+ulexit:		tst.l	(a7)+			* Discard top of stack
+		movem.l	(a7)+,d4-d7		* Restore registers
+		unlk	a6			* Unlink stack frames
+		rts				* Return to caller
+*
+		.bss
+		.even
+*
+_uldivr:	ds.l	1
+*
+		.end
