Skip to content

Commit

Permalink
Rebased on latest IP65. Needs latest CC65 to build.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbimanners committed Sep 14, 2022
1 parent d8d532f commit 9561545
Show file tree
Hide file tree
Showing 29 changed files with 274 additions and 258 deletions.
4 changes: 2 additions & 2 deletions apps/email.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct datetime {

static char filename[80];
static char userentry[80];
static char linebuf[LINEBUFSZ];
static uint8_t linebuf[LINEBUFSZ];
static FILE *fp;
static struct emailhdrs *headers;
static uint16_t selection = 1;
Expand Down Expand Up @@ -1796,7 +1796,7 @@ char prompt_okay(char *msg) {
*/
void get_email_body(struct emailhdrs *h, FILE *f, char mode) {
uint16_t chars;
char c, *readp, *writep;
uint8_t c, *readp, *writep;
uint32_t pos = 0;
const int8_t *b = b64dec - 43;
uint8_t mime = 0, mime_enc = ENC_7BIT, mime_binary, mime_hasfile;
Expand Down
6 changes: 3 additions & 3 deletions apps/hfs65.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void send(unsigned char flags, const char* str, ...)
}

va_start(args, str);
send_size += vsnprintf(send_buffer + send_size, sizeof(send_buffer) - send_size, str, args);
send_size += vsnprintf((char*)send_buffer + send_size, sizeof(send_buffer) - send_size, str, args);
va_end(args);

if (flags & SEND_LAST || sizeof(send_buffer) - send_size < 1024 / 4)
Expand Down Expand Up @@ -309,9 +309,9 @@ int main(void)
{
read(file, &eth_init, 1);
close(file);
eth_init &= ~'0';
eth_init &= 7;
}
printf("- %d", eth_init);
printf("- %u", eth_init);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion apps/ifttt.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int ifttt_trigger(const char* key, const char* event,
return -1;
}

len = url_download(url, download, sizeof(download));
len = url_download(url, (uint8_t*)download, sizeof(download));

if (len < 12)
{
Expand Down
32 changes: 19 additions & 13 deletions apps/linenoise.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ struct linenoiseState {
int history_index; /* The history index we are currently editing. */
};

enum KEY_ACTION{
CTRL_A = 1, /* Ctrl+a */
CTRL_B = 2, /* Ctrl-b */
CTRL_C = 3, /* Ctrl-c */
CTRL_D = 4, /* Ctrl-d */
CTRL_E = 5, /* Ctrl-e */
CTRL_F = 6, /* Ctrl-f */
CTRL_N = 14, /* Ctrl-n */
CTRL_P = 16 /* Ctrl-p */
enum KEY_ACTION {
CTRL_A = 1, /* Ctrl+a */
CTRL_B = 2, /* Ctrl-b */
CTRL_C = 3, /* Ctrl-c */
CTRL_D = 4, /* Ctrl-d */
CTRL_E = 5, /* Ctrl-e */
CTRL_F = 6, /* Ctrl-f */
CTRL_N = 14, /* Ctrl-n */
CTRL_P = 16 /* Ctrl-p */
};

static void refreshLine(struct linenoiseState *l);
Expand All @@ -102,14 +102,16 @@ static int getColumns() {
return cols;
}

#ifdef __APPLE2__
#pragma code-name (push, "LC")
#endif

/* Beep, used for completion when there is nothing to complete or when all
* the choices were already shown. */
static void linenoiseBeep(void) {
#ifdef __APPLE2__
unsigned char x = wherex();
#endif
putchar('\a');
#ifdef __APPLE2__
gotox(x);
#endif
}

/* ============================== Completion ================================ */
Expand All @@ -123,6 +125,10 @@ static void freeCompletions(linenoiseCompletions *lc) {
free(lc->cvec);
}

#ifdef __APPLE2__
#pragma code-name (push, "LC")
#endif

/* This is an helper function for linenoiseEdit() and is called when the
* user types the <tab> key in order to complete the string currently in the
* input.
Expand Down
5 changes: 3 additions & 2 deletions apps/nntp65.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,12 @@ void main(int argc, char *argv[]) {
}

// Copy IP config from IP65 to W5100
w5100_config(eth_init);
w5100_init(eth_init);
w5100_config();

printf("Ok\nConnecting to %s (%u) - ", cfg_server, nntp_port);

if (!w5100_connect(parse_dotted_quad(cfg_server), nntp_port)) {
if (!w5100_connect_addr(parse_dotted_quad(cfg_server), nntp_port)) {
printf("Fail\n");
error_exit();
}
Expand Down
5 changes: 3 additions & 2 deletions apps/nntp65.up.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ void main(int argc, char *argv[]) {
printf("Ok\n");

// Copy IP config from IP65 to W5100
w5100_config(eth_init);
w5100_init(eth_init);
w5100_config();

sprintf(filename, "%s/NEWS.OUTBOX", cfg_emaildir);
dp = opendir(filename);
Expand Down Expand Up @@ -632,7 +633,7 @@ void main(int argc, char *argv[]) {
if (!connected) {
printf("\nConnecting to %s (%u) - ", cfg_server, nntp_port);

if (!w5100_connect(parse_dotted_quad(cfg_server), nntp_port)) {
if (!w5100_connect_addr(parse_dotted_quad(cfg_server), nntp_port)) {
printf("Fail\n");
error_exit();
}
Expand Down
6 changes: 4 additions & 2 deletions apps/pop65.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,17 +534,19 @@ void main(int argc, char *argv[]) {
// Abort on Ctrl-C to be consistent with Linenoise
abort_key = 0x83;

w5100_init(eth_init);

printf("Ok\nObtaining IP address - ");
if (dhcp_init()) {
ip65_error_exit();
}

// Copy IP config from IP65 to W5100
w5100_config(eth_init);
w5100_config();

printf("Ok\nConnecting to %s - ", cfg_server);

if (!w5100_connect(parse_dotted_quad(cfg_server), pop_port)) {
if (!w5100_connect_addr(parse_dotted_quad(cfg_server), pop_port)) {
printf("Fail\n");
error_exit();
}
Expand Down
5 changes: 3 additions & 2 deletions apps/print65.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ void main(int argc, char *argv[]) {
printf("Ok\n");

// Copy IP config from IP65 to W5100
w5100_config(eth_init);
w5100_init(eth_init);
w5100_config();

fp = fopen(filename, "rb");
if (!fp) {
Expand All @@ -291,7 +292,7 @@ void main(int argc, char *argv[]) {
if (!connected) {
printf("\nConnecting to %s:%d - ", cfg_server, jetdirect_port);

if (!w5100_connect(parse_dotted_quad(cfg_server), jetdirect_port)) {
if (!w5100_connect_addr(parse_dotted_quad(cfg_server), jetdirect_port)) {
printf("Fail\n");
error_exit();
}
Expand Down
5 changes: 3 additions & 2 deletions apps/smtp65.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ void main(int argc, char *argv[]) {
printf("Ok\n");

// Copy IP config from IP65 to W5100
w5100_config(eth_init);
w5100_init(eth_init);
w5100_config();

sprintf(filename, "%s/OUTBOX", cfg_emaildir);
dp = opendir(filename);
Expand Down Expand Up @@ -644,7 +645,7 @@ void main(int argc, char *argv[]) {
if (!connected) {
printf("\nConnecting to %s - ", cfg_smtp_server);

if (!w5100_connect(parse_dotted_quad(cfg_smtp_server), smtp_port)) {
if (!w5100_connect_addr(parse_dotted_quad(cfg_smtp_server), smtp_port)) {
printf("Fail\n");
error_exit();
}
Expand Down
4 changes: 2 additions & 2 deletions apps/tweet65.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ int main(void)
{
read(file, &eth_init, 1);
close(file);
eth_init &= ~'0';
eth_init &= 7;
}
printf("- %d\n", eth_init);
printf("- %u\n", eth_init);
}
#endif

Expand Down
96 changes: 52 additions & 44 deletions apps/w5100.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ static uint16_t addr_mask [2];

static void set_addr(uint16_t addr)
{
// The variables are necessary to have cc65 generate code
// suitable to access the W5100 auto-increment registers.
uint8_t addr_hi = addr >> 8;
uint8_t addr_lo = addr;
*w5100_addr_hi = addr_hi;
*w5100_addr_lo = addr_lo;
*w5100_addr_hi = addr >> 8;
*w5100_addr_lo = addr;
}

static uint8_t get_byte(uint16_t addr)
Expand All @@ -91,54 +87,44 @@ static uint16_t get_word(uint16_t addr)
{
set_addr(addr);

{
// The variables are necessary to have cc65 generate code
// suitable to access the W5100 auto-increment registers.
uint8_t data_hi = *w5100_data;
uint8_t data_lo = *w5100_data;
return data_hi << 8 | data_lo;
}
return *w5100_data << 8 | *w5100_data;
}

static void set_word(uint16_t addr, uint16_t data)
{
set_addr(addr);

{
// The variables are necessary to have cc65 generate code
// suitable to access the W5100 auto-increment registers.
uint8_t data_hi = data >> 8;
uint8_t data_lo = data;
*w5100_data = data_hi;
*w5100_data = data_lo;
}
*w5100_data = data >> 8;
*w5100_data = data;
}

static void set_quad(uint16_t addr, uint32_t data)
{
set_addr(addr);

{
// The variables are necessary to have cc65 generate code
// suitable to access the W5100 auto-increment registers.
uint8_t data_1 = data;
uint8_t data_2 = data >> 8;
uint8_t data_3 = data >> 16;
uint8_t data_4 = data >> 24;
*w5100_data = data_1;
*w5100_data = data_2;
*w5100_data = data_3;
*w5100_data = data_4;
}
*w5100_data = data;
*w5100_data = data >> 8;
*w5100_data = data >> 16;
*w5100_data = data >> 24;
}

void w5100_config(uint8_t eth_init)
bool w5100_init(uint8_t eth_init)
{
w5100_mode = (uint8_t*)(eth_init << 4 | 0xC084);
w5100_addr_hi = w5100_mode + 1;
w5100_addr_lo = w5100_mode + 2;
w5100_data = w5100_mode + 3;

// PPP Link Control Protocol Request Timer Register defaults to 0x28
// on a real W5100. However, AppleWin features a virtual W5100 that
// supports DNS offloading. On that virtual W5100, the (otherwise
// anyhow unused) register defaults to 0x00 as detection mechanism.
// https://github.com/a2retrosystems/uthernet2/wiki/Virtual-W5100-with-DNS
return get_byte(0x0028) == 0x00;
}

void w5100_config(void)
{
#ifdef SINGLE_SOCKET

// IP65 is inhibited so disable the W5100 Ping Block Mode.
Expand Down Expand Up @@ -193,14 +179,14 @@ void w5100_config(uint8_t eth_init)
}
}

bool w5100_connect(uint32_t addr, uint16_t port)
static bool w5100_connect(uint16_t port)
{
// Socket x Mode Register: TCP
set_byte(SOCK_REG(0x00), 0x01);

// Socket x Source Port Register
set_word(SOCK_REG(0x04), ip65_random_word());

// Socket x Destination Port Register
set_word(SOCK_REG(0x10), port);

// Socket x Command Register: OPEN
set_byte(SOCK_REG(0x01), 0x01);

Expand All @@ -213,12 +199,6 @@ bool w5100_connect(uint32_t addr, uint16_t port)
}
}

// Socket x Destination IP Address Register
set_quad(SOCK_REG(0x0C), addr);

// Socket x Destination Port Register
set_word(SOCK_REG(0x10), port);

// Socket x Command Register: CONNECT
set_byte(SOCK_REG(0x01), 0x04);

Expand All @@ -238,6 +218,34 @@ bool w5100_connect(uint32_t addr, uint16_t port)
}
}

bool w5100_connect_addr(uint32_t addr, uint16_t port)
{
// Socket x Mode Register: TCP, Use No Delayed ACK
set_byte(SOCK_REG(0x00), 0x21);

// Socket x Destination IP Address Register
set_quad(SOCK_REG(0x0C), addr);

return w5100_connect(port);
}

bool w5100_connect_name(const char* name, uint8_t length, uint16_t port)
{
// Socket x Mode Register: TCP, Use No Delayed ACK, Use DNS Offloading
set_byte(SOCK_REG(0x00), 0x29);

// Socket x DNS name length
set_byte(SOCK_REG(0x2A), length);

// Socket x DNS name chars
while (length--)
{
*w5100_data = *name++;
}

return w5100_connect(port);
}

bool w5100_connected(void)
{
// Socket x Status Register: SOCK_ESTABLISHED ?
Expand Down
16 changes: 13 additions & 3 deletions apps/w5100.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,23 @@ void w5100_data_commit(bool do_send, uint16_t size);
// to be sent to the server.
extern volatile uint8_t* w5100_data;

// Initialize this module after the IP65 TCP/IP stack has been initialized.
// Return true if the (virtual) W5100 supports DNS Offloading.
// https://github.com/a2retrosystems/uthernet2/wiki/Virtual-W5100-with-DNS
bool w5100_init(uint8_t eth_init);

// Configure W5100 Ethernet controller with additional information from IP65
// after the IP65 TCP/IP stack has been configured.
void w5100_config(uint8_t eth_init);
void w5100_config(void);

// Connect to server with IP address <addr> on TCP port <port>.
// Return true if the connection is established, return false otherwise.
bool w5100_connect_addr(uint32_t addr, uint16_t port);

// Connect to server with IP address <server_addr> on TCP port <server_port>.
// Connect to server with name <name>, <length> on TCP port <port> using
// DNS Offloading.
// Return true if the connection is established, return false otherwise.
bool w5100_connect(uint32_t addr, uint16_t port);
bool w5100_connect_name(const char* name, uint8_t length, uint16_t port);

// Check if still connected to server.
// Return true if the connection is established, return false otherwise.
Expand Down
Loading

0 comments on commit 9561545

Please sign in to comment.