; General macros
;
; (C)1988 By Ami Bar-Yadin.
;	AMUS ID: AMI/AM
;
; All commercial rights reserved, etc.
;
; If you want to include STAMP with a commercial package,
; go right ahead so long as you include the UNCHANGED source (.m68) with it.
;
; No warranties and/or guarranties of any kind, etc.
;
; Not responsible for damages resulting from the use of this program, etc.
;
; My employer (United Fashions) has nothing to do with this program and
; should not be blamed for it.
;
; I can be reached at:
;		United Fashions of Texas, Inc.
;		200 Ash Ave.
;		McAllen, TX  78501
;		(512) 631-2277/2276
;		8am-6pm
;
	UNIVERSAL
	COPY	ASCII.TBL

;-------
; misc simple macros
;
 DEFINE	OUTCHR	CHR
	IF NB,CHR,	MOVB	CHR,D1
	TTY
 ENDM

 DEFINE	DIAG	CODE
	MOVB	CODE,^H0FFFE00                                       
 ENDM

;-------
; TCRT calls
				; function (general)
 DEFINE	XTABF	X
	IF	DF,SAVD1,	PUSH	D1
	MOVW	#<-1_8>+X,D1
	TCRT
	IF	DF,SAVD1,	POP	D1
 ENDM
				; short (decimal)
 DEFINE	XTAB	Y,X
	IF	DF,SAVD1,	PUSH	D1
	MOVW	#<Y'._8>+X'.,D1
	TCRT
	IF	DF,SAVD1,	POP	D1
 ENDM
				; medium (decimal)
 DEFINE	XTABL	Y,X
	IF	DF,SAVD1,	PUSH	D1
	MOV	#<<<Y'.>&255.>_8.>+X'.,D1
	TCRT
	IF	DF,SAVD1,	POP	D1
 ENDM

 DEFINE	XTABLF	Y,X
	IF	DF,SAVD1,	PUSH	D1
	MOV	#<Y'._8.>+X'.,D1
	TCRT
	IF	DF,SAVD1,	POP	D1
 ENDM
				; rotate (decimal)
 DEFINE	XTABR	Y,X
	IF	DF,SAVD1,	PUSH	D1
	MOVW	#Y'.,D1
	ROLW	D1,#8
	MOVB	#X'.,D1
	TCRT
	IF	DF,SAVD1,	POP	D1
 ENDM
				; rotate (general)
 DEFINE	XTABG	Y,X
	IF	DF,SAVD1,	PUSH	D1
	MOVW	Y,D1
	ROLW	D1,#8
	MOVB	X,D1
	TCRT
	IF	DF,SAVD1,	POP	D1
 ENDM

;-------
; Impure definition
				; init impure
 DEFINE	IMPINI	START
	DSECT
	IF B,START,	.=0
	IF NB,START,	.=START	
 ENDM
				; define label
 DEFINE	IMPDEF	LBL,SIZE
	IF NB,SIZE
LBL:	BLKB	SIZE
	IFF
LBL:	BLKB	0
	ENDC
 ENDM
				; define size label
 DEFINE	IMPSIZ	LBL
	IF NB,LBL
LBL:
	ENDC
	PSECT
 ENDM


DEFINE	IMPGET	SIZE,IDX,NOMEM,MODNM1,MODNM2,MODEXT
	PUSH	SIZE		;(MAC:SYS.M68:  PUSH #SIZE)
	PUSH
	GETMEM	@SP
	IF	B,NOMEM
	BEQ	10$$
	EXIT
    10$$:
	IFF
	JNE	NOMEM
	ENDC
	POP	IDX
	POP
	IF	NB,MODNM1,	MOVW	#[MODNM1],M.NAM-ZID(IDX)
	IF	NB,MODNM2,	MOVW	#[MODNM2],M.NAM+2-ZID(IDX)
	IF	NB,MODEXT,	MOVW	#[MODEXT],M.EXT-ZID(IDX)
	ENDM
				; allocate memory

;-------
; Record definition
				; init impure
 DEFINE	RECINI	START
	ASECT
	IF NB,START,	.=START	
 ENDM
				; define label
 DEFINE	RECDEF	LBL,SIZE
	IF NB,SIZE
LBL:	BLKB	SIZE
	IFF
LBL:	BLKB	0
	ENDC
 ENDM
				; define size label
 DEFINE	RECSIZ	LBL
	IF NB,LBL
LBL:
	ENDC
	PSECT
 ENDM

;-------
; Table offset definition
;				; init table
 DEFINE	TBLINI	START
START:
$$TBL=START
 ENDM
				; define table offset
 DEFINE	TBLOFF	TARGET
	WORD	TARGET-$$TBL
 ENDM

;-------
; memory module symbols
;
	RECINI
	RECDEF	M.SIZ,4
	RECDEF	M.FLG,2
	RECDEF	M.NAM,4
	RECDEF	M.EXT,2
	RECSIZ

;-------
; sign on
; display module name, version and free memory size in bytes
 DEFINE	SGNON	ADR
	SAVE	A1,A2,D1,D2
	LEA	A1,ADR
	LEA	A1,M.NAM-ZID(A1)
	LEA	A2,-10(SP)
	UNPACK
	UNPACK
	LEA	A2,-10(SP)
	MOV	#5,D2
1$$:	OUTCHR	(A2)+
	DBF	D2,1$$
	TYPE	< v>
	LEA	A2,ADR
	ADD	#2,A2
	VCVT	@A2,OT$TRM
	TAB
	USRFRE	D0
	USREND	D1
	SUB	D0,D1
	DCVT	0,OT$TRM+OT$TSP
	TYPECR	<bytes free>
	REST	A1,A2,D1,D2
 ENDM

;
;
	END