PDA

View Full Version : Dev Questions



PS2Atari
December 19th, 2004, 23:59
Hey everyone, I've been playing around dc-development the past few days, I've written /compiled a few dc-apps to test my ability to get controller input / throw polys at the screen, and I am impressed with the current level of the dc homebrew scene. I used Visual Basic to make a graphical user interface for dc-tool so I can use windows common dialog to send files, w\out having to go thru dos... which I may release some day, but for now I have a few questions:

1) Where can I get info on playing sounds from romdisk? Source code would be greatly appreciated.

2) Do any libs or code examples exist to use purupuru packs? (the "rumble2" demo doesn’t work for me )

3) Does KOS-GL support blending yet?, if so is it just like regular gl blending? (again: sources?)

4) How I can access the second maple port... there aren't any convenient macro’s like "maple_second_controller()", is it some kind of pointer off set?

5) Why would anyone want to use the download function of dc-tool?

6) If you choose to upload a file via dc-tool, how can you then execute it later on, with out using -x in the first place?

7) Is there any official or in-depth KOS documentation?

Thanks for reading, and any questions you can answer;
)>-PS2Atari-<(

Kamjin
December 20th, 2004, 02:38
I'll take a shot, at a few of 'em..


author=PS2Atari

1) Where can I get info on playing sounds from romdisk? Source code would be greatly appreciated.


This would be the basics to play soundfx, check
the older docs or Dan's website, I might have made a typo.

//decl.
sfxhnd_t fire;

//handle+load
fire = snd_sfx_load("/rd/fire.wav");

//play hand,L-Rbal,Volume
snd_sfx_play(fire, 64, 128 );




2) Do any libs or code examples exist to use purupuru packs? (the "rumble2" demo doesn’t work for me Â* Â*)


http://www.dchomebrew.org/kamjin/

click on DC then Puru, there's a KOS driver written
by SinisterTengu, almost all the info on the reverse eng. of the puru. If the Kos driver don't work for you let me know and I'll send you some maple code that works around KOS.




4) How I can access the second maple port... there aren't any convenient macro’s like "maple_second_controller()", is it some kind of pointer off set?

again off the top of my head adn sloppy.. so..



cont_cond_t cond1,cond2;
uint8 port,device,controller[4];

for(port=0;port<4;port++){
for(device=0;device<4;device++){
if ( maple_device_func(port,device) == MAPLE_FUNC_CONTROLLER ) {
controller[players]=maple_create_addr(port,device);
players++;
printf("found at %d,%d\n",port,device);
}//end if
}//end for device
}//end for port

//for player1
cont_get_cond(controller[0], &cond1);
//for player2
cont_get_cond(controller[1], &cond2);

if(!(cond1.buttons & CONT_A)printf("P1 Pressed!\n");
if(!(cond2.buttons & CONT_A)printf("P2 Pressed!\n");





5) Why would anyone want to use the download function of dc-tool?

Dump screens, memory, results.. debugging etc..



7) Is there any official or in-depth KOS documentation?


http://gamedev.allusion.net/docs/kos/cvs/kos_html/

The rest of the Docs is by going through the headers, and example code, and of course ask others which probably is the best reference.

DanPotter
December 20th, 2004, 12:07
cont_cond_t cond1,cond2;
uint8 port,device,controller[4];

for(port=0;port<4;port++){
Â* Â*for(device=0;device<4;device++){
Â* Â* Â* if ( maple_device_func(port,device) == MAPLE_FUNC_CONTROLLER ) {
Â* Â* Â* Â* Â* Â* Â* controller[players]=maple_create_addr(port,device);
Â* Â* Â* Â* Â* Â* Â* players++;
Â* Â* Â* Â* Â* Â* Â* printf("found at %d,%d\n",port,device);
Â* Â* Â* }//end if
Â* Â* Â* }//end for device
Â* Â* Â* }//end for port

//for player1
cont_get_cond(controller[0], &cond1);
//for player2
cont_get_cond(controller[1], &cond2);

if(!(cond1.buttons & CONT_A)printf("P1 Pressed!\n");
if(!(cond2.buttons & CONT_A)printf("P2 Pressed!\n");
Â* Â* Â* Â*



This actually won't work anymore in KOS 1.3.x (the stuff that comes out of subversion). It's also problematic in that you have to scan for controllers periodically unless you don't want to allow hot-swapping. The new way is this:



// To do initial player count if you want
players = 0;
MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st)
players++;
printf("found at %c%d\n", __dev->port+'A', __dev->unit);
MAPLE_FOREACH_END()

// To actually do inputs
player = 0;
MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st)
if (st->buttons & CONT_A) {
printf("P%d PRESSED!\n", player);
}
player++;
MAPLE_FOREACH_END()


Or maybe I was going to take out the old compat functions and haven't yet... but they are soon to go, either way. Note that this works also in KOS 1.2.0, so it's the forward-compatible way to go now. maple.h has much more info (and lots of comments).


http://gamedev.allusion.net/docs/kos/cvs/kos_html/

The rest of the Docs is by going through the headers, and example code, and of course ask others which probably is the best reference.

Those docs are pretty out of date now... seems like they always are. :( The best source of up to date info, as always, as Kamjin mentions, is in the header files. Over time we've been working to get them into a doxygen compatible format so a reference doc can be automatically extracted, but it's still not there yet.


Also, KGL is pretty defunct -- I'd recommend grabbing KGL-X if you really want to use it. You can't just enable and disable blending unfortunately because it pretty much takes your input and goes straight to the PVR with it, with no DMA buffers. So you need to do it in lists like with the PVR functions.

PS2Atari
December 20th, 2004, 20:27
Thanks for your quick replies.

The sound code doesn't work for me, when it tries to play a sound, it exits the program. I read in the documentation (that kamjin linked) that it only supports RIFF wavs, and since I've been trying to figure out what type I tested with / how to make "RIFF" wavs.. so maybe that is the problem.

> The rumble binary works fine, but I can't get get the source to compile. (btw, I'm trying to use the Dev-C++ setup)

> Haven't had time to mess with controllers today.

Back to sound tho, I looked in the dcinclude directory, with all the header files and I found the mp3 header files. One of which is "sfxmgr.h". It has functions similar to the ones above, but without the snd_ prefix. I included <mp3\sfxmgr.h> but when it try's to link, it says there is an undefinded reference to the function, ex:

[Linker error] undefined reference to `sfx_load'

In the documentation link, it mentions a "snd_init()" function to initialize the sound system.. when I try to call this the compiler cannot find it, and I can't find its source either, I guess this is a out dated function?

Also note, that I never downloaded KOS by itself, I downloaded a developer tool set that had kos, dc-tool, a serial loader, and a few examples. Maybe this is a problem? (all the header files are KOS-1.2.0)

Thanks for any help you can offer,
)>-PS2Atari-<(

Kamjin
December 20th, 2004, 21:53
Even I learned something! better controller code..

PS2Atari

See if you can compile either of these.

Just unzip this to preserve the romdisk folder,
makefile is in there.
http://www.dchomebrew.org/kamjin/files/sound.zip

Use a generic makefile, you might have to add
#include<kos.h> at the top and link with -lm (math)
http://www.dchomebrew.org/kamjin/files/pururaw.zip

curt_grymala
December 21st, 2004, 07:36
This probably belongs in the Dev forum. To quote Hawq:

Buckle your seatbelts, we're headed for a ride.

DanPotter
December 21st, 2004, 12:36
The sound code doesn't work for me, when it tries to play a sound, it exits the program. I read in the documentation (that kamjin linked) that it only supports RIFF wavs, and since I've been trying to figure out what type I tested with / how to make "RIFF" wavs.. so maybe that is the problem.

All wav files are RIFF wavs, so there's no problem there. :) If you look in the header you'll see the characters "RIFF", that's all it means. Any plain PCM mono or stereo wav file with less than 64k samples should play just fine. There is a problem with >64k because of the way the AICA registers work... in that case you have to use a snd_stream thing to stream the bigger sound. One of those things I've been meaning to write into the normal sfx processing, but never got around to doing it...

FWIW, and this should probably go in the KOS FAQ since it comes up so often... :) but when the program quits unexpectedly there are a couple of different outcomes usually:

1) Assert message. If the message itself doesn't solve the problem, then go take a look at the source code line it references. The code is pretty well commented on average and you can often figure out what's going wrong just by looking in the vicinity to see what it's doing. Turning on frame pointers and recompiling the whole KOS/ports/etc will also give you stack traces on asserts, which can be helpful with method #3 below.

2) Program exits "normally" but there doesn't seem to be an error -- this is pretty rare. Dig through the stdout output and see if you don't see something wrong.

3) Crash, register dump. First off, make sure you're compiling your stuff with -g on both the compilation and link commands. Now when you get a crash, you'll get a PC and PR value. Often times you can figure out what's wrong by looking at where it crashed, using sh-elf-addr2line:

sh-elf-addr2line -e myprog.elf 8c021510

or whatever value you get for PC and PR instead of 8c021510. If everything is kosher in the program still this will usually give you a small stack trace (at least what died and who called it). Also each crash has an exception code -- you can look these up in arch/irq.h to see what the exact error was. If that still doesn't cut it, you can use:

sh-elf-objdump -d myprog.elf | less

Then hit / to search, and type ^8c021510 or whatever the crash address was, and hit enter. It'll zip down to the actual instruction it happened, if the address is valid. You can then look at the register values from the crash and such and see if the values you're seeing make sense. This is BTW how people usually find compiler bugs. They trace back from the crash state and realize that there's no way the compiler should have written some code it wrote, to do what you wanted it to do. You can also use the -S option on objdump and it'll try to interleave the source code with the assembly. This is a lot slower to search through but it can be a lot more helpful.


Finally, PLEASE if you are doing anything more than downloading KOS and feeling good for having DC tools on your drive ;) then join the KOS mailing list on SourceForge. The response time varies, but I've generally found that people asking on there get a much quicker and more relevant answer than on forums and even by emailing me directly (well, the latter is no surprise considering how much of a slacker I am :)).

Some better examples some day will help with a lot of these I'm sure... but you can guess how likely that is to happen in the near future...

PS2Atari
December 21st, 2004, 14:34
Alright, thanks for all the info, and after posting this I'll go find the KOS mailing list. :)

OK, I think I found the problem with the sound files tho.

@Kamjin:

I got your sound example to compile perfectly (not with your make file tho, but it compiles and plays sound on the dc just fine)

However, when I try to implement the same thing into my own project, the console says

snd_sfx: loading effect /rd/fire.wav
snd_sfx: can't open sfx /rd/fire.wav

I think my romdisk might not be working right, because I tried to also implement a plprint type method; but when I use it, the console outputs:

pvr_prim: attempt to submit to unopened list

I'm guessing that's because the line:

TheFont = new fntTexFont("/rd/courier-bold.txf");

failed to load the font from the rd?



I'm using the same make file \ linkage \ compiler params for both your sound example and my project, yet yours works fine and mine doesn't...

As for the pururaw example, I tried setting it up in devcpp and it gives me a handful of errors dealing with not being able to convert from void* to unsigned long*, but I'll work more on purupuru after I find out what’s wrong with sound / the way I init rd

@Dan Potter:
Thanks for all the debugging tips, *saves in notepad*,
and the info about wavs - so thats definitely not the problem. I think its the RD problem I mentioned above.

Anyway I'm off to sign up for the KOS Mailing List.

Thanks alot tho, I'm almost there,
)>-PS2Atari-<(

DanPotter
December 21st, 2004, 20:28
Alright, thanks for all the info, and after posting this I'll go find the KOS mailing list. Â*:)

Great! It's been pretty quiet lately so I doubt anyone will mind some traffic. Sometimes people get a little netiquette-anal (mainly about people hitting 'reply' to random messages :)) but it's not as bad as a lot of lists.


pvr_prim: attempt to submit to unopened list

This probably actually means just what it says. Make sure you've done a pvr_list_begin(PVR_LIST_TR_POLY) or whichever list (that's probably the one though) before trying to submit any vertices for a list.

PS2Atari
December 26th, 2004, 18:14
Hey, just an update, if your wondering why my question never came up on the mailing list, I solved it a few minutes later.

For future reference these were the problems:

the print function failed because I forgot to extern romdisk in its file *woops* :-/

and for some reason, after I call:

fntTexFont("/rd/courier-bold.txf");


it prevents me from loading sounds from the romdisk??
however, if I load sounds first, and font last it works.

weird, but my program is up & running, thanks to everyone!