sceDisplayGetFrameBuf() fails, Bufferwidth / Pixelformat = 0

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
J-Fox
Posts: 15
Joined: Wed Sep 26, 2007 12:25 am
Location: Hannover, Germany

sceDisplayGetFrameBuf() fails, Bufferwidth / Pixelformat = 0

Post by J-Fox »

Hey, I m currently having a problem getting my code to work:

Code: Select all

#include <pspkernel.h>
#include <pspdisplay.h>
#include <stdio.h>
#include <string.h>

PSP_MODULE_INFO&#40;"MSUpdate", 0x1000, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

static int bufferwidth, pixelformat, unk, fd;
static u32* vram32;
static char cancel, format&#91;512&#93;;

void add_log&#40;const char* Text&#41;
&#123;
	fd = sceIoOpen&#40;"ms0&#58;/msupdate.txt", PSP_O_WRONLY | PSP_O_APPEND, 0777&#41;;
	sceIoWrite&#40;fd,Text,strlen&#40;Text&#41;&#41;;
	sceIoWrite&#40;fd,"\n",strlen&#40;"\n"&#41;&#41;;
	sceIoClose&#40;fd&#41;;
&#125;

int loop&#40;SceSize args, void *argp&#41;
&#123;
	add_log&#40;"Waiting"&#41;;
	sceKernelDelayThread&#40;1000*5000&#41;;
	add_log&#40;"Loop"&#41;;
	while&#40;!cancel&#41; 
	&#123;	
		sceDisplayWaitVblankStart&#40;&#41;;
		sceDisplayGetFrameBuf&#40;&#40;void*&#41;&vram32, &bufferwidth, &pixelformat, &unk&#41;;
		if&#40;bufferwidth!=0&#41;
		&#123;
			int x; int y;
			for &#40;x=0;x<20;x++&#41;
			&#123;
				for &#40;y=0;y<20;y++&#41;
				&#123;
					vram32&#91;x + y*bufferwidth&#93; = 0xffff00ff;
				&#125;
			&#125;
		&#125; else &#123;
			sprintf&#40;format,"Buffer-Width&#58; %i, %i",bufferwidth, pixelformat&#41;;
			add_log&#40;format&#41;;
			add_log&#40;"Error"&#41;;
			cancel=1;
		&#125;
	&#125;
	add_log&#40;"Quit"&#41;;
	return 0;
&#125;

int module_start&#40;int argc, char **argv&#41;
&#123;
	fd = sceIoOpen&#40;"ms0&#58;/msupdate.txt", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;;
	sceIoClose&#40;fd&#41;;
	add_log&#40;"MSUpdate 0.1"&#41;;	
	int thid = sceKernelCreateThread&#40;"MSUpdate", loop, 0x20, 0x1000, 0, 0&#41;;

	sprintf&#40;format,"Thread&#58; %i",thid&#41;;
	add_log&#40;format&#41;;

	if&#40;thid >= 0&#41; sceKernelStartThread&#40;thid, 0, 0&#41;;
	return 0;
&#125;

Code: Select all

TARGET = msupdate
OBJS = main.o

BUILD_PRX=1
PRX_EXPORTS=exports.exp

USE_KERNEL_LIBS = 1
USE_KERNEL_LIBC = 1

LIBS = -lpspkernel
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;
LDFLAGS = -nostdlib -nodefaultlibs

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
All this returns is:

Code: Select all

MSUpdate 0.1
Thread&#58; 73806443
Waiting
Loop
Buffer-Width&#58; 0, 0
Error
Quit
meaning that bufferwidth and pixelformat are 0. Now I wonder why...
GetVideoMode returns 480x272 so there doesnt seem to be a problem with the display calls in general.

The whole thing is running on 3.71 M33 (PSP1000) and 3.71 M33 (PSP2000), both having the same problem. Any ideas?

//Edit: This is supposed to draw a 20x20px box on the screen starting at the upper left corner in the XMB. It is loaded using the Recovery menu -> Plugins from VSH.txt
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

did you fix nids before attempting this?
0xDEA197D4 [0x00001E6C] - sceDisplayGetMode => this wasn't touched by sony while get framebuffer was
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

The last arg for sceDisplayGetFrameBuf() is not &unk, it's the same as sceDisplaySetFrameBuf - a constant of either PSP_DISPLAY_SETBUF_IMMEDIATE or PSP_DISPLAY_SETBUF_NEXTFRAME.
J-Fox
Posts: 15
Joined: Wed Sep 26, 2007 12:25 am
Location: Hannover, Germany

Post by J-Fox »

weltall:
I havent works with nids before and i wasnt able to find any helpful posts on the forum either about this topic, however: i assumed adding an ASM Stub would help:

Code: Select all

.set noreorder
#include "pspstub.s"
STUB_START "sceDisplay_driver", 0x40010000, 0x00010005
STUB_FUNC 0xEEDA2E54, sceDisplayGetFrameBuf
STUB_END
I added this to the "OBJS" but it didnt really help either. (I m pretty sure i m doing something wrong here :P, the first param for STUB_FUNC was taken from http://silverspring.lan.st/3.5x/index.html btw, since i wasnt able to find any newer version for 3.7x)

J.F.:
Yeh i read about this in another topic, but i had an outdated toolchain which still had the wrong parameters, so i decided to put it like that so it doesnt bitch on every compile (it didnt work anyways ;) )

//Edit:

Just changed the stub to:

Code: Select all

.set noreorder
#include "pspstub.s"
STUB_START "sceDisplay", 0x40010000, 0x00010005
STUB_FUNC 0xEEDA2E54, sceDisplayGetFrameBuf
STUB_END
And its still not working, BUT i m kinda sure that the nid is correct cause i tried using prxtool on Coolj's screenshot plugin which is using exactly the same imports! Somehow i start to believe that the function can only be called from usermode or something weird

//Edit:

_______________________________________________________

Working solution


makefile

Code: Select all

TARGET = msupdate
OBJS = main.o

BUILD_PRX=1
PRX_EXPORTS=exports.exp

INCDIR = 
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
main.c

Code: Select all

#include <pspuser.h> 
#include <pspdisplay.h> 
#include <stdio.h> 
#include <string.h> 

PSP_MODULE_INFO&#40;"MSUpdate", 0x0, 1, 1&#41;; 
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;; 

static int bufferwidth, pixelformat, fd; 
static char cancel, format&#91;512&#93;; 
static u32* vram32;  


void add_log&#40;const char* Text&#41; 
&#123; 
   fd = sceIoOpen&#40;"ms0&#58;/msupdate.txt", PSP_O_WRONLY | PSP_O_APPEND, 0777&#41;; 
   sceIoWrite&#40;fd,Text,strlen&#40;Text&#41;&#41;; 
   sceIoWrite&#40;fd,"\r\n",strlen&#40;"\r\n"&#41;&#41;; 
   sceIoClose&#40;fd&#41;;   
&#125; 
int main&#40;int argc, char **argv&#41; 
&#123; 
   fd = sceIoOpen&#40;"ms0&#58;/msupdate.txt", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;; 
   sceIoClose&#40;fd&#41;; 
   add_log&#40;"MSUpdate 0.1"&#41;;    
   add_log&#40;"Waiting"&#41;; 
   int i;
   for &#40;i=0;i<60*5;i++&#41;
   &#123;
      sceDisplayWaitVblankStart&#40;&#41;; 
   &#125;
   add_log&#40;"Loop"&#41;; 
   while&#40;!cancel&#41; 
   &#123;    
      sceDisplayWaitVblankStart&#40;&#41;; 
      sceDisplayGetFrameBuf&#40;&#40;void*&#41;&vram32, &bufferwidth, &pixelformat, 0&#41;; 
      if&#40;bufferwidth!=0&#41; 
      &#123; 
         int x; int y; 
         for &#40;x=0;x<20;x++&#41; 
         &#123; 
            for &#40;y=0;y<20;y++&#41; 
            &#123; 
               vram32&#91;x + y*bufferwidth&#93; = 0xffff00ff; 
            &#125; 
         &#125; 
      &#125; else &#123; 
         sprintf&#40;format,"Display Data&#58; %i, %i",bufferwidth, pixelformat&#41;; 
         add_log&#40;format&#41;;  
	   for &#40;i=0;i<60*5;i++&#41;
	   &#123;
      	sceDisplayWaitVblankStart&#40;&#41;; 
	   &#125;
      &#125;
   &#125; 
   add_log&#40;"Quit"&#41;; 
   return 0; 
&#125;
I m still asking myself: WHY... Can't see a reason why it havent worked before. However, shouldnt be too hard to find out
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

because before you had a wrong nid (the nid you posted isn't right on 3.71)
while the other is an improper plugin as it's user mode and could give problems to homebrews and games (just like the screenshoot plugin for 3.71)
nids for user weren't changed so now it seems to work.
if you want to do a proper plugin please fix that nid with the new one you may use prxtool to easily get it (tyranid did an update to it to make this easier yesterday) and build it in kernel mode
Post Reply