starting to add timing to vm driver
[dcpu16] / hw_spc2000.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <errno.h>
4
5 #include "dcpu16.h"
6 #include "hw_spc2000.h"
7
8 static dcpu16_hw_signal_t spc2000_reset_;
9 static dcpu16_hw_signal_t spc2000_cycle_;
10 static dcpu16_hw_signal_t spc2000_hwi_;
11 static struct dcpu16_hw hw_ = {
12 .name_ = "SPC2000 - Suspension Chamber 2000",
13 .id_l = 0x1d9d,
14 .id_h = 0x40e4,
15 .ver = 0x005e,
16 .mfg_l = 0x8b36,
17 .mfg_h = 0x1c6c,
18 .hwi = spc2000_hwi_,
19 .cycle = spc2000_cycle_,
20 .reset = spc2000_reset_,
21 .data = (struct spc2000_ *)NULL
22 };
23
24 struct spc2000_ {
25 DCPU16_WORD skip_unit;
26 long long skip;
27 };
28
29 static
30 void spc2000_reset_(struct dcpu16 *vm, void *data) {
31 struct spc2000_ *spc2000 = (struct spc2000_ *)data;
32
33 (void)vm;
34
35 memset(spc2000, 0, sizeof *spc2000);
36 }
37
38 static
39 void spc2000_cycle_(struct dcpu16 *vm, void *data) {
40 struct spc2000_ *spc2000 = (struct spc2000_ *)data;
41
42 (void)vm;
43 (void)spc2000;
44 }
45
46 static
47 void spc2000_hwi_(struct dcpu16 *vm, void *data) {
48 struct spc2000_ *spc2000 = (struct spc2000_ *)data;
49 DCPU16_WORD reg_a = vm->reg[DCPU16_REG_A],
50 reg_b = vm->reg[DCPU16_REG_B];
51 long long x;
52
53 switch (reg_a) {
54 case 0: /* GET_STATUS */
55 case 2: /* TRIGGER_DEVICE */
56 /* check status */
57 vm->reg[DCPU16_REG_C] = 0;
58 vm->reg[DCPU16_REG_B] = 0;
59 if (reg_a == 0
60 || vm->reg[DCPU16_REG_C] != 0)
61 break;
62 /* trigger */
63 vm->warn_cb_("spc2000 triggered\n");
64 break;
65
66 case 1: /* SET_UNIT_TO_SKIP */
67 spc2000->skip = vm->ram[reg_b];
68 x = vm->ram[reg_b + 1];
69 spc2000->skip |= x << 16;
70 x = vm->ram[reg_b + 2];
71 spc2000->skip |= x << 32;
72 x = vm->ram[reg_b + 3];
73 spc2000->skip |= x << 48;
74 break;
75
76 case 3: /* SET_SKIP_UNIT */
77 spc2000->skip_unit = reg_b;
78 break;
79 }
80 }