PDA

View Full Version : Getting started with KOS



pnpbios
May 19th, 2005, 23:54
Hello everybody! I've started developing for the dreamcast a little while ago. So far I have just been making stupid patterns by writing directly to the frame buffer with KOS.

I am looking at doing something a bit more powerfull now. I want to access resources in my base directory over my serial cable connection, with the eventual hope of using them in my game.

fs_open seems to be the right function for this, but it always returns NULL for some reason.

Is there something I have to do with DC-Tool in order to get the directory setup? Or is my path just goofy? If anybody has some ideas, that would be great, cause I am stumped.

Here is the source code for my little demo project.

#include <kos.h>
#include <stdio.h>


#define _RGB(r, g, b) ((r << 12)|(g << 5)|(b << 0))

void drawPix(int x, int y, int color);

int main(int argc, char **argv) {
int x, y;
int color;
file_t fptr;

fptr = fs_open("/pc/dummy.txt", O_RDONLY);

color = _RGB(255,255,255);

if(fptr != 0)
{
fs_close(fptr);
color = _RGB(0,0,255);
}

/* Bother us with output only if something died */
dbglog_set_level(DBG_DEAD);

/* Set the video mode */
vid_set_mode(DM_640x480, PM_RGB565);

for (y=0; y<480; y++)
for (x=0; x<640; x++) {
drawPix(x,y, color);
}


/* Pause to see the results */
usleep(5*1000*1000);

return 0;
}

void drawPix(int x, int y, int color)
{
vram_s[y*640+x] = color;
return;
}

And yes, I know that the default is to read from the root directory. I put the file 'dummy/txt' in the root directory and in the base directory, so I am thinking that the problem lies with dc-tool somewhere.

Mekanaizer
May 20th, 2005, 01:52
Hi

Since you only want to read the dummy.txt file you can read it via Romdisk, here are the changes:


#include <kos.h>
#include <stdio.h>

extern uint8 romdisk[];
KOS_INIT_FLAGS(INIT_DEFAULT|INIT_MALLOCSTATS);
KOS_INIT_ROMDISK(romdisk);

#define _RGB(r, g, b) ((r << 12)|(g << 5)|(b << 0))

void drawPix(int x, int y, int color);

int main(int argc, char **argv) {
int x, y;
int color;
file_t fptr;

fptr = fs_open("/rd/dummy.txt", O_RDONLY);
..........

still you need to change the makefile to your needs on the Romdisk 'use', so check the 'Hello world' KOS example.

or see it here:


#
# Basic KallistiOS skeleton / test program
# (c)2001 Dan Potter
#

# Put the filename of the output binary here
TARGET = hello.elf

# List all of your C files here, but change the extension to ".o"
OBJS = hello.o

all: rm-elf $(TARGET)

include $(KOS_BASE)/Makefile.rules

clean:
-rm -f $(TARGET) $(OBJS) romdisk.*

rm-elf:
-rm -f $(TARGET) romdisk.*

# If you don't need a ROMDISK, then remove "romdisk.o" from the next few
# lines. Also change the -l arguments to include everything you need,
# such as -lmp3, etc.. these will need to go _before_ $(KOS_LIBS)
$(TARGET): $(OBJS) romdisk.o
$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET) $(KOS_START) \
$(OBJS) romdisk.o $(OBJEXTRA) $(KOS_LIBS)

# You can safely remove the next two targets if you don't use a ROMDISK
romdisk.img:
$(KOS_GENROMFS) -f romdisk.img -d romdisk -v

romdisk.o: romdisk.img
$(KOS_BASE)/utils/bin2o/bin2o romdisk.img romdisk romdisk.o

run: $(TARGET)
$(KOS_LOADER) $(TARGET)

dist:
rm -f $(OBJS) romdisk.o romdisk.img
$(KOS_STRIP) $(TARGET)
-Mekanaizer-

pnpbios
May 20th, 2005, 08:08
I'm not interested in the romdisk, that isn't teaching me what I want to know.

I found a cheap trick that will work for me, and this is probably what I am going to do.

Instead of messing with paths and such, I use mkisofs on my content directory to turn it into an ISO, then i just load that over with DC-Tool.

now, if only I could get mkisofs to run from my makefile, i would be set.