move UCI_COMMANDS fully to PROGMEM

This commit is contained in:
Quinten Kock 2020-06-19 18:58:33 +02:00
parent ce19f8793a
commit 9184324a7f
1 changed files with 24 additions and 12 deletions

36
Uci.h
View File

@ -23,17 +23,28 @@ uci_return uci_unknown() {
Serial.println(F("Not an UCI command"));
}
const uci_cmd UCI_COMMANDS[] = {
{PS2("uci"), &uci_hello},
{PS2("debug"), &uci_unimpl},
{PS2("isready"), &uci_unimpl},
{PS2("setoption"), &uci_unimpl},
{PS2("ucinewgame"), &uci_unimpl},
{PS2("position"), &uci_unimpl},
{PS2("go"), &uci_unimpl},
{PS2("stop"), &uci_unimpl},
{PS2("ponderhit"), &uci_unimpl},
{PS2("quit"), &uci_unimpl},
const char UCI_COMMAND_uci[] PROGMEM = "uci";
const char UCI_COMMAND_debug[] PROGMEM = "debug";
const char UCI_COMMAND_isready[] PROGMEM = "isready";
const char UCI_COMMAND_setoption[] PROGMEM = "setoption";
const char UCI_COMMAND_ucinewgame[] PROGMEM = "ucinewgame";
const char UCI_COMMAND_position[] PROGMEM = "position";
const char UCI_COMMAND_go[] PROGMEM = "go";
const char UCI_COMMAND_stop[] PROGMEM = "stop";
const char UCI_COMMAND_ponderhit[] PROGMEM = "ponderhit";
const char UCI_COMMAND_quit[] PROGMEM = "quit";
const uci_cmd UCI_COMMANDS[] PROGMEM = {
{UCI_COMMAND_uci, &uci_hello},
{UCI_COMMAND_debug, &uci_unimpl},
{UCI_COMMAND_isready, &uci_unimpl},
{UCI_COMMAND_setoption, &uci_unimpl},
{UCI_COMMAND_ucinewgame, &uci_unimpl},
{UCI_COMMAND_position, &uci_unimpl},
{UCI_COMMAND_go, &uci_unimpl},
{UCI_COMMAND_stop, &uci_unimpl},
{UCI_COMMAND_ponderhit, &uci_unimpl},
{UCI_COMMAND_quit, &uci_unimpl},
};
const uci_cmd UCI_INVALID = {PS2(""), &uci_unknown};
@ -42,7 +53,8 @@ uci_cmd get_uci_command(const char* command) {
size_t command_num = sizeof(UCI_COMMANDS) / sizeof(uci_cmd);
for(size_t i = 0; i < command_num; i++) {
size_t ci = 0;
uci_cmd to_try = UCI_COMMANDS[i];
uci_cmd to_try;
memcpy_P(&to_try, &UCI_COMMANDS[i], sizeof(uci_cmd));
while(true) {
char reference = pgm_read_byte_near(to_try.command + ci);
if(reference != command[ci]) {