-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolcommands.c
56 lines (50 loc) · 1.61 KB
/
controlcommands.c
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
#include <stdlib.h>
#include <stdio.h>
#include "controlcommands.h"
#include "stateutils.h"
#include "controlsocket.h"
#include "runner.h"
void handle_packet_load(struct EmuState* state, int client, struct payload_load* payload) {
set_rom(state, payload->romv, payload->romc);
free(payload->romv);
free(payload);
}
void handle_packet_continue(struct EmuState* state, int client, struct payload_continue* payload) {
state->stepping = true;
state->run = payload->count;
state->stepping = (state->run != UINT16_MAX);
emulate(state);
free(payload);
}
void handle_packet_get_state(struct EmuState* state, int client) {
struct response_get_state resp;
resp.romc = state->romc;
resp.romv = state->rom;
resp.ramc = state->ramc;
resp.ramv = state->ram;
send_response_set_state(client, &resp);
}
#ifdef DEBUG
#define PRINT_PACKET_TYPE(type) printf("command: " #type "\n")
#else
#define PRINT_PACKET_TYPE(type) (void)0
#endif
bool handle_packet(struct EmuState* state, int client, packet_type type, void* payload) {
switch (type) {
case TYPE_PACKET_LOAD:
PRINT_PACKET_TYPE(LOAD);
handle_packet_load(state, client, (struct payload_load*)payload);
break;
case TYPE_PACKET_CONTINUE:
PRINT_PACKET_TYPE(CONTINUE);
handle_packet_continue(state, client, (struct payload_continue*)payload);
break;
case TYPE_PACKET_GET_STATE:
PRINT_PACKET_TYPE(GET_STATE);
handle_packet_get_state(state, client);
break;
default:
return false;
}
return true;
}