Work on VERA API and interrupts

This commit is contained in:
Kyle Cardoza 2024-03-28 22:31:35 -04:00
parent 5032212b94
commit fc7419530b
7 changed files with 177 additions and 105 deletions

View File

@ -25,7 +25,7 @@
)
(memory MidRAM
(address (#x00F000 . #x00FFFF))
(address (#x00F000 . #x00FDFF))
(section code)
(section cnear)
(section reset)

View File

@ -7,6 +7,7 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
typedef enum {
@ -57,3 +58,9 @@ uint16_t vera_read_word(uint32_t addr);
void vera_write_byte(uint32_t addr, uint8_t value);
void vera_write_word(uint32_t addr, uint16_t value);
void vera_read(void *dest, uint32_t src, size_t length);
void vera_write(uint32_t dest, void *src, size_t length);
void vera_memset(uint32_t addr, uint8_t value, size_t length);

View File

@ -8,6 +8,8 @@
#include "config.h"
extern void interrupts_init(void);
void set_user_nmi_handler(void (*f)(void));
void set_user_brk_handler(void (*f)(void));

View File

@ -49,3 +49,43 @@ vera_write_word(uint32_t addr, uint16_t value)
vera_poke_data0((uint8_t)(value & 0x00FF));
vera_poke_data0((uint8_t)(value & 0xFF00) >> 8);
}
void
vera_read(void *dest, uint32_t src, size_t length)
{
uint8_t *dst = dest;
vera_set_data0_address(src);
vera_set_addr0_auto_increment(ADDR_INCREMENT_1);
vera_set_addr0_decrement(false);
for (size_t i = 0; i < length; i += 1) {
dst[i] = vera_peek_data0();
}
}
void
vera_write(uint32_t dest, void *src, size_t length)
{
uint8_t *source = src;
vera_set_data0_address(dest);
vera_set_addr0_auto_increment(ADDR_INCREMENT_1);
vera_set_addr0_decrement(false);
for (size_t i = 0; i < length; i += 1) {
vera_poke_data0(source[i]);
}
}
void
vera_memset(uint32_t addr, uint8_t value, size_t length)
{
vera_set_data0_address(addr);
vera_set_addr0_auto_increment(ADDR_INCREMENT_1);
vera_set_addr0_decrement(false);
for (size_t i = 0; i < length; i += 1) {
vera_poke_data0(value);
}
}

View File

@ -111,107 +111,3 @@ set_user_t0_handler(void (*f)(void))
{
user_t0_handler = f;
}
interrupt_handler(0x00FFBA) void
nmi_handler(void)
{
if (user_nmi_handler != NULL) {
user_nmi_handler();
}
}
interrupt_handler(0x00FFB6) void
brk_handler(void)
{
if (user_brk_handler != NULL) {
user_brk_handler();
}
}
interrupt_handler(0x00FFB4) void
cop_handler(void)
{
if (user_cop_handler != NULL) {
user_cop_handler();
}
}
interrupt_handler(0x00FF9E) void
irq_handler(void)
{
if (user_irq_handler != NULL) {
user_irq_handler();
}
}
interrupt_handler(0x00FF98) void
int_vera_irq_handler(void)
{
if (user_vera_irq_handler != NULL) {
user_vera_irq_handler();
}
}
interrupt_handler(0x00FF8E) void
int_t7_handler(void)
{
if (user_t7_handler != NULL) {
user_t7_handler();
}
}
interrupt_handler(0x00FF8C) void
int_t6_handler(void)
{
if (user_t6_handler != NULL) {
user_t6_handler();
}
}
interrupt_handler(0x00FF8A) void
int_t5_handler(void)
{
if (user_t5_handler != NULL) {
user_t5_handler();
}
}
interrupt_handler(0x00FF88) void
int_t4_handler(void)
{
if (user_t4_handler != NULL) {
user_t4_handler();
}
}
interrupt_handler(0x00FF86) void
int_t3_handler(void)
{
if (user_t3_handler != NULL) {
user_t3_handler();
}
}
interrupt_handler(0x00FF84) void
int_t2_handler(void)
{
if (user_t2_handler != NULL) {
user_t2_handler();
}
}
interrupt_handler(0x00FF82) void
int_t1_handler(void)
{
if (user_t1_handler != NULL) {
user_t1_handler();
}
}
interrupt_handler(0x00FF80) void
int_t0_handler(void)
{
if (user_t0_handler != NULL) {
user_t0_handler();
}
}

125
src/interrupts2.s Normal file
View File

@ -0,0 +1,125 @@
;;*****************************************************************************
;; Sentinel 65X Kernel
;;
;; src/interrupts2.s
;;*****************************************************************************
#include "macros.h"
.section code
.public interrupts_init
.extern _Dp
.extern __program_start
;------------------------------------------------------------------------------
interrupts_init:
sei
; 16 bit a/x
rep #0b00110000
; Set the vector for the IRQ handler.
lda #.near(irq_handler)
sta 0x00FF9E
; Set the vector for the NMI handler.
lda #.near(nmi_handler)
sta 0x00FF9E
; Set the vector for the COP handler.
lda #.near(cop_handler)
sta 0x00FFB4
; Set the vector for the VERA IRQ handler.
lda #.near(vera_irq_handler)
sta 0x00FF98
rts
;------------------------------------------------------------------------------
common_irq_return:
; 16 bit a/x
rep #0b00110000
ply
plx
pla
pld
plb
rti
;------------------------------------------------------------------------------
irq_handler:
phb
phd
; 16 bit a/x
rep #0b00110000
pha
phx
phy
bra common_irq_return
;------------------------------------------------------------------------------
vera_irq_handler:
phb
phd
; 16 bit a/x
rep #0b00110000
pha
phx
phy
bra common_irq_return
;------------------------------------------------------------------------------
nmi_handler:
phb
phd
; 16 bit a/x
rep #0b00110000
pha
phx
phy
bra common_irq_return
;------------------------------------------------------------------------------
cop_handler:
phb
phd
; 16 bit a/x
rep #0b00110000
pha
phx
phy
; COP dispatch here
; Function number comes in X, gets multiplied by 2, then
; used as an index to the jump table.
pha
txa
asl a
tax
pla
jmp (cop_dispatch_table,x)
cop_dispatch_table:
.word .near(cop_reset)
;------------------------------------------------------------------------------
cop_reset:
sei
; 16 bit a/x
rep #0b00110000
jmp long:__program_start

View File

@ -6,11 +6,13 @@
#include "config.h"
#include "interrupts.h"
#include "drivers/vera.h"
void
main(void)
{
interrupts_init();
vera_init();
for (;;) {}