X-Git-Url: http://git.squeep.com/?p=dcpu16;a=blobdiff_plain;f=hw_spc2000.c;h=402a1d7949a2e150b768365cdc742a604d50e15a;hp=49ba35042c5ace4360c7eca649617c52b5cecb20;hb=57241bb9e6f6b1acb019efe4f32eb758cf9e93d7;hpb=9e40f875436d85767042714823f47fdf136ba9b0 diff --git a/hw_spc2000.c b/hw_spc2000.c index 49ba350..402a1d7 100644 --- a/hw_spc2000.c +++ b/hw_spc2000.c @@ -9,6 +9,7 @@ static dcpu16_hw_signal_t spc2000_reset_; static dcpu16_hw_signal_t spc2000_cycle_; static dcpu16_hw_signal_t spc2000_hwi_; static struct dcpu16_hw hw_ = { + .vm = NULL, .name_ = "SPC2000 - Suspension Chamber 2000", .id_l = 0x1d9d, .id_h = 0x40e4, @@ -21,11 +22,41 @@ static struct dcpu16_hw hw_ = { .data = (struct spc2000_ *)NULL }; +static dcpu16_hw_data_init_t spc2000_data_init_; +static dcpu16_hw_data_free_t spc2000_data_free_; +struct dcpu16_hw_module dcpu16_hw_module_spc2000 = { + .template = &hw_, + .data_init = spc2000_data_init_, + .data_free = spc2000_data_free_, +}; + struct spc2000_ { DCPU16_WORD skip_unit; long long skip; }; +static +int spc2000_data_init_(struct dcpu16_hw *hw, void *extra) { + (void)extra; + + hw->data = calloc(1, sizeof(struct spc2000_)); + if (hw->data == NULL) { + hw->vm->warn_cb_("%s():%s", "calloc", strerror(errno)); + return -1; + } + return 0; +} + +static +void spc2000_data_free_(struct dcpu16_hw *hw) { + if (hw) { + if (hw->data) { + free(hw->data); + hw->data = NULL; + } + } +} + static void spc2000_reset_(struct dcpu16 *vm, void *data) { struct spc2000_ *spc2000 = (struct spc2000_ *)data;