FreeCalypso > hg > freecalypso-reveng
changeset 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 | 4e1d7ce0ee71 |
children | 20feaf83c661 |
files | frbl/reconst/Makefile frbl/reconst/convert.c |
diffstat | 2 files changed, 109 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/frbl/reconst/Makefile Thu Mar 05 00:27:22 2020 +0000 +++ b/frbl/reconst/Makefile Thu Mar 05 04:48:55 2020 +0000 @@ -1,8 +1,9 @@ CFLAGS= -mn -mt -mw -me -pw2 CPPFLAGS=-DTOOL_CHOICE=0 -D_TMS470 -I. -Iinc -OBJS= boot.disasm +OBJS= boot.obj convert.obj +DISASM= boot.disasm convert.disasm -all: ${OBJS} +all: ${OBJS} ${DISASM} %.obj: %.c ./cl470 -q -c ${CFLAGS} ${CPPFLAGS} $<
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frbl/reconst/convert.c Thu Mar 05 04:48:55 2020 +0000 @@ -0,0 +1,106 @@ +#include "main/sys_types.h" +#include "convert.h" + +static SYS_UWORD8 *bss_0; +static SYS_UWORD32 bss_4; +static SYS_UWORD16 bss_8; +static SYS_UWORD8 bss_0xa; +static SYS_UWORD32 bss_0xc; + +long +con_get_command_from_string(SYS_UWORD8 byte_to_analyze, SYS_UWORD8 *command) +{ + long sp8 = 0; + + switch (bss_4) { + case 0: + /* 0x10 */ + if (byte_to_analyze == 0xAA) { + /* 0x18 */ + bss_0xc = (bss_0xc + 1) & 1; + } else { + /* 0x26 */ + if (bss_0xc == 0) + return (sp8); + bss_0 = command + 1; + bss_0xa = 0; + bss_8 = byte_to_analyze; + bss_0xc = 0; + bss_4 = 1; + } + return (sp8); + case 1: + /* 0x52 */ + if (byte_to_analyze == 0xAA) { + /* 0x5a */ + if (bss_0xc) { + /* 0x62 */ + *bss_0++ = byte_to_analyze; + bss_0xa++; + bss_0xc = 0; + } else { + /* 0x7a */ + bss_0xc = 1; + } + } else { + /* 0x82 */ + if (bss_0xc) { + /* 0x8a */ + bss_0 = command + 1; + bss_0xa = 0; + bss_8 = byte_to_analyze + 1; + bss_0xc = 0; + } else { + /* 0xa6 */ + *bss_0++ = byte_to_analyze; + bss_0xa++; + } + } + /* 0xbc */ + bss_8--; + if (bss_8) + return (sp8); + *command = bss_0xa; + sp8 = 1; + bss_4 = 0; + bss_0xc = 0; + /* FLUID hack */ + if (command[0] == 0x01 && command[1] == 0xDD) + fluid_bootloader(); + /* end FLUID hack */ + return (sp8); + } + return (sp8); +} + +void +con_build_string_from_command(SYS_UWORD8 *command, SYS_UWORD8 *string, + SYS_UWORD16 *string_length) +{ + SYS_UWORD16 sp12; + SYS_UWORD8 *sp16; + SYS_UWORD8 *sp20; + + sp16 = string + 1; + sp20 = command++; + *string = 0xAA; + string += 2; + *string_length = 0; + for (sp12 = 0; sp12 < *sp20; sp12++) { + if (*command == 0xAA) { + *string++ = 0xAA; + *string_length += 1; + } + *string++ = *command++; + *string_length += 1; + } + *sp16 = *string_length; + *string_length += 2; +} + +void +con_initialize_conversion(void) +{ + bss_4 = 0; + bss_0xc = 0; +}