65X-DOS/include/kernel/hardware/vera.h

381 lines
9.2 KiB
C
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// SPDX-License-Identifier: MIT
//
// boot/vera.h
// Defines for the VERA chip
//
// Copyright © 2024 Kyle J Cardoza <Kyle.Cardoza@icloud.com>
#ifdef __CALYPSI_CC__
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#endif
#define AUTO_NONE 0x000000
#define AUTO_INC_1 0x100000
#define AUTO_INC_2 0x200000
#define AUTO_INC_4 0x300000
#define AUTO_INC_8 0x400000
#define AUTO_INC_16 0x500000
#define AUTO_INC_32 0x600000
#define AUTO_INC_64 0x700000
#define AUTO_INC_128 0x800000
#define AUTO_INC_256 0x900000
#define AUTO_INC_512 0xA00000
#define AUTO_INC_40 0xB00000
#define AUTO_INC_80 0xC00000dest, void *src, size_t length
#define AUTO_INC_160 0xD00000
#define AUTO_INC_320 0xE00000
#define AUTO_INC_640 0xF00000
#define DISABLED 0
#define ENABLED 1
#define VERA_L_BPP1 0b00000000
#define VERA_L_BPP2 0b00000001
#define VERA_L_BPP4 0b00000010
#define VERA_L_BPP8 0b00000011
#define VERA_L_BITMAP 0b00000100
#define VERA_L_T256C 0b00001000
#define VERA_L_32W 0b00000000
#define VERA_L_64W 0b00010000
#define VERA_L_128W 0b00100000
#define VERA_L_256W 0b00110000
#define VERA_L_32H 0b00000000
#define VERA_L_64H 0b01000000
#define VERA_L_128H 0b10000000
#define VERA_L_256 <stddef.h>H 0b11000000
#define VERA_TILESIZE8x8 0b00000000
#define VERA_TILESIZE16x8 0b00000001
#define VERA_TILESIZE8x16 0b00000010
#define VERA_TILESIZE16x16 0b00000011
// The base address of the VERA chip
#define VERA_BASE 0x00DF00
// Offsets (relative to VERA_BASE) for each VERA register
#define VERA_ADDRx_L (VERA_BASE + 0x00)
#define VERA_ADDRx_M (VERA_BASE + 0x01)
#define VERA_ADDRx_H (VERA_BASE + 0x02)
// Accssible with ADDRSEL 0
#define VERA_ADDR0_L (VERA_BASE + 0x00)
#define VERA_ADDR0_M (VERA_BASE + 0x01)
#define VERA_ADDR0_H (VERA_BASE + 0x02)
// Accssible with ADDRSEL 1
#define VERA_ADDR1_L (VERA_BASE + 0x00)
#define VERA_ADDR1_M (VERA_BASE + 0x01)
#define VERA_ADDR1_H (VERA_BASE + 0x02)
#define VERA_DATA_0 (VERA_BASE + 0x03)
#define VERA_DATA_1 (VERA_BASE + 0x04)
#define VERA_CTRL (VERA_BASE + 0x05)
#define VERA_IEN (VERA_BASE + 0x06)
#define VERA_ISR (VERA_BASE + 0x07)
#define VERA_IRQLINE_L (VERA_BASE + 0x08)
#define VERA_SCANLINE_L (VERA_BASE + 0x08)
// Accssible with DCSEL 0
#define VERA_DC_VIDEO (VERA_BASE + 0x09)
#define VERA_DC_HSCALE (VERA_BASE + 0x0A)
#define VERA_DC_VSCALE (VERA_BASE + 0x0B)
#define VERA_DC_BORDER (VERA_BASE + 0x0C)
// Accssible with DCSEL 1
#define VERA_DC_HSTART (VERA_BASE + 0x09)
#define VERA_DC_HSTOP (VERA_BASE + 0x0A)
#define VERA_DC_VSTART (VERA_BASE + 0x0B)
#define VERA_DC_VSTOP (VERA_BASE + 0x0C)
// Layer 0
#define VERA_L0_CONFIG (VERA_BASE + 0x0D)
#define VERA_L0_MAPBASE (VERA_BASE + 0x0E)
#define VERA_L0_TILEBASE (VERA_BASE + 0x0F)
#define VERA_L0_HSCROLL_L (VERA_BASE + 0x10)
#define VERA_L0_HSCROLL_H (VERA_BASE + 0x11)
#define VERA_L0_VSCROLL_L (VERA_BASE + 0x12)
#define VERA_L0_VSCROLL_H (VERA_BASE + 0x13)
// Layer 1
#define VERA_L1_CONFIG (VERA_BASE + 0x14)
#define VERA_L1_MAPBASE (VERA_BASE + 0x15)
#define VERA_L1_TILEBASE (VERA_BASE + 0x16)
#define VERA_L1_HSCROLL_L (VERA_BASE + 0x17)
#define VERA_L1_HSCROLL_H (VERA_BASE + 0x18)
#define VERA_L1_VSCROLL_L (VERA_BASE + 0x19)
#define VERA_L1_VSCROLL_H (VERA_BASE + 0x1A)
// Audio
#define VERA_AUDIO_CTRL (VERA_BASE + 0x1B)
#define VERA_AUDIO_RATE (VERA_BASE + 0x1C)
#define VERA_AUDIO_DATA (VERA_BASE + 0x1D)
// SPI (Unused in prototype four!)
#define VERA_SPI_DATA (VERA_BASE + 0x1E)
#define VERA_SPI_CTRL (VERA_BASE + 0x1F)
// VRAM layout
#define TEXT_CONSOLE_TILES 0x000800
#define TEXT_CONSOLE0_VRAM 0x001800 // Runs up to 0x5800
#define TEXT_CONSOLE_SPRITE_BITMAPS 0x005800
#define VERA_PSG_BASE 0x01F9C0
#define VERA_PALETTE_BASE 0x01FA00
#define VERA_SPRITE_ATTR_BASE 0x01FC00
// The assembler can't handle this stuff.
#ifdef __CALYPSI_CC__
__attribute__((simple_call))
uint8_t vera_addr_l_read(void);
__attribute__((simple_call))
void vera_addr_l_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_addr_m_read(void);
__attribute__((simple_call))
void vera_addr_m_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_addr_h_read(void);
__attribute__((simple_call))
void vera_addr_h_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_data_0_read(void);
__attribute__((simple_call))
void vera_data_0_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_data_1_read(void);
__attribute__((simple_call))
void vera_data_1_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_ctrl_read(void);
__attribute__((simple_call))
void vera_ctrl_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_ien_read(void);
__attribute__((simple_call))
void vera_ien_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_isr_read(void);
__attribute__((simple_call))
void vera_isr_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_scanline_l_read(void);
__attribute__((simple_call))
void vera_irq_line_l_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_dc_video_read(void);
__attribute__((simple_call))
void vera_dc_video_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_dc_hscale_read(void);
__attribute__((simple_call))
void vera_dc_hscale_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_dc_vscale_read(void);
__attribute__((simple_call))
void vera_dc_vscale_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_dc_border_read(void);
__attribute__((simple_call))
void vera_dc_border_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_dc_hstart_read(void);
__attribute__((simple_call))
void vera_dc_hstart_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_dc_hstop_read(void);
__attribute__((simple_call))
void vera_dc_hstop_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_dc_vstart_read(void);
__attribute__((simple_call))
void vera_dc_vstart_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_dc_vstop_read(void);
__attribute__((simple_call))
void vera_dc_vstop_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l0_config_read(void);
__attribute__((simple_call))
void vera_l0_config_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l0_mapbase_read(void);
__attribute__((simple_call))
void vera_l0_mapbase_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l0_tilebase_read(void);
__attribute__((simple_call))
void vera_l0_tilebase_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l0_hscroll_l_read(void);
__attribute__((simple_call))
void vera_l0_hscroll_l_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l0_hscroll_h_read(void);
__attribute__((simple_call))
void vera_l0_hscroll_h_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l0_vscroll_l_read(void);
__attribute__((simple_call))
void vera_l0_vscroll_l_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l0_vscroll_h_read(void);
__attribute__((simple_call))
void vera_l0_vscroll_h_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l1_config_read(void);
__attribute__((simple_call))
void vera_l1_config_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l1_mapbase_read(void);
__attribute__((simple_call))
void vera_l1_mapbase_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l1_tilebase_read(void);
__attribute__((simple_call))
void vera_l1_tilebase_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l1_hscroll_l_read(void);
__attribute__((simple_call))
void vera_l1_hscroll_l_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l1_hscroll_h_read(void);
__attribute__((simple_call))
void vera_l1_hscroll_h_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l1_vscroll_l_read(void);
__attribute__((simple_call))
void vera_l1_vscroll_l_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_l1_vscroll_h_read(void);
__attribute__((simple_call))
void vera_l1_vscroll_h_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_audio_ctrl_read(void);
__attribute__((simple_call))
void vera_audio_ctrl_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_audio_rate_read(void);
__attribute__((simple_call))
void vera_audio_rate_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_audio_data_read(void);
__attribute__((simple_call))
void vera_audio_data_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_spi_data_read(void);
__attribute__((simple_call))
void vera_l1_spi_data_write(uint8_t value);
__attribute__((simple_call))
uint8_t vera_spi_ctrl_read(void);
__attribute__((simple_call))
uint8_t vera_l1_spi_ctrl_write(uint8_t value);
__attribute__((simple_call))
void vera_reset(void);
void vera_init(void);
static inline void vera_address_select(uint8_t value) {
uint8_t ctrl = vera_ctrl_read();
if (value == 0) {
ctrl &= 0b11111110;
} else {
ctrl |= 0b00000001;
}
vera_ctrl_write(ctrl);
}
static inline void vera_address_set(uint32_t address) {
vera_addr_l_write(address & 0x0000FF);
vera_addr_m_write((address >> 8) & 0x0000FF);
vera_addr_h_write((address >> 16) & 0x0000FF);
}
void vera_mem_write(uint32_t dest, void *src, size_t length);
void vera_mem_set(uint32_t dest, uint8_t value, size_t length);
void vera_mem_clear(uint32_t dest, size_t length);
#endif