| |||||||
| Register | Top Posters | FAQ | PSP Downloads | Arcade | Wallpapers | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| GamingCrazy Novice ![]() | C Snippets/Help Section So...your new to coding and you don't know where to start? Some great tutorials by 'Yeldarb' have been written for people in your position. His tutorials cover everything from setting up your development environment, right into displaying your first image on-screen. His tutorials even go into enough depth as to show you how to get MP3s running within your games! His tutorials can be seen on the following pages: [Only registered and activated users can see links. ] [Only registered and activated users can see links. ] [Only registered and activated users can see links. ] [Only registered and activated users can see links. ] [Only registered and activated users can see links. ] [Only registered and activated users can see links. ] And now...some snippets of code in C you may find useful: (more to come) USB MODE By: Slasher Headers: Code: #include <pspkernel.h> #include <pspdisplay.h> #include <pspusb.h> #include <pspusbstor.h> #include <string.h> Code:
// Defines
#define printf pspDebugScreenPrintf
// Functions
int LoadStartModule(char *path) {
u32 loadResult;
u32 startResult;
int status;
loadResult = sceKernelLoadModule(path, 0, NULL);
if (loadResult & 0x80000000) return -1;
else
startResult = sceKernelStartModule(loadResult, 0, NULL, &status, NULL);
if (loadResult != startResult) return -2;
return 0;
}
void initUSB() {
u32 retVal;
LoadStartModule("flash0:/kd/semawm.prx");
LoadStartModule("flash0:/kd/usbstor.prx");
LoadStartModule("flash0:/kd/usbstormgr.prx");
LoadStartModule("flash0:/kd/usbstorms.prx");
LoadStartModule("flash0:/kd/usbstorboot.prx");
retVal = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0);
if (retVal != 0) {
printf("Error starting USB Bus driver (0x%08X)\n", retVal);
sceKernelSleepThread();
}
retVal = sceUsbStart(PSP_USBSTOR_DRIVERNAME, 0, 0);
if (retVal != 0) {
printf("Error starting USB Mass Storage driver (0x%08X)\n", retVal);
sceKernelSleepThread();
}
retVal = sceUsbstorBootSetCapacity(0x800000);
if (retVal != 0) {
printf("Error setting capacity with USB Mass Storage driver (0x%08X)\n", retVal);
sceKernelSleepThread();
}
retVal = 0;
}
void usbMode(char * what) {
u32 retVal;
if (stricmp(what, "on")==0) {
retVal = sceUsbActivate(0x1c8);
}
else if (stricmp(what, "off")==0) {
retVal = sceUsbDeactivate();
}
}
Code: initUSB(); Code: usbMode("on");
or
usbMode("off");
Code: In LIBS= -lpspusb -lpspusbstor FADE SPLASH SCREEN By: Samstag Headers: Your going to need to follow the tutorials [Only registered and activated users can see links. ] to get basic images blitting with graphics.c/h and framebuffer.c/h Your going to also need [Only registered and activated users can see links. ] files. Code: #include <pspdisplay.h> #include <pspctrl.h> #include <pspkernel.h> #include <pspdebug.h> #include <pspgu.h> #include <png.h> #include <stdio.h> #include "graphics.h" #include "framebuffer.h" Code:
/*
Features:
- Modifies an entire image for fading effects
- Takes a percentage input of 0 (transparent) to 100 (opaque)
Inputs:
- Image* image - valid Image pointer from the loadImage(filename) function in Yeldarb's tutorial #4
- unsigned char alpha - a number from 0-100
*/
void set_image_alpha(Image *image, unsigned char alpha) {
int i, size;
Color *pixel;
unsigned int alpha_mod;
if(!image || !image->data) return;
size = image->textureWidth * image->textureHeight;
pixel = image->data;
if(alpha > 100) alpha = 100;
alpha_mod = ((alpha * 255) / 100) << 24;
for(i = 0; i <= size; i++) {
*pixel = (*pixel & 0x00ffffff) | alpha_mod;
pixel++;
}
}
/*
Features:
- Centers undersized images on a black background
- Fades in the image at a rate you set
- After fade-in, it will wait X seconds or any button press
Inputs:
- Image* pic - a valid Image pointer from the loadImage(filename) function in Yeldarb's tutorial #4
- int fade_rate - the speed to fade the image in (higher = faster)
- int timeout - time in seconds to display the image after the fade is complete
*/
Code: Image* intro1;
Image* intro2;
intro1 = loadImage("title_screen.png");
intro2 = loadImage("credits_screen.png");
if(intro1) {
show_splash(intro1, 8, 4);
freeImage(intro1);
}
if(intro2) {
show_splash(intro2, 8, 4);
freeImage(intro2);
}
Put this in your 'Makefile': Code: In OBJS= graphics.o framebuffer.o In LIBS= -lpspgu -lpng -lz -lm Last edited by Slasher; 04-24-2006 at 10:08 PM.. |
| | |
| Sponsored Links | |
| | |
| | #2 (permalink) |
| GamingCrazy Newbie ![]() | Re: Source Codes here's a simple code. this will load a bg pic for your program #include<pspdisplay.h> #include<pspctrl.h> #include<pspkernel.h> #include<pspdebug.h> #include<pspgu.h> #include<png.h> #include<stdio.h> #include"graphics.h" #define printf pspDebugScreenPrintf #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) PSP_MODULE_INFO("Image Display Program", 0, 1, 1); /* 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, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } int main() { pspDebugScreenInit(); SetupCallbacks(); initGraphics(); // Draw BG Pic char buffer[200]; Image* ourImage; sprintf(buffer, "ms0:/loader/backpic.png"); // this prevents a buffer overflow ourImage = loadImage(buffer); sceDisplayWaitVblankStart(); blitAlphaImageToScreen(0 ,0 ,480 , 272, ourImage, 0, 0); flipScreen(); // Next sceKernelSleepThread(); return 0; } regards chossy Last edited by Slasher; 04-24-2006 at 10:00 PM.. |
| | |