int main(int argc, char *argv[]) { char eventFullPathName[100]; int eventnum; int x,y,prex = 0,prey = 0; int fb_fd,fp; struct fb_var_screeninfo fbvar; struct fb_fix_screeninfo fbfix; unsigned char *fb_mapped; int mem_size; if (argc != 2) { printf("Usage : touchapp <event Number>\n"); printf("To see the event number, do \"cat /proc/bus/input/devices\" \n"); return 1; } eventnum = atoi(argv[1]); sprintf(eventFullPathName,"%s%d",EVENT_STR,eventnum); printf("touch input event name:%s\n", eventFullPathName); fp = open( eventFullPathName, O_RDONLY); if (-1 == fp) { printf("%s open fail\n",eventFullPathName); return 1; } if( access(FBDEV_FILE, F_OK) ) { printf("%s: access error\n", FBDEV_FILE); close(fp); return 1; } if( (fb_fd = open(FBDEV_FILE, O_RDWR)) < 0) { printf("%s: open error\n", FBDEV_FILE); close(fp); return 1; } if( ioctl(fb_fd, FBIOGET_VSCREENINFO, &fbvar) ) { printf("%s: ioctl error - FBIOGET_VSCREENINFO \n", FBDEV_FILE); goto fb_err; } if( ioctl(fb_fd, FBIOGET_FSCREENINFO, &fbfix) ) { printf("%s: ioctl error - FBIOGET_FSCREENINFO \n", FBDEV_FILE); goto fb_err; } screen_width = fbvar.xres; screen_height = fbvar.yres; bits_per_pixel = fbvar.bits_per_pixel; line_length = fbfix.line_length; printf("screen_width : %d\n", screen_width); printf("screen_height : %d\n", screen_height); printf("bits_per_pixel : %d\n", bits_per_pixel); printf("line_length : %d\n", line_length); mem_size = screen_width * screen_height * 4; fb_mapped = (unsigned char *)mmap(0, mem_size, PROT_READ|PROT_WRITE, MAP_SHARED, fb_fd, 0); if (fb_mapped < 0) { printf("mmap error!\n"); goto fb_err; } initScreen(fb_mapped); while(1) { readFirstCoordinate(fp,&x, &y); drawCoordinate(fb_mapped,x,y, prex, prey); prex = x; prey = y; } fb_err: close(fb_fd); close(fp); return 0; }
int main(int argc, char* argv[]) { int seed = init_rand(); //int seed = init_rand(1314485160); std::cout << "seed:" << seed << std::endl; initScreen(); displayTitleScreen(); int world_width = worldScreenDims[WIDTH]; int world_height = worldScreenDims[HEIGHT]; int world_depth = 5; world = new World(world_width, world_height, world_depth); setWorld(world);//interface.h, just to keep a pointer to the world so It doesn't have to get passed with every message, prompt, etc. probably a better way to do this but i cba player = world->generatePlayer(); enemies = world->generateEnemies(4,8); world->generateItems(25,50); std::stringstream intro_stream; intro_stream << "You are " << player->getName() << ", an Adventurer in search of the Icon of Weedaula."; message(intro_stream.str()); message("Bring the Icon back to the surface to win the game!"); message("Press '?' for help"); while (!isGameOver()) { world->incrementTimeStep(); player->FOV(player->getMapLevel()); displayGameScreen(); updateScreen(); player->startTurn(); while (!player->isTurnFinished() && player->isTurn() && !isGameOver()) { handleKeyPress(); } player->endTurn(); enemies = world->getEnemyList(); for (unsigned int i = 0; i < enemies.size(); i++) { Enemy *en = enemies[i]; en->FOV(en->getMapLevel()); en->startTurn(); if (en->isTurn() && withinRange(en->getMapLevel(), player->getMapLevel(), player->getMapLevel())) { en->takeTurn(); } en->endTurn(); } } if (isGameOver()) { if (!player->isAlive()) { displayGameOverScreen("You have been struck down"); } } }
/* internal engine routines */ static void * _output_setup(int w, int h) { Render_Engine *re; int i; u16 width, height; DATA32 *image_data = NULL; int image_size; printf ("_output_setup called : %dx%d\n", w, h); re = calloc(1, sizeof(Render_Engine)); if (!re) return NULL; /* Allocate a 1Mb buffer, alligned to a 1Mb boundary * to be our shared IO memory with the RSX. */ re->host_addr = memalign (1024 * 1024, HOST_SIZE); if (re->host_addr == NULL) { free (re); return NULL; } re->context = initScreen (re->host_addr, HOST_SIZE); if (re->context == NULL) { free (re->host_addr); free (re); return NULL; } width = w; height = h; setResolution (re->context, &width, &height); re->currentBuffer = 0; re->width = width; re->height = height; for (i = 0; i < MAX_BUFFERS; i++) makeBuffer (&re->buffers[i], width, height, i); flipBuffer(re->context, MAX_BUFFERS - 1); /* if we haven't initialized - init (automatic abort if already done) */ evas_common_cpu_init(); evas_common_blend_init(); evas_common_image_init(); evas_common_convert_init(); evas_common_scale_init(); evas_common_rectangle_init(); evas_common_polygon_init(); evas_common_line_init(); evas_common_font_init(); evas_common_draw_init(); evas_common_tilebuf_init(); re->tb = evas_common_tilebuf_new(w, h); /* in preliminary tests 16x16 gave highest framerates */ evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE); /* Allocate our memaligned backbuffer */ image_size = ((w * h * sizeof(u32)) + 0xfffff) & - 0x100000; image_data = memalign (1024 * 1024, image_size); re->rgba_image = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(), w, h, image_data, 1, EVAS_COLORSPACE_ARGB8888); gcmMapMainMemory(image_data, image_size, &re->rgba_image_offset); return re; }
void setup(void){ // Setup Car simulator pinMode(39, OUTPUT); //Serial.begin(9600); printf("Setup...\n"); pinMode(sda, OUTPUT); pinMode(scl, OUTPUT); digitalWrite(scl, HIGH); digitalWrite(sda, HIGH); //attachInterrupt(pinInt0, checkChangesDigital, FALLING); // Set interrupt - changes in pin0 (HIGH) execute function checkChangesDigital() audi = readData(); // Setup VM800 unsigned char duty; //Serial.begin(9600); printf("Poczatek inicjalizacji\n"); #ifdef PIC //initial PIC SPI configuration SSPEN=0; // diable SSP module to begin configuration SSPSTAT=0b01000000; // 0 - BF<0>, Buffer Full Status bit, SSPBUFF is empty // 1 - CKE<6>, CKP = 1, Data on falling edge of SCK // 0 - SMP<7>, SPI Master Mode, Input data sample in middle of data output time SSPCON=0b00000000; // 0000 - SSPM<3:0>, SPI Master mode, clock = FOSC/4 10MHz. // 1 - CKP<4>, Clock Polarity Select Bit, Idle high state // 1 - SSPEN<5>, Enable serial port and config SCK, SDO, SDI // 0 - SSPOV<6>, Reset Synchronous Serial Port OVerflow, before sending // 0 - WCOL<7>, Clear, No collisions SSPEN=1; // re-enable SSP module #else pinMode(xSDI, INPUT); pinMode(xSDO, OUTPUT); pinMode(xclock, OUTPUT); pinMode(xPD, OUTPUT); pinMode(xCS, OUTPUT); #endif // LCD display parameters #ifdef LCD_QVGA // QVGA display parameters lcdWidth = 320; // Active width of LCD display lcdHeight = 240; // Active height of LCD display lcdHcycle = 408; // Total number of clocks per line lcdHoffset = 70; // Start of active line lcdHsync0 = 0; // Start of horizontal sync pulse lcdHsync1 = 10; // End of horizontal sync pulse lcdVcycle = 263; // Total number of lines per screen lcdVoffset = 13; // Start of active screen lcdVsync0 = 0; // Start of vertical sync pulse lcdVsync1 = 2; // End of vertical sync pulse lcdPclk = 8; // Pixel Clock lcdSwizzle = 2; // Define RGB output pins lcdPclkpol = 0; // Define active edge of PCLK #endif #ifdef LCD_WQVGA // WQVGA display parameters lcdWidth = 480; // Active width of LCD display lcdHeight = 272; // Active height of LCD display lcdHcycle = 548; // Total number of clocks per line lcdHoffset = 43; // Start of active line lcdHsync0 = 0; // Start of horizontal sync pulse lcdHsync1 = 41; // End of horizontal sync pulse lcdVcycle = 292; // Total number of lines per screen lcdVoffset = 12; // Start of active screen lcdVsync0 = 0; // Start of vertical sync pulse lcdVsync1 = 10; // End of vertical sync pulse lcdPclk = 5; // Pixel Clock lcdSwizzle = 0; // Define RGB output pins lcdPclkpol = 1; // Define active edge of PCLK #endif //wake up FT800 #ifdef PIC RC7=0; // set PD LOW delay_ms(20); RC7=1; // set PD high delay_ms(20); #else digitalWrite(xPD, LOW); delay_ms(2); digitalWrite(xPD, HIGH); delay_ms(2); #endif ft800cmdWrite(FT800_ACTIVE); // Start FT800 delay_ms(5); // Give some time to process ft800cmdWrite(FT800_CLKEXT); // Set FT800 for external clock delay_ms(5); //Give some time to process ft800cmdWrite(FT800_CLK48M); // Set FT800 for 48MHz PLL delay_ms(5); ft800cmdWrite(FT800_CORERST); // Set FT800 for 48MHz PLL delay_ms(5); ft800cmdWrite(FT800_GPUACTIVE); // Set FT800 for 48MHz PLL delay_ms(5); if(ft800memRead8(REG_ID)!=0x7C){ // Read ID register - is it 0x7C? printf("Cos nie tak: \n"); //Serial.println(ft800memRead8(REG_ID)); //return; } printf("OK\n"); delay_us(2); ft800memWrite8(REG_PCLK, ZERO); // Set PCLK to zero - don't clock the LCD until later ft800memWrite8(REG_PWM_DUTY, ZERO); // Turn off backlight // Initialize Display ft800memWrite16(REG_HSIZE, lcdWidth); // active display width ft800memWrite16(REG_HCYCLE, lcdHcycle); // total number of clocks per line, incl front/back porch ft800memWrite16(REG_HOFFSET,lcdHoffset); // start of active line ft800memWrite16(REG_HSYNC0, lcdHsync0); // start of horizontal sync pulse ft800memWrite16(REG_HSYNC1, lcdHsync1); // end of horizontal sync pulse ft800memWrite16(REG_VSIZE, lcdHeight); // active display height ft800memWrite16(REG_VCYCLE, lcdVcycle); // total number of lines per screen, incl pre/post ft800memWrite16(REG_VOFFSET,lcdVoffset); // start of active screen ft800memWrite16(REG_VSYNC0, lcdVsync0); // start of vertical sync pulse ft800memWrite16(REG_VSYNC1, lcdVsync1); // end of vertical sync pulse ft800memWrite8(REG_SWIZZLE, lcdSwizzle); // FT800 output to LCD - pin order ft800memWrite8(REG_PCLK_POL,lcdPclkpol); // LCD data is clocked in on this PCLK edge // Don't set PCLK yet - wait for just after the first display list // End of Initialize Display // Configure Touch and Audio - not used in this example, so disable both //ft800memWrite8(REG_TOUCH_MODE, 0x03); ft800memWrite16(REG_TOUCH_RZTHRESH, 1200); // Eliminate any false touches ft800memWrite8(REG_VOL_PB, ZERO); // turn recorded audio volume down ft800memWrite8(REG_VOL_SOUND, ZERO); // turn synthesizer volume down ft800memWrite16(REG_SOUND, 0x6000); // set synthesizer to mute // End of Configure Touch and Audio // Write Initial Display List & Enable Display ramDisplayList=RAM_DL; // start of Display List ft800memWrite32(ramDisplayList, DL_CLEAR_RGB); // Clear Color RGB 00000010 RRRRRRRR GGGGGGGG BBBBBBBB (R/G/B = Colour values) default zero / black ramDisplayList+=4; // point to next location ft800memWrite32(ramDisplayList, (DL_CLEAR|CLR_COL|CLR_STN|CLR_TAG)); // Clear 00100110 -------- -------- -----CST (C/S/T define which parameters to clear) ramDisplayList+=4; // point to next location ft800memWrite32(ramDisplayList, DL_DISPLAY); // DISPLAY command 00000000 00000000 00000000 00000000 (end of display list) ft800memWrite32(REG_DLSWAP, DLSWAP_FRAME); // 00000000 00000000 00000000 000000SS (SS bits define when render occurs) // Nothing is being displayed yet... the pixel clock is still 0x00 ramDisplayList=RAM_DL; // Reset Display List pointer for next list ft800Gpio=ft800memRead8(REG_GPIO); // Read the FT800 GPIO register for a read/modify/write operation ft800Gpio=ft800Gpio|0x80; // set bit 7 of FT800 GPIO register (DISP) - others are inputs ft800memWrite8(REG_GPIO, ft800Gpio); // Enable the DISP signal to the LCD panel ft800memWrite8(REG_PCLK, lcdPclk); // Now start clocking data to the LCD panel for(duty=0; duty<127; duty++){ ft800memWrite8(REG_PWM_DUTY,duty); // Turn on backlight - ramp up slowly to full brighness delay_ms(10); } printf("Koniec inicjalizacji\n"); initScreen(); }
int main(int argc, char **argv) { int ch; #ifndef SYM struct autocopt *copt; int32_t ret; copt = autocopt_init(AUTOCOPT_DEFAULT_DEV); if (copt == NULL) { return EXIT_FAILURE; } ret = autocopt_control(copt, &ctl); if (ret < 0) { mvwprintw(win, 0, 0, "can't send to copter"); } ret = autocopt_select(copt, AUTOCOPT_MODE_LINUX); if (ret < 0) { fprintf(stderr, "Can't select mode\n"); return EXIT_FAILURE; } #endif initscr(); height = 30; width = 30; starty = (LINES - height) / 2; startx = (COLS - width) / 2; initScreen(); timeout(100); while((ch = getch()) != 'z') { switch(ch) { case 'w': ctl.pitch += PITCH_STEPSIZE; if (ctl.pitch > 1.) { ctl.pitch = 1; } break; case 's': ctl.pitch -= PITCH_STEPSIZE; if (ctl.pitch < -1.) { ctl.pitch = -1; } break; case 'd': ctl.roll += ROLL_SETPSIZE; if (ctl.roll > 1.) { ctl.roll = 1; } break; case 'a': ctl.roll -= ROLL_SETPSIZE; if (ctl.roll < -1.) { ctl.roll = -1; } break; case 'q': ctl.yaw -= YAW_SETPSIZE; if (ctl.yaw < -1.) { ctl.yaw = -1; } break; case 'e': ctl.yaw += YAW_SETPSIZE; if (ctl.yaw > 1.) { ctl.yaw = 1; } break; case 'f': ctl.thrust -= THURST_STEPSIZE; if (ctl.thrust < -1) { ctl.thrust = -1; } break; case 'r': ctl.thrust += THURST_STEPSIZE; if (ctl.thrust > 1.) { ctl.thrust = 1; } break; case 't': ctl.roll = ctlSave.roll; ctl.pitch = ctlSave.pitch; ctl.yaw = ctlSave.yaw; break; case 'g': ctlSave.roll = ctl.roll; ctlSave.pitch = ctl.pitch; ctlSave.yaw = ctl.yaw; break; case 'z': break; case ERR: ctl.roll = 0; ctl.pitch = 0; ctl.yaw = 0; break; case 'c': ctl.thrust = -0.2; break; case 'x': ctl.thrust = -1; break; case '1': #ifndef SYM ret = autocopt_select(copt, AUTOCOPT_MODE_SPECTRUM); if (ret < 0) { mvwprintw(win, 0, 0, "Can't select mode\n"); } #endif break; case '2': #ifndef SYM ret = autocopt_select(copt, AUTOCOPT_MODE_LINUX); if (ret < 0) { mvwprintw(win, 0, 0, "Can't select mode\n"); } #endif break; case '3': #ifndef SYM ret = autocopt_select(copt, AUTOCOPT_MODE_LINUX_THRUST_ONLY); if (ret < 0) { mvwprintw(win, 0, 0, "Can't select mode\n"); } #endif break; case '4': #ifndef SYM ret = autocopt_select(copt, AUTOCOPT_MODE_LINUX_RPY_ONLY); if (ret < 0) { mvwprintw(win, 0, 0, "Can't select mode\n"); } #endif break; case 'y': #ifndef SYM ret = autocopt_emergencyLanding(copt); if (ret < 0) { mvwprintw(win, 0, 0, "Can't send emergency Landing\n"); } #endif break; default: mvwprintw(win, 0, 0, "err: %c", ch); break; } #ifndef SYM ret = autocopt_control(copt, &ctl); if (ret < 0) { mvwprintw(win, 0, 0, "can't send to copter"); } #endif updateWin(); } #ifndef SYM ret = autocopt_select(copt, AUTOCOPT_MODE_SPECTRUM); if (ret < 0) { fprintf(stderr, "Can't select mode\n"); return EXIT_FAILURE; } #endif endwin(); return EXIT_SUCCESS; }
int main (void) { Screen s; initScreen(&s); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { SDL_Surface *screen = NULL, *image = NULL, *scaledImage = NULL, *name = NULL; SDL_Rect picturePortion; TTF_Font *font = NULL; double scale = 1.0; int currentImageNumber = 1, showFileName = TRUE, runSlideShow = FALSE, isRunning = TRUE; SDL_TimerID slideShowTimer = 0; // Process command line if (argc < 2) { fprintf(stderr, "\n" " imgv v%s. Syntax: imgv <image files>\n\n" " Hotkeys:\n" " 'f' fit to screen\n" " 'z' zoom at pixel level\n" " 'i' zoom in 'o' zoom out\n" " 'l' rotate left 'r' rotate right\n" " 'n' next image 'p' previous image\n" " 'd' show / hide file name\n" " 's' start / stop slide show\n" " 'arrows' pan 'ESC' quit\n\n", VERSION); exit(0); } screen = initScreen(); font = TTF_OpenFont("font.ttf", 11); if (font == (TTF_Font *) (NULL)) { font = TTF_OpenFont("/usr/share/imgv/font.ttf", 11); } if (font == (TTF_Font *) (NULL)) { font = TTF_OpenFont("/usr/share/fonts/ttf-dejavu/DejaVuSans.ttf", 11); } picturePortion.w = SCREENWIDTH; picturePortion.h = SCREENHEIGHT; image = loadImage(argv[1]); if (image->w < SCREENWIDTH && image->h < SCREENHEIGHT) { scaledImage = zoom100(image, &picturePortion, &scale); } else { scaledImage = zoomFit(image, &picturePortion, &scale); } name = drawFileName(argv[currentImageNumber], font, runSlideShow); drawImage(scaledImage, &picturePortion, screen, name); do { SDL_Event event; if (SDL_WaitEvent(&event) && event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_LEFT: // PAN LEFT pan(scaledImage, &picturePortion, -PANSTEP, 0); break; case SDLK_RIGHT: // PAN RIGHT pan(scaledImage, &picturePortion, PANSTEP, 0); break; case SDLK_UP: // PAN UP pan(scaledImage, &picturePortion, 0, -PANSTEP); break; case SDLK_DOWN: // PAN DOWN pan(scaledImage, &picturePortion, 0, PANSTEP); break; case SDLK_i: // ZOOM IN SDL_FreeSurface(scaledImage); scaledImage = zoomIn(image, &picturePortion, &scale); break; case SDLK_o: // ZOOM OUT SDL_FreeSurface(scaledImage); scaledImage = zoomOut(image, &picturePortion, &scale); break; case SDLK_f: // ZOOM TO FIT SCREEN SDL_FreeSurface(scaledImage); scaledImage = zoomFit(image, &picturePortion, &scale); break; case SDLK_z: // ZOOM TO ORIGINAL SIZE SDL_FreeSurface(scaledImage); scaledImage = zoom100(image, &picturePortion, &scale); break; case SDLK_l: // ROTATE LEFT { SDL_FreeSurface(scaledImage); SDL_Surface *tmp = rotateSurface90Degrees(image, 3); SDL_FreeSurface(image); image = tmp; scaledImage = zoomSurface(image, scale, scale, SMOOTHING_ON); int x = picturePortion.x; picturePortion.x = picturePortion.y + SCREENHEIGHT/2 - SCREENWIDTH/2; picturePortion.y = scaledImage->h - x - SCREENHEIGHT/2 - SCREENWIDTH/2; pan(scaledImage, &picturePortion, 0, 0); } break; case SDLK_r: // ROTATE RIGHT { SDL_FreeSurface(scaledImage); SDL_Surface *tmp = rotateSurface90Degrees(image, 1); SDL_FreeSurface(image); image = tmp; scaledImage = zoomSurface(image, scale, scale, SMOOTHING_ON); int x = picturePortion.x; picturePortion.x = scaledImage->w - picturePortion.y - SCREENWIDTH/2 - SCREENHEIGHT/2; picturePortion.y = x + SCREENWIDTH/2 - SCREENHEIGHT/2; pan(scaledImage, &picturePortion, 0, 0); } break; case SDLK_n: // NEXT IMAGE if (currentImageNumber < argc-1) { ++currentImageNumber; SDL_FreeSurface(image); SDL_FreeSurface(scaledImage); SDL_FreeSurface(name); image = loadImage(argv[currentImageNumber]); if (image->w < SCREENWIDTH && image->h < SCREENHEIGHT) { scaledImage = zoom100(image, &picturePortion, &scale); } else { scaledImage = zoomFit(image, &picturePortion, &scale); } name = drawFileName(argv[currentImageNumber], font, runSlideShow); } else { if (runSlideShow) { SDL_RemoveTimer(slideShowTimer); runSlideShow = FALSE; name = drawFileName(argv[currentImageNumber], font, runSlideShow); } } break; case SDLK_p: // PREVIOUS IMAGE if (currentImageNumber > 1) { --currentImageNumber; SDL_FreeSurface(image); SDL_FreeSurface(scaledImage); SDL_FreeSurface(name); image = loadImage(argv[currentImageNumber]); if (image->w < SCREENWIDTH && image->h < SCREENHEIGHT) { scaledImage = zoom100(image, &picturePortion, &scale); } else { scaledImage = zoomFit(image, &picturePortion, &scale); } name = drawFileName(argv[currentImageNumber], font, runSlideShow); } break; case SDLK_s: // START / STOP SLIDESHOW runSlideShow = 1 - runSlideShow; name = drawFileName(argv[currentImageNumber], font, runSlideShow); if (runSlideShow) { slideShowTimer = SDL_AddTimer(SLIDESHOWTIMEOUT, timerCallback, NULL); } else { SDL_RemoveTimer(slideShowTimer); } break; case SDLK_d: // SHOW / HIDE FILENAME showFileName = 1 - showFileName; break; case SDLK_ESCAPE: // QUIT case SDLK_q: isRunning = FALSE; break; default: break; } // end of switch (event.key.keysym.sym) } // end of if(SDL_WaitEvent()) drawImage(scaledImage, &picturePortion, screen, showFileName ? name : 0); } while(isRunning); // end of do SDL_FreeSurface(image); SDL_FreeSurface(scaledImage); SDL_FreeSurface(screen); TTF_CloseFont(font); TTF_Quit(); SDL_Quit(); return 0; }
NoRSX::NoRSX(int real_screen_type, int buffer_screen_type) : EventHandler(){ screen_type = real_screen_type; buffer_type = buffer_screen_type; currentBuffer = 0; host_addr = memalign(1024*1024, HOST_SIZE); switch(real_screen_type){ case RESOLUTION_1920x1080: { width=1920;height=1080; buffers[0].width=1920;buffers[0].height=1080; buffers[1].width=1920;buffers[1].height=1080; } break; case RESOLUTION_1280x720: { width=1280;height=720; buffers[0].width=1280;buffers[0].height=720; buffers[1].width=1280;buffers[1].height=720; } break; case RESOLUTION_720x576: { width=720;height=576; buffers[0].width=720;buffers[0].height=576; buffers[1].width=720;buffers[1].height=576; } break; case RESOLUTION_720x480: { width=720;height=480; buffers[0].width=720;buffers[0].height=480; buffers[1].width=720;buffers[1].height=480; } break; default: getResolution(&width,&height); switch(real_screen_type){ default: case RESOLUTION_AUTO_LOWER_1080p: { if(height>=1080){ real_screen_type = RESOLUTION_1280x720; width=1280;height=720; buffers[0].width=1280;buffers[0].height=720; buffers[1].width=1280;buffers[1].height=720; }else real_screen_type = RESOLUTION_AUTO; } break; case RESOLUTION_AUTO_LOWER_720p: { if(height>=720){ real_screen_type = RESOLUTION_720x576; width=720;height=576; buffers[0].width=720;buffers[0].height=576; buffers[1].width=720;buffers[1].height=576; }else real_screen_type = RESOLUTION_AUTO; } break; case RESOLUTION_AUTO_LOWER_576p: { if(height>=576){ real_screen_type = RESOLUTION_720x480; width=720;height=480; buffers[0].width=720;buffers[0].height=480; buffers[1].width=720;buffers[1].height=480; }else real_screen_type = RESOLUTION_AUTO; } break; real_screen_type = RESOLUTION_AUTO; break; } break; } context = initScreen(host_addr, HOST_SIZE, real_screen_type, width, height); for(int i=0;i<2;i++) makeBuffer(&buffers[i],width,height,i); switch(buffer_screen_type){ case RESOLUTION_1920x1080: width=1920; height=1080; break; case RESOLUTION_1280x720: width=1280; height=720; break; case RESOLUTION_720x576: width=720; height=576; break; case RESOLUTION_720x480: width=720; height=480; break; default: getResolution(&width,&height); break; } buffer = makeMemBuffer(width,height,&buffer_size); buffer_size = buffers[0].width * buffers[0].height * sizeof(u32); flip(context, 0); setRenderTarget(context, &buffers[0]); RegisterCallBack(EVENT_SLOT0); }
int main(int argc, const char **argv) { // Instantiate a ModelManager: ModelManager manager("Navbot Controller"); navBot = nub::soft_ref<NavBot>(new NavBot(manager)); manager.addSubComponent(navBot); // catch signals and redirect them to terminate for clean exit: signal(SIGHUP, terminate); signal(SIGINT, terminate); signal(SIGQUIT, terminate); signal(SIGTERM, terminate); signal(SIGALRM, terminate); initScreen(); // Parse command-line: if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); // let's get all our ModelComponent instances started: manager.start(); LINFO("Starting NavBot"); int key = getKey(); int speed = 30; while(key != 'Q') { switch (key) { case KEY_UP: mvprintw(0,0,"Moving forward speed %i R:(%i:%i)\n", speed, navBot->setMotor(NavBot::LEFT_WHEEL, speed), navBot->setMotor(NavBot::RIGHT_WHEEL, speed)); break; case KEY_DOWN: mvprintw(0,0,"Moving Back speed %i R:(%i,%i)\n", speed, navBot->setMotor(NavBot::LEFT_WHEEL, -1*speed), navBot->setMotor(NavBot::RIGHT_WHEEL, -1*speed)); break; case KEY_LEFT: mvprintw(0,0,"Moving Left speed %i R:(%i,%i)\n", speed, navBot->setMotor(NavBot::LEFT_WHEEL, speed), navBot->setMotor(NavBot::RIGHT_WHEEL, -1*speed)); break; case KEY_RIGHT: mvprintw(0,0,"Moving Right speed %i R:(%i,%i)\n", speed, navBot->setMotor(NavBot::LEFT_WHEEL, -1*speed), navBot->setMotor(NavBot::RIGHT_WHEEL, speed)); break; case ' ': mvprintw(0,0,"Stop!! %i\n", navBot->stopAllMotors()); break; case 'b': mvprintw(1,0,"Battery voltage %0.2f\n", navBot->getBatteryVoltage()); break; case '+': speed += 5; mvprintw(0,0,"Speed %i\n", speed); break; case '-': speed -= 5; mvprintw(0,0,"Speed %i\n", speed); break; } key = getKey(); } // stop all our ModelComponents manager.stop(); // all done! return 0; }
SelectStage::SelectStage() : _winSize(Director::getInstance()->getWinSize()) { // Sprite Sheet // SpriteFrameCache::getInstance()->addSpriteFramesWithFile(SELECT_STAGE_PLIST); // init screen // initScreen(); // motion streak // _motionStreak = MotionStreak::create(3.0, 1.0f, 50.0f, Color3B::YELLOW, "ball.png"); addChild(_motionStreak); // listen touches auto dispatcher = Director::getInstance()->getEventDispatcher(); auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = [] (const vector<Touch *> & touches, Event * event) {}; listener->onTouchesEnded = [] (const vector<Touch *> & touches, Event * event) {}; dispatcher->addEventListenerWithSceneGraphPriority(listener, this); setTouchesEnabled(true); // time // time_t cl; // time(&cl); // printf("%ld: %ld", cl, time(NULL)); time_t timeValue; struct tm * timeObject; time(&timeValue); timeObject = localtime(&timeValue); printf("%d年%d月%d日 %d:%d", timeObject->tm_year + 1900 , timeObject->tm_mon + 1 , timeObject->tm_mday, timeObject->tm_hour, timeObject->tm_min); // char hour[100] = {static_cast<char>(timeObject->tm_hour)}; // char min[100] = {static_cast<char>(timeObject->tm_min)}; char hour = static_cast<char>(timeObject->tm_hour); char min = static_cast<char>(timeObject->tm_min); CCLOG("%c:%c", hour,min); printf("%c:%c", hour,min); int iHour = timeObject->tm_hour; unsigned char cHour = 0; cHour = iHour; // auto * get_hour = LabelTTF::create(asctime(timeObject->tm_hour), "Hevetica-BoldOblique", 20); auto * time = LabelTTF::create(asctime(timeObject) , "Hevetica-BoldOblique", 20); // auto * get_hour = LabelTTF::create(hour, "Hevetica-BoldOblique", 20); // auto * get_time = LabelTTF::create(min, "Hevetica-BoldOblique", 20); // // get_hour->setPosition(Point(_winSize.width * 0.45f, _winSize.height * 0.9f)); // get_time->setPosition(Point(_winSize.width * 0.55f, _winSize.height * 0.9f)); // addChild(get_hour, kForeground, 1); // addChild(get_time, kForeground, 1); time->setPosition(Point(_winSize.width / 2, _winSize.height * 0.9f)); addChild(time, kForeground, 1); _motionStreak = MotionStreak::create(3.0, 1.0f,50.0f, Color3B::YELLOW, "ball.png"); addChild(_motionStreak, kForeground); // Update scheduleUpdate(); }
int main(s32 argc, const char* argv[]) { //Mutex. sys_mutex_attr_t attr; memset(&attr, 0, sizeof(attr)); attr.attr_protocol = SYS_MUTEX_PROTOCOL_FIFO; attr.attr_recursive = SYS_MUTEX_ATTR_NOT_RECURSIVE; attr.attr_pshared = SYS_MUTEX_ATTR_PSHARED; attr.attr_adaptive = SYS_MUTEX_ATTR_NOT_ADAPTIVE; strcpy(attr.name, "mutex"); sysMutexCreate(&thread_mutex, &attr); //Threads. THREADS_RUNNING = 2; sys_ppu_thread_t pad_id, program_id; sysThreadCreate(&pad_id, pad_thread, (void*) &GLOBAL_EXIT, 1500, 0x400, 0, "pad"); sysThreadCreate(&program_id, program_thread, (void*) &GLOBAL_EXIT, 1337, 0x400, 0, "program"); //Create buffers. gcmContextData *context; void *host_addr = NULL; rsxBuffer buffers[MAX_BUFFERS]; int currentBuffer = 0; //Allocate a 1Mb buffer, alligned to a 1Mb boundary to be our shared IO memory with the RSX. host_addr = memalign(1024*1024, HOST_SIZE); context = initScreen(host_addr, HOST_SIZE); //Get resolution. u16 width, height; getResolution(&width, &height); //Create buffers. int i; for(i = 0; i < MAX_BUFFERS; i++) { makeBuffer(&buffers[i], width, height, i); } flip(context, MAX_BUFFERS - 1); //Main loop. while(THREADS_RUNNING > 0) { //Prepare buffer. setRenderTarget(context, &buffers[currentBuffer]); waitFlip(); //Flip buffer onto screen. flip(context, buffers[currentBuffer].id); //Change buffer. currentBuffer++; if(currentBuffer >= MAX_BUFFERS) { currentBuffer = 0; } } //Free buffers. gcmSetWaitFlip(context); for(i = 0; i < MAX_BUFFERS; i++) { rsxFree(buffers[i].ptr); } rsxFinish(context, 1); free(host_addr); //Mutex destroy. sysMutexDestroy(thread_mutex); return 0; }
/* Main Function */ int main( int argc, char *argv[] ) { //Color constants' initilizations BLACK = makeColour( 0, 0, 0 ); WHITE = makeColour(63,63,63 ); RED = makeColour(63, 0, 0 ); GREEN = makeColour( 0,63, 0 ); BLUE = makeColour( 0, 0,63 ); //Initializations initInterrupts(); initScreen(); initChars(); //Enable Interrupts enableBalloonIRQ(1000*ONE_MS, balloonISR ); int keys_to_watch = 0x04 | 0x02 ; enableKeyIRQ( keys_to_watch, keyISR ); // fillScreen(BLACK); int i = 0; welcomeMessage(); mouse_status = resetPS2(); int left, right; int lastTime; while(1) { //in case of losing (past 20 misses) if(missed >= MAX_MISS) { disableInterrupt(IRQ_COUNTER); fillScreen(RED); emptyScreen(); printStr(10, 10, "Too many misses..."); printStr(14, 13, "GAME OVER!"); printStr(8, 16, "Press KEY2 to restart"); for(i = 0; i < 30000000; i++); // while(missed >= 20); // printStr(8, 20, "HOOOOOORAY"); enableInterrupt(IRQ_COUNTER); printStr(10, 10, " "); printStr(14, 13, " "); printStr(8, 16, " "); } drawChar (1, 6, ' '); disableInterrupt(IRQ_COUNTER); if (*pSWITCH != 0) { if (*pSWITCH&1) { increment = 1; circleRad = 30; } else if (*pSWITCH&2) { increment = 2; circleRad = 20; } else if (*pSWITCH&4) { increment = 3; circleRad = 15; } } else { increment = 1; circleRad = 30; } enableInterrupt(IRQ_COUNTER); /// MUSIC PLAYER /// // drawChar (1, 5, 16); if(musicCounter == 0) { left = 0; right = 1; } if(musicCounter < musicLength/4) { i = musicCounter; for(i; i<musicCounter+200; i++) { playMusic(music[left], music[right]); left+=2; right+=2; } musicCounter += 200; } else { musicCounter = 0; left = 0; right = 1; } /// MUSIC /// if ( mouse_status == PS2_MOUSE ) { // drawChar (1, 5, 22); if( getMouseMotion( &dxMouse, &dyMouse, &mouse_button ) ) { if( mouse_button & MOUSE_BUTTON1 ) { if(getColor(xMouse+1, yMouse) == RED) { score += increment; drawCircle(xCircle, yCircle, 30, BLACK); /// SOUND EFFECT /// int sleft = 0; int sright = 1; int i; for(i=0; i<effectLength/4; i++) { playMusic(effect[sleft], effect[sright]); sleft+=2; sright+=2; } sleft = 0; sright = 1; /// SOUND EFFECT /// } else { if(time != lastTime) { missed++; time = lastTime; } } } /* if( mouse_button & MOUSE_BUTTON2 ) fillScreen( BLACK ); if( mouse_button & MOUSE_BUTTON3 ) { printStr(17, 13, "PAUSED!"); disableInterrupts(IRQ_COUNTER); while( 1 ) { if( mouse_button & MOUSE_BUTTON2 ) { enableInterrupts(IRQ_COUNTER); printStr(17, 13, " "); break; } } } */ if(getColor(xMouse+1, yMouse) == RED) dragColor = RED; else dragColor = BLACK; drawPixel( xMouse, yMouse, dragColor ); xMouse += dxMouse; yMouse -= dyMouse; xMouse = max( 0, min( xMouse, MAX_X_PIXELS-1 ) ); yMouse = max( 0, min( yMouse, MAX_Y_PIXELS-1 ) ); drawPixel( xMouse, yMouse, WHITE ); //drawCursor(xMouse, yMouse); } } } return 0; }
int main(void) { while (1) { state = 0; int setTime = 15; numPlayers = 2; initScreen(); clearScreen(); initCharBuffer(); clean_up(); initKeyboard(); initState0(); initAI(); //Bypass the menu system for testing if (IORD(keys,0) == 8) { initPlayer(pOne, MARIO, "pOne", 50, 100, HUMAN); initPlayer(pTwo, LUIGI, "pTwo", 50, 100, COMPUTER); state = 2; } else { while (state == 0) { decode_scancode(ps2, &decode_mode, buf, &ascii); state_0(decode_mode, buf[0]); }; initState1(pOne); if(aOn)file_handle = initAudio(fname); if(aOn)alt_irq_register(AUDIO_0_IRQ, &ab, (alt_isr_func) write_fifo); if(aOn) alt_up_audio_enable_write_interrupt(ab->audio); while (state == 1) { decode_scancode(ps2, &decode_mode, buf, &ascii); state_1(decode_mode, buf[0], ascii); if(aOn)loop_audio(file_handle, fname, ab); }; } //clean_up(); clearCharBuffer(); clearScreen(); //enable keyboard IRQ void* keyboard_control_register_ptr = (void*) (KEYBOARD_BASE + 4); alt_irq_register(KEYBOARD_IRQ, keyboard_control_register_ptr, keyboard_ISR); alt_up_ps2_enable_read_interrupt(ps2); //Draw field and UI to both buffers initField(); updateField(); drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name); drawGas(p[pOne].gas); drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp); drawBullet(p[pOne].bulletType); //drawWindIndicator(1); updateScreen(); updateField(); drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name); drawGas(p[pOne].gas); drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp); drawBullet(p[pOne].bulletType); //drawWindIndicator(1); float time; alt_timestamp_start(); int start_timer_flag = 1; //printf("NUM PLAYERA %i\n", numPlayers); int i; while (state == 2) { int fallFlag = 1; //Checks to see if any players are falling while (fallFlag == 1) { fallFlag = 0; for (i = 0; i < numPlayers; i++) { if (p[i].alive) { if (p[i].y + TANK_HEIGHT >= SCREEN_HEIGHT-1) { p[i].hp = 0; p[i].alive = DEAD; } checkPlayerFalling(i); if (p[i].isFalling) { undrawPlayer(i); updatePlayer(i); fallFlag = 1; } } } if (fallFlag == 1) { updateScreen(); } } if(start_timer_flag){ start_time = (float) alt_timestamp() / (float) alt_timestamp_freq(); start_timer_flag = 0; } time = (float) alt_timestamp() / (float) alt_timestamp_freq()-start_time; if (time >= setTime) { setPlayerTurn(); } if (p[turn].type == HUMAN) { runGame(); } else { p[turn].deg = 0; aiMain(turn); setPlayerTurn(); } printTimer(setTime - time); int deadCount = 0; for (i = 0; i < numPlayers; i++) { if (p[i].alive == DEAD) deadCount++; } if (deadCount == numPlayers - 1) { usleep(500000); state = 3; } } alt_up_ps2_disable_read_interrupt(ps2); if(aOn)alt_up_audio_disable_write_interrupt(ab->audio); GameOverScreen(); } }
int main (s32 argc, const char* argv[]) { gcmContextData *context; void *host_addr = NULL; rsxBuffer buffers[MAX_BUFFERS]; int currentBuffer = 0; padInfo padinfo; padData paddata; u16 width; u16 height; int frame = 0; int i; /* Allocate a 1Mb buffer, alligned to a 1Mb boundary * to be our shared IO memory with the RSX. */ host_addr = memalign (1024*1024, HOST_SIZE); context = initScreen (host_addr, HOST_SIZE); ioPadInit (7); getResolution(&width, &height); for (i = 0; i < MAX_BUFFERS; i++) makeBuffer (&buffers[i], width, height, i); flip(context, MAX_BUFFERS - 1); DEBUG ("Starting Cairo test\n"); while (1) { ioPadGetInfo (&padinfo); for(i = 0; i < MAX_PADS; i++) { if(padinfo.status[i]) { ioPadGetData (i, &paddata); if(paddata.BTN_START) { goto end; } } } setRenderTarget(context, &buffers[currentBuffer]); DEBUG ("Drawing frame %d\n", frame); waitFlip (); drawFrame (&buffers[currentBuffer], frame++); /* Draw into the unused buffer */ flip (context, buffers[currentBuffer].id); /* Flip buffer onto screen */ currentBuffer++; if (currentBuffer >= MAX_BUFFERS) currentBuffer = 0; } end: gcmSetWaitFlip(context); for (i = 0; i < MAX_BUFFERS; i++) rsxFree (buffers[i].ptr); rsxFinish (context, 1); free (host_addr); ioPadEnd(); return 0; }