mirror of
https://gitlab.com/octospacc/MultiSpaccSDK
synced 2025-03-03 03:07:51 +01:00
Upd. Makefile and CI, add keypad reading to example, improve lib internals
This commit is contained in:
parent
2026d954ee
commit
014f3eabab
@ -3,15 +3,19 @@ image: debian:latest
|
||||
before_script: |
|
||||
sudo apt update
|
||||
sudo apt install -y \
|
||||
make gcc mingw-w64 wine wine32 cc65 emscripten curl python3 python3-pil \
|
||||
make gcc mingw-w64 wine wine32 cc65 emscripten curl p7zip-full python3 python3-pil \
|
||||
libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libsdl-mixer1.2-dev \
|
||||
libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev \
|
||||
;
|
||||
curl -o ./mingw32.7z https://hlb0.octt.eu.org/Drive/Misc/mingw32-9.2.0.7z.sfx.exe
|
||||
7z x ./mingw32.7z
|
||||
cp ./mingw32/bin/*.dll ./mingw32/libexec/gcc/mingw32/9.2.0/
|
||||
sudo mv ./mingw32 /opt/Sdk/mingw32
|
||||
curl https://apt.devkitpro.org/install-devkitpro-pacman | sudo bash
|
||||
sudo dkp-pacman -Sy nds-dev
|
||||
|
||||
Tests:
|
||||
stage: Tests
|
||||
stage: build
|
||||
script: |
|
||||
cd ./LibMultiSpacc/Examples
|
||||
for Example in */
|
||||
@ -23,6 +27,7 @@ Tests:
|
||||
"Target=WindowsPC MultiSpacc_Target=SDL12"
|
||||
"Target=WindowsPC MultiSpacc_Target=SDL20"
|
||||
"Target=Windows9x"
|
||||
"Target=Web"
|
||||
"Target=NDS"
|
||||
"Target=NES"
|
||||
; do
|
||||
|
@ -1,4 +1,5 @@
|
||||
AppName = $(notdir ${CURDIR})
|
||||
AppName = $(notdir $(CURDIR))
|
||||
AppAssets = CHARS.png
|
||||
AppSources = $(wildcard *.c)
|
||||
AppHeaders = $(wildcard *.h)
|
||||
SpaccSources = $(wildcard ../../LibMultiSpacc/*.c)
|
||||
@ -21,8 +22,6 @@ ifndef Target
|
||||
endif
|
||||
endif
|
||||
|
||||
# TODO: handle building for Windows targets from Linux hosts
|
||||
|
||||
ifeq ($(Target), LinuxPC)
|
||||
ExeSuffix = .run
|
||||
Defines += -DTarget_LinuxPC
|
||||
@ -45,6 +44,7 @@ else ifeq ($(Target), Windows9x)
|
||||
else
|
||||
ToolsSyspath = /opt/Sdk/mingw32/bin
|
||||
ToolsWrapper = wine
|
||||
LdFlags += -LZ:/opt/Sdk/mingw32/lib
|
||||
endif
|
||||
ToolsPrefix = $(ToolsSyspath)/
|
||||
else ifeq ($(Target), Web)
|
||||
@ -70,6 +70,7 @@ else ifeq ($(MultiSpacc_Target), SDL20)
|
||||
BuildProcess = __Normal__
|
||||
else ifeq ($(MultiSpacc_Target), Web)
|
||||
Defines += -DMultiSpacc_Target_Web -DMultiSpacc_Target_SDL20 -DMultiSpacc_Target_SDLCom
|
||||
LdFlags += -sWASM=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sSDL2_IMAGE_FORMATS='["png"]' -sUSE_SDL_TTF=2 -sUSE_SDL_MIXER=2
|
||||
BuildProcess = __Web__
|
||||
else ifeq ($(MultiSpacc_Target), NDS)
|
||||
Defines += -DMultiSpacc_Target_NDS
|
||||
@ -93,8 +94,9 @@ __Normal__: $(BuildObjects)
|
||||
$(CC) $^ $(LdFlags) -o $(AppName)$(ExeSuffix)
|
||||
|
||||
__Web__:
|
||||
emcc $(BuildSources) -sWASM=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sSDL2_IMAGE_FORMATS='["png"]' -sUSE_SDL_TTF=2 -sUSE_SDL_MIXER=2 --preload-file Emscripten -o Emscripten.js
|
||||
cp ../Emscripten.html ./$(AppName.html)
|
||||
mkdir -p ./Build/Web
|
||||
emcc $(BuildSources) $(CFlags) $(Defines) $(LdFlags) --preload-file $(AppAssets) -o ./Build/Web/Emscripten.js
|
||||
cp ../Emscripten.html ./Build/Web/$(AppName).html
|
||||
# TODO: bundle JS, WASM, and assets package in HTML file
|
||||
|
||||
# TODO: Fix include substitutions properly in non-standard build processes
|
||||
|
@ -10,11 +10,13 @@ typedef struct MainArgs {
|
||||
MultiSpacc_SurfaceConfig *WindowConfig;
|
||||
MultiSpacc_Window *Window;
|
||||
MultiSpacc_Surface *Screen;
|
||||
MultiSpacc_Surface *Background;
|
||||
MultiSpacc_Surface *Foreground;
|
||||
MultiSpacc_Surface *TilesImg;
|
||||
} MainArgs;
|
||||
|
||||
/*{pal:"nes",layout:"nes"}*/
|
||||
const char PALETTE[32] = {
|
||||
const char palette[32] = {
|
||||
0x03, // screen
|
||||
0x11,0x30,0x27,0x00, // background 0
|
||||
0x1c,0x20,0x2c,0x00, // background 1
|
||||
@ -33,6 +35,7 @@ bool MainLoop( void *args )
|
||||
MainArgs *margs = (MainArgs*)args;
|
||||
|
||||
MultiSpacc_Sprite( 0, margs->spriteX, margs->spriteY, 1, margs->TilesImg, margs->Screen );
|
||||
// ... this must go on Foreground
|
||||
//scroll(spriteX,0);
|
||||
|
||||
margs->spriteX += margs->accelX;
|
||||
@ -42,21 +45,25 @@ bool MainLoop( void *args )
|
||||
{
|
||||
margs->spriteX = 0;
|
||||
}
|
||||
|
||||
if( margs->spriteY == 0 || margs->spriteY == ( margs->WindowConfig->Height - 8 ) )
|
||||
{
|
||||
margs->accelY *= -1;
|
||||
}
|
||||
|
||||
// check keys
|
||||
// if ESC pressed exit
|
||||
// ...
|
||||
/* TODO: listen for OS terminate signal */
|
||||
if( MultiSpacc_CheckKey( MultiSpacc_Key_Pause, 0 ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !MultiSpacc_WaitUpdateDisplay( margs->Window, &nextTick ) )
|
||||
{
|
||||
MultiSpacc_PrintDebug("[E] Error Updating Screen.\n");
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
// apply Background and then Foreground on Screen
|
||||
// ...
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -73,12 +80,11 @@ int main( int argc, char *argv[] )
|
||||
WindowConfig.Width = 320;
|
||||
WindowConfig.Height = 240;
|
||||
WindowConfig.Bits = 16;
|
||||
memcpy( WindowConfig.Palette, PALETTE, 32 );
|
||||
memcpy( WindowConfig.Palette, palette, 32 );
|
||||
//WindowConfig.Frequency = 50;
|
||||
|
||||
margs.Window = MultiSpacc_SetWindow( &WindowConfig );
|
||||
margs.Screen = MultiSpacc_GetWindowSurface( margs.Window );
|
||||
|
||||
if( margs.Screen == NULL )
|
||||
{
|
||||
MultiSpacc_PrintDebug("[E] Error Initializing Video System.\n");
|
||||
@ -91,7 +97,13 @@ 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)
|
||||
margs.TilesImg = MultiSpacc_LoadImage( "CHARS.png", margs.Screen, NULL );
|
||||
if( margs.TilesImg == NULL )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
MultiSpacc_PrintText( "Hello, World!", margs.Screen, &WindowConfig, 2, 2, margs.TilesImg );
|
||||
// ... this must print on Background
|
||||
|
||||
return MultiSpacc_SetMainLoop( MainLoop, &margs );
|
||||
}
|
||||
|
18
LibMultiSpacc/LibMultiSpacc/Keys.c
Normal file
18
LibMultiSpacc/LibMultiSpacc/Keys.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include "./MultiSpacc.h"
|
||||
|
||||
bool MultiSpacc_CheckKey( char key, char pad )
|
||||
{
|
||||
#if defined(MultiSpacc_Target_SDLCom)
|
||||
SDL_Event event;
|
||||
while( SDL_PollEvent(&event) )
|
||||
{
|
||||
if ( event.type == SDL_KEYDOWN && event.key.keysym.sym == key )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#elif defined(MultiSpacc_Target_NES)
|
||||
return ( pad_poll(pad) & key );
|
||||
#endif
|
||||
}
|
56
LibMultiSpacc/LibMultiSpacc/Keys.h
Normal file
56
LibMultiSpacc/LibMultiSpacc/Keys.h
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef _MultiSpacc_Keys_h_
|
||||
#define _MultiSpacc_Keys_h_
|
||||
|
||||
#if defined(MultiSpacc_Target_NES)
|
||||
#define MultiSpacc_Key_Action1 PAD_A
|
||||
#endif
|
||||
|
||||
#if defined(MultiSpacc_Target_NES)
|
||||
#define MultiSpacc_Key_Action2 PAD_B
|
||||
#endif
|
||||
|
||||
#if defined(MultiSpacc_Target_NES)
|
||||
#define MultiSpacc_Key_Confirm PAD_A
|
||||
#endif
|
||||
|
||||
#if defined(MultiSpacc_Target_NES)
|
||||
#define MultiSpacc_Key_Cancel PAD_B
|
||||
#endif
|
||||
|
||||
#if defined(MultiSpacc_Target_NES)
|
||||
#define MultiSpacc_Key_Start PAD_START
|
||||
#endif
|
||||
|
||||
#if defined(MultiSpacc_Target_SDLCom)
|
||||
#define MultiSpacc_Key_Pause SDLK_ESCAPE
|
||||
#elif defined(MultiSpacc_Target_NES)
|
||||
#define MultiSpacc_Key_Pause PAD_START
|
||||
#endif
|
||||
|
||||
#if defined(MultiSpacc_Target_NES)
|
||||
#define MultiSpacc_Key_Select PAD_SELECT
|
||||
#endif
|
||||
|
||||
#if defined(MultiSpacc_Target_SDLCom)
|
||||
#define MultiSpacc_Key_Up SDLK_UP
|
||||
#define MultiSpacc_Key_Down SDLK_DOWN
|
||||
#define MultiSpacc_Key_Left SDLK_LEFT
|
||||
#define MultiSpacc_Key_Right SDLK_RIGHT
|
||||
#elif defined(MultiSpacc_Target_NES)
|
||||
#define MultiSpacc_Key_Up PAD_UP
|
||||
#define MultiSpacc_Key_Down PAD_DOWN
|
||||
#define MultiSpacc_Key_Left PAD_LEFT
|
||||
#define MultiSpacc_Key_Right PAD_RIGHT
|
||||
#endif
|
||||
|
||||
// #if defined(MultiSpacc_Target_SDLCom)
|
||||
// #define MultiSpacc_Key_Action1 SPACE
|
||||
// #define MultiSpacc_Key_Action2 SHIFT
|
||||
// #define MultiSpacc_Key_Confirm ENTER
|
||||
// #define MultiSpacc_Key_Cancel ESC
|
||||
// #define MultiSpacc_Key_Select TAB
|
||||
// #endif
|
||||
|
||||
bool MultiSpacc_CheckKey( char key, char pad );
|
||||
|
||||
#endif // _MultiSpacc_Keys_h_
|
@ -1,54 +1,28 @@
|
||||
#include "./MultiSpacc.h"
|
||||
|
||||
bool MultiSpacc_SetMainLoop( bool function( void *args ), void *args )
|
||||
MultiSpacc_Surface *MultiSpacc_LoadImage( char FilePath[], MultiSpacc_Surface *Screen, Uint32 *ColorKey )
|
||||
{
|
||||
#ifdef MultiSpacc_Target_Web
|
||||
emscripten_set_main_loop_arg( function, args, -1, true );
|
||||
#else
|
||||
while(true){
|
||||
if( !function(args) ){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MultiSpacc_UpdateDisplay( MultiSpacc_Window *window )
|
||||
{
|
||||
#if defined(MultiSpacc_Target_SDL12)
|
||||
return !SDL_Flip(window);
|
||||
#elif defined(MultiSpacc_Target_SDL20)
|
||||
return !SDL_UpdateWindowSurface(window);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MultiSpacc_WaitFrame( Uint32 *nextTick )
|
||||
{
|
||||
#if defined(MultiSpacc_Target_SDLStandard)
|
||||
// TODO: check if this actually works with any framerate or it caps the game speed
|
||||
Uint32 now;
|
||||
now = SDL_GetTicks();
|
||||
if ( *nextTick <= now ) {
|
||||
MultiSpacc_Sleep(0);
|
||||
#ifdef MultiSpacc_Target_SDLCom
|
||||
MultiSpacc_Surface *Final = NULL;
|
||||
MultiSpacc_Surface *Raw = IMG_Load( FilePath );
|
||||
if( Raw == NULL ) {
|
||||
MultiSpacc_PrintDebug("[E] Error Reading Image %s.\n", FilePath);
|
||||
} else {
|
||||
MultiSpacc_Sleep( *nextTick - now );
|
||||
}
|
||||
*nextTick += 1000/60; // TODO: specified framerate and variable framerate
|
||||
*nextTick = SDL_GetTicks() + 1000/60; // this last part should execute at the start of a loop maybe ???
|
||||
#elif defined(MultiSpacc_Target_NES)
|
||||
ppu_wait_frame();
|
||||
Final = SDL_ConvertSurface( Raw, Screen->format, 0 );
|
||||
SDL_FreeSurface( Raw );
|
||||
if( Final == NULL ) {
|
||||
MultiSpacc_PrintDebug("[E] Error Adapting Image %s.\n", FilePath);
|
||||
} else {
|
||||
Uint32 FinalColorKey = SDL_MapRGB( Final->format, 0xFF, 0x00, 0xFF ); // Magenta
|
||||
if( ColorKey != NULL )
|
||||
FinalColorKey = *ColorKey;
|
||||
MultiSpacc_SetColorKey( Final, true, FinalColorKey );
|
||||
};
|
||||
};
|
||||
return Final;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MultiSpacc_WaitUpdateDisplay( MultiSpacc_Window *window, Uint32 *nextTick )
|
||||
{
|
||||
if( !MultiSpacc_UpdateDisplay(window) || !MultiSpacc_WaitFrame(nextTick) ){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key )
|
||||
@ -77,6 +51,22 @@ int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key )
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef MultiSpacc_Target_SDLCom
|
||||
void MultiSpacc_Sleep( int milliseconds )
|
||||
{
|
||||
/* TODO: 50 or 60 FPS based on region for appropriate consoles */
|
||||
int frames = (60 * milliseconds / 1000);
|
||||
while( --frames )
|
||||
{
|
||||
#if defined(MultiSpacc_Target_NDS)
|
||||
swiWaitForVBlank();
|
||||
#elif defined(MultiSpacc_Target_NES)
|
||||
ppu_wait_frame();
|
||||
#endif
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MultiSpacc_Target_SDLCom
|
||||
int MultiSpacc_PollEvent( MultiSpacc_Event *Event )
|
||||
{
|
||||
@ -88,48 +78,6 @@ int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key )
|
||||
};
|
||||
return Result;
|
||||
}
|
||||
|
||||
MultiSpacc_Surface *MultiSpacc_LoadImage( char FilePath[], MultiSpacc_Surface *Screen, Uint32 *ColorKey )
|
||||
{
|
||||
MultiSpacc_Surface *Final = NULL;
|
||||
MultiSpacc_Surface *Raw = IMG_Load( FilePath );
|
||||
if( Raw == NULL ) {
|
||||
MultiSpacc_PrintDebug("[E] Error reading image %s.\n", FilePath);
|
||||
} else {
|
||||
Final = SDL_ConvertSurface( Raw, Screen->format, 0 );
|
||||
SDL_FreeSurface( Raw );
|
||||
if( Final == NULL ) {
|
||||
MultiSpacc_PrintDebug("[E] Error adapting image %s.\n", FilePath);
|
||||
} else {
|
||||
Uint32 FinalColorKey = SDL_MapRGB( Final->format, 0xFF, 0x00, 0xFF ); // Magenta
|
||||
if( ColorKey != NULL )
|
||||
FinalColorKey = *ColorKey;
|
||||
MultiSpacc_SetColorKey( Final, true, FinalColorKey );
|
||||
};
|
||||
};
|
||||
return Final;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MultiSpacc_Target_NDS
|
||||
int MultiSpacc_UpdateWindowSurface( MultiSpacc_Window *Window )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MultiSpacc_Sleep( int milliseconds )
|
||||
{
|
||||
int frames = (60 * milliseconds / 1000);
|
||||
for (int i=0; i<frames; i++)
|
||||
{
|
||||
swiWaitForVBlank();
|
||||
};
|
||||
}
|
||||
|
||||
MultiSpacc_Surface *MultiSpacc_LoadImage( char FilePath[], MultiSpacc_Surface *Screen, Uint32 *ColorKey )
|
||||
{
|
||||
return NULL;
|
||||
};
|
||||
#endif
|
||||
|
||||
void MultiSpacc_Sprite( int id, int x, int y, int sprite, MultiSpacc_Surface *Tiles, MultiSpacc_Surface *Surface )
|
||||
@ -144,23 +92,8 @@ void MultiSpacc_Sprite( int id, int x, int y, int sprite, MultiSpacc_Surface *Ti
|
||||
};
|
||||
SDL_BlitSurface( Tiles, &Clip, Surface, &Offset );
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MultiSpacc_Target_NES
|
||||
oam_spr(x, y, sprite, 0, id);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MultiSpacc_Target_NES
|
||||
int MultiSpacc_UpdateWindowSurface( MultiSpacc_Window *Window )
|
||||
{
|
||||
ppu_wait_frame();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MultiSpacc_Sleep( int milliseconds ){}
|
||||
|
||||
MultiSpacc_Surface *MultiSpacc_LoadImage( char FilePath[], MultiSpacc_Surface *Screen, Uint32 *ColorKey )
|
||||
{
|
||||
return NULL;
|
||||
};
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef _MultiSpacc_h_
|
||||
#define _MultiSpacc_h_
|
||||
#ifndef _MultiSpacc_MultiSpacc_h_
|
||||
#define _MultiSpacc_MultiSpacc_h_
|
||||
|
||||
#include <stdarg.h>
|
||||
#ifndef MultiSpacc_Target_NES
|
||||
@ -40,8 +40,6 @@
|
||||
#define MultiSpacc_Init SDL_Init
|
||||
#define MultiSpacc_Surface SDL_Surface
|
||||
#define MultiSpacc_GetTicks SDL_GetTicks
|
||||
#define MultiSpacc_Sleep SDL_Delay
|
||||
#define MultiSpacc_Rect SDL_Rect
|
||||
#endif
|
||||
|
||||
#ifdef MultiSpacc_Target_Web
|
||||
@ -56,21 +54,35 @@
|
||||
typedef struct MultiSpacc_Event {
|
||||
int Keys;
|
||||
} MultiSpacc_Event;
|
||||
int MultiSpacc_UpdateWindowSurface( MultiSpacc_Window *Window );
|
||||
void MultiSpacc_Sleep( int milliseconds );
|
||||
#endif
|
||||
|
||||
#ifdef MultiSpacc_Target_NES
|
||||
#include <nes.h>
|
||||
#include "neslib.h"
|
||||
#define Uint32 int
|
||||
#define MultiSpacc_Window int
|
||||
#define MultiSpacc_Surface int
|
||||
#define MultiSpacc_Event int
|
||||
int MultiSpacc_UpdateWindowSurface( MultiSpacc_Window *Window );
|
||||
#define MultiSpacc_Window char
|
||||
#define MultiSpacc_Surface char
|
||||
#define MultiSpacc_Event char
|
||||
#endif
|
||||
|
||||
#ifdef MultiSpacc_Target_SDLCom
|
||||
#define MultiSpacc_Sleep SDL_Delay
|
||||
#else
|
||||
void MultiSpacc_Sleep( int milliseconds );
|
||||
#endif
|
||||
|
||||
#ifdef MultiSpacc_Target_SDLCom
|
||||
#define MultiSpacc_Point SDL_Point
|
||||
#define MultiSpacc_Rect SDL_Rect
|
||||
#else
|
||||
typedef struct MultiSpacc_Point {
|
||||
int x, y;
|
||||
} MultiSpacc_Point;
|
||||
typedef struct MultiSpacc_Rect {
|
||||
int x, y, w, h;
|
||||
} MultiSpacc_Rect;
|
||||
#endif
|
||||
|
||||
typedef struct MultiSpacc_SurfaceConfig {
|
||||
int Width;
|
||||
int Height;
|
||||
@ -99,4 +111,6 @@ void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, MultiSpacc_
|
||||
|
||||
void MultiSpacc_Sprite( int id, int x, int y, int sprite, MultiSpacc_Surface *Tiles, MultiSpacc_Surface *Surface );
|
||||
|
||||
#endif // _MultiSpacc_h_
|
||||
#include "./Keys.h"
|
||||
|
||||
#endif // _MultiSpacc_MultiSpacc_h_
|
||||
|
@ -3,6 +3,7 @@
|
||||
void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, MultiSpacc_SurfaceConfig *WindowConfig, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ )
|
||||
{
|
||||
#ifdef MultiSpacc_Target_SDLCom
|
||||
/* TODO: not just 8x8 tiles */
|
||||
for( int i = 0; i < strlen(Text); i++ )
|
||||
{
|
||||
MultiSpacc_Rect Offset = {
|
||||
@ -20,7 +21,7 @@ void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, MultiSpacc_
|
||||
#endif
|
||||
|
||||
#ifdef MultiSpacc_Target_NDS
|
||||
iprintf("%s", Text);
|
||||
iprintf( "%s", Text );
|
||||
#endif
|
||||
|
||||
#ifdef MultiSpacc_Target_NES
|
||||
@ -35,8 +36,8 @@ void MultiSpacc_PrintDebug( const char *format, ... )
|
||||
{
|
||||
#ifdef MultiSpacc_Target_SDLCom
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
fprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
va_start( args, format );
|
||||
fprintf( stderr, format, args );
|
||||
va_end( args );
|
||||
#endif
|
||||
}
|
||||
|
@ -43,6 +43,20 @@ MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window )
|
||||
#endif
|
||||
}
|
||||
|
||||
bool MultiSpacc_SetMainLoop( bool function( void *args ), void *args )
|
||||
{
|
||||
#ifdef MultiSpacc_Target_Web
|
||||
emscripten_set_main_loop_arg( (em_arg_callback_func)function, args, -1, true );
|
||||
#else
|
||||
while(true){
|
||||
if( !function(args) ){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char *Title )
|
||||
{
|
||||
#ifdef MultiSpacc_Target_SDL12
|
||||
|
41
LibMultiSpacc/LibMultiSpacc/VideoCycle.c
Normal file
41
LibMultiSpacc/LibMultiSpacc/VideoCycle.c
Normal file
@ -0,0 +1,41 @@
|
||||
#include "./MultiSpacc.h"
|
||||
|
||||
bool MultiSpacc_UpdateDisplay( MultiSpacc_Window *window )
|
||||
{
|
||||
#if defined(MultiSpacc_Target_SDL12)
|
||||
return !SDL_Flip(window);
|
||||
#elif defined(MultiSpacc_Target_SDL20)
|
||||
return !SDL_UpdateWindowSurface(window);
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool MultiSpacc_WaitFrame( Uint32 *nextTick )
|
||||
{
|
||||
#if defined(MultiSpacc_Target_SDLStandard)
|
||||
// TODO: check if this actually works with any framerate or it caps the game speed
|
||||
Uint32 now;
|
||||
now = SDL_GetTicks();
|
||||
if ( *nextTick <= now ) {
|
||||
MultiSpacc_Sleep(0);
|
||||
} else {
|
||||
MultiSpacc_Sleep( *nextTick - now );
|
||||
}
|
||||
*nextTick += 1000/60; // TODO: framerate specified from app and variable framerate
|
||||
*nextTick = SDL_GetTicks() + 1000/60; // this last part should execute at the start of a loop maybe ???
|
||||
#elif defined(MultiSpacc_Target_NDS)
|
||||
swiWaitForVBlank();
|
||||
#elif defined(MultiSpacc_Target_NES)
|
||||
ppu_wait_frame();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MultiSpacc_WaitUpdateDisplay( MultiSpacc_Window *window, Uint32 *nextTick )
|
||||
{
|
||||
if( !MultiSpacc_UpdateDisplay(window) || !MultiSpacc_WaitFrame(nextTick) ){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
@ -36,10 +36,10 @@
|
||||
|
||||
|
||||
// define basic types for convenience
|
||||
typedef unsigned char byte; // 8-bit unsigned
|
||||
typedef signed char sbyte; // 8-bit signed
|
||||
typedef unsigned short word; // 16-bit signed
|
||||
typedef enum { false, true } bool; // boolean
|
||||
typedef unsigned char byte; // 8-bit unsigned
|
||||
typedef signed char sbyte; // 8-bit signed
|
||||
typedef unsigned short word; // 16-bit signed
|
||||
typedef enum { false, true } bool; // boolean
|
||||
|
||||
|
||||
// set bg and spr palettes, data is 32 bytes array
|
||||
@ -283,14 +283,14 @@ void __fastcall__ nmi_set_callback(void (*callback)(void));
|
||||
#define MAX(x1,x2) ((x1)<(x2)?(x2):(x1))
|
||||
#define MIN(x1,x2) ((x1)<(x2)?(x1):(x2))
|
||||
|
||||
#define MASK_SPR 0x10
|
||||
#define MASK_BG 0x08
|
||||
#define MASK_EDGE_SPR 0x04
|
||||
#define MASK_EDGE_BG 0x02
|
||||
#define MASK_TINT_RED 0x20
|
||||
#define MASK_TINT_BLUE 0x40
|
||||
#define MASK_TINT_GREEN 0x80
|
||||
#define MASK_MONO 0x01
|
||||
#define MASK_SPR 0x10
|
||||
#define MASK_BG 0x08
|
||||
#define MASK_EDGE_SPR 0x04
|
||||
#define MASK_EDGE_BG 0x02
|
||||
#define MASK_TINT_RED 0x20
|
||||
#define MASK_TINT_BLUE 0x40
|
||||
#define MASK_TINT_GREEN 0x80
|
||||
#define MASK_MONO 0x01
|
||||
|
||||
#define NAMETABLE_A 0x2000
|
||||
#define NAMETABLE_B 0x2400
|
||||
@ -326,10 +326,10 @@ void __fastcall__ nmi_set_callback(void (*callback)(void));
|
||||
// OAM buffer @ $200-$2FF
|
||||
|
||||
typedef struct OAMSprite {
|
||||
byte y; // Y coordinate
|
||||
byte name; // tile index in name table
|
||||
byte attr; // attribute flags
|
||||
byte x; // X coordinate
|
||||
byte y; // Y coordinate
|
||||
byte name; // tile index in name table
|
||||
byte attr; // attribute flags
|
||||
byte x; // X coordinate
|
||||
} OAMSprite;
|
||||
|
||||
#define OAMBUF ((OAMSprite*) 0x200)
|
||||
@ -340,4 +340,3 @@ extern byte oam_off;
|
||||
#pragma zpsym ("oam_off")
|
||||
|
||||
#endif /* neslib.h */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user