1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
|
/* iosstart.m: iOS-specific interface code for Glulx. (Objective C)
Designed by Andrew Plotkin <erkyrath@eblong.com>
http://eblong.com/zarf/glulx/index.html
*/
#import "TerpGlkViewController.h"
#import "TerpGlkDelegate.h"
#import "GlkLibrary.h"
#import "GlkAppWrapper.h"
#import "GlkWindow.h"
#import "GlkStream.h"
#import "GlkFileRef.h"
#import "GlkUtilTypes.h"
#import "Geometry.h"
#include "glk.h" /* This comes with the IosGlk library. */
#include "glulxe.h"
#include "iosstart.h"
#include "iosglk_startup.h" /* This comes with the IosGlk library. */
static library_state_data library_state; /* used by the archive/unarchive hooks */
#if VM_DEBUGGER
/* This header file may come with the Glk library. If it doesn't, comment
out VM_DEBUGGER in glulxe.h -- you won't be able to use debugging. */
#include "gi_debug.h"
#endif /* VM_DEBUGGER */
static void iosglk_game_start(void);
static void iosglk_game_autorestore(void);
static void iosglk_game_select(glui32 selector, glui32 arg0, glui32 arg1, glui32 arg2);
static void stash_library_state(void);
static void recover_library_state(void);
static void free_library_state(void);
static void iosglk_library_archive(NSCoder *encoder);
static void iosglk_library_unarchive(NSCoder *decoder);
/* This is only needed for autorestore. */
extern gidispatch_rock_t glulxe_classtable_register_existing(void *obj, glui32 objclass, glui32 dispid);
static NSString *documents_dir()
{
/* We use an old-fashioned way of locating the Documents directory. (The NSManager method for this is iOS 4.0 and later.) */
NSArray *dirlist = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if (!dirlist || dirlist.count == 0) {
NSLog(@"unable to locate Documents directory.");
return nil;
}
return dirlist[0];
}
/* Backtrack through the current opcode (at prevpc), and figure out whether its input arguments are on the stack or not. This will be important when setting up the saved VM state for restarting its opcode.
The opmodes argument must be an array int[3]. Returns YES on success.
*/
static int parse_partial_operand(int *opmodes)
{
glui32 addr = prevpc;
/* Fetch the opcode number. */
glui32 opcode = Mem1(addr);
addr++;
if (opcode & 0x80) {
/* More than one-byte opcode. */
if (opcode & 0x40) {
/* Four-byte opcode */
opcode &= 0x3F;
opcode = (opcode << 8) | Mem1(addr);
addr++;
opcode = (opcode << 8) | Mem1(addr);
addr++;
opcode = (opcode << 8) | Mem1(addr);
addr++;
}
else {
/* Two-byte opcode */
opcode &= 0x7F;
opcode = (opcode << 8) | Mem1(addr);
addr++;
}
}
if (opcode != 0x130) { /* op_glk */
NSLog(@"iosglk_startup_code: parsed wrong opcode: %d", opcode);
return NO;
}
/* @glk has operands LLS. */
opmodes[0] = Mem1(addr) & 0x0F;
opmodes[1] = (Mem1(addr) >> 4) & 0x0F;
opmodes[2] = Mem1(addr+1) & 0x0F;
return YES;
}
/* We don't load in the game file here. Instead, we set a hook which glk_main() will call back to do that. Why? Because of the annoying restartability of the VM under iosglk; we may finish glk_main() and then have to call it again.
*/
void iosglk_startup_code()
{
set_library_start_hook(&iosglk_game_start);
set_library_autorestore_hook(&iosglk_game_autorestore);
set_library_select_hook(&iosglk_game_select);
max_undo_level = 32; // allow 32 undo steps
#ifdef IOSGLK_EXTEND_STARTUP_CODE
IOSGLK_EXTEND_STARTUP_CODE
#endif // IOSGLK_EXTEND_STARTUP_CODE
}
/* This is the library_start_hook, which will be called every time glk_main() begins. (VM thread)
*/
static void iosglk_game_start()
{
TerpGlkViewController *glkviewc = [TerpGlkViewController singleton];
NSString *pathname = glkviewc.terpDelegate.gamePath;
NSLog(@"iosglk_startup_code: game path is %@", pathname);
/* Retain this, because we're assigning it to a global. (It will look like a leak to XCode's leak-profiler.) */
gamefile = [[GlkStreamFile alloc] initWithMode:filemode_Read rock:1 unicode:NO textmode:NO dirname:@"." pathname:pathname];
/* Now we have to check to see if it's a Blorb file. */
int res;
unsigned char buf[12];
glk_stream_set_position(gamefile, 0, seekmode_Start);
res = glk_get_buffer_stream(gamefile, (char *)buf, 12);
if (!res) {
init_err = "The data in this stand-alone game is too short to read.";
return;
}
if (buf[0] == 'G' && buf[1] == 'l' && buf[2] == 'u' && buf[3] == 'l') {
locate_gamefile(FALSE);
}
else if (buf[0] == 'F' && buf[1] == 'O' && buf[2] == 'R' && buf[3] == 'M'
&& buf[8] == 'I' && buf[9] == 'F' && buf[10] == 'R' && buf[11] == 'S') {
locate_gamefile(TRUE);
}
else {
init_err = "This is neither a Glulx game file nor a Blorb file which contains one.";
}
}
/* This is the library_autorestore_hook, which will be called from glk_main() between VM setup and the beginning of the execution loop. (VM thread)
*/
static void iosglk_game_autorestore()
{
GlkLibrary *library = [GlkLibrary singleton];
NSString *dirname = documents_dir();
if (!dirname)
return;
NSString *gamepath = [dirname stringByAppendingPathComponent:@"autosave.glksave"];
NSString *libpath = [dirname stringByAppendingPathComponent:@"autosave.plist"];
if (![library.filemanager fileExistsAtPath:gamepath])
return;
if (![library.filemanager fileExistsAtPath:libpath])
return;
library_state.active = NO;
library_state.protectstart = 0;
library_state.protectend = 0;
library_state.iosys_mode = 0;
library_state.iosys_rock = 0;
library_state.stringtable = 0;
library_state.gamefiletag = 0;
library_state.accel_params = NULL;
library_state.accel_funcs = NULL;
library_state.id_map_list = NULL;
GlkLibrary *newlib = nil;
[GlkLibrary setExtraUnarchiveHook:iosglk_library_unarchive];
NSError *error = nil;
@try {
newlib = [NSKeyedUnarchiver unarchivedObjectOfClasses:[NSSet setWithArray:@[[GlkLibrary class], [NSString class], [NSMutableArray class], [NSMutableString class], [GlkWindow class], [GlkStream class], [GlkFileRef class], [NSValue class], [NSNumber class], [GlkStyledLine class], [GlkStyledString class], [GlkGridLine class], [Geometry class], [GlkObjIdEntry class]]] fromData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:libpath]] error:&error];
}
@catch (NSException *ex) {
// leave newlib as nil
NSLog(@"Unable to restore autosave library: Exception %@ Error %@", ex, error);
}
[GlkLibrary setExtraUnarchiveHook:nil];
if (!newlib || !library_state.active) {
/* Without a Glk state, there's no point in even trying the VM state. */
NSLog(@"library autorestore failed! Error: %@", error);
return;
}
int res;
GlkStreamFile *savefile = [[GlkStreamFile alloc] initWithMode:filemode_Read rock:1 unicode:NO textmode:NO dirname:dirname pathname:gamepath];
res = perform_restore(savefile, TRUE);
glk_stream_close(savefile, nil);
savefile = nil;
if (res) {
NSLog(@"VM autorestore failed!");
return;
}
pop_callstub(0);
/* Annoyingly, the updateFromLibrary we're about to do will close the currently-open gamefile. We'll recover it immediately, in recover_library_state(). */
gamefile = nil;
[library updateFromLibrary:newlib];
recover_library_state();
NSLog(@"autorestore succeeded.");
free_library_state();
}
/* This is the library_select_hook, which will be called every time glk_select() is invoked. (VM thread)
*/
static void iosglk_game_select(glui32 selector, glui32 arg0, glui32 arg1, glui32 arg2)
{
glui32 lasteventtype = [GlkAppWrapper singleton].lasteventtype;
//NSLog(@"### game called select, last event was %d", lasteventtype);
/* Do not autosave if we've just started up, or if the last event was a rearrange event. (We get rearranges in clusters, and they don't change anything interesting anyhow.) */
if (lasteventtype == -1 || lasteventtype == evtype_Arrange)
return;
iosglk_do_autosave(selector, arg0, arg1, arg2);
}
void iosglk_do_autosave(glui32 selector, glui32 arg0, glui32 arg1, glui32 arg2)
{
GlkLibrary *library = [GlkLibrary singleton];
//NSLog(@"### attempting autosave (pc = %x, eventaddr = %x, stack = %d before stub)", prevpc, eventaddr, stackptr);
/* When the save file is autorestored, the VM will restart the @glk opcode. That means that the Glk argument (the event structure address) must be waiting on the stack. Possibly also the @glk opcode's operands -- these might or might not have come off the stack. */
glui32 oldmode, oldrock;
int res;
int opmodes[3];
res = parse_partial_operand(opmodes);
if (!res)
return;
NSString *dirname = documents_dir();
if (!dirname)
return;
NSString *tmpgamepath = [dirname stringByAppendingPathComponent:@"autosave-tmp.glksave"];
GlkStreamFile *savefile = [[GlkStreamFile alloc] initWithMode:filemode_Write rock:1 unicode:NO textmode:NO dirname:dirname pathname:tmpgamepath];
/* Push all the necessary arguments for the @glk opcode. */
glui32 origstackptr = stackptr;
int stackvals = 0;
if (selector == 0x00C0) {
/* The event structure address: */
stackvals++;
if (stackptr+4 > stacksize)
fatal_error("Stack overflow in autosave callstub.");
StkW4(stackptr, arg0); /* eventaddr */
stackptr += 4;
}
else if (selector == 0x0062) {
/* The three arguments: */
stackvals++;
if (stackptr+4 > stacksize)
fatal_error("Stack overflow in autosave callstub.");
StkW4(stackptr, arg2); /* rock */
stackptr += 4;
stackvals++;
if (stackptr+4 > stacksize)
fatal_error("Stack overflow in autosave callstub.");
StkW4(stackptr, arg1); /* fmode */
stackptr += 4;
stackvals++;
if (stackptr+4 > stacksize)
fatal_error("Stack overflow in autosave callstub.");
StkW4(stackptr, arg0); /* usage */
stackptr += 4;
}
else {
fatal_error("Autosave with unrecognized glk selector.");
}
if (opmodes[1] == 8) {
/* The number of Glk arguments (1): */
stackvals++;
if (stackptr+4 > stacksize)
fatal_error("Stack overflow in autosave callstub.");
StkW4(stackptr, 1);
stackptr += 4;
}
if (opmodes[0] == 8) {
/* The Glk call selector (0x00C0): */
stackvals++;
if (stackptr+4 > stacksize)
fatal_error("Stack overflow in autosave callstub.");
StkW4(stackptr, selector);
stackptr += 4;
}
/* Push a temporary callstub which contains the *last* PC -- the address of the @glk(select) invocation. */
if (stackptr+16 > stacksize)
fatal_error("Stack overflow in autosave callstub.");
StkW4(stackptr+0, 0);
StkW4(stackptr+4, 0);
StkW4(stackptr+8, prevpc);
StkW4(stackptr+12, frameptr);
stackptr += 16;
/* temporarily set I/O system to GLK, which perform_save() needs */
stream_get_iosys(&oldmode, &oldrock);
stream_set_iosys(2, 0);
res = perform_save(savefile);
stream_set_iosys(oldmode, oldrock);
stackptr -= 16; // discard the temporary callstub
stackptr -= 4 * stackvals; // discard the temporary arguments
if (origstackptr != stackptr)
fatal_error("Stack pointer mismatch in autosave");
glk_stream_close(savefile, nil);
savefile = nil;
if (res) {
NSLog(@"VM autosave failed!");
return;
}
library_state.active = NO;
library_state.protectstart = 0;
library_state.protectend = 0;
library_state.iosys_mode = 0;
library_state.iosys_rock = 0;
library_state.stringtable = 0;
library_state.gamefiletag = 0;
library_state.accel_params = NULL;
library_state.accel_funcs = NULL;
library_state.id_map_list = NULL;
stash_library_state();
/* The iosglk_library_archive hook will write out the contents of library_state. */
NSString *finallibpath = [dirname stringByAppendingPathComponent:@"autosave.plist"];
[GlkLibrary setExtraArchiveHook:iosglk_library_archive];
NSError *error = nil;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:library requiringSecureCoding:NO error:&error];
BOOL result = [data writeToURL:[NSURL fileURLWithPath:finallibpath] options:NSDataWritingAtomic error:&error];
res = (result == YES);
[GlkLibrary setExtraArchiveHook:nil];
free_library_state();
if (!res) {
NSLog(@"library serialize failed! Error: %@", error);
return;
}
NSString *finalgamepath = [dirname stringByAppendingPathComponent:@"autosave.glksave"];
/* This is not really atomic, but we're already past the serious failure modes. */
[library.filemanager removeItemAtPath:finalgamepath error:nil];
error = nil;
res = [library.filemanager moveItemAtPath:tmpgamepath toPath:finalgamepath error:&error];
if (!res) {
NSLog(@"could not move game autosave to final position! Error: %@", error);
return;
}
}
/* Delete an autosaved game, if one exists.
*/
void iosglk_clear_autosave()
{
GlkLibrary *library = [GlkLibrary singleton];
NSString *dirname = documents_dir();
if (!dirname)
return;
NSString *finalgamepath = [dirname stringByAppendingPathComponent:@"autosave.glksave"];
NSString *finallibpath = [dirname stringByAppendingPathComponent:@"autosave.plist"];
[library.filemanager removeItemAtPath:finallibpath error:nil];
[library.filemanager removeItemAtPath:finalgamepath error:nil];
}
/* Utility function used by stash_library_state. Assumes that library_state.accel_funcs is a valid NSMutableArray. */
static void stash_one_accel_func(glui32 index, glui32 addr)
{
NSMutableArray *arr = (NSMutableArray *)library_state.accel_funcs;
GlulxAccelEntry *ent = [[GlulxAccelEntry alloc] initWithIndex:index addr:addr];
[arr addObject:ent];
}
/* Copy extra chunks of the VM state into the (static) library_state object. This is information needed by autosave, but not included in the regular save process.
*/
static void stash_library_state()
{
library_state.active = YES;
library_state.protectstart = protectstart;
library_state.protectend = protectend;
stream_get_iosys(&library_state.iosys_mode, &library_state.iosys_rock);
library_state.stringtable = stream_get_table();
glui32 count = accel_get_param_count();
NSMutableArray *accel_params = [NSMutableArray arrayWithCapacity:count];
library_state.accel_params = accel_params;
for (int ix=0; ix<count; ix++) {
glui32 param = accel_get_param(ix);
[accel_params addObject:@(param)];
}
NSMutableArray *accel_funcs = [NSMutableArray arrayWithCapacity:8];
library_state.accel_funcs = accel_funcs;
accel_iterate_funcs(&stash_one_accel_func);
if (gamefile)
library_state.gamefiletag = gamefile.tag.intValue;
GlkLibrary *library = [GlkLibrary singleton];
NSMutableArray *id_map_list = [NSMutableArray arrayWithCapacity:4];
library_state.id_map_list = id_map_list;
for (GlkWindow *win in library.windows) {
GlkObjIdEntry *ent = [[GlkObjIdEntry alloc] initWithClass:gidisp_Class_Window tag:win.tag id:find_id_for_window(win)];
[id_map_list addObject:ent];
}
for (GlkStream *str in library.streams) {
GlkObjIdEntry *ent = [[GlkObjIdEntry alloc] initWithClass:gidisp_Class_Stream tag:str.tag id:find_id_for_stream(str)];
[id_map_list addObject:ent];
}
for (GlkFileRef *fref in library.filerefs) {
GlkObjIdEntry *ent = [[GlkObjIdEntry alloc] initWithClass:gidisp_Class_Fileref tag:fref.tag id:find_id_for_fileref(fref)];
[id_map_list addObject:ent];
}
}
/* Copy chunks of VM state out of the (static) library_state object.
*/
static void recover_library_state()
{
if (library_state.active) {
protectstart = library_state.protectstart;
protectend = library_state.protectend;
stream_set_iosys(library_state.iosys_mode, library_state.iosys_rock);
stream_set_table(library_state.stringtable);
if (library_state.accel_params) {
for (int ix=0; ix<library_state.accel_params.count; ix++) {
NSNumber *num = library_state.accel_params[ix];
glui32 param = num.unsignedIntValue;
accel_set_param(ix, param);
}
}
if (library_state.accel_funcs) {
for (GlulxAccelEntry *entry in library_state.accel_funcs) {
accel_set_func(entry.index, entry.addr);
}
}
}
GlkLibrary *library = [GlkLibrary singleton];
if (library_state.id_map_list) {
for (GlkObjIdEntry *ent in library_state.id_map_list) {
switch (ent.objclass) {
case gidisp_Class_Window: {
GlkWindow *win = [library windowForIntTag:ent.tag];
if (!win) {
NSLog(@"### Could not find window for tag %d", ent.tag);
continue;
}
win.disprock = glulxe_classtable_register_existing((__bridge void *)(win), ent.objclass, ent.dispid);
}
break;
case gidisp_Class_Stream: {
GlkStream *str = [library streamForIntTag:ent.tag];
if (!str) {
NSLog(@"### Could not find stream for tag %d", ent.tag);
continue;
}
str.disprock = glulxe_classtable_register_existing((__bridge void *)(str), ent.objclass, ent.dispid);
}
break;
case gidisp_Class_Fileref: {
GlkFileRef *fref = [library filerefForIntTag:ent.tag];
if (!fref) {
NSLog(@"### Could not find fileref for tag %d", ent.tag);
continue;
}
fref.disprock = glulxe_classtable_register_existing((__bridge void *)(fref), ent.objclass, ent.dispid);
}
break;
}
}
}
if (library_state.gamefiletag)
gamefile = [library streamForIntTag:library_state.gamefiletag];
}
static void free_library_state()
{
library_state.active = false;
if (library_state.accel_params) {
library_state.accel_params = nil;
}
if (library_state.accel_funcs) {
library_state.accel_funcs = nil;
}
if (library_state.id_map_list) {
library_state.id_map_list = nil;
}
}
static void iosglk_library_archive(NSCoder *encoder)
{
if (library_state.active) {
[encoder encodeBool:YES forKey:@"glulx_library_state"];
[encoder encodeInt32:library_state.protectstart forKey:@"glulx_protectstart"];
[encoder encodeInt32:library_state.protectend forKey:@"glulx_protectend"];
[encoder encodeInt32:library_state.iosys_mode forKey:@"glulx_iosys_mode"];
[encoder encodeInt32:library_state.iosys_rock forKey:@"glulx_iosys_rock"];
[encoder encodeInt32:library_state.stringtable forKey:@"glulx_stringtable"];
if (library_state.accel_params)
[encoder encodeObject:library_state.accel_params forKey:@"glulx_accel_params"];
if (library_state.accel_funcs)
[encoder encodeObject:library_state.accel_funcs forKey:@"glulx_accel_funcs"];
[encoder encodeInt32:library_state.gamefiletag forKey:@"glulx_gamefiletag"];
if (library_state.id_map_list)
[encoder encodeObject:library_state.id_map_list forKey:@"glulx_id_map_list"];
}
}
static void iosglk_library_unarchive(NSCoder *decoder)
{
NSArray *arr;
if ([decoder decodeBoolForKey:@"glulx_library_state"]) {
library_state.active = true;
library_state.protectstart = [decoder decodeInt32ForKey:@"glulx_protectstart"];
library_state.protectend = [decoder decodeInt32ForKey:@"glulx_protectend"];
library_state.iosys_mode = [decoder decodeInt32ForKey:@"glulx_iosys_mode"];
library_state.iosys_rock = [decoder decodeInt32ForKey:@"glulx_iosys_rock"];
library_state.stringtable = [decoder decodeInt32ForKey:@"glulx_stringtable"];
arr = [decoder decodeObjectForKey:@"glulx_accel_params"];
library_state.accel_params = arr;
arr = [decoder decodeObjectForKey:@"glulx_accel_funcs"];
library_state.accel_funcs = arr;
library_state.gamefiletag = [decoder decodeInt32ForKey:@"glulx_gamefiletag"];
arr = [decoder decodeObjectForKey:@"glulx_id_map_list"];
library_state.id_map_list = arr;
}
}
int iosglk_can_restart_cleanly()
{
return vm_exited_cleanly;
}
void iosglk_shut_down_process()
{
/* Yes, we really do want to exit the app here. A fatal error has occurred at the interpreter level, so we can't restart it cleanly. The user has either hit a "goodbye" dialog button or the Home button; either way, it's time for suicide. */
NSLog(@"iosglk_shut_down_process: goodbye!");
exit(1);
}
/* GlkObjIdEntry: A simple data class which stores the mapping of a GlkLibrary object (window, stream, etc) to its Glulx-VM ID number. */
@implementation GlkObjIdEntry
+ (BOOL)supportsSecureCoding {
return YES;
}
- (instancetype) initWithClass:(int)objclassval tag:(NSNumber *)tagref id:(glui32)dispidval
{
self = [super init];
if (self) {
objclass = objclassval;
tag = tagref.intValue;
dispid = dispidval;
}
return self;
}
- (instancetype) initWithCoder:(NSCoder *)decoder
{
self = [super init];
if (self) {
objclass = [decoder decodeInt32ForKey:@"objclass"];
tag = [decoder decodeInt32ForKey:@"tag"];
dispid = [decoder decodeInt32ForKey:@"dispid"];
}
return self;
}
- (void) encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeInt32:objclass forKey:@"objclass"];
[encoder encodeInt32:tag forKey:@"tag"];
[encoder encodeInt32:dispid forKey:@"dispid"];
}
- (glui32) objclass { return objclass; }
- (glui32) tag { return tag; }
- (glui32) dispid { return dispid; }
@end
/* GlulxAccelEntry: A simple data class which stores an accelerated-function table entry. */
@implementation GlulxAccelEntry
+ (BOOL)supportsSecureCoding {
return YES;
}
- (instancetype) initWithIndex:(glui32)indexval addr:(glui32)addrval
{
self = [super init];
if (self) {
index = indexval;
addr = addrval;
}
return self;
}
- (instancetype) initWithCoder:(NSCoder *)decoder
{
self = [super init];
if (self) {
index = [decoder decodeInt32ForKey:@"index"];
addr = [decoder decodeInt32ForKey:@"addr"];
}
return self;
}
- (void) encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeInt32:index forKey:@"index"];
[encoder encodeInt32:addr forKey:@"addr"];
}
- (glui32) index { return index; }
- (glui32) addr { return addr; }
@end
|