/*-----------------------------------------------------------------*/ void allocIntoSeg (symbol *sym) { memmap *segment; if (SPEC_ADDRSPACE (sym->etype)) { namedspacemap *nm; for (nm = namedspacemaps; nm; nm = nm->next) if (!strcmp (nm->name, SPEC_ADDRSPACE (sym->etype)->name)) break; if (!nm) { nm = Safe_alloc (sizeof (namedspacemap)); nm->name = Safe_alloc (strlen(SPEC_ADDRSPACE (sym->etype)->name) + 1); strcpy (nm->name, SPEC_ADDRSPACE (sym->etype)->name); nm->is_const = (SPEC_ADDRSPACE (sym->etype)->type && SPEC_CONST (SPEC_ADDRSPACE (sym->etype)->type)); nm->map = nm->is_const ? allocMap (0, 1, 0, 0, 0, 1, options.code_loc, SPEC_ADDRSPACE (sym->etype)->name, 'C', CPOINTER) : allocMap (0, 0, 0, 1, 0, 0, options.data_loc, SPEC_ADDRSPACE (sym->etype)->name, 'E', POINTER); nm->next = namedspacemaps; namedspacemaps = nm; } addSet (&nm->map->syms, sym); return; } segment = SPEC_OCLS (sym->etype); addSet (&segment->syms, sym); if (segment == pdata) sym->iaccess = 1; }
static void _pblaze_finaliseOptions(void) { port->mem.default_local_map = port->mem.default_globl_map = data; /* change stack to be in far space */ /* internal stack segment ; SFRSPACE - NO FAR-SPACE - YES PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACESS - NO DEBUG-NAME - 'B' POINTER-TYPE - FPOINTER */ istack = allocMap(0, 1, 0, 0, 0, 0, options.stack_loc, ISTACK_NAME, 'B', FPOINTER); /* also change xdata to be direct space since we can use lds/sts */ xdata->direct = 1; }
/*-----------------------------------------------------------------*/ void initMem () { /* allocate all the segments */ /* xternal stack segment ; SFRSPACE - NO FAR-SPACE - YES PAGED - YES DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'A' POINTER-TYPE - FPOINTER */ xstack = allocMap (0, 1, 1, 0, 0, 0, options.xstack_loc, XSTACK_NAME, 'A', PPOINTER); /* internal stack segment ; SFRSPACE - NO FAR-SPACE - NO PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'B' POINTER-TYPE - POINTER */ istack = allocMap (0, 0, 0, 0, 0, 0, options.stack_loc, ISTACK_NAME, 'B', POINTER); /* code segment ; SFRSPACE - NO FAR-SPACE - YES PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - YES DEBUG-NAME - 'C' POINTER-TYPE - CPOINTER */ code = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, CODE_NAME, 'C', CPOINTER); /* home segment ; SFRSPACE - NO FAR-SPACE - YES PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - YES DEBUG-NAME - 'C' POINTER-TYPE - CPOINTER */ home = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, HOME_NAME, 'C', CPOINTER); /* Static segment (code for variables ); SFRSPACE - NO FAR-SPACE - YES PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - YES DEBUG-NAME - 'D' POINTER-TYPE - CPOINTER */ statsg = allocMap (0, 1, 0, 0, 0, 1, 0, STATIC_NAME, 'D', CPOINTER); /* Constant Absolute Data segment (for variables ); SFRSPACE - NO FAR-SPACE - YES PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - YES DEBUG-NAME - 'D' POINTER-TYPE - CPOINTER */ c_abs = allocMap (0, 1, 0, 0, 0, 1, 0, CABS_NAME, 'D', CPOINTER); /* Data segment - internal storage segment ; SFRSPACE - NO FAR-SPACE - NO PAGED - NO DIRECT-ACCESS - YES BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'E' POINTER-TYPE - POINTER */ data = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME, 'E', POINTER); initialized = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, INITIALIZED_NAME, 'E', POINTER); initializer = allocMap (0, 0, 0, 1, 0, 1, options.code_loc, INITIALIZER_NAME, 'C', CPOINTER); /* Absolute internal storage segment ; SFRSPACE - NO FAR-SPACE - NO PAGED - NO DIRECT-ACCESS - YES BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'E' POINTER-TYPE - POINTER */ d_abs = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, IABS_NAME, 'E', POINTER); /* overlay segment - same as internal storage segment ; SFRSPACE - NO FAR-SPACE - NO PAGED - NO DIRECT-ACCESS - YES BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'E' POINTER-TYPE - POINTER */ if (OVERLAY_NAME) overlay = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME, 'E', POINTER); /* Xternal paged segment ; SFRSPACE - NO FAR-SPACE - NO PAGED - YES DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'P' POINTER-TYPE - PPOINTER */ pdata = allocMap (0, 0, 1, 0, 0, 0, options.xstack_loc, PDATA_NAME, 'P', PPOINTER); /* Xternal Data segment - SFRSPACE - NO FAR-SPACE - YES PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'F' POINTER-TYPE - FPOINTER */ xdata = allocMap (0, 1, 0, 0, 0, 0, options.xdata_loc, XDATA_NAME, 'F', FPOINTER); xidata = allocMap (0, 1, 0, 0, 0, 0, 0, XIDATA_NAME, 'F', FPOINTER); xinit = allocMap (0, 1, 0, 0, 0, 1, 0, XINIT_NAME, 'C', CPOINTER); /* Absolute external storage segment ; SFRSPACE - NO FAR-SPACE - YES PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'F' POINTER-TYPE - FPOINTER */ x_abs = allocMap (0, 1, 0, 0, 0, 0, options.xdata_loc, XABS_NAME, 'F', FPOINTER); /* Indirectly addressed internal data segment SFRSPACE - NO FAR-SPACE - NO PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'G' POINTER-TYPE - IPOINTER */ idata = allocMap (0, 0, 0, 0, 0, 0, options.idata_loc, IDATA_NAME, 'G', IPOINTER); /* Indirectly addressed absolute internal segment SFRSPACE - NO FAR-SPACE - NO PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'E' POINTER-TYPE - IPOINTER */ i_abs = allocMap (0, 0, 0, 0, 0, 0, options.data_loc, IABS_NAME, 'E', IPOINTER); /* Bit space ; SFRSPACE - NO FAR-SPACE - NO PAGED - NO DIRECT-ACCESS - YES BIT-ACCESS - YES CODE-ACCESS - NO DEBUG-NAME - 'H' POINTER-TYPE - _NONE_ */ bit = allocMap (0, 0, 0, 1, 1, 0, 0, BIT_NAME, 'H', 0); /* Special function register space :- SFRSPACE - YES FAR-SPACE - NO PAGED - NO DIRECT-ACCESS - YES BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'I' POINTER-TYPE - _NONE_ */ sfr = allocMap (1, 0, 0, 1, 0, 0, 0, REG_NAME, 'I', 0); /* Register space ; SFRSPACE - YES FAR-SPACE - NO PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - ' ' POINTER-TYPE - _NONE_ */ reg = allocMap (1, 0, 0, 0, 0, 0, 0, REG_NAME, ' ', 0); /* SFR bit space SFRSPACE - YES FAR-SPACE - NO PAGED - NO DIRECT-ACCESS - YES BIT-ACCESS - YES CODE-ACCESS - NO DEBUG-NAME - 'J' POINTER-TYPE - _NONE_ */ sfrbit = allocMap (1, 0, 0, 1, 1, 0, 0, REG_NAME, 'J', 0); /* EEPROM space SFRSPACE - NO FAR-SPACE - YES PAGED - NO DIRECT-ACCESS - NO BIT-ACCESS - NO CODE-ACCESS - NO DEBUG-NAME - 'K' POINTER-TYPE - EEPPOINTER */ eeprom = allocMap (0, 1, 0, 0, 0, 0, 0, REG_NAME, 'K', EEPPOINTER); /* the unknown map */ generic = allocMap (1, 0, 0, 1, 1, 0, 0, REG_NAME, ' ', GPOINTER); }
//#define SWAP(a, b) tmp=a; a=b; b=tmp; void main() { bitmap_t ptmp; // player sprite word q=1; const char *cpus; static int persist_aniframe = 0; /* gonna be increased to 1 before being used, so 0 is ok for default */ page_t screen, screen2, screen3; map_t map; map_view_t mv, mv2, mv3; map_view_t *bg, *spri, *mask;//, *tmp; byte *ptr; /* create the map */ map = allocMap(MAPX,MAPY); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly initMap(&map); mv.map = ↦ mv2.map = ↦ mv3.map = ↦ /* draw the tiles */ ptr = map.data; /*data\\*/ ptmp = bitmapLoadPcx("ptmp.pcx"); // load sprite setkb(1); modexEnter(); modexPalUpdate(ptmp.palette); screen = modexDefaultPage(); screen.width += (TILEWH*2); screen.height += (TILEWH*2)+QUADWH; mv.page = &screen; screen2 = modexNextPage(mv.page); mv2.page = &screen2; screen3 = screen2; mv3.page = &screen3; /* set up paging */ bg = &mv; spri = &mv2; mask = &mv3; //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen mapGoTo(bg, 0, 0); mapGoTo(spri, 0, 0); //mapGoTo(mask, 0, 0); //TODO: put player in starting position of spot //default player position on the viewable map player.tx = bg->tx + 10; player.ty = bg->ty + 8; player.x = player.tx*TILEWH; player.y = player.ty*TILEWH; player.triggerx = player.tx; player.triggery = player.ty+1; //TODO: erase player initial draw modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp); //temp draw trigger box modexClearRegion(spri->page, player.triggerx*16, player.triggery*16, 16, 16, 1); modexClearRegion(bg->page, player.triggerx*16, player.triggery*16, 16, 16, 1); modexShowPage(spri->page); while(!keyp(1))//!keyp(1)) { //top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction //when player.tx or player.ty == 0 or player.tx == 20 or player.ty == 15 then stop because that is edge of map and you do not want to walk of the map #define INC_PER_FRAME if(q&1) persist_aniframe++; if(persist_aniframe>4) persist_aniframe = 1; //temp testing /*if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10) { for(q=1; q<=(TILEWH/SPEED); q++) { //INC_PER_FRAME; //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp); //animatePlayer(bg, spri, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp); mapScrollRight(bg, SPEED); //mapScrollRight(spri, SPEED); //mapScrollRight(mask, SPEED); modexShowPage(bg->page); } player.tx++; } else if(player.tx < MAPX) { for(q=1; q<=(TILEWH/SPEED); q++) { INC_PER_FRAME; player.x+=SPEED; //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp); animatePlayer(bg, spri, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp); modexShowPage(spri->page); } player.tx++; } else { break; }*/ if(keyp(77) && !keyp(75)) { if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10 && !(player.tx+1 == TRIGGX && player.ty == TRIGGY)) { for(q=1; q<=(TILEWH/SPEED); q++) { INC_PER_FRAME; //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp); animatePlayer(bg, spri, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp); mapScrollRight(bg, SPEED); mapScrollRight(spri, SPEED); //mapScrollRight(mask, SPEED); modexShowPage(spri->page); } player.tx++; } else if(player.tx < MAPX && !(player.tx+1 == TRIGGX && player.ty == TRIGGY)) { for(q=1; q<=(TILEWH/SPEED); q++) { INC_PER_FRAME; player.x+=SPEED; //animatePlayer(bg, spri, mask, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp); animatePlayer(bg, spri, 1, 0, player.x, player.y, persist_aniframe, q, &ptmp); modexShowPage(spri->page); } player.tx++; } else { modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32); modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 32, 24, 32, &ptmp); modexShowPage(spri->page); } player.triggerx = player.tx+1; player.triggery = player.ty; } if(keyp(75) && !keyp(77)) { if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY)) { for(q=1; q<=(TILEWH/SPEED); q++) { INC_PER_FRAME; //animatePlayer(bg, spri, mask, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp); animatePlayer(bg, spri, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp); mapScrollLeft(bg, SPEED); mapScrollLeft(spri, SPEED); //mapScrollLeft(mask, SPEED); modexShowPage(spri->page); } player.tx--; } else if(player.tx > 1 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY)) { for(q=1; q<=(TILEWH/SPEED); q++) { INC_PER_FRAME; player.x-=SPEED; //animatePlayer(bg, spri, mask, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp); animatePlayer(bg, spri, 3, 0, player.x, player.y, persist_aniframe, q, &ptmp); modexShowPage(spri->page); } player.tx--; } else { modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32); modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 96, 24, 32, &ptmp); modexShowPage(spri->page); } player.triggerx = player.tx-1; player.triggery = player.ty; } if(keyp(80) && !keyp(72)) { if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty+1 == TRIGGY)) { for(q=1; q<=(TILEWH/SPEED); q++) { INC_PER_FRAME; //animatePlayer(bg, spri, mask, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp); animatePlayer(bg, spri, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp); mapScrollDown(bg, SPEED); mapScrollDown(spri, SPEED); //mapScrollDown(mask, SPEED); modexShowPage(spri->page); } player.ty++; } else if(player.ty < MAPY && !(player.tx == TRIGGX && player.ty+1 == TRIGGY)) { for(q=1; q<=(TILEWH/SPEED); q++) { INC_PER_FRAME; player.y+=SPEED; //animatePlayer(bg, spri, mask, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp); animatePlayer(bg, spri, 2, 0, player.x, player.y, persist_aniframe, q, &ptmp); modexShowPage(spri->page); } player.ty++; } else { modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32); modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp); modexShowPage(spri->page); } player.triggerx = player.tx; player.triggery = player.ty+1; } if(keyp(72) && !keyp(80)) { if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY)) { for(q=1; q<=(TILEWH/SPEED); q++) { INC_PER_FRAME; //animatePlayer(bg, spri, mask, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp); animatePlayer(bg, spri, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp); mapScrollUp(bg, SPEED); mapScrollUp(spri, SPEED); //mapScrollUp(mask, SPEED); modexShowPage(spri->page); } player.ty--; } else if(player.ty > 1 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY)) { for(q=1; q<=(TILEWH/SPEED); q++) { INC_PER_FRAME; player.y-=SPEED; //animatePlayer(bg, spri, mask, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp); modexShowPage(spri->page); animatePlayer(bg, spri, 0, 0, player.x, player.y, persist_aniframe, q, &ptmp); } player.ty--; } else { modexCopyPageRegion(spri->page, bg->page, player.x-4, player.y-TILEWH, player.x-4, player.y-TILEWH, 24, 32); modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 0, 24, 32, &ptmp); modexShowPage(spri->page); } player.triggerx = player.tx; player.triggery = player.ty-1; } //modexClearRegion(mask->page, 66, 66, 2, 40, 0); if((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(KEY_ENTER)) { short i; for(i=600; i>=400; i--) { sound(i); } nosound(); } } modexLeave(); setkb(0); printf("Project 16 scroll.exe\n"); printf("tx: %d\n", bg->tx); printf("ty: %d\n", bg->ty); printf("player.x: %d\n", player.x); printf("player.y: %d\n", player.y); printf("player.tx: %d\n", player.tx); printf("player.ty: %d\n", player.ty); printf("player.triggx: %d\n", player.triggerx); printf("player.triggy: %d\n", player.triggery); printf("dxThresh: %d\n", bg->dxThresh); printf("dyThresh: %d\n", bg->dyThresh); printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n"); printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n"); printf("\n"); switch(detectcpu()) { case 0: cpus = "8086/8088 or 186/88"; break; case 1: cpus = "286"; break; case 2: cpus = "386 or newer"; break; default: cpus = "internal error"; break; } printf("detected CPU type: %s\n", cpus); }
GENE * GA(PROTAIN * prot){ MAP * map = allocMap(prot->len); GENE * current[G_SIZE]; GENE * next[G_SIZE]; for(int i = 0; i < G_SIZE; i++){ current[i] = allocGene(prot->len); next[i] = allocGene(prot->len); setGeneAtRondom(current[i]); //printGene(current[i]); } int counter_cross = 0; int counter_copy = 0; int counter_mutate = 0; for(int generation = 0; generation < MAX_GEN; generation++){ // if((generation == 0) || (generation == MAX_GEN - 1)){ printf("**********************************************\n"); printf("**********************************************\n"); printf("**** generation %3d ****\n", generation); printf("**********************************************\n"); printf("**********************************************\n"); // } //各遺伝子の評価値の計算 int max = -1; int maxIndex = -1; for(int i = 0; i < MAX_GEN; i++){ initGeneVal(current[i]); geneValue(map, prot, current[i]); if(max < current[i]->val){ max = current[i]->val; maxIndex = i; } //printf("%d : val = %d\n", i, current[i]->val); } geneValue(map, prot, current[maxIndex]); // if((generation == 0) || (generation == MAX_GEN - 1)){ printMap(map); printf("max val is %d (index : %d)\n", current[maxIndex]->val, maxIndex); // } /* * select and generate */ int counter = 0; while(counter < G_SIZE){ int roulette = rand() % 1000; if(roulette < P_CROSS){//crossing int index1 = selectByRoulette(current); int index2; do{ index2 = selectByRoulette(current); }while(index1 == index2); cross(current[index1], current[index2], next[counter]); counter_cross++; }else if(roulette < P_CROSS + P_COPY){//copying int index = selectByRoulette(current); copy(current[index], next[counter]); counter_copy++; }else{//mutation int index = selectByRoulette(current); mutate(current[index], next[counter]); counter_mutate++; } counter++; } swapGeneration(current, next); } printf("crossing %d times occurred\n", counter_cross); printf("copying %d times occurred\n", counter_copy); printf("mutation %d times occurred\n", counter_mutate); return NULL; }