How does the floating point math package in BASIC work?

Hardware Hacking, Programming and Game Solutions/Cheats
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the floating point math package in BASIC work?

Post by jedie »

Run the first Test.

Test values are: 0, 1, 2, 126, 127, 128, 129, 130, 253, 254, 255

Values as expected are: 1, 2, 126, 127, 128, 130, 254
Values with results in differences are: 0, 129, 253, 255

Complete Output:

Code: Select all

Float value was: 0
	exponent......: dez.: 0 hex: $00
	exponent byte.: dez.: 128 hex: $80
	mantissa value: dez.: 0.0
	mantissa bytes: dez.: [0, 0, 0, 0] hex: $00, $00, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $80, $00, $00, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10000000 00000000 00000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $00 (dez: 0)      | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $00 (dez: 0)      | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** ERROR:
in RAM...: $00, $00, $00, $00, $00, $00
Reference: $80, $00, $00, $00, $00, $00

-------------------------------------------------------------------------------

Float value was: 1
	exponent......: dez.: 1 hex: $01
	exponent byte.: dez.: 129 hex: $81
	mantissa value: dez.: 0.5
	mantissa bytes: dez.: [128, 0, 0, 0] hex: $80, $00, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $81, $80, $00, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10000001 10000000 00000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $81 (dez: 129)    | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $80 (dez: 128)    | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** OK

-------------------------------------------------------------------------------

Float value was: 2
	exponent......: dez.: 2 hex: $02
	exponent byte.: dez.: 130 hex: $82
	mantissa value: dez.: 0.5
	mantissa bytes: dez.: [128, 0, 0, 0] hex: $80, $00, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $82, $80, $00, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10000010 10000000 00000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $82 (dez: 130)    | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $80 (dez: 128)    | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** OK

-------------------------------------------------------------------------------


...

Float value was: 126
	exponent......: dez.: 7 hex: $07
	exponent byte.: dez.: 135 hex: $87
	mantissa value: dez.: 0.984375
	mantissa bytes: dez.: [252, 0, 0, 0] hex: $fc, $00, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $87, $fc, $00, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10000111 11111100 00000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $87 (dez: 135)    | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $fc (dez: 252)    | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** OK

-------------------------------------------------------------------------------

Float value was: 127
	exponent......: dez.: 7 hex: $07
	exponent byte.: dez.: 135 hex: $87
	mantissa value: dez.: 0.9921875
	mantissa bytes: dez.: [254, 0, 0, 0] hex: $fe, $00, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $87, $fe, $00, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10000111 11111110 00000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $87 (dez: 135)    | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $fe (dez: 254)    | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** OK

-------------------------------------------------------------------------------

Float value was: 128
	exponent......: dez.: 8 hex: $08
	exponent byte.: dez.: 136 hex: $88
	mantissa value: dez.: 0.5
	mantissa bytes: dez.: [128, 0, 0, 0] hex: $80, $00, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $88, $80, $00, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10001000 10000000 00000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $88 (dez: 136)    | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $80 (dez: 128)    | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** OK

-------------------------------------------------------------------------------

Float value was: 129
	exponent......: dez.: 8 hex: $08
	exponent byte.: dez.: 136 hex: $88
	mantissa value: dez.: 0.50390625
	mantissa bytes: dez.: [128, 128, 0, 0] hex: $80, $80, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $88, $80, $80, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10001000 10000000 10000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $88 (dez: 136)    | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $81 (dez: 129)    | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** ERROR:
in RAM...: $88, $81, $00, $00, $00, $00
Reference: $88, $80, $80, $00, $00, $00

-------------------------------------------------------------------------------

Float value was: 130
	exponent......: dez.: 8 hex: $08
	exponent byte.: dez.: 136 hex: $88
	mantissa value: dez.: 0.5078125
	mantissa bytes: dez.: [130, 0, 0, 0] hex: $82, $00, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $88, $82, $00, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10001000 10000010 00000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $88 (dez: 136)    | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $82 (dez: 130)    | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** OK

-------------------------------------------------------------------------------


...

Float value was: 253
	exponent......: dez.: 8 hex: $08
	exponent byte.: dez.: 136 hex: $88
	mantissa value: dez.: 0.98828125
	mantissa bytes: dez.: [252, 128, 0, 0] hex: $fc, $80, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $88, $fc, $80, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10001000 11111100 10000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $88 (dez: 136)    | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $fd (dez: 253)    | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** ERROR:
in RAM...: $88, $fd, $00, $00, $00, $00
Reference: $88, $fc, $80, $00, $00, $00

-------------------------------------------------------------------------------

Float value was: 254
	exponent......: dez.: 8 hex: $08
	exponent byte.: dez.: 136 hex: $88
	mantissa value: dez.: 0.9921875
	mantissa bytes: dez.: [254, 0, 0, 0] hex: $fe, $00, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $88, $fe, $00, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10001000 11111110 00000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $88 (dez: 136)    | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $fe (dez: 254)    | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** OK

-------------------------------------------------------------------------------

Float value was: 255
	exponent......: dez.: 8 hex: $08
	exponent byte.: dez.: 136 hex: $88
	mantissa value: dez.: 0.99609375
	mantissa bytes: dez.: [254, 128, 0, 0] hex: $fe, $80, $00, $00
	matissa-sign..: hex: $00
	binary........: hex: $88, $fe, $80, $00, $00, $00
	exponent |            mantissa             | mantissa-sign
	10001000 11111110 10000000 00000000 00000000 00000000

Memory dump from $004f to $0054:
	$004f: $88 (dez: 136)    | $4f: *PV FLOATING POINT ACCUMULATOR #0 FPA0 EXPONENT
	$0050: $ff (dez: 255)    | $50: *PV FLOAT.ACCU #0 FPA0 MANTISSA MS  Most Significant Byte
	$0051: $00 (dez: 0)      | $51: *PV FLOAT.ACCU #0 FPA0 MANTISSA NMS Next Most Significant Byte
	$0052: $00 (dez: 0)      | $52: *PV FLOAT.ACCU #0 FPA0 MANTISSA NLS Next Least Significant Byte
	$0053: $00 (dez: 0)      | $53: *PV FLOAT.ACCU #0 FPA0 MANTISSA LS  Least Significant Byte
	$0054: $00 (dez: 0)      | $54: *PV FLOATING POINT ACCUMULATOR #0 FPA0 SIGN
*** ERROR:
in RAM...: $88, $ff, $00, $00, $00, $00
Reference: $88, $fe, $80, $00, $00, $00

-------------------------------------------------------------------------------

OK: [1, 2, 126, 127, 128, 130, 254]
Failed: [0, 129, 253, 255]
Any idea?


Are my reference values wrong? Has the used code part of my Emulation bugs?
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the floating point math package in BASIC work?

Post by jedie »

I try to create a BASIC test programm.

But what's the address of the "Assign D to FAC" in D32 Basic?

I tested $8C37 from Inside Dragon page 234 But without success: Image

Source code of my test program: https://github.com/jedie/PyDragon32/blo ... t_FPA0.bas
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: How does the floating point math package in BASIC work?

Post by JeeK »

jedie wrote:
JeeK wrote:for space, e.g. storing values in variables or variable arrays: the sign is encoded in the first leading bit of the mantissa which is always 1, because the mantissa is normalized (starts always with 0.1xxxxx).
Then it looks simmilar to the C64 example here: http://www.c64-wiki.com/index.php/Float ... on_example

But here the Exponent is calculated with: 152 - 129 = 23
But Inside Dragon says an page 232: 128 must be subtracted.
These representations are mainly the same. It's just the way you calculate
Case EXP-129:
2^(EXP-129) * 1.xxxxxxx
is the same as
2^(EXP-128) * 0.1xxxxxx

It depends on how the normalized representation of the mantissa is regarded ...
The dragon on my side: http://klasek.at/hc/dragon/
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: How does the floating point math package in BASIC work?

Post by JeeK »

jedie wrote:I try to create a BASIC test programm.

But what's the address of the "Assign D to FAC" in D32 Basic?

I tested $8C37 from Inside Dragon page 234 But without success:
[..]

Source code of my test program: https://github.com/jedie/PyDragon32/blo ... t_FPA0.bas
I think the problem is that the you can't read the FPA0 without destroying it, because lines like this (from above example listing)

Code: Select all

EX  =PEEK(&H004F) ' FPA0 EXPONENT
uses the FPA0, too.
Your machine-code subroutine has to save the FPA0 values to a safe place, from where they could be read from BASIC without harm. ;)
The dragon on my side: http://klasek.at/hc/dragon/
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the floating point math package in BASIC work?

Post by jedie »

JeeK wrote:I think the problem is that the you can't read the FPA0 without destroying it, because lines like this (from above example listing)

Code: Select all

EX  =PEEK(&H004F) ' FPA0 EXPONENT
uses the FPA0, too.
Your machine-code subroutine has to save the FPA0 values to a safe place, from where they could be read from BASIC without harm. ;)
Ah, you are right! Thanks!
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the floating point math package in BASIC work?

Post by jedie »

new test code:

Code: Select all

1 PRINT:PRINT "TEST FLOATS IN FPA0 V0.1"
2 PRINT "(GPL V3 OR ABOVE)"
3 PRINT:PRINT "COPYLEFT (C) 2014 JENS DIEMER":PRINT
11 COUNT=13
20 LA=&H4000			' LOAD / EXECUTE ADDRESS
25 PRINT "POKE MACHINE CODE TO: $";HEX$(LA)
30 PA = LA			' START ADDRESS FOR POKE
50 READ HB$			' HEX CONSTANTS
60 IF HB$="END" THEN 100
65 V=VAL("&H"+HB$)
70 POKE PA,V	                ' POKE VALUE INTO MEMORY
75 'PRINT "POKE $";HEX$(V);" AT $";HEX$(PA)
80 PA = PA + 1			' INCREMENT POKE ADDRESS
90 GOTO 50
100 PRINT "LOADED, END ADDRESS IS: $"; HEX$(PA-1)
110 PRINT:INPUT "INPUT START VALUE (DEZ)";D$
115 IF D$="" THEN 20000 ELSE D=VAL(D$)
130 GOTO 500
140 PRINT "UP/DOWN OR ANYKEY FOR NEW VALUE";
150 I$ = INKEY$:IF I$="" THEN 150
160 IF I$=CHR$(&H5E) THEN D=D2-(COUNT*2) : GOTO 500 ' UP KEYPRESS
170 IF I$=CHR$(&H0A) THEN D=D2 : GOTO 500 ' DOWN KEYPRESS
180 GOTO 110 ' NOT UP/DOWN
500 CLS:PRINT "D=";D
550 FOR I = 0 TO COUNT
551 D2=(D+I) 'AND &HFFFF
552 'PRINT "SET D=";D2
553 POKE &H4500,D2 ' SET START VALUE
554 'PRINT "EXEC MACHINE CODE"
560 EXEC LA
565 'PRINT "GET VALUES FROM FPA0"
570 EX  =PEEK(&H1000) ' $4F FPA0 EXPONENT
580 MP  =PEEK(&H1001) ' $50 FPA0 MS
580 NMS =PEEK(&H1002) ' %51 FPA0 NMS
580 NLS =PEEK(&H1003) ' $52 FPA0 NLS
580 LS  =PEEK(&H1004) ' $53 FPA0 LS
580 SIGN=PEEK(&H1005) ' $54 FPA0 SIGN
690 PRINT "D=";RIGHT$("  "+STR$(D2),4);" FPA0=$"+HEX$(EX)+" $"+HEX$(MS)+" $"+HEX$(NMS)+" $"+HEX$(NLS)+" $"+HEX$(LS)+" $"+HEX$(SIGN)
700 NEXT I
710 GOTO 140
1000 ' MACHINE CODE IN HEX
1010 ' LDD $4500
1020 DATA FC,45,00
1030 ' JSR $8C37     ; ADD D TO FPA0
1040 DATA BD,8C,37
1050 ' LDB   #6      ; BYTE COUNT TO MOVE
1060 DATA C6,06
1070 ' LDX   #$4F    ; SOURCE POS
1080 DATA 8E,00,4F
1090 ' LDU   #$1000  ; DESTINATION POS
1100 DATA CE,10,00
1110 ' LOOP: LDA ,X+ ; GET BYTE FROM X
1120 DATA A6,80
1130 ' STA   ,U+     ; STORE IT AT U
1140 DATA A7,C0
1150 ' DECB          ; MOVED ALL BYTES?
1160 DATA 5A
1170 ' BNE   LOOP    ; NO -> LOOP
1180 DATA 26,F9
10000 ' RTS
10010 DATA 39
10020 DATA END
20000 PRINT:PRINT "BYE"
Think the BNE is wrong. Maybe BNE with a PC offset of -5 ? But how?
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the floating point math package in BASIC work?

Post by jedie »

OK, i do a simple, boring move data:

Code: Select all

1 PRINT:PRINT "TEST FLOATS IN FPA0 V0.1"
2 PRINT "(GPL V3 OR ABOVE)"
3 PRINT:PRINT "COPYLEFT (C) 2014 JENS DIEMER":PRINT
11 COUNT=14
20 LA=&H4000			' LOAD / EXECUTE ADDRESS
25 PRINT "POKE MACHINE CODE TO: $";HEX$(LA)
30 PA = LA			' START ADDRESS FOR POKE
50 READ HB$			' HEX CONSTANTS
60 IF HB$="END" THEN 100
65 V=VAL("&H"+HB$)
70 POKE PA,V	                ' POKE VALUE INTO MEMORY
75 'PRINT "POKE $";HEX$(V);" AT $";HEX$(PA)
80 PA = PA + 1			' INCREMENT POKE ADDRESS
90 GOTO 50
100 PRINT "LOADED, END ADDRESS IS: $"; HEX$(PA-1)
110 PRINT:INPUT "INPUT START VALUE (DEZ)";D$
115 IF D$="" THEN 20000 ELSE D=VAL(D$)
130 GOTO 500
140 PRINT "UP/DOWN OR ANYKEY FOR NEW VALUE";
150 I$ = INKEY$:IF I$="" THEN 150
160 IF I$=CHR$(&H5E) THEN D=D2-(COUNT*2) : GOTO 500 ' UP KEYPRESS
170 IF I$=CHR$(&H0A) THEN D=D2 : GOTO 500 ' DOWN KEYPRESS
180 GOTO 110 ' NOT UP/DOWN
500 CLS':PRINT "D=";D
550 FOR I = 0 TO COUNT
551 D2=(D+I) 'AND &HFFFF
552 'PRINT "SET D=";D2
553 POKE &H4500,D2 ' SET START VALUE
554 'PRINT "EXEC MACHINE CODE"
560 EXEC LA
565 'PRINT "GET VALUES FROM FPA0"
570 EX  =PEEK(&H104F) ' $4F FPA0 EXPONENT
580 MP  =PEEK(&H1050) ' $50 FPA0 MS
580 NMS =PEEK(&H1051) ' %51 FPA0 NMS
580 NLS =PEEK(&H1052) ' $52 FPA0 NLS
580 LS  =PEEK(&H1053) ' $53 FPA0 LS
580 SIGN=PEEK(&H1054) ' $54 FPA0 SIGN
690 PRINT "D=";RIGHT$("  "+STR$(D2),4);" FPA0=$"+HEX$(EX)+" $"+HEX$(MS)+" $"+HEX$(NMS)+" $"+HEX$(NLS)+" $"+HEX$(LS)+" $"+HEX$(SIGN)
700 NEXT I
710 GOTO 140
1000 ' MACHINE CODE IN HEX
1010 ' LDD $4500
1020 DATA FC,45,00
1030 ' JSR $8C37     ; ADD D TO FPA0
1040 DATA BD,8C,37
1050 ' LDB #$4F
1060 DATA C6,4F
1070 ' STB $104F
1080 DATA F7,10,4F
1090 ' LDB #$50
1100 DATA C6,50
1110 ' STB $1050
1120 DATA F7,10,50
1130 ' LDB $51
1140 DATA D6,51
1150 ' STB $1051
1160 DATA F7,10,51
1170 ' LDB #$52
1180 DATA C6,52
1190 ' STB $1052
1200 DATA F7,10,52
1210 ' LDB #$53
1220 DATA C6,53
1230 ' STB $1053
1240 DATA F7,10,53
1250 ' LDB #$54
1260 DATA C6,54
1270 ' STB $1054
1280 DATA F7,10,54
10000 ' RTS
10010 DATA 39
10020 DATA END
20000 PRINT:PRINT "BYE"
Also doesn't work correctly:
Image





EDIT: OK, found one error, e.g.:

Code: Select all

1050 ' LDB #$4F
1060 DATA C6,4F
changed to:

Code: Select all

1050 ' LDB $4F
1060 DATA D6,4F
But also not working correctly:

Image



Complete code: https://gist.github.com/jedie/22dba94f5b7534f946f9
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: How does the floating point math package in BASIC work?

Post by JeeK »

jedie wrote:[..]

EDIT: OK, found one error, e.g.:

Code: Select all

1050 ' LDB #$4F
1060 DATA C6,4F
changed to:

Code: Select all

1050 ' LDB $4F
1060 DATA D6,4F
But also not working correctly:


[..]
There are multiple errors:

Code: Select all

1050 ' LDB #$4F          <--------
1060 DATA C6,4F
1070 ' STB $104F
1080 DATA F7,10,4F
1090 ' LDB #$50          <--------
1100 DATA C6,50
1110 ' STB $1050
1120 DATA F7,10,50
1130 ' LDB $51
1140 DATA D6,51
1150 ' STB $1051
1160 DATA F7,10,51
1170 ' LDB #$52          <--------
1180 DATA C6,52
1190 ' STB $1052
1200 DATA F7,10,52
1210 ' LDB #$53          <--------
1220 DATA C6,53
1230 ' STB $1053
1240 DATA F7,10,53
1250 ' LDB #$54          <--------
1260 DATA C6,54
1270 ' STB $1054
All C6 opcodes should be D6 ...
The dragon on my side: http://klasek.at/hc/dragon/
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: How does the floating point math package in BASIC work?

Post by jedie »

JeeK wrote:All C6 opcodes should be D6 ...
I have changed all C6 to D6, see complete code: https://gist.github.com/jedie/22dba94f5b7534f946f9 :D

EDIT: I testes bigger values and see:

Image

Seems that "mantissa sign" switched correctly?
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: How does the floating point math package in BASIC work?

Post by JeeK »

jedie wrote:
JeeK wrote:All C6 opcodes should be D6 ...
I have changed all C6 to D6, see complete code: https://gist.github.com/jedie/22dba94f5b7534f946f9 :D

EDIT: I testes bigger values and see:
[..]
Seems that "mantissa sign" switched correctly?
Whatever you expecting, I doubt that $8C37 does it in this way. A $942D it can be seen that A is loaded from $50 (destroys D) and B is stored as exponent ...??? I can't imagine this is a usable entry point... (referring to the disassembly you provided in the corresponding forums thread).
If compare it to the D64 ROM this entry point looks more like that you are expecting. Maybe some information has been intermixed between various ROM versions (D32 ROM and D64 ROM in D32 mode)?
The dragon on my side: http://klasek.at/hc/dragon/
Post Reply