; ROT translater       Code: Torque		      sjoyce@primenet.com

mn:		move.l	a0,arg				; Pointer to command line arguement
		move.l	d0,num				; Number of characters in arguement
		move.l	$4.w,a6 			; ExecBase
		lea		dos,a1				; dos library name
		move.l	#0,d0				; any version
		jsr		-552(a6)                        ; Open Dos Library
		tst.b	d0					; Did it open?
		beq		over				; No? Quit
		move.l	d0,dosbase			; Save DosBase
		move.l	d0,a6				; Move DosBase into a useful position
		jsr		-$3c(a6)                        ; Get stdout
		tst.b	d0					; Did it work?
		beq		closedos			; No? Shutdown...
		move.l	d0,output			; Save stdout
addnul: move.l	arg,a0				; Get arguement pointer
		move.l	num,d0				; Get length
		cmpi.b	#1,d0				; Was there no arguements?
		bne		nul					; No? Show syntax message
arg_err:	move.l	output,d1		; Get stdout in d1
		move.l	#RotInf,d2			; Pointer to syntax message
		move.l	#RotIsize,d3		; Length of message
		jsr		-$30(a6)                        ; Write message to current window
		bra		closedos			; Shutdown...
nul:	add.l	#1,a0				; Next byte
		dbra	d0,nul				; Subtract until end of arguement
		sub.l	#2,a0				; Go back a couple bytes (I.E. LF,NULL)
		move.b	#0,(a0)                         ; Insert NULL terminator
openfile:	move.l	arg,d1			; The filename to be opened
		move.l	#$000003ed,d2		; OldFile (Already exists) Flag
		jsr		-$1e(a6)                        ; Attempt file open...
		move.l	d0,fh				; Get file handle
		tst.b	d0					; Did it open?
		bne		readfile			; Yes? Start the read...
err:	move.l	output,d1			; File Error occured; stdout to d1
		move.l	#FileErr,d2			; Pointer to file error message
		move.l	#FEsize,d3			; Length of message
		jsr		-$30(a6)                        ; Output to current window
		bra		closedos			; Shutdown...
readfile:	move.l	#Buffer,d2		; One Byte buffer for read
		move.l	fh,d1				; File Handle
		move.l	#1,d3				; Read one byte only
		jsr		-$2a(a6)                        ; Read
		cmpi.b	#-1,d0				; An error?
		beq		err					; Yes? Print File Error message...
		cmpi.b	#0,d0				; End of File?
		beq		close				; Yes? Shutdown...
code:	move.b	Buffer,d0			; Get buffer in d0
		cmpi.b	#123,d0 			; Find out if this byte is -
		bge		print				; a letter by finding the general -
		cmpi.b	#64,d0				; range...
		ble		print
		cmpi.b	#91,d0				; Is it a non-letter in between the
		bge		step2				; 2 case alphabets?
		move.b	#0,CaseFlag			; It is Upper case
		bra		crunch
step2:	move.b	#1,CaseFlag			; It might be a Lower case letter?
		cmpi.b	#96,d0				; Make sure it is not a non-letter
		ble		print				; If it is, just print it
crunch: cmpi.b	#1,CaseFlag			; Is it Lower Case?
		beq		LCase
UCase:	cmpi.b	#78,d0				; It must be Upper Case, find out if
		bge		sb					; the letter is N or greater...
		addi.b	#13,Buffer			; No, skip to (LETTER+13)
		bra		print				; Write it to screen...
sb:		subi.b	#13,Buffer			; Yes, skip to (LETTER-13)
		bra		print				; Write it to screen...
LCase:	cmpi.b	#110,d0 			; It must be Lower Case, find out if
		bge		sb2					; the letter is N or greater...
		addi.b	#13,Buffer			; No, (LETTER+13)
		bra		print				; Write it...
sb2:	subi.b	#13,Buffer			; Yes, (LETTER-13)
print:	move.l	#Buffer,d2			; the pointer to the current letter
		move.l	output,d1			; stdout
		move.l	#Bufsize,d3			; Buffersize (always 1)
		jsr		-$30(a6)                        ; Write the letter...
		move.b	$bfec01,d4			; Get RAW key
		cmpi.b	#$39,d4 			; Check for CTRL key
		beq		break				; Did it get pressed? Yes? BREAK...
		bra		readfile			; Keep going...
break:	move.l	output,d1			; stdout
		move.l	#brk,d2 			; Break message pointer
		move.l	#brksize,d3			; Buffer Size
		jsr		-$30(a6)                        ; Write the message
close:	move.b	#10,Buffer			; Line feed
		move.l	#Buffer,d2			; Pointer to LF
		move.l	output,d1			; stdout
		move.l	#Bufsize,d3			; 1 byte
		jsr		-$30(a6)                        ; Write...
closefile:	move.l	fh,d1			; Get file handle in d1
		jsr		-$24(a6)                        ; Close file
closedos: move.l	$4.w,a6 		; ExecBase
		move.l	dosbase,a1			; Get dosbase in a1
		jsr		-$19e(a6)                       ; Close DosBase
		move.l	#0,d0				; Clear d0 (no errors)..
over:	rts



dos:	dc.b	'dos.library',0
arg:	dc.l	0
num:	dc.l	0
str:	dc.b	0
dosbase:	dc.l	0
output: dc.l	0
RotInf: dc.b	10,'AROT - V1.0, 1994, Public Domain',10
		dc.b	10,'(DE/UNEN)crypts a ROT message and dumps it to the screen.',10
		dc.b	10,'Syntax: AROT <file>',10,10,'<CTRL> Breaks',10,10
		dc.b	'Torque    sjoyce@primenet.com',10,10
RotIsize	EQU	*-RotInf
fh:		dc.l	0
FileErr:	dc.b	10,'FILE ERROR!',10
FEsize	EQU	*-FileErr
Buffer: dc.b	0
Bufsize EQU *-Buffer
CaseFlag:	dc.b	0
brk:	dc.b	10,'*** BREAK ***'
brksize EQU	*-brk
