![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on can i have a c source code within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; can i have a c source code for a game so i can see how its put together ps- i ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#5 |
![]() |
Code:
// Holla World! - My First App for the PSP
/*
This program was created by Bob on 1/1/
*/
#include <pspkernel.h>
#include <pspdebug.h>
PSP_MODULE_INFO("Hello World", 0, 1, 1);
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
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();
printf("Hello World");
sceKernelSleepThread();
return 0;
}
__________________
If you ever need me, you can contact me at [URL="**********.net"]**********.net.[/URL] |
|
|
|
|
|
#8 |
![]() ![]() I'm Baaaack!
|
Here's a basic menu that *should* work. Somebody let me know if there's problems.
main.c Code:
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdio.h>
#include <string.h>
#include <pspctrl.h>
#include "graphics.h"
#define printc printTextCentered
#define RGB(r, g, b) ((r) | ((g) <<8) | ((b) <<16))
PSP_MODULE_INFO("Menu Example",0,1,1);
//our colors
Color yellow = RGB(255,255,0);
Color black = RGB(0,0,0);
Color blue = RGB(0,0,255);
//Custom function to print Text perfectly centered
void printTextCentered(int y,char* text,u32 color)
{
//get length of string
auto int length = strlen(text);
//take length of string and multiply by 8 since each letter is 8 pixels wide
//subtract half of that from 240 to center it
auto int x = 240 - ((length*8)/2);
//now print it to the screen using the inputed y position, text and color, and use the x coordinate we made
printTextScreen(x,y,text,color);
}
//integer to keep track of menu status
int select = 0;
//timer we'll need later
int timer = 0;
//variable we'll need later
int pos;
//table to hold menu entries
//6 options, each able to hold 50 characters including the /0 terminator
char menu[6][50] = {
{"Start"},
{"Difficulty"},
{"Sound Options"},
{"Gameplay Options"},
{"Cheat Codes"},
{"Exit"},
};
//start of main function
int main() {
//initiate graphics buffer so we can use the screen
initGraphics();
//assign variable 'pad' to the buttons
SceCtrlData pad;
//start of endless loop
while(1) {
//clear the screen yellow
clearScreen(yellow);
//initialize button input
sceCtrlReadBufferPositive(&pad, 1);
//increase the timer, so we can control button input later
timer++;
//print our 6 menu options using a for loop
for(pos=0;pos<6;pos++) {
printc((pos*10)+110,menu[pos],black);
}
//print the selected menu choice over the old one, in a different color
printc((select*10)+110,menu[select],blue);
//make it so if we press up, select decreases, but only to 0, not lower than 0
//also make it so the timer be greater than 10, so we can control the speed of the movement
if((pad.Buttons & PSP_CTRL_UP) && (select > 0) && (timer > 10)) {
//decrease select variable
select--;
//set timer to 0 to control speed
timer = 0;
}
//same thing with down button
if((pad.Buttons & PSP_CTRL_DOWN) && (select < 5) && (timer > 10)) {
//increase select variable
select++;
//set timer to 0 to control speed
timer = 0;
}
//make it so if select is equal to 5("exit" is highlighted) and we press X, it will exit
if((pad.Buttons & PSP_CTRL_CROSS) && (select == 5)) {
//exit the game
sceKernelExitGame();
}
//flip the screen so we can see everything
flipScreen();
//finish the endless loop
}
return 0;
}
Code:
TARGET = example OBJS = main.o graphics.o framebuffer.o CFLAGS = -O2 -G0 -Wall CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) LIBS = -lpspgu -lpng -lz -lm EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = Example PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak
__________________
|
|
|
|
|
|
#9 |
![]() ![]() Developer
|
C++ TicTacToe in the command window:
PDF document on how is it put together and why (WIP) http://parabellumgames.no-ip.org/art...ing-practises/ Source Code http://parabellumgames.no-ip.org/art...tactoe-source/ Dance2x for the GP2X SDL Project Page with Videos http://parabellumgames.no-ip.org/yaustar/dance2x.php Source Code http://archive.gp2x.de/cgi-bin/cfile...,0,0,0,46,1722 Report http://yaustar.pwp.blueyonder.co.uk/...fullreport.pdf PS for Dance2x, do NOT copy the commenting style in the .cpp files, I was trying a different programming method/style and I have since realised it is relatively poor in terms of maintenence.
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] Last edited by yaustar; 03-12-2007 at 04:42 AM.. |
|
|
|
![]() |
| Tags |
| code , source |
| Thread Tools | |
|
|