Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Generates ASCII art text for printing on punched paper tape
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <stdio.h>
- using namespace std;
- ifstream infile;
- string buffer;
- int size;
- char c;
- int lookup(char c)
- {
- switch (c)
- {
- case 'a':
- buffer = "\x60\x94\x94\x94\xf8";
- size = 5;
- break;
- case 'b':
- buffer = "\xff\x88\x88\x88\x70";
- size = 5;
- break;
- case 'c':
- buffer = "\x70\x88\x88\x88\x90";
- size = 5;
- break;
- case 'd':
- buffer = "\x70\x88\x88\x88\xff";
- size = 5;
- break;
- case 'e':
- buffer = "\x78\x94\x94\x94\x98";
- size = 5;
- break;
- case 'f':
- buffer = "\x10\xfe\x11";
- size = 3;
- break;
- case 'g':
- buffer = "\x98\xa4\xa4\x78";
- size = 4;
- break;
- case 'h':
- buffer = "\xff\x08\x08\x08\xf0";
- size = 5;
- break;
- case 'i':
- buffer = "\x88\xfa\x80";
- size = 3;
- break;
- case 'j':
- buffer = "\x40\x80\x84\x7d";
- size = 4;
- break;
- case 'k':
- buffer = "\xff\x20\x50\x88";
- size = 4;
- break;
- case 'l':
- buffer = "\x81\xff\x80";
- size = 3;
- break;
- case 'm':
- buffer = "\xf8\x08\xf8\x08\xf0";
- size = 5;
- break;
- case 'n':
- buffer = "\xf8\x08\x08\x08\xf0";
- size = 5;
- break;
- case 'o':
- buffer = "\x70\x88\x88\x88\x70";
- size = 5;
- break;
- case 'p':
- buffer = "\xf8\x24\x24\x18";
- size = 4;
- break;
- case 'q':
- buffer = "\x18\x24\x24\xf8";
- size = 4;
- break;
- case 'r':
- buffer = "\x08\xf0\x08\x10";
- size = 4;
- break;
- case 's':
- buffer = "\x90\xa8\xa8\xa8\x48";
- size = 5;
- break;
- case 't':
- buffer = "\x08\x7e\x88\x48";
- size = 4;
- break;
- case 'u':
- buffer = "\x78\x80\x80\x80\xf8";
- size = 5;
- break;
- case 'v':
- buffer = "\x18\x60\x80\x60\x18";
- size = 5;
- break;
- case 'w':
- buffer = "\x78\x80\x78\x80\x78";
- size = 5;
- break;
- case 'x':
- buffer = "\x88\x50\x20\x50\x88";
- size = 5;
- break;
- case 'y':
- buffer = "\x98\xa0\xa0\x78";
- size = 4;
- break;
- case 'z':
- buffer = "\x88\xc8\xa8\x98\x88";
- size = 5;
- break;
- case 'A':
- buffer = "\xfe\x09\x09\x09\xfe";
- size = 5;
- break;
- case 'B':
- buffer = "\xff\x89\x89\x89\x76";
- size = 5;
- break;
- case 'C':
- buffer = "\x73\x81\x81\x81";
- size = 4;
- break;
- case 'D':
- buffer = "\xff\x81\x81\x42\x3c";
- size = 5;
- break;
- case 'E':
- buffer = "\xff\x89\x89\x89\x81";
- size = 5;
- break;
- case 'F':
- buffer = "\xff\x09\x09\x09\x01";
- size = 5;
- break;
- case 'G':
- buffer = "\x7e\x81\x81\x89\x7a";
- size = 5;
- break;
- case 'H':
- buffer = "\xff\x08\x08\x08\xff";
- size = 5;
- break;
- case 'I':
- buffer = "\x81\xff\x81";
- size = 3;
- break;
- case 'J':
- buffer = "\x60\x80\x80\x7f";
- size = 4;
- break;
- case 'K':
- buffer = "\xff\x08\x14\xe3";
- size = 4;
- break;
- case 'L':
- buffer = "\xff\x80\x80\x80";
- size = 4;
- break;
- case 'M':
- buffer = "\xff\x02\x04\x18\x04\x02\xff";
- size = 7;
- break;
- case 'N':
- buffer = "\xff\x06\x18\x60\xff";
- size = 5;
- break;
- case 'O':
- buffer = "\x7e\x81\x81\x81\x7e";
- size = 5;
- break;
- case 'P':
- buffer = "\xff\x09\x09\x09\x06";
- size = 5;
- break;
- case 'Q':
- buffer = "\x3e\x41\x61\x41\xbe";
- size = 5;
- break;
- case 'R':
- buffer = "\xff\x09\x19\x29\xc6";
- size = 5;
- break;
- case 'S':
- buffer = "\x46\x89\x89\x89\x72";
- size = 5;
- break;
- case 'T':
- buffer = "\x01\x01\xff\x01\x01";
- size = 5;
- break;
- case 'U':
- buffer = "\x3f\x80\x80\x80\x3f";
- size = 5;
- break;
- case 'V':
- buffer = "\x3f\x40\x80\x40\x3f";
- size = 5;
- break;
- case 'W':
- buffer = "\x7f\x80\x70\x80\x7f";
- size = 5;
- break;
- case 'X':
- buffer = "\xe3\x14\x08\x14\xe3";
- size = 5;
- break;
- case 'Y':
- buffer = "\x07\x08\xf0\x08\x07";
- size = 5;
- break;
- case 'Z':
- buffer = "\xc1\xa1\x91\x89\x87";
- size = 5;
- break;
- case '0':
- buffer = "\x7e\xa1\x99\x85\x7e";
- size = 5;
- break;
- case '1':
- buffer = "\x81\xff\x80";
- size = 3;
- break;
- case '2':
- buffer = "\xc2\xa1\x91\x91\x8e";
- size = 5;
- break;
- case '3':
- buffer = "\x42\x81\x91\x91\x6e";
- size = 5;
- break;
- case '4':
- buffer = "\x1f\x10\x10\xff\x10";
- size = 5;
- break;
- case '(':
- buffer = "\x3c\x42\x81";
- size = 3;
- break;
- case ')':
- buffer = "\x81\x42\x3c";
- size = 3;
- break;
- case '!':
- buffer = "\xbf";
- size = 1;
- break;
- case '?':
- buffer = "\x02\x01\xb1\x09\x06";
- size = 5;
- break;
- case '$':
- buffer = "\x44\x4a\xff\x4a\x32";
- size = 5;
- break;
- case '#':
- buffer = "\x24\xff\x24\xff\x24";
- size = 5;
- break;
- case '*':
- buffer = "\x08\x2a\x1c\x2a\x08";
- size = 5;
- break;
- case '.':
- buffer = "\xc0\xc0";
- size = 2;
- break;
- case '&':
- buffer = "\x76\x89\x96\x60\x90";
- size = 5;
- break;
- case '\"':
- buffer = "\x07\x00\x07";
- size = 3;
- break;
- case '\'':
- buffer = "\x07";
- size = 1;
- break;
- case ',':
- buffer = "\xb0\x80";
- size = 2;
- break;
- case '/':
- buffer = "\xc0\x30\x0c\x03";
- size = 4;
- break;
- case '\\':
- buffer = "\x03\x0c\x30\xc0";
- size = 4;
- break;
- case ':':
- buffer = "\xc3\xc3";
- size = 2;
- break;
- case ';':
- buffer = "\xcb\xc7";
- size = 2;
- break;
- case '[':
- buffer = "\xff\x81\x81";
- size = 3;
- break;
- case ']':
- buffer = "\x81\x81\xff";
- size = 3;
- break;
- case '%':
- buffer = "\x46\x26\x10\xc8\xc4";
- size = 5;
- break;
- case '^':
- buffer = "\x04\x02\x01\x02\x04";
- size = 5;
- break;
- case '_':
- buffer = "\x80\x80\x80\x80\x80";
- size = 5;
- break;
- case '=':
- buffer = "\x28\x28\x28";
- size = 3;
- break;
- case '+':
- buffer = "\x10\x38\x10";
- size = 3;
- break;
- case '-':
- buffer = "\x10\x10\x10";
- size = 3;
- break;
- case '{':
- buffer = "\x08\x76\x81\x81";
- size = 4;
- break;
- case '}':
- buffer = "\x81\x81\x76\x08";
- size = 4;
- break;
- case '<':
- buffer = "\x20\x50\x88";
- size = 3;
- break;
- case '>':
- buffer = "\x88\x50\x20";
- size = 3;
- break;
- case '@':
- buffer = "\x7e\x81\x99\xa5\xbe\x80";
- size = 6;
- break;
- case '|':
- buffer = "\xf7";
- size = 1;
- break;
- case '\n':
- case ' ':
- buffer = "\x00\x00\x00\x00\x00";
- size = 5;
- break;
- default:
- return -1;
- }
- return 0;
- }
- int main(int argc, char** argv)
- {
- if (argc > 1)
- {
- infile.open(argv[1]);
- if (!infile.is_open())
- {
- cerr << "Error opening file" << endl;
- return -1;
- }
- else
- {
- while (infile.good())
- {
- c = infile.get();
- if (c >= 0 && c <= 255)
- {
- int error = lookup(c);
- char hexchar[32];
- if (error < 0)
- {
- cerr << "Character not defined: ";
- sprintf(hexchar, "0x%X\n",c);
- cerr << hexchar;
- }
- else
- {
- buffer += "\0";
- size++;
- cout.write(buffer.data(), size);
- //cerr << size << endl;
- }
- }
- }
- // buffer = "\0";
- // cout << buffer;
- infile.close();
- }
- return 0;
- }
- else
- {
- cerr << "Too few arguments" << endl;
- return -1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement