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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
#include "rsp.h"
#include "rsp_lemm.h"
#include "utils.h"
#include "dos_lemm.h"
#include <stdint.h> /* uint16_t... */
#include <string.h> /* strcpy() */
#include <stdio.h> /* printf() */
int main(int argc, char *argv[]) {
int i, rv, similar_frames, end;
struct rsp_state rsp;
char ds_si[10], command[16];
union lemm_data lemm, prevlemm;
char draw_hint_str[256][16];
char state_str[16][16];
memset(lemm.raw, 0, sizeof(lemm.raw));
for (i=0;i<256;i++) strcpy(draw_hint_str[i], "hint_unknown");
strcpy(draw_hint_str[hint_nothing], "hint_nothing");
strcpy(draw_hint_str[hint_falling], "hint_falling");
strcpy(draw_hint_str[hint_special1],"hint_special1");
strcpy(draw_hint_str[hint_walking], "hint_walking");
strcpy(draw_hint_str[hint_building],"hint_building");
strcpy(draw_hint_str[hint_mining], "hint_mining");
strcpy(draw_hint_str[hint_bashing], "hint_bashing");
strcpy(state_str[0],"s_splatting");
strcpy(state_str[1],"s_exploding");
strcpy(state_str[2],"s_falling");
strcpy(state_str[3],"s_ascending");
strcpy(state_str[4],"s_digging");
strcpy(state_str[5],"s_climbing");
strcpy(state_str[6],"s_climb_ending");
strcpy(state_str[7],"s_building");
strcpy(state_str[8],"s_blocking");
strcpy(state_str[9],"s_bashing");
strcpy(state_str[10],"s_floating");
strcpy(state_str[11],"s_mining");
strcpy(state_str[12],"s_drawning");
strcpy(state_str[13],"s_ending");
strcpy(state_str[14],"s_dying");
strcpy(state_str[15],"s_exploding2");
rv=rsp_lemm_init(&rsp, ds_si);
if ( rv != 0 ) {
printf("Error rsp_lemm_init() returns %i\n", rv);
return 1;
}
end=0;
similar_frames=0;
while (!end) {
rsp_query(&rsp, "c"); // Continue
if ( rsp.replied != 1 ) printf("Bug 03\n");
rsp_recv_full(&rsp);
if ( rsp_check_and_clear(&rsp, "S05") != 0 ) printf("Bug 04\n");
snprintf(command, 15, "m%s,0x2d", ds_si);
rsp_query(&rsp, command); // Read a lemming record
if ( rsp_decode(&rsp) != 2*sizeof(lemm.raw) ) {
printf("Bug 07\n");
continue;
}
memcpy(prevlemm.raw, lemm.raw, sizeof(lemm.raw));
//printf("%s\n", rsp.decoded);
rv = hexascii2bin(rsp.decoded, lemm.raw, sizeof(lemm.raw));
if ( rv != sizeof(lemm.raw) ) {
printf("Bug 08\n");
continue;
}
for (i=0; i<sizeof(lemm.raw); i++) {
// Search the differences between previous frame and now
if ( prevlemm.raw[i] == lemm.raw[i] ) continue;
switch(i) {
case 0x0: // x
case 0x1: // x
case 0x2: // y
case 0x3: // y
case 0x28: //spr_frame
continue; // Don't want to see those state changes because is well-known and frequent
case 0x20: //expl_countdown
if ( lemm.s.expl_countdown < 0x4e && lemm.s.expl_countdown > 0x02) {
// Skip detailing all 80 changes... Just beginning and ending
continue;
}
}
// If here, an interessting change has been detected
if ( similar_frames > 0) {
printf("(%i similar frames)\n", similar_frames);
}
similar_frames=-1;
switch(i) {
case 0x4: // x_spr_offset
i=0x5; // go to the next case (prevents double printing)
case 0x5: // x_spr_offset
printf("x_spr_offset\t%i -> %i\n",prevlemm.s.x_spr_offset, lemm.s.x_spr_offset);
break;
case 0x6: // y_spr_offset
i=0x7;
case 0x7: // y_spr_offset
printf("y_spr_offset\t%i -> %i\n",prevlemm.s.y_spr_offset, lemm.s.y_spr_offset);
break;
case 0x8: // state
i=0x9;
case 0x9: // state
rv=bit_position(lemm.s.state.raw);
switch (rv) {
case -2:
//FIXME : boucle bit par bit car ya parfois de multiple bits...
printf("state\t\t%04x -> %04x (multiple)\n",prevlemm.s.state.raw, lemm.s.state.raw);
break;
case -1:
printf("state\t\t%04x -> %04x (walking...)\n",prevlemm.s.state.raw, lemm.s.state.raw);
break;
default:
printf("state\t\t%04x -> %04x (%s)\n",prevlemm.s.state.raw, lemm.s.state.raw, state_str[rv]);
break;
}
break;
case 0xc: // spr_data_ptr
i=0xd;
case 0xd: // spr_data_ptr
printf("spr_data_ptr\t%04x -> %04x\n",prevlemm.s.spr_data_ptr, lemm.s.spr_data_ptr);
break;
case 0xe: // floattime_dble ?
printf("floattime_dble\t%02x -> %02x\n",prevlemm.s.floattime_dble, lemm.s.floattime_dble);
break;
case 0x14: // ptr2 ?
i=0x15;
case 0x15: // ptr2 ?
printf("ptr2\t\t%04x -> %04x\n",prevlemm.s.ptr2, lemm.s.ptr2);
break;
case 0x20: //expl_countdown
printf("expl_countdown\t%02x -> %02x\n",prevlemm.s.expl_countdown, lemm.s.expl_countdown);
break;
case 0x21: //steps_remain
printf("steps_remain\t%02x -> %02x\n",prevlemm.s.steps_remain, lemm.s.steps_remain);
break;
case 0x23: //falldist
printf("falldist\t%02x -> %02x\n",prevlemm.s.falldist, lemm.s.falldist);
break;
case 0x24: //flags1
if ( prevlemm.s.flags1.bits.fl1_cap_climber != lemm.s.flags1.bits.fl1_cap_climber ) {
printf("cap_climber\t%2i -> %2i\n",
prevlemm.s.flags1.bits.fl1_cap_climber,
lemm.s.flags1.bits.fl1_cap_climber
);
} else if ( prevlemm.s.flags1.bits.fl1_walk_pause_for_shruggling != lemm.s.flags1.bits.fl1_walk_pause_for_shruggling ) {
printf("walk_pause_for_shruggling\t%2i -> %2i\n",
prevlemm.s.flags1.bits.fl1_walk_pause_for_shruggling,
lemm.s.flags1.bits.fl1_walk_pause_for_shruggling
);
} else {
printf("flags1.unknown\t%02x -> %02x\n",prevlemm.s.flags1.raw, lemm.s.flags1.raw);
}
break;
case 0x25: //cap_floater
printf("cap_floater\t%02x -> %02x\n",prevlemm.s.cap_floater, lemm.s.cap_floater);
break;
case 0x26: //is_gone
printf("is_gone\t%02x -> %02x\n",prevlemm.s.is_gone, lemm.s.is_gone);
break;
case 0x27: //direction
printf("direction\t%i -> %i\n",prevlemm.s.direction, lemm.s.direction);
break;
case 0x29: //draw_hint ?
printf("draw_hint\t\t%02x -> %02x (%s)\n",prevlemm.s.draw_hint, lemm.s.draw_hint, draw_hint_str[lemm.s.draw_hint]);
break;
default:
printf("(0x%02x)\t\t%02x -> %02x\n", i, prevlemm.raw[i], lemm.raw[i]);
}
}
similar_frames++;
}
rsp_quit(&rsp);
return 0;
}
|