;------------------------------------------------------------------------
;		Copyright 2012 Integrated Logic Systems
;                  Source Code is Copyright Stephen J. Carden
;
;
;			Please do not share this source!
;------------------------------------------------------------------------
;                              SIO2SD.com
;
;This is a program that sends two text strings to the display of the SIO2SD
;		init	9/09/2012	sjc new design
;
;
;
;------------------------------------------------------------------------
; 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,"Sio2sd.com  ",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $10
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the Month in dec for the first time this revision 
;was compiled
;
c_month:		equ   10
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the day in dec for the first time this revision 
;was compiled
c_day:			equ   12
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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
r..bypassdos:		equ	$15	; bypass dos check
r..bpasintro:		equ	$ff


l_frstscreenbyte:	equ	r..crl
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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:

get_sector_count:
			LDA 	COMTAB  ; calc address of SIO 
			SEC 
			SBC 	# low lsio
			STA 	XSIO+1
			LDA 	COMTAB+1
			SBC 	# high lsio
			STA 	XSIO+2
			lda	#$6c
			sta	xsio

			lda	#$70
			sta	$300
			lda	#$03
			sta	$301
			lda	#$10				;$4e
			sta	$0302
			lda	#$80
			sta	$0303
			lda	# low real_data
			sta	$0304
			lda	# high real_data
			sta	$0305
			lda	#40
			sta	$0308
			lda	#$00
			sta	$0309
			lda	#0
			sta	$030a
			lda	#$00
			sta	$030b
			jsr	xsio
			lda	$303
			cmp	#$01
			bne	.error

			lda	#$70
			sta	$300
			lda	#$03
			sta	$301
			lda	#$10				;$4e
			sta	$0302
			lda	#$80
			sta	$0303
			lda	# low huh_data
			sta	$0304
			lda	# high huh_data
			sta	$0305
			lda	#40
			sta	$0308
			lda	#$00
			sta	$0309
			lda	#1
			sta	$030a
			lda	#$00
			sta	$030b
			jsr	xsio
			jmp	good_message
			rts
.error:
			jsr	printsi
			dc.b	$9b,$9b,$9b
			dc.b	"  Sio2SD "
			dc.b	<+128>,"Not Present"
			dc.b	$9b
			dc.b	-1
			jsr	driverror
			rts
good_message:
			jsr	printsi
			dc.b	$9b,$9b,$9b
			dc.b	"  Sio2SD "
			dc.b	<+128>,"Present!"
			dc.b	$9b
			dc.b	-1
			jsr	driverror
			rts
;
;
XSIO:			jMP	$ffff

driverror:
			pha
			jsr	printsi
			dc.b	$9b," Siov Error # ",$FF
			pla
			jsr	pr_byte
			jsr	printsi
			dc.b	$9b,-1
			rts

; 
pr_byte:
			ldx	#$00
pr_card:
			sta	$d4
			stx	$d4+1
			lda	#$00
			sta	$f2
			jsr	$d9aa
			jsr	$d8e6
			ldy	#$00
.a:
			lda	($f3),y
			php
			and	#$7f
			iny
			jsr	echo
			plp
			bpl	.a
			rts
; 
;================================= 
;       print/input routines 
;================================= 
; 
;       Print character 
;       --------------- 
; in: 
;       A       = character to print 
; out: 
;       all registers preserved 
; 
ECHO:     JSR SAVER
         JSR ZOUT
         JMP RESALL
; 
ZOUT:     STA ZTEMP+1
         LDA $0347
         PHA 
         LDA $0346
         PHA 
ZTEMP:    LDA #0
         LDX #0			;1      ; force NO output to PRINT Dn: 
         RTS 
; 
; 
;       Print text 
;       ---------- 
; out: 
;       all registers preserved 
; notes: 
;       This print routine will print all characters 
;       following the JSR PRINT until a delimiter of 
;       -1 ($FF) is reached. PRINT will return to the 
;       point one byte beyond the delimiter. 
; 
printsi:   JSR SAVER
         TSX 
         LDA $0105,X
         STA ZOCH+1
         LDA $0106,X
         STA ZOCH+2
; 
         LDY #1
ZOCH:     LDA $FFFF,Y
         CMP #$FF
         BEQ ZECHO
         JSR ECHO
         INY 
         BNE ZOCH
ZECHO:    TYA 
         CLC 
         ADC $0105,X
         STA $0105,X
         LDA $0106,X
         ADC #0
         STA $0106,X
         JMP RESALL
; 
; 
;       SAVE & RESTORE registers 
;       ------------------------ 
; 
SAVER:    PHP 
         PHA 
         PHA 
         PHA 
         PHP 
         PHA 
         TXA 
         PHA 
         TSX 
         LDA $0109,X
         STA $0105,X
         LDA $0107,X
         STA $0109,X
         LDA $0101,X
         STA $0107,X
         LDA $0108,X
         STA $0104,X
         LDA $0106,X
         STA $0108,X
         TYA 
         STA $0106,X
         PLA 
         TAX 
         PLA 
         PLP 
         RTS 
; 
RESALL:   PLA 
         TAY 
         PLA 
         TAX 
         PLA 
         PLP 
         RTS 
; 
; 
; 




real_data:		dc.b	"RealDos Build 30"
			ds.b	40
huh_data:		dc.b	"SIO2SD Detected!"
			ds.b	256

win_end:		ds.b	0
;
;
;