From 9184324a7fe0537d1be9734d8ed6b57b018b0c89 Mon Sep 17 00:00:00 2001 From: Quinten Kock Date: Fri, 19 Jun 2020 18:58:33 +0200 Subject: [PATCH] move UCI_COMMANDS fully to PROGMEM --- Uci.h | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/Uci.h b/Uci.h index 6a8ad2f..1de76db 100644 --- a/Uci.h +++ b/Uci.h @@ -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]) {