информационная безопасность
без паники и всерьез
 подробно о проекте
Страшный баг в WindowsАтака на InternetПортрет посетителя
BugTraq.Ru
Русский BugTraq
 Анализ криптографических сетевых... 
 Модель надежности двухузлового... 
 Специальные марковские модели надежности... 
 Модульный ботнет от русских хакеров 
 Торвальдс и вайбтестеры 
 Атака на GitHub 
главная обзор RSN блог библиотека закон бред форум dnet о проекте
bugtraq.ru / форум / programming
Имя Пароль
ФОРУМ
если вы видите этот текст, отключите в настройках форума использование JavaScript
регистрация





Легенда:
  новое сообщение
  закрытая нитка
  новое сообщение
  в закрытой нитке
  старое сообщение
  • Напоминаю, что масса вопросов по функционированию форума снимается после прочтения его описания.
  • Новичкам также крайне полезно ознакомиться с данным документом.
[Pas 2 C] держи заготовку - править напильником вручную... 24.09.01 16:06  Число просмотров: 1435
Автор: XR <eXtremal Research> Статус: The Elderman
<"чистая" ссылка>
> есть прога небольшая, для меня весьма важная..
> к ней есть исходник на паскале..
> поначалу я думал, что сам разберусь, однако не вышло..
>
> собственно я был бы весьма признателен, если кто-нибудь
> переписал её в С..
>
>

/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */
/* From input file "test.pas" */


/* */
/* Written by Stephane BAUSSON (1993) */
/*

Parallel Port DB25-Female

pin assignment pin assignment

1 -Strobe 2 Data 0
3 Data 1 4 Data 2
5 Data 3 6 Data 4
7 Data 5 8 Data 6
9 Data 7 10 -Ack
11 Busy 12 Paper Empty
13 Select 14 -Auto Feed
15 -Error 16 -Init
17 -Slct in 18 GND
19 GND 20 GND
21 GND 22 GND
23 GND 24 GND
25 GND

6 (d.b.0) - Data 4
8 Rst Data 6
9 Clk Data 7
11 Busy I/O
19 GND GND

$40 - Rst
$80 - Clk
$C0 - Rst & Clock
[port+1] and $80 - I/O
==========================================
Leshka
25 Gnd
1 -Strobe I/O
2 Data0 Clk
3 Data1 Rst
4 Data2 Vcc

$37a:=$20 - ???®¤ ? 0?¬ ?­??

*/


#include <p2c/p2c.h>


#define port_address    0x378   /* lpr1 chosen */

#define out_address     (port_address + 2)
#define in_address      (port_address + 1)

#define ino_address     port_address

/*
c0 = $ff;
c1 = $fe; { VCC Strobe pin 1 */
#define cr              0xfd   /* Rst AutoLineFeed pin 14 */
#define cc              0xf7   /* Clk SLCT IN pin 17 */
/* p2c: test.pas, line 64: Warning: Symbol 'C1' is not defined [221] */

#define c1r             (c1 & cr)
/* p2c: test.pas, line 65: Warning: Symbol 'C1' is not defined [221] */
#define c1c             (c1 & cc)
/* p2c: test.pas, line 66: Warning: Symbol 'C1' is not defined [221] */
#define c1rc            (c1 & cr & cc)

#define crc             (cr & cc)
#define data_mask       0xb   /* ¤«?ND */
/* p2c: test.pas, line 69: Warning: Unmatched '*)' in input file [245] */

#define c0              0
#define c1              0x4
/* p2c: test.pas, line 73: Warning: Symbol 'CR' was already defined [220] */
#define cr_             0x2
/* p2c: test.pas, line 74: Warning: Symbol 'CC' was already defined [220] */
#define cc_             0x1
#define cd              0x8
/* p2c: test.pas, line 76: 
 * Warning: Symbol 'C1R' was already defined [220] */
#define c1r_            (c1 | cr_)
/* p2c: test.pas, line 77: 
 * Warning: Symbol 'C1C' was already defined [220] */
#define c1c_            (c1 | cc_)
/* p2c: test.pas, line 78: 
 * Warning: Symbol 'C1RC' was already defined [220] */
#define c1rc_           (c1 | cr_ | cc_)
#define c1d             (c1 | cd)
#define c1dc            (c1 | cd | cc_)
#define c1dr            (c1 | cd | cr_)
#define c1drc           (c1 | cd | cr_ | cc_)
/* p2c: test.pas, line 83: 
 * Warning: Symbol 'CRC' was already defined [220] */
#define crc_            (cr_ | cc_)
/* p2c: test.pas, line 84: 
 * Warning: Symbol 'DATA_MASK' was already defined [220] */
#define data_mask_      0xf   /* ¤«?ND. Ne objazat-no */


typedef Char string8[9];

typedef Char string2[3];

typedef Char string4[5];

typedef uchar TBuf[64];
typedef uchar TAutor[6];



Static long delayconst = 0;   /* k-vo ciklov w 1 us*/
Static long displaying = 0, byte_number = 16, delaytyp = 1, measure = 1;
    /* ++ ¤??  ¬?¦¤?lk1>0 ? ?§¬?7??¬ */
Static long period = 15;   /* "«?­  Clk */
Static Registers reg;
Static long i, j;
Static TBuf Data;
Static Char car;
Static FILE *f;
Static LONGINT biosticks = (long *)0x46c;


/* p2c: test.pas, line 99:
 * Note: Absolute-addressed variable biosticks was generated [116] */


Static Void absdelay(delayus)
LONGINT delayus;
{
  LONGINT i;
  LONGINT j = delayus;

  for (i = 1; i <= j; i++) ;
}


/*delayconst - 1000 us
x - delaytmp us
x=delayconst*delaytmp/1000
*/
Static Void MyDelay(delayus)
LONGINT delayus;
{
  LONGINT i, j;

  /* x:=delayconst*delayus / 1000;
j:=round(x); */
  if (delayus >= 0)
    j = delayus * delayconst;
  else
    j = -delayus;
  for (i = 1; i <= j; i++) ;
}


/* Mydelay2(delayconst) - zaderzhka na 1000 us*/
Static Void MyDelay2(delaytmp)
LONGINT delaytmp;
{
  LONGINT i, j;

  /* x:=delayconst*delaytmp / 1000;
j:=round(x); */
  if (delaytmp >= 0)
    j = delaytmp * delayconst;
  else
    j = -delaytmp;
  for (i = 1; i <= delaytmp; i++) ;
}


-----------------------------------------------------------------------------
Static Void Send0(b)
uchar b;
{
  PORT(ino_address) = data_mask_ & b;
/* p2c: test.pas, line 137: Note: Reference to PORT [191] */
/* p2c: test.pas, line 137: Warning: Invalid assignment [168] */
}


Static Void Send(b)
uchar b;
{
  MyDelay(period);
  PORT(ino_address) = data_mask_ & b;
/* p2c: test.pas, line 143: Note: Reference to PORT [191] */
/* p2c: test.pas, line 143: Warning: Invalid assignment [168] */
}


Static Void dummy()
{
  long i = 0;
}


Static Void Sendtest(b)
uchar b;
{
  dummy();
  PORT(ino_address) = data_mask_ & b;
/* p2c: test.pas, line 155: Note: Reference to PORT [191] */
/* p2c: test.pas, line 155: Warning: Invalid assignment [168] */
}


Static Void sendbyte(b)
uchar b;
{
  uchar x, i;

  for (i = 8; i >= 1; i--) {
    x = (b >> i) & 1;
    Send(x);
  }
}


-----------------------------------------------------------------------------

Static uchar Get()
{
  uchar b;

  b = PORT(in_address);
/* p2c: test.pas, line 173: Note: Reference to PORT [191] */
  b = (b >> 6) & 1;
  return b;
}


/* ?®?^(a)  ?® «?­?? I/O */
Static Void put(b)
uchar b;
{
  MyDelay(period);
  PORT(ino_address) = b;
/* p2c: test.pas, line 182: Note: Reference to PORT [191] */
/* p2c: test.pas, line 182: Warning: Invalid assignment [168] */
}


Static Void mkrst()
{
  Send(c1r_);
  Send(c1);
}


Static Void mkclk()
{
  Send(c1c_);
  Send(c1);
}


Static Void goto0()
{
  Send(c1);
  Send(c1r_);
  Send(c1rc_);
  Send(c1r_);
  Send(c1);
}


Static Void goton(value)
long value;
{
  long i;

  goto0();
  for (i = 1; i <= value; i++) {
    Send(c1c_);
    Send(c1);
  }
}


Static Void clks(value)
long value;
{
  long i;

  for (i = 1; i <= value; i++) {
    Send(c1c_);
    Send(c1);
  }
}


/* - convert a 4 bit long decimal number to hexadecimal. */

Static Char dec2hexa_one(value)
uchar value;
{
  Char Result;

  switch (value) {

  case 10:
  case 11:
  case 12:
  case 13:
  case 14:
  case 15:
    Result = value + 0x37;
    break;

  default:
    if (value <= 9)
      Result = value + 0x30;
    break;
  }
  return Result;
}


-----------------------------------------------------------------------------
/* FUNCTION d2h(decimal_byte):string2; */
/* */
/* - convert a decimal byte to its hexadecimal representation. */
-----------------------------------------------------------------------------

Static Char *d2h(Result, value)
Char *Result;
uchar value;
{
  uchar msbb, lsbb;

  msbb = (value & 0xf0) >> 4;
  lsbb = value & 0xf;
  sprintf(Result, "%c%c", dec2hexa_one(msbb), dec2hexa_one(lsbb));
  return Result;
}


Static Char *w2h(Result, value)
Char *Result;
long value;
{
  string4 s;
  string2 STR1, STR2;

  sprintf(s, "%s%s",
	  d2h(STR1, ((int)(value & 0xff00L)) >> 8),
	  d2h(STR2, (int)(value & 0xff)));
  return strcpy(Result, s);
}


Static Char *w2hsp(Result, value)
Char *Result;
long value;
{
  string4 s;
  long i;

  w2h(s, value);
  for (i = 0; i <= 2; i++) {
    if (s[i] == '0')
      s[i] = ' ';
    else {
      fflush(0);
      P_ioresult = 0;
    }
  }
/* p2c: test.pas, line 254:
 * Warning: Expected a '(', found a semicolon [227] */
/* p2c: test.pas, line 254:
 * Warning: Expected an expression, found a semicolon [227] */
  return strcpy(Result, s);
}


-----------------------------------------------------------------------------

Static Char *Binary(Result, b)
Char *Result;
uchar b;
{
  uchar weigth = 0x80;
  string8 s;

  *s = '\0';
  while (weigth > 0) {
    if ((b & weigth) == weigth)
      strcat(s, "1");
    else
      strcat(s, "0");
    weigth /= 0x2;
  }
  return strcpy(Result, s);
}


/*
FUNCTION Units:byte;

VAR u, i : integer;
s : string8;

BEGIN u:=0;
i:=13;
while (Data[i] = $FF) do
BEGIN u:=u+8;
i:=i+1;
END;
s:=Binary(Data[i]);
while(s[1]='1') do
BEGIN inc(u);
s:=copy(s,2,length(s));
END;
units:=u;
END;


function Units_2:LongInt;

BEGIN Units_2:=4096*Data[9]+512*Data[10]+64*Data[11]+8*Data[12]+Data[13];
END;

*/

Static Void waiting()
{
  Send(c1);
  /* write('Delay (1/2 period): ',mhz,' us, 1us=(',delayconst,') '); */
  printf(" Press a key ...");
  do {
  } while (!kbhit());
  gotoxy(1, (int)wherey);
  clreol();
}


-----------------------------------------------------------------------------

Static Void Full_Displaying()
{
  long FORLIM;
  string8 STR1;
  string2 STR3;

  for (i = 1; i <= 80; i++)
    putchar('-');
  FORLIM = byte_number / 6 + 1;
  for (i = 1; i <= FORLIM; i++) {
    printf("%3ld", (i - 1) * 48);
    for (j = 1; j <= 6; j++) {
      if (j + (i - 1) * 6 <= byte_number)
	printf("%9s", Binary(STR1, Data[j + (i - 1) * 6 - 1]));
    }
    gotoxy(59, (int)wherey);
    printf("%3ld", (i - 1) * 6);
    for (j = 1; j <= 6; j++) {
      if (j + (i - 1) * 6 <= byte_number)
	printf(" %s", d2h(STR3, Data[j + (i - 1) * 6 - 1]));
    }
    putchar('\n');
  }
}


-----------------------------------------------------------------------------

Static Void Short_Displaying()
{
  long j, FORLIM;
  string2 STR1;

  FORLIM = byte_number;
  for (j = 0; j < FORLIM; j++)
    printf("%s ", d2h(STR1, Data[j]));
  putchar('\n');
}


Static Void Hex_Displaying()
{
  long FORLIM;
  string4 STR2;
  string2 STR3;

  for (i = 1; i <= 80; i++)
    putchar('-');
  FORLIM = byte_number / 16;
  for (i = 1; i <= FORLIM; i++) {
    printf("[%3ld%4ld%s]",
	   (i - 1) * 16, (i - 1) * 128, w2hsp(STR2, (i - 1) * 128));
    for (j = 1; j <= 8; j++) {
      if (j + (i - 1) * 16 <= byte_number)
	printf(" %s", d2h(STR3, Data[j + (i - 1) * 16 - 1]));
    }
    printf(" [%3ld%4ld%s]",
	   (i - 1) * 16 + 8, (i - 1) * 128 + 64,
	   w2hsp(STR2, (i - 1) * 128 + 64));
    for (j = 9; j <= 16; j++) {
      if (j + (i - 1) * 16 <= byte_number)
	printf(" %s", d2h(STR3, Data[j + (i - 1) * 16 - 1]));
    }
    putchar('\n');
  }
}


/*-----------------------------------------------------------------------------
,?^(a)®?­®? ?­??
-----------------------------------------------------------------------------*/
Static Void reading()
{
  long i, j;
  uchar value;
  LONGINT x, y, z;
  long FORLIM;

  x = period;
  y = measure;
  if (x <= 0)
    x = -x;
  else
    x *= delayconst;
  if (y <= 0)
    y = -y;
  else
    y *= delayconst;
  if (x > y)
    x -= y;
  else
    x = 0;
  FORLIM = byte_number;
  for (i = 0; i < FORLIM; i++) {
    value = 0;
    for (j = 1; j <= 8; j++) {
      for (z = 1; z <= y; z++) ;
      value = (value << 1) + Get();
      for (z = 1; z <= x; z++) ;
      Send(c1c_);
      MyDelay(period);
      Send(c1);
    }
    Data[i] = value;
  }
}


Static Void show_result()
{
  switch (displaying) {

  case 0:
    Full_Displaying();
    break;

  case 1:
    Short_Displaying();
    break;

  case 2:
    Hex_Displaying();
    break;
  }
}


Static Void readnshow()
{
  reading();
  show_result();
}


Static Void Reading2()
{
  long i, j;
  uchar Value;
  long FORLIM;

  FORLIM = byte_number;
  for (i = 0; i < FORLIM; i++) {
    Value = 0;
    for (j = 1; j <= 8; j++) {
      Value += Value + Get();
      Send(c1c_);
      Send(c1);
    }
    Data[i] = Value;
  }
  switch (displaying) {

  case 0:
    Full_Displaying();
    break;

  case 1:
    Short_Displaying();
    break;

  case 2:
    Hex_Displaying();
    break;
  }
}


-----------------------------------------------------------------------------

Static Void writting()
{
  long n;

  printf("Which bit do you want to set to \"0\" (from 0): ");
  scanf("%ld%*[^\n]", &n);
  getchar();

  goton(n);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(5000L);
  Send(c1);
}


Static Void writting1()
{
  long j, n, m;
  LONGINT d;

  printf("Enter bit pos (from 0), # of bits and delay in us : ");
  scanf("%ld%ld%ld%*[^\n]", &n, &m, &d);
  getchar();

  for (j = 0; j < m; j++) {
    goton(n + j);
    Send(c1r_);
    Send(c1);
    Send(c1c_);
    if (d != 0)
      MyDelay(d);
    Send(c1);
  }
}


Static Void wrcarry()
{
  long n;
  LONGINT d;

  printf("Write carry. Enter bit pos (from 0) and delay in us : ");
  scanf("%ld%ld%*[^\n]", &n, &d);
  getchar();

  goton(n);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(d);
  Send(c1);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(d);
  Send(c1);
}


Static Void triple()
{
  long n;
  LONGINT d;

  printf("Triple Rst Clk. Enter bit pos (from 0) and delay in us : ");
  scanf("%ld%ld%*[^\n]", &n, &d);
  getchar();

  goton(n);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(d);
  Send(c1);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(d);
  Send(c1);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(d);
  Send(c1);
}


-----------------------------------------------------------------------------

Static Void dumping()
{
  Char filename[256];
  FILE *f = NULL;
  unsigned short i;
  string2 STR1;
  unsigned short FORLIM;

  printf("Enter the filename: ");
  gets(filename);
/* p2c: test.pas, line 494: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(f, filename);
/* p2c: test.pas, line 495: Note: REWRITE does not specify a name [181] */
  if (f != NULL)
    rewind(f);
  else
    f = tmpfile();
  if (f == NULL)
    _EscIO(FileNotFound);
  FORLIM = byte_number;
  for (i = 0; i <= FORLIM - 1; i++)
    fprintf(f, "%s ", d2h(STR1, Data[i]));
  fclose(f);
  f = NULL;
}


/* 1 sec = 18.2 ticks
ticks - delayconst
18.2 - x
*/
Static Void testspd()
{
  LONGINT ticks;
  double x;

  delayconst = 1;
  while (delayconst < 0x40000000L) {
    ticks = *biosticks;
    MyDelay2(delayconst);
    ticks = *biosticks - ticks;
    if (ticks > 10) {
      /* x:=(delayconst*18.2)/ticks*10(-3) - pri takoj const. zaderzhka 1 msec. */
      x = delayconst * 18.2 / ticks / 1000000L;
      delayconst = (long)floor(x + 0.5);
/* p2c: test.pas, line 518:
 * Warning: Expected a '(', found a semicolon [227] */
/* p2c: test.pas, line 518:
 * Warning: Expected an expression, found a semicolon [227] */
      fflush(0);
      P_ioresult = 0;
    }
    delayconst <<= 1;
  }
  if (delayconst < 2)
    printf("Slow cpu, delays are inaccurate\n");
}


-----------------------------------------------------------------------------

Static Void initialize()
{
  long i;

  clrscr();
  window(1L, 1L, 80L, 25L);
  printf(" B-read begin\n");
  printf(" 1-%3ld bit\n", byte_number * 8);
  printf(" F-format%2ld\n", displaying);
  window(17L, 1L, 80L, 25L);
  printf("P-Period%7ld\n", period);
  printf(" Delay %7ld\n", measure);
  printf("R-read&comp\n");
  window(38L, 1L, 80L, 25L);
  printf("H-help\n");
  printf("Q-quit\n");
  printf("S-save\n");
  window(49L, 1L, 80L, 25L);
  printf("W-write bit\n");
  printf("N-write n bit\n");
  printf("C-write carry\n");
  window(64L, 1L, 80L, 25L);
  printf("K-from keyb\n");
  printf("O-power-off tst\n");
  printf("3-triple RstClk\n");
  window(1L, 4L, 80L, 25L);
  printf("===== 1us=(%4ld) ", delayconst);
  for (i = 18; i <= 80; i++)
    putchar('=');
  window(1L, 5L, 80L, 25L);
  PORT(port_address + 2) &= 0xdf;   /* ???®¤ ? 0?¬ § ???*/
/* p2c: test.pas, line 558: Note: Reference to PORT [191] */
/* p2c: test.pas, line 558: Note: Reference to PORT [191] */
/* p2c: test.pas, line 558: Warning: Invalid assignment [168] */
  PORT(port_address) = 0;
/* p2c: test.pas, line 559: Note: Reference to PORT [191] */
/* p2c: test.pas, line 559: Warning: Invalid assignment [168] */
}


Static Void dohelp()
{
  clrscr();
  printf("A - Autorisation from file\n");
  printf("U - aUtorization endless\n");
  printf("D - Dump to file\n");
}


Static Void resetadr()
{
  goto0();
  readnshow();
}


Static Void loopread()
{
  do {
    readnshow();
  } while (!kbhit());
}


#define ctrl            4
#define alt             8
#define caps            0x40


Static Void interact()
{
  uchar *kb_flags = (uchar *)0x417;
/* p2c: test.pas, line 585:
 * Note: Absolute-addressed variable kb_flags was generated [116] */
  uchar *kb_flags1 = (uchar *)0x418;
/* p2c: test.pas, line 586:
 * Note: Absolute-addressed variable kb_flags1 was generated [116] */
  uchar b;
  uchar bo = 0xff;
  Char s[21];
  long t = 0;
  LONGINT mdelay;
  string4 STR1;

  gotoxy(1, 18);
  clreol();
  gotoxy(1, 19);
  clreol();
  printf(" Clk Rst I/O Alt=Clk Ctrl=Rst CapsLock-repeat Clk(Alt-accelerat)\n");
  clreol();
  do {
    b = c1;
    strcpy(s, " ");
    if (((*kb_flags) & alt) == 0) {
      b = c1c_;
      strcpy(s, " 1 ");
    }
    if (((*kb_flags) & ctrl) == 0) {
      b &= cr_;
      strcat(s, " 1 ");
    } else
      strcat(s, " ");
    switch (b) {

    case c1rc_:
      t = 0;
      break;

    case c1:
      if (bo == c1c_)
	t++;
      break;
    }
    bo = b;
    Send(b);
    b = Get();
    if (b > 0)
      strcat(s, " 1 ");
    else
      strcat(s, " 0 ");
    gotoxy(1, 20);
    printf("%s%6ld%6s", s, t, w2hsp(STR1, t));
    while (((*kb_flags1) & caps) > 0) {
      if (((*kb_flags) & alt) == 0)
	mdelay = 50000L;
      else
	mdelay = 7000;
      Send(c1c_);
      MyDelay(mdelay);
      Send(c1);
      MyDelay(mdelay);
      b = Get();
      gotoxy(1, 20);
      printf("%3c%8d%7ld%6s", 'x', b, t, w2hsp(STR1, t));
      t++;
      if (t > 512)
	t = 0;
    }

  } while (!kbhit());
}

#undef ctrl
#undef alt
#undef caps


Static Void pwrtest()
{
  LONGINT pause;

  gotoxy(1, (int)wherey);
  clreol();
  printf("Enter power-off pause (us) ");
  scanf("%ld%*[^\n]", &pause);
  getchar();
  Send0(c0);
  MyDelay(500000L);
  Send0(c1);
  MyDelay(3000L);
  readnshow();
  Send0(c0);
  MyDelay(pause);
  Send0(c1);
  MyDelay(3000L);
  readnshow();

}


Static Void readcmp()
{
  long i = 1;
  long j, n;
  TBuf buf;
  boolean z = true;
  long FORLIM;

  printf("Read and compare. Enter numb_of_try ");
  scanf("%ld%*[^\n]", &n);
  getchar();
  goto0();
  reading();
  memmove((Anyptr)buf, (Anyptr)Data, sizeof(TBuf));
  while (i <= n && z) {
    goto0();
    reading();
    FORLIM = byte_number;
    for (j = 0; j < FORLIM; j++)
      z = (z && Data[j] == buf[j]);
    i++;
  }
  if (z)
    printf("All identical\n");
  else {
    printf("Mismatch in%5ld test\n", i);
    show_result();
  }
  putchar('\n');
}


Static Void getperiod()
{
  printf("Enter period and delay in us ");
  scanf("%ld%ld%*[^\n]", &period, &measure);
  getchar();
  initialize();
}


Static Void saveinit()
{
  FILE *f = NULL;

/* p2c: test.pas, line 666: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(f, "card.ini");
/* p2c: test.pas, line 667: Note: REWRITE does not specify a name [181] */
  if (f != NULL)
    rewind(f);
  else
    f = tmpfile();
  if (f == NULL)
    _EscIO(FileNotFound);
  fprintf(f, "%12ld %12ld %12ld %12ld",
	  period, measure, byte_number, displaying);
  fclose(f);
  f = NULL;
  printf("Settinds saved\n");
}


Static Char *autorform(Result, ch, z)
Char *Result;
uchar *ch;
unsigned short z;
{
  long i;
  Char s[256];
  string2 STR1;
  string4 STR2;

  *s = '\0';
  for (i = 0; i <= 5; i++)
    sprintf(s + strlen(s), "%s ", d2h(STR1, ch[i]));
  sprintf(s + strlen(s), " %s", w2h(STR2, (long)z));
  return strcpy(Result, s);
}


Static unsigned short autor1(ch)
uchar *ch;
{
  long i, j;
  unsigned short z = 0;
  uchar t;

  goto0();
  clks(110L);
  mkrst();
  Send(c1c_);
  Send(c1);
  clks(177L);
  for (i = 0; i <= 5; i++) {
    for (j = 7; j >= 0; j--) {
      t = (ch[i] >> j) & 1;
      if (t == 1)
	Send(c1c_);
      else
	Send(c1dc);
      MyDelay(1L);
      Send(c1);
    }
  }
  MyDelay(1L);
  for (i = 1; i <= 16; i++) {
    clks(160L);
    MyDelay(1L);
    z = (z << 1) + Get();
  }
  return z;
}


Static Void autor()
{
  FILE *fr = NULL, *fw = NULL;
  Char sr[31], sw[31];
  long i;
  unsigned short z;
  TAutor ch;
  Char STR1[256];
  Char *TEMP;
  int TEMP1;

  printf("Enter file_challenge >");
  fgets(sr, 31, stdin);
  TEMP = strchr(sr, '\n');
  if (TEMP != NULL)
    *TEMP = 0;
/* p2c: test.pas, line 717: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(fr, sr);
  rewind(fr);
  if (P_ioresult != 0) {
    printf("Error reading %s", sr);
    return;
  }
  printf("Enter file_output >");
  fgets(sw, 31, stdin);
  TEMP = strchr(sw, '\n');
  if (TEMP != NULL)
    *TEMP = 0;
/* p2c: test.pas, line 721: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(fw, sw);
/* p2c: test.pas, line 721: Note: REWRITE does not specify a name [181] */
  if (fw != NULL)
    rewind(fw);
  else
    fw = tmpfile();
  if (fw == NULL)
    _EscIO(FileNotFound);
  while (!P_eof(fr)) {
    for (i = 0; i <= 5; i++) {
      fscanf(fr, "%d", &TEMP1);
      ch[i] = TEMP1;
    }
    fscanf(fr, "%*[^\n]");
    getc(fr);
    z = autor1(ch);
    fprintf(fw, "%s\n", autorform(STR1, ch, z));
    clks(50L);   /* Na wsjakij sluchaj */
  }
  if (fr != NULL)
    fclose(fr);
  fr = NULL;
  fclose(fw);
  fw = NULL;
}


Static Void autorless()
{
  FILE *fw = NULL;
  Char sw[31];
  long i, j;
  unsigned short z;
  TAutor ch;
  Char c = 'a';
  LONGINT l, ticks;
  string2 STR1;
  Char *TEMP;
  Char STR2[256], STR3[256];
  int TEMP1, TEMP2, TEMP3, TEMP4, TEMP5, TEMP6;

  printf("Enter file_output >");
  fgets(sw, 31, stdin);
  TEMP = strchr(sw, '\n');
  if (TEMP != NULL)
    *TEMP = 0;
/* p2c: test.pas, line 743: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(fw, sw);
/* p2c: test.pas, line 743: Note: REWRITE does not specify a name [181] */
  if (fw != NULL)
    rewind(fw);
  else
    fw = tmpfile();
  if (fw == NULL)
    _EscIO(FileNotFound);
  reading();
  for (i = 1; i <= sizeof(TBuf); i++) {
    fprintf(fw, "%3s", d2h(STR1, Data[i-1]));
    if ((i & 7) == 0)
      putc('\n', fw);
  }
  putc('\n', fw);

  for (i = 0; i <= 5; i++)
    ch[i] = 0;
  z = autor1(ch);
  fprintf(fw, "%s\n", autorform(STR2, ch, z));

  for (i = 0; i <= 5; i++)
    ch[i] = 0xff;
  z = autor1(ch);
  fprintf(fw, "%s\n\n", autorform(STR2, ch, z));

  for (i = 47; i >= 0; i--) {
    for (j = 0; j <= 5; j++)
      ch[j] = 0;
    j = ((unsigned long)i) >> 3;
    ch[j] = 1 << (7 - (i & 7));
    z = autor1(ch);
    fprintf(fw, "%s\n", autorform(STR2, ch, z));
  }
  putc('\n', fw);
  printf("Enter first challenge (6 bytes) > ");
  scanf("%d%d%d%d%d%d%*[^\n]", &TEMP1, &TEMP2, &TEMP3, &TEMP4, &TEMP5, &TEMP6);
  getchar();
  ch[0] = TEMP1;
  ch[1] = TEMP2;
  ch[2] = TEMP3;
  ch[3] = TEMP4;
  ch[4] = TEMP5;
  ch[5] = TEMP6;
  printf("Performing Challenge scan. Press Q to quit\n\n");
  ticks = *biosticks;
  while ((ch[0] | ch[1] | ch[2] | ch[3] | ch[4] | ch[5]) > 0) {
    z = autor1(ch);
    fprintf(fw, "%s\n", autorform(STR2, ch, z));
    if (kbhit()) {
      c = toupper(getch());
      if (c == 'Q') {
	fflush(0);
	P_ioresult = 0;
      }
/* p2c: test.pas, line 777:
 * Warning: Expected a '(', found a semicolon [227] */
/* p2c: test.pas, line 777:
 * Warning: Expected an expression, found a semicolon [227] */
    }
    ch[5]++;
    if (ch[5] == 0) {
      ch[4]++;
      if (ch[4] == 0) {
	ch[3]++;
	if (ch[3] == 0) {
	  ch[2]++;
	  if (ch[2] == 0) {
	    ch[1]++;
	    if (ch[1] == 0)
	      ch[0]++;
	  }
	}
      }
    }
    l = *biosticks - ticks;
    if (l <= 180)
      continue;
    fclose(fw);
/* p2c: test.pas, line 789: Note: APPEND does not specify a name [181] */
    fw = tmpfile();
    if (fw == NULL)
      _EscIO(FileNotFound);
    printf("\015%s", autorform(STR3, ch, z));
    ticks = *biosticks;
  }
  fclose(fw);
}


=============================================================================

main(argc, argv)
int argc;
Char *argv[];
{
  PASCAL_MAIN(argc, argv);
  f = NULL;
  testspd();
/* p2c: test.pas, line 800: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(f, "card.ini");
  rewind(f);
  if (P_ioresult == 0) {
    fscanf(f, "%ld%ld%ld%ld", &period, &measure, &byte_number, &displaying);
    if (f != NULL)
      fclose(f);
    f = NULL;
  }
  initialize();
  /* send($C0); send($0); */
  do {
    waiting();
    car = toupper(getch());
    switch (car) {

    case 'W':
      writting();
      break;

    case 'N':
      writting1();
      break;

    case 'C':
      wrcarry();
      break;

    case 'B':
      resetadr();
      break;

    case 'L':
      loopread();
      break;

    case 'Q':
      /* blank case */
      break;

    case '3':
      triple();
      break;

    case '1':
      if (byte_number == 64)
	byte_number = 16;
      else
	byte_number <<= 1;
      initialize();
      break;

    case 'K':
      interact();
      break;

    case 'O':
      pwrtest();
      break;

    /* 'D':begin delaytyp:=(delaytyp+1) and 1; initialize; end; */
    case 'F':
      if (displaying < 2)
	displaying++;
      else
	displaying = 0;
      initialize();
      break;

    case 'D':
      dumping();
      break;

    case 'P':
      getperiod();
      break;

    case 'S':
      saveinit();
      break;

    case 'R':
      readcmp();
      break;

    case 'A':
      autor();
      break;

    case 'U':
      autorless();
      break;

    case 'H':
      dohelp();
      break;

    default:
      readnshow();
      break;
    }
  } while (car != 'Q');
  PORT(port_address + 2) |= 0x20;   /* ???®¤ ? 0?¬ ?­??*/
/* p2c: test.pas, line 834: Note: Reference to PORT [191] */
/* p2c: test.pas, line 834: Note: Reference to PORT [191] */
/* p2c: test.pas, line 834: Warning: Invalid assignment [168] */
  if (f != NULL)
    fclose(f);
  exit(EXIT_SUCCESS);
}



/* End. */



---
<programming>
[Pas 2 C] прогу из pas в с(++) 24.09.01 14:13  
Автор: zelych Статус: Member
<"чистая" ссылка>
есть прога небольшая, для меня весьма важная..
к ней есть исходник на паскале..
поначалу я думал, что сам разберусь, однако не вышло..

собственно я был бы весьма признателен, если кто-нибудь переписал её в С..

по поводу дополнительных условий договоримся..
если есть какие предложения - пишите лучше на s_@id.ru, а то я здесь последнее время весьма редко бываю..

а вот собственно и прога:

{ }
{ Written by Stephane BAUSSON (1993) }
{

Parallel Port DB25-Female

pin assignment pin assignment

1 -Strobe 2 Data 0
3 Data 1 4 Data 2
5 Data 3 6 Data 4
7 Data 5 8 Data 6
9 Data 7 10 -Ack
11 Busy 12 Paper Empty
13 Select 14 -Auto Feed
15 -Error 16 -Init
17 -Slct in 18 GND
19 GND 20 GND
21 GND 22 GND
23 GND 24 GND
25 GND

6 (d.b.0) - Data 4
8 Rst Data 6
9 Clk Data 7
11 Busy I/O
19 GND GND

$40 - Rst
$80 - Clk
$C0 - Rst & Clock
[port+1] and $80 - I/O
==========================================
Leshka
25 Gnd
1 -Strobe I/O
2 Data0 Clk
3 Data1 Rst
4 Data2 Vcc

$37a:=$20 - &#143;¥ॢ®¤ ¢ ०¨¬ 碥­¨

}

USES crt, dos;

CONST port_address=$378; { lpr1 chosen }
out_address =port_address+2;
in_address =port_address+1;
ino_address =port_address;

delayconst : longint = 0; { k-vo ciklov w 1 us}
displaying : integer = 0;
byte_number : integer = 16;
delaytyp : integer = 1;
measure : longint = 1; { &#135; ¤¥প  ¬¥¦¤㠃lk1>0 ¨ ¨§¬¥७¨¥¬ }
period : longint = 15; { &#132;«¨­  Clk }

(*
c0 = $ff;
c1 = $fe; { VCC Strobe pin 1 }
cr = $fd; { Rst AutoLineFeed pin 14 }
cc = $f7; { Clk SLCT IN pin 17 }
c1r = c1 and cr;
c1c = c1 and cc;
c1rc = c1 and cr and cc;
crc = cr and cc;
data_mask = $b; { ¤«ND }
*)

c0 = $00;
c1 = $04;
cr = $02;
cc = $01;
cd = $08;
c1r = c1 or cr;
c1c = c1 or cc;
c1rc = c1 or cr or cc;
c1d = c1 or cd;
c1dc = c1 or cd or cc;
c1dr = c1 or cd or cr;
c1drc = c1 or cd or cr or cc;
crc = cr or cc;
data_mask = $0f; { ¤«ND. Ne objazat-no }

TYPE
string8=string[8];
string2=string[2];
string4=string[4];
TBuf = array[1..64] of byte;
TAutor = array[0..5] of byte;


VAR reg : registers;
i,j : integer;
Data : TBuf;
car : char;
f : text;
biosticks : longint absolute 0:$46c;


procedure absdelay(delayus : longint);
var i,j : longint;
begin
j:=delayus;
for i:=1 to j do ;
end;
{delayconst - 1000 us
x - delaytmp us
x=delayconst*delaytmp/1000
}
procedure MyDelay(delayus : longint);
var i,j : longint;
x : real;
begin
{ x:=delayconst*delayus / 1000;
j:=round(x); }
if delayus>=0 then j:=delayus*delayconst else j:=-delayus;
for i:=1 to j do ;
end;

{ Mydelay2(delayconst) - zaderzhka na 1000 us}
procedure MyDelay2(delaytmp : longint);
var i,j : longint;
x : real;
begin
{ x:=delayconst*delaytmp / 1000;
j:=round(x); }
if delaytmp>=0 then j:=delaytmp*delayconst else j:=-delaytmp;
for i:=1 to delaytmp do ;
end;


{-----------------------------------------------------------------------------}
PROCEDURE Send0(b:byte);
BEGIN
port[ino_address]:=data_mask and b;
END;

PROCEDURE Send(b:byte);
BEGIN
MyDelay(period);
port[ino_address]:=data_mask and b;
END;

procedure dummy;
var i : integer;
begin
i:=0;
end;

PROCEDURE Sendtest(b:byte);
BEGIN
dummy;
port[ino_address]:=data_mask and b;
END;

procedure sendbyte(b:byte);
var x,i : byte;
BEGIN
for i:=8 downto 1 do begin
x:=(b shr i) and 1;
send(x);
end;
END;

{-----------------------------------------------------------------------------}

FUNCTION Get:byte;
var b : byte;

BEGIN
b:=(port[in_address]);
b:=(b shr 6) and 1;
get:=b;
END;

{ &#143;®᫫ª  ¯® «¨­¨¨ I/O }
procedure put(b:byte);
begin
MyDelay(period);
port[ino_address]:=b;
end;

procedure mkrst;
begin
send(c1r); send(c1);
end;

procedure mkclk;
begin
send(c1c); send(c1);
end;

procedure goto0;
begin
send(c1); send(c1r); send(c1rc); send(c1r); send(c1);
end;

procedure goton(value:integer);
var i : integer;
begin
goto0;
for i:=1 to value do begin send(c1c); send(c1); end;
end;

procedure clks(value:integer);
var i : integer;
begin
for i:=1 to value do begin send(c1c); send(c1); end;
end;


{ - convert a 4 bit long decimal number to hexadecimal. }

FUNCTION dec2hexa_one(value:byte):char;

BEGIN case value of
0..9 : dec2hexa_one:=chr(value+$30);
10..15 : dec2hexa_one:=chr(value+$37);
END;
END;

{-----------------------------------------------------------------------------}
{ FUNCTION d2h(decimal_byte):string2; }
{ }
{ - convert a decimal byte to its hexadecimal representation. }
{-----------------------------------------------------------------------------}

FUNCTION d2h(value:byte):string2;

VAR msbb,lsbb:byte;

BEGIN
msbb:=(value and $f0) shr 4;
lsbb:=(value and $0f);
d2h := dec2hexa_one(msbb) + dec2hexa_one(lsbb);
END;

FUNCTION w2h(value:integer):string4;
var s : string4;
i : integer;
begin
s:= d2h((value and $ff00) shr 8) + d2h(value and $ff);
w2h:=s;
end;


FUNCTION w2hsp(value:integer):string4;
var s : string4;
i : integer;
begin
s:= w2h(value);
for i:=1 to 3 do if s[i]='0' then s[i]:=' ' else break;
w2hsp:=s;
end;

{-----------------------------------------------------------------------------}

Function Binary( b : byte):string8;

var weigth : byte;
s : string8;

BEGIN weigth:=$80;
s:='';
while (weigth > 0) do
BEGIN if ((b and weigth) = weigth) then s:=s+'1'
else s:=s+'0';
weigth:=weigth div $02;
END;
Binary:=s;
END;

{
FUNCTION Units:byte;

VAR u, i : integer;
s : string8;

BEGIN u:=0;
i:=13;
while (Data[i] = $FF) do
BEGIN u:=u+8;
i:=i+1;
END;
s:=Binary(Data[i]);
while(s[1]='1') do
BEGIN inc(u);
s:=copy(s,2,length(s));
END;
units:=u;
END;


function Units_2:LongInt;

BEGIN Units_2:=4096*Data[9]+512*Data[10]+64*Data[11]+8*Data[12]+Data[13];
END;

}

PROCEDURE waiting;

BEGIN send(c1);
{ write('Delay (1/2 period): ',mhz,' us, 1us=(',delayconst,') '); }
write(' Press a key ...');
repeat until keypressed;
gotoxy(1, wherey);
clreol;
END;

{-----------------------------------------------------------------------------}

PROCEDURE Full_Displaying;
var madr : integer;
BEGIN
for i:=1 to 80 do write('-');
for i:=1 to (byte_number div 6 + 1) do begin
write((i-1)*6*8:3);
for j:=1 to 6 do
if j+6*(i-1) <= byte_number then write(binary(Data[j+6*(i-1)]):9);
gotoxy(59,wherey);
write((i-1)*6:3);
for j:=1 to 6 do
if j+6*(i-1) <= byte_number then write(' ',d2h(Data[j+6*(i-1)]));
writeln;
end;
END;

{-----------------------------------------------------------------------------}

PROCEDURE Short_Displaying;

VAR j : integer;

BEGIN for j:=1 to byte_number do
BEGIN write(d2h(Data[j]),' ');
END;
writeln;
END;

Procedure Hex_Displaying;
begin
for i:=1 to 80 do write('-');
for i:=1 to (byte_number div 16) do begin
write('[',(i-1)*16:3, (i-1)*16*8:4, w2hsp((i-1)*16*8),']');
for j:=1 to 8 do
if j+16*(i-1) <= byte_number then write(' ',d2h(Data[j+16*(i-1)]));
write(' [',(i-1)*16+8:3, (i-1)*16*8+64:4, w2hsp((i-1)*16*8+64),']');
for j:=9 to 16 do
if j+16*(i-1) <= byte_number then write(' ',d2h(Data[j+16*(i-1)]));
writeln;
end;
end;

{-----------------------------------------------------------------------------
&#130;롮ª®⮧­®¥ 碥­¨¥
-----------------------------------------------------------------------------}
procedure reading;
var i,j : integer;
value : byte;
x,y,z : longint;
begin
x:=period; y:=measure;
if x<=0 then x:=-x else x:=x*delayconst;
if y<=0 then y:=-y else y:=y*delayconst;
if (x>y) then x:=x-y else x:=0;
for i:=1 to byte_number do begin
value:=0;
for j:=1 to 8 do begin
for z:=1 to y do ;
value:=(value shl 1) + get;
for z:=1 to x do ;
send(c1c);
MyDelay(period);
send(c1);
end;
Data[i]:=Value;
end;
end;

procedure show_result;
begin
case displaying of
0 :full_displaying;
1 :short_displaying;
2 :hex_displaying;
END;
end;

procedure readnshow;
begin
reading;
show_result;
end;

PROCEDURE Reading2;

VAR i, j : integer;
Value : byte;

BEGIN
for i:=1 to byte_number do
BEGIN Value:=0;
for j:=1 to 8 do
BEGIN Value:=Value+Value + get;
send(c1c); send(c1);
END;
Data[i]:=Value;
END;
case displaying of
0 :full_displaying;
1 :short_displaying;
2 :hex_displaying;
END;
END;

{-----------------------------------------------------------------------------}

PROCEDURE writting;

VAR i,n:integer;
car:char;

BEGIN write('Which bit do you want to set to "0" (from 0): ');
readln(n);

goton(n);
send(c1r); send(c1);
send(c1c); mydelay(5000); send(c1);
END;

PROCEDURE writting1;

VAR i,j,n,m:integer;
d : longint;
car:char;

BEGIN write('Enter bit pos (from 0), # of bits and delay in us : ');
readln(n,m,d);

for j:=1 to m do begin
goton(n+j-1);
send(c1r); send(c1);
send(c1c); if d<>0 then mydelay(d); send(c1);
end;
END;

PROCEDURE wrcarry;

VAR i,n:integer;
car:char;
d : longint;

BEGIN write('Write carry. Enter bit pos (from 0) and delay in us : ');
readln(n, d);

goton(n);
send(c1r); send(c1);
send(c1c); mydelay(d); send(c1);
send(c1r); send(c1);
send(c1c); mydelay(d); send(c1);
END;

PROCEDURE triple;

VAR i,n:integer;
car:char;
d : longint;

BEGIN write('Triple Rst Clk. Enter bit pos (from 0) and delay in us : ');
readln(n, d);

goton(n);
send(c1r); send(c1);
send(c1c); mydelay(d); send(c1);
send(c1r); send(c1);
send(c1c); mydelay(d); send(c1);
send(c1r); send(c1);
send(c1c); mydelay(d); send(c1);
END;

{-----------------------------------------------------------------------------}

PROCEDURE dumping;

VAR filename : string;
f : text;
i : word;

BEGIN write('Enter the filename: ');
readln(filename);
assign(f, filename);
rewrite(f);
for i:=1 to byte_number do write(f,d2h(Data[i]),' ');
close(f);
END;

{ 1 sec = 18.2 ticks
ticks - delayconst
18.2 - x
}
procedure testspd;
var
i,j,k,ticks : longint;
x : real;
begin
delayconst:=1;
while delayconst < $40000000 do
begin
ticks:=biosticks; mydelay2(delayconst); ticks:=biosticks-ticks;
if (ticks > 10) then
begin
{ x:=(delayconst*18.2)/ticks*10(-3) - pri takoj const. zaderzhka 1 msec. }
x:=delayconst*18.2/ticks/1000000;
delayconst:=round(x);
break;
end;
delayconst:=delayconst shl 1;
end;
if delayconst < 2 then writeln('Slow cpu, delays are inaccurate');
end;


{-----------------------------------------------------------------------------}

PROCEDURE initialize;

VAR i : integer;

BEGIN
clrscr;
window(1,1,80,25);
writeln(' B-read begin');
writeln(' 1-',(byte_number*8):3,' bit');
writeln(' F-format',displaying:2);
window(17,1,80,25);
writeln('P-Period',period:7);
writeln(' Delay ',measure:7);
writeln('R-read&comp');
window(38,1,80,25);
writeln('H-help');
writeln('Q-quit');
Writeln('S-save');
window(49,1,80,25);
writeln('W-write bit');
writeln('N-write n bit');
writeln('C-write carry');
window(64,1,80,25);
writeln('K-from keyb');
writeln('O-power-off tst');
writeln('3-triple RstClk');
window(1,4,80,25);
write('===== 1us=(',delayconst:4,') ');
for i:=18 to 80 do write('=');
window(1,5,80,25);
port[port_address+2]:=port[port_address+2] and $df; { ¯¥ॢ®¤ ¢ ०¨¬ § ¯¨ᨠ}
port[port_address]:=0;
END;


PROCEDURE dohelp;

BEGIN
clrscr;
writeln('A - Autorisation from file');
writeln('U - aUtorization endless');
writeln('D - Dump to file');
END;

procedure resetadr;
begin
goto0;
readnshow;
end;

procedure loopread;
var i : integer;
begin
repeat readnshow until keypressed;
end;

procedure interact;
var kb_flags : byte absolute 0:$417;
kb_flags1 : byte absolute 0:$418;
b,bo : byte;
s : string[20];
t : integer;
mdelay : longint;
const ctrl = 4;
alt = 8;
caps = $40;
begin
gotoxy(1,18); clreol;
gotoxy(1,19); clreol;
writeln(' Clk Rst I/O Alt=Clk Ctrl=Rst CapsLock-repeat Clk(Alt-accelerat)');
clreol;
t:=0; bo:=$ff;
repeat
b:=c1; s:=' ';
if (kb_flags and alt)=0 then begin b:=c1c; s:=' 1 ' end;
if (kb_flags and ctrl)=0 then begin b:=b and cr; s:=s+' 1 ' end else s:=s+' ';
case b of
c1rc : t:=0;
c1 : if bo=c1c then t:=t+1;
end;
bo:=b;
send(b); b:=get;
if b>0 then s:=s+' 1 ' else s:=s+' 0 ';
gotoxy(1,20); write(s, t:6, w2hsp(t):6);
while (kb_flags1 and caps)>0 do begin
if (kb_flags and alt)=0 then mdelay:=50000 else mdelay:=7000;
send(c1c); mydelay(mdelay); send(c1); mydelay(mdelay);
b:=get;
gotoxy(1,20); write('x':3,b:8, t:7, w2hsp(t):6);
t:=t+1; if t>512 then t:=0;
end;

until keypressed;
end;

procedure pwrtest;
var pause : longint;
begin
gotoxy(1,wherey); clreol;
write('Enter power-off pause (us) '); readln(pause);
send0(c0); mydelay(500000);
send0(c1); mydelay(3000); readnshow;
send0(c0); mydelay(pause);
send0(c1); mydelay(3000); readnshow;

end;

procedure readcmp;
var i,j,n : integer;
buf : TBuf;
z : boolean;
BEGIN
write('Read and compare. Enter numb_of_try ');
readln(n);
goto0; reading;
move(Data, buf, SizeOf(buf));
z:=true; i:=1;
while (i<=n) and z do begin
goto0; reading;
for j:=1 to byte_number do z:= z and (data[j] = buf[j]);
i:=i+1;
end;
if z then writeln('All identical') else
begin writeln('Mismatch in',i:5,' test'); show_result end;
writeln;
end;

procedure getperiod;
begin
write('Enter period and delay in us ');
readln(period,measure);
initialize;
end;


procedure saveinit;
var f : text;
begin
assign(f, 'card.ini');
rewrite(f);
write(f,period, ' ', measure, ' ', byte_number,' ', displaying);
close(f);
writeln('Settinds saved');
end;

function autorform(var ch : TAutor; z : word) : string;
var i : integer;
s : string;
begin
s:='';
for i:=0 to 5 do s:=s+d2h(ch[i])+' ';
s:=s+' '+w2h(z);
autorform:=s;
end;

function autor1(var ch : TAutor) : word;
var
i,j : integer;
z : word;
t : byte;
begin
goto0; clks(110);
mkrst; send(c1c); send(c1);
clks(177);
for i:=0 to 5 do for j:=7 downto 0 do begin
t:=(ch[i] shr j) and 1;
if t=1 then send(c1c) else send(c1dc);
MyDelay(1); send(c1);
end;
MyDelay(1);
z:=0;
for i:=1 to 16 do begin
clks(160);
MyDelay(1);
z:=(z shl 1) + get;
end;
autor1:=z;
end;

procedure autor;
var fr,fw : text;
sr,sw,x : string[30];
i,j : integer;
z : word;
ch : TAutor;
b,t : byte;
begin
write('Enter file_challenge >');
readln(sr);
assign(fr,sr);
{$I-} Reset(fr); {$I+}
if IOResult <> 0 then begin write('Error reading '+sr); exit; end;
write('Enter file_output >'); readln(sw);
assign(fw,sw); rewrite(fw);
while not eof(fr) do begin
for i:=0 to 5 do read(fr,ch[i]); readln(fr);
z:=autor1(ch);
writeln(fw,autorform(ch,z));
clks(50); { Na wsjakij sluchaj }
end;
close(fr); close(fw);
end;


procedure autorless;
var fw : text;
sw,x : string[30];
i,j : integer;
z : word;
ch : TAutor;
b,t : byte;
c : char;
l,ticks : longint;
begin
write('Enter file_output >'); readln(sw);
assign(fw,sw); rewrite(fw);
Reading;
for i:=1 to sizeof(TBuf) do begin
write(fw,d2h(Data[i]):3);
if ((i and 7) = 0) then writeln(fw);
end;
writeln(fw);

for i:=0 to 5 do ch[i]:=0;
z:=autor1(ch);
writeln(fw,autorform(ch,z));

for i:=0 to 5 do ch[i]:=$ff;
z:=autor1(ch);
writeln(fw,autorform(ch,z)); writeln(fw);

for i:=47 downto 0 do begin
for j:=0 to 5 do ch[j]:=0;
j:=i shr 3;
ch[j]:=1 shl (7-(i and 7));
z:=autor1(ch);
writeln(fw,autorform(ch,z));
end;
writeln(fw);
write('Enter first challenge (6 bytes) > ');
readln(ch[0],ch[1],ch[2],ch[3],ch[4],ch[5]);
writeln('Performing Challenge scan. Press Q to quit'); writeln;
c:='a';
ticks:=biosticks;
while (ch[0] or ch[1] or ch[2] or ch[3] or ch[4] or ch[5]) > 0 do begin
z:=autor1(ch);
writeln(fw,autorform(ch,z));
if keypressed then begin
c:=upcase(readkey);
if c='Q' then break;
end;
ch[5]:=ch[5]+1; if ch[5]=0 then begin
ch[4]:=ch[4]+1; if ch[4]=0 then begin
ch[3]:=ch[3]+1; if ch[3]=0 then begin
ch[2]:=ch[2]+1; if ch[2]=0 then begin
ch[1]:=ch[1]+1; if ch[1]=0 then begin
ch[0]:=ch[0]+1;
end; end; end; end; end;
l:=biosticks-ticks;
if (l > 180) then begin
close(fw);
append(fw);
write(#13,autorform(ch,z));
ticks:=biosticks;
end;
end;
close(fw);
end;

{=============================================================================}

BEGIN testspd;
assign(f, 'card.ini');
{$I-} Reset(f); {$I+}
if IOResult = 0 then begin read(f,period, measure, byte_number, displaying); close(f) end;
initialize;
{ send($C0); send($0); }
repeat waiting;
car:=upcase(readkey);
case car of
'W':writting;
'N':writting1;
'C':wrcarry;
'B':resetadr;
'L':loopread;
'Q':;
'3':triple;
'1':begin if (byte_number=64) then byte_number:=16 else byte_number:=(byte_number shl 1);
initialize;
end;
'K':interact;
'O':pwrtest;
{ 'D':begin delaytyp:=(delaytyp+1) and 1; initialize; end; }
'F':begin if displaying<2 then displaying:=(displaying+1) else displaying:=0;
initialize;
end;
'D':dumping;
'P':getperiod;
'S':saveinit;
'R':readcmp;
'A':autor;
'U':autorless;
'H':dohelp;
else readnshow;
END;
until car='Q';
port[port_address+2]:=port[port_address+2] or $20; { ¯¥ॢ®¤ ¢ ०¨¬ 碥­¨
END.
[Pas 2 C] держи заготовку - править напильником вручную... 24.09.01 16:06  
Автор: XR <eXtremal Research> Статус: The Elderman
<"чистая" ссылка>
> есть прога небольшая, для меня весьма важная..
> к ней есть исходник на паскале..
> поначалу я думал, что сам разберусь, однако не вышло..
>
> собственно я был бы весьма признателен, если кто-нибудь
> переписал её в С..
>
>

/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */
/* From input file "test.pas" */


/* */
/* Written by Stephane BAUSSON (1993) */
/*

Parallel Port DB25-Female

pin assignment pin assignment

1 -Strobe 2 Data 0
3 Data 1 4 Data 2
5 Data 3 6 Data 4
7 Data 5 8 Data 6
9 Data 7 10 -Ack
11 Busy 12 Paper Empty
13 Select 14 -Auto Feed
15 -Error 16 -Init
17 -Slct in 18 GND
19 GND 20 GND
21 GND 22 GND
23 GND 24 GND
25 GND

6 (d.b.0) - Data 4
8 Rst Data 6
9 Clk Data 7
11 Busy I/O
19 GND GND

$40 - Rst
$80 - Clk
$C0 - Rst & Clock
[port+1] and $80 - I/O
==========================================
Leshka
25 Gnd
1 -Strobe I/O
2 Data0 Clk
3 Data1 Rst
4 Data2 Vcc

$37a:=$20 - ???®¤ ? 0?¬ ?­??

*/


#include <p2c/p2c.h>


#define port_address    0x378   /* lpr1 chosen */

#define out_address     (port_address + 2)
#define in_address      (port_address + 1)

#define ino_address     port_address

/*
c0 = $ff;
c1 = $fe; { VCC Strobe pin 1 */
#define cr              0xfd   /* Rst AutoLineFeed pin 14 */
#define cc              0xf7   /* Clk SLCT IN pin 17 */
/* p2c: test.pas, line 64: Warning: Symbol 'C1' is not defined [221] */

#define c1r             (c1 & cr)
/* p2c: test.pas, line 65: Warning: Symbol 'C1' is not defined [221] */
#define c1c             (c1 & cc)
/* p2c: test.pas, line 66: Warning: Symbol 'C1' is not defined [221] */
#define c1rc            (c1 & cr & cc)

#define crc             (cr & cc)
#define data_mask       0xb   /* ¤«?ND */
/* p2c: test.pas, line 69: Warning: Unmatched '*)' in input file [245] */

#define c0              0
#define c1              0x4
/* p2c: test.pas, line 73: Warning: Symbol 'CR' was already defined [220] */
#define cr_             0x2
/* p2c: test.pas, line 74: Warning: Symbol 'CC' was already defined [220] */
#define cc_             0x1
#define cd              0x8
/* p2c: test.pas, line 76: 
 * Warning: Symbol 'C1R' was already defined [220] */
#define c1r_            (c1 | cr_)
/* p2c: test.pas, line 77: 
 * Warning: Symbol 'C1C' was already defined [220] */
#define c1c_            (c1 | cc_)
/* p2c: test.pas, line 78: 
 * Warning: Symbol 'C1RC' was already defined [220] */
#define c1rc_           (c1 | cr_ | cc_)
#define c1d             (c1 | cd)
#define c1dc            (c1 | cd | cc_)
#define c1dr            (c1 | cd | cr_)
#define c1drc           (c1 | cd | cr_ | cc_)
/* p2c: test.pas, line 83: 
 * Warning: Symbol 'CRC' was already defined [220] */
#define crc_            (cr_ | cc_)
/* p2c: test.pas, line 84: 
 * Warning: Symbol 'DATA_MASK' was already defined [220] */
#define data_mask_      0xf   /* ¤«?ND. Ne objazat-no */


typedef Char string8[9];

typedef Char string2[3];

typedef Char string4[5];

typedef uchar TBuf[64];
typedef uchar TAutor[6];



Static long delayconst = 0;   /* k-vo ciklov w 1 us*/
Static long displaying = 0, byte_number = 16, delaytyp = 1, measure = 1;
    /* ++ ¤??  ¬?¦¤?lk1>0 ? ?§¬?7??¬ */
Static long period = 15;   /* "«?­  Clk */
Static Registers reg;
Static long i, j;
Static TBuf Data;
Static Char car;
Static FILE *f;
Static LONGINT biosticks = (long *)0x46c;


/* p2c: test.pas, line 99:
 * Note: Absolute-addressed variable biosticks was generated [116] */


Static Void absdelay(delayus)
LONGINT delayus;
{
  LONGINT i;
  LONGINT j = delayus;

  for (i = 1; i <= j; i++) ;
}


/*delayconst - 1000 us
x - delaytmp us
x=delayconst*delaytmp/1000
*/
Static Void MyDelay(delayus)
LONGINT delayus;
{
  LONGINT i, j;

  /* x:=delayconst*delayus / 1000;
j:=round(x); */
  if (delayus >= 0)
    j = delayus * delayconst;
  else
    j = -delayus;
  for (i = 1; i <= j; i++) ;
}


/* Mydelay2(delayconst) - zaderzhka na 1000 us*/
Static Void MyDelay2(delaytmp)
LONGINT delaytmp;
{
  LONGINT i, j;

  /* x:=delayconst*delaytmp / 1000;
j:=round(x); */
  if (delaytmp >= 0)
    j = delaytmp * delayconst;
  else
    j = -delaytmp;
  for (i = 1; i <= delaytmp; i++) ;
}


-----------------------------------------------------------------------------
Static Void Send0(b)
uchar b;
{
  PORT(ino_address) = data_mask_ & b;
/* p2c: test.pas, line 137: Note: Reference to PORT [191] */
/* p2c: test.pas, line 137: Warning: Invalid assignment [168] */
}


Static Void Send(b)
uchar b;
{
  MyDelay(period);
  PORT(ino_address) = data_mask_ & b;
/* p2c: test.pas, line 143: Note: Reference to PORT [191] */
/* p2c: test.pas, line 143: Warning: Invalid assignment [168] */
}


Static Void dummy()
{
  long i = 0;
}


Static Void Sendtest(b)
uchar b;
{
  dummy();
  PORT(ino_address) = data_mask_ & b;
/* p2c: test.pas, line 155: Note: Reference to PORT [191] */
/* p2c: test.pas, line 155: Warning: Invalid assignment [168] */
}


Static Void sendbyte(b)
uchar b;
{
  uchar x, i;

  for (i = 8; i >= 1; i--) {
    x = (b >> i) & 1;
    Send(x);
  }
}


-----------------------------------------------------------------------------

Static uchar Get()
{
  uchar b;

  b = PORT(in_address);
/* p2c: test.pas, line 173: Note: Reference to PORT [191] */
  b = (b >> 6) & 1;
  return b;
}


/* ?®?^(a)  ?® «?­?? I/O */
Static Void put(b)
uchar b;
{
  MyDelay(period);
  PORT(ino_address) = b;
/* p2c: test.pas, line 182: Note: Reference to PORT [191] */
/* p2c: test.pas, line 182: Warning: Invalid assignment [168] */
}


Static Void mkrst()
{
  Send(c1r_);
  Send(c1);
}


Static Void mkclk()
{
  Send(c1c_);
  Send(c1);
}


Static Void goto0()
{
  Send(c1);
  Send(c1r_);
  Send(c1rc_);
  Send(c1r_);
  Send(c1);
}


Static Void goton(value)
long value;
{
  long i;

  goto0();
  for (i = 1; i <= value; i++) {
    Send(c1c_);
    Send(c1);
  }
}


Static Void clks(value)
long value;
{
  long i;

  for (i = 1; i <= value; i++) {
    Send(c1c_);
    Send(c1);
  }
}


/* - convert a 4 bit long decimal number to hexadecimal. */

Static Char dec2hexa_one(value)
uchar value;
{
  Char Result;

  switch (value) {

  case 10:
  case 11:
  case 12:
  case 13:
  case 14:
  case 15:
    Result = value + 0x37;
    break;

  default:
    if (value <= 9)
      Result = value + 0x30;
    break;
  }
  return Result;
}


-----------------------------------------------------------------------------
/* FUNCTION d2h(decimal_byte):string2; */
/* */
/* - convert a decimal byte to its hexadecimal representation. */
-----------------------------------------------------------------------------

Static Char *d2h(Result, value)
Char *Result;
uchar value;
{
  uchar msbb, lsbb;

  msbb = (value & 0xf0) >> 4;
  lsbb = value & 0xf;
  sprintf(Result, "%c%c", dec2hexa_one(msbb), dec2hexa_one(lsbb));
  return Result;
}


Static Char *w2h(Result, value)
Char *Result;
long value;
{
  string4 s;
  string2 STR1, STR2;

  sprintf(s, "%s%s",
	  d2h(STR1, ((int)(value & 0xff00L)) >> 8),
	  d2h(STR2, (int)(value & 0xff)));
  return strcpy(Result, s);
}


Static Char *w2hsp(Result, value)
Char *Result;
long value;
{
  string4 s;
  long i;

  w2h(s, value);
  for (i = 0; i <= 2; i++) {
    if (s[i] == '0')
      s[i] = ' ';
    else {
      fflush(0);
      P_ioresult = 0;
    }
  }
/* p2c: test.pas, line 254:
 * Warning: Expected a '(', found a semicolon [227] */
/* p2c: test.pas, line 254:
 * Warning: Expected an expression, found a semicolon [227] */
  return strcpy(Result, s);
}


-----------------------------------------------------------------------------

Static Char *Binary(Result, b)
Char *Result;
uchar b;
{
  uchar weigth = 0x80;
  string8 s;

  *s = '\0';
  while (weigth > 0) {
    if ((b & weigth) == weigth)
      strcat(s, "1");
    else
      strcat(s, "0");
    weigth /= 0x2;
  }
  return strcpy(Result, s);
}


/*
FUNCTION Units:byte;

VAR u, i : integer;
s : string8;

BEGIN u:=0;
i:=13;
while (Data[i] = $FF) do
BEGIN u:=u+8;
i:=i+1;
END;
s:=Binary(Data[i]);
while(s[1]='1') do
BEGIN inc(u);
s:=copy(s,2,length(s));
END;
units:=u;
END;


function Units_2:LongInt;

BEGIN Units_2:=4096*Data[9]+512*Data[10]+64*Data[11]+8*Data[12]+Data[13];
END;

*/

Static Void waiting()
{
  Send(c1);
  /* write('Delay (1/2 period): ',mhz,' us, 1us=(',delayconst,') '); */
  printf(" Press a key ...");
  do {
  } while (!kbhit());
  gotoxy(1, (int)wherey);
  clreol();
}


-----------------------------------------------------------------------------

Static Void Full_Displaying()
{
  long FORLIM;
  string8 STR1;
  string2 STR3;

  for (i = 1; i <= 80; i++)
    putchar('-');
  FORLIM = byte_number / 6 + 1;
  for (i = 1; i <= FORLIM; i++) {
    printf("%3ld", (i - 1) * 48);
    for (j = 1; j <= 6; j++) {
      if (j + (i - 1) * 6 <= byte_number)
	printf("%9s", Binary(STR1, Data[j + (i - 1) * 6 - 1]));
    }
    gotoxy(59, (int)wherey);
    printf("%3ld", (i - 1) * 6);
    for (j = 1; j <= 6; j++) {
      if (j + (i - 1) * 6 <= byte_number)
	printf(" %s", d2h(STR3, Data[j + (i - 1) * 6 - 1]));
    }
    putchar('\n');
  }
}


-----------------------------------------------------------------------------

Static Void Short_Displaying()
{
  long j, FORLIM;
  string2 STR1;

  FORLIM = byte_number;
  for (j = 0; j < FORLIM; j++)
    printf("%s ", d2h(STR1, Data[j]));
  putchar('\n');
}


Static Void Hex_Displaying()
{
  long FORLIM;
  string4 STR2;
  string2 STR3;

  for (i = 1; i <= 80; i++)
    putchar('-');
  FORLIM = byte_number / 16;
  for (i = 1; i <= FORLIM; i++) {
    printf("[%3ld%4ld%s]",
	   (i - 1) * 16, (i - 1) * 128, w2hsp(STR2, (i - 1) * 128));
    for (j = 1; j <= 8; j++) {
      if (j + (i - 1) * 16 <= byte_number)
	printf(" %s", d2h(STR3, Data[j + (i - 1) * 16 - 1]));
    }
    printf(" [%3ld%4ld%s]",
	   (i - 1) * 16 + 8, (i - 1) * 128 + 64,
	   w2hsp(STR2, (i - 1) * 128 + 64));
    for (j = 9; j <= 16; j++) {
      if (j + (i - 1) * 16 <= byte_number)
	printf(" %s", d2h(STR3, Data[j + (i - 1) * 16 - 1]));
    }
    putchar('\n');
  }
}


/*-----------------------------------------------------------------------------
,?^(a)®?­®? ?­??
-----------------------------------------------------------------------------*/
Static Void reading()
{
  long i, j;
  uchar value;
  LONGINT x, y, z;
  long FORLIM;

  x = period;
  y = measure;
  if (x <= 0)
    x = -x;
  else
    x *= delayconst;
  if (y <= 0)
    y = -y;
  else
    y *= delayconst;
  if (x > y)
    x -= y;
  else
    x = 0;
  FORLIM = byte_number;
  for (i = 0; i < FORLIM; i++) {
    value = 0;
    for (j = 1; j <= 8; j++) {
      for (z = 1; z <= y; z++) ;
      value = (value << 1) + Get();
      for (z = 1; z <= x; z++) ;
      Send(c1c_);
      MyDelay(period);
      Send(c1);
    }
    Data[i] = value;
  }
}


Static Void show_result()
{
  switch (displaying) {

  case 0:
    Full_Displaying();
    break;

  case 1:
    Short_Displaying();
    break;

  case 2:
    Hex_Displaying();
    break;
  }
}


Static Void readnshow()
{
  reading();
  show_result();
}


Static Void Reading2()
{
  long i, j;
  uchar Value;
  long FORLIM;

  FORLIM = byte_number;
  for (i = 0; i < FORLIM; i++) {
    Value = 0;
    for (j = 1; j <= 8; j++) {
      Value += Value + Get();
      Send(c1c_);
      Send(c1);
    }
    Data[i] = Value;
  }
  switch (displaying) {

  case 0:
    Full_Displaying();
    break;

  case 1:
    Short_Displaying();
    break;

  case 2:
    Hex_Displaying();
    break;
  }
}


-----------------------------------------------------------------------------

Static Void writting()
{
  long n;

  printf("Which bit do you want to set to \"0\" (from 0): ");
  scanf("%ld%*[^\n]", &n);
  getchar();

  goton(n);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(5000L);
  Send(c1);
}


Static Void writting1()
{
  long j, n, m;
  LONGINT d;

  printf("Enter bit pos (from 0), # of bits and delay in us : ");
  scanf("%ld%ld%ld%*[^\n]", &n, &m, &d);
  getchar();

  for (j = 0; j < m; j++) {
    goton(n + j);
    Send(c1r_);
    Send(c1);
    Send(c1c_);
    if (d != 0)
      MyDelay(d);
    Send(c1);
  }
}


Static Void wrcarry()
{
  long n;
  LONGINT d;

  printf("Write carry. Enter bit pos (from 0) and delay in us : ");
  scanf("%ld%ld%*[^\n]", &n, &d);
  getchar();

  goton(n);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(d);
  Send(c1);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(d);
  Send(c1);
}


Static Void triple()
{
  long n;
  LONGINT d;

  printf("Triple Rst Clk. Enter bit pos (from 0) and delay in us : ");
  scanf("%ld%ld%*[^\n]", &n, &d);
  getchar();

  goton(n);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(d);
  Send(c1);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(d);
  Send(c1);
  Send(c1r_);
  Send(c1);
  Send(c1c_);
  MyDelay(d);
  Send(c1);
}


-----------------------------------------------------------------------------

Static Void dumping()
{
  Char filename[256];
  FILE *f = NULL;
  unsigned short i;
  string2 STR1;
  unsigned short FORLIM;

  printf("Enter the filename: ");
  gets(filename);
/* p2c: test.pas, line 494: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(f, filename);
/* p2c: test.pas, line 495: Note: REWRITE does not specify a name [181] */
  if (f != NULL)
    rewind(f);
  else
    f = tmpfile();
  if (f == NULL)
    _EscIO(FileNotFound);
  FORLIM = byte_number;
  for (i = 0; i <= FORLIM - 1; i++)
    fprintf(f, "%s ", d2h(STR1, Data[i]));
  fclose(f);
  f = NULL;
}


/* 1 sec = 18.2 ticks
ticks - delayconst
18.2 - x
*/
Static Void testspd()
{
  LONGINT ticks;
  double x;

  delayconst = 1;
  while (delayconst < 0x40000000L) {
    ticks = *biosticks;
    MyDelay2(delayconst);
    ticks = *biosticks - ticks;
    if (ticks > 10) {
      /* x:=(delayconst*18.2)/ticks*10(-3) - pri takoj const. zaderzhka 1 msec. */
      x = delayconst * 18.2 / ticks / 1000000L;
      delayconst = (long)floor(x + 0.5);
/* p2c: test.pas, line 518:
 * Warning: Expected a '(', found a semicolon [227] */
/* p2c: test.pas, line 518:
 * Warning: Expected an expression, found a semicolon [227] */
      fflush(0);
      P_ioresult = 0;
    }
    delayconst <<= 1;
  }
  if (delayconst < 2)
    printf("Slow cpu, delays are inaccurate\n");
}


-----------------------------------------------------------------------------

Static Void initialize()
{
  long i;

  clrscr();
  window(1L, 1L, 80L, 25L);
  printf(" B-read begin\n");
  printf(" 1-%3ld bit\n", byte_number * 8);
  printf(" F-format%2ld\n", displaying);
  window(17L, 1L, 80L, 25L);
  printf("P-Period%7ld\n", period);
  printf(" Delay %7ld\n", measure);
  printf("R-read&comp\n");
  window(38L, 1L, 80L, 25L);
  printf("H-help\n");
  printf("Q-quit\n");
  printf("S-save\n");
  window(49L, 1L, 80L, 25L);
  printf("W-write bit\n");
  printf("N-write n bit\n");
  printf("C-write carry\n");
  window(64L, 1L, 80L, 25L);
  printf("K-from keyb\n");
  printf("O-power-off tst\n");
  printf("3-triple RstClk\n");
  window(1L, 4L, 80L, 25L);
  printf("===== 1us=(%4ld) ", delayconst);
  for (i = 18; i <= 80; i++)
    putchar('=');
  window(1L, 5L, 80L, 25L);
  PORT(port_address + 2) &= 0xdf;   /* ???®¤ ? 0?¬ § ???*/
/* p2c: test.pas, line 558: Note: Reference to PORT [191] */
/* p2c: test.pas, line 558: Note: Reference to PORT [191] */
/* p2c: test.pas, line 558: Warning: Invalid assignment [168] */
  PORT(port_address) = 0;
/* p2c: test.pas, line 559: Note: Reference to PORT [191] */
/* p2c: test.pas, line 559: Warning: Invalid assignment [168] */
}


Static Void dohelp()
{
  clrscr();
  printf("A - Autorisation from file\n");
  printf("U - aUtorization endless\n");
  printf("D - Dump to file\n");
}


Static Void resetadr()
{
  goto0();
  readnshow();
}


Static Void loopread()
{
  do {
    readnshow();
  } while (!kbhit());
}


#define ctrl            4
#define alt             8
#define caps            0x40


Static Void interact()
{
  uchar *kb_flags = (uchar *)0x417;
/* p2c: test.pas, line 585:
 * Note: Absolute-addressed variable kb_flags was generated [116] */
  uchar *kb_flags1 = (uchar *)0x418;
/* p2c: test.pas, line 586:
 * Note: Absolute-addressed variable kb_flags1 was generated [116] */
  uchar b;
  uchar bo = 0xff;
  Char s[21];
  long t = 0;
  LONGINT mdelay;
  string4 STR1;

  gotoxy(1, 18);
  clreol();
  gotoxy(1, 19);
  clreol();
  printf(" Clk Rst I/O Alt=Clk Ctrl=Rst CapsLock-repeat Clk(Alt-accelerat)\n");
  clreol();
  do {
    b = c1;
    strcpy(s, " ");
    if (((*kb_flags) & alt) == 0) {
      b = c1c_;
      strcpy(s, " 1 ");
    }
    if (((*kb_flags) & ctrl) == 0) {
      b &= cr_;
      strcat(s, " 1 ");
    } else
      strcat(s, " ");
    switch (b) {

    case c1rc_:
      t = 0;
      break;

    case c1:
      if (bo == c1c_)
	t++;
      break;
    }
    bo = b;
    Send(b);
    b = Get();
    if (b > 0)
      strcat(s, " 1 ");
    else
      strcat(s, " 0 ");
    gotoxy(1, 20);
    printf("%s%6ld%6s", s, t, w2hsp(STR1, t));
    while (((*kb_flags1) & caps) > 0) {
      if (((*kb_flags) & alt) == 0)
	mdelay = 50000L;
      else
	mdelay = 7000;
      Send(c1c_);
      MyDelay(mdelay);
      Send(c1);
      MyDelay(mdelay);
      b = Get();
      gotoxy(1, 20);
      printf("%3c%8d%7ld%6s", 'x', b, t, w2hsp(STR1, t));
      t++;
      if (t > 512)
	t = 0;
    }

  } while (!kbhit());
}

#undef ctrl
#undef alt
#undef caps


Static Void pwrtest()
{
  LONGINT pause;

  gotoxy(1, (int)wherey);
  clreol();
  printf("Enter power-off pause (us) ");
  scanf("%ld%*[^\n]", &pause);
  getchar();
  Send0(c0);
  MyDelay(500000L);
  Send0(c1);
  MyDelay(3000L);
  readnshow();
  Send0(c0);
  MyDelay(pause);
  Send0(c1);
  MyDelay(3000L);
  readnshow();

}


Static Void readcmp()
{
  long i = 1;
  long j, n;
  TBuf buf;
  boolean z = true;
  long FORLIM;

  printf("Read and compare. Enter numb_of_try ");
  scanf("%ld%*[^\n]", &n);
  getchar();
  goto0();
  reading();
  memmove((Anyptr)buf, (Anyptr)Data, sizeof(TBuf));
  while (i <= n && z) {
    goto0();
    reading();
    FORLIM = byte_number;
    for (j = 0; j < FORLIM; j++)
      z = (z && Data[j] == buf[j]);
    i++;
  }
  if (z)
    printf("All identical\n");
  else {
    printf("Mismatch in%5ld test\n", i);
    show_result();
  }
  putchar('\n');
}


Static Void getperiod()
{
  printf("Enter period and delay in us ");
  scanf("%ld%ld%*[^\n]", &period, &measure);
  getchar();
  initialize();
}


Static Void saveinit()
{
  FILE *f = NULL;

/* p2c: test.pas, line 666: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(f, "card.ini");
/* p2c: test.pas, line 667: Note: REWRITE does not specify a name [181] */
  if (f != NULL)
    rewind(f);
  else
    f = tmpfile();
  if (f == NULL)
    _EscIO(FileNotFound);
  fprintf(f, "%12ld %12ld %12ld %12ld",
	  period, measure, byte_number, displaying);
  fclose(f);
  f = NULL;
  printf("Settinds saved\n");
}


Static Char *autorform(Result, ch, z)
Char *Result;
uchar *ch;
unsigned short z;
{
  long i;
  Char s[256];
  string2 STR1;
  string4 STR2;

  *s = '\0';
  for (i = 0; i <= 5; i++)
    sprintf(s + strlen(s), "%s ", d2h(STR1, ch[i]));
  sprintf(s + strlen(s), " %s", w2h(STR2, (long)z));
  return strcpy(Result, s);
}


Static unsigned short autor1(ch)
uchar *ch;
{
  long i, j;
  unsigned short z = 0;
  uchar t;

  goto0();
  clks(110L);
  mkrst();
  Send(c1c_);
  Send(c1);
  clks(177L);
  for (i = 0; i <= 5; i++) {
    for (j = 7; j >= 0; j--) {
      t = (ch[i] >> j) & 1;
      if (t == 1)
	Send(c1c_);
      else
	Send(c1dc);
      MyDelay(1L);
      Send(c1);
    }
  }
  MyDelay(1L);
  for (i = 1; i <= 16; i++) {
    clks(160L);
    MyDelay(1L);
    z = (z << 1) + Get();
  }
  return z;
}


Static Void autor()
{
  FILE *fr = NULL, *fw = NULL;
  Char sr[31], sw[31];
  long i;
  unsigned short z;
  TAutor ch;
  Char STR1[256];
  Char *TEMP;
  int TEMP1;

  printf("Enter file_challenge >");
  fgets(sr, 31, stdin);
  TEMP = strchr(sr, '\n');
  if (TEMP != NULL)
    *TEMP = 0;
/* p2c: test.pas, line 717: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(fr, sr);
  rewind(fr);
  if (P_ioresult != 0) {
    printf("Error reading %s", sr);
    return;
  }
  printf("Enter file_output >");
  fgets(sw, 31, stdin);
  TEMP = strchr(sw, '\n');
  if (TEMP != NULL)
    *TEMP = 0;
/* p2c: test.pas, line 721: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(fw, sw);
/* p2c: test.pas, line 721: Note: REWRITE does not specify a name [181] */
  if (fw != NULL)
    rewind(fw);
  else
    fw = tmpfile();
  if (fw == NULL)
    _EscIO(FileNotFound);
  while (!P_eof(fr)) {
    for (i = 0; i <= 5; i++) {
      fscanf(fr, "%d", &TEMP1);
      ch[i] = TEMP1;
    }
    fscanf(fr, "%*[^\n]");
    getc(fr);
    z = autor1(ch);
    fprintf(fw, "%s\n", autorform(STR1, ch, z));
    clks(50L);   /* Na wsjakij sluchaj */
  }
  if (fr != NULL)
    fclose(fr);
  fr = NULL;
  fclose(fw);
  fw = NULL;
}


Static Void autorless()
{
  FILE *fw = NULL;
  Char sw[31];
  long i, j;
  unsigned short z;
  TAutor ch;
  Char c = 'a';
  LONGINT l, ticks;
  string2 STR1;
  Char *TEMP;
  Char STR2[256], STR3[256];
  int TEMP1, TEMP2, TEMP3, TEMP4, TEMP5, TEMP6;

  printf("Enter file_output >");
  fgets(sw, 31, stdin);
  TEMP = strchr(sw, '\n');
  if (TEMP != NULL)
    *TEMP = 0;
/* p2c: test.pas, line 743: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(fw, sw);
/* p2c: test.pas, line 743: Note: REWRITE does not specify a name [181] */
  if (fw != NULL)
    rewind(fw);
  else
    fw = tmpfile();
  if (fw == NULL)
    _EscIO(FileNotFound);
  reading();
  for (i = 1; i <= sizeof(TBuf); i++) {
    fprintf(fw, "%3s", d2h(STR1, Data[i-1]));
    if ((i & 7) == 0)
      putc('\n', fw);
  }
  putc('\n', fw);

  for (i = 0; i <= 5; i++)
    ch[i] = 0;
  z = autor1(ch);
  fprintf(fw, "%s\n", autorform(STR2, ch, z));

  for (i = 0; i <= 5; i++)
    ch[i] = 0xff;
  z = autor1(ch);
  fprintf(fw, "%s\n\n", autorform(STR2, ch, z));

  for (i = 47; i >= 0; i--) {
    for (j = 0; j <= 5; j++)
      ch[j] = 0;
    j = ((unsigned long)i) >> 3;
    ch[j] = 1 << (7 - (i & 7));
    z = autor1(ch);
    fprintf(fw, "%s\n", autorform(STR2, ch, z));
  }
  putc('\n', fw);
  printf("Enter first challenge (6 bytes) > ");
  scanf("%d%d%d%d%d%d%*[^\n]", &TEMP1, &TEMP2, &TEMP3, &TEMP4, &TEMP5, &TEMP6);
  getchar();
  ch[0] = TEMP1;
  ch[1] = TEMP2;
  ch[2] = TEMP3;
  ch[3] = TEMP4;
  ch[4] = TEMP5;
  ch[5] = TEMP6;
  printf("Performing Challenge scan. Press Q to quit\n\n");
  ticks = *biosticks;
  while ((ch[0] | ch[1] | ch[2] | ch[3] | ch[4] | ch[5]) > 0) {
    z = autor1(ch);
    fprintf(fw, "%s\n", autorform(STR2, ch, z));
    if (kbhit()) {
      c = toupper(getch());
      if (c == 'Q') {
	fflush(0);
	P_ioresult = 0;
      }
/* p2c: test.pas, line 777:
 * Warning: Expected a '(', found a semicolon [227] */
/* p2c: test.pas, line 777:
 * Warning: Expected an expression, found a semicolon [227] */
    }
    ch[5]++;
    if (ch[5] == 0) {
      ch[4]++;
      if (ch[4] == 0) {
	ch[3]++;
	if (ch[3] == 0) {
	  ch[2]++;
	  if (ch[2] == 0) {
	    ch[1]++;
	    if (ch[1] == 0)
	      ch[0]++;
	  }
	}
      }
    }
    l = *biosticks - ticks;
    if (l <= 180)
      continue;
    fclose(fw);
/* p2c: test.pas, line 789: Note: APPEND does not specify a name [181] */
    fw = tmpfile();
    if (fw == NULL)
      _EscIO(FileNotFound);
    printf("\015%s", autorform(STR3, ch, z));
    ticks = *biosticks;
  }
  fclose(fw);
}


=============================================================================

main(argc, argv)
int argc;
Char *argv[];
{
  PASCAL_MAIN(argc, argv);
  f = NULL;
  testspd();
/* p2c: test.pas, line 800: Warning:
 * Don't know how to ASSIGN to a non-explicit file variable [207] */
  assign(f, "card.ini");
  rewind(f);
  if (P_ioresult == 0) {
    fscanf(f, "%ld%ld%ld%ld", &period, &measure, &byte_number, &displaying);
    if (f != NULL)
      fclose(f);
    f = NULL;
  }
  initialize();
  /* send($C0); send($0); */
  do {
    waiting();
    car = toupper(getch());
    switch (car) {

    case 'W':
      writting();
      break;

    case 'N':
      writting1();
      break;

    case 'C':
      wrcarry();
      break;

    case 'B':
      resetadr();
      break;

    case 'L':
      loopread();
      break;

    case 'Q':
      /* blank case */
      break;

    case '3':
      triple();
      break;

    case '1':
      if (byte_number == 64)
	byte_number = 16;
      else
	byte_number <<= 1;
      initialize();
      break;

    case 'K':
      interact();
      break;

    case 'O':
      pwrtest();
      break;

    /* 'D':begin delaytyp:=(delaytyp+1) and 1; initialize; end; */
    case 'F':
      if (displaying < 2)
	displaying++;
      else
	displaying = 0;
      initialize();
      break;

    case 'D':
      dumping();
      break;

    case 'P':
      getperiod();
      break;

    case 'S':
      saveinit();
      break;

    case 'R':
      readcmp();
      break;

    case 'A':
      autor();
      break;

    case 'U':
      autorless();
      break;

    case 'H':
      dohelp();
      break;

    default:
      readnshow();
      break;
    }
  } while (car != 'Q');
  PORT(port_address + 2) |= 0x20;   /* ???®¤ ? 0?¬ ?­??*/
/* p2c: test.pas, line 834: Note: Reference to PORT [191] */
/* p2c: test.pas, line 834: Note: Reference to PORT [191] */
/* p2c: test.pas, line 834: Warning: Invalid assignment [168] */
  if (f != NULL)
    fclose(f);
  exit(EXIT_SUCCESS);
}



/* End. */



---
1





Рейтинг@Mail.ru


  Copyright © 2001-2026 Dmitry Leonov   Page build time: 0 s   Design: Vadim Derkach