From 0b90926c09560c181ca62408facfb61170276ee5 Mon Sep 17 00:00:00 2001 From: Rikard Nordgren Date: Mon, 3 Mar 2025 20:08:06 +0100 Subject: [PATCH] Add inv_FAC1_mantissa --- STATUS.md | 2 +- src/,,config_custom.s | 2 +- src/,,config_testing_60K.s | 2 +- src/basic/{,stubs_math => math}/b947.interop | 0 .../b947.inv_FAC1_mantissa.s | 20 +++++++++-- strings/65D00AE664D006E663D002E66260 | 3 ++ strings/BBA90085 | 3 ++ strings/D0034C09 | 3 ++ testsuite/unit/math.vs | 35 +++++++++++++++++++ 9 files changed, 65 insertions(+), 5 deletions(-) rename src/basic/{,stubs_math => math}/b947.interop (100%) rename src/basic/{,stubs_math => math}/b947.inv_FAC1_mantissa.s (51%) create mode 100644 strings/65D00AE664D006E663D002E66260 create mode 100644 strings/BBA90085 create mode 100644 strings/D0034C09 diff --git a/STATUS.md b/STATUS.md index 8e27f439..87ae4c88 100644 --- a/STATUS.md +++ b/STATUS.md @@ -211,7 +211,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$B867` | `add_MEM_FAC1` | DONE | | | `$B86A` | `add_FAC2_FAC1` | DONE | | | `$B8FE` | `normal_FAC1` | DONE | | -| `$B947` | `inv_FAC1_mantissa` | NOT DONE | | +| `$B947` | `inv_FAC1_mantissa` | DONE | | | `$B9EA` | `log_FAC1` | NOT DONE | | | `$BA28` | `mul_MEM_FAC1` | DONE | | | `$BA2B` | `mul_FAC2_FAC1` | DONE | | diff --git a/src/,,config_custom.s b/src/,,config_custom.s index b692a05f..6c33a923 100644 --- a/src/,,config_custom.s +++ b/src/,,config_custom.s @@ -108,7 +108,7 @@ ; --- Software features ;; #CONFIG# PANIC_SCREEN YES -;; #CONFIG# DOS_WEDGE YES +;; #CONFIG# DOS_WEDGE NO ;; #CONFIG# TAPE_WEDGE YES ;; #CONFIG# TAPE_HEAD_ALIGN NO ;; #CONFIG# BCD_SAFE_INTERRUPTS YES diff --git a/src/,,config_testing_60K.s b/src/,,config_testing_60K.s index 3f54b601..f2b60b78 100644 --- a/src/,,config_testing_60K.s +++ b/src/,,config_testing_60K.s @@ -97,7 +97,7 @@ ; --- Software features ;; #CONFIG# PANIC_SCREEN YES -;; #CONFIG# DOS_WEDGE YES +;; #CONFIG# DOS_WEDGE NO ;; #CONFIG# TAPE_WEDGE YES ;; #CONFIG# TAPE_HEAD_ALIGN NO ;; #CONFIG# BCD_SAFE_INTERRUPTS YES diff --git a/src/basic/,stubs_math/b947.interop b/src/basic/math/b947.interop similarity index 100% rename from src/basic/,stubs_math/b947.interop rename to src/basic/math/b947.interop diff --git a/src/basic/,stubs_math/b947.inv_FAC1_mantissa.s b/src/basic/math/b947.inv_FAC1_mantissa.s similarity index 51% rename from src/basic/,stubs_math/b947.inv_FAC1_mantissa.s rename to src/basic/math/b947.inv_FAC1_mantissa.s index c0b60e54..ce7429f5 100644 --- a/src/basic/,stubs_math/b947.inv_FAC1_mantissa.s +++ b/src/basic/math/b947.inv_FAC1_mantissa.s @@ -12,9 +12,25 @@ ; - https://sta.c64.org/cbm64basconv.html ; -; XXX implement, test +; 2-complement the FAC1 mantissa +; The 4 byte mantissa is treated as an integer in big endian form inv_FAC1_mantissa: - +STUB_IMPLEMENTATION + ldx #3 +@1: lda FAC1_mantissa,X + eor #$FF + sta FAC1_mantissa,X + dex + bpl @1 + + inc FAC1_mantissa+3 + bne @2 + inc FAC1_mantissa+2 + bne @2 + inc FAC1_mantissa+1 + bne @2 + inc FAC1_mantissa + +@2: rts diff --git a/strings/65D00AE664D006E663D002E66260 b/strings/65D00AE664D006E663D002E66260 new file mode 100644 index 00000000..839712f9 --- /dev/null +++ b/strings/65D00AE664D006E663D002E66260 @@ -0,0 +1,3 @@ +$65 + BNE $0A + INC $64 + BNE $06 + INC $63 + BNE $02 + INC $62 + RTS + +Incrementing a 32-bit integer at the well known position of the FAC1 mantissa in the zero page. diff --git a/strings/BBA90085 b/strings/BBA90085 new file mode 100644 index 00000000..00e17111 --- /dev/null +++ b/strings/BBA90085 @@ -0,0 +1,3 @@ +fragment + LDA #$00 + STA fragment + +Fragments of clearing byte in zero page. diff --git a/strings/D0034C09 b/strings/D0034C09 new file mode 100644 index 00000000..e0fa0aca --- /dev/null +++ b/strings/D0034C09 @@ -0,0 +1,3 @@ +BNE $03 + JMP fragment + +If zero do jump else not. Common long conditional branch idiom. diff --git a/testsuite/unit/math.vs b/testsuite/unit/math.vs index 6db037a0..7a4940c7 100644 --- a/testsuite/unit/math.vs +++ b/testsuite/unit/math.vs @@ -314,6 +314,41 @@ print "COMPARE" compare $61 $66 $1001 print "END" +print "TEST: inv_FAC1_mantissa 0" +fill $62 $65 00 00 00 00 +r PC=$B947 +ret +fill $1001 $1004 00 00 00 00 +print "COMPARE" +compare $62 $65 $1001 +print "END" + +print "TEST: inv_FAC1_mantissa 1" +fill $62 $65 00 00 00 01 +r PC=$B947 +ret +fill $1001 $1004 FF FF FF FF +print "COMPARE" +compare $62 $65 $1001 +print "END" + +print "TEST: inv_FAC1_mantissa 2130706432" +fill $62 $65 7F 00 00 00 +r PC=$B947 +ret +fill $1001 $1004 81 00 00 00 +print "COMPARE" +compare $62 $65 $1001 +print "END" + +print "TEST: inv_FAC1_mantissa -100" +fill $62 $65 FF FF FF 9C +r PC=$B947 +ret +fill $1001 $1004 00 00 00 64 +print "COMPARE" +compare $62 $65 $1001 +print "END" q