1 /* variable.c - Variable and stack related 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 * z_dec, decrement a variable.
26 * zargs[0] = variable to decrement
36 else if (zargs[0] < 16)
39 zword addr = h_globals + 2 * (zargs[0] - 16);
40 LOW_WORD (addr, value)
42 SET_WORD (addr, value)
48 * z_dec_chk, decrement a variable and branch if now less than value.
50 * zargs[0] = variable to decrement
51 * zargs[1] = value to check variable against
61 else if (zargs[0] < 16)
62 value = --(*(fp - zargs[0]));
64 zword addr = h_globals + 2 * (zargs[0] - 16);
65 LOW_WORD (addr, value)
67 SET_WORD (addr, value)
70 branch ((short) value < (short) zargs[1]);
75 * z_inc, increment a variable.
77 * zargs[0] = variable to increment
87 else if (zargs[0] < 16)
90 zword addr = h_globals + 2 * (zargs[0] - 16);
91 LOW_WORD (addr, value)
93 SET_WORD (addr, value)
99 * z_inc_chk, increment a variable and branch if now greater than value.
101 * zargs[0] = variable to increment
102 * zargs[1] = value to check variable against
106 void z_inc_chk (void)
112 else if (zargs[0] < 16)
113 value = ++(*(fp - zargs[0]));
115 zword addr = h_globals + 2 * (zargs[0] - 16);
116 LOW_WORD (addr, value)
118 SET_WORD (addr, value)
121 branch ((short) value > (short) zargs[1]);
126 * z_load, store the value of a variable.
128 * zargs[0] = variable to store
138 else if (zargs[0] < 16)
139 value = *(fp - zargs[0]);
141 zword addr = h_globals + 2 * (zargs[0] - 16);
142 LOW_WORD (addr, value)
150 * z_pop, pop a value off the game stack and discard it.
164 * z_pop_stack, pop n values off the game or user stack and discard them.
166 * zargs[0] = number of values to discard
167 * zargs[1] = address of user stack (optional)
171 void z_pop_stack (void)
174 if (zargc == 2) { /* it's a user stack */
177 zword addr = zargs[1];
179 LOW_WORD (addr, size)
184 } else sp += zargs[0]; /* it's the game stack */
189 * z_pull, pop a value off...
191 * a) ...the game or a user stack and store it (V6)
193 * zargs[0] = address of user stack (optional)
195 * b) ...the game stack and write it to a variable (other than V6)
197 * zargs[0] = variable to write value to
205 if (h_version != V6) { /* not a V6 game, pop stack and write */
211 else if (zargs[0] < 16)
212 *(fp - zargs[0]) = value;
214 zword addr = h_globals + 2 * (zargs[0] - 16);
215 SET_WORD (addr, value)
218 } else { /* it's V6, but is there a user stack? */
220 if (zargc == 1) { /* it's a user stack */
223 zword addr = zargs[0];
225 LOW_WORD (addr, size)
231 LOW_WORD (addr, value)
233 } else value = *sp++; /* it's the game stack */
242 * z_push, push a value onto the game stack.
244 * zargs[0] = value to push onto the stack
256 * z_push_stack, push a value onto a user stack then branch if successful.
258 * zargs[0] = value to push onto the stack
259 * zargs[1] = address of user stack
263 void z_push_stack (void)
266 zword addr = zargs[1];
268 LOW_WORD (addr, size)
272 storew ((zword) (addr + 2 * size), zargs[0]);
284 * z_store, write a value to a variable.
286 * zargs[0] = variable to be written to
287 * zargs[1] = value to write
293 zword value = zargs[1];
297 else if (zargs[0] < 16)
298 *(fp - zargs[0]) = value;
300 zword addr = h_globals + 2 * (zargs[0] - 16);
301 SET_WORD (addr, value)