12#ifndef _PICO9918_UTIL_H
13#define _PICO9918_UTIL_H
21#define TMS_DEFAULT_VRAM_NAME_ADDRESS 0x3800
22#define TMS_DEFAULT_VRAM_COLOR_ADDRESS 0x0000
23#define TMS_DEFAULT_VRAM_PATT_ADDRESS 0x2000
24#define TMS_DEFAULT_VRAM_SPRITE_ATTR_ADDRESS 0x3B00
25#define TMS_DEFAULT_VRAM_SPRITE_PATT_ADDRESS 0x1800
53 for (
size_t i = 0; i < numBytes; ++i)
62 for (
size_t i = 0; i < rpt; ++i)
72 size_t len = strlen(str);
73 for (
size_t i = 0; i < len; ++i)
82 size_t len = strlen(str);
83 for (
size_t i = 0; i < len; ++i)
92 return (uint8_t)((uint8_t)fg << 4) | (uint8_t)bg;
void pico9918_write_addr(pico9918_t *tms9918, uint8_t data)
write an address (mode = 1) to the tms9918
void pico9918_write_data(pico9918_t *tms9918, uint8_t data)
write data (mode = 0) to the tms9918
pico9918-core - core interface
pico9918_color_t
the sixteen TMS9918 colours, in palette-index order
#define PICO9918_INST_ARG
declare the instance ahead of other parameters
pico9918_register_t
the eight TMS9918 registers, by number and by what each one holds
#define PICO9918_INST_ONLY_ARG
declare the instance as the only parameter
#define PICO9918_INST
pass the instance ahead of other arguments
#define PICO9918_DLLEXPORT
the linkage every public entry point carries - see LINKAGE MODES above
static void pico9918_write_string(pico9918_t *tms9918, const char *str)
write a string to VRAM, its terminator excluded
static void pico9918_set_address_write(pico9918_t *tms9918, uint16_t addr)
point the VRAM address register at addr for writing, ie.
static void pico9918_write_string_offset(pico9918_t *tms9918, const char *str, uint8_t offset)
write a string to VRAM with offset added to each character's pattern index
static void pico9918_set_fg_bg_color(pico9918_t *tms9918, pico9918_color_t fg, pico9918_color_t bg)
set register 7, the text-mode foreground colour and the backdrop
static void pico9918_set_color_table_addr(pico9918_t *tms9918, uint16_t addr)
set the colour table address, which register 3 holds in 64-byte units
static void pico9918_set_address_read(pico9918_t *tms9918, uint16_t addr)
point the VRAM address register at addr for reading
static void pico9918_set_sprite_patt_table_addr(pico9918_t *tms9918, uint16_t addr)
set the sprite pattern table address, which register 6 holds in 2KB units
static void pico9918_set_name_table_addr(pico9918_t *tms9918, uint16_t addr)
set the name table address, which register 2 holds in 1KB units
static void pico9918_write_bytes(pico9918_t *tms9918, const uint8_t *bytes, size_t numBytes)
write a block of bytes to VRAM from the current address
static void pico9918_set_sprite_attr_table_addr(pico9918_t *tms9918, uint16_t addr)
set the sprite attribute table address, which register 5 holds in 128-byte units
static void pico9918_write_byte_rpt(pico9918_t *tms9918, uint8_t byte, size_t rpt)
write byte to VRAM rpt times from the current address
static void pico9918_write_register_value(pico9918_t *tms9918, pico9918_register_t reg, uint8_t value)
write a VDP register as a host would, value byte first
void pico9918_initialise_gfx_ii(pico9918_t *tms9918)
set up Graphics II with the default table addresses and a cleared VRAM
uint32_t pico9918_palette[]
the sixteen TMS9918 colours, each packed as 0xrrggbbaa
static uint8_t pico9918_fg_bg_color(pico9918_color_t fg, pico9918_color_t bg)
pack fg into the high nibble and bg into the low nibble of one colour byte
void pico9918_initialise_gfx_i(pico9918_t *tms9918)
set up Graphics I with the default table addresses and a cleared VRAM
static void pico9918_set_pattern_table_addr(pico9918_t *tms9918, uint16_t addr)
set the pattern table address, which register 4 holds in 2KB units