Updated Nintendo DS support
Frank Zago This patch updates the DS port: - do not use the now removed compat layer. - integrate parts of libgl2D since I got permission from the author, and thus removed an external dependancy, - a few bugs fixes. Now, the textures should be completely supported, except reading from them which doesn't makes sense to have on the DS. Sound is still not supported. If someone else wants to work on the missing pieces, feel free.
This commit is contained in:
parent
9514b6a286
commit
982b4b8c20
11 changed files with 613 additions and 99 deletions
|
@ -28,7 +28,7 @@ ARCH := -mthumb -mthumb-interwork
|
|||
# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
|
||||
# *insists* it has a FPU or VFP, and it won't take no for an answer!
|
||||
CFLAGS := -save-temps -g -Wall -O0\
|
||||
-mcpu=arm9tdmi -mtune=arm9tdmi \
|
||||
-mcpu=arm9tdmi -mtune=arm9tdmi \
|
||||
$(ARCH)
|
||||
|
||||
CFLAGS += $(INCLUDE) -DARM9 -D__NDS__
|
||||
|
@ -41,23 +41,23 @@ LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)
|
|||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lSDL -lfat -lnds9
|
||||
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(LIBNDS)
|
||||
|
||||
LIBDIRS := $(LIBNDS) $(PORTLIBS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
|
@ -67,7 +67,7 @@ CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
|||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
|
@ -84,32 +84,31 @@ endif
|
|||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
|
||||
.PHONY: $(BUILD) clean
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba
|
||||
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
|
@ -117,16 +116,16 @@ $(OUTPUT).ds.gba : $(OUTPUT).nds
|
|||
$(OUTPUT).nds : $(OUTPUT).arm9
|
||||
$(OUTPUT).arm9 : $(OUTPUT).elf
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.pcx.o : %.pcx
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
|
||||
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
|
|
|
@ -1,39 +1,34 @@
|
|||
|
||||
/*
|
||||
* Really basic sample for the NDS.
|
||||
*
|
||||
* Fills a rectangle increasingly smaller of random color every time a
|
||||
* button (a, b, x, y) is pressed.
|
||||
*
|
||||
* The behaviour whether SDL is compiled with HW support or not (see
|
||||
* USE_HW_RENDERER in Makefile.ds).
|
||||
*
|
||||
* In framebuffer mode, the old rectangles stay because the screen has
|
||||
* not been cleared.
|
||||
*
|
||||
* In accelerated mode, old the last rectangle is visible.
|
||||
*
|
||||
* No text is displayed.
|
||||
*/
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#if defined(NDS) || defined(__NDS__) || defined (__NDS)
|
||||
#include <nds.h>
|
||||
#include <fat.h>
|
||||
#else
|
||||
#define swiWaitForVBlank()
|
||||
#define consoleDemoInit()
|
||||
#define fatInitDefault()
|
||||
#define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3))
|
||||
#endif
|
||||
void
|
||||
splash(SDL_Surface * screen, int s)
|
||||
{
|
||||
SDL_Surface *logo;
|
||||
SDL_Rect area = { 0, 0, 256, 192 };
|
||||
|
||||
logo = SDL_LoadBMP("sdl.bmp");
|
||||
if (!logo) {
|
||||
printf("Couldn't splash.\n");
|
||||
return;
|
||||
}
|
||||
/*logo->flags &= ~SDL_PREALLOC; */
|
||||
SDL_BlitSurface(logo, NULL, screen, &area);
|
||||
SDL_Flip(screen);
|
||||
while (s-- > 0) {
|
||||
int i = 60;
|
||||
while (--i)
|
||||
swiWaitForVBlank();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
int main(void)
|
||||
{
|
||||
SDL_Surface *screen;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Joystick *stick;
|
||||
SDL_Event event;
|
||||
SDL_Rect rect = { 0, 0, 256, 192 };
|
||||
|
@ -41,48 +36,48 @@ main(void)
|
|||
|
||||
consoleDemoInit();
|
||||
puts("Hello world! Initializing FAT...");
|
||||
fatInitDefault();
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
|
||||
puts("# error initializing SDL");
|
||||
puts(SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
puts("* initialized SDL");
|
||||
screen = SDL_SetVideoMode(256, 192, 15, SDL_SWSURFACE);
|
||||
if (!screen) {
|
||||
puts("# error setting video mode");
|
||||
puts(SDL_GetError());
|
||||
return 2;
|
||||
|
||||
if (SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_ACCELERATED, &window, &renderer) < 0 &&
|
||||
SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_SOFTWARE, &window, &renderer) < 0) {
|
||||
exit(1);
|
||||
}
|
||||
screen->flags &= ~SDL_PREALLOC;
|
||||
puts("* set video mode");
|
||||
|
||||
stick = SDL_JoystickOpen(0);
|
||||
if (stick == NULL) {
|
||||
puts("# error opening joystick");
|
||||
puts(SDL_GetError());
|
||||
// return 3;
|
||||
}
|
||||
puts("* opened joystick");
|
||||
|
||||
/*splash(screen, 3); */
|
||||
|
||||
SDL_FillRect(screen, &rect, RGB15(0, 0, 31) | 0x8000);
|
||||
SDL_Flip(screen);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
while (1)
|
||||
while (SDL_PollEvent(&event))
|
||||
switch (event.type) {
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
SDL_FillRect(screen, &rect, (u16) rand() | 0x8000);
|
||||
SDL_Flip(screen);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, rand(), rand(), rand(), SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
SDL_RenderPresent(renderer);
|
||||
if (rect.w > 8) {
|
||||
rect.x += 4;
|
||||
rect.y += 3;
|
||||
rect.w -= 8;
|
||||
rect.h -= 6;
|
||||
}
|
||||
printf("button %d pressed at %d ticks\n",
|
||||
event.jbutton.button, SDL_GetTicks());
|
||||
/*
|
||||
printf("button %d pressed at %d ticks\n",
|
||||
event.jbutton.button, SDL_GetTicks());
|
||||
*/
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
SDL_Quit();
|
||||
|
@ -90,7 +85,5 @@ main(void)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue