// SPDX-License-Identifier: MIT // // boot/vera.h // Defines for the VERA chip // // Copyright © 2024 Kyle J Cardoza #ifdef __CALYPSI_CC__ #include #include #include #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 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__ static inline uint8_t vera_addr_l_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF00 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_addr_l_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF00 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_addr_m_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF01 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_addr_m_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF01 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_addr_h_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF02 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_addr_h_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF02 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_data_0_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF03 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_data_0_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF03 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_data_1_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF04 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_data_1_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF04 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_ctrl_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF05 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_ctrl_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF05 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_ien_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF06 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_ien_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF06 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_isr_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF07 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_isr_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF07 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_scanline_l_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF08 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_irq_line_l_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF08 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_dc_video_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda #0b00000010 \n" " trb 0x00DF05 \n" " lda 0x00DF09 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_dc_video_write(uint8_t value) { __asm(" sep #0x20 \n" " pha \n" " lda #0b00000010 \n" " trb 0x00DF05 \n" " pla \n" " sta 0x00DF09 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_dc_hscale_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda #0b00000010 \n" " trb 0x00DF05 \n" " lda 0x00DF0A \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_dc_hscale_write(uint8_t value) { __asm(" sep #0x20 \n" " pha \n" " lda #0b00000010 \n" " trb 0x00DF05 \n" " pla \n" " sta 0x00DF0A \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_dc_vscale_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda #0b00000010 \n" " trb 0x00DF05 \n" " lda 0x00DF0B \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_dc_vscale_write(uint8_t value) { __asm(" sep #0x20 \n" " pha \n" " lda #0b00000010 \n" " trb 0x00DF05 \n" " pla \n" " sta 0x00DF0B \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_dc_border_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda #0b00000010 \n" " trb 0x00DF05 \n" " lda 0x00DF0C \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_dc_border_write(uint8_t value) { __asm(" sep #0x20 \n" " pha \n" " lda #0b00000010 \n" " trb 0x00DF05 \n" " pla \n" " sta 0x00DF0C \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_dc_hstart_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda #0b00000010 \n" " tsb 0x00DF05 \n" " lda 0x00DF09 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_dc_hstart_write(uint8_t value) { __asm(" sep #0x20 \n" " pha \n" " lda #0b00000010 \n" " tsb 0x00DF05 \n" " pla \n" " sta 0x00DF09 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_dc_hstop_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda #0b00000010 \n" " tsb 0x00DF05 \n" " lda 0x00DF0A \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_dc_hstop_write(uint8_t value) { __asm(" sep #0x20 \n" " pha \n" " lda #0b00000010 \n" " tsb 0x00DF05 \n" " pla \n" " sta 0x00DF0A \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_dc_vstart_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda #0b00000010 \n" " tsb 0x00DF05 \n" " lda 0x00DF0B \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_dc_vstart_write(uint8_t value) { __asm(" sep #0x20 \n" " pha \n" " lda #0b00000010 \n" " tsb 0x00DF05 \n" " pla \n" " sta 0x00DF0B \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_dc_vstop_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda #0b00000010 \n" " tsb 0x00DF05 \n" " lda 0x00DF0C \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_dc_vstop_write(uint8_t value) { __asm(" sep #0x20 \n" " pha \n" " lda #0b00000010 \n" " tsb 0x00DF05 \n" " pla \n" " sta 0x00DF0C \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l0_config_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF0D \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l0_config_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF0D \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l0_mapbase_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF0E \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l0_mapbase_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF0E \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l0_tilebase_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF0F \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l0_tilebase_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF0F \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l0_hscroll_l_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF10 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l0_hscroll_l_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF10 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l0_hscroll_h_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF11 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l0_hscroll_h_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF11 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l0_vscroll_l_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF12 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l0_vscroll_l_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF12 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l0_vscroll_h_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF13 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l0_vscroll_h_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF13 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l1_config_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF14 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l1_config_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF14 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l1_mapbase_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF15 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l1_mapbase_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF15 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l1_tilebase_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF16 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l1_tilebase_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF16 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l1_hscroll_l_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF17 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l1_hscroll_l_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF17 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l1_hscroll_h_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF18 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l1_hscroll_h_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF18 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l1_vscroll_l_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF19 \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l1_vscroll_l_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF19 \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_l1_vscroll_h_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF1A \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l1_vscroll_h_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF1A \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_audio_ctrl_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF1B \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_audio_ctrl_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF1B \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_audio_rate_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF1C \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_audio_rate_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF1C \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_audio_data_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF1D \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_audio_data_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF1D \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_spi_data_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF1E \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l1_spi_data_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF1E \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } static inline uint8_t vera_spi_ctrl_read(void) { uint8_t result; __asm(" sep #0x20 \n" " lda 0x00DF1F \n" " rep #0x20 \n" " and 0x00FF \n" : "=Ka"(result) : : "c" ); return result; } static inline void vera_l1_spi_ctrl_write(uint8_t value) { __asm(" sep #0x20 \n" " sta 0x00DF1F \n" " rep #0x20 \n" " and 0x00FF \n" : : "Ka"(value) : "c" ); } void vera_init(void); void vera_reset(void); void vera_address_select(uint8_t value); void vera_address_set(uint32_t address); 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