-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathusrmod.asm
executable file
·60 lines (51 loc) · 1.22 KB
/
usrmod.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
;xa -O PETSCII -o usrmod.prg usrmod.asm
; Modulo function using USR()
; Copyright 1992,1999 Peter Karlsson
; For Go64!/Commodore World magazine
*= 49152
.text
.word *
*= *-2
; BASIC ROM entry points used
usrvec = $0311
mov2f57 = $bbca
mov2f5c = $bbc7
frmnum = $ad8a
fdivmem = $bb0f
int = $bccc
fmultmem = $ba28
fsubmem = $b850
tmp1 = $57
tmp2 = $5c
; Setup the USR vector
lda #<modulo
ldx #>modulo
sta usrvec
stx usrvec+1
rts
; Entry point for the USR function
modulo ; Move numerator (FAC1) to TMP1
jsr mov2f57
; Retrieve denominator and
; move from FAC1 to TMP2
jsr frmnum
jsr mov2f5c
; Calculate FAC1=FAC1/TMP1
; retval=x/y
lda #<tmp1
ldy #>tmp1
jsr fdivmem
; Calculate FAC1=INT(FAC1)
; retval=int(x/y)
jsr int
; Calculate FAC1=FAC1*TMP2
; retval=int(x/y)*y
lda #<tmp2
ldy #>tmp2
jsr fmultmem
; Calculate FAC1=TMP1-FAC1
; retval=x-int(x/y)*y
; =mod(x,y)
lda #<tmp1
ldy #>tmp1
jmp fsubmem