mirror of
https://github.com/bobbimanners/emailler.git
synced 2024-10-31 13:08:40 +00:00
4577c2ab19
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.
214 lines
3.4 KiB
C
214 lines
3.4 KiB
C
#include <cc65.h>
|
|
#include <fcntl.h>
|
|
#include <ctype.h>
|
|
#include <conio.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#ifdef __APPLE2__
|
|
#include <apple2_filetype.h>
|
|
#endif
|
|
|
|
#include "../inc/ip65.h"
|
|
#include "ifttt.h"
|
|
|
|
char key[80 + 1];
|
|
char text[280 + 1];
|
|
|
|
void error_exit(void)
|
|
{
|
|
switch (ip65_error)
|
|
{
|
|
case IP65_ERROR_DEVICE_FAILURE:
|
|
printf("- No device found\n");
|
|
break;
|
|
case IP65_ERROR_ABORTED_BY_USER:
|
|
printf("- User abort\n");
|
|
break;
|
|
case IP65_ERROR_TIMEOUT_ON_RECEIVE:
|
|
printf("- Timeout\n");
|
|
break;
|
|
case IP65_ERROR_MALFORMED_URL:
|
|
printf("- Malformed URL\n");
|
|
break;
|
|
case IP65_ERROR_DNS_LOOKUP_FAILED:
|
|
printf("- Lookup failed\n");
|
|
break;
|
|
default:
|
|
printf("- Error $%X\n", ip65_error);
|
|
}
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
void confirm_exit(void)
|
|
{
|
|
printf("\nPress any key ");
|
|
cgetc();
|
|
}
|
|
|
|
unsigned char cols(void)
|
|
{
|
|
unsigned char cols, rows;
|
|
|
|
screensize(&cols, &rows);
|
|
return cols;
|
|
}
|
|
|
|
void input(char* str, unsigned int max, const char* tag)
|
|
{
|
|
char chr;
|
|
uint8_t row;
|
|
uint16_t len = max / cols() + 1;
|
|
|
|
for (row = len; --row; row)
|
|
{
|
|
putchar('\n');
|
|
}
|
|
row = wherey() - len;
|
|
len = 0;
|
|
|
|
while (true)
|
|
{
|
|
str[len] = '\0';
|
|
|
|
gotoxy(0, row);
|
|
cprintf("%s (%d/%d) \r\n%s", tag, len, max, str);
|
|
|
|
cursor(1);
|
|
chr = cgetc();
|
|
cursor(0);
|
|
|
|
if (chr == CH_ENTER)
|
|
{
|
|
break;
|
|
}
|
|
if (chr == CH_DEL)
|
|
{
|
|
if (len == 0)
|
|
{
|
|
continue;
|
|
}
|
|
if (wherex() > 0)
|
|
{
|
|
gotox(wherex() - 1);
|
|
}
|
|
else
|
|
{
|
|
gotoxy(cols() - 1, wherey() - 1);
|
|
}
|
|
cputc(' ');
|
|
--len;
|
|
continue;
|
|
}
|
|
if (len == max)
|
|
{
|
|
continue;
|
|
}
|
|
if (isprint(chr))
|
|
{
|
|
str[len++] = chr;
|
|
}
|
|
}
|
|
}
|
|
|
|
void main()
|
|
{
|
|
int retval;
|
|
uint8_t eth_init = ETH_INIT_DEFAULT;
|
|
|
|
if (doesclrscrafterexit())
|
|
{
|
|
atexit(confirm_exit);
|
|
}
|
|
|
|
{
|
|
int file;
|
|
|
|
printf("\nLoading key ");
|
|
file = open("ifttt.key", O_RDONLY);
|
|
if (file != -1)
|
|
{
|
|
read(file, key, sizeof(key));
|
|
close(file);
|
|
printf("- Ok\n");
|
|
}
|
|
else
|
|
{
|
|
printf("- Failed\n\n\n");
|
|
input(key, sizeof(key) - 1, "IFTTT webhook key");
|
|
if (*key == '\0')
|
|
{
|
|
printf("\n");
|
|
return;
|
|
}
|
|
|
|
printf("\n\nSaving key ");
|
|
#ifdef __APPLE2__
|
|
_filetype = PRODOS_T_TXT;
|
|
#endif
|
|
file = open("ifttt.key", O_WRONLY | O_CREAT | O_TRUNC);
|
|
if (file != -1)
|
|
{
|
|
write(file, key, sizeof(key));
|
|
close(file);
|
|
printf("- Ok\n");
|
|
}
|
|
else
|
|
{
|
|
printf("- ");
|
|
perror(NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
#ifdef __APPLE2__
|
|
{
|
|
int file;
|
|
|
|
printf("\nSetting slot ");
|
|
file = open("ethernet.slot", O_RDONLY);
|
|
if (file != -1)
|
|
{
|
|
read(file, ð_init, 1);
|
|
close(file);
|
|
eth_init &= ~'0';
|
|
}
|
|
printf("- %d\n", eth_init);
|
|
}
|
|
#endif
|
|
|
|
printf("\nInitializing ");
|
|
if (ip65_init(eth_init))
|
|
{
|
|
error_exit();
|
|
}
|
|
|
|
printf("- Ok\n\nObtaining IP address ");
|
|
if (dhcp_init())
|
|
{
|
|
error_exit();
|
|
}
|
|
|
|
printf("- Ok\n\n\n");
|
|
input(text, sizeof(text) - 1, "Text");
|
|
if (*text == '\0')
|
|
{
|
|
printf("\n");
|
|
return;
|
|
}
|
|
|
|
printf("\n\nSending tweet ");
|
|
retval = ifttt_trigger(key, "tweet", text, NULL, NULL);
|
|
|
|
if (retval < 0)
|
|
{
|
|
error_exit();
|
|
}
|
|
if (retval != 200)
|
|
{
|
|
printf("- Error (HTTP status %d)\n", retval);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
printf("- Ok\n");
|
|
}
|