Debian Codegraph @

src/encoding.c

raw symbols SCIP
1 // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
2 // Copyright (C) 1998-2024 Marco Baye
3 // Have a look at "acme.c" for further info
4 //
5 // Character encoding stuff
6 #include "encoding.h"
7
8
9 // struct definition
10 struct encoder {
11 unsigned char (*fn)(unsigned char);
12 // maybe add table pointer?
13 };
14
15
16 // variables
17 static unsigned char outermost_table[256]; // space for encoding table...
18 const struct encoder *encoder_current; // gets set before each pass
19 unsigned char *encoding_loaded_table = outermost_table; // ...loaded from file
20
21
22 // encoder functions:
23
24
25 // convert raw to raw (do not convert at all)
26 static unsigned char encoderfn_raw(unsigned char byte)
27 {
28 return byte;
29 }
30 // convert raw to petscii
31 static unsigned char encoderfn_pet(unsigned char byte)
32 {
33 if ((byte >= (unsigned char) 'A') && (byte <= (unsigned char) 'Z'))
34 return byte | 0x80;
35 if ((byte >= (unsigned char) 'a') && (byte <= (unsigned char) 'z'))
36 return byte - 32;
37 return byte;
38 }
39 // convert raw to C64 screencode
40 static unsigned char encoderfn_scr(unsigned char byte)
41 {
42 if ((byte >= (unsigned char) 'a') && (byte <= (unsigned char) 'z'))
43 return byte - 96; // shift uppercase down
44 if ((byte >= (unsigned char) '[') && (byte <= (unsigned char) '_'))
45 return byte - 64; // shift [\]^_ down
46 if (byte == '`')
47 return 64; // shift ` down
48 if (byte == '@')
49 return 0; // shift @ down
50 return byte;
51 }
52 // convert raw to whatever is defined in table
53 static unsigned char encoderfn_file(unsigned char byte)
54 {
55 return encoding_loaded_table[byte];
56 }
57
58
59 // predefined encoder structs:
60
61
62 const struct encoder encoder_raw = {
63 encoderfn_raw
64 };
65 const struct encoder encoder_pet = {
66 encoderfn_pet
67 };
68 const struct encoder encoder_scr = {
69 encoderfn_scr
70 };
71 const struct encoder encoder_file = {
72 encoderfn_file
73 };
74
75
76 // exported functions
77
78
79 // convert character using current encoding (exported for use by alu.c and pseudoopcodes.c)
80 unsigned char encoding_encode_char(unsigned char byte)
81 {
82 return encoder_current->fn(byte);
83 }
84
85 // set "raw" as default encoding
86 void encoding_passinit(void)
87 {
88 encoder_current = &encoder_raw;
89 }