;BOOTA.68K	JUN-30-88
;Apex bootstrap for the Amiga computer.
;Written by Loren Blaney
;
;REVISION HISTORY:
;FEB-13-87, Original, converted from Stride bootstrap (BOOT.68K).
;MAY-16-87, Initialize all memory to zero.
;JUN-88, Remove bit plane initialization.
;
;This code resides in the first three blocks (two sectors) of the boot
; disk. The Amiga boot PROM reads the first sector from the disk,
; verifies that it says: "KICK", and then reads the next 256K bytes and
; loads them starting at $FC0000. It then starts this program which
; initializes the Amiga hardware, moves RESCOD.SYS into its proper
; places in memory and starts it. RESCOD.SYS, in turn, reads in
; SYSTEM.SYS (APEX.XPL) and starts it.
;
;This code is installed by using LOAD and WRITE. First make sure that
; the unit to be installed onto is not in a sub directory.
;
; LOAD BOOTA
;	CHANGE DEFAULTS (Y/N)? Y
;	XPL EXECUTION BASE ADDRESS?		$0
;	MINIMUM EXECUTION ADDRESS?		$FBFE00
;	MAXIMUM EXECUTION ADDRESS?		$FC00FF
;	LOAD LOCATION OF MINIMUM ADDRESS?	$8000
;	CHANGE DEFAULTS (Y/N)? N
;	(CTRL-C)
;
; WRITE
;	UNIT? 0
;	BLOCK? 0
;	BUFFER? $8000
;	SIZE (BLOCKS)? 3
;
;The boot boot (the real boot in real ROM) does not copy the two blocks
; containing "KICK" into RAM. Hence the RAM disk appears to start at
; FBFE00 (= FC0000 - 200). The RAM disk is 1024 blocks long, and it
; actually contains blocks 2-1025. In practice only blocks 9-1023 are
; used.
;
;	DISK	RAM	CONTENTS
;	0	-	KICK
;	1	-	0
;	2	FC0000	BOOTA
;	3	FC0100	0
;	4-8	FC0200	unused
;	9-12	FC0700	directory
;	13-16	FC0B00	backup directory
;	17-1023	FC0F00	normal file space
;	1024	FFFE00	extra block
;	1025	FFFF00	extra block
;
;
MEMTOP	EQU	$80000		;Highest memory address +1
VSTART	EQU	$0400		;Start location for RESCOD

CIAA	EQU	$BFE001		;Base address of 8520-A chip
;Offsets to CIA registers:
PRA	EQU	$0		;Peripheral Data Register A
DDRA	EQU	$200		;Data Direction Register A

CHIPREG	EQU	$DFF000		;Base address of chip registers
;Offsets to chip registers:
DMACON	EQU	$96		;DMA control
INTENA	EQU	$9A		;Interrupt enable bits
INTREQ	EQU	$9C		;Interrupt request bits

;-----------------------------------------------------------------------
;Move RESCOD.SYS to its correct locations.
; RESCOD.SYS starts in block 17 which got loaded at 17 *256 + $FC0000
;  = $FC1100
;
	ORG	$FBFE00		;Amiga's boot wants to see "KICK" on
	ASCII	'KICK'		; the first sector of the disk
	DCB.B	512-4,0		;Fill the rest of the sector with zeros

	ORG	$FC0000		;Amiga's boot enters at $FC0002
	DC.W	$1111		; (?)

START	JMP	START2.L	;Amiga boot requires a JMP here
	ASCII	"Apex, V1.8, (c) Jun-15-88 P.J.R. Boyle"

START2	LEA	MEMTOP.L,SP	;Set the stack in the designated loc

	MOVE.L	#$20000,D0	;Kill some time (because ROM Kernal does
BT10	SUBQ.L	#1,D0		; it)
	BGT.S	BT10

	LEA	CIAA.L,A4
	MOVE.B	#$03,DDRA(A4)	;Set bits 0 & 1 as outputs
	MOVE.B	#$02,PRA(A4)	;Overlay = 0 (off), LED = dim

	LEA	CHIPREG.L,A4
	MOVE.W	#$7FFF,D6	;Disable all bits
	MOVE.W	D6,INTENA(A4)	;Clear all interrupt enable bits
	MOVE.W	D6,INTREQ(A4)	;Clear all interrupt requests
	MOVE.W	D6,DMACON(A4)	;Disable all DMA channels

	ORI	#$0700,SR	;Disable interrupts

	LEA	-4(SP),A6	;Initialize all memory to zero
	MOVEQ	#0,D0
BT20	MOVE.L	D0,(A6)
	SUBQ.L	#4,A6		;(Does not set condition codes)
	CMPA.L	#0,A6
	BGE.S	BT20

;Move low part of RESCOD:
	LEA	$FC0F00.L,A6	;Set "from" address
	LEA	$0000,A5	;Set "to" address
	MOVE.W	#16*8,D0	;Move 16 blocks ($0000 up to $1000)
	BSR.S	MOVBLK		;Go do it

;Move high part of RESCOD:
	LEA	$FC1F00.L,A6	;Set "from" address
	LEA	MEMTOP-$4000.L,A5 ;Set "to" address
	MOVE.W	#63*8+4,D0	;Move 63.5 blocks (-$4000 up to -$0080)
	BSR.S	MOVBLK		;Go do it

	JMP	VSTART		;Enter RESCOD

;-----------------------------------------------------------------------
;Move D0*32 bytes from A6 to A5.
; Most registers are destroyed.
; Note unusual entry point.
;
MOV10	MOVEM.L	(A6)+,A4/D1-D7	;Read 32 bytes at A6
	MOVEM.L	A4/D1-D7,(A5)	;Write 32 bytes at A5
	ADDA.L	#32,A5		;(Post incrementing is not allowed)
MOVBLK	DBF	D0,MOV10	;Loop until done
	RTS


MAX	EQU	$FC0100		;Maximum load location +1
	IF	@ > MAX
ERROR - TOO BIG, THIS WILL BOMB THE EXTENDED DIRECTORY
	ELSE			;(Extended dir won't work on RAM disk)
	DCB.B	MAX-@, 0	;Fill the rest of the block with zeros
	ENDIF

	END
CTORY
	ELSE			;(Extended dir won't work on RAM disk)
	DCB.B	