1
/* Nitfol - z-machine interpreter using Glk for output.
2
Copyright (C) 1999 Evin Robertson
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
18
The author can be reached at nitfol@deja.com
23
N_INLINE static void skip_branch(zbyte branch)
25
if(!(branch & b01000000)) /* Bit 6 clear means 'branch occupies two bytes' */
29
N_INLINE static void take_branch(zbyte branch)
31
int o = branch & b00111111;
33
if(!(branch & b01000000)) {/* Bit 6 clear means 'branch occupies two bytes'*/
34
o = (o << 8) + HIBYTE(PC);
36
if(branch & b00100000)
49
n_show_error(E_INSTR, "attempt to conditionally jump outside of story", o - 2);
55
/* printf("cjmp %x -> %x\n", oldPC, PC); */
59
void mop_skip_branch(void)
61
zbyte branch = HIBYTE(PC);
64
if(branch & b10000000) /* Bit 7 set means 'branch when true' */
71
void mop_take_branch(void)
73
zbyte branch = HIBYTE(PC);
76
if(branch & b10000000) /* Bit 7 set means 'branch when true' */
82
void mop_cond_branch(BOOL cond)
84
zbyte branch = HIBYTE(PC);
86
if((branch >> 7) ^ cond)
96
for(i = 1; i < numoperands; i++)
97
if(operand[0] == operand[i]) {
107
if(is_greaterthan(operand[0], operand[1]))
115
if(is_lessthan(operand[0], operand[1]))
123
operand[0] -= 2; /* not documented in zspec */
124
if(is_neg(operand[0])) {
126
if(neg(operand[0]) > PC) {
127
n_show_error(E_INSTR, "attempt to jump before beginning of story", -neg(operand[0]));
131
PC -= neg(operand[0]);
136
n_show_error(E_INSTR, "attempt to jump past end of story", operand[0]);
141
/* printf("jump %x -> %x\n", oldPC, PC); */
146
mop_cond_branch(operand[0] == 0);
151
mop_cond_branch((operand[0] & operand[1]) == operand[1]);
156
mop_cond_branch(LOWORD(HD_CHECKSUM) == z_checksum);
161
mop_cond_branch(aye_matey);