This is my main.c
Code: Select all
//Headers are here
PSP_MODULE_INFO("DL_File", 0x0800, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_VSH);
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
   sceKernelExitGame();
   return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
   int cbid;
   cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
   sceKernelRegisterExitCallback(cbid);
   sceKernelSleepThreadCB();
   return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
   int thid = 0;
   thid = sceKernelCreateThread("update_thread", CallbackThread,
                 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0);
   if(thid >= 0)
   {
      sceKernelStartThread(thid, 0, 0);
   }
   return thid;
}
int connect_to_apctl(int config)
{
  int sceWlanGetSwitchState(void);  
  int err;
  int stateLast = -1;
  if (sceWlanGetSwitchState() != 1)
    pspDebugScreenClear();
  while (sceWlanGetSwitchState() != 1)
  {
    pspDebugScreenSetXY(0, 0);
    printf("enable WLAN to continue.\n");
    sceKernelDelayThread(1000 * 1000);
  }
  err = sceNetApctlConnect(config);
  if (err != 0)
  {
    printf("sceNetApctlConnect returns %08X\n", err);
    return 0;
  }
  printf("Connecting...\n");
  while (1)
  {
    int state;
    err = sceNetApctlGetState(&state);
    if (err != 0)
    {
      printf("sceNetApctlGetState returns $%x\n", err);
      break;
    }
    if (state != stateLast)
    {
      printf(" Connection state %d of 4.\n", state);
      stateLast = state;
    }
    if (state == 4)
    {
      break;
    }
    sceKernelDelayThread(50 * 1000);
  }
  printf("connected!\n");
  sceKernelDelayThread(3000 * 1000);
  if (err != 0)
  {
    return 0;
  }
  return 1;
}
char *getconfname(int confnum)
{
     static char confname[128];
     sceUtilityGetNetParam(confnum, PSP_NETPARAM_NAME, (netData *)confname);
     return confname;
}
int net_thread(SceSize args, void *argp)
{
  int selComponent = 1;
 
  printf("Connection %d (%s) to connect...\n", selComponent, getconfname(selComponent));
  if (connect_to_apctl(selComponent))
  {
    char szMyIPAddr[32];
    if (sceNetApctlGetInfo(8, szMyIPAddr) != 0)
    {
           strcpy(szMyIPAddr, "unknown IP address");
           printf("ip: %s\n", szMyIPAddr);
           sceKernelSleepThread();
    }
  }  
  return 0;
}
int InitialiseNetwork(void)
{
  int err;
  
  //Load the Network modules
  printf("load network modules... ");
  
  err = sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON);  
  if (err != 0)
  {
    printf("Error, could not load PSP_NET_MODULE_COMMON %08X\n", err);
    return 1;
  }
  
  err = sceUtilityLoadNetModule(PSP_NET_MODULE_INET);  
  if (err != 0)
  {
    printf("Error, could not load PSP_NET_MODULE_INET %08X\n", err);
    return 1;
  }
  
  printf("Done\n");
  err = pspSdkInetInit();  
  if (err != 0)
  {
    printf("Error, could not initialize the network %08X\n", err);
    return 1;
  }
  
   //Now the http modules
   if (sceUtilityLoadNetModule(PSP_NET_MODULE_PARSEURI) < 0)
   {
         // error here
         printf("Error, Could Not initialize the Net module PARSEURI\n");
    
    return 1;
   }
  if (sceUtilityLoadNetModule(PSP_NET_MODULE_PARSEHTTP) < 0)
  {
         // error here
         printf("Error, Could Not initialize the Net module PARSEHTTP\n");
    
    return 1;
  }
  if (sceUtilityLoadNetModule(PSP_NET_MODULE_HTTP) < 0)
  {
         // error here
         printf("Error, Could Not initialize the Net module HTTP\n");
    
    return 1;
  } 
  
  return 0;
}
/* Simple thread */
int main(int argc, char **argv)
{
   SceUID thid;
   SetupCallbacks();
   pspDebugScreenInit();
   
   pspDebugScreenClear();
   
   if (InitialiseNetwork() != 0)
   {
      printf("Error! Network Couldn't be Initialised\n");
      sceKernelSleepThread();
   }
  thid = sceKernelCreateThread("net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL);
  if (thid < 0)
  {
    printf("thread couldnt be created!\n");
    sceKernelSleepThread();
  }
  sceKernelStartThread(thid, 0, NULL);
	
	pspDebugScreenSetTextColor(0xFFFFF1);
	printf("Some text crap\n");
	while (1)
	{
          SceCtrlData pad;
          
		sceCtrlReadBufferPositive(&pad, 1);
		if (pad.Buttons & PSP_CTRL_CROSS)
		{                       
			break;
		}
		else if (pad.Buttons & PSP_CTRL_RTRIGGER)
		{
			sceKernelExitGame();
		}
		sceKernelDelayThread(10000);
	}
	
    char *the_url = "http://someweb.com/file.bin";
    
    u8 buf[100*1024] __attribute__((aligned(64))); // this should go as global var
    
    u32 filesize;
    int nbytes;
    
    if (sceHttpInit(20000) < 0)
    {
         // error here
         printf("Error\n");
    
    } 
    int template = sceHttpCreateTemplate("MyUserAgent/0.0.1 libhttp/1.0.0", 1, 1);
    if (template < 0)
    {
         // error here
         printf("Error\n");
         
    } 
    if (sceHttpSetResolveTimeOut(template, 3000000) < 0)
    {
         // error here
         printf("Error\n");
         
    } 
    if (sceHttpSetRecvTimeOut(template, 60000000) < 0)
    {
         // error here
         printf("Error\n");
         
    } 
    if (sceHttpSetSendTimeOut(template, 60000000) < 0)
    {
         // error here
         printf("Error\n");
         
    } 
  
    int connection = sceHttpCreateConnectionWithURL(template, the_url, 0);
    if (connection < 0)
    {
         // error here
         printf("Error\n");
         
    } 
    int request = sceHttpCreateRequestWithURL(connection, 0, the_url, 0);
    if (request < 0)
    {
         // error here
         printf("Error\n");
         
    } 
    if (sceHttpSendRequest(request, 0, 0) < 0)
    {
         // error here
         printf("Error\n");
         
    } 
    int status = sceHttpGetStatusCode(request, &status);
    if (status != 200)
    {
         // error here
         printf("Error\n");
         
    } 
  
    if (sceHttpGetContentLength(request, &filesize) < 0)
    {
         // error here
         printf("Error\n");
         
    } 
    printf("File size = %d\n", filesize);
    while ((nbytes = sceHttpReadData(request, buf, sizeof(buf))) != 0)
    {
       if (nbytes < 0)
       {
         // error here, abort loop
         printf("Error\n");
         
       } 
       // Write nbytes to a file or whatever
    }    
   return 0;
} 
 
Now my makefile, i sorta adapt this makefile to everything so it may be wrong as usual, im using the kernels 3.XX or 1.50 either one. atm im using the 3.XX
Code: Select all
TARGET = DL_File
OBJS = main.o HttpRequest.o HttpPacket.o HttpResponse.o
INCDIR = 
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LIBS = sceHttp.S -lpsppower -lpspgu -lz -lm -lpspwlan sceWlanDrv_lib.S sceWlanDrv.S
LDFLAGS =
PSP_FW_VERSION = 340
BUILD_PRX = 1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = DL_File
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
I know im going wrong, just can't correct it, It compiles for me, but doesnt load now? it gets past the gameboot then....Black Screen. Idea's anyone.
i also tried in user,
Code: Select all
PSP_MODULE_INFO("DL_File", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER); 
Do i need to add more stuff??, take stuff out, lol.