Skip to content

Commit 10795f3

Browse files
committed
Initial Sony Playstation 2 port.
TODO´S: Add SDL_GameController support from dsda-doom
1 parent 9695151 commit 10795f3

File tree

12 files changed

+409
-11
lines changed

12 files changed

+409
-11
lines changed

prboom2/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ set(CMAKE_REQUIRED_INCLUDES_PREV ${CMAKE_REQUIRED_INCLUDES})
181181
set(CMAKE_REQUIRED_LIBRARIES_PREV ${CMAKE_REQUIRED_LIBRARIES})
182182
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${SDL2_INCLUDE_DIRS})
183183
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${SDL2_LIBRARIES})
184-
check_symbol_exists(SDL_JoystickGetAxis "SDL.h" HAVE_SDL_JOYSTICKGETAXIS)
184+
if(PS2)
185+
# the check fails for our SDL.h for some reason
186+
set(HAVE_SDL_JOYSTICKGETAXIS TRUE)
187+
else()
188+
check_symbol_exists(SDL_JoystickGetAxis "SDL.h" HAVE_SDL_JOYSTICKGETAXIS)
189+
endif()
185190
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_PREV})
186191
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_PREV})
187192

@@ -212,9 +217,14 @@ else()
212217
-Wpointer-arith -Wno-unused -Wno-switch -Wno-sign-compare -Wno-pointer-sign \
213218
-ffast-math"
214219
)
220+
if (PS2)
221+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=r5900 -Wextra -Winline -O2 -fomit-frame-pointer -D_GNU_SOURCE=1")
222+
set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -g")
223+
endif()
215224
endif()
216225

217226
# Support cross compiling
227+
if(NOT PS2)
218228
option(FORCE_CROSSCOMPILE "Enable cross-compilation" OFF)
219229
if(FORCE_CROSSCOMPILE)
220230
set(CMAKE_CROSSCOMPILING ON)
@@ -228,14 +238,17 @@ else()
228238
set(CROSS_EXPORTS "")
229239
endif()
230240
endif()
241+
endif()
231242

232243
set(PRBOOM_OUTPUT_PATH ${CMAKE_BINARY_DIR})
233244

234245
set(WAD_DATA prboom-plus.wad)
235246
set(WAD_DATA_PATH "${PRBOOM_OUTPUT_PATH}/${WAD_DATA}")
236247

248+
if(NOT PS2)
237249
add_subdirectory(data)
238250
add_subdirectory(doc)
251+
endif()
239252
add_subdirectory(src)
240253

241254
if(NOT CMAKE_CROSSCOMPILING)

prboom2/src/CMakeLists.txt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,27 @@ function(AddGameExecutable TARGET SOURCES)
374374
target_include_directories(${TARGET} PRIVATE ${ALSA_INCLUDE_DIR})
375375
target_link_libraries(${TARGET} PRIVATE ${ASOUND_LIBRARY})
376376
endif()
377+
if(PS2)
378+
target_link_libraries(${TARGET} PRIVATE
379+
atomic
380+
ogg
381+
vorbis
382+
modplug
383+
mikmod
384+
stdc++
385+
m
386+
debug
387+
c
388+
gskit
389+
dmakit
390+
dma
391+
ps2_drivers
392+
patches
393+
config
394+
draw)
395+
else()
377396
add_dependencies(${TARGET} prboomwad)
397+
endif()
378398

379399
if(MSVC)
380400
set_target_properties(${TARGET} PROPERTIES
@@ -404,10 +424,15 @@ function(AddGameExecutable TARGET SOURCES)
404424
endif()
405425
endfunction()
406426

427+
if(PS2)
428+
AddGameExecutable(prboom-plus.elf "${PRBOOM_PLUS_SOURCES}")
429+
else()
407430
AddGameExecutable(prboom-plus "${PRBOOM_PLUS_SOURCES}")
408-
409-
431+
endif()
410432
# PrBoom-Plus server executable
433+
if(NOT PS2)
434+
set(BUILD_SERVER OFF)
435+
endif()
411436

412437
option(BUILD_SERVER "Build PrBoom-Plus server executable" ON)
413438

prboom2/src/MUSIC/opl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ static void FillBuffer(int16_t *buffer, unsigned int nsamples)
251251

252252
// FIXME???
253253
//assert(nsamples < opl_sample_rate);
254-
254+
#ifdef __PS2__
255+
Chip__GenerateBlock2(&opl_chip, nsamples, (Bit32s*)mix_buffer);
256+
#else
255257
Chip__GenerateBlock2(&opl_chip, nsamples, mix_buffer);
256-
258+
#endif
257259
// Mix into the destination buffer, doubling up into stereo.
258260

259261
for (i=0; i<nsamples; ++i)

prboom2/src/SDL/i_joy.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,68 @@ void I_PollJoystick(void)
6767
{
6868
#ifdef HAVE_SDL_JOYSTICKGETAXIS
6969
event_t ev;
70+
#ifdef _EE
71+
Sint16 xaxisl, yaxisl, xaxisr;
72+
Uint8 hat;
73+
#else
7074
Sint16 axis_value;
75+
#endif
76+
#ifdef _EE
77+
ev.data1 = 0;
78+
// rm -- treat buttons like key inputs (easier than recoding main)
79+
//ev.data1 =
80+
// (SDL_JoystickGetButton(joystick, 0)<<0) |
81+
// (SDL_JoystickGetButton(joystick, 1)<<1) |
82+
// (SDL_JoystickGetButton(joystick, 2)<<2) |
83+
// (SDL_JoystickGetButton(joystick, 3)<<3);
84+
85+
hat = SDL_JoystickGetHat(joystick, 0);
86+
87+
if(hat == SDL_HAT_CENTERED)
88+
{
89+
xaxisl = SDL_JoystickGetAxis(joystick, 0) / 3000;
90+
91+
if(abs(xaxisl) < 3)
92+
ev.data1 = 0;
93+
else if(xaxisl > 0)
94+
ev.data1 = 1;
95+
else
96+
ev.data1 = -1;
97+
98+
yaxisl = SDL_JoystickGetAxis(joystick, 1) / 3000;
99+
100+
if(abs(yaxisl) < 2)
101+
ev.data3 = 0;
102+
else if(yaxisl > 0)
103+
ev.data3 = 1;
104+
else
105+
ev.data3 = -1;
106+
107+
xaxisr = SDL_JoystickGetAxis(joystick, 2) / 3000;
108+
109+
if(abs(xaxisr) < 2)
110+
ev.data2 = 0;
111+
else if(xaxisr > 0)
112+
ev.data2 = 1;
113+
else
114+
ev.data2 = -1;
115+
}
116+
else
117+
{
118+
if(hat & SDL_HAT_UP)
119+
ev.data3 = -1;
120+
121+
if(hat & SDL_HAT_RIGHT)
122+
ev.data2 = 1;
71123

124+
if(hat & SDL_HAT_DOWN)
125+
ev.data3 = 1;
126+
127+
if(hat & SDL_HAT_LEFT)
128+
ev.data2 = -1;
129+
130+
}
131+
#else
72132
if (!usejoystick || (!joystick)) return;
73133
ev.type = ev_joystick;
74134
ev.data1 =
@@ -86,7 +146,7 @@ void I_PollJoystick(void)
86146
axis_value = SDL_JoystickGetAxis(joystick, 1) / 3000;
87147
if (abs(axis_value)<7) axis_value=0;
88148
ev.data3 = axis_value;
89-
149+
#endif
90150
D_PostEvent(&ev);
91151
#endif
92152
}
@@ -113,10 +173,12 @@ void I_InitJoystick(void)
113173
else {
114174
I_AtExit(I_EndJoystick, true);
115175
lprintf(LO_INFO, "%sopened %s\n", fname, SDL_JoystickName(joystick));
176+
#ifndef _EE
116177
joyup = 32767;
117178
joydown = -32768;
118179
joyright = 32767;
119180
joyleft = -32768;
181+
#endif
120182
}
121183
#endif
122184
}

prboom2/src/SDL/i_main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ int main(int argc, char **argv)
598598
else
599599
fprintf(stderr, "Revoked uid %d\n",stored_euid);
600600
#endif
601-
602601
myargc = argc;
603602
myargv = (char**)malloc(sizeof(myargv[0]) * myargc);
604603
memcpy(myargv, argv, sizeof(myargv[0]) * myargc);

prboom2/src/SDL/i_system.c

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ const char *I_DoomExeDir(void)
351351

352352
if (!base) // cache multiple requests
353353
{
354+
#ifdef __PS2__
355+
base = malloc(strlen(prboom_dir) + 1);
356+
strcpy(base, prboom_dir);
357+
#else
354358
char *home = M_getenv("HOME");
355359
char *p_home = strdup(home);
356360
size_t len = strlen(home);
@@ -362,7 +366,7 @@ const char *I_DoomExeDir(void)
362366
base = malloc(p_len);
363367
snprintf(base, p_len, "%s/.%s", p_home, prboom_dir);
364368
free(p_home);
365-
369+
#endif
366370
// if ~/.$prboom_dir doesn't exist,
367371
// create and use directory in XDG_DATA_HOME
368372
if (M_stat(base, &data_dir) || !S_ISDIR(data_dir.st_mode))
@@ -552,6 +556,82 @@ const char* I_FindFile2(const char* wfname, const char* ext)
552556
return (const char*) I_FindFileInternal(wfname, ext, true);
553557
}
554558

559+
#elif defined(_EE)
560+
char* I_FindFileInternal(const char* wfname, const char* ext, dboolean isStatic)
561+
{
562+
(void) isStatic;
563+
int i;
564+
/* Precalculate a length we will need in the loop */
565+
size_t pl = strlen(wfname) + strlen(ext) + 4;
566+
567+
for(i = 0; i < 5; i++)
568+
{
569+
char * p;
570+
const char * d = NULL;
571+
const char * s = NULL;
572+
573+
/* Each entry in the switch sets d to directory to look in
574+
* and optionally s to a subdirectory of d*/
575+
switch(i)
576+
{
577+
case 0:
578+
d = "";
579+
break;
580+
581+
case 1:
582+
d = "host:"
583+
break;
584+
585+
case 2:
586+
d = "hdd0:/+DOOM/"
587+
break;
588+
589+
case 3:
590+
d = "mass:/"
591+
break;
592+
593+
case 4:
594+
d = "cdrom:\\";
595+
break;
596+
597+
case 5:
598+
d = I_DoomExeDir();
599+
break;
600+
601+
}
602+
603+
p = malloc((d ? strlen(d) : 0) + ( s ? strlen(s) : 0 + pl);
604+
sprintf(p, "%s%s%s%s%s", d ? d : "", (d && !HasTrailingSlash(d)) ? "/" : ""),
605+
s ? s : "", (s && !HasTrailingSlash(s)) ? "/" : "",
606+
wfname);
607+
608+
if(access(p, F_OK))
609+
strcat(p, ext);
610+
611+
if (!access(p, F_OK))
612+
{
613+
lprintf(LO_INFO, " found %s\n", p);
614+
return p;
615+
}
616+
617+
free(p);
618+
619+
}
620+
621+
return NULL;
622+
}
623+
624+
char* I_FindFile(const char* wfname, const char* ext)
625+
{
626+
return I_FindFileInternal(wfname, ext, false);
627+
}
628+
629+
const char* I_FindFile2(const char* wfname, const char* ext)
630+
{
631+
return (const char*) I_FindFileInternal(wfname, ext, true);
632+
}
633+
634+
555635
#endif
556636

557637
#endif // PRBOOM_SERVER

prboom2/src/SDL/i_video.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,27 @@ static int I_TranslateKey(SDL_Keysym* key)
269269

270270
}
271271

272+
#ifdef _EE
273+
// Map buttons to keys
274+
//
275+
static int I_TranslateButton(Uint8 button)
276+
{
277+
int rc = 0;
278+
279+
switch(button)
280+
{
281+
case PS2_START:
282+
rc = KEYD_ESCAPE;
283+
break;
284+
285+
default:
286+
rc = button;
287+
break;
288+
}
289+
return rc;
290+
}
291+
#endif
292+
272293
/////////////////////////////////////////////////////////////////////////////////
273294
// Main input code
274295

@@ -300,6 +321,19 @@ static void I_GetEvent(void)
300321
while (SDL_PollEvent(Event))
301322
{
302323
switch (Event->type) {
324+
#ifdef _EE
325+
case SDL_JOYBUTTONDOWN:
326+
event.type = ev_keydown;
327+
event.data1 = I_TranslateButton(Event->jbutton.button);
328+
D_PostEvent(&event);
329+
break;
330+
331+
case SDL_JOYBUTTONUP:
332+
event.type = ev_keyup;
333+
event.data1 = I_TranslateButton(Event->jbutton.button);
334+
D_PostEvent(&event);
335+
break;
336+
#endif
303337
case SDL_KEYDOWN:
304338
#ifdef MACOSX
305339
if (Event->key.keysym.mod & KMOD_META)
@@ -1322,10 +1356,12 @@ void I_UpdateVideoMode(void)
13221356
else
13231357
{
13241358
int flags = SDL_RENDERER_TARGETTEXTURE;
1325-
1359+
#ifdef __PS2__ /* PS2 Currently supports software only */
1360+
flags |= SDL_RENDERER_SOFTWARE | SDL_RENDERER_PRESENTVSYNC;
1361+
#else
13261362
if (render_vsync && !novsync)
13271363
flags |= SDL_RENDERER_PRESENTVSYNC;
1328-
1364+
#endif
13291365
sdl_window = SDL_CreateWindow(
13301366
PACKAGE_NAME " " PACKAGE_VERSION,
13311367
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,

prboom2/src/doomdef.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,21 @@ typedef enum {
314314
#define KEYD_MWHEELUP (0x80 + 0x6b)
315315
#define KEYD_MWHEELDOWN (0x80 + 0x6c)
316316

317+
#ifdef __PS2__
318+
#define PS2_SQUARE 0
319+
#define PS2_CROSS 1
320+
#define PS2_CIRCLE 2
321+
#define PS2_TRIANGLE 3
322+
#define PS2_SELECT 4
323+
#define PS2_START 5
324+
#define PS2_L1 6
325+
#define PS2_R1 7
326+
#define PS2_L2 8
327+
#define PS2_R2 9
328+
#define PS2_L3 10
329+
#define PS2_R3 11
330+
#endif
331+
317332
// phares 4/19/98:
318333
// Defines Setup Screen groups that config variables appear in.
319334
// Used when resetting the defaults for every item in a Setup group.

0 commit comments

Comments
 (0)