Update mov_FAC1_FAC2 to match the original implementation
This commit is contained in:
1 parent
0e6e0a5fc4
commit
ee3c8cb11d
11 files changed
+110
-71
No files matched your search
@@ -19,3 +19,26 @@ including each source file, unless otherwise noted in each file or directory.
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
@@ -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)
|
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_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
|
build/testresults: testsuite/unit/testresults.cc
|
||||||
$(CXX) -std=c++20 -O2 -Wall -o $@ $<
|
$(CXX) -std=c++20 -O2 -Wall -o $@ $<
|
||||||
|
|||||||
@@ -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 |
|
| `$BBD0` | `mov_r_FAC1_VAR` | PARTIAL | not fully tested yet |
|
||||||
| `$BBD4` | `mov_r_FAC1_MEM` | PARTIAL | not fully tested yet |
|
| `$BBD4` | `mov_r_FAC1_MEM` | PARTIAL | not fully tested yet |
|
||||||
| `$BBFC` | `mov_FAC2_FAC1` | DONE | |
|
| `$BBFC` | `mov_FAC2_FAC1` | DONE | |
|
||||||
| `$BC0C` | `mov_r_FAC1_FAC2` | PARTIAL | not fully tested yet |
|
| `$BC0C` | `mov_r_FAC1_FAC2` | DONE | From the Microsoft BASIC, original name: MOVAF |
|
||||||
| `$BC0F` | `mov_FAC1_FAC2` | DONE | |
|
| `$BC0F` | `mov_FAC1_FAC2` | DONE | From the Microsoft BASIC, original name: MOVEF |
|
||||||
| `$BC1B` | `round_FAC1` | PARTIAL | not fully tested yet |
|
| `$BC1B` | `round_FAC1` | PARTIAL | not fully tested yet |
|
||||||
| `$BC2B` | `sgn_FAC1_A` | DONE | |
|
| `$BC2B` | `sgn_FAC1_A` | DONE | |
|
||||||
| `$BC39` | `sgn_FAC1` | DONE | |
|
| `$BC39` | `sgn_FAC1` | DONE | |
|
||||||
|
|||||||
@@ -3,13 +3,19 @@
|
|||||||
;; #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 - round and move FAC1 to FAC2
|
; Math package - round and move FAC1 to FAC2
|
||||||
;
|
;
|
||||||
|
; This is identical to the original Microsoft implementation where it was named MOVAF.
|
||||||
|
;
|
||||||
; Output:
|
; Output:
|
||||||
; - .A - FAC1 exponent
|
; - .A - FAC1 exponent
|
||||||
;
|
;
|
||||||
; See also:
|
; See also:
|
||||||
|
; - https://github.com/microsoft/BASIC-M6502/blob/7460af2c03ae19c0e60ff327489229d2005b9357/m6502.asm#L5540C1-L5548C12
|
||||||
; - [CM64] Computes Mapping the Commodore 64 - page 115
|
; - [CM64] Computes Mapping the Commodore 64 - page 115
|
||||||
; - https://www.c64-wiki.com/wiki/BASIC-ROM
|
; - https://www.c64-wiki.com/wiki/BASIC-ROM
|
||||||
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
|
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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
|
||||||
@@ -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
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
00 00 00 00 03
|
||||||
|
|
||||||
|
Mostly NULL
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
$BD + PLA + JSR $BC3C
|
||||||
|
|
||||||
|
Fragment + jump to well known floating point subroutine
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
DEX + BNE $F9 + STX $70 + RTS
|
||||||
|
|
||||||
|
Loop fragment + store to well known zero page location
|
||||||
+28
-9
@@ -20,20 +20,31 @@ int matches[MAX_SIZE];
|
|||||||
|
|
||||||
int phase_mask[MAX_SIZE+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 main(int argc,char **argv)
|
||||||
{
|
{
|
||||||
int verbose=0;
|
int verbose=0;
|
||||||
|
int basic = 0;
|
||||||
|
|
||||||
if (argc<3) {
|
if (argc<3) {
|
||||||
fprintf(stderr,"usage: similarity <file1> <file2> [verbose]\n");
|
fprintf(stderr,"usage: similarity <file1> <file2> [--verbose] [--basic]\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
if (argc==4) {
|
if (argc >= 4) {
|
||||||
if (!strcmp(argv[3],"verbose")) verbose=1;
|
for (int i = 3; i < argc; i++) {
|
||||||
else {
|
if (!strcmp(argv[i], "--verbose")) {
|
||||||
fprintf(stderr,"Unrecognised directive.\n");
|
verbose = 1;
|
||||||
exit(-1);
|
} else if (!strcmp(argv[i], "--basic")) {
|
||||||
}
|
basic = 1;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Unrecognised directive.\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0;i<MAX_SIZE;i++) matches[i]=0;
|
for(int i=0;i<MAX_SIZE;i++) matches[i]=0;
|
||||||
@@ -51,7 +62,7 @@ int main(int argc,char **argv)
|
|||||||
}
|
}
|
||||||
stat(argv[1], &st);
|
stat(argv[1], &st);
|
||||||
s1=st.st_size;
|
s1=st.st_size;
|
||||||
f1 = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0);
|
f1 = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_POPULATE, fd, 0);
|
||||||
if (f1== MAP_FAILED) {
|
if (f1== MAP_FAILED) {
|
||||||
fprintf(stderr,"Could not mmap '%s'\n",argv[1]);
|
fprintf(stderr,"Could not mmap '%s'\n",argv[1]);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
@@ -69,6 +80,14 @@ int main(int argc,char **argv)
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (basic) {
|
||||||
|
for (int i = 0; i < NUM_CHUNKS; i++) {
|
||||||
|
for (int addr = microsoft_basic_chunks[i * 2]; addr <= microsoft_basic_chunks[i * 2 + 1]; addr++) {
|
||||||
|
f1[addr - 0xA000] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stderr,"Searching files for similarities...\n");
|
fprintf(stderr,"Searching files for similarities...\n");
|
||||||
|
|
||||||
for(int i=0;i<s1;i++) {
|
for(int i=0;i<s1;i++) {
|
||||||
|
|||||||
Reference in new issue
Block a user