annotate lunalcd/common.c @ 99:2e35070d289f

fc-simtool: savebin command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 25 Jan 2021 00:14:19 +0000
parents cdf2c99e5025
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
65
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <stdio.h>
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdlib.h>
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <string.h>
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <strings.h>
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 static enum {
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 MODE_L8,
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 MODE_U8,
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 MODE_16,
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 MODE_USB
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 } mode;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 set_output_mode(kw)
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char *kw;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 if (!strcmp(kw, "l8"))
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 mode = MODE_L8;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 else if (!strcmp(kw, "u8"))
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 mode = MODE_U8;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 else if (!strcmp(kw, "16"))
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 mode = MODE_16;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 else if (!strcmp(kw, "usb"))
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 mode = MODE_USB;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 else {
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 fprintf(stderr, "error: mode \"%s\" not understood\n", kw);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(1);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 write_ir(val16)
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 unsigned val16;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (mode != MODE_USB)
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 printf("w16 fffe4802 200\n");
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 switch (mode) {
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 case MODE_L8:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 printf("w16 02000000 %02x\n", val16 >> 8);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 printf("w16 02000000 %02x\n", val16 & 0xFF);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 break;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 case MODE_U8:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 printf("w16 02000000 %02x00\n", val16 >> 8);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 printf("w16 02000000 %02x00\n", val16 & 0xFF);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 break;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 case MODE_16:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 printf("w16 02000000 %04x\n", val16);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 break;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 case MODE_USB:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 printf("wi %04x\n", val16);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 write_dr(val16)
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 unsigned val16;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 {
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (mode != MODE_USB)
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 printf("w16 fffe4802 600\n");
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 switch (mode) {
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 case MODE_L8:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 printf("w16 02000002 %02x\n", val16 >> 8);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 printf("w16 02000002 %02x\n", val16 & 0xFF);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 break;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 case MODE_U8:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 printf("w16 02000002 %02x00\n", val16 >> 8);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 printf("w16 02000002 %02x00\n", val16 & 0xFF);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 break;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 case MODE_16:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 printf("w16 02000002 %04x\n", val16);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 break;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 case MODE_USB:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 printf("wd %04x\n", val16);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 bulk_wd_prep()
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 {
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (mode != MODE_USB)
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 printf("w16 fffe4802 600\n");
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 bulk_wd(val16)
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 unsigned val16;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 {
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 switch (mode) {
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 case MODE_L8:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 printf("w16 02000002 %02x\n", val16 >> 8);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 printf("w16 02000002 %02x\n", val16 & 0xFF);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 break;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 case MODE_U8:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 printf("w16 02000002 %02x00\n", val16 >> 8);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 printf("w16 02000002 %02x00\n", val16 & 0xFF);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 break;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 case MODE_16:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 printf("w16 02000002 %04x\n", val16);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 break;
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 case MODE_USB:
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 printf("wd %04x\n", val16);
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
cdf2c99e5025 lunalcd project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }