1 /* table.c - Table handling 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_copy_table, copy a table or fill it with zeroes.
26 * zargs[0] = address of table
27 * zargs[1] = destination address or 0 for fill
28 * zargs[2] = size of table
30 * Note: Copying is safe even when source and destination overlap; but
31 * if zargs[1] is negative the table _must_ be copied forwards.
35 void z_copy_table (void)
38 zword size = zargs[2];
42 if (zargs[1] == 0) /* zero table */
44 for (i = 0; i < size; i++)
45 storeb ((zword) (zargs[0] + i), 0);
47 else if ((short) size < 0 || zargs[0] > zargs[1]) /* copy forwards */
49 for (i = 0; i < (((short) size < 0) ? - (short) size : size); i++) {
51 LOW_BYTE (addr, value)
52 storeb ((zword) (zargs[1] + i), value);
55 else /* copy backwards */
57 for (i = size - 1; i >= 0; i--) {
59 LOW_BYTE (addr, value)
60 storeb ((zword) (zargs[1] + i), value);
66 * z_loadb, store a value from a table of bytes.
68 * zargs[0] = address of table
69 * zargs[1] = index of table entry to store
75 zword addr = zargs[0] + zargs[1];
78 LOW_BYTE (addr, value)
85 * z_loadw, store a value from a table of words.
87 * zargs[0] = address of table
88 * zargs[1] = index of table entry to store
94 zword addr = zargs[0] + 2 * zargs[1];
97 LOW_WORD (addr, value)
104 * z_scan_table, find and store the address of a target within a table.
106 * zargs[0] = target value to be searched for
107 * zargs[1] = address of table
108 * zargs[2] = number of table entries to check value against
109 * zargs[3] = type of table (optional, defaults to 0x82)
111 * Note: The table is a word array if bit 7 of zargs[3] is set; otherwise
112 * it's a byte array. The lower bits hold the address step.
116 void z_scan_table (void)
118 zword addr = zargs[1];
121 /* Supply default arguments */
126 /* Scan byte or word array */
128 for (i = 0; i < zargs[2]; i++) {
130 if (zargs[3] & 0x80) { /* scan word array */
134 LOW_WORD (addr, wvalue)
136 if (wvalue == zargs[0])
139 } else { /* scan byte array */
143 LOW_BYTE (addr, bvalue)
145 if (bvalue == zargs[0])
150 addr += zargs[3] & 0x7f;
164 * z_storeb, write a byte into a table of bytes.
166 * zargs[0] = address of table
167 * zargs[1] = index of table entry
168 * zargs[2] = value to be written
175 storeb ((zword) (zargs[0] + zargs[1]), zargs[2]);
180 * z_storew, write a word into a table of words.
182 * zargs[0] = address of table
183 * zargs[1] = index of table entry
184 * zargs[2] = value to be written
191 storew ((zword) (zargs[0] + 2 * zargs[1]), zargs[2]);