mirror of
https://github.com/bobbimanners/emailler.git
synced 2025-03-20 11:29:37 +00:00
Added first C application :-)
The date application isn't of much actual use. But it shows - how easy to use the IP65 C API is - the power of combining IP65 with the C library (going from SNTP time format to a date string in two lines of code)
This commit is contained in:
parent
a40942075d
commit
393e27922b
@ -23,6 +23,7 @@ endif
|
||||
ATRDRIVERLIB = ../drivers/atrdragon.lib
|
||||
|
||||
UDP =\
|
||||
date
|
||||
|
||||
TCP =\
|
||||
telnet65
|
||||
@ -70,6 +71,8 @@ telnet65.com: ATARI_CFG = atrtelnet.cfg
|
||||
%.o: %.s
|
||||
ca65 $<
|
||||
|
||||
%.o: %.c
|
||||
|
||||
%.prg: %.o ip65 drivers $(INCFILES)
|
||||
ld65 -o $*.prg -C c64.cfg -m $*.c64.map -vm $< $(IP65LIB) $(C64DRIVERLIB) c64.lib
|
||||
|
||||
@ -79,18 +82,33 @@ telnet65.com: ATARI_CFG = atrtelnet.cfg
|
||||
%.com: %.o ip65 drivers $(INCFILES)
|
||||
ld65 -o $*.com -C $(ATARI_CFG) -m $*.atr.map -vm $< $(IP65LIB) $(ATRDRIVERLIB) atari.lib
|
||||
|
||||
%.prg: %.c ip65 drivers $(INCFILES)
|
||||
cl65 -o $*.prg -O -t c64 -m $*.c64.map -vm $< $(IP65LIB) ../drivers/ip65_c64.lib
|
||||
rm $*.o
|
||||
|
||||
%.bin: %.c ip65 drivers $(INCFILES)
|
||||
cl65 -o $*.bin -O -t apple2 -m $*.a2.map -vm $< $(IP65LIB) ../drivers/ip65_apple2.lib
|
||||
rm $*.o
|
||||
|
||||
%.com: %.c ip65 drivers $(INCFILES)
|
||||
cl65 -o $*.com -O -t atari -m $*.atr.map -vm $< $(IP65LIB) ../drivers/ip65_atari.lib
|
||||
rm $*.o
|
||||
|
||||
ip65.d64: prg
|
||||
$(C1541) -format ip65,00 d64 $@
|
||||
$(C1541) -attach $@ -write date.prg date,p
|
||||
$(C1541) -attach $@ -write telnet65.prg telnet65,p
|
||||
|
||||
ip65.dsk: bin
|
||||
cp prodos.dsk $@
|
||||
java -jar $(AC) -cc65 $@ date bin < date.bin
|
||||
java -jar $(AC) -cc65 $@ telnet65 bin < telnet65.bin
|
||||
|
||||
ip65.atr: com
|
||||
mkdir atr
|
||||
cp dos.sys atr/dos.sys
|
||||
cp dup.sys atr/dup.sys
|
||||
cp date.com atr/date.com
|
||||
cp telnet65.com atr/telnet65.com
|
||||
$(DIR2ATR) -b Dos25 1040 $@ atr
|
||||
rm -r atr
|
||||
|
77
apps/date.c
Normal file
77
apps/date.c
Normal file
@ -0,0 +1,77 @@
|
||||
#include <cc65.h>
|
||||
#include <time.h>
|
||||
#include <conio.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../inc/ip65.h"
|
||||
|
||||
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_DNS_LOOKUP_FAILED:
|
||||
printf("- Lookup failed\n");
|
||||
break;
|
||||
default:
|
||||
printf("- Error $%X\n", ip65_error);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void confirm_exit(void)
|
||||
{
|
||||
printf("\nPress any key");
|
||||
cgetc();
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
unsigned long server, time;
|
||||
|
||||
if (doesclrscrafterexit())
|
||||
{
|
||||
atexit(confirm_exit);
|
||||
}
|
||||
|
||||
printf("Initializing ");
|
||||
if (ip65_init())
|
||||
{
|
||||
error_exit();
|
||||
}
|
||||
|
||||
printf("- Ok\n\nObtaining IP address ");
|
||||
if (dhcp_init())
|
||||
{
|
||||
error_exit();
|
||||
}
|
||||
|
||||
printf("- Ok\n\nResolving pool.ntp.org ");
|
||||
server = dns_resolve("pool.ntp.org");
|
||||
if (!server)
|
||||
{
|
||||
error_exit();
|
||||
}
|
||||
|
||||
printf("- Ok\n\nGetting UTC ");
|
||||
time = sntp_get_time(server);
|
||||
if (!time)
|
||||
{
|
||||
error_exit();
|
||||
}
|
||||
|
||||
// Convert time from seconds since 1900 to
|
||||
// seconds since 1970 according to RFC 868.
|
||||
time -= 2208988800UL;
|
||||
|
||||
printf("- %s", ctime(&time));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user