Skip to content

Commit 9028e8e

Browse files
committed
Fix bug in VAL not setting error code
On error VAL returns 0 as expected, but was not setting ERR_NR to 9 (Invalid argument). Fixed.
1 parent 0f76b2e commit 9028e8e

4 files changed

Lines changed: 81 additions & 78 deletions

File tree

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

tests/functional/valcrash1.asm

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ _test__leave:
8181
__LABEL0:
8282
DEFW 0001h
8383
DEFB 35h
84-
#line 1 "free.asm"
84+
;; --- end of user code ---
85+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm"
8586
; vim: ts=4:et:sw=4:
8687
; Copyleft (K) by Jose M. Rodriguez de la Rosa
8788
; (a.k.a. Boriel)
@@ -141,7 +142,7 @@ __LABEL0:
141142
; HL = BLOCK Start & DE = Length.
142143
; An init directive is useful for initialization routines.
143144
; They will be added automatically if needed.
144-
#line 1 "heapinit.asm"
145+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm"
145146
; vim: ts=4:et:sw=4:
146147
; Copyleft (K) by Jose M. Rodriguez de la Rosa
147148
; (a.k.a. Boriel)
@@ -246,7 +247,7 @@ __MEM_INIT2:
246247
ld (__MEM_INIT), a; "Pokes" with a RET so ensure this routine is not called again
247248
ret
248249
ENDP
249-
#line 69 "free.asm"
250+
#line 69 "/zxbasic/src/arch/zx48k/library-asm/free.asm"
250251
; ---------------------------------------------------------------------
251252
; MEM_FREE
252253
; Frees a block of memory
@@ -343,9 +344,9 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed
343344
ld (hl), d ; Next saved
344345
ret
345346
ENDP
346-
#line 58 "valcrash1.bas"
347-
#line 1 "loadstr.asm"
348-
#line 1 "alloc.asm"
347+
#line 59 "valcrash1.bas"
348+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm"
349+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
349350
; vim: ts=4:et:sw=4:
350351
; Copyleft (K) by Jose M. Rodriguez de la Rosa
351352
; (a.k.a. Boriel)
@@ -405,7 +406,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed
405406
; HL = BLOCK Start & DE = Length.
406407
; An init directive is useful for initialization routines.
407408
; They will be added automatically if needed.
408-
#line 1 "error.asm"
409+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm"
409410
; Simple error control routines
410411
; vim:ts=4:et:
411412
ERR_NR EQU 23610 ; Error code system variable
@@ -437,7 +438,7 @@ __ERROR_CODE:
437438
__STOP:
438439
ld (ERR_NR), a
439440
ret
440-
#line 69 "alloc.asm"
441+
#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
441442
; ---------------------------------------------------------------------
442443
; MEM_ALLOC
443444
; Allocates a block of memory in the heap.
@@ -467,9 +468,9 @@ __MEM_START:
467468
__MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE
468469
ld a, h ; HL = NULL (No memory available?)
469470
or l
470-
#line 111 "/zxbasic/arch/zx48k/library-asm/alloc.asm"
471+
#line 111 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
471472
ret z ; NULL
472-
#line 113 "/zxbasic/arch/zx48k/library-asm/alloc.asm"
473+
#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
473474
; HL = Pointer to Free block
474475
ld e, (hl)
475476
inc hl
@@ -533,7 +534,7 @@ __MEM_SUBTRACT:
533534
inc hl ; Return hl
534535
ret
535536
ENDP
536-
#line 2 "loadstr.asm"
537+
#line 2 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm"
537538
; Loads a string (ptr) from HL
538539
; and duplicates it on dynamic memory again
539540
; Finally, it returns result pointer in HL
@@ -568,13 +569,13 @@ __LOADSTR: ; __FASTCALL__ entry
568569
ldir ; Copies string (length number included)
569570
pop hl ; Recovers destiny in hl as result
570571
ret
571-
#line 59 "valcrash1.bas"
572-
#line 1 "pstoref.asm"
572+
#line 60 "valcrash1.bas"
573+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/pstoref.asm"
573574
; Stores FP number in A ED CB at location HL+IX
574575
; HL = Offset
575576
; IX = Stack Frame
576577
; A ED CB = FP Number
577-
#line 1 "storef.asm"
578+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/storef.asm"
578579
__PISTOREF: ; Indect Stores a float (A, E, D, C, B) at location stored in memory, pointed by (IX + HL)
579580
push de
580581
ex de, hl ; DE <- HL
@@ -600,7 +601,7 @@ __STOREF: ; Stores the given FP number in A EDCB at address HL
600601
inc hl
601602
ld (hl), b
602603
ret
603-
#line 7 "pstoref.asm"
604+
#line 7 "/zxbasic/src/arch/zx48k/library-asm/pstoref.asm"
604605
; Stored a float number in A ED CB into the address pointed by IX + HL
605606
__PSTOREF:
606607
push de
@@ -610,8 +611,8 @@ __PSTOREF:
610611
add hl, de ; HL <- IX + DE
611612
pop de
612613
jp __STOREF
613-
#line 60 "valcrash1.bas"
614-
#line 1 "storestr.asm"
614+
#line 61 "valcrash1.bas"
615+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr.asm"
615616
; vim:ts=4:et:sw=4
616617
; Stores value of current string pointed by DE register into address pointed by HL
617618
; Returns DE = Address pointer (&a$)
@@ -622,8 +623,8 @@ __PSTOREF:
622623
;
623624
; This function will resize (REALLOC) the space pointed by HL
624625
; before copying the content of b$ into a$
625-
#line 1 "strcpy.asm"
626-
#line 1 "realloc.asm"
626+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/strcpy.asm"
627+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/realloc.asm"
627628
; vim: ts=4:et:sw=4:
628629
; Copyleft (K) by Jose M. Rodriguez de la Rosa
629630
; (a.k.a. Boriel)
@@ -751,7 +752,7 @@ __REALLOC_END:
751752
dec hl ; To begin of block
752753
ret
753754
ENDP
754-
#line 2 "strcpy.asm"
755+
#line 2 "/zxbasic/src/arch/zx48k/library-asm/strcpy.asm"
755756
; String library
756757
__STRASSIGN: ; Performs a$ = b$ (HL = address of a$; DE = Address of b$)
757758
PROC
@@ -828,7 +829,7 @@ __NOTHING_TO_COPY:
828829
dec hl
829830
ret
830831
ENDP
831-
#line 14 "storestr.asm"
832+
#line 14 "/zxbasic/src/arch/zx48k/library-asm/storestr.asm"
832833
__PISTORE_STR: ; Indirect assignement at (IX + BC)
833834
push ix
834835
pop hl
@@ -853,9 +854,9 @@ __STORE_STR:
853854
ld (hl), d ; Stores a$ ptr into elemem ptr
854855
pop hl ; Returns ptr to b$ in HL (Caller might needed to free it from memory)
855856
ret
856-
#line 61 "valcrash1.bas"
857-
#line 1 "val.asm"
858-
#line 1 "stackf.asm"
857+
#line 62 "valcrash1.bas"
858+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/val.asm"
859+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/stackf.asm"
859860
; -------------------------------------------------------------
860861
; Functions to manage FP-Stack of the ZX Spectrum ROM CALC
861862
; -------------------------------------------------------------
@@ -892,7 +893,7 @@ __FPSTACK_I16: ; Pushes 16 bits integer in HL into the FP ROM STACK
892893
xor a
893894
ld b, a
894895
jp __FPSTACK_PUSH
895-
#line 3 "val.asm"
896+
#line 3 "/zxbasic/src/arch/zx48k/library-asm/val.asm"
896897
VAL: ; Computes VAL(a$) using ROM FP-CALC
897898
; HL = address of a$
898899
; Returns FP number in C ED LH registers
@@ -972,7 +973,7 @@ __VAL_EMPTY: ; Jumps here on empty string
972973
or a
973974
call nz, __MEM_FREE ; Frees "" string
974975
__RET_ZERO: ; Returns 0 Floating point on error
975-
ld a, ERROR_Ok
976+
ld a, ERROR_InvalidArg
976977
ld (ERR_NR), a
977978
xor a
978979
ld b, a
@@ -981,5 +982,5 @@ __RET_ZERO: ; Returns 0 Floating point on error
981982
ld e, c
982983
ret
983984
ENDP
984-
#line 62 "valcrash1.bas"
985+
#line 63 "valcrash1.bas"
985986
END

0 commit comments

Comments
 (0)