OpenCores
URL https://opencores.org/ocsvn/rtf65002/rtf65002/trunk

Subversion Repositories rtf65002

[/] [rtf65002/] [trunk/] [software/] [asm/] [pi_calc816.asm] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 40 robfinch
; ============================================================================
2
;        __
3
;   \\__/ o\    (C) 2014  Robert Finch, Stratford
4
;    \  __ /    All rights reserved.
5
;     \/_//     robfinch@finitron.ca
6
;       ||
7
;
8
;
9
; This source file is free software: you can redistribute it and/or modify
10
; it under the terms of the GNU Lesser General Public License as published
11
; by the Free Software Foundation, either version 3 of the License, or
12
; (at your option) any later version.
13
;
14
; This source file is distributed in the hope that it will be useful,
15
; but WITHOUT ANY WARRANTY; without even the implied warranty of
16
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
; GNU General Public License for more details.
18
;
19
; You should have received a copy of the GNU General Public License
20
; along with this program.  If not, see .
21
;
22
; This code calculates PI to 360 digits. It runs on a 65C816 processor.
23
; The code was found at www.6502.org
24
; ============================================================================
25
;
26
P       EQU             2
27
Q       EQU             1193*2 + 2
28
R       EQU             Q + 2
29
SSS     EQU             R + 2
30
 
31
                jsr             INITSUB
32
                ldx             #359
33
                ldy             #1193
34
L1S:
35
                phy
36
                pha
37
                phx
38
                stz             Q
39
;               txa
40
;               ldx             #5
41
;               wdm
42
;               xce
43
;               cpu             RTF65002
44
;               jsr             PRTNUM
45
;               clc
46
;               xce
47
;               cpu             W65C816S
48
;               rep             #$30
49
;               plx
50
;               phx
51
                tya
52
                tax
53
L2S:
54
                txa
55
 
56
;               phx
57
;               ldx             #5
58
;               wdm
59
;               xce
60
;               cpu             RTF65002
61
;               jsr             PRTNUM
62
;               clc
63
;               xce
64
;               cpu             W65C816S
65
;               rep             #$30
66
;               plx
67
;               txa
68
 
69
                jsr             MULSUB
70
                sta             SSS
71
                lda             #10
72
                sta             Q
73
                jsr             ADJ1SUB
74
                lda             P-1,x
75
                jsr             UNADJ1SUB
76
                jsr             MULSUB
77
                clc
78
                adc             SSS
79
                sta             Q
80
                txa
81
                asl
82
                dea
83
                jsr             DIVSUB
84
                jsr             ADJ1SUB
85
                sta             P-1,x
86
                jsr             UNADJ1SUB
87
                dex
88
                bne             L2S
89
                lda             #10
90
                jsr             DIVSUB
91
                sta             P
92
                plx
93
                pla
94
                ldy             Q
95
                cpy             #10
96
                bcc             L3S
97
                ldy             #0
98
                ina
99
L3S:
100
                cpx             #358
101
                bcc             L4S
102
                bne             L5S
103
                jsr             OUTPUTSUB
104
                lda             #46
105
L4S:
106
                jsr             OUTPUTSUB
107
L5S:
108
                tya
109
                eor             #48
110
                ply
111
                cpx             #358
112
                bcs             L6S
113
                dey
114
                dey
115
                dey
116
L6S:
117
                dex
118
                beq             L7S
119
                jmp             L1S
120
L7S:
121
                jsr             OUTPUTSUB
122
                wdm
123
                xce
124
                cpu             RTF65002
125
                rts
126
 
127
                cpu             W65C816S
128
INITSUB:
129
                lda             #2
130
                ldx             #1192
131
IS1:
132
                jsr             ADJSUB
133
                sta             P,x
134
                jsr             UNADJSUB
135
                dex
136
                bpl             IS1
137
                rts
138
 
139
MULSUB:
140
                sta             R
141
                ldy             #16
142
M1S:    asl
143
                asl             Q
144
                bcc             M2S
145
                clc
146
                adc             R
147
M2S:    dey
148
                bne             M1S
149
                rts
150
 
151
DIVSUB:
152
                sta             R
153
                ldy             #16
154
                lda             #0
155
                asl             Q
156
D1S:    rol
157
                cmp             R
158
                bcc             D2S
159
                sbc             R
160
D2S:    rol             Q
161
                dey
162
                bne             D1S
163
                rts
164
 
165
ADJSUB:
166
                pha
167
                txa
168
                asl
169
                tax
170
                pla
171
                rts
172
UNADJSUB:
173
                pha
174
                txa
175
                lsr
176
                tax
177
                pla
178
                rts
179
ADJ1SUB:
180
                pha
181
                txa
182
                asl
183
                tax
184
                pla
185
                dex
186
                rts
187
UNADJ1SUB:
188
                pha
189
                txa
190
                lsr
191
                tax
192
                pla
193
                inx
194
                rts
195
 
196
OUTPUTSUB:
197
        ; switching back to '816 mode will force the registers to 8 bit, so we
198
        ; have to save off their values, then restore them after the switch
199
                wdm             ; switch to 32 bit mode
200
                xce
201
                cpu             RTF65002
202
                jsr             DisplayChar
203
                clc             ; switch back to 816 mode
204
                xce
205
                cpu             W65C816S
206
                rts

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.