;------------------------------------------------------------------------
;		Copyright 2010 Integrated Logic Systems
;                  Source Code is Copyright Stephen J. Carden
;
;
;			Please do not share this source!
;------------------------------------------------------------------------
;                             S2Utime.com.com
;
;
;  
; **********************
; **                  **
; ** SPARTA DOS TIME  **
; **   UTILITY FOR    **
; **     SIO2USB      **
; ** (C) 2008 ABBUC   **
; ** LICENSE: GPLv3   **
; **                  **
; ** P: C. Strotmann  **
; ** H: T. Grasel     **
; **    H. Reminder   **
; **    E. Puetz      **
; **                  **
; ** VERSION 1.00     **
; **                  **
; **********************
;
;
;       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;------------------------------------------------------------------------
; 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   13,"filename.ext",$9b
			dc.b   12,"S2Utime.com ",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $11
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the Month in dec for the first time this revision 
;was compiled
;
c_month:		equ   9
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the day in dec for the first time this revision 
;was compiled
c_day:			equ   1
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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
;
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
r..crl:			equ	$7d
r..crlf:		equ	$9b
r..space:		equ	$20
r..bypassdos:		equ	$15	; bypass dos check
r..supress:		equ	$ff

l_frstscreenbyte:	equ	r..bypassdos
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; The language the output file is in. 
;
;
; 0	=	Undifined
; 1	=	English
; 2	=	German
;
r..language:		equ	1
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ZPF0:			equ	$F0
ZPF1:			equ	ZPF0+1
SDBASE:			equ	$700
SDDEV:			equ	$761
SDDATE:			equ	$77B
SDTIME:			equ	SDDATE+3
EDITRV:			equ	$E400


			.include	equates
			.include	globals
			.include	macros

			.org  $5000

win_start:
header_info:
			.include	header			; this reads info out of the header and displays to screen
;								; based on info stored at the front of the file
peekabyte:
;------------------------------
START:
			lda	#$60
			sta	start
			jsr	COUTINIT
;			jsr	BANNER
			jsr	GETTIME
			bmi	SIOERROR
			jsr	TESTDATA
			jsr	SETTIME
			jmp	EXIT
;------------------------------
ERRORMSG:
			jsr	PRINT
			dc.b	$FD 			; Beep
			dc.b	"Error: "
			dc.b	$EA
			RTS
;------------------------------
SIOERROR:
			jsr	ERRORMSG
			jsr	PRINT
			dc.b	"during SIO Communication"
			dc.b	$EA
			jmp	EEXIT
;------------------------------
DATAERROR:
			jsr	ERRORMSG
			jsr	PRINT
			dc.b	"wrong or incomplete data recieved"
			dc.b	$EA
			jmp	EEXIT
;------------------------------
EEXIT:
			jsr	PRINT
			dc.b	$9B
			dc.b	"Date/Time not set!"
			dc.b	$9B,$EA
			jmp	TODOS
;------------------------------
;BANNER:
;			jsr	PRINT
;			dc.b	"SIO2USB DATE/TIME UTILITY v1.0"
;			dc.b	$9B
;			dc.b	"(C) 2008 ABBUC/RAF"
;			dc.b	$9B,$EA
;			RTS
;------------------------------
;DETECTDOS:
;			ldy	#0
;			lda	SDBASE,Y
;			cmp	#'S'
;			bne	ISREAL
;			INY
;			INY
;			INY
;			lda	SDBASE,Y
;			cmp	#'B'
;			beq	BEWEDOS
; IS ORIGINAL SPARTADOS
;			jsr	PRINT
;			dc.b	"Sparta DOS"
;			dc.b	$EA
;			jsr	DETECTED
;			jmp	SETTIME
;BEWEDOS:
;			jsr	PRINT
;			dc.b	"BW-DOS"
;			dc.b	$EA
;			jsr	DETECTED
;			jsr	PRINT
;			dc.b	$9B,$EA
;			jmp	SETTIMEBW
;ISREAL:
;			cmp	#'R'
;			bne	NOSPARTA


;			jsr	PRINT
;			dc.b	"REALDOS"
;			dc.b	$EA
;			jsr	PRINT
;			dc.b	" detected"
;			dc.b	$EA
;			jmp	SETTIME
;NOSPARTA:
;			jsr	PRINT
;			dc.b	"No SPARTA compatible DOS"
;			dc.b	$EA
;			jsr	DETECTED
;			lda	#$9B
;			jsr	COUT
;			jmp	EEXIT
;------------------------------
;DETECTED:
;			RTS
;------------------------------
COUTINIT:
			ldy	#$1E
.1:			lda	HATABS,Y
			cmp	#'E'
			beq	.3
			DEY
			DEY
			DEY
			bpl	.1
			jmp	.2
.3:			lda	HATABS+1,Y
			sta	ZPF0
			lda	HATABS+2,Y
			sta	ZPF1
			ldy	#7
			lda	(ZPF0),Y
			sta	COUT2+1
			DEY
			lda	(ZPF0),Y
			sta	COUT1+1
.2:			RTS
;------------------------------
COUT:
			TAX
COUT2:			lda	#$F2
			PHA
COUT1:			lda	#$AF
			PHA
			TXA
			RTS
;------------------------------
PRINT:
			PLA
			sta	ZPF0
			PLA
			sta	ZPF1
.1:			inc	ZPF0
			bne	.2
			inc	ZPF1
.2:			ldx	#0
			lda	(ZPF0,X)
			cmp	#$EA
			beq	.3
			jsr	COUT
			jmp	.1
.3:			jmp	(ZPF0)
;------------------------------
;ISXL:
;			ldy	#$1B
;			lda	(DOSVEC),Y
;			cmp	#$FF
;			beq	.1
;			jsr	PRINT
;			dc.b	" under ROM (XL/XE)"
;			dc.b	$9B,$EA
;			CLC
;			RTS
;
;.1:			jsr	PRINT
;			dc.b	" in main RAM"
;			dc.b	$9B,$EA
;			SEC
;			RTS
;------------------------------
GETTIME:
			ldx	#$0B
.1:			lda	READRTC,X
			sta	DDEVIC,X
			DEX
			bpl	.1
			jmp	SIOV
;------------------------------
TESTDATA:
			lda	su2.buf
			cmp	#6
			bne	.3
			lda	su2.buf+7
			cmp	#$FF
			beq	.2
.3:			jmp	DATAERROR
; CONVERT BCD -> DEC
.2:			ldx	#5
.1:			lda	su2.buf+1,X
			AND	#$F0
			LSR
			LSR
			sta	ZPF0
			LSR
			adc	ZPF0
			SBC	su2.buf+1,X
			EOR	#$FF
			sta	su2.buf+1,X
			DEX
			bpl	.1
;
			ldx	#2
			ldy	#$0F
.4:			lda	su2.buf+4,X
			sta	(DOSVEC),Y
			DEY
			DEX
			bpl	.4
;
			ldy	#$10
			lda	su2.buf+3
			sta	(DOSVEC),Y
			INY
			lda	su2.buf+2
			sta	(DOSVEC),Y
			INY
			lda	su2.buf+1
			sta	(DOSVEC),Y
			RTS
;------------------------------
SETTIME:
;			jsr	ISXL
			lda	PORTB
			PHA
			AND	#$FE
			sta	PORTB
			jsr	VSETTD	
			PLA
			sta	PORTB
			RTS
;------------------------------
SETTIMEBW:
			jmp	($708)
; FALLTHROUGH
;------------------------------
EXIT:
			jsr	PRINT
			dc.b	"Date/Time set"
			dc.b	$9B,$EA
; FALLTHROUGH
;------------------------------
TODOS:
			jmp	(DOSVEC)
;------------------------------
READRTC:
			dc.b	$71,$00,$02,$40
			dc.w	su2.buf
			dc.b	$07,$00,$80,$00
;------------------------------
su2.buf:		dc.b	$00,$00,$00,$00
			dc.b	$00,$00,$00,$00
;------------------------------
Win_end:		ds.b	0
;
;