static int32_t initwithoutgps(stateFilter *self) { struct data *this = (struct data *)self->localdata; this->useGPS = 0; return maininit(self); }
// Relocation fixup code that runs at new address after relocation complete. static void afterReloc(void) { // Running at new code address - do code relocation fixups malloc_fixupreloc(); // Move low-memory initial variable content to new location. extern u8 datalow_start[], datalow_end[], final_datalow_start[]; memmove(final_datalow_start, datalow_start, datalow_end - datalow_start); // Run main code maininit(); }
int init(Genome* g1=0, Genome* g2=0) { maininit(); cpVect vl[4] = {cpv(0, 0), cpv(1, 0), cpv(0.7, 3), cpv(0.3, 3)}; Ship* s = addship(sizeof(vl)/sizeof(cpVect), vl, cpv(0, 0), g1); cpVect vl2[4] = {cpv(0, 0), cpv(1, 0), cpv(0.7, 3), cpv(0.3, 3)}; Ship* s2 = addship(sizeof(vl2)/sizeof(cpVect), vl2, cpv(20, 0), g2); if (g2==0) s2->player = true; s->target = s2; s2->target = s; return 0; }
// Relocate init code and then call maininit() at new address. static void reloc_init(void) { if (!CONFIG_RELOCATE_INIT) { maininit(); return; } // Symbols populated by the build. extern u8 code32flat_start[]; extern u8 _reloc_min_align; extern u32 _reloc_abs_start[], _reloc_abs_end[]; extern u32 _reloc_rel_start[], _reloc_rel_end[]; extern u32 _reloc_init_start[], _reloc_init_end[]; extern u8 code32init_start[], code32init_end[]; extern u32 _reloc_datalow_start[], _reloc_datalow_end[]; extern u8 datalow_start[], datalow_end[], final_datalow_start[]; // Allocate space for init code. u32 initsize = code32init_end - code32init_start; u32 codealign = (u32)&_reloc_min_align; void *codedest = memalign_tmp(codealign, initsize); if (!codedest) panic("No space for init relocation.\n"); // Copy code and update relocs (init absolute, init relative, and runtime) dprintf(1, "Relocating low data from %p to %p (size %d)\n" , datalow_start, final_datalow_start, datalow_end - datalow_start); updateRelocs(code32flat_start, _reloc_datalow_start, _reloc_datalow_end , final_datalow_start - datalow_start); dprintf(1, "Relocating init from %p to %p (size %d)\n" , code32init_start, codedest, initsize); s32 delta = codedest - (void*)code32init_start; memcpy(codedest, code32init_start, initsize); updateRelocs(codedest, _reloc_abs_start, _reloc_abs_end, delta); updateRelocs(codedest, _reloc_rel_start, _reloc_rel_end, -delta); updateRelocs(code32flat_start, _reloc_init_start, _reloc_init_end, delta); // Call maininit() in relocated code. void (*func)(void) = (void*)afterReloc + delta; barrier(); func(); }
void inir(void) { char kbuf[80],vbuf[80]; int i,j,p; bool cgaflag; for (i=0;i<17;i++) { sprintf(kbuf,"%s%c",keynames[i],(i>=5 && i<10) ? '2' : 0); sprintf(vbuf,"%i/%i/%i/%i/%i",keycodes[i][0],keycodes[i][1], keycodes[i][2],keycodes[i][3],keycodes[i][4]); GetINIString(INI_KEY_SETTINGS,kbuf,vbuf,vbuf,80,ININAME); krdf[i]=true; p=0; for (j=0;j<5;j++) { keycodes[i][j]=atoi(vbuf+p); while (vbuf[p]!='/' && vbuf[p]!=0) p++; if (vbuf[p]==0) break; p++; } } gtime=(int)GetINIInt(INI_GAME_SETTINGS,"GauntletTime",120,ININAME); if (ftime == 0) { ftime=GetINIInt(INI_GAME_SETTINGS,"Speed",80000l,ININAME); } gauntlet=GetINIBool(INI_GAME_SETTINGS,"GauntletMode",false,ININAME); GetINIString(INI_GAME_SETTINGS,"Players","1",vbuf,80,ININAME); strupr(vbuf); if (vbuf[0]=='2' && vbuf[1]=='S') { diggers=2; nplayers=1; } else { diggers=1; nplayers=atoi(vbuf); if (nplayers<1 || nplayers>2) nplayers=1; } soundflag=GetINIBool(INI_SOUND_SETTINGS,"SoundOn",true,ININAME); musicflag=GetINIBool(INI_SOUND_SETTINGS,"MusicOn",true,ININAME); sound_device=(int)GetINIInt(INI_SOUND_SETTINGS,"Device",DEF_SND_DEV,ININAME); sound_port=(int)GetINIInt(INI_SOUND_SETTINGS,"Port",544,ININAME); sound_irq=(int)GetINIInt(INI_SOUND_SETTINGS,"Irq",5,ININAME); sound_dma=(int)GetINIInt(INI_SOUND_SETTINGS,"DMA",1,ININAME); sound_rate=(int)GetINIInt(INI_SOUND_SETTINGS,"Rate",22050,ININAME); sound_length=(int)GetINIInt(INI_SOUND_SETTINGS,"BufferSize",DEFAULT_BUFFER, ININAME); #if !defined(UNIX) && !defined(_SDL) if (sound_device==1) { #else if (!quiet) { #endif volume=1; setupsound=s1setupsound; killsound=s1killsound; fillbuffer=s1fillbuffer; initint8=s1initint8; restoreint8=s1restoreint8; soundoff=s1soundoff; setspkrt2=s1setspkrt2; settimer0=s1settimer0; timer0=s1timer0; settimer2=s1settimer2; timer2=s1timer2; soundinitglob(sound_port,sound_irq,sound_dma,sound_length,sound_rate); } dx_sound_volume=(int)GetINIInt(INI_SOUND_SETTINGS,"SoundVolume",0,ININAME); g_bWindowed=true; use_640x480_fullscreen=GetINIBool(INI_GRAPHICS_SETTINGS,"640x480",false, ININAME); use_async_screen_updates=GetINIBool(INI_GRAPHICS_SETTINGS,"Async",true, ININAME); synchvid=GetINIBool(INI_GRAPHICS_SETTINGS,"Synch",false,ININAME); cgaflag=GetINIBool(INI_GRAPHICS_SETTINGS,"CGA",false,ININAME); biosflag=GetINIBool(INI_GRAPHICS_SETTINGS,"BIOSPalette",false,ININAME); if (cgaflag || biosflag) { ddap->ginit=cgainit; ddap->gpal=cgapal; ddap->ginten=cgainten; ddap->gclear=cgaclear; ddap->ggetpix=cgagetpix; ddap->gputi=cgaputi; ddap->ggeti=cgageti; ddap->gputim=cgaputim; ddap->gwrite=cgawrite; ddap->gtitle=cgatitle; ddap->ginit(); ddap->gpal(0); } unlimlives=GetINIBool(INI_GAME_SETTINGS,"UnlimitedLives",false,ININAME); startlev=(int)GetINIInt(INI_GAME_SETTINGS,"StartLevel",1,ININAME); } void redefkeyb(bool allf) { int i,j,k,l,z,y=0; bool f; char kbuf[80],vbuf[80]; maininit(); if (diggers==2) { outtext(ddap, "PLAYER 1:",0,y,3); y+=12; } outtext(ddap, "PRESS NEW KEY FOR",0,y,3); y+=12; /* Step one: redefine keys that are always redefined. */ for (i=0;i<5;i++) { outtext(ddap, keynames[i],0,y,2); /* Red first */ findkey(i); outtext(ddap, keynames[i],0,y,1); /* Green once got */ y+=12; for (j=0;j<i;j++) { /* Note: only check keys just pressed (I hate it when this is done wrong, and it often is.) */ if (keycodes[i][0]==keycodes[j][0] && keycodes[i][0]!=0) { i--; y-=12; break; } for (k=2;k<5;k++) for (l=2;l<5;l++) if (keycodes[i][k]==keycodes[j][l] && keycodes[i][k]!=-2) { j=i; k=5; i--; y-=12; break; /* Try again if this key already used */ } } } if (diggers==2) { outtext(ddap, "PLAYER 2:",0,y,3); y+=12; for (i=5;i<10;i++) { outtext(ddap, keynames[i],0,y,2); /* Red first */ findkey(i); outtext(ddap, keynames[i],0,y,1); /* Green once got */ y+=12; for (j=0;j<i;j++) { /* Note: only check keys just pressed (I hate it when this is done wrong, and it often is.) */ if (keycodes[i][0]==keycodes[j][0] && keycodes[i][0]!=0) { i--; y-=12; break; } for (k=2;k<5;k++) for (l=2;l<5;l++) if (keycodes[i][k]==keycodes[j][l] && keycodes[i][k]!=-2) { j=i; k=5; i--; y-=12; break; /* Try again if this key already used */ } } } } /* Step two: redefine other keys which step one has caused to conflict */ z=0; y-=12; for (i=10;i<17;i++) { f=false; for (j=0;j<10;j++) for (k=0;k<5;k++) for (l=2;l<5;l++) if (keycodes[i][k]==keycodes[j][l] && keycodes[i][k]!=-2) f=true; for (j=10;j<i;j++) for (k=0;k<5;k++) for (l=0;l<5;l++) if (keycodes[i][k]==keycodes[j][l] && keycodes[i][k]!=-2) f=true; if (f || (allf && i!=z)) { if (i!=z) y+=12; outtext(ddap, keynames[i],0,y,2); /* Red first */ findkey(i); outtext(ddap, keynames[i],0,y,1); /* Green once got */ z=i; i--; } } /* Step three: save the INI file */ for (i=0;i<17;i++) if (krdf[i]) { sprintf(kbuf,"%s%c",keynames[i],(i>=5 && i<10) ? '2' : 0); sprintf(vbuf,"%i/%i/%i/%i/%i",keycodes[i][0],keycodes[i][1], keycodes[i][2],keycodes[i][3],keycodes[i][4]); WriteINIString(INI_KEY_SETTINGS,kbuf,vbuf,ININAME); } }
void parsecmd(int argc,char *argv[]) { char *word; int argch; int16_t arg,i=0,j,speedmul; bool sf, gs, norepf, hasopt; gs = norepf = false; #if defined(UNIX) digger_log = stderr; #else digger_log = fopen("DIGGER.log", "w+"); #endif for (arg=1;arg<argc;arg++) { word=argv[arg]; if (word[0]=='/' || word[0]=='-') { #if defined(UNIX) && defined(_SDL) argch = getarg(word[1], "FOUH?QM2BCKVL:R:P:S:E:G:X:A:I:", &hasopt); #else argch = getarg(word[1], "OUH?QM2BCKVL:R:P:S:E:G:A:I:", &hasopt); #endif i = 2; if (argch != -1 && hasopt && word[2] == ':') { i = 3; } if (argch == 'L') { j=0; while (word[i]!=0) levfname[j++]=word[i++]; levfname[j]=word[i]; levfflag=true; } #if defined(UNIX) && defined(_SDL) if (argch == 'X') { unsigned int x11_parent; x11_parent = strtol (&word[i], 0, 0); sdl_set_x11_parent(x11_parent); } if (argch == 'F') { sdl_enable_fullscreen(); } #endif if (argch =='R') recname(word+i); if (argch =='P' || argch =='E') { maininit(); openplay(word+i); if (escape) norepf=true; } if (argch == 'E') { finish(); if (escape) exit(0); exit(1); } if (argch =='O' && !norepf) { arg=0; continue; } if (argch == 'S') { speedmul=0; while (word[i]!=0) speedmul=10*speedmul+word[i++]-'0'; if (speedmul > 0) { ftime=speedmul*2000l; } else { ftime = 1; } gs=true; } if (argch == 'I') sscanf(word+i,"%hi",&startlev); if (argch == 'U') unlimlives=true; if (argch == '?' || argch == 'H' || argch == -1) { if (argch == -1) { fprintf(stderr, "Unknown option \"%c%c\"\n", word[0], word[1]); } finish(); printf("DIGGER - Copyright (c) 1983 Windmill software\n" "Restored 1998 by AJ Software\n" #ifdef ARM "Acorn port by Julian Brown\n" #endif "http://www.digger.org\n" "Version: "DIGGER_VERSION"\n\n" "Command line syntax:\n" " DIGGER [[/S:]speed] [[/L:]level file] [/C] [/B] [/Q] [/M] " "[/P:playback file]\n" " [/E:playback file] [/R:record file] [/O] [/K[A]] " "[/G[:time]] [/2]\n" " [/A:device,port,irq,dma,rate,length] [/V] [/U] " "[/I:level] " #if defined(UNIX) && defined(_SDL) "[/X:xid]" #endif "\n\n" #ifndef UNIX "/C = Use CGA graphics\n" "/B = Use BIOS palette functions for CGA (slow!)\n" #endif "/Q = Quiet mode (no sound at all) " "/M = No music\n" "/R = Record graphics to file\n" "/P = Playback and restart program " "/E = Playback and exit program\n" "/O = Loop to beginning of command line\n" "/K = Redefine keyboard\n" "/G = Gauntlet mode\n" "/2 = Two player simultaneous mode\n" "/A = Use alternate sound device\n" #ifndef UNIX "/V = Synchronize timing to vertical retrace\n" #endif #if defined(UNIX) && defined(_SDL) "/X = Embed in window\n" #endif "/U = Allow unlimited lives\n" "/I = Start on a level other than 1\n"); exit(1); } if (argch == 'Q') soundflag=false; if (argch == 'M') musicflag=false; if (argch == '2') diggers=2; if (argch == 'B' || argch == 'C') { ddap->ginit=cgainit; ddap->gpal=cgapal; ddap->ginten=cgainten; ddap->gclear=cgaclear; ddap->ggetpix=cgagetpix; ddap->gputi=cgaputi; ddap->ggeti=cgageti; ddap->gputim=cgaputim; ddap->gwrite=cgawrite; ddap->gtitle=cgatitle; if (argch == 'B') biosflag=true; ddap->ginit(); ddap->gpal(0); } if (argch == 'K') { if (word[2]=='A' || word[2]=='a') redefkeyb(true); else redefkeyb(false); } if (argch =='A') sscanf(word+i,"%hu,%hx,%hu,%hu,%hu,%hu",&sound_device,&sound_port,&sound_irq, &sound_dma,&sound_rate,&sound_length); if (argch == 'Q') quiet=true; if (argch == 'V') synchvid=true; if (argch == 'G') { gtime=0; while (word[i]!=0) gtime=10*gtime+word[i++]-'0'; if (gtime>3599) gtime=3599; if (gtime==0) gtime=120; gauntlet=true; } } else { i=strlen(word); if (i<1) continue; sf=true; if (!gs) for (j=0;j<i;j++) if (word[j]<'0' || word[j]>'9') { sf=false; break; } if (sf) { speedmul=0; j=0; while (word[j]!=0) speedmul=10*speedmul+word[j++]-'0'; gs=true; if (speedmul > 0) { ftime=speedmul*2000l; } else { ftime = 1; } } else { j=0; while (word[j]!=0) { levfname[j]=word[j]; j++; } levfname[j]=word[j]; levfflag=true; } } } if (levfflag) { if (read_levf(levfname) != 0) { #if defined(DIGGER_DEBUG) fprintf(digger_log, "levels load error\n"); #endif levfflag = false; } } }
int main(int argc,char *argv[]) { parsecmd(argc,argv); maininit(); return mainprog(); }