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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/*
** Gobliiins 1
** Original game by CoktelVision
**
** Reverse engineered by Ivan Dubrov <WFrag@yandex.ru>
**
*/
#include "gob/gob.h"
#include "gob/debug.h"
#include "gob/scenery.h"
namespace Gob {
static int16 logFile = -2;
static char buf[256];
extern uint32 always0_dword_23EC_560;
static void log_close(void) {
if (logFile != -2)
close(logFile);
logFile = -2;
}
static void log_init(void) {
if (logFile == -2) {
logFile = open(LOG_NAME, O_WRONLY | O_CREAT);
if (logFile != -1)
atexit(&log_close);
}
}
void log_write(const char *format, ...) {
va_list lst;
va_start(lst, format);
log_init();
if (logFile >= 0) {
vsprintf(buf, format, lst);
write(logFile, buf, strlen(buf));
}
va_end(lst);
}
void dbg_printInt(int16 val) {
log_write("dbg_printInt: %d\n", val);
}
void dbg_printPtr(void *ptr) {
log_write("dbg_printPtr: %p\n", ptr);
}
void dbg_printStr(char *str) {
log_write("dbg_printStr: ");
log_write(str);
log_write("\n");
}
void dbg_dumpMem(char *ptr, int16 size) {
int16 i;
log_write("dbg_dumpMem %p %d:", ptr, size);
for (i = 0; i < size; i++)
log_write("%02x ", (uint16)(byte)ptr[i]);
log_write("\n");
}
void dbg_dumpMemChars(char *ptr, int16 size) {
int16 i;
log_write("dbg_dumpMem %p %ld:", ptr, size);
for (i = 0; i < size; i++)
log_write("%c ", ptr[i]);
log_write("\n");
}
void dbg_printDelim() {
log_write("-------------------\n");
}
void dbg_printHexInt(int16 val) {
log_write("%02x\n", val);
}
void dbg_dumpStaticScenery(Scen_Static * st) {
int16 i, j;
Scen_StaticPlane *ptr;
log_write("dbg_dumpStaticScenery\n");
log_write("----------\n");
log_write("Layers count = %d\n", st->layersCount);
for (i = 0; i < st->layersCount; i++) {
log_write("Layer %d:\n", i);
log_write("Back sprite resource id = %d\n",
st->layers[i]->backResId);
log_write("Plane count = %d\n", st->layers[i]->planeCount);
for (j = 0; j < st->layers[i]->planeCount; j++) {
ptr = &st->layers[i]->planes[j];
log_write
("Plane %d: pictIndex = %d, pieceIndex = %d, drawOrder = %d\n",
j, (int16)ptr->pictIndex, (int16)ptr->pieceIndex,
(int16)ptr->drawOrder);
log_write
("destX = %d, destY = %d, transparency = %d\n",
ptr->destX, ptr->destY, (char *)ptr->transp);
}
}
log_write("----------\n\n");
}
int16 calcDest(char dest, byte add) {
if (dest >= 0)
return dest + ((uint16)add << 7);
else
return dest - ((uint16)add << 7);
}
/*
void dbg_dumpFramePiece(Scen_AnimFramePiece* piece, int16 j, Scen_AnimLayer* layer) {
log_write("Piece for %d anim, %p: ", j, piece);
log_write("pictIndex = %x, pieceIndex = %d, destX = %d, destY = %d, not final = %d\n",
(uint16)piece->pictIndex,
(uint16)piece->pieceIndex,
layer->deltaX+calcDest(piece->destX, (char)((piece->pictIndex & 0xc0)>>6)),
layer->deltaY+calcDest(piece->destY, (char)((piece->pictIndex & 0x30)>>4)),
(int16)piece->notFinal);
}
void dbg_dumpAnimation(Scen_Animation* anim) {
int16 i, j;
Scen_AnimLayer* layer;
Scen_AnimFramePiece* piece;
log_write("dbg_dumpAnimation\n");
log_write("----------\n");
log_write("Layers count = %d\n", anim->layersCount);
for(i = 0; i < anim->layersCount; i++)
{
layer = anim->layers[i];
log_write("Layer %d:\n", i);
log_write("unknown0 = %d\n", layer->unknown0);
log_write("deltaX = %d\n", layer->deltaX);
log_write("deltaY = %d\n", layer->deltaY);
log_write("unknown1 = %d\n", layer->unknown1);
log_write("unknown2 = %d\n", layer->unknown2);
log_write("transparency = %d\n", (int16)layer->transp);
log_write("animsCount %d\n", layer->framesCount);
piece = layer->frames;
j = 0;
while(j < layer->framesCount)
{
dbg_dumpFramePiece(piece, j, layer);
if(piece->notFinal != 1)
j++;
piece++;
}
}
log_write("----------\n\n");
}
*/
} // End of namespace Gob
|