| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include "glk.h" |
| 5 |
#include "gi_dispa.h" |
| 6 |
#include "gi_blorb.h" |
| 7 |
#include "glulxe.h" |
| 8 |
|
| 9 |
#include "macglk_startup.h" |
| 10 |
|
| 11 |
static OSType gamefile_types[2] = {'UlxG', 'IFRS'}; |
| 12 |
extern strid_t gamefile; |
| 13 |
extern glui32 gamefile_start, gamefile_len; |
| 14 |
extern char *init_err, *init_err2; |
| 15 |
|
| 16 |
static Boolean startup_when_selected(FSSpec *file, OSType filetype); |
| 17 |
static Boolean startup_when_builtin(void); |
| 18 |
|
| 19 |
Boolean macglk_startup_code(macglk_startup_t *data) |
| 20 |
{ |
| 21 |
giblorb_err_t err; |
| 22 |
|
| 23 |
data->app_creator = 'gUlx'; |
| 24 |
data->startup_model = macglk_model_ChooseOrBuiltIn; |
| 25 |
data->gamefile_types = gamefile_types; |
| 26 |
data->num_gamefile_types = 2; |
| 27 |
data->savefile_type = 'IFZS'; |
| 28 |
data->datafile_type = 'UlxD'; |
| 29 |
data->gamefile = &gamefile; |
| 30 |
data->when_selected = &startup_when_selected; |
| 31 |
data->when_builtin = &startup_when_builtin; |
| 32 |
|
| 33 |
return TRUE; |
| 34 |
} |
| 35 |
|
| 36 |
static Boolean startup_when_selected(FSSpec *file, OSType filetype) |
| 37 |
{ |
| 38 |
if (filetype == 'UlxG') { |
| 39 |
return locate_gamefile(FALSE); |
| 40 |
} |
| 41 |
else if (filetype == 'IFRS') { |
| 42 |
return locate_gamefile(TRUE); |
| 43 |
} |
| 44 |
else { |
| 45 |
init_err = "This is neither a Glulx game file nor a Blorb file which contains one."; |
| 46 |
return FALSE; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
static Boolean startup_when_builtin() |
| 51 |
{ |
| 52 |
unsigned char buf[12]; |
| 53 |
int res; |
| 54 |
|
| 55 |
glk_stream_set_position(gamefile, 0, seekmode_Start); |
| 56 |
res = glk_get_buffer_stream(gamefile, (char *)buf, 12); |
| 57 |
if (!res) { |
| 58 |
init_err = "The data in this stand-alone game is too short to read."; |
| 59 |
return FALSE; |
| 60 |
} |
| 61 |
|
| 62 |
if (buf[0] == 'G' && buf[1] == 'l' && buf[2] == 'u' && buf[3] == 'l') { |
| 63 |
return locate_gamefile(FALSE); |
| 64 |
} |
| 65 |
else if (buf[0] == 'F' && buf[1] == 'O' && buf[2] == 'R' && buf[3] == 'M' |
| 66 |
&& buf[8] == 'I' && buf[9] == 'F' && buf[10] == 'R' && buf[11] == 'S') { |
| 67 |
return locate_gamefile(TRUE); |
| 68 |
} |
| 69 |
else { |
| 70 |
init_err = "This is neither a Glulx game file nor a Blorb file which contains one."; |
| 71 |
return FALSE; |
| 72 |
} |
| 73 |
} |
| 74 |
|