2020-11-22 23:01:22 +01:00
|
|
|
; Arduino terminal driver
|
|
|
|
; @author Daniele Verducci
|
|
|
|
|
|
|
|
; config (IO port 0)
|
2020-12-09 20:09:52 +01:00
|
|
|
TERM_DATA_REG: EQU IO_0
|
2020-12-16 08:49:28 +01:00
|
|
|
TERM_DATA_AVAIL_REG: EQU IO_0 + 1
|
2020-11-22 23:01:22 +01:00
|
|
|
|
2020-11-23 08:25:02 +01:00
|
|
|
; variables
|
2020-11-24 21:34:51 +01:00
|
|
|
TERM_VAR_SPACE: EQU DRV_VAR_SPACE + 128
|
|
|
|
incoming_string: EQU TERM_VAR_SPACE
|
2020-11-23 08:25:02 +01:00
|
|
|
|
2020-11-22 23:01:22 +01:00
|
|
|
; functions
|
|
|
|
|
|
|
|
; Sends string
|
|
|
|
; @param BC Pointer to a null-terminated string first character
|
|
|
|
Term_print:
|
|
|
|
ld a, (bc) ; bc is the pointer to passed string's first char
|
|
|
|
cp 0 ; compare A content with 0 (subtract 0 from value and set zero flag Z if result is 0)
|
|
|
|
ret z ; if prev compare is true (Z flag set), string is finished, return
|
2020-12-09 20:09:52 +01:00
|
|
|
out (TERM_DATA_REG),a ; output char
|
2020-11-22 23:01:22 +01:00
|
|
|
inc bc ; increment bc to move to next char
|
|
|
|
jp Term_print
|
|
|
|
|
|
|
|
; Writes a single character
|
|
|
|
; @param A Value of character to print
|
|
|
|
Term_printc:
|
2020-12-09 20:09:52 +01:00
|
|
|
out (TERM_DATA_REG),a
|
2020-11-22 23:01:22 +01:00
|
|
|
ret
|
2020-11-23 08:25:02 +01:00
|
|
|
|
2020-12-16 08:49:28 +01:00
|
|
|
; Reads a single character. 0s are ignored (can be used with keyboard).
|
|
|
|
; Doesn't check DATA_AVAILABLE register of parallel port, because a 0 byte
|
|
|
|
; is ignored anyway (it represents the ASCII NUL control char).
|
2020-11-23 08:25:02 +01:00
|
|
|
; @return A The read character
|
|
|
|
Term_readc:
|
2020-12-09 20:09:52 +01:00
|
|
|
in a, (TERM_DATA_REG) ; reads a character
|
2020-11-24 21:34:51 +01:00
|
|
|
add a, 0
|
|
|
|
jp z, Term_readc ; if char is 0 (NULL), ignores it and waits for another character
|
2020-11-23 08:25:02 +01:00
|
|
|
ret ; if not NULL, returns it in the a register
|
|
|
|
|
2020-12-09 21:01:57 +01:00
|
|
|
; Reads a line. 0s are ignored (can be used with keyboard)
|
2020-12-16 08:49:28 +01:00
|
|
|
; Doesn't check DATA_AVAILABLE register of parallel port, because a 0 byte
|
|
|
|
; is ignored anyway (it represents the ASCII NUL control char).
|
2020-11-23 08:25:02 +01:00
|
|
|
; @return BC The pointer to a null-terminated read string
|
|
|
|
Term_readline:
|
2020-11-24 21:34:51 +01:00
|
|
|
ld bc, incoming_string ; this array will contain read string
|
2020-12-09 20:09:52 +01:00
|
|
|
in a, (TERM_DATA_REG) ; reads a character
|
2020-11-23 08:25:02 +01:00
|
|
|
; if char is 0 (ascii NULL), ignore it
|
2020-11-24 21:34:51 +01:00
|
|
|
add a, 0
|
2020-11-23 08:25:02 +01:00
|
|
|
jp z, Term_readline ; if 0 (= ascii NULL), ignores it and waits for another character
|
2020-11-24 21:34:51 +01:00
|
|
|
; if char is a newline (CR or LF), line is finished.
|
2020-11-23 08:25:02 +01:00
|
|
|
cp 10 ; CR
|
|
|
|
jp z, term_readline_foundcr ; Found newline. Jump to term_readline_foundcr
|
|
|
|
cp 13 ; LF
|
|
|
|
jp z, term_readline_foundcr ; Found newline. Jump to term_readline_foundcr
|
|
|
|
; At this point the read character is a valid ascii character
|
2020-11-24 21:34:51 +01:00
|
|
|
ld (bc), a ; adds char to the read string
|
|
|
|
inc bc ; point to next array position
|
2020-11-23 08:25:02 +01:00
|
|
|
jp Term_readline
|
|
|
|
term_readline_foundcr: ; called when carriage return was found (end of line)
|
2020-11-25 19:39:20 +01:00
|
|
|
;ld (bc), 0 ; Null-terminate string
|
2020-11-24 21:34:51 +01:00
|
|
|
ld bc, incoming_string ; Returns read string pointer
|
2020-11-23 08:25:02 +01:00
|
|
|
ret
|
2020-12-09 21:01:57 +01:00
|
|
|
|
2020-12-16 08:49:28 +01:00
|
|
|
; Returns the number of bytes available on the parallel port using the
|
|
|
|
; DATA_AVAILABLE register.
|
|
|
|
; @return a the number of available bytes
|
|
|
|
Term_availb:
|
|
|
|
in a, (TERM_DATA_AVAIL_REG)
|
|
|
|
ret
|
|
|
|
|
|
|
|
; Reads the first available byte on the serial port using the DATA register.
|
2020-12-09 21:01:57 +01:00
|
|
|
; 0s are not ignored (cannot be used with keyboard)
|
|
|
|
; Affects NO condition bits!
|
2020-12-16 08:49:28 +01:00
|
|
|
; @return the available byte, even if 0
|
2020-12-09 21:01:57 +01:00
|
|
|
Term_readb:
|
|
|
|
in a, (TERM_DATA_REG) ; reads a byte
|
|
|
|
ret
|