Update atn_FAC1

Also update similarity to be able to test BASIC parts in KERNAL ROM area
This commit is contained in:
Rikard Nordgren authored and FeralChild64 committed 2026-04-29 21:18:16 +02:00
1 parent 629b1efe20
commit d3e4af6f6f
4 files changed
+54 -43

No files matched your search

+1 -1
View File
@@ -930,7 +930,7 @@ testremote: build/kernal_custom.rom build/basic_custom.rom $(TARGET_CHR_PXL) bui
x64 -kernal build/kernal_custom.rom -basic build/basic_custom.rom -chargen $(TARGET_CHR_PXL) -moncommands build/symbols_custom.vs -remotemonitor x64 -kernal build/kernal_custom.rom -basic build/basic_custom.rom -chargen $(TARGET_CHR_PXL) -moncommands build/symbols_custom.vs -remotemonitor
testsimilarity: $(TOOL_SIMILARITY) $(DIR_TST38)/OUTx_x.BIN $(ROM_CBM_KERNAL) $(ROM_CBM_BASIC) testsimilarity: $(TOOL_SIMILARITY) $(DIR_TST38)/OUTx_x.BIN $(ROM_CBM_KERNAL) $(ROM_CBM_BASIC)
$(TOOL_SIMILARITY) $(ROM_CBM_KERNAL) $(DIR_TST38)/OUTx_x.BIN $(TOOL_SIMILARITY) $(ROM_CBM_KERNAL) $(DIR_TST38)/OUTx_x.BIN --basic --high
$(TOOL_SIMILARITY) $(ROM_CBM_BASIC) $(DIR_TST38)/OUTx_x.BIN --basic $(TOOL_SIMILARITY) $(ROM_CBM_BASIC) $(DIR_TST38)/OUTx_x.BIN --basic
build/testresults: testsuite/unit/testresults.cc build/testresults: testsuite/unit/testresults.cc
+1 -1
View File
@@ -265,7 +265,7 @@ Floating point mathematical routines - not official, but well known and broadly
| `$E264` | `cos_FAC1` | PARTIAL | not fully tested yet | | `$E264` | `cos_FAC1` | PARTIAL | not fully tested yet |
| `$E26B` | `sin_FAC1` | PARTIAL | not fully tested yet | | `$E26B` | `sin_FAC1` | PARTIAL | not fully tested yet |
| `$E2B4` | `tan_FAC1` | PARTIAL | not fully tested yet | | `$E2B4` | `tan_FAC1` | PARTIAL | not fully tested yet |
| `$E30E` | `atn_FAC1` | PARTIAL | not fully tested yet | | `$E30E` | `atn_FAC1` | DONE | From the Microsoft BASIC, original name: ATN |
<br /> <br />
+33 -36
View File
@@ -2,9 +2,13 @@
;; #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 - arc tangent of FAC1 ; Math package - arc tangent of FAC1
; ;
; This is verified to be identical to the original Microsoft implementation where it was named ATN
;
; See also: ; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 211 ; - [CM64] Computes Mapping the Commodore 64 - page 211
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic ; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
@@ -23,41 +27,34 @@
atn_FAC1: atn_FAC1:
lda FAC1_sign ; Save sign of FAC1 on the stack lda FAC1_sign ; What is sign?
pha pha ; (Meanwhile save it for later)
lda #$00 ; FAC1 = abs(FAC1) bpl ATN1
sta FAC1_sign jsr toggle_sign_FAC1 ; If negative, negate FAC1, use arctan(x) = -arctan(-x)
sta TEMPF1 ; AX not scaled ATN1:
lda FAC1_exponent
lda #<const_ONE pha ; Save this too for later
ldy #>const_ONE cmp #$81 ; See if FAC1 >= 1.0
jsr FCOMP bcc ATN2 ; It is less than 1
bmi atn_skipscale lda #<const_ONE ; Get pointer to 1.0
ldy #>const_ONE
lda #<const_ONE jsr div_MEM_FAC1 ; Compute reciprocal. Use arctan(x) = pi/2 - arctan(1/x)
ldy #>const_ONE ATN2:
jsr div_MEM_FAC1 lda #<poly_atn ; Pointer to arctan polynomial
inc TEMPF1 ; AX scaled ldy #>poly_atn
jsr poly1_FAC1
atn_skipscale: pla
lda #<poly_atn cmp #$81 ; Was original argument < 1 ?
ldy #>poly_atn bcc ATN3 ; Yes
jsr poly1_FAC1 lda #<const_HALF_PI
ldy #>const_HALF_PI
lda TEMPF1 jsr sub_MEM_FAC1 ; Subtract arctan from pi/2
beq atn_skipoffset ATN3:
pla ; Was original argument positive?
lda #<const_HALF_PI bpl ATN4 ; Yes
ldy #>const_HALF_PI jmp toggle_sign_FAC1 ; If negative, negate result
jsr sub_MEM_FAC1 ATN4:
rts
atn_skipoffset:
pla
bpl atn_out
jmp toggle_sign_FAC1
atn_out:
rts
} else { } else {
+19 -5
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 9 #define NUM_CHUNKS 10
// 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] = {
0xB391, 0xB39D, 0xB391, 0xB39D,
@@ -32,6 +32,7 @@ unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {
0xBDB3, 0xBDC1, 0xBDB3, 0xBDC1,
0xBDDD, 0xBF51, 0xBDDD, 0xBF51,
0xBFB4, 0xBFEC, 0xBFB4, 0xBFEC,
0xE30E, 0xE33D,
}; };
@@ -40,6 +41,7 @@ int main(int argc,char **argv)
{ {
int verbose=0; int verbose=0;
int basic = 0; int basic = 0;
int high =0;
if (argc<3) { if (argc<3) {
fprintf(stderr,"usage: similarity <file1> <file2> [--verbose] [--basic]\n"); fprintf(stderr,"usage: similarity <file1> <file2> [--verbose] [--basic]\n");
@@ -51,6 +53,8 @@ int main(int argc,char **argv)
verbose = 1; verbose = 1;
} else if (!strcmp(argv[i], "--basic")) { } else if (!strcmp(argv[i], "--basic")) {
basic = 1; basic = 1;
} else if (!strcmp(argv[i], "--high")) {
high = 1;
} else { } else {
fprintf(stderr, "Unrecognised directive.\n"); fprintf(stderr, "Unrecognised directive.\n");
exit(-1); exit(-1);
@@ -94,11 +98,21 @@ int main(int argc,char **argv)
if (basic) { if (basic) {
for (int i = 0; i < NUM_CHUNKS; i++) { for (int i = 0; i < NUM_CHUNKS; i++) {
for (int addr = microsoft_basic_chunks[i * 2]; addr <= microsoft_basic_chunks[i * 2 + 1]; addr++) { for (int addr = microsoft_basic_chunks[i * 2]; addr <= microsoft_basic_chunks[i * 2 + 1]; addr++) {
short index = addr - 0xA000; short index1, index2;
if (f1[index] != f2[index]) { if (high && addr < 0xE000 || !high && addr >= 0xE000) {
printf("BASIC does not match MS BASIC at %X (%X != %X)\n", addr, f1[index], f2[index]); continue;
} }
f1[index] = 0xFF; if (!high) {
index1 = addr - 0xA000;
index2 = index1;
} else {
index1 = addr - 0xE000;
index2 = addr - 0xA000;
}
if (f1[index1] != f2[index2]) {
printf("BASIC does not match MS BASIC at %X (%X != %X)\n", addr, f1[index1], f2[index2]);
}
f1[index1] = 0xFF;
} }
} }
} }