
           lib     hardware
           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     #$BF
           sta     DDRB08
           lda     #%00100011
           sta     AUX08
           lda     #(i_t2cnt+i_via)
           sta     IER08
           ldd     #$0500            give a full second before first count
           std     T2CNTR              set initial count
           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!
mchin1
           ldb     #$D0                Clear any interrupts on WD Floppy
           stb     COM1797
           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     #%11111111          set up VIA29 directions
           sta     DDRA29
           lda     #(fdmotor+nxdrive+hltogg)   un hinge head load toggle bit
           sta     ORA29
           clra
           sta     DDRB29              b side all inputs
           lda     #%00001100          set the shift register mode
           sta     AUX29
           lda     PCR29               configure the edges
           ora     #%01100110          CB2,CA2 rising /CA1 CB1 falling edges
           anda    #%01110110
           sta     PCR29
           lda     #%01111011          Disable interr except shift reg timer
           sta     IER29
           lda     #$FF                clear ANY pending IRQ's
           sta     IFR29
           lda     SHT29               clear any shift reg irq's
* Now allow interrupts from the board
           lda     IER29
           ora     #%10001011          enable CA1, CA2 irq's and CB2
           sta     IER29
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
*
* 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!
           ldb     #INITBR           ***  9600 BAUD DEFAULT
           stb     BAUDRG         ***  go set default baud rates
           lbra    mchin10             continue
*
mchin6
*
*   Initialize the parallel console I/O thru VIA
*
           cmpa    #6                  special parallel I/O
           bne     mchin8
           cmpy    #IFR08
           bne     mchin10
*          lda     #%10111111          PB6 input to timer2
*          sta     DDRB08              set B side to output
*          clr     DDRA08              set A side to input
*          clr     ORB08
*          clr     ORA08
*          lda     #$88                handshake i/o
*          sta     PCR08
*          lda     #%00100011          pb6 timer2 countdown & latched i/o
*          sta     AUX08
*          ldd     #$0500
*          std     T2CNTR              set big initial count
*          lda     ORA08              get fake input char
*          lda     #i_via+CB1+CA1
*          sta     IER08
mchin8
mchin10    leax    INTSIZ,x            bump to next entry
           dec     0,s                 end?
           lbne    mchin3
 ldb strm get terminal count
 addb #4 skip past ttys 04-07 ###### FOR FUTURE EXPANSION ######
 stb strm
           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


****  Added by DEV 7/18/84  **** Also global endinit at top ****

* endinit - End of machine initialization

endinit
 rts

