forked from spitbol/x64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharith.c
162 lines (130 loc) · 2.58 KB
/
arith.c
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
Copyright 1987-2012 Robert B. K. Dewar and Mark Emmer.
Copyright 2012-2015 David Shields
This file is part of Macro SPITBOL.
Macro SPITBOL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Macro SPITBOL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Macro SPITBOL. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* arith.c - floating point support for spitbol
*
* These routines are not called from other C routines. Rather they
* are called by inter.*, and by external functions, to perform basic
* arithmetic operatios.
*/
#include "port.h"
// reg_rb is used to pass arguments to read operations
extern double reg_rb;
// overflow codes
// OF = 0x80
// cf = 0x01
// zr = 0x40
void f_ldr() { // load real
reg_ra = reg_rb;
return;
}
void f_adr() { // add real
reg_ra += reg_rb;
return;
}
void f_sbr() { // subtract real
reg_fl = 0;
reg_ra -= reg_rb;
return;
}
void f_mlr() { // multiply real
reg_ra *= reg_rb;
reg_fl = 0;
return;
}
void f_dvr() { // divide real
if (reg_rb != 0.0) {
reg_ra /= reg_rb;
reg_fl = 0;
}
else
reg_fl = 1;
return;
}
void f_ngr() { // negate real
reg_ra = -reg_ra;
return;
}
void f_itr() { // integer to real
reg_ra = (double) reg_ia;
return;
}
void f_rti() { // real to integer
reg_ia = reg_ra;
}
void f_cpr() {
if ( reg_ra == 0.0)
reg_fl = 0;
else if ( reg_ra < 0.0)
reg_fl = -1;
else
reg_fl = 1;
}
void f_pra () {
}
void i_ldi() {
reg_ia = reg_w0;
}
void i_adi() {
reg_fl = 0;
reg_ia += reg_w0;
}
void i_dvi() {
if (reg_w0 == 0) {
reg_fl = 1;
}
else {
reg_fl = 0;
reg_ia /= reg_w0;
}
}
void i_mli() {
reg_fl = 0;
reg_ia *= reg_w0;
}
void i_ngi() {
reg_fl = 0;
reg_ia = -reg_ia;
}
void i_rmi() {
if (reg_w0 == 0) {
reg_fl = 1;
}
else {
reg_ia = reg_ia % reg_w0;
reg_fl = 0;
}
}
void i_sbi() {
reg_ia -= reg_w0;
}
void i_cvd() {
reg_wa = reg_ia % 10;
reg_ia /= 10;
reg_wa = -reg_wa + 48; // convert remainder to character code for digit
}
long ctbw_r;
long ctbw_v;
void ctw_() {
long reg;
reg = (ctbw_r + CPW - 1) >> LOG_CPW;
reg += ctbw_v;
ctbw_r = reg;
}
void ctb_() {
ctw_();
ctbw_r = ctbw_r * CPW;
}