Mercurial > hg > index.cgi
changeset 100:6db72a92ff7a
Make value accumulator descriptions consistent and make usage consistent
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 23 Oct 2023 22:46:55 -0600 |
parents | 4d7fa11ebe3f |
children | b0422868a7b1 |
files | src/defs.s src/fps.s src/number.s src/vars.s |
diffstat | 4 files changed, 22 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/src/defs.s Mon Oct 23 20:23:28 2023 -0600 +++ b/src/defs.s Mon Oct 23 22:46:55 2023 -0600 @@ -13,24 +13,22 @@ linebuffsize equ 0x100 ; the line input buffer (256 bytes) stringstacknum equ 20 ; number of entries on the anonymous string descriptor stack ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; Data structure used for calculations. Calculations are handled via structurs called value accumulators. A value +; Data structure used for calculations. Calculations are handled via structures called value accumulators. A value ; accumulator consists of a data type flag (at the end of the structure) and a data area whose layout varies based ; on the actual data type. The layouts for each value type are described below. ; ; A value type that is NULL (not set to anything) has type 0 (valtype_none) and the rest should be zero. ; -; A value accumulator has the following structure for floating point: +; A value accumulator has the following structure for floating point, which holds a packed floating point value: ; Offset Length Contents -; 0 1 fp exponent -; 1 4 fp mantissa -; 5 1 fp sign +; 0 1 fp exponent and sign +; 1 5 fp mantissa ; 6 1 value type ; ; A value accumulator has the following structure for integers: ; Offset Length Contents -; 0 1 *unsued* -; 1 4 integer value (two's complement) -; 5 1 *unused* +; 0 4 integer value (two's complement) +; 4 2 *unused* ; 6 1 value type ; ; A value accumulator has the following structure for a string: @@ -62,13 +60,12 @@ ; Value accumulator structure definitions; note that the actual value data must be first and any ; incidental meta data must follow val.value equ 0 ; offset of the value stored in the accumulator -val.fpsexp equ val.value ; floating point exponent +val.fpsexp equ val.value ; floating point exponent (and sign) val.fpssig equ val.fpsexp+1 ; floating point significand -val.fpssign equ val.fpssig+5 ; floating point sign val.int equ val.value ; integer offset val.strlen equ val.value+str.len ; string length offset val.strptr equ val.value+str.ptr ; string data pointer (low word) -val.type equ val.value+val.fpssign+1 ; use the largest of the data types here +val.type equ 6 ; use the largest of the data type sizes here val.size equ val.type+1 ; size of a value accumulator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ifdef COCO3
--- a/src/fps.s Mon Oct 23 20:23:28 2023 -0600 +++ b/src/fps.s Mon Oct 23 22:46:55 2023 -0600 @@ -908,8 +908,7 @@ std fpaextra+2 ldd val.int,x std fpaextra -fps_fromint0 leay ,x ; set result destination pointer - ldd zero ; zero out destination +fps_fromint0 ldd zero ; zero out destination std fpa0+fpa.sig std fpa0+fpa.sig+2 sta fpa0+fpa.sig+4 @@ -934,20 +933,10 @@ rol fpa0+fpa.sig dec fpaextra+5 ; done all digits? bne fps_fromint1 ; brif not - jsr fps_normalizea0 ; go normalize the result in fpa0 - ldd fpa0+fpa.sig ; copy result to destination - std val.fpssig,y - ldd fpa0+fpa.sig+2 - std val.fpssig+2,y - lda fpa0+fpa.sig+4 - sta val.fpssig+4,y - lda fpa0+fpa.exp - sta val.fpsexp,y - lda fpa0+fpa.sign - sta val.fpssign,y lda #valtype_float ; set result type to floating point sta val.type,y - rts + jsr fps_normalizea0 ; go normalize fpa0 + jmp fps_pack0 ; pack the result to the original accumulator ; This is the digit check for the double-dabble algorith. The left digit check is only concerned if the left digit ; is 5 or higher. Since we can make that comparison without masking the bits, we don't bother. For the right digit, ; however, we do have to mask the upper digit off. It saves and ANDA and a subsequent indexed reload. @@ -966,16 +955,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Convert the floating point value in the value accumulator at (X) to a 32 bit signed integer. Will trigger an overflow ; if the magnitude is too large and it will truncate (round toward zero) any fractional value. -fps_toint lda val.fpsexp,x ; copy the exponent, sign, and significand to fpa0 - sta fpa0+fpa.exp - ldd val.fpssig,x - std fpa0+fpa.sig - ldd val.fpssig+2,x - std fpa0+fpa.sig+2 - lda val.fpssig+4,x - sta fpa0+fpa.sig+4 - lda val.fpssign,x - sta fpa0+fpa.sign +fps_toint jsr fps_unpack0 ; unpack the floating point value to fpa0 bsr fps_tointa0 ; convert value to integer in fpa0 significand lda #valtype_int ; set result to integer sta val.type,x
--- a/src/number.s Mon Oct 23 20:23:28 2023 -0600 +++ b/src/number.s Mon Oct 23 22:46:55 2023 -0600 @@ -268,17 +268,8 @@ adda #64 sta fpa0+fpa.exp jsr fps_normalizea0 ; normalize fpa0 - ldd fpa0+fpa.sig ; copy result to the right place - std val0+val.fpssig - ldd fpa0+fpa.sig+2 - std val0+val.fpssig+2 - lda fpa0+fpa.sig+4 - sta val0+val.fpssig+4 - lda fpa0+fpa.exp - sta val0+val.fpsexp - lda fpa0+fpa.sign - sta val0+val.fpssign - rts + ldx #val0 ; pack the result to the right place and return + jmp fps_pack0 val_parsenum14 lda #valtype_int ; set value type to integer sta val0+val.type ldb fpa0+fpa.exp ; add the exponent bias in
--- a/src/vars.s Mon Oct 23 20:23:28 2023 -0600 +++ b/src/vars.s Mon Oct 23 22:46:55 2023 -0600 @@ -39,14 +39,16 @@ tok_kwnum rmb 1 ; the actual token number tok_kwmatchl rmb 1 ; the length of the best match during lookup tok_kwmatch rmb 2 ; the current best matched token number -; General value accumulators used during expression evaluation +; General value accumulators used during expression evaluation. These are in the same format used for storing +; values in variables with the exception of having a type flag. val0 rmb val.size ; value accumulator 0 - current expression value val1 rmb val.size ; value accumulator 1 - usually left operand of binary operator -; The fpa0 and fpa1 areas are used for scratch work during floating point operations. They are only used -; by floating point operations. This saves a fair fiew clock cycles over simply working off the index register -; pointers passed into the routines and it also allows for being able to leave the input operands for the -; routines unmodified, or to overlap the input and output operands. These floating point accumulators can hold -; the maximum precision floating point values used by the system. +; The fpa0 and fpa1 areas are used for scratch work during floating point operations. They are only used by +; floating point operations and operations related to floating point such as number conversion. This saves a fair +; few clock cycles over simply working off the index register pointers passed into the routines and it also allows +; for being able to leave the input operands for the routines unmodified, or to overlap the input and output +; operands. These floating point accumulators can hold the maximum precision floating point values used by the +; system. fpa0 rmb fpa.size ; floating point accumulator 1 fpa1 rmb fpa.size ; floating point accumulator 1 fpaextra rmb 12 ; "extra" bytes for calculations