VERA driver work

This commit is contained in:
Kyle J Cardoza 2024-07-13 16:30:07 -04:00
parent 52f06b7d15
commit b689b8c57a
3 changed files with 103 additions and 16 deletions

View File

@ -6,6 +6,7 @@
// Copyright © 2024 Kyle J Cardoza <Kyle.Cardoza@icloud.com> // Copyright © 2024 Kyle J Cardoza <Kyle.Cardoza@icloud.com>
#ifdef __CALYPSI_CC__ #ifdef __CALYPSI_CC__
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#endif #endif
@ -22,7 +23,7 @@
#define AUTO_INC_256 0x900000 #define AUTO_INC_256 0x900000
#define AUTO_INC_512 0xA00000 #define AUTO_INC_512 0xA00000
#define AUTO_INC_40 0xB00000 #define AUTO_INC_40 0xB00000
#define AUTO_INC_80 0xC00000 #define AUTO_INC_80 0xC00000dest, void *src, size_t length
#define AUTO_INC_160 0xD00000 #define AUTO_INC_160 0xD00000
#define AUTO_INC_320 0xE00000 #define AUTO_INC_320 0xE00000
#define AUTO_INC_640 0xF00000 #define AUTO_INC_640 0xF00000
@ -46,7 +47,7 @@
#define VERA_L_32H 0b00000000 #define VERA_L_32H 0b00000000
#define VERA_L_64H 0b01000000 #define VERA_L_64H 0b01000000
#define VERA_L_128H 0b10000000 #define VERA_L_128H 0b10000000
#define VERA_L_256H 0b11000000 #define VERA_L_256 <stddef.h>H 0b11000000
#define VERA_TILESIZE8x8 0b00000000 #define VERA_TILESIZE8x8 0b00000000
#define VERA_TILESIZE16x8 0b00000001 #define VERA_TILESIZE16x8 0b00000001
@ -58,19 +59,19 @@
// Offsets (relative to VERA_BASE) for each VERA register // Offsets (relative to VERA_BASE) for each VERA register
#define VERA_ADDRx_L VERA_BASE + 00 #define VERA_ADDRx_L VERA_BASE + 0x00
#define VERA_ADDRx_M VERA_BASE + 01 #define VERA_ADDRx_M VERA_BASE + 0x01
#define VERA_ADDRx_H VERA_BASE + 02 #define VERA_ADDRx_H VERA_BASE + 0x02
// Accssible with ADDRSEL 0 // Accssible with ADDRSEL 0
#define VERA_ADDR0_L VERA_BASE + 00 #define VERA_ADDR0_L VERA_BASE + 0x00
#define VERA_ADDR0_M VERA_BASE + 01 #define VERA_ADDR0_M VERA_BASE + 0x01
#define VERA_ADDR0_H VERA_BASE + 02 #define VERA_ADDR0_H VERA_BASE + 0x02
// Accssible with ADDRSEL 1 // Accssible with ADDRSEL 1
#define VERA_ADDR1_L VERA_BASE + 00 #define VERA_ADDR1_L VERA_BASE + 0x00
#define VERA_ADDR1_M VERA_BASE + 01 #define VERA_ADDR1_M VERA_BASE + 0x01
#define VERA_ADDR1_H VERA_BASE + 02 #define VERA_ADDR1_H VERA_BASE + 0x02
#define VERA_DATA_0 VERA_BASE + 0x03 #define VERA_DATA_0 VERA_BASE + 0x03
#define VERA_DATA_1 VERA_BASE + 0x04 #define VERA_DATA_1 VERA_BASE + 0x04
@ -131,16 +132,20 @@
// The assembler can't handle this stuff. // The assembler can't handle this stuff.
#ifdef __CALYPSI_CC__ #ifdef __CALYPSI_CC__
uint8_t vera_reg_get(uint8_t reg); void vera_init(void);
void vera_reg_set(uint8_t reg, uint8_t value); uint8_t vera_reg_read(uint8_t regnum);
void vera_reset(void); void vera_reg_write(uint8_t reg, uint8_t value);
void vera_mem_read(void *dest, uint32_t src, size_t length); 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_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_set(uint32_t dest, uint8_t value, size_t length);
void vera_mem_clear(uint32_t dest, size_t length);
#endif #endif

View File

@ -126,4 +126,4 @@ __call_heap_initialize:
.section boot, root, noreorder .section boot, root, noreorder
lda ##0 ; argc = 0 lda ##0 ; argc = 0
jsl long:main jsl long:main
jmp long:exit stp

View File

@ -0,0 +1,82 @@
// SPDX-License-Identifier: MIT
//
// src/kernel/hardware/vera/vera.c
// IRQ handlers
//
// Copyright © 2024 Kyle J Cardoza <Kyle.Cardoza@icloud.com>
#include <stdint.h>
#include "kernel/hardware/vera.h"
static uint8_t *vera_ctrl = (uint8_t *)(VERA_CTRL);
static uint8_t *vera_addr_l = (uint8_t *)(VERA_ADDRx_L);
static uint8_t *vera_addr_m = (uint8_t *)(VERA_ADDRx_M);
static uint8_t *vera_addr_h = (uint8_t *)(VERA_ADDRx_H);
static uint8_t *vera_data_0 = (uint8_t *)(VERA_DATA_0);
void vera_address_select(uint8_t value) {
if (value % 2 == 0) {
*vera_ctrl &= 0b11111110;
} else {
*vera_ctrl |= 0b00000001;
}
}
void vera_address_set(uint32_t address) {
*vera_addr_l = (uint8_t)(address & 0x0000FF);
*vera_addr_m = (uint8_t)((address & 0x00FF00) >> 8);
*vera_addr_h = (uint8_t)(address >> 16);
}
uint8_t vera_reg_read(uint8_t regnum) {
uint8_t *reg = (uint8_t *)((uint32_t)(VERA_BASE) + regnum);
return *reg;
}
void vera_reg_write(uint8_t regnum, uint8_t value) {
uint8_t *reg = (uint8_t *)((uint32_t)(VERA_BASE) + regnum);
*reg = value;
}
void vera_mem_read(void *dest, uint32_t src, size_t length) {
vera_address_select(0);
vera_address_set(src | AUTO_INC_1);
uint8_t *destination = dest;
for (size_t i = 0; i < length; i += 1, destination += 1) {
*destination = *vera_data_0;
}
}
void vera_mem_write(uint32_t dest, void *src, size_t length) {
vera_address_select(0);
vera_address_set(dest | AUTO_INC_1);
uint8_t *source = src;
for (size_t i = 0; i < length; i += 1, source += 1) {
*vera_data_0 = *source;
}
}
void vera_mem_set(uint32_t dest, uint8_t value, size_t length) {
vera_address_select(0);
vera_address_set(dest | AUTO_INC_1);
for (size_t i = 0; i < length; i += 1) {
*vera_data_0 = value;
}
}
void vera_mem_clear(uint32_t dest, size_t length) {
vera_address_select(0);
vera_address_set(dest | AUTO_INC_1);
for (size_t i = 0; i < length; i += 1) {
*vera_data_0 = 0x00;
}
}