I was working on a little program to browse files and folders of any cd/dvd, used the libcdvdfs and gskit to display everything.
I tested the program on my pc using an emulator(I made a emulator-friendly version :p, used the GS_PERSISTENT mode, refreshing the screen only with a button press) , and it seemed to work.
I tested the same version that worked with the emulator on my SCPH-70001 ps2, and, before anything ,the screen crashed before anything showed up.
The controller seems to work, because the analog led becomes locked.
I tryed a non-emulator version, using the GS_ONESHOT mode, but tha screen crached in the same way :(
Some parts of the code I copied from samples, but the file browser itself was written by me.
Look at the code: (may look a little confusing)
Code: Select all
#include <tamtypes.h>
#include <stdio.h>
#include <kernel.h>
#include <fileio.h>
#include <malloc.h>
#include <debug.h>
#include <string.h>
#include <iopcontrol.h>
#include <iopheap.h>
#include <libpad.h>
#include "gsKit.h"
#include "dmaKit.h"
#include "irx/cdvd.h"
#include "irx/freesio2.c"
#include "irx/usbd.c"
#include "irx/freepad.c"
#include "irx/usb_mass.c" // for duture mass: compatibility.
#include <sifrpc.h>
#include <loadfile.h>
#include "cdvd.h"
#include "cdvd_rpc.h"
#define ENTRIES 30
char* padTypeStr[] = { "Unsupported controller", "Mouse", "Nejicon",
"Konami Gun", "Digital", "Analog", "Namco Gun",
"DualShock"};
u32 port;
struct padButtonStatus buttons;
int dualshock[2];
int acts[2];
static char *padBuf[2];
u32 portConnected[2];
u32 paddata[2];
u32 old_pad[2];
u32 new_pad[2];
u8 actDirect[2][6] = { {0,0,0,0,0,0}, {0,0,0,0,0,0}};
u64 White, Black, BlackFont, WhiteFont, RedFont, GreenFont, BlueFont, BlueTrans, RedTrans, GreenTrans, WhiteTrans;
GSGLOBAL *gsGlobal;
GSFONT *gsFont;
void initScreen(){
gsGlobal = gsKit_init_global(GS_MODE_PAL);
gsFont = gsKit_init_font(GSKIT_FTYPE_FONTM, NULL);
dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
dmaKit_chan_init(DMA_CHANNEL_GIF);
dmaKit_chan_init(DMA_CHANNEL_FROMSPR);
dmaKit_chan_init(DMA_CHANNEL_TOSPR);
White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
Black = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00);
BlueTrans = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x40,0x00);
RedTrans = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x60,0x00);
GreenTrans = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x50,0x00);
WhiteTrans = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x50,0x00);
WhiteFont = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
BlackFont = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x80,0x00);
RedFont = GS_SETREG_RGBAQ(0xFF,0x80,0x80,0x80,0x00);
GreenFont = GS_SETREG_RGBAQ(0x80,0xFF,0x80,0x80,0x00);
BlueFont = GS_SETREG_RGBAQ(0x80,0x80,0xFF,0x80,0x00);
gsKit_init_screen(gsGlobal);
gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
gsKit_clear(gsGlobal, White);
gsKit_font_upload(gsGlobal, gsFont);
gsKit_clear(gsGlobal, Black);
gsKit_queue_exec(gsGlobal);
gsKit_sync_flip(gsGlobal);
gsKit_mode_switch(gsGlobal, GS_ONESHOT);
}
void resetIop(){
printf("Resetando IOP...\n");
SifExitIopHeap();
SifLoadFileExit();
SifExitRpc();
if (SifIopReset("rom0:UDNL rom0:EELOADCNF",0)) printf("IOP RESETADO\n");
printf("Aguarde ate a sincronizacao do IOP...\n");
while (SifIopSync());
printf("IOP Sincronizado!\n");
}
void loadmodules(int free)
{
s32 ret;
SifExecModuleBuffer(freesio2, size_freesio2, 0, NULL, &ret);
if(ret<0) printf("Erro ao carregar modulo!!\n");
SifExecModuleBuffer(freepad, size_freepad, 0, NULL, &ret);
if(ret<0) printf("Erro ao carregar modulo!!\n");
SifExecModuleBuffer(usbd, size_usbd, 0, NULL, &ret);
if(ret<0) printf("Erro ao carregar modulo!!\n");
SifExecModuleBuffer(usb_mass, size_usb_mass, 0, NULL, &ret);
if(ret<0) printf("Erro ao carregar modulo!!\n");
}
void padWait(int port)
{
/* Wait for request to complete. */
while(padGetReqState(port, 0) != PAD_RSTAT_COMPLETE);
//wait_vsync();
/* Wait for pad to be stable. */
while(padGetState(port, 0) != PAD_STATE_STABLE);
//wait_vsync();
}
int getCdvdPath(char* path){
static struct TocEntry* TocEntryList;
int selected = 0, liststart = 0, listend = liststart + ENTRIES;
int y=0;
int request = 1;
int printrequest = 1; // For the emulator version
char pathname[128] = "/";
int numfiles, filenum, end = 0;
TocEntryList = memalign(64,1000*sizeof(struct TocEntry));
char EntryList[1000][64];
while(!end){
if(selected<liststart) liststart--;
if (selected>=listend) liststart++;
listend = liststart + ENTRIES;
if(request){
numfiles = CDVD_GetDir(pathname, NULL, CDVD_GET_FILES_AND_DIRS, TocEntryList,1000, pathname);
request=0;
}
if(printrequest){
for(filenum=0; filenum < numfiles; filenum++)
{
if(TocEntryList[filenum].fileProperties & 0x02){
if(filenum == selected) sprintf(EntryList[filenum], "/%s*", TocEntryList[filenum].filename);
else sprintf(EntryList[filenum], "/%s", TocEntryList[filenum].filename);
}
else {
if(filenum == selected) sprintf(EntryList[filenum], "%s*", TocEntryList[filenum].filename);
else sprintf(EntryList[filenum], "%s", TocEntryList[filenum].filename);
}
}
y=20;
char mensagem[64];
sprintf(mensagem, "Número de arquivos e pastas: %d", numfiles);
gsKit_font_print_scaled(gsGlobal, gsFont, 0, y, 5, 0.5f, WhiteFont, mensagem);
y+=12;
for(filenum = liststart; filenum<listend && filenum<numfiles; filenum++)
{
gsKit_font_print_scaled(gsGlobal, gsFont, 0, y, 5, 0.5f, WhiteFont, EntryList[filenum]);
y+=12;
}
/* For the emulator version
gsKit_queue_exec(gsGlobal);
gsKit_sync_flip(gsGlobal);
printrequest = 0;*/
}
if(1){
s32 state = padGetState(port, 0);
if((state == PAD_STATE_STABLE) && (portConnected[port] == 0))
{
u32 i;
u8 mTable[8];
u32 ModeCurId;
u32 ModeCurOffs;
u32 ModeCurExId;
u32 ModeTableNum = padInfoMode(port, 0, PAD_MODETABLE, -1);
printf("Controller (%i) connected\n", port);
/* Check if dualshock and if so, activate analog mode */
for(i = 0; i < ModeTableNum; i++)
mTable[i] = padInfoMode(port, 0, PAD_MODETABLE, i);
/* Works for dualshock2 */
if((mTable[0] == 4) && (mTable[1] == 7) && (ModeTableNum == 2))
dualshock[port] = 1;
/* Active and lock analog mode */
if(dualshock[port] == 1)
{
padSetMainMode(port, 0, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK);
padWait(port);
}
ModeCurId = padInfoMode(port, 0, PAD_MODECURID, 0);
ModeCurOffs = padInfoMode(port, 0, PAD_MODECUROFFS, 0);
ModeCurExId = padInfoMode(port, 0, PAD_MODECUREXID, 0);
ModeTableNum = padInfoMode(port, 0, PAD_MODETABLE, -1);
acts[port] = padInfoAct(port, 0, -1, 0);
printf(" ModeCurId : %i (%s)\n", (int)ModeCurId, padTypeStr[ModeCurId]);
printf(" ModeCurExId : %i\n", (int)ModeCurExId);
printf(" ModeTable : ");
for(i = 0; i < ModeTableNum; i++)
{
mTable[i] = padInfoMode(port, 0, PAD_MODETABLE, i);
printf("%i ", (int)mTable[i]);
}
printf("\n");
printf(" ModeTableNum : %i\n", (int)ModeTableNum);
printf(" ModeCurOffs : %i\n", (int)ModeCurOffs);
printf(" NumOfAct : %i\n", (int)acts[port]);
printf(" PressMode : %i\n", (int)padInfoPressMode(port, 0));
if(acts[port] > 0)
{
u8 actAlign[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
u32 i;
/* Set offsets for motor parameters for SetActDirect. */
for(i=0; i < acts[port]; i++)
actAlign[i] = i;
padSetActAlign(port, 0, actAlign);
padWait(port);
}
printf(" EnterPressMode : %i\n", (int)padEnterPressMode(port, 0));
padWait(port);
printf("Ready\n");
portConnected[port] = 1;
}
if((state == PAD_STATE_DISCONN) && (portConnected[port] == 1))
{
printf("Controller (%i) disconnected\n", port);
portConnected[port] = 0;
}
if(portConnected[port] == 1)
{
s32 ret = padRead(port, 0, &buttons);
if(ret != 0)
{
paddata[port] = 0xffff ^ buttons.btns;
new_pad[port] = paddata[port] & ~old_pad[port];
old_pad[port] = paddata[port];
if(new_pad[0] & PAD_UP){
printrequest = 1;
if(selected>0) selected--;
}
if(new_pad[0] & PAD_DOWN){
printrequest = 1;
if(selected<numfiles-1) selected++;
}
if(new_pad[0] & PAD_RIGHT)
{
if(EntryList[selected][0] == '/'){
request = 1; printrequest = 1;
strncat(pathname, TocEntryList[selected].filename, 32);
selected = 0;
}
else{
if(strlen(pathname) > 1)
strncat(pathname, "/", 32);
strncat(pathname, TocEntryList[selected].filename, 32);
sprintf(path, "cdfs:%s", pathname);
return 1;
}
}
if(new_pad[0] & PAD_LEFT)
{
request = 1; printrequest = 1;
int position = strlen(pathname);
while(pathname[position] != '/') position--;
memset(&pathname[position], 0, strlen(pathname));
if(strlen(pathname) == 1)
end = 1;
}
}
}
}
gsKit_queue_exec(gsGlobal);
gsKit_sync_flip(gsGlobal);
} //end
return 0;
}
int main(){
resetIop();
SifInitRpc(0);
s32 rv;
SifExecModuleBuffer(cdvd, size_cdvd, 0, NULL, &rv);
loadmodules(1);
padInit(0);
padBuf[0] = memalign(64, 256);
padBuf[1] = memalign(64, 256);
old_pad[0] = 0;
old_pad[1] = 0;
portConnected[0] = 0;
portConnected[1] = 0;
dualshock[0] = 0;
dualshock[1] = 0;
acts[0] = 0;
acts[1] = 0;
padPortOpen(0, 0, padBuf[0]);
padPortOpen(1, 0, padBuf[1]);
initScreen();
CDVD_Init();
CDVD_DiskReady(CdBlock);
gsKit_font_print_scaled(gsGlobal, gsFont, 350, 80, 5, 0.5f, WhiteFont, "Teste"); //For testing purposes
gsKit_mode_switch(gsGlobal, GS_ONESHOT);
gsKit_font_print_scaled(gsGlobal, gsFont, 20, 20, 5, 0.5f, WhiteFont, "Teste2");
gsKit_queue_exec(gsGlobal);
gsKit_sync_flip(gsGlobal);
char teste[64];
if(getCdvdPath(teste)){//if 1 show part of the file on the screen
gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
gsKit_font_print_scaled(gsGlobal, gsFont, 50, 350, 5, 0.5f, WhiteFont, "O usuario escolheu: ");
gsKit_font_print_scaled(gsGlobal, gsFont, 50, 365, 5, 0.5f, WhiteFont, teste);
FILE * pFile;
pFile = fopen ( teste , "r" );
long lSize;
char * buffer;
size_t result;
if (pFile==NULL) {fputs ("File error",stderr); exit (1);}
// obtain file size:
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
// allocate memory to contain the whole file:
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
// copy the file into the buffer:
result = fread (buffer,1,lSize,pFile);
if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
// the whole file is now loaded in the memory buffer.
int a;
for(a=0; a<400; a+=25){
char buffer2[50];
memset(buffer2, 0, sizeof(buffer2));
memcpy(buffer2, &buffer[a], 25);
gsKit_font_print_scaled(gsGlobal, gsFont, 0, a, 5, 0.5f, WhiteFont, buffer2);
gsKit_queue_exec(gsGlobal);
gsKit_sync_flip(gsGlobal);
}
// terminate
//fclose (pFile);
//free (buffer);
}
else{
gsKit_mode_switch(gsGlobal, GS_PERSISTENT);
gsKit_clear(gsGlobal, Black);
gsKit_queue_exec(gsGlobal);
gsKit_sync_flip(gsGlobal);
gsKit_clear(gsGlobal, Black);
gsKit_font_print_scaled(gsGlobal, gsFont, 100, 100, 5, 0.5f, WhiteFont, "O usuário não escolheu nada!!!\n");}
while(1){
gsKit_queue_exec(gsGlobal);
gsKit_sync_flip(gsGlobal);
}
return 0;
}
}
Code: Select all
CDVD = $(PS2DEV)/libcdvd
EE_BIN = Path.elf
EE_OBJS = PathGet.o
EE_LDFLAGS += -L$(CDVD)/lib
EE_LIBS += -lkernel -lcdvdfs -ldebug -lpadx -lgskit
EE_INCS += -I $(CDVD)/ee
all: $(EE_BIN)
clean:
rm -f *.elf *.o *.a
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
# Include the GsKit Makefile.global, thai I modified
include Makefile.global
Someone can hekp me?
Thanks!
ps.: I am using the latest fully compiled GSHI-ps2sdk, which comes with the gsKit and the libcdvdfs.