static struct ematch_util *get_ematch_kind_num(__u16 kind) { char name[32]; if (lookup_map(kind, name, sizeof(name), EMATCH_MAP) < 0) return NULL; return get_ematch_kind(name); }
int map_lseek_action(char *s) { int flags = 0; char *s1; while ((s1 = strchr(s, '|'))) { *s1 = '\0'; flags |= lookup_map(s, lseek_action_map, ARRAY_SIZE(lseek_action_map)); *s1 = '|'; s = s1 + 1; } /* Last option */ flags |= lookup_map(s, lseek_action_map, ARRAY_SIZE(lseek_action_map)); return flags; }
int map_open_flags(char *s) { int flags = 0; char *s1; while ((s1 = strchr(s, '|'))) { *s1 = '\0'; flags |= lookup_map(s, open_flags_map, ARRAY_SIZE(open_flags_map)); *s1 = '|'; s = s1 + 1; } /* Last option */ flags |= lookup_map(s, open_flags_map, ARRAY_SIZE(open_flags_map)); return flags; }
int flying(void) { unsigned char ch; int shipy; int turning=0; int draw_splash=0,splash_count=0; int zint; /************************************************/ /* Flying */ /************************************************/ gr(); ram[DRAW_PAGE]=PAGE0; clear_bottom(); ram[DRAW_PAGE]=PAGE1; clear_bottom(); shipy=20; while(1) { if (splash_count>0) splash_count--; ch=grsim_input(); if ((ch=='q') || (ch==27)) break; #if 0 if (ch=='g') { BETA+=0.1; printf("Horizon=%lf\n",BETA); } if (ch=='h') { BETA-=0.1; printf("Horizon=%lf\n",BETA); } if (ch=='s') { scale_x++; scale_y++; printf("Scale=%lf\n",scale_x); } #endif if ((ch=='w') || (ch==APPLE_UP)) { if (shipy>16) { shipy-=2; space_z.i++; } splash_count=0; // printf("Z=%lf\n",space_z); } if ((ch=='s') || (ch==APPLE_DOWN)) { if (shipy<28) { shipy+=2; space_z.i--; } else { splash_count=10; } // printf("Z=%lf\n",space_z); } if ((ch=='a') || (ch==APPLE_LEFT)) { if (turning>0) { turning=0; } else { turning=-20; angle-=1; if (angle<0) angle+=ANGLE_STEPS; } } if ((ch=='d') || (ch==APPLE_RIGHT)) { if (turning<0) { turning=0; } else { turning=20; angle+=1; if (angle>=ANGLE_STEPS) angle-=ANGLE_STEPS; } } /* Used to be able to go backwards */ if (ch=='z') { if (speed<3) speed++; } if (ch=='x') { if (speed>0) speed--; } if (ch==' ') { speed=SPEED_STOPPED; } if (ch=='h') { print_help(); } /* Ending */ if (ch==13) { int landing_color,tx,ty; tx=cx.i; ty=cy.i; landing_color=lookup_map(tx,ty); printf("Trying to land at %d %d\n",tx,ty); printf("Color=%d\n",landing_color); if (landing_color==12) { int loop; zint=space_z.i; /* Land the ship */ for(loop=zint;loop>0;loop--) { draw_background_mode7(); grsim_put_sprite(shadow_forward,SHIPX+3,31+zint); grsim_put_sprite(ship_forward,SHIPX,shipy); page_flip(); usleep(200000); space_z.i--; } return 0; } else { htab(11); vtab(22); move_cursor(); print_both_pages("NEED TO LAND ON GRASS!"); } } if (speed!=SPEED_STOPPED) { int ii; dx.i = fixed_sin_scale[(angle+4)&0xf].i; // cos dx.f = fixed_sin_scale[(angle+4)&0xf].f; // cos dy.i = fixed_sin_scale[angle&0xf].i; dy.f = fixed_sin_scale[angle&0xf].f; for(ii=0;ii<speed;ii++) { fixed_add(&cx,&dx,&cx); fixed_add(&cy,&dy,&cy); } } draw_background_mode7(); zint=space_z.i; draw_splash=0; if (speed>0) { if ((shipy>25) && (turning!=0)) { splash_count=1; } if ((over_water) && (splash_count)) { draw_splash=1; } } // printf("VMW: %d %d\n",draw_splash,splash_count); if (turning==0) { if (draw_splash) { grsim_put_sprite(splash_forward, SHIPX+1,shipy+9); } grsim_put_sprite(shadow_forward,SHIPX+3,31+zint); grsim_put_sprite(ship_forward,SHIPX,shipy); } if (turning<0) { if (draw_splash) { grsim_put_sprite(splash_left, SHIPX+1,36); } grsim_put_sprite(shadow_left,SHIPX+3,31+zint); grsim_put_sprite(ship_left,SHIPX,shipy); turning++; } if (turning>0) { if (draw_splash) { grsim_put_sprite(splash_right, SHIPX+1,36); } grsim_put_sprite(shadow_right,SHIPX+3,31+zint); grsim_put_sprite(ship_right,SHIPX,shipy); turning--; } page_flip(); usleep(20000); } return 0; }
void draw_background_mode7(void) { int map_color; over_water=0; /* Draw Sky */ /* Originally wanted to be fancy and have sun too, but no */ color_equals(COLOR_MEDIUMBLUE); for(screen_y=0;screen_y<6;screen_y+=2) { hlin_double(ram[DRAW_PAGE], 0, 40, screen_y); } /* Draw hazy horizon */ color_equals(COLOR_GREY); hlin_double(ram[DRAW_PAGE], 0, 40, 6); // fixed_to_double(&space_z,&double_space_z); // double_factor=double_space_z*double_BETA; fixed_mul(&space_z,&BETA,&factor,0); if (!displayed) { printf("SPACEZ/BETA/FACTOR %x %x * %x %x = %x %x\n", space_z.i,space_z.f,BETA.i,BETA.f,factor.i,factor.f); } // printf("spacez=%lf beta=%lf factor=%lf\n", // fixed_to_double(&space_z), // fixed_to_double(&BETA), // fixed_to_double(&factor)); for (screen_y = 8; screen_y < LOWRES_H; screen_y+=2) { // then calculate the horizontal scale, or the distance between // space points on this horizontal line // double_horizontal_scale = double_space_z / (screen_y + horizon); // double_to_fixed(double_horizontal_scale,&horizontal_scale); horizontal_scale.i=0; horizontal_scale.f= horizontal_lookup[space_z.i&0xf][(screen_y-8)/2]; if (!displayed) { printf("HORIZ_SCALE %x %x\n", horizontal_scale.i,horizontal_scale.f); } // calculate the distance of the line we are drawing fixed_mul(&horizontal_scale,&scale,&distance,0); //fixed_to_double(&distance,&double_distance); // printf("Distance=%lf, horizontal-scale=%lf\n", // distance,horizontal_scale); if (!displayed) { printf("DISTANCE %x:%x\n", distance.i,distance.f); } // calculate the dx and dy of points in space when we step // through all points on this line dx.i=fixed_sin[(angle+8)&0xf].i; // -sin() dx.f=fixed_sin[(angle+8)&0xf].f; // -sin() fixed_mul(&dx,&horizontal_scale,&dx,0); if (!displayed) { printf("DX %x:%x\n", dx.i,dx.f); } dy.i=fixed_sin[(angle+4)&0xf].i; // cos() dy.f=fixed_sin[(angle+4)&0xf].f; // cos() fixed_mul(&dy,&horizontal_scale,&dy,0); if (!displayed) { printf("DY %x:%x\n", dy.i,dy.f); } // calculate the starting position //double_space_x =(double_distance+double_factor); fixed_add(&distance,&factor,&space_x); // double_to_fixed(double_space_x,&space_x); fixed_temp.i=fixed_sin[(angle+4)&0xf].i; // cos fixed_temp.f=fixed_sin[(angle+4)&0xf].f; // cos fixed_mul(&space_x,&fixed_temp,&space_x,0); fixed_add(&space_x,&cx,&space_x); fixed_temp.i=0xec; // -20 (LOWRES_W/2) fixed_temp.f=0; fixed_mul(&fixed_temp,&dx,&fixed_temp,0); fixed_add(&space_x,&fixed_temp,&space_x); if (!displayed) { printf("SPACEX! %x:%x\n", space_x.i,space_x.f); } fixed_add(&distance,&factor,&space_y); // double_space_y =(double_distance+double_factor); // double_to_fixed(double_space_y,&space_y); fixed_temp.i=fixed_sin[angle&0xf].i; fixed_temp.f=fixed_sin[angle&0xf].f; fixed_mul(&space_y,&fixed_temp,&space_y,0); fixed_add(&space_y,&cy,&space_y); fixed_temp.i=0xec; // -20 (LOWRES_W/2) fixed_temp.f=0; fixed_mul(&fixed_temp,&dy,&fixed_temp,0); fixed_add(&space_y,&fixed_temp,&space_y); if (!displayed) { printf("SPACEY! %x:%x\n", space_y.i,space_y.f); } // go through all points in this screen line for (screen_x = 0; screen_x < LOWRES_W-1; screen_x++) { // get a pixel from the tile and put it on the screen map_color=lookup_map(space_x.i,space_y.i); ram[COLOR]=map_color; ram[COLOR]|=map_color<<4; if ((screen_x==20) && (screen_y==38)) { if (map_color==COLOR_DARKBLUE) over_water=1; } hlin_double(ram[DRAW_PAGE], screen_x, screen_x+1, screen_y); // advance to the next position in space fixed_add(&space_x,&dx,&space_x); fixed_add(&space_y,&dy,&space_y); } } displayed=1; }
enum file_op map_syscall(char *syscall) { return lookup_map(syscall, fileop_map, ARRAY_SIZE(fileop_map)); }