1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "glk/zcode/processor.h"
24 
25 namespace Glk {
26 namespace ZCode {
27 
z_add()28 void Processor::z_add() {
29 	store((zword)((short)zargs[0] + (short)zargs[1]));
30 }
31 
z_and()32 void Processor::z_and() {
33 	store((zword)(zargs[0] & zargs[1]));
34 }
35 
z_art_shift()36 void Processor::z_art_shift() {
37 	if ((short)zargs[1] > 0)
38 		store((zword)((short)zargs[0] << (short)zargs[1]));
39 	else
40 		store((zword)((short)zargs[0] >> - (short)zargs[1]));
41 }
42 
z_div()43 void Processor::z_div() {
44 	if (zargs[1] == 0)
45 		runtimeError(ERR_DIV_ZERO);
46 
47 	store((zword)((short)zargs[0] / (short)zargs[1]));
48 }
49 
z_je()50 void Processor::z_je() {
51 	branch(
52 		zargc > 1 && (zargs[0] == zargs[1] || (
53 		zargc > 2 && (zargs[0] == zargs[2] || (
54 		zargc > 3 && (zargs[0] == zargs[3])))))
55 	);
56 }
57 
z_jg()58 void Processor::z_jg() {
59 	branch((short)zargs[0] > (short)zargs[1]);
60 }
61 
z_jl()62 void Processor::z_jl() {
63 	branch((short)zargs[0] < (short)zargs[1]);
64 }
65 
z_jz()66 void Processor::z_jz() {
67 	branch((short)zargs[0] == 0);
68 }
69 
z_log_shift()70 void Processor::z_log_shift() {
71 	if ((short)zargs[1] > 0)
72 		store((zword)(zargs[0] << (short)zargs[1]));
73 	else
74 		store((zword)(zargs[0] >> - (short)zargs[1]));
75 }
76 
z_mod()77 void Processor::z_mod() {
78 	if (zargs[1] == 0)
79 		runtimeError(ERR_DIV_ZERO);
80 
81 	store((zword)((short)zargs[0] % (short)zargs[1]));
82 }
83 
z_mul()84 void Processor::z_mul() {
85 	store((zword)((short)zargs[0] * (short)zargs[1]));
86 }
87 
z_not()88 void Processor::z_not() {
89 	store((zword)~zargs[0]);
90 }
91 
z_or()92 void Processor::z_or() {
93 	store((zword)(zargs[0] | zargs[1]));
94 }
95 
z_sub()96 void Processor::z_sub() {
97 	store((zword)((short)zargs[0] - (short)zargs[1]));
98 }
99 
z_test()100 void Processor::z_test() {
101 	branch((zargs[0] & zargs[1]) == zargs[1]);
102 }
103 
104 } // End of namespace ZCode
105 } // End of namespace Glk
106