annotate frbl/reconst/convert.c @ 319:f9482000b838

frbl/reconst/convert.c: almost perfect reconstruction
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 05 Mar 2020 04:48:55 +0000
parents
children 20feaf83c661
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
319
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include "main/sys_types.h"
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include "convert.h"
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 static SYS_UWORD8 *bss_0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 static SYS_UWORD32 bss_4;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 static SYS_UWORD16 bss_8;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 static SYS_UWORD8 bss_0xa;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 static SYS_UWORD32 bss_0xc;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 long
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 con_get_command_from_string(SYS_UWORD8 byte_to_analyze, SYS_UWORD8 *command)
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 long sp8 = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 switch (bss_4) {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 case 0:
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 /* 0x10 */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (byte_to_analyze == 0xAA) {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 /* 0x18 */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 bss_0xc = (bss_0xc + 1) & 1;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 } else {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 /* 0x26 */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (bss_0xc == 0)
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return (sp8);
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 bss_0 = command + 1;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 bss_0xa = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 bss_8 = byte_to_analyze;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 bss_0xc = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 bss_4 = 1;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return (sp8);
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 case 1:
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 /* 0x52 */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (byte_to_analyze == 0xAA) {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 /* 0x5a */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (bss_0xc) {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 /* 0x62 */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 *bss_0++ = byte_to_analyze;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 bss_0xa++;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 bss_0xc = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 } else {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 /* 0x7a */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 bss_0xc = 1;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 } else {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 /* 0x82 */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (bss_0xc) {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 /* 0x8a */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 bss_0 = command + 1;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 bss_0xa = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 bss_8 = byte_to_analyze + 1;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 bss_0xc = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 } else {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 /* 0xa6 */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 *bss_0++ = byte_to_analyze;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 bss_0xa++;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 /* 0xbc */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 bss_8--;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (bss_8)
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return (sp8);
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 *command = bss_0xa;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 sp8 = 1;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 bss_4 = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 bss_0xc = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 /* FLUID hack */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (command[0] == 0x01 && command[1] == 0xDD)
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 fluid_bootloader();
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 /* end FLUID hack */
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 return (sp8);
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return (sp8);
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 void
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 con_build_string_from_command(SYS_UWORD8 *command, SYS_UWORD8 *string,
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 SYS_UWORD16 *string_length)
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 SYS_UWORD16 sp12;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 SYS_UWORD8 *sp16;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 SYS_UWORD8 *sp20;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 sp16 = string + 1;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 sp20 = command++;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 *string = 0xAA;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 string += 2;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 *string_length = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 for (sp12 = 0; sp12 < *sp20; sp12++) {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (*command == 0xAA) {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 *string++ = 0xAA;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 *string_length += 1;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 *string++ = *command++;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 *string_length += 1;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 *sp16 = *string_length;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 *string_length += 2;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 void
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 con_initialize_conversion(void)
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 {
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 bss_4 = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 bss_0xc = 0;
f9482000b838 frbl/reconst/convert.c: almost perfect reconstruction
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 }