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

*
* 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
 ldd #HZTIM set gimix clock rate
 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.
*

BDATA  equ 0 via b side data register offset
DDB    equ 2 via b side data direction register
PCR    equ 12 via peripheral control register
IER    equ 14 via interrupt enable register
IFR    equ 13 via interrupt flag register

mchint
 clr strm # terminals calculated here!
 lda cputyp get cpu info from UniBUG
 bita #%01000000 is it 50 HZ?
 beq mchin1
 sta sphz set 50 HZ flag
mchin1
 ldb #$D0 179x force interrupt
 stb DMF3COM clear any WD Floppy interrupts
 ldb W5CMD and any WD Winchester interrupts
 lda #wd_sz_512+%11000 ** Turn off select light **
 sta wd_sdh
* configure the via, but dont actually enable interrupts yet
 lda #%10000011 be sure the data direction is correct
 sta VIA+DDB
 lda #%00001110
 sta VIA+PCR be sure correct edges also
 lda #%01111111 disable VIA interrupts
 sta VIA+IER
 lda #$FF clear out any pending VIA irqs
 sta VIA+IFR
* Now allow interrupts from the board
 lda #%10010000 set up the VIA irq enable register
 sta VIA+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
 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
