Code refactoring, working char read and print, working line print, not working line read

This commit is contained in:
Daniele Verducci su MatissePenguin 2020-11-24 21:34:51 +01:00
parent 33fd225a0f
commit 4d74b03e3f
4 changed files with 39 additions and 37 deletions

View File

@ -37,6 +37,9 @@ Passarne il puntatore ad una funzione:
ld bc, myVar
call lcd_print
```
### Segmentation fault
Controllare che non si stia puntando ad un registro con le parentesi:
`ld (ix), a`
# C
## Deploy

View File

@ -5,8 +5,8 @@
DATA_REG: EQU IO_0
; variables
LCD_VAR_SPACE: EQU DRV_VAR_SPACE + 128
incoming_string: EQU LCD_VAR_SPACE
TERM_VAR_SPACE: EQU DRV_VAR_SPACE + 128
incoming_string: EQU TERM_VAR_SPACE
; functions
@ -29,29 +29,29 @@ Term_printc:
; Reads a single character
; @return A The read character
Term_readc:
in a, (IO_0) ; reads a character
cp 0
jp z, Term_readline ; if NULL, ignores it and waits for another character
in a, (DATA_REG) ; reads a character
add a, 0
jp z, Term_readc ; if char is 0 (NULL), ignores it and waits for another character
ret ; if not NULL, returns it in the a register
; Reads a line
; @return BC The pointer to a null-terminated read string
Term_readline:
ld ix, incoming_string ; this array will contain read string
in a, (IO_0) ; reads a character
ld bc, incoming_string ; this array will contain read string
in a, (DATA_REG) ; reads a character
; if char is 0 (ascii NULL), ignore it
cp 0
add a, 0
jp z, Term_readline ; if 0 (= ascii NULL), ignores it and waits for another character
; if char is a newline (CR or LF), line is finished.
; if char is a newline (CR or LF), line is finished.
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
ld (ix), a ; adds char to the read string
inc ix ; point to next array position
ld (bc), a ; adds char to the read string
inc bc ; point to next array position
jp Term_readline
term_readline_foundcr: ; called when carriage return was found (end of line)
ld (ix), 0 ; Null-terminate string
ld bc, incoming_string ; Returns read string
ld (bc), 0 ; Null-terminate string
ld bc, incoming_string ; Returns read string pointer
ret

View File

@ -1,5 +1,11 @@
; HD44780 20x4 characters LCD display driver
; @author Daniele Verducci
;
; USAGE:
; STR: DB "Hello world!",0 <-- null terminated string
; call Lcd_init <-- inits hd44780 controller
; ld bc, STR <-- load pointer to string's first char in reg BC
; call Lcd_print <-- this function will print the string
; LCD config (IO port 0)
LCD_INSTR_REG: EQU IO_0

View File

@ -2,7 +2,7 @@ jp Sysinit ; Startup vector: DO NOT MOVE! Must be the first instruction
; Pat80 BIOS v0.01
; @author: Daniele Verducci
;
;
; MEMORY MAP
; ROM is at 0x0000
; RAM is at 0x8000
@ -78,30 +78,23 @@ Readline:
; System initialization
Sysinit:
;call Lcd_init
; position to line 2 char 3
;ld b, 1
;ld c, 1
;call Lcd_locate
; I/O TEST
; write characters to display
ld bc, SYSINIT_GREETING
call Lcd_print ; write string to screen
_io_test_loop:
in a, (IO_0) ; legge dal terminale
cp 0
jp z, _io_test_loop
;sub a, 32 ; trasforma in maiuscola (ascii - 32)
out (IO_0), a ; scrive la lettera trasformata
call Print
_io_test_loop:
call Readline
call Print
; call Printc
; call Readline
; ld a, (bc)
; cp a, 0
; jp z, _io_test_loop
; ld (APP_VAR_SPACE), bc
; ld bc, SAYS
; call Print
; ld bc, (APP_VAR_SPACE)
; call Print
jp _io_test_loop
halt
; poll keyboard
;_poll_keyb:
;call Keyb_read
;jp _poll_keyb