emailler/test/tcp.c

135 lines
1.9 KiB
C
Raw Normal View History

2017-11-06 22:36:44 +00:00
#include <cc65.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../inc/ip65.h"
#define LEN 500
#define SRV "192.168.0.10"
unsigned char buf[1500];
int len;
void error_exit(void)
{
printf("Error $%X\n", ip65_error);
if (doesclrscrafterexit())
{
printf("Press any key\n");
cgetc();
}
exit(1);
}
void tcp_recv(const unsigned char* tcp_buf, int tcp_len)
2017-11-06 22:36:44 +00:00
{
if (len)
{
return;
}
len = tcp_len;
2017-11-06 22:36:44 +00:00
if (len != -1)
{
memcpy(buf, tcp_buf, len);
2017-11-06 22:36:44 +00:00
}
}
void main(void)
{
unsigned i;
unsigned long srv;
char key;
if(!(srv = parse_dotted_quad(SRV)))
{
error_exit();
}
printf("Init\n");
Removed Ethernet driver I/O base. So far the base address of the Ethernet chip was a general property of all Ethernet drivers. It served two purposes: 1. Allowing to use a single Ethernet driver for a certain Ethernet chip, no matter what machine was connected to the chip. 2. Allowing use an Ethernet card in all Apple II slots. However, we now use customized Ethernet drivers for the individual machines so 1.) isn't relevant anymore. In fact one wants to omit the overhead of a runtime-adjustable base address where it isn't needed. So only the Apple II slots are left. But this should rather be a driver-internal approach then. We should just hand the driver the slot number the user wants to use and have the driver do its thing. Independently from the aspect if the driver parameter is a base address or a slot number the parameter handling was changed too. For asm programs there was so far a specific init function to be called prior to the main init function if it was desired to chnage the parameter default. This was done to keep the main init function backward compatible. But now that the parameter (now the slot number) is only used on the Apple II anyhow it seems reasonable to drop the specific init function again and just provide the parameter to the main init function. All C64-only user code can stay as-is. Only Apple II user code needs to by adjusted. Please note that this change only affects asm programs, C programs always used a single init function with the Apple II slot number as parameter.
2019-05-02 12:44:24 +00:00
if (ip65_init(ETH_INIT_DEFAULT))
2017-11-06 22:36:44 +00:00
{
error_exit();
}
printf("DHCP\n");
if (dhcp_init())
{
error_exit();
}
printf("IP Addr: %s\n", dotted_quad(cfg_ip));
printf("Netmask: %s\n", dotted_quad(cfg_netmask));
printf("Gateway: %s\n", dotted_quad(cfg_gateway));
printf("DNS Srv: %s\n", dotted_quad(cfg_dns));
printf("Connect to %s\n", SRV);
if (tcp_connect(srv, 6502, tcp_recv))
{
error_exit();
}
printf("(T)CP or e(X)it\n");
do
{
if (kbhit())
{
key = cgetc();
}
else
{
key = '\0';
}
if (key == 't')
{
printf("Send Len %d", LEN);
for (i = 0; i < LEN; ++i)
{
buf[i] = i;
}
if (tcp_send(buf, LEN))
{
printf("!\n");
}
else
{
printf(".\n");
}
}
ip65_process();
2017-11-06 22:36:44 +00:00
if (len == -1)
{
printf("Disconnect\n");
}
else if (len)
{
printf("Recv Len %d", len);
for (i = 0; i < len; ++i)
{
if ((i % 11) == 0)
{
ip65_process();
2017-11-06 22:36:44 +00:00
printf("\n$%04X:", i);
}
printf(" %02X", buf[i]);
}
len = 0;
printf(".\n");
}
}
while (key != 'x' && len != -1);
printf("Close\n");
if (tcp_close())
{
error_exit();
}
printf("Done\n");
}