view lunalcd/common.c @ 162:72eac15f0917

fc-simtool and fc-uicc-tool moved once again to fc-sim-tools
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 17:36:43 +0000
parents cdf2c99e5025
children
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

static enum {
	MODE_L8,
	MODE_U8,
	MODE_16,
	MODE_USB
} mode;

set_output_mode(kw)
	char *kw;
{
	if (!strcmp(kw, "l8"))
		mode = MODE_L8;
	else if (!strcmp(kw, "u8"))
		mode = MODE_U8;
	else if (!strcmp(kw, "16"))
		mode = MODE_16;
	else if (!strcmp(kw, "usb"))
		mode = MODE_USB;
	else {
		fprintf(stderr, "error: mode \"%s\" not understood\n", kw);
		exit(1);
	}
}

write_ir(val16)
	unsigned val16;
{
	if (mode != MODE_USB)
		printf("w16 fffe4802 200\n");
	switch (mode) {
	case MODE_L8:
		printf("w16 02000000 %02x\n", val16 >> 8);
		printf("w16 02000000 %02x\n", val16 & 0xFF);
		break;
	case MODE_U8:
		printf("w16 02000000 %02x00\n", val16 >> 8);
		printf("w16 02000000 %02x00\n", val16 & 0xFF);
		break;
	case MODE_16:
		printf("w16 02000000 %04x\n", val16);
		break;
	case MODE_USB:
		printf("wi %04x\n", val16);
	}
}

write_dr(val16)
	unsigned val16;
{
	if (mode != MODE_USB)
		printf("w16 fffe4802 600\n");
	switch (mode) {
	case MODE_L8:
		printf("w16 02000002 %02x\n", val16 >> 8);
		printf("w16 02000002 %02x\n", val16 & 0xFF);
		break;
	case MODE_U8:
		printf("w16 02000002 %02x00\n", val16 >> 8);
		printf("w16 02000002 %02x00\n", val16 & 0xFF);
		break;
	case MODE_16:
		printf("w16 02000002 %04x\n", val16);
		break;
	case MODE_USB:
		printf("wd %04x\n", val16);
	}
}

bulk_wd_prep()
{
	if (mode != MODE_USB)
		printf("w16 fffe4802 600\n");
}

bulk_wd(val16)
	unsigned val16;
{
	switch (mode) {
	case MODE_L8:
		printf("w16 02000002 %02x\n", val16 >> 8);
		printf("w16 02000002 %02x\n", val16 & 0xFF);
		break;
	case MODE_U8:
		printf("w16 02000002 %02x00\n", val16 >> 8);
		printf("w16 02000002 %02x00\n", val16 & 0xFF);
		break;
	case MODE_16:
		printf("w16 02000002 %04x\n", val16);
		break;
	case MODE_USB:
		printf("wd %04x\n", val16);
	}
}