12 DCPU16_WORD interrupt_message
;
16 void clock_reset_(struct dcpu16
*vm
, struct dcpu16_hw
*hw
) {
17 struct clock_
*clock
= (struct clock_
*)hw
->data
;
21 memset(clock
, 0, sizeof *clock
);
25 void clock_cycle_(struct dcpu16
*vm
, struct dcpu16_hw
*hw
) {
26 struct clock_
*clock
= (struct clock_
*)hw
->data
;
28 /* cycle is only called 100000 times per second */
29 /* maximum rate is 60hz / word_max = 3932160 */
35 if (clock
->cycle_
>= clock
->rate
) {
36 /* THIS CHECK IS WRONG, JUST A PLACEHOLDER */
40 if (clock
->interrupt_message
) {
41 if (dcpu16_interrupt(vm
, clock
->interrupt_message
))
42 vm
->msg_cb_(DCPU16_MSG_ERROR
, "%s: could not send interrupt", hw
->mod
->name_
);
48 void clock_hwi_(struct dcpu16
*vm
, struct dcpu16_hw
*hw
) {
49 struct clock_
*clock
= (struct clock_
*)hw
->data
;
50 DCPU16_WORD reg_a
= vm
->reg
[DCPU16_REG_A
];
51 DCPU16_WORD reg_b
= vm
->reg
[DCPU16_REG_B
];
54 case 0: /* set tick gather rate, 60hz/B */
58 case 1: /* fetch elapsed count since rate was set */
59 vm
->reg
[DCPU16_REG_C
] = clock
->tick
;
63 clock
->interrupt_message
= reg_b
;
69 int clock_data_init_(struct dcpu16_hw
*hw
, void *data
) {
72 hw
->data
= calloc(1, sizeof(struct clock_
));
73 if (hw
->data
== NULL
) {
74 hw
->vm
->msg_cb_(DCPU16_MSG_ERROR
, "%s():%s", "calloc", strerror(errno
));
81 void clock_data_free_(struct dcpu16_hw
*hw
) {
91 struct dcpu16_hw_module dcpu16_hw_module_clock
= {
92 .name_
= "Generic Clock (compatible)",
100 .cycle
= clock_cycle_
,
101 .reset
= clock_reset_
,
103 .data_init
= clock_data_init_
,
104 .data_free
= clock_data_free_
,