/* * 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. */ /* * Configuration DEFINEs * * Before including this file, you may define one or more of the following * to customize the library for your application: * * SWAP_RESTORE * * When using functions such as FAR_PEEK or bitmap features, return the * swap slot back to it's original memory location before returning. By * default, the swap slot is left in whatever state the last function that * used it switched it to. * * WITHOUT_GRAPHICS * * Shortcut for WITHOUT_BITMAP, WITHOUT_TILE, and WITHOUT_SPRITE. * * WITHOUT_BITMAP * * Disables bitmap functions. * * WITHOUT_TILE * * Disables tilemap functions. * * WITHOUT_SPRITE * * Disables sprite functions. * * WITHOUT_FILE * * Disables file handling support. * * WITHOUT_KERNEL * * Disables microkernel support. Also disables FILE, PLATFORM, and MAIN. * * WITHOUT_TEXT * * Disables text functions. Also disables PLATFORM. * * WITHOUT_MATH * * Disables math coprocessor support. Also disables TEXT, PLATFORM and * BITMAP. * * WITHOUT_MAIN * * Removes support for the standardized "int main(int argc, char *argv[])" * function and replaces it with "int main(void)". You must also manually * call "f256Init()" at the start of your program. * * WITHOUT_PLATFORM * * Removes basic C library I/O support for "getchar()" and "__putchar()". * This removes printf(). * * WITHOUT_DMA * * Removes DMA support. In the future, will also disable BITMAP. * */ #ifndef F256_H #define F256_H #ifdef __cplusplus extern "C" { #endif #include #include #ifndef F256LIB_AMALGAMATED_BUILD #include "stddclmr.h" #include "f_api.h" #include "f256_dma.h" #include "f256_intmath.h" #include "f256_irq.h" #include "f256jr.h" #include "f256_rtc.h" #include "f256_sprites.h" #include "f256_tiles.h" #include "f256_timers.h" #include "f256_via.h" #include "f256_xymath.h" #endif typedef unsigned char byte; typedef unsigned char bool; #define true 1 #define false 0 // Near memory slot to use for far memory swapping. #ifndef SWAP_SLOT #define SWAP_SLOT MMU_MEM_BANK_7 #endif #if SWAP_SLOT == MMU_MEM_BANK_7 #define SWAP_IO_SETUP() \ byte sios_ram = PEEK(MMU_MEM_BANK_7); \ asm("sei"); #define SWAP_IO_SHUTDOWN() \ POKE(MMU_MEM_BANK_7, sios_ram); \ asm("cli"); #else #define SWAP_IO_SETUP() #define SWAP_IO_SHUTDOWN() #endif #ifdef SWAP_RESTORE #define SWAP_RESTORE_SLOT() POKE(SWAP_SLOT, SWAP_SLOT - MMU_MEM_BANK_0) #else #define SWAP_RESTORE_SLOT() #endif #define SWAP_ADDR ((uint16_t)(SWAP_SLOT - MMU_MEM_BANK_0) * (uint16_t)0x2000) // Things not in the Merlin defs. #define EIGHTK 0x2000 #define TEXT_MATRIX 0xc000 // I/O Page 2 #define RAST_ROW_L 0xd01a #define RAST_ROW_H 0xd01b #define VKY_TS0_SQUARE (VKY_TS0_ADDR_H+1) #define VKY_TS1_SQUARE (VKY_TS1_ADDR_H+1) #define VKY_TS2_SQUARE (VKY_TS2_ADDR_H+1) #define VKY_TS3_SQUARE (VKY_TS3_ADDR_H+1) #define VKY_TS4_SQUARE (VKY_TS4_ADDR_H+1) #define VKY_TS5_SQUARE (VKY_TS5_ADDR_H+1) #define VKY_TS6_SQUARE (VKY_TS6_ADDR_H+1) #define VKY_TS7_SQUARE (VKY_TS7_ADDR_H+1) #define VIRQ 0xfffe #define JOY_UP 1 #define JOY_DOWN 2 #define JOY_LEFT 4 #define JOY_RIGHT 8 #define JOY_BUTTON_1 16 #define JOY_BUTTON_2 32 #define JOY_BUTTON_3 64 typedef struct colorS { byte r; byte g; byte b; } colorT; // Allow embedding binary data into program #define IBSTR2(x) #x #define IBSTR(x) IBSTR2(x) #define EMBED(INCBIN_SECTION, name, file) \ __asm__(".section " INCBIN_SECTION ",\"aR\" \n" \ ".global incbin_" IBSTR(name) "_start\n" \ ".balign 16\n" \ "incbin_" IBSTR(name) "_start:\n" \ ".incbin \"" file "\"\n" \ \ ".global incbin_" IBSTR(name) "_end\n" \ ".balign 1\n" \ "incbin_" IBSTR(name) "_end:\n" \ ".byte 0\n" \ ); \ extern __attribute__((aligned(16))) const char incbin_ ## name ## _start[]; \ extern const char incbin_ ## name ## _end[] // Single-byte #define PEEK(addy) ((byte)*(volatile byte *)(addy)) #define POKE(addy, value) (*(volatile byte *)(addy) = (value)) // Word (two bytes) #define PEEKW(addy) ((uint16_t)*(volatile uint16_t *)(addy)) #define POKEW(addy, value) (*(volatile uint16_t *)(addy) = (value)) // Address (three bytes) //#define PEEKA #define POKEA(addy, value) POKE(addy, value & 0xFF); POKE(addy + 1, (value >> 8) & 0xFF); POKE(addy + 2, (value >> 16) & 0xFF) // Double-word (four bytes) #define PEEKD(addy) ((uint32_t)*(volatile uint32_t *)(addy)) #define POKED(addy,value) (*(volatile uint32_t *)(addy) = (value)) // Bit fun. #define LOW_BYTE(x) ((byte)(x)) #define HIGH_BYTE(x) ((byte)(((uint16_t)(x)) >> 8)) #define SWAP_NIBBLES(x) ((x & 0x0F) << 4 | (x & 0xF0) >> 4) #define SWAP_UINT16(x) (((x) >> 8) | ((x) << 8)) #define CHECK_BIT(x, pos) (x & (1UL << pos)) #define TOGGLE_BIT(x, pos) (x ^= (1U << pos)) #define CLEAR_BIT(x, pos) (x &= (~(1U << pos))) #define SET_BIT(x, pos) (x |= (1U << pos)) // Verify configuration DEFINEs. #if (defined WITHOUT_BITMAP && defined WITHOUT_TILE && defined WITHOUT_SPRITE) #define WITHOUT_GRAPHICS #endif #ifdef WITHOUT_GRAPHICS #define WITHOUT_BITMAP #define WITHOUT_TILE #define WITHOUT_SPRITE #endif #ifdef WITHOUT_KERNEL #define WITHOUT_FILE #define WITHOUT_MAIN #define WITHOUT_PLATFORM #endif #ifdef WITHOUT_TEXT #define WITHOUT_PLATFORM #endif #ifdef WITHOUT_MATH #define WITHOUT_TEXT #define WITHOUT_PLATFORM #endif #ifndef F256LIB_AMALGAMATED_BUILD #include "f_kernel.h" #include "f_dma.h" #include "f_math.h" #include "f_random.h" #include "f_text.h" #include "f_bitmap.h" #include "f_tile.h" #include "f_graphics.h" #include "f_sprite.h" #include "f_file.h" #include "f_platform.h" #endif void f256Init(void); void f256Reset(void); byte FAR_PEEK(uint32_t address); uint16_t FAR_PEEKW(uint32_t address); void *FAR_POINTER(uint32_t address); void FAR_POKE(uint32_t address, byte value); void FAR_POKEW(uint32_t address, uint16_t value); #ifndef WITHOUT_MAIN #define main f256main // This one is needed if you build f256.c as it's own compilation unit. #endif #ifdef __cplusplus } #endif #ifndef F256LIB_AMALGAMATED_BUILD #ifdef F256LIB_IMPLEMENTATION #include "f256.c" #endif #endif #endif // F256_H