;------------------------------------------------------------------------
;		Copyright 2010 Integrated Logic Systems
;                  Source Code is Copyright Stephen J. Carden
;
;
;			Please do not share this source!
;------------------------------------------------------------------------
;                              Delay.com
;
;       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;------------------------------------------------------------------------
; 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
;------------------------------------------------------------------------
;
;		init design for "WASEO"	sjc
; added no parm will delay forever
; added "/q" for quiet will delay and not show anything to screen
; Added pal detection to alter the tic var.	6/13/2010	sjc
;
;	Updated the screen Print Utility so it will work with the exp-80
; This change will also help "Print P:"		6/19/2010	sjc
;
;
;
;
;
;
;=====================================================================
com_file_name:		.macro
;			dc.b	13,"filename.ext",$9b
			dc.b	12,"Delay.com   ",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $16
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the Month in dec for the first time this revision 
;was compiled
;
c_month:		equ   6
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the day in dec for the first time this revision 
;was compiled
c_day:			equ   19
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the year in dec for the first time this revision 
;was compiled
c_year:			equ   2010
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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
r..bypass:		equ	$ff
l_frstscreenbyte:	equ	r..bypass
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; The language the output file is in. 
;
;
; 0	=	Undifined
; 1	=	English
; 2	=	German
;
r..language:		equ	1
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


			.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:
			jsr	pal_ntsc			; Go set or time var 50 tics for pal 60 tics for ntsc
								; let'S see if anything is on the parm line
			ldy	#LBUF    			; loading the offset into comtab
mux_1a:			lda	(comtab),y
			cmp	#' '				; looking for the space in the parm line
			beq	mux_1b 				; got the space let'S see if there is anything we can use
			cmp	#$9b				; nope!!  no parm
			beq	.a				; let'S see if they are playing with the consol
			iny
			jmp	mux_1a
.a:			jmp	NO_number			; no parm delay forever

mux_1b:
			ldx	#$00
			iny					; let'S get one more byte of contab+63,y

.a:			lda	(comtab),y			; well got a byte
			jsr	upcase 				; let'S make sure it is upper case
			cmp	#'H'
			beq	.help				; going to the help menu
			cmp	#'?'
			beq	.help1				; going to the help menu
			cmp	#'B'				; batch files
			beq	.go_bat				; ok don't care about timer just do the
			cmp	#' '				; got another parm after timer value
			beq	.slash
			sta	mynumberstring,x
			cmp	#'0'     			; let'S see if it is between o and 9
			bcc	.oknum 				; less than 1
			cmp	#'9' +1
			bcs	.oknum				; greater than 9
			inx
			stx	.holdx
			iny
			jmp	.a

.help1:			jmp	mux_man1
.help:			jmp	mux_man3
.holdx:			dc.b	0
.go_bat:		jmp	go_bat

.slash:
			iny					; /
			iny
			lda	(comtab),y			; well got a byte
			jsr	upcase
			sta	scr_hold
			cmp	#'Q'				; this will supress header
			beq	.oknum1
.oknum:
			jsr	start-3				; intro out of .header

.oknum1:		ldx	.holdx
			inx
			lda	#$9b
			sta	mynumberstring,x

			jsr	get_number_cli
			sta	howlongtohold			; let's change the drive number in the bat string
			cmp	#$00
			bne	mux_1c
			jmp	NO_number			; the must be zero
			
mux_1c:
			lda	#$ff				; Trash any Key press
			sta	764				; and store it into the key buffer
			jsr	setup				; setup the screen
.a:
			lda	#consol_start			; JUST START KEY
			cmp	$d01f				; CONSOL KEY
			beq	mux_man1			; humm  they want to go strait to dos
			lda	#consol_option			; OPTION KEY
			cmp	$d01f				; CONSOL KEY
			beq	mux_man3			; YEP!!!  HELP MENU

			lda	764
			cmp	#$3f		;'A'
			beq	.abort
			cmp	#$7f
			beq	.abort
			cmp	#$ff
			bne	.out
			lda	howlongtohold
			cmp	reference
			beq	.out
			jsr	delay
			dec	howlongtohold
			jmp	.a

.abort:			jmp	$e474				; Process a reset to stop Batch file

.out:

			lda	#$ff				; got to eat the key show it isn't processed
			sta	764
			lda	#$00				; turning the cursor on
			sta	752				; this currsor location

			lda	scr_hold
			cmp	#'Q'
			beq	.exit

			jsr	printsi
			dc.b	$9b,$9b,$9b,-1
.exit:			rts 					; just a place holder for right now



go_bat:			jmp	mux_man2			; let'S load the batch file

mux_man3:		jmp	my_file_notice			; help menu

scr_hold:		dc.b	0

mux_man1:		jsr	bell				; Ooop'S they aborted the file
			jsr	printsi
			dc.b	$7d,$9b,$9b
			dc.b	" "
			dc.b	<+128>,""
			dc.b	$9B
			dc.b	" "
			dc.b	<+128>,"| Delay.com   Batch file timer   |"
			dc.b	$9B
			dc.b	" "
			dc.b	<+128>,"| Written by: Stephen J. Carden  |"
			dc.b	$9B
			dc.b	" "
			dc.b	<+128>,""
			dc.b	$9b,$9b
			dc.b	" Usage: Delay [Parm 1] [Parm 2]",$9b
			dc.b	" [Parm 1]= 1 to 255 Seconds",$9b
			dc.b	" No [Parm 1] = Wait for a key press",$9b
			dc.b	" 'Delay Seconds /q' = timed no text",$9b
			dc.b	" 'Delay 0 /q' Wait forever, no text",$9b
			dc.b	" 'Delay ? or H' = This menu",$9b
			dc.b	" 'Delay B Batch file -Dn:>delay.bat",$9b
			dc.b	" 'Delay B Batch -Dn:>DELAYCAR.BAT",$9b
			dc.b	$9B,$9B,$FF
			rts
setup:
			lda	scr_hold
			cmp	#'Q'
			beq	.a
			lda	#$01				; turning the cursor off
			sta	752				; this currsor location
			ldx     #2
			ldy     #20
			jsr	gotoxy
			jsr	printsi
			dc.b	$9b
			dc.b	$9b
			dc.b	" Number of Seconds in Delay ="
			dc.b	-1

.a:			rts
;
setup1:
			lda	scr_hold
			cmp	#'Q'
			beq	.a
			lda	#$01				; turning the cursor off
			sta	752				; this currsor location
			jsr	printsi
			dc.b	$9b
			dc.b	" Press any Key To Continue "
			dc.b	-1

.a:			rts
;

NO_number:
			lda	#$ff				; Trash any Key press
			sta	764				; and store it into the key buffer
			jsr	setup1				; setup the screen

.a:
			lda	#$06				; JUST START KEY
			cmp	$d01f				; CONSOL KEY
			beq	.mux_man1			; humm  they want to go strait to dos
			lda	#$03				; OPTION KEY
			cmp	$d01f				; CONSOL KEY
			beq	.mux_man3			; YEP!!!  HELP MENU

			lda	764
			cmp	#$3f		;'A'
			beq	.abort
			cmp	#$7f
			beq	.abort
			cmp	#$ff
			bne	.out
			jmp	.a

.abort:			jmp	$e474
.out:
			lda	#$ff				; got to eat the key show it isn't processed
			sta	764
			lda	#$00				; turning the cursor on
			sta	752				; this currsor location
			lda	scr_hold
			cmp	#'Q'
			beq	.exit

			jsr	printsi
			dc.b	$9b,-1
.exit:			rts 					; just a place holder for right now
;
.mux_man1:		jmp	mux_man1
.mux_man3:		jmp	mux_man3
;
;
;
;
count_in_seconds:

; prep the batch file
mux_man2:
			jsr	start-3				; intro out of .header
			lda	$6a
			cmp	#$a0
			beq	tat_12
			jsr	bat_load			;  let'S move the string to comtab+63
			dc.b	"-D"
			dc.b	"1:>delay.bat"
			dc.b	$9B,$FF
			jsr	line_process			;  well let'S turn this over to dos
			lda	#$0c
			sta	764
			rts
;-----------------------
;
tat_12:
			jsr	printsi
			dc.b	$9b,$9b," left Cartridge or Basic present",$9B,$FF
			jsr	bat_load
			dc.b	"-D"
			dc.b	"1:>DELAYCAR.BAT"
			dc.b	$9B,$FF
			jsr	line_process
			lda	#$0c
			sta	764
			rts
;
;
		
;-----------------------


gotoxy:			stx	85
			sty	84
			rts

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;Prints a byte or a card to the screen
pr_byte:
			ldx	#$00
pr_card:
			sta	fr0
			stx	fr0+1
			lda	#$00
			sta	cix
			sta	.bytecard
			jsr	ifp
			jsr	fasc
			ldy	#$00
.aprbloop:
			inc	.bytecard
			lda	($f3),y
			php
			and	#$7f
			sta	.bytecard+1,y
			iny
;			jsr	echo
			plp
			bpl	.aprbloop
			mea	.bytecard,pr_ptr
			jsr	echos
			rts

.bytecard:		ds.b	10


;
;  prints: prints string with address in PR_PTR, length byte in 0th byte
;  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

echos:
			ldy	#0
			lda	(pr_ptr),y		;get length to print
			beq	.xpri     		;exit, null string
			sta	.maxlth
			iny
			sty	.tempy

.pril:			ldy	.tempy
			lda	(pr_ptr),y
			cmp	#$00
			beq	.xpri
			jsr	echo
.prnext:		inc	.tempy
			dec	.maxlth
			bne	.pril
.xpri:			rts

.tempy:			dc.b	1
.maxlth:		dc.b    1



;
;       gets a BYTE value - returned in Accum
;       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

get_number_cli:
                	mea     mynumberstring,inbuff
                	lda     #0			;1
                	sta     cix
                	jsr     afp                     ;ascii --> floating pt.
                	bcs     .default
                	jsr     fpi                     ;floating --> integer
                	bcs     .default
                	lda     fr0+1                   ;enter > 255?
                	bne     .ovfl                   ;yes
                	lda     fr0
                	rts
.ovfl:          	lda     #255
               		rts
.default:       	lda     #0
                	rts

.work:          	ds.b    6

mynumberstring:		ds.b	255
;
;
howlongtohold:		dc.b	0

reference:		dc.b	0


;-----------------------
;
; Pause the computer for 1 second
;
;----------------------
delay:
			lda	scr_hold
			cmp	#'Q'
			beq	.q
			ldx     #31
			ldy     #22
			jsr	gotoxy
			jsr	printsi
			dc.b	"    ",-1

			ldx     #31
			ldy     #22
			jsr	gotoxy
			lda	howlongtohold
			jsr	pr_byte
.q:
			lda	#$00
			sta	$14
one_second:
			lda	764
			cmp	#$ff
			bne	d.out
seconds:		lda	#60
			cmp	$14
			bne	one_second
d.out:
			rts

;------------------------------------------------------------------
;checking for pal/ntsc machines
;
;
pal_ntsc:
			lda	$d014
			ora	#$f0 ; masking high order bytes
			cmp	#$ff ;
			beq	.ntsc
			bne	.pal
			rts
.ntsc:
			lda	#60
			sta	seconds+1
			RTS
.pal:
			lda	#50
			sta	seconds+1
			RTS


;
;-----------------------------
;this load'S a string into
;comtab+63. usage
; jsr	bat_load
; .byte "dx:>path>filename.ext",$9b,$ff
;-------------------------
;
bat_load:
			pla
			sta	bl+1
			pla
			sta	bl+2
			ldy	#LBUF-1
bprsl:
			iny
			inc	bl+1
			bne	bl
			inc	bl+2
bl:			lda	$ffff
			sta	(comtab),y
			cmp	#$ff
			beq	bestri
			jmp	bprsl
bestri:
			lda	bl+2
			pha
			lda	bl+1
			pha
			rts
;------------------------
;this turn's the content'S
;of contab+63 over to Dos
; to execute the program
;------------------------
;
line_process:
			lda	#$00
			ldy	#bufoff 			; offset for bufoff
			sta	(comtab),y			; comtab+10
			lda	$d301				; got to get under
			pha     				; the os the execute the
			and	#$fe				; the vxcomli
			sta	$d301
			jsr	$ffd2				; vxcomli
			pla
			sta	$d301
			rts
;
;
;
;---------------------------
;this one make's a nice tone
;---------------------------
bell
			sta	.data
			sty	.data+1
			stx	.data+2
			ldy	#$af
			lda	#$14
			sta	$d200
.a:			sty	$d201
			lda	#$00
			sta	$14
.b:			lda	$14
			cmp	#$02
			bcc	.b
			dey
			cpy	#$a0
			bcs	.a
			lda	.data
			ldy	.data+1
			ldx	.data+2
			rts
.data:			dc.b	$00,$00,$00
;
;
;
;----------------------------------
;printsi Routeen macro      
;this is a slow print to the screen
;usage jsr	printsi
;    .byte $9b," string to be printed",$ff
;----------------------------------
;
printsi:		pla
			sta	$b0
			pla
			sta	$b1
			ldy	#$01
.a:			lda	($b0),y
			cmp	#$ff
			beq	.b
			jsr	sprint
			jsr	.c
			jmp	.a
.b:			jsr	.c
			lda	$b1
			pha
			lda	$b0
			pha
			rts
.c:			inc	$b0
			bne	.d
			inc	$b1
.d:			rts
;
;
;------------
; PRINT BYTE 
;------------
echo:
sprint:
			ldx	#11
			stx	$0342
			ldx	#0
			stx	$0348
			stx	$0349
			jmp	$e456

;------------------------------
;   GET KEY  ROUTEEN           
;this routeen get's one key and
;return it to the accumlator   
;------------------------------
;
getkey:			stx	$b6
			sty	$b7
			jsr	.a
			ldx	$b6
			ldy	$b7
			rts
.a:			lda	$e420+5
			pha
			lda	$e420+4
			pha
			rts
;
;-----------------------------
;CHANGES THE CHARTER TO UPCASE
;-----------------------------
upcase
			cmp	#$61
			bcc	.a
			cmp	#$7a
			bcs	.a
			sbc	#$1f
.a:			rts
;
;-----------------------------
;CHANGES THE CHARTER TO LOCASE
;-----------------------------
locase
			cmp	#$41
			bcc	.a
			cmp	#$5a
			bcs	.a
			adc	#$1f
.a:			rts
;
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;   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	


;--------------
;  help menu section
;--------------
help_menu:
my_file_notice:

			.include	notice

			rts

win_end:
			ds.b	0
