;**************************************************************** ; BIN Loader for SBC08K * ;**************************************************************** ; Loads a BIN of a user-specified byte size to $1000+ over * ; serial port 1 (J3). The user must specify the starting address* ; and file size in the first two respective longwords prior to * ; any code. After loading the file, control is returned to * ; the TUTOR ROM. * ; Please note that this program expects to live at $18000 in * ; a non-volatile memory. Download speed and protocol are * ; identical to the TUTOR ROM (9600bps, 8N1, No flow control). * ; * ; Written by: Osman Celimli * ;**************************************************************** ; INCLUDES * ;**************************************************************** include SBC08K_E.asm ;**************************************************************** ; CODE START * ;**************************************************************** ;Starting Address- $18000 org $18000 Start: move.l #$7FFE,a7 ; Move stack to top of 32KB block for a bit... jsr PIT_Init ; Initialize PIT jsr DUART_Init ; Initialize DUART LEA BinPrompt,a1 clr.b d4 @displayprompt addq.b #1,d4 move.b (a1)+,d0 jsr DUART_PortA_PollPutChar cmpi.b #BinPromptSize,d4 bne @displayprompt ; Wait for a junk character in DUART jsr DUART_PortA_PollGetChar jsr DUART_PortA_PollPutChar ; First eight bytes are address then size (4 ea.) @getaddr jsr DUART_PortA_PollGetChar ;Get starting address in a0 move.b d0,d2 lsl.l #8,d2 jsr DUART_PortA_PollGetChar move.b d0,d2 lsl.l #8,d2 jsr DUART_PortA_PollGetChar move.b d0,d2 lsl.l #8,d2 jsr DUART_PortA_PollGetChar move.b d0,d2 movea.l d2,a0 @getsize jsr DUART_PortA_PollGetChar ;Get size in d2 move.b d0,d2 lsl.l #8,d2 jsr DUART_PortA_PollGetChar move.b d0,d2 lsl.l #8,d2 jsr DUART_PortA_PollGetChar move.b d0,d2 lsl.l #8,d2 jsr DUART_PortA_PollGetChar move.b d0,d2 move.l d2,d2 ; Exit if d2=0 beq @restart @getbytes jsr DUART_PortA_PollGetChar ;Get current byte in d0 move.b d0,(a0)+ ; Write to address in a0, post inc not.b d0 ;Invert d0 (Since our LEDs are active low) move.b d0,PBDR ;Write it to parallel out B (For sanity) subq.l #1,d2 ; We done yet? bne @getbytes @restart move.l #$444,a7 ; Put sys stack back to Tutor's default jmp $E0146; And go back to the Tutor reset vector ;**************************************************************** ; DUART_Init * ; Initializes the DUART for communication over * ; Port A (J3) at 9600bps, no parity, no flow control, no IRQs. * ;**************************************************************** DUART_Init: LEA DUART_IRQ,a0 move.l a0,IRQVEC_DUART ;Set DUART IRQ Vector move.b #$30,CRA move.b #$20,CRA move.b #$10,CRA ;Reset Port A xmit, receiver, & mode move.b #$80,ACR move.b #$BB,CSRA move.b #$93,MRA ; 9600bps, 8N1, No parity move.b #$37,MRA move.b #$05,CRA ; Enable Port A transmit and receive. rts ;**************************************************************** ; DUART_IRQ * ; A dummy IRQ handler for the DUART. * ;**************************************************************** DUART_IRQ: rte ;**************************************************************** ; DUART_PortA_PollGetChar * ; Captures a character in Port A of the DUART, returning * ; it in d0. * ;**************************************************************** DUART_PortA_PollGetChar: nop @wait move.b SRA,d0 btst #0,d0 beq @wait ;Wait until character is rec'd, move.b RHRA,d0 ;then put it in d0 rts ;**************************************************************** ; DUART_PortA_PollPutChar * ; Sends the character in d0 over Port A of the DUART, d1 * ; is trashed (31-24). * ;**************************************************************** DUART_PortA_PollPutChar: nop @wait move.b SRA,d1 btst #2,d1 beq @wait ;Wait until ready to send move.b d0,THRA ;then write d0 to xmit reg rts ;**************************************************************** ; PIT_Init * ; Initializes the PIT for Port B as an output. * ;**************************************************************** PIT_Init: move.b #$00,PBCR ; Zero B Control Reg move.b #$FF,PBDDR ; Direction B (1=output, 0=input) move.b #0,PBDR ; Zero Port B Outputs rts ;**************************************************************** ; Prompts... * ;**************************************************************** BinPrompt dc.b " ",10,13,"BIN Loader Ready-",10,13 BinPrompt2 dc.b "Remember, the binary header must have:",10,13 BinPrompt3 dc.b " *4 Bytes Start Address",10,13," *4 Bytes Binary Size",10,13 BinPrompt4 dc.b "Press any key, then begin binary load.",10,13 BinPromptSize EQU *-BinPrompt