Skip to content

Commit a660d83

Browse files
committed
fix: fixes reading a Ubyte as a Byte
1 parent dc2e9f1 commit a660d83

16 files changed

Lines changed: 352 additions & 240 deletions

File tree

src/lib/arch/zx48k/runtime/read_restore.asm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ _from_u16:
212212

213213
dynamic_cast4:
214214
;; The user type is "shorter" than the read one
215+
ld a, b ;; read type
216+
cp _i16 ;; if user type < read type < _i16 => From Ubyte to Byte. Return af'
217+
jr nc, 1f
218+
ex af, af'
219+
ret
220+
1:
221+
ld a, c ;; recover user required type
215222
cp _f16 ;; required type
216223
jr c, before_to_int ;; required < fixed (f16)
217224
ex af, af'

src/lib/arch/zxnext/runtime/read_restore.asm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ _from_u16:
212212

213213
dynamic_cast4:
214214
;; The user type is "shorter" than the read one
215+
ld a, b ;; read type
216+
cp _i16 ;; if user type < read type < _i16 => From Ubyte to Byte. Return af'
217+
jr nc, 1f
218+
ex af, af'
219+
ret
220+
1:
221+
ld a, c ;; recover user required type
215222
cp _f16 ;; required type
216223
jr c, before_to_int ;; required < fixed (f16)
217224
ex af, af'

tests/functional/arch/zx48k/arrbase1.asm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ __DATA__END:
107107
; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))]
108108
; What I will do here is to calculate the following sequence:
109109
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
110-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm"
110+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul16.asm"
111111
push namespace core
112112
__MUL16: ; Mutiplies HL with the last value stored into de stack
113113
; Works for both signed and unsigned
@@ -1217,6 +1217,13 @@ _from_u16:
12171217
jp _from_i32
12181218
dynamic_cast4:
12191219
;; The user type is "shorter" than the read one
1220+
ld a, b ;; read type
1221+
cp 4 ;; if user type < read type < _i16 => From Ubyte to Byte. Return af'
1222+
jr nc, 1f
1223+
ex af, af'
1224+
ret
1225+
1:
1226+
ld a, c ;; recover user required type
12201227
cp 8 ;; required type
12211228
jr c, before_to_int ;; required < fixed (f16)
12221229
ex af, af'

tests/functional/arch/zx48k/data1.asm

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ _a:
5757
__DATA__END:
5858
DEFB 00h
5959
;; --- end of user code ---
60-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
60+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
6161
;; This implements READ & RESTORE functions
6262
;; Reads a new element from the DATA Address code
6363
;; Updates the DATA_ADDR read ptr for the next read
@@ -75,7 +75,7 @@ __DATA__END:
7575
;; 09: Float
7676
;; bit7 is set for a parameter-less function
7777
;; In that case, the next two bytes are the ptr of the function to jump
78-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm"
78+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm"
7979
; Simple error control routines
8080
; vim:ts=4:et:
8181
push namespace core
@@ -109,9 +109,9 @@ __STOP:
109109
ld (ERR_NR), a
110110
ret
111111
pop namespace
112-
#line 23 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
113-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm"
114-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
112+
#line 23 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
113+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm"
114+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm"
115115
; vim: ts=4:et:sw=4:
116116
; Copyleft (K) by Jose M. Rodriguez de la Rosa
117117
; (a.k.a. Boriel)
@@ -171,7 +171,7 @@ __STOP:
171171
; HL = BLOCK Start & DE = Length.
172172
; An init directive is useful for initialization routines.
173173
; They will be added automatically if needed.
174-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm"
174+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm"
175175
; vim: ts=4:et:sw=4:
176176
; Copyleft (K) by Jose M. Rodriguez de la Rosa
177177
; (a.k.a. Boriel)
@@ -278,7 +278,7 @@ __MEM_INIT2:
278278
ret
279279
ENDP
280280
pop namespace
281-
#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
281+
#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm"
282282
; ---------------------------------------------------------------------
283283
; MEM_ALLOC
284284
; Allocates a block of memory in the heap.
@@ -309,9 +309,9 @@ __MEM_START:
309309
__MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE
310310
ld a, h ; HL = NULL (No memory available?)
311311
or l
312-
#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
312+
#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm"
313313
ret z ; NULL
314-
#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
314+
#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm"
315315
; HL = Pointer to Free block
316316
ld e, (hl)
317317
inc hl
@@ -376,7 +376,7 @@ __MEM_SUBTRACT:
376376
ret
377377
ENDP
378378
pop namespace
379-
#line 2 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm"
379+
#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm"
380380
; Loads a string (ptr) from HL
381381
; and duplicates it on dynamic memory again
382382
; Finally, it returns result pointer in HL
@@ -413,8 +413,8 @@ __LOADSTR: ; __FASTCALL__ entry
413413
pop hl ; Recovers destiny in hl as result
414414
ret
415415
pop namespace
416-
#line 24 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
417-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/iload32.asm"
416+
#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
417+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/iload32.asm"
418418
; __FASTCALL__ routine which
419419
; loads a 32 bits integer into DE,HL
420420
; stored at position pointed by POINTER HL
@@ -432,8 +432,8 @@ __ILOAD32:
432432
ex de, hl
433433
ret
434434
pop namespace
435-
#line 25 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
436-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/iloadf.asm"
435+
#line 25 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
436+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/iloadf.asm"
437437
; __FASTCALL__ routine which
438438
; loads a 40 bits floating point into A ED CB
439439
; stored at position pointed by POINTER HL
@@ -460,10 +460,10 @@ __LOADF: ; Loads a 40 bits FP number from address pointed by HL
460460
ld b, (hl)
461461
ret
462462
pop namespace
463-
#line 26 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
464-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/ftof16reg.asm"
465-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm"
466-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/neg32.asm"
463+
#line 26 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
464+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftof16reg.asm"
465+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm"
466+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/neg32.asm"
467467
push namespace core
468468
__ABS32:
469469
bit 7, d
@@ -488,7 +488,7 @@ __NEG32: ; Negates DEHL (Two's complement)
488488
inc de
489489
ret
490490
pop namespace
491-
#line 2 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm"
491+
#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm"
492492
push namespace core
493493
__FTOU32REG: ; Converts a Float to (un)signed 32 bit integer (NOTE: It's ALWAYS 32 bit signed)
494494
; Input FP number in A EDCB (A exponent, EDCB mantissa)
@@ -560,7 +560,7 @@ __FTOU8: ; Converts float in C ED LH to Unsigned byte in A
560560
ld a, l
561561
ret
562562
pop namespace
563-
#line 2 "/zxbasic/src/arch/zx48k/library-asm/ftof16reg.asm"
563+
#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/ftof16reg.asm"
564564
push namespace core
565565
__FTOF16REG: ; Converts a Float to 16.16 (32 bit) fixed point decimal
566566
; Input FP number in A EDCB (A exponent, EDCB mantissa)
@@ -591,9 +591,9 @@ __FTOF16REG: ; Converts a Float to 16.16 (32 bit) fixed point decimal
591591
ld b, a ; Loop counter = exponent - 128 + 16 (we need to shift 16 bit more)
592592
jp __FTOU32REG_LOOP ; proceed as an u32 integer
593593
pop namespace
594-
#line 27 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
595-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/f16tofreg.asm"
596-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/u32tofreg.asm"
594+
#line 27 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
595+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/f16tofreg.asm"
596+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm"
597597
push namespace core
598598
__I8TOFREG:
599599
ld l, a
@@ -663,7 +663,7 @@ __U32TOFREG_END:
663663
ret
664664
ENDP
665665
pop namespace
666-
#line 3 "/zxbasic/src/arch/zx48k/library-asm/f16tofreg.asm"
666+
#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/f16tofreg.asm"
667667
push namespace core
668668
__F16TOFREG: ; Converts a 16.16 signed fixed point (stored in DEHL)
669669
; to a Floating Point Number returned in (C ED CB)
@@ -698,8 +698,8 @@ __F16TOFREG2: ; Converts an unsigned 32 bit integer (DEHL)
698698
jp __U32TOFREG_LOOP ; Proceed as an integer
699699
ENDP
700700
pop namespace
701-
#line 28 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
702-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm"
701+
#line 28 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
702+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm"
703703
; vim: ts=4:et:sw=4:
704704
; Copyleft (K) by Jose M. Rodriguez de la Rosa
705705
; (a.k.a. Boriel)
@@ -857,16 +857,16 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed
857857
ret
858858
ENDP
859859
pop namespace
860-
#line 29 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
861-
#line 31 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
862-
#line 32 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
863-
#line 33 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
864-
#line 34 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
865-
#line 35 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
866-
#line 36 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
867-
#line 37 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
868-
#line 38 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
869-
#line 39 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm"
860+
#line 29 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
861+
#line 31 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
862+
#line 32 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
863+
#line 33 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
864+
#line 34 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
865+
#line 35 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
866+
#line 36 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
867+
#line 37 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
868+
#line 38 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
869+
#line 39 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
870870
;; Updates restore point to the given HL mem. address
871871
push namespace core
872872
__RESTORE:
@@ -1026,6 +1026,13 @@ _from_u16:
10261026
jp _from_i32
10271027
dynamic_cast4:
10281028
;; The user type is "shorter" than the read one
1029+
ld a, b ;; read type
1030+
cp 4 ;; if user type < read type < _i16 => From Ubyte to Byte. Return af'
1031+
jr nc, 1f
1032+
ex af, af'
1033+
ret
1034+
1:
1035+
ld a, c ;; recover user required type
10291036
cp 8 ;; required type
10301037
jr c, before_to_int ;; required < fixed (f16)
10311038
ex af, af'
@@ -1146,8 +1153,8 @@ __DATA_ADDR: ;; Stores current DATA ptr
11461153
dw .DATA.__DATA__0
11471154
ENDP
11481155
pop namespace
1149-
#line 32 "data1.bas"
1150-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/storef.asm"
1156+
#line 32 "arch/zx48k/data1.bas"
1157+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storef.asm"
11511158
push namespace core
11521159
__PISTOREF: ; Indect Stores a float (A, E, D, C, B) at location stored in memory, pointed by (IX + HL)
11531160
push de
@@ -1175,5 +1182,5 @@ __STOREF: ; Stores the given FP number in A EDCB at address HL
11751182
ld (hl), b
11761183
ret
11771184
pop namespace
1178-
#line 33 "data1.bas"
1185+
#line 33 "arch/zx48k/data1.bas"
11791186
END

tests/functional/arch/zx48k/opt3_data2.asm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,13 @@ _from_u16:
13131313
jp _from_i32
13141314
dynamic_cast4:
13151315
;; The user type is "shorter" than the read one
1316+
ld a, b ;; read type
1317+
cp 4 ;; if user type < read type < _i16 => From Ubyte to Byte. Return af'
1318+
jr nc, 1f
1319+
ex af, af'
1320+
ret
1321+
1:
1322+
ld a, c ;; recover user required type
13161323
cp 8 ;; required type
13171324
jr c, before_to_int ;; required < fixed (f16)
13181325
ex af, af'

0 commit comments

Comments
 (0)