summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavi Del Campo <xavi.dcr@tutanota.com>2020-03-03 20:07:27 +0100
committerXavi Del Campo <xavi.dcr@tutanota.com>2020-03-05 18:38:04 +0100
commite32281cf6b01800f95d7640a127811c79234fe6f (patch)
treef34d870bfdfa425600aead8cbf9aadcbc71d4fbc /src
parent792e22676786a577b2edc0ed0ed78e51c5b38245 (diff)
downloadopensend-e32281cf6b01800f95d7640a127811c79234fe6f.tar.gz
Work on SIO IRQ
Diffstat (limited to 'src')
-rw-r--r--src/Font.c18
-rw-r--r--src/Gfx.c46
-rw-r--r--src/IO.c2
-rw-r--r--src/LoadMenu.c204
-rw-r--r--src/Serial.c73
-rw-r--r--src/System.c5
-rw-r--r--src/main.c10
-rw-r--r--src/sio.s94
8 files changed, 165 insertions, 287 deletions
diff --git a/src/Font.c b/src/Font.c
index d8d1e9e..d70125c 100644
--- a/src/Font.c
+++ b/src/Font.c
@@ -3,6 +3,12 @@
* *************************************/
#include "Font.h"
+#include "Gfx.h"
+#include <psxgpu.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
/* *************************************
* Defines
@@ -21,7 +27,7 @@
static char _internal_text[FONT_INTERNAL_TEXT_BUFFER_MAX_SIZE];
static unsigned char _blend_effect_lum;
-bool FontLoadImage(char *path, struct font *font)
+bool FontLoadImage(const char *const path, struct font *const font)
{
if (GfxSpriteFromFile(path, &font->spr) == false)
{
@@ -55,8 +61,6 @@ bool FontLoadImage(char *path, struct font *font)
font->init_ch = FONT_DEFAULT_INIT_CHAR;
- dprintf("Sprite CX = %d, sprite CY = %d\n",font->spr.cx, font->spr.cy);
-
return true;
}
@@ -168,14 +172,6 @@ void FontPrintText(struct font *font, short x, short y, char* str, ...)
font->spr.g = NORMAL_LUMINANCE;
font->spr.b = NORMAL_LUMINANCE;
}
- /*dprintf("char_w = %d, char_h = %d, char_per_row = %d, init_ch: %c\n",
- font->char_w,
- font->char_h,
- font->char_per_row,
- font->init_ch);
- dprintf("Char: %c, spr.u = %d, spr.v = %d\n",str[i],font->spr.u, font->spr.v);
- dprintf("Sprite CX = %d, sprite CY = %d\n",font->spr.cx, font->spr.cy);*/
- /* dprintf("Sprite rgb={%d,%d,%d}\n",font->spr.r, font->spr.g, font->spr.b); */
GfxSortSprite(&font->spr);
x += font->char_spacing;
diff --git a/src/Gfx.c b/src/Gfx.c
index 49f0f12..60fa4bd 100644
--- a/src/Gfx.c
+++ b/src/Gfx.c
@@ -1,17 +1,3 @@
-/*******************************************************************//**
-*
-* \file Gfx.c
-*
-* \author Xavier Del Campo
-*
-* \brief Implementation of Gfx module.
-*
-************************************************************************/
-
-/* *************************************
- * Includes
- * *************************************/
-
#include "Gfx.h"
#include "IO.h"
#include <psx.h>
@@ -22,22 +8,6 @@
#include <stdio.h>
#include <stdint.h>
-/* *************************************
- * Defines
- * *************************************/
-
-/* *****************************************************************************
- * Types definition
- * ****************************************************************************/
-
-/* *****************************************************************************
- * Global variables definition
- * ****************************************************************************/
-
-/* *****************************************************************************
- * Local variables definition
- * ****************************************************************************/
-
/* The drawing environment points to VRAM
* coordinates where primitive data is
* being drawn onto. */
@@ -51,10 +21,6 @@ static GsDispEnv sDispEnv;
/* This variable is set to true on VSYNC event. */
static volatile bool bSyncFlag;
-/* *****************************************************************************
- * Local prototypes declaration
- * ****************************************************************************/
-
static void GfxInitDrawEnv(void);
static void GfxInitDispEnv(void);
static void GfxSwapBuffers(void);
@@ -62,10 +28,6 @@ static void GfxSortBigSprite(GsSprite *const psSpr);
static void GfxSetPrimList(void);
static void ISR_VBlank(void);
-/* *****************************************************************************
- * Functions definition
- * ****************************************************************************/
-
/***************************************************************************//**
*
* \brief Initialization of Gfx module.
@@ -498,10 +460,10 @@ void GfxSaveDisplayData(GsSprite *const spr)
GFX_SECOND_DISPLAY_U = GFX_SECOND_DISPLAY_X % GFX_TPAGE_WIDTH
};
- while (GfxIsGPUBusy());
+ while (GfxIsBusy());
- MoveImage( DispEnv.x,
- DispEnv.y,
+ MoveImage( sDispEnv.x,
+ sDispEnv.y,
GFX_SECOND_DISPLAY_X,
GFX_SECOND_DISPLAY_Y,
X_SCREEN_RESOLUTION,
@@ -519,5 +481,5 @@ void GfxSaveDisplayData(GsSprite *const spr)
spr->g = NORMAL_LUMINANCE;
spr->b = NORMAL_LUMINANCE;
- while (GfxIsGPUBusy());
+ while (GfxIsBusy());
}
diff --git a/src/IO.c b/src/IO.c
index 401971b..a50c9bf 100644
--- a/src/IO.c
+++ b/src/IO.c
@@ -115,7 +115,7 @@ static const uint8_t *IOLoadFileFromCd(char* const buffer, size_t* const fileSiz
{
/* Buffer cannot hold such amount of data.
* Fall through. */
- printf("%s does not fit into internal buffer (%ld / %ld bytes)\n",
+ printf("%s does not fit into internal buffer (%u / %u bytes)\n",
buffer, *fileSize, FILE_BUFFER_SIZE);
}
diff --git a/src/LoadMenu.c b/src/LoadMenu.c
deleted file mode 100644
index ffc3f3a..0000000
--- a/src/LoadMenu.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/* **************************************
- * Includes *
- * *************************************/
-
-#include "LoadMenu.h"
-
-/* **************************************
- * Defines *
- * *************************************/
-
-/* **************************************
- * Structs and enums *
- * *************************************/
-
-enum
-{
- SMALL_FONT_SIZE = 8,
- SMALL_FONT_SIZE_BITSHIFT = 3,
- SMALL_FONT_SPACING = 6
-};
-
-enum
-{
- BG_BLUE_TARGET_VALUE = 0xC0,
- BG_WHITE_TARGET_VALUE = /*0x40*/ 0,
- BG_INCREASE_STEP = 0x10
-};
-
-enum
-{
- LOADING_BAR_X = 64,
- LOADING_BAR_Y = 200,
- LOADING_BAR_N_LINES = 4,
-
- LOADING_BAR_WIDTH = 256,
- LOADING_BAR_HEIGHT = 16,
-
- LOADING_BAR_LUMINANCE_TARGET = NORMAL_LUMINANCE,
- LOADING_BAR_LUMINANCE_STEP = 10
-};
-
-enum
-{
- LOADING_TITLE_CLUT_X = 384,
- LOADING_TITLE_CLUT_Y = 496,
- LOADING_TITLE_X = 128,
- LOADING_TITLE_Y = 32,
-
- LOADING_TITLE_U = 0,
- LOADING_TITLE_V = 0,
-
- LOADING_TITLE_LUMINANCE_STEP = 10,
- LOADING_TITLE_LUMINANCE_TARGET = NORMAL_LUMINANCE
-};
-
-enum
-{
- PLANE_START_X = 56,
- PLANE_START_Y = 200,
-
- PLANE_U = 0,
- PLANE_V = 32,
- PLANE_SIZE = 16,
-
- PLANE_LUMINANCE_STEP = 0x10,
- PLANE_LUMINANCE_TARGET_VALUE = NORMAL_LUMINANCE
-};
-
-/* *************************************
- * Local Prototypes
- * *************************************/
-
-static void LoadMenuLoadFileList( char* fileList[], void * dest[],
- uint8_t szFileList, uint8_t szDestList);
-
-/* *************************************
- * Local Variables
- * *************************************/
-
-static char* LoadMenuFiles[] = { "cdrom:\\DATA\\FONTS\\FONT_2.FNT;1" };
-
-static void * LoadMenuDest[] = { (struct font*)&SmallFont };
-
-static char* strCurrentFile;
-
-/* Flags to communicate with ISR state */
-/* * startup_flag: background fades in from black to blue. */
-/* * end_flag: tells the background to fade out to black. */
-/* * isr_ended: background has totally faded out to black. */
-/* * isr_started: tells the ISR has finished starting up. */
-static volatile bool startup_flag;
-static volatile bool isr_started;
-static volatile bool end_flag;
-static volatile bool isr_ended;
-/* Set to true when LoadMenuInit() has been called, and set to false */
-/* once LoadMenuEnd() is called. */
-/* It's used when multiple modules call LoadMenu() at the same time, */
-/* so load menu does not have to be initialised each time; */
-static bool load_menu_running;
-
-void LoadMenuInit(void)
-{
- static bool first_load = false;
-
- if (first_load == false)
- {
- first_load = true;
- LoadMenuLoadFileList( LoadMenuFiles,
- LoadMenuDest,
- sizeof(LoadMenuFiles) / sizeof(char*),
- sizeof(LoadMenuDest) / sizeof(void*));
- }
-
- FontSetSize(&SmallFont, SMALL_FONT_SIZE, SMALL_FONT_SIZE_BITSHIFT);
- FontSetSpacing(&SmallFont, SMALL_FONT_SPACING);
-
- SmallFont.spr.r = 0;
- SmallFont.spr.g = 0;
- SmallFont.spr.b = 0;
-
- GfxSetGlobalLuminance(NORMAL_LUMINANCE);
-}
-
-void LoadMenu( char* fileList[],
- void * dest[],
- uint8_t szFileList , uint8_t szDestList)
-{
-
- if (load_menu_running == false)
- {
- LoadMenuInit();
- }
-
- LoadMenuLoadFileList(fileList,dest,szFileList,szDestList);
-}
-
-void LoadMenuLoadFileList( char* fileList[], void * dest[],
- uint8_t szFileList, uint8_t szDestList)
-{
- char aux_file_name[100];
- char* extension;
- uint8_t fileLoadedCount;
-
- if (szFileList != szDestList)
- {
- dprintf("File list size different from dest list size! %d vs %d\n",
- szFileList, szDestList);
- return;
- }
-
- for (fileLoadedCount = 0; fileLoadedCount < szFileList ; fileLoadedCount++)
- {
- if (fileList[fileLoadedCount] == NULL)
- {
- continue;
- }
-
- strCurrentFile = fileList[fileLoadedCount];
-
- /* dprintf("Files %d / %d loaded. New plane X = %d.\n",fileLoadedCount,szFileList,LoadMenuPlaneSpr.x); */
-
- /* Backup original file path */
- strncpy(aux_file_name,fileList[fileLoadedCount],100);
-
- /* We want to get file extension, so split into tokens */
- strtok(fileList[fileLoadedCount],".;");
- extension = strtok(NULL,".;");
-
- dprintf("File extension: .%s\n",extension);
- /* Restore original file path in order to load file */
- strncpy(fileList[fileLoadedCount],aux_file_name,100);
-
- if (strncmp(extension,"TIM",3) == 0)
- {
- if (GfxSpriteFromFile(fileList[fileLoadedCount], dest[fileLoadedCount]) == false)
- {
- dprintf("Could not load image file \"%s\"!\n",fileList[fileLoadedCount]);
- }
- }
- else if (strncmp(extension,"CLT",3) == 0)
- {
- if (dest[fileLoadedCount] != NULL)
- {
- dprintf("WARNING: File %s linked to non-NULL destination pointer!\n", dest[fileLoadedCount]);
- }
-
- if (GfxCLUTFromFile(fileList[fileLoadedCount]) == false)
- {
- dprintf("Could not load CLUT file \"%s\"!\n",fileList[fileLoadedCount]);
- }
- }
- else if (strncmp(extension,"FNT",3) == 0)
- {
- if (FontLoadImage(fileList[fileLoadedCount], dest[fileLoadedCount]) == false)
- {
- dprintf("Could not load font file \"%s\"!\n",fileList[fileLoadedCount]);
- }
- }
- else
- {
- dprintf("LoadMenu does not recognize following extension: %s\n",extension);
- }
- }
-}
diff --git a/src/Serial.c b/src/Serial.c
index 4bfb45c..f0c092e 100644
--- a/src/Serial.c
+++ b/src/Serial.c
@@ -1,38 +1,57 @@
-/* *************************************
- * Includes
- * *************************************/
-
#include "Serial.h"
#include "Interrupts.h"
#include <psxsio.h>
#include <stdarg.h>
#include <stdio.h>
+#include <psxbios.h>
+#include <psx.h>
+#include <stddef.h>
+
+static volatile size_t isr_calls;
+
+void sio_handler_callback(void)
+{
+ printf("%s\n", __func__);
+ isr_calls++;
+}
-/* *************************************
- * Defines
- * *************************************/
+void SerialInit(void)
+{
+ int *sio_handler(void);
-#define SERIAL_BAUDRATE 115200
-#define SERIAL_TX_RX_TIMEOUT 20000
-#define SERIAL_RX_FIFO_EMPTY 0
-#define SERIAL_TX_NOT_READY 0
-#define SERIAL_PRINTF_INTERNAL_BUFFER_SIZE 256
+ enum
+ {
+ SIO_CLASS = 0xF000000B
+ };
-/* **************************************
- * Structs and enums *
- * *************************************/
+ EnterCriticalSection();
-/* *************************************
- * Local Variables
- * *************************************/
+ IMASK |= 1 << 8;
-/* *************************************
- * Local Prototypes
- * *************************************/
+ const int sio_handle = OpenEvent(SIO_CLASS, 0x1000, 0x1000, sio_handler);
-void SerialInit(void)
-{
- SIOStart(115200);
+ if (sio_handle != 0xFFFFFFFF)
+ {
+ enum
+ {
+ BAUD_RATE = 115200
+ };
+
+ EnableEvent(sio_handle);
+ SIOStart(BAUD_RATE);
+ redirect_stdio_to_sio();
+ printf("sio_handle = 0x%08X", sio_handle);
+ }
+
+ ExitCriticalSection();
+
+ SIOSendByte('y');
+
+ printf("%u\n", isr_calls);
+
+ while (!(IPENDING & (1 << 8)));
+
+ printf("SIO ISR triggered\n");
}
void SerialRead(uint8_t *ptrArray, size_t nBytes)
@@ -43,7 +62,8 @@ void SerialRead(uint8_t *ptrArray, size_t nBytes)
do
{
- while ( (SIOCheckInBuffer() == SERIAL_RX_FIFO_EMPTY)); // Wait for RX FIFO not empty
+ /* Wait for RX FIFO not empty. */
+ while (!SIOCheckInBuffer());
*(ptrArray++) = SIOReadByte();
} while (--nBytes);
@@ -59,7 +79,8 @@ void SerialWrite(const void* ptrArray, size_t nBytes)
InterruptsDisableInt(INT_SOURCE_VBLANK);
do
{
- while ( (SIOCheckOutBuffer() == SERIAL_TX_NOT_READY)); // Wait for TX FIFO empty.
+ /* Wait for TX FIFO empty. */
+ while (!SIOCheckOutBuffer());
SIOSendByte(*(uint8_t*)ptrArray++);
diff --git a/src/System.c b/src/System.c
index d7a1574..9a48d30 100644
--- a/src/System.c
+++ b/src/System.c
@@ -2,10 +2,15 @@
#include "Serial.h"
#include "Gfx.h"
#include <psx.h>
+#include <stdio.h>
void SystemInit(void)
{
+#if 0
PSX_InitEx(PSX_INIT_SAVESTATE | PSX_INIT_CD);
+#else
+ PSX_InitEx(0);
+#endif
SerialInit();
GfxInit();
}
diff --git a/src/main.c b/src/main.c
index 4e357a2..400468e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,12 +1,16 @@
+#include "System.h"
+#include <stdio.h>
+
#define PSX_EXE_HEADER_SIZE 2048
#define EXE_DATA_PACKET_SIZE 8
-void _start(void);
-
int main(void)
{
SystemInit();
+ for (;;);
+
+#if 0
{
uint32_t initPC_Address;
uint32_t RAMDest_Address;
@@ -117,6 +121,6 @@ int main(void)
exeAddress();
}
-
+#endif
return 0;
}
diff --git a/src/sio.s b/src/sio.s
new file mode 100644
index 0000000..7e4d887
--- /dev/null
+++ b/src/sio.s
@@ -0,0 +1,94 @@
+.extern sio_handler_callback
+.extern sio_handler
+
+sio_handler:
+ addi $sp, -120
+.set noat
+ sw $at, 0($sp)
+ mfhi $at
+ sw $at, 112($sp)
+ mflo $at
+ sw $at, 116($sp)
+.set at
+ sw $v0, 4($sp)
+ sw $v1, 8($sp)
+ sw $a0, 12($sp)
+ sw $a1, 16($sp)
+ sw $a2, 20($sp)
+ sw $a3, 24($sp)
+ sw $t0, 28($sp)
+ sw $t1, 32($sp)
+ sw $t2, 36($sp)
+ sw $t3, 40($sp)
+ sw $t4, 44($sp)
+ sw $t5, 48($sp)
+ sw $t6, 52($sp)
+ sw $t7, 56($sp)
+ sw $s0, 60($sp)
+ sw $s1, 64($sp)
+ sw $s2, 68($sp)
+ sw $s3, 72($sp)
+ sw $s4, 76($sp)
+ sw $s5, 80($sp)
+ sw $s6, 84($sp)
+ sw $s7, 88($sp)
+ sw $t8, 92($sp)
+ sw $t9, 96($sp)
+ sw $gp, 100($sp)
+ sw $s8, 104($sp)
+
+ la $t0, sio_handler_callback
+ lw $t1, 0($t0)
+
+ addiu $sp, $sp, -24
+ jalr $t1
+ nop
+ addiu $sp, $sp, 24
+
+ li $t0, 0x1f801070 # IPENDING
+
+ lw $t1, 0($t0)
+ nop
+ nop
+ xori $t1, $t1, 0x100 # Acknowledge SIO IRQ
+ sw $t1, 0($t0)
+
+.set noat
+ lw $at, 112($sp)
+ nop
+ mthi $at
+ lw $at, 116($sp)
+ nop
+ mtlo $at
+ lw $at, 0($sp)
+.set at
+ lw $v0, 4($sp)
+ lw $v1, 8($sp)
+ lw $a0, 12($sp)
+ lw $a1, 16($sp)
+ lw $a2, 20($sp)
+ lw $a3, 24($sp)
+ lw $t0, 28($sp)
+ lw $t1, 32($sp)
+ lw $t2, 36($sp)
+ lw $t3, 40($sp)
+ lw $t4, 44($sp)
+ lw $t5, 48($sp)
+ lw $t6, 52($sp)
+ lw $t7, 56($sp)
+ lw $s0, 60($sp)
+ lw $s1, 64($sp)
+ lw $s2, 68($sp)
+ lw $s3, 72($sp)
+ lw $s4, 76($sp)
+ lw $s5, 80($sp)
+ lw $s6, 84($sp)
+ lw $s7, 88($sp)
+ lw $t8, 92($sp)
+ lw $t9, 96($sp)
+ lw $gp, 100($sp)
+ lw $s8, 104($sp)
+ lw $ra, 108($sp)
+ addi $sp, 120
+ jr $ra
+ nop