	.title	JTlic
; Copyright (c) 1993, 1994 Glenn C. Everhart
; All Rights Reserved
vms$v5=1
; JT licensing pkg
;
; Author:
;	Glenn Everhart. Uses some code from ZDEC.MAR by Mark Oakley.
;--

	.SBTTL	Symbols, Macros, Data

	.LIBRARY	/SYS$LIBRARY:LIB.MLB/

	$TPADEF		; Symbols for LIB$TPARSE.
	$SSDEF		; Symbols for return status.
	$UCBDEF		; Symbols for device ucb.
	$STSDEF		; Symbols for returned status.
	$DVIDEF		; Symbols for $GETDVI service.
	$DCDEF		; Symbols for device type.
	$dptdef
	$DEVDEF		; SYM. FOR SDI TYPE DEVICE.
	$brkdef
	$opcdef
	$pcbdef		; pcb symbols

	.PSECT	CDEV_DATA,RD,WRT,NOEXE,LONG,SHR,PIC

wrk:	.long	0		; scratch
PIDDS:	.ASCID	/PID/		; /PID switch
PIDVL:	.word	32		; length of buffer
	.byte	dsc$k_dtype_t	;text type
	.byte	1		;fixed static
	.address	pidtx
pidtx:	.blkl	8		;text area for /pid:nnnnnnnn "nnnnnnnn" value
pidwk:	.long	0		;work storage
newpid:	.long	0		;pid to move device to
P1DSC:	.ascid	/Device/
; in .cld have a line
; parameter p1,prompt="Device:",value(required,type=$device),label=Device
DEV_BUF:			; Buffer to hold device name.
	.BLKB	40
DEV_BUF_SIZ = . - DEV_BUF
DEV_BUF_DESC:			; Descriptor pointing to device name.
	.LONG	 DEV_BUF_SIZ
	.ADDRESS DEV_BUF
PID:				; Owner of device (if any).
	.BLKL	1
K_ARG:				; Argument list for kernel-mode routine.
	.LONG	 2		; 2 args
	.ADDRESS DEV_BUF_DESC	; Pass descriptor for device name.
	.address newpid		; PID to "give" device to.
		; Note: pid field must be nonzero or this is a no-op.
		; UCB$L_PID is set...
	.macro	sztxt1,text
	zcnt=0
	.irpc x,<text>
	zcnt = zcnt+1
	y = ^a?x? & ^xe1
;	y = y ! zcnt
	.byte y
	.endr
	.endm
	.macro	sztxt2,text
	zcnt=0
	.irpc x,<text>
	zcnt = zcnt+1
	y = ^a?x? & ^x12
;	y = y ! zcnt
	.byte y
	.endr
	.endm
	.macro	sztxt3,text
	.irpc x,<text>
	y = ^a?x? & ^x0C
	.byte y
	.endr
	.endm
;
sz1:	sztxt1 <EACF, Copyright 1994 General Cybernetic Enterprises>
	.byte	13,10
	sztxt1 <(603) 465 9517, Everhart@Arisia.GCE.Com>
	.byte	13,10
	sztxt1 <Licensed exclusively to:>
	.byte	13,10
	sztxt1 <{customername} {orgazization} {phone}>
sz2:	sztxt2 <EACF, Copyright 1994 General Cybernetic Enterprises>
	.byte	13,10
	sztxt2 <(603) 465 9517, Everhart@Arisia.GCE.Com>
	.byte	13,10
	sztxt2 <Licensed exclusively to:>
	.byte	13,10
	sztxt2 <{customername} {orgazization} {phone}>
sz3:	sztxt3 <EACF, Copyright 1994 General Cybernetic Enterprises>
	.byte	13,10
	sztxt3 <(603) 465 9517, Everhart@Arisia.GCE.Com>
	.byte	13,10
	sztxt3 <Licensed exclusively to:>
	.byte	13,10
	sztxt3 <{customername} {orgazization} {phone}>
; 
bldc:	.ascii	/                                           /
	.byte	0,0
	.blkb	256
	.ascii	/                                                     /
	.byte	0,0
iosb:	.long	0,0
	.align long
opd:	.ascid	/OPA0:/
	.align long
omsgd:	.word	omsgl
	.byte	dsc$k_dtype_t,1
	.address	oprmsg
bmsgd:	.word	mmsgl
	.byte	dsc$k_dtype_t,1
	.address	msgd
oprmsg:	.byte	opc$_rq_rqst
	.long	opc$m_nm_device
	.byte	1
	.word	0		;fill out
; leave the ASCII in here as a red flag. If it gets clobbered
; when we reconstitute, refuse to operate. Someone might just
; try to mess with the image to obscure the origin. This will
; inhibit such.
msgd:	.ascii	/EACF, Copyright 1994 General Cybernetic Enterprises/
	.byte	13,10
	.ascii	/(603) 465 9517, Everhart@Arisia.GCE.Com/
	.byte	13,10
	.ascii /Licensed exclusively to:/
	.byte	13,10
	.ascii	/{customername} {orgazization} {phone}/
msgl=.-msgd
	.byte	7,7
	.byte 13,10
	.ascii	/May not be used without a valid license./
mmsgl=.-msgd
omsgl=.-oprmsg
	.blkl	32
	.SBTTL	Main program
	.PSECT	CDEV_CODE,RD,NOWRT,EXE,LONG,SHR,PIC
	.ENTRY	LicMsg,^M<R2,R3,R4,R5,R6,R7,R8,R9,R10,R11>
; Get the args.
	movab	sz1,r2
	movab	sz2,r3
	movab	sz3,r4
	movl	#msgl,r5
	subl2	#2,r5		;leave bells off
	movab	bldc,r11
	movab	msgd,r10
10$:	movzbl	(r2)+,r6
	movzbl	(r3)+,r7
	movzbl	(r4)+,r8
; got 3 chars. Xor them all together now.
	xorl2	r6,r7
	xorl2	r7,r8
	cmpb	r8,(r10)+	;are the xor'd chars identical with
				;the originals?
	beql	11$
	movl	#8596,r0	;ss$_nolicense
	brw	exit		;if not, there's been tampering. Refuse to run
11$:
	movb	r8,(r11)+
	sobgtr	r5,10$
;
	movab	bmsgd,r2
	movab	opd,r3
	$brkthruw_s efn=#1,msgbuf=(r2),sendto=(r3),sndtyp=#brk$c_device,-
	  iosb=iosb,timout=#20
	movab	omsgd,r2
	$sndopr_s msgbuf=(r2)
	movl	#1,r0
	BRW	EXIT
80$:
; leave ret code in r0
EXIT:
	RET
	.END
