Update convert_i16_to_FAC1

This commit is contained in:
Rikard Nordgren authored and FeralChild64 committed 2026-03-29 21:45:24 +02:00
1 parent 64ac8b2073
commit 94f8dfc822
4 files changed
+25 -43

No files matched your search

+1 -1
View File
@@ -237,7 +237,7 @@ Floating point mathematical routines - not official, but well known and broadly
| `$BC2B` | `sgn_FAC1_A` | DONE | From the Microsoft BASIC, original name: SIGN | | `$BC2B` | `sgn_FAC1_A` | DONE | From the Microsoft BASIC, original name: SIGN |
| `$BC39` | `sgn_FAC1` | DONE | From the Microsoft BASIC, original name: SGN | | `$BC39` | `sgn_FAC1` | DONE | From the Microsoft BASIC, original name: SGN |
| `$BC3C` | `convert_A_to_FAC1` | DONE | From the Microsoft BASIC, original name: FLOAT | | `$BC3C` | `convert_A_to_FAC1` | DONE | From the Microsoft BASIC, original name: FLOAT |
| `$BC44` | `convert_i16_to_FAC1` | DONE | | | `$BC44` | `convert_i16_to_FAC1` | DONE | From the Microsoft BASIC, original name: FLOATS |
| `$BC58` | `abs_FAC1` | DONE | From the Microsoft BASIC, original name: ABS | | `$BC58` | `abs_FAC1` | DONE | From the Microsoft BASIC, original name: ABS |
| `$BC5B` | `FCOMP` | DONE | | | `$BC5B` | `FCOMP` | DONE | |
| `$BC9B` | `QINT` | DONE | From the Microsoft BASIC, original name: QINT | | `$BC9B` | `QINT` | DONE | From the Microsoft BASIC, original name: QINT |
+22 -15
View File
@@ -3,27 +3,34 @@
;; #LAYOUT# * BASIC_0 #TAKE ;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE ;; #LAYOUT# * * #IGNORE
; ; This file is under the MIT license, it contains code released by Microsoft Corporation.
; See LICENSE for more information.
; Math package - Convert signed 16-bit integer to floating point ; Math package - Convert signed 16-bit integer to floating point
; ;
; This is verified to be identical to the original Microsoft implementation where it was named FLOATS.
;
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics ; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
; - https://www.c64-wiki.com/wiki/GIVAYF (which calls this function) ; - https://www.c64-wiki.com/wiki/GIVAYF (which calls this function)
; ;
; Convert the signed 16-bit integer in FAC1 mantissa ($62:$63) ; Convert the signed 16-bit integer in FAC1 mantissa ($62:$63)
; into a floating point number in FAC1 ; into a floating point number in FAC1. Assume X=exponent
;
; NOTE: ; Alternative entry points:
; According to https://c64os.com/post/floatingpointmath at $BC49 ; FLOATC: Assume FAC1_mantissa+0 and +1 loaded. Assume CF=0 if negative and C=1 if positive
; Assume FAC1_mantissa+0 and +1. X=exponent and C=0 if negative and C=1 if positive ; FLOATB: as for FLOATC and do not clear FAC1_mantissa+2 and +3 and set sign and FACOV to A
convert_i16_to_FAC1: convert_i16_to_FAC1:
ldx #$90
jsr carry
jmp convert_i16_expsign_to_FAC1 ; This should be at $BC49 (see note above) lda FAC1_mantissa+0
eor #$FF
rol ; CF = Complement of sign
carry: FLOATC:
lda FAC1_mantissa lda #0
cmp #$80 ; Copy sign into carry sta FAC1_mantissa+3
rts sta FAC1_mantissa+2
FLOATB:
stx FAC1_exponent
sta FACOV
sta FAC1_sign
jmp abs_and_normal_FAC1
@@ -1,24 +0,0 @@
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
;
; Math package - convert i16 with exponent in X and sign in C to FAC1
convert_i16_expsign_to_FAC1:
lda #$00
sta FAC1_mantissa+2 ; Clear high bytes of mantissa
sta FAC1_mantissa+3
stx FAC1_exponent
sta FAC1_sign
bcc @1
; Handle signed int
lda FAC1_mantissa ; Clear sign bit of int 16
and #$7F
sta FAC1_mantissa
ldy #>CONST_NEG_32768 ; Subtract with 32768 to invert negative number
lda #<CONST_NEG_32768
jsr add_MEM_FAC1
@1: jmp normal_FAC1
+2 -3
View File
@@ -20,7 +20,7 @@ int matches[MAX_SIZE];
int phase_mask[MAX_SIZE+MAX_SIZE]; int phase_mask[MAX_SIZE+MAX_SIZE];
#define NUM_CHUNKS 8 #define NUM_CHUNKS 7
// Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC // Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC
unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = { unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {
0xB849, 0xB84F, 0xB849, 0xB84F,
@@ -28,8 +28,7 @@ unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {
0xB947, 0xB97D, 0xB947, 0xB97D,
0xB983, 0xB9BB, 0xB983, 0xB9BB,
0xBBA2, 0xBC1A, 0xBBA2, 0xBC1A,
0xBC2B, 0xBC43, 0xBC2B, 0xBC5A,
0xBC58, 0xBC5A,
0xBC9B, 0xBCF2, 0xBC9B, 0xBCF2,
}; };