Skip to content

Commit b42bb0a

Browse files
committed
Add GP2X specific code (GP2X preprocessor definition) and fix timing
1 parent c7bee7e commit b42bb0a

File tree

10 files changed

+718
-28
lines changed

10 files changed

+718
-28
lines changed

Makefile-gp2x

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
HOST=generic
2+
#HOST=mingw
3+
#HOST=haiku
4+
5+
CC=arm-open2x-linux-g++
6+
RM=rm
7+
CFLAGS= -O3 -DGP2X -march=armv4t -mtune=arm920t -I`sdl-config --prefix`/include
8+
COPTS= $(CFLAGS) -funsigned-char -ffast-math
9+
LIBS= -L`sdl-config --prefix`/lib/mixer-ogg -lSDL_mixer `sdl-config --libs` -lvorbisidec -lvorbisfile -lpthread -lm -larmmem -static -s
10+
SRCS= alien.c asylum.c bullet.c file.c keyboard.c maze.c menus.c player.c projectile.c sound.c vdu.c
11+
12+
RESOURCES=data/Resources data/Ego data/Psyche data/Id data/Voices
13+
14+
INSTALLGROUP=games
15+
CHGRP=chgrp
16+
CHMOD=chmod
17+
18+
# For a non-root install, try something like this:
19+
#
20+
#INSTALLBIN=/home/blotwell/bin/asylum
21+
#INSTALLRESOURCEPATH=/home/blotwell/lib/asylum
22+
#INSTALLHISCORES=/home/blotwell/.asylum-hiscores
23+
#
24+
#INSTALLGROUP=foo
25+
#CHGRP=echo
26+
#CHMOD=echo
27+
ifeq ($(HOST),haiku)
28+
CC=i586-pc-haiku-gcc
29+
COPTS+=$(CPPFLAGS) -D_NO_SOUND
30+
INSTALLBIN=/boot/common/games/asylum/asylum
31+
INSTALLRESOURCEPATH=/boot/common/games/asylum/data
32+
INSTALLHISCORES=/boot/common/games/asylum/hiscores
33+
OS_SOURCE=asylum_haiku.c
34+
LIBS=-lSDL_mixer -lSDL -lbe -lroot -ldevice -lgame -lGL -ltextencoding -lmedia
35+
endif
36+
ifeq ($(HOST),mingw)
37+
INSTALLBIN="c:/program files/asylum/asylum.exe"
38+
INSTALLRESOURCEPATH="c:/program files/asylum/data"
39+
INSTALLHISCORES="c:/program files/asylum/hiscores"
40+
OS_SOURCE=asylum_win.c
41+
RM=del
42+
EXE=.exe
43+
LIBS=-lm -lmingw32 -lSDL_mixer -lSDLmain -lSDL -mwindows
44+
endif
45+
ifeq ($(HOST),generic)
46+
INSTALLBIN=/usr/games/asylum
47+
INSTALLRESOURCEPATH=/usr/share/games/asylum
48+
INSTALLHISCORES=/var/games/asylum
49+
endif
50+
51+
default: build
52+
53+
ifneq ($(HOST),mingw)
54+
$(INSTALLBIN): asylum$(EXE) Makefile
55+
cp asylum$(EXE) $(INSTALLBIN)
56+
$(CHGRP) $(INSTALLGROUP) $(INSTALLBIN)
57+
$(CHMOD) g+s $(INSTALLBIN)
58+
$(CHMOD) a+x $(INSTALLBIN)
59+
60+
install-resources: $(RESOURCES) Makefile
61+
mkdir -p $(INSTALLRESOURCEPATH)
62+
cp -r $(RESOURCES) $(INSTALLRESOURCEPATH)/
63+
$(CHGRP) -R $(INSTALLGROUP) $(INSTALLRESOURCEPATH)/
64+
$(CHMOD) -R a+rX $(INSTALLRESOURCEPATH)/
65+
66+
install-hiscores: Makefile
67+
mkdir -p $(INSTALLHISCORES)
68+
touch $(INSTALLHISCORES)/EgoHighScores
69+
touch $(INSTALLHISCORES)/PsycheHighScores
70+
touch $(INSTALLHISCORES)/IdHighScores
71+
touch $(INSTALLHISCORES)/ExtendedHighScores
72+
$(CHGRP) -R $(INSTALLGROUP) $(INSTALLHISCORES)/*
73+
$(CHMOD) -R 660 $(INSTALLHISCORES)/*
74+
75+
install-binary: $(INSTALLBIN)
76+
77+
install: install-resources install-hiscores install-binary
78+
79+
uninstall:
80+
rm -rf $(INSTALLBINARY) $(INSTALLRESOURCEPATH) $(INSTALLHISCORES)
81+
endif
82+
83+
oggs:
84+
bash -c 'pushd data; for i in */Music?; do pushd ..; ./asylum --dumpmusic $$i `if (echo \$$i|grep Resources.Music2>/dev/null); then echo -n --slower; fi`; \
85+
popd;\
86+
tail -c +33 $$i.au| \
87+
oggenc - --raw --raw-endianness=1 --raw-rate=22050 --artist="Andy Southgate" \
88+
--album="Background music for Asylum computer game" \
89+
>$$i.ogg;\
90+
rm $$i.au;\
91+
done; popd'
92+
93+
build: asylum$(EXE)
94+
95+
asylum$(EXE): $(SRCS) $(OS_SOURCE) asylum.h Makefile
96+
$(CC) $(COPTS) $(LDFLAGS) -o asylum$(EXE) $(SRCS) $(OS_SOURCE) $(LIBS)
97+
98+
clean:
99+
$(RM) asylum$(EXE)
100+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
SDL Asylum is a C port of the computer game Asylum, which was written by Andy Southgate in 1994 for the Acorn Archimedes and is now public domain. It should be possible to run it on any platform which support SDL and OpenGL graphics. It's developed primarily on Linux but has also been built successfully on Cygwin, FreeBSD, Windows and Haiku.
66

7-
This fork contains bug fixes and Pandora specific functionality.
7+
This fork contains bug fixes and Pandora/GP2X specific functionality.
88

99

1010
##Instructions

asylum.c

Lines changed: 123 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
#include <SDL/SDL_mixer.h>
2020
#if defined(PANDORA)
2121
#include <unistd.h>
22+
#elif defined(GP2X)
23+
#include <sys/ioctl.h>
24+
#include <unistd.h>
25+
#include <sys/soundcard.h>
26+
#include <fcntl.h>
2227
#endif
2328

2429
#include "asylum_os.h"
@@ -138,6 +143,7 @@ int game()
138143
frameinc = 1;
139144
rate50 = 1;
140145
swi_blitz_wait(1);
146+
uint32_t last_tick = SDL_GetTicks();
141147
while (!swi_readescapestate())
142148
{
143149
mainloop:
@@ -183,8 +189,31 @@ int game()
183189
if (cheatpermit == 1) cheatread();
184190
scorewipe();
185191
plotscore();
186-
frameinc = ((options.gearchange == 0) ? 2 : 1);
187-
swi_blitz_wait(frameinc);
192+
if (options.gearchange == 0)
193+
{
194+
frameinc = 2;
195+
swi_blitz_wait(frameinc);
196+
}
197+
else
198+
{
199+
frameinc = 1;
200+
201+
uint32_t diff = 20;
202+
uint32_t current_tick = SDL_GetTicks();
203+
if (current_tick - last_tick >= 2 * diff)
204+
{
205+
last_tick = current_tick - diff;
206+
}
207+
else
208+
{
209+
while (current_tick - last_tick < diff)
210+
{
211+
SDL_Delay(1);
212+
current_tick = SDL_GetTicks();
213+
}
214+
last_tick += diff;
215+
}
216+
}
188217
if ((rate50 != 1) && (frameinc < 2)) //rate 25 but one frame passed
189218
{
190219
swi_blitz_wait(1);
@@ -250,6 +279,8 @@ void bonus1()
250279
const int keydefs[] =
251280
#if defined(PANDORA)
252281
{ -SDLK_LEFT, -SDLK_RIGHT, -SDLK_UP, -SDLK_DOWN, -SDLK_HOME };
282+
#elif defined(GP2X)
283+
{ -SDLK_LEFT, -SDLK_RIGHT, -SDLK_UP, -SDLK_DOWN, -SDLK_a };
253284
#else
254285
{ -SDLK_z, -SDLK_x, -SDLK_SEMICOLON, -SDLK_PERIOD, -SDLK_RETURN };
255286
#endif
@@ -483,6 +514,83 @@ void c_array_initializers()
483514
init_keyboard();
484515
}
485516

517+
#if defined(GP2X)
518+
static int InitialVolume;
519+
520+
// Set new GP2X mixer level, 0-100
521+
static void Set_GP2X_Volume (int newvol)
522+
{
523+
int soundDev, vol;
524+
525+
if ((newvol >= 0) && (newvol <= 100))
526+
{
527+
soundDev = open("/dev/mixer", O_RDWR);
528+
if (soundDev != -1)
529+
{
530+
vol = ((newvol << 8) | newvol);
531+
ioctl(soundDev, SOUND_MIXER_WRITE_PCM, &vol);
532+
close(soundDev);
533+
}
534+
}
535+
}
536+
537+
// Returns 0-100, current mixer volume, -1 on error.
538+
static int Get_GP2X_Volume (void)
539+
{
540+
int soundDev, vol;
541+
542+
vol = -1;
543+
soundDev = open("/dev/mixer", O_RDONLY);
544+
if (soundDev != -1)
545+
{
546+
ioctl(soundDev, SOUND_MIXER_READ_PCM, &vol);
547+
close(soundDev);
548+
if (vol != -1)
549+
{
550+
//just return one channel , not both channels, they're hopefully the same anyways
551+
return (vol & 0xFF);
552+
}
553+
}
554+
555+
return vol;
556+
}
557+
558+
static void Set_Initial_GP2X_Volume (void)
559+
{
560+
Set_GP2X_Volume(InitialVolume);
561+
}
562+
563+
void Change_HW_Audio_Volume (int amount)
564+
{
565+
int current_volume;
566+
567+
current_volume = Get_GP2X_Volume();
568+
569+
if (current_volume == -1) current_volume = 68;
570+
571+
if ((amount > 1) && current_volume < 12)
572+
{
573+
amount = 1;
574+
}
575+
else if ((amount < -1) && current_volume <= 12)
576+
{
577+
amount = -1;
578+
}
579+
580+
current_volume += amount;
581+
582+
if (current_volume > 100)
583+
{
584+
current_volume = 100;
585+
}
586+
else if (current_volume < 0)
587+
{
588+
current_volume = 0;
589+
}
590+
Set_GP2X_Volume(current_volume);
591+
}
592+
#endif
593+
486594
int main(int argc, char** argv)
487595
{
488596
find_resources();
@@ -498,11 +606,19 @@ int main(int argc, char** argv)
498606
open_scores();
499607
dropprivs();
500608

609+
#if defined(GP2X)
610+
InitialVolume = Get_GP2X_Volume();
611+
atexit(Set_Initial_GP2X_Volume);
612+
#endif
613+
501614
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
502615
SDL_WM_SetCaption("Asylum", "Asylum");
503616
SDL_EnableUNICODE(1);
504617
#ifndef _NO_SOUND
505618
init_audio();
619+
#endif
620+
#if defined(GP2X)
621+
Set_Initial_GP2X_Volume();
506622
#endif
507623
c_array_initializers();
508624
swi_stasis_control(8, 8);
@@ -718,7 +834,7 @@ void loadconfig()
718834
case 4: options.firekey = -temp; break;
719835
case 5: options.soundtype = temp; break;
720836
//case 6: options.soundquality=temp; break;
721-
#if !defined(PANDORA)
837+
#if !(defined(GP2X) || defined(PANDORA))
722838
case 7: options.fullscreen = temp; break;
723839
#endif
724840
#ifndef DISABLE_OPENGL
@@ -754,7 +870,7 @@ void saveconfig()
754870
config_keywords[5], options.soundtype,
755871
//config_keywords[6], options.soundquality,
756872
config_keywords[7],
757-
#if defined(PANDORA)
873+
#if defined(GP2X) || defined(PANDORA)
758874
1,
759875
#else
760876
options.fullscreen,
@@ -785,7 +901,7 @@ void saveconfig()
785901
options.initials[2],
786902
((options.idpermit == 1) ? idpermitstring : ""));
787903
fclose(r0);
788-
#if defined(PANDORA)
904+
#if defined(GP2X) || defined(PANDORA)
789905
sync();
790906
#endif
791907
}
@@ -843,7 +959,7 @@ void savegame()
843959
fwrite(neuronadr->contents, neuronadr->width, neuronadr->height, r0);
844960
}
845961
fclose(r0);
846-
#if defined(PANDORA)
962+
#if defined(GP2X) || defined(PANDORA)
847963
sync();
848964
#endif
849965
}
@@ -857,7 +973,7 @@ void permitid()
857973
{
858974
fprintf(r0, "%s", idpermitstring);
859975
fclose(r0);
860-
#if defined(PANDORA)
976+
#if defined(GP2X) || defined(PANDORA)
861977
sync();
862978
#endif
863979
}

asylum.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ void screensave();
466466
void getvars();
467467
void init_palette();
468468
void vduread(asylum_options);
469+
#if defined(GP2X)
470+
void Change_HW_Audio_Volume (int amount);
471+
#endif
469472
int main(int argc, char** argv);
470473
void load_voices(int dumpmusic);
471474
void init_sounds();

file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ FILE* find_game(int op)
4646
{
4747
char fullname[240] = "";
4848

49-
#if defined(PANDORA)
49+
#if defined(GP2X) || defined(PANDORA)
5050
strcpy(fullname, "..");
5151
#else
5252
char* home = getenv("HOME");
@@ -69,7 +69,7 @@ FILE* find_config(int op)
6969
{
7070
char fullname[240] = "";
7171

72-
#if defined(PANDORA)
72+
#if defined(GP2X) || defined(PANDORA)
7373
strcpy(fullname, "..");
7474
#else
7575
char* home = getenv("HOME");
@@ -334,7 +334,7 @@ int swi_osfile(int op, const char* name, char* start, char* end)
334334
f = fopen(name, "wb");
335335
for (char* i = start; i < end; i++) fputc(*i, f);
336336
fclose(f);
337-
#if defined(PANDORA)
337+
#if defined(GP2X) || defined(PANDORA)
338338
sync();
339339
#endif
340340
return 0;

0 commit comments

Comments
 (0)