Build doom on clipv2 and clip+
[kugel-rb.git] / apps / plugins / frotz / table.c
blobeb3a16366d2d75dca7e7c42c47a6f2f91d15023f
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #include "frotz.h"
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)
37 zword addr;
38 zword size = zargs[2];
39 zbyte value;
40 int i;
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++) {
50 addr = zargs[0] + 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--) {
58 addr = zargs[0] + i;
59 LOW_BYTE (addr, value)
60 storeb ((zword) (zargs[1] + i), value);
63 }/* z_copy_table */
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
73 void z_loadb (void)
75 zword addr = zargs[0] + zargs[1];
76 zbyte value;
78 LOW_BYTE (addr, value)
80 store (value);
82 }/* z_loadb */
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
92 void z_loadw (void)
94 zword addr = zargs[0] + 2 * zargs[1];
95 zword value;
97 LOW_WORD (addr, value)
99 store (value);
101 }/* z_loadw */
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];
119 int i;
121 /* Supply default arguments */
123 if (zargc < 4)
124 zargs[3] = 0x82;
126 /* Scan byte or word array */
128 for (i = 0; i < zargs[2]; i++) {
130 if (zargs[3] & 0x80) { /* scan word array */
132 zword wvalue;
134 LOW_WORD (addr, wvalue)
136 if (wvalue == zargs[0])
137 goto finished;
139 } else { /* scan byte array */
141 zbyte bvalue;
143 LOW_BYTE (addr, bvalue)
145 if (bvalue == zargs[0])
146 goto finished;
150 addr += zargs[3] & 0x7f;
154 addr = 0;
156 finished:
158 store (addr);
159 branch (addr);
161 }/* z_scan_table */
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
172 void z_storeb (void)
175 storeb ((zword) (zargs[0] + zargs[1]), zargs[2]);
177 }/* z_storeb */
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
188 void z_storew (void)
191 storew ((zword) (zargs[0] + 2 * zargs[1]), zargs[2]);
193 }/* z_storew */