Skip to content

Commit 238c0a2

Browse files
authored
Merge pull request #449 from boriel/bugfix/VAL_error_code
Bugfix/val error code
2 parents 39c0156 + 9028e8e commit 238c0a2

7 files changed

Lines changed: 182 additions & 78 deletions

File tree

docs/code.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#CODE
2+
3+
##Syntax
4+
5+
6+
```
7+
code(<value>)
8+
```
9+
10+
##Description
11+
12+
Returns the ASCII code of the first character of the given string value.
13+
If the string is empty, the returned value is 0.
14+
Returned value type is [UByte](types.md#UByte).
15+
16+
##Examples
17+
18+
```
19+
REM ASCII CODE of "A"
20+
PRINT "ASCII CODE of A is "; CODE("A")
21+
LET a$ = ""
22+
PRINT "ASCII CODE of emtpy string is "; CODE(a$)
23+
```
24+
25+
##Remarks
26+
27+
* This function is 100% Sinclair BASIC Compatible
28+
29+
##See Also
30+
31+
* [CHR](chr.md)
32+
* [STR](str.md)

docs/str.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#STR
2+
3+
##Syntax
4+
5+
6+
```
7+
STR(<numeric value>)
8+
```
9+
10+
##Description
11+
12+
Converts the given numeric value to a String. It's the opposite of [VAL](val.md)
13+
Returned value type is [String](types.md#UByte).
14+
15+
##Examples
16+
17+
```
18+
REM Convert numeric expression to value
19+
LET a = -5.2
20+
PRINT STR(a + 1)
21+
```
22+
23+
##Remarks
24+
25+
* This function is 100% Sinclair BASIC Compatible
26+
27+
##See Also
28+
29+
* [CHR](chr.md)
30+
* [CODE](code.md)
31+
* [VAL](chr.md)

docs/val.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#VAL
2+
3+
##Syntax
4+
5+
6+
```
7+
VAL(<string value>)
8+
```
9+
10+
##Description
11+
12+
Converts the given numeric string value into its numeric value. It's the opposite of [STR](str.md).
13+
If the string can be converted into a number, [PEEK](peek.md) 23610 (ROM ERR_NR variable) will return 255 (_Ok_).
14+
15+
On the other side, if expression cannot be parsed (i.e. it's not a valid number expression), 0 will be returned,
16+
and [PEEK](peek.md) 23610 (ROM ERR_NR variable) will return 9 (_Invalid Argument_).
17+
18+
Returned value type is [Float](types.md#float).
19+
20+
##Examples
21+
22+
```
23+
REM Convert numeric expression to value
24+
LET a$ = "-55.3e-1"
25+
PRINT "Value of "; a$; " is "; VAL(a$)
26+
LET a$ = "aaa"
27+
PRINT "Numeric value of "; a$; " is "; VAL(a$): REM prints 0
28+
```
29+
30+
##Remarks
31+
32+
* This function is 100% Sinclair BASIC Compatible
33+
34+
##See Also
35+
36+
* [CHR](chr.md)
37+
* [CODE](code.md)
38+
* [STR](str.md)

src/arch/zx48k/library-asm/val.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ __VAL_EMPTY: ; Jumps here on empty string
105105
call nz, __MEM_FREE ; Frees "" string
106106

107107
__RET_ZERO: ; Returns 0 Floating point on error
108-
ld a, ERROR_Ok
108+
ld a, ERROR_InvalidArg
109109
ld (ERR_NR), a
110110

111111
xor a

tests/functional/loadstr.asm

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ __LABEL0:
5757
DEFW 0002h
5858
DEFB 31h
5959
DEFB 30h
60-
#line 1 "storestr.asm"
60+
;; --- end of user code ---
61+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr.asm"
6162
; vim:ts=4:et:sw=4
6263
; Stores value of current string pointed by DE register into address pointed by HL
6364
; Returns DE = Address pointer (&a$)
@@ -68,8 +69,8 @@ __LABEL0:
6869
;
6970
; This function will resize (REALLOC) the space pointed by HL
7071
; before copying the content of b$ into a$
71-
#line 1 "strcpy.asm"
72-
#line 1 "realloc.asm"
72+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/strcpy.asm"
73+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/realloc.asm"
7374
; vim: ts=4:et:sw=4:
7475
; Copyleft (K) by Jose M. Rodriguez de la Rosa
7576
; (a.k.a. Boriel)
@@ -129,7 +130,7 @@ __LABEL0:
129130
; HL = BLOCK Start & DE = Length.
130131
; An init directive is useful for initialization routines.
131132
; They will be added automatically if needed.
132-
#line 1 "error.asm"
133+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm"
133134
; Simple error control routines
134135
; vim:ts=4:et:
135136
ERR_NR EQU 23610 ; Error code system variable
@@ -161,8 +162,8 @@ __ERROR_CODE:
161162
__STOP:
162163
ld (ERR_NR), a
163164
ret
164-
#line 70 "realloc.asm"
165-
#line 1 "alloc.asm"
165+
#line 70 "/zxbasic/src/arch/zx48k/library-asm/realloc.asm"
166+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
166167
; vim: ts=4:et:sw=4:
167168
; Copyleft (K) by Jose M. Rodriguez de la Rosa
168169
; (a.k.a. Boriel)
@@ -222,7 +223,7 @@ __STOP:
222223
; HL = BLOCK Start & DE = Length.
223224
; An init directive is useful for initialization routines.
224225
; They will be added automatically if needed.
225-
#line 1 "heapinit.asm"
226+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm"
226227
; vim: ts=4:et:sw=4:
227228
; Copyleft (K) by Jose M. Rodriguez de la Rosa
228229
; (a.k.a. Boriel)
@@ -327,7 +328,7 @@ __MEM_INIT2:
327328
ld (__MEM_INIT), a; "Pokes" with a RET so ensure this routine is not called again
328329
ret
329330
ENDP
330-
#line 70 "alloc.asm"
331+
#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
331332
; ---------------------------------------------------------------------
332333
; MEM_ALLOC
333334
; Allocates a block of memory in the heap.
@@ -357,9 +358,9 @@ __MEM_START:
357358
__MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE
358359
ld a, h ; HL = NULL (No memory available?)
359360
or l
360-
#line 111 "/zxbasic/arch/zx48k/library-asm/alloc.asm"
361+
#line 111 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
361362
ret z ; NULL
362-
#line 113 "/zxbasic/arch/zx48k/library-asm/alloc.asm"
363+
#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
363364
; HL = Pointer to Free block
364365
ld e, (hl)
365366
inc hl
@@ -423,8 +424,8 @@ __MEM_SUBTRACT:
423424
inc hl ; Return hl
424425
ret
425426
ENDP
426-
#line 71 "realloc.asm"
427-
#line 1 "free.asm"
427+
#line 71 "/zxbasic/src/arch/zx48k/library-asm/realloc.asm"
428+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm"
428429
; vim: ts=4:et:sw=4:
429430
; Copyleft (K) by Jose M. Rodriguez de la Rosa
430431
; (a.k.a. Boriel)
@@ -580,7 +581,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed
580581
ld (hl), d ; Next saved
581582
ret
582583
ENDP
583-
#line 72 "realloc.asm"
584+
#line 72 "/zxbasic/src/arch/zx48k/library-asm/realloc.asm"
584585
; ---------------------------------------------------------------------
585586
; MEM_REALLOC
586587
; Reallocates a block of memory in the heap.
@@ -649,7 +650,7 @@ __REALLOC_END:
649650
dec hl ; To begin of block
650651
ret
651652
ENDP
652-
#line 2 "strcpy.asm"
653+
#line 2 "/zxbasic/src/arch/zx48k/library-asm/strcpy.asm"
653654
; String library
654655
__STRASSIGN: ; Performs a$ = b$ (HL = address of a$; DE = Address of b$)
655656
PROC
@@ -726,7 +727,7 @@ __NOTHING_TO_COPY:
726727
dec hl
727728
ret
728729
ENDP
729-
#line 14 "storestr.asm"
730+
#line 14 "/zxbasic/src/arch/zx48k/library-asm/storestr.asm"
730731
__PISTORE_STR: ; Indirect assignement at (IX + BC)
731732
push ix
732733
pop hl
@@ -751,8 +752,8 @@ __STORE_STR:
751752
ld (hl), d ; Stores a$ ptr into elemem ptr
752753
pop hl ; Returns ptr to b$ in HL (Caller might needed to free it from memory)
753754
ret
754-
#line 32 "loadstr.bas"
755-
#line 1 "storestr2.asm"
755+
#line 33 "loadstr.bas"
756+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm"
756757
; Similar to __STORE_STR, but this one is called when
757758
; the value of B$ if already duplicated onto the stack.
758759
; So we needn't call STRASSING to create a duplication
@@ -783,13 +784,13 @@ __STORE_STR2:
783784
ld (hl), d
784785
dec hl ; HL points to mem address variable. This might be useful in the future.
785786
ret
786-
#line 33 "loadstr.bas"
787-
#line 1 "str.asm"
787+
#line 34 "loadstr.bas"
788+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/str.asm"
788789
; The STR$( ) BASIC function implementation
789790
; Given a FP number in C ED LH
790791
; Returns a pointer (in HL) to the memory heap
791792
; containing the FP number string representation
792-
#line 1 "stackf.asm"
793+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/stackf.asm"
793794
; -------------------------------------------------------------
794795
; Functions to manage FP-Stack of the ZX Spectrum ROM CALC
795796
; -------------------------------------------------------------
@@ -826,8 +827,8 @@ __FPSTACK_I16: ; Pushes 16 bits integer in HL into the FP ROM STACK
826827
xor a
827828
ld b, a
828829
jp __FPSTACK_PUSH
829-
#line 9 "str.asm"
830-
#line 1 "const.asm"
830+
#line 9 "/zxbasic/src/arch/zx48k/library-asm/str.asm"
831+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/const.asm"
831832
; Global constants
832833
P_FLAG EQU 23697
833834
FLAGS2 EQU 23681
@@ -836,7 +837,7 @@ __FPSTACK_I16: ; Pushes 16 bits integer in HL into the FP ROM STACK
836837
CHARS EQU 23606 ; Pointer to ROM/RAM Charset
837838
UDG EQU 23675 ; Pointer to UDG Charset
838839
MEM0 EQU 5C92h ; Temporary memory buffer used by ROM chars
839-
#line 10 "str.asm"
840+
#line 10 "/zxbasic/src/arch/zx48k/library-asm/str.asm"
840841
__STR:
841842
__STR_FAST:
842843
PROC
@@ -886,8 +887,8 @@ __STR_END:
886887
RECLAIM2 EQU 19E8h
887888
STK_END EQU 5C65h
888889
ENDP
889-
#line 34 "loadstr.bas"
890-
#line 1 "val.asm"
890+
#line 35 "loadstr.bas"
891+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/val.asm"
891892
VAL: ; Computes VAL(a$) using ROM FP-CALC
892893
; HL = address of a$
893894
; Returns FP number in C ED LH registers
@@ -967,7 +968,7 @@ __VAL_EMPTY: ; Jumps here on empty string
967968
or a
968969
call nz, __MEM_FREE ; Frees "" string
969970
__RET_ZERO: ; Returns 0 Floating point on error
970-
ld a, ERROR_Ok
971+
ld a, ERROR_InvalidArg
971972
ld (ERR_NR), a
972973
xor a
973974
ld b, a
@@ -976,5 +977,5 @@ __RET_ZERO: ; Returns 0 Floating point on error
976977
ld e, c
977978
ret
978979
ENDP
979-
#line 35 "loadstr.bas"
980+
#line 36 "loadstr.bas"
980981
END

0 commit comments

Comments
 (0)