/* * Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /* * Z-Machine for the Foenix F256 computers. * * F256 machines are 65c02 based systems with 512k of banked RAM. * As such, this ZIP is going to load the story entirely into "high" * memory (above the 64k accessable to the CPU) and page things in * and out as needed. * * To keep library code at a minimum, we'll also statically allocate * as much as possible and do other "bad" things now frowned upon in * modern development. :-) */ #include "f256.h" #include "portme.h" #include "story.h" #include "memory.h" #include "state.h" #include "interpreter.h" #define BASE_ADDRESS 0x10000 uint8_t portByteGet(uint16_t address) { return FAR_PEEK(BASE_ADDRESS + address); } void portByteSet(uint16_t address, uint8_t value) { FAR_POKE(BASE_ADDRESS + address, value); } void portCharPrint(char c) { static char ch[2] = { 0, 0 }; ch[0] = c; textPrint(ch); } void portDie(char *fmt, ...) { #ifdef DEBUGGING printf("%s\n", fmt); // Yeah, this isn't right. #endif exit(1); } bool portFileRestore(void) { FILE *in; bool ok = false; uint32_t i; byte b; in = fopen("save.dat", "rb"); if (in) { ok = true; // Read in PC. ok &= (fread(&__state.pc, sizeof(__state.pc), 1, in) == 1); // Read in SP. ok &= (fread(&__state.sp, sizeof(__state.sp), 1, in) == 1); // Read in BP. ok &= (fread(&__state.bp, sizeof(__state.bp), 1, in) == 1); // Read in dynamic game RAM. for (i=0; i 0) { textGetXY(&x, &y); if (x > 0) { x--; } else { x = 0; y--; } textGotoXY(x, y); textPrint(" "); textGotoXY(x, y); i--; } } else { ZPOKE(ramAddr + i, c[0]); // Enter/Return. if ((c[0] == 13) || (c[0] == 10)) { textPrint("\n"); break; } textPrint(c); } } } uint16_t portRandomGet(int16_t range) { // If range is zero, randomize with "best" random seed. // If range is negative, use the positive value to seed. if (range == 0) return 0; if (range < 0) { randomSeed(-range); return 0; } return (randomRead() % range) + 1; } void portStoryLoad(void) { // Later, we probably want to see if the user has a memory expansion // installed. If they do, we can use it and then use the lower memory // for graphics and sound. ZPOKE(STORY_SCREEN_WIDTH_CHARACTERS, 80); ZPOKE(STORY_SCREEN_HEIGHT_LINES, 30); // Currently no status bar. ZPOKE(STORY_FLAG_V3, ZPEEK(STORY_FLAG_V3) | STORY_FLAG_V3_STATUS_LINE_NOT_AVAILABLE); // Uncomment for status bar and window splitting. //POKE(STORY_FLAG_V3, PEEK(STORY_FLAG_V3) & ~STORY_FLAG_V3_STATUS_LINE_NOT_AVAILABLE); //POKE(STORY_FLAG_V3, PEEK(STORY_FLAG_V3) | STORY_FLAG_V3_SCREEN_SPLITTING); } uint16_t portWordGet(uint16_t address) { return SWAP_UINT16(FAR_PEEKW(BASE_ADDRESS + address)); } void portWordSet(uint16_t address, uint16_t value) { FAR_POKEW(BASE_ADDRESS + address, SWAP_UINT16(value)); } int main(void) { f256Init(); textSetCursor(199); stateReset(); portStoryLoad(); opcodesSetup(); storySetup(); interpreterRun(); return 0; }