aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2019-03-15 17:14:18 -0400
committerB. Watson <yalhcru@gmail.com>2019-03-15 17:14:18 -0400
commit3be3c332a5e47434d74e99e2ed77e9fb9f4cf60c (patch)
treed36549357611a80add50e5d8c896acf032e80b88 /src
parente0e6a9b6ee60c0b7367be4c0caa99534b6d23071 (diff)
downloadfujichat-3be3c332a5e47434d74e99e2ed77e9fb9f4cf60c.tar.gz
printf removal
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/Makefile9
-rw-r--r--src/common.c102
-rw-r--r--src/common.h4
-rw-r--r--src/formatip.c34
-rw-r--r--src/formatip.h1
-rw-r--r--src/fujichat.atrbin92176 -> 92176 bytes
-rw-r--r--src/fujichat.c1
-rw-r--r--src/fujiconf.c1
-rw-r--r--src/fujimenu.c38
-rw-r--r--src/fujitest.atrbin92176 -> 92176 bytes
-rw-r--r--src/makeauto.c76
12 files changed, 110 insertions, 162 deletions
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 <stdio.h>
+#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
--- a/src/fujichat.atr
+++ b/src/fujichat.atr
Binary files 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 <stdio.h>
#include <conio.h>
#include <string.h>
+#include <stdlib.h>
#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
--- a/src/fujitest.atr
+++ b/src/fujitest.atr
Binary files 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 <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
#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<DRIVER_LIST_LEN; ++i) {
- printf("%d: %s\n",
- i + 1,
- rs232_drivers[i][1]);
+ putchar('1' + i);
+ putchar(':');
+ putchar(' ');
+ puts(rs232_drivers[i][1]);
}
- puts("\nEnter number from list, or the\ndriver filename if not listed.");
- fputs("[2]: ", stdout);
+ fputs("\nEnter number from list, or the\ndriver filename if not listed.\n[2]: ", stdout);
fflush(stdout);
do {
@@ -147,12 +128,11 @@ static void rs232_driver_menu() {
} /* else use whatever they entered as a filename */
} while(i);
- // if(!rename("D:AUTORUN.SYS", "D:AUTORUN.BAK")) {
- // puts("Renamed AUTORUN.SYS to AUTORUN.BAK");
- // }
-
do {
- printf("\nCreating AUTORUN.SYS from\n%s and LOADMENU.COM\n", buf);
+ puts("\nCreating AUTORUN.SYS from");
+ fputs(buf, stdout);
+ puts(" and LOADMENU.COM");
+
i = !append_files("D:AUTORUN.SYS", buf, "D:LOADMENU.COM");
if(i) {
i = get_yesno("\xfdRetry", 1);