Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added SPU functions and error list

  • Loading branch information...
commit 96b8a31b017d3980752032387baa6fe663f6d16d 1 parent 4f5642e
@wargio authored
View
0  Makefile 100644 → 100755
File mode changed
View
3  README.md
@@ -78,6 +78,9 @@ Changelog:
- 0.1.8 -
Added Animation.cpp and Animation.h to create animations
New Bitmap Functions
+ - 0.1.9 -
+ Added Spu.cpp to use spu stuff
+ Added NoRSX error list (incomplete)
Homebrews built with this lib:
------------------------------
View
0  libNoRSX/Animation.cpp 100644 → 100755
File mode changed
View
2  libNoRSX/Makefile
@@ -43,7 +43,7 @@ CXXFLAGS := $(CFLAGS)
VPATH := $(BASEDIR)
#---------------------------------------------------------------------------------
-OBJS := Background.o Font.o Min.o NoRSX.o NoRSXutil.o Bitmap.o Image.o Msg.o Objects.o EventHandler.o Animation.o
+OBJS := Background.o Font.o Min.o NoRSX.o NoRSXutil.o Bitmap.o Image.o Msg.o Objects.o EventHandler.o Animation.o Spu.o
#---------------------------------------------------------------------------------
all: install-headers ppu install
View
2  libNoRSX/NoRSX.h
@@ -28,6 +28,8 @@
#include <NoRSX/Bitmap.h>
#include <NoRSX/EventHandler.h>
#include <NoRSX/Animation.h>
+#include <NoRSX/Errors.h>
+#include <NoRSX/Spu.h>
#include <stdio.h>
#include <malloc.h>
View
0  libNoRSX/NoRSX/Animation.h 100644 → 100755
File mode changed
View
50 libNoRSX/NoRSX/Errors.h
@@ -0,0 +1,50 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ This program was created by Grazioli Giovanni Dante <wargio@libero.it>.
+*/
+
+#ifndef __NORSX_ERROR_LIST_H__
+#define __NORSX_ERROR_LIST_H__
+
+#define NORSX_OK 0
+
+/* NoRSX Main Errors*/
+/*
+#define NORSX_NO_ERROR 0xFF0E0000
+#define NORSX_NOT_STARTED 0xFF0EDEAD
+#define NORSX_ALREADY_STARTED 0xFF0EFAAD
+#define NORSX_STARTED 0xFF0EFEED
+*/
+
+
+/* SPU Errors */
+#define SPU_NO_ERROR 0xDEA00000
+#define SPU_NOT_STARTED 0xDEA0DEAD
+#define SPU_ALREADY_STARTED 0xDEA0FAAD
+#define SPU_STARTED 0xDEA0FEED
+#define SPU_ERROR_INIT 0xDEA00E0F
+#define SPU_CANNOT_IMPORT_IMAGE 0xDEA0AE0F
+#define SPU_CANNOT_OPEN_IMAGE 0xDEA0BE0F
+#define SPU_CANNOT_LOAD_IMAGE 0xDEA0CE0F
+#define SPU_CANNOT_CREATE_RAW 0xDEA0DE0F
+#define SPU_CANNOT_DESTROY_RAW 0xDEA0EE0F
+#define SPU_CANNOT_CLOSE_IMAGE 0xDEA0FE0F
+
+
+
+
+
+
+#endif
View
69 libNoRSX/NoRSX/Spu.h
@@ -0,0 +1,69 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ This program was created by Grazioli Giovanni Dante <wargio@libero.it>.
+*/
+
+#ifndef __NORSX_SPU_H__
+#define __NORSX_SPU_H__
+
+#include <sys/spu.h>
+#include <NoRSX/Errors.h>
+
+#define ptr2ea(x) ((u64)((void*)(x)))
+
+typedef struct {
+ sysSpuImage image;
+
+ sysSpuThreadArgument args;
+ sysSpuThreadGroupAttribute group_attr;
+ sysSpuThreadAttribute attr;
+
+ u32 group_num;
+
+ u32 status;
+ u32 cause;
+
+
+ u32 spu_id;
+ u32 thread_id;
+ u32 group_id;
+
+ int loaded_grp_attr;
+ int loaded_attr;
+
+} NoRSX_Spu;
+
+class Spu{
+public:
+ Spu();
+ ~Spu();
+
+ void SpuAttrubute(NoRSX_Spu *spus, const char *text);
+ void SpuGroupAttribute(NoRSX_Spu *spus, const char* text, u32 group_type, u32 mem_container);
+ void SpuArgs(NoRSX_Spu *spus, u64 arg1, u64 arg2, u64 arg3, u64 arg4);
+ void SpuThreadGroupCreate(NoRSX_Spu *spus, u32 priority);
+ void SpuThreadInit(NoRSX_Spu *spus);
+ int LoadELF(const void *module, NoRSX_Spu *spus);
+ int LoadELF(const char *module_path, NoRSX_Spu *spus);
+ void SpuCloseImage(NoRSX_Spu *spus);
+
+ int GetSpuError() const;
+
+protected:
+ int error;
+
+};
+
+#endif
View
167 libNoRSX/Spu.cpp
@@ -0,0 +1,167 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ This program was created by Grazioli Giovanni Dante <wargio@libero.it>.
+*/
+
+#include <NoRSX/Spu.h>
+#include <string.h>
+#include <malloc.h>
+#include <errno.h>
+
+#define SPU_SIZE(x) (((x)+127) & ~127)
+
+#define NORSX_SPU_LOADED 0
+#define NORSX_SPU_NOT_LOADED 1
+
+static u32 spu_init = SPU_NOT_STARTED;
+
+Spu::Spu(){
+ spu_init = SPU_NO_ERROR;
+
+ if(spu_init == SPU_ALREADY_STARTED)
+ error = SPU_ALREADY_STARTED;
+
+ u32 ret = sysSpuInitialize(6, 5);
+
+ if (ret == NORSX_OK)
+ spu_init = SPU_STARTED;
+ else
+ error = SPU_ERROR_INIT;
+}
+
+Spu::~Spu(){
+}
+
+int Spu::GetSpuError() const{
+ return error;
+}
+
+void Spu::SpuAttrubute(NoRSX_Spu *spus, const char *text){
+ if(spus->loaded_attr != NORSX_SPU_LOADED){
+ spus->attr.nameAddress = ptr2ea(text);
+ spus->attr.nameSize = strlen(text)+1;
+ spus->attr.attribute = SPU_THREAD_ATTR_NONE;
+ spus->loaded_attr = NORSX_SPU_LOADED;
+ }
+}
+
+void Spu::SpuGroupAttribute(NoRSX_Spu *spus, const char* text, u32 group_type, u32 mem_container){
+ if(spus->loaded_grp_attr != NORSX_SPU_LOADED){
+ spus->group_attr.nameAddress = ptr2ea(text);
+ spus->group_attr.nameSize = strlen(text)+1;
+ spus->group_attr.groupType = group_type;
+ spus->group_attr.memContainer = mem_container;
+ spus->group_num = 1;
+ spus->loaded_grp_attr = NORSX_SPU_LOADED;
+ }
+}
+
+void Spu::SpuArgs(NoRSX_Spu *spus, u64 arg1, u64 arg2, u64 arg3, u64 arg4){
+ spus->args.arg0 = arg1;
+ spus->args.arg1 = arg2;
+ spus->args.arg2 = arg3;
+ spus->args.arg3 = arg4;
+}
+
+void Spu::SpuThreadGroupCreate(NoRSX_Spu *spus, u32 priority){
+ sysSpuThreadGroupCreate(&spus->group_id,
+ 1,
+ priority,
+ &spus->group_attr);
+}
+
+void Spu::SpuThreadInit(NoRSX_Spu *spus){
+ sysSpuThreadInitialize( &spus->thread_id,
+ spus->group_id,
+ 0,
+ &spus->image,
+ &spus->attr,
+ &spus->args);
+ sysSpuThreadGroupStart(spus->group_id);
+}
+
+int Spu::LoadELF(const void *module, NoRSX_Spu *spus){
+ sysSpuSegment *segment;
+
+ size_t len;
+ u32 entry, count;
+
+ s32 ret = sysSpuRawCreate(&spus->spu_id, NULL);
+ if(ret != NORSX_OK){
+ error = SPU_CANNOT_CREATE_RAW;
+ return ret;
+ }
+ sysSpuElfGetInformation(module, &entry, &count);
+ len = sizeof(sysSpuSegment)*count;
+ segment = (sysSpuSegment*) memalign(128, SPU_SIZE(len));
+ memset(segment, 0, len);
+ sysSpuElfGetSegments(module, segment, count);
+
+ ret = sysSpuImageImport(&spus->image, module, 0);
+ if (ret != NORSX_OK){
+ error = SPU_CANNOT_IMPORT_IMAGE;
+ goto Error;
+ }
+
+ ret = sysSpuRawImageLoad(spus->spu_id, &spus->image);
+ if (ret != NORSX_OK){
+ error = SPU_CANNOT_LOAD_IMAGE;
+ goto Error;
+ }
+
+ return 0;
+
+Error:
+ if (segment)
+ free(segment);
+
+ return ret;
+}
+
+int Spu::LoadELF(const char *module_path, NoRSX_Spu *spus){
+ s32 ret = sysSpuRawCreate(&spus->spu_id, NULL);
+ if(ret != NORSX_OK){
+ error = SPU_CANNOT_CREATE_RAW;
+ return ret;
+ }
+ ret = sysSpuImageOpen(&spus->image, module_path);
+ if (ret != NORSX_OK){
+ error = SPU_CANNOT_OPEN_IMAGE;
+ return ret;
+ }
+
+ ret = sysSpuRawImageLoad(spus->spu_id, &spus->image);
+
+ if (ret != NORSX_OK){
+ error = SPU_CANNOT_LOAD_IMAGE;
+ return ret;
+ }
+
+ return 0;
+}
+
+
+void Spu::SpuCloseImage(NoRSX_Spu *spus){
+ sysSpuThreadGroupJoin( spus->group_id,
+ &spus->cause,
+ &spus->status);
+ u32 ret = sysSpuRawDestroy(spus->spu_id);
+ if (ret != NORSX_OK)
+ error = SPU_CANNOT_DESTROY_RAW;
+
+ ret = sysSpuImageClose(&spus->image);
+ if (ret != NORSX_OK)
+ error = SPU_CANNOT_CLOSE_IMAGE;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.