Skip to content

Commit 2a2c187

Browse files
committedNov 7, 2023
Add SF2000 platform
1 parent f24a282 commit 2a2c187

File tree

6 files changed

+158
-11
lines changed

6 files changed

+158
-11
lines changed
 

‎Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,18 @@ else ifeq ($(platform), gcw0)
322322
DISABLE_ERROR_LOGGING := 1
323323
CFLAGS += -march=mips32 -mtune=mips32r2 -mhard-float
324324

325+
# SF2000
326+
else ifeq ($(platform), sf2000)
327+
TARGET := $(TARGET_NAME)_libretro_$(platform).a
328+
MIPS:=/opt/mips32-mti-elf/2019.09-03-2/bin/mips-mti-elf-
329+
CC = $(MIPS)gcc
330+
AR = $(MIPS)ar
331+
CFLAGS = -EL -march=mips32 -mtune=mips32 -msoft-float -ffast-math -fomit-frame-pointer
332+
CFLAGS += -G0 -mno-abicalls -fno-pic
333+
CFLAGS += -ffunction-sections -fdata-sections
334+
CFLAGS += -DSF2000 -DDISABLE_ERROR_LOGGING
335+
STATIC_LINKING = 1
336+
325337
# MIYOO
326338
else ifeq ($(platform), miyoo)
327339
TARGET := $(TARGET_NAME)_libretro.so

‎Makefile.common

+6-4
Original file line numberDiff line numberDiff line change
@@ -1811,13 +1811,15 @@ SOURCES_C += $(CORE_DIR)/src/libretro/libretro.c \
18111811
$(CORE_DIR)/src/libretro/shared.c
18121812

18131813
ifeq ($(WANT_LIBCO), 1)
1814-
DEFS += -DWANT_LIBCO -I$(LIBRETRO_COMM_DIR)/include
1815-
SOURCES_C += $(LIBRETRO_COMM_DIR)/libco/libco.c
1816-
else
1817-
SOURCES_C += $(LIBRETRO_COMM_DIR)/rthreads/rthreads.c
1814+
DEFS += -DWANT_LIBCO
18181815
endif
18191816

18201817
ifneq ($(STATIC_LINKING), 1)
1818+
ifeq ($(WANT_LIBCO), 1)
1819+
SOURCES_C += $(LIBRETRO_COMM_DIR)/libco/libco.c
1820+
else
1821+
SOURCES_C += $(LIBRETRO_COMM_DIR)/rthreads/rthreads.c
1822+
endif
18211823
SOURCES_C += $(LIBRETRO_COMM_DIR)/compat/compat_strl.c \
18221824
$(LIBRETRO_COMM_DIR)/compat/compat_strcasestr.c \
18231825
$(LIBRETRO_COMM_DIR)/file/file_path.c

‎src/libretro/fileio.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,9 @@ int osd_display_loading_rom_message (const char *name, int current, int total)
14481448
printf ("loading %-12s\n", name);
14491449
else
14501450
printf (" \n");
1451+
#if !defined(SF2000)
14511452
fflush (stdout);
1452-
1453+
#endif
14531454
if( keyboard_pressed (KEYCODE_LCONTROL) && keyboard_pressed (KEYCODE_C) )
14541455
return 1;
14551456

‎src/libretro/libretro.c

+92-6
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ void decompose_rom_sample_path(char *rompath, char *samplepath);
8989
void init_joy_list(void);
9090

9191
extern UINT32 create_path_recursive(char *path);
92-
92+
93+
#if defined(SF2000)
94+
static retro_log_printf_t log_cb;
95+
#endif
96+
9397
#if defined(_3DS)
9498
void* linearMemAlign(size_t size, size_t alignment);
9599
void linearFree(void* mem);
@@ -98,11 +102,15 @@ void linearFree(void* mem);
98102
void CLIB_DECL logerror(const char *text,...)
99103
{
100104
#ifdef DISABLE_ERROR_LOGGING
105+
#if defined(SF2000)
106+
//log_cb(RETRO_LOG_DEBUG, text);
107+
#else
101108
va_list arg;
102109
va_start(arg,text);
103110
vprintf(text,arg);
104111
va_end(arg);
105112
#endif
113+
#endif
106114
}
107115

108116
int global_showinfo = 1;
@@ -119,11 +127,22 @@ int attenuation = 0;
119127

120128
void gp2x_printf(char* fmt, ...)
121129
{
122-
va_list marker;
123-
124-
va_start(marker, fmt);
125-
vprintf(fmt, marker);
126-
va_end(marker);
130+
#if defined(SF2000)
131+
char buffer[500];
132+
133+
va_list args;
134+
va_start(args, fmt);
135+
vsnprintf(buffer, sizeof(buffer), fmt, args);
136+
va_end(args);
137+
138+
if (log_cb)
139+
log_cb(RETRO_LOG_INFO, buffer);
140+
#else
141+
va_list marker;
142+
va_start(marker, fmt);
143+
vprintf(fmt, marker);
144+
va_end(marker);
145+
#endif
127146
}
128147

129148
void gp2x_set_video_mode(int bpp,int width,int height)
@@ -140,6 +159,9 @@ void gp2x_video_setpalette(void)
140159
unsigned long gp2x_joystick_read(int n)
141160
{
142161
(void)n;
162+
#if defined(SF2000)
163+
return 0;
164+
#endif
143165
}
144166

145167
int osd_init(void)
@@ -316,6 +338,14 @@ void retro_set_environment(retro_environment_t cb)
316338
environ_cb = cb;
317339

318340
cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
341+
342+
#if defined(SF2000)
343+
struct retro_log_callback log;
344+
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
345+
log_cb = log.log;
346+
else
347+
log_cb = NULL;
348+
#endif
319349
}
320350

321351
void retro_set_audio_sample(retro_audio_sample_t cb)
@@ -350,8 +380,13 @@ void retro_reset(void)
350380

351381
static void update_input(void)
352382
{
383+
#if !defined(SF2000)
353384
#define RK(port,key) input_state_cb(port, RETRO_DEVICE_KEYBOARD, 0,RETROK_##key)
354385
#define JS(port, button) joypad_bits & (1 << RETRO_DEVICE_ID_JOYPAD_##button)
386+
#else
387+
#define RK(port,key) (input_state_cb(port, RETRO_DEVICE_KEYBOARD, 0,RETROK_##key))
388+
#define JS(port, button) (joypad_bits & (1 << RETRO_DEVICE_ID_JOYPAD_##button))
389+
#endif
355390
int i, j, c = 0;
356391
input_poll_cb();
357392

@@ -388,7 +423,11 @@ static void update_input(void)
388423
joy_pressed[c++] = JS(i, L);
389424
joy_pressed[c++] = JS(i, R);
390425

426+
#if defined(SF2000)
427+
key[KEY_TAB] |= (JS(i, L) > 0) && (JS(i, START) > 0);
428+
#else
391429
key[KEY_TAB] |= JS(i, R2);
430+
#endif
392431
}
393432

394433
key[KEY_A] =RK(0, a);
@@ -515,8 +554,14 @@ void hook_video_done(void)
515554
void run_thread_proc(void)
516555
{
517556
run_game(game_index);
557+
#if !defined(SF2000)
518558
hook_audio_done();
519559
hook_video_done();
560+
#else
561+
// never exit a co-thread
562+
while (true)
563+
co_switch(main_thread);
564+
#endif
520565
}
521566
#else
522567
static void hook_check(void)
@@ -548,6 +593,7 @@ void hook_video_done(void)
548593
slock_unlock(libretro_mutex);
549594
}
550595

596+
#if !defined(SF2000)
551597
#ifdef WANT_LIBCO
552598
void *run_thread_proc(void *v)
553599
{
@@ -569,6 +615,15 @@ void run_thread_proc(void *v)
569615
hook_video_done();
570616
}
571617
#endif
618+
#else
619+
void run_thread_proc(void *v)
620+
{
621+
run_game(game_index);
622+
thread_done = 1;
623+
hook_audio_done();
624+
hook_video_done();
625+
}
626+
#endif
572627

573628
static void lock_mame(void)
574629
{
@@ -716,6 +771,7 @@ void retro_run(void)
716771
}
717772
}
718773

774+
#ifndef WANT_LIBCO
719775
audio_done = 0;
720776
video_done = 0;
721777

@@ -804,7 +860,11 @@ bool retro_load_game(const struct retro_game_info *info)
804860
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
805861
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
806862
{
863+
#if !defined(SF2000)
807864
fprintf(stderr, "[libretro]: RGB565 is not supported.\n");
865+
#else
866+
logerror("[libretro]: RGB565 is not supported.\n");
867+
#endif
808868
return false;
809869
}
810870

@@ -834,8 +894,14 @@ bool retro_load_game(const struct retro_game_info *info)
834894
}
835895
printf("SAVE_DIRECTORY: %s\n", retro_save_directory);
836896

897+
#if !defined(SF2000)
837898
sprintf(core_sys_directory,"%s%cmame2000\0",retro_system_directory,slash);
838899
sprintf(core_save_directory,"%s%cmame2000\0",retro_save_directory,slash);
900+
#else
901+
sprintf(core_sys_directory,"%s%cmame2000",retro_system_directory,slash);
902+
sprintf(core_save_directory,"%s%cmame2000",retro_save_directory,slash);
903+
#endif
904+
839905
printf("MAME2000_SYS_DIRECTORY: %s\n", core_sys_directory);
840906
printf("MAME2000_SAVE_DIRECTORY: %s\n", core_save_directory);
841907

@@ -857,6 +923,9 @@ bool retro_load_game(const struct retro_game_info *info)
857923
strcat(IMAMESAMPLEPATH, "/samples");
858924

859925
/* do we have a driver for this? */
926+
#if defined(SF2000)
927+
game_index = -1;
928+
#endif
860929
for (i = 0; drivers[i] && (game_index == -1); i++)
861930
{
862931
if (strcasecmp(baseName,drivers[i]->name) == 0)
@@ -871,6 +940,9 @@ bool retro_load_game(const struct retro_game_info *info)
871940
printf("Game \"%s\" not supported\n", baseName);
872941
return false;
873942
}
943+
#if defined(SF2000)
944+
printf("game_index=%d driver_name=%s\n", game_index, drivers[game_index]->name);
945+
#endif
874946

875947
/* parse generic (os-independent) options */
876948
//parse_cmdline (argc, argv, game_index);
@@ -912,6 +984,10 @@ bool retro_load_game(const struct retro_game_info *info)
912984
options.samplerate = sample_rate;
913985
usestereo = stereo_enabled;
914986

987+
#if defined(SF2000)
988+
printf("sample_rate=%d\n", sample_rate);
989+
#endif
990+
915991
/* This is needed so emulated YM3526/YM3812 chips are used instead on physical ones. */
916992
options.use_emulated_ym3812 = 1;
917993

@@ -1037,13 +1113,23 @@ bool retro_load_game(const struct retro_game_info *info)
10371113

10381114
decompose_rom_sample_path(IMAMEBASEPATH, IMAMESAMPLEPATH);
10391115

1116+
#if !defined(SF2000)
10401117
mame_sleep = 1;
1118+
#endif
10411119

10421120
#ifdef WANT_LIBCO
10431121
main_thread = co_active();
10441122
core_thread = co_create(0x10000, run_thread_proc);
10451123
co_switch(core_thread);
1124+
#if defined(SF2000)
1125+
extern int bailing;
1126+
if (bailing)
1127+
return false;
1128+
#endif
10461129
#else
1130+
#if defined(SF2000)
1131+
mame_sleep = 1;
1132+
#endif
10471133
run_thread = sthread_create(run_thread_proc, NULL);
10481134
#endif
10491135

‎src/tilemap.c

+13
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ struct tilemap *tilemap_create(
474474
first_tilemap = tilemap;
475475
return tilemap;
476476
}
477+
#if defined(SF2000)
478+
else
479+
printf("error creating tilemap\n");
480+
481+
#endif
477482
tilemap_dispose( tilemap );
478483
}
479484
return 0;
@@ -484,9 +489,17 @@ void tilemap_dispose( struct tilemap *tilemap ){
484489
first_tilemap = tilemap->next;
485490
}
486491
else {
492+
#if !defined(SF2000)
487493
struct tilemap *prev = first_tilemap;
488494
while( prev->next != tilemap ) prev = prev->next;
489495
prev->next =tilemap->next;
496+
#else
497+
if (first_tilemap) {
498+
struct tilemap *prev = first_tilemap;
499+
while( prev->next != tilemap ) prev = prev->next;
500+
prev->next =tilemap->next;
501+
}
502+
#endif
490503
}
491504

492505
free( tilemap->cached_tile_info );

‎src/vidhrdw/sf1.c

+33
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ int sf1_active = 0;
77

88
static struct tilemap *bgb_tilemap, *bgm_tilemap, *char_tilemap;
99

10+
#if defined(SF2000)
11+
static data16_t bgscroll, fgscroll;
12+
static int bgprev = 0, fgprev = 0;
13+
#endif
1014

1115
/***************************************************************************
1216
@@ -16,7 +20,11 @@ static struct tilemap *bgb_tilemap, *bgm_tilemap, *char_tilemap;
1620

1721
static void get_bgb_tile_info(int tile_index)
1822
{
23+
#if !defined(SF2000)
1924
unsigned char *base = memory_region(REGION_GFX5) + 2*tile_index;
25+
#else
26+
unsigned char *base = memory_region(REGION_GFX5) + ((bgscroll >> 4) << 5) + 2*tile_index;
27+
#endif
2028
int attr = base[0x10000];
2129
int color = base[0];
2230
int code = (base[0x10000+1]<<8) | base[1];
@@ -26,7 +34,11 @@ static void get_bgb_tile_info(int tile_index)
2634

2735
static void get_bgm_tile_info(int tile_index)
2836
{
37+
#if !defined(SF2000)
2938
unsigned char *base = memory_region(REGION_GFX5) + 0x20000 + 2*tile_index;
39+
#else
40+
unsigned char *base = memory_region(REGION_GFX5) + ((fgscroll >> 4) << 5) + 0x20000 + 2*tile_index;
41+
#endif
3042
int attr = base[0x10000];
3143
int color = base[0];
3244
int code = (base[0x10000+1]<<8) | base[1];
@@ -53,8 +65,13 @@ int sf1_vh_start(void)
5365
{
5466
int i;
5567

68+
#if !defined(SF2000)
5669
bgb_tilemap = tilemap_create(get_bgb_tile_info, tilemap_scan_cols,TILEMAP_OPAQUE, 16,16,2048,16);
5770
bgm_tilemap = tilemap_create(get_bgm_tile_info, tilemap_scan_cols,TILEMAP_TRANSPARENT,16,16,2048,16);
71+
#else
72+
bgb_tilemap = tilemap_create(get_bgb_tile_info, tilemap_scan_cols,TILEMAP_OPAQUE, 16,16,(512/16)+1,16);
73+
bgm_tilemap = tilemap_create(get_bgm_tile_info, tilemap_scan_cols,TILEMAP_TRANSPARENT,16,16,(512/16)+1,16);
74+
#endif
5875
char_tilemap = tilemap_create(get_char_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8, 64,32);
5976

6077
if (!bgb_tilemap || !bgm_tilemap || !char_tilemap)
@@ -90,12 +107,28 @@ WRITE_HANDLER( sf1_videoram_w )
90107

91108
WRITE_HANDLER( sf1_deltaxb_w )
92109
{
110+
#if !defined(SF2000)
93111
tilemap_set_scrollx(bgb_tilemap, 0, data);
112+
#else
113+
bgscroll = COMBINE_WORD(bgscroll, data);
114+
tilemap_set_scrollx(bgb_tilemap,0,bgscroll & 0x0f);
115+
116+
if ((bgscroll >> 4) != bgprev) tilemap_mark_all_tiles_dirty( bgb_tilemap );
117+
bgprev = bgscroll >> 4;
118+
#endif
94119
}
95120

96121
WRITE_HANDLER( sf1_deltaxm_w )
97122
{
123+
#if !defined(SF2000)
98124
tilemap_set_scrollx(bgm_tilemap, 0, data);
125+
#else
126+
fgscroll = COMBINE_WORD(fgscroll, data);
127+
tilemap_set_scrollx(bgm_tilemap,0,fgscroll & 0x0f);
128+
129+
if ((fgscroll >> 4) != fgprev) tilemap_mark_all_tiles_dirty( bgm_tilemap );
130+
fgprev = fgscroll >> 4;
131+
#endif
99132
}
100133

101134
void sf1_active_w(int data)

0 commit comments

Comments
 (0)
Please sign in to comment.