Add character counting guard

This commit is contained in:
maddiebaka
2026-08-23 20:14:43 -04:00
parent b8a3647ae5
commit 014689916d
+24 -22
View File
@@ -13,8 +13,8 @@ humid_offset equ 09eh
bdos equ 0005h
conout equ 02h
conin equ 01h
printstr equ 09h
char_idx equ 10h
start:
call init_lcd
@@ -42,8 +42,6 @@ start:
main:
call read_char_b
call parse_char
;call lcd_delay
;call print_char_to_lcd
ld c,11
call bdos
or a
@@ -119,14 +117,24 @@ parse_char: ; char should be in register a
cp a,048h ; H character
jr z,set_char_idx_h ; point the char_idx to the humidity buffer
push af
ld a,(char_cnt) ; get number stored in char_cnt
cp char_max ; compare it to maximum character count
jr nc,store_full ; if no carry, the buffer is full
inc a ; otherwise increment
ld (char_cnt),a ; and store back in char_cnt
pop af
ld bc,(char_idx) ; get address stored in char_idx
ld (bc),a ; deref that address and store char
inc bc
ld (char_idx),bc ; store incremented address in char_idx
;out (lcd_data),a
parse_char_done:
ret
store_full:
pop af
ret
print_telem_to_lcd:
call move_to_tempaddr
@@ -142,7 +150,6 @@ print_telem_to_lcd:
call print_str_to_lcd
ld a,1h
out (0),a
ret
null_term: ; null terminate end of parsed string in memory
@@ -155,36 +162,25 @@ null_term: ; null terminate end of parsed s
set_char_idx_t:
ld bc,temperature
ld (char_idx),bc
xor a ; reset char_cnt to zero
ld (char_cnt),a
ret
set_char_idx_p:
ld bc,pressure
ld (char_idx),bc
xor a ; reset char_cnt to zero
ld (char_cnt),a
ret
set_char_idx_h:
ld bc,humidity
ld (char_idx),bc
xor a ; reset char_cnt to zero
ld (char_cnt),a
ret
print_char_to_lcd:
cp a,00h ; null byte
jr z,lcd_done
cp a,0dh ; carriage return
jr z,lcd_done
cp a,0ah ; new line
jr z,lcd_done
cp a,054h ; T character
call z,move_to_tempaddr
cp a,050h ; P character
call z,move_to_presaddr
cp a,048h ; H character
call z,move_to_humidaddr
out (lcd_data),a
lcd_done:
ret
print_str_to_lcd: ; place memory address in hl first
ld a,(hl)
or a
@@ -221,6 +217,12 @@ clabel: DB 'degree C',0
plabel: DB 'pascal',0
hlabel: DB '% RH',0
char_max equ 15
char_cnt DB 0
char_idx DW scratch
scratch: DS 16
temperature: DS 16
humidity: DS 16
pressure: DS 16