コード例 #1
0
ファイル: wldr_udi.cpp プロジェクト: VWarlock/zx-evo
int FDD::write_udi(FILE *ff)
{
   memset(snbuf, 0, 0x10);
   *(unsigned*)snbuf = WORD4('U','D','I','!');
   snbuf[8] = snbuf[11] = 0;
   snbuf[9] = cyls-1;
   snbuf[10] = sides-1;
   *(unsigned*)(snbuf+12) = 0;

   u8 *dst = snbuf+0x10;
   for (unsigned c = 0; c < cyls; c++)
      for (unsigned s = 0; s < sides; s++)
      {
         *dst++ = 0;
         unsigned len = trklen[c][s];
         *(u16*)dst = len; dst += 2;
         memcpy(dst, trkd[c][s], len); dst += len;
         len = (len+7)/8;
         memcpy(dst, trki[c][s], len); dst += len;
      }
   if (*dsc) strcpy((char*)dst, dsc), dst += strlen(dsc)+1, snbuf[11] = 1;
   *(unsigned*)(snbuf+4) = dst-snbuf;
   int crc = -1; crc32(crc, snbuf, dst-snbuf);
   *(unsigned*)dst = crc; dst += 4;
   if (fwrite(snbuf, 1, dst-snbuf, ff) != (unsigned)(dst-snbuf)) return 0;
   return 1;
}
コード例 #2
0
ファイル: draw.cpp プロジェクト: tslabs/zx-evo
unsigned getYUY2(unsigned r, unsigned g, unsigned b)
{
   int y = (int)(0.29*r + 0.59*g + 0.14*b);
   int u = (int)(128.0 - 0.14*r - 0.29*g + 0.43*b);
   int v = (int)(128.0 + 0.36*r - 0.29*g - 0.07*b);
   if (y < 0) y = 0; if (y > 255) y = 255;
   if (u < 0) u = 0; if (u > 255) u = 255;
   if (v < 0) v = 0; if (v > 255) v = 255;
   return WORD4(y,u,y,v);
}
コード例 #3
0
ファイル: rijndael.c プロジェクト: Anachid/mozilla-central
/* generate values for the tables with a function*/
static PRUint32 gen_TInvXi(PRUint8 tx, PRUint8 i)
{
    PRUint8 si01, si02, si03, si04, si08, si09, si0B, si0D, si0E;
    si01 = SINV(i);
    si02 = XTIME(si01);
    si04 = XTIME(si02);
    si08 = XTIME(si04);
    si03 = si02 ^ si01;
    si09 = si08 ^ si01;
    si0B = si08 ^ si03;
    si0D = si09 ^ si04;
    si0E = si08 ^ si04 ^ si02;
    switch (tx) {
    case 0:
	return WORD4(si0E, si09, si0D, si0B);
    case 1:
	return WORD4(si0B, si0E, si09, si0D);
    case 2:
	return WORD4(si0D, si0B, si0E, si09);
    case 3:
	return WORD4(si09, si0D, si0B, si0E);
    }
    return -1;
}
コード例 #4
0
ファイル: wldr_fdi.cpp プロジェクト: VWarlock/zx-evo
int FDD::write_fdi(FILE *ff)
{
   unsigned c,s, total_s = 0;
   for (c = 0; c < cyls; c++)
      for (s = 0; s < sides; s++) {
         t.seek(this, c,s, LOAD_SECTORS);
         total_s += t.s;
      }
   unsigned tlen = strlen(dsc)+1;
   unsigned hsize = 14+(total_s+cyls*sides)*7;
   *(unsigned*)snbuf = WORD4('F','D','I',0);
   *(u16*)(snbuf+4) = cyls;
   *(u16*)(snbuf+6) = sides;
   *(u16*)(snbuf+8) = hsize;
   *(u16*)(snbuf+0x0A) = hsize + tlen;
   *(u16*)(snbuf+0x0C) = 0;
   fwrite(snbuf, 1, 14, ff);
   unsigned trkoffs = 0;
   for (c = 0; c < cyls; c++)
      for (s = 0; s < sides; s++) {
         t.seek(this,c,s,LOAD_SECTORS);
         unsigned secoffs = 0;
         *(unsigned*)snbuf = trkoffs;
         *(unsigned*)(snbuf+4) = 0;
         snbuf[6] = t.s;
         fwrite(snbuf, 1, 7, ff);
         for (unsigned se = 0; se < t.s; se++) {
            *(unsigned*)snbuf = *(unsigned*)&t.hdr[se];
            snbuf[4] = t.hdr[se].c2 ? (1<<(t.hdr[se].l & 3)) : 0; // [vv]
            if (t.hdr[se].data && t.hdr[se].data[-1] == 0xF8) snbuf[4] |= 0x80;
            if (!t.hdr[se].data) snbuf[4] |= 0x40;
            *(unsigned*)(snbuf+5) = secoffs;
            fwrite(snbuf, 1, 7, ff);
            secoffs += t.hdr[se].datlen;
         }
         trkoffs += secoffs;
      }
   fseek(ff, hsize, SEEK_SET);
   fwrite(dsc, 1, tlen, ff);
   for (c = 0; c < cyls; c++)
      for (s = 0; s < sides; s++) {
         t.seek(this,c,s,LOAD_SECTORS);
         for (unsigned se = 0; se < t.s; se++)
            if (t.hdr[se].data)
               if (fwrite(t.hdr[se].data, 1, t.hdr[se].datlen, ff) != t.hdr[se].datlen) return 0;
      }
   return 1;
}
コード例 #5
0
int FDD::write_td0(FILE *ff)
{
   u8 zerosec[256] = { 0 };
   u8 td0hdr[12] = { 0 };

   *(u16*)td0hdr = WORD2('T','D');
   td0hdr[4] = 21; td0hdr[6] = 2; td0hdr[9] = (u8)sides;
   if (*dsc) td0hdr[7] = 0x80;
   *(u16*)(td0hdr + 10) = crc16(td0hdr, 10);
   fwrite(td0hdr, 1, 12, ff);
   if (*dsc) {
      u8 inf[0x200] = { 0 };
      strcpy((char*)inf+10, dsc);
      unsigned len = strlen(dsc)+1;
      *(unsigned*)(inf+2) = len;
      *(u16*)inf = crc16(inf+2, len+8);
      fwrite(inf, 1, len+10, ff);
   }

   unsigned c; //Alone Coder 0.36.7
   for (/*unsigned*/ c = 0; c < cyls; c++)
      for (unsigned s = 0; s < sides; s++) {
         t.seek(this,c,s,LOAD_SECTORS);
         u8 bf[16];
         *bf = t.s;
         bf[1] = c, bf[2] = s;
         bf[3] = (u8)crc16(bf, 3);
         fwrite(bf, 1, 4, ff);
         for (unsigned sec = 0; sec < t.s; sec++) {
            if (!t.hdr[sec].data) { t.hdr[sec].data = zerosec, t.hdr[sec].datlen = 256, t.hdr[sec].l = 1; }
            *(unsigned*)bf = *(unsigned*)&t.hdr[sec];
            bf[4] = 0; // flags
            bf[5] = (u8)crc16(t.hdr[sec].data, t.hdr[sec].datlen);
            *(u16*)(bf+6) = t.hdr[sec].datlen + 1;
            bf[8] = 0; // compression type = none
            fwrite(bf, 1, 9, ff);
            if (fwrite(t.hdr[sec].data, 1, t.hdr[sec].datlen, ff) != t.hdr[sec].datlen) return 0;
         }
      }
   c = WORD4(0xFF,0,0,0);
   if (fwrite(&c, 1, 4, ff) != 4) return 0;
   return 1;
}
コード例 #6
0
ファイル: rijndael.c プロジェクト: Anachid/mozilla-central
static PRStatus 
init_rijndael_tables(void)
{
    PRUint32 i;
    PRUint8 si01, si02, si03, si04, si08, si09, si0B, si0D, si0E;
    struct rijndael_tables_str *rts;
    rts = (struct rijndael_tables_str *)
                   PORT_Alloc(sizeof(struct rijndael_tables_str));
    if (!rts) return PR_FAILURE;
    for (i=0; i<256; i++) {
	/* The forward values */
	si01 = SBOX(i);
	si02 = XTIME(si01);
	si03 = si02 ^ si01;
	rts->T0[i] = WORD4(si02, si01, si01, si03);
	rts->T1[i] = WORD4(si03, si02, si01, si01);
	rts->T2[i] = WORD4(si01, si03, si02, si01);
	rts->T3[i] = WORD4(si01, si01, si03, si02);
	/* The inverse values */
	si01 = SINV(i);
	si02 = XTIME(si01);
	si04 = XTIME(si02);
	si08 = XTIME(si04);
	si03 = si02 ^ si01;
	si09 = si08 ^ si01;
	si0B = si08 ^ si03;
	si0D = si09 ^ si04;
	si0E = si08 ^ si04 ^ si02;
	rts->TInv0[i] = WORD4(si0E, si09, si0D, si0B);
	rts->TInv1[i] = WORD4(si0B, si0E, si09, si0D);
	rts->TInv2[i] = WORD4(si0D, si0B, si0E, si09);
	rts->TInv3[i] = WORD4(si09, si0D, si0B, si0E);
    }
    /* wait until all the values are in to set */
    rijndaelTables = rts;
    return PR_SUCCESS;
}