home *** CD-ROM | disk | FTP | other *** search
- \ DOWN.SEQ Boot downloader, located at 200h
-
- long_branch
- long_library
-
- registers \ by default this starts at $24
-
- 2variable DPOINT \ pointers and counters
- variable DCOUNT \ for display block move
- variable ROW_COUNTER
-
- variable SP_FLAGS \ serial port status image
-
- $200 cseg down-cseg
- down-cseg
-
- : MAIN
- BEGIN
- SP_POLL
- AGAIN
- ;
-
-
- \ Serial port support
-
- $0D CONSTANT HI_THERE \ enquiry from PC
- '!' constant IM_HERE \ response to PC
- $0AF constant LISTEN_UP \ wake-up request from PC
- $0FA constant GO_AHEAD \ response to PC's LISTEN-UP
-
- 9600 constant BAUD \ actual baud rate
- 7500 constant BAUD_VAL \ 1/(BAUD/100)
- BAUD_VAL 1- 255 AND constant BAUD_L \ baud value to set
- BAUD_VAL 1- 256 / $80 OR constant BAUD_H
-
- $49 constant SP_SETUP \ enable transmitter, set mode=1
- 3 constant TXE_BIT \ transmit empty bit
- 8 constant TXE_MASK
- TXE_MASK not constant NOT.TXE_MASK
- 6 constant RI_BIT \ receive interrupt bit
- $40 constant RI_MASK
- RI_MASK not constant NOT.RI_MASK
- $21 constant IOC1_SETUP \ to enable serial port and PWM
-
- order
- LABEL SP_SEND?L \ ready to send?
- \ usage 1 $: CALL SP_SEND?L
- \ JNC 1 $
- order \ CALL SP_SENDL
- \
- \ returns with W1 = SP_FLAGS
- \
- LDB W1 SP_STAT \ get the status port
- ORB W1 SP_FLAGS \ and the remembered flags
- STB W1 SP_FLAGS \ remember them again
- BITSET W1 TXE_BIT IF SETC THEN
- RET
- end-code \ return with C set if ready
-
- LABEL SP_SENDL \ send the byte in W0
- LD W2 0
- 1 $:
- DEC W2
- JE 2 $ \ timeout in case transmitter broken
- CALL SP_SEND?L
- JNC 1 $ \ wait for transmitter ready
- LDB SBUF W0 \ send the byte
-
- ANDB W1 # NOT.TXE_MASK
- STB W1 SP_FLAGS \ update the remembered flags
- RET
- 2 $:
- LDB SBUF W0 \ if timed out send the byte, anyway
- RET
- end-code
-
- CODE SP_SEND ( c -- ) \ send one byte for hi-level
- LD W0 TTOS
- CALL SP_SENDL
- LOAD_TTOS
- RET
- end-code
-
- LABEL SP_RX?L \ something received?
- \ usage 1 $: CALL SP_RX?L
- \ JNC 1 $
- \ CALL SP_RXL
- \
- \ returns with W1 = SP_FLAGS
- \
- \ changes W1 and SP_FLAGS
- \
- LDB W1 SP_STAT \ get the status port
- ORB W1 SP_FLAGS \ and the remembered flags
- STB W1 SP_FLAGS \ remember them again
- BITSET W1 RI_BIT IF SETC THEN
- RET \ return with C set if something received
- END-CODE
-
- CODE SP_RX? ( -- f ) \ see if something received for hi-level
- SAVE_TTOS
- CLR TTOS
- CALL SP_RX?L
- C0<> IF DEC TTOS THEN \ FFFF on stack if something to pick up
- RET
- end-code
-
- LABEL SP_RXL ( -- C ) \ get received byte, in W0, for code definitions
- BEGIN CALL SP_RX?L
- C0<> UNTIL \ wait for something to get
- LDB W0 SBUF \ get the byte
- ANDB W1 # NOT.RI_MASK
- STB W1 SP_FLAGS \ update the remembered flags
- RET
- end-code
-
- CODE SP_RX ( -- c ) \ get recieved byte for high-level
- SAVE_TTOS
- CALL SP_RXL
- LDB TTOS W0
- CLRB TTOSH
- RET
- end-code
-
-
- LABEL SP_RX_TL ( -- ) \ get received byte, or timeout after 10ms
- \ on exit, W0 = received byte
- \ if timed out, W2 = 0 and Z flag is true
- \ if not timed out W2 <> 0 and Z flag is false
- LD W2 # 900
- 3 $: \ ( approx. 58 states in loop, = 10 usec. )
- DEC W2 \ decrement timeout counter
- JE 4 $ \ go exit if timed out
- CALL SP_RX?L
- JNC 3 $ \ wait for item in receiver
- CALL SP_RXL \ get item from receiver
- 4 $: RET end-code
-
-
- CODE SP_RX_T ( -- C ) \ get received byte, or timeout after 10ms
- \ if timed out TTOS word = -1
- \ if not timed out TTOSH = 0 and TTOS has the byte
- SAVE_TTOS
- LD W2 # 900
- 3 $: \ ( approx. 58 states in loop, = 10 usec. )
- DEC W2 \ decrement timeout counter
- JE 4 $ \ go exit if timed out
- CALL SP_RX?L
- JNC 3 $ \ wait for item in receiver
- CALL SP_RXL \ get item from receiver
- LDB TTOS W0
- CLRB TTOSH \ return the received byte on the stack
- RET
- 4 $: LD TTOS # -1 \ otherwise put -1 on the stack
- RET
- end-code
-
- CODE SP_POLLC \ serial port poll
- DI
- CALL SP_RX?L \ see if there's something received
- JNC 2 $ \ if not, return to background
- CALL SP_RXL \ get received byte
- CMPB W0 # HI_THERE \ see if it is a "hi-there"
- JNE 1 $
-
- LD W0 # IM_HERE \ if so respond with a "i'm here"
- CALL SP_SENDL
- SJMP 2 $
- 1 $:
- CMPB W0 # LISTEN_UP \ see if it is a request
- JNE 2 $ \ if not, return to background
- LD W0 # GO_AHEAD
- CALL SP_SENDL \ send "I'm here" byte
- RET \ and let high-level do the rest
-
- 2 $:| POP W0 \ exit from the word that called SP_POLLC
- \ if there's no command to do
- RET
- end-code
-
- LABEL SP_POLL_L END-CODE \ entry to SP_POLL from a code word
- : SP_POLL
- SP_POLLC \ It may exit SP_POLL from within SP_POLLC
- SP_RX_T
- DUP 0< IF DROP EXIT THEN \ exit if it timed out
- \ DUP 30 >= IF DROP EXIT THEN \ exit if it is too big
- exec:
- \ table of function subroutines
- \ 0
- JUMP_TO
- NULL_FUNCT
- NULL_FUNCT \ MEASURE_ALL
- WRITE_BYTES
- READ_BYTES
- \ 5
- NULL_FUNCT \ MEASURE_AD
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT
- \ 10
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT \ WRITE_BYTESW
- NULL_FUNCT \ READ_BYTESW \ 0Dh -- subverted by the "Hi-there"
- NULL_FUNCT \ WRITE_WORDSW
- \ 15
- NULL_FUNCT \ READ_WORDSW
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT
- \ 20
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT
- FILL_MEM
- \ 25
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT
- NULL_FUNCT
- ;
-
- : NULL_FUNCT ;
-
- \ SPCMDS.SEQ serial port commands.
-
- LABEL GET_WORDL \ Get a word value into W0 from the serial port
- PUSH TTOS
- CALL SP_RX_TL
- JE 1 $ \ low byte
- LDB TTOS W0
- CALL SP_RX_TL \ high byte
- LDB TTOSH W0
- LD W0 TTOS \ now W0 is the value
- 1 $: POP TTOS
- RET
- end-code
-
- \ *************************************************************************
- \
- \ Serial port function to go call a subroutine
- \
- \ *************************************************************************
-
- CODE JUMP_TO
- CALL GET_WORDL \ get an address
- 0<> IF BR[] W0 THEN \ jump to it
- \ subsequent RET will be to idle loop
- RET
- end-code
-
-
- \ *************************************************************************
- \
- \ Write and Read bytes in
- \ regular memory, or the normal register set
- \
- \ *************************************************************************
-
-
- CODE FILL_MEM \ fill memory with a byte value
- PUSH TTOS
- CALL GET_WORDL \ get address
- JE 2 $
- LD TTOS W0
- CALL GET_WORDL \ third and fourth are byte count
- JE 2 $
- PUSH W0
- CALL SP_RX_TL \ get the byte to write
- POP W2
- JE 2 $
- 1 $:
- STB W0 []+ TTOS \ write the byte
- DEC W2
- JNE 1 $
- 2 $:
- CALL SP_SENDL \ send a byte to say it is done
- POP TTOS
- RET
- end-code
-
- CODE WRITE_BYTES \ write memory byte contents
- PUSH TTOS
- PUSH TTOS2
- CALL GET_WORDL \ get address
- JE 2 $
- LD TTOS W0
- CALL SP_RX_TL
- JE 2 $
- LDB TTOS2 W0 \ third byte is byte count, put it in TTOS2
- 1 $:
- CALL SP_RX_TL \ get a byte of data to write
- JE 2 $
- STB W0 []+ TTOS \ write the byte
- DJNZ TTOS2 1 $
- 2 $: POP TTOS2
- POP TTOS
- RET
- end-code
-
- CODE READ_BYTES \ return memory byte contents
- PUSH TTOS
- PUSH TTOS2
- CALL GET_WORDL \ get address into W0
- JE 2 $
- PUSH W0
- CALL SP_RX_TL \ third byte is byte count
- LDB TTOS2 W0 \ put it in TTOS2
- POP TTOS \ address in TTOS
- JE 2 $
- 1 $:
- LDB W0 []+ TTOS \ read a byte
- CALL SP_SENDL \ send the byte
- DJNZ TTOS2 1 $
- 2 $: POP TTOS2
- POP TTOS
- RET
- end-code
-
-
- end-cseg
-
- \s
- comment:
- code set-hso ( n -- ) \ set bits n in the HSO
- LDB W0 IOS0
- LDB WSR # 15
- ORB W0 # TTOS
- LDB IOS0 W0
- LDB WSR 0
- LOAD_TTOS
- ret
- end-code
-
- code clear-hso ( n -- ) \ reset bits n in the HSO
- NOTB TTOS
- LDB W0 IOS0
- LDB WSR # 15
- ANDB W0 # TTOS
- LDB IOS0 W0
- LDB WSR 0
- LOAD_TTOS
- ret
- end-code
- comment;
-
-
-