summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2016-08-15 14:09:02 +0200
committerLeo C2016-08-15 14:09:02 +0200
commitc9b3681ce26a30c47a312c3eeeea4f7655e94354 (patch)
tree60767bdb0d49b72e4f0fd102173d413f1817c682
parent30673dea0bd87d670a5267d516535b9615756f9c (diff)
downloadddt180-c9b3681ce26a30c47a312c3eeeea4f7655e94354.zip
read_symfile: Check symbols for valid characters.
-rw-r--r--ddt180.z80105
1 files changed, 76 insertions, 29 deletions
diff --git a/ddt180.z80 b/ddt180.z80
index 5275297..50d500e 100644
--- a/ddt180.z80
+++ b/ddt180.z80
@@ -516,9 +516,7 @@ skipbl0:
inc de
skipbl:
ld a,(de)
- cp ' '
- jr z,skipbl0
- cp TAB
+ call test_whitespace
jr z,skipbl0
or a
ret
@@ -3137,64 +3135,62 @@ rs_2:
call read_hexbyte ; symval L
ld l,a
add hl,de
- push hl ; symval
call read_byte
cp ' '
jr z,rs_4
- pop hl ; discard symval
rs_3: call read_byte
cp ' '
- jr c,rs_2
- jr rs_3
+ jr nc,rs_3
+ jr rs_2
-rs_4: ld hl,(BDOS+1) ;
- ld d,0 ; setup symlen
-rs_5: dec hl ;
+rs_4:
+ push hl ; symval
+ ld hl,(BDOS+1) ;
+ ld b,0 ; setup symlen
+rs_5:
+ dec hl ;
call read_byte ; next char of symbol name
- cp TAB ; symbol term?
- jr z,rs_6 ;
- cp CR ;
- jr z,rs_6 ;
- cp '!' ; TODO: check for valid symbol char instead
- jr c,error3 ;
+ call test_sym_char ; valid char?
+ jr nz,rs_6
ld (hl),a ;
- inc d ; symlen++
- ld a,d ;
+ inc b ; symlen++
+ ld a,b ;
cp 10h+1 ;
jr c,rs_5 ;
error3:
jp ERROR ;
-rs_6: push de ; symlen
- push hl ;
+rs_6:
+ call test_symterm_ch
+ jr nz,error3
+
+ push bc ; symlen
ex de,hl ;
ld hl,(BDOS+1) ;
inc hl ;
- ld e,(hl) ;
+ ld c,(hl) ;
inc hl ;
- ld d,(hl) ;
- pop hl ;
- ld (hl),d ;
+ ld b,(hl) ;
+ ex de,hl
+ ld (hl),b ;
dec hl ;
- ld (hl),e ;
+ ld (hl),c ;
dec hl ;
ld (hl),0c3h ;
ld de,(max_load) ;
call cp_hl_de ;
jr c,error3 ;
-
ld de,(reg_sp) ;
call cp_hl_de ;
jr nc,rs_61 ;
ld (reg_sp),hl ;
rs_61:
-
ld de,(BDOS+1) ;
ld (BDOS+1),hl ;
ex de,hl ;
- pop af ;
- ld (hl),a ; symlen
+ pop af ; symlen
+ ld (hl),a ;
inc hl ;
pop de ; symval
ld (hl),e ;
@@ -3207,6 +3203,57 @@ rs_61:
jp rs_1 ;
+; test for valid character for symbols
+; return z if valid
+
+test_sym_char:
+ cp '$'
+ ret z
+ cp '%'
+ ret z
+ cp '.'
+ ret z
+ cp '_'
+ ret z
+ call test_alphanum
+ ret c ; cy == 1 --> z == 0
+ cp a ; return z
+ ret
+
+
+; check if char is in [0..9,?,@,A..Z,a..z]
+; return cy if invalid
+; return nc if valid alfanumeric char
+
+test_alphanum:
+ cp 'z'+1
+ ccf
+ ret c
+ cp 'a'
+ ret nc
+ cp 'Z'+1
+ ccf
+ ret c
+ cp '?'
+ ret nc
+test_numeral:
+ cp '9'+1
+ ccf
+ ret c
+ cp '0'
+ ret
+
+test_symterm_ch:
+ cp CR
+ ret z
+ cp LF
+ ret z
+test_whitespace:
+ cp ' '
+ ret z
+ cp TAB
+ ret
+
p_max_high0:
call assert_eol
p_max_high: