aboutsummaryrefslogtreecommitdiff
path: root/engines/gargoyle/frotz/err.cpp
blob: f75b764ad0ff7216b0a179217f881934f28c4da0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "gargoyle/frotz/err.h"
#include "gargoyle/frotz/frotz.h"
#include "common/textconsole.h"

namespace Gargoyle {
namespace Frotz {

const char *const Errors::ERR_MESSAGES[ERR_NUM_ERRORS] = {
    "Text buffer overflow",
    "Store out of dynamic memory",
    "Division by zero",
    "Illegal object",
    "Illegal attribute",
    "No such property",
    "Stack overflow",
    "Call to illegal address",
    "Call to non-routine",
    "Stack underflow",
    "Illegal opcode",
    "Bad stack frame",
    "Jump to illegal address",
    "Can't save while in interrupt",
    "Nesting stream #3 too deep",
    "Illegal window",
    "Illegal window property",
    "Print at illegal address",
    "Illegal dictionary word length",
    "@jin called with object 0",
    "@get_child called with object 0",
    "@get_parent called with object 0",
    "@get_sibling called with object 0",
    "@get_prop_addr called with object 0",
    "@get_prop called with object 0",
    "@put_prop called with object 0",
    "@clear_attr called with object 0",
    "@set_attr called with object 0",
    "@test_attr called with object 0",
    "@move_object called moving object 0",
    "@move_object called moving into object 0",
    "@remove_object called with object 0",
    "@get_next_prop called with object 0"
};

Errors::Errors() {
	Common::fill(&_count[0], &_count[ERR_NUM_ERRORS], 0);
}

void Errors::runtimeError(ErrorCode errNum) {
#ifdef TODO
	int wasfirst;
    
    if (errNum <= 0 || errNum > ERR_NUM_ERRORS)
	return;

    if (g_vm->_err_report_mode == ERR_REPORT_FATAL
		|| (!g_vm->_ignore_errors && errNum <= ERR_MAX_FATAL)) {
		g_vm->_buffer.flush();
		error(ERR_MESSAGES[errNum - 1]);
		return;
    }

    wasfirst = (_count[errNum - 1] == 0);
    _count[errNum - 1]++;
    
    if ((g_vm->_err_report_mode == ERR_REPORT_ALWAYS)
			|| (_err_report_mode == ERR_REPORT_ONCE && wasfirst)) {
		long pc = g_vm->_processor
		GET_PC(pc);
		printString("Warning: ");
		printString(ERR_MESSAGES[errNum - 1]);
		printString(" (PC = ");
		printLong(pc, 16);
		printChar(')');
        
		if (_err_report_mode == ERR_REPORT_ONCE) {
			printString(" (will ignore further occurrences)");
		} else {
			printString(" (occurence ");
			printLong(_count[errNum - 1], 10);
			printChar(')');
		}

		newLine();
    }
#endif
}

void Errors::printLong(uint value, int base) {
    unsigned long i;
    char c;

    for (i = (base == 10 ? 1000000000 : 0x10000000); i != 0; i /= base)
	if (value >= i || i == 1) {
	    c = (value / i) % base;
	    printChar(c + (c <= 9 ? '0' : 'a' - 10));
	}
}

void Errors::printChar(const char c) {
	// TODO
}

void Errors::printString(const char *str) {
	// TODO
}

void Errors::newLine() {
	// TODO
}

} // End of namespace Scott
} // End of namespace Gargoyle