summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorXavi Del Campo <xavi.dcr@tutanota.com>2020-03-03 18:39:09 +0100
committerXavi Del Campo <xavi.dcr@tutanota.com>2020-03-03 19:40:00 +0100
commit792e22676786a577b2edc0ed0ed78e51c5b38245 (patch)
tree3a5b1092af322003be3189bf6d58f362dcfe1dca /include
parent62adc2edd17cbd39272715d29d1b4c8650ef7dde (diff)
downloadopensend-792e22676786a577b2edc0ed0ed78e51c5b38245.tar.gz
Refactoring
Diffstat (limited to 'include')
-rw-r--r--include/EndAnimation.h25
-rw-r--r--include/Font.h78
-rw-r--r--include/GameStructures.h57
-rw-r--r--include/Gfx.h133
-rw-r--r--include/Global_Inc.h41
-rw-r--r--include/IO.h50
-rw-r--r--include/Interrupts.h68
-rw-r--r--include/LoadMenu.h19
-rw-r--r--include/Serial.h58
-rw-r--r--include/System.h118
10 files changed, 237 insertions, 410 deletions
diff --git a/include/EndAnimation.h b/include/EndAnimation.h
deleted file mode 100644
index edb7b07..0000000
--- a/include/EndAnimation.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef __END_SCREEN_HEADER__
-#define __END_SCREEN_HEADER__
-
-/* **************************************
- * Includes *
- * **************************************/
-
-#include "Global_Inc.h"
-#include "Gfx.h"
-
-/* **************************************
- * Defines *
- * **************************************/
-
-/* **************************************
- * Global Prototypes *
- * **************************************/
-
-void EndAnimation(void);
-
-/* **************************************
- * Global Variables *
- * **************************************/
-
-#endif // __END_SCREEN_HEADER__
diff --git a/include/Font.h b/include/Font.h
index 5a7d6b5..97a52ac 100644
--- a/include/Font.h
+++ b/include/Font.h
@@ -1,44 +1,60 @@
-#ifndef __FONT_HEADER__
-#define __FONT_HEADER__
+#ifndef FONT_H
+#define FONT_H
/* *************************************
* Includes
* *************************************/
-#include "Global_Inc.h"
-#include "System.h"
-#include "Gfx.h"
-#include "GameStructures.h"
#include <stdarg.h>
-
-/* *************************************
- * Defines
- * *************************************/
-
-#define FONT_DEFAULT_CHAR_SIZE 16
-#define FONT_DEFAULT_INIT_CHAR '!'
-
-/* **************************************
- * Structs and enums *
- * *************************************/
-
-/* *************************************
- * Global prototypes
- * *************************************/
-
-bool FontLoadImage(char* strPath, TYPE_FONT * ptrFont);
-void FontSetSize(TYPE_FONT * ptrFont, short size, short bitshift);
-void FontPrintText(TYPE_FONT *ptrFont, short x, short y, char* str, ...);
-void FontSetInitChar(TYPE_FONT * ptrFont, char c);
-void FontSetFlags(TYPE_FONT * ptrFont, FONT_FLAGS flags);
+#include <stdbool.h>
+
+enum
+{
+ FONT_DEFAULT_CHAR_SIZE = 16,
+ FONT_DEFAULT_INIT_CHAR = '!'
+};
+
+enum t_fontflags
+{
+ FONT_NOFLAGS,
+ FONT_CENTERED = 0x01,
+ FONT_WRAP_LINE = 0x02,
+ FONT_BLEND_EFFECT = 0x04,
+ FONT_1HZ_FLASH = 0x08,
+ FONT_2HZ_FLASH = 0x10,
+ FONT_H_CENTERED = 0x20
+};
+
+struct font
+{
+ GsSprite spr;
+ short char_spacing;
+ short char_w;
+ short char_w_bitshift;
+ short char_h;
+ char init_ch;
+ uint8_t char_per_row;
+ uint8_t max_ch_wrap;
+ enum font_flags flags;
+ short spr_w;
+ short spr_h;
+ short spr_u;
+ short spr_v;
+};
+
+bool FontLoadImage(const char *path, struct font *font);
+void FontSetSize(struct font *font, short size, short bitshift);
+void FontPrintText(struct font *font, short x, short y, char* str, ...);
+void FontSetInitChar(struct font *font, char c);
+void FontSetFlags(struct font *font, enum font_flags flags);
void FontCyclic(void);
-void FontSetSpacing(TYPE_FONT* ptrFont, short spacing);
+void FontSetSpacing(struct font *font, short spacing);
/* *************************************
* Global variables
* *************************************/
-TYPE_FONT RadioFont;
-TYPE_FONT SmallFont;
+extern struct font RadioFont;
+extern struct font SmallFont;
-#endif //__FONT_HEADER__
+#endif /* FONT_H */
diff --git a/include/GameStructures.h b/include/GameStructures.h
deleted file mode 100644
index e092e1d..0000000
--- a/include/GameStructures.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef __GAME_STRUCTURES__HEADER__
-#define __GAME_STRUCTURES__HEADER__
-
-/* *************************************
- * Defines
- * *************************************/
-
-#define CHEAT_ARRAY_SIZE 16
-
-/* *************************************
- * Structs and enums
- * *************************************/
-
-typedef enum t_fontflags
-{
- FONT_NOFLAGS = 0,
- FONT_CENTERED = 0x01,
- FONT_WRAP_LINE = 0x02,
- FONT_BLEND_EFFECT = 0x04,
- FONT_1HZ_FLASH = 0x08,
- FONT_2HZ_FLASH = 0x10,
- FONT_H_CENTERED = 0x20
-}FONT_FLAGS;
-
-typedef struct t_Font
-{
- GsSprite spr;
- short char_spacing;
- short char_w;
- short char_w_bitshift;
- short char_h;
- char init_ch;
- uint8_t char_per_row;
- uint8_t max_ch_wrap;
- FONT_FLAGS flags;
- short spr_w;
- short spr_h;
- short spr_u;
- short spr_v;
-}TYPE_FONT;
-
-typedef struct t_Timer
-{
- uint32_t time;
- uint32_t orig_time;
- bool repeat_flag;
- bool busy;
- void (*Timeout_Callback)(void);
-}TYPE_TIMER;
-
-typedef struct t_Cheat
-{
- unsigned short Combination[CHEAT_ARRAY_SIZE];
- void (*Callback)(void);
-}TYPE_CHEAT;
-
-#endif // __GAME_STRUCTURES__HEADER__
diff --git a/include/Gfx.h b/include/Gfx.h
index b2b8295..9f1ec03 100644
--- a/include/Gfx.h
+++ b/include/Gfx.h
@@ -1,109 +1,58 @@
-#ifndef __GFX_HEADER__
-#define __GFX_HEADER__
+#ifndef GFX_H
+#define GFX_H
-/* *************************************
- * Includes
- * *************************************/
+#include <psxgpu.h>
+#include <stdbool.h>
-#include "Global_Inc.h"
-#include "System.h"
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+#define SPRITE_INDEX_INVALID (size_t)(0xFFFFFFFF)
+#define MAX_SIZE_FOR_GSSPRITE ((short)256)
+enum
+{
+ GFX_TPAGE_WIDTH = 64,
+ GFX_TPAGE_WIDTH_BITSHIFT = __builtin_ctz(GFX_TPAGE_WIDTH)
+};
/* *************************************
- * Defines
+ * Public types definition
* *************************************/
-#define X_SCREEN_RESOLUTION 384
-#define Y_SCREEN_RESOLUTION 240
-#define VRAM_W 1024
-#define VRAM_H 512
-#define MAX_SIZE_FOR_GSSPRITE 256
-#define GFX_TPAGE_WIDTH 64
-#define GFX_TPAGE_HEIGHT 256
-#define GFX_1HZ_FLASH (1<<7)
-#define GFX_2HZ_FLASH (1<<8)
-#define FULL_LUMINANCE 0xFF
+enum
+{
+ X_SCREEN_RESOLUTION = 368,
+ Y_SCREEN_RESOLUTION = 240
+};
/* *************************************
- * Global prototypes
+ * Public variables declaration
* *************************************/
-void GfxInitDrawEnv(void);
-void GfxInitDispEnv(void);
-void GfxSetPrimitiveList(void);
-
-// Renders new scene. Use this function unless you know what you are doing!
-void GfxDrawScene(void);
-
-// Blocking version. Calls GfxDrawScene() and then adds a while(GfxIsBusy() )
-// after it.
-void GfxDrawScene_Slow(void);
-
-void GfxDrawScene_NoSwap(void);
-
-void GfxSwapBuffers(void);
-
-// Only renders screen and does not update any pad data or timer data.
-// To be used in ISR!
-void GfxDrawScene_Fast(void);
-
-// Repotedly, tells is GPU is ready for a DMA transfer.
-bool GfxReadyForDMATransfer(void);
-
-// Fills a GsSprite structure with information from a TIM file.
-bool GfxSpriteFromFile(char* fname, GsSprite * spr);
-
-// Reportedly, loads CLUT data from a TIM image (image data is discarded)
-bool GfxCLUTFromFile(char* fname);
+/* *************************************
+ * Public functions declaration
+ * *************************************/
-// Returns true if current object is within screen limits, false otherwise.
+void GfxInit(void);
+bool GfxSpriteFromFile(const char* path, GsSprite *spr);
+void GfxSortSprite(GsSprite *spr);
bool GfxIsInsideScreenArea(short x, short y, short w, short h);
+bool GfxIsSpriteInsideScreenArea(const GsSprite *spr);
+void GfxDrawScene(void);
+void GfxClear(void);
+int GfxToDegrees(int rotate);
+int GfxFromDegrees(int degrees);
+bool GfxIsBusy(void);
+void GfxDrawRectangle(GsRectangle *rect);
+void GfxSaveDisplayData(GsSprite *const spr);
-// Function overload for GsSprite structures.
-bool GfxIsSpriteInsideScreenArea(GsSprite * spr);
-
-// Used to know whether GPU operation can be done.
-bool GfxIsGPUBusy(void);
-
-// Draws a sprite on screen. First, it checks whether sprite is inside
-// screen limits.
-void GfxSortSprite(GsSprite * spr);
-
-uint8_t GfxGetGlobalLuminance(void);
-
-void GfxSetGlobalLuminance(uint8_t value);
-
-void GfxIncreaseGlobalLuminance(int8_t step);
-
-void GfxButtonSetFlags(uint8_t flags);
-
-void GfxButtonRemoveFlags(uint8_t flags);
-
-int GfxRotateFromDegrees(int deg);
-
-void GfxDrawButton(short x, short y, unsigned short btn);
-
-// Sends current display data on a specific VRAM section and fills
-// sprite structure pointed to by "spr".
-void GfxSaveDisplayData(GsSprite *spr);
-
-// Fills GsSprite structure pointed to by "spr" with texture page and U/V
-// offset data given a position in VRAM.
-bool GfxTPageOffsetFromVRAMPosition(GsSprite * spr, short x, short y);
-
-void GfxSetSplitScreen(uint8_t playerIndex);
-
-void GfxDisableSplitScreen(void);
-
-void GfxDrawScene_NoSwap(void);
-
-void GfxDevMenuEnable(void);
-
-/* *************************************
- * Global variables
- * *************************************/
+/** \} */
-extern GsSprite PSXButtons;
+#ifdef __cplusplus
+}
+#endif
-#endif //__GFX_HEADER__
+#endif /* GFX_H */
diff --git a/include/Global_Inc.h b/include/Global_Inc.h
deleted file mode 100644
index 0c8f446..0000000
--- a/include/Global_Inc.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef __GLOBAL_INC__H__
-#define __GLOBAL_INC__H__
-
-/* *************************************
- * Includes
- * *************************************/
-
-#include <psx.h>
-#include <stdio.h>
-#include <psxsio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <types.h>
-#include <fixmath.h>
-#include <runexe.h>
-
-/* *************************************
- * Defines
- * *************************************/
-
-#define REFRESH_FREQUENCY 50 //50 Hz PAL / 60 Hz NTSC
-#define DEBUG_PRINT_VAR(var) dprintf(#var " = %d\n", var);
-
-#ifndef bool
- typedef enum
- {
- false = 0,
- true = 1
- }bool;
-#endif
-
-#if (PSXSDK_VERSION != 0x0599)
-#error "Wrong PSXSDK version! Please use version 0.5.99."
-#endif
-
-/* Test for GCC > 5.2.0 */
-#if ( (__GNUC__ != 5) || (__GNUC_MINOR__ != 2) || (__GNUC_PATCHLEVEL__ != 0) )
-#error "Wrong GCC version! Please use version 5.2.0."
-#endif
-
-#endif // __GLOBAL_INC__H__
diff --git a/include/IO.h b/include/IO.h
new file mode 100644
index 0000000..4a6343d
--- /dev/null
+++ b/include/IO.h
@@ -0,0 +1,50 @@
+#ifndef IO_H
+#define IO_H
+
+/*******************************************************************//**
+*
+* \file IO.h
+*
+* \author Xavier Del Campo
+*
+* \brief Include file for IO module.
+*
+************************************************************************/
+
+/* *************************************
+ * Includes
+ * *************************************/
+
+#include <stdint.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* *************************************
+ * Defines
+ * *************************************/
+
+#define IO_INVALID_FILE_SIZE (size_t)(-1)
+
+/* *************************************
+ * Public types definition
+ * *************************************/
+
+/* *************************************
+ * Public variables declaration
+ * *************************************/
+
+/* *************************************
+ * Public functions declaration
+ * *************************************/
+
+const uint8_t *IOLoadFile(const char* const strFilePath, size_t* const fileSize);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* IO_H */
diff --git a/include/Interrupts.h b/include/Interrupts.h
new file mode 100644
index 0000000..e06e1e3
--- /dev/null
+++ b/include/Interrupts.h
@@ -0,0 +1,68 @@
+#ifndef INTERRUPTS_H
+#define INTERRUPTS_H
+
+/*******************************************************************//**
+*
+* @file Interrupts.h
+*
+* @author Xavier Del Campo
+*
+* @brief Include file for Interrupts module.
+*
+************************************************************************/
+
+/* *************************************
+ * Includes
+ * *************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* *************************************
+ * Defines
+ * *************************************/
+
+/* *************************************
+ * Public types definition
+ * *************************************/
+
+/*******************************************************************//**
+*
+* \brief List of HW interrupt sources.
+*
+************************************************************************/
+enum InterruptSource
+{
+ INT_SOURCE_VBLANK,
+ INT_SOURCE_GPU,
+ INT_SOURCE_CDROM,
+ INT_SOURCE_DMA,
+ INT_SOURCE_RCNT0,
+ INT_SOURCE_RCNT1,
+ INT_SOURCE_RCNT2,
+ INT_CONTROLLER_MEMCARD_BYTE_RECEIVED,
+ INT_SIO,
+ INT_SPU,
+ INT_CONTROLLER_LIGHTPEN_PIO,
+
+ MAX_INTERRUPT_SOURCES
+};
+
+/* *************************************
+ * Public variables declaration
+ * *************************************/
+
+/* *************************************
+ * Public functions declaration
+ * *************************************/
+
+void InterruptsEnableInt(const enum InterruptSource intSource);
+void InterruptsDisableInt(const enum InterruptSource intSource);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INTERRUPTS_H */
diff --git a/include/LoadMenu.h b/include/LoadMenu.h
index 8afc373..881eb01 100644
--- a/include/LoadMenu.h
+++ b/include/LoadMenu.h
@@ -1,14 +1,11 @@
-#ifndef __LOAD_MENU_HEADER__
-#define __LOAD_MENU_HEADER__
+#ifndef LOAD_MENU_H
+#define LOAD_MENU_H
/* *************************************
* Includes
* *************************************/
-#include "Global_Inc.h"
-#include "Gfx.h"
-#include "System.h"
-#include "Font.h"
+#include <stdint.h>
/* *************************************
* Defines
@@ -20,10 +17,10 @@
void LoadMenuInit(void);
-void LoadMenu( char* fileList[],
- void * dest[],
- uint8_t szFileList , uint8_t szDestList);
-
+void LoadMenu( const char *const *fileList,
+ void *const *dest,
+ uint8_t szFileList, uint8_t szDestList);
+
void LoadMenuEnd(void);
-#endif //__LOAD_MENU_HEADER__
+#endif /* LOAD_MENU_H */
diff --git a/include/Serial.h b/include/Serial.h
index da2c4ce..88e50db 100644
--- a/include/Serial.h
+++ b/include/Serial.h
@@ -1,49 +1,31 @@
-#ifndef __SERIAL_HEADER__
-#define __SERIAL_HEADER__
+#ifndef SERIAL_H
+#define SERIAL_H
/* *************************************
- * Includes
+ * Includes
* *************************************/
-#include "Global_Inc.h"
-#include "System.h"
-#include "Gfx.h"
-#include "Font.h"
+#include <stdint.h>
+#include <stddef.h>
-/* *************************************
- * Defines
- * *************************************/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+#define SERIAL_DATA_PACKET_SIZE 8
#define ACK_BYTE_STRING "b"
-/* **************************************
- * Structs and enums *
- * *************************************/
+void SerialInit(void);
+void SerialRead(uint8_t *ptrArray, size_t nBytes);
+void SerialWrite(const void* ptrArray, size_t nBytes);
-typedef enum
-{
- SERIAL_STATE_INIT = 0,
- SERIAL_STATE_STANDBY,
- SERIAL_STATE_WRITING_ACK,
- SERIAL_STATE_READING_HEADER,
- SERIAL_STATE_READING_EXE_SIZE,
- SERIAL_STATE_READING_EXE_DATA,
- SERIAL_STATE_WAITING_USER_INPUT,
- SERIAL_STATE_CLEANING_MEMORY,
-}SERIAL_STATE;
+#ifdef SERIAL_INTERFACE
+void Serial_printf(const char* str, ...);
+#endif // SERIAL_INTERFACE
-/* *************************************
- * Global prototypes
- * *************************************/
+#ifdef __cplusplus
+}
+#endif
-void SerialInit(void);
-bool SerialRead(uint8_t* ptrArray, size_t nBytes);
-bool SerialWrite(void* ptrArray, size_t nBytes);
-void ISR_Serial(void);
-void SerialSetState(SERIAL_STATE state);
-void SerialSetPCAddress(uint32_t addr);
-void SerialSetRAMDestAddress(uint32_t addr);
-void SerialSetExeSize(size_t size);
-void SerialSetExeBytesReceived(uint32_t bytes_read);
-
-#endif // __SERIAL_HEADER__
+#endif /* SERIAL_H */
diff --git a/include/System.h b/include/System.h
index 2994366..028a840 100644
--- a/include/System.h
+++ b/include/System.h
@@ -1,118 +1,6 @@
-#ifndef __SYSTEM_HEADER__
-#define __SYSTEM_HEADER__
+#ifndef SYSTEM_H
+#define SYSTEM_H
-/* **************************************
- * Includes *
- * **************************************/
-
-#include "Global_Inc.h"
-#include "Gfx.h"
-#include "Serial.h"
-
-/* **************************************
- * Defines *
- * **************************************/
-
-#define TIMER_PRESCALER_1_SECOND 10
-#define TIMER_PRESCALER_1_MINUTE (TIMER_PRESCALER_1_SECOND * 60)
-
-/* **************************************
- * Global Prototypes *
- * **************************************/
-
-// Calls PSXSDK init routines
void SystemInit(void);
-// Sets default VSync (only sets flag to true and increases global_timer)
-void ISR_SystemDefaultVBlank(void);
-
-void SystemSetBusyFlag(bool value);
-
-// Calls srand() using current global_timer value as seed
-void SystemSetRandSeed(void);
-
-// Returns VSync flag value
-bool SystemRefreshNeeded(void);
-
-// Loads a file into system's internal buffer
-bool SystemLoadFile(char*fname);
-
-// Loads a file into desired buffer
-bool SystemLoadFileToBuffer(char* fname, uint32_t init_pos, uint8_t* buffer, uint32_t szBuffer);
-
-// Clears VSync flag after each frame
-void SystemDisableScreenRefresh(void);
-
-// Returns file buffer address
-uint8_t* SystemGetBufferAddress(void);
-
-// Tells whether srand() has been called using a pseudo-random value
-bool SystemIsRandSeedSet(void);
-
-// Stops program flow during X cycles
-void SystemWaitCycles(uint32_t cycles);
-
-// 1 cycle-length flag with a frequency of 1 Hz
-bool System1SecondTick(void);
-
-// 1 cycle-length flag with a frequency of 2 Hz
-bool System500msTick(void);
-
-// 1 cycle-length flag with a frequency of 10 Hz
-bool System100msTick(void);
-
-// Returns random value between given minimum and maximum values
-uint32_t SystemRand(uint32_t min, uint32_t max);
-
-// Increases global timer by 1 step
-void SystemIncreaseGlobalTimer(void);
-
-// Sets value to emergency mode flag
-void SystemSetEmergencyMode(bool value);
-
-// Returns emergency mode flag state
-bool SystemGetEmergencyMode(void);
-
-// (Experimental)
-uint64_t SystemGetGlobalTimer(void);
-
-// Returns whether critical section of code is being entered
-volatile bool SystemIsBusy(void);
-
-// Returns whether indicated value is contained inside buffer
-bool SystemContains_u8(uint8_t value, uint8_t* buffer, size_t sz);
-
-// Overload for uint16_t
-bool SystemContains_u16(uint16_t value, uint16_t* buffer, size_t sz);
-
-// Reportedly, sets all timer data to zero.
-void SystemResetTimers(void);
-
-// To be called every cycle (i.e.: inside GfxDrawScene() ).
-void SystemUserTimersHandler(void);
-
-// Looks for string "str" inside a string array pointed to by "array".
-// Returns index inside string array on success, -1 if not found.
-int32_t SystemIndexOfStringArray(char* str, char** array);
-
-// Function overload for uint16_t data type.
-int32_t SystemIndexOf_U16(uint16_t value, uint16_t* array, uint32_t sz);
-
-// Function overload for uint8_t data type.
-int32_t SystemIndexOf_U8(uint8_t value, uint8_t* array, uint32_t from, uint32_t sz);
-
-void SystemCyclicHandler(void);
-
-size_t SystemGetBufferSize(void);
-
-void SystemClearBuffer(void);
-
-void SystemDisableVBlankInterrupt(void);
-
-void SystemEnableVBlankInterrupt(void);
-
-/* **************************************
- * Global Variables *
- * **************************************/
-
-#endif //__SYSTEM_HEADER__
+#endif /* SYSTEM_H */