comparison 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
comparison
equal deleted inserted replaced
318:4e1d7ce0ee71 319:f9482000b838
1 #include "main/sys_types.h"
2 #include "convert.h"
3
4 static SYS_UWORD8 *bss_0;
5 static SYS_UWORD32 bss_4;
6 static SYS_UWORD16 bss_8;
7 static SYS_UWORD8 bss_0xa;
8 static SYS_UWORD32 bss_0xc;
9
10 long
11 con_get_command_from_string(SYS_UWORD8 byte_to_analyze, SYS_UWORD8 *command)
12 {
13 long sp8 = 0;
14
15 switch (bss_4) {
16 case 0:
17 /* 0x10 */
18 if (byte_to_analyze == 0xAA) {
19 /* 0x18 */
20 bss_0xc = (bss_0xc + 1) & 1;
21 } else {
22 /* 0x26 */
23 if (bss_0xc == 0)
24 return (sp8);
25 bss_0 = command + 1;
26 bss_0xa = 0;
27 bss_8 = byte_to_analyze;
28 bss_0xc = 0;
29 bss_4 = 1;
30 }
31 return (sp8);
32 case 1:
33 /* 0x52 */
34 if (byte_to_analyze == 0xAA) {
35 /* 0x5a */
36 if (bss_0xc) {
37 /* 0x62 */
38 *bss_0++ = byte_to_analyze;
39 bss_0xa++;
40 bss_0xc = 0;
41 } else {
42 /* 0x7a */
43 bss_0xc = 1;
44 }
45 } else {
46 /* 0x82 */
47 if (bss_0xc) {
48 /* 0x8a */
49 bss_0 = command + 1;
50 bss_0xa = 0;
51 bss_8 = byte_to_analyze + 1;
52 bss_0xc = 0;
53 } else {
54 /* 0xa6 */
55 *bss_0++ = byte_to_analyze;
56 bss_0xa++;
57 }
58 }
59 /* 0xbc */
60 bss_8--;
61 if (bss_8)
62 return (sp8);
63 *command = bss_0xa;
64 sp8 = 1;
65 bss_4 = 0;
66 bss_0xc = 0;
67 /* FLUID hack */
68 if (command[0] == 0x01 && command[1] == 0xDD)
69 fluid_bootloader();
70 /* end FLUID hack */
71 return (sp8);
72 }
73 return (sp8);
74 }
75
76 void
77 con_build_string_from_command(SYS_UWORD8 *command, SYS_UWORD8 *string,
78 SYS_UWORD16 *string_length)
79 {
80 SYS_UWORD16 sp12;
81 SYS_UWORD8 *sp16;
82 SYS_UWORD8 *sp20;
83
84 sp16 = string + 1;
85 sp20 = command++;
86 *string = 0xAA;
87 string += 2;
88 *string_length = 0;
89 for (sp12 = 0; sp12 < *sp20; sp12++) {
90 if (*command == 0xAA) {
91 *string++ = 0xAA;
92 *string_length += 1;
93 }
94 *string++ = *command++;
95 *string_length += 1;
96 }
97 *sp16 = *string_length;
98 *string_length += 2;
99 }
100
101 void
102 con_initialize_conversion(void)
103 {
104 bss_4 = 0;
105 bss_0xc = 0;
106 }