aboutsummaryrefslogtreecommitdiffstats
path: root/com32/samples
diff options
context:
space:
mode:
Diffstat (limited to 'com32/samples')
-rw-r--r--com32/samples/Makefile80
-rw-r--r--com32/samples/fancyhello.c43
-rw-r--r--com32/samples/hello.c41
-rw-r--r--com32/samples/keytest.c79
4 files changed, 243 insertions, 0 deletions
diff --git a/com32/samples/Makefile b/com32/samples/Makefile
new file mode 100644
index 00000000..93b7343a
--- /dev/null
+++ b/com32/samples/Makefile
@@ -0,0 +1,80 @@
+#ident "$Id$"
+## -----------------------------------------------------------------------
+##
+## Copyright 2001-2004 H. Peter Anvin - All Rights Reserved
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
+## USA; either version 2 of the License, or (at your option) any later
+## version; incorporated herein by reference.
+##
+## -----------------------------------------------------------------------
+
+##
+## samples for syslinux users
+##
+
+gcc_ok = $(shell if gcc $(1) -c -x c /dev/null -o /dev/null 2>/dev/null; \
+ then echo $(1); else echo $(2); fi)
+
+M32 := $(call gcc_ok,-m32,)
+
+CC = gcc $(M32)
+LD = ld -m elf_i386
+AR = ar
+NASM = nasm
+RANLIB = ranlib
+CFLAGS = -W -Wall -march=i386 -Os -fomit-frame-pointer -I../libutil/include -I../include -D__COM32__
+LNXCFLAGS = -W -Wall -march=i386 -Os -g -I../libutil/include
+LNXSFLAGS = -march=i386
+LNXLDFLAGS = -g
+SFLAGS = -D__COM32__ -march=i386
+LDFLAGS = -T ../lib/com32.ld
+OBJCOPY = objcopy
+PPMTOLSS16 = ../ppmtolss16
+LIBGCC := $(shell $(CC) --print-libgcc)
+LIBS = ../libutil/libutil_com.a ../lib/libcom32.a $(LIBGCC)
+LNXLIBS = ../libutil/libutil_lnx.a
+
+.SUFFIXES: .lss .c .o .elf .c32 .lnx
+
+all: hello.c32 \
+ fancyhello.c32 fancyhello.lnx \
+ keytest.c32 keytest.lnx
+
+.PRECIOUS: %.o
+%.o: %.S
+ $(CC) $(SFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.o
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.elf
+%.elf: %.o $(LIBS)
+ $(LD) $(LDFLAGS) -o $@ $^
+
+.PRECIOUS: %.lo
+%.lo: %.S
+ $(CC) $(LNXSFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.lo
+%.lo: %.c
+ $(CC) $(LNXCFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.lnx
+%.lnx: %.lo $(LNXLIBS)
+ $(CC) $(LNXLDFLAGS) -o $@ $^
+
+%.c32: %.elf
+ $(OBJCOPY) -O binary $< $@
+
+tidy:
+ rm -f *.o *.lo *.a *.lst *.elf
+
+clean: tidy
+ rm -f *.lss *.c32 *.lnx *.com
+
+spotless: clean
+ rm -f *~ \#*
diff --git a/com32/samples/fancyhello.c b/com32/samples/fancyhello.c
new file mode 100644
index 00000000..cf255fbc
--- /dev/null
+++ b/com32/samples/fancyhello.c
@@ -0,0 +1,43 @@
+
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2004 H. Peter Anvin - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+ * Bostom MA 02111-1307, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * fancyhello.c
+ *
+ * Hello, World! using libcom32 and ANSI console; also possible to compile
+ * as a Linux application for testing.
+ */
+
+#include <string.h>
+#include <stdio.h>
+
+#include <consoles.h> /* Provided by libutil */
+
+int main(void)
+{
+ char buffer[1024];
+
+ console_ansi_std();
+
+ 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);
+ if ( !strncmp(buffer, "exit", 4) )
+ break;
+ printf("\033[1m:\033[0m %s", buffer);
+ }
+ return 0;
+}
diff --git a/com32/samples/hello.c b/com32/samples/hello.c
new file mode 100644
index 00000000..7d0504bc
--- /dev/null
+++ b/com32/samples/hello.c
@@ -0,0 +1,41 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2004 H. Peter Anvin - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+ * Bostom MA 02111-1307, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * hello.c
+ *
+ * Hello, World! using libcom32
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <console.h>
+
+int main(void)
+{
+ char buffer[1024];
+
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
+
+ printf("Hello, World!\n");
+
+ for (;;) {
+ printf("> ");
+ fgets(buffer, sizeof buffer, stdin);
+ if ( !strncmp(buffer, "exit", 4) )
+ break;
+ printf(": %s", buffer);
+ }
+
+ return 0;
+}
diff --git a/com32/samples/keytest.c b/com32/samples/keytest.c
new file mode 100644
index 00000000..e9af9ac6
--- /dev/null
+++ b/com32/samples/keytest.c
@@ -0,0 +1,79 @@
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2004 H. Peter Anvin - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+ * Bostom MA 02111-1307, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * keytest.c
+ *
+ * Test the key parsing library
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <consoles.h> /* Provided by libutil */
+#include <getkey.h>
+
+static void cooked_keys(void)
+{
+ int key;
+
+ printf("[cooked]");
+
+ for(;;) {
+ key = get_key(stdin);
+
+ if ( key == 0x03 ) {
+ printf("[done]\n");
+ exit(0);
+ } else if ( key == '?' )
+ return;
+
+ if ( key >= 0x20 && key < 0x100 ) {
+ putchar(key);
+ } else {
+ printf("[%04x]", key);
+ }
+ }
+}
+
+static void raw_keys(void)
+{
+ int key;
+
+ printf("[raw]");
+
+ for(;;) {
+ key = getc(stdin);
+
+ if ( key == 0x03 ) {
+ printf("[done]\n");
+ exit(0);
+ } else if ( key == '!' )
+ return;
+
+ printf("<%02x>", key);
+ }
+}
+
+int main(void)
+{
+ console_ansi_raw();
+
+ printf("Press keys, end with Ctrl-C...\n");
+
+ for (;;) {
+ cooked_keys();
+ raw_keys();
+ }
+}