
           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
*****TEMP  jsr     scsirst             go RESET SCSI Controller

           jsr     atrewind            go rewind tape if ok
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
*
* get a page from free list, init with zeros, and call it the white hole
*
w_hole     pshs    d
           jsr     clrpag              get a page that is inited to 0's
           beq     0f                  error getting memory
           sta     WHTHOL
           ldd     #0
           std     $D000               make sure that it is all
           std     $D002               zeros
           std     $D004
           puls    pc,d
0          ldx     #wh_err
           jsr     Pdata
w_hole_l   bra     w_hole_l            die

wh_err     fcb     13,10,10,10,10
           fcc     "UNABLE TO ALLOCATE MEMORY"
           fcb     7,7,0

* 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
           jsr     w_hole reserve a white hole page
           rts
