diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-03-02 23:49:38 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-03-02 23:49:38 +0000 |
commit | 384de102469fee4e0792df8fe38586d3206774ed (patch) | |
tree | ee5342103e17738acfb8421328ea7c57433f55e6 /apps/plugins/rockboy/rockboy.c | |
parent | 48dad47df98bdec632e8930b6a97359dc2c428f5 (diff) | |
download | rockbox-384de102469fee4e0792df8fe38586d3206774ed.tar.gz rockbox-384de102469fee4e0792df8fe38586d3206774ed.zip |
Rockboy - gameboy emulation for rockbox, based on gnuboy. Still a bit early, but already playable on iRiver H1xx and the simulators. The archos recorder version is currently rather slow...
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6104 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/rockboy/rockboy.c')
-rw-r--r-- | apps/plugins/rockboy/rockboy.c | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c new file mode 100644 index 0000000000..c9788e2438 --- /dev/null +++ b/apps/plugins/rockboy/rockboy.c | |||
@@ -0,0 +1,137 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Gameboy emulator based on gnuboy | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "plugin.h" | ||
20 | #include "loader.h" | ||
21 | #include "rockmacros.h" | ||
22 | |||
23 | #if MEM <= 8 && !defined(SIMULATOR) | ||
24 | /* On archos this is loaded as an overlay */ | ||
25 | |||
26 | /* These are defined in the linker script */ | ||
27 | extern unsigned char ovl_start_addr[]; | ||
28 | extern unsigned char ovl_end_addr[]; | ||
29 | |||
30 | const struct { | ||
31 | unsigned long magic; | ||
32 | unsigned char *start_addr; | ||
33 | unsigned char *end_addr; | ||
34 | enum plugin_status (*entry_point)(struct plugin_api*, void*); | ||
35 | } header __attribute__ ((section (".header"))) = { | ||
36 | 0x524f564c, /* ROVL */ | ||
37 | ovl_start_addr, ovl_end_addr, plugin_start | ||
38 | }; | ||
39 | #endif | ||
40 | |||
41 | /* here is a global api struct pointer. while not strictly necessary, | ||
42 | it's nice not to have to pass the api pointer in all function calls | ||
43 | in the plugin */ | ||
44 | struct plugin_api* rb; | ||
45 | int shut,cleanshut; | ||
46 | char *errormsg; | ||
47 | int gnuboy_main(char *rom); | ||
48 | |||
49 | /* libc functions */ | ||
50 | |||
51 | int isdigit(int c) { | ||
52 | return c>='0' && c<= '9'; | ||
53 | } | ||
54 | |||
55 | int isalpha(int c) { | ||
56 | return (c>='a' && c<='z')||(c>='A' && c<='Z'); | ||
57 | } | ||
58 | |||
59 | int isupper(int c) { | ||
60 | return c>='A'&&c<='Z'; | ||
61 | } | ||
62 | |||
63 | int isalnum(int c) { | ||
64 | return isdigit(c)||isalpha(c); | ||
65 | } | ||
66 | |||
67 | void die(char *message, ...) | ||
68 | { | ||
69 | shut=1; | ||
70 | errormsg=message; | ||
71 | } | ||
72 | |||
73 | void *mp3_bufferbase; | ||
74 | void *mp3_bufferpointer; | ||
75 | unsigned int mp3_buffer_free; | ||
76 | |||
77 | void *my_malloc(size_t size) | ||
78 | { | ||
79 | void *alloc; | ||
80 | |||
81 | if (!mp3_bufferbase) | ||
82 | { | ||
83 | mp3_bufferbase = mp3_bufferpointer | ||
84 | = rb->plugin_get_mp3_buffer(&mp3_buffer_free); | ||
85 | #if MEM <= 8 && !defined(SIMULATOR) | ||
86 | /* loaded as an overlay, protect from overwriting ourselves */ | ||
87 | if ((unsigned)(ovl_start_addr - (unsigned char *)mp3_bufferbase) | ||
88 | < mp3_buffer_free) | ||
89 | mp3_buffer_free = ovl_start_addr - (unsigned char *)mp3_bufferbase; | ||
90 | #endif | ||
91 | } | ||
92 | if (size + 4 > mp3_buffer_free) | ||
93 | return 0; | ||
94 | alloc = mp3_bufferpointer; | ||
95 | mp3_bufferpointer += size + 4; | ||
96 | mp3_buffer_free -= size + 4; | ||
97 | return alloc; | ||
98 | } | ||
99 | |||
100 | void setmallocpos(void *pointer) | ||
101 | { | ||
102 | mp3_bufferpointer = pointer; | ||
103 | mp3_buffer_free = mp3_bufferpointer - mp3_bufferbase; | ||
104 | } | ||
105 | |||
106 | /* this is the plugin entry point */ | ||
107 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | ||
108 | { | ||
109 | /* this macro should be called as the first thing you do in the plugin. | ||
110 | it test that the api version and model the plugin was compiled for | ||
111 | matches the machine it is running on */ | ||
112 | TEST_PLUGIN_API(api); | ||
113 | |||
114 | /* if you are using a global api pointer, don't forget to copy it! | ||
115 | otherwise you will get lovely "I04: IllInstr" errors... :-) */ | ||
116 | rb = api; | ||
117 | shut=0; | ||
118 | cleanshut=0; | ||
119 | mp3_bufferbase=mp3_bufferpointer=0; | ||
120 | mp3_buffer_free=0; | ||
121 | |||
122 | /* now go ahead and have fun! */ | ||
123 | rb->splash(HZ*2, true, "Rockboy v0.3"); | ||
124 | rb->lcd_clear_display(); | ||
125 | gnuboy_main(parameter); | ||
126 | |||
127 | if(shut&&!cleanshut) { | ||
128 | rb->splash(HZ*2, true, errormsg); | ||
129 | return PLUGIN_ERROR; | ||
130 | } | ||
131 | |||
132 | rb->splash(HZ*2, true, "Shutting down.. byebye ^^"); | ||
133 | |||
134 | cleanup(); | ||
135 | |||
136 | return PLUGIN_OK; | ||
137 | } | ||