/* defs.h Copyright (C) 2026 Pierre Sarrazin This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _H_defs #define _H_defs #include #if 0 #include #else #ifndef NDEBUG void assertHandler(const char *file, int lineno, const char *condition); #define assert(cond) do { if (!(cond)) assertHandler(__FILE__, __LINE__, ""); } while (0) #define static_assert(cond) typedef char CONCAT(_StaticAssertDummyArray_, __LINE__)[(cond) ? 1 : -1] #else #define assert(cond) ((void) 0) #define static_assert(cond) ((void) 0) #endif #define CONCAT2(a, b) a ## b #define CONCAT(a, b) CONCAT2(a, b) #endif // STRINGIFY(FOO) gives "FOO". // #define STRINGIFY(x) #x // If we have #define FOO 42 // then STRINGIFY_VALUE(FOO) gives "42". // #define STRINGIFY_VALUE(x) STRINGIFY(x) #ifndef MAX_NUM_DICT_BLOCKS #error "MAX_NUM_DICT_BLOCKS not defined." #endif #ifndef MIN_WORD_LEN #error "MIN_WORD_LEN not defined." #endif #ifndef MAX_WORD_LEN #error "MAX_WORD_LEN not defined." #endif // See HACKING.md for a memory map. enum { NUM_DISK_DRIVES = 1, IRQ_VECTOR = 0xFFF8, TEXT_SCREEN = 0xE000, // 32x16 and 40x24 hardware text screen buffer FONT_4x8_BUFFER = TEXT_SCREEN + 40 * 24, // contains bytes defined in font4x8-ascii.c FONT_4x8_SECTORS = 3, // number of sectors to read to fill that buffer FONT_5x8_BUFFER = FONT_4x8_BUFFER + FONT_4x8_SECTORS * 256, // contains bytes defined in font5x8-ascii.c FONT_5x8_SECTORS = 1, // number of sectors to read to fill that buffer STACK_BOTTOM = 0xFEEE, BLOCK_SIZE = 8192, // size in bytes of a GIME MMU block BREAK_KEY = 3, // Graphics: NUM_GRAPHICS_BLOCKS = 3, // 256x192x16 takes three 8k blocks SCRN_WIDTH = 256u, // in pixels SCRN_HEIGHT = 192u, // in pixels NUM_COLORS = 16, // number of CoCo 3 palette slots BYTES_PER_ROW = SCRN_WIDTH / 2, CHAR_WIDTH = 5, // number of pixels per graphics text window character column CHAR_HEIGHT = 8, // number of pixels per graphics text window character row TEXT_SCREEN_WIDTH = 51, // in characters TEXT_SCREEN_HEIGHT = 24, TEXT_WIN_LEFT = 37, // leftmost 51x24 screen column of text window (at right of board) TEXT_WIN_TOP = 18, TEXT_WIN_WIDTH = TEXT_SCREEN_WIDTH - TEXT_WIN_LEFT, // in characters TEXT_WIN_HEIGHT = TEXT_SCREEN_HEIGHT - TEXT_WIN_TOP, TEXT_TURN_ROW = 3, // text row where "Your/My turn" is written TEXT_RESULT_ROW = 5, TEXT_INSTR_ROW = 10, // instructions TEXT_SCORE_ROW = 16, // Hardware text mode (no color attributes): HW_TEXT_SCREEN_WIDTH = 40, HW_TEXT_SCREEN_HEIGHT = 24, HW_TEXT_SCREEN_BUFFER = 0xE000, HW_TEXT_SCREEN_BACK_COLOR = 0, HW_TEXT_SCREEN_FORE_COLOR = 63, // Game: BOARD_SIZE = 15, // number of board rows and columns TILE_WIDTH = 12, // in pixels TILE_HEIGHT = 12, // in pixels NUM_TILE_TYPES = 27, // A..Z plus blank RACK_SIZE = 7, // maximum number of tiles in a player's rack TILE_TYPE_NONE = 255, TILE_TYPE_BLANK = 0, NUM_BLANK_TILES = 2, NUM_PLAYERS = 2, LEVEL_EASY = 0, LEVEL_HARD = 1, // CoCo 3 memory blocks. (A 128k machine has blocks 48..63.) FIRST_GRAPHICS_BLOCK = 51, // graphics in 51..53 GRAPHICS_START = FIRST_GRAPHICS_BANK * BLOCK_SIZE, GRAPHICS_END = GRAPHICS_START + SCRN_WIDTH * SCRN_HEIGHT / 2, // SCRN_* need to be unsigned for this computation to work. // CoCo 3 memory banks (0..7). DICT_BANK = 0, FIRST_GRAPHICS_BANK = 4, // Palette values. PAL_POS_CURSOR = PAL_BOARD_WRITING, PAL_BLANK_TILE_FORE = PAL_BOARD_BG, }; // Board square types. // enum { SQ_EMPTY, SQ_START, SQ_TRIPLE_WORD, SQ_DOUBLE_WORD, SQ_TRIPLE_LETTER, SQ_DOUBLE_LETTER }; typedef interrupt void (*ISR)(void); // Gives a number of elements, not a number of bytes. // #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) #define ARRAY_END(array) ((array) + ARRAY_SIZE(array)) #define poke(address, byteValue) (* (byte *) (address) = (byteValue)) #define pokeWord(address, wordValue) (* (word *) (address) = (wordValue)) #define mmuSet(bank, block) (poke(0xFFA0 + (bank), (block))) typedef struct WordLengthRecord { byte blockNo; // MMU block that contains dictionary data; // (0 .. MAX_NUM_DICT_BLOCKS - 2) word wordOffset; // in dictionary words, from start of MMU block word offset; // in bytes, from start of MMU block } WordLengthRecord; // Array that is defined in word-length-index.c, generated by build-data.pl. // extern const WordLengthRecord wordLengthRecords[]; extern const byte numWordLengthRecords; // number of elements in wordLengthRecords[] #endif /* _H_defs */