1 /* math.c - Arithmetic, compare and logical opcodes
2 * Copyright (c) 1995-1997 Stefan Jokisch
4 * This file is part of Frotz.
6 * Frotz is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Frotz is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 * z_add, 16bit addition.
26 * zargs[0] = first value
27 * zargs[1] = second value
34 store ((zword
) ((short) zargs
[0] + (short) zargs
[1]));
39 * z_and, bitwise AND operation.
41 * zargs[0] = first value
42 * zargs[1] = second value
49 store ((zword
) (zargs
[0] & zargs
[1]));
54 * z_art_shift, arithmetic SHIFT operation.
57 * zargs[1] = #positions to shift left (positive) or right
61 void z_art_shift (void)
64 if ((short) zargs
[1] > 0)
65 store ((zword
) ((short) zargs
[0] << (short) zargs
[1]));
67 store ((zword
) ((short) zargs
[0] >> - (short) zargs
[1]));
72 * z_div, signed 16bit division.
74 * zargs[0] = first value
75 * zargs[1] = second value
83 runtime_error (ERR_DIV_ZERO
);
85 store ((zword
) ((short) zargs
[0] / (short) zargs
[1]));
90 * z_je, branch if the first value equals any of the following.
92 * zargs[0] = first value
93 * zargs[1] = second value (optional)
95 * zargs[3] = fourth value (optional)
103 zargc
> 1 && (zargs
[0] == zargs
[1] || (
104 zargc
> 2 && (zargs
[0] == zargs
[2] || (
105 zargc
> 3 && (zargs
[0] == zargs
[3]))))));
110 * z_jg, branch if the first value is greater than the second.
112 * zargs[0] = first value
113 * zargs[1] = second value
120 branch ((short) zargs
[0] > (short) zargs
[1]);
125 * z_jl, branch if the first value is less than the second.
127 * zargs[0] = first value
128 * zargs[1] = second value
135 branch ((short) zargs
[0] < (short) zargs
[1]);
140 * z_jz, branch if value is zero.
149 branch ((short) zargs
[0] == 0);
154 * z_log_shift, logical SHIFT operation.
157 * zargs[1] = #positions to shift left (positive) or right (negative)
161 void z_log_shift (void)
164 if ((short) zargs
[1] > 0)
165 store ((zword
) (zargs
[0] << (short) zargs
[1]));
167 store ((zword
) (zargs
[0] >> - (short) zargs
[1]));
172 * z_mod, remainder after signed 16bit division.
174 * zargs[0] = first value
175 * zargs[1] = second value
183 runtime_error (ERR_DIV_ZERO
);
185 store ((zword
) ((short) zargs
[0] % (short) zargs
[1]));
190 * z_mul, 16bit multiplication.
192 * zargs[0] = first value
193 * zargs[1] = second value
200 store ((zword
) ((short) zargs
[0] * (short) zargs
[1]));
205 * z_not, bitwise NOT operation.
214 store ((zword
) ~zargs
[0]);
219 * z_or, bitwise OR operation.
221 * zargs[0] = first value
222 * zargs[1] = second value
229 store ((zword
) (zargs
[0] | zargs
[1]));
234 * z_sub, 16bit substraction.
236 * zargs[0] = first value
237 * zargs[1] = second value
244 store ((zword
) ((short) zargs
[0] - (short) zargs
[1]));
249 * z_test, branch if all the flags of a bit mask are set in a value.
251 * zargs[0] = value to be examined
252 * zargs[1] = bit mask
259 branch ((zargs
[0] & zargs
[1]) == zargs
[1]);