
y me sale esto

A ver si podeis ayudarme, os pego trozos de los archivos k tan relacionados con el error:
functions.c
Spoiler:
- Código: Seleccionar todo
static void *xfb[2] = {NULL, NULL};
GXRModeObj *rmode;
f32 yscale;
u32 xfbHeight;
Mtx view;
Mtx44 perspective;
u32 fb = 0; // initial xfb index
GXColor background = {0, 0, 0, 0xff};
void InitVideo() {
VIDEO_Init();
rmode = VIDEO_GetPreferredMode(NULL);
// allocate 2 framebuffers for double buffering
xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(xfb[fb]);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
// setup the fifo and then init the flipper
void *gp_fifo = NULL;
gp_fifo = memalign(32,DEFAULT_FIFO_SIZE);
memset(gp_fifo,0,DEFAULT_FIFO_SIZE);
GX_Init(gp_fifo,DEFAULT_FIFO_SIZE);
// clears the bg to color and clears the z buffer
GX_SetCopyClear(background, 0x00ffffff);
// other gx setup
GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1);
yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight);
xfbHeight = GX_SetDispCopyYScale(yscale);
GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight);
GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight);
GX_SetDispCopyDst(rmode->fbWidth,xfbHeight);
GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter);
GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE));
GX_SetCullMode(GX_CULL_NONE);
GX_CopyDisp(xfb[fb],GX_TRUE);
GX_SetDispCopyGamma(GX_GM_1_0);
// setup our camera at the origin
// looking down the -z axis with y up
guVector cam = {0.0F, 0.0F, 0.0F},
up = {0.0F, 1.0F, 0.0F},
look = {0.0F, 0.0F, -1.0F};
guLookAt(view, &cam, &up, &look);
// setup our projection matrix
// this creates a perspective matrix with a view angle of 90,
// and aspect ratio based on the display resolution
f32 w = rmode->viWidth;
f32 h = rmode->viHeight;
guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F);
GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE);
}
GXTexObj texObj;
void DrawImg(f32 xpos, f32 ypos, u16 width, u16 height, void *data, f32 degrees, f32 scaleX, f32 scaleY, u8 alpha) {
GX_InitTexObj(&texObj, data, width,height, GX_TF_RGBA8,GX_CLAMP, GX_CLAMP,GX_FALSE);
GX_InvalidateTexAll();
GX_InvVtxCache();
GX_LoadTexObj(&texObj, GX_TEXMAP0);
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
Mtx m,m1,m2, mv;
width *=.5;
height*=.5;
guMtxIdentity (m1);
guMtxScaleApply(m1,m1,scaleX,scaleY,1.0);
guVector axis = (guVector) {0 , 0, 1 };
guMtxRotAxisDeg (m2, &axis, degrees);
guMtxConcat(m2,m1,m);
guMtxTransApply(m,m, xpos+width,ypos+height,0);
guMtxConcat (view, m, mv);
GX_LoadPosMtxImm (mv, GX_PNMTX0);
GX_Begin(GX_QUADS, GX_VTXFMT0,4);
GX_Position3f32(-width, -height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(0, 0);
GX_Position3f32(width, -height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(1, 0);
GX_Position3f32(width, height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(1, 1);
GX_Position3f32(-width, height, 0);
GX_Color4u8(0xFF,0xFF,0xFF,alpha);
GX_TexCoord2f32(0, 1);
GX_End();
GX_LoadPosMtxImm (view, GX_PNMTX0);
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
}
void StopGX() {
GX_AbortFrame();
GX_Flush();
VIDEO_SetBlack(TRUE);
VIDEO_Flush();
console_init(xfb[0], 20, 64, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * 2);
VIDEO_WaitVSync();
}
void resetVideo() {
GX_DrawDone(); // Tell the GX engine we are done drawing
GX_InvalidateTexAll();
fb ^= 1; // Toggle framebuffer index
GX_SetZMode (GX_TRUE, GX_LEQUAL, GX_TRUE);
GX_SetColorUpdate(GX_TRUE);
GX_CopyDisp (xfb[fb], GX_TRUE);
VIDEO_SetNextFramebuffer(xfb[fb]); // Select eXternal Frame Buffer
VIDEO_Flush(); // Flush video buffer to screen
VIDEO_WaitVSync(); // Wait for screen to update
// Interlaced screens require two frames to update
if (rmode->viTVMode &VI_NON_INTERLACE) VIDEO_WaitVSync();
}
image.c
Spoiler:
- Código: Seleccionar todo
//jpeg
JPEGIMG jpeg;
int fila, columna, pixeldoble, offset;
unsigned int *jpegout;
FILE *JPG;
int jpeglSize;
char *jpegbuffer;
size_t jpegresult;
//Png
PNGUPROP imgProp;
IMGCTX ctx;
void *data = NULL;
static int lua_imagePngLoad(lua_State *l) {
if (lua_gettop(l) != 3) return luaL_error(l, "wrong number of arguments");
const char *file = luaL_checkstring(l, 1);
int x1 = luaL_checkint(l, 2);
int y1 = luaL_checkint(l, 3);
ctx = PNGU_SelectImageFromDevice(file);
PNGU_GetImageProperties(ctx, &imgProp);
int res = PNGU_DecodeTo4x4RGBA8(ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255);
if(res == PNGU_OK) {
DCFlushRange(data, imgProp.imgWidth * imgProp.imgHeight * 4);
DrawImg(x1, y1, imgProp.imgWidth, imgProp.imgHeight, data, 0, 1, 1, 255);
} else {
free(data);
data = NULL;
}
PNGU_ReleaseImageContext (ctx);
return 1;
}
u32 *jpegfb;
static int lua_imageJpegLoad(lua_State *l) {
if (lua_gettop(l) != 3) return luaL_error(l, "wrong number of arguments");
const char *file = luaL_checkstring(l, 1);
int x1 = luaL_checkint(l, 2);
int y1 = luaL_checkint(l, 3);
JPG = fopen(file, "rb");
fseek(JPG , 0 , SEEK_END);
jpeglSize = ftell(JPG);
rewind(JPG);
jpegbuffer = (char*) malloc (sizeof(char)*jpeglSize);
jpegresult = fread(jpegbuffer,1,jpeglSize,JPG);
fclose(JPG);
memset(&jpeg, 0, sizeof(JPEGIMG));
jpeg.inbuffer = jpegbuffer;
jpeg.inbufferlength = jpeglSize;
JPEG_Decompress(&jpeg);
jpegout = (unsigned int *) jpeg.outbuffer;
offset = 0;
int i,j;
int heightjpeg = jpeg.height;
int widthjpeg = jpeg.width/2;
for(i=0;i<=widthjpeg;i++) {
for(j=0;j<=heightjpeg-2;j++) {
jpegfb[(i+x1)+320*(j+16+y1)]=jpegout[i+widthjpeg*j];
}
}
free(jpeg.outbuffer);
data=jpegfb;
DCFlushRange(data, widthjpeg * heightjpeg * 4);
DrawImg(x1, y1, widthjpeg, heightjpeg, data, 0, 1, 1, 255);
return 1;
}
main.c
Spoiler:
- Código: Seleccionar todo
#include "functions.h"
extern int luaopen_Sound(lua_State *l);
extern int luaopen_Image(lua_State *l);
extern int luaopen_System(lua_State *l);
extern int luaopen_Screen(lua_State *l);
extern int luaopen_Controls(lua_State *l);
int main() {
InitVideo();
InitOthers();
while(1) {
l = lua_open();
luaL_openlibs(l);
luaopen_Screen(l);
luaopen_System(l);
luaopen_Image(l);
luaopen_Sound(l);
luaopen_Controls(l);
GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1);
int s = luaL_loadfile(l, "script.lua");
if (s == 0) {
s = lua_pcall(l, 0, 0, 0);
}
while (s) {
StopGX();
screenCoorPrintf(2, 2,"error: %s\n", lua_tostring(l, -1));
VIDEO_WaitVSync();
lua_pop(l, 1); // remove error message
}
lua_close(l);
resetVideo();
}
return 0;
}