📄 zmisc.c
字号:
cancount = 5;
Again:
if (((KEYPRESS()) and (READKB()==27)))
begin
send_can();
z_log( KBD_msg );
return ZCAN;
end
Rxframeind = Rxtype = 0;
switch (c = _Z_TimedRead())
begin
case ZPAD: /*-----------------------------------------------*/
/* This is what we want. */
/*-----------------------------------------------*/
break;
case RCDO:
case TIMEOUT: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
goto Done;
case CAN: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
if (--cancount <= 0)
begin
c = ZCAN;
goto Done;
end
/* fallthrough... */
default: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
Agn2:
if (--n <= 0)
begin
z_log( FUBAR_msg );
send_can();
return ZCAN;
end
if (c != CAN) cancount = 5;
goto Again;
end /* switch */
cancount = 5;
Splat:
switch (c = _Z_TimedRead())
begin
case ZDLE: /*-----------------------------------------------*/
/* This is what we want. */
/*-----------------------------------------------*/
break;
case ZPAD: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
goto Splat;
case RCDO:
case TIMEOUT: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
goto Done;
default: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
goto Agn2;
end /* switch */
switch (c = _Z_TimedRead())
begin
case ZBIN: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
Rxframeind = ZBIN;
c = _Z_GetBinaryHeader(hdr);
break;
case ZHEX: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
Rxframeind = ZHEX;
c = _Z_GetHexHeader(hdr);
break;
case CAN: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
if (--cancount <= 0)
begin
c = ZCAN;
goto Done;
end
goto Agn2;
case RCDO:
case TIMEOUT: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
goto Done;
default: /*-----------------------------------------------*/
/* */
/*-----------------------------------------------*/
goto Agn2;
end /* switch */
Rxpos = _Z_PullLongFromHeader(hdr);
Done:
return c;
end /* Z_GetHeader */
/*--------------------------------------------------------------------------*/
/* Z GET BINARY HEADER */
/* Receive a binary style header (type and position) */
/*--------------------------------------------------------------------------*/
static int pascal _Z_GetBinaryHeader(hdr)
byte *hdr;
begin
register int c;
register word crc;
int n;
if ((c = Z_GetZDL()) & ~0xFF) return c;
Rxtype = c;
crc = Z_UpdateCRC(c, 0);
for (n=4; --n >= 0;)
begin
if ((c = Z_GetZDL()) & ~0xFF) return c;
crc = Z_UpdateCRC(c, crc);
*hdr++ = c;
end
if ((c = Z_GetZDL()) & ~0xFF) return c;
crc = Z_UpdateCRC(c, crc);
if ((c = Z_GetZDL()) & ~0xFF) return c;
crc = Z_UpdateCRC(c, crc);
if (crc & 0xFFFF)
begin
z_message( CRC_msg );
return ERROR;
end
return Rxtype;
end /* _Z_GetBinaryHeader */
/*--------------------------------------------------------------------------*/
/* Z GET HEX HEADER */
/* Receive a hex style header (type and position) */
/*--------------------------------------------------------------------------*/
static int pascal _Z_GetHexHeader(hdr)
unsigned char *hdr;
begin
register int c;
register word crc;
int n;
if ((c = _Z_GetHex()) < 0) return c;
Rxtype = c;
crc = Z_UpdateCRC(c, 0);
for (n=4; --n >= 0;)
begin
if ((c = _Z_GetHex()) < 0) return c;
crc = Z_UpdateCRC(c, crc);
*hdr++ = c;
end
if ((c = _Z_GetHex()) < 0) return c;
crc = Z_UpdateCRC(c, crc);
if ((c = _Z_GetHex()) < 0) return c;
crc = Z_UpdateCRC(c, crc);
if (crc & 0xFFFF)
begin
z_message( CRC_msg );
return ERROR;
end
if (Z_GetByte(1) == '\r') Z_GetByte(1); /* Throw away possible cr/lf */
return Rxtype;
end
/*--------------------------------------------------------------------------*/
/* Z GET HEX */
/* Decode two lower case hex digits into an 8 bit byte value */
/*--------------------------------------------------------------------------*/
static int pascal _Z_GetHex()
begin
register int c, n;
if ((n = _Z_TimedRead()) < 0) return n;
n -= '0';
if (n > 9) n -= ('a' - ':');
if (n & ~0xF) return ERROR;
if ((c = _Z_TimedRead()) < 0) return c;
c -= '0';
if (c > 9) c -= ('a' - ':');
if (c & ~0xF) return ERROR;
return (n<<4 | c);
end
/*--------------------------------------------------------------------------*/
/* Z GET ZDL */
/* Read a byte, checking for ZMODEM escape encoding */
/* including CAN*5 which represents a quick abort */
/*--------------------------------------------------------------------------*/
int pascal Z_GetZDL()
begin
register int c;
if ((c = _Z_qk_read()) != ZDLE) return c;
switch (c=_Z_qk_read())
begin
case CAN: return ((c=_Z_qk_read())<0)? c :
((c==CAN) && ((c=_Z_qk_read())<0))? c :
((c==CAN) && ((c=_Z_qk_read())<0))? c : (GOTCAN);
case ZCRCE:
case ZCRCG:
case ZCRCQ:
case ZCRCW: return (c | GOTOR);
case ZRUB0: return 0x7F;
case ZRUB1: return 0xFF;
default: return (c<0)? c :
((c&0x60)==0x40)? (c ^ 0x40) : ERROR;
end /* switch */
end /* Z_GetZDL */
/*--------------------------------------------------------------------------*/
/* Z TIMED READ */
/* Read a character from the modem line with timeout. */
/* Eat parity, XON and XOFF characters. */
/*--------------------------------------------------------------------------*/
static int pascal _Z_TimedRead()
begin
register int c;
for (;;)
begin
if ((c = _Z_qk_read()) < 0) return c;
switch (c &= 0x7F)
begin
case XON:
case XOFF: continue;
default: return c;
end /* switch */
end /* for */
end /* _Z_TimedRead */
/*--------------------------------------------------------------------------*/
/* Z LONG TO HEADER */
/* Store long integer pos in Txhdr */
/*--------------------------------------------------------------------------*/
void pascal Z_PutLongIntoHeader(pos)
long pos;
begin
Txhdr[ZP0] = pos;
Txhdr[ZP1] = pos>>8;
Txhdr[ZP2] = pos>>16;
Txhdr[ZP3] = pos>>24;
end /* Z_PutLongIntoHeader */
/*--------------------------------------------------------------------------*/
/* Z PULL LONG FROM HEADER */
/* Recover a long integer from a header */
/*--------------------------------------------------------------------------*/
static long pascal _Z_PullLongFromHeader(hdr)
unsigned char *hdr;
begin
long l;
l = hdr[ZP3];
l = (l << 8) | hdr[ZP2];
l = (l << 8) | hdr[ZP1];
l = (l << 8) | hdr[ZP0];
return l;
end /* _Z_PullLongFromHeader */
/* END OF FILE: n_zmodem.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -