Exemplo n.º 1
0
void si5338_complete_transfer( uint8_t check_rxack ) {
    if( (IORD_8DIRECT(I2C, OC_I2C_CMD_STATUS)&OC_I2C_TIP) == 0 ) {
        while( (IORD_8DIRECT(I2C, OC_I2C_CMD_STATUS)&OC_I2C_TIP) == 0 ) { } ;
    }
    while( IORD_8DIRECT(I2C, OC_I2C_CMD_STATUS)&OC_I2C_TIP ) { } ;
    while( check_rxack && IORD_8DIRECT(I2C, OC_I2C_CMD_STATUS)&OC_I2C_RXACK ) { } ;
}
Exemplo n.º 2
0
static void readDat(){
	unsigned short accumulatedData = 0;
	int i;
	copyController(&prev_controller_state, controller_state);

	IOWR_8DIRECT(controller_out, 0, 0x01);
	IOWR_8DIRECT(controller_out, 0, 0x03);
	alt_busy_sleep(12);
	IOWR_8DIRECT(controller_out, 0, 0x01);
	alt_busy_sleep(6);

	accumulatedData = IORD_8DIRECT(controller_in, 0);

	for (i = 0; i < 16; i++)
	{
		IOWR_8DIRECT(controller_out, 0, 0x00);
		alt_busy_sleep(6);
		accumulatedData <<= 1;
		accumulatedData += IORD_8DIRECT(controller_in, 0);
		IOWR_8DIRECT(controller_out, 0, 0x01); // Pulse clock
		alt_busy_sleep(6);
	}

	IOWR_8DIRECT(leds, 0, accumulatedData);

	copyController(&controller_state, getControllerButtons(accumulatedData));
}
Exemplo n.º 3
0
int check_switches()
// FUNCTION: Reads the value of all switches
// RETURNS: Value of all switches
{

	return IORD_8DIRECT(SWITCHES_BASE, 0);
}
static int alt_unlock_block_intel(alt_flash_cfi_dev* flash, int block_offset)
{
  alt_u8  locked;
  alt_u8  status;
  int ret_code = 0;
  int timeout = flash->write_timeout * 100;


  /*
  * Is this block locked?
  */
  flash->write_native((alt_u8*)flash->dev.base_addr + block_offset, 0x90);
  locked = IORD_8DIRECT(flash->dev.base_addr, block_offset + 4);
  if (locked & 0x1)
  {
    flash->write_native((alt_u8*)flash->dev.base_addr + block_offset, 0x60);
    flash->write_native((alt_u8*)flash->dev.base_addr + block_offset, 0xD0);

    do
    {
      status = IORD_8DIRECT(flash->dev.base_addr, block_offset);
      if (status & 0x80)
      {
        break;
      }
      timeout--;
      usleep(1);
    }while(timeout > 0);

    if (timeout == 0)
    {
      ret_code = -ETIMEDOUT;
    }
    else if (status & 0x7f)
    {
      /* If we have an error of some kind bomb out */
      ret_code = -EIO;
    }
  }

  /*
  * Back to Read Array mode
  */
  flash->write_native((alt_u8*)flash->dev.base_addr + block_offset, 0xFF);

  return ret_code;
}
/*
 * alt_erase_block_intel
 * 
 * Erase the selected erase block
 */
int alt_erase_block_intel(alt_flash_dev* flash_info, int block_offset)
{
  int   ret_code = 0;
  alt_flash_cfi_dev* flash = (alt_flash_cfi_dev*)flash_info;
  volatile alt_u8  status;
  int   timeout = flash->erase_timeout;

  /*
  * If this block is locked then unlock it
  */
  ret_code = alt_unlock_block_intel(flash, block_offset);

  if (!ret_code)
  {

    flash->write_native((alt_u8*)flash->dev.base_addr + block_offset, 0x20);
    flash->write_native((alt_u8*)flash->dev.base_addr + block_offset, 0xD0);

    do
    {
      status = IORD_8DIRECT(flash->dev.base_addr, block_offset);
      if (status & 0x80)
      {
        break;
      }
      usleep(1);
      timeout--;
    }while(timeout > 0);
    
    if (timeout == 0)
    {
      ret_code = -ETIMEDOUT;
    }
    else if (status & 0x7f)
    {
      /* If we have an error of some kind bomb out */
      ret_code = -EIO;
      status = IORD_8DIRECT(flash->dev.base_addr, block_offset);
    }

    /* Put the device back into read array mode */
    flash->write_native((alt_u8*)flash->dev.base_addr + block_offset, 0xFF);
  }
  
  return ret_code;
}
Exemplo n.º 6
0
/******************************************************************
*  Function: main
*
*  Purpose: Continually prints the menu and performs the actions
*           requested by the user.
* 
******************************************************************/
int main( void )
{
	
	unsigned char ImageData;
	
	int i;
	
	struct BitMapFileHeader header1;
	struct BitMapInfoHeader header2;
	
	unsigned int Offset;
	
	FILE * UartFile;
	
	if( ( UartFile = fopen ( "/dev/uart1", "r" ) ) == NULL )
	{
		
		printf( "Uart open failed!\n" );
		return 0;
		
	}
	
	// waiting for input data
	while( ( ImageData = fgetc( UartFile ) ) == EOF );
	
	printf( "PC -> Target..............\n" );
	
	for( i = 0, Offset = SDRAM_BASE; i < TotalMemory; i ++, Offset ++ )
	{
		
		fscanf( UartFile, "%x", &ImageData );
		IOWR_8DIRECT( SDRAM_BASE, Offset, ImageData );
		
	}
	
	printf( "PC -> Target done\n" );
	
	for( i = 0, Offset = SDRAM_BASE; i < TotalMemory; i ++, Offset ++ )
	{
		
		ImageData = IORD_8DIRECT( SDRAM_BASE, Offset );
		
		if( 0 == i % 16 )
			printf( "\n" );
		
		fprintf( stdout, "%02X ", ImageData );
		
	}
	
	printf( "\nDone\n" );
	
	fclose( UartFile );
	
	return 0;
	
}
Exemplo n.º 7
0
int main()
{
  printf("Hello from cpu_3!\n");
  alt_mutex_dev* mutex = altera_avalon_mutex_open( "/dev/mutex_1" );

  while(TRUE) {
	altera_avalon_mutex_lock( mutex, 1 );
	if (IORD_8DIRECT(FLAG,0) == 1) {
		value=IORD_8DIRECT(VALUE,0);
		printf("Reading from shared memory (safe): %d\n",value);
		IOWR_8DIRECT(VALUE,0,++value);
		IOWR_8DIRECT(FLAG,0,0);
		printf("\tWriting to shared memory (safe): %d\n",value);
	}
	altera_avalon_mutex_unlock( mutex );
	delay(10);
  }

  return 0;
}
Exemplo n.º 8
0
int main()
{
    unsigned char i,j;
    int temp;
    for(i=0;i<100;i++)
        IOWR_8DIRECT(SDRAM_U1_BASE,i,i);
    
    IOWR(SDRAM_MASTER_INST_BASE,S_ADDR,SDRAM_U1_BASE);
    IOWR(SDRAM_MASTER_INST_BASE,D_ADDR,SDRAM_U2_BASE);
    IOWR(SDRAM_MASTER_INST_BASE,LONGTH,100);
    IOWR(SDRAM_MASTER_INST_BASE,START_ADDR,1);
    
    temp=IORD(SDRAM_MASTER_INST_BASE,S_ADDR);
    printf("S_ADDR:w,r==%d,%d\n",SDRAM_U1_BASE,temp);
    temp=IORD(SDRAM_MASTER_INST_BASE,D_ADDR);
    printf("D_ADDR:w,r==%d,%d\n",SDRAM_U2_BASE,temp);    
    temp=IORD(SDRAM_MASTER_INST_BASE,LONGTH);
    printf("LONGTH:w,r==%d,%d\n",100,temp);    
    
    while(IORD(SDRAM_MASTER_INST_BASE,STATUS_ADDR)!=1){
    printf("waiting...!\n");
    //break;
    };
    
    for(i=0;i<100;i++){
        j=IORD_8DIRECT(SDRAM_U1_BASE,i);
        printf("SDRAM_U1:i,j == %d, %d\n",i,j);
    }
    for(i=0;i<100;i++){
        j=IORD_8DIRECT(SDRAM_U2_BASE,i);
        printf("SDRAM_U2:i,j == %d, %d\n",i,j);
    }    
        
    
  printf("Hello from Nios II!\n");

  return 0;
}
Exemplo n.º 9
0
/*
 * get_board_mac_addr
 *
 * Read the MAC address in a board specific way
 *
 */
error_t get_board_mac_addr(unsigned char mac_addr[6])
{
  error_t error = 0;
  alt_u32 signature;

  /* Get the flash sector with the MAC address. */
  error = FindLastFlashSectorOffset(&last_flash_sector_offset);
  if (!error)
    last_flash_sector = CFI_FLASH_BASE + last_flash_sector_offset;
  else
    printf ("Could not locate flash sector with MAC address.\n");

/* This last_flash_sector region of flash is examined to see if 
 * valid network settings are present, indicated by a signature of 0x00005afe at 
 * the first address of the last flash sector.  This hex value is chosen as the 
 * signature since it looks like the english word "SAFE", meaning that it is 
 * safe to use these network address values.  
*/
  ///*
  if (!error)
  {
    signature = IORD_32DIRECT(last_flash_sector, 0);
    if (signature != 0x00005afe)
    {
      error = generate_and_store_mac_addr();
    }
  }
  //*/
//    mac_addr[0] = 0x00;
//    mac_addr[1] = 0x07;
//    mac_addr[2] = 0xed;
//    mac_addr[3] = 0x12;
//    mac_addr[4] = 0x8f;
//    mac_addr[5] = 0xff;
  if (!error)
  {
    mac_addr[0] = IORD_8DIRECT(last_flash_sector, 4);
    mac_addr[1] = IORD_8DIRECT(last_flash_sector, 5);
    mac_addr[2] = IORD_8DIRECT(last_flash_sector, 6);
    mac_addr[3] = IORD_8DIRECT(last_flash_sector, 7);
    mac_addr[4] = IORD_8DIRECT(last_flash_sector, 8);
    mac_addr[5] = IORD_8DIRECT(last_flash_sector, 9);
    
    printf("Your Ethernet MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n", 
            mac_addr[0],
            mac_addr[1],
            mac_addr[2],
            mac_addr[3],
            mac_addr[4],
            mac_addr[5]);

  }

  return error;
}
Exemplo n.º 10
0
void si5338_read( uint8_t addr, uint8_t *data ) {

    // Set the address to the Si5338
    IOWR_8DIRECT(I2C, OC_I2C_DATA, SI5338_I2C ) ;
    IOWR_8DIRECT(I2C, OC_I2C_CMD_STATUS, OC_I2C_STA | OC_I2C_WR ) ;
    si5338_complete_transfer( 1 ) ;

    IOWR_8DIRECT(I2C, OC_I2C_DATA, addr ) ;
    IOWR_8DIRECT(I2C, OC_I2C_CMD_STATUS, OC_I2C_WR | OC_I2C_STO ) ;
    si5338_complete_transfer( 1 ) ;

    // Next transfer is a read operation, so '1' in the read/write bit
    IOWR_8DIRECT(I2C, OC_I2C_DATA, SI5338_I2C | 1 ) ;
    IOWR_8DIRECT(I2C, OC_I2C_CMD_STATUS, OC_I2C_STA | OC_I2C_WR ) ;
    si5338_complete_transfer( 1 ) ;

    IOWR_8DIRECT(I2C, OC_I2C_CMD_STATUS, OC_I2C_RD | OC_I2C_NACK | OC_I2C_STO ) ;
    si5338_complete_transfer( 0 ) ;

    *data = IORD_8DIRECT(I2C, OC_I2C_DATA) ;
    return ;
}
//------------------------------------------------------------------------------
int target_lock(void)
{
    alt_u8  val;

    if (pLock_l == NULL)
        return -1;

    // spin if id is not written to shared memory
    do
    {
        val = IORD_8DIRECT(pLock_l, 0);

        // write local id if unlocked
        if (val == LOCK_UNLOCKED_C)
        {
            IOWR_8DIRECT(pLock_l, 0, LOCK_LOCAL_ID);
            continue; // return to top of loop to check again
        }
    } while (val != LOCK_LOCAL_ID);

    return 0;
}
int alt_write_word_intel( alt_flash_cfi_dev* flash, 
                                  const int offset, const alt_u8* src_addr)
{ 
  int ret_code = 0;
  alt_u8 status;
  (*flash->write_native)((alt_u8*)flash->dev.base_addr+offset, 0x40);
  alt_write_value_to_flash(flash, offset, src_addr);

  do
  {
    status = IORD_8DIRECT(flash->dev.base_addr, offset);
  }while(!(status & 0x80));

  /* If we have an error of some kind bomb out */
  if (status & 0x7f)
  {
    ret_code = -EIO;
  }

  /* Put the device back into read array mode */
  flash->write_native((alt_u8*)flash->dev.base_addr + offset, 0xFF);
  
  return ret_code;
}
Exemplo n.º 13
0
/*
* get_board_mac_addr
*
* Read the MAC address in a board specific way
*
*/
error_t get_board_mac_addr(unsigned char mac_addr[6])
{
  error_t error = 0;

  alt_u32 signature;
  alt_u32 mac_addr_ptr = EXT_FLASH_BASE + ETHERNET_OPTION_BITS;
  
/* This last_flash_sector region of flash is examined to see if 
 * valid network settings are present, indicated by a signature of 0x00005afe at 
 * the first address of the last flash sector.  This hex value is chosen as the 
 * signature since it looks like the english word "SAFE", meaning that it is 
 * safe to use these network address values.  
*/

  /* Get the flash sector with the MAC address. */
  signature = IORD_32DIRECT(mac_addr_ptr, 0);
    
  if (signature != 0x00005afe)
  {
    error = generate_and_store_mac_addr();
  }
  
  if (!error)
  {
    mac_addr[0] = IORD_8DIRECT(mac_addr_ptr, 4);
    mac_addr[1] = IORD_8DIRECT(mac_addr_ptr, 5);
    mac_addr[2] = IORD_8DIRECT(mac_addr_ptr, 6);
    mac_addr[3] = IORD_8DIRECT(mac_addr_ptr, 7);
    mac_addr[4] = IORD_8DIRECT(mac_addr_ptr, 8);
    mac_addr[5] = IORD_8DIRECT(mac_addr_ptr, 9);
    
    printf("Your Ethernet MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n", 
            mac_addr[0],
            mac_addr[1],
            mac_addr[2],
            mac_addr[3],
            mac_addr[4],
            mac_addr[5]);

  }

  return error;
}
Exemplo n.º 14
0
/******************************************************************
*  Function: MemTest8_16BitAccess
*
*  Purpose: Tests that the memory at the specified base address
*           can be read and written in both byte and half-word 
*           modes.
*
******************************************************************/
static int MemTest8_16BitAccess(unsigned int memory_base)
{
  int ret_code = 0x0;

  /* Write 4 bytes */
  IOWR_8DIRECT(memory_base, 0, 0x0A);
  IOWR_8DIRECT(memory_base, 1, 0x05);
  IOWR_8DIRECT(memory_base, 2, 0xA0);
  IOWR_8DIRECT(memory_base, 3, 0x50);

  /* Read it back as one word */
  if(IORD_32DIRECT(memory_base, 0) != 0x50A0050A)
  {
    ret_code = memory_base;
  }

  /* Read it back as two half-words */
  if (!ret_code)
  {
    if ((IORD_16DIRECT(memory_base, 2) != 0x50A0) ||
        (IORD_16DIRECT(memory_base, 0) != 0x050A))
    {
      ret_code = memory_base;
    }
  }

  /* Read it back as 4 bytes */
  if (!ret_code)
  {
    if ((IORD_8DIRECT(memory_base, 3) != 0x50) ||
        (IORD_8DIRECT(memory_base, 2) != 0xA0) ||
        (IORD_8DIRECT(memory_base, 1) != 0x05) ||
        (IORD_8DIRECT(memory_base, 0) != 0x0A))
    {
    ret_code = memory_base;
    }
  }

  /* Write 2 half-words */
  if (!ret_code)
  {
    IOWR_16DIRECT(memory_base, 0, 0x50A0);
    IOWR_16DIRECT(memory_base, 2, 0x050A);

    /* Read it back as one word */
    if(IORD_32DIRECT(memory_base, 0) != 0x050A50A0)
    {
      ret_code = memory_base;
    }
  }

  /* Read it back as two half-words */
  if (!ret_code)
  {
    if ((IORD_16DIRECT(memory_base, 2) != 0x050A) ||
        (IORD_16DIRECT(memory_base, 0) != 0x50A0))
    {
      ret_code = memory_base;
    }
  }

  /* Read it back as 4 bytes */
  if (!ret_code)
  {
    if ((IORD_8DIRECT(memory_base, 3) != 0x05) ||
        (IORD_8DIRECT(memory_base, 2) != 0x0A) ||
        (IORD_8DIRECT(memory_base, 1) != 0x50) ||
        (IORD_8DIRECT(memory_base, 0) != 0xA0))
    {
      ret_code = memory_base;
    }
  }

  return(ret_code);
}
Exemplo n.º 15
0
int main()
{
	int i,k,ipl_mode=1;
	//UINT r;

	// Initialize Disk I/F and ROM
	System_Initialize();

	/* Event loop never exits. */
	while (1){
		// IPL
		if(ipl_mode==1){
			// System Program Load
			IPL();
			// Start MZ
			MZ_release();
			ipl_mode=0;
		}

		// CMT Control
		if((z80_sts.status&S_CMT)==S_CMT){
			z80_sts.status&=~S_CMT;
			// Eject and Set Tape
			if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_OPEN)==C_OPEN){
				IOWR_8DIRECT(REG_BASE, MZ_CMT_STATUS, C_OPEN);
				tape_unmount();
				fname[0]='\0';
				key0(settape);
				z80_sts.status|=S_FBTN;	// Set Flag
				MZ_Brequest();
				menu_process();
				MZ_Brelease();
				z80_sts.status&=~S_FBTN;	// Clear Flag
			}
			// Load
			if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_PLAY)==C_PLAY){
				IOWR_8DIRECT(REG_BASE, MZ_CMT_STATUS, C_PLAY);
				IOWR_8DIRECT(REG_BASE, MZ_CMT_CTRL, C_MTON+C_TAPE);	// Motor On
				cmtload();
			}
			// Rewind
			if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_REW)==C_REW){
				if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_APSS)==C_APSS){
					apss_r();
				} else {
					tape_rewind();
					IOWR_8DIRECT(REG_BASE, MZ_CMT_STATUS, C_REW);
				}
			}
			// F.Forward
			if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_FF)==C_FF){
				if((IORD_8DIRECT(REG_BASE, MZ_CMT_STATUS)&C_APSS)==C_APSS){
					apss_f();
				} else {
					IOWR_8DIRECT(REG_BASE, MZ_CMT_STATUS, C_FF);
				}
			}
		}

		// Function Button
		if((z80_sts.status&S_FBTN)==S_FBTN){
			MZ_Brequest();
			menu_process();
			MZ_Brelease();
			z80_sts.status&=~S_FBTN;
		}

		// BST check
		if((IORD_8DIRECT(REG_BASE, MZ_SYS_STATUS)&S_BST)==S_BST){
			ipl_mode=1;
		}

		// Quick Load/Save
//		if((z80_sts.status&0x02)==0x02){
//			if(IORD(CMT_0_BASE, 3)==0x0f){	// CMD is Load
//				IOWR(CMT_0_BASE, 2, 0x80);	// set STAT busy

				// Wait for confirm busy by Z80
//				while(IORD(CMT_0_BASE, 3)!=0);

//				if(tname[0]=='\0'){	// if tape file is empty
//					z80_sts.status=0x03;
//					// Z80-Bus request
//					MZ_Brequest();
//					key0(settape);
//					k=menu(0,0,0);	// Root menu
//					// Z80-Bus release
//					MZ_Brelease();
//					z80_sts.status=0x02;
//					if(k!=10){
//						z80_sts.status=0;
//						IOWR(CMT_0_BASE, 2, 0xff);	// set STAT error
//						continue;
//					}
//					//keybuf_clear();
//					strcpy(tname, fname);
//					IOWR(CMT_0_BASE, 1, 1);
//					ql_pt=0;
//				}

//				quick_load();
//				IOWR(CMT_0_BASE, 2, 0);	// set STAT free
//				z80_sts.status&=0xfffffffd;
//			}

//			if(IORD(CMT_0_BASE, 3)==0xf0){	// CMD is Save
//				IOWR(CMT_0_BASE, 2, 0x80);	// set STAT busy

//				// Wait for confirm busy by Z80
//				while(IORD(CMT_0_BASE, 3)!=0);

//				if(tname[0]=='\0'){	// if tape file is empty
//					// Z80-Bus request
//					MZ_Brequest();
//					i=input_file_name();
//					// Z80-Bus release
//					MZ_Brelease();
//					if(tname[0]=='\0'||i<0){
//						z80_sts.status=0;
//						IOWR(CMT_0_BASE, 2, 0xff);	// set STAT error
//						continue;
//					}
//					keybuf_clear();
//					IOWR(CMT_0_BASE, 1, 1);
//				}

//				if(quick_save()!=FR_OK)
//					IOWR(CMT_0_BASE, 2, 0xff);	// set STAT error
//				else
//					IOWR(CMT_0_BASE, 2, 0);	// set STAT free
//				z80_sts.status&=0xfffffffd;
//			}
// 		}
	}

	return 0;
}
Exemplo n.º 16
0
/*
 * IPL Emulation
 */
void IPL(void)
{
	UINT size,record,i,silent_boot,l_track;
	int length;
	unsigned char k;

	// Enter Boot Mode
	MZ_BOOT();
	MZ_cls();
	fname[0]='\0';
	// disk already exists
	if(dname[0][0]=='\0')
		silent_boot=0;
	else
		silent_boot=1;

	if(IORD_8DIRECT(REG_BASE, MZ_SYS_SW70)&0x10){
		IPL_from_tape();
	} else {
		// Boot from FD or CMT
		if(silent_boot==0){
			MZ_msg(10,0,"Make Ready FD");
		}

		while(1){
			if(silent_boot==0){
				MZ_msg(10,2,"Press F or C");
				MZ_msg(11,4,"F:Floppy Disk");
				if(!(IORD_8DIRECT(REG_BASE, MZ_SYS_SW98)&0x2)) MZ_msg(24,4,"ette");
				MZ_msg(11,5,"C:Cassette Tape");
			}
			while(1){
				if(silent_boot==0){
					if((z80_sts.status&S_FBTN)==S_FBTN){
						SaveVRAM();
						menu_process();
						z80_sts.status&=~S_FBTN;	// Clear Flag
						RestoreVRAM();
					}
					k=get_key();
				}else{
					k='F';
				}
				if((k&'C')=='C'){
					if(IPL_from_tape()==0) return; else break;
				}
				if((k&'F')=='F'){
					if(silent_boot==0){
						MZ_cls();
						MZ_msg(10,2,"Drive No? (1-4)");
						do{ k=get_key(); }while(k<'1' || k>'4');
						MZ80B_MEM(0x7fec)=k-'1';
						if((k=='1'&&dname[0][0]=='\0')||(k=='2'&&dname[1][0]=='\0')||k=='3'||k=='4'){
							MZ_cls();
							MZ_msg(10,0,"Loading error");
							break;
						}
					}else{
						k='1';
					}
					read_1sector(k-'1', 0, &MZ80B_MEM(0x4f00), &l_track);
					if(MZ80B_MEM(0x4f00)==0x01&&strncmp((char *)&MZ80B_MEM(0x4f01), "IPLPRO", 6)==0){
						MZ_cls();
						MZ_msg(0,0,"IPL is loading ");
						MZ_msgx(16,0,(char *)&MZ80B_MEM(0x4f07),10);
						size=(MZ80B_MEM(0x4f15)<<8)+MZ80B_MEM(0x4f14);
						record=(MZ80B_MEM(0x4f1f)<<8)+MZ80B_MEM(0x4f1e);
						for(i=0;i<size;i+=length){
							length=read_1sector(k-'1', record++, &MZ80B_MEM(i), &l_track);
							if(length<0) break;
						}
						if(length>0){
							d_tnum[k-'1']=l_track/2;
							track_setting(k-'1', l_track/2);
							return;
						}
					}
					MZ_cls();
					MZ_msg(7,0,"This disk is not master");
					silent_boot=0;
					break;
				}
			}
		}

	}

}
Exemplo n.º 17
0
/*
 * IPL Emulation(CMT only)
 */
int IPL_from_tape(void)
{
	UINT size;
	unsigned char k;

	MZ_cls();
	t_block=0;

	// Select Tape file
	if(tname[0]=='\0'){
		MZ_msg(10,0,"Make Ready CMT");

		do{
			k=get_key();
			if((k&'C')=='C'){
				key0(settape);
				z80_sts.status|=S_FBTN;	// Set Flag
			}else if(k==0x1b&&!(IORD_8DIRECT(REG_BASE, MZ_SYS_SW70)&0x10)){
				return -1;
			}else if((z80_sts.status&S_FBTN)!=S_FBTN){
				continue;
			}
			SaveVRAM();
			menu_process();
			z80_sts.status&=~S_FBTN;	// Clear Flag
			RestoreVRAM();
		}while(fname[0]=='\0');

		tape_mount();
	}

	while(1){
		// File Read
		MZ_msg(4,0,"IPL is looking for a program");
		usleep(500000);
		tape_rdinf_bulk(&MZ80B_MEM(0x4f00));
		MZ_cls();
		MZ_msg(0,0,"IPL is loading ");
		MZ_msgx(16,0,(char *)&MZ80B_MEM(0x4f01),16);
		if((MZ80B_MEM(0x4f00))==0x01) break;
		MZ_cls();
		MZ_msg(10,0,"File Mode error");
		tape_unmount();
		fname[0]='\0';
		if(!(IORD_8DIRECT(REG_BASE, MZ_SYS_SW70)&0x10)) return -1;
		MZ_msg(4,2,"Pressing S key starts the CMT");
		while(1){
			if((get_key()&'S')=='S'){
				if(fname[0]!='\0') break;
			}else if((z80_sts.status&S_FBTN)==S_FBTN){
				SaveVRAM();
				menu_process();
				z80_sts.status&=~S_FBTN;	// Clear Flag
				RestoreVRAM();
			}
		}
		MZ_cls();
	}

	size=(MZ80B_MEM(0x4f13)<<8)+MZ80B_MEM(0x4f12);
	tape_rddat_bulk(&MZ80B_MEM(0),size);
	return 0;
}
Exemplo n.º 18
0
void System_Initialize(void)
{
	char SecName[8],buffer[512],data[4096];
	unsigned char *cgrom,*keymap;
	int k;
	UINT i,r;
	ROMS_t *romdata=(ROMS_t *)(CFI_BASE+0x100000);

	// Interrupt regist
	int_regist();

	sd_mount();
	tname[0]='\0'; dname[0][0]='\0'; dname[1][0]='\0';

	// Clear VRAM
	for(i=0;i<1000;i++)
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+i, 0);
	// Clear GRAM
	for(i=0;i<65536;i++)
		MZ80B_GRAM(i)=0;
	cgrom=romdata->char80b;
	keymap=romdata->key80b;
	// CG ROM
	for(i=0;i<2048;i++){	// (0xc800-0xcfff)
		IOWR_8DIRECT(REG_BASE, MZ_CGROM+i, cgrom[i]);
	}
	// Key Map Data
	for(i=0;i<256;i++){	// (0xc000-0xc0ff)
		IOWR_8DIRECT(REG_BASE, MZ_KMAP+i, keymap[i]);
	}

	if(IORD_8DIRECT(REG_BASE, MZ_SYS_SW70)&0x20){
		// Select Section Name by MZ mode
		if((IORD_8DIRECT(REG_BASE, MZ_SYS_SW98)&0x2))
			strcpy(SecName, "MZ-2000");
		else
			strcpy(SecName, "MZ-80B");

		// CG ROM
		GetPrivateProfileString(SecName, "CGROM", "NULL", buffer, "system.ini");
		if(strcmp(buffer,"NULL")==0)
			GetPrivateProfileString("COMMON", "CGROM", "NULL", buffer, "system.ini");
		if(strcmp(buffer,"NULL")!=0){
			file_bulk_read(buffer, data, 2048);
			for(i=0;i<2048;i++){	// (0xc800-0xcfff)
				IOWR_8DIRECT(REG_BASE, MZ_CGROM+i, data[i]);
			}
		}
		// Key Map Data
		GetPrivateProfileString(SecName, "KEYMAP", "NULL", buffer, "system.ini");
		if(strcmp(buffer,"NULL")==0)
			GetPrivateProfileString("COMMON", "KEYMAP", "NULL", buffer, "system.ini");
		if(strcmp(buffer,"NULL")!=0){
			file_bulk_read(buffer, data, 256);
			for(i=0;i<256;i++){	// (0xc000-0xc0ff)
				IOWR_8DIRECT(REG_BASE, MZ_KMAP+i, data[i]);
			}
		}
	}

}
Exemplo n.º 19
0
Arquivo: main.c Projeto: karfair/doge
int main(){
	printf("NEW GAME!\n\n");

	volatile int old_game_state = 0;
	int doge = 0; //animation counter

	//buffer init stuff
	pixel_buffer = alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma");
	char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer");

	//phil's stuff
	master* m = master_init();

	printf("NEW GAME!\n\n");

	// Set the 1st buffer address
	alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr1);
	// Swap buffers – we have to swap because there is only an API function
	// to set the address of the background buffer.
	alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
	while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer));
	// Set the 2nd buffer address
	alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr2);

	printf("NEW GAME!\n\n");

	// Clear the screen
	alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1);
	alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
	while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer));
	alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1);
	alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
	while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer));

	alt_up_char_buffer_clear(char_buffer);
	//Write some text
	alt_up_char_buffer_string(char_buffer, "LOADING...", 0, 0);

	//load bitmap files
	title = read_bmp("title.bmp");
	alt_up_char_buffer_string(char_buffer, "title.bmp", 0, 2);

	menu = read_bmp("menu.bmp");
	alt_up_char_buffer_string(char_buffer, "MENU.BMP", 0, 3);

	selA = read_bmp("selA.bmp");
	alt_up_char_buffer_string(char_buffer, "selA.bmp", 0, 4);

	selB = read_bmp("selB.bmp");
	alt_up_char_buffer_string(char_buffer, "selB.bmp", 0, 5);

	selC = read_bmp("selC.bmp");
	alt_up_char_buffer_string(char_buffer, "selC.bmp", 0, 6);

	dead = read_bmp("dead.bmp");
	alt_up_char_buffer_string(char_buffer, "dead.bmp", 0, 7);



	bmp * b 	= read_bmp("para1.bmp");
	alt_up_char_buffer_string(char_buffer, "para.bmp", 0, 8);

	bmp * doge0 = read_bmp("doge0.bmp");
	alt_up_char_buffer_string(char_buffer, "doge0.bmp", 0, 9);

	bmp * doge1 = read_bmp("doge1.bmp");
	alt_up_char_buffer_string(char_buffer, "doge1.bmp", 0, 10);

	bmp * doge2 = read_bmp("doge2.bmp");
	alt_up_char_buffer_string(char_buffer, "doge2.bmp", 0, 11);

	bmp * doge3 = read_bmp("doge3.bmp");
	alt_up_char_buffer_string(char_buffer, "doge3.bmp", 0, 12);

	bmp * flat  = read_bmp("flat.bmp");
	alt_up_char_buffer_string(char_buffer, "flat.bmp", 0, 13);

	bmp * coin  = read_bmp("coin.bmp");
	alt_up_char_buffer_string(char_buffer, "coin.bmp", 0, 14);

	bmp * spike = read_bmp("spike.bmp");
	alt_up_char_buffer_string(char_buffer, "spike.bmp", 0, 15);

	bmp * box1  = read_bmp("box1.bmp");
	alt_up_char_buffer_string(char_buffer, "box1.bmp", 0, 16);

	bmp * box3  = read_bmp("box3.bmp");
	alt_up_char_buffer_string(char_buffer, "box3.bmp", 0, 17);

	bmp * low  = read_bmp("low.bmp");
	alt_up_char_buffer_string(char_buffer, "low.bmp", 0, 18);

	bmp * flatb = read_bmp("flatb.bmp");
	alt_up_char_buffer_string(char_buffer, "flatb.bmp", 0, 19);

	bmp * flatr = read_bmp("flatr.bmp");
	alt_up_char_buffer_string(char_buffer, "flatr.bmp", 0, 20);

	bmp * blue = read_bmp("bstar.bmp");
	alt_up_char_buffer_string(char_buffer, "blue.bmp", 0, 21);

	bmp * red = read_bmp("rstar.bmp");
	alt_up_char_buffer_string(char_buffer, "red.bmp", 0, 22);

	bmp * flag_img = read_bmp("flag.bmp");
	alt_up_char_buffer_string(char_buffer, "flag.bmp", 0, 23);

	name = read_bmp("name.bmp");
	alt_up_char_buffer_string(char_buffer, "name.bmp", 0, 24);

	instr = read_bmp("instr.bmp");
	alt_up_char_buffer_string(char_buffer, "instr.bmp", 0, 25);

	dcol = read_bmp("dcol.bmp");
	alt_up_char_buffer_string(char_buffer, "dcol.bmp", 0, 26);

	win = read_bmp("win.bmp");
	alt_up_char_buffer_string(char_buffer, "win.bmp", 0,27);



	alt_up_char_buffer_clear(char_buffer);



	printf("NEW GAME!\n\n");

	//interrupt init stuff (for object writing)
	//TIMERPERIOD
	int timer_period = 1 * 500000;
	IOWR_16DIRECT(TIMER_0_BASE, 8, timer_period & 0xFFFF); //writes the period to the hardware timer
	IOWR_16DIRECT(TIMER_0_BASE, 12, timer_period >> 16);
	IOWR_16DIRECT(TIMER_0_BASE, 4, 1 << 3); //stop timer
	alt_irq_register(TIMER_0_IRQ,NULL,(void*)handle_timer_interrupts);//registers function to a specific IRQ
	//IOWR_16DIRECT(TIMER_0_BASE, 4, 0x5); //start timer

	//SET UP KEYBOARD INTERRUPT//
	ps2 = alt_up_ps2_open_dev(KEYBOARD_NAME);
	alt_up_ps2_init(ps2);
	alt_up_ps2_clear_fifo(ps2);
	//void* keyboard_control_register_ptr = (void*) (PS2_0_BASE + 4);
	alt_irq_register(PS2_0_IRQ, m, keyboard_ISR);
	alt_up_ps2_enable_read_interrupt(ps2);

	char sw = 0;
	char p_sw = 0;


/////////////////////////////////////////////////////////////////////////
	printf("NEW GAME!\n\n");
	//SUPERDUPERLOOP
	while (1){

		printf("old state:%i\nnew state: %i\n\n",old_game_state, game_state);

		draw_menu(game_state);					//update screen

		while (old_game_state == game_state);

		printf("old state:%i\nnew state: %i\n\n",old_game_state, game_state);	//only when entering a new menu
		alt_up_char_buffer_clear(char_buffer);


		//ENTER GAME LOOP
		if (game_state == 5){

			printf("START GAME! LEVEL: %i\n\n", highlighted_level);
			alt_up_char_buffer_string(char_buffer, playername, 10, 4);

			if (highlighted_level == 1)
			{
				free_bmp(b);
				b = read_bmp("para1.bmp");
				game_start(m,b,"lvl/1.txt","song1.wav");
			}
			else if (highlighted_level == 2) {
				free_bmp(b);
				b = read_bmp("bg2.bmp");
				game_start(m,b,"lvl/2.txt","a/abcd.wav");
			}
			else{
				free_bmp(b);
				b = read_bmp("bg3.bmp");
				game_start(m,b,"lvl/2.txt","a/nyan1.wav");
			}


			//collision loop
			while(!m->c->collide && !m->c->win){
				alt_up_char_buffer_string(char_buffer, "POINTS: ", 50, 4);
				char str[15];
				sprintf(str, "%d", m->c->points);
				alt_up_char_buffer_string(char_buffer, str, 58, 4);

				sw = IORD_8DIRECT(SWITCHES_BASE,0);
				IOWR_8DIRECT(LEDS_BASE,0,sw);

				if(sw == 1 && p_sw == 0){
					//m->ab->sfx_flag = 1;
					m->c->jump_pressed = 1;
				}

				p_sw = sw;

				//boxes
				int i;
				for( i= 0 ; i < OBJECT_SIZE ; i++) {
					if(m->o->color[i] == -1)
						draw_object(pixel_buffer, box, flat, i);
					else if(m->o->color[i] == 0)
						draw_object(pixel_buffer, box, flatb, i);
					else if(m->o->color[i] == 1)
						draw_object(pixel_buffer, box, flatr, i);
					draw_object(pixel_buffer, co, coin, i );
					draw_object(pixel_buffer, spikes, spike, i);
					draw_object(pixel_buffer, box_3, box3, i);
					draw_object(pixel_buffer, box_1, box1, i);
//								if(m->color_gates->color[i] == 1)
//									draw_object(pixel_buffer,cgates, rgate,i);
//								else if (m->color_gates->color[i] == 0)
//									draw_object(pixel_buffer,cgates, bgate,i);
				}
				//draws the win flag
				draw_object(pixel_buffer, flag, flag_img, 0);

				//Draw Doge
				if (m->c->ducking)
					draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,low);
				else{
					doge++;
					if(doge == 37) doge = 0;

					if( doge <9)
						draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge0);
					else if (doge <18)
						draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge1);
					else if (doge <27)
						draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge2);
					else
						draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge3);
				}


				//Draw Color Indicator
				if(m->c->color == 0)
					draw_bmp(pixel_buffer, m->c->x- m->c->width + 5, m->c->y - m->c->height - 10, blue);
				else
					draw_bmp(pixel_buffer,m->c->x- m->c->width + 5, m->c->y - m->c->height - 10, red);

				p_counter++;
				if(p_counter == 3){
					p_shift++;
					alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
					while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer))
						refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer
					unrolled_parallax_draw(pixel_buffer, b);

				}else if(p_counter == 4){ //if(p_counter == 1){
					alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
					while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer))
						refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer
					unrolled_parallax_draw(pixel_buffer, b);
					p_counter = 0;


				}else{
//					alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
//					while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer))
//						refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer
//					unrolled_parallax_draw(pixel_buffer, b);

					alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
					while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer))
						refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer

					int j; for( j = 0 ; j < OBJECT_SIZE ; j++) {
						clear_object(pixel_buffer,  box,  b, j);
						clear_object(pixel_buffer,  co,  b, j);
						clear_object(pixel_buffer,  spikes,  b, j);
						clear_object(pixel_buffer,  box_3,  b, j);
						clear_object(pixel_buffer,  box_1,  b, j);
					}
					clear_object(pixel_buffer,flag,b,0);

					//clear doge
					clear_doge(pixel_buffer, m->c->x - m->c->width, m->c->y - m->c->height , b);
					//clear_loc(pixel_buffer,m->c->x- m->c->width + 5, m->c->y - m->c->height - 10,m->c->x- m->c->width + 5 - 10, m->c->y - m->c->height - 20,b);

				}





			}
			alt_up_char_buffer_string(char_buffer, "POINTS: ", 50, 4);
			char str[15];
			sprintf(str, "%d", m->c->points);
			alt_up_char_buffer_string(char_buffer, str, 58, 4);

			printf("game exited\n");
			if(m->c->win)
				game_state  = 7;
			else
				game_state  = 6;

			highlighted_item = 3;

			game_reset(m);
		}



		//exit game mode, restart superduperloop in main menu
		old_game_state = game_state;
	}

	return 0;
}
Exemplo n.º 20
0
int main()
{

	IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0);
	int dir = 0;
	int posX = doubleToInt(21.5), posY = doubleToInt(11.5);  //x and y start position
 // int posX = 22, posY = 11;  //x and y start position
  int x =0;

  int p, q;


  IOSKYWR_RAM_DATA(SKYGEN_0_BASE, 262143, 0x0000);

  for(p = 0; p < 480; p++){
	  for(q = 0; q < 512; q++)
	  {

		  IOSKYWR_RAM_DATA(SKYGEN_0_BASE, p*512+q, (sky[p*1024+q*2+1]<<8) + (sky[p*1024+q*2]));

	  }
  }

  IOSKYWR_RAM_DATA(SKYGEN_0_BASE, 262143, 0x000F);
  double sine_temp;
  double cosine_temp;

	for(x = 0; x < lookupLength ; x++)
	{
			//calculate ray position and direction

		sine_temp = sin(x*RAD + HALF_RAD);
		cosine_temp = cos(x*RAD + HALF_RAD);

		dirsine[x] = doubleToInt(sin(x*RAD));
		dircosine[x] = doubleToInt(cos(x*RAD));
		sine[x] = doubleToInt(sine_temp);
		cosine[x] = doubleToInt(cosine_temp);
	}


  int angle;
  int fish_angle;
  int move;

  int rayDirX;
  int rayDirY;
  int count_step;

  int k;
  int k2;
  int forward = 0;
  int backward = 0;
  int left = 0;
  int right = 0;
  //char key[] = { 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d',
//		  'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d'};

  unsigned char code = 0;
  //char key[] = {'d'};
  k2 = 0;
  //start the main loop
  //for (k2 = 0; k2 < sizeof(key); k2++)

  int hardwareData = 0;

  while(1)
  {

	  code = 0;

		//while (!IORD_8DIRECT(DE2_PS2_0_BASE, 0)) ; /* Poll the status */

//		code = IORD_8DIRECT(DE2_PS2_0_BASE, 0);

//		if (code)


	//printf("%c, %x, %d\n", code, code, code);

		/* Get received byte */

	  //code = 'k';

	  //hardwareData = IORD_RAM_DATA(NIOSINTERFACE_1_0_BASE, 1);
	  //printf("%d\n", hardwareData >> 4);

	  code = IORD_8DIRECT(DE2_PS2_1_BASE, 1);

	  switch(code)
	  {
	  	  case 'u':
	  		  forward = 1;
	  		  backward = 0;
	  		  break;
	  	  case 'r':
	  		  forward = 0;
	  		  backward = 1;
	  		  break;
	  	  case 't':
	  		  right = 1;
	  		  left = 0;
	  		  break;
	  	  case 'k':
	  		  left = 1;
	  		  right = 0;
	  		  break;
	  	  case 'U':
	  		  forward = 0;
	  		  break;
	  	  case 'R':
	  		  backward = 0;
	  		  break;
	  	  case 'T':
	  		  right = 0;
	  		  break;
	  	  case 'K':
	  		  left = 0;
	  		  break;

	  	  case ')':
	  		forward = 0;
	  		backward = 0;
	  		right = 0;
	  		left = 0;
	  		break;

	  }

     x = 0;
    for(k = -halfScreenWidth; k < halfScreenWidth; k++)
    {
        angle = dir + k;

        if ( angle < 0)
                angle += lookupLength;

        if (angle >= lookupLength)
                angle -= lookupLength;

        fish_angle = k;

        if ( fish_angle < 0)
            fish_angle += lookupLength;

        if (fish_angle >= lookupLength)
             fish_angle -= lookupLength;


      //calculate ray position and direction
      //double cameraX = 2*x/double(w)-1; //x-coordinate in camera space
      rayDirX = cosine[angle]>>extensionFactor;
      rayDirY = sine[angle]>>extensionFactor;
      count_step = cosine[fish_angle]>>extensionFactor;

      //using a happy medium between 1/32 and 1/64 ray extension increment
//      rayDirX = (cosine[angle]>>6)+(cosine[angle]>>7);
//      rayDirY = (sine[angle]>>6) +(sine[angle]>>7);
//      count_step = (cosine[fish_angle]>>6) +(cosine[fish_angle]>>7);


 //     hardwareData = IORD_32DIRECT(NIOSINTERFACE_1_0_BASE, 1);
    //  printf("%d\n", hardwareData);
     DrawAccelerate(angle, posX, posY, count_step, rayDirX, rayDirY, x);
     IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0);

     hardwareData = IORD_32DIRECT(NIOSINTERFACE_1_0_BASE, 1);

	 while (!(hardwareData & 1)){
		 hardwareData = IORD_32DIRECT(NIOSINTERFACE_1_0_BASE, 1);
	  }


      //IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0);

      IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0xFFFFFFFF);



//	  printf("out of loop\n");
	  //IOWR_RAM_DATA(NIOSINTERFACE_0_BASE, 0, 0);

//	  int rayPosX = posX;
//	  int rayPosY = posY;
//	  int count = 0;
//      int mapX;
//      int mapY;
//
//      //what direction to step in x or y-direction (either +1 or -1)
//      int stepX;
//      int stepY;
//
//      int hit = 0; //was there a wall hit?
//      unsigned int side = 0; //was a NS or a EW wall hit?
//
//      //calculate step and initial sideDist
//      if (rayDirX < 0)
//         stepX = -1;
//      else
//         stepX = 1;
//
//      if (rayDirY < 0)
//         stepY = -1;
//      else
//         stepY = 1;
//
//
//      while ( worldMap[rayPosX>>posShift][rayPosY>>posShift] == 0)
//      {
//        count += count_step;
//
//        //jump to next map square, OR in x-direction, OR in y-direction
//        rayPosX += rayDirX;
//        rayPosY += rayDirY;
//
//        //Check if ray has hit a wall
//      }
//
//      hit = 1;
//      ////////////////////////////////////////////////////////////////////////
//      /////LOOOP BACK CODE FOR SMOOTHER EDGES AND FASTER SPEEDS///////////////
//
//      count_step = count_step>>4;
//      rayDirX = rayDirX>>4;
//      rayDirY = rayDirY>>4;
//
//      while(hit == 1)
//      {
//
//        count -= count_step;
//
//        //jump to next map square, OR in x-direction, OR in y-direction
//        rayPosX -= rayDirX;
//        rayPosY -= rayDirY;
//
//        //Check if ray has hit a wall
//        if (worldMap[rayPosX>>posShift][rayPosY>>posShift] == 0) hit = 0;
//
//      }
//
//      count += count_step;
//      rayPosX += rayDirX;
//      rayPosY += rayDirY;
//
//      ////////////////////////////////////////////////////////////////////////
//      ////////////////////////////////////////////////////////////////////////
//
//      mapX = ((rayPosX>>posShift)  + ((1 - stepX)>>1))<<posShift;
//      mapY = ((rayPosY>>posShift)  + ((1 - stepY)>>1))<<posShift;
//
//      //Calculate distance of perpendicular ray (oblique distance will give fisheye effect!)
//      if ( absVal(mapX - rayPosX) <  absVal(mapY - rayPosY) )
//          side  = 1;
//
//
//      //Calculate height of line to draw on screen
//      //int lineHeight = abs( (screenHeight<<posShift) /count);
//      int lineHeight = (screenHeight<<posShift) /count;
//      //printf("lineHeight= %d", lineHeight);
////      if (lineHeight >= screenHeight){
////    	  lineHeight = 0x1FF;
////    	  //printf(" lineHeight= %d", lineHeight);
////      }
//      //printf("\n");
//
//      //calculate lowest and highest pixel to fill in current stripe
//      int drawStart = (-lineHeight >> 1) + (screenHeight >> 1);
//      if(drawStart < 0) drawStart = 0;
//      int drawEnd = (lineHeight >> 1) + (screenHeight >> 1);
//      if(drawEnd >= screenHeight) drawEnd = screenHeight - 1;
//
//      /////////////////////////////////////////////////
//      ////texturing calculations
//      /////////////////////////////////////////////////
//	   unsigned int texNum = worldMap[rayPosX>>posShift][rayPosY>>posShift] - 1; //1 subtracted from it so that texture 0 can      be used!
//
//	   //calculate value of wallX
//	   int wallX; //where exactly the wall was hit
//
//	   if (side == 0) wallX = rayPosX;
//	   else           wallX = rayPosY;
//
//
//	   wallX -= (wallX>>posShift)<<posShift;
//
//	   //x coordinate on the texture
//	   unsigned int texX = (wallX * texWidth)>>posShift;
//	   if(side == 1 && rayDirX > 0) texX = texWidth - texX - 1;
//	   if(side == 0 && rayDirY < 0) texX = texWidth - texX - 1;
//
//	   unsigned int invLineHeight = (texHeight << 16)/lineHeight;
//	   int line_minus_h = lineHeight - screenHeight;
//
//
//
//	   DrawTexture(x, texX, drawStart, drawEnd, side, texNum, invLineHeight , line_minus_h);

//       unsigned int color;
//      switch(worldMap[rayPosX>>posShift][rayPosY>>posShift])
//      {
//        case 1:  color = RED_8BIT;  break; //red
//        case 2:  color = GREEN_8BIT;  break; //green
//        case 3:  color = BLUE_8BIT;   break; //blue
//        case 4:  color = WHITE_8BIT;  break; //white
//        default: color = YELLOW_8BIT; break; //yellow
//      }

      //draw the pixels of the stripe as a vertical line
      //DrawColumn(x, color, drawStart, drawEnd, side);
      //DrawColumn(x, color, lineHeight, side);
      //verLine(x, drawStart, drawEnd, color);

      x++;
    }



    //move forward if no wall in front of you
    if (forward == 1)
    {
        move = dircosine[dir]>>4;
        if(worldMap[(posX + move)>>posShift][posY>>posShift] == 0)
                posX += move;

        move = dirsine[dir]>>4;
        if(worldMap[posX>>posShift][(posY+move)>>posShift] == 0)
                posY += move;
    }
    //move backwards if no wall behind you
    if (backward == 1)
    {
        move = dircosine[dir]>>4;
        if(worldMap[(posX - move)>>posShift][posY>>posShift] == 0)
                posX -= move;

        move = dirsine[dir]>>4;
        if(worldMap[posX>>posShift][(posY - move)>>posShift] == 0)
                posY -= move;
    }
Exemplo n.º 21
0
// Entry point
int main()
{
  struct uart_pkt {
      unsigned char magic;
#define UART_PKT_MAGIC          'N'

      //  | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
      //  |  dir  |  dev  |     cnt       |
      unsigned char mode;
#define UART_PKT_MODE_CNT_MASK   0xF
#define UART_PKT_MODE_CNT_SHIFT  0

#define UART_PKT_MODE_DEV_MASK   0x30
#define UART_PKT_MODE_DEV_SHIFT  4
#define UART_PKT_DEV_GPIO        (0<<UART_PKT_MODE_DEV_SHIFT)
#define UART_PKT_DEV_LMS         (1<<UART_PKT_MODE_DEV_SHIFT)
#define UART_PKT_DEV_VCTCXO      (2<<UART_PKT_MODE_DEV_SHIFT)
#define UART_PKT_DEV_SI5338      (3<<UART_PKT_MODE_DEV_SHIFT)

#define UART_PKT_MODE_DIR_MASK   0xC0
#define UART_PKT_MODE_DIR_SHIFT  6
#define UART_PKT_MODE_DIR_READ   (2<<UART_PKT_MODE_DIR_SHIFT)
#define UART_PKT_MODE_DIR_WRITE  (1<<UART_PKT_MODE_DIR_SHIFT)
  };

  struct uart_cmd {
      unsigned char addr;
      unsigned char data;
  };

  // Set the prescaler for 400kHz with an 80MHz clock (prescaer = clock / (5*desired) - 1)
  IOWR_16DIRECT(I2C, OC_I2C_PRESCALER, 39 ) ;
  IOWR_8DIRECT(I2C, OC_I2C_CTRL, OC_I2C_ENABLE ) ;

  // Set the UART divisor to 14 to get 4000000bps UART (baud rate = clock/(divisor + 1))
  IOWR_ALTERA_AVALON_UART_DIVISOR(UART_0_BASE, 19) ;

  // Set the IQ Correction parameters to 0
  IOWR_ALTERA_AVALON_PIO_DATA(IQ_CORR_RX_PHASE_GAIN_BASE, DEFAULT_CORRECTION);
  IOWR_ALTERA_AVALON_PIO_DATA(IQ_CORR_TX_PHASE_GAIN_BASE, DEFAULT_CORRECTION);

  /* Event loop never exits. */
  {
      char state;
      enum {
          LOOKING_FOR_MAGIC,
          READING_MODE,
          READING_CMDS,
          EXECUTE_CMDS
      };

      unsigned short i, cnt;
      unsigned char mode;
      unsigned char buf[14];
      struct uart_cmd *cmd_ptr;
      uint32_t tmpvar = 0;

      state = LOOKING_FOR_MAGIC;
      while(1)
      {
          // Check if anything is in the FSK UART
          if( IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE) & ALTERA_AVALON_UART_STATUS_RRDY_MSK )
          {
              uint8_t val ;
              int isRead;
              int isWrite;

              val = IORD_ALTERA_AVALON_UART_RXDATA(UART_0_BASE) ;

              switch (state) {
              case LOOKING_FOR_MAGIC:
                  if (val == UART_PKT_MAGIC)
                      state = READING_MODE;
                  break;
              case READING_MODE:
                  mode = val;
                  if ((mode & UART_PKT_MODE_CNT_MASK) > 7) {
                      mode &= ~UART_PKT_MODE_CNT_MASK;
                      mode |= 7;
                  }
                  i = 0;
                  cnt = (mode & UART_PKT_MODE_CNT_MASK) * sizeof(struct uart_cmd);
                  state = READING_CMDS;
                  break;
              case READING_CMDS:
                  // cnt here means the number of bytes to read
                  buf[i++] = val;
                  if (!--cnt)
                      state = EXECUTE_CMDS;
                  break;
              default:
                  break;
              }

              void write_uart(unsigned char val) {
                  while (!(IORD_ALTERA_AVALON_UART_STATUS(UART_0_BASE) & ALTERA_AVALON_UART_STATUS_TRDY_MSK));
                  IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE,  val);
              }

              isRead = (mode & UART_PKT_MODE_DIR_MASK) == UART_PKT_MODE_DIR_READ;
              isWrite = (mode & UART_PKT_MODE_DIR_MASK) == UART_PKT_MODE_DIR_WRITE;

              if (state == EXECUTE_CMDS) {
                  write_uart(UART_PKT_MAGIC);
                  write_uart(mode);
                  // cnt here means the number of commands
                  cnt = (mode & UART_PKT_MODE_CNT_MASK);
                  cmd_ptr = (struct uart_cmd *)buf;

                  if ((mode & UART_PKT_MODE_DEV_MASK) == UART_PKT_DEV_LMS) {
                      for (i = 0; i < cnt; i++) {
                          if (isRead) {
                              lms_spi_read(cmd_ptr->addr, &cmd_ptr->data);
                          } else if (isWrite) {
                              lms_spi_write(cmd_ptr->addr, cmd_ptr->data);
                              cmd_ptr->data = 0;
                          } else {
                              cmd_ptr->addr = 0;
                              cmd_ptr->data = 0;
                          }
                          cmd_ptr++;
                      }
                  }
                  if ((mode & UART_PKT_MODE_DEV_MASK) == UART_PKT_DEV_SI5338) {
                      for (i = 0; i < cnt; i++) {
                          if (isRead) {
                              uint8_t tmpvar;
                              si5338_read(cmd_ptr->addr, &tmpvar);
                              cmd_ptr->data = tmpvar;
                          } else if (isWrite) {
                              si5338_write(cmd_ptr->addr, cmd_ptr->data);
                              cmd_ptr->data = 0;
                          } else {
                              cmd_ptr->addr = 0;
                              cmd_ptr->data = 0;
                          }
                          cmd_ptr++;
                      }
                  }

                  const struct {
                      enum {
                          GDEV_UNKNOWN,
                          GDEV_GPIO,
                          GDEV_IQ_CORR_RX,
                          GDEV_IQ_CORR_TX,
                          GDEV_FPGA_VERSION,
                          GDEV_TIME_TIMER,
                          GDEV_VCTXCO,
                          GDEV_XB_LO,
                          GDEV_EXPANSION,
                          GDEV_EXPANSION_DIR,
                      } gdev;
                      int start, len;
                  } gdev_lut[] = {
                          {GDEV_GPIO,           0, 4},
                          {GDEV_IQ_CORR_RX,     4, 4},
                          {GDEV_IQ_CORR_TX,     8, 4},
                          {GDEV_FPGA_VERSION,  12, 4},
                          {GDEV_TIME_TIMER,    16, 16},
                          {GDEV_VCTXCO,        34, 2},
                          {GDEV_XB_LO,         36, 4},
                          {GDEV_EXPANSION,     40, 4},
                          {GDEV_EXPANSION_DIR, 44, 4},
                  };
#define ARRAY_SZ(x) (sizeof(x)/sizeof(x[0]))
#define COLLECT_BYTES(x)       tmpvar &= ~ ( 0xff << ( 8 * cmd_ptr->addr));   \
                              tmpvar |= cmd_ptr->data << (8 * cmd_ptr->addr); \
                              if (lastByte) { x; tmpvar = 0; } \
                              cmd_ptr->data = 0;

                  if ((mode & UART_PKT_MODE_DEV_MASK) == UART_PKT_DEV_GPIO) {
                    uint32_t device;
                    int lut, lastByte;
                    for (i = 0; i < cnt; i++) {
                        device = GDEV_UNKNOWN;
                        lastByte = 0;
                        for (lut = 0; lut < ARRAY_SZ(gdev_lut); lut++) {
                            if (gdev_lut[lut].start <= cmd_ptr->addr && (gdev_lut[lut].start + gdev_lut[lut].len) > cmd_ptr->addr) {
                                cmd_ptr->addr -= gdev_lut[lut].start;
                                device = gdev_lut[lut].gdev;
                                lastByte = cmd_ptr->addr == (gdev_lut[lut].len - 1);
                                break;
                            }
                        }

                        if (isRead) {
                            if (device == GDEV_FPGA_VERSION)
                                cmd_ptr->data = (FPGA_VERSION >> (cmd_ptr->addr * 8));
                            else if (device == GDEV_TIME_TIMER)
                                cmd_ptr->data = IORD_8DIRECT(TIME_TAMER, cmd_ptr->addr);
                            else if (device == GDEV_GPIO)
                                cmd_ptr->data = (IORD_ALTERA_AVALON_PIO_DATA(PIO_0_BASE)) >> (cmd_ptr->addr * 8);
                            else if (device == GDEV_EXPANSION)
                                cmd_ptr->data = (IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE)) >> (cmd_ptr->addr * 8);
                            else if (device == GDEV_EXPANSION_DIR)
                                cmd_ptr->data = (IORD_ALTERA_AVALON_PIO_DATA(PIO_2_BASE)) >> (cmd_ptr->addr * 8);
                            else if (device == GDEV_IQ_CORR_RX)
                                cmd_ptr->data = (IORD_ALTERA_AVALON_PIO_DATA(IQ_CORR_RX_PHASE_GAIN_BASE)) >> (cmd_ptr->addr * 8);
                            else if (device == GDEV_IQ_CORR_TX)