Exemplo n.º 1
0
/* CHANGE *********************************************************************/
void changeState() {

    if ((time > 165 || game.getFuelRemaining() < 10) && // end game stage
        game.getMemoryFilled() > 0) {
        att_state = UPLOAD;
    }

    if (game.getMemoryFilled() == 2) {
        att_state = UPLOAD;
    }

    if (game.getMemoryFilled() == 0) {
        att_state = FACE_ENEMY;
    }

    if (move_state == STOP) {
        move_state = GET_SCORE_PACKS;
    }

    if (move_state == GET_SCORE_PACKS || move_state == GET_MIRROR) {
        if (itemBool[itemNum] != -1) {
            itemNum = recalibrate(3,6);
            if (itemNum == -1) {
                move_state = END_GAME;
            }
            else {
                move_state = GET_SCORE_PACKS;
            }
        }
    }

    if (energy < 1.3 && game.posInDark(me)) {
        move_state = STOP;
    }
}
Exemplo n.º 2
0
bool
RFM69::begin(const void* config)
{
  // Wait for the transceiver to become ready
  do write(SYNC_VALUE1, 0xaa); while (read(SYNC_VALUE1) != 0xaa);
  do write(SYNC_VALUE1, 0x55); while (read(SYNC_VALUE1) != 0x55);

  // Upload the configuration. Check for default configuration
  const uint8_t* cp = RFM69::config;
  Reg reg;
  if (config != NULL) cp = (const uint8_t*) config;
  while ((reg = (Reg) pgm_read_byte(cp++)) != 0)
    write(reg, pgm_read_byte(cp++));

  // Adjust configuration with instance specific state
  uint16_t sync = hton(m_addr.network);
  write(SYNC_VALUE1, &sync, sizeof(sync));
  write(NODE_ADDR, m_addr.device);

  // Set standby mode and calibrate RC oscillator
  recalibrate();

  // Initiate device driver state and enable interrupt handler
  m_avail = false;
  m_done = true;
  spi.attach(this);
  m_irq.enable();
  return (true);
}
Exemplo n.º 3
0
/*
 * remote configuration facility
 */
void fs20_configuration(void) {
  
  ccInitChip();
  
  fs20_resetbuffer();
  fs20_rxon();

  fstelegram_t t;
  t.type = 'U'; // undefined
  uint16_t rxtimeout = 300; // wait 300*100ms= 30s for reception

  // wait for next telegram
  // exit if button pressed or timeout occured
  while(!fs20_readFS20Telegram(&t) && (rxtimeout--)>0) {
    _delay_ms(100);
    if(LED_PIN!=PA3) LED_TOGGLE(); // do not touch pin for CC1100 communication
  }
  fs20_idle();

  // evaluate the result
  if(t.type=='F')   {
    if((t.housecode==HOUSECODE) && (t.button==BUTTON_COMMAND)) {
      led_blink(3); // blink for confirmation
      switch(t.cmd) {
	case COMMAND_HCALIB1:
	  xcalib1= get_voltage();
	  hcalib1= t.data[0]/100.0;
	  recalibrate();
	  break;
	case COMMAND_HCALIB2:
	  xcalib2= get_voltage();
	  hcalib2= t.data[0]/100.0;
	  recalibrate();
	  break;
	case COMMAND_USFOFFSET:
	  // we receive ufsoffset in centimeters
	  set_usfconfig(t.data[0]/100.0, usfheight);
	  break;
	case COMMAND_USFHEIGHT:
	  // we receive usfheight in centimenters
	  set_usfconfig(usfoffset, t.data[0]/100.0);
	  break;
      }
    }
  }   
}
Exemplo n.º 4
0
// get time of call, possibly recalibrating before returning
__forceinline ULONGLONG gethectonanotime_first(void) {
	ULONGLONG curtsc = gettsc();
	ULONGLONG now = hectonanotime_of_tsc(curtsc);
	if ((lastrecal == 0) || (now - lastrecal) > recalinterval) {
		recalibrate();
		now = hectonanotime_of_tsc(curtsc);
	}
	return now;
}
Exemplo n.º 5
0
void init() {
    for (int i = 0 ; i < 9 ; i++) {
        game.getItemLoc(items[i], i);
    }
    updateGameState();
    
    origin[0] = origin[1] = origin[2] = 0.0f;

    move_state = GET_SCORE_PACKS;
    att_state = FACE_OTHER;
    itemID = recalibrate(3, 6);

    DEBUG(("Hello from SHA-2468!"));
}
Exemplo n.º 6
0
/* CHANGE *********************************************************************/
void changeState() {
    if (game.getMemoryFilled() == 2) {
        att_state = UPLOAD;
    }

    if (att_state == UPLOAD && game.getMemoryFilled() == 0) {
        att_state = FACE_OTHER;
    }

    if (game.getCurrentTime() > 165 && game.getMemoryFilled() > 0) {
        att_state = UPLOAD;
    }

    if (move_state == GET_SCORE_PACKS) {
        if (game.getScore() > 3) {
            itemID = recalibrate(3,6);
            if (itemID == -1 || distance(me, items[itemID]) - distance(other, items[itemID]) > GIVE_UP_THRESHOLD) {
                move_state = END_GAME;
            }
        }
        else if (itemBool[itemID] != -1) {
            itemID = recalibrate(3, 6);
            if (itemID == -1) {
                move_state = END_GAME;
            }
        }
    }
    else {
        if (!inBounds(other)) {
            move_state = TO_ORIGIN;
        }
        else {
            move_state = END_GAME;
        }
    }
}
Exemplo n.º 7
0
/* this gets the FDC to a known state */
static void reset(void)
{
	outportb(FDC_DOR,0);
	mtick=0;
	motor=0;
	outportb(FDC_DRS,0);
	outportb(FDC_DOR,0x0c);
	done=1;
	sendbyte(CMD_SPECIFY);
	sendbyte(0xdf);  /* SRT = 3ms, HUT = 240ms */
	sendbyte(0x02);  /* HLT = 16ms, ND = 0 */
	flseek(1);
	recalibrate();
	dchange = 0;
}
Exemplo n.º 8
0
void init(){
    for (int i = 0 ; i < 9 ; i++) {
        game.getItemLoc(items[i], i);
    }
	updateGameState();
	
	origin[0] = origin[1] = origin[2] = earth[0] = earth[1] = 0.0f;
	
	earth[2] = 1.0f;
	
	itemNum = recalibrate(7,8);
	memcpy(target,items[itemNum],3*sizeof(float)); //do this here so we don't have to do it in GET_MIRROR
	
	move_state = GET_MIRROR;
	att_state = FACE_ENEMY;
	
	DEBUG(("Hello from SHA-2468!"));
}
Exemplo n.º 9
0
int flpy_read(struct fdd *d, uint32_t lba, uint8_t *buf, uint32_t nr_sectors)
{
	int rc = 0;
	uint8_t retries;
	struct chs f_addr;

	if (d->param->cmos_type == 0) return -1;

	while (_busy) ;	/* Wait while the floppy driver is already busy. BUSY WAIT! */
	_busy = TRUE;

	start_motor(d);

	specify(d);

	/* Only retry for 3 times */
	for (retries = 0; retries < 3; retries++) {
		/* Move head to right track */
		if (flpy_seek(d, f_addr.c) == 0) {
			/* If changeline is active, no disk is in drive */
			if (inportb(d->fdc->base_port + FDC_DIR) & 0x80) {
				DEBUG(DL_ERR, ("no disk in drive %d\n",
					       d->number));
				rc = -1;
				goto errorout;
			}
			rc = fdc_xfer(d, &f_addr, dma_addr, nr_sectors, FDC_READ);
			if (rc == 0) break;
		} else
			rc = -1;
		if (retries < 2) recalibrate(d);
	}

	/* Copy data from the DMA buffer into the caller's buffer */
	if ((rc == 0) && buf)
		;

 errorout:
	stop_motor(d);
	_busy = FALSE;

	return rc;
}
Exemplo n.º 10
0
int flpy_write(struct fdd *d, uint32_t lba, const uint8_t buf, uint32_t nr_sectors)
{
	int rc = 0;
	uint8_t retries;
	struct chs f_addr;

	if (d->param->cmos_type == 0) return -1;
	
	while (_busy) ;	// The BUSY WAIT!
	_busy = TRUE;

	start_motor(d);

	specify(d);
	
	for (retries = 0; retries < 3; retries++) {
		/* Move head to right track */
		if (flpy_seek(d, f_addr.c) == 0) {
			/* If changeline is active, no disk is in drive */
			if (inportb(d->fdc->base_port + FDC_DIR) & 0x80) {
				DEBUG(DL_ERR, ("no disk in drive %d\n",
					       d->number));
				rc = -1;
				break;
			}
			rc = fdc_xfer(d, &f_addr, dma_addr, nr_sectors, FDC_WRITE);
			if (rc == 0) break;
		} else
			rc = -1;
		if (retries < 2 ) recalibrate(d);
	}

	stop_motor(d);
	_busy = FALSE;

	return rc;
}
Exemplo n.º 11
0
Arquivo: fd.c Projeto: huangrui/Thunix
/*
 *    reset the floppy.
 *
 *    The first thing that the driver needs to do is reset the controller.This 
 * will put it in a known state. To reset the primary floppy controller,(in C)
 *
 * 1.write 0x00 to the DIGITAL_OUTPUT_REG of the desired controller
 * 2.write 0x0C to the DIGITAL_OUTPUT_REG of the desired controller
 * 3.wait for an interrupt from the controller
 * 4.check interrupt status (this is function 0x08 of controllers)
 * 5.write 0x00 to the CONFIG_CONTROL_REG
 * 6.configure the drive desired on the controller (function 0x03 of controller)
 * 7.calibrate the drive (function 0x07 of controller)
 *
 */
static void reset( )
{
        //LOG("reset() called ...\n");

        /* stop the motor and disable IRQ/DMA */
        outb_p(0x0c,FD_DOR);

        /* program data rate (500K/s) */
        outb_p(0,FD_DCR);
        
        /* re-enable interrupts */
        outb_p(0x1c,FD_DOR);

        /* resetting triggered an interrupt - handle it */
        done = TRUE;
        wait_fdc(TRUE);

        /* specify drive timings (got these off the BIOS) */
        send_byte(FD_SPECIFY);
        send_byte(0xdf);      /* SRT = 3ms, HUT = 240ms */
        send_byte(0x06);      /* HLT = 16ms, ND = 0     */

        recalibrate();
}
Exemplo n.º 12
0
Arquivo: fd.c Projeto: huangrui/Thunix
/*
 * And now, it's time to implenent the read or write function, that's
 * all the floppy driver mean!
 * 
 * Read/Write one sector once.
 */
static int floppy_rw(int sector, char *buf, int command)
{
	int head;
	char *dma_buffer = buf;
	static char tmp_dma_buffer[512];

	//LOG("TMP dma buffer: %p\n", tmp_dma_buffer);

        lba_to_chs(sector, &head, &track, &sector);
	LOG("head: %d \ttrack: %d \tsector: %d\n", head, track, sector);

        /* turn it on if not */
        motor_on();

        if (inb_p(FD_DIR) & 0x80) {
                changed = TRUE;
                seek(1, head);        /* clear "disk change" status */
                recalibrate();
                motor_off();
                printk("floppy_rw: Disk change detected. You are going to DIE:)\n");
                
                pause();  /* just put it in DIE */
        }

        /* move head to the right track */
        if (!seek(track, head)) {
                motor_off();
                printk("floppy_rw: Error seeking to track#%d\n", track);
                return FALSE;
        }
                
	if ((unsigned long)buf >= 0xff000) {
		dma_buffer = tmp_dma_buffer;
		if (command == FD_WRITE)
			memcpy(dma_buffer, buf, 512);
	}

        setup_DMA((unsigned long)dma_buffer, command);

        send_byte(command);
        send_byte(head<<2 | 0);
        send_byte(track);
        send_byte(head);
	send_byte(sector);
        send_byte(2);           /* sector size = 125 * 2^(2) */
        send_byte(floppy.sector);
        send_byte(0);
        send_byte(0xFF);        /* sector size(only two valid vaules, 0xff when n!=0*/

        if (!wait_fdc(FALSE)) {
                //LOG("wait fdc failed!\n");
                //return 0;
                /*
                printk("Time out, trying operation again after reset() \n");
                reset();
                return floppy_rw(sector, buf, command);
                */
        }

        motor_off();

        if (/*res != 7 || */(ST0 & 0xf8) || (ST1 & 0xbf) || (ST2 & 0x73) ) {
                if (ST1 & 0x02) 
                        LOG("Drive is write protected!\n");
                else
                        LOG("floppy_rw: bad interrupt!\n");

                return -EIO;
        } else {
		LOG("floppy_rw: OK\n");
		if ((unsigned long)buf >= 0xff000 && command == FD_READ)
			memcpy(buf, dma_buffer, 512);
		return 0;
        }
}
Exemplo n.º 13
0
char ATA_DEVICE::exec_ata_cmd(unsigned char cmd)
{
//   printf(__FUNCTION__" cmd=%02X\n", cmd);
   // EXECUTE DEVICE DIAGNOSTIC for both ATA and ATAPI
   if (cmd == 0x90)
   {
       reset_signature(RESET_SOFT);
       return 1;
   }

   if (atapi)
       return 0;

   // INITIALIZE DEVICE PARAMETERS
   if (cmd == 0x91)
   {
     // pos = (reg.cyl * h + (reg.devhead & 0x0F)) * s + reg.sec - 1;
     h = (reg.devhead & 0xF) + 1;
     s = reg.count;
     if(s == 0)
     {
          reg.status = STATUS_DRDY | STATUS_DF | STATUS_DSC | STATUS_ERR;
          return 1;
     }

     c = lba / s / h;

     reg.status = STATUS_DRDY | STATUS_DSC;
     return 1;
   }

   if ((cmd & 0xFE) == 0x20) // ATA-3 (mandatory), read sectors
   { // cmd #21 obsolette, rqd for is-dos
//       printf(__FUNCTION__" sec_cnt=%d\n", reg.count);
       read_sectors();
       return 1;
   }

   if((cmd & 0xFE) == 0x40) // ATA-3 (mandatory),  verify sectors
   { //rqd for is-dos
       verify_sectors();
       return 1;
   }

   if ((cmd & 0xFE) == 0x30 && !readonly) // ATA-3 (mandatory), write sectors
   {
      if (seek())
      {
          state = S_WRITE_SECTORS;
          reg.status = STATUS_DRQ | STATUS_DSC;
          transptr = 0;
          transcount = 0x100;
      }
      return 1;
   }

   if(cmd == 0x50) // format track (данная реализация - ничего не делает)
   {
      reg.sec = 1;
      if (seek())
      {
          state = S_FORMAT_TRACK;
          reg.status = STATUS_DRQ | STATUS_DSC;
          transptr = 0;
          transcount = 0x100;
      }
      return 1;
   }

   if (cmd == 0xEC)
   {
       prepare_id();
       return 1;
   }

   if (cmd == 0xE7)
   { // FLUSH CACHE
      if (ata_p.flush())
      {
          command_ok();
          intrq = 1;
      }
      else
          reg.status = STATUS_DRDY | STATUS_DF | STATUS_DSC | STATUS_ERR; // 0x71
      return 1;
   }

   if (cmd == 0x10)
   {
      recalibrate();
      command_ok();
      intrq = 1;
      return 1;
   }

   if (cmd == 0x70)
   { // seek
      if (!seek())
          return 1;
      command_ok();
      intrq = 1;
      return 1;
   }

   printf("*** unknown ata cmd %02X ***\n", cmd);

   return 0;
}
Exemplo n.º 14
0
/**
    \fn updateImageTiming
*/
bool ADM_Composer::updateImageTiming(_SEGMENT *seg,ADMImage *image)
{
    recalibrate(&(image->Pts),seg);
//    recalibrate(&(image->Dts),seg);
    return true;
}
Exemplo n.º 15
0
void mfm_harddisk_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	switch (id)
	{
	case INDEX_TM:
		// Simple index hole handling. We assume that there is only a short pulse.
		m_revolution_start_time = machine().time();
		if (!m_index_pulse_cb.isnull())
		{
			m_index_pulse_cb(this, ASSERT_LINE);
			m_index_pulse_cb(this, CLEAR_LINE);
		}
		break;

	case SPINUP_TM:
		recalibrate();
		break;

	case CACHE_TM:
		m_cache->write_back_one();
		break;

	case SEEK_TM:
		switch (m_step_phase)
		{
		case STEP_COLLECT:
			// Collect timer has expired; start moving head
			head_move();
			break;
		case STEP_MOVING:
			// Head has reached final position
			// Check whether we have a new delta
			if (m_track_delta == 0)
			{
				// Start the settle timer
				m_step_phase = STEP_SETTLE;
				m_seek_timer->adjust(m_settle_time);
				if (TRACE_STEPS && TRACE_DETAIL) logerror("%s: Arrived at target cylinder %d, settling ...\n", tag(), m_current_cylinder);
			}
			else
			{
				// need to move the head again
				head_move();
			}
			break;
		case STEP_SETTLE:
			// Do we have new step pulses?
			if (m_track_delta != 0) head_move();
			else
			{
				// Seek completed
				if (!m_recalibrated)
				{
					m_ready = true;
					m_recalibrated = true;
					if (TRACE_STATE) logerror("%s: Spinup complete, drive recalibrated and positioned at cylinder %d; drive is READY\n", tag(), m_current_cylinder);
					if (!m_ready_cb.isnull()) m_ready_cb(this, ASSERT_LINE);
				}
				else
				{
					if (TRACE_SIGNALS) logerror("%s: Settling done at cylinder %d, seek complete\n", tag(), m_current_cylinder);
				}
				m_seek_complete = true;
				if (!m_seek_complete_cb.isnull()) m_seek_complete_cb(this, ASSERT_LINE);
				m_step_phase = STEP_COLLECT;
			}
			break;
		}
	}
}
Exemplo n.º 16
0
EventReceiver::EventReceiver()
    : inputManager(0),
      mouse(0),
      keyboard(0),
      joystick(0),
      deadZone(0.01f),
      test_kc(0),
      keyNameMap(),
      lastSteer(0.0f)
{
    inputManager = OIS::InputManager::createInputSystem(TheGame::getInstance()->getWindowId());

    // for mem leak test
    //for (unsigned int i = 0; i < 10; i++)
    //{
    //    new char[100+i];
    //}

    if (inputManager->getNumberOfDevices(OIS::OISKeyboard) <= 0)
    {
        PrintError(1, "Unable to detect keyboard. Program will exit");
        assert(0);
    }
    keyboard = static_cast<OIS::Keyboard*>(inputManager->createInputObject(OIS::OISKeyboard, false));
    //mouse = static_cast<OIS::Mouse*>(inputManager->createInputObject(OIS::OISMouse, false));
    dprintf(MY_DEBUG_ERROR, "If crash here report me the error\n");
    if (inputManager->getNumberOfDevices(OIS::OISJoyStick) > 0)
    {
        joystick = static_cast<OIS::JoyStick*>(inputManager->createInputObject(OIS::OISJoyStick, false));
    }

    recalibrate();

    KeyProperty kp;
    kp.primaryKeyConfig = kp.secondaryKeyConfig = 0;
    kp.continous = true;
    keyNameMap["accelerate"] = ACCELERATE;
    kp.keyLongName = "Accelerate";
    keyMap[ACCELERATE] = kp;
    keyNameMap["brake"] = BRAKE;
    kp.keyLongName = "Brake";
    keyMap[BRAKE] = kp;
    keyNameMap["left"] = LEFT;
    kp.keyLongName = "Steer left";
    keyMap[LEFT] = kp;
    keyNameMap["right"] = RIGHT;
    kp.keyLongName = "Steer right";
    keyMap[RIGHT] = kp;
    keyNameMap["handbrake"] = HANDBRAKE;
    kp.keyLongName = "Handbrake";
    keyMap[HANDBRAKE] = kp;
    keyNameMap["clutch"] = CLUTCH;
    kp.keyLongName = "Clutch";
    keyMap[CLUTCH] = kp;
    keyNameMap["look_left"] = LOOK_LEFT;
    kp.keyLongName = "Look left";
    keyMap[LOOK_LEFT] = kp;
    keyNameMap["look_right"] = LOOK_RIGHT;
    kp.keyLongName = "Look right";
    keyMap[LOOK_RIGHT] = kp;
    keyNameMap["gear_1"] = GEAR_1;
    kp.keyLongName = "First gear";
    keyMap[GEAR_1] = kp;
    keyNameMap["gear_2"] = GEAR_2;
    kp.keyLongName = "Second gear";
    keyMap[GEAR_2] = kp;
    keyNameMap["gear_3"] = GEAR_3;
    kp.keyLongName = "Third gear";
    keyMap[GEAR_3] = kp;
    keyNameMap["gear_4"] = GEAR_4;
    kp.keyLongName = "Fourth gear";
    keyMap[GEAR_4] = kp;
    keyNameMap["gear_5"] = GEAR_5;
    kp.keyLongName = "Fifth gear";
    keyMap[GEAR_5] = kp;
    keyNameMap["gear_6"] = GEAR_6;
    kp.keyLongName = "Sixth gear";
    keyMap[GEAR_6] = kp;
    keyNameMap["gear_r"] = GEAR_R;
    kp.keyLongName = "Reverse gear";
    keyMap[GEAR_R] = kp;

    kp.continous = false;
    keyNameMap["physics"] = PHYSICS;
    kp.keyLongName = "Switch Physics on/off";
    keyMap[PHYSICS] = kp;
    keyNameMap["fps_camera"] = FPS_CAMERA;
    kp.keyLongName = "Change FPS camera";
    keyMap[FPS_CAMERA] = kp;
    keyNameMap["switch_hud"] = SWITCH_HUD;
    kp.keyLongName = "Turn on/off HUD";
    keyMap[SWITCH_HUD] = kp;
    keyNameMap["change_view"] = CHANGE_VIEW;
    kp.keyLongName = "Change view";
    keyMap[CHANGE_VIEW] = kp;
    keyNameMap["open_editor"] = OPEN_EDITOR;
    kp.keyLongName = "Open editor window";
    keyMap[OPEN_EDITOR] = kp;
    keyNameMap["reset_vehicle"] = RESET_VEHICLE;
    kp.keyLongName = "Reset vehicle";
    keyMap[RESET_VEHICLE] = kp;
    keyNameMap["repair_vehicle"] = REPAIR_VEHICLE;
    kp.keyLongName = "Repair vehicle";
    keyMap[REPAIR_VEHICLE] = kp;
    keyNameMap["switch_input"] = SWITCH_INPUT;
    kp.keyLongName = "Switch input while editor (game/editor)";
    keyMap[SWITCH_INPUT] = kp;
    keyNameMap["exit_to_menu"] = EXIT_TO_MENU;
    kp.keyLongName = "Game pause menu";
    keyMap[EXIT_TO_MENU] = kp;
    keyNameMap["roadbook_next"] = ROADBOOK_NEXT;
    kp.keyLongName = "Go to the next roadbook element";
    keyMap[ROADBOOK_NEXT] = kp;
    keyNameMap["roadbook_prev"] = ROADBOOK_PREV;
    kp.keyLongName = "Go to the previous roadbook element";
    keyMap[ROADBOOK_PREV] = kp;
    keyNameMap["reset_partial"] = RESET_PARTIAL;
    kp.keyLongName = "Reset partial";
    keyMap[RESET_PARTIAL] = kp;
    keyNameMap["inc_fps_speed"] = INC_FPS_SPEED;
    kp.keyLongName = "Increase FPS camera movement speed";
    keyMap[INC_FPS_SPEED] = kp;
    keyNameMap["dec_fps_speed"] = DEC_FPS_SPEED;
    kp.keyLongName = "Decrease FPS camera movement speed";
    keyMap[DEC_FPS_SPEED] = kp;
    keyNameMap["gear_up"] = GEAR_UP;
    kp.keyLongName = "Gear up (if sequential)";
    keyMap[GEAR_UP] = kp;
    keyNameMap["gear_down"] = GEAR_DOWN;
    kp.keyLongName = "Gear down (if sequential)";
    keyMap[GEAR_DOWN] = kp;
#ifdef DETECT_MEM_LEAKS
    keyNameMap["print_mem_leaks"] = PRINT_MEM_LEAKS;
    kp.keyLongName = "Print memory leaks";
    keyMap[PRINT_MEM_LEAKS] = kp;
    keyNameMap["print_mem_leaks_irr"] = PRINT_MEM_LEAKS_IRR;
    kp.keyLongName = "Print memory leaks from Irrlicht";
    keyMap[PRINT_MEM_LEAKS_IRR] = kp;
#endif // DETECT_MEM_LEAKS

    loadKeyMapping();
    //saveKeyMapping();
}
Exemplo n.º 17
0
void loop(){
	api.getMyZRState(me);
	api.getOtherZRState(other);
	
	getItemArray();
	
	if((game.getCurrentTime() > 165 || game.getFuelRemaining() < 10) && game.getMemoryFilled() >= 1){
	    game.takePic();
	    state = UPLOAD; //game changer
	}
	
	if(game.getEnergy() < 1 && !game.posInLight(me))
	    state = STOP;
	
	if(game.getFuelRemaining() == 0)
	    game.takePic();
	
	switch(state) {
	    case MAIN: //normal case
	        if(distance(me,items[itemNum])<0.3 && distance(me,items[itemNum])>distance(other,items[itemNum]) )
	            itemBool[itemNum]=false;
	        if(!itemBool[itemNum]){
	            itemNum = recalibrate(4,6);
	        }
	        memcpy(target,items[itemNum],3*sizeof(float));
	        
	        moveTo(target);
	            
	        mathVecSubtract(facing, other, me, 3);
	        api.setAttitudeTarget(facing);
	        
	        if( checkPhoto(me,other,facing) )
	            game.takePic();
	            
	        if(game.getMemoryFilled() == 2)
	            state = UPLOAD;
	        break;
	        
	    case UPLOAD: //upload
	        if(game.getEnergy() > 2)
	            moveTo(target);
	        else
	            api.setVelocityTarget(origin);
	        api.setAttitudeTarget(earth);
	        
	        if( game.getEnergy() > 1 && checkUpload(me) )
	            game.uploadPics();
	            
	        if( game.getMemoryFilled() == 0){
	            state = MAIN;
	        }
	        break;
	        
	   case STOP: //chill out
	        api.setVelocityTarget(origin);
	        api.setAttRateTarget(origin);
	        
	        if(!mathVecInner(me+6,facing,3) > 0.9689f)
	            api.setAttitudeTarget(facing);
	        
	        if(game.posInLight(me)){
	            if(game.getMemoryFilled() == 2)
	                state = UPLOAD;
	            else
	                state = MAIN;
	        }
	        break;
	        
	   case LIGHTDARK: //if we are in light and they are in dark
	        itemNum = recalibrate(7,8);
	        
	        if(!itemBool[itemNum]) //if both mirrors are taken
	            itemNum = 6;
	        
	        memcpy(target,items[itemNum],3*sizeof(float));
	        api.setPositionTarget(target);
	        
	        mathVecSubtract(facing, other, me, 3);
	        api.setAttitudeTarget(facing);
	        break;
	}
}
Exemplo n.º 18
0
/*since reads and writes differ only by a few lines, this handles both.*/
static UINT fdc_rw(int block,char *blockbuff,UINT cmd_read,ULONG nosectors)
{
	int head,track,sector,tries, copycount = 0;
	char *p_tbaddr = (char *)0x80000;
	char *p_blockbuff = blockbuff;

	block2hts(block,&head,&track,&sector); /* convert logical address into physical address */
	motoron(); /* spin up the disk */
	if (!cmd_read && blockbuff) {
		/* copy data from data buffer into track buffer */
		for(copycount=0;copycount<(nosectors*FLOPPY_SECTOR_SIZE);copycount++) {
			*p_tbaddr=*p_blockbuff;
			p_blockbuff++;
			p_tbaddr++;
		}
	}
	for (tries=0;tries<3;tries++) {
		if (inportb(FDC_DIR) & 0x80) { /* check for diskchange */
			dchange=1;
			flseek(1);  /* clear "disk change" status */
			recalibrate();
			motoroff();
			return fdc_rw(block, blockbuff, cmd_read, nosectors);
		}
		if (!flseek(track)) {/* move head to right track */
			motoroff();
			return 0;
		}
		outportb(FDC_CCR,0);/* program data rate (500K/s) */
		if (cmd_read) { /* send command */
			dma_xfer(2,tbaddr,nosectors*FLOPPY_SECTOR_SIZE,0);
			sendbyte(CMD_READ);
		} else {
			dma_xfer(2,tbaddr,nosectors*FLOPPY_SECTOR_SIZE,1);
			sendbyte(CMD_WRITE);
		}
		sendbyte(head<<2);
		sendbyte(track);
		sendbyte(head);
		sendbyte(sector);
		sendbyte(2);               /* 512 bytes/sector */
		sendbyte(geometry.spt);
		if (geometry.spt == DG144_SPT) sendbyte(DG144_GAP3RW);  /* gap 3 size for 1.44M read/write */
			else sendbyte(DG168_GAP3RW);  /* gap 3 size for 1.68M read/write */
		sendbyte(0xFF);            /* DTL = unused */
		/* wait for command completion */
		/* read/write don't need "sense interrupt status" */
		if (!waitfdc(1)) {
			reset();
			return fdc_rw(block, blockbuff, cmd_read, nosectors);
		}
		if (!(status[0]&0xC0)) break;   /* worked! outta here! */
		recalibrate();  /* oops, try again... */
	}
	motoroff();
	if (cmd_read && blockbuff) {
		/* copy data from track buffer into data buffer */
		p_blockbuff=blockbuff;
		p_tbaddr = (char *) 0x80000;
		for(copycount=0; copycount<(nosectors*FLOPPY_SECTOR_SIZE);copycount++) {
			*p_blockbuff=*p_tbaddr;
			p_blockbuff++;
			p_tbaddr++;
		}
	}
	return (tries!=3);
}