1
0
mirror of https://github.com/cc65/cc65.git synced 2025-02-20 14:29:03 +00:00

some cleanup

This commit is contained in:
mrdudz 2022-07-21 00:51:28 +02:00
parent 6818fef71f
commit b9bdcc51e0
24 changed files with 137 additions and 137 deletions

View File

@ -1811,7 +1811,7 @@ static void UnaryOp (ExprDesc* Expr)
hie10 (Expr);
/* We can only handle integer types */
if (!IsClassInt (Expr->Type)
if (!IsClassInt (Expr->Type)
&& !IsClassFloat (Expr->Type) /* FIXME: float */
) {
Error ("Argument must have integer type");
@ -2159,7 +2159,7 @@ printf("hie_internal Expr->Type:%s Expr2->Type:%s\n",
if (Val2 == 0.0f) {
Error ("Division by zero");
Expr->V.FVal = FP_D_FromInt(0);
} else
} else
#endif
{
Expr->V.FVal = FP_D_Div(Val1, Val2);

View File

@ -41,7 +41,7 @@ typedef struct {
*
* The exponent can be computed from bits 47-40 by subtracting 129 (!) (130 = 2^1)
* MSB of the Mantissa must always be 1, if it is 0 the value is 0
*
*
* 1.0 = exp=129, mantissa=$80
*
*/

View File

@ -56,7 +56,7 @@ __basicoff:
.else
.include "float.inc"
.endif
.importzp sreg, ptr1
;---------------------------------------------------------------------------------------------
@ -78,27 +78,27 @@ __float_u8_to_fac:
__enable_basic_if_needed
jsr BASIC_u8_to_FAC
__return_with_cleanup
; get C-parameter (signed int), convert to FAC
___float_s16_to_fac:
;a: low x: high
tay
txa
;y: low a: high
; convert signed int (YA) to FAC
__float_s16_to_fac:
__enable_basic_if_needed ; enable BASIC (trashes X)
jsr BASIC_s16_to_FAC
__return_with_cleanup
; get C-parameter (unsigned short), convert to FAC
; get C-parameter (unsigned short), convert to FAC
___float_u16_to_fac:
;a: low x: high
tay
txa
;y: low a: high
__float_u16_to_fac:
sta FAC_MANTISSA0
sty FAC_MANTISSA1
@ -116,7 +116,7 @@ __float_fac_to_u16:
ldx FAC_MANTISSA2
lda FAC_MANTISSA3
rts
;---------------------------------------------------------------------------------------------
; converter float to string and back
;---------------------------------------------------------------------------------------------
@ -150,9 +150,9 @@ ___float_float_to_fac:
sta FAC_MANTISSA1 ; 3
stx FAC_MANTISSA0 ; 2
ldy sreg ; 1
sty FAC_EXPONENT
sty FAC_EXPONENT
ldy sreg+1 ; 0
sty FAC_SIGN
sty FAC_SIGN
ldx #$00
stx FAC_MANTISSA2
@ -164,7 +164,7 @@ ___float_float_to_fac:
stx FAC_MANTISSA1 ; 2
lda sreg ; 1
ora #$80
sta FAC_MANTISSA0
sta FAC_MANTISSA0
; bit7=0 sign=0
; bit7=1 sign=$ff
@ -176,7 +176,7 @@ ___float_float_to_fac:
stx FAC_SIGN
ldy sreg+1 ; 0
sty FAC_EXPONENT
sty FAC_EXPONENT
ldx #$00
stx FAC_MANTISSA3
@ -213,9 +213,9 @@ ___float_float_to_fac:
stx FAC_ROUNDING
.endif
rts
; load BASIC float into FAC
; in: pointer (a/x) to BASIC float (not packed)
; load BASIC float into FAC
; in: pointer (a/x) to BASIC float (not packed)
__float_float_to_fac: ; only used in ATAN2?
sta ptr1
stx ptr1+1
@ -251,7 +251,7 @@ ___float_float_to_fac_arg:
___float_float_to_arg:
ldy #$03
jsr ldeaxysp
.if BINARYFORMAT = BINARYFORMAT_CBM_UNPACKED
sta ARG_MANTISSA1 ; 3
stx ARG_MANTISSA0 ; 2
@ -273,8 +273,8 @@ ___float_float_to_arg:
stx ARG_MANTISSA1 ; 2
lda sreg ; 1
ora #$80
sta ARG_MANTISSA0
sta ARG_MANTISSA0
; bit7=0 sign=0
; bit7=1 sign=$ff
ldx #0
@ -283,13 +283,13 @@ ___float_float_to_arg:
dex
@pos:
stx ARG_SIGN
ldy sreg+1 ; 0
sty ARG_EXPONENT
sty ARG_EXPONENT
ldx #$00
stx ARG_MANTISSA3
lda ARG_SIGN
eor FAC_SIGN
sta FAC_SIGN_COMPARE ; sign compare
@ -332,7 +332,7 @@ ___float_float_to_arg:
jmp incsp4
; load BASIC float into ARG
; in: pointer (a/x) to BASIC float (not packed)
; in: pointer (a/x) to BASIC float (not packed)
__float_float_to_arg: ; only used in ATAN2?
sta ptr1
stx ptr1+1
@ -358,7 +358,7 @@ __float_float_to_arg: ; only used in ATAN2?
eor FAC_SIGN
sta FAC_SIGN_COMPARE
rts
; return to C, float as unsigned long
___float_fac_to_float:
.if BINARYFORMAT = BINARYFORMAT_CBM_UNPACKED
@ -368,11 +368,11 @@ ___float_fac_to_float:
sta sreg ; 1
ldx FAC_MANTISSA0 ; 2
lda FAC_MANTISSA1 ; 3
.endif
.endif
.if BINARYFORMAT = BINARYFORMAT_CBM_PACKED
lda FAC_EXPONENT
sta sreg+1 ; 0
; use the MSB of the mantissa for the sign
lda FAC_SIGN ; either $ff or $00
ora #$7f ; -> $ff or $7f
@ -381,7 +381,7 @@ ___float_fac_to_float:
ldx FAC_MANTISSA1 ; 2
lda FAC_MANTISSA2 ; 3
.endif
.endif
.if BINARYFORMAT = BINARYFORMAT_IEEE754
; return float in a/x/sreg/sreg+1
lda FAC_EXPONENT
@ -402,10 +402,10 @@ ___float_fac_to_float:
ldx FAC_MANTISSA1 ; 2
lda FAC_MANTISSA2 ; 3 lsb
.endif
rts
.endif
rts
;; store float in memory
;; store float in memory
;; in: dest. pointer (a/x), float in FAC
;__float_fac_to_float: ; UNUSED
; sta ptr1
@ -430,8 +430,8 @@ ___float_fac_to_float:
; sta (ptr1),y
; rts
;; store packed float in memory
;; in: dest. pointer (a/x), float in FAC
;; store packed float in memory
;; in: dest. pointer (a/x), float in FAC
;__float_fac_to_float_packed: ; UNUSED
; sta ptr1
; stx ptr1+1
@ -454,8 +454,8 @@ ___float_fac_to_float:
; lda FAC_EXPONENT
; sta (ptr1),y
; rts
;; store packed float in memory
;; store packed float in memory
;; in: dest. pointer (a/x), float in ARG
__float_arg_to_float_packed:
sta ptr1
@ -479,7 +479,7 @@ __float_arg_to_float_packed:
lda ARG_EXPONENT
sta (ptr1),y
rts
;---------------------------------------------------------------------------------------------
.export __ftostr
@ -512,10 +512,10 @@ __float_strbuf_to_string:
rts
.export __strtof
; convert a string to a float
; float __fastcall__ _strtof(char *d);
;-> unsigned long __fastcall__ _strtof(char *d);
; convert a string to a float
; float __fastcall__ _strtof(char *d);
;-> unsigned long __fastcall__ _strtof(char *d);
__strtof:
jsr ___float_str_to_fac
jmp ___float_fac_to_float
@ -530,7 +530,7 @@ __strtof:
jmp ___float_fac_to_float
.export __utof
; convert unsigned char to float
; float __fastcall__ _utof(unsigned char v);
;-> unsigned long __fastcall__ _utof(unsigned char v);
@ -539,7 +539,7 @@ __strtof:
jmp ___float_fac_to_float
.export __stof
; convert short to float
; float __fastcall__ _stof(unsigned short v);
;-> unsigned long __fastcall__ _stof(unsigned short v);
@ -558,7 +558,7 @@ __strtof:
jmp ___float_fac_to_float
.export __ftoi
; convert float to integer
; int __fastcall__ _ftoi(float f);
;-> int __fastcall__ _ftoi(unsigned long f);
@ -596,11 +596,11 @@ __fsqr: __ffunc1 BASIC_FAC_Sqr
__ftan: __ffunc1 BASIC_FAC_Tan
__fnot: __ffunc1 BASIC_FAC_Not
__fround: __ffunc1 BASIC_FAC_Round ; rounding
;---------------------------------------------------------------------------------------------
; these functions take two args (in FAC and ARG) and return result (in FAC)
;---------------------------------------------------------------------------------------------
__float_ret2:
;jsr __basicoff
@ -625,11 +625,11 @@ __float_ret2:
jsr addr
jmp __float_ret2
.endmacro
.export __fadd, __fsub, __fmul, __fdiv, __fpow
; float __fastcall__ _fadd(float f, float a);
;-> unsigned long __fastcall__ _fadd(unsigned long f, unsigned long a);
; float __fastcall__ _fadd(float f, float a);
;-> unsigned long __fastcall__ _fadd(unsigned long f, unsigned long a);
__fadd: __ffunc2a BASIC_ARG_FAC_Add
__fsub: __ffunc2a BASIC_ARG_FAC_Sub
__fmul: __ffunc2a BASIC_ARG_FAC_Mul
@ -640,7 +640,7 @@ __fpow: __ffunc2a BASIC_ARG_FAC_Pow
__fand: __ffunc2b BASIC_ARG_FAC_And
__for: __ffunc2b BASIC_ARG_FAC_Or
__float_ret3:
;jsr __basicoff
.if .defined(__C64__)
@ -649,17 +649,17 @@ __float_ret3:
cli
.endif
ldx #0
rts
rts
.bss
tempfloat:
.res 5
.SEGMENT "LOWCODE"
.export __fcmp
__fcmp:
jsr ___float_float_to_fac_arg
lda #<tempfloat
@ -675,7 +675,7 @@ ___float_cmp_fac_arg:
jmp __float_ret3
.export __ftestsgn
__ftestsgn:
jsr ___float_float_to_fac
;___float_testsgn_fac:
@ -683,7 +683,7 @@ __ftestsgn:
; in: FAC(x1)
jsr BASIC_FAC_testsgn
jmp __float_ret3
___float_testsgn_fac:
lda FAC_EXPONENT
beq @s
@ -733,9 +733,9 @@ __fpoly2:
__enable_basic_if_needed
jsr BASIC_FAC_Poly1
jmp __float_ret2
;---------------------------------------------------------------------------------------------
__float_atn_fac:
__enable_basic_if_needed
jsr BASIC_FAC_Atn
@ -750,7 +750,7 @@ __float_add_fac_arg:
lda FAC_EXPONENT
jsr BASIC_ARG_FAC_Add
__return_with_cleanup
__float_swap_fac_arg: ; only used in ATAN2
lda FAC_EXPONENT
ldx ARG_EXPONENT
@ -777,7 +777,7 @@ __float_swap_fac_arg: ; only used in ATAN2
stx FAC_SIGN
sta ARG_SIGN
rts
.export __fneg
__fneg:
jsr ___float_float_to_fac
@ -789,8 +789,8 @@ __fneg:
sta FAC_SIGN
@sk:
jmp ___float_fac_to_float
__f_pi2: .byte $81,$80+$49,$0f,$da,$a1,$00
__f_pi: .byte $82,$80+$49,$0f,$da,$a1,$00
__f_1pi2: .byte $83,$80+$16,$cb,$e3,$f9,$00
@ -846,4 +846,4 @@ __fatan2:
ldx #>__f_1pi2
jsr __float_float_to_fac
jmp __float_ret2

View File

@ -7,12 +7,12 @@
// convert float into a string. this is surprisingly complex, so we just use
// the kernal function, and then fix up the result
char *ftoa(char *buf, float n)
{
char *ftoa(char *buf, float n)
{
char i, ii, epos = 0, ex;
char tempbuf[0x20];
_ftostr(tempbuf, n);
// find position of the 'e'
i=0;while(tempbuf[i]) {
if (tempbuf[i] == 69) { /* 'e' */
@ -21,14 +21,14 @@ char *ftoa(char *buf, float n)
}
i++;
}
if (epos == 0) {
i = ii = 0;
// no exponent, we can return the number as is
if (tempbuf[i] == '-') {
buf[ii] = tempbuf[i];
i++;ii++;
}
}
// else {
// buf[ii] = ' ';
// ii++;
@ -51,12 +51,12 @@ char *ftoa(char *buf, float n)
buf[ii] = 0;
} else {
// we have an exponent, get rid of it
i = ii = 0;
if (tempbuf[i] == '-') {
buf[ii] = tempbuf[i];
i++;ii++;
}
}
// else {
// buf[ii] = ' ';
// ii++;
@ -65,18 +65,18 @@ char *ftoa(char *buf, float n)
if (tempbuf[i] == ' ') {
i++;
}
ex = ((tempbuf[epos+2] - '0') * 10) + (tempbuf[epos+3] - '0');
if (tempbuf[epos+1] == '+') {
// positive exponent, move decimal point to right, add zeros to the right
// first copy until we see either the decimal point, or the 'e'
while (tempbuf[i] && tempbuf[i] != '.' && tempbuf[i] != 69) {
buf[ii] = tempbuf[i];
i++;ii++;
}
// 'e' found, add as many zeros as in the exponent
if (tempbuf[i] == 69) {
while(ex) {
@ -101,15 +101,15 @@ char *ftoa(char *buf, float n)
ex--;
}
}
} else {
// negative exponent, move decimal point to left, add zeros to left
buf[ii] = '0'; ii++;
buf[ii] = '.'; ii++;
ex--;
// add zeros
while(ex) {
buf[ii] = '0';
@ -124,11 +124,11 @@ char *ftoa(char *buf, float n)
buf[ii] = tempbuf[i];
i++;ii++;
}
}
buf[ii] = 0;
}
return buf;
return buf;
}

View File

@ -178,6 +178,6 @@ int main(void)
printf("fp2 0x%08lx [] %s ()\n", *((uint32_t*)&fp2), _ftostr(buf, fp2));
printf("fp3 0x%08lx [] %s ()\n", *((uint32_t*)&fp3), _ftostr(buf, fp3));
return 0;
}

View File

@ -73,7 +73,7 @@ void testconversions(void)
printf("b:0x%08lx ", ftobin(b));
n=(int)(b);
printf("n:%d\n", n);
b=atof("1234");
printf("b:0x%08lx ", ftobin(b));
n=(int)(b);
@ -83,7 +83,7 @@ void testconversions(void)
printf("s:%s\n", strbuf);
printf("a:%s\n", _ftostr(strbuf, (float)(1234)));
printf("a:%s b:%s c:%s\n",
_ftostr(strbuf, (float)(1234)),
_ftostr(strbuf2, (float)(5678)),
@ -127,7 +127,7 @@ void testcompare(void)
cgetc();
#endif
}
int main(void)
{
printf("sizeof (float): %d\n", (int)sizeof(float));

View File

@ -55,7 +55,7 @@ int main(void)
#if 1
printf("(local) get address, read via ptr\n");
fp2 = 23.1234f;
// get address of local
p = (uintptr_t)&fp2;
fp_p = (float*)p;

View File

@ -169,11 +169,11 @@ void f1(void)
#if 0
if(FCMPGT(0x00028000,U16TOF(0)))
{
if (FCMPGTEQ(var_i,(U16TOF(var_bs+1000)))) break;
if (FCMPGTEQ(var_i,(U16TOF(var_bs+1000)))) break;
}
else if(FCMPLT(0x00028000,U16TOF(0)))
{
if (FCMPLTEQ(var_i,(U16TOF(var_bs+1000)))) break;
if (FCMPLTEQ(var_i,(U16TOF(var_bs+1000)))) break;
}
#endif
// var_i=var_i + 0x00028000;
@ -202,11 +202,11 @@ void testbasicmath(void)
{
printf("\ntestbasicmath:\n\n");
t=123;
fd=(float)((int)t);
fd=(float)((int)t);
fs=_fneg(fd);
_ftostr(strbuf,fd);
_ftostr(strbuf,fd);
printf("123:%s\n",strbuf);
_ftostr(strbuf,fs);
_ftostr(strbuf,fs);
printf("-123:%s\n",strbuf);
a = (float)(4321);
@ -227,37 +227,37 @@ void testbasicmath(void)
_ftoa(strbuf, c1);
printf("1111-2222:%s\n", strbuf);
fd=(float)((int)t);
fs=(float)((int)2);
fd=(float)((int)t);
fs=(float)((int)2);
fd=fd / fs;
_ftostr(strbuf,fd);
_ftostr(strbuf,fd);
printf("t:%s\n",strbuf);
// 1234 / 60 = 20,5666...
t=1234;
fd=(float)((int)t);
fs=(float)((int)60);
fd=(float)((int)t);
fs=(float)((int)60);
fd=fd / fs;
_ftostr(strbuf,fd);
_ftostr(strbuf,fd);
printf("t:%s\n",strbuf);
// 5678 / 60 = 94,6333...
t=5678;
fd=(float)((int)t);
fs=(float)((int)60);
fd=(float)((int)t);
fs=(float)((int)60);
fd=fd / fs;
_ftostr(strbuf,fd);
_ftostr(strbuf,fd);
printf("t:%s\n",strbuf);
// ! operator DOES work on floats!
fd=(float)((int)4);
fd=(float)((int)4);
fd=!fd;
_ftostr(strbuf,!fd);
_ftostr(strbuf,!fd);
printf("!!4:%s\n",strbuf);
fd=(float)((int)0);
fd=(float)((int)0);
fd=!fd;
_ftostr(strbuf,!fd);
_ftostr(strbuf,!fd);
printf("!!0:%s\n",strbuf);
a = 10.0f;

View File

@ -24,7 +24,7 @@ char *_ftostr(char *d, float s)
return d;
}
char *_ftoa(char *d, float s)
char *_ftoa(char *d, float s)
{
if (d == NULL) {
d = &buffer[0];

View File

@ -8,42 +8,42 @@
; Primary = TOS + Primary (like tosaddeax)
.export ftosaddeax
;ftosaddeax:
;ftosaddeax:
; FIXME
; rts
; rts
; CC65 runtime: long add
; ; EAX = TOS + EAX
;
;
; ;tosadd0ax:
; ldy #$00
; sty sreg
; sty sreg+1
;
;
; ;tosaddeax:
; clc
; ldy #0
; adc (sp),y ; lo byte
; iny
;
;
; sta tmp1 ; use as temp storage
; txa
; adc (sp),y ; byte 1
; tax
; iny
;
;
; lda sreg
; adc (sp),y ; byte 2
; sta sreg
; iny
;
;
; lda sreg+1
; adc (sp),y ; byte 3
; sta sreg+1
; lda tmp1 ; load byte 0
; jmp addysp1 ; drop TOS
; found at https://github.com/CrashAndSideburns/6502ieee754/blob/main/arithmetic/addition.s
@ -51,7 +51,7 @@
ftosaddeax:
; arg0: a/x/sreg/sreg+1
; arg1: (sp),y (y=0..3)
lda #0
sta SIGN_ONE
sta SIGN_TWO
@ -64,7 +64,7 @@ ftosaddeax:
lda sreg+0
ROL
STA MANTISSA_TWO + 2
; Pull MSB of mantissa off of stack and shift exponent LSB into carry.
tax
ROL
@ -111,7 +111,7 @@ ftosaddeax:
ROR MANTISSA_TWO + 1
ROR MANTISSA_TWO + 2
ROR MANTISSA_TWO + 3
@add_first_implicit_bit:
LDA EXPONENT_ONE
CMP #$00
@ -216,7 +216,7 @@ ftosaddeax:
; PHA
; PHA
; PHA
LDA #$ff
sta sreg+1
sta sreg
@ -633,5 +633,5 @@ ftosaddeax:
LDA MANTISSA_ONE + 3
jmp addysp1 ; drop TOS
RTS
RTS

View File

@ -7,6 +7,6 @@
.import popax
.export ftosdiveax
ftosdiveax:
ftosdiveax:
; FIXME
rts
rts

View File

@ -7,6 +7,6 @@
.import popax
.export ftosmuleax
ftosmuleax:
ftosmuleax:
; FIXME
rts
rts

View File

@ -7,11 +7,11 @@
.include "ieee754.inc"
.import ftosaddeax
.export ftossubeax
ftossubeax:
; FIXME
rts
rts
; found at https://github.com/CrashAndSideburns/6502ieee754/blob/main/arithmetic/addition.s
; subtraction:

View File

@ -4,4 +4,4 @@ MANTISSA_ONE = $e4 ; e4, e5, e6, e7, e8, e9, ea (7 bytes)
SIGN_TWO = $eb
EXPONENT_TWO = $ec
MANTISSA_TWO = $ed
MANTISSA_TWO = $ed

View File

@ -3,12 +3,12 @@
#define _FLOAT_H_
/* ieee754 32bit format:
*
*
* sign
* / /exponent/mantissa
* 3 32222222 22211111111110000000000
* 1 09876543 21098765432109876543210
*
*
* The sign is stored in bit 31.
* The exponent can be computed from bits 23-30 by subtracting 127. (128 = 2^1)
* The mantissa is stored in bits 0-22.
@ -51,4 +51,4 @@ float __fastcall__ _strtof(char *d);
#define _fpreset()
#endif /* _FLOAT_H_ */

View File

@ -49,4 +49,4 @@ float __fastcall__ _fatan2(float x, float y);
float ffloor(float x);
#endif /* _MATH_H_ */

View File

@ -1,5 +1,5 @@
.include "wozfp.inc"
.export ftoseqeax
ftoseqeax:
; FIXME

View File

@ -1,5 +1,5 @@
.include "wozfp.inc"
.export ftosgeeax
ftosgeeax:
; FIXME

View File

@ -1,5 +1,5 @@
.include "wozfp.inc"
.export ftosgteax
ftosgteax:
; FIXME

View File

@ -1,5 +1,5 @@
.include "wozfp.inc"
.export ftosleeax
ftosleeax:
; FIXME

View File

@ -1,5 +1,5 @@
.include "wozfp.inc"
.export ftoslteax
ftoslteax:
; FIXME

View File

@ -1,5 +1,5 @@
.include "wozfp.inc"
.export ftosneeax
ftosneeax:
; FIXME

View File

@ -5,4 +5,4 @@ ftossubeax:
; FIXME
lda #0
tax
rts
rts

View File

@ -13,4 +13,4 @@
SEXP = T+4
INT = SEXP+4
;