view frbl/reconst/convert.c @ 379:a760a5eeed65

compal/audio/omr-guide: another avenue of investigation
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 10 Oct 2021 19:53:35 +0000
parents 6e442ed0f64d
children
line wrap: on
line source

#include "main/sys_types.h"
#include "convert.h"

static SYS_UWORD8 *bss_0;
static enum {NO_STRING, IN_STRING} 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 command_built = 0;

	switch (bss_4) {
	case NO_STRING:
		/* 0x10 */
		if (byte_to_analyze == 0xAA) {
			/* 0x18 */
			bss_0xc = (bss_0xc + 1) & 1;
		} else {
			/* 0x26 */
			if (bss_0xc == 0)
				break;
			bss_0 = command + 1;
			bss_0xa = 0;
			bss_8 = byte_to_analyze;
			bss_0xc = 0;
			bss_4 = IN_STRING;
		}
		break;
	case IN_STRING:
		/* 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)
			break;
		*command = bss_0xa;
		command_built = 1;
		bss_4 = NO_STRING;
		bss_0xc = 0;
		/* FLUID hack */
		if (command[0] == 0x01 && command[1] == 0xDD)
			fluid_bootloader();
		/* end FLUID hack */
	}
	return command_built;
}

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 = NO_STRING;
	bss_0xc = 0;
}