 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 DMF2COM
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 at 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
*
* Initialize 8274 port
*
 cmpa #5 8274 port?
 bne mchin6 no
 ldu instat,x pick up 8274 address
 lda #$18 send initialize code
 sta 2,u
 sta 3,u
 pshs d delay
 puls d
 lda 2,u check response
 anda #$87
 cmpa #$04 check for "xmit buffer empty"
 beq 0f
 clr inmask,x zero interrupt mask
 leau INTSIZ,x point at B side
 clr inmask,u zero out B side also
 bra 3f
0 ldy #cnfstr point to configuration string
2 lda 0,y+ send to port
 beq 3f
 bmi 25f
 sta 2,u
 lda ,y+
 sta 2,u
 bra 2b
25 anda #$7F strip high bit
 sta 3,u
 lda ,y+
 sta 3,u
 bra 2b
3 leax INTSIZ,x 8274's take up two slots
 dec 0,s
 inc strm 8274's count for 2 terminals!
 lbra mchin10 continue
*
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

* configuration data

cnfstr fcb $02,$14,$04,$4c,$03,$E1,$05,$ea,$01,$04,$10,$30,$28,$F8
       fcb $82,$00,$84,$4c,$83,$E1,$85,$ea,$81,$04,$90,$30,$A8,$F8
       fcb 0

*
* endinit - Machine initialization complete
* -- Do any necessary clean up before interrupts enabled
*
endinit rts
