2 * Copyright 2010-2012 Chris Spiegel.
4 * This file is part of Bocfel.
6 * Bocfel is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version
8 * 2 or 3, as published by the Free Software Foundation.
10 * Bocfel is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Bocfel. If not, see <http://www.gnu.org/licenses/>.
28 void branch_if(int do_branch)
35 if(!do_branch) branch ^= 0x80;
37 offset = branch & 0x3f;
39 if((branch & 0x40) == 0)
41 offset = (offset << 8) | BYTE(pc++);
43 /* Get the sign right. */
44 if(offset & 0x2000) offset |= 0xc000;
51 pc += (int16_t)offset - 2;
52 ZASSERT(pc < memory_size, "branch to invalid address 0x%lx", (unsigned long)pc);
63 /* -= 2 because pc has been advanced past the jump instruction. */
64 pc += (int16_t)zargs[0];
67 ZASSERT(pc < memory_size, "@jump to invalid address 0x%lx", (unsigned long)pc);
72 branch_if(zargs[0] == 0);
77 if (znargs == 1) branch_if(0);
78 else if(znargs == 2) branch_if(zargs[0] == zargs[1]);
79 else if(znargs == 3) branch_if(zargs[0] == zargs[1] || zargs[0] == zargs[2]);
80 else branch_if(zargs[0] == zargs[1] || zargs[0] == zargs[2] || zargs[0] == zargs[3]);
85 branch_if((int16_t)zargs[0] < (int16_t)zargs[1]);
90 branch_if((int16_t)zargs[0] > (int16_t)zargs[1]);