Esempio n. 1
0
File: code.c Progetto: k0gaMSX/mcm
char writesong ()
{
  static char i,*ptr;
  static unsigned short cont,top,j;

  writebyte(stdout,0x0C);
  writebyte(stdout,0x00);

  cont=2;
  for(i=0;i<12;i++)
    {
      cont+=2;
      top=channels[i].cont;
      if(!top)
        {
          top++;
          writeword(stdout,cont+top);
          writebyte(stdout,0);
          cont++;
        }
      else
        {
          writeword(stdout,cont+top);
          for(j=0,ptr=channels[i].data;j<top;j++)
            writebyte(stdout,*ptr++);

          cont+=top;
        }
    }
  writeword(stdout,0);
}
Esempio n. 2
0
/* Process a z80 non-maskable interrupt */
static void
z80_nmi( libspectrum_dword ts, int type, void *user_data )
{
  /* TODO: this isn't ideal */
  if( spectranet_available && spectranet_nmi_flipflop() )
    return;

  if( z80.halted ) { PC++; z80.halted = 0; }

  IFF1 = 0;

  writebyte( --SP, PCH ); writebyte( --SP, PCL );

  if( machine_current->capabilities &
      LIBSPECTRUM_MACHINE_CAPABILITY_SCORP_MEMORY ) {

    /* Page in ROM 2 */
    writeport_internal( 0x1ffd, machine_current->ram.last_byte2 | 0x02 );

  } else if( beta_available ) {

    /* Page in TR-DOS ROM */
    beta_page();
  } else if( spectranet_available ) {
    
    /* Page in spectranet */
    spectranet_nmi();
  }

  /* FIXME: how is R affected? */

  /* FIXME: how does contention apply here? */
  tstates += 11; PC = 0x0066;
}
void SetupShiftBrite(void){
	unsigned char i;

	//setup pins
	RGB_LAT_DIR=0;
	RGB_LAT=0;
	RGB_DAT_DIR=0;
	RGB_DAT=0;
	RGB_CLK_DIR=0;
	RGB_CLK=0;

	//give everything some time to settle
	for(i=0; i<20; i++){
		delay(255);
	}

	//setup chip
	writebyte(0x47);
	writebyte(0xf1);
	writebyte(0xfc);
	writebyte(0x7f);
	//latch high and low
	RGB_LAT=1;
	delay(SBDELAY);
	RGB_LAT=0;

	shiftBriteColor(0x0000, 0x0000, 0x0000);

}
Esempio n. 4
0
//**输出数据->pcf8563
void writeData(UINT8 address,UINT8 mdata)
{
    Start();
    writebyte(0xa2);          /*写命令*/
    writebyte(address);          /*写地址*/
    writebyte(mdata);          /*写数据*/
    Stop();
}
Esempio n. 5
0
/* 10101....0101010101111111 */
void headtune(FILE *fp)
{
	int	i;
	
	for (i=0; i<16;i++)
		writebyte(85,fp);
	writebyte(127,fp);

}
Esempio n. 6
0
static void WriteData(unsigned cmd)
{
	unsigned fb=mDevID+RS(1)+RW(0);
	SCLK(1);
	SDI(1);
	CS(0);
	gdelay(1);
	writebyte(fb);
	writebyte(cmd);
	CS(1);	
}
Esempio n. 7
0
void write_add(unsigned char address,unsigned char date)//向地址写一个字节数据
{
 start();
 writebyte(0xa0);//A0,A1,A2接地,AT24C02芯片地址为1010,送控制字为1010A2A1A0R/~W
 respons();
 writebyte(address);
 respons();
 writebyte(date);
 respons();
 stop();
}
Esempio n. 8
0
boolean ServoShield2::start(void) {
  Wire.begin();
  
  writebyte(MODE1REG, 0x0);
  uint8_t mode1regvalue = readbyte(MODE1REG);
  uint8_t newregvalue = (mode1regvalue & 0x7F) | 0x10;    
  writebyte(MODE1REG, newregvalue);            
  writebyte(PRE_SCALEREG, prescale);   
  writebyte(MODE1REG, mode1regvalue);
  delay(5);
  writebyte(MODE1REG, mode1regvalue | 0x80);
  return true;
}
Esempio n. 9
0
//*输入数据<-pcf8563
UINT8 ReadData(UINT8 address)               /*单字节*/
{  
	UINT8 rdata;
    Start();
    writebyte(0xa2);             /*写命令*/
    writebyte(address);          /*写地址*/
    Start();
     writebyte(0xa3);             /*读命令*/
    rdata=Readbyte();
    writenoack();
    Stop();
    return(rdata);
 }
Esempio n. 10
0
unsigned char read_add(unsigned char address)//向地址读一个字节数据
{
 unsigned char date;
 start();
 writebyte(0xa0);//A0,A1,A2接地,AT24C02芯片地址为1010,送控制字为1010A2A1A0R/~W
 respons();
 writebyte(address);
 respons();
 start();
 writebyte(0xa1);//A0,A1,A2接地,AT24C02芯片地址为1010,送控制字为1010A2A1A0R/~W
 respons();
 date = readbyte();
 stop();
 return date;
}
Esempio n. 11
0
/* Process a z80 maskable interrupt */
int
z80_interrupt( void )
{
  /* An interrupt will occur if IFF1 is set and the /INT line hasn't
     gone high again. On a Timex machine, we also need the SCLD's
     INTDISABLE to be clear */
  if( IFF1 &&
      tstates < machine_current->timings.interrupt_length &&
      !scld_last_dec.name.intdisable ) {

    /* If interrupts have just been enabled, don't accept the interrupt now,
       but check after the next instruction has been executed */
    if( tstates == z80.interrupts_enabled_at ) {
      event_add( tstates + 1, z80_interrupt_event );
      return 0;
    }

    if( z80.halted ) { PC++; z80.halted = 0; }
    
    IFF1=IFF2=0;

    writebyte( --SP, PCH ); writebyte( --SP, PCL );

    R++; rzx_instructions_offset--;

    switch(IM) {
      case 0: PC = 0x0038; tstates += 7; break;
      case 1: PC = 0x0038; tstates += 7; break;
      case 2: 
	{
	  libspectrum_word inttemp=(0x100*I)+0xff;
	  PCL = readbyte(inttemp++); PCH = readbyte(inttemp);
	  tstates += 7;
	  break;
	}
      default:
	ui_error( UI_ERROR_ERROR, "Unknown interrupt mode %d", IM );
	fuse_abort();
    }

    return 1;			/* Accepted an interrupt */

  } else {

    return 0;			/* Did not accept an interrupt */

  }
}
Esempio n. 12
0
/* attach 2nd winbond 627HF */
void TyanTigerMPinit()
{
	unsigned char c;

	OpenIO();
	if (vendercheck()) {
		CloseIO();
		/* change ISA IO-port to 627HF */
		isa_port_base = SENS2_IO_PORT;
		return;
	}

	OUTb(TTPortCTR, 0x87);	/* get access to 627HF on TTPortCTR */
	OUTb(TTPortCTR, 0x87);

	OUTb(TTPortCTR, 0x07);
	OUTb(TTPortDAT, 0x0B);	/* want device as 0x0B access */

	OUTb(TTPortCTR, 0x60);	/* want device 0x0B on ISA port base 0x0C00 */
	c = SENS2_IO_PORT >> 8;
	OUTb(TTPortDAT, c);
	OUTb(TTPortCTR, 0x61);
	c = SENS2_IO_PORT & 0xFF;
	OUTb(TTPortDAT, c);

	/* change ISA IO-port to 627HF */
	isa_port_base = SENS2_IO_PORT;
	
	OUTb(TTPortCTR, 0x30);	/* now enabled */
	OUTb(TTPortDAT, 0x01);

#ifdef TyanTigerMP_SMBUS
	OUTb(TTPortCTR, 0x2B);	/* SMBus access enabled */
	c = INb(TTPortDAT) & 0x3F;
	OUTb(TTPortCTR, 0x2B);
	OUTb(TTPortDAT, c);

	writebyte(WINBD_SMBADDR, 0x2E); /* set 627HF on SMBus slave 0x5C(0x2E) */
	writebyte(WINBD_TEMPADDR, 0x32); /* set temp2,3 on SMBus slave 0x94,0x96 */
#endif

	writebyte(WINBD_CONFIG, 0x80);	/* kickstart it */
	writebyte(WINBD_CONFIG, 0x01);

	CloseIO();

	return;
}
Esempio n. 13
0
static void write_DQTinfo(void)
{
	unsigned i;
	
	writeword(0xFFDB);
	writeword(132);
	writebyte(0);

	for (i = 0; i < 64; i++) 
		writebyte(((unsigned char*)qtable_0_lum)[zig[i]]); // zig-zag order

	writebyte(1);

	for (i = 0; i < 64; i++) 
		writebyte(((unsigned char*)qtable_0_chrom)[zig[i]]); // zig-zag order
}
Esempio n. 14
0
  void ReadData1(UINT8 address,UINT8 count,UINT8 * buff)   /*多字节*/
  {   
	 UINT8 i;
      Start();
      writebyte(0xa2);             /*写命令*/
      writebyte(address);          /*写地址*/
      Start();
      writebyte(0xa3);             /*读命令*/
      for(i=0;i<count;i++)
      {
          buff[i]=Readbyte();
          if(i<count-1) WriteACK();
      }
      writenoack();
      Stop();
  }
Esempio n. 15
0
static void write_APP0info(void)
{
	writeword(0xFFE0); //marker
	writeword(16);     //length
	writebyte('J');
	writebyte('F');
	writebyte('I');
	writebyte('F');
	writebyte(0);
	writebyte(1);//versionhi
	writebyte(1);//versionlo
	writebyte(0);//xyunits
	writeword(1);//xdensity
	writeword(1);//ydensity
	writebyte(0);//thumbnwidth
	writebyte(0);//thumbnheight
}
Esempio n. 16
0
File: file.c Progetto: k0gaMSX/mcm
int writeword(FILE * out,unsigned short word)
  {
    unsigned char aux;

#ifdef __LITLE__
    aux=(unsigned char) word;
    writebyte(out,aux);
    aux=(unsigned char) (word>>8);
    writebyte(out,aux);
#else
    aux=(unsigned char) (word>>8);
    writebyte(out,aux);
    aux=(unsigned char) word;
    writebyte(out,aux);
#endif

    return 0;
  }
Esempio n. 17
0
void ServoShield2::setposition(int servo, int position) {
  
  if (position > servosmax[servo])
    position = servosmax[servo];
    
  if (position < servosmin[servo])
    position = servosmin[servo];
    
  if (invertedservos[servo]) {
      
  }
  
  position = floor(position / 4.88);
  writebyte(LED_ON_L + 4 * servo, 0);
  writebyte(LED_ON_H + 4 * servo, 0 >> 8);
  writebyte(LED_OFF_L + 4 * servo, position);
  writebyte(LED_OFF_H + 4 * servo, position >> 8);  
}
void DAC8571_Write_DATA(uint16_t DATA)
{
  uint8_t DATA_H,DATA_L;
  DATA_H=(DATA>>8);
  DATA_L=(DATA&0xff);
  
  I2C_START();
  Delay_us(1);
  writebyte(0x98);
  Delay_us(1);
  writebyte(0x10);
  Delay_us(1);
  writebyte(DATA_H);
  Delay_us(1);
  writebyte(DATA_L);
  Delay_us(1);
  I2C_STOP();
}
Esempio n. 19
0
static int hx8352_val_get_value(void *data, u64 *val)
{
	unsigned byte=mDevID+RS(1)+RW(1);
	CS(0);
	writebyte(byte);
	byte = readbyte(); //dummy 
	byte = readbyte();
	CS(1);	
	*val = byte;
	printk("[LCDC] reg 0x%X=0x%x\n", regval, (unsigned)*val);
	return 0;
}
Esempio n. 20
0
File: write.c Progetto: z88dk/z88dk
ssize_t write(int fd, void *ptr, size_t len)
{
	int	i;

	for ( i = 0; i < len ; i++ ) {
		if ( writebyte(fd,ptr[i]) == -1 ) {
			return i;
		}
	}

	return i;
}
Esempio n. 21
0
static void
load_data( HWND hwndDlg, LONG user_data )
{
  struct binary_info *info = ( struct binary_info * )user_data;

  long start, length; size_t i;
  
  TCHAR *temp_buffer;
  size_t temp_buffer_len;

  errno = 0;
  temp_buffer_len = SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_LENGTH,
                                        WM_GETTEXTLENGTH, 0, 0 );
  temp_buffer = malloc( sizeof( TCHAR ) * ( temp_buffer_len + 1 ) );
  SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_LENGTH, WM_GETTEXT,
                      temp_buffer_len + 1, ( LPARAM ) temp_buffer );
  length = _tcstol( temp_buffer, NULL, 10 );
  free( temp_buffer );
  if( errno || length < 1 || length > 0x10000 ) {
    ui_error( UI_ERROR_ERROR, "Length must be between 1 and 65536" );
    return;
  }

  if( length > info->file.length ) {
    ui_error( UI_ERROR_ERROR,
	      "'%s' contains only %lu bytes",
	      info->filename, (unsigned long)info->file.length );
    return;
  }

  errno = 0;
  temp_buffer_len = SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_START,
                                        WM_GETTEXTLENGTH, 0, 0 );
  temp_buffer = malloc( sizeof( TCHAR ) * ( temp_buffer_len + 1 ) );
  SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_START, WM_GETTEXT,
                      temp_buffer_len + 1, ( LPARAM ) temp_buffer );
  start = _tcstol( temp_buffer, NULL, 10 );
  free( temp_buffer );
  if( errno || start < 0 || start > 0xffff ) {
    ui_error( UI_ERROR_ERROR, "Start must be between 0 and 65535" );
    return;
  }

  if( start + length > 0x10000 ) {
    ui_error( UI_ERROR_ERROR, "Block ends after address 65535" );
    return;
  }

  for( i = 0; i < length; i++ )
    writebyte( start + i, info->file.buffer[ i ] );

  EndDialog( hwndDlg, 0 );
}
Esempio n. 22
0
static unsigned readreg(unsigned reg)
{
	unsigned byte=mDevID+RS(1)+RW(1);
	WriteCommand(reg);
	mdelay(10);
	CS(0);
	writebyte(byte);
	byte = readbyte(); //dummy 
	byte = readbyte();
	CS(1);
	return byte;
}
Esempio n. 23
0
void test_1 (void)
{
  int n_bytes = sizeof(b_seq_1)/sizeof(b_seq_1[0]);
  int i;
  FILE *f = fopen("test1.txt", "wb");
  if (f == NULL) error("Could not create test1.txt!");

  for (i = 0;  i < n_bytes;  i++)
    writebyte(f, b_seq_1[i]);
  fclose(f);

  test_byte_file("test1.txt", b_seq_1, n_bytes);
}
Esempio n. 24
0
/*
  init_lcd - Do various things to initialize the LCD display.
*/
void init_lcd() {
  _delay_ms(15);              // Delay at least 15ms

  writenibble(0x03);          // Use writenibble to send 0011
  _delay_ms(5);               // Delay at least 4msec

  writenibble(0x03);          // Use writenibble to send 0011
  _delay_us(120);             // Delay at least 100usec

  writenibble(0x03);          // Use writenibble to send 0011
  
  writenibble(0x02);          // Use writenibble to send 0010
  _delay_ms(2);
  
  writebyte(0x28, 0x00);      // Function Set: 4-bit interface, 2 lines
  _delay_ms(2);

  writebyte(0x0F, 0x00);      // Display and cursor on
  _delay_ms(2);

  clear();                    // Clear everything
  PORTB |= 0x04;              // Enable backlight
}
Esempio n. 25
0
static int trap_load_block( libspectrum_tape_rom_block *block )
{
  libspectrum_byte parity, *data;
  int loading, i;

  /* If the block's too short, give up and go home (with carry reset
     to indicate error */
  if( block->length < DE ) { 
    F = ( F & ~FLAG_C );
    return 0;
  }

  data = block->data;
  parity = *data;

  /* If the flag byte (stored in A') does not match, reset carry and return */
  if( *data++ != A_ ) {
    F = ( F & ~FLAG_C );
    return 0;
  }

  /* Loading or verifying determined by the carry flag of F' */
  loading = ( F_ & FLAG_C );

  if( loading ) {
    for( i=0; i<DE; i++ ) {
      writebyte( IX+i, *data );
      parity ^= *data++;
    }
  } else {		/* verifying */
    for( i=0; i<DE; i++) {
      parity ^= *data;
      if( *data++ != readbyte(IX+i) ) {
	F = ( F & ~FLAG_C );
	return 0;
      }
    }
  }

  /* If the parity byte does not match, reset carry and return */
  if( *data++ != parity ) {
    F = ( F & ~FLAG_C );
    return 0;
  }

  /* Else return with carry set */
  F |= FLAG_C;

  return 0;
}
Esempio n. 26
0
size_t write(int fd, void *ptr, size_t len)
{
	int	i;

//    if ( fd >= MAXFILE )
//	return -1;

	for ( i = 0; i < len ; i++ ) {
		if ( writebyte(fd,ptr[i]) == -1 ) {
			return i;
		}
	}

	return i;
}
Esempio n. 27
0
static int vendercheck(void)
{
	int nv, save, ret;

	ret = 0;
	save = isa_port_base;
	isa_port_base = SENS2_IO_PORT;
	nv = readbyte(WINBD_VENDID) & 0xFF;
	if (nv == 0xA3) {
		writebyte(WINBD_VENDEX, 0x80);
		nv = readbyte(WINBD_VENDID) & 0xFF;
		if (nv == 0x5C)
			ret = 1;
	}
	isa_port_base = save;
	return ret;
}
Esempio n. 28
0
static void fcreate(const char *word, ucell cfaval)
{
	if (strlen(word) == 0) {
		printk("WARNING: tried to create unnamed word.\n");
		return;
	}

	writestring(word);
	/* get us at least 1 byte for flags */
	writebyte(0);
	paddict(sizeof(cell));
	/* set flags high bit. */
	dict[dicthead - 1] = 128;
	/* lfa and cfa */
	writecell(read_ucell(latest));
	*latest = target_ucell(pointer2cell(dict) + dicthead - sizeof(cell));
	writecell(cfaval);
}
Esempio n. 29
0
//------------------------------------------------------------
void writeword(unsigned int i, FILE *fp)
{
   writebyte(i%256,fp);
   writebyte(i/256,fp);
}
Esempio n. 30
0
int main(int argc, char *argv[])
{
   char   name[11], mybuf[20];
   FILE   *fpin, *fpout;
   int    c,   i, len, pos=32768;

   if ((argc < 3 )||(argc > 4 )) {
      fprintf(stdout,"Usage: %s [code file] [tap file] <ORG location>\n",argv[0]);
      exit(1);
   }
   
   if (argc == 4 ) { pos=atoi(argv[3]); }

   if ( (fpin=fopen(argv[1],"rb") ) == NULL ) {
      fprintf(stderr,"Can't open input file\n");
      exit(1);
   }

   if   (fseek(fpin,0,SEEK_END)) {   // get input file size
      fprintf(stderr,"Couldn't determine size of file\n");
      fclose(fpin);
      exit(1);
   }
   len=ftell(fpin);
   fseek(fpin,0L,SEEK_SET);

   if ( (fpout=fopen(argv[2],"wb") ) == NULL ) {
      fprintf(stdout,"Can't open output file\n");
      exit(1);
   }

   /* M/C program, Write out the code header file */
   writeword(19,fpout);   /* Header len */
   writebyte(0,fpout);   /* Header is 0 */
   parity=0;
   writebyte(3,fpout);   /* Filetype (Code) */

   if (strlen(argv[1]) >= 10 ) {   // filename
      strncpy(name,argv[1],10);
   } else {
      strcpy(name,argv[1]);
      strncat(name,"          ",10-strlen(argv[1]));
   }
   for   (i=0;i<=9;i++)
      writebyte(name[i],fpout);
   writeword(len,fpout);
   writeword(pos,fpout);   /* load address */
   writeword(0,fpout);   /* offset */
   writebyte(parity,fpout);

   writeword(len+2,fpout);   /* Length of next block */
   parity=0;
   writebyte(255,fpout);   /* Data... */
   for (i=0; i<len;i++) {
      c=getc(fpin);
      writebyte(c,fpout);
   }
   writebyte(parity,fpout);
   fclose(fpin);
   fclose(fpout);
}