; 
; 
;                     BANZAI.ASM Ver.1.1
; 
;                          as of
; 
;                     September 3, 1980
; 
;  So  you  have embedded your copyright notice in your  pride 
; and joy (3000 hours, 'till 3 in the morning "super program") 
; and  have  even included serial numbers  to  discourage  the 
; "rip-off"  artists...Great,  the "rip-off" artist takes your 
; ".COM" file and puts DDT or SID to work on it,  and calls it 
; his/hers...Oh well...but WAIT...there is HOPE.
; 
;  Include  BANZAI in your source file,  reassemble  with  the 
; appropriate copyright notice and serial number, and wait for 
; the  fireworks...ANY ATTEMPT to corrupt either the copyright 
; notice  or the serial number,  will "scramble" your file  so 
; bad  on  the  disk,  that  it  will  never  be  figured  out 
; again...In  addition,  any remnent parts of the  program  in 
; memory  are  also  "clobberd",  so back-tracking  is  nearly 
; impossible...a fitting justice to the "rip-off" artist.
; 
;  Digital  Research's  macro assemble "MAC"  is  required  to 
; assemble "BANZAI.ASM".
; 
; 
;                          Best regards,
;      
;                          Kelly Smith, CP/M-NET (tm)
;                          805-527-9321 (Modem, 300 Baud)
;                          805-527-0518 (Verbal)
; 
; 
;
;DEFINE DATA MOVE MACRO: MOVE FROM,TO,LENGTH FROM MAY BE ADDR, OR QUOTED STRING
;
MOVE	MACRO	?F,?T,?L
	IF	NOT NUL ?F
	IRPC	?C,?F
?Q	SET	'&?C&?C' ;;TEST FOR QUOTE
	EXITM
	ENDM
	IF	?Q EQ ''''
	LOCAL	?B,?Z
	CALL	?Z
?B	DB	?F
?Z	POP	H	;GET FROM
	LXI	B,?Z-?B	;GET LEN
	ELSE
	LXI	H,?F
	ENDIF
	ENDIF
	IF	NOT NUL ?T
	LXI	D,?T
	ENDIF
	IF	NOT NUL ?L
	LXI	B,?L
	ENDIF
	CALL	MOVER
	ENDM
;
;DEFINE CP/M MACRO - CPM FNC,PARM
;
CPM	MACRO	?F,?P
	PUSH	B
	PUSH	D
	PUSH	H
	IF	NOT NUL ?F
	MVI	C,?F
	ENDIF
	IF	NOT NUL ?P
	LXI	D,?P
	ENDIF
	CALL	BDOS
	POP	H
	POP	D
	POP	B
	ENDM


;
LXIH	EQU	021H	;DEFINE LXI H,XX TO CONFUSE DISASSEMBLERS
;

	ORG	100H
;
; INITIALIZE LOCAL STACK
; 
STARTZ:LXI	H,0
	DAD	SP
	SHLD	STACK
	LXI	SP,STACK
; 
; START OF PROGRAM EXECUTION

START:	JMP	BEGIN	; JUMP OVER COPYRIGHT NOTICE AND SERIAL NUMBER
	DB	LXIH	;CONFUSE DISASSEMBLERS

COPY$RIGHT:

	DB	' Copyright 1980, by Microcosm Associates '
SERIAL$NUMBER:

	DB	'UAC15234'

BEGIN:	JMP	GET$COPYRIGHT
	DB	LXIH	;CONFUSE DISASSEMBLERS
INSTR:	MOV	A,B
	SUB	C
	CMC
	RNC
	MOV	B,A
INSTR1:	PUSH	B
	PUSH	D
	PUSH	H
	JMP	GET$MATCH
	DB	LXIH	;CONFUSE DISASSEMBLERS
MATCH:	INR	C
MATCH1:	DCR	C
	RZ
	LDAX	D
	ANI	07FH	;REVEAL HIDDEN TEXT
	SUB	M
	RNZ
	INX	H
	INX	D
	JMP	MATCH1
	DB	LXIH	;CONFUSE DISASSEMBLERS
GET$MATCH:
	CALL	MATCH
	POP	H
	POP	D
	POP	B
	JZ	MATCH$OK
	ANA	A
	DCR	B
	RM
	INX	H
	JMP	INSTR1
	DB	LXIH	;CONFUSE DISASSEMBLERS
MATCH$OK:
	MVI	B,0
	DAD	B
	STC
	RET
	DB	LXIH	;CONFUSE DISASSEMBLERS
GET$COPYRIGHT:
	LXI	H,COPY$RIGHT
	MVI	B,40H
	MVI	C,CHECK$COPYRIGHT-HIDDEN$COPYRIGHT
	LXI	D,HIDDEN$COPYRIGHT
	CALL	INSTR
	JMP	CHECK$COPYRIGHT
	DB	LXIH	;CONFUSE DISASSEMBLERS
HIDDEN$COPYRIGHT:
	DB	' '+80H
	DB	'C'+80H
	DB	'o'+80H
	DB	'p'+80H
	DB	'y'+80H
	DB	'r'+80H
	DB	'i'+80H
	DB	'g'+80H
	DB	'h'+80H
	DB	't'+80H
	DB	' '+80H
	DB	'1'+80H
	DB	'9'+80H
	DB	'8'+80H
	DB	'0'+80H
	DB	','+80H
	DB	' '+80H
	DB	'b'+80H
	DB	'y'+80H
	DB	' '+80H
	DB	'M'+80H
	DB	'i'+80H
	DB	'c'+80H
	DB	'r'+80H
	DB	'o'+80H
	DB	'c'+80H
	DB	'o'+80H
	DB	's'+80H
	DB	'm'+80H
	DB	' '+80H
	DB	'A'+80H
	DB	's'+80H
	DB	's'+80H
	DB	'o'+80H
	DB	'c'+80H
	DB	'i'+80H
	DB	'a'+80H
	DB	't'+80H
	DB	'e'+80H
	DB	's'+80H
	DB	' '+80H
CHECK$COPYRIGHT:
	JNC	BANZAI	; BANZAI FILE, IF COPYRIGHT CORRUPTED
	LXI	H,SERIAL$NUMBER
	MVI	B,40H
	MVI	C,CHECK$SERIAL$NUMBER-HIDDEN$SERIAL$NUMBER
	LXI	D,HIDDEN$SERIAL$NUMBER
	CALL	INSTR
	JMP	CHECK$SERIAL$NUMBER
	DB	LXIH	;CONFUSE DISASSEMBLERS
HIDDEN$SERIAL$NUMBER:
	DB	'U'+80H
	DB	'A'+80H
	DB	'C'+80H
	DB	'1'+80H
	DB	'5'+80H
	DB	'2'+80H
	DB	'3'+80H
	DB	'4'+80H
CHECK$SERIAL$NUMBER:
	JNC	BANZAI	; BANZAI FILE, IF SERIAL NUMBER CORRUPTED
	JMP	NOBANZAI; EXIT, FOR PURPOSES OF DEMO...
			; ...NORMAL EXECUTION OF FILE WOULD CONTINUE
	DB	LXIH	;CONFUSE DISASSEMBLERS
; 
; 
; 

BANZAI:			; BANZAI THE SPECIFIED FILE IN "TFCB"

; 
; SCRAMBLE A WHILE TO MIX UP THE SEED
; 
	MVI	H,0	; GET 256 #'S
MIXUP:	CALL	PSEURAN	; GET A #
	DCR	H	; MORE?
	JNZ	MIXUP	; LOOP IF SO
;
;GET LOGGED IN DRIVE NUMBER
;
	LDA	FCB	; GET FROM "JUST LOADED" FILENAME
	STA	TFCB	; AND SAVE IN TEMPORARY FCB
; 
; SEE THAT THE INPUT FILE EXISTS
; 
	CPM	OPEN,TFCB
	INR	A	; OK?
	JNZ	SCRAMLP	; YES, SCRAMBLE IT
	CALL	ERXIT
	DB	'++NO SUCH FILE++$'
	DB	LXIH	;CONFUSE DISASSEMBLERS
; 
; READ THE FILE, SCRAMBLE A SECTOR, RE-WRITE IT.
; 
SCRAMLP:CALL	RDSECT	; READ A SECTOR
	JC	FINISH	; EXIT LOOP IF EOF
	CALL	SCRAMBL	; SCRAMBLE IT
	CALL	BACKUP	; RE-POSITION FOR WRITE
	CALL	WRSECT	; RE-WRITE THE SECTOR
	JMP	SCRAMLP	; LOOP UNTIL EOF
	DB	LXIH	;CONFUSE DISASSEMBLERS
; 
; 
FINISH:	CPM	CLOSE,TFCB
	JMP	EXIT	; THIS BETTER WORK..
	DB	LXIH	;CONFUSE DISASSEMBLERS
; 
; SECTOR READ ROUTINE
; 
RDSECT:	CPM	READ,TFCB
	ORA	A
	RZ		; ALL OK
; 
; READ ERROR OR EOF
; 
	CPI	1	; EOF?
	STC		; CARRY SHOWS EOF
	RZ		; RET, CARRY SET
	JMP	EXIT	; GREAT, A READ ERROR MAY HAVE BANZAI'D THE FILE
	DB	LXIH	;CONFUSE DISASSEMBLERS
; 
; SCRAMBLE THE SECTOR
; 
SCRAMBL:LXI	H,80H	; POINT TO SECTOR
SCRLP:	CALL	PSEURAN	; GET PSEUDO RANDOM #
	XRA	M	; SCRAMBLE
	MOV	M,A
	INR	L	; MORE IN SECTOR?
	JNZ	SCRLP
	RET
	DB	LXIH	;CONFUSE DISASSEMBLERS
; 
; BACKUP THE FILE POINTER FOR THE RE-WRITE
; 
BACKUP:	LDA	FCBRNO	; GET SECTOR #
	DCR	A	; BACK UP
	STA	FCBRNO
	RP		; RETURN IF OK
; 
; WE BACKED UP INTO PREVIOUS EXTENT, WILL HAVE TO RE-OPEN IT
; 
	LDA	FCBEXT	; GET EXTENT
	DCR	A	; BACK UP 1
	STA	FCBEXT
	CPM	OPEN,TFCB ; RE-OPEN
	INR	A
	JNZ	OPEN2OK
	JMP	EXIT	; GREAT, OPEN ERROR MAY HAVE BANZAI'D THE FILE
	DB	LXIH	;CONFUSE DISASSEMBLERS
OPEN2OK:MVI	A,7FH	; GET HI SECTOR
	STA	FCBRNO
	RET
	DB	LXIH	;CONFUSE DISASSEMBLERS
; 
; WRITE BACK THE SECTOR
; 
WRSECT:	CPM	WRITE,TFCB
	ORA	A
	RZ
	JMP	EXIT	; GREAT, WRITE ERROR MAY HAVE BANZAI'D THE FILE
	DB	LXIH	;CONFUSE DISASSEMBLERS
; 
; GET A PSEUDO-RANDOM 8 BIT NUMBER USING THE PASSWORD AS A SEED
; 
; 	FOR SPEED, THIS ROUTINE DOES NO REGISTER
; 	PUSHES AND POPS, HOWEVER HL AREN'T USED.
; 
PSEURAN:MVI	C,4	; GRAB EVERY 4TH PSEU. #
PSEULP0:MVI	B,8	; SHIFT THRU 8 BYTES
	LXI	D,PASSWD
	ORA	A	; CLEAR INITIAL CARRY
PSEULP1:LDAX	D	; GET A CHAR
	RAR		; SHIFT
	STAX	D
	INX	D
	DCR	B
	JNZ	PSEULP1
; EXCLUSIVE-OR THE LAST FEW BITS INTO THE FIRST ONE
	DCX	D	; BACK UP TO LAST
	RAR
	RAR		; SHIFT A FEW MORE
	XCHG
	XRA	M
	RRC		; SHIFT LO BIT INTO HI
	ANI	80H	; ISOLATE SINGLE BIT
	LXI	H,PASSWD ; GET FIRST BYTE
 	ORA	M	; 'OR' IN THE BIT
	MOV	M,A	; MOVE IT BACK
	XCHG		; RESTORE HL
	DCR	C
	JNZ	PSEULP0	; LOOP IF MORE PASSES
	RET
	DB	LXIH	;CONFUSE DISASSEMBLERS
; 
; MOVE SUBROUTINES
; 
MOVER:	MOV	A,M
	STAX	D
	INX	H
	INX	D
	DCX	B
	MOV	A,B
	ORA	C
	JNZ	MOVER
	RET
	DB	LXIH	;CONFUSE DISASSEMBLERS
; 
; EXIT WITH ERROR MESSAGE
; 
MSGEXIT	EQU	$	; EXIT WITH MESSAGE
ERXIT:	POP	D	; GET MSG
	MVI	C,PRNSTRG
	CALL	BDOS
; 
; EXIT, CLOBBER MEMORY, RESTORE STACK, AND RETURN (HEH, HEH...)
; 
ENDZ	EQU	$		; END OF MEMORY TO BE CLOBBERD
EXIT:	LXI	B,ENDZ-STARTZ	; GET BYTE NUMBER TO CLOBBER
	LXI	H,STARTZ	; POINT TO START OF CLOBBER
CLOBBER:MOV	M,A		; DO IT...TO IT...
	INX	H
	DCX	B
	MOV	A,B
	ORA	C
	JNZ	CLOBBER		; CLOBBER ALL...
NOBANZAI:			; NO BANZAI REQUIRED...
	LHLD	STACK
	SPHL
	RET		; RETURN TO CP/M
	DB	LXIH	;CONFUSE DISASSEMBLERS

PASSWD:	DB	'KILLFILE'
	DB	LXIH	;CONFUSE DISASSEMBLERS

TFCB:	DB	0,'BANZAI  COM',0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

	DS	128	; STACK AREA
STACK	DS	2

;
; BDOS/CBIOS EQUATES (VERSION 7)	
;
RDCON	EQU	1
WRCON	EQU	2
PRNSTRG	EQU	9
CONST	EQU	11
OPEN	EQU	15
CLOSE	EQU	16
SRCHF	EQU	17
SRCHN	EQU	18
ERASE	EQU	19
READ	EQU	20
WRITE	EQU	21
MAKE	EQU	22
REN	EQU	23
STDMA	EQU	26
BDOS	EQU	5
FCB	EQU	5CH 
FCB2	EQU	6CH
FCBEXT	EQU	TFCB+12
FCBRNO	EQU	TFCB+32

	END
