$ make
zcc +cpm -clib=8080 -create-app -oxr --list --c-code-in-asm xr.c
Error at file 'fputc_cons.asm' line 32: symbol '__bdos' not defined
Error at file 'fputc_cons.asm' line 43: symbol '__bdos' not defined
Error at file 'fputc_cons.asm' line 48: symbol '__bdos' not defined
etc.
Code: Select all
Makefile
xr: xr.c
zcc +cpm -clib=8080 -create-app -oxr --list --c-code-in-asm xr.c
# zcc +cpm -create-app -otoupper main.c --list --c-code-in-asm
clean:
rm *.o *.err *.lis *.def *.sym *.exe *.COM xr
install:
sudo cp ./*.COM /var/www/html/.
Code: Select all
#include <stdlib.h>
#include <fcntl.h>
/*
Read data from host via XMODEM protocol.
This will only read data. */
#define SOH 0x01
#define EOT 0x04
#define ACK 0x06
#define NAK 0x15
#define ETB 0x17
#define CAN 0x18
#define Sync 0x43
#define ThreeSeconds 4000
#define PayLoadSz 131-4
typedef struct packed
{
unsigned char Header;
unsigned char PackNr;
unsigned char NotPackNr;
unsigned char Data[PayLoadSz];
unsigned char CRC[2];
} PACKET;
PACKET record;
int i;
int fd;
char filename[14];
/* poll console port for incoming data */
int Poll()
{
#asm
ld c,0bh
call 5
ld l,a
ld h,0
#endasm
}
/* read a byte from console port */
int Read()
{
while(!Poll());
#asm
ld c,06h
ld e,0ffh
call 5
ld l,a
ld h,0
#endasm
}
unsigned char _c;
int Write(unsigned char c)
{
_c = c;
#asm
ld c,06h
ld a,(__c)
ld e,a
call 5
#endasm
}
/* close the output file */
int CloseFile()
{
close(fd);
}
/* write to the output file */
/* may need to implement a blocking algorithm here */
int FileWrite(char *data)
{
write(fd,data,PayLoadSz);
}
/* open the output file */
/* may want to check for file name conflict here */
int FileOpen(char *filename)
{
fd = open(filename,O_WRONLY,O_CREAT);
}
int
ReadPacket (PACKET * buff)
{
/* see if the first char is an SOH or
at EOT or ETB */
/* poll for data */
while (!Poll ());
buff->Header = Read ();
if ((buff->Header) == EOT)
{
CloseFile ();
exit (0);
}
else if ((buff->Header) == ETB)
{
CloseFile ();
exit (0);
}
/* read packet number */
buff->PackNr = Read ();
buff->NotPackNr = Read ();
/* may need those later */
for (i = 0; i < PayLoadSz; i++)
{
buff->Data[i] = Read ();
}
/* get the CRC bytes */
buff->CRC[0] = Read ();
buff->CRC[1] = Read ();
}
int
CheckSOH ()
{
if (record.Header == SOH)
return 1;
return 0;
}
int timer;
void
AdvanceTime ()
{
timer += 1;
}
void
AckOut ()
{
Write(ACK);
}
void
NackOut ()
{
Write(NAK);
}
void
SyncOut ()
{
Write(Sync);
}
int
calcrc (unsigned char *ptr, int count)
{
int crc;
char i;
crc = 0;
while (--count >= 0)
{
crc = crc ^ (int) *ptr++ << 8;
i = 8;
do
{
if (crc & 0x8000)
crc = crc << 1 ^ 0x1021;
else
crc = crc << 1;
}
while (--i);
}
return (crc);
}
int
CheckCRC ()
{
if (record.CRC == calcrc (record.Data, PayLoadSz))
return 1;
else
return 0;
}
void
main (int argc, char *argv[])
{
/* send a Sync, and wait for 3 seconds to see if the host
starts sending data, else after 3 seconds, send another one */
while (1)
{
SyncOut ();
timer = 0;
while (timer <= ThreeSeconds)
{
if (CheckSOH (record))
{
goto here;
}
AdvanceTime ();
}
}
here:
if (CheckCRC (ReadPacket (record)) == 1)
{
AckOut ();
/* record is good, so write it out */
FileWrite (record.Data);
}
else
NackOut ();
goto here;
}