Skip to content

Commit 6dc4bd1

Browse files
authored
Libultra implementations (Kenix3#493)
* Rebased towards latest main * Fixed tidy * Implemented rumble on multiple controllers (cherry picked from commit 6064d7b) * Implemented first version of osContGetStatus * Fixed dumb mistake (cherry picked from commit ee95529) * Added channel copy on osMotorInit * Implemented eeprom support and fixed rumble * Fixed tidy on rcp.h * Fixed tidy on gu.h * Implemented eeprom support and fixed rumble (cherry picked from commit 0c3e1ac) * Fixed libultraship include * Moved os.h header to libultra * Fixed includes on os.h * Removed LUS::Controller changes * Removed whitespace * Removed added newline * Renamed to Ship::Context * Removed WiiU Defines * Fixed osAiSetNextBuffer definitions * Fixed linking issues
1 parent 7b8e521 commit 6dc4bd1

File tree

16 files changed

+700
-47
lines changed

16 files changed

+700
-47
lines changed

include/libultraship/libultra.h

+2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#include "libultra/abi.h"
55
#include "libultra/controller.h"
66
#include "libultra/convert.h"
7+
#include "libultra/eeprom.h"
78
#include "libultra/exception.h"
89
#include "libultra/gbi.h"
910
#include "libultra/gs2dex.h"
1011
#include "libultra/gu.h"
12+
#include "libultra/os.h"
1113
#include "libultra/internal.h"
1214
#include "libultra/interrupt.h"
1315
#include "libultra/mbi.h"
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef ULTRA64_EEPROM_H
2+
#define ULTRA64_EEPROM_H
3+
4+
#include "message.h"
5+
6+
#define EEPROM_TYPE_4K 0x01
7+
#define EEPROM_TYPE_16K 0x02
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
int32_t osEepromProbe(OSMesgQueue*);
14+
int32_t osEepromLongRead(OSMesgQueue*, uint8_t, uint8_t*, int32_t);
15+
int32_t osEepromLongWrite(OSMesgQueue*, uint8_t, uint8_t*, int32_t);
16+
17+
#ifdef __cplusplus
18+
}
19+
#endif
20+
21+
#endif

include/libultraship/libultra/gu.h

+195
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,203 @@
11
#ifndef ULTRA64_GU_H
22
#define ULTRA64_GU_H
33

4+
#include "../libultraship.h"
5+
#include "sptask.h"
6+
47
#define GU_PI 3.1415926
58

69
#define ROUND(x) (s32)(((x) >= 0.0) ? ((x) + 0.5) : ((x)-0.5))
710

11+
#ifndef MAX
12+
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
13+
#endif
14+
#ifndef MIN
15+
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
816
#endif
17+
18+
#define D_PI 3.14159265358979323846
19+
#define D_DTOR (3.14159265358979323846 / 180.0)
20+
21+
#define FTOFIX32(x) (long)((x) * (float)0x00010000)
22+
#define FIX32TOF(x) ((float)(x) * (1.0f / (float)0x00010000))
23+
#define FTOFRAC8(x) ((int)MIN(((x) * (128.0f)), 127.0f) & 0xff)
24+
25+
#define FILTER_WRAP 0
26+
#define FILTER_CLAMP 1
27+
28+
#define RAND(x) (guRandom() % x) /* random number between 0 to x */
29+
30+
/*
31+
* Data Structures
32+
*/
33+
typedef struct {
34+
unsigned char* base;
35+
int fmt, siz;
36+
int xsize, ysize;
37+
int lsize;
38+
/* current tile info */
39+
int addr;
40+
int w, h;
41+
int s, t;
42+
} Image;
43+
44+
typedef struct {
45+
float col[3];
46+
float pos[3];
47+
float a1, a2; /* actual color = col/(a1*dist + a2) */
48+
} PositionalLight;
49+
50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
53+
54+
/*
55+
* Function Prototypes
56+
*/
57+
58+
extern int guLoadTextureBlockMipMap(Gfx** glist, unsigned char* tbuf, Image* im, unsigned char startTile,
59+
unsigned char pal, unsigned char cms, unsigned char cmt, unsigned char masks,
60+
unsigned char maskt, unsigned char shifts, unsigned char shiftt, unsigned char cfs,
61+
unsigned char cft);
62+
63+
extern int guGetDPLoadTextureTileSz(int ult, int lrt);
64+
extern void guDPLoadTextureTile(Gfx* glistp, void* timg, int texl_fmt, int texl_size, int img_width, int img_height,
65+
int uls, int ult, int lrs, int lrt, int palette, int cms, int cmt, int masks, int maskt,
66+
int shifts, int shiftt);
67+
68+
/*
69+
* matrix operations:
70+
*
71+
* The 'F' version is floating point, in case the application wants
72+
* to do matrix manipulations and convert to fixed-point at the last
73+
* minute.
74+
*/
75+
extern void guMtxIdent(Mtx* m);
76+
extern void guMtxIdentF(float mf[4][4]);
77+
extern void guOrtho(Mtx* m, float l, float r, float b, float t, float n, float f, float scale);
78+
extern void guOrthoF(float mf[4][4], float l, float r, float b, float t, float n, float f, float scale);
79+
extern void guFrustum(Mtx* m, float l, float r, float b, float t, float n, float f, float scale);
80+
extern void guFrustumF(float mf[4][4], float l, float r, float b, float t, float n, float f, float scale);
81+
extern void guPerspective(Mtx* m, u16* perspNorm, float fovy, float aspect, float near, float far, float scale);
82+
extern void guPerspectiveF(float mf[4][4], u16* perspNorm, float fovy, float aspect, float near, float far,
83+
float scale);
84+
extern void guLookAt(Mtx* m, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp,
85+
float zUp);
86+
extern void guLookAtF(float mf[4][4], float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp,
87+
float yUp, float zUp);
88+
extern void guLookAtReflect(Mtx* m, LookAt* l, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt,
89+
float xUp, float yUp, float zUp);
90+
extern void guLookAtReflectF(float mf[4][4], LookAt* l, float xEye, float yEye, float zEye, float xAt, float yAt,
91+
float zAt, float xUp, float yUp, float zUp);
92+
extern void guLookAtHilite(Mtx* m, LookAt* l, Hilite* h, float xEye, float yEye, float zEye, float xAt, float yAt,
93+
float zAt, float xUp, float yUp, float zUp, float xl1, float yl1, float zl1, float xl2,
94+
float yl2, float zl2, int twidth, int theight);
95+
extern void guLookAtHiliteF(float mf[4][4], LookAt* l, Hilite* h, float xEye, float yEye, float zEye, float xAt,
96+
float yAt, float zAt, float xUp, float yUp, float zUp, float xl1, float yl1, float zl1,
97+
float xl2, float yl2, float zl2, int twidth, int theight);
98+
extern void guLookAtStereo(Mtx* m, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp,
99+
float yUp, float zUp, float eyedist);
100+
extern void guLookAtStereoF(float mf[4][4], float xEye, float yEye, float zEye, float xAt, float yAt, float zAt,
101+
float xUp, float yUp, float zUp, float eyedist);
102+
extern void guRotate(Mtx* m, float a, float x, float y, float z);
103+
extern void guRotateF(float mf[4][4], float a, float x, float y, float z);
104+
extern void guRotateRPY(Mtx* m, float r, float p, float y);
105+
extern void guRotateRPYF(float mf[4][4], float r, float p, float h);
106+
extern void guAlign(Mtx* m, float a, float x, float y, float z);
107+
extern void guAlignF(float mf[4][4], float a, float x, float y, float z);
108+
extern void guScale(Mtx* m, float x, float y, float z);
109+
extern void guScaleF(float mf[4][4], float x, float y, float z);
110+
extern void guTranslate(Mtx* m, float x, float y, float z);
111+
extern void guTranslateF(float mf[4][4], float x, float y, float z);
112+
extern void guPosition(Mtx* m, float r, float p, float h, float s, float x, float y, float z);
113+
extern void guPositionF(float mf[4][4], float r, float p, float h, float s, float x, float y, float z);
114+
extern void guMtxF2L(float mf[4][4], Mtx* m);
115+
extern void guMtxL2F(float mf[4][4], Mtx* m);
116+
extern void guMtxCatF(float m[4][4], float n[4][4], float r[4][4]);
117+
extern void guMtxCatL(Mtx* m, Mtx* n, Mtx* res);
118+
extern void guMtxXFMF(float mf[4][4], float x, float y, float z, float* ox, float* oy, float* oz);
119+
extern void guMtxXFML(Mtx* m, float x, float y, float z, float* ox, float* oy, float* oz);
120+
121+
/* vector utility: */
122+
extern void guNormalize(float* x, float* y, float* z);
123+
124+
/* light utilities: */
125+
void guPosLight(PositionalLight* pl, Light* l, float xOb, float yOb, float zOb);
126+
void guPosLightHilite(PositionalLight* pl1, PositionalLight* pl2, Light* l1, Light* l2, LookAt* l, Hilite* h,
127+
float xEye, float yEye, float zEye, float xOb, float yOb, float zOb, float xUp, float yUp,
128+
float zUp, int twidth, int theight);
129+
extern int guRandom(void);
130+
131+
/*
132+
* Math functions
133+
*/
134+
// extern float sinf(float angle);
135+
// extern float cosf(float angle);
136+
// extern signed short sins (unsigned short angle);
137+
// extern signed short coss (unsigned short angle);
138+
extern float guSqrtf(float value);
139+
140+
/*
141+
* Dump routines for low-level display lists
142+
*/
143+
/* flag values for guParseRdpDL() */
144+
#define GU_PARSERDP_VERBOSE 1
145+
#define GU_PARSERDP_PRAREA 2
146+
#define GU_PARSERDP_PRHISTO 4
147+
#define GU_PARSERDP_DUMPONLY 32 /* doesn't need to be same as */
148+
/* GU_PARSEGBI_DUMPOLNY, but this */
149+
/* allows app to use interchangeably */
150+
151+
extern void guParseRdpDL(u64* rdp_dl, u64 nbytes, u8 flags);
152+
extern void guParseString(char* StringPointer, u64 nbytes);
153+
154+
/*
155+
* NO LONGER SUPPORTED,
156+
* use guParseRdpDL with GU_PARSERDP_DUMPONLY flags
157+
*/
158+
/* extern void guDumpRawRdpDL(u64 *rdp_dl, u64 nbytes); */
159+
160+
/* flag values for guBlinkRdpDL() */
161+
#define GU_BLINKRDP_HILITE 1
162+
#define GU_BLINKRDP_EXTRACT 2
163+
164+
extern void guBlinkRdpDL(u64* rdp_dl_in, u64 nbytes_in, u64* rdp_dl_out, u64* nbytes_out, u32 x, u32 y, u32 radius,
165+
u8 red, u8 green, u8 blue, u8 flags);
166+
167+
/* flag values for guParseGbiDL() */
168+
#define GU_PARSEGBI_ROWMAJOR 1
169+
#define GU_PARSEGBI_NONEST 2
170+
#define GU_PARSEGBI_FLTMTX 4
171+
#define GU_PARSEGBI_SHOWDMA 8
172+
#define GU_PARSEGBI_ALLMTX 16
173+
#define GU_PARSEGBI_DUMPONLY 32
174+
/*
175+
#define GU_PARSEGBI_HANGAFTER 64
176+
#define GU_PARSEGBI_NOTEXTURES 128
177+
*/
178+
extern void guParseGbiDL(u64* gbi_dl, u32 nbytes, u8 flags);
179+
extern void guDumpGbiDL(OSTask* tp, u8 flags);
180+
181+
#define GU_PARSE_GBI_TYPE 1
182+
#define GU_PARSE_RDP_TYPE 2
183+
#define GU_PARSE_READY 3
184+
#define GU_PARSE_MEM_BLOCK 4
185+
#define GU_PARSE_ABI_TYPE 5
186+
#define GU_PARSE_STRING_TYPE 6
187+
188+
typedef struct {
189+
int dataSize;
190+
int dlType;
191+
int flags;
192+
u32 paddr;
193+
} guDLPrintCB;
194+
195+
void guSprite2DInit(uSprite* SpritePointer, void* SourceImagePointer, void* TlutPointer, int Stride, int SubImageWidth,
196+
int SubImageHeight, int SourceImageType, int SourceImageBitSize, int SourceImageOffsetS,
197+
int SourceImageOffsetT);
198+
199+
#ifdef __cplusplus
200+
}
201+
#endif
202+
203+
#endif

include/libultraship/libultra/internal.h

+6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ typedef struct {
1818
/* 0x04 */ OSMesg msg;
1919
} __OSEventState; // size = 0x08
2020

21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
2124
extern OSMgrArgs __osPiDevMgr;
2225
extern __OSEventState __osEventStateTab[];
26+
#ifdef __cplusplus
27+
}
28+
#endif
2329

2430
#endif

include/libultraship/libultra/message.h

+11
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,15 @@ typedef struct OSMesgQueue {
5252
/* 0x14 */ OSMesg* msg;
5353
} OSMesgQueue; // size = 0x18
5454

55+
#ifdef __cplusplus
56+
extern "C" {
57+
#endif
58+
void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msgBuf, int32_t count);
59+
int32_t osSendMesg(OSMesgQueue* mq, OSMesg msg, int32_t flag);
60+
int32_t osJamMesg(OSMesgQueue* mq, OSMesg msg, int32_t flag);
61+
int32_t osRecvMesg(OSMesgQueue* mq, OSMesg* msg, int32_t flag);
62+
void osSetEventMesg(OSEvent event, OSMesgQueue* mq, OSMesg msg);
63+
#ifdef __cplusplus
64+
}
65+
#endif
5566
#endif

include/libultraship/libultra/motor.h

+7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
#define osMotorStart(x) __osMotorAccess((x), MOTOR_START)
1010
#define osMotorStop(x) __osMotorAccess((x), MOTOR_STOP)
1111

12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
1216
s32 __osMotorAccess(OSPfs* pfs, u32 vibrate);
1317
s32 osMotorInit(OSMesgQueue* ctrlrqueue, OSPfs* pfs, s32 channel);
1418

19+
#ifdef __cplusplus
20+
}
21+
#endif
1522
#endif

0 commit comments

Comments
 (0)