예제 #1
0
static void cpu_updatecallback(int param)
{
	/* update the screen if we didn't before */
	if (Machine->drv->video_attributes & VIDEO_UPDATE_AFTER_VBLANK)
		time_to_quit = updatescreen();
	vblank = 0;

	/* update IPT_VBLANK input ports */
	inputport_vblank_end();

	/* reset partial updating */
	reset_partial_updates();

	/* check the watchdog */
	if (watchdog_counter > 0)
		if (--watchdog_counter == 0)
		{
			logerror("reset caused by the watchdog\n");
			machine_reset();
		}

	/* track total frames */
	current_frame++;

	/* reset the refresh timer */
	timer_adjust(refresh_timer, TIME_NEVER, 0, 0);
}
예제 #2
0
void 
GameSession::draw()
{
  world->draw();
  drawstatus();

  if(game_pause)
    {
      int x = screen->h / 20;
      for(int i = 0; i < x; ++i)
        {
          fillrect(i % 2 ? (pause_menu_frame * i)%screen->w : -((pause_menu_frame * i)%screen->w) ,(i*20+pause_menu_frame)%screen->h,screen->w,10,20,20,20, rand() % 20 + 1);
        }
      fillrect(0,0,screen->w,screen->h,rand() % 50, rand() % 50, rand() % 50, 128);
      blue_text->drawf("PAUSE - Press 'P' To Play", 0, 230, A_HMIDDLE, A_TOP, 1);
    }

  if(Menu::current())
    {
      Menu::current()->draw();
      mouse_cursor->draw();
    }

  updatescreen();
}
예제 #3
0
static void cpu_vblankcallback(int param)
{
	int cpunum;

   if (vblank_countdown == 1)
      vblank = 1;

	/* loop over CPUs */
	for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++)
	{
		/* if the interrupt multiplier is valid */
		if (cpu[cpunum].vblankint_multiplier != -1)
		{
			/* decrement; if we hit zero, generate the interrupt and reset the countdown */
			if (!--cpu[cpunum].vblankint_countdown)
			{
				/* a param of -1 means don't call any callbacks */
				if (param != -1)
				{
					/* if the CPU has a VBLANK handler, call it */
					if (Machine->drv->cpu[cpunum].vblank_interrupt && cpu_getstatus(cpunum))
					{
						cpuintrf_push_context(cpunum);
						(*Machine->drv->cpu[cpunum].vblank_interrupt)();
						cpuintrf_pop_context();
					}

					/* update the counters */
					cpu[cpunum].iloops--;
				}

				/* reset the countdown and timer */
				cpu[cpunum].vblankint_countdown = cpu[cpunum].vblankint_multiplier;
				timer_adjust(cpu[cpunum].vblankint_timer, TIME_NEVER, 0, 0);
			}
		}

		/* else reset the VBLANK timer if this is going to be a real VBLANK */
		else if (vblank_countdown == 1)
			timer_adjust(cpu[cpunum].vblankint_timer, TIME_NEVER, 0, 0);
	}

	/* is it a real VBLANK? */
	if (!--vblank_countdown)
	{
		/* do we update the screen now? */
		if (!(Machine->drv->video_attributes & VIDEO_UPDATE_AFTER_VBLANK))
			time_to_quit = updatescreen();

		/* Set the timer to update the screen */
		timer_set(TIME_IN_USEC(Machine->drv->vblank_duration), 0, cpu_updatecallback);

		/* reset the globals */
		cpu_vblankreset();

		/* reset the counter */
		vblank_countdown = vblank_multiplier;
	}
}
예제 #4
0
파일: screen.c 프로젝트: kindy/vim0
/*
 * updateline() - update the line the cursor is on
 *
 * Updateline() is called after changes that only affect the line that
 * the cursor is on. This improves performance tremendously for normal
 * insert mode operation. The only thing we have to watch for is when
 * the cursor line grows or shrinks around a row boundary. This means
 * we have to repaint other parts of the screen appropriately. If
 * lfiletonext() returns FALSE, the size of the cursor line (in rows)
 * has changed and we have to call updatescreen() to do a complete job.
 */
void
updateline()
{
        if (!lfiletonext())
                updatescreen();                /* bag it, do the whole screen */
        else
                lnexttoscreen();
}
예제 #5
0
HRESULT  __stdcall myIDDraw2::WaitForVerticalBlank(DWORD a, HANDLE b)
{
	logf("myIDDraw2::WaitForVerticalBlank(%d,%d)",a,b);

	updatescreen();

	return NOERROR;
}
예제 #6
0
파일: gui.c 프로젝트: FliPPeh/dcpu16tools
void updategui(dcpu16 *cpu) {
    mvprintw(0, 0, "dcpu16emu");
    mvhline(1, 0, ACS_BULLET, 10);


    updatescreen(cpu);
    updatestatus(cpu);
}
예제 #7
0
파일: menu.cpp 프로젝트: kerheol/uae4all
void text_flip(void)
{
	if(prSDLScreen == NULL){
		prSDLScreen = SDL_GetVideoSurface();
	}
	SDL_Delay(10);
	SDL_BlitSurface(text_screen,NULL,prSDLScreen,NULL);
	updatescreen( prSDLScreen, 0, 0, 0, 0 );
}
예제 #8
0
void screenMessage(char *message)
  {
  static int preHoldThisScreen = TRANSITION_IDLE;
  
  if (*message != '\0') // Setting a message
    {
    updatescreen(-1,""); //Blank
    layer_set_bounds(inverter_layer_get_layer(inverter), GRect(0,0,0,0)); // Turn off the inverter layer
    preHoldThisScreen = holdThisScreen; // Remember what it was
    holdThisScreen = -1;
    messageClick = true;
    text_layer_set_text(messageLayer, message);
  }
  else //Clearing a message
    {
    messageClick = false;
    holdThisScreen = preHoldThisScreen; // Restore it to what it was
    text_layer_set_text(messageLayer,"");  
    updatescreen(currentScreen, "");
  }
  
}
예제 #9
0
//
// Handle incoming messages from phone
//
void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Store incoming information
  static char *layDecode[] = {"SPN", "SCB", "SMD",NULL,NULL,NULL,NULL,NULL,NULL,NULL,"PPN","PCB","PMD","PPN","PCB","PMD"};
  static int tackLog[7] = {0,0,0,0,0,0,0};
  static bool warnedLineBurn = false;
  static int currentState = -1;
  static int thisTack = 0, oldTack = 0;
  int angle;
  bool earlyWarnDone = false;
  bool weAreRacing = false;
  bool doScreenTransition;
  #ifdef PBL_COLOR
  bool redAWA, highVMG;
  #endif
  int j, tmp, ii;
  bool foundKey, negNum; 
  #ifdef CONFIG_SUPPORT
  bool foundAKey = false; // Did we find any data keys in the message?
  #endif
  int startingScreen; // To remember which screen we were at when we arrived here so we don't loop forever looking for a screen with data on it
  int a;
  float b;
  static int flashFlag = 0;
  char *sa, *sb;
  bool fieldUpdated[6];
  bool canDoVMG;
  int twd, bs, hdg;
  #ifdef CONFIG_SUPPORT
    bool receivedConfig = false;
  #endif
  
  if (doubleClick || messageClick)
    return; // Get out of here if we are displaying a message - note - we may miss a tack because of this, but unlikely!!
  startingScreen = currentScreen;
#ifdef PBL_COLOR
  text_layer_set_background_color(flash, flashFlag == 0 ? GColorGreen : GColorClear);
#else
  layer_set_bounds(inverter_layer_get_layer(flash), flashFlag == 0 ? GRectZero : GRect(0,0,7,7)); 
#endif
  flashFlag = 1 - flashFlag;
  if (holdThisScreen > 0)
    holdThisScreen--;
  
  weAreRacing = false; // Assume we're not racing unless we receive a mark name
  do
    {
    for (ii = 0; ii < screens[currentScreen].num_fields; ii++) {
      fieldUpdated[ii] = false;
    }
    canDoVMG = false;
    #ifdef PBL_COLOR
    redAWA = false;
    highVMG = false;
    #endif
    doScreenTransition = false;
    weAreRacing = false;
    // Read first item
    Tuple *t = dict_read_first(iterator);
    j = 0;
    while(t != NULL) {
    foundKey = true;
    char *bj;
    bj = buffer[j];
    // Which key was received?
    //APP_LOG(APP_LOG_LEVEL_INFO, "Key %d Value %d", (int)t->key, (int)t->value->int32);
    switch(t->key) {
      
      case KEY_LINE_BURN:      
      case KEY_LAY_TIME:
      case KEY_LINE_TIME:
      case KEY_SECS_TO_START:
      case KEY_LAY_BURN:
      case KEY_TIME_TO_MARK:
      negNum = false;    
      tmp = abs((int)t->value->int32) ;
      negNum = ((int)t->value->int32 < 0);

      if (tmp >= 100)
      {
        if ((tmp < 6000 && isBigField(t->key)) || tmp < 600) // We have room for mins & seconds & always when mins < 10
        {
          snprintf(bj, sizeof(buffer[0]),"%d:%02d", tmp / 60, tmp % 60);
        }
        else if (tmp < 3600)
        {
          snprintf(bj, sizeof(buffer[0]),"%dm", tmp / 60 + ((tmp % 60) >= 30 ? 1:0));
        }
        else
          {
          snprintf(bj, sizeof(buffer[0]),"%dh", tmp / 3600 + ((tmp % 3600) >= 1800 ? 1:0));          
        }
      }
      else // (tmp < 100)
      {
        snprintf(bj, sizeof(buffer[0]),"%ds", tmp);
      }
      break;

      case KEY_LAST_TACK:
      oldTack = thisTack; // Remember the tack from the last message 
      thisTack = (int)t->value->int32;
      negNum = false; // This definitely shouldn't happen!
      if (currentState != 1)
        bj[0] = '\0';
      else
        snprintf(bj, sizeof(buffer[0]),"%d", abs((int)t->value->int32));
      break;
      
      case KEY_TARGET_TACK:
      negNum = false;
      snprintf(bj, sizeof(buffer[0]),"%d", abs((int)t->value->int32));
      
      case KEY_TWD:
      if (t->key == KEY_TWD) {
        canDoVMG = true;
        twd = t->value->int32;
      }
      case KEY_LAY_DIST:
      case KEY_LINE_DIST:

      case KEY_TARGET_ANGLE:
      case KEY_MARK_BEARING:
      case KEY_HEADING_COG:
      case KEY_HEADING:
      if (t->key == KEY_HEADING)
        hdg = t->value->int32;
      case KEY_AWS:

      case KEY_TWS:
      case KEY_DEPTH:
      case KEY_HEEL:
      case KEY_CURRENT_DIR:
      negNum = ((int)t->value->int32 < 0);
      snprintf(bj, sizeof(buffer[0]),"%d", abs((int)t->value->int32));
      break;
 
      case KEY_TWA:
      case KEY_AWA:
      negNum = false;
      angle = (int)t->value->int32;
      #ifdef PBL_COLOR
      redAWA = angle > 180;
      if (colourAWA) {
              snprintf(bj, sizeof(buffer[0]),"%d", angle <= 180 ? angle : abs(angle - 360));
      } else {
              snprintf(bj, sizeof(buffer[0]),"%d%s", angle <= 180 ? angle : abs(angle - 360), angle <= 180 ? "S":"P");
      }
      #else
      snprintf(bj, sizeof(buffer[0]),"%d%s", angle <= 180 ? angle : abs(angle - 360), angle <= 180 ? "S":"P");
      #endif
      break;
      
      case KEY_BOAT_SOG:
      case KEY_BOAT_SPEED:
      if (t->key == KEY_BOAT_SPEED)
        bs = t->value->int32;
      case KEY_TARGET_SPEED: 
      case KEY_CURRENT_SPEED:
      snprintf(bj, sizeof(buffer[0]),"%d.%d", abs((int)t->value->int32)/10, abs((int)t->value->int32) % 10);
      negNum = ((int)t->value->int32 < 0);
      break;
      
      case KEY_LINE_ANGLE: // If this is negative, we will be over the line early - red burn time
      a = t->value->int32;
      #ifdef PBL_COLOR
      highVMG = (a < 0);
      #endif
      a = abs(a);
      negNum = false;
      snprintf(bj, sizeof(buffer[0]),"%d", a);
      break;
      
      case KEY_MARK_DIST:
      case KEY_MARK_LAY_DIST:
      negNum = false;
      if (currentState != 1  && t->key == KEY_MARK_LAY_DIST)
        bj[0] = '\000';
      else
        {
        a = (int)t->value->int32;
        negNum = (a < 0);
        a = abs(a);
        b = a / 18.52;
        bool bf = isBigField((int)t->key);
        if (a < 1000) // Less than 1000m - just show m
          snprintf(bj, sizeof(buffer[0]), "%d", a);
        else if (b < 1000 || bf) // less than 100nm or it's a big field - show nm.n
          {
          int d1, d2, d3;
          d1 = (int)b/100;
          d2 = (((int)b % 100)/10);
          d3 = ((((int)b % 10) > 4) ? 1 : 0);
          if (d3 == 1)
            d2 += 1;
          if (d2 == 10)
            {
            d1 += 1;
            d2 = 0;
          }
          snprintf(bj, sizeof(buffer[0]), "%d.%d", d1, d2);
        }
        else
            {
            snprintf(bj, sizeof(buffer[0]), "%d", (int)b/10);
        }
      }
      break;
      
      case KEY_LAY_SEL:
      //APP_LOG(APP_LOG_LEVEL_INFO, "Key %d Value %d", (int)t->key, (int)t->value->int32);
      negNum = false;
      snprintf(bj, sizeof(buffer[0]),"%s", layDecode[(int)t->value->int32]);
      break;
      
      /* These are the turn style values - Rnn & Lnn */
      case KEY_MARK_TURN:
      case KEY_TACK_HEADER:
      negNum = false;
      if (currentState != 1 && t-> key == KEY_TACK_HEADER)
        bj[0] = '\000';
      else
        {
//        if (t->value->int32 >= 0)
          snprintf(bj, sizeof(buffer[0]), "%c%02d", t->value->int32 >= 0 ? 'R' : 'L', abs((int)t->value->int32));
//        else
//          snprintf(buffer[j], sizeof(buffer[j]), "L%02d", -(int)(t->value->int32));
      }
      break;
      
      case KEY_CURRENT_MARK:
      weAreRacing = true; //This data only arrives once the start is over, we must be racing
      negNum = false;
      sa = t->value->cstring;
      sb = tmpbuf;
             // APP_LOG(APP_LOG_LEVEL_ERROR, "Mark->%s", sa);
      while (*sa != '\000') {
        *sb = *sa; // Copy the current char
        if (*sb == ':' && *(sa+1) == ':') { // Found :: don't increment b so we ignore the extra :
          sa++;
          continue;
        }
        else if (*sb == ':' && *(sa+1) == '\000') { // End of string coming up & last char was : - don't increment b - it will be zapped
          sa++;
          continue;
        }
        else {
          sa++;
          sb++;
        }
      }
      *sb = '\000';
      snprintf(bj, sizeof(buffer[0]), "%s", tmpbuf);
      break;
      
      case KEY_TACK_STATE:
      a = (int)t->value->int32;
      negNum = a < 0;
      snprintf(bj, sizeof(buffer[0]), "%d", abs((int)(t->value->int32)));
      if (currentState == 1 && a != 1) // Just detected a tack
        {
        tackLog[0] = oldTack;
        int i;
        for (i = 6; i > 0; i--) // Shuffle them all up one
          tackLog[i] = tackLog[i-1];
      }
      currentState = a;
      // Now display the log
      int k = 1; // Start the log at 1 - 0 is the current tack ready to be shuffled up
      int i = 0;
      for (i=0; i < screens[currentScreen].num_fields; i++) // Go look for TACK LOG on the screen
      {
        if (keyTitles[screens[currentScreen].field_data_map[i]].key == KEY_TACK_LOG) // Tack Log is displayed
        {
          if (tackLog[k] == 0)
            tackLogBuffer[k][0] = '\000';
          else
            snprintf(tackLogBuffer[k], sizeof(tackLogBuffer[0]), "%d", tackLog[k]);
          setField(i, false, tackLogBuffer[k]);
          fieldUpdated[i] = true;
          k++; // Step to the next tacklog entry
        }
      }
      break;
      #ifdef CONFIG_SUPPORT
      case KEY_CONFIG_BOLD: useBold = (t->value->int32 != 0);
      foundKey = false;
      receivedConfig = true;
      break;
      
      case KEY_CONFIG_RACEBOX: racebox = t->value->int32;
      foundKey = false;
      receivedConfig = true;
      break;
      
      case KEY_CONFIG_VIBEDISCONNECT: vibeDisconnect = t->value->int32;
      foundKey = false;
      receivedConfig = true;
      break;
      
      
      case KEY_CONFIG_COLOURAWA: 
      #ifdef PBL_COLOR
        colourAWA = t->value->int32 != 0;
      #endif // PBL_COLOUR
      foundKey = false;
      receivedConfig = true;
      break;

      #endif //CONFIG_SUPPORT
      default:
      APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized, value %d", (int)t->key, (int)t->value->int32);
      foundKey = false;
      break;
    }
    if (foundKey) // Now look through the fields on the current screen to see if it is displayed
      {
      #ifdef CONFIG_SUPPORT
      foundAKey = true;
      #endif
      if (t->key == KEY_LINE_BURN) // Do vibrate regardless of what is displayed
              {
              if (!earlyWarnDone && t->value->int32 < 10 && t->value->int32 >0)
                {
                vibes_double_pulse ();
                earlyWarnDone = true;
              }
              else if (t->value->int32 <= 0)
                {
                if (!warnedLineBurn)
                    {
                    vibes_long_pulse();
                    warnedLineBurn = true;
                }
              }
              else
                {
                warnedLineBurn = false;
              }
            }
                
      int i;
        for (i=0; i<screens[currentScreen].num_fields; i++)
          {
          if (weAreRacing && keyTitles[screens[currentScreen].field_data_map[i]].preStart) // We are racing & we have pre-start data displayed
              doScreenTransition = true; // Force a transition if we are racing with a screen displaying prestart data
          if (keyTitles[screens[currentScreen].field_data_map[i]].key == (int)t->key) // Did we find a match?
            { // To this point we have only decoded the message into the buffer
            setField(i, negNum, bj);  // Display the data - we found a match
            fieldUpdated[i] = true;
          }
        }
    // Use next buffer - the buffer remains in use even after the data actually appears on the screen
    // So we need to use a different buffer for each message.
      j++;
    }
    t = dict_read_next(iterator); // Look for next item
  }
#ifdef CONFIG_SUPPORT    
  if (receivedConfig) {
    screenMessageTimer = 3;
    screenMessage("Configuration received");
}
  if (foundAKey) {
  // Messages are still arriving
    if (tickCounter >= 7 && vibeDisconnect)
      vibes_double_pulse();
    tickCounter = 0;
  }
#endif    
  if (weAreRacing && doScreenTransition && holdThisScreen == 0) // We are racing, are showing some prestart data & don't need to hold this screen
    {
      do // Loop around looing for the next in use screen
        {
        currentScreen = (1 + currentScreen) % NUM_SCREENS;
      } while (screens[currentScreen].num_fields == 0);
    if (currentScreen == startingScreen)
      doScreenTransition = false; // Stop looking - we're back where we started!
    updatescreen(currentScreen, NULL); 
  }
  } while (weAreRacing && doScreenTransition && holdThisScreen == 0);
  
  int VMGtoWind;
  
  if (canDoVMG) {
    VMGtoWind = mycos(M_PI * ((hdg - twd) / 180.0)) * (bs * 10);
    VMGtoWind = VMGtoWind / 10 + (VMGtoWind % 10 >=5 ? 1 : 0);
    snprintf(VMGtoWindBuffer, sizeof(VMGtoWindBuffer), "%d.%d", abs(VMGtoWind)/10, abs(VMGtoWind)%10);
  }
  
  // Post process screen fields - VMGWind, blank non-updated fields etc.
  for (ii = 0; ii < screens[currentScreen].num_fields; ii++) {
    int fieldKeyTitle = keyTitles[screens[currentScreen].field_data_map[ii]].key;
    if (canDoVMG) {
      if (fieldKeyTitle == KEY_VMG_WIND) {
        setField(ii, false, VMGtoWindBuffer);  
        fieldUpdated[ii] = true;
      }
    }
    #ifdef PBL_COLOR
    if ((fieldKeyTitle == KEY_LINE_BURN && highVMG) || (colourAWA && (fieldKeyTitle == KEY_AWA || fieldKeyTitle == KEY_TWA) && redAWA)) {
      // APP_LOG(APP_LOG_LEVEL_ERROR, "High VMG/AWA Port in post process");
      text_layer_set_text_color(s_data_layer[screens[currentScreen].field_layer_map[ii]], redTextColour); 
    }
    else if (colourAWA && (fieldKeyTitle == KEY_AWA || fieldKeyTitle == KEY_TWA) && !redAWA) {
      // APP_LOG(APP_LOG_LEVEL_ERROR, "AWA Starboard in post process");
      text_layer_set_text_color(s_data_layer[screens[currentScreen].field_layer_map[ii]], greenTextColour);       
    }
    #endif
    if (!fieldUpdated[ii])
      {
      setField(ii, false, ""); // If a field has not been updated, blank it out - it will be mapped to the wrong buffer[] element
    }
  }
  
}
예제 #10
0
파일: CPUINTRF.C 프로젝트: neiderm/arcade
void cpu_run(void)
{
    int totalcpu,usres;
    unsigned char *ROM0;	/* opcode decryption is currently supported only for the first memory region */


    ROM0 = ROM;

    /* count how many CPUs we have to emulate */
    totalcpu = 0;
    while (totalcpu < MAX_CPU)
    {
        const struct MemoryReadAddress *mra;
        const struct MemoryWriteAddress *mwa;


        if (Machine->drv->cpu[totalcpu].cpu_type == 0) break;

        /* if sound is disabled, don't emulate the audio CPU */
        if (play_sound == 0 && (Machine->drv->cpu[totalcpu].cpu_type & CPU_AUDIO_CPU))
            cpurunning[totalcpu] = 0;
        else
            cpurunning[totalcpu] = 1;

        /* initialize the memory base pointers for memory hooks */
        RAM = Machine->memory_region[Machine->drv->cpu[totalcpu].memory_region];
        mra = Machine->drv->cpu[totalcpu].memory_read;
        while (mra->start != -1)
        {
            if (mra->base) *mra->base = &RAM[mra->start];
            mra++;
        }
        mwa = Machine->drv->cpu[totalcpu].memory_write;
        while (mwa->start != -1)
        {
            if (mwa->base) *mwa->base = &RAM[mwa->start];
            mwa++;
        }


        totalcpu++;
    }

#ifdef BUGS
    extern void g_exec(void);
    g_exec();
#else // BUGS

reset:
    for (activecpu = 0; activecpu < totalcpu; activecpu++)
    {
        int cycles;


        cycles = Machine->drv->cpu[activecpu].cpu_clock /
                 (Machine->drv->frames_per_second * Machine->drv->cpu[activecpu].interrupts_per_frame);

        switch(Machine->drv->cpu[activecpu].cpu_type & ~CPU_FLAGS_MASK)
        {
        case CPU_Z80:
        {
            struct z80context *ctxt;


            ctxt = (struct z80context *)cpucontext[activecpu];
            Z80_Reset();
            Z80_GetRegs(&ctxt->regs);
            ctxt->icount = cycles;
            ctxt->iperiod = cycles;
            ctxt->irq = Z80_IGNORE_INT;
        }
        break;

#if 0
        case CPU_M6502:
        {
            M6502 *ctxt;


            ctxt = (M6502 *)cpucontext[activecpu];
            /* Reset6502() needs to read memory to get the PC start address */
            RAM = Machine->memory_region[Machine->drv->cpu[activecpu].memory_region];
            memoryread = Machine->drv->cpu[activecpu].memory_read;
            ctxt->IPeriod = cycles;	/* must be done before Reset6502() */
            Reset6502(ctxt);
        }
        break;
        case CPU_I86:
            RAM = Machine->memory_region[Machine->drv->cpu[activecpu].memory_region];
            I86_Reset(RAM,cycles);
            break;
        /* DS... */
        case CPU_M6809:
        {
            struct m6809context *ctxt;

            ctxt = (struct m6809context *)cpucontext[activecpu];
            /* m6809_reset() needs to read memory to get the PC start address */
            RAM = Machine->memory_region[Machine->drv->cpu[activecpu].memory_region];
            memoryread = Machine->drv->cpu[activecpu].memory_read;
            m6809_IPeriod = cycles;
            m6809_reset();
            m6809_GetRegs(&ctxt->regs);
            ctxt->icount = cycles;
            ctxt->iperiod = cycles;
            ctxt->irq = INT_NONE;
        }
        break;
#endif
            /* ...DS */
        }
    }


    do
    {
        for (activecpu = 0; activecpu < totalcpu; activecpu++)
        {
            if (cpurunning[activecpu])
            {
                int loops;


                memoryread = Machine->drv->cpu[activecpu].memory_read;
                memorywrite = Machine->drv->cpu[activecpu].memory_write;

                RAM = Machine->memory_region[Machine->drv->cpu[activecpu].memory_region];
                /* opcode decryption is currently supported only for the first memory region */
                if (activecpu == 0) ROM = ROM0;
                else ROM = RAM;


                switch(Machine->drv->cpu[activecpu].cpu_type & ~CPU_FLAGS_MASK)
                {
                case CPU_Z80:
                {
                    struct z80context *ctxt;


                    ctxt = (struct z80context *)cpucontext[activecpu];

                    Z80_SetRegs(&ctxt->regs);
                    Z80_ICount = ctxt->icount;
                    Z80_IPeriod = ctxt->iperiod;
                    Z80_IRQ = ctxt->irq;

                    for (loops = 0; loops < Machine->drv->cpu[activecpu].interrupts_per_frame; loops++)
                        Z80_Execute();

                    Z80_GetRegs(&ctxt->regs);
                    ctxt->icount = Z80_ICount;
                    ctxt->iperiod = Z80_IPeriod;
                    ctxt->irq = Z80_IRQ;
                }
                break;

#if 0
                case CPU_M6502:
                    for (loops = 0; loops < Machine->drv->cpu[activecpu].interrupts_per_frame; loops++)
                        Run6502((M6502 *)cpucontext[activecpu]);
                    break;

                case CPU_I86:
                    for (loops = 0; loops < Machine->drv->cpu[activecpu].interrupts_per_frame; loops++)
                        I86_Execute();
                    break;
                /* DS... */
                case CPU_M6809:
                {
                    struct m6809context *ctxt;

                    ctxt = (struct m6809context *)cpucontext[activecpu];

                    m6809_SetRegs(&ctxt->regs);
                    m6809_ICount = ctxt->icount;
                    m6809_IPeriod = ctxt->iperiod;
                    m6809_IRequest = ctxt->irq;

                    for (loops = 0; loops < Machine->drv->cpu[activecpu].interrupts_per_frame; loops++)
                        m6809_execute();

                    m6809_GetRegs(&ctxt->regs);
                    ctxt->icount = m6809_ICount;
                    ctxt->iperiod = m6809_IPeriod;
                    ctxt->irq = m6809_IRequest;
                }
                break;
#endif
                    /* ...DS */
                }
            }
        }

        usres = updatescreen();
        if (usres == 2)	/* user asked to reset the machine */
            goto reset;
    } while (usres == 0);
#endif // BUGS
}
예제 #11
0
void
edit()
{
	extern	bool_t	need_redraw;
	int	c;
	register char	*p, *q;

	Prenum = 0;

	/* position the display and the cursor at the top of the file. */
	*Topchar = *Filemem;
	*Curschar = *Filemem;
	Cursrow = Curscol = 0;

	do_mlines();		/* check for mode lines before starting */

	updatescreen();

	for ( ;; ) {

	/* Figure out where the cursor is based on Curschar. */
	cursupdate();

	if (need_redraw && !anyinput()) {
		updatescreen();
		need_redraw = FALSE;
	}

	if (!anyinput())
		windgoto(Cursrow,Curscol);


	c = vgetc();

	if (State == NORMAL) {

		/* We're in the normal (non-insert) mode. */

		/* Pick up any leading digits and compute 'Prenum' */
		if ( (Prenum>0 && isdigit(c)) || (isdigit(c) && c!='0') ){
			Prenum = Prenum*10 + (c-'0');
			continue;
		}
		/* execute the command */
		normal(c);
		Prenum = 0;

	} else {

		/*
		 * Insert or Replace mode.
		 */
		switch (c) {

		case ESC:	/* an escape ends input mode */

			/*
			 * If we just did an auto-indent, truncate the
			 * line, and put the cursor back.
			 */
			if (did_ai) {
				Curschar->linep->s[0] = NUL;
				Curschar->index = 0;
				did_ai = FALSE;
			}

			set_want_col = TRUE;

			/* Don't end up on a '\n' if you can help it. */
			if (gchar(Curschar) == NUL && Curschar->index != 0)
				dec(Curschar);

			/*
			 * The cursor should end up on the last inserted
			 * character. This is an attempt to match the real
			 * 'vi', but it may not be quite right yet.
			 */
			if (Curschar->index != 0 && !endofline(Curschar))
				dec(Curschar);

			State = NORMAL;
			msg("");

			/* construct the Redo buffer */
			p=Redobuff;
			q=Insbuff;
			while ( q < Insptr )
				*p++ = *q++;
			*p++ = ESC;
			*p = NUL;
			updatescreen();
			break;

		case CTRL('D'):
			/*
			 * Control-D is treated as a backspace in insert
			 * mode to make auto-indent easier. This isn't
			 * completely compatible with vi, but it's a lot
			 * easier than doing it exactly right, and the
			 * difference isn't very noticeable.
			 */
		case BS:
			/* can't backup past starting point */
			if (Curschar->linep == Insstart->linep &&
			    Curschar->index <= Insstart->index) {
				beep();
				break;
			}

			/* can't backup to a previous line */
			if (Curschar->linep != Insstart->linep &&
			    Curschar->index <= 0) {
				beep();
				break;
			}

			did_ai = FALSE;
			dec(Curschar);
			if (State == INSERT)
				delchar(TRUE);
			/*
			 * It's a little strange to put backspaces into
			 * the redo buffer, but it makes auto-indent a
			 * lot easier to deal with.
			 */
			*Insptr++ = BS;
			Ninsert++;
			cursupdate();
			updateline();
			break;

		case CR:
		case NL:
			if (State == REPLACE)		/* DMT added, 12/89 */
				delchar(FALSE);
			*Insptr++ = NL;
			Ninsert++;
			opencmd(FORWARD, TRUE);		/* open a new line */
			break;

		default:
			did_ai = FALSE;
			insertchar(c);
			break;
		}
	}
	}
}
예제 #12
0
파일: galag.c 프로젝트: neiderm/arcade
/***************************************************************************

  This function takes care of refreshing the screen, processing user input,
  and throttling the emulation speed to obtain the required frames per second.

  IN: blocking (no longer used)
        1 == blocking, i.e. read keys, doesn't return until vblank complete.
        0 == non-blocking, i.e. read keys but return if not vblank

 ***************************************************************************/
int _updatescreen(int blocking)
{
    static uclock_t prev;

    static int this1, last1;
    static int this2, last2;
    static int this3, last3;
    static int thisct, lastct;

    float fps = sim_fps;

    thisct = code_pressed(KEYCODE_LCONTROL);

    if (thisct && lastct != thisct)
    {
        io_input[1] &= ~0x10; // see note for f_1F04
    }
    else
    {
        io_input[1] |= 0x10; // see note for f_1F04
    }
    lastct = thisct;

    if ( code_pressed(KEYCODE_RIGHT) )
    {
        io_input[1] &= ~2;
    }
    else
    {
        io_input[1] |= 2;
    }

    if ( code_pressed(KEYCODE_LEFT) )
    {
        io_input[1] &= ~8;
    }
    else
    {
        io_input[1] |= 8;
    }


    /* if the user pressed ESC, stop the emulation */
    if ( code_pressed(KEYCODE_ESC) ) return 1;

    // get keys for coin-in switch and start button, which need to be debounced

    this3 = code_pressed(KEYCODE_3);
    if (this3 && last3 != this3)
    {
        if (io_input[0] < 255)
        {
            io_input[0]++;
        }
    }
    last3 = this3;

    this1 = code_pressed(KEYCODE_1);
    if (this1 && last1 != this1)
    {
        if (io_input[0] > 0)
        {
            io_input[0]--;
        }
    }
    last1 = this1;

    this2 = code_pressed(KEYCODE_2);
    if (this2 && last2 != this2)
    {
        if (io_input[0] > 0)
        {
            io_input[0] -= 2;
        }
    }
    last2 = this2;


    if (1)
    {
        uclock_t curr;

        updatescreen();

        /* now wait until it's time to trigger the interrupt */
        do
        {
            curr = uclock();
        }
        while (curr - prev < UCLOCKS_PER_SEC / fps);

        vblank_work();
        prev = curr;
    }

    return 0;
}
예제 #13
0
/* --- TITLE SCREEN --- */
void title(void)
{
  random_timer.init(true);

  walking = true;

  st_pause_ticks_init();

  GameSession session(datadir + "/levels/misc/menu.stl", 0, ST_GL_DEMO_GAME);

  clearscreen(0, 0, 0);
  updatescreen();

  /* Load images: */
  bkg_title = new Surface(datadir + "/images/title/background.jpg", IGNORE_ALPHA);
  logo = new Surface(datadir + "/images/title/logo.png", USE_ALPHA);
  img_choose_subset = new Surface(datadir + "/images/status/choose-level-subset.png", USE_ALPHA);

  /* Generating contrib maps by only using a string_list */
  // Since there isn't any world dir or anything, add a hardcoded entry for Bonus Island
  string_list_init(&worldmap_list);

  string_list_type files = dfiles("levels/worldmaps/", ".stwm", "couldn't list worldmaps");
  for(int i = 0; i < files.num_items; ++i) {
    if(strcmp(files.item[i], "world1.stwm") == 0)
      continue;
    string_list_add_item(&worldmap_list, files.item[i]);
  }
  string_list_free(&files);

  /* --- Main title loop: --- */
  frame = 0;

  /* Draw the title background: */
  bkg_title->draw_bg();

  update_time = st_get_ticks();
  random_timer.start(rand() % 2000 + 2000);

  Menu::set_current(main_menu);
  while (Menu::current())
    {
      // if we spent to much time on a menu entry
      if( (update_time - last_update_time) > 1000)
        update_time = last_update_time = st_get_ticks();

      // Calculate the movement-factor
      double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
      if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
        frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85;
      /* Lower the frame_ratio that Tux doesn't jump to hectically throught the demo. */
      frame_ratio /= 2;

      SDL_Event event;
      while (SDL_PollEvent(&event))
        {
          if (Menu::current())
            {
              Menu::current()->event(event);
            }
         // FIXME: QUIT signal should be handled more generic, not locally
          if (event.type == SDL_QUIT)
            Menu::set_current(0);
        }

      /* Draw the background: */
      draw_demo(&session, frame_ratio);
      
      if (Menu::current() == main_menu)
        logo->draw( 160, 30);

      white_small_text->draw(" SuperTux " VERSION "\n"
                             "Copyright (c) 2003 SuperTux Devel Team\n"
                             "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n"
                             "are welcome to redistribute it under certain conditions; see the file COPYING\n"
                             "for details.\n",
                             0, 420, 0);

      /* Don't draw menu, if quit is true */
      Menu* menu = Menu::current();
      if(menu)
        {
          menu->draw();
          menu->action();
        
          if(menu == main_menu)
            {
              MusicManager* music_manager;
	      MusicRef menu_song;
              switch (main_menu->check())
                {
                case MNID_STARTGAME:
                  // Start Game, ie. goto the slots menu
                  update_load_save_game_menu(load_game_menu);
                  break;
                case MNID_CONTRIB:
                  // Contrib Menu
                  puts("Entering contrib menu");
                  generate_contrib_menu();
                  break;
                case MNID_LEVELEDITOR:
                  leveleditor();
                  Menu::set_current(main_menu);
                  break;
                case MNID_CREDITS:
                  music_manager = new MusicManager();
                  menu_song  = music_manager->load_music(datadir + "/music/credits.ogg");
                  music_manager->halt_music();
                  music_manager->play_music(menu_song,0);
                  display_text_file("CREDITS", bkg_title, SCROLL_SPEED_CREDITS);
                  music_manager->halt_music();
                  menu_song = music_manager->load_music(datadir + "/music/theme.mod");
                  music_manager->play_music(menu_song);
                  Menu::set_current(main_menu);
                  break;
                case MNID_QUITMAINMENU:
                  Menu::set_current(0);
                  break;
                }
            }
          else if(menu == options_menu)
            {
              process_options_menu();
            }
          else if(menu == load_game_menu)
            {
              if(event.key.keysym.sym == SDLK_DELETE)
                {
                int slot = menu->get_active_item_id();
                char str[1024];
                sprintf(str,"Are you sure you want to delete slot %d?", slot);
                
                draw_background();

                if(confirm_dialog(str))
                  {
                  sprintf(str,"%s/slot%d.stsg", st_save_dir, slot);
                  printf("Removing: %s\n",str);
                  remove(str);
                  }

                update_load_save_game_menu(load_game_menu);
                update_time = st_get_ticks();
                Menu::set_current(main_menu);
                }
              else if (process_load_game_menu())
                {
                  // FIXME: shouldn't be needed if GameSession doesn't relay on global variables
                  // reset tux
                  scroll_x = 0;
                  //titletux.level_begin();
                  update_time = st_get_ticks();
                }
            }
          else if(menu == contrib_menu)
            {
              check_contrib_menu();
            }
          else if (menu == contrib_subset_menu)
            {
              check_contrib_subset_menu();
            }
        }

      mouse_cursor->draw();
      
      flipscreen();

      /* Set the time of the last update and the time of the current update */
      last_update_time = update_time;
      update_time = st_get_ticks();

      /* Pause: */
      frame++;
      SDL_Delay(25);
    }
  /* Free surfaces: */

  free_contrib_menu();
  string_list_free(&worldmap_list);
  delete bkg_title;
  delete logo;
  delete img_choose_subset;
}
예제 #14
0
파일: edit.c 프로젝트: kindy/vim0
void
edit()
{
        int c;
        char *p, *q;

        Prenum = 0;

        /* position the display and the cursor at the top of the file. */
        *Topchar = *Filemem;
        *Curschar = *Filemem;
        Cursrow = Curscol = 0;

        for ( ;; ) {

        /* Figure out where the cursor is based on Curschar. */
        cursupdate();

        windgoto(Cursrow,Curscol);

        c = vgetc();

        if (State == NORMAL) {

                /* We're in the normal (non-insert) mode. */

                /* Pick up any leading digits and compute 'Prenum' */
                if ( (Prenum>0 && isdigit(c)) || (isdigit(c) && c!='0') ){
                        Prenum = Prenum*10 + (c-'0');
                        continue;
                }
                /* execute the command */
                normal(c);
                Prenum = 0;

        } else {

                switch (c) {        /* We're in insert mode */

                case ESC:        /* an escape ends input mode */

                        set_want_col = TRUE;

                        /* Don't end up on a '\n' if you can help it. */
                        if (gchar(Curschar) == NUL && Curschar->index != 0)
                                dec(Curschar);

                        /*
                         * The cursor should end up on the last inserted
                         * character. This is an attempt to match the real
                         * 'vi', but it may not be quite right yet.
                         */
                        if (Curschar->index != 0 && !endofline(Curschar))
                                dec(Curschar);

                        State = NORMAL;
                        msg("");
                        *Uncurschar = *Insstart;
                        Undelchars = Ninsert;
                        /* Undobuff[0] = '\0'; */
                        /* construct the Redo buffer */
                        p=Redobuff;
                        q=Insbuff;
                        while ( q < Insptr )
                                *p++ = *q++;
                        *p++ = ESC;
                        *p = NUL;
                        updatescreen();
                        break;

                case CTRL('D'):
                        /*
                         * Control-D is treated as a backspace in insert
                         * mode to make auto-indent easier. This isn't
                         * completely compatible with vi, but it's a lot
                         * easier than doing it exactly right, and the
                         * difference isn't very noticeable.
                         */
                case BS:
                        /* can't backup past starting point */
                        if (Curschar->linep == Insstart->linep &&
                            Curschar->index <= Insstart->index) {
                                beep();
                                break;
                        }

                        /* can't backup to a previous line */
                        if (Curschar->linep != Insstart->linep &&
                            Curschar->index <= 0) {
                                beep();
                                break;
                        }

                        did_ai = FALSE;
                        dec(Curschar);
                        delchar(TRUE);
                        Insptr--;
                        Ninsert--;
                        cursupdate();
                        updateline();
                        break;

                case CR:
                case NL:
                        *Insptr++ = NL;
                        Ninsert++;
                        opencmd(FORWARD, TRUE);                /* open a new line */
                        cursupdate();
                        updatescreen();
                        break;

                default:
                        did_ai = FALSE;
                        insertchar(c);
                        break;
                }
        }
        }
}
예제 #15
0
파일: screen.c 프로젝트: kindy/vim0
void
cursupdate()
{
        LPTR *p;
        int inc, c, nlines;
        int i;
        int didinc;

        if (bufempty()) {                /* special case - file is empty */
                *Topchar  = *Filemem;
                *Curschar = *Filemem;
        } else if ( LINEOF(Curschar) < LINEOF(Topchar) ) {
                nlines = cntllines(Curschar,Topchar);
                /* if the cursor is above the top of */
                /* the screen, put it at the top of the screen.. */
                *Topchar = *Curschar;
                Topchar->index = 0;
                /* ... and, if we weren't very close to begin with, */
                /* we scroll so that the line is close to the middle. */
                if ( nlines > Rows/3 ) {
                        for (i=0, p = Topchar; i < Rows/3 ;i++, *Topchar = *p)
                                if ((p = prevline(p)) == NULL)
                                        break;
                } else
                        s_ins(0, nlines-1);
                updatescreen();
        }
        else if (LINEOF(Curschar) >= LINEOF(Botchar)) {
                nlines = cntllines(Botchar,Curschar);
                /* If the cursor is off the bottom of the screen, */
                /* put it at the top of the screen.. */
                /* ... and back up */
                if ( nlines > Rows/3 ) {
                        p = Curschar;
                        for (i=0; i < (2*Rows)/3 ;i++)
                                if ((p = prevline(p)) == NULL)
                                        break;
                        *Topchar = *p;
                } else {
                        scrollup(nlines);
                }
                updatescreen();
        }

        Cursrow = Curscol = Cursvcol = 0;
        for ( p=Topchar; p->linep != Curschar->linep ;p = nextline(p) )
                Cursrow += plines(p);

        Cline_row = Cursrow;
        Cline_size = plines(p);

        for (i=0; i <= Curschar->index ;i++) {
                c = Curschar->linep->s[i];
                /* A tab gets expanded, depending on the current column */
                if ( c == TAB && !P(P_LS) )
                        inc = P(P_TS) - (Curscol % P(P_TS));
                else
                        inc = chars[(unsigned)(c & 0xff)].ch_size;
                Curscol += inc;
                Cursvcol += inc;
                if ( Curscol >= Columns ) {
                        Curscol -= Columns;
                        Cursrow++;
                        didinc = TRUE;
                }
                else
                        didinc = FALSE;
        }
        if (didinc)
                Cursrow--;

        if (c == TAB && State == NORMAL && !P(P_LS)) {
                Curscol--;
                Cursvcol--;
        } else {
                Curscol -= inc;
                Cursvcol -= inc;
        }
        if (Curscol < 0)
                Curscol += Columns;

        if (set_want_col) {
                Curswant = Cursvcol;
                set_want_col = FALSE;
        }
}
예제 #16
0
int run_game(int game)
{
	callback_item *cb;
	int error = 0;

	/* start in the "pre-init phase" */
	current_phase = MAME_PHASE_PREINIT;

/* AdvanceMAME: Disable validity checks */
#if 0
	/* perform validity checks before anything else */
	if (mame_validitychecks(game) != 0)
		return 1;
#endif

	/* loop across multiple hard resets */
	exit_pending = FALSE;
	while (error == 0 && !exit_pending)
	{
		/* use setjmp/longjmp for deep error recovery */
		fatal_error_jmpbuf_valid = TRUE;
		error = setjmp(fatal_error_jmpbuf);
		if (error == 0)
		{
			int settingsloaded;

			/* move to the init phase */
			current_phase = MAME_PHASE_INIT;

			/* start tracking resources for real */
			begin_resource_tracking();

			/* if we have a logfile, set up the callback */
			logerror_callback_list = NULL;
			if (options.logfile)
				add_logerror_callback(logfile_callback);

			/* create the Machine structure and driver */
			create_machine(game);

			/* then finish setting up our local machine */
			init_machine();

			/* load the configuration settings and NVRAM */
			settingsloaded = config_load_settings();
			nvram_load();

			/* initialize the UI and display the startup screens */
			if (ui_init(!settingsloaded && !options.skip_disclaimer, !options.skip_warnings, !options.skip_gameinfo) != 0)
				fatalerror("User cancelled");

			/* ensure we don't show the opening screens on a reset */
			options.skip_disclaimer = options.skip_warnings = options.skip_gameinfo = TRUE;

			/* start resource tracking; note that soft_reset assumes it can */
			/* call end_resource_tracking followed by begin_resource_tracking */
			/* to clear out resources allocated between resets */
			begin_resource_tracking();

			/* perform a soft reset -- this takes us to the running phase */
			soft_reset(0);

			/* run the CPUs until a reset or exit */
			hard_reset_pending = FALSE;
			while ((!hard_reset_pending && !exit_pending) || saveload_pending_file != NULL)
			{
				profiler_mark(PROFILER_EXTRA);

				/* execute CPUs if not paused */
				if (!mame_paused)
					cpuexec_timeslice();

				/* otherwise, just pump video updates through */
				else
				{
					updatescreen();
					reset_partial_updates();
				}

				/* handle save/load */
				if (saveload_schedule_callback)
					(*saveload_schedule_callback)();

				profiler_mark(PROFILER_END);
			}

			/* and out via the exit phase */
			current_phase = MAME_PHASE_EXIT;

			/* stop tracking resources at this level */
			end_resource_tracking();

			/* save the NVRAM and configuration */
			nvram_save();
			config_save_settings();
		}
		fatal_error_jmpbuf_valid = FALSE;

		/* call all exit callbacks registered */
		for (cb = exit_callback_list; cb; cb = cb->next)
			(*cb->func.exit)();

		/* close all inner resource tracking */
		while (resource_tracking_tag != 0)
			end_resource_tracking();

		/* free our callback lists */
		free_callback_list(&exit_callback_list);
		free_callback_list(&reset_callback_list);
		free_callback_list(&pause_callback_list);
	}

	/* return an error */
	return error;
}
예제 #17
0
int main(int argc, char * argv[])
{

#ifdef _WII_
  IO::SD OurSD;
  OurSD.Mount();
  IO::USB OurUSB;
  OurUSB.Startup();
  OurUSB.Mount();
#endif

  st_directory_setup();

#ifndef _WII_
  parseargs(argc, argv);
  ////
#endif



  st_audio_setup();
  st_video_setup();


  clearscreen(0, 0, 0);
  loading_surf = new Surface(datadir + "/images/title/loading.png", USE_ALPHA);
  loading_surf->draw( 160, 30);
  updatescreen();


  st_joystick_setup();
  st_general_setup();
  st_menu();
  loadshared();

  if (launch_leveleditor_mode && level_startup_file)
    {
    leveleditor(level_startup_file);
    }
  else if (level_startup_file)
    {
      GameSession session(level_startup_file, 1, ST_GL_LOAD_LEVEL_FILE);
      session.run();
    }
  else
    {
      title();
    }

  clearscreen(0, 0, 0);
  updatescreen();

  unloadshared();
  st_general_free();
  TileManager::destroy_instance();
#ifdef DEBUG
  Surface::debug_check();
#endif
  st_shutdown();

  delete loading_surf;

  return 0;
}
예제 #18
0
int main(int argc, char **argv) {
	SDL_Surface			*screen = NULL;			// Whole screen
	SDL_Surface			*fieldSurface = NULL;
	SDL_Surface			*heatmapSurface = NULL;
	SDL_Surface			*zoomSurface = NULL;
	SDL_Event			event;

	bool				quit = false;
	char				field[FWIDTH*FHEIGHT];	// the playing field
	unsigned int		heatmap[FWIDTH*FHEIGHT];
	int					antx, anty;				// ant position
	int					zoomx, zoomy;			// current zoom start x,y
	char				antdir;					// ant direction

	SDL_Init(SDL_INIT_EVERYTHING);

	screen = SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_SWSURFACE);
	SDL_WM_SetCaption("Langton's Ant", NULL);

	fieldSurface = SDL_CreateRGBSurface(SDL_HWSURFACE, FWIDTH, FHEIGHT, 32, 0, 0, 0, 0);
	heatmapSurface = SDL_CreateRGBSurface(SDL_HWSURFACE, FWIDTH, FHEIGHT, 32, 0, 0, 0, 0);
	zoomSurface = SDL_CreateRGBSurface(SDL_HWSURFACE, FWIDTH, FHEIGHT, 32, 0, 0, 0, 0);

	// init arrays
	for (int y = 0; y < FHEIGHT; y++) {
		for (int x = 0; x < FWIDTH; x++) {
			field[y*FWIDTH+x] = 0;
			heatmap[y*FWIDTH+x] = 0;
		}
	}

	// initial ant position
	antx = FWIDTH/2;
	anty = FHEIGHT/2;
	antdir = 3;
	zoomx = 0;
	zoomy = 0;

	// draw border
	for (int x = 0; x < WIDTH; x++) {
		putpixel(screen, x, FHEIGHT, 255, 255, 255);
	}
	for (int y = 0; y < HEIGHT; y++) {
		putpixel(screen, FWIDTH, y, 255, 255, 255);
	}

	while (!quit) {
		while (SDL_PollEvent(&event)) {
			if (event.type == SDL_QUIT) {
				quit = true;
			}
		}
		
		// move the ant
		heatmap[anty*FWIDTH+antx]++;
		char	newfieldval;
		switch (field[anty*FWIDTH+antx]) {
			case 0:
				newfieldval = 1;
				if (++antdir > 3)
					antdir = 0;
				break;
			case 1:
				newfieldval = 0;
				if (--antdir < 0)
					antdir = 3;
				break;
		}
		field[anty*FWIDTH+antx] = newfieldval;

		switch (antdir) {
			case 0:
				if (anty == 0) {
					anty = FHEIGHT-1;
				} else {
					anty--;
				}
				break;

			case 1:
				if (antx >= FWIDTH-1) {
					antx = 0;
				} else {
					antx++;
				}
				break;

			case 2:
				if (anty >= FHEIGHT-1) {
					anty = 0;
				} else {
					anty++;
				}
				break;

			case 3:
				if (antx == 0) {
					antx = FWIDTH-1;
				} else {
					antx--;
				}
				break;
		}

		// update various surfaces
		field2surface(field, fieldSurface);
		heatmap2surface(heatmap, heatmapSurface);
		updateZoom(antx, anty, field, zoomSurface, zoomx, zoomy);

		// display ant
		putpixel(fieldSurface, antx, anty, 255, 0, 0);
		updatescreen(screen, fieldSurface, zoomSurface, heatmapSurface);

		SDL_Delay(1);	// Don't hog the CPU too much
	}

	SDL_Quit();
}
예제 #19
0
static void main_window_load(Window *window) {
  
  //APP_LOG(APP_LOG_LEVEL_ERROR, "In Main_window_load");
  // Use system font, apply it and add to Window
  s_3_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PTN_64));
  s_2_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PTN_59));
  s_4_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PTN_50));
  s_6_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PTN_47));
 
  
  s_title_font = fonts_get_system_font(FONT_KEY_GOTHIC_14);
  s_large_title_font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD);
  s_medium_title_font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);

  inverter = inverter_layer_create(GRect(0,0,144,168));
  layer_set_bounds(inverter_layer_get_layer(inverter),GRectZero);
  
  flash = inverter_layer_create(GRect(2,7,7,7));
  
  int jj;
  for (jj = 0; jj < 6; jj++) {
  dataInverter[jj] = inverter_layer_create(GRect(0,0,144,168));
  layer_set_bounds(inverter_layer_get_layer(dataInverter[jj]),GRectZero);  
  }
  
  // Create Display RectAngles
  
  // Six data fields & their titles
  #define SIX_FIELD_INDEX 0
  #define SIX_FIELD_MAX 5
  s_data_layer[0] = text_layer_create(GRect(0, 2, 71, 49));
  s_data_title[0] = text_layer_create(GRect(0, 49, 71, 15));

  s_data_layer[1] = text_layer_create(GRect(73, 2, 71, 49));
  s_data_title[1] = text_layer_create(GRect(73, 49, 71, 15));
  
  s_data_layer[2] = text_layer_create(GRect(0, 53, 71, 49));
  s_data_title[2] = text_layer_create(GRect(0, 102, 71, 14));
  
  s_data_layer[3] = text_layer_create(GRect(73, 53, 71, 49));
  s_data_title[3] = text_layer_create(GRect(73, 102, 71, 14));
  
  s_data_layer[4] = text_layer_create(GRect(0, 105, 71, 49));
  s_data_title[4] = text_layer_create(GRect(0, 154, 71, 15));
  
  s_data_layer[5] = text_layer_create(GRect(73, 105, 71, 49));
  s_data_title[5] = text_layer_create(GRect(73, 154, 71, 15));
  
  // Two data fields & their titles
  #define TWO_FIELD_INDEX 6
  #define TWO_FIELD_MAX 7
  s_data_layer[6] = text_layer_create(GRect(0, 2, 288, 60));
  layer_set_frame((Layer *) s_data_layer[6], GRect(0, 2, 144, 60));
  s_data_title[6] = text_layer_create(GRect(0, 64, 144, 28));
  
  s_data_layer[7] = text_layer_create(GRect(0, 79, 288, 60));
  layer_set_frame((Layer *) s_data_layer[7], GRect(0, 79, 144, 60));
  s_data_title[7] = text_layer_create(GRect(0, 140, 144, 28));

  
  // Four data fields & their titles
  #define FOUR_FIELD_INDEX 8
  #define FOUR_FIELD_MAX 11
  s_data_layer[8] = text_layer_create(GRect(0, 12, 142, 51));
  layer_set_frame((Layer *) s_data_layer[8], GRect(0, 12, 71, 51));
  s_data_title[8] = text_layer_create(GRect(0, 65, 71, 24));
  
  s_data_layer[9] = text_layer_create(GRect(73, 12, 71, 51));
  s_data_title[9] = text_layer_create(GRect(73, 65, 71, 24));
  
  s_data_layer[10] = text_layer_create(GRect(0, 91, 142, 51));
  layer_set_frame((Layer *) s_data_layer[10], GRect(0, 91, 71, 51));
  s_data_title[10] = text_layer_create(GRect(0, 144, 71, 24));
  
  s_data_layer[11] = text_layer_create(GRect(73, 91,  71, 51));
  s_data_title[11] = text_layer_create(GRect(73, 144, 71, 24));
  
  // Three fields - One big, two small
  //#define THREE_FIELD_INDEX 12
  #define THREE_FIELD_MAX 14
  s_data_layer[12] = text_layer_create(GRect(0, 10, 432, 65));
  layer_set_frame((Layer *) s_data_layer[12], GRect(0, 10, 144, 65));
  s_data_title[12] = text_layer_create(GRect(0, 75, 144, 28));

  s_data_layer[13] = text_layer_create(GRect(0, 91, 150, 51));
  layer_set_frame((Layer *) s_data_layer[13], GRect(0, 91, 71, 51));
  s_data_title[13] = text_layer_create(GRect(0, 144, 71, 24));
  
  
  //s_data_layer[14] = text_layer_create(GRect(73, 91, 142, 51));
  //layer_set_frame((Layer *) s_data_layer[14], GRect(73, 91, 71, 51));
  s_data_layer[14] = text_layer_create(GRect(73, 91,  71, 51));
  s_data_title[14] = text_layer_create(GRect(73, 144, 71, 24));
  
  
  // Top title
  s_data_layer[TITLE_INDEX] = text_layer_create(GRect(0, 0, 144, 16));
  
  

  // Set up top title area
    text_layer_set_background_color(s_data_layer[TITLE_INDEX], GColorBlack);
    text_layer_set_text_color(s_data_layer[TITLE_INDEX], GColorWhite);
    text_layer_set_text_alignment(s_data_layer[TITLE_INDEX], GTextAlignmentCenter);
    text_layer_set_text(s_data_layer[TITLE_INDEX], "StartLine");
    text_layer_set_font(s_data_layer[TITLE_INDEX], s_title_font);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_data_layer[TITLE_INDEX])); 
 
  window_set_background_color(window, GColorBlack);
  // Set up the messgage layer
  messageLayer = text_layer_create(GRect(10,30,124,120));
  text_layer_set_background_color(messageLayer, GColorClear);
  text_layer_set_text_color(messageLayer, GColorWhite);
  text_layer_set_text_alignment(messageLayer, GTextAlignmentCenter);
  text_layer_set_font(messageLayer, s_large_title_font);
  
  

  
  titleLayer = layer_create(GRect(0, 0, 144, 168));
  layer_insert_below_sibling(titleLayer, (Layer *)s_data_layer[TITLE_INDEX]);
  
  
  dataLayer = layer_create(GRect(0, 0, 144, 168));
  layer_insert_below_sibling(dataLayer, titleLayer); 
 
  
  int i;
  for (i =0; i < TITLE_INDEX; i++)
    {
    //Data

    text_layer_set_background_color(s_data_layer[i], GColorClear);
    text_layer_set_text_color(s_data_layer[i], GColorWhite);
    text_layer_set_text_alignment(s_data_layer[i], GTextAlignmentCenter);
    text_layer_set_overflow_mode(s_data_layer[i], GTextOverflowModeWordWrap);
    layer_add_child(dataLayer, text_layer_get_layer(s_data_layer[i]));
    
    //Title

    text_layer_set_background_color(s_data_title[i], GColorClear);
    text_layer_set_text_color(s_data_title[i], GColorWhite);
    text_layer_set_text_alignment(s_data_title[i], GTextAlignmentCenter);
    
    if (i >= SIX_FIELD_INDEX && i <= SIX_FIELD_MAX) // Small title fonts on the 6 field layout
      {
      text_layer_set_font(s_data_layer[i], s_6_font);    
      text_layer_set_font(s_data_title[i], s_title_font);
    }
    else if (i >= TWO_FIELD_INDEX && i <= TWO_FIELD_MAX) // This is 2 fields
      {
      text_layer_set_font(s_data_layer[i], s_2_font); 
      text_layer_set_font(s_data_title[i], s_large_title_font);
    }

    else if (i >= FOUR_FIELD_INDEX && i <= FOUR_FIELD_MAX) // 4 field layout
      {
      text_layer_set_font(s_data_layer[i], s_4_font); 
      text_layer_set_font(s_data_title[i], s_medium_title_font);
    }
    else if (i >= THREE_FIELD_INDEX && i <= THREE_FIELD_MAX)
      {
      if (i == THREE_FIELD_INDEX) // First field is big
        {
        text_layer_set_font(s_data_layer[i], s_3_font); 
        text_layer_set_font(s_data_title[i], s_large_title_font);
      } else
        {
        text_layer_set_font(s_data_layer[i], s_4_font);    
        text_layer_set_font(s_data_title[i], s_medium_title_font);        
      }
    }      
   
    layer_add_child(titleLayer, text_layer_get_layer(s_data_title[i]));
    
  }
  
 layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(inverter));


  int ii;
  for (ii = 0; ii < 6; ii++) {
     layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(dataInverter[ii]));
  }
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(messageLayer)); 

   layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(flash));

  
  // Go find a screen with some fields in use
  for (currentScreen = 0; screens[currentScreen].num_fields == 0; currentScreen++)
    ;

  // Add the padlock icon - steals the rest of my heap!!
  s_padlockLayer = bitmap_layer_create(GRect(133, 3, 8, 11));
  s_res_padlock = gbitmap_create_with_resource(RESOURCE_ID_PADLOCK);
  bitmap_layer_set_bitmap(s_padlockLayer, s_res_padlock);
  layer_add_child(window_get_root_layer(window), (Layer *)s_padlockLayer);
  layer_set_hidden((Layer *)s_padlockLayer, configLock == 1);
  
  // And make it the current screen
  updatescreen(currentScreen,"00");
}