From 3be3c332a5e47434d74e99e2ed77e9fb9f4cf60c Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 15 Mar 2019 17:14:18 -0400 Subject: printf removal --- src/ChangeLog | 6 ++++ src/Makefile | 9 +++-- src/common.c | 102 ------------------------------------------------------- src/common.h | 4 --- src/formatip.c | 34 +++++++++++++++++++ src/formatip.h | 1 + src/fujichat.atr | Bin 92176 -> 92176 bytes src/fujichat.c | 1 + src/fujiconf.c | 1 + src/fujimenu.c | 38 ++++++++++++++++++--- src/fujitest.atr | Bin 92176 -> 92176 bytes src/makeauto.c | 76 +++++++++++++++-------------------------- 12 files changed, 110 insertions(+), 162 deletions(-) create mode 100644 src/formatip.c create mode 100644 src/formatip.h (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 299e9ba..0ecb00a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +- 20190315 bkw: + +Eliminate printf/sprintf calls from fujimenu.c and makeauto.c. Also +eliminate perror() from makeauto.c, which shrinks the xex by almost 2KB +(but prints numeric error messages instead of human-readable ones). + - 20190313 bkw: FujiChat is back! diff --git a/src/Makefile b/src/Makefile index 8d27157..9d963d4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,7 +13,7 @@ all: fujichat.xex fujiconf.xex aexec.xex fujimenu.xex makeauto.xex about.xex loa # The uIP Makefile: -include Makefile.include -uip: $(addprefix $(OBJECTDIR)/, fujichat.o common.o commands.o rs232dev.o clock-arch.o) keybuf.o apps.a uip.a fujiput.s +uip: $(addprefix $(OBJECTDIR)/, fujichat.o common.o commands.o rs232dev.o clock-arch.o) keybuf.o apps.a uip.a fujiput.s formatip.o fujichat.xex: uip mv uip fujichat.xex @@ -24,8 +24,11 @@ keybuf.o: keybuf.s common.o: common.c common.h $(CC) $(CFLAGS) -c -o common.o common.c -fujiconf.xex: fujiconf.c fujichat.h common.o - $(CC) $(CFLAGS) -o fujiconf.xex fujiconf.c common.o obj/uiplib.o +formatip.o: formatip.c formatip.h + $(CC) $(CFLAGS) -c -o formatip.o formatip.c + +fujiconf.xex: fujiconf.c fujichat.h common.o formatip.o + $(CC) $(CFLAGS) -o fujiconf.xex fujiconf.c common.o formatip.o obj/uiplib.o fujimenu.xex: fujimenu.c fujichat.h aexec.xex common.o $(CC) $(CFLAGS) -o fujimenu.xex fujimenu.c common.o diff --git a/src/common.c b/src/common.c index deab584..e482731 100644 --- a/src/common.c +++ b/src/common.c @@ -18,25 +18,6 @@ void disable_break(void) { asm("sta $D20E"); /* IRQEN */ } -/* easier to copy/paste this tiny function from uip.c - than it would be to rebuild all of uIP for use in - this program! Also don't want to bloat fujiconf by - linking uip.a, even if it would link without a - recompile. */ -/* -u16_t local_htons(u16_t val) { - return HTONS(val); -} -*/ - -/* this version's half the size */ -u16_t local_htons(u16_t val) { - __AX__ = val; - asm("sta tmp1"); - asm("txa"); - asm("ldx tmp1"); -} - /* helper for fuji_cgetc */ void __fastcall__ call_keybdv(void) { asm("lda $E420+5"); /* KEYBDV */ @@ -54,37 +35,6 @@ char __fastcall__ fuji_cgetc(void) { asm("ldx #0"); } - -#if 0 -char get_config(void) { - char config_valid = 0; - FILE *f = fopen(DEFAULT_CONF_FILE, "rb"); - - puts("Loading config from " DEFAULT_CONF_FILE); - - if(f) { - config_valid = - fread(config, 1, sizeof(fuji_conf_t), f) == sizeof(fuji_conf_t); - fclose(f); - if(!config_valid) - puts("Config file is wrong size"); - } else { - puts("No config file found"); - } - - if(config_valid) { - if(!config_is_valid()) { - puts("Invalid or outdated config file"); - config_valid = 0; - } else { - puts("Loaded OK"); - } - } - - return config_valid; -} - -#else /* using open() read() close() instead of fopen() fread() fclose() is a big win: save us 438 bytes! */ char get_config(void) { @@ -114,7 +64,6 @@ char get_config(void) { return config_valid; } -#endif char config_is_valid(void) { // return( (memcmp(config->signature, CONF_SIGNATURE, 2) == 0) && (config->version == CONF_VERSION) ); @@ -159,57 +108,6 @@ void set_default_config(void) { // config_valid = 1; } -static char ipbuf[20]; -/* -static char *fmt = "%d.%d.%d.%d"; -*/ -char * format_ip(uip_ipaddr_t *ip) { - - u16_t *ipaddr = (u16_t *)ip; - sprintf(ipbuf, "%d.%d.%d.%d", - local_htons(ipaddr[0]) >> 8, - local_htons(ipaddr[0]) & 0xff, - local_htons(ipaddr[1]) >> 8, - local_htons(ipaddr[1]) & 0xff); - - return ipbuf; - - /* - asm(" sta ptr1"); - asm(" stx ptr1+1"); - - asm(" lda #<_ipbuf"); - asm(" ldx #>_ipbuf"); - asm(" jsr pushax"); - - asm(" lda #<_fmt"); - asm(" ldx #>_fmt"); - asm(" jsr pushax"); - - asm(" ldy #0"); - asm(" lda (ptr1),y"); - asm(" jsr pusha0"); - - asm(" ldy #1"); - asm(" lda (ptr1),y"); - asm(" jsr pusha0"); - - asm(" ldy #2"); - asm(" lda (ptr1),y"); - asm(" jsr pusha0"); - - asm(" ldy #3"); - asm(" lda (ptr1),y"); - asm(" jsr pusha0"); - - asm(" ldy #$0c"); - asm(" jsr _sprintf"); - - asm(" lda #<_ipbuf"); - asm(" ldx #>_ipbuf"); - */ -} - void get_line(char *buf, unsigned char len) { asm("ldy #$00"); asm("lda (sp),y"); diff --git a/src/common.h b/src/common.h index c84b417..1f7b4f5 100644 --- a/src/common.h +++ b/src/common.h @@ -9,10 +9,6 @@ /* This stays resident */ extern fuji_conf_t *config; -/* uIP-related */ -char * format_ip(uip_ipaddr_t *ip); -u16_t local_htons(u16_t val); - /* config-related */ char get_config(void); char config_is_valid(void); diff --git a/src/formatip.c b/src/formatip.c new file mode 100644 index 0000000..f1a2fd1 --- /dev/null +++ b/src/formatip.c @@ -0,0 +1,34 @@ +#include +#include "uip.h" + +/* easier to copy/paste this tiny function from uip.c + than it would be to rebuild all of uIP for use in + this program! Also don't want to bloat fujiconf by + linking uip.a, even if it would link without a + recompile. */ +/* +u16_t local_htons(u16_t val) { + return HTONS(val); +} +*/ + +/* this version's half the size */ +static u16_t local_htons(u16_t val) { + __AX__ = val; + asm("sta tmp1"); + asm("txa"); + asm("ldx tmp1"); +} + +static char ipbuf[20]; + +char *format_ip(uip_ipaddr_t *ip) { + u16_t *ipaddr = (u16_t *)ip; + sprintf(ipbuf, "%d.%d.%d.%d", + local_htons(ipaddr[0]) >> 8, + local_htons(ipaddr[0]) & 0xff, + local_htons(ipaddr[1]) >> 8, + local_htons(ipaddr[1]) & 0xff); + + return ipbuf; +} diff --git a/src/formatip.h b/src/formatip.h new file mode 100644 index 0000000..f7c387e --- /dev/null +++ b/src/formatip.h @@ -0,0 +1 @@ +char *format_ip(uip_ipaddr_t *ip); diff --git a/src/fujichat.atr b/src/fujichat.atr index d29229e..ed5a7f1 100644 Binary files a/src/fujichat.atr and b/src/fujichat.atr differ diff --git a/src/fujichat.c b/src/fujichat.c index 2f369d5..3d61a09 100644 --- a/src/fujichat.c +++ b/src/fujichat.c @@ -55,6 +55,7 @@ /* FujiChat includes */ #include "fujichat.h" #include "common.h" +#include "formatip.h" #include "features.h" #ifdef FEAT_KEYBOARD_MACROS diff --git a/src/fujiconf.c b/src/fujiconf.c index f77f2a9..e2305ae 100644 --- a/src/fujiconf.c +++ b/src/fujiconf.c @@ -8,6 +8,7 @@ #include "uiplib.h" #include "fujichat.h" #include "common.h" +#include "formatip.h" /* TODO: move these to an external file or otherwise come up with a way to reuse the memory */ diff --git a/src/fujimenu.c b/src/fujimenu.c index 29c9d7d..58037d5 100644 --- a/src/fujimenu.c +++ b/src/fujimenu.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "fujichat.h" #include "common.h" @@ -9,10 +10,19 @@ */ void run_prog(char *file) { + static char err[4]; int c; - printf("\nLoading %s...\n", file); + fputs("\nLoading ", stdout); + fputs(file, stdout); + puts("..."); c = atari_exec(file); - printf("Error %d!\n\xfd", c); + // printf("Error %d!\n\xfd", c); + (void)itoa(c, err, 10); + fputs("Error ", stdout); + fputs(err, stdout); + putchar('!'); + putchar(0xfd); + putchar('\n'); } void main(void) { @@ -27,17 +37,35 @@ void main(void) { set_default_config(); while(1) { - printf("\n %cbout\n", 'A' | 0x80); - + putchar('\n'); + putchar(' '); + putchar(' '); + putchar(0xc1); + puts("bout"); + // printf("\n %cbout\n", 'A' | 0x80); + + putchar(have_conf ? ' ' : '*'); + putchar(' '); + putchar(0xd3); + puts("etup"); + /* printf("%s%cetup\n", (have_conf ? " " : "* "), 'S' | 0x80); + */ + putchar(have_conf ? '*' : ' '); + putchar(' '); + putchar(0xc3); + puts("hat"); + /* printf("%s%chat\n", (have_conf ? "* " : " "), 'C' | 0x80); + */ - printf(" %cOS\n", 'D' | 0x80); + puts(" \xc4OS"); + // printf(" %cOS\n", 'D' | 0x80); putchar('\n'); putchar('>'); diff --git a/src/fujitest.atr b/src/fujitest.atr index faa9134..53981bf 100644 Binary files a/src/fujitest.atr and b/src/fujitest.atr differ diff --git a/src/makeauto.c b/src/makeauto.c index 6e8ff71..36fc6e3 100644 --- a/src/makeauto.c +++ b/src/makeauto.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "fujichat.h" #include "common.h" @@ -14,9 +15,6 @@ static char *rs232_drivers[][2] = { { "D:PRCONN.SER", "P:R: Connection" }, }; -/* APPEND_BUF_SIZE should be >= the size of the largest .SER file */ -#define APPEND_BUF_SIZE 2048 - void reboot(void) { asm("jmp $e477"); } @@ -24,10 +22,12 @@ void reboot(void) { static char get_yesno(char *prompt, char dflt) { char buf[5]; - printf("%s [%c/%c]: ", - prompt, - (dflt ? 'Y' : 'y'), - (dflt ? 'n' : 'N')); + fputs(prompt, stdout); + fputs(" [", stdout); + putchar(dflt ? 'Y' : 'y'); + putchar('/'); + putchar(dflt ? 'n' : 'N'); + fputs("]: ", stdout); fflush(stdout); get_line(buf, 4); @@ -45,41 +45,22 @@ static char get_yesno(char *prompt, char dflt) { } } -//char append_to(FILE *to, char *src) { -// int bytes; -// char ret; -// static char buf[APPEND_BUF_SIZE]; -// FILE *from = fopen(src, "rb"); -// -// printf("append_to: %s\n", src); -// -// if(!from) { -// perror(src); -// return 0; -// } -// -// while( (bytes = fread(buf, 1, APPEND_BUF_SIZE, from)) ) { -// printf("%d bytes in, eof? %d\n", bytes, feof(from)); -// bytes = fwrite(buf, 1, bytes, to); -// printf("%d bytes out\n", bytes); -// } -// -// ret = feof(from); /* 1 = no error */ -// fclose(from); -// -// return ret; -//} +void printerr(char *msg) { + char ebuf[4]; + (void)itoa(_oserror, ebuf, 10); + fputs(msg, stdout); + fputs(": Error ", stdout); + puts(ebuf); + putchar(A_BEL); +} char append_to(FILE *to, char *src) { int bytes = 0, c; char ret; - // static char buf[APPEND_BUF_SIZE]; FILE *from = fopen(src, "rb"); - printf("append_to: %s\n", src); - if(!from) { - perror(src); + printerr(src); return 0; } @@ -94,7 +75,6 @@ char append_to(FILE *to, char *src) { ret = feof(from); /* 1 = no error */ fclose(from); - printf("bytes=%d, ret=%d\n", bytes, ret); return ret; } @@ -107,7 +87,8 @@ char append_files(char *dst, char *src1, char *src2) { fclose(dfile); return ret; } else { - perror(dst); + printerr(dst); + fclose(dfile); return 0; } } @@ -116,15 +97,15 @@ static void rs232_driver_menu() { static char buf[256]; int i; - puts("Select your serial port type\n"); + puts("Select your serial port driver"); for(i=0; i