Skip to content

Commit

Permalink
【HTTP】Add address map command.
Browse files Browse the repository at this point in the history
  • Loading branch information
skylersaleh committed Jul 18, 2023
1 parent 7a7153c commit 422eb6f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
28 changes: 28 additions & 0 deletions docs/HTTP_CONTROL_SERVER.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ The paramater format specifies which image format to use. It can be set to png,

Reads one or multiple bytes of data from the emulated system at addresses provided using parameters. The addr parameter can be repeated an arbitrary amount of times to read an arbitrary amount of bytes.

The paramater map can be used to specify different address maps. This is currently only used in the NDS core where address map 7 is used for the ARM7 address map and 0 and 9 are used for the ARM9 address map. The default address map is 0. The map command only effects bytes read after the parameter and does not persist across API calls.

**Example (Read a single byte):**

```http://localhost:8080/read_byte?addr=02000004```
Expand All @@ -127,10 +129,22 @@ Reads one or multiple bytes of data from the emulated system at addresses provid

```f0bf01```

**Example (Read multiple bytes from different address spaces ):**

```http://localhost:8080/read_byte?addr=02000004&map=7&addr=02000005&addr=02000006```

**Result:**

3 bytes of data are returned in hexadecimal (in the order mem_map0[0x02000004], mem_map7[0x02000005], mem_map7[0x02000006] of map 7)

```f0bf01```

# /write_byte command

Writes one or multiple bytes of data from the emulated system at addresses provided using parameters. Multiple addresses can be written to in a single command. Returns "ok" on completion

The paramater map can be used to specify different address maps. This is currently only used in the NDS core where address map 7 is used for the ARM7 address map and 0 and 9 are used for the ARM9 address map. The default address map is 0. The map command only effects bytes read after the parameter and does not persist across API calls.

**Example (Write a single byte):**

```http://localhost:8080/write_byte?02000000=ff```
Expand All @@ -155,6 +169,20 @@ mem[0x02000002] = 0xcc;

```ok```

**Example (Write multiple bytes from different maps ):**

```http://localhost:8080/write_byte?02000000=ff&map=7&02000001=ee&02000002=cc```

**Result:**

mem_map0[0x02000000] = 0xff;

mem_map7[0x02000001] = 0xee;

mem_map7[0x02000002] = 0xcc;

```ok```

# /input command

Sends an input to the emulated system which will stay until a different input command assigns a new value. The parameters specify the input to set and the value to set it to. In general all inputs that have keybinds in the GUI can be set using this command. A full list of the valid input names and their current state is viewable with the /status command. An arbitrary number of inputs can be set using this command. Returns "ok" on completion.
Expand Down
16 changes: 11 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4093,10 +4093,12 @@ uint8_t* se_hcs_callback(const char* cmd, const char** params, uint64_t* result_
}else if(strcmp(cmd,"/read_byte")==0){
uint64_t response_size = 0;
char *response = NULL;
int address_map=0;
while(*params){
if(strcmp(params[0],"addr")==0){
if(strcmp(params[0],"map")==0) address_map = atoi(params[1]);
else if(strcmp(params[0],"addr")==0){
uint64_t addr = se_hex_string_to_int(params[1]);
uint8_t byte = se_read_byte(addr,0);
uint8_t byte = se_read_byte(addr,address_map);
const char *map="0123456789abcdef";
se_append_char_to_string(&response,&response_size,map[SB_BFE(byte,4,4)]);
se_append_char_to_string(&response,&response_size,map[SB_BFE(byte,0,4)]);
Expand All @@ -4110,10 +4112,14 @@ uint8_t* se_hcs_callback(const char* cmd, const char** params, uint64_t* result_
}else if(strcmp(cmd,"/write_byte")==0){
uint64_t response_size = 0;
char *response = NULL;
int address_map = 0;
while(*params){
uint64_t addr = se_hex_string_to_int(params[0]);
uint8_t data = se_hex_string_to_int(params[1]);
se_write_byte(addr,0,data);
if(strcmp(params[0],"map")==0) address_map = atoi(params[1]);
else{
uint64_t addr = se_hex_string_to_int(params[0]);
uint8_t data = se_hex_string_to_int(params[1]);
se_write_byte(addr,address_map,data);
}
params+=2;
}
str_result="ok";
Expand Down

0 comments on commit 422eb6f

Please sign in to comment.