projects
/
dcpu16
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
typo, missing semicolon
[dcpu16]
/
hw_clock.c
diff --git
a/hw_clock.c
b/hw_clock.c
index 89d5912e0092132739f6d74a2fe3686a440f1f70..a6c87b11b08bac58cfe0a7c0f23349c2512279ae 100644
(file)
--- a/
hw_clock.c
+++ b/
hw_clock.c
@@
-5,22
+5,6
@@
#include "dcpu16.h"
#include "hw_clock.h"
#include "dcpu16.h"
#include "hw_clock.h"
-static dcpu16_hw_signal_t clock_reset_;
-static dcpu16_hw_signal_t clock_cycle_;
-static dcpu16_hw_signal_t clock_hwi_;
-static struct dcpu16_hw hw_ = {
- .name_ = "Generic Clock (compatible)",
- .id_l = 0xb402,
- .id_h = 0x12d0,
- .ver = 0x0001,
- .mfg_l = 0x0000,
- .mfg_h = 0x0000,
- .hwi = clock_hwi_,
- .cycle = clock_cycle_,
- .reset = clock_reset_,
- .data = (struct clock_ *)NULL
-};
-
struct clock_ {
DCPU16_WORD cycle_;
DCPU16_WORD rate;
struct clock_ {
DCPU16_WORD cycle_;
DCPU16_WORD rate;
@@
-29,8
+13,8
@@
struct clock_ {
};
static
};
static
-void clock_reset_(struct dcpu16 *vm,
void *data
) {
- struct clock_ *clock = (struct clock_ *)data;
+void clock_reset_(struct dcpu16 *vm,
struct dcpu16_hw *hw
) {
+ struct clock_ *clock = (struct clock_ *)
hw->
data;
(void)vm;
(void)vm;
@@
-38,8
+22,8
@@
void clock_reset_(struct dcpu16 *vm, void *data) {
}
static
}
static
-void clock_cycle_(struct dcpu16 *vm,
void *data
) {
- struct clock_ *clock = (struct clock_ *)data;
+void clock_cycle_(struct dcpu16 *vm,
struct dcpu16_hw *hw
) {
+ struct clock_ *clock = (struct clock_ *)
hw->
data;
/* cycle is only called 100000 times per second */
/* maximum rate is 60hz / word_max = 3932160 */
/* cycle is only called 100000 times per second */
/* maximum rate is 60hz / word_max = 3932160 */
@@
-55,14
+39,14
@@
void clock_cycle_(struct dcpu16 *vm, void *data) {
if (clock->interrupt_message) {
if (dcpu16_interrupt(vm, clock->interrupt_message))
if (clock->interrupt_message) {
if (dcpu16_interrupt(vm, clock->interrupt_message))
- vm->warn_cb_("%s: could not send interrupt", hw
_.
name_);
+ vm->warn_cb_("%s: could not send interrupt", hw
->mod->
name_);
}
}
}
static
}
}
}
static
-void clock_hwi_(struct dcpu16 *vm,
void *data
) {
- struct clock_ *clock = (struct clock_ *)data;
+void clock_hwi_(struct dcpu16 *vm,
struct dcpu16_hw *hw
) {
+ struct clock_ *clock = (struct clock_ *)
hw->
data;
DCPU16_WORD reg_a = vm->reg[DCPU16_REG_A];
DCPU16_WORD reg_b = vm->reg[DCPU16_REG_B];
DCPU16_WORD reg_a = vm->reg[DCPU16_REG_A];
DCPU16_WORD reg_b = vm->reg[DCPU16_REG_B];
@@
-81,32
+65,43
@@
void clock_hwi_(struct dcpu16 *vm, void *data) {
}
}
}
}
-/* instantitate a new clock */
-
struct dcpu16_hw *clock_new(struct dcpu16 *vm
) {
-
struct dcpu16_hw *hw
;
+static
+
int clock_data_init_(struct dcpu16_hw *hw, void *data
) {
+
(void)data
;
- hw = calloc(1, sizeof *hw);
- if (hw == NULL) {
- vm->warn_cb_("%s():%s", "calloc", strerror(errno));
- return NULL;
- }
- memcpy(hw, &hw_, sizeof *hw);
- hw->data = calloc(1, sizeof hw->data);
+ hw->data = calloc(1, sizeof(struct clock_));
if (hw->data == NULL) {
if (hw->data == NULL) {
- vm->warn_cb_("%s():%s", "calloc", strerror(errno));
- free(hw);
- return NULL;
+ hw->vm->warn_cb_("%s():%s", "calloc", strerror(errno));
+ return -1;
}
}
-
- return hw;
+ return 0;
}
}
-void clock_del(struct dcpu16_hw **hw) {
+static
+void clock_data_free_(struct dcpu16_hw *hw) {
if (hw) {
if (hw) {
- free((*hw)->data);
- (*hw)->data = NULL;
-
- free((*hw));
- *hw = NULL;
+ if (hw->data) {
+ free(hw->data);
+ hw->data = NULL;
+ }
}
}
}
}
+
+
+struct dcpu16_hw_module dcpu16_hw_module_clock = {
+ .name_ = "Generic Clock (compatible)",
+
+ .id_l = 0xb402,
+ .id_h = 0x12d0,
+ .ver = 0x0001,
+ .mfg_l = 0x0000,
+ .mfg_h = 0x0000,
+ .hwi = clock_hwi_,
+ .cycle = clock_cycle_,
+ .reset = clock_reset_,
+
+ .data_init = clock_data_init_,
+ .data_free = clock_data_free_,
+ .ctl = NULL,
+ .ctl_cmd = NULL,
+};