X-Git-Url: http://git.squeep.com/?p=dcpu16;a=blobdiff_plain;f=hw_spc2000.c;h=151b98cdd29d0eab82072cf7b9613a9e64fbbcf8;hp=2fa0c7b3ff8702734681adec556ad7316aed099b;hb=HEAD;hpb=19bb0a4e64c9ab3e62ff4bbd959289704ee5b8f1 diff --git a/hw_spc2000.c b/hw_spc2000.c index 2fa0c7b..151b98c 100644 --- a/hw_spc2000.c +++ b/hw_spc2000.c @@ -5,21 +5,14 @@ #include "dcpu16.h" #include "hw_spc2000.h" -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_ = { - .name_ = "SPC2000 - Suspension Chamber 2000", - .id_l = 0x1d9d, - .id_h = 0x40e4, - .ver = 0x005e, - .mfg_l = 0x8b36, - .mfg_h = 0x1c6c, - .hwi = spc2000_hwi_, - .cycle = spc2000_cycle_, - .reset = spc2000_reset_, - .data = (struct spc2000_ *)NULL -}; +#define MSG_(__level__, __vm__, ...) do { ((__vm__) ? ((struct dcpu16 *)(__vm__))->msg_cb_ : dcpu16_msg_)(__level__, __VA_ARGS__); } while (0) +#define MSG_INFO(__vm__, ...) MSG_(DCPU16_MSG_INFO, __vm__, __VA_ARGS__) +#define MSG_ERROR(__vm__, ...) MSG_(DCPU16_MSG_ERROR, __vm__, __VA_ARGS__) +#ifdef DEBUG +#define MSG_DEBUG(__vm__, ...) MSG_(DCPU16_MSG_DEBUG, __vm__, __VA_ARGS__) +#else /* DEBUG */ +#define MSG_DEBUG(__vm__, ...) do { } while (0) +#endif /* DEBUG */ struct spc2000_ { DCPU16_WORD skip_unit; @@ -27,8 +20,30 @@ struct spc2000_ { }; static -void spc2000_reset_(struct dcpu16 *vm, void *data) { - struct spc2000_ *spc2000 = (struct spc2000_ *)data; +int spc2000_data_init_(struct dcpu16_hw *hw, void *data) { + (void)data; + + hw->data = calloc(1, sizeof(struct spc2000_)); + if (hw->data == NULL) { + MSG_ERROR(hw->vm, "%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, struct dcpu16_hw *hw) { + struct spc2000_ *spc2000 = (struct spc2000_ *)hw->data; (void)vm; @@ -36,16 +51,16 @@ void spc2000_reset_(struct dcpu16 *vm, void *data) { } static -void spc2000_cycle_(struct dcpu16 *vm, void *data) { - struct spc2000_ *spc2000 = (struct spc2000_ *)data; +void spc2000_cycle_(struct dcpu16 *vm, struct dcpu16_hw *hw) { + struct spc2000_ *spc2000 = (struct spc2000_ *)hw->data; (void)vm; (void)spc2000; } static -void spc2000_hwi_(struct dcpu16 *vm, void *data) { - struct spc2000_ *spc2000 = (struct spc2000_ *)data; +void spc2000_hwi_(struct dcpu16 *vm, struct dcpu16_hw *hw) { + struct spc2000_ *spc2000 = (struct spc2000_ *)hw->data; DCPU16_WORD reg_a = vm->reg[DCPU16_REG_A], reg_b = vm->reg[DCPU16_REG_B]; long long x; @@ -60,7 +75,7 @@ void spc2000_hwi_(struct dcpu16 *vm, void *data) { || vm->reg[DCPU16_REG_C] != 0) break; /* trigger */ - vm->warn_cb_("spc2000 triggered\n"); + MSG_INFO(vm, "spc2000 triggered\n"); break; case 1: /* SET_UNIT_TO_SKIP */ @@ -78,3 +93,21 @@ void spc2000_hwi_(struct dcpu16 *vm, void *data) { break; } } + +struct dcpu16_hw_module dcpu16_hw_module_spc2000 = { + .name_ = "SPC2000 - Suspension Chamber 2000", + + .id_l = 0x1d9d, + .id_h = 0x40e4, + .ver = 0x005e, + .mfg_l = 0x8b36, + .mfg_h = 0x1c6c, + .hwi = spc2000_hwi_, + .cycle = spc2000_cycle_, + .reset = spc2000_reset_, + + .data_init = spc2000_data_init_, + .data_free = spc2000_data_free_, + .ctl = NULL, + .ctl_cmd = NULL, +};