Update inv_FAC1

This commit is contained in:
Rikard Nordgren authored and FeralChild64 committed 2026-02-01 18:35:00 +01:00
1 parent 03db0610a8
commit dbc603322e
4 files changed
+46 -38

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
;; #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 - neg (2s complement) FAC1
;
; This is verified to be identical to the original Microsoft implementation where it was named NEGFAC.
;
; The alternative entry point neg_FAC1_mantissa (NEGFCH) will negate only the mantissa
;
; See also:
; - https://www.c64-wiki.com/wiki/BASIC-ROM
; - https://sta.c64.org/cbm64basconv.html
;
neg_FAC1:
lda FAC1_sign
eor #$FF
sta FAC1_sign
neg_FAC1_mantissa:
lda FAC1_mantissa+0
eor #$FF
sta FAC1_mantissa+0
lda FAC1_mantissa+1
eor #$FF
sta FAC1_mantissa+1
lda FAC1_mantissa+2
eor #$FF
sta FAC1_mantissa+2
lda FAC1_mantissa+3
eor #$FF
sta FAC1_mantissa+3
lda FACOV
eor #$FF
sta FACOV
bne inc_FAC1_ret
; Fallthrough to inc_FAC1
-36
View File
@@ -1,36 +0,0 @@
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
;
; Math package - invert FAC1 mantissa
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 113
; - https://www.c64-wiki.com/wiki/BASIC-ROM
; - https://sta.c64.org/cbm64basconv.html
;
; 2-complement the FAC1 mantissa
; The 4 byte mantissa is treated as an integer in big endian form
inv_FAC1_mantissa:
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