summaryrefslogtreecommitdiff
path: root/src/dosbox_snif/main_dump_delta.c
blob: 2e393c6b743fa3438ff7789842946aa287698cf5 (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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "rsp.h"
#include "rsp_lemm.h"
#include "utils.h"

#include <stdint.h> /* uint16_t... */
#include <string.h> /* strcpy() */
#include <stdio.h> /* printf() */


struct _state {
	uint8_t s_splatting:1;		//0X1
	uint8_t s_exploding:1;		//0X2 combinable 
	uint8_t s_falling:1;		//0X4
	uint8_t s_ascending:1;		//0X8
	uint8_t s_digging:1;		//0x10
	uint8_t s_climbing:1;		//0x20
	uint8_t s_climb_ending:1;	//0X40
	uint8_t s_building:1;		//0X80

	uint8_t s_blocking:1;		//0X1
	uint8_t s_bashing:1;		//0X2
	uint8_t s_floating:1;		//0X4
	uint8_t s_mining:1;		//0X8
	uint8_t s_drawning:1;		//0x10
	uint8_t s_ending:1;		//0x20
	uint8_t s_b7:1;			//0X40
	uint8_t s_b8:1;			//0X80 when exploding too ?
} __attribute__ ((__packed__));

union state {
	uint16_t raw;
	struct _state bf;
};

struct _flags1 {
	uint8_t cap_climber:1; // 0x1
	uint8_t bit_1:1;
	uint8_t bit_2:1;
	uint8_t bit_3:1;
	uint8_t bit_4:1;
	uint8_t bit_5:1;
	uint8_t bit_6:1;
	uint8_t walk_pause_for_shruggling:1; // 0X80
} __attribute__ ((__packed__));

union flags1 {
	uint8_t raw;
	struct _flags1 bf;
};

struct _lemm_data {
	uint16_t x_effective;	//0x0 - 0x1
	uint16_t y_effective;	//0x2 - 0x3
	int16_t x_spr_offset;	//0x4 - 0x5
	int16_t y_spr_offset;	//0x6 - 0x7
	union state state;	//0x8 - 0x9
	uint8_t b_10,b_11;
	uint16_t spr_data_ptr;	//0xc - 0xd
	uint8_t floattime_dble;	//0xe
	uint8_t b_15,b_16,b_17,b_18,b_19;
	uint16_t ptr2;		//0x14 - 0x15
	uint8_t b_22,b_23,b_24,b_25,b_26,b_27,b_28,b_29,b_30,b_31;
	uint8_t expl_countdown;	//0x20
	uint8_t steps_remain;	//0x21
	uint8_t b_34;
	uint8_t falldist;	//0x23
	union flags1 flags1;	//0x24
	uint8_t cap_floater;	//0x25
	uint8_t is_gone;	//0x26
	int8_t direction;	//0x27
	uint8_t spr_frame;	//0x28
	uint8_t draw_hint;	//0x29
	uint8_t b_42,b_43,b_44;
} __attribute__ ((__packed__));

union lemm_data {
	unsigned char raw[0x2d];
	struct _lemm_data s;
};

enum draw_hint {
	hint_nothing=0x00, hint_falling=0x04, hint_special1=0x08, /* climbing or slow falling or shruggling */
	hint_walking=0x09, hint_building=0x10, hint_mining=0x18, hint_bashing=0x20
};
char draw_hint_str[256][16];

enum state_bit {
	s_splatting=0, s_exploding, s_falling, s_ascending, s_digging, s_climbing, s_climb_ending, s_building,
	s_blocking, s_bashing, s_floating, s_mining, s_drawning, s_ending, s_b7, s_b8
};
char state_str[16][16];

int main(int argc, char *argv[]) {
	int i, rv, end=0;
	struct rsp_state rsp;
	char ds_si[10], command[16];
	union lemm_data lemm, prevlemm;

	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[s_splatting],"s_splatting");
	strcpy(state_str[s_exploding],"s_exploding");
	strcpy(state_str[s_falling],"s_falling");
	strcpy(state_str[s_ascending],"s_ascending");
	strcpy(state_str[s_digging],"s_digging");
	strcpy(state_str[s_climbing],"s_climbing");
	strcpy(state_str[s_climb_ending],"s_climb_ending");
	strcpy(state_str[s_building],"s_building");
	strcpy(state_str[s_blocking],"s_blocking");
	strcpy(state_str[s_bashing],"s_bashing");
	strcpy(state_str[s_floating],"s_floating");
	strcpy(state_str[s_mining],"s_mining");
	strcpy(state_str[s_drawning],"s_drawning");
	strcpy(state_str[s_ending],"s_ending");
	strcpy(state_str[s_b7],"s_b7");
	strcpy(state_str[s_b8],"s_b8");

	rv=rsp_lemm_init(&rsp, ds_si);
	if ( rv != 0 ) {
		printf("Error rsp_lemm_init() returns %i\n", rv);
		return 1;
	}

	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) != 0x2d * 2 ) {
			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
					break; /* Don't want to see state changes because the is well-known and frequent */

				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 (none)\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
					if ( !( lemm.s.expl_countdown < 0x4e && lemm.s.expl_countdown > 0x02) ) {
 						// Skip detailing all 80 changes... Just beginning and ending
						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.bf.cap_climber != lemm.s.flags1.bf.cap_climber ) {
						printf("cap_climber\t%2i -> %2i\n", prevlemm.s.flags1.bf.cap_climber, lemm.s.flags1.bf.cap_climber);
					} else if ( prevlemm.s.flags1.bf.walk_pause_for_shruggling != lemm.s.flags1.bf.walk_pause_for_shruggling ) {
						printf("walk_pause_for_shruggling\t%2i -> %2i\n", prevlemm.s.flags1.bf.walk_pause_for_shruggling, lemm.s.flags1.bf.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]); 
			}
		}
	}
	rsp_quit(&rsp);
	return 0;
}