forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with cdvdfs/gsKit

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
methos3



Joined: 01 Feb 2008
Posts: 89

PostPosted: Mon Jan 05, 2009 11:02 pm    Post subject: Help with cdvdfs/gsKit Reply with quote

Hello! I need help again :(
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:

#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;
}


}



Here's the Makefile:

Code:

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


I am using the freepad.irx module because it's free and because I need multitap-compatibility on all of my programs.

Someone can hekp me?
Thanks!

ps.: I am using the latest fully compiled GSHI-ps2sdk, which comes with the gsKit and the libcdvdfs.


Last edited by methos3 on Tue Jan 06, 2009 2:13 am; edited 1 time in total
Back to top
View user's profile Send private message
methos3



Joined: 01 Feb 2008
Posts: 89

PostPosted: Tue Jan 06, 2009 2:10 am    Post subject: Reply with quote

Ok, I tested the same program in debug mode (scr_printf), and the little file browser worker perfectly on my ps2!
It's something with the gsKit?
I used the same initScreen() function with another rpogram that I made one week ago (a cool virtual keyboard :D ), and it works, but... mixed with the cdvdlib, the screen craches! Blank rectangles apear from the bottom to the midle of the screen (6 or 7 rectangles, everytime they appear in the same position!), and nothing else will show up on the screen.
I've tryed NTSC and PAL modes (my ps2 is connected to the TV via Component AV cable, so the color system doesn't matter).

Thx again to those who could help me.
Back to top
View user's profile Send private message
cosmito



Joined: 04 Mar 2007
Posts: 314
Location: Portugal

PostPosted: Tue Jan 06, 2009 9:06 am    Post subject: Reply with quote

methos3 wrote:
but... mixed with the cdvdlib, the screen craches

Did you compiled the cdvdlib or used an already compiled version?
If the latter case, if compiled against an older version of ps2sdk than your, then the weird issues may be justified.
Back to top
View user's profile Send private message Visit poster's website
methos3



Joined: 01 Feb 2008
Posts: 89

PostPosted: Tue Jan 06, 2009 10:05 pm    Post subject: Reply with quote

Mmm, I downloaded the newest cdvdlib from the website and the newest gsKit from the svn, compiled, and applied this to my project, but... Looks like the cdvdlib needs the ps2lib to be compiled, not the ps2sdk.
But I will test on my ps2 later and post the results.
Cya!

[edit]
Worked!!!!
I re-downloaded and compiled the gsKit and the libcdvd, then put the program to run, and the screen weren't "crashed" anymore -just black this time :D - and I spent some time, putting debug messages in the persistent mode to se why this black screen, and discovered that the ps2 hangs when hit this block:
Code:

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);

I probably besause the var mensagem[64] was being declared in a while() loop.
I removed these damm lines and now the program works, thanks!!
Now I can continue my little project.

ps.: here goes a translation:
Code:

char message[64];
sprintf(mensagem, "Number of fils and dirs: %d", numfiles);
    gsKit_font_print_scaled(gsGlobal, gsFont, 0, y, 5, 0.5f,  WhiteFont, message);
Back to top
View user's profile Send private message
cosmito



Joined: 04 Mar 2007
Posts: 314
Location: Portugal

PostPosted: Thu Jan 08, 2009 12:40 am    Post subject: Reply with quote

Nice to hear that. By the way :
methos3 wrote:
I used the same initScreen() function with another rpogram that I made one week ago (a cool virtual keyboard :D )

I've got curious about your virtual keyboard... Can you give some details about it? Was it done to be re-usable? There are some nice v.keyboards for the PSP but as far I can remember, the only one I've seen for the PS2 was the one implemented into PS2VICE.

Can you give us a binary built example of it? Or the source if you are willing to?
Back to top
View user's profile Send private message Visit poster's website
methos3



Joined: 01 Feb 2008
Posts: 89

PostPosted: Thu Jan 08, 2009 2:48 am    Post subject: Reply with quote

Mmm...
I made it for personal use, I didn't think that there weren't anything better.
Yes, I made it to be used in all of my programs, but with minor changes it can be used with any other programs.
I used the freepad.irx module, and the iop have to be reseted in order to use it.
I am still developing a better version, with good graph effects, and a button to switch between upper and lower case.

The keyboard is based on this function:
int getString(char* String, int mode);
where mode can be 0 for normal and 1 for numeric mode.

For now I am working on another part of my project (cdvd/usb mass readings), and will improve the keyboard later, just wait two or three days until I finish everything.

By the way, do you know if I can use that usbhdfsd.irx module in place of that usb_mass.irx? I saw on the readme file:
"This project is based directly off the original "USB_MASS" project. I've removed the PC testing stuff like VFAT, etc
and some of the debugging things. I've also removed the RPC server. In addition I split some files up into
more files and renamed other files."
What's this RPC server?
Back to top
View user's profile Send private message
methos3



Joined: 01 Feb 2008
Posts: 89

PostPosted: Sat Jan 10, 2009 11:49 am    Post subject: Reply with quote

Hey, my keybard is ready for commercial use ;)
But...
I couldn't make a function to print the actual string on the screen with line breaks, the better that I could do was a a function that return -1 some of its words (words, no t the thole string) surpass the max char number per line.
But... if you use a max char number (per line) of 40 or more it won't give much trouble.

Unless if you have a good sugestion to do this.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group