; setup script for Todd Day's DSP board
; must include Todd's standard include files
; before including this program

; setup.asm
; setup the SRAMS
; setup the ssi port to talk to the 5805s
; setup the sci port to talk to host

; set up mode register
; LF  **  TM  **  S1  S0  I1  I0
;  0   0   0   0   0   0   1   1
;	No loop flag (LF)
;	No trace mode (TR)
;	No scaling (Sn)
;	Mask Interrupts (In)

	ori	#$03,mr

; set bus control register for one wait state for X and Y mem (SRAMS)
; XMEM YMEM PMEM EXIO
;  $1   $1   $0   $0
;	Number of wait states for each type of memory

	movep	#$1100,x:m_bcr

; set interrupt priority levels
; SCL1 SCL0 SSL1 SSL0 HPL1 HPL0 **** ****
;   0    0    1    1    0    0    0    0
; **** **** IBL2 IBL1 IBL0 IAL2 IAL1 IAL0
;   0    0    0    0    0    0    0    0
;	No SCI interrupts {we'll poll} (SCLn=0)
;	Priority 2 for SSI (SSLn=1)
;	No Host interrrupts (HPLn=0)
;	No IRQx interrups (IxLn=0)

	movep	#$3000,x:m_ipr

; initialize ssi port
; setup Control Register A (CRA)
; PSR WL1 WL0 DC4 DC3 DC2 DC1 DC0 PM7 PM6 PM5 PM4 PM3 PM2 PM1 PM0
;  0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
;	No prescaler (PMn)
;	No frame rate (DCn)
;	Word length = 16 (WL1=1, WL0=0)
;	No prescaler range (PSR)

	movep	#$4000,x:m_cra

; setup Control Register B (CRB)
; RIE TIE RE TE MOD GCK SYN FSL *** *** SCKD SCD2 SCD1 SCD0 OF1 OF0
;  0   0   1  1  0   0   1   0   0   0   0    0    0    0    0   0
;	No output flags (OFn)
;	SCn and SCK are all inputs (SCxx=0)
;	Frame length = data word (FSL=0)
;	Synchronous (SYN=1)
;	No gated glock (GCK=0)
;	Normal Mode (MOD=0)
;	Transmit on Frame Sync (TE=1)
;	Receive on Frame Sync (RE=1)
;	No transmit interrupt (TIE=0)
;	No receive interrupt, yet (RIE=0)

	movep	#$3200,x:m_crb

; initialize SCI port
; setup SCI Interface Control Register (SCR)
; **** **** TMIE  TIE  RIE ILIE  TE   RE
;   0    0    0    0    0    0    1    1
; WOMS  RWU WAKE  SBK **** WDS2 WDS1 WDS0
;   0    0    0    0    0    0    1    0
;	1 start-8 data-1 stop (WDS2,WDS1,WDS0=0,1,0)
;	No send break (SBK=0)
;	No wake-up (WAKE,RWU=0)
;	No open-collector output (WOMS=0)
;	Enable receiver (RE=1)
;	Enable transmitter (TE=1)
;	No idle line interrupt (ILIE=0)
;	No receive interrupt {we'll poll} (RIE=0)
;	No transmit interrupt (TIE=0)
;	No timer interrupt (TMIE=0)

	movep	#$0302,x:m_scr

; setup SCI Clock Control Register (SCCR)
;  TCM  RCM  SCP  COD CD11 CD10  CD9  CD8
;   0    0    0    0    0    0    0    0
;  CD7  CD6  CD5  CD4  CD3  CD2  CD1  CD0
;   0    1    0    0    0    0    0    1
;	We need a baud rate of 4800
;	Divider = 20,000,000 / (2*1*2*16*4800) = 65
;	Baud rate really is 4808 (< 0.2% error)
;	CD11-CD0 = 000001000001
;	No clock output (COD=0)
;	No prescaler (SCP=0)
;	Use internal clock for receive (RCM=0)
;	Use internal clock for transmit (TCM=0)

	movep	#$0041,x:m_sccr

; enable SSI and SCI pins (Port C Control Register - PCC)
; CC8 CC7 CC6 CC5 CC4 CC3 CC2 CC1 CC0
;  1   1   1   1   0   1   0   1   1
;	STD enable (CC8=1)
;	SRD enable (CC7=1)
;	SCK enable (CC6=1)
;	SC2 enable (CC5=1)
;	No SC1 (CC4=0)
;	SC0 enable (CC3=1)
;	No SCLK (CC2=0)
;	TXD enable (CC1=1)
;	RXD enable (CC0=1)

	movep	#$01EB,x:m_pcc
