 lib environment
 lib inttab
 data
 sttl Machine Dependent Rouintes
 pag
 name mach
 global clkinz,mchint,endinit

*
* clkinz
*
* Initialize system clock.
*

clkinz ldb #0 clear out lbolt counter
 stb lbolt
 lda stup set auto update counter
 sta tmtuct
 lda #1 reset the clock
 sta CLKSEL
 lda #%10000000 set reset bit
 sta CLOCK save in control
 clr CLKSEL reset control
 tst sphz 60 Hz or 50 Hz?
 bne 0f
 ldd #HZTIM_60 set clock rate = 60 Hz
 bra 1f
0 ldd #HZTIM_50 set clock rate = 50 Hz
1 std CLKLAT set latch count
 lda #CLKCON get control byte
 sta CLOCK send to clock
 lda #1 select timer 1
 sta CLKSEL
 clr CLOCK reset clocks
 rts return

*
* mchint
*
* Initialize all hardware junk and try to find
* the existing acias.  The ones that aren't there
* need to have their mask bits cleared.
*

mchint
 clr strm # terminals calculated here!
 lda cputyp get cpu info from UniBUG
 anda #%01000000 is it 50 HZ?
 beq mchin1
 sta sphz set 50 HZ flag
mchin1
 ldb #$D0 Clear any interrupts on WD Floppy
 stb DMF3COM
 ldb W5CMD clear any WD winchester interrupts also
 lda #wd_sz_512+%11000 ** Turn off winchester select light **
 sta wd_sdh
*
*   configure the VIA, but dont actually enable interrupts yet
*
 lda #%01111111 disable all VIA interrupts
 sta AT_IER
 lda #-1
 sta AT_DTB initialize B side
 sta AT_DXA and A side Data Registers
 sta AT_DRA set all outputs on A side
 lda #%10000011
 sta AT_DRB set up B direction reg
 lda #%00101110 CB2 falling indep/CA2 high out
 sta AT_PCR set peripheral control reg
 jsr ATinit initialize archive tape
*
*   Now allow interrupts from the board
*
 lda #-1 clear out any pending VIA irqs
 sta AT_IFR
 lda #%10001000 enable CB2 interrupst only
 sta AT_IER

mchin2
 ldx #inttab point to int table
 ldb ,x+ pick up number of devices
 pshs b
mchin3
 ldd indev,x check device # for TTYxx
 cmpd #$0100
 bhs 0f jump if not TTYxx
 inc strm
0 lda intype,x get interrupt device type
 cmpa #0 ACIA?
 bne mchin4 no
*
* Initialize ACIA port
*
 ldu instat,x get ACIA address
 lda #$43 set up reset code
 sta 0,u reset acia
 pshs d delay
 puls d
 lda 0,u check response
 beq 0f
 anda #%11110011
 beq 0f
 clr inmask,x zero int mask
0 cmpu scon was this the system console
 bne 1f no - continue
 pshs x save registers
 jsr syscon yes - go reinitialize console
 puls x restore registers
1 lbra mchin10 continue initialization
*
* Initialize PIA port
*
mchin4 cmpa #1 PIA?
 bne mchin5 no
 ldu instat,x pick up PIA address
 leau -1,u point to PIA
 lda #$2e set up pia
 sta 1,u
 pshs d delay
 puls d
 lda 0,u
 pshs d
 puls d
 tst 1,u
 bpl 0f
 clr inmask,x zero int mask
0 lbra mchin10 continue initialization
mchin5
*
mchin6
*
* Initialize NEC port
*
 cmpa #3 NEC special
 bne mchin7
 lda #$2e set up
 ldu instat,x get port address
 sta 0,u points to NECPRT+2
 sta 1,u
 pshs d
 puls d
 ldd -2,u
 pshs d
 puls d
 tst 0,u
 bmi 10f
 tst 1,u
 bpl 20f
10 clr inmask,x zero masks
 leau INTSIZ,x point at second side
 clr inmask,u zero out second side
20 leax INTSIZ,x NEC takes up two slots also
 dec 0,s
*
mchin7
mchin10 leax INTSIZ,x bump to next entry
 dec 0,s end?
 lbne mchin3
 puls b reset stack
 rts

*
* endinit - End of machine initialization
*
endinit rts
