; boot.s -- the soundtracker system's whole program: the 68000's vectors, a start that hands the module to ptplayer,
; and an idle loop.  Everything else happens in ptplayer's level-6 interrupt (CIA-B timer A: mt_music at the
; song's tempo; timer B: audio DMA on, then the loop pointers).
;
; The memory is ONE block RAM whose initial contents are this image (`make image`): vectors at 0, this code,
; ptplayer with its variables (it writes them pc-relative, so it must sit in writable memory), the module, and the
; stack at the top.  Assembled with vasm (Motorola syntax), linked at 0, `-Fbin`.
;
;   0x000000  the block RAM (MEMSIZE bytes): vectors, code, ptplayer, the module; the stack grows down from the top
;   0xBFD000  CIA-B (registers on the even byte, a register every 0x100)
;   0xDFF000  the custom chips: INTENA/INTREQ/DMACON and Paula's four audio channels

MEMSIZE	equ	$20000

MINIMAL		equ	1		; the player alone: no sound effects, no master volume
ENABLE_SAWRECT	equ	1

	org	0
vectors:
	dc.l	MEMSIZE			; 0: the initial SSP
	dc.l	start			; 1: the reset pc
	rept	22			; 2..23: bus/address error, illegal, zero divide, CHK, TRAPV, privilege, trace,
	dc.l	fault			;  line A/F, reserved, spurious (24) excluded
	endr
	dc.l	fault			; 24: spurious interrupt
	rept	7			; 25..31: the autovectors, levels 1..7; ptplayer sets level 6 ($78) itself
	dc.l	fault
	endr
	rept	32			; 32..63: TRAP #0..15 and the reserved ones
	dc.l	fault
	endr

start:
	lea	$dff000,a6
	move.w	#$7fff,$9a(a6)		; INTENA: every source off
	move.w	#$7fff,$9c(a6)		; INTREQ: every request cleared
	move.w	#$7fff,$96(a6)		; DMACON: every channel off
	move.w	#$8200,$96(a6)		; DMACON: DMAEN (the master enable); ptplayer turns the channels on
	sub.l	a0,a0			; the vector base: 0 on a 68000
	moveq	#1,d0			; PAL timer clock
	bsr	_mt_install
	lea	module,a0
	sub.l	a1,a1			; the samples follow the patterns
	moveq	#0,d0			; from song position 0
	bsr	_mt_init
	st	_mt_Enable
	move.w	#$2000,sr		; supervisor, interrupt mask 0
idle:	bra.s	idle

fault:	move.w	#$2700,sr		; anything unexpected: stop with every interrupt masked
	move.w	#$000f,$dff096	; silence
.h:	bra.s	.h

	cnop	0,4
module:
	include	"module.i"		; `incbin` of the module (written by the Makefile)
	cnop	0,4

	; LAST: ptplayer.asm ends with `end`, which stops the assembly
	include	"ptplayer.asm"
