moved from h4570/tyra
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_AUDIO_
|
||||
#define _TYRA_AUDIO_
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include <stdio.h>
|
||||
#include <audsrv.h>
|
||||
#include <kernel.h>
|
||||
#include "../models/audio_listener.hpp"
|
||||
|
||||
#define STACK_SIZE 8 * 1024
|
||||
|
||||
/** Class responsible for audio playing */
|
||||
class Audio
|
||||
{
|
||||
|
||||
public:
|
||||
Audio();
|
||||
~Audio();
|
||||
|
||||
u8 isTrackDone;
|
||||
ee_sema_t sema;
|
||||
int fillbufferSema;
|
||||
|
||||
void init(u32 t_listenersAmount);
|
||||
void play();
|
||||
void stop();
|
||||
void loadSong(char *t_filename);
|
||||
void unloadSong();
|
||||
void setVolume(u8 t_volume);
|
||||
void addListener(AudioListener *t_listener);
|
||||
void startThread();
|
||||
|
||||
private:
|
||||
void work();
|
||||
static void audioThread();
|
||||
u8 isInitialized, shouldPlay, songLoaded, isVolumeSet;
|
||||
|
||||
ee_thread_t audioThreadAttr;
|
||||
u8 audioThreadStack[STACK_SIZE] ALIGNED(16);
|
||||
int audioThreadId;
|
||||
|
||||
AudioListener **listeners;
|
||||
u32 listenersAmount;
|
||||
u32 addedListeners;
|
||||
void initSema();
|
||||
void loadModules();
|
||||
void initAUDSRV();
|
||||
|
||||
int ret, played;
|
||||
char chunk[2048];
|
||||
FILE *wav;
|
||||
audsrv_fmt_t format;
|
||||
static int fillbuffer(void *arg);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_CAMERA_BASE_
|
||||
#define _TYRA_CAMERA_BASE_
|
||||
|
||||
#include "../models/math/plane.hpp"
|
||||
#include "../models/math/matrix.hpp"
|
||||
#include "../models/math/vector3.hpp"
|
||||
#include "../models/screen_settings.hpp"
|
||||
|
||||
/** Class responsible for frustum culling */
|
||||
class CameraBase
|
||||
{
|
||||
|
||||
public:
|
||||
CameraBase(ScreenSettings *t_screen, Vector3 *t_position, Vector3 *t_up, Vector3 *t_unitCirclePosition);
|
||||
virtual ~CameraBase(){};
|
||||
|
||||
void setScreen();
|
||||
void updatePlanes(Vector3 t_target);
|
||||
Plane planes[6];
|
||||
Matrix worldView;
|
||||
|
||||
protected:
|
||||
ScreenSettings *screen;
|
||||
|
||||
private:
|
||||
Vector3 *position2, *up2, *unitCirclePosition2;
|
||||
float farPlaneDist, nearPlaneDist, nearHeight, nearWidth, farHeight, farWidth;
|
||||
Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_GIF_SENDER_
|
||||
#define _TYRA_GIF_SENDER_
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include <draw_buffers.h>
|
||||
#include <draw_types.h>
|
||||
#include <draw_primitives.h>
|
||||
#include <math3d.h>
|
||||
#include <packet.h>
|
||||
#include "../models/mesh.hpp"
|
||||
#include "../models/math/matrix.hpp"
|
||||
#include "../models/screen_settings.hpp"
|
||||
#include "../models/light_bulb.hpp"
|
||||
#include "../models/render_data.hpp"
|
||||
|
||||
/** Class responsible for sending data packets via GIF (PATH3) */
|
||||
class GifSender
|
||||
{
|
||||
|
||||
public:
|
||||
GifSender(u32 t_packetSize, ScreenSettings *t_screen);
|
||||
~GifSender();
|
||||
|
||||
void initPacket(u8 context);
|
||||
void addObjects(RenderData *t_renderData, Mesh **t_objects3D, u32 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount);
|
||||
void addClear(zbuffer_t *t_zBuffer);
|
||||
void sendPacket();
|
||||
void sendClear(zbuffer_t *t_zBuffer);
|
||||
static void sendTexture(Texture &texture, texbuffer_t *t_texBuffer);
|
||||
|
||||
private:
|
||||
xyz_t *xyz;
|
||||
color_t *rgbaq;
|
||||
texel_t *st;
|
||||
u8 isAnyObjectAdded;
|
||||
ScreenSettings *screen;
|
||||
u64 *dw;
|
||||
qword_t *q, *dmatag;
|
||||
packet_t *packets[2];
|
||||
packet_t *currentPacket;
|
||||
u8 packetsCount;
|
||||
int packetSize;
|
||||
float halfScreenW, halfScreenH;
|
||||
MATRIX localWorld, localScreen, localLight;
|
||||
|
||||
u32 calc3DObject(Matrix t_perspective, Mesh &t_mesh, RenderData *t_renderData, LightBulb *t_bulbs, u16 t_bulbsCount);
|
||||
void convertCalcs(u32 t_vertCount, VECTOR *t_vertices, VECTOR *t_colors, VECTOR *t_sts, u8 t_alpha);
|
||||
void addCurrentCalcs(u32 &t_vertexCount);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_LIGHT_
|
||||
#define _TYRA_LIGHT_
|
||||
|
||||
#include <math3d.h>
|
||||
#include <tamtypes.h>
|
||||
#include "../models/math/vector3.hpp"
|
||||
#include "../models/light_bulb.hpp"
|
||||
|
||||
class Light
|
||||
{
|
||||
|
||||
public:
|
||||
Light();
|
||||
~Light();
|
||||
|
||||
static u16 getLightsCount(u32 t_bulbsCount);
|
||||
static void calculateLight(VECTOR *t_lightDirections, VECTOR *t_lightColors, int *t_lightTypes, LightBulb *t_bulbs, u32 t_bulbsCount, Vector3 t_objPosition);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_PAD_
|
||||
#define _TYRA_PAD_
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include <libpad.h>
|
||||
|
||||
/** Class responsible for player pad */
|
||||
class Pad
|
||||
{
|
||||
|
||||
public:
|
||||
u8 isCrossClicked, isSquareClicked, isTriangleClicked, isCircleClicked;
|
||||
u8 isDpadUpPressed, isDpadDownPressed, isDpadLeftPressed, isDpadRightPressed;
|
||||
u8 lJoyH, lJoyV, rJoyH, rJoyV;
|
||||
|
||||
Pad();
|
||||
~Pad();
|
||||
void update();
|
||||
|
||||
private:
|
||||
char padBuf[256] __attribute__((aligned(64)));
|
||||
char actAlign[6];
|
||||
int actuators, ret, port, slot;
|
||||
padButtonStatus buttons;
|
||||
u32 padData, oldPad, newPad;
|
||||
|
||||
void reset();
|
||||
void loadModules();
|
||||
int waitPadReady();
|
||||
int initPad();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_RENDERER_
|
||||
#define _TYRA_RENDERER_
|
||||
|
||||
#include <draw_buffers.h>
|
||||
#include <draw_primitives.h>
|
||||
#include <packet.h>
|
||||
#include "gif_sender.hpp"
|
||||
#include "vif_sender.hpp"
|
||||
#include "../models/math/plane.hpp"
|
||||
#include "../models/screen_settings.hpp"
|
||||
#include "../models/render_data.hpp"
|
||||
|
||||
/** Class responsible for intializing draw env, textures and buffers */
|
||||
class Renderer
|
||||
{
|
||||
|
||||
public:
|
||||
Renderer(u32 t_packetSize, ScreenSettings *t_screen);
|
||||
~Renderer();
|
||||
|
||||
framebuffer_t frameBuffers[2];
|
||||
u8 context;
|
||||
zbuffer_t zBuffer;
|
||||
prim_t prim;
|
||||
|
||||
/** PATH3 Many + lighting */
|
||||
void drawByPath3(Mesh **t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount);
|
||||
/** PATH3 Single + lighting */
|
||||
void drawByPath3(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount);
|
||||
/** PATH3 Many */
|
||||
void drawByPath3(Mesh **t_meshes, u16 t_amount);
|
||||
/** PATH3 Single */
|
||||
void drawByPath3(Mesh *t_mesh);
|
||||
|
||||
/** PATH1 Many + lighting */
|
||||
void draw(Mesh **t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount);
|
||||
/** PATH1 Single + lighting */
|
||||
void draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount);
|
||||
/** PATH1 Many */
|
||||
void draw(Mesh **t_meshes, u16 t_amount);
|
||||
/** PATH1 Single */
|
||||
void draw(Mesh *t_mesh);
|
||||
|
||||
void setCameraDefinitions(Matrix *t_worldView, Vector3 *t_cameraPos, Plane *t_planes);
|
||||
|
||||
void endFrame(float fps);
|
||||
|
||||
private:
|
||||
void changeTexture(Mesh *t_mesh, u8 t_textureIndex);
|
||||
void flipBuffers();
|
||||
void beginFrameIfNeeded();
|
||||
u8 isFrameEmpty;
|
||||
Matrix perspective;
|
||||
RenderData renderData;
|
||||
|
||||
u32 lastTextureId;
|
||||
GifSender *gifSender;
|
||||
VifSender *vifSender;
|
||||
packet_t *flipPacket;
|
||||
void allocateBuffers(float t_screenW, float t_screenH);
|
||||
void initDrawingEnv(float t_screenW, float t_screenH);
|
||||
void setPrim();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_TIMER_
|
||||
#define _TYRA_TIMER_
|
||||
|
||||
#include <tamtypes.h>
|
||||
|
||||
/** Class responsible for fps counting */
|
||||
class Timer
|
||||
{
|
||||
|
||||
public:
|
||||
Timer();
|
||||
~Timer();
|
||||
|
||||
u32 getTimeDelta();
|
||||
void primeTimer();
|
||||
float getFPS();
|
||||
|
||||
private:
|
||||
u32 lastTime, time, change;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_VIF_SENDER_
|
||||
#define _TYRA_VIF_SENDER_
|
||||
|
||||
#include <tamtypes.h>
|
||||
#include "../models/render_data.hpp"
|
||||
#include "../models/light_bulb.hpp"
|
||||
#include "../models/mesh.hpp"
|
||||
#include "../models/math/matrix.hpp"
|
||||
#include "../models/math/vector3.hpp"
|
||||
#include "vu1.hpp"
|
||||
|
||||
/** Class responsible for sending 3D objects via VIF (PATH 1) */
|
||||
class VifSender
|
||||
{
|
||||
|
||||
public:
|
||||
VifSender();
|
||||
~VifSender();
|
||||
|
||||
// TODO refactor
|
||||
void drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, VECTOR *colors, Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount);
|
||||
|
||||
private:
|
||||
void drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_colors, VECTOR *t_coordinates, prim_t *t_prim);
|
||||
|
||||
MATRIX localWorld, localScreen;
|
||||
VECTOR position, rotation;
|
||||
u32 vertCount;
|
||||
VU1 vu1;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||
# Licenced under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef _TYRA_VU1_
|
||||
#define _TYRA_VU1_
|
||||
|
||||
#include "../models/math/matrix.hpp"
|
||||
#include <draw_buffers.h>
|
||||
#include <tamtypes.h>
|
||||
#include <draw_primitives.h>
|
||||
#include <packet.h>
|
||||
#include <math3d.h>
|
||||
|
||||
const u32 VIF_BUFFER_SIZE = 48 * 1024;
|
||||
|
||||
typedef struct VU1BuildList
|
||||
{
|
||||
u8 isBuilding;
|
||||
void *offset;
|
||||
void *kickBuffer;
|
||||
u32 dmaSize;
|
||||
u32 dmaSizeAll;
|
||||
u32 dmaDestination;
|
||||
} VU1BuildList;
|
||||
|
||||
/** Class responsible for managing VU1 micro programs */
|
||||
class VU1
|
||||
{
|
||||
|
||||
public:
|
||||
VU1();
|
||||
~VU1();
|
||||
|
||||
static void uploadProgram(int t_dest, u32 *t_start, u32 *t_end);
|
||||
void createList();
|
||||
void sendSingleRefList(int t_destAddress, void *t_data, int t_quadSize);
|
||||
void addListBeginning();
|
||||
void continueList();
|
||||
void addReferenceList(u32 t_offset, void *t_data, u32 t_size, u8 t_useTops);
|
||||
void addFloat(float v);
|
||||
void add32(u32 v);
|
||||
void add64(u64 v);
|
||||
void add128(u64 v1, u64 v2);
|
||||
void addListEnding();
|
||||
void addStartProgram();
|
||||
void addContinueProgram();
|
||||
void sendList();
|
||||
void addDoubleBufferSetting();
|
||||
void addFlush();
|
||||
|
||||
private:
|
||||
u8 isDoubleBufferSet;
|
||||
void checkDataAlignment(void *data);
|
||||
VU1BuildList buildList;
|
||||
char dmaBuffer1[VIF_BUFFER_SIZE] __attribute__((aligned(16)));
|
||||
char dmaBuffer2[VIF_BUFFER_SIZE] __attribute__((aligned(16)));
|
||||
void *currentBuffer;
|
||||
u32 switchBuffer;
|
||||
static u32 countProgramSize(u32 *t_start, u32 *t_end);
|
||||
void checkList();
|
||||
inline s32 AddUnpack(int format, int addr, int num, int usetops = 0, int nosign = 1, int masking = 0)
|
||||
{
|
||||
return (s32)((0x60 << 24) + (format << 24) + (masking << 28) + (usetops << 15) +
|
||||
(nosign << 14) + (num << 16) + addr);
|
||||
}
|
||||
};
|
||||
|
||||
#define DMA_REF_TAG(ADDR, COUNT) ((((unsigned long)ADDR) << 32) | (0x3 << 28) | COUNT)
|
||||
#define DMA_CNT_TAG(COUNT) (((unsigned long)(0x1) << 28) | COUNT)
|
||||
#define DMA_END_TAG(COUNT) (((unsigned long)(0x7) << 28) | COUNT)
|
||||
#define VIF_NOP 0x00
|
||||
#define VIF_STCYL 0x01
|
||||
#define VIF_OFFSET 0x02
|
||||
#define VIF_BASE 0x03
|
||||
#define VIF_FLUSH 0x11
|
||||
#define VIF_MSCAL 0x14
|
||||
#define VIF_MSCNT 0x17
|
||||
#define VIF_MPG 0x4A
|
||||
#define V4_32 0xC
|
||||
#define VIF_UNPACK 0x60
|
||||
#define U128(n) ((u128)(n))
|
||||
#define VIF_UNPACK_V4_32 (VIF_UNPACK | V4_32)
|
||||
#define VIF_CODE(CMD, NUM, IMMEDIATE) ((((unsigned int)(CMD)) << 24) | \
|
||||
(((unsigned int)(NUM)) << 16) | \
|
||||
((unsigned int)(IMMEDIATE)))
|
||||
#define GS_PRIM(PRIM, IIP, TME, FGE, ABE, AA1, FST, CTXT, FIX) U128((FIX << 10) | (CTXT << 9) | (FST << 8) | (AA1 << 7) | (ABE << 6) | (FGE << 5) | (TME << 4) | (IIP << 3) | (PRIM))
|
||||
#define GS_GIFTAG(NLOOP, EOP, PRE, PRIM, FLG, NREG) (((u64)(NREG) << 60) | ((u64)(FLG) << 58) | ((u64)(PRIM) << 47) | ((u64)(PRE) << 46) | (EOP << 15) | (NLOOP << 0))
|
||||
#define VU1_DMA_CHAN_TIMEOUT -1
|
||||
#define GS_GIFTAG_PACKED 0
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user