Makefile problems compiling an SDL app

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.
Post Reply
Silent Marauder
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 24
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Jul 21, 2004 8:06 pm
Has thanked: 0
Been thanked: 0

Makefile problems compiling an SDL app

Post by Silent Marauder »

Hi, everyone. This is (I think) my first post here, since I only started working with SDL yesterday. I've got a very simple sprite app working on my PC, and I'm trying to port it to DC so I can learn how to do this in the future.

I'm working with the DC Development Kit-on-an-ISO made by LyingWake (I think I have that right?), with cygwin under Windows XP Pro.

Unfortunately, because I haven't worked with makefiles before (I'm really a VC++ 6.0 kind of guy), I'm having all sorts of problems. The most I've ever done with a makefile before was to alter the source and target objects, so I'm in over my head here, I think.

I was getting all sorts of errors at first, mostly stemming from the fact that GCC couldn't find SDL.h, SDL_mixer.h (left in my program for future reference - if it won't work now, it won't work then), and SDL_ttf.h. I tried working from two example SDL-using makefiles (one from here and one from DCEmu.co.uk), and neither one would tell GCC where to look. The only way I could finally move past that error was to go into kos-ports/include/SDL and copy everything into my project directory (C:\cygwin\usr\local\dc\kos1.3\kos\techdemo). Then GCC started whining about my timing routine (int clock = SDL_GetTicks(); ) and mismatched types, so I commented all that stuff out. Then GCC started complaining about itoa() being undefined (I use it to append the sprite's position to a basic string -- I'm working with #include <string>, if there's anything better I can use, please tell me :) ), so I commented that line out. Now I'm getting about four dozen dozen linker errors that seem to be saying that I don't have a standard library. There also seem to be a few errors referring to the SDL_TTF library.

From what I've been reading on here and elsewhere, I was under the impression that at least part of the STL worked under KOS/SDL? I've worked with pointers, can write my own linked lists, etc., but I have neither the time nor the desire to reinvent the string class.

My makefile is here:

Code: Select all

TARGET = target.elf
OBJS = main.o sprite.o

all: rm-elf $(TARGET)

include $(KOS_BASE)/Makefile.rules
 
KOS_CFLAGS += -DENABLE_FOCUS

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

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

$(TARGET): $(OBJS) 
	$(KOS_CCPLUS) $(KOS_CFLAGS) $(KOS_CPPFLAGS) $(KOS_LDFLAGS) -I$(KOS_BASE)/../kos-ports/include/SDL -o $(TARGET) $(KOS_START) \
		$(OBJS) $(OBJEXTRA) -L$(KOS_BASE)/lib -lgcc -lSDL -lpng -lz -ljpeg -lSDL_mixer -lSDL_image -lSDL_TTF -lSDL -lpng -lz -ljpeg -lm -lk++ $(KOS_LIBS)

run: $(TARGET)
	$(KOS_LOADER) $(TARGET)
Very simple, as you can see. The sprite.o refers to a very basic class I whipped up to test images under SDL -- if I can actually get something to compile, I'm hopefully going to have a Pong clone working soon.

Since I have only a very vague idea what a ROMDISK is, I'm not using one, but I don't think that should be causing the kind of errors I'm getting.

I've already tried both source environ.sh, and source environ_dreamcast.sh, and neither one seems to make any difference.

My #includes are as follows:

Code: Select all

#include "SDL.h"
#include "SDL_ttf.h"
#include "SDL_mixer.h"
#include <stack>
#include <string>
#include "sprite.h"
The program compiled and worked perfectly under Windows, so I know the code itself is fine as long as I can get the libraries included and linked.

I do appreciate any help you can offer!

EDIT:
I should add I'm also getting the ubiquitous "___gxx_personality_v0" error - which doesn't make any sense, since I'm using CPPFLAGS in addition to CFLAGS, and I have absolutely no exceptions in my code.
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY
Has thanked: 0
Been thanked: 0

Re: Makefile problems compiling an SDL app

Post by OneThirty8 »

Silent Marauder wrote:

Code: Select all

TARGET = target.elf
OBJS = main.o sprite.o

all: rm-elf $(TARGET)

include $(KOS_BASE)/Makefile.rules
 
KOS_CFLAGS += -DENABLE_FOCUS

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

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

$(TARGET): $(OBJS) 
	$(KOS_CCPLUS) $(KOS_CFLAGS) $(KOS_CPPFLAGS) $(KOS_LDFLAGS) -I$(KOS_BASE)/../kos-ports/include/SDL -o $(TARGET) $(KOS_START) \
		$(OBJS) $(OBJEXTRA) -L$(KOS_BASE)/lib -lgcc -lSDL -lpng -lz -ljpeg -lSDL_mixer -lSDL_image -lSDL_TTF -lSDL -lpng -lz -ljpeg -lm -lk++ $(KOS_LIBS)

run: $(TARGET)
	$(KOS_LOADER) $(TARGET)
Try changing this line:
KOS_CFLAGS += -DENABLE_FOCUS

-I$(KOS_BASE)/../kos-ports/include/SDL should go there, instead of where you have it, iirc.
Silent Marauder
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 24
Joined: Wed Jul 21, 2004 8:06 pm
Has thanked: 0
Been thanked: 0

Post by Silent Marauder »

Do you mean replace it with the -I $(KOS_BASE)... line, or add the line after the KOS_CFLAGS += -DENABLE_FOCUS line? I can't add it in without getting a "missing separator" error, so I don't think that'll work. Same with replacing the line altogether.

When I type make, am I supposed to see such a short command invoking the compiler? What I mean is that despite all of the flags that are set to be enabled, when I run the makefile, I only see the following:

Code: Select all

rm -f target.elf romdisk.*
kos-c++ -c main.cpp -o main.o

(followed by lots and lots of errors)
It looks like make isn't parsing the makefile correctly?
Silent Marauder
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 24
Joined: Wed Jul 21, 2004 8:06 pm
Has thanked: 0
Been thanked: 0

Post by Silent Marauder »

Well, I finally figured out how to get rid of all of the "missing separator" errors in the example makefile posted in this forum, so I began using that one instead of the one from DCEmu.uk. The -I$(KOS_BASE)/../kos-ports/include/SDL line was exactly the same in this new makefile, yet it magically worked where the old one did not.

I also actually see all of the flags on the line that calls the compiler with this makefile, and it managed to include everything correctly (I removed all of the copied SDL*.h files from my directory first to make sure).

But that still leaves me with the million or so link errors I had before.I'm still getting the __gxx_personality_v0 error, despite having no exceptions in my code. I'm getting numerous "undefined reference" errors for the STL (the string class, specifically), and for SDL_TTF.

Here are the errors I get"

Code: Select all

main.o(.text+0x2dc): In function `_main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a
llocator<char> >::basic_string(char const*, std::allocator<char> const&)'
main.o(.text+0x2e4): In function `_main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a
llocator<char> >::_Rep::_S_empty_rep_storage'
main.o(.text+0x2e8): In function `_main':
: undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
main.o(.text+0x2ec): In function `_main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a
llocator<char> >::_Rep::_M_destroy(std::allocator<char> const&)'
main.o(.text+0x2f8): In function `_main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a
llocator<char> >::_Rep::_S_empty_rep_storage'
main.o(.text+0x328): In function `_main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a
llocator<char> >::assign(char const*, unsigned int)'
main.o(.text+0x32c): In function `_main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a
llocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, s
td::allocator<char> > const&)'
main.o(.text+0x4bc): In function `_main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a
llocator<char> >::_Rep::_S_empty_rep_storage'
main.o(.text+0x4c0): In function `_main':
: undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
main.o(.text+0x4c4): In function `_main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a
llocator<char> >::_Rep::_M_destroy(std::allocator<char> const&)'
main.o(.text+0x558): In function `_main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a
llocator<char> >::_Rep::_S_empty_rep_storage'
main.o(.text+0x55c): In function `_main':
: undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
main.o(.text+0x560): In function `_main':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a
llocator<char> >::_Rep::_M_destroy(std::allocator<char> const&)'
main.o(.eh_frame+0x13): undefined reference to `___gxx_personality_v0'
sprite.o(.eh_frame+0x12): undefined reference to `___gxx_personality_v0'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x54
): In function `TTF_Init':
/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:148: undefined reference to
 `_FT_Init_FreeType'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x1a
0): In function `TTF_CloseFont':
/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:469: undefined reference to
 `_FT_Done_Face'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x3b
0): In function `TTF_OpenFontIndex':
/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:212: undefined reference to
 `_FT_New_Face'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x3b
8):/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:212: undefined reference
 to `_FT_Set_Char_Size'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x3b
c):/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:212: undefined reference
 to `_FT_MulFix'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x3c
8):/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:212: undefined reference
 to `_FT_Done_Face'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x77
0): In function `Find_Glyph':
/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:463: undefined reference to
 `_FT_Load_Glyph'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x77
4):/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:463: undefined reference
 to `_FT_Render_Glyph'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x91
c):/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:313: undefined reference
 to `_FT_Get_Char_Index'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x92
0):/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:313: undefined reference
 to `_FT_Render_Glyph'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0xb5
c):/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:404: undefined reference
 to `_FT_Outline_Transform'
/usr/local/dc/kos1.3/kos/addons/lib/dreamcast/libSDL_TTF.a(SDL_ttf.o)(.text+0x22
b8): In function `TTF_Quit':
/usr/local/dc/kos1.3/kos-ports/SDL/SDL_ttf/SDL_ttf.c:1300: undefined reference t
o `_FT_Done_FreeType'
collect2: ld returned 1 exit status
make: *** [target.elf] Error 1
(BTW, can anyone recommend a good, usable-on-Dreamcast String class, so I can try and avoid these STL errors?)

Here's the new makefile:

Code: Select all

#SDL Makefile

INC =-DDREAMCAST -DSDL -DINLINE=__inline__

TARGET = target.elf

OBJS= main.o sprite.o

all: target.bin  rm-elf $(TARGET)

include $(KOS_BASE)/Makefile.rules

OPT1= -Os
KOS_CFLAGS = $(INC) -ml -m4-single-only -D_arch_dreamcast -D_arch_sub_pristine  \
$(OPT1) -I$(KOS_BASE)/../kos-ports/include -I$(KOS_BASE)/include -I$(KOS_BASE)/kernel/arch/dreamcast/include -I$(KOS_BASE)/addons/include -I$(KOS_BASE)/include -I$(KOS_BASE)/addons/include -I$(KOS_BASE)/../kos-ports/include  -I$(KOS_BASE)/../kos-ports/include/zlib -I$(KOS_BASE)/../kos-ports/libpng -I$(KOS_BASE)/../kos-ports/include/SDL

clean:
	-rm -f $(TARGET) $(OBJS) romdisk.* target.bin 1ST_READ.bin

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

$(TARGET): $(OBJS) $(PROBJS) romdisk.o
	$(KOS_CCPLUS) $(KOS_CFLAGS) $(KOS_CPPFLAGS) $(KOS_LDFLAGS) -o $(TARGET) $(KOS_START) $(OBJS) $(PROBJS) romdisk.o -L$(KOS_BASE)/lib -lgcc -lSDL -lSDL_Mixer -lSDL -loggvorbisplay -ltremor -loggvorbisplay -lpng -lz -lSDL_TTF -lk++ -lm $(KOS_LIBS)

romdisk.img:
	$(KOS_GENROMFS) -f romdisk.img -d romdisk -v

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

target.bin: $(TARGET)
	$(KOS_OBJCOPY) -O binary -R .stack $(TARGET) target.bin
	$(KOS_BASE)/utils/scramble/scramble target.bin 1ST_READ.bin

run: $(TARGET)
	dc-tool -t 192.168.0.2 -i DC.iso -x target.bin
The line that calls the compiler here is actually just one REALLY long line, not multiple lines as it looks like posted here.

Thank you for your help so far.
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 »

change the -lk++ to -lstdc++ to link with.

also SDL_ttf requires lib freetype -lfreetype

Troy
Silent Marauder
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 24
Joined: Wed Jul 21, 2004 8:06 pm
Has thanked: 0
Been thanked: 0

Post by Silent Marauder »

Thank you so much! Linking stdc++ works, but when I try adding -lfreetype, the linker gives me a "cannot find -lfreetype" error. I assume this is because I need to compile the freetype library, but when I go into kos-ports/freetype and type make, the makefile stops with the following error:

Code: Select all

make: *** No rule to make target `/usr/local/dc/kos1.3/kos/include/freetype/cache/ftlru.h', needed by `objs/ftcache.o'.  Stop.
Silent Marauder
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 24
Joined: Wed Jul 21, 2004 8:06 pm
Has thanked: 0
Been thanked: 0

Post by Silent Marauder »

For now, I've decided to forget about SDL_TTF and just comment out all the stuff that uses it in my code. It finally compiles, and the makefile gives me a nice ready-to-go scrambled binary. I use sezious's IP.BIN maker to create an IP.BIN for my disc, (this was after several hours of cdi2nero not giving me a working image of DemoMenu to use), make sure all the files I need are in the same directory (basically just the one sprite), and I run Selfboot.exe to get an image. I burn it, put it in the DC, and it does boot - to a black screen after the SEGA logo disappears. No sprite to be found anywhere.

I don't know if I'm using the wrong video mode or what.

main.cpp:

Code: Select all

//ElectroPong

#include "SDL.h"
#include "SDL_mixer.h" //left in since I hope this will use sound someday
#include <stack>
#include <string>
#include "sprite.h" //my own basic sprite class

//constants
const int FRAMERATE = 1000 / 30;

//global variables (eww!)
SDL_Surface* backBuffer = NULL;
int clocky;

//Borrowed from Aaron Cox's game programming tutorials
struct StateStruct 
{
	void (*StatePointer)();
};
//End borrowed code

//function headers
void init();

int main(int argc, char **argv)
{
	fs_chdir("/cd");
	init();
	
        SDL_Event event;
        gameRunning = true;

	Sprite test("duck.bmp", 48, 48, 1, 0);
	test.setPos(296,216);
	test.setSpeed(0,0);

	SDL_Joystick* control_pad = SDL_JoystickOpen(0);

	if(!control_pad)
		gameRunning = false;

	SDL_JoystickEventState(SDL_ENABLE);

	int startButton, analogX, analogY;

   while (gameRunning)
   {
		if((SDL_GetTicks() - clocky) >= FRAMERATE)
		{
			SDL_FillRect(backBuffer, 0, 0);
			test.draw(backBuffer);
			if((test.getX() > 640) || (test.getX() < -48))
				test.setSpeed(-test.getDeltaX(), test.getDeltaY());
			if((test.getY() > 480) || (test.getY() < -48))
				test.setSpeed(test.getDeltaX(), -test.getDeltaY());
			char buffer[256];
			SDL_Flip(backBuffer);

                        //yes, I realize I forgot to add "clocky = SDL_GetTicks()" here, but since SDL_GetTicks() should always be greater without this line, the loop should still run continuously
		}
		
      			if (SDL_PollEvent(&event))
      			{
      			   if ((event.type == SDL_QUIT))
         		   {
            			gameRunning = false;
         		   }
			   else
			   {
				analogX = SDL_JoystickGetAxis(control_pad, 0);
				analogY = SDL_JoystickGetAxis(control_pad, 1);
				startButton = SDL_JoystickGetButton(control_pad, 4);

				if(startButton)
					gameRunning = false;

				test.setPos(test.getX() + (analogX / 4), test.getY() + (analogY / 4));
				if(test.getX() < 0)
					test.setPos(0, test.getY());
				else if(test.getX() > 592)
					test.setPos(592, test.getY());
				if(test.getY() < 0)
					test.setPos(test.getX(), 0);
				else if(test.getY() > 432)
					test.setPos(test.getX(), 432);
			   }

     			}

   }

	SDL_JoystickClose(control_pad);
   SDL_FreeSurface(backBuffer);
   SDL_Quit();

   return 0;
}

void init()
{
	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK);
	SDL_ShowCursor(SDL_DISABLE);

	backBuffer = SDL_SetVideoMode(640, 480, 24, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
	clocky = SDL_GetTicks();

}
That's my main.cpp with the commented-out code removed. Any help would be greatly appreciated by this newbie! :)
User avatar
greay
DCEmu Ultra Poster
DCEmu Ultra Poster
Posts: 1938
Joined: Wed Jan 21, 2004 10:59 am
Location: 24 hours from Tulsa
Has thanked: 0
Been thanked: 0
Contact:

Post by greay »

I don't do C++ (or, well, SDL for that matter) so I'll stay pretty much out of tihs one, but I'd recommend logging as much stuff as you can to the console, to try & see if it's hanging somewhere or what's going wrong.
I'm a lone wolf looking for trouble.
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY
Has thanked: 0
Been thanked: 0

Post by OneThirty8 »

Try commenting out a line or three, like so...

Code: Select all

while (gameRunning)
   {
 /*     if((SDL_GetTicks() - clocky) >= FRAMERATE)
      {  Get rid of this for now... */
         SDL_FillRect(backBuffer, 0, 0);
         test.draw(backBuffer);
         if((test.getX() > 640) || (test.getX() < -48))
            test.setSpeed(-test.getDeltaX(), test.getDeltaY());
         if((test.getY() > 480) || (test.getY() < -48))
            test.setSpeed(test.getDeltaX(), -test.getDeltaY());
         char buffer[256];
         SDL_Flip(backBuffer);

                        //yes, I realize I forgot to add "clocky = SDL_GetTicks()" here, but since SDL_GetTicks() should always be greater without this line, the loop should still run continuously
   /*   }   get rid of this for now... */
      
              if (SDL_PollEvent(&event))
               {
                  if ((event.type == SDL_QUIT))
                  {
                     gameRunning = false;
                  }
            else
            {
            analogX = SDL_JoystickGetAxis(control_pad, 0);
            analogY = SDL_JoystickGetAxis(control_pad, 1);
            startButton = SDL_JoystickGetButton(control_pad, 4);

            if(startButton)
               gameRunning = false;

            test.setPos(test.getX() + (analogX / 4), test.getY() + (analogY / 4));
            if(test.getX() < 0)
               test.setPos(0, test.getY());
            else if(test.getX() > 592)
               test.setPos(592, test.getY());
            if(test.getY() < 0)
               test.setPos(test.getX(), 0);
            else if(test.getY() > 432)
               test.setPos(test.getX(), 432);
            }

              }

   }
Something tells me that bit about if( (SDL_GetTicks() - clocky) >= framerate) is borking up your code, since that's where you actually draw stuff to the screen. See if it works without it.

*edit*

Code: Select all

   if(!control_pad)
      gameRunning = false;
If what I said to kill doesn't work, try commenting these two lines out instead. I'm not sure if that is doing what you think it's doing.
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 »

try changing the loading of the sprite to include the path
ie
Sprite test("/cd/duck.bmp", 48, 48, 1, 0);

it might be that your code is not loading from the relative path or something.

Also about freetype- if I remember right I think I had some problems building it to. Can't quite remember what I fixed, but it might have been adding -I$(KOS_BASE)/../kos-ports/include to my KOS_INC_PATHS

and for SDL_GetTicks() try replaceing it with timer_ms_gettime64();

or another would be to try to fix SDL_GetTicks which I dont remember if I fixed before releasing the toolchain your using. here is my SDL_GetTicks function

Uint32 SDL_GetTicks(void)
{
// return((jiffies-start)*1000/HZ);
return timer_ms_gettime64()-start;
}


c:\cygwin\usr\local\dc\kos1.3\kos-ports\SDL\base\src\timer\dc\SDL_systimer.c

That might be the fix or not, its been awhile since iv done SDL.

Troy
Silent Marauder
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 24
Joined: Wed Jul 21, 2004 8:06 pm
Has thanked: 0
Been thanked: 0

Post by Silent Marauder »

Thanks a million, guys! After switching to Dchakker + a multisession disc as my new method of testing, I edited out the lines you and OneThirty8 suggested. Now my program works perfectly (albeit very slowly)! :)

This is very encouraging, indeed. Now if only I could find a way to speed up SDL (besides going to 320x240x8bpp)...

P.S.: GPF, where is the KOS_ALL_INCS located? I can't seem to find it, and I still can't get freetype to compile.
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY
Has thanked: 0
Been thanked: 0

Post by OneThirty8 »

Try fixing your SDL_GetTicks() function and your SDL_StartTicks() function like Troy said. That should help a little bit with speed on anything that uses SDL_GetTicks to regulate the framerate at all.. Here's my version of basiacally the same thing Troy showed you above, and my SDL_StartTicks() function as well. I think that there's some unnecessary typecasting in these, but they seem to do the job. Do something like this (copying Troys would probably be easiest, and just do something similar with SDL_StartTicks()), because the way it is by default doesn't seem to really work right.

Code: Select all

void SDL_StartTicks(void)
{

/* Set first ticks value */

/*start = jiffies;*/
 /* 138's hack */
 Uint32 *milis, *secs;
 timer_ms_gettime(secs, milis);
 start = ((Uint32)secs*1000)+(Uint32)milis;
}

Uint32 SDL_GetTicks(void)
{

/*return((jiffies-start)*1000/HZ);*/\
  /* 138's hack */
 Uint32 *milis, *secs;
 timer_ms_gettime(secs, milis);
 return ((((Uint32)secs*1000)+(Uint32)milis)-start);
}
The other thing that is killing your speed is using a 640x480 display. I know you don't want to, but try reworking your code to use 320x240 and you'll probably get acceptable speed if you aren't doing anything too crazy.

/* A question for those more experienced than I am... */

I was thinking about how SDL on Dreamcast actually draws stuff to the screen. Doesn't it basically write one byte or one pixel (so, maybe 2 or more bytes, but not a whole 640x480x2) at a time? Would it make sense to create a RGB Surface in main memory and draw to that, and then instead of calling SDL_Flip(screen), just copy the whole thing over to the framebuffer in one shot using store ques? Is there anything to gain there, or would it be an exercise in futility to try to get it to render a 640x480 screen and maintain a decent framerate?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Post by BlueCrab »

Freetype isn't exactly the easiest beast to compile for KOS, but it is quite possible. I actually use Freetype in my (dreamcast/multiplatform) game engine ljsdcdev. Assuming that you're using KOS 1.3.x (which I guessed since you did get your C++ code to compile), you can get a patch to apply to Freetype 2.1.9 from here: http://ljsdcdev.sunsite.dk/dls/kos/ft219-kos13.diff to get it to compile for KOS. I unfortunately won't be able to provide any more assistance with it for the time being, since I will be away from my computer for the rest of the week/weekend tomorrow morning.

One thing to think about though: its much better not to use SDL on the Dreamcast. As long as you're not doing pixel level access, you might find my game library libcrabclaw helpful for cross-platform stuff. You can read about that here: http://www.ljsdcdev.net/ccdocs/ and get it from http://www.ljsdcdev.net/. Just something to think about.

Also about the idea of using store queues, it wouldn't be such a bad idea, but it would require copying the whole thing over every frame, even if only one pixel was modified. It might be interesting to try to hack about with SDL, and possibly get it to render to a bunch of (for instance) 32x32 pixel areas in main memory, and only transfer the changed ones each time that a redraw is requested. I unfortunately don't have the time to work on something like this at the time.... I actually played with an idea like this when ljsdcdev used to use SDL, but never got far before abandoning any hope for SDL on the dc.
Post Reply