;------------------------------------------------------------------------
;
;		Copyright 2010 Intergraded Logic	Systems
;                  Source Code is Copyright Stephen J. Carden
;
;
;			Please do not share this source!
;------------------------------------------------------------------------
;		oss utility for real.dos v1.0) 
;
;------------------------------------------------------------------------
;
;                         Dis_bat.com
;	This program disables batch files from running!
;
;	Code History.     Init design,   11/12/2005   sjc
;
;	This version will only turn off batch processing ewquiring you 
;	to reboot to enable batch processings.
;
;	Updated the screen Print Utility so it will work with the exp-80
; This change will also help "Print P:"		6/19/2010	sjc
;
;
;
;Updated the screen Print Utility so it will work with the exp-80
; This change will also help "Print P:"		8/17/2012	sjc
;
;
;Also added code for Control+1 pause of screen to the high speed screen
;handling.		8/24/2012	sjc
;
;	Dis_bat.com turns on and off batch processing. 8/29/2012 sjc
;
;	Still have some cleanup code to write
;
;
;
;
;
;
;
;int.dis_bat
;------------------------------------------------------------------------
; Notes: o This source code MAY NOT be placed for download on any BBS's!
;        o "mea" is a	macro that loads the address of the first field
;          into the pointer specified by the second field.
;------------------------------------------------------------------------
; Assembler:  MADMAc	(tm) ST Cross Assembler (Atari Corp)
;             XASM   st and IBM VERSIONS
;------------------------------------------------------------------------
com_file_name:		.macro
;			dc.b	12,"filename.ext",$9b
			dc.b	12,"Dis_bat.com ",$9b
			.endm

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $12
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the Month in dec	for the first time this revision 
;was compiled
;
c_month:		equ   8
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the day in dec	for the first time this revision 
;was compiled
c_day:			equ   28
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the year in dec	for the first time this revision 
;was compiled
c_year:			equ   2012
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Type of compiler used in program
;
; 0 = unknown Compiler
; 1 = xasm
; 2 = mac_65
; 3 = basic
; 4 = compiled basic	xl
; 5 = C65
; 6 = Action
;
; We can add more as time goes on!
;
;
xasm:			equ	1
mac_65:			equ	2 
basic:			equ	3
basicxl:		equ	4
c65:			equ	5
action:			equ	6

file_compiler:		equ	xasm
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; is this relocatable code ?
; anyother value other than 1 or 2 would be unknown
r..yes:			equ	1
r..no:			equ	2
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Gotta	define if it can be relocated
l_relocatable:		equ	r..no
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Gotta define if it can be relocated
r..crl:			equ	$7d
r..crlf:		equ	$9b
r..space:		equ	$20

l_frstscreenbyte:	equ	r..space
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; The language the output file is in. 
;
;
; 0	=	Undifined
; 1	=	English
; 2	=	German
;
r..language:		equ	1

;        System Equates
;----------------------------
;
; $04



			.include	equates
			.include	globals
			.include	macros

			.org  $4000
;
win_start:
header_info:
			.include	header			; this reads info out of the header and displays to screen
;
start:
			lda	#$60				; Loading an rts in the accumlator
			sta	header_start			; Storing the rts at the begining of the file

			jsr	os_off				; turn the os off for a sec
			lda	int.dis_bat
			sta	hold.data
			jsr	os_on

			lda	hold.data
			cmp	#$60
			beq	.aa

;			jsr	os_off
;			mea	tsr,s_ptr			; gonna check aginst the tsr bytes
;			lda	#dis_bat			; Has dis_bat mode on?
;			jsr	seclvl 				; call routing checking 
;			bmi 	.init				; Nope! dis_bat mode is off
;
;
;			jsr	os_on				; Turning the OS back on


			jmp	turn_on_bat
	 		jmp	turnoff_dis_bat			; Yeap! dis_bat mode is on

.init:
			jsr	os_on
			jmp	turn_on_bat
;---------------------------------------------------
;this places the location of the E:handler that does 
;batch files to be enable and work
;---------------------------------------------------
.aa:
turnoff_dis_bat:

			LDY	#0
.a:			LDA	$031a,Y
			CMP	#'E'
			BEQ	.b
			INY
			INY
			INY
			BNE	.a
.b:
			sty	.temp
			jsr	os_off
			ldy	.temp			

			lda	$031a+1,Y
			sta	int.dis_bat
			lda	$031a+2,Y
			sta	int.dis_bat+1

			LDA	# low $e400
			STA	$031a+1,Y
			LDA	# high $E400
			STA	$031a+2,Y

			mea	tsr,s_ptr
			lda	#dis_bat
			jsr	setlvl
			jsr	os_on


			jsr	printsi
			dc.b	$9b,$9b
			dc.b	" RealDos Batch Processor is now",$9b,$9b
			dc.b	" Turned "
			dc.b	<+128>,"OFF"
			dc.b	$9b,$9b
			dc.b	-1
			RTS

.temp:			dc.b	0
hold.data:		dc.b	0
;


turn_on_bat:
			LDY	#0
.a:			LDA	$031a,Y
			CMP	#'E'
			BEQ	.b
			INY
			INY
			INY
			BNE	.a
.b:
			sty	.temp
			jsr	os_off
			ldy	.temp			
			lda	int.dis_bat
			sta	$031a+1,Y
			lda	int.dis_bat+1
			sta	$031a+2,Y

			lda	#$60
			sta	int.dis_bat
			lda	#$00
			sta	int.dis_bat+1

			mea	tsr,s_ptr
			lda	#dis_bat
			jsr	clrlvl
			jsr	os_on

			jsr	printsi
			dc.b	$9b,$9b
			dc.b	" RealDos Batch Processor is now",$9b,$9b
			dc.b	" Turned "
			dc.b	<+128>,"ON"
			dc.b	$9b,$9b
			dc.b	-1
			RTS

.temp:			dc.b	0





;     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set_handler:
			jsr	os_off
			mea	tsr,s_ptr
			lda	#dis_bat
			jsr	setlvl
			jsr	os_on
			rts

;     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clear_handler:
			jsr	os_off
			mea	tsr,s_ptr
			lda	#dis_bat
			jsr	clrlvl
			jsr	os_on
			rts






;--------------------------------------------
;printsi Routeen macro             
;this is a slow print to the screen
;usage jsr	printsi
;    .byte $9b," string to be printed",$ff
;--------------------------------------------
;
printsi:
			pla
			sta	.pstr+1
			pla
			sta	.pstr+2
.prsl:			inc	.pstr+1
			bne	.pstr
			inc	.pstr+2
.pstr:			lda	$ffff
			cmp	#$ff
			beq	.estri
			jsr	fast_output
			jmp	.prsl
.estri:			lda	.pstr+2
			pha
			lda	.pstr+1
			pha
			rts
;
;	

;
;-------------------------
;actual screen handler    
;screen offset definitions
;-------------------------
scr_offset:
			dc.w	0
			dc.w	40
			dc.w	80
			dc.w	120
			dc.w	160
			dc.w	200
			dc.w	240
			dc.w	280
			dc.w	320
			dc.w	360
			dc.w	400
			dc.w	440
			dc.w	480
			dc.w	520
			dc.w	560
			dc.w	600
			dc.w	640
			dc.w	680
			dc.w	720
			dc.w	760
			dc.w	800
			dc.w	840
			dc.w	880
			dc.w	920
;
fast_output:
			sta	$5a
			lda	sc.redirect
			cmp	#print_p
			beq	.go_cio
.leo:
			lda 	$02ff   	; CONTROL 1 FLAG
			cmp 	#$00
			bne 	.leo

			lda	$5a
			cmp	#32
			bcc	.do_look
			cmp	#125
			bcc	.do_here
.do_look:		ldy	#0
.lookup:		lda	.char_table,y
			beq	.do_here
			cmp	$5a
			beq	.go_cio
			iny
			bne	.lookup


.go_cio:		lda	$5a
			jmp	putlocal


.do_here:		ldy	#0
			lda	$5d
			sta	($5e),y
			lda	$5a
			cmp	#$9b
			beq	.docr
.notcr:			jsr	.get_adr
			lda	$5a
			and	#$7f
			cmp	#32
			bcc	.add64
			cmp	#96
			bcc	.sub32
			jmp	.asis
.add64:			clc
			adc	#64
			jmp	.asis
.sub32:			sec
			sbc	#32
.asis:			bit	$5a
			bpl	.xxlate
			ora	#$80
.xxlate:		ldy	#0
			sta	($5e),y
			inc	$55
			inc	$63
			lda	$55
			cmp	#40
			bcs	.next_row
			iny
			lda	($5e),y
			sta	$5d
			ora	#$80
			ldx	752
			bne	.nocurs1
			sta	($5e),y
.nocurs1:		inc	$5e
			bne	.nooav
			inc	$5e+1
.nooav:			rts
.docr:			lda	#0
			sta	$63
.next_row:		lda	$52
			sta	$55
			inc	$54
			ldy	$54
			cpy	#24
			bcs	.scroll
			jsr	.get_adr
			ldy	#0
			lda	($5e),y
			sta	$5d
			ldx	752
			bne	.nocurs2
			ora	#$80
			sta	($5e),y
.nocurs2:		rts

.scroll:		dec	$54
			lda	$58
			sta	$68
			clc
			adc	#40
			sta	$5e
			lda	$58+1
			sta	$68+1
			adc	#0
			sta	$5e+1
			ldy	#0
			ldx	#3
.scloop:		lda	($5e),y
			sta	($68),y
			iny
			bne	.scloop
			inc	$5e+1
			inc	$68+1
			dex
			bne	.scloop
.scloop2:		lda	($5e),y
			sta	($68),y
			iny
			cpy	#152
			bcc	.scloop2
			lda	$58
			clc
			adc	#920&$ff
			sta	$5e
			lda	$58+1
			adc	#920/256
			sta	$5e+1
			ldy	#0
			tya
.clear:			sta	($5e),y
			iny
			cpy	#40
			bcc	.clear
			ldx	752
			bne	.nocurs3
			lda	#$80
			ldy	$55
			sta	($5e),y
.nocurs3:		lda	#0
			sta	$5d
			lda	$5e
			clc
			adc	$55
			sta	$5e
			lda	$5e+1
			adc	#0
			sta	$5e+1
			rts
.get_adr:		lda	$54
			asl
			tay
			lda	$58
			clc
			adc	scr_offset,y
			sta	$5e
			lda	$58+1
			adc	scr_offset+1,y
			sta	$5e+1
			lda	$5e
			clc
			adc	$55
			sta	$5e
			lda	$5e+1
			adc	#0
			sta	$5e+1
			rts
.char_table:
			dc.b	27,28,29,30,31,125,126,127
			dc.b	156,157,158,159,253,254,255,0


putlocal:
			ldx	#11
			stx	$0342
			ldx	#0
			stx	$0348
			stx	$0349
			jmp	$e456
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;   OS on and off ROUTEEN
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;

os_off:
			SEI	
			LDA	PORTB
			AND	#$FE
			STA	PORTB
			CLI	
			RTS	
;
os_on:
			SEI	
			LDA	PORTB
			ORA	#1
			STA	PORTB
			CLI	
			RTS	

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;checks user security level pointed to by S_PTR to see if the
;bit specified in the A register is ON.  Returns MInus if the
;user doesn't have the specified security level.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

seclvl:	    		sty	.tempy
			stx	.tempx
			cmp	#0			;sec lvl of zero?
			beq	.passed			;yes..they have it
			tay				;-1 for shifting
			lda	#128
			sta	.temp			;initialize mask
			lda	#0
			sta	.temp+1
			sta	.temp+2
			sta	.temp+3
			dey
			beq	.mask			;if it was one, no need to shift
.shloop:	   	lsr	.temp			;shift bits down to form mask
			ror	.temp+1
			ror	.temp+2
			ror	.temp+3
			dey
			bne	.shloop
			ldy	#0
.mask:			lda	.temp,y			;now, AND off all the bits
			and	(s_ptr),y
			sta	.temp,y
			iny
			cpy	#4
			bne	.mask
.check:			lda	.temp			;next, OR all the bytes...if any one
			ora	.temp+1			; is > 0, then they passed (whew!)
			ora	.temp+2
			ora	.temp+3
			cmp	#0
			beq	.failed
.passed:	   	lda	#0
			beq	.return
.failed:	   	lda	#$80
.return:	   	php
			ldy	.tempy
			ldx	.tempx
			plp
			rts

.tempy:	    		dc.b    0
.tempx:	    		dc.b    0
.temp:			dc.b    0,0,0,0


;     sets the bit specified (in the A register) of the security
;     level pointed to by S_PTR to a TRUE value.
;     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

setlvl:			sty	.tempy
			stx	.tempx
			cmp	#0			;sec lvl of zero?
			beq	.return			;yes..just exit (shouldn't happen!)
			tay				 ;-1 for shifting
			lda	#128
			sta	.temp			;initialize mask
			lda	#0
			sta	.temp+1
			sta	.temp+2
			sta	.temp+3
			dey
			beq	.mask			;if it was one, no need to shift
.shloop:	   	lsr	.temp			;shift bits down to form mask
			ror	.temp+1
			ror	.temp+2
			ror	.temp+3
			dey
			bne	.shloop
			ldy	#0
.mask:			lda	.temp,y			;now, OR the bit on
			ora	(s_ptr),y
			sta	(s_ptr),y
			iny
			cpy	#4
			bne	.mask
.return:	   	rts

.tempy:			dc.b    0
.tempx:			dc.b    0
.temp:			dc.b    0,0,0,0




;     CLEARS the bit specified (in the A register) of the
;     security level pointed to by S_PTR to a FALSE value.
;     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

clrlvl:         sty     .tempy
                stx     .tempx
                cmp     #0              ;sec lvl of zero?
                beq     .return         ;yes..just exit (shouldn't happen!)
                tay                     ;-1 for shifting
                lda     #128
                sta     .temp           ;initialize mask
                lda     #0
                sta     .temp+1
                sta     .temp+2
                sta     .temp+3
                dey
                beq     .mask           ;if it was one, no need to shift
.shloop:        lsr     .temp           ;shift bits down to form mask
                ror     .temp+1
                ror     .temp+2
                ror     .temp+3
                dey
                bne     .shloop
                ldy     #0
.mask:          lda     .temp,y         ;now, XOR the bit low
                eor     #$ff
                sta     .temp,y
                iny
                cpy     #4
                bne     .mask
                ldy     #0
.low:           lda     .temp,y         ;now, AND the bit low
                and     (s_ptr),y
                sta     (s_ptr),y
                iny
                cpy     #4
                bne     .low
.return:        rts

.tempy:         dc.b    0
.tempx:         dc.b    0
.temp:          dc.b    0,0,0,0





;
win_end:		ds.b	0
;
;
			ds.b	0
;
;
