2003-02-16 14:43:00 +00:00
|
|
|
/* ascii.c
|
|
|
|
**
|
|
|
|
** Shows the ASCII (or ATASCII, PETSCII) codes of typed characters.
|
|
|
|
**
|
2003-06-03 11:39:02 +00:00
|
|
|
** 2003-03-09, Greg King <gngking@erols.com>
|
2003-02-16 14:43:00 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-03 11:39:02 +00:00
|
|
|
/* Define USE_STDIO, when you want to use the stdio functions.
|
|
|
|
** Do not define it, when you want to use the conio functions.
|
|
|
|
** NOTE: stdin on some targets is line-bufferred. You might need to type
|
|
|
|
** a key, then tap the return(enter)-key, in order to see each code.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
#define USE_STDIO
|
2003-02-16 14:43:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <conio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
#define QUIT 'Q'
|
2003-02-16 14:43:00 +00:00
|
|
|
|
2003-06-03 11:39:02 +00:00
|
|
|
/* r -- row. t -- table-column.
|
|
|
|
*/
|
2003-02-16 14:43:00 +00:00
|
|
|
static unsigned char height, width, r, t;
|
|
|
|
static int c;
|
|
|
|
|
2003-06-03 11:39:02 +00:00
|
|
|
#ifndef USE_STDIO
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
# define PRINT cprintf
|
|
|
|
# define PUT(c) cputc((char)(c))
|
2003-02-16 14:43:00 +00:00
|
|
|
|
|
|
|
/* conio doesn't echo typed characters.
|
|
|
|
** So, this function does it.
|
|
|
|
*/
|
|
|
|
static int GET(void) {
|
2013-05-09 11:56:54 +00:00
|
|
|
PUT(c = (int)cgetc());
|
|
|
|
return c;
|
|
|
|
}
|
2003-06-03 11:39:02 +00:00
|
|
|
|
2003-02-16 14:43:00 +00:00
|
|
|
#else
|
2003-06-03 11:39:02 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
# define PRINT printf
|
|
|
|
# define GET getchar
|
2003-06-03 11:39:02 +00:00
|
|
|
|
2003-02-16 14:43:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
# ifndef USE_STDIO
|
|
|
|
/* 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
|
2003-02-16 14:43:00 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
/* 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) {
|
2003-02-16 14:43:00 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
# ifndef USE_STDIO
|
|
|
|
if (r == height) {
|
|
|
|
clrscr();
|
|
|
|
t = 0;
|
|
|
|
PUT(c); /* echo char. again because screen was erased */
|
|
|
|
r = 1;
|
|
|
|
}
|
|
|
|
if (c == '\n')
|
|
|
|
++r;
|
|
|
|
# endif
|
2003-02-16 14:43:00 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
PRINT("=$%02x ", c);
|
|
|
|
if (c == QUIT)
|
|
|
|
break;
|
|
|
|
if (++t == width) {
|
|
|
|
PRINT("\r\n");
|
|
|
|
++r;
|
|
|
|
t = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PRINT("\r\n");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|