diff --git a/LICENSE b/LICENSE
index 8ce246b0..3c67a682 100644
--- a/LICENSE
+++ b/LICENSE
@@ -19,3 +19,26 @@ including each source file, unless otherwise noted in each file or directory.
along with this program. If not, see .
+Some BASIC files (noted in the specific files) are subject to this license and copyright:
+
+MIT License
+
+ Copyright (c) Microsoft Corporation.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE
diff --git a/Makefile b/Makefile
index a06a6849..e98e5796 100644
--- a/Makefile
+++ b/Makefile
@@ -931,7 +931,7 @@ testremote: build/kernal_custom.rom build/basic_custom.rom $(TARGET_CHR_PXL) bui
testsimilarity: $(TOOL_SIMILARITY) $(DIR_GEN)/OUTx_x.BIN $(ROM_CBM_KERNAL) $(ROM_CBM_BASIC)
$(TOOL_SIMILARITY) $(ROM_CBM_KERNAL) $(DIR_GEN)/OUTx_x.BIN
- $(TOOL_SIMILARITY) $(ROM_CBM_BASIC) $(DIR_GEN)/OUTx_x.BIN
+ $(TOOL_SIMILARITY) $(ROM_CBM_BASIC) $(DIR_GEN)/OUTx_x.BIN --basic
build/testresults: testsuite/unit/testresults.cc
$(CXX) -std=c++20 -O2 -Wall -o $@ $<
diff --git a/STATUS.md b/STATUS.md
index 4ba6a553..de65c125 100644
--- a/STATUS.md
+++ b/STATUS.md
@@ -228,8 +228,8 @@ Floating point mathematical routines - not official, but well known and broadly
| `$BBD0` | `mov_r_FAC1_VAR` | PARTIAL | not fully tested yet |
| `$BBD4` | `mov_r_FAC1_MEM` | PARTIAL | not fully tested yet |
| `$BBFC` | `mov_FAC2_FAC1` | DONE | |
-| `$BC0C` | `mov_r_FAC1_FAC2` | PARTIAL | not fully tested yet |
-| `$BC0F` | `mov_FAC1_FAC2` | DONE | |
+| `$BC0C` | `mov_r_FAC1_FAC2` | DONE | From the Microsoft BASIC, original name: MOVAF |
+| `$BC0F` | `mov_FAC1_FAC2` | DONE | From the Microsoft BASIC, original name: MOVEF |
| `$BC1B` | `round_FAC1` | PARTIAL | not fully tested yet |
| `$BC2B` | `sgn_FAC1_A` | DONE | |
| `$BC39` | `sgn_FAC1` | DONE | |
diff --git a/src/basic/math_mov/bc0c.mov_r_FAC1_FAC2.s b/src/basic/math_mov/bc0c.mov_r_FAC1_FAC2.s
index dbaae34c..0cdc9570 100644
--- a/src/basic/math_mov/bc0c.mov_r_FAC1_FAC2.s
+++ b/src/basic/math_mov/bc0c.mov_r_FAC1_FAC2.s
@@ -3,13 +3,19 @@
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
+; This file is under the MIT license, it contains code released by Microsoft Corporation.
+; See LICENSE for more information.
+
;
; Math package - round and move FAC1 to FAC2
;
+; This is identical to the original Microsoft implementation where it was named MOVAF.
+;
; Output:
; - .A - FAC1 exponent
;
; See also:
+; - https://github.com/microsoft/BASIC-M6502/blob/7460af2c03ae19c0e60ff327489229d2005b9357/m6502.asm#L5540C1-L5548C12
; - [CM64] Computes Mapping the Commodore 64 - page 115
; - https://www.c64-wiki.com/wiki/BASIC-ROM
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
diff --git a/src/basic/math_mov/bc0f.mov_FAC1_FAC2.jmp.s b/src/basic/math_mov/bc0f.mov_FAC1_FAC2.jmp.s
deleted file mode 100644
index f7409462..00000000
--- a/src/basic/math_mov/bc0f.mov_FAC1_FAC2.jmp.s
+++ /dev/null
@@ -1,8 +0,0 @@
-;; #LAYOUT# STD * #TAKE
-;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
-;; #LAYOUT# * BASIC_0 #TAKE
-;; #LAYOUT# * * #IGNORE
-
-; Just a compatibility jump - our routine is longer than original one
-
- jmp mov_FAC1_FAC2
diff --git a/src/basic/math_mov/bc0f.mov_FAC1_FAC2.s b/src/basic/math_mov/bc0f.mov_FAC1_FAC2.s
new file mode 100644
index 00000000..65c69a65
--- /dev/null
+++ b/src/basic/math_mov/bc0f.mov_FAC1_FAC2.s
@@ -0,0 +1,41 @@
+;; #LAYOUT# STD * #TAKE
+;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
+;; #LAYOUT# * BASIC_0 #TAKE
+;; #LAYOUT# * * #IGNORE
+
+; This file is under the MIT license, it contains code released by Microsoft Corporation.
+; See LICENSE for more information.
+
+;
+; Math package - move FAC1 to FAC2
+;
+; This is verified to be identical to the original Microsoft implementation where it was named MOVEF.
+;
+; Output:
+; - .A - FAC1 exponent
+; - .X - always 0
+
+; Preserves:
+; - .Y
+;
+; Note:
+; - Always clears FACOV, not sure why
+;
+; See also:
+; - https://github.com/microsoft/BASIC-M6502/blob/7460af2c03ae19c0e60ff327489229d2005b9357/m6502.asm#L5540C1-L5548C12
+; - [CM64] Computes Mapping the Commodore 64 - page 115
+; - https://www.c64-wiki.com/wiki/BASIC-ROM
+; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
+;
+
+mov_FAC1_FAC2:
+
+ ldx #6
+
+@1
+ lda FAC1_exponent - 1,X
+ sta FAC2_exponent - 1,X
+ dex
+ bne @1
+ stx FACOV ; Always zero
+ rts
diff --git a/src/basic/math_mov/mov_FAC1_FAC2.s b/src/basic/math_mov/mov_FAC1_FAC2.s
deleted file mode 100644
index 25202fc0..00000000
--- a/src/basic/math_mov/mov_FAC1_FAC2.s
+++ /dev/null
@@ -1,51 +0,0 @@
-;; #LAYOUT# STD * #TAKE
-;; #LAYOUT# * BASIC_0 #TAKE
-;; #LAYOUT# * * #IGNORE
-
-;
-; Math package - move FAC1 to FAC2
-;
-; Output (all found by experimentation):
-; - .A - FAC1 exponent
-; - .X - always 0
-;
-; Preserves (found by experimentation):
-; - .Y
-;
-; Note:
-; - observed that original ROM always clears FACOV, not sure why
-;
-; See also:
-; - [CM64] Computes Mapping the Commodore 64 - page 115
-; - https://www.c64-wiki.com/wiki/BASIC-ROM
-; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
-;
-
-mov_FAC1_FAC2:
-
- ; Copy the exponent
- lda FAC1_exponent
- sta FAC2_exponent
- beq @1 ; for 0 no need to copy mantissa and sign
-
- ; Copy the mantissa
- lda FAC1_mantissa+0
- sta FAC2_mantissa+0
- lda FAC1_mantissa+1
- sta FAC2_mantissa+1
- lda FAC1_mantissa+2
- sta FAC2_mantissa+2
- lda FAC1_mantissa+3
- sta FAC2_mantissa+3
-
- ; Copy the sign
- lda FAC1_sign
- sta FAC2_sign
-
- lda FAC1_exponent
-@1:
- ; Duplicate the original ROM behaviour
- ldx #$00
- stx FACOV
-
- rts
diff --git a/strings/0000000003 b/strings/0000000003
new file mode 100644
index 00000000..92362534
--- /dev/null
+++ b/strings/0000000003
@@ -0,0 +1,3 @@
+00 00 00 00 03
+
+Mostly NULL
diff --git a/strings/BC68203CBC b/strings/BC68203CBC
new file mode 100644
index 00000000..9e23597a
--- /dev/null
+++ b/strings/BC68203CBC
@@ -0,0 +1,3 @@
+$BD + PLA + JSR $BC3C
+
+Fragment + jump to well known floating point subroutine
diff --git a/strings/CAD0F9867060 b/strings/CAD0F9867060
new file mode 100644
index 00000000..c0c7dada
--- /dev/null
+++ b/strings/CAD0F9867060
@@ -0,0 +1,3 @@
+DEX + BNE $F9 + STX $70 + RTS
+
+Loop fragment + store to well known zero page location
diff --git a/tools/similarity.c b/tools/similarity.c
index 235b5ceb..7f1e3b51 100644
--- a/tools/similarity.c
+++ b/tools/similarity.c
@@ -20,20 +20,31 @@ int matches[MAX_SIZE];
int phase_mask[MAX_SIZE+MAX_SIZE];
+#define NUM_CHUNKS 1
+// Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC
+unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {0xBC0C, 0xBC1A};
+
+
int main(int argc,char **argv)
{
int verbose=0;
-
+ int basic = 0;
+
if (argc<3) {
- fprintf(stderr,"usage: similarity [verbose]\n");
+ fprintf(stderr,"usage: similarity [--verbose] [--basic]\n");
exit(-1);
}
- if (argc==4) {
- if (!strcmp(argv[3],"verbose")) verbose=1;
- else {
- fprintf(stderr,"Unrecognised directive.\n");
- exit(-1);
- }
+ if (argc >= 4) {
+ for (int i = 3; i < argc; i++) {
+ if (!strcmp(argv[i], "--verbose")) {
+ verbose = 1;
+ } else if (!strcmp(argv[i], "--basic")) {
+ basic = 1;
+ } else {
+ fprintf(stderr, "Unrecognised directive.\n");
+ exit(-1);
+ }
+ }
}
for(int i=0;i