aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--com32/modules/Makefile9
-rw-r--r--com32/modules/fancyhello.c33
2 files changed, 32 insertions, 10 deletions
diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index cfd44b43..737e6f55 100644
--- a/com32/modules/Makefile
+++ b/com32/modules/Makefile
@@ -25,7 +25,8 @@ LD = ld -m elf_i386
AR = ar
NASM = nasm
RANLIB = ranlib
-CFLAGS = -W -Wall -march=i386 -Os -fomit-frame-pointer -I../include
+CFLAGS = -W -Wall -march=i386 -Os -fomit-frame-pointer -I../include -D__COM32__
+LNXCFLAGS = -W -Wall -march=i386 -Os -g
SFLAGS = -march=i386
LDFLAGS = -T ../lib/com32.ld
OBJCOPY = objcopy
@@ -35,7 +36,7 @@ LIBGCC := $(shell $(CC) --print-libgcc)
.SUFFIXES: .lss .c .o .elf .c32
-all: hello.c32 fancyhello.c32
+all: hello.c32 fancyhello.c32 fancyhello.lnx
.PRECIOUS: %.o
%.o: %.S
@@ -49,6 +50,10 @@ all: hello.c32 fancyhello.c32
%.elf: %.o $(LIB)
$(LD) $(LDFLAGS) -o $@ $^ $(LIBGCC)
+.PRECIOUS: %.lnx
+%.lnx: %.c
+ $(CC) $(LNXCFLAGS) -o $@ $^
+
%.c32: %.elf
$(OBJCOPY) -O binary $< $@
diff --git a/com32/modules/fancyhello.c b/com32/modules/fancyhello.c
index a59be43a..42c04d92 100644
--- a/com32/modules/fancyhello.c
+++ b/com32/modules/fancyhello.c
@@ -1,3 +1,4 @@
+
#ident "$Id$"
/* ----------------------------------------------------------------------- *
*
@@ -14,31 +15,47 @@
/*
* fancyhello.c
*
- * Hello, World! using libcom32 and ASI console
+ * Hello, World! using libcom32 and ANSI console; also possible to compile
+ * as a Linux application for testing.
*/
#include <string.h>
#include <stdio.h>
+
+#ifdef __COM32__
+
#include <console.h>
+static void console_init(void)
+{
+ /* Write both to the ANSI console and the serial port, if configured */
+ openconsole(&dev_stdcon_r, &dev_ansiserial_w);
+ printf("\033[20h"); /* Automatically convert \r\n -> \n */
+}
+
+#else
+
+static void console_init(void)
+{
+ /* Do Linux initialization (none needed) */
+}
+
+#endif
+
int main(void)
{
char buffer[1024];
- /* Write both to the ANSI console and the serial port, if configured */
- openconsole(&dev_stdcon_r, &dev_ansiserial_w);
+ console_init();
- printf("(lifesign)\r\n(another)\r\n(another)\r\n");
- printf("\033[1;33;44m *** \033[37mHello, World!\033[33m *** \033[0m\r\n");
+ printf("\033[1;33;44m *** \033[37mHello, World!\033[33m *** \033[0m\n");
for (;;) {
printf("\033[1;36m>\033[0m ");
fgets(buffer, sizeof buffer, stdin);
- /* fgets() prints an \n for us, but not \r */
- putchar('\r');
if ( !strncmp(buffer, "exit", 4) )
break;
- printf("\033[1m:\033[0m %s\r", buffer);
+ printf("\033[1m:\033[0m %s", buffer);
}
return 0;
}