;------------------------------------------------------------------------
;       (General DOS formatter for real.dos v1.0 
;
;		Copyright 2005 Intergrated Logic Systems
;                  Source Code is Copyright Stephen J. Carden
;  Please do not share this source!
;------------------------------------------------------------------------
;                         Real.dos xinit.COM
;			This program is to replace
;		      		xinit.com
;
;	Code History.     Init design,   August 10, 2005
;			  last updated 9/11/2005	sjc
;			  working on it again 10/09/2005 sjc
;			  fixed the boot sector stuff 10/14/2005
;	Added percom table
;	added header section and debug code for multi language  5/20/2010 sjc
;
;
;       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;------------------------------------------------------------------------
; 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,"Xinit.com   ",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $13
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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   16
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 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..yes
;
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Gotta define if it so I can print what I need
r..crl:			equ	$7d
r..crlf:		equ	$9b
r..space:		equ	$20
r..supress:		equ	-1

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

DRIVE:    	equ   DUNIT


		.include	equates
		.include	globals
		.include	macros
;
;
		.org	$3600 
;
win_start:
header_info:
		.include	header		; this reads info out of the header and	displays to screen
	 	jmp	START_IT  		;did this for debug


		.org	$4000

Split:
;###############################################################################
;
;       ==================== 
;       Stage 1 boot program 
;       ==================== 
;

initz1:
;
BOOTS:
		dc.b	$00
		dc.b	$03
		dc.b	$00
		dc.b	$30
		cpx	#$07
w01:		jmp	LOADER
;
l4009:
		dc.w	0
		dc.w	0
		dc.w	0
		dc.b	0
		dc.w	4
		dc.w	0
		dc.w	0
		dc.b	"        "
		dc.b	0
DENLOA:		dc.b	0
		dc.b	$20
		dc.b	6
		dc.b	1
		dc.b	-1
		dc.b	-1
		dc.b	0
		dc.b	0
		dc.b	0
FIRMAP:		dc.w	0
		dc.b	$00
		dc.b	$00
		dc.b	$00
		dc.w	0
		dc.b	$00


NODMSG:		dc.b	"Error: No DOS",$9b
; 
; 
;       get next sector map.. initz new map # 
;       ------------------------------------- 
; 

LOANM:
w02:		lda	FIRMAP
		sta	SECTOR
w03:		lda	FIRMAP+1
		sta	SECTOR+1
		lda	# low secmap
		ldx	# high secmap
w04:		jsr	READS
		lda	secmap
w05:		sta	FIRMAP
		lda	secmap+1
w06:		sta	FIRMAP+1
		ldy	#4
		sty	SECPTR
; 
;       get next sector number.. 
;       ------------------------ 
; 

GNXSEC:		ldy	SECPTR
w07:		cpy	DENLOA
		beq	LOANM
		lda	secmap,Y
		sta	SECTOR
		lda	secmap+1,Y
		sta	SECTOR+1
		INY
		INY
		sty	SECPTR
LRTS:		RTS
;
DOINITZ:	jmp	($2e2)
;
l407c:
		dc.b	0
		dc.b	0
		dc.b	0
		dc.b	0

LOADER:		ldx	#0
w08:		lda	DENLOA 				; set ahead sector map ptr.. 
		sta	SECPTR 				;  to max val.. force map load 
		sta	CHPTR  				;  to max val.. force data load 
		sta	DBYTLO 				; set sector size accordingly 
		bne	ISX
		INX
ISX:		stx	DBYTHI 				; set sector length high
w09:		jsr	GETBYTE				; get FF FF header 
		sta	temp
w10:		jsr	GETBYTE
		and	temp
		cmp	#$FF
		bne	TYPER				; Not binary file error
BEGIN:
lb_1:		lda	# low LRTS			; null initz 
		sta	INITAD
hb_1:		lda	# high LRTS
		sta	INITAD+1
w11:		jsr	GETBYTE
		sta	buf				; get start address 
w12:		jsr	GETBYTE
		sta	buf+1
		ora	buf
		beq	STAD				; a header of zero indicates end..
w13:		jsr	GETBYTE
		SEC
		sbc	buf				; calc number of bytes
		PHA
		PHP
w14:		jsr	GETBYTE
		PLP
		sbc	buf+1
		sta	LENG+1				; set total size-1 
		PLA
		sta	LENG

w15:		jsr	LOABUF				;  and	load buffer.. 
w16:		jsr	DOINITZ				; repeat for next segment 
w17:		jmp	BEGIN				; do start.. 
;
STAD:		jmp	($2e0)
;
; 
; 
;       error.. no DOS on diskette 
;       -------------------------- 
; 
TYPER:
lb_2:		lda	# low NODMSG
hb_2:		ldx	# high NODMSG
		sta	ICBAL
		stx	ICBAH
		stx	ICBLL
		lda	#9
		sta	ICCOM
		ldx	#0
		jsr	CIO

FOREV:
w18:      	jmp	FOREV				; endless loop 
;
; 
; 
;       read sector at address 
;       ---------------------- 
; 
READS:
		ldy	#$40   				; read data sector at XA
		sty	DSTATS
		sta	DBUFLO
		stx	DBUFHI 				; note command	is $52 ('R')
		lda	SECTOR
		ora	SECTOR+1
		beq	TYPER  				; if sector zero.. then error
		jsr	SIO    				; use $E459 sio address.. 
		bmi	TYPER  				; if error.. say no DOS 
		RTS
; 
; 
;       get byte/burst routine 
;       ---------------------- 
;
;
GETBYTE:
		lda	#0
		sta	LENG+1
		sta	LENG

GETBYT:		ldx	CHPTR  				; get ptr to next char to load 
w19:		cpx	DENLOA 				; check if at end.. 
		beq	LOANS  				;  if so, load next sector
		lda	datbuf,X
		inc	CHPTR
		RTS
;
; 
; 
;       Load next sector in buffer/ or burst if possible 
;       ------------------------------------------------ 
; 
LOANS:
w20:		jsr	GNXSEC 				; get next sector # 
		lda	LENG+1 				; check if to do burst
		bne	OKBUR
w21:		lda	DENLOA
		beq	NOBUR
		lda	LENG
		bmi	OKBUR  				; if >127, then burst it 

NOBUR:		lda	#low datbuf
		ldx	#high datbuf
w22:		jsr	READS  				; read sector into data buffer.. 
		SEC
		rol	CHPTR  				; put 1 into char ptr 
		lda	datbuf 				; get first char..
		RTS
;
; 
;       Do burst read sector 
;       -------------------- 
; 
OKBUR:		lda	buf    				; get address of where to load 
		ldx	buf+1
w23:		jsr	READS  				; read into correct place 
		lda	buf    				; add length of sector.. 
		CLC
		adc	DBYTLO
		sta	buf
		lda	buf+1
		adc	DBYTHI
		sta	buf+1
		SEC        				; subtract from length
		lda	LENG
		sbc	DBYTLO
		sta	LENG
		lda	LENG+1
		sbc	DBYTHI
		sta	LENG+1
w24:		jmp	LOANS  				; go load next sector
;
; 
; 
;       Load entire buffer from file 
;       ---------------------------- 
; 

LOABUFX:	lda	LENG   				; decrement length
		bne	NOB
		dec	LENG+1
NOB:		dec	LENG


LOABUF:
w25:		jsr	GETBYT 				; get byte.. 
		ldy	#0
		sta	(buf),Y
		inc	buf
		bne	SK11
		inc	buf+1
SK11:		lda	LENG
		ora	LENG+1
		bne	LOABUFX
		RTS
		brk

zend1:		ds.b	0


BOOTI:    =   SPLIT  					; location of boot sectors

; 
;
; 
		.org  $5000
;========================================= 
;       Beginning and	initialization 
;========================================= 
; 
START_IT:
		jsr	rlocate
BEGINI:		lda	COMTAB 				; calc address of SIO 
		SEC 
		sbc	# low lsio
		sta	XSIO+1
		lda	COMTAB+1
		sbc	# high lsio
		sta	XSIO+2
		jmp	FORMAT
XSIO:		jmp	(0)
;
;================================== 
;       Main parameter input 
;================================== 
FORMAT:		TSX 
		STX	STACKP
		jsr	end_of_header-3


START:
; 
; 
; GET DRIVE FOR DIRECTORY 
; 
		LDA	COMTAB 				; get address of CRUNCH routine 
		CLC 
		ADC	# low ZCRNAME
		STA	JVC+1
		LDA	COMTAB+1
		ADC	# high ZCRNAME
		STA	JVC+2
JVC:		JSR	$00    				; all that is of interest is the 
;                              				;  device spec.. 
; 
		LDY	#$21   				; Do directory of .DOS files 
MVNA:		LDA	(COMTAB),Y
		STA	FSPEC-$21,Y
		INY 
		CPY	#$24
		BNE	MVNA
; 
; 
; DO DIRECTORY FOR .DOS FILES 
; --------------------------- 
DODIR:		LDA	#0     				; zero directory ptrs.. 
		STA	DOSP
		STA	DIRP

		lDX	#$10
		lda	#3
		sta	ICCOM,X
		lda	# low FSPEC
		sta	ICBAL,X
		lda	# high FSPEC
		sta	ICBAH,X
		lda	#6
		sta	ICAX1,X
		lda	#0
		sta	ICAX2,X
		jsr	CIO
		bpl	OKO
; 
ERROR:		jsr	printsi
		dc.b	$9B,"Error #",-1
		TYA 
		jsr	ECHO_HEX
		jsr	printsi
		dc.b	" - Format Aborted..",$9B,-1
RETURN:		ldx	STACKP
		TXS 
CLOSE:		lda	#CCCLOS				; close IOCB #1 just in case 
		ldx	#$10
		sta	ICCOM,X
		jsr	CIO
		RTS 
; 
OKO:		lda	#5     				; get record 
		ldx	#$10
		sta	ICCOM,X
		lda	# low ENTRY
		sta	ICBAL,X
		lda	# high ENTRY
		sta	ICBAH,X
		lda	#40
		sta	ICBLL,X
		jsr	CIO
		bmi	ERROR
;        
		lda	ENTRY  				; at end of directory if 
		cmp	#'0'           			;  free sector count 
		bcs	XDIR
; 
		ldy	DIRP   				; get ptr to entry 
		ldx	DOSP    			; ptr to entry in ptr table 
		TYA 
		sta	DOSPT,X
		INX 
		stx	DOSP
; 
		ldx	#2     				; name to DOS names 
MVNA1:		lda	ENTRY,X
		cmp	#$20
		beq	ATED
		cpx	#10
		beq	ATED
		sta	NAMES,Y
		INX 
		INY 
		bne	MVNA1
; 
ATED:		ldx	#0     				; move .DOS extension 
MVNA2:		lda	EXTN,X
		sta	NAMES,Y
		INY 
		INX 
		cpx	#5
		bne	MVNA2
		sty	DIRP   				; save ptr into names 
		jmp	OKO
; 
XDIR:		jsr	CLOSE  				; close directory 
; 
		lda	DOSP   				; # of .DOS files 
		bne	SOME
		ldx	#-1
		stx	CURP
		jsr	printsi
		dc.b	"No "
		dc.b	$22,"DOS",$22
		dc.b	" Files Found on Diskette...",$9B,$9B,-1
; 
		jmp	CONTIN
; 
;  GET DOS IMAGE SELECTION 
; ------------------------ 
SOME:		ldx	#0
		jsr	printsi
		dc.b	"Select Your DOS Version:",$9B,$9B,-1
SAP:		stx	COUNT  				; get ptr into names.. 
		ldy	DOSPT,X
		jsr	printsi
		dc.b	"   ",-1
		INX 
		TXA        				; print choice number 
		jsr	PRNIB  				;  print low nibble 
		jsr	printsi
		dc.b	")  ",-1
LPCH:		lda	NAMES,Y				; print chars in name until 
		cmp	#'.'           			;  '.' is encountered.. 
		beq	ENAN
		jsr	ECHO
		INY 
		bne	LPCH
ENAN:		jsr	printsi
		dc.b	$9B,-1
		ldx	COUNT
		INX        				; get next file name 
		cpx	DOSP
		bne	SAP
; 
		jsr	printsi
		dc.b	"   N)  -No DOS-",$9B
		dc.b	$9B,"Choice ? ",-1
LPN:		jsr	INCH
		cmp	#'N' 
		bne	CKNUM
		ldx	#-1
		stx	CURP
		bne	SHOWN
CKNUM:		cmp	#'1' 
		bcc	LPN
		sbc	#'1' 
		cmp	DOSP
		bcs	LPN
		sta	CURP
		adc	#'1' 
SHOWN:		jsr	ECHO
		jsr	printsi
		dc.b	$9B,$9B,-1
; 
; READ DOS IMAGE 
; 
CONTIN:		bit	CURP
		bmi	NOREA  				; if 'none' then do not read.. 
; 
		ldx	CURP   				; get ptr to file name 
		ldy	DOSPT,X
		ldx	#0
MVNAM3:		lda	NAMES,Y
		sta	DOSI+3,X
		cmp	#$9B
		beq	ATE2
		INX 
		INY 
		bne	MVNAM3
ATE2:		ldx	#3-1
MVNAM4:		lda	FSPEC,X				; move drive number to DOSI 
		sta	DOSI,X
		DEX 
		bpl	MVNAM4
; 
		lda	#3     				; open file... 
		ldx	#$10
		sta	ICCOM,X
		lda	# low DOSI
		sta	ICBAL,X
		lda	# high DOSI
		sta	ICBAH,X
		lda	#4
		sta	ICAX1,X				; open for input 
		jsr	CIO    				; ax2 need not be set since no run vector 
		bpl	OKRD2
ERJX1:		jmp	ERROR
; 
OKRD2:		lda	#CCGTCH				; read characters 
		sta	ICCOM,X
		lda	# low TABLE			; put DOS at table 
		sta	ICBAL,X
		lda	# high TABLE
		sta	ICBAH,X
		lda	#128   				; 32k???? 
		sta	ICBLL,X
		sta	ICBLH,X
		jsr	CIO
		cpy	#$88
		bne	ERJX1
		lda	ICBLL,X				; GET ACTUAL LENGTH 
		sta	TABLEN
		lda	ICBLH,X
		sta	TABLEN+1
; 
		jsr	CLOSE  				; close file.. 
; 
NOREA:		ldy	#60+1
		lda	# low INIT
		sta	(COMTAB),Y
		INY 
		lda	# high INIT
		sta	(COMTAB),Y
; 
; 
; 
; GET DRIVE TO FORMAT 
; -------------------- 
INIT:		TSX 
		stx	STACKP
;
.a:		nop
		nop
		nop
		lda	#$20
		sta	.a
		lda	#low end_of_header-3
		sta	.a+1
 		lda	#high end_of_header-3
		sta	.a+2
 
		jsr	printsi 			; drive to format 
		dc.b	$9B,$9B,"Drive to format ? ",-1
		jsr	INDRIV
		sbc	#47				; change ascii to hex $01->$09
		sta	DUNIT				; save in drive unit 
; 
; 
; 
; GET TRACKS/SIDES 
; 
		jsr	printsi
		dc.b	$9B,"Select number of tracks:",$9B,$9B
		dc.b	" 1) 40 trks/SS   5) 40 trks/DS",$9B
		dc.b	" 2) 77 trks/SS   6) 77 trks/DS",$9B
		dc.b	" 3) 80 trks/SS   7) 80 trks/DS",$9B
		dc.b	" 4) 35 trks/SS   8) 35 trks/DS",$9B
;		dc.b	" 9) Format ramdisk 512",$9b
		dc.b	$9B,"Choice ? ",-1
REIN:		jsr	INCH
		cmp	#'1' 
		bcc	REIN
		cmp	#'9'+1				; gonna do 9 drives now 
		bcs	REIN
		jsr	ECHO
		and	#15
		TAX 
		DEX 
		lda	TRKST,X				; get number of tracks 
		sta	TRACKS
		ldy	#0
		and	#$7F
		cmp	#77
		bne	PVAL
		DEY 
PVAL:		sty	INCH8
; 
		TXA        				; get track index * 6 
		ASL
		sta	TRKINX
		ASL
		adc	TRKINX
		sta	TRKINX
; 
; 
; GET DENSITY/LENGTH/#SECTORS 
; 
		jsr	printsi
		dc.b	$9B,$9B,"Select density:",$9B,$9B
		dc.b	" 1) Single density",$9B
		dc.b	" 2) Double density",$9B,-1
		bit	INCH8
		bmi	NO1050
		jsr	printsi
		dc.b	" 3) 1050 double density",$9B,-1
NO1050:		jsr	printsi
		dc.b	$9B,"Choice ? ",-1
REIN2:		jsr	INCH
		cmp	#'1' 
		bcc	REIN2
		cmp	#'4' 
		bcs	REIN2
		bit	INCH8
		bpl	OKCH2
		cmp	#'3' 
		beq	REIN2
OKCH2:		jsr	ECHO
		and	#7
		sta	DENINX
		TAX 
		bit	INCH8
		bmi	GET8V
; 
		lda	LEN5T-1,X			; get bytes/sector 
		sta	DENSITY
		lda	DEN5T-1,X			; get density flag 4/0 
		sta	DENS
		lda	SEC5T-1,X
		sta	SECTORS
		bne	CON
; 
GET8V:		lda	LEN8T-1,X			; get bytes/sector 
		sta	DENSITY
		lda	DEN8T-1,X			; get density flag 6/2 
		sta	DENS
		lda	SEC8T-1,X
		sta	SECTORS
; 
CON:		DEX 
		TXA 
		ASL
		adc	TRKINX
		TAX        				; get dens*2 + trks*6 
		lda	MAXST,X
		sta	MAXSEC
		lda	MAXST+1,X
		sta	MAXSEC+1
; 
; 
; GET VOLUME NAME 
; 
GETVOL:		jsr	printsi
		dc.b	$9B,$9B,"Volume Name ? ",-1
		ldy	#8
		lda	#BMD+SDVOL
		ldx	# high BOOTI
		jsr	GETLINE
; 
; 
; SEE IF TO FORMAT IN 'US' 
; 
OKVOL:		jsr	printsi
		dc.b	$9B,$9B,"UltraSpeed Sector Skew (Doubler)? ",-1
		jsr	INYN
		ror	US     				; us<0 if NO ultra speed 
; 
; 
; SEE IF OTHER HIGH SPEED SKEW 
		bit	US
		bpl	ISUS1
		jsr	printsi
		dc.b	$9B,"Indus or XF551 High Speed Skew ?  ",-1
		jsr	INYN
		ror	HIGHSP
ISUS1:
; FORMAT DISKETTE 
; 
		jsr	printsi
		dc.b	$9B,"Insert Diskette to Format,",$9B
		dc.b	"Press <RETURN> When Ready.. ",$9B,-1
		jsr	INCH
; 
; 
		jsr	printsi
		dc.b	$9B,$9B,"Formatting...",-1
; 
		lda	# low FMTBUF
		sta	DBUFLO
		lda	# high FMTBUF
		sta	DBUFHI
		lda	#$31
		sta	DDEVIC
; 
		lda	#'S' 
		sta	DCOMND
		lda	#$40
		sta	DSTATS 				; get status (determines the baud rate 
		lda	#4     				;  for the drive we are using) 
		sta	DBYTLO
		lda	#0
		sta	DBYTHI
		jsr	XSIO
; 
		lda	#'N'           			; get config command	
		sta	DCOMND
		lda	#$40
		sta	DSTATS
		lda	#12
		sta	DBYTLO
		lda	#0
		sta	DBYTHI
		jsr	XSIO
		bmi	NOTCONF				; jump if 810 or 1050 
; 
		lda	#'O' 
		ldx	#12
		bit	US
		bmi	SETTY  				; jump if to send config 
		lda	#'f' 
		ldx	#128   				; no US.. just give config 
; 
SETTY:		sta	DCOMND 				; setup for configure command	
		stx	DBYTLO 				;  or format command	if UltraSpeed 
		lda	#0
		sta	DBYTHI
		lda	#$80
		sta	DSTATS
; 
		lda	TRACKS 				; set number of tracks 
		and	#$7F
		sta	FMTBUF+0
		lda	SECTORS				; set number of sectors 
		sta	FMTBUF+3
		ldx	#0
		lda	DENSITY
		sta	FMTBUF+7			; set sector length 
		bmi	ISSN
		ldx	#1
ISSN:		stx	FMTBUF+6
		lda	DENS   				; set density/type bits 
		sta	FMTBUF+5
		lda	TRACKS
		and	#$80
		ASL
		ROL
		sta	FMTBUF+4			; set number of sides 
; 
		ldx	DENINX 				; get index into density table 
		DEX 
		TXA 
		ASL      				; set up ultraspeed sector 
		TAX        				;  layout 
		lda	ORDT,X
		sta	GVAL+1
		lda	ORDT+1,X
		sta	GVAL+2
		ldx	#0
GVAL:		lda	$FFFF,X
		sta	FMTBUF+12,X
		INX 
		cpx	#26
		bne	GVAL
; 
		bit	US     				; check if just sending format.. 
		bpl	FMTWRM 				; jump if this does the format 
		jsr	XSIO   				; send Config 
		bpl	STDFMT 				;  jump to format 
		jmp	ERROR
; 
NOTCONF:	lda	#$FF   				; can't run high speed 
		sta	HIGHSP
		bit	US     				; check if supposed to write UltraSpeed 
		bmi	NOUS
		jsr	printsi
		dc.b	$9B,"Drive Cannot Run UltraSpeed..",$9B,-1
; 
NOUS:		lda	DENINX
		cmp	#3
		bne	STDFMT
		ldx	#$22   				; 1050 format command	
		dc.b	$2C
STDFMT:		ldx	#$21
		bit	HIGHSP
		bmi	STD2   				; jump if not high speed... 
		ldx	#$A1
STD2:		stx	DCOMND
; 
		ldx	DENSITY
		stx	DBYTLO
		lda	#0
		cpx	#0
		bne	LLK
		lda	#1
LLK:		sta	DBYTHI
		lda	#$40
		sta	DSTATS
		lda	#4
		sta	SECTOR
		lda	#0
		sta	SECTOR+1
; 
FMTWRM:		lda	#$F8
		sta	DTIMLO
; 
NOSPEC:		jsr	XSIO
		bpl	OKFMT2 				; jump if format is OK 
XERR:		jmp	ERROR
; 
OKFMT2:		jsr	RECALC 				; calculate all data area positions 
		jsr	WRITE  				; write all setup sectors 
; 
		bit	CURP   				; check if to write DOS 
		bmi	NOMS1
		jsr	printsi
		dc.b	$9B,$9B,"Writing your DOS Selection!",-1
;
		lda	#CCOPEN
		ldx	#$10
		sta	ICCOM,X
		lda	# low DOSI
		sta	ICBAL,X
		lda	# high DOSI
		sta	ICBAH,X
		lda	dunit
;
		adc	#48
		sta	DOSI+1
		lda	#8
		sta	ICAX1,X
		jsr	CIO    				; open file for write 
		bpl	WRTDN
JERX2:		jmp	ERROR
; 
WRTDN:		lda	#CCPUCH				; put chars.. 
		sta	ICCOM,X
		lda	# low TABLE
		sta	ICBAL,X
		lda	# high TABLE
		sta	ICBAH,X
		lda	TABLEN
		sta	ICBLL,X
		lda	TABLEN+1
		sta	ICBLH,X
		jsr	CIO    				; write file... 
		bmi	JERX2
		jsr	CLOSE  				; close file... 
; 
NOMS1:		jsr	printsi
		dc.b	$9B,$9B,"Diskette Initialized...",$9B
		dc.b	"Press <RETURN> to Continue ",-1
		jsr	INCH
		jmp	INIT   				; continue warm 
; 
;
;
;================================ 
;       Input subroutines 
;================================ 
; 
;       Get drive number 
;       ---------------- 
; 
INDRIV:		jsr	INCH
		cmp	#'1' 
		bcc	INDRIV
		cmp	#'9'+1    			;'9'+1 this is where we add drive 9
		bcs	INDRIV
		jsr	ECHO
		jsr	printsi
		dc.b	$9B,-1
		RTS 
; 
; 
;       Get YES/NO responce.. CS if NO 
;       ------------------------------ 
; 
INYN:		jsr	INCH
		cmp	#'Y' 
		beq	YES
		cmp	#'y' 
		beq	YES
		cmp	#'N' 
		beq	NO
		cmp	#'n' 
		bne	INYN
NO:		jsr	printsi
		dc.b	"N",$9B,-1
		SEC 
		RTS 
YES:		jsr	printsi
		dc.b	"Y",$9B,-1
		CLC 
		RTS 
; 
; 
;       Input character with escape processing 
;       -------------------------------------- 
; 
INCH:		jsr	GET_KEY
		cmp	#27
		beq	EXI
		RTS 
EXI:		jmp	RETURN
; 
; 
; 
;================================= 
;       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
; 
; 
; 
;       Print byte 
;       ---------- 
; in: 
;       A       = byte to print 
; out: 
;       all registers preserved 
; 
ECHO_HEX:	jsr	SAVER
		jsr	ZOUTBYT
		jmp	RESALL
; 
ZOUTBYT:	PHA 
		LSR
		LSR
		LSR
		LSR
		jsr	ZOB
		PLA 
ZOB:		and	#$0F
		ora	#$30
		cmp	#$3A
		bcc	ZKKKK
		adc	#6
ZKKKK:		jsr	ECHO
		RTS 
; 
; 
; 
;       Print low nibble 
;       ---------------- 
; in: 
;       A       = nibble to print 
; out: 
;       all registers preserved 
; 
PRNIB:		jsr	SAVER
		jsr	ZOB
		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 
; 
; 
; 
;       Get character 
;       ------------- 
; out: 
;       A       = character (all others preserved) 
; 
GET_KEY:	jsr	ZGETCH
ZCH:		lda	#0
		RTS 
; 
ZGETCH:		jsr	SAVER
		jsr	ZPHG
		sta	ZCH+1
		jmp	RESALL
; 
ZPHG:		lda	$E425
		PHA 
		lda	$E424
		PHA 
		RTS 
; 
; 
; 
;       Get line 
;       -------- 
; in: 
;       XA      = buffer address 
;       Y       = maximum number of characters 
; out: 
;       @XA     = data, return ends input, a backspace works 
;       all registers preserved 
; notes: 
;       This routine will first clear the input window 
; 
GETLINE:	jsr	SAVER
		sty	ZCNT
		sta	ZSTOR+1
		stx	ZSTOR+2
; 
		ldy	#0
		lda	#$20
ZCLX:		jsr	ZSTOR
		INY 
		cpy	ZCNT
		bne	ZCLX
; 
		ldy	#0
ZINLP:		jsr	GET_KEY
		cmp	#$7E
		beq	ZBS
		cmp	#$9B
		beq	ZENDZ
		cpy	ZCNT
		beq	ZINLP
		jsr	ECHO
		jsr	ZSTOR
		INY 
		bne	ZINLP
; 
ZBS:		cpy	#0
		beq	ZINLP
		jsr	ECHO
		DEY 
		lda	#$20
		jsr	ZSTOR
		bne	ZINLP
ZENDZ:		jmp	RESALL
; 
ZSTOR:		sta	$FFFF,Y
		RTS 
ZCNT:		dc.b	0
; 
; 
;========================================= 
;       write/calculate diskette data 
;========================================= 
;       Write all data to disk 
;       ---------------------- 
WRITE:		ldx	#1     				; Write out all sectors 
		stx	SECTOR
		DEX 
		stx	SECTOR+1			; begin at sector 1 
; 
		ldx	# high BOOTI
		ldy	# low BOOTI
		lda	#3
		jsr	WRBLOCK				; write boot program 
; 
		ldy	BOOTI+BMD+SDQBM			; # bitmap sectors 
		sty	TEMPQX
; 
		lda	DATASEC				; Zero beginning of bit	map 
		LSR
		LSR
		LSR
		TAX 
		stx	TEMPQX+1
		lda	DATASEC
		and	#7
		TAY 
		lda	MASK,Y
		EOR #$FF
; 
CLFIR:		sta	BITMAP,X
		lda	#0
		DEX 
		bpl	CLFIR
; 
		ldx	TEMPQX+1
		INX 
		dc.b	$2C
; 
NXB:		ldx	#0     				; clear bit	map 
		lda	#$FF
SEA:		sta	BITMAP,X
		INX 
		bne	SEA
; 
		ldy	TEMPQX 				; if not last, then use as is 
		DEY 
		bne	WRBITX
; 
		ldx	NIBOFF 				; offset into nibble of last sector # 
		lda	MASK,X
		ldx	BYTOFF
CLREST:		sta	BITMAP,X			; clear out end 
		lda	#0
		INX 
		bne	CLREST
; 
WRBITX:		lda	#1     				; write one bitmap sector 
		ldx	# high BITMAP
		ldy	# low BITMAP
		jsr	WRBLOCK
		dec	TEMPQX
		bne	NXB
; 
		lda	#0
		TAX 
CLMAPS:		sta	SCMAP,X				; Clear sector map and	data sector 
		sta	DATSEC,X
		INX 
		bne	CLMAPS
; 
		ldx	BOOTI+MDD			; Sector map # of main directory 
		INX 
		stx	SCMAP+4				; Put data sector # into sector map 
		lda	#1
		ldx	# high SCMAP			; Write sector map 
		ldy	# low SCMAP
		jsr	WRBLOCK
; 
		ldx	#11-1  				; Put directory name into data sector 
MVNAM:		lda	NAMTAB,X
		sta	DATSEC+DEFNAM,X
		DEX 
		bpl	MVNAM
		lda	#DESSUB+DESUSE
		sta	DATSEC+DESTA
		lda	#DDEX
		sta	DATSEC+DENBYT
		lda	#1
		ldx	# high DATSEC
		ldy	# low DATSEC
		jmp	WRBLOCK				; Write directory sector 
; 
; 
;       Write a block of sectors 
;       ------------------------ 
; 
WRBLOCK:	stx	DBUFHI 				; address 
		sta	NUMSECS				; number sectors to save 
		sty	DBUFLO
; 
		lda	DENSITY				; get density 
		ldx	SECTOR+1
		bne	ISTHD
		ldx	SECTOR
		cpx	#4
		bcs	ISTHD
		lda	#$80
ISTHD:		sta	DBYTLO
		ldx	#0
		TAY 
		bne	ISSNG
		ldx	#1
ISSNG:		stx	DBYTHI
; 
REPOUT:		lda	#'P'           			; Assume blocks all same density 
		sta	DCOMND
		lda	#$80
		sta	DSTATS
		jsr	XSIO
		bpl	OKWRTX
		jmp	ERROR
; 
OKWRTX:		inc	SECTOR
		bne	SK1
		inc	SECTOR+1
; 
SK1:		CLC 
		lda	DBUFLO
		adc	DBYTLO
		sta	DBUFLO
		lda	DBUFHI
		adc	DBYTHI
		sta	DBUFHI
; 
		dec	NUMSECS
		bne	REPOUT
		RTS 
; 
; 
MASK:		dc.b	$00,$80,$C0,$E0
		dc.b	$F0,$F8,$FC,$FE,$FF
; 
NAMTAB:		dc.b	"MAIN       "
; 
; 
;       Calculate all sector positions for given density 
;       ------------------------------------------------ 
; 
RECALC:		lda	MAXSEC 				; Get last sector # 
		sta	TEMPQX
		lda	MAXSEC+1
		sta	TEMPQX+1
; 
		lda	#0
		ldx	#3     				; divide by 8 for # of bms 
REPROL:		LSR	tempqx+1 
		ror	TEMPQX
		ROR
		DEX 
		bne	REPROL
		LSR
		LSR
		LSR
		LSR
		LSR
		sta	NIBOFF 				; Offset into byte 
; 
		lda	TEMPQX
		ldx	TEMPQX+1			; Get # of bit	maps and	offset into last 
; 
		bit	DENSITY
		bpl	G2
		ASL
		PHA 
		TXA 
		ROL
		TAX 
		PLA 
		LSR
; 
G2:		sta	BYTOFF
		INX 
		stx	BOOTI+BMD+SDQBM			; # bit	map sectors 
		TXA 
		CLC 
		adc	#4     				; Add to bit	map sector to get first 
		sta	BOOTI+MDD			;  sector map sector 
		adc	#2     				; Get first data sector # 
		sta	DATASEC
		sta	BOOTI+BMD+SDDIR			; Free sector scan start (direct) 
		adc	#30    				; leave lots of room for dirs 
		sta	BOOTI+BMD+SDALLOC		; Free sec scan (data sec) 
		bit	CURP   				; check if to make this zero 
		bpl	ISSOMD
		lda	#0     				; zero indicates no DOS 
ISSOMD:		and	#$F8   				; IMPORTANT... DOS starts at a block 
;		                     			;  when doing alloc search 
		sta	BOOTI+EXTR+DDMAP		; Start DOS sector # 
; 
		SEC 
		lda	MAXSEC 				; # sectors total & free 
		sta	BOOTI+BMD+SDTOT
		sbc	DATASEC
		sta	BOOTI+BMD+SDFRE
		lda	MAXSEC+1
		sta	BOOTI+BMD+SDTOT+1
		sbc	#0
		sta	BOOTI+BMD+SDFRE+1
		lda	DENSITY				; set density & tracks 
		sta	BOOTI+DPD+SPDEN
		lda	TRACKS
		sta	BOOTI+DPD+SPTRK
; 
		lda	$D20A  				; get random number 
		sta	BOOTI+EXTR+DRAND
		RTS 
; 
; 
; 
;=========================== 
;       data storage 
;=========================== 
; 
FSPEC:			dc.b	"D1:*"
EXTN:			dc.b	".DOS",$9B
; 
MAXST:			dc.w	40*18,40*18,40*26			; sectors per disk table 
			dc.w	77*26,77*26,0
			dc.w	80*18,80*18,80*26
			dc.w	35*18,35*18,35*26
			dc.w	40*18*2,40*18*2,40*26*2
			dc.w	77*26*2,77*26*2,0
			dc.w	80*18*2,80*18*2,80*26*2
			dc.w	35*18*2,35*18*2,35*26*2
;
;	added for ramdisks
;			dc.w	32*128,32*128,32*128
; 
LEN8T:			dc.b	128,256					; <256	; 8 inch bytes/sector
DEN8T:			dc.b	2,6  					; density/drive flag 
SEC8T:			dc.b	26,26					; sectors/track 
; 
LEN5T:			dc.b	128,256,128				; <256,128  5 inch bytes per sector
DEN5T:			dc.b	0,4,4					; density/drive flag 
SEC5T:			dc.b	18,18,26				; sectors/track 
; 
TRKST:			dc.b	40,77,80,35
			dc.b	40+128,77+128,80+128,35+128
;			dc.b	32					; added for 512k ramdisk
; 
ORDT:			dc.w	SD18,DD18,DD26				; table of HS layouts 
SD18:			dc.b	$04,$08,$0C,$10,$01,$05,$09,$0D,$11
			dc.b	$02,$06,$0A,$0E,$12,$03,$07,$0B,$0F

DD18:			dc.b	$01,$0E,$09,$04,$11,$0C,$07,$02,$0F
			dc.b	$0A,$05,$12,$0D,$08,$03,$10,$0B,$06

DD26:			dc.b	$04,$08,$0C,$10,$14,$18,$01,$05,$09
			dc.b	$0D,$11,$15,$19,$02,$06,$0A,$0E,$12
			dc.b	$16,$1A,$03,$07,$0B,$0F,$13,$17
; 
; 

DENSITY:		ds.b	1      				; bytes per sector 
SECTORS:		ds.b	1      				; number of sectors per track 
MAXSEC:			ds.b	2      				; total number of sectors 
DENS:			ds.b	1      				; drive type/density flag 
; 
INCH8:			ds.b	1      				; eight inch drive flag, -1=true 
TRACKS:			ds.b	1      				; number of tracks on disk (B7=DS) 
TRKINX:			ds.b	1      				; index into trkst 
DENINX:			ds.b	1      				; density index 
; 
COUNT:			ds.b	1      				; general counter.. 
STACKP:			ds.b	1      				; return stack ptr 
CURP:			ds.b	1      				; current DOS image ptr 
DOSP:			ds.b	1      				; current # of .DOS files 
DOSPT:			ds.b	10     				; space for 10 ptrs into names 
DIRP:			ds.b	1      				; current ptr into names 
NAMES:			ds.b	130
ENTRY:			ds.b	25     				; area for reading entries 
DOSI:			ds.b	3+8+5  				; room for Dn:fname.DOS 
US:			ds.b	1
HIGHSP:			ds.b	1
; 
DATASEC:		ds.b	1      				; Beginning of data sectors 
TEMPQX:			ds.b	2
BYTOFF:			ds.b	1
NIBOFF:			ds.b	1
NUMSECS:		ds.b	1      				; Number sectors to write 
TABLEN:			ds.b	2      				; length of DOS file... 
; 
FMTBUF:			ds.b	256    				; buffer for format data 
BITMAP:			ds.b	256    				; bitmap buffer 
SCMAP:			ds.b	256    				; sector map buffer 
DATSEC:			ds.b	256    				; first directory sector 
TABLE:			ds.b	256    				; area to load DOS file 
; 
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Ok the relocation marker is to tell the DOS we are now using
;more data at memlow..  
;
;
initz:			dc.b	0				; start address


zend:			dc.b	0				;end address

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
;                        *** END OF HANDLER ***
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
;
;       Relocater: main entry
;       ---------------------
; in:
;       segtab  = table of segment descriptors
;               +00 = relocater table address
;               +02 = originate address of block
;               +04 = destination originate of block
;               +06 = address of block
;               +08 = number of bytes in block
;               +10 = destination address of block
;		+12 = Length of segment descriptor
;		+14 = this is the word location addjust memory

;
;
;
;
;       reltab  = relocater table
;               list of address of words to adjust      2 bytes each entry
;               list of address low bytes to adjust     2 bytes each entry
;               list of address high bytes to adjust    3 bytes each entry
;                       followed by their low bytes
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rlocate:

         	lda	segtab+segaddress		; setting some stuff up for the relocator
        	sta	segtab+dorgadr			; Passing Stuff to the relocator
	      	sta	segtab+blkdes			; Passing Stuff to the relocator
	     	lda	segtab+segaddress+1		; setting some stuff up for the relocator
         	sta	segtab+dorgadr+1		; Passing Stuff to the relocator
         	sta	segtab+blkdes+1			; Passing Stuff to the relocator
;         	jsr	rlocate				; ok do relocation of code!!!!!!!



		lda	#0				; set ptr to segment 0
		sta	segment

segloop:	ldx	segment
		lda	segtab+rettad,x 		; get address of relocater table
		sta	relget+1
		lda	segtab+rettad+1,x
		sta	relget+2
		ora	relget+1			; if zero, then end of segtab
		bne	havseg
		rts

havseg:		sec					; calculate offset to add to segment
		lda	segtab+dorgadr,x
		sbc	segtab+orgadr,x
		sta	zoffset
		lda	segtab+dorgadr+1,x
		sbc	segtab+orgadr+1,x
		sta	zoffset+1

zwordlp:	jsr	getzwp
		beq	zlbytlp				; if zero, go adjust low bytes

		lda	(zwptr),y			; add offset to address
		clc
		adc	zoffset
		sta	(zwptr),y
		iny
		lda	(zwptr),y
		adc	zoffset+1
		sta	(zwptr),y
		jmp	zwordlp

zlbytlp:	jsr	getzwp				; get address
		beq	zhbytlp				; if zero, then adjust high bytes

		lda	(zwptr),y
		clc
		adc	zoffset
		sta	(zwptr),y
		jmp	zlbytlp

zhbytlp:	jsr	getzwp				; get address
		beq	zmovlp				; jump if end of table

		jsr	relget				; get low byte
		clc
		adc	zoffset
		lda	(zwptr),y
		adc	zoffset+1
		sta	(zwptr),y
		jmp	zhbytlp
		rts

zmovlp:

		lda	segment+segmove			; gonna check the memover
		cmp	#seg_off			; $ff we quit subroutein
		bne	.zmovlp				; most of been something other than ff do mem move
		rts					; ok time to exit subroutien 	
.zmovlp:	ldx	segment				; get block start and	to address
		lda	segtab+blkadr,x
		sta	zmovfr+1
		lda	segtab+blkadr+1,x
		sta	zmovfr+2

		lda	segtab+blkdes,x
		sta	zmovto+1
		lda	segtab+blkdes+1,x
		sta	zmovto+2

							; get # pages to move
		ldy	segtab+blkbyt+1,x

		ldx	#0
zmovfr:		lda	$ffff,x
zmovto:		sta	$ffff,x
		inx
		bne	zmovfr
		inc	zmovfr+2
		inc	zmovto+2
		dey
		bpl	zmovfr				; move even # pages, so may move up to 256;;
							;  bytes more than neede;d
		lda	segment
		clc
		adc	#seglen				; go to next segment
		sta	segment
		jmp	segloop


relget:		lda	$ffff
		inc	relget+1
		bne	nc1
		inc	relget+2
nc1:		rts

getzwp:		jsr	relget				; top of word adjust loop
		sta	zwptr				; save address of word
		jsr	relget
		ldy	#0
		sta	zwptr+1
		ora	zwptr				; check if at end
		rts

segment:	dc.b	0				; current segment
zoffset:	dc.w	0				; offset to add to addresses
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
;		      Relocation data table
;       	      ---------------------
;		We resolve Word locations First!
;
;	Things like	lda	$5000
;			sta	$5000
;			lda	$5000,y
;			jsr	$5000
;			jmp	$5000
;
;	Well you get the Idea..
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
; $3000  tabel
;
rtable1:
		dc.w	w01+1
		dc.w	w02+1
		dc.w	w03+1
		dc.w	w04+1
		dc.w	w05+1
		dc.w	w06+1
		dc.w	w07+1
		dc.w	w08+1
		dc.w	w09+1
		dc.w	w10+1

		dc.w	w11+1
		dc.w	w12+1
		dc.w	w13+1
		dc.w	w14+1
		dc.w	w15+1
		dc.w	w16+1
		dc.w	w17+1
		dc.w	w18+1
		dc.w	w19+1
		dc.w	w20+1

		dc.w	w21+1
		dc.w	w22+1
		dc.w	w23+1
		dc.w	w24+1
		dc.w	w25+1


		dc.w	0				; ok done with this part
;
;
;Ok these are low Byte Locations..  only one byte changed!!
;   OK Resolving Low Byte's First
;
		dc.w	lb_1+1
		dc.w	lb_2+1
		dc.w	0				; ok done with this part
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;Now to resolve High Bytes...... Only one byte to change!
; Here is what is needed...  location of high byte in .word format
; Second thing needed is the low byte of the address you are wishing
;to adjust!
;
		dc.w	hb_1+1
		dc.b	LRTS
		dc.w	hb_2+1
		dc.b	NODMSG

		dc.w	0				; ok we are done
		dc.b	0				; ok we are done



;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;End of relocation Table!!!
;master table:
;
segtab:
		dc.w	rtable1				; address of relocater table
		dc.w	initz1				; assembly start address
		dc.w	0	     			; relocate to address (filled in)
		dc.w	initz1		 		; absolute start address of block
		dc.w	zend1-initz1     		; size of block
		dc.w	0	     			; destination of block (filled in)
		dc.w	0       			; END of segments
		dc.w	$3000				;segaddress memory to adgust by.
		dc.b	seg_off				; -1 meand	do not mem move


win_end:	ds.b	0
;
;