/* * 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. */ #include #include #include #include #include "portme.h" #include "story.h" #include "state.h" #include "interpreter.h" #include "text.h" #pragma push_macro("bool") #undef bool #define DOS_IMPLEMENTATION #include "dos.h" #pragma pop_macro("bool") static char *_storyFile = NULL; static uint8_t *_RAM = NULL; static uint8_t _attr = (1 << 4) + 7; void portAttributeSet(byte attribute) { switch (attribute) { case TEXT_ATTR_NORMAL: textbackground(1); textcolor(7); _attr = (1 << 4) + 7; break; case TEXT_ATTR_REVERSE: textbackground(7); textcolor(1); _attr = (7 << 4) + 1; break; case TEXT_ATTR_BOLD: textbackground(1); textcolor(15); _attr = (1 << 4) + 15; break; case TEXT_ATTR_EMPHASIS: textbackground(1); textcolor(14); _attr = (1 << 4) + 14; break; } } uint8_t portByteGet(uint32_t address) { return _RAM[address]; } void portByteSet(uint32_t address, uint8_t value) { _RAM[address] = value; } char portCharGet(void) { char c; enum keycode_t key; #if 0 static char playback[] = "open mailbox\ntake leaflet\nread leaflet\ndrop leaflet\n"; static uint32_t pointer = 0; if (pointer < strlen(playback)) return playback[pointer++]; #endif do { c = *readchars(); key = *readkeys(); if (key == KEY_RETURN) c = 13; if (key == KEY_BACK) c = 127; if (key == KEY_DELETE) c = 8; } while (c == 0); return c; } void portCharGetPos(byte *x, byte *y) { *x = wherex() + 1; *y = wherey() + 1; } void portCharPrint(char c) { char ch[2] = { 0, 0 }; uint16_t *p; uint16_t v = (_attr << 8) + ' '; byte x; if ((wherex() >= screenwidth()) || (c == '\n')) { gotoxy(0, wherey() + 1); while (wherey() >= screenheight()) { memmove(((uint16_t*)screenbuffer()), ((uint16_t*)screenbuffer()) + screenwidth(), screenwidth() * (screenheight() - 1) * sizeof(uint16_t)); p = (uint16_t *)screenbuffer() + (screenwidth() * (screenheight() - 1)); for (x=0; x> 8) & 0xff; // MSB first. _RAM[address + 1] = value & 0xff; } int main(int argc, char *argv[]) { if (argc != 2) portDie("Usage: %s [storyfile]\n", argv[0]); _storyFile = argv[1]; setvideomode(videomode_80x25_9x16); curson(); textbackground(1); textcolor(7); clrscr(); gotoxy(0, screenheight() - 1); stateReset(); portStoryLoad(); opcodesSetup(); storySetup(80, 25); interpreterRun(); free(_RAM); return 0; }