/* Generates BUZBEE command hash data table asm file */ #include #include /* Length of commands in printable-char count (excluding NUL terminator). */ const int s_cchCmd = 4; /* Add your commands here to be hashed. Imprtant that they all be CCH_CMD * chars long EXCLUDING the NUL terminator. Order is important here. */ const char *s_ppszCmds[] = { "CALL", "HELP", "PEEK", "POKE", "SREC", /* "BOOT", */ }; int mkHash(const char pszCmd[]); int main(void) { /* Emit file header */ puts("; CHIBI PC-09 -- BUZBEE -- Command Hash Table\n\ ; Copyright (c) 2025 Gale Faraday\n\ ; Licensed under MIT\n\ \n\ ; This file generated by bbmkhash.c\n\ \n\ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\ ;;\n\ ;; BUZBEE Command Hash Table\n\ ;;\n\ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\ \n\ SECTION BBHASHES\n\ \n\ EXPORT BBCHTC\n\ EXPORT BBCHT\n"); /* Command count. * NOTE: This is a u16 because it gets emitted into the output assembly. */ uint16_t cCmds = sizeof(s_ppszCmds) / sizeof(char *); /* Emit command count */ printf("BBCHTC\n fdb $%.4X\n", cCmds); /* Emit table data */ puts("\nBBCHT"); for (int iCmd = 0; iCmd < cCmds; iCmd++) { uint8_t uHash = mkHash(s_ppszCmds[iCmd]); printf(" fcb $%.2X\n", uHash); } return 0; } int mkHash(const char pszCmd[]) { uint8_t nhash = 0; /* NOTE: Very important that condition is the length of the string MINUS the * NUL terminator, in this case iChar < 4 */ for (int iChar = 0; iChar < s_cchCmd; iChar++) nhash = nhash - pszCmd[iChar]; return nhash; }