Looking for sample code

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
User avatar
UndeadDC
Insane DCEmu
Insane DCEmu
Posts: 110
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu Aug 11, 2005 9:26 pm
Has thanked: 4 times
Been thanked: 0

Looking for sample code

Post by UndeadDC »

I'm looking for some sample code or open source game code that showcases the use of KOS really well, preferably something that has decent comenting :wink: Is there a sourceforge page or something where I could download some stuff? It just now occured to me that the homebrew page would probably be a good place to look also, but if any of you could point me to something that specificaly uses KOS, I would really appreciate it.
User avatar
Quzar
Dream Coder
Dream Coder
Posts: 7500
Joined: Wed Jul 31, 2002 12:14 am
Location: Miami, FL
Has thanked: 4 times
Been thanked: 14 times
Contact:

Post by Quzar »

kos comes with examples of how to use different features it provides, you should look at those.
"When you post fewer lines of text than your signature, consider not posting at all." - A Wise Man
User avatar
bucanero
DC Developer
DC Developer
Posts: 120
Joined: Sat Apr 05, 2003 4:58 pm
Location: Rapture
Has thanked: 1 time
Been thanked: 2 times
Contact:

Post by bucanero »

Maybe I'm wrong, but I think that Dan Potter released parts of the source code of Feet of Fury, so you might want to check out Cryptic Allusion's web site and see around there.
Image
User avatar
UndeadDC
Insane DCEmu
Insane DCEmu
Posts: 110
Joined: Thu Aug 11, 2005 9:26 pm
Has thanked: 4 times
Been thanked: 0

Post by UndeadDC »

Last time I checked Cryptic Allusion was down. I found the examples. Thanks, I don't know how I missed them before :roll:
User avatar
UndeadDC
Insane DCEmu
Insane DCEmu
Posts: 110
Joined: Thu Aug 11, 2005 9:26 pm
Has thanked: 4 times
Been thanked: 0

Post by UndeadDC »

Could someone give me an example of what to type into cygwin in order to compile one of the kos examples? I realize this is an odd request, but I'm trying to learn Cygwin/bash, GCC, and kos all at the same time, and I think it would help a lot if I had a jumping off point I could work from. I'm using LyingWakes awsome self building distro that puts you at

me@computer /usr/local/dc/kos1.3/kos

when you start the program. Thanks.
Phantom
DC Developer
DC Developer
Posts: 1753
Joined: Thu Jan 16, 2003 4:01 am
Location: The Netherlands
Has thanked: 0
Been thanked: 0
Contact:

Post by Phantom »

Try this:

Code: Select all

cd examples/dreamcast/hello
make
"Nothing works" - Catweazle
User avatar
UndeadDC
Insane DCEmu
Insane DCEmu
Posts: 110
Joined: Thu Aug 11, 2005 9:26 pm
Has thanked: 4 times
Been thanked: 0

Post by UndeadDC »

I get,

bash: make: command not found

I also tried,
$ gcc hello.c -o hello

and got,
bash: gcc: command not found





edit:
Now that I'm beginning to understand what a weird pain in the butt compiling with gcc is I don't feel so silly about asking for this. Thanks to the home of the hitmen I'm getting closer, but I'm still not there yet

$ sh-elf-gcc -m4 hello.c -o hello
hello.c:7:17: kos.h: no such file or directory
hello.c:10: error: parse error before "romdisk"
hello.c:10: warning: data definition has no type or storage class
hello.c:24: error: parse error before '|' token
.......etc.

any takers?
c99koder
DC Developer
DC Developer
Posts: 200
Joined: Wed Oct 17, 2001 7:44 pm
Location: East Windsor, NJ
Has thanked: 0
Been thanked: 0
Contact:

Post by c99koder »

use kos-cc, not sh-elf-gcc. kos-cc is a helper script that sticks all the required flags onto the command line for you.

However, it would be better to install make (it looks like you missed some cygwin packages when you installed it), since the Makefiles do this all for you anyway.

-Sam
Image
GPF
DC Developer
DC Developer
Posts: 529
Joined: Wed Oct 17, 2001 7:44 pm
Location: Texas
Has thanked: 0
Been thanked: 0
Contact:

Post by GPF »

run the environment script first

. ./environ.sh

sets up all the paths etc
User avatar
UndeadDC
Insane DCEmu
Insane DCEmu
Posts: 110
Joined: Thu Aug 11, 2005 9:26 pm
Has thanked: 4 times
Been thanked: 0

Post by UndeadDC »

I got it to compile, but it's having trouble with the romdisk for some reason.

.....:30: undefined reference to '_romdisk'

If I remove the romdisk it seems to compile fine.
c99koder
DC Developer
DC Developer
Posts: 200
Joined: Wed Oct 17, 2001 7:44 pm
Location: East Windsor, NJ
Has thanked: 0
Been thanked: 0
Contact:

Post by c99koder »

If you're not using the Makefile, you'll need to create romdisk.o manually:

Code: Select all

genromfs -f romdisk.img -d romdisk -v
bin2o romdisk.img romdisk romdisk.o
Then you'd need to link romdisk.o along with main.c:

Code: Select all

kos-cc main.c romdisk.o -o test.elf
Both genromfs and bin2o are in the KOS utils directory.

-Sam
Image
User avatar
UndeadDC
Insane DCEmu
Insane DCEmu
Posts: 110
Joined: Thu Aug 11, 2005 9:26 pm
Has thanked: 4 times
Been thanked: 0

Post by UndeadDC »

Thanks, now that I think of it the examples already have the romdisks made for them I just didn't include it when I compiled it.

The output I did get was hello.file. Do I just need to rename this to ip.bin to use it or is there something further I have to do with it?
c99koder
DC Developer
DC Developer
Posts: 200
Joined: Wed Oct 17, 2001 7:44 pm
Location: East Windsor, NJ
Has thanked: 0
Been thanked: 0
Contact:

Post by c99koder »

It most probably output an elf file, but you can check by running

Code: Select all

file hello.file
. It should say something like "ELF 32-bit LSB executable, Hitachi SH, version 1 (SYSV), statically linked". You can convert that to a bin file with

Code: Select all

sh-elf-objcopy -O binary -R .stack hello.file hello.bin
Then, if you want to be able to boot from a CD, you need to scramble the binary file and name it 1ST_READ.BIN.

-Sam
Image
User avatar
UndeadDC
Insane DCEmu
Insane DCEmu
Posts: 110
Joined: Thu Aug 11, 2005 9:26 pm
Has thanked: 4 times
Been thanked: 0

Post by UndeadDC »

OK, I decided before I went any further I would get cygwin running like it should (I was having trouble with more than just make). Everything seems to be working peachy now, but will I need to create makefiles for programs I write? If so, can I just edit the makefiles in the examples some how? I'm assuming the big pile of stuff right after the kos-cc line is the the helper script mentioned by c99koder in an earlier post and the last line, "bubbles.o -lparallax -lgl ...etc" is the linker. Finally, what does this line do:

rm -f bubbles.elf


edit: Concerning the line where the libraries are linked to the object file what is '--start-group' and '--end-group' for? I can't find any info on it in my documentation. And assuming the .elf file is the final output file how is it created or modified after the final linking is done to the object file? There aren't any commands after that. Does it have something to do the line I mentioned above?

That's all for now I guess :) Anybody know where to get documentation on make?
Last edited by UndeadDC on Sun Nov 27, 2005 7:59 pm, edited 1 time in total.
c99koder
DC Developer
DC Developer
Posts: 200
Joined: Wed Oct 17, 2001 7:44 pm
Location: East Windsor, NJ
Has thanked: 0
Been thanked: 0
Contact:

Post by c99koder »

1. Yes, you can just modify the example Makefiles. The only line you should need to change is where it says "OBJS = ".

2. Yes, -l tells gcc to link a library along with your elf.

3. "rm" ReMoves a file, and -f means force. So that line deletes bubbles.elf.

-Sam
Image
User avatar
UndeadDC
Insane DCEmu
Insane DCEmu
Posts: 110
Joined: Thu Aug 11, 2005 9:26 pm
Has thanked: 4 times
Been thanked: 0

Post by UndeadDC »

Looks like you posted while I was editing. Here we go. Why does rm need to remove the file before it's even made? Is it incase the file has already been created? If so wouldn't it just be overwritten?

Thanks for all your help.
c99koder
DC Developer
DC Developer
Posts: 200
Joined: Wed Oct 17, 2001 7:44 pm
Location: East Windsor, NJ
Has thanked: 0
Been thanked: 0
Contact:

Post by c99koder »

Which makefile are you looking at? The only time I see rm in the parallax bubbles example is in the "clean" rule, which is used to erase everything you've compiled.

You can find Make's documentation at http://www.gnu.org/software/make/manual/make.html

-Sam
Image
User avatar
UndeadDC
Insane DCEmu
Insane DCEmu
Posts: 110
Joined: Thu Aug 11, 2005 9:26 pm
Has thanked: 4 times
Been thanked: 0

Post by UndeadDC »

c99koder wrote:Which makefile are you looking at? The only time I see rm in the parallax bubbles example is in the "clean" rule, which is used to erase everything you've compiled.

You can find Make's documentation at http://www.gnu.org/software/make/manual/make.html

-Sam
It's the bubbles example I'm looking at. Before the kos-cc line is run rm is run to erase bubbles.elf. Is this done to clean the file before a new compile is done? I'm thinking that's what you meant, but I just want to be sure.

Again, thanks for all your help. You don't know how much I appreciate it.
c99koder
DC Developer
DC Developer
Posts: 200
Joined: Wed Oct 17, 2001 7:44 pm
Location: East Windsor, NJ
Has thanked: 0
Been thanked: 0
Contact:

Post by c99koder »

Ah, that's actually in a different section. Here's a quick intro Makefiles:

Makefiles are basically a set of rules and dependancies. When you run "make" by itself, it will execute the first rule it finds. Rules are all the way at the left of the file (not indented), and commands that are part of that rule are indented with 1 tab. So here's a really simple Makefile:

Code: Select all

Hello:
(tab)echo "Hello world!"
When you run "make", it will execute the first rule (hello), and run the echo statement.

Now, in the bubbles Makefile, there are several rules. The first one, "all", is what make will execute if you just run "make". It says "all" depends on "rm-elf", and "$(TARGET)" which is bubbles.elf (declared at the top). So basically, when you run "make", it will first execute the "rm-elf" rule, followed by the bubbles.elf rule. Doing it this way will force make to re-link your binary even if none of your C files have changed. Make will see that bubbles.elf is missing (because it deleted it), and then run the rule to create it again.

There are several other rules defined in that Makefile: "run", and "dist". If you wanted to use one of those, you would call "make run" or "make dist" (you can also call "make clean" to run the clean rule, which deletes all your object files). According to the makefile, "make run" is the same as running "dc-tool -x bubbles.elf", and "make dist" will delete all your object files and then strip the binary of any debugging symbols.

I know I'm not the best at explaining things, so let me know if you need anything clarified :)

-Sam
Image
GyroVorbis
Elysian Shadows Developer
Elysian Shadows Developer
Posts: 1876
Joined: Mon Mar 22, 2004 4:55 pm
Location: #%^&*!!!11one Super Sonic
Has thanked: 82 times
Been thanked: 64 times
Contact:

Post by GyroVorbis »

Thank you, c99koder, and I love you. :kiss)

So many people are in the dark with makefiles. To this day, I'm still not half as familiar with them as I'd like to be.

I couldn't find any documentation or anything explaining how the hell they worked. This is simple and nice. Thanks man.
Post Reply