]> git.sur5r.net Git - cc65/commitdiff
Add new sample code contributed by Greg King
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 16 Feb 2003 14:43:00 +0000 (14:43 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 16 Feb 2003 14:43:00 +0000 (14:43 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1990 b7a2c559-68d2-44c3-8de9-860c34a00d81

samples/.cvsignore
samples/Makefile
samples/README
samples/ascii.c [new file with mode: 0644]

index 47edd4ba8032d998ced85c552f65476cf12a7452..181c11b3e67e02054942230b6220966d50d7e09d 100644 (file)
@@ -1,3 +1,4 @@
+ascii
 fire
 hello
 mousedemo
index 7df3d004f7d1caca84ad27a43cd410dbb5da1574..d91229f4c2771dd9e4c62ffb81df8973a713f1d5 100644 (file)
@@ -32,11 +32,14 @@ C1541       = c1541
 # --------------------------------------------------------------------------
 # Rules how to make each one of the binaries
 
-EXELIST=fire hello mousedemo nachtm plasma sieve tgidemo
+EXELIST=ascii fire hello mousedemo nachtm plasma sieve tgidemo
 
 .PHONY:        all
 all:           $(EXELIST)
 
+ascii:                 $(CRT0) ascii.o $(CLIB)
+       @$(LD) -t $(SYS) -m ascii.map -Ln ascii.lbl -o $@ $^
+
 fire:          $(CRT0) fire.o $(CLIB)
        @$(LD) -t $(SYS) -m fire.map -Ln fire.lbl -o $@ $^
 
index 7b350c31085556e351db01a409dbf39893aa40a4..572ec96b353c15bf49fe08c1aa52314572829e31 100644 (file)
@@ -1,4 +1,4 @@
-                                      
+
 This directory contains sample programs for the cc65 compiler.
 
 Below is a short description for each of the programs together with a list of
@@ -18,6 +18,14 @@ Please note:
 
 List of supplied sample programs:
 
+-----------------------------------------------------------------------------
+Name:           ascii
+Description:   Shows the ASCII (or ATASCII, PETSCII) codes of typed
+               characters. Written and contributed by Greg King 
+               <gngking@erols.com>.
+Platforms:             All platforms with conio or stdio (compile time 
+               configurable).
+
 -----------------------------------------------------------------------------
 Name:           fire
 Description:   Another graphics demo written by groepaz/hitmen.
diff --git a/samples/ascii.c b/samples/ascii.c
new file mode 100644 (file)
index 0000000..704833b
--- /dev/null
@@ -0,0 +1,78 @@
+/* ascii.c
+**
+** Shows the ASCII (or ATASCII, PETSCII) codes of typed characters.
+**
+** 2002-12-25, Greg King <gngking@erols.com>
+*/
+
+/* Define CONIO when you want to use the conio functions.
+** Undefine it when you want to use the stdio functions.
+** NOTE: Undefining CONIO will currently not work on the CBMs!!!
+*/
+#define CONIO
+
+#include <conio.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+#define QUIT   'Q'
+
+static unsigned char height, width, r, t;
+static int c;
+
+#ifdef CONIO
+# define PRINT cprintf
+# define PUT(c)        cputc((char)(c))
+
+/* conio doesn't echo typed characters.
+** So, this function does it.
+*/
+static int GET(void) {
+       PUT(c = (int)cgetc());
+       return c;
+       }
+#else
+# define PRINT printf
+# define GET   getchar
+#endif
+
+int main(void) {
+
+#      ifdef CONIO
+       /* conio doesn't scroll!  Avoid trouble by starting at the top
+       ** of the screen, and never going "below" the bottom of the screen.
+       */
+       clrscr();
+       r = 7;          /* allow for prompt */
+#      endif
+
+       /* This prompt fits on the VIC-20's narrow screen.
+       */
+       PRINT("Type characters to see\r\ntheir hexadecimal code\r\nnumbers:\r\n\n");
+       screensize(&width, &height);    /* get the screen's dimensions */
+       width /= 6;                     /* get number of codes on a line */
+               cursor(true);
+       t = 0;
+       while ((c = GET()) != EOF) {
+
+#              ifdef CONIO
+               if (r == height) {
+                       clrscr();
+                       PUT(c); /* echo char. again because screen was erased */
+                       r = 1;
+                       }
+#              endif
+
+               PRINT("=$%02x ", c);
+               if (c == QUIT)
+                   break;
+               if (++t == width) {
+                       PRINT("\r\n");
+                       ++r;
+                       t = 0;
+                       }
+               }
+       PRINT("\r\n");
+       return EXIT_SUCCESS;
+       }