cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

bin_to_com.h (1311B)


      1// This is free and unencumbered software released into the public domain.
      2// For more information, please refer to <https://unlicense.org>
      3// bbbbbr 2020
      4
      5#ifndef _BIN_TO_COM_H
      6#define _BIN_TO_COM_H
      7
      8#define MAX(a, b)            ((a > b) ? a : b)
      9#define BANKS_MAX_COUNT  256
     10#define BANKS_MAX_ID     (BANKS_MAX_COUNT - 1)
     11#define BANK_SIZE        (0x4000u)
     12#define BANK_START_ADDR  (0x0000u)
     13#define BANK_0           0
     14#define BANK_0_ADDR_OFFSET 0x100
     15
     16#define BANK_GET_NUM(addr)   ((addr & 0xFFFF0000U) >> 16)
     17#define WITHOUT_BANK(addr)   (addr & 0x0000FFFFU)
     18// Converts a symbol bank address such as 0x34000 to a bin/rom address such as 0x12000 (i.e: ~0x4000 * 3)
     19// Make sure base bank addess doesn't go negative
     20#define BANK_GET_ROM_ADDR(addr) ( (MAX(WITHOUT_BANK(addr), BANK_SIZE) - BANK_SIZE) + (BANK_SIZE * BANK_GET_NUM(addr)) )
     21
     22// Apply bank 0 address offset and make sure it doesn't go negative
     23#define BANK_0_RELOC_ADDR(addr)   (MAX((addr), BANK_0_ADDR_OFFSET) - BANK_0_ADDR_OFFSET)
     24
     25void copy_data(uint16_t bank_num, uint32_t rom_src_addr, uint32_t bank_out_addr, uint32_t length);
     26uint8_t * bank_get_ptr(uint16_t bank_num);
     27void copy_to_bank(uint16_t bank_num, uint32_t rom_src_addr, uint32_t bank_out_addr, uint32_t length);
     28void banks_cleanup(void);
     29int bin2com(void);
     30
     31#endif // _BIN_TO_COM_H