Add shiftr_FAC

This commit is contained in:
Rikard Nordgren authored and FeralChild64 committed 2026-02-01 18:35:00 +01:00
1 parent dbc603322e
commit 5b8dc457ab
3 files changed
+68 -1

No files matched your search

+1
View File
@@ -213,6 +213,7 @@ Floating point mathematical routines - not official, but well known and broadly
| `$B8FE` | `normal_FAC1` | DONE | |
| `$B947` | `inv_FAC1_mantissa` | DONE | From the Microsoft BASIC, original name: NEGFAC |
| `$B96F` | `inc_FAC1` | DONE | From the Microsoft BASIC, original name: INCFAC |
| `$B983` | `shiftr_FAC1` | DONE | From the Microsoft BASIC, original name: SHIFTR |
| `$B9EA` | `log_FAC1` | PARTIAL | not fully tested yet |
| `$BA28` | `mul_MEM_FAC1` | DONE | |
| `$BA2B` | `mul_FAC2_FAC1` | DONE | |
+65
View File
@@ -0,0 +1,65 @@
;; #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 - shift a floating point register right
;
; The main entry point is shiftr_FAC which shifts any FAC to the right with sign extension
; Inputs:
; - A is the negative of the number of bits to shift
; - X points to to the bytes to be shifted
; Returns:
; - Y = 0
; - CF = 0
; - A = overflowed bits
;
; Alternative entry point shift_for_mul_RES will shift the RES register for multiplication.
; Alternative entry point short_shift_FAC will makes a short shift without sign extension
;
; This is verified to be identical to the original Microsoft implementation where it was named SHIFTR.
;
shift_for_mul_RES:
ldx #RESHO-1
.bytes:
ldy 4,X ; Shift entire bytes
sty FACOV
ldy 3,X
sty 4,X
ldy 2,X
sty 3,X
ldy 1,X
sty 2,X
ldy BITS
sty 1,X
shiftr_FAC:
adc #8
bmi .bytes ; More than or equal to 8 bits remaining
beq .bytes
sbc #8 ; Go back to previous value
tay
lda FACOV
bcs shiftr_FAC
.sext:
asl 1,X
bcc @2
inc 1,X
@2:
ror 1,X ; Undo previous shift
ror 1,X
short_shift_FAC:
ror 2,X
ror 3,X
ror 4,X
ror
iny
bne .sext
shftrt:
clc
rts
+2 -1
View File
@@ -20,11 +20,12 @@ int matches[MAX_SIZE];
int phase_mask[MAX_SIZE+MAX_SIZE];
#define NUM_CHUNKS 4
#define NUM_CHUNKS 5
// Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC
unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {
0xB849, 0xB84F,
0xB947, 0xB97D,
0xB983, 0xB9BB,
0xBBA2, 0xBC1A,
0xBC58, 0xBC5A
};