Adding libugba interrupt handler

This commit is contained in:
Rodrigo Alfonso
2022-05-20 05:30:56 -03:00
parent e219892664
commit e18f3232ab
66 changed files with 2686 additions and 43 deletions

View File

@@ -131,13 +131,13 @@ export PATH := $(DEVKITARM)/bin:$(PATH)
export PROJ ?= $(notdir $(CURDIR))
TITLE := $(PROJ)
LIBS := -ltonc
LIBS := -ltonc -lugba
BUILD := build
SRCDIRS := src
DATADIRS := data
INCDIRS := src lib
LIBDIRS := $(TONCLIB)
INCDIRS := src
LIBDIRS := $(TONCLIB) $(PWD)/../_lib/libugba
# --- switches ---

View File

@@ -1 +0,0 @@
../../../lib/LinkConnection.h

View File

@@ -0,0 +1,22 @@
#include "interrupt.h"
#include <ugba.h>
void interrupt_init(void) {
IRQ_Init();
}
void interrupt_set_handler(interrupt_index index, interrupt_vector function) {
IRQ_SetHandler((irq_index)index, function);
}
void interrupt_enable(interrupt_index index) {
IRQ_Enable((irq_index)index);
}
void interrupt_disable(interrupt_index index) {
IRQ_Disable((irq_index)index);
}
void interrupt_set_reference_vcount(unsigned long y) {
IRQ_SetReferenceVCOUNT(y);
}

View File

@@ -0,0 +1,30 @@
#ifndef INTERRUPT_H
#define INTERRUPT_H
typedef enum {
INTR_VBLANK = 0,
INTR_HBLANK = 1,
INTR_VCOUNT = 2,
INTR_TIMER0 = 3,
INTR_TIMER1 = 4,
INTR_TIMER2 = 5,
INTR_TIMER3 = 6,
INTR_SERIAL = 7,
INTR_DMA0 = 8,
INTR_DMA1 = 9,
INTR_DMA2 = 10,
INTR_DMA3 = 11,
INTR_KEYPAD = 12,
INTR_GAMEPAK = 13,
INTR_NUMBER
} interrupt_index;
typedef void (*interrupt_vector)(void);
void interrupt_init(void);
void interrupt_set_handler(interrupt_index index, interrupt_vector function);
void interrupt_enable(interrupt_index index);
void interrupt_disable(interrupt_index index);
void interrupt_set_reference_vcount(unsigned long y);
#endif // INTERRUPT_H

View File

@@ -1,9 +1,9 @@
#include <tonc.h>
#include <string>
#include "interrupt.h"
// (0) Include the header
#include "../lib/LinkConnection.h"
#include "../../_lib/LinkConnection.h"
void log(std::string text);
@@ -14,12 +14,14 @@ void init() {
REG_DISPCNT = DCNT_MODE0 | DCNT_BG0;
tte_init_se_default(0, BG_CBB(0) | BG_SBB(31));
irq_init(NULL);
// (2) Add the interrupt service routines
irq_add(II_VBLANK, LINK_ISR_VBLANK);
irq_add(II_SERIAL, LINK_ISR_SERIAL);
irq_add(II_TIMER3, LINK_ISR_TIMER);
interrupt_init();
interrupt_set_handler(INTR_VBLANK, LINK_ISR_VBLANK);
interrupt_enable(INTR_VBLANK);
interrupt_set_handler(INTR_SERIAL, LINK_ISR_SERIAL);
interrupt_enable(INTR_SERIAL);
interrupt_set_handler(INTR_TIMER3, LINK_ISR_TIMER);
interrupt_enable(INTR_TIMER3);
// (3) Initialize the library
linkConnection->activate();
@@ -32,7 +34,7 @@ int main() {
for (u32 i = 0; i < LINK_MAX_PLAYERS; i++)
data[i] = 0;
while (1) {
while (true) {
// (4) Send/read messages messages
u16 keys = ~REG_KEYS & KEY_ANY;
u16 message = keys + 1;
@@ -44,8 +46,9 @@ int main() {
output += "Players: " + std::to_string(linkState->playerCount) + "\n";
for (u32 i = 0; i < linkState->playerCount; i++) {
while (linkState->hasMessage(i))
while (linkState->hasMessage(i)) {
data[i] = linkState->readMessage(i) - 1;
}
output += "Player " + std::to_string(i) + ": " +
std::to_string(data[i]) + "\n";
@@ -53,8 +56,9 @@ int main() {
output += "_sent: " + std::to_string(message) + "\n";
output += "_self pID: " + std::to_string(linkState->currentPlayerId);
} else
} else {
output += std::string("Waiting...");
}
log(output);
VBlankIntrWait();