void bluetoothIRQ(void* context) {
	char read = 0;
	while(!(IORD_ALTERA_AVALON_UART_STATUS(UART_BLUETOOTH_BASE) & ALTERA_AVALON_UART_STATUS_RRDY_MSK));
	read = IORD_ALTERA_AVALON_UART_RXDATA(UART_BLUETOOTH_BASE);
	if(read == -1) {

	} else {
		// Debug stuff for LEDs
		if(read != START_BYTE && read != END_BYTE) {
			if(read == 'f') {
				charInter = 0x1;
			} else if(read == 'b') {
				charInter = 0x1;
			} else if(read == 'l') {
				charInter = 0x1;
			} else if(read == 'r') {
				charInter = 0x1;
			} else if(read == 's') {
				charInter = 0x0;
			} else {
				charInter = 0;
			}
			IOWR_8DIRECT(PIO_LEDS_BASE, 0, charInter | charRecv | curCommand | (sendCount << 4));
		}

		OSQPost(byteQueue, (void*) read);
	}
}
int alt_up_pixel_buffer_draw(alt_up_pixel_buffer_dev *pixel_buffer, unsigned int color, unsigned int x, unsigned int y)
/* This function draws a pixel to the back buffer.
 */
{
	// boundary check
	if (x >= pixel_buffer->x_resolution || y >= pixel_buffer->y_resolution )
		return -1;

	unsigned int addr = 0;
	/* Check the mode VGA Pixel Buffer is using. */
	if (pixel_buffer->addressing_mode == ALT_UP_PIXEL_BUFFER_XY_ADDRESS_MODE) {
		/* For X-Y addressing mode, the address format is | unused | Y | X |. So shift bits for coordinates X and Y into their respective locations. */
		addr |= ((x & pixel_buffer->x_coord_mask) << pixel_buffer->x_coord_offset);
		addr |= ((y & pixel_buffer->y_coord_mask) << pixel_buffer->y_coord_offset);
	} else {
		/* In a consecutive addressing mode, the pixels are stored in consecutive memory locations. So the address of a pixel at (x,y) can be computed as
		 * (y*x_resolution + x).*/
		addr += ((x & pixel_buffer->x_coord_mask) << pixel_buffer->x_coord_offset);
		addr += (((y & pixel_buffer->y_coord_mask) * pixel_buffer->x_resolution) << pixel_buffer->x_coord_offset);
	}
	/* Now, depending on the color depth, write the pixel color to the specified memory location. */
	if (pixel_buffer->color_mode == ALT_UP_8BIT_COLOR_MODE) {
		IOWR_8DIRECT(pixel_buffer->back_buffer_start_address, addr, color);
	} else if (pixel_buffer->color_mode == ALT_UP_16BIT_COLOR_MODE) {
		IOWR_16DIRECT(pixel_buffer->back_buffer_start_address, addr, color);
	} else {
		IOWR_32DIRECT(pixel_buffer->back_buffer_start_address, addr, color);
	}

	return 0;
}
예제 #3
0
int main(void) {
	int counter = 0;
	unsigned int wait;

	printf("Lets start counting \n");
	IOWR_8DIRECT(LEDS_BASE,0,0);

	while(1) {
		counter ++;
		printf("counter = %d \n",counter);
		IOWR_8DIRECT(LEDS_BASE,0,counter);
		// silly busy wait
		for(wait = 0; wait < DELAY; wait++)
		asm volatile ("nop");
	}
}
예제 #4
0
void initInterrupts(void){

	// PS2
	 alt_up_ps2_dev * ps2_device = alt_up_ps2_open_dev(PS2_NAME);

	  if(ps2_device == NULL){
	    printf("can't find PS/2 device\n");
	    return 1;
	  }

	  alt_up_ps2_clear_fifo (ps2_device) ;

	  alt_irq_register(PS2_IRQ, ps2_device, ps2_isr);
	  // register the PS/2 interrupt
	  IOWR_8DIRECT(PS2_BASE,4,1);


	  // button

	  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PUSH_BUTTON_BASE, 0x7);

	    // enable interrupts for all buttons
	    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(PUSH_BUTTON_BASE, 0x7);
	  alt_irq_register(PUSH_BUTTON_IRQ, NULL, button_interrupts_function);
//
//
	  	 // frequency analyzer
	  alt_irq_register(FREQUENCY_ANALYSER_IRQ,(void*)&frequency_value, frequency_interrupt_function);
}
//------------------------------------------------------------------------------
int target_unlock(void)
{
    if (pLock_l == NULL)
        return -1;

    IOWR_8DIRECT(pLock_l, 0, LOCK_UNLOCKED_C);

    return 0;
}
예제 #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;
	
}
void helper_plot_pixel(register unsigned int buffer_start, register int line_size, register int x, register int y, register int color, register int mode)
/* This is a helper function that draws a pixel at a given location. Note that no boundary checks are made,
 * so drawing off-screen may cause unpredictable side effects. */
{
	if (mode == 0)
		IOWR_8DIRECT(buffer_start, line_size*y+x, color);
	else if (mode == 1)
		IOWR_16DIRECT(buffer_start, (line_size*y+x) << 1, color);
	else
		IOWR_32DIRECT(buffer_start, (line_size*y+x) << 2, color);
}
예제 #8
0
파일: cpu_3.c 프로젝트: johangas/IL2212
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;
}
예제 #9
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));
}
예제 #10
0
int main(void) {
	// Start the timestamp -- will be used for seeding the random number generator.

	alt_timestamp_start();
	sdcard_handle *sd_dev = init_sdcard();
	initAudio();

	loadMusic("Title2.wav", 1, 0.25);

	// Set latch and clock to 0.
	IOWR_8DIRECT(controller_out, 0, 0x00);

	init_display();

	clear_display();

	if (sd_dev == NULL)
		return 1;

	printf("Card connected.\n");

	ticks_per_sec = alt_ticks_per_second();

	seed(alt_timestamp());

	alt_u32 tickCount = alt_nticks();
	num_ticks = ticks_per_sec / 60;
	//alt_alarm *update_alarm = malloc(sizeof(alt_alarm));
	//alt_alarm_start(update_alarm, num_ticks, update, (void*)0);

	while (true)
	{
		if (alt_nticks() - tickCount >= num_ticks)
		{
			tickCount = alt_nticks();
			update(0);
		}
	}

	return 0;
}
예제 #11
0
void init_threshold_control(void)
{
	xTaskHandle task;
	threshold_queue = xQueueCreate(1, sizeof(struct threshold));
	if (threshold_queue == NULL)
		panic("xQueueCreate failed");
	vSemaphoreCreateBinary(threshold_sem);
	if (threshold_sem == NULL)
		panic("vSemaphoreCreateBinary failed");
	xTaskCreate(threshold_control_task, "threshold_control", configMINIMAL_STACK_SIZE,
		    NULL, tskIDLE_PRIORITY+1, &task);

	// initialise ps2 (keyboard) device, register keyboard irq
	alt_up_ps2_dev *ps2_device = alt_up_ps2_open_dev(PS2_NAME);
	if (ps2_device == NULL)
		panic("unable to open ps2 device");
	alt_up_ps2_clear_fifo (ps2_device);
	alt_irq_register(PS2_IRQ, ps2_device, do_keyboard_irq);
	// register the PS/2 interrupt
	IOWR_8DIRECT(PS2_BASE,4,1);
}
//------------------------------------------------------------------------------
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;
}
void sendTask(void* pdata) {
	LenBuffer* buf;
	INT8U err;
	static unsigned char packetId = 4;

	while(1) {
		buf = (LenBuffer*) OSQPend(sendQueue, 0, &err);
		--sendCount;
		IOWR_8DIRECT(PIO_LEDS_BASE, 0, charInter | charRecv | curCommand | (sendCount << 4));
		memmove(buf->buf+2, buf->buf, buf->len);
		buf->buf[0] = packetId++;
		buf->buf[1] = buf->len;
		buf->len += 2;
		send(*buf);
		send(*buf);
		send(*buf);

		free(buf->buf);
		free(buf);
	}

}
예제 #14
0
void si5338_write( 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_CMD_STATUS | OC_I2C_WR ) ;
    si5338_complete_transfer( 1 ) ;

    IOWR_8DIRECT(I2C, OC_I2C_DATA, data ) ;
    IOWR_8DIRECT(I2C, OC_I2C_CMD_STATUS, OC_I2C_WR | OC_I2C_STO ) ;
    si5338_complete_transfer( 0 ) ;

    return ;
}
예제 #15
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;
}
예제 #16
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 ;
}
예제 #17
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]);
			}
		}
	}

}
예제 #18
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;
      uint16_t dacval;

      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 ;

              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);
              }

              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 ((mode & UART_PKT_MODE_DIR_MASK) == UART_PKT_MODE_DIR_READ) {
                              lms_spi_read(cmd_ptr->addr, &cmd_ptr->data);
                          } else if ((mode & UART_PKT_MODE_DIR_MASK) == UART_PKT_MODE_DIR_WRITE) {
                              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 ((mode & UART_PKT_MODE_DIR_MASK) == UART_PKT_MODE_DIR_READ) {
                              uint8_t tmpvar;
                              si5338_read(cmd_ptr->addr, &tmpvar);
                              cmd_ptr->data = tmpvar;
                          } else if ((mode & UART_PKT_MODE_DIR_MASK) == UART_PKT_MODE_DIR_WRITE) {
                              si5338_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_GPIO) {
                    uint32_t device;
                    switch(cmd_ptr->addr)
                    {
                        case 0:case 1:case 2: case 3:
                            device = PIO_0_BASE;break;
                        case 4: case 5: case 6: case 7:
                            device = IQ_CORR_RX_PHASE_GAIN_BASE;
                            cmd_ptr->addr -= 4;
                            break;
                        case 8: case 9: case 10: case 11:
                            device = IQ_CORR_TX_PHASE_GAIN_BASE;
                            cmd_ptr->addr -= 8;
                            break;
                        case 12: case 13: case 14: case 15:
                            device = FPGA_VERSION_ID;
                            cmd_ptr->addr -= 12;
                            break;
                        default:
                            //error
                            device = PIO_0_BASE;
                    }

                      if ((mode & UART_PKT_MODE_DIR_MASK) == UART_PKT_MODE_DIR_READ) {
                          if (device == FPGA_VERSION_ID)
                          {
                            cmd_ptr->data = (FPGA_VERSION >> (cmd_ptr->addr * 8));
                          }
                          else
                          {
                            cmd_ptr->data = (IORD_ALTERA_AVALON_PIO_DATA(device)) >> (cmd_ptr->addr * 8);
                          }
                      } else if ((mode & UART_PKT_MODE_DIR_MASK) == UART_PKT_MODE_DIR_WRITE) {
예제 #19
0
파일: menu.c 프로젝트: NibblesLab/mz80b_de0
/*
 * Display Frame by Item numbers
 */
void frame(unsigned int level, unsigned int items, unsigned int select)
{
	unsigned int i,j;
	unsigned char c1,c2,c3,c4;

	c1=0x97; c2=0x95; c3=0x96; c4=0x98;

	IOWR_8DIRECT(REG_BASE, MZ_VRAM+level*13, c1);
	IOWR_8DIRECT(REG_BASE, MZ_VRAM+40+level*13, c4);
	IOWR_8DIRECT(REG_BASE, MZ_VRAM+level*13+1, c2);
	IOWR_8DIRECT(REG_BASE, MZ_VRAM+40+level*13+1, c3);
	for(i=1;i<13;i++){
		usleep(10000);
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+level*13+i, 0x9b);
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+level*13+i+1, c2);
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+40+level*13+i, 0x9b);
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+40+level*13+i+1, c3);
	}

	for(i=1;i<=items;i++){
		usleep(10000);
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+i*40+level*13, 0x9a);
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+i*40+level*13+13, 0x9a);
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+(i+1)*40+level*13, c4);
		for(j=1;j<13;j++){
			IOWR_8DIRECT(REG_BASE, MZ_VRAM+i*40+level*13+j, 0);
			IOWR_8DIRECT(REG_BASE, MZ_VRAM+(i+1)*40+level*13+j, 0x9b);
		}
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+(i+1)*40+level*13+13, c3);
	}

	if(level){
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+(select+1)*40+level*13, 0x9e);
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+(select+1)*40+level*13-1, 0x9b);
	}
}
void receiveTask(void* pdata) {
	char byte = '1';
	INT8U err;
	PacketBuffer pb;
	init(&pb);
	LenBuffer* buf;

	printf("ReceiveTask :: started!\n");
	while(1) {
		byte = (char) OSQPend(byteQueue, 0, &err);

		if(byte != START_BYTE && byte != END_BYTE) {
			if(byte == 'f') {
				charRecv = 0x2;
			} else if(byte == 'b') {
				charRecv = 0x2;
			} else if(byte == 'l') {
				charRecv = 0x2;
			} else if(byte == 'r') {
				charRecv = 0x2;
			} else if(byte == 's') {
				charRecv = 0x0;
			} else {
				charRecv = 0;
			}
			IOWR_8DIRECT(PIO_LEDS_BASE, 0, charInter | charRecv | curCommand | (sendCount << 4));
		}
		if(err != OS_NO_ERR) {
			printf("ReceiveTask :: ERROR: %i", err);
			charRecv = 0x0;
			IOWR_8DIRECT(PIO_LEDS_BASE, 0, charInter | charRecv | curCommand | (sendCount << 4));
			continue;
		}
		printf("ReceiveTask :: Received: %i\n", byte);
		if(byte == START_BYTE) {
			clear(&pb);
			pb.isStarted = 1;
		} else if(byte == END_BYTE) {
			if(pb.isStarted) {
				// We have to malloc this because it's
				buf = (LenBuffer*) malloc(sizeof(LenBuffer));
				buf->buf = (char*) malloc(BUF_SIZE * sizeof(char));
				memset(buf->buf, 0, BUF_SIZE);
				buf->len = mRead(&pb, buf->buf);
				pb.isStarted = 0;

				OSQPost(receiveQueue, (void*) buf);
			}

		} else {
			if(pb.isStarted) {
				if(pushChar(&pb, byte)) {
//					printf("ReceiveTask :: %i\n", byte);
				} else {
//					printf("ReceiveTask :: No room in buffer!\n");
				}
			} else {
//				printf("ReceiveTask :: %i - discarded\n", byte);
			}
		}
	}
}
예제 #21
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;
}
예제 #22
0
파일: thread1.c 프로젝트: blickly/pret_iss
INT main( )
{
	const DWORD N_COL_SCREEN = 	VGA_RESOLUTION_WIDTH / N_VGA_PIXEL_PER_ONCE;
	DWORD i = 0;
	DWORD j = 0;
	volatile DWORD * p_color_line = NULL;

	PRINTS( "The VGA driver started\n" );

#ifdef VGA_EMUL
	puts( "VGA emul mode\n" );

	const int DUMP_FRAME = 3;

	// initialize the driver
	if( vga_emul_init( ) == FALSE )
	{
		PRINTS( "FILE OPEN ERROR!\n" );
	}
#endif

	while( !vga_is_refreshing( ) );
	puts( "vga initial refresh\n" );

	DEADPLL( N_VGA_CLK_V_SYNC );

	while( TRUE )
	{
		// process superfield
		
		// process vsync
		IOWR_32DIRECT( IO_ADDR_VGA, 0, VGA_COLOR_V_SYNC );
		IOWR_8DIRECT( IO_ADDR_VGA, 1, VGA_CONTROL_V_SYNC_ON );
		DEADPLL( N_VGA_CLK_V_BP );
		IOWR_8DIRECT( IO_ADDR_VGA, 1, VGA_CONTROL_V_SYNC_OFF );
		PRINTS( "VSYNC PROCESSED\n" );
		
		// process back-porch line
		// during back-porch line, refresh the screen buffer
		if( vga_is_refreshing( ) )
		{
			vga_toggle_graphic_buffer( );
			puts( "vga refreshed\n" );
#ifdef	VGA_EMUL
			n_frame++;
			//			puts( "n_frame: %d\n", n_frame );
			if( n_frame == DUMP_FRAME )
			{
				puts( "start dump\n" );
			}
#endif
		}

		DEADPLL( N_VGA_CLK_H_SYNC );
		PRINTS( "BP LINE PROCESSED\n" );
		
		// draw field
		for( i = 0; i < VGA_RESOLUTION_HEIGHT; i++ )
		{
			// process hsync
			IOWR_32DIRECT( IO_ADDR_VGA, 0, VGA_COLOR_H_SYNC );
			IOWR_8DIRECT( IO_ADDR_VGA, 1, VGA_CONTROL_H_SYNC_ON );
			//p_color_line = &_screen[ _current_buffer ][ i ][ 0 ];	// access the screen memory in advance
			p_color_line = ( _screen + ( *( _current_buffer ) * VGA_RESOLUTION_HEIGHT * N_COL_SCREEN ) + ( i * N_COL_SCREEN ) );	// access the screen memory in advance
			j = N_COL_SCREEN - 1;
			DEADPLL( N_VGA_CLK_H_BP );
			IOWR_8DIRECT( IO_ADDR_VGA, 1, VGA_CONTROL_H_SYNC_OFF );
			PRINTS( "HSYNC PROCESSED\n" );
			int tmp = *p_color_line;
			int limit = ( int ) ( p_color_line + N_COL_SCREEN - 1 );
			// process back-porch pixel
			PRINTS( "BP PIXEL PROCESSED\n" );

			// draw horizontal pixels
			do
			{
#ifdef VGA_EMUL
				if( n_frame == DUMP_FRAME )
				{
					vga_emul_plot_pixel( *p_color_line );
				}
#else
				DEADPLLI( "10" );
				IOWR_32DIRECT( IO_ADDR_VGA, 0, *p_color_line );
#endif
			} while( ( int ) p_color_line++ < ( int ) limit );

			// process front-porch pixel
			DEADPLL( N_VGA_CLK_H_FP );
			IOWR_32DIRECT( IO_ADDR_VGA, 0, VGA_COLOR_H_FP );
			DEADPLL( N_VGA_CLK_H_SYNC );
			PRINTS( "FP PIXEL PROCESSED\n" );
		}

		//puts( "FRAME DRAWING END: %d\n", i );

#ifdef VGA_EMUL
		if( n_frame == DUMP_FRAME )
		{
			puts( "end dump\n" );
		}
#endif

		// process front-porch line
		IOWR_32DIRECT( IO_ADDR_VGA, 0, VGA_COLOR_V_FP );
		DEADPLL( N_VGA_CLK_V_FP - N_VGA_CLK_H_SYNC );
		DEADPLL( N_VGA_CLK_V_SYNC );
		PRINTS( "FP LINE PROCESSED\n" );
	}
	
	return 0;
}
예제 #23
0
파일: main.c 프로젝트: 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;
}
예제 #24
0
파일: menu.c 프로젝트: NibblesLab/mz80b_de0
/*
 * View the Inventory of ROMs
 */
int view_inventory(void)
{
	unsigned int i,j;
	ROMS_t *romdata=(ROMS_t *)(CFI_BASE+0x100000);

	for(i=1;i<=24;i++){
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+i*40+13, 0x9a);
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+i*40+39, 0x9a);
	}
	for(i=14;i<=38;i++){
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+i, 0x9b);
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+960+i, 0x9b);
	}

	for(i=1;i<=23;i++){
		for(j=14;j<=38;j++){
			IOWR_8DIRECT(REG_BASE, MZ_VRAM+i*40+j, 0);
		}
	}

	IOWR_8DIRECT(REG_BASE, MZ_VRAM+13, 0x97);
	IOWR_8DIRECT(REG_BASE, MZ_VRAM+39, 0x95);
	IOWR_8DIRECT(REG_BASE, MZ_VRAM+999, 0x96);
	IOWR_8DIRECT(REG_BASE, MZ_VRAM+973, 0x98);

	IOWR_8DIRECT(REG_BASE, MZ_VRAM+53, 0x9e);
	IOWR_8DIRECT(REG_BASE, MZ_VRAM+52, 0x9b);

	IOWR_8DIRECT(REG_BASE, MZ_VRAM+212, 0x3e);
	IOWR_8DIRECT(REG_BASE, MZ_VRAM+252, 0x3e);

	MZ_msg(14, 1, "MZ-80B on FPGA B.U.System");
	MZ_msg(14, 2, " BY NibblesLab VER."); MZ_msg(33, 2, version);
	MZ_msg(14, 4, "    TAPE    :"); MZ_msg(27, 4, tname);
	MZ_msg(14, 5, "    FDD 1   :"); MZ_msg(27, 5, dname[0]);
	MZ_msg(14, 6, "    FDD 2   :"); MZ_msg(27, 6, dname[1]);
	MZ_msg(14, 11, "   CG ROM   :"); MZ_msgx(27, 11, romdata->char80b_name, 12);
	MZ_msg(14, 12, "  KEY MAP   :"); MZ_msgx(27, 12, romdata->key80b_name, 12);

	while(1){
		if((z80_sts.status&S_FBTN)==0) return(-1);
		switch(get_key()){
		case 0x1b:	// escape menu
			z80_sts.status&=~S_FBTN;
			break;
		case 0x1d:	// menu back
			return(999);
			break;
		default:
			break;
		}
	}
	return(-1);
}
void alt_up_pixel_buffer_draw_vline(alt_up_pixel_buffer_dev *pixel_buffer, int x, int y0, int y1, int color, int backbuffer)
/* This method draws a vertical line. This method is faster than using the line method because we know the direction of the line. */

{
	register unsigned int addr;
	register unsigned int limit_x = pixel_buffer->x_resolution;
	register unsigned int limit_y = pixel_buffer->y_resolution;
	register unsigned int temp;
	register unsigned int line_x = x;
	register unsigned int t_y = y0;
	register unsigned int b_y = y1;
	register unsigned int local_color = color;
	
	/* Check coordinates */
	if (t_y > b_y)
	{
		temp = t_y;
		t_y = b_y;
		b_y = temp;
	}
	if ((line_x >= limit_x) || (t_y >= limit_y) || (line_x < 0) || (b_y < 0))
	{
		/* Drawing outside of the window, so don't bother. */
		return;
	}
	/* Clip the box and draw only within the confines of the screen. */
	if (t_y < 0)
	{
		t_y = 0;
	}
	if (b_y >= limit_y)
	{
		b_y = limit_y - 1;
	}

	/* Set up the address to start clearing from and the screen boundaries. */
	if (backbuffer == 1)
		addr = pixel_buffer->back_buffer_start_address;
	else
		addr = pixel_buffer->buffer_start_address;

	/* Draw the vertical line using one of the addressing modes. */
	if (pixel_buffer->addressing_mode == ALT_UP_PIXEL_BUFFER_XY_ADDRESS_MODE) {
		/* Draw a vertical line of a given color on the screen using the XY addressing mode. */
		register unsigned int y;
		register unsigned int offset_y;
		offset_y = pixel_buffer->y_coord_offset;
		addr = addr + (t_y << offset_y);
		
		/* This portion of the code is purposefully replicated. This is because having a text for
		 * the mode would unnecessarily slow down the drawing of a box. */
		if (pixel_buffer->color_mode == ALT_UP_8BIT_COLOR_MODE) {
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_8DIRECT(addr, line_x, local_color);
				addr = addr + (1 << offset_y);
			}
		} else if (pixel_buffer->color_mode == ALT_UP_16BIT_COLOR_MODE) {
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_16DIRECT(addr, line_x << 1, local_color);
				addr = addr + (1 << offset_y);
			}
		}
		else
		{
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_32DIRECT(addr, line_x << 2, local_color);
				addr = addr + (1 << offset_y);
			}
		}
	} else {
		/* Draw a vertical line of a given color on the screen using the linear addressing mode. */
		register unsigned int y;
		/* This portion of the code is purposefully replicated. This is because having a text for
		 * the mode would unnecessarily slow down the drawing of a box. */
		if (pixel_buffer->color_mode == ALT_UP_8BIT_COLOR_MODE) {
			addr = addr + t_y * limit_x;
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_8DIRECT(addr, line_x, local_color);
				addr = addr + limit_x;
			}
		} else if (pixel_buffer->color_mode == ALT_UP_16BIT_COLOR_MODE) {
			limit_x = limit_x << 1;
			addr = addr + t_y * limit_x;
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_16DIRECT(addr, line_x << 1, local_color);
				addr = addr + limit_x;
			}
		}
		else
		{
			limit_x = limit_x << 2;
			addr = addr + t_y * limit_x;
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_32DIRECT(addr, line_x << 2, local_color);
				addr = addr + limit_x;
			}
		}
	}
}
예제 #26
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);
}
예제 #27
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)