VERA driver work

This commit is contained in:
Kyle J Cardoza 2024-07-13 22:43:26 -04:00
parent b689b8c57a
commit 233a869420
6 changed files with 117 additions and 13 deletions

View File

@ -134,9 +134,11 @@
void vera_init(void); void vera_init(void);
uint8_t vera_reg_read(uint8_t regnum); void vera_reset(void);
void vera_reg_write(uint8_t reg, uint8_t value); uint8_t vera_reg_read(uint32_t regnum);
void vera_reg_write(uint32_t regnum, uint8_t value);
void vera_address_select(uint8_t value); void vera_address_select(uint8_t value);

View File

@ -47,16 +47,16 @@ w65c265s_init:
trb PD4 trb PD4
tsb PDD4 tsb PDD4
fclk_start
fclk_select
; Now we delay a while. ; Now we delay a while.
ldy ##0x0FFF ldy ##0x0FFF
delay_y delay_y
dey dey
bne delay_y bne delay_y
fclk_start
fclk_select
; Enable all the in-use chip select lines. ; Enable all the in-use chip select lines.
lda #0b11110011 lda #0b11110011
sta PCS7 sta PCS7
@ -127,3 +127,5 @@ __call_heap_initialize:
lda ##0 ; argc = 0 lda ##0 ; argc = 0
jsl long:main jsl long:main
stp stp

View File

@ -8,6 +8,7 @@
#include <stdint.h> #include <stdint.h>
#include "kernel/hardware/vera.h" #include "kernel/hardware/vera.h"
#include "kernel/util/delay.h"
static uint8_t *vera_ctrl = (uint8_t *)(VERA_CTRL); static uint8_t *vera_ctrl = (uint8_t *)(VERA_CTRL);
@ -17,6 +18,10 @@ static uint8_t *vera_addr_h = (uint8_t *)(VERA_ADDRx_H);
static uint8_t *vera_data_0 = (uint8_t *)(VERA_DATA_0); static uint8_t *vera_data_0 = (uint8_t *)(VERA_DATA_0);
extern uint16_t *vera_palette;
extern uint8_t vera_font_0[];
void vera_address_select(uint8_t value) { void vera_address_select(uint8_t value) {
if (value % 2 == 0) { if (value % 2 == 0) {
*vera_ctrl &= 0b11111110; *vera_ctrl &= 0b11111110;
@ -31,13 +36,13 @@ void vera_address_set(uint32_t address) {
*vera_addr_h = (uint8_t)(address >> 16); *vera_addr_h = (uint8_t)(address >> 16);
} }
uint8_t vera_reg_read(uint8_t regnum) { uint8_t vera_reg_read(uint32_t regnum) {
uint8_t *reg = (uint8_t *)((uint32_t)(VERA_BASE) + regnum); uint8_t *reg = (uint8_t *)((uint32_t)(regnum));
return *reg; return *reg;
} }
void vera_reg_write(uint8_t regnum, uint8_t value) { void vera_reg_write(uint32_t regnum, uint8_t value) {
uint8_t *reg = (uint8_t *)((uint32_t)(VERA_BASE) + regnum); uint8_t *reg = (uint8_t *)((uint32_t)(regnum));
*reg = value; *reg = value;
} }
@ -80,3 +85,53 @@ void vera_mem_clear(uint32_t dest, size_t length) {
*vera_data_0 = 0x00; *vera_data_0 = 0x00;
} }
} }
// Pull the VERA reset line (P4.2) low, hold it for a bit, then let it
// go high.
void vera_reset(void) {
__asm("\n"
" sep #0x20\n"
" lda #1 << 2\n"
" trb 0x00DF20\n"
" rep #0x20\n"
);
delay(1);
__asm("\n"
" sep #0x20\n"
" lda #1 << 2\n"
" tsb 0x00DF20\n"
" rep #0x20\n"
);
delay(1);
}
void vera_init(void) {
vera_reset();
vera_mem_write(VERA_PALETTE_BASE, vera_palette, 0x200);
vera_mem_write(TEXT_CONSOLE_TILES, vera_font_0, 0x1000);
vera_reg_write(VERA_DC_HSCALE, 0x80);
vera_reg_write(VERA_DC_VSCALE, 0x80);
vera_reg_write(VERA_L0_CONFIG, VERA_L_BPP1 | VERA_L_64H | VERA_L_128W);
vera_reg_write(VERA_L0_MAPBASE, TEXT_CONSOLE0_VRAM >> 9);
vera_reg_write(VERA_L0_TILEBASE, ((TEXT_CONSOLE_TILES >> 9) & 0b11111100) | VERA_TILESIZE8x16);
vera_reg_write(VERA_L0_HSCROLL_H, 0);
vera_reg_write(VERA_L0_HSCROLL_L, 0);
vera_reg_write(VERA_L0_VSCROLL_H, 0);
vera_reg_write(VERA_L0_HSCROLL_L, 0);
uint8_t ien_value = vera_reg_read(VERA_IEN) | 0b00000001;
vera_reg_write(VERA_IEN, ien_value);
uint8_t isr_value = vera_reg_read(VERA_ISR) | 0b00000001;
vera_reg_write(VERA_ISR, isr_value);
uint8_t dc_vid_value = vera_reg_read(VERA_DC_VIDEO) | 0b00010001;
vera_reg_write(VERA_DC_VIDEO, dc_vid_value);
}

View File

@ -6,5 +6,6 @@
; Copyright © 2024 Kyle J Cardoza <Kyle.Cardoza@icloud.com> ; Copyright © 2024 Kyle J Cardoza <Kyle.Cardoza@icloud.com>
.section cfar,rodata .section cfar,rodata
.public vera_font_0
vera_font_0: vera_font_0:
.incbin "vera_font_0.fnt" .incbin "vera_font_0.fnt"

View File

@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
//
// src/kernel/hardware/vera/vera_palette.c
// IRQ handlers
//
// Copyright © 2024 Kyle J Cardoza <Kyle.Cardoza@icloud.com>
#include <stdint.h>
uint16_t vera_palette[] = {
0x0000, 0x0fff, 0x0800, 0x0afe, 0x0c4c, 0x00c5, 0x000a, 0x0ee7,
0x0d85, 0x0640, 0x0f77, 0x0333, 0x0777, 0x0af6, 0x008f, 0x0bbb,
0x0000, 0x0111, 0x0222, 0x0333, 0x0444, 0x0555, 0x0666, 0x0777,
0x0888, 0x0999, 0x0aaa, 0x0bbb, 0x0ccc, 0x0ddd, 0x0eee, 0x0fff,
0x0211, 0x0433, 0x0644, 0x0866, 0x0a88, 0x0c99, 0x0fbb, 0x0211,
0x0422, 0x0633, 0x0844, 0x0a55, 0x0c66, 0x0f77, 0x0200, 0x0411,
0x0611, 0x0822, 0x0a22, 0x0c33, 0x0f33, 0x0200, 0x0400, 0x0600,
0x0800, 0x0a00, 0x0c00, 0x0f00, 0x0221, 0x0443, 0x0664, 0x0886,
0x0aa8, 0x0cc9, 0x0feb, 0x0211, 0x0432, 0x0653, 0x0874, 0x0a95,
0x0cb6, 0x0fd7, 0x0210, 0x0431, 0x0651, 0x0862, 0x0a82, 0x0ca3,
0x0fc3, 0x0210, 0x0430, 0x0640, 0x0860, 0x0a80, 0x0c90, 0x0fb0,
0x0121, 0x0343, 0x0564, 0x0786, 0x09a8, 0x0bc9, 0x0dfb, 0x0121,
0x0342, 0x0463, 0x0684, 0x08a5, 0x09c6, 0x0bf7, 0x0120, 0x0241,
0x0461, 0x0582, 0x06a2, 0x08c3, 0x09f3, 0x0120, 0x0240, 0x0360,
0x0480, 0x05a0, 0x06c0, 0x07f0, 0x0121, 0x0343, 0x0465, 0x0686,
0x08a8, 0x09ca, 0x0bfc, 0x0121, 0x0242, 0x0364, 0x0485, 0x05a6,
0x06c8, 0x07f9, 0x0020, 0x0141, 0x0162, 0x0283, 0x02a4, 0x03c5,
0x03f6, 0x0020, 0x0041, 0x0061, 0x0082, 0x00a2, 0x00c3, 0x00f3,
0x0122, 0x0344, 0x0466, 0x0688, 0x08aa, 0x09cc, 0x0bff, 0x0122,
0x0244, 0x0366, 0x0488, 0x05aa, 0x06cc, 0x07ff, 0x0022, 0x0144,
0x0166, 0x0288, 0x02aa, 0x03cc, 0x03ff, 0x0022, 0x0044, 0x0066,
0x0088, 0x00aa, 0x00cc, 0x00ff, 0x0112, 0x0334, 0x0456, 0x0668,
0x088a, 0x09ac, 0x0bcf, 0x0112, 0x0224, 0x0346, 0x0458, 0x056a,
0x068c, 0x079f, 0x0002, 0x0114, 0x0126, 0x0238, 0x024a, 0x035c,
0x036f, 0x0002, 0x0014, 0x0016, 0x0028, 0x002a, 0x003c, 0x003f,
0x0112, 0x0334, 0x0546, 0x0768, 0x098a, 0x0b9c, 0x0dbf, 0x0112,
0x0324, 0x0436, 0x0648, 0x085a, 0x096c, 0x0b7f, 0x0102, 0x0214,
0x0416, 0x0528, 0x062a, 0x083c, 0x093f, 0x0102, 0x0204, 0x0306,
0x0408, 0x050a, 0x060c, 0x070f, 0x0212, 0x0434, 0x0646, 0x0868,
0x0a8a, 0x0c9c, 0x0fbe, 0x0211, 0x0423, 0x0635, 0x0847, 0x0a59,
0x0c6b, 0x0f7d, 0x0201, 0x0413, 0x0615, 0x0826, 0x0a28, 0x0c3a,
0x0f3c, 0x0201, 0x0403, 0x0604, 0x0806, 0x0a08, 0x0c09, 0x0f0b
};

View File

@ -10,13 +10,15 @@
#include "kernel/util/delay.h" #include "kernel/util/delay.h"
#include "kernel/hardware/led.h" #include "kernel/hardware/led.h"
#include "kernel/hardware/vera.h"
void main(void) { void main(void) {
led_init(); led_init();
for (;;) { vera_reset();
for (;;) {
led_red_on(); led_red_on();
delay(1); delay(1);
led_red_off(); led_red_off();
@ -30,6 +32,5 @@ void main(void) {
led_blue_off(); led_blue_off();
delay(1); delay(1);
} }
} }