/* * 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. */ #ifndef F256LIB_AMALGAMATED_BUILD #include "f256.h" #include "f_kernel.c" #include "f_dma.c" #include "f_math.c" #include "f_random.c" #include "f_text.c" #include "f_bitmap.c" #include "f_tile.c" #include "f_graphics.c" #include "f_sprite.c" #include "f_file.c" #include "f_platform.c" #endif void f256Init(void) { // Swap I/O page 0 into bank 6. This is our normal state. POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); POKE(VKY_MSTR_CTRL_0, 63); // Enable text and all graphics. POKE(MMU_MEM_CTRL, 0xb3); // MLUT editing enabled, editing 3, 3 is active. // Set all memory slots to be CPU memory. POKE(MMU_MEM_BANK_0, 0); POKE(MMU_MEM_BANK_1, 1); POKE(MMU_MEM_BANK_2, 2); POKE(MMU_MEM_BANK_3, 3); POKE(MMU_MEM_BANK_4, 4); POKE(MMU_MEM_BANK_5, 5); //POKE(MMU_MEM_BANK_6, 6); // Don't use this - it's for the micro kernel. //POKE(MMU_MEM_BANK_7, 7); // Don't use this - it's for the micro kernel. #ifndef WITHOUT_KERNEL kernelReset(); #endif #ifndef WITHOUT_GRAPHICS graphicsReset(); #endif #ifndef WITHOUT_TEXT textReset(); #endif #ifndef WITHOUT_BITMAP bitmapReset(); #endif #ifndef WITHOUT_TILE tileReset(); #endif #ifndef WITHOUT_SPRITE spriteReset(); #endif #ifndef WITHOUT_FILE fileReset(); #endif #ifndef WITHOUT_RANDOM randomReset(); #endif } void f256Reset(void) { asm("sei"); POKE(MMU_MEM_BANK_7, 7); POKE(0xD6A2, 0xDE); POKE(0xD6A3, 0xAD); POKE(0xD6A0, 0xF0); POKE(0xD6A0, 0x00); asm("JMP ($FFFC)"); } byte FAR_PEEK(uint32_t address) { byte block; byte result; SWAP_IO_SETUP(); block = address / EIGHTK; address &= 0x1FFF; // Find offset into this block. POKE(SWAP_SLOT, block); result = PEEK(SWAP_ADDR + address); SWAP_RESTORE_SLOT(); SWAP_IO_SHUTDOWN(); return result; } uint16_t FAR_PEEKW(uint32_t address) { byte block; uint16_t result; SWAP_IO_SETUP(); block = address / EIGHTK; address &= 0x1FFF; // Find offset into this block. POKE(SWAP_SLOT, block); result = PEEKW(SWAP_ADDR + address); SWAP_RESTORE_SLOT(); SWAP_IO_SHUTDOWN(); return result; } void *FAR_POINTER(uint32_t address) { // This only works if we use slot 5 and don't restore it after swapping. #if SWAP_SLOT == MMU_MEM_BANK_5 byte block; block = address / EIGHTK; address &= 0x1FFF; // Find offset into this block. POKE(SWAP_SLOT, block); return (void *)address; #else return 0; #endif } void FAR_POKE(uint32_t address, byte value) { byte block; SWAP_IO_SETUP(); block = address / EIGHTK; address &= 0x1FFF; // Find offset into this block. POKE(SWAP_SLOT, block); POKE(SWAP_ADDR + address, value); SWAP_RESTORE_SLOT(); SWAP_IO_SHUTDOWN(); } void FAR_POKEW(uint32_t address, uint16_t value) { byte block; SWAP_IO_SETUP(); block = address / EIGHTK; address &= 0x1FFF; // Find offset into this block. POKE(SWAP_SLOT, block); POKEW(SWAP_ADDR + address, value); SWAP_RESTORE_SLOT(); SWAP_IO_SHUTDOWN(); } #ifndef WITHOUT_MAIN #ifdef main #undef main #endif int f256main(int argc, char *argv[]); int main(void) { f256Init(); f256main(kernelArgs->common.extlen / 2, (char **)kernelArgs->common.ext); f256Reset(); return 0; } #define main f256main // This one is needed if you build f256.c included with your code. #endif