Add NES building and adapt example functions

This commit is contained in:
2023-11-01 13:58:22 +01:00
parent 5c404b5faf
commit 9be90d7629
33 changed files with 3951 additions and 35 deletions

View File

@ -3,7 +3,7 @@ AppSources = $(wildcard *.c)
AppHeaders = $(wildcard *.h)
SpaccSources = $(wildcard ../../LibMultiSpacc/*.c)
SpaccHeaders = $(wildcard ../../LibMultiSpacc/*.h)
CFlags = -Os -Wpedantic -Werror
CFlags = -Os -Werror -Wpedantic -Wdeclaration-after-statement
# Default build is always for the host system
ifndef Target
@ -36,30 +36,37 @@ ifeq ($(MultiSpacc_Target), SDL12)
Defines += -DMultiSpacc_Target_SDL12 -DMultiSpacc_Target_SDLCom
CFlags += $(shell sdl-config --cflags)
LdFlags += $(shell sdl-config --libs) -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf
BuildProcess = Normal
BuildProcess = __Normal__
else ifeq ($(MultiSpacc_Target), SDL20)
Defines += -DMultiSpacc_Target_SDL20 -DMultiSpacc_Target_SDLCom
CFlags += $(shell sdl2-config --cflags)
LdFlags += $(shell sdl2-config --libs) -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf
BuildProcess = Normal
BuildProcess = __Normal__
else ifeq ($(MultiSpacc_Target), NDS)
Defines += -DMultiSpacc_Target_NDS
BuildProcess = NDS
BuildProcess = __NDS__
else ifeq ($(MultiSpacc_Target), NES)
Defines += -DMultiSpacc_Target_NES
BuildProcess = NES
BuildProcess = __NES__
endif
CC = $(ToolsPrefix)gcc $(CFlags) $(Defines)
BuildSources = $(AppSources) $(SpaccSources)
Objects = $(BuildSources:.c=.o)
Shell = $(shell echo $$SHELL)
AppObjects = $(AppSources:.c=.o)
SpaccObjects = $(SpaccSources:.c=.o)
BuildObjects = $(AppObjects) $(SpaccObjects)
#BuildSources = $(AppSources) $(SpaccSources)
#Objects = $(BuildSources:.c=.o)
All all: $(BuildProcess)
Normal: $(Objects)
# TODO: use virtual build dirs even for normals to allow linking against different wrapped libraries
__Normal__: $(BuildObjects)
$(CC) $^ $(LdFlags) -o $(AppName)$(ExeSuffix)
NDS:
# TODO: Fix include substitutions properly in non-standard build processes
__NDS__:
$(eval VirtualBuildDir = ./Build/NDS)
mkdir -p $(VirtualBuildDir)/source/.tmp
cp ../NDS.mk $(VirtualBuildDir)/Makefile
@ -71,8 +78,20 @@ NDS:
for i in $(VirtualBuildDir)/source/*; do sed -i 's|#include[ \t]"./|#include "./LibMultiSpacc_|g' $$i; done
cd $(VirtualBuildDir); make
NES:
#
__NES__:
cd ../../neslib; make
$(eval VirtualBuildDir = ./Build/NES)
mkdir -p $(VirtualBuildDir)/.tmp
cp $(SpaccSources) $(SpaccHeaders) $(VirtualBuildDir)/.tmp/
cd $(VirtualBuildDir)/.tmp; for i in *; do mv ./$$i ../LibMultiSpacc_$$i; done
cp $(AppSources) $(AppHeaders) $(VirtualBuildDir)/
for i in $(VirtualBuildDir)/*; do sed -i 's|#include[ \t]"../../LibMultiSpacc/|#include "LibMultiSpacc_|g' $$i; done
for i in $(VirtualBuildDir)/*; do sed -i 's|#include[ \t]"../MultiSpacc|#include "LibMultiSpacc_MultiSpacc|g' $$i; done
for i in $(VirtualBuildDir)/*; do sed -i 's|#include[ \t]"./|#include "./LibMultiSpacc_|g' $$i; done
cp ../../neslib/*.cfg ../../neslib/crt0.o ../../neslib/chr_generic.o ../../neslib/*.lib ../../neslib/*.h $(VirtualBuildDir)/
echo "AppName='$(AppName)'; Defines='$(Defines)'; AppSources='$(AppSources)'; SpaccSources='$(SpaccSources)'; AppObjects='$(AppObjects)'; BuildObjects='$(BuildObjects)';" > $(VirtualBuildDir)/Make.sh
cat ../NES.mk.sh >> $(VirtualBuildDir)/Make.sh
cd $(VirtualBuildDir); $(Shell) ./Make.sh
Run run: All
./$(AppName)$(ExeSuffix)
@ -80,5 +99,5 @@ Run run: All
Clean clean Clear clear:
find -L . -name "*.o" -type f -delete
find -L ../../LibMultiSpacc -name "*.o" -type f -delete
rm -f ./$(AppName)$(ExeSuffix) ./$(AppName).*$(ExeSuffix)
rm -f ./$(AppName)$(ExeSuffix)
rm -rf ./Build

View File

@ -2,16 +2,38 @@
#define AppName "Hello World"
/*{pal:"nes",layout:"nes"}*/
const char PALETTE[32] = {
0x03, // screen
0x11,0x30,0x27,0x00, // background 0
0x1c,0x20,0x2c,0x00, // background 1
0x00,0x10,0x20,0x00, // background 2
0x06,0x16,0x26,0x00, // background 3
0x16,0x35,0x24,0x00, // sprite 0
0x00,0x37,0x25,0x00, // sprite 1
0x0d,0x2d,0x3a,0x00, // sprite 2
0x0d,0x27,0x2a, // sprite 3
};
int main( int argc, char *argv[] )
{
int spriteX = 0;
int spriteY = 0;
int accelX = +2;
int accelX = +1;
int accelY = +2;
MultiSpacc_SurfaceConfig WindowConfig = { .Width = 320, .Height = 240, .Bits = 16 };
MultiSpacc_Window *Window = MultiSpacc_SetWindow( WindowConfig );
MultiSpacc_Surface *Screen = MultiSpacc_GetWindowSurface( Window );
MultiSpacc_SurfaceConfig WindowConfig = {0};
MultiSpacc_Window *Window;
MultiSpacc_Surface *Screen;
MultiSpacc_Surface *TilesImg;
WindowConfig.Width = 256;
WindowConfig.Height = 240;
WindowConfig.Bits = 16;
memcpy( WindowConfig.Palette, PALETTE, 32 );
//WindowConfig.Frequency = 50;
Window = MultiSpacc_SetWindow( &WindowConfig /*, &PALETTE*/ );
Screen = MultiSpacc_GetWindowSurface( Window );
if( Screen == NULL )
{
@ -23,19 +45,14 @@ int main( int argc, char *argv[] )
// Bitmap font borrowed from: <https://github.com/nesdoug/01_Hello/blob/master/Alpha.chr>
// Copyright (c) 2018 Doug Fraker www.nesdoug.com (MIT)
MultiSpacc_Surface *TilesImg = MultiSpacc_LoadImage( "Tiles.png", Screen, NULL );
MultiSpacc_PrintText( "Hello, World!", Screen, WindowConfig, 0, 0, TilesImg );
//TilesImg = MultiSpacc_LoadImage( "Tiles.png", Screen, NULL );
MultiSpacc_PrintText( "Hello, World!", Screen, &WindowConfig, 2, 2, TilesImg );
MultiSpacc_PrintDebug("[I] Ready!\n");
// if( MultiSpacc_UpdateWindowSurface(Window) != 0 )
// {
// MultiSpacc_PrintDebug("[E] Error Updating Screen.\n");
// return -1;
// };
while(true)
{
MultiSpacc_Sprite( 0, spriteX, spriteY, 0x80, TilesImg, Screen );
MultiSpacc_Sprite( 0, spriteX, spriteY, 20/*128*/, TilesImg, Screen );
//scroll(spriteX,0);
spriteX += accelX;
spriteY += accelY;
@ -57,9 +74,8 @@ int main( int argc, char *argv[] )
};
// TODO: Implement cross-platform vblank-wait
MultiSpacc_Sleep(16);
//MultiSpacc_Sleep(16);
}
//MultiSpacc_Sleep(4000);
return 0;
}

View File

@ -0,0 +1,14 @@
#!/dev/null
set -e
# ${SpaccSources} ${AppSources} ${SpaccObjects} ${AppObjects} chr_generic.s chr_generic.o crt0.o
for File in *.c
do cc65 -Oirs --target nes ${File} ${Defines}
done
for File in *.s
do ca65 --target nes ${File}
done
ld65 -v -o ${AppName}.nes *.o *.lib nes.lib --config NROM256.cfg -DNES_MAPPER=0 -DNES_PRG_BANKS=2 -DNES_CHR_BANKS=1 -DNES_MIRRORING=0