/* SNTP client for Ethernet UNAPI By Konamiman 2/2010 Compilation command line: sdcc --code-loc 0x170 --data-loc 0 -mz80 --disable-warning 196 --no-std-crt0 crt0_msxdos_advanced.rel msxchar.rel asm.lib sntp.c hex2bin -e com sntp.ihx ASM.LIB, MSXCHAR.REL and crt0msx_msxdos_advanced.rel are available at www.konamiman.com (You don't need MSXCHAR.LIB if you manage to put proper PUTCHAR.REL, GETCHAR.REL and PRINTF.REL in the standard Z80.LIB... I couldn't manage to do it, I get a "Library not created with SDCCLIB" error) Comments are welcome: konamiman@konamiman.com */ #include #include "asm.h" #define LowerCase(c) ((c) | 32) #define BUFFER ((byte*)(0x8000)) #define _GENV 0x6B #define _TERM0 0 #define _SDATE 0x2B #define _STIME 0x2D #define SNTP_PORT 123 #define TICKS_TO_WAIT (3*50) #define SYSTIMER ((uint*)0xFC9E) #define SECS_IN_MINUTE ((unsigned long)(60)) #define SECS_IN_HOUR ((unsigned long)(SECS_IN_MINUTE * 60)) #define SECS_IN_DAY ((unsigned long)(SECS_IN_HOUR * 24)) #define SECS_IN_MONTH_28 ((unsigned long)(SECS_IN_DAY * 28)) #define SECS_IN_MONTH_29 ((unsigned long)(SECS_IN_DAY * 29)) #define SECS_IN_MONTH_30 ((unsigned long)(SECS_IN_DAY * 30)) #define SECS_IN_MONTH_31 ((unsigned long)(SECS_IN_DAY * 31)) #define SECS_IN_YEAR ((unsigned long)(SECS_IN_DAY * 365)) #define SECS_IN_LYEAR ((unsigned long)(SECS_IN_DAY * 366)) //Secs from 1900-1-1 to 2010-1-1 #define SECS_1900_TO_2010 ((unsigned long)(3471292800)) //Secs from 2036-1-1 0:00:00 to 2036-02-07 6:28:16 #define SECS_2036_TO_2036 ((unsigned long)(3220096)) unsigned long SecsPerMonth[12]; // Just in case you want to define a faster print function // for printing plain strings (without formatting). #define print(x) printf(x) enum TcpipUnapiFunctions { TCPIP_GET_CAPAB = 1, TCPIP_DNS_Q = 6, TCPIP_DNS_S = 7, TCPIP_UDP_OPEN = 8, TCPIP_UDP_CLOSE = 9, TCPIP_UDP_STATE = 10, TCPIP_UDP_SEND = 11, TCPIP_UDP_RCV = 12, TCPIP_WAIT = 29 }; enum TcpipErrorCodes { ERR_OK, ERR_NOT_IMP, ERR_NO_NETWORK, ERR_NO_DATA, ERR_INV_PARAM, ERR_QUERY_EXISTS, ERR_INV_IP, ERR_NO_DNS, ERR_DNS, ERR_NO_FREE_CONN, ERR_CONN_EXISTS, ERR_NO_CONN, ERR_CONN_STATE, ERR_BUFFER, ERR_LARGE_DGRAM, ERR_INV_OPER }; const char* strPresentation= "SNTP time setter for the TCP/IP UNAPI 1.0\r\n" "By Konamiman, 4/2010\r\n" "\r\n"; const char* strUsage= "Usage: sntp |. [