SBTTL 'Initialization Section (13_Nov_84)' PAGE ;====================================================================== ; ; Copyright 1984 ; Morrow Designs, Inc. ; San Leandro, Ca. ; ; This file includes all of the code that is unique to initialization. ; ;---------------------------------------------------------------------- ; Index (13_Nov_84) ;------------------ ; ; INITC Cold Start Initialization (Reset) ; INITW Warm Start Initialization (Reset & After dip switches changed) ; ; SLFTST Self Test Routine ; KTEST Keyboard Test ; MTEST Memory Test ; ; INIUART Initialize the Uart Main Line ; SETBAUD Determine the Baud Rate ; SETUART Set the Uart's Baud Rate ; INIT8 Set the Uart's Reciever/Transmitter Format ; ; GETSW Get the value of the Dip Switches ; INITBUF Initialize the Input Buffers ; SETXLT Set up pointers for doing tranlation of foreign character sets PAGE ;---------------------------------------------------------------------- ; Cold Start Initialization (13_Nov_84) ;-------------------------------------- ; 1) Normal Reset Entry ; INITC: LDA #0 ; disable NMI handling STA NMIOK STA BAUD ; put kbrd in quiescent state STA BDREG CLD CLDLP1: STA RAM,X ; clear z page DEX BPL CLDLP1 LDA #$FF ; Disable keyboard buffer until init done STA LOCKMD ; Initialize the Crt Controller LDX #16 ; clear bit 6 of status reg on 6545 STX CRTC LDA CRTC+1 ; by reading LPEN register LDA CRTC ; read CRTC status register AND #%01000000 CMP #%00000000 ; see if 6545 BNE CLDSK1 ; if not 6545, then init as 6845 LDX #15 ; init CRTC (6545) CLDLP2: STX CRTC LDA SETUP65,X STA CRTC+1 DEX BPL CLDLP2 JMP CLDSK2 CLDSK1: LDX #15 ; init CRTC (6845) CLDLP3: STX CRTC LDA SETUP68,X STA CRTC+1 DEX BPL CLDLP3 CLDSK2: LDA #' ' ;set to clear screen to spaces STA CLRCHAR JSR CLRSCR ;clear screen JSR SLFTST ;test for KBRD, and test RAM RTS ;Return ;---------------------------------------------------------------------- ; Warm Start Initialization (13_Nov_84) ;-------------------------------------- ; 1) re-initialization after DIP Switch change starts here ; INITW: JSR GETSW ;get dip switch setting JSR INIUART ;init BAUD port and USART JSR INITBUF ;fill in and out buffers with 0ffh LDA #2 ;init pointers for input buffer STA INEP+1 STA INSP+1 JSR SETXLT ;set up pointers for xlation LDA #0 ;set function key sequence type LDY DIP1 ;depends on switch 8 of dip switch BMI WRMSK1 ;if 1, then morrow function sequence LDA #$FF ;else, set for Televideo lead in WRMSK1: STA FNCNTYP ;set function type LDA #0 ;clear ESCRCVD flag (used in monitor mode) STA ESCRCVD ; initialize attributes to [all off] JSR INVOFF ;set inverse video mode LDA #' ' ;set to clear to spaces STA CLRCHAR JSR CLRSCR ;clear the screen JSR SETCUR ;put cursor on screen LDA #2 ;set default attribute for BRIGHT/DIM STA DEFINV LDA #0 ;set default cursor STA DCURTYP JSR CURST2 ;set cursor type to what's in A reg CLI LDA #CLCKON ;turn on key click JSR KBRDOUT LDA #CAPSOFF ;turn off caps lock light JSR KBRDOUT LDA #AUTON ;turn on auto repeat JSR KBRDOUT LDA #LOCKOFF ;turn off kbrd lock LED JSR KBRDOUT LDA #OFLNOFF ;turn off OFF LINE LED JSR KBRDOUT LDA #BEEP ;BEEP!! JSR KBRDOUT LDY #0 WRMLP1: LDA #$20 ;put spaces in RAM where bottom 2 lines STA CHRLINE,Y ;are stored LDA #$02 ;put normal attribute in RAM STA ATTLINE,Y INY CPY #160 BNE WRMLP1 LDA #0 ;turn keyboard buffer on now STA LOCKMD LDA #$A5 STA NMIOK RTS ;Return PAGE ;---------------------------------------------------------------------- ; Self-Test Routine ;------------------ ; SLFTST: JSR KTEST ;Test the Keyboard JSR MTEST ;Test Ram Memory RTS ;---------------------------------------------------------------------- ; Test the Keyboard ;------------------ ; KTEST: LDX BAUD ;While (Keyboard is trying to send) BPL KTSK1 JSR GETKEY ; get the key from keyboard JMP KTEST KTSK1: LDA #$1 ;assert attention to KBRD ORA BDREG STA BAUD LDX #200 ;Time_Delay:= 4 ms ( 200 * 20 Micro secs ) KTLP1: TXA ;Repeat PHA ; (save Time_Delay) LDX 2 JSR KDLY ; wait 20 micro seconds LDX BAUD ; If (Ack Recieved from Keyboard) BMI KTSK2 ; Goto Keyboard Ok PLA ; decrement time out count TAX DEX BNE KTLP1 ;Until (Time_Delay eq 0) LDA KMESG ;point to memory fail message STA MESG LDA KMESG+1 STA MESG+1 JSR PRNTMSG ;print message PLA PLA ;(preserve stack) JMP SLFTST ;wait for the keyboard to be connected KTSK2: PLA ;fix stack LDA #BEEP ;now, we have to give this ack a character SEI ;and set up the needed parameters PHA LDY #8 JMP ACK1 ;go send it a key, and return to Selftest PAGE ;---------------------------------------------------------------------- ; Test Memory ;------------ ; MTEST: LDY #0 MTLP1: TYA STA CRAM,Y STA CRAM+1021,Y STA ARAM,Y STA ARAM+509,Y INY BNE MTLP1 MTLP2: TYA CMP CRAM,Y BNE MTSK1 CMP CRAM+1021,Y BNE MTSK1 CMP ARAM+509,Y BNE MTSK1 CMP ARAM,Y BNE MTSK1 INY BNE MTLP2 RTS MTSK1: LDA #BEEP ;beep the bell JSR KBRDOUT LDA MMESG ;point to memory fail message STA MESG LDA MMESG+1 STA MESG+1 JSR PRNTMSG ;print message SELF: JMP SELF ;and loop forever PAGE ;---------------------------------------------------------------------- ; Uart Initialization ;-------------------- ; INIUART:JSR SETBAUD ;determine baud rate selection bits JSR SETUART ;setup UART for proper BAUD rate, etc JSR INIT8 ;set status of bit 8 parity, or mark, or space RTS ;---------------------------------------------------------------------- ; Determine the Baud Rate Settings ;--------------------------------- ; SETBAUD:LDA BDREG ;get current contents of baud register AND #$F9 ;Clear BD0 and BD1 STA BDREG LDA DIP1 ;get dipsw value AND #$03 ;get baud rate selection bits ASL A ;align with BDREG ORA BDREG ;set/clr baud bits STA BDREG ;Save it STA BAUD ;and set baud bits RTS PAGE ;---------------------------------------------------------------------- ; Set the Uart Baud Rate ;----------------------- ; SETUART:LDX #$80 ;after setting baud rate, wait to settle SULP1: DEX BNE SULP1 LDA #$80 ;reset USART STA S1STAT TAX TAX ;WAIT STA S1STAT LDA #$40 STA S1STAT ;Put USART in command mode LDA DIP1 ;get dip switch settings AND #%00001100 ;get the parity select bits ASL A ASL A ;align them for USART Mode byte STA TEMP ;put it aside LDA DIP1 ;get dip switch AND #%00000010 ;determine if it needs /16 or /64 LSR A ;move the determining bit over ORA TEMP ;get parity select bits back ORA #%01001110 ;OR in USART MODE boiler plate (8-data, 1-stop) STA S1STAT ;set USART Mode LDA #%00110111 ;get enable byte for USART STA S1STAT ;Enable USART STA UARTCMD ;save it in command instr. register LDA S1DATA ;Flush one character RTS ;---------------------------------------------------------------------- ; Set Transmission/Reception Format ;---------------------------------- ; INIT8: LDA DIP1 ;get dip setings LSR A ;get parity on/off status LSR A TAX AND #%00000001 STA PARSTAT ;save it in parity status TXA LSR A AND #%00000001 ;get whether mark or space/ odd/even STA BIT8 RTS PAGE ;---------------------------------------------------------------------- ; Read the Dip Switches ;---------------------- ; GETSW: LDA DIPSW11 ; READ DIP SWITCH ASL A STA DIP1 LDA DIPSW12 ; GET 8TH SWITCH AND #01 ; MASK OFF BAD BITS ORA DIP1 ; ASSEMBLE THE 8 DATA BITS STA DIP1 ; save the dipsw settings RTS ;---------------------------------------------------------------------- ; Initialize the Input Buffers (9_Nov_84) ;---------------------------------------- ; INITBUF:LDA #$FF ;A:= 0FFh (End of Buffer Character LDX #0 ;Index/Counter:= 0 ITBLP1: STA INBUF,X ;Repeat Input_Buffer:= 0FFh DEX ; Decrement the Index/Counter BNE ITBLP1 ;Until (Counter eq 0) ITBLP2: STA INBUF2,X ;Repeat (Input_Buffer_2:= 0FFh) DEX ; Decrement the Index/Counter BNE ITBLP2 ;Until (Counter eq 0) ITBLP3: STA SNDBUF,X ;Repeat (Send_Buffer:= 0FFh) INX ; Decrement the Index/Counter BPL ITBLP3 ;Until (Counter eq 0) RTS ;Return PAGE ;---------------------------------------------------------------------- ; Set up pointers for doing tranlation of foreign character sets ;--------------------------------------------------------------- ; SETXLT: LDA DIP1 ;get dip switch settings LSR A LSR A LSR A LSR A AND #%00000111 ;get the foreign mode select bits STA FOREIGN ;save their value ASL A ;each char mode has two bytes of numxlt TAY LDA XLTCNT,Y ;get # of chars that need XLATION STA NUMXLTI ;......for data from host INY LDA XLTCNT,Y STA NUMXLTO ;for data from KBRD DEY ;set back to former value TYA ASL A ;Now, get a pointer to XLT table vectors ASL A TAY LDX #0 ;set to count for 8 vectors SXTLP1: LDA XLTVCT,Y ;move a vector STA XLT1,X INY INX CPX #8 ;see if 8 vectors moved yet BNE SXTLP1 ;if not, move another RTS ;Return END