OpenCores
URL https://opencores.org/ocsvn/forth-cpu/forth-cpu/trunk

Subversion Repositories forth-cpu

[/] [forth-cpu/] [trunk/] [text.c] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 howe.r.j.8
#include <stdio.h>
2
#include <stdint.h>
3
#include <stdbool.h>
4
 
5
#define MAX_READ (3200)
6
#define DEFAULT_ATTRIBUTES (0x3800u)
7
 
8
static int printer(FILE *o, uint16_t n, bool binary_not_hex)
9
{
10
        n |= DEFAULT_ATTRIBUTES;
11
        if(binary_not_hex) {
12
                unsigned i;
13
                for(i = 15; i <= 15; i--)
14
                        fputc(n & (1 << i) ? '1' : '0', o);
15
                fputc('\n', o);
16
        } else {
17
                fprintf(o, "%04x\n", (unsigned)n);
18
        }
19
        return 0;
20
}
21
 
22
static void usage(const char *arg0)
23
{
24
        static const char *help = "\
25
Generate initial VGA screen text for the H2 CPU project.\n\
26
Options:\n\n\
27
\t-h print this help message and exit\n\
28
\t-g turn on generation mode - generate file full of spaces\n\n\
29
This program turns a byte stream into a text file containing\n\
30
a single 16-bit (doubling up the input data) ASCII file encoded\n\
31
'1' and '0' characters.\n\n";
32
        fprintf(stderr, "usage: %s -h -g\n", arg0);
33
        fprintf(stderr, "%s", help);
34
        fprintf(stderr, "%d characters are read in and converted.\n\n", MAX_READ);
35
}
36
 
37
int main(int argc, char **argv)
38
{
39
        size_t i;
40
        int ia, gen = 0;
41
        for(ia = 1; ia < argc && argv[ia][0] == '-'; ia++) {
42
                switch(argv[ia][1]) {
43
                case '\0': goto done; /* stop processing options */
44
                case 'h':  usage(argv[0]);
45
                           return -1;
46
                case 'g':  gen = 1; break;
47
                default:
48
                           fprintf(stderr, "unknown option '%s'\n", argv[ia]);
49
                           return -1;
50
                }
51
        }
52
done:
53
        if(argc != ia) {
54
                fprintf(stderr, "too many arguments supplied\n");
55
                return -1;
56
        }
57
        for(i = 0; i < MAX_READ; i++) {
58
                int c = gen ? ' ' : fgetc(stdin);
59
                if(c == EOF)
60
                        return 0;
61
                if(printer(stdout, c, false) < 0)
62
                        return -1;
63
        }
64
        return 0;
65
}
66
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.