this is C/C++? right? because it doesn't look it to me:rolleyes:
because i asked for it in C/C++
Printable View
this is C/C++? right? because it doesn't look it to me:rolleyes:
because i asked for it in C/C++
It's C:Zitat:
Zitat von Kwastie
http://www.cplusplus.com/fopen
sorry :( i tought he was wrong..
At the moment my code breaks everytime i press enter. Would i have to put getchar(); in certain places?
Run the game via commandlin not by double clicking on .exe. It's a console program, so it would normally be running from the console.Zitat:
Zitat von eldiablov
oh that makes sense. Thanks again yaustar :)
It's a pain, I know but some IDEs like Visual Studio and Code::Blocks will automatically wait for user input before closing if it was executed within the IDE.
Edit: Never mind.
No wonder answered my question before. How do you "dofile" (lua) something in C? Also, is it possible to load lua scripts from C? That would be really cool, but it sounds hard.
There isn't one that works in the same way. The closest is the #include preprocessor.Zitat:
Zitat von Xylem
http://www.gamedev.net/reference/art...rticle1798.asp
You can. That is the whole point of scripting languages.Zitat:
Also, is it possible to load lua scripts from C? That would be really cool, but it sounds hard.
My classes for graphics for PSP & Mac PowerPC & Intel is ready apart from using the PSP Graphics functions when compiled for PSP and JPEG support not completed for Mac, so have desided to spend more time getting JPEG to work and look at the PSP GU functions before releasing it.
Like to thank Bronx for help in making PNG display correct for Intel Macs as well as PowerPC Macs, been a big help in getting the endian issues ioned out.
I am also in contact with Bronx on the JPEG side so I can make sure it works for not just PowerPC macs but Intel Macs as well.
Hope to release it soon and have the JPEG issue sorted out by Monday 26 March at the latest.
Thanks for the credit, Xart :)
"0x03010010"= firmware 3.10 (version.txt)
what is 3.03 firmware, 3.02 2.71 ?
because i want my progam to "print firmware version:Jump:
Let me reword my question. How do you load .lua files from C?Zitat:
Zitat von yaustar
Check out lua (not lua player) from the ps2dev.org SVN, there's an example included.
Using google:Zitat:
Zitat von Xylem
http://www.google.co.uk/search?q=usi...en-US:official
Results: http://csl.sublevel3.org/lua/
i use file checks anywayZitat:
Zitat von Kwastie
(popsloader , ...)
Hm, can somebody tell me why this little prog freezes upon exit?
HmCode:[includes]
int is_connected;
PSP_MODULE_INFO(MODULE_NAME, 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
[standard callbacks]
int main(int argc, char **argv)
{
SceUID netthid;
SetupCallbacks();
pspDebugScreenInit();
initGraphics();
int i;
char *command;
SceCtrlData pad, lastpad;
is_connected = 0;
while(1)
{
if(is_connected>0)
{
// Read buttons
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons != lastpad.Buttons) {
lastpad = pad;
if(pad.Buttons & PSP_CTRL_CROSS){
command = "play";
send_command(sock, command);
}
if(pad.Buttons & PSP_CTRL_TRIANGLE){
command = "stop";
send_command(sock, command);
}
if(pad.Buttons & PSP_CTRL_SQUARE){
command = "previous";
send_command(sock, command);
}
if(pad.Buttons & PSP_CTRL_CIRCLE){
command = "next";
send_command(sock, command);
}
if(pad.Buttons & PSP_CTRL_VOLUP){
command = "volup";
send_command(sock, command);
}
if(pad.Buttons & PSP_CTRL_VOLDOWN){
command = "voldown";
send_command(sock, command);
}
}
}
for(i=0; i<1; i++) {
sceDisplayWaitVblankStart();
}
}
return 0;
}
Luke
-= Double Post =-
PS: xArt, what's that apostrophe in Logo's on your homepage?
still no one who can tell me what hex of firmware is:
0x03010010=3.10 firmware
and i want it to know from firmware 3.03 & 3.02.. :Cry: I can't find it :(
sorry, no clue
-= Double Post =-
I know that was a worthless post, but sometimes it's more frustrating to me when I get no reply at all than people telling me they can't help. hm
sceDisplayWaitVblankStart ();Zitat:
Zitat von Lukeson
No need of for 1 pass...
----That's just the 1 I caught, which m8 not be causing the problem!
1)EDIT: GOT IT: Noob to pointers[I am]:
1)it should be *command = "value"!
2Unless u malloc, I suggest using Char *command[anysize same as the one it is poiting to]
3 I donot see it being assigned any address before being used!
And also replace the function parameters also to *command.
That should solve it!
Post the results!
Edit: Sorry again, but i want to keep my code personal. ;)
Yeah I know it's utterly useless, but I saw that in the psp-programming.com tutorials and thaught like 'why not, maybe it helps'. Well, as you can guess, it didn't.Zitat:
Zitat von Mr305
However, using *command="value" it still freezes when I exit the program. Same with char command[256]; and strcpy(command, "play");
1) No it shouldn't. * coimmand would mean you would be dereferencing cahr pointer to a char, not a C string.Zitat:
Zitat von Mr305
2) Nope. It should be:
To assign it new strings, you have to use sprintf or strcpy.Code:char command[80]; // or any other size
3) I agree, what he is doing at the moment is undefined behaviour.
Can u tell me whats wrong with this prx
Code:#include <pspctrl.h>
#include <pspkernel.h>
#include <stdio.h>
#include <string.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#define printf pspDebugScreenPrintf
PSP_MODULE_INFO("VSHTimer", 0x1000, 1, 0);
PSP_NO_CREATE_MAIN_THREAD();
void CheckCleanExit(void) {
SceUID thids[50];
int thid_count = 0;
int i;
//SceUID fd;
//SceUID memid;
SceKernelThreadInfo thinfo;
//if sceKernelExitGame was called, exit before the system crashes
sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread,thids,50,&thid_count);
for(i=0;i<thid_count;i++)
{
memset(&thinfo,0,sizeof(SceKernelThreadInfo));
thinfo.size = sizeof(SceKernelThreadInfo);
sceKernelReferThreadStatus(thids[i],&thinfo);
if(strcmp(&thinfo.name[0],"SceKernelLoadExecThread")==0)
{
sceKernelSelfStopUnloadModule(0, 0, NULL);
}
}
}
int MainThread (SceSize args, void *argp) {
CheckCleanExit();
pspDebugScreenInit();
int counter = 0;
unsigned int paddata_old = 0;
int state = 0;
SceCtrlData pad;
for(;;) {
if(pad.Buttons != paddata_old){
pspDebugScreenClear();
sceCtrlPeekBufferPositive(&pad, 1);
if(state==0) {
pspDebugScreenSetXY(0,10);
printf("Press [R] to start the timer");
if(pad.Buttons & PSP_CTRL_RTRIGGER) {
state=1;
pspDebugScreenClear();
}
}
if(state==1) {
pspDebugScreenSetXY(0,10);
printf("Press [L] to stop the timer\n");
printf("Counter: %i",counter);
counter++;
if(pad.Buttons & PSP_CTRL_LTRIGGER) {
state=2;
pspDebugScreenClear();
}
}
if(state==2) {
pspDebugScreenSetXY(0,10);
printf("Counter Finished\n");
printf("Final Count: %i", counter);
printf("\n\nPress Note to restart\n");
if(pad.Buttons & PSP_CTRL_NOTE) {
state=0;
pspDebugScreenClear();
counter=0;
}
}
}
paddata_old = pad.Buttons;
}
return 0;
}
int module_start(SceSize args, void *argp) {
SceUID thid;
thid = sceKernelCreateThread("VSHTimer", MainThread, 0x18, 0x1000, 0, NULL);
if (thid >= 0) sceKernelStartThread(thid, args, argp);
return 0;
}
int module_stop(void) {
return 0;
}
Still freezes when I exit the programZitat:
Zitat von yaustar2) It should be:
[code
-= Double Post =-
Can you tell us what's the problem with your program and post only code you think is relevant?Zitat:
Zitat von psp-freak222
I can't see anywhere in your program where it exits the main loop. How did oyu exit the program? If it is via the callbacks then we need to see the callback functions.Zitat:
Zitat von Lukeson
Change that. As easy as that :PZitat:
while(1)
HINT: Add a global variable isrunning and initialize it to 1, and in your exit_callback function set that to zero. Then just make that a while (isrunning).
PS: The rest of the code is absolutely ok. He just changes the pointer to the location of the constant strings and sends that as the command. Assuming he somewhere setup the variable sock, that is.
You program NEVER reads the control input
is_connected is initialised to 0 therefore the if statement is never true to enter the loop to read the input.Code:is_connected = 0;
while(1)
{
if(is_connected>0)
{
What you have just done is the same as:
Code:while(1)
{
if(0>0)
Well, this is because I left out the parts I previously commented out to find the source <strike>of evil</strike> why it freezes when I exit. Before entering the loop I start a thread that connects to WLAN and a server to which I send commands with the send_command() function. is-connected becomes 1 when the thread has finished connecting.Zitat:
Zitat von yaustar
I thought I didn't need that. I thought I it was an ok-method to run a 'main loop' to do all the input and display stuff. Exiting should work by pressing the home-button (I thought).Zitat:
I can't see anywhere in your program where it exits the main loop. How did oyu exit the program? If it is via the callbacks then we need to see the callback functions.
Quoting myself
In other words, show us your entire code otherwise we are going to keep picking up problems that don't exist in 'your' code.Zitat:
I can't see anywhere in your program where it exits the main loop. How did oyu exit the program? If it is via the callbacks then we need to see the callback functions.
You don't but if you say there is a bug in your code when you exit your game but not show us any code that has any exit clauses or the code that happens on exit then we might as well not be looking at it. Show use all relevent code to do with exiting and on exit of your program.Zitat:
I thought I didn't need that. I thought I it was an ok-method to run a 'main loop' to do all the input and display stuff. Exiting should work by pressing the home-button (I thought).
Well... I already pointed at the cause of the 'hang'. Doing infinite loops in the main thread will cause a hang at exit most of the time.
Ok, globals.h and constants.h are not really neccessary here, but I'll post them too. I commented out all calls of functions in netfunctions.c (except for send_command but that's obviously never called). Here it is:
Spoiler for main.c:
PS: I know / I'm sure there are way too much includes at the beginning, but I was gonna sort em out later...
Spoiler for netfunctions.c:
Spoiler for globals.h:
Spoiler for constants.h:
-= Double Post =-
So what is the proper way to manage inputs and display? I know that question is like 'hey tell me how to program c' but can you give me a hint (/the basic priciples) or where I can read about it?Zitat:
Zitat von Raphael
Just read my post on the previous site again. I hinted at how to do the loop correctly. Apart from that, nothing is really wrong with your code.
I didn't think that the infinite loop would effect the use of the Home button callback?Zitat:
Zitat von Raphael
It does, because the main thread will still continue to run. Even sceKernelExitGame sometimes cannot kill such a thread, hence the hang.
Ahh... I see, that makes sense.
It works! Thank you!!
One last question: If I press (X) to confirm I really want to exit, the program responds to it sending a command to the server. How do I prevent that?
Ok, i have been having the same problem again and again this morning. I finally figured it out. I thought that my wav files weren't loading, but i figured that they were working fine on a the sample C file that comes with the Wav Loader v.1. Now, for some reason, in this code that i will show, everytime i put the line "pspAudioInit();", cygwin successfully compiles it without errors, but when i go to play it, it doesn't work. When i don't put in any audio or "pspAudioInit();", my code works flawlessly. Now, what is wrong with this wierd code? The makefile of it is the same as the working code, but there is something wrong with this code. I even used simple simple mp3 player code, even from the psp-programming tutorial, and then my mp3 worked (with same makefile). But what is wrong with this code that causes my psp to freeze everytime i put "pspAudioInit();"? Here is my code (yes, i know; i "init" and sometimes loaded some of the same things twice, but the compiler doesn't work if i only put the "init" 's in the main loop):
I think if you remove the "pspAudioInit();" 's, the code works, but the mp3 obviously doesn't play when i press up or down. :( However, if you keep it, the psp simply freezes. Also, i have tried to reinstall libmad, and i also checked if i had the pspaudio.h and pspaudiolib.h.Code://G-Pack v.3 Shell
//Made by SuperbatXS
#include <stdio.h>
#include <stdlib.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspiofilemgr.h>
#include "graphics.h"
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <pspcallbacks.h>
#include "mp3player.h"
#include <psppower.h>
#include <string.h>
PSP_MODULE_INFO("G-Pack v.3", 0, 1, 1);
#define printf pspDebugScreenPrintf
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
int ThemeSetting = 1;
int thememenu()
{
SetupCallbacks();
pspDebugScreenInit();
initGraphics();
pspAudioInit();
SceCtrlData pad, lastpad;
sceCtrlReadBufferPositive(&lastpad, 1);
MP3_Init(1);
MP3_Load("./sounds/beep.mp3");
Image* Background;
Background = loadImage("./images/bubbles.png");
Color Color1 = RGB(0, 0, 0);
Color Color2 = RGB(0, 0, 0);
Color Color3 = RGB(0, 0, 0);
int ThemeMenu = 1;
extern int ThemeSetting;
while (1)
{
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons != lastpad.Buttons)
{
if (pad.Buttons & PSP_CTRL_CROSS)
{
if (ThemeMenu == 1)
{
//HERE'S WHERE WE WOULD START THE ACTUAL GAME
}
}
if (pad.Buttons & PSP_CTRL_UP)
{
MP3_Play();
if (ThemeMenu == 1)
{
ThemeSetting--;
if (ThemeSetting < 1)
ThemeSetting = 1;
}
}
if (pad.Buttons & PSP_CTRL_DOWN)
{
MP3_Play();
if (ThemeMenu == 1)
{
ThemeSetting++;
if (ThemeSetting > 3)
ThemeSetting = 3;
}
}
}
blitAlphaImageToScreen(0, 0 , 480, 272, Background, 0, 0);
if (ThemeMenu == 1)
{
if (ThemeSetting == 1)
{
Color1 = RGB(190, 190, 190);
Color2 = RGB(0, 0, 0);
Color3 = RGB(0, 0, 0);
}
else if (ThemeSetting == 2)
{
Color1 = RGB(0, 0, 0);
Color2 = RGB(190, 190, 190);
Color3 = RGB(0, 0, 0);
}
else if (ThemeSetting == 3)
{
Color1 = RGB(0, 0, 0);
Color2 = RGB(0, 0, 0);
Color3 = RGB(190, 190, 190);
}
printTextScreen(170, 140, "Dark Theme", Color1);
printTextScreen(170, 150, "Penguin Theme", Color2);
printTextScreen(170, 160, "Kill your Fear Theme", Color3);
}
sceDisplayWaitVblankStart();
flipScreen();
lastpad = pad;
}
MP3_FreeTune();
sceKernelSleepThread();
return 0;
}
int main () {
SetupCallbacks();
pspDebugScreenInit();
initGraphics();
pspAudioInit();
SceCtrlData pad, lastpad;
sceCtrlReadBufferPositive(&lastpad, 1);
MP3_Init(1);
Image* Background2;
Background2 = loadImage("./images/sbg.png");
Image* Background3;
Background3 = loadImage("./images/background.png");
char x[2];
char variable[2] = "0";
char variable1[2] = "1";
char variable2[2] = "2";
FILE *theme;
if ((theme = fopen("./theme.txt","rb")) == NULL)
{
printf("There is nothing in this file");
}
x[fread(x, 1, 1/*Number of bytes to read, In this case, 1*/, theme)] = 0;
fclose(theme);
if(strcmp (variable,x) == 0)
{
thememenu();
}
if(strcmp (variable1,x) == 0)
{
blitAlphaImageToScreen(0, 0 , 480, 272, Background2, 0, 0);
sceDisplayWaitVblankStart();
flipScreen();
}
if(strcmp (variable2,x) == 0)
{
blitAlphaImageToScreen(0, 0 , 480, 272, Background3, 0, 0);
sceDisplayWaitVblankStart();
flipScreen();
}
sceKernelSleepThread();
return 0;
}
You're calling pspAudioInit() multiple times, remove the call in the thememenu() function.
Also if you want to use my wavloader library (even with MP3 too) don't call pspAudioInit() at all, as mikmod does this internally.