src/mess/video/dl1416.c
| r1764 | r1765 | |
| 20 | 20 | * |
| 21 | 21 | * Changes: |
| 22 | 22 | * - 2007-07-30: Initial version. [Dirk Best] |
| 23 | * - 2008-02-25: Converted to the new device interface. [Dirk Best] |
| 23 | 24 | * |
| 24 | 25 | ****************************************************************************/ |
| 25 | 26 | |
| r1764 | r1765 | |
| 28 | 29 | Includes |
| 29 | 30 | *****************************************************************************/ |
| 30 | 31 | |
| 31 | | |
| 32 | 32 | #include "driver.h" |
| 33 | | #include "deprecat.h" |
| 34 | 33 | #include "dl1416.h" |
| 35 | 34 | |
| 36 | 35 | |
| 37 | 36 | |
| 38 | 37 | /***************************************************************************** |
| 39 | | Macros |
| 38 | Constants |
| 40 | 39 | *****************************************************************************/ |
| 41 | 40 | |
| 42 | | |
| 43 | | #define MAX_DL1416 (5) |
| 44 | | |
| 45 | 41 | #define SEG_UNDEF (-1) |
| 46 | 42 | #define SEG_BLANK (0) |
| 47 | 43 | #define SEG_CURSOR (0xffff) |
| r1764 | r1765 | |
| 52 | 48 | Type definitions |
| 53 | 49 | *****************************************************************************/ |
| 54 | 50 | |
| 55 | | /* DL1416 chip state */ |
| 56 | | typedef struct _dl1416_state dl1416_state; |
| 57 | | |
| 58 | | struct _dl1416_state |
| 51 | struct _dl1416_t |
| 59 | 52 | { |
| 60 | 53 | const dl1416_interface *intf; |
| 61 | 54 | |
| r1764 | r1765 | |
| 123 | 116 | }; |
| 124 | 117 | |
| 125 | 118 | |
| 126 | | static dl1416_state dl1416[MAX_DL1416]; |
| 127 | 119 | |
| 128 | | |
| 129 | | |
| 130 | 120 | /***************************************************************************** |
| 131 | | Implementation |
| 121 | Device interface |
| 132 | 122 | *****************************************************************************/ |
| 133 | 123 | |
| 134 | | /* Config */ |
| 135 | | void dl1416_config(int which, const dl1416_interface *intf) |
| 124 | static void *dl1416_start(running_machine *machine, const char *tag, |
| 125 | const void *static_config, const void *inline_config) |
| 136 | 126 | { |
| 137 | | assert_always(mame_get_phase(Machine) == MAME_PHASE_INIT, "Can only call dl1416_config at init time!"); |
| 138 | | assert_always(which < MAX_DL1416, "'which' exceeds maximum number of configured DL1416s!"); |
| 127 | dl1416_t *dl1416; |
| 128 | char unique_tag[30]; |
| 139 | 129 | |
| 140 | | dl1416[which].intf = intf; |
| 130 | /* validate arguments */ |
| 131 | assert(tag != NULL); |
| 132 | assert(strlen(tag) < 20); |
| 141 | 133 | |
| 142 | | state_save_register_item("dl1416", which, dl1416[which].chip_enable); |
| 143 | | state_save_register_item("dl1416", which, dl1416[which].cursor_enable); |
| 144 | | state_save_register_item("dl1416", which, dl1416[which].write_enable); |
| 145 | | state_save_register_item_array("dl1416", which, dl1416[which].cursor_ram); |
| 134 | /* allocate the object that holds the state */ |
| 135 | dl1416 = auto_malloc(sizeof(*dl1416)); |
| 136 | memset(dl1416, 0, sizeof(*dl1416)); |
| 137 | |
| 138 | dl1416->intf = static_config; |
| 139 | |
| 140 | /* register for state saving */ |
| 141 | state_save_combine_module_and_tag(unique_tag, "dl1416", tag); |
| 142 | |
| 143 | state_save_register_item(unique_tag, 0, dl1416->chip_enable); |
| 144 | state_save_register_item(unique_tag, 0, dl1416->cursor_enable); |
| 145 | state_save_register_item(unique_tag, 0, dl1416->write_enable); |
| 146 | state_save_register_item_array(unique_tag, 0, dl1416->cursor_ram); |
| 147 | |
| 148 | return dl1416; |
| 146 | 149 | } |
| 147 | 150 | |
| 148 | 151 | |
| 149 | | /* Reset */ |
| 150 | | void dl1416_reset(int which) |
| 152 | static void dl1416_reset(running_machine *machine, void *token) |
| 151 | 153 | { |
| 152 | 154 | int i; |
| 155 | dl1416_t *chip = token; |
| 153 | 156 | |
| 154 | | assert_always(which < MAX_DL1416, "'which' exceeds maximum number of configured DL1416s!"); |
| 155 | | |
| 156 | 157 | /* Disable all lines */ |
| 157 | | dl1416[which].chip_enable = FALSE; |
| 158 | | dl1416[which].write_enable = FALSE; |
| 159 | | dl1416[which].cursor_enable = FALSE; |
| 158 | chip->chip_enable = FALSE; |
| 159 | chip->write_enable = FALSE; |
| 160 | chip->cursor_enable = FALSE; |
| 160 | 161 | |
| 161 | 162 | /* Randomize cursor memory */ |
| 162 | 163 | for (i = 0; i < 4; i++) |
| 163 | | dl1416[which].cursor_ram[i] = mame_rand(Machine); |
| 164 | chip->cursor_ram[i] = mame_rand(machine); |
| 164 | 165 | } |
| 165 | 166 | |
| 166 | 167 | |
| 168 | static void dl1416_set_info(running_machine *machine, void *token, UINT32 state, const deviceinfo *info) |
| 169 | { |
| 170 | switch (state) |
| 171 | { |
| 172 | /* no parameters to set */ |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | |
| 177 | void dl1416_get_info(running_machine *machine, void *token, UINT32 state, deviceinfo *info) |
| 178 | { |
| 179 | switch (state) |
| 180 | { |
| 181 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 182 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 183 | |
| 184 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 185 | case DEVINFO_FCT_SET_INFO: info->set_info = dl1416_set_info; break; |
| 186 | case DEVINFO_FCT_START: info->start = dl1416_start; break; |
| 187 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 188 | case DEVINFO_FCT_RESET: info->reset = dl1416_reset; break; |
| 189 | |
| 190 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 191 | case DEVINFO_STR_NAME: info->s = "DL1416"; break; |
| 192 | case DEVINFO_STR_FAMILY: info->s = "DL1416"; break; |
| 193 | case DEVINFO_STR_VERSION: info->s = "1.0"; break; |
| 194 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 195 | case DEVINFO_STR_CREDITS: info->s = "Copyright MESS Team"; break; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | |
| 200 | |
| 201 | /***************************************************************************** |
| 202 | Implementation |
| 203 | *****************************************************************************/ |
| 204 | |
| 167 | 205 | /* Write enable, active low */ |
| 168 | | void dl1416_set_input_w(int which, int data) |
| 206 | void dl1416_set_input_w(dl1416_t *chip, int data) |
| 169 | 207 | { |
| 170 | | assert_always(which < MAX_DL1416, "'which' exceeds maximum number of configured DL1416s!"); |
| 171 | | dl1416[which].write_enable = !data; |
| 208 | chip->write_enable = !data; |
| 172 | 209 | } |
| 173 | 210 | |
| 174 | 211 | |
| 175 | 212 | /* Chip enable, active low */ |
| 176 | | void dl1416_set_input_ce(int which, int data) |
| 213 | void dl1416_set_input_ce(dl1416_t *chip, int data) |
| 177 | 214 | { |
| 178 | | assert_always(which < MAX_DL1416, "'which' exceeds maximum number of configured DL1416s!"); |
| 179 | | dl1416[which].chip_enable = !data; |
| 215 | chip->chip_enable = !data; |
| 180 | 216 | } |
| 181 | 217 | |
| 182 | 218 | |
| 183 | 219 | /* Cursor enable, active low */ |
| 184 | | void dl1416_set_input_cu(int which, int data) |
| 220 | void dl1416_set_input_cu(dl1416_t *chip, int data) |
| 185 | 221 | { |
| 186 | | assert_always(which < MAX_DL1416, "'which' exceeds maximum number of configured DL1416s!"); |
| 187 | | dl1416[which].cursor_enable = !data; |
| 222 | chip->cursor_enable = !data; |
| 188 | 223 | } |
| 189 | 224 | |
| 190 | 225 | |
| 191 | 226 | /* Data */ |
| 192 | | void dl1416_write(int which, offs_t offset, UINT8 data) |
| 227 | void dl1416_write(dl1416_t *chip, offs_t offset, UINT8 data) |
| 193 | 228 | { |
| 194 | 229 | int i, digit; |
| 195 | 230 | |
| 196 | | assert_always(which < MAX_DL1416, "'which' exceeds maximum number of configured DL1416s!"); |
| 197 | | |
| 198 | 231 | offset &= 0x03; /* A0-A1 */ |
| 199 | 232 | data &= 0x7f; /* D0-D6 */ |
| 200 | 233 | |
| 201 | 234 | /* Only try to update the data if we are enabled and write is enabled */ |
| 202 | | if (dl1416[which].chip_enable && dl1416[which].write_enable) |
| 235 | if (chip->chip_enable && chip->write_enable) |
| 203 | 236 | { |
| 204 | | if (dl1416[which].cursor_enable) |
| 237 | if (chip->cursor_enable) |
| 205 | 238 | { |
| 206 | | switch (dl1416[which].intf->type) |
| 239 | switch (chip->intf->type) |
| 207 | 240 | { |
| 208 | 241 | |
| 209 | 242 | case DL1416B: |
| 210 | 243 | |
| 211 | 244 | /* The cursor will be set if D0 is high and the original */ |
| 212 | 245 | /* character restored otherwise */ |
| 213 | | digit = data & 1 ? SEG_CURSOR : dl1416[which].cursor_ram[offset]; |
| 246 | digit = data & 1 ? SEG_CURSOR : chip->cursor_ram[offset]; |
| 214 | 247 | |
| 215 | 248 | /* Call update function */ |
| 216 | | dl1416[which].intf->digit_changed(offset, digit); |
| 249 | chip->intf->digit_changed(offset, digit); |
| 217 | 250 | |
| 218 | 251 | break; |
| 219 | 252 | |
| r1764 | r1765 | |
| 222 | 255 | for (i = 0; i < 4; i++) |
| 223 | 256 | { |
| 224 | 257 | /* Save old digit */ |
| 225 | | int previous_digit = dl1416[which].cursor_ram[i]; |
| 258 | int previous_digit = chip->cursor_ram[i]; |
| 226 | 259 | |
| 227 | 260 | /* Either set the cursor or restore the original character */ |
| 228 | | digit = data & i ? SEG_CURSOR : dl1416[which].cursor_ram[i]; |
| 261 | digit = data & i ? SEG_CURSOR : chip->cursor_ram[i]; |
| 229 | 262 | |
| 230 | 263 | /* Call update function if we changed something */ |
| 231 | 264 | if (previous_digit != digit) |
| 232 | | dl1416[which].intf->digit_changed(i, digit); |
| 265 | chip->intf->digit_changed(i, digit); |
| 233 | 266 | } |
| 234 | 267 | break; |
| 235 | 268 | |
| r1764 | r1765 | |
| 240 | 273 | /* On the DL1416T, a digit can only be changed if there is no */ |
| 241 | 274 | /* previously stored cursor, or overriden by an undefined */ |
| 242 | 275 | /* character (blank) */ |
| 243 | | if ((dl1416[which].intf->type != DL1416T) || ( |
| 244 | | (dl1416[which].cursor_ram[offset] != SEG_CURSOR) || |
| 276 | if ((chip->intf->type != DL1416T) || ( |
| 277 | (chip->cursor_ram[offset] != SEG_CURSOR) || |
| 245 | 278 | (dl1416t_segments[data] == SEG_UNDEF))) |
| 246 | 279 | { |
| 247 | 280 | /* Load data */ |
| r1764 | r1765 | |
| 252 | 285 | digit = SEG_BLANK; |
| 253 | 286 | |
| 254 | 287 | /* Save value */ |
| 255 | | dl1416[which].cursor_ram[offset] = digit; |
| 288 | chip->cursor_ram[offset] = digit; |
| 256 | 289 | |
| 257 | 290 | /* Call update function */ |
| 258 | | dl1416[which].intf->digit_changed(offset, digit); |
| 291 | chip->intf->digit_changed(offset, digit); |
| 259 | 292 | } |
| 260 | 293 | } |
| 261 | 294 | } |
| 262 | 295 | } |
| 263 | | |
| 264 | | |
| 265 | | /* Standard handlers */ |
| 266 | | WRITE8_HANDLER( dl1416_0_w ) { dl1416_write(0, offset, data); } |
| 267 | | WRITE8_HANDLER( dl1416_1_w ) { dl1416_write(1, offset, data); } |
| 268 | | WRITE8_HANDLER( dl1416_2_w ) { dl1416_write(2, offset, data); } |
| 269 | | WRITE8_HANDLER( dl1416_3_w ) { dl1416_write(3, offset, data); } |
| 270 | | WRITE8_HANDLER( dl1416_4_w ) { dl1416_write(4, offset, data); } |
src/mess/machine/aim65.c
| r1764 | r1765 | |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | /****************************************************************************** |
| 26 | | Function Prototypes |
| 27 | | ******************************************************************************/ |
| 28 | | |
| 29 | | static void aim65_update_ds1(int digit, int data); |
| 30 | | static void aim65_update_ds2(int digit, int data); |
| 31 | | static void aim65_update_ds3(int digit, int data); |
| 32 | | static void aim65_update_ds4(int digit, int data); |
| 33 | | static void aim65_update_ds5(int digit, int data); |
| 34 | | |
| 35 | | |
| 36 | | |
| 37 | | /****************************************************************************** |
| 38 | 26 | Global variables |
| 39 | 27 | ******************************************************************************/ |
| 40 | 28 | |
| r1764 | r1765 | |
| 42 | 30 | static UINT8 pia_a, pia_b; |
| 43 | 31 | static UINT8 riot_port_a; |
| 44 | 32 | |
| 45 | | /* Display driver interfaces */ |
| 46 | | static const dl1416_interface dl1416_ds1 = { DL1416T, aim65_update_ds1 }; |
| 47 | | static const dl1416_interface dl1416_ds2 = { DL1416T, aim65_update_ds2 }; |
| 48 | | static const dl1416_interface dl1416_ds3 = { DL1416T, aim65_update_ds3 }; |
| 49 | | static const dl1416_interface dl1416_ds4 = { DL1416T, aim65_update_ds4 }; |
| 50 | | static const dl1416_interface dl1416_ds5 = { DL1416T, aim65_update_ds5 }; |
| 51 | 33 | |
| 52 | 34 | |
| 53 | | |
| 54 | 35 | /****************************************************************************** |
| 55 | 36 | Interrupt handling |
| 56 | 37 | ******************************************************************************/ |
| r1764 | r1765 | |
| 90 | 71 | * PB7: CU (Cursor) |
| 91 | 72 | */ |
| 92 | 73 | |
| 93 | | static void aim65_pia(void) |
| 74 | static void dl1416_update(dl1416_t *chip, int index) |
| 94 | 75 | { |
| 95 | | int which; |
| 76 | dl1416_set_input_ce(chip, pia_a & (0x04 << index)); |
| 77 | dl1416_set_input_w(chip, pia_a & 0x80); |
| 78 | dl1416_set_input_cu(chip, pia_b & 0x80); |
| 79 | dl1416_write(chip, pia_a & 0x03, pia_b & 0x7f); |
| 80 | } |
| 96 | 81 | |
| 97 | | for (which = 0; which < 5; which++) |
| 98 | | { |
| 99 | | dl1416_set_input_ce(which, pia_a & (0x04 << which)); |
| 100 | | dl1416_set_input_w(which, pia_a & 0x80); |
| 101 | | dl1416_set_input_cu(which, pia_b & 0x80); |
| 102 | | dl1416_write(which, pia_a & 0x03, pia_b & 0x7f); |
| 103 | | } |
| 82 | static void aim65_pia(void) |
| 83 | { |
| 84 | dl1416_update(devtag_get_token(Machine, DL1416, "ds1"), 0); |
| 85 | dl1416_update(devtag_get_token(Machine, DL1416, "ds2"), 1); |
| 86 | dl1416_update(devtag_get_token(Machine, DL1416, "ds3"), 2); |
| 87 | dl1416_update(devtag_get_token(Machine, DL1416, "ds4"), 3); |
| 88 | dl1416_update(devtag_get_token(Machine, DL1416, "ds5"), 4); |
| 104 | 89 | } |
| 105 | 90 | |
| 106 | 91 | |
| r1764 | r1765 | |
| 135 | 120 | }; |
| 136 | 121 | |
| 137 | 122 | |
| 138 | | static void aim65_update_ds1(int digit, int data) { output_set_digit_value( 0 + (digit ^ 3), data); } |
| 139 | | static void aim65_update_ds2(int digit, int data) { output_set_digit_value( 4 + (digit ^ 3), data); } |
| 140 | | static void aim65_update_ds3(int digit, int data) { output_set_digit_value( 8 + (digit ^ 3), data); } |
| 141 | | static void aim65_update_ds4(int digit, int data) { output_set_digit_value(12 + (digit ^ 3), data); } |
| 142 | | static void aim65_update_ds5(int digit, int data) { output_set_digit_value(16 + (digit ^ 3), data); } |
| 123 | void aim65_update_ds1(int digit, int data) { output_set_digit_value( 0 + (digit ^ 3), data); } |
| 124 | void aim65_update_ds2(int digit, int data) { output_set_digit_value( 4 + (digit ^ 3), data); } |
| 125 | void aim65_update_ds3(int digit, int data) { output_set_digit_value( 8 + (digit ^ 3), data); } |
| 126 | void aim65_update_ds4(int digit, int data) { output_set_digit_value(12 + (digit ^ 3), data); } |
| 127 | void aim65_update_ds5(int digit, int data) { output_set_digit_value(16 + (digit ^ 3), data); } |
| 143 | 128 | |
| 144 | 129 | |
| 145 | 130 | |
| r1764 | r1765 | |
| 247 | 232 | memory_set_bankptr(1, mess_ram); |
| 248 | 233 | |
| 249 | 234 | if (mess_ram_size < 4 * 1024) |
| 250 | | memory_install_readwrite8_handler(0, ADDRESS_SPACE_PROGRAM, |
| 235 | memory_install_readwrite8_handler(0, ADDRESS_SPACE_PROGRAM, |
| 251 | 236 | mess_ram_size, 0x0fff, 0, 0, MRA8_NOP, MWA8_NOP); |
| 252 | 237 | |
| 253 | | /* Init display driver */ |
| 254 | | dl1416_config(0, &dl1416_ds1); |
| 255 | | dl1416_config(1, &dl1416_ds2); |
| 256 | | dl1416_config(2, &dl1416_ds3); |
| 257 | | dl1416_config(3, &dl1416_ds4); |
| 258 | | dl1416_config(4, &dl1416_ds5); |
| 259 | | |
| 260 | | dl1416_reset(0); |
| 261 | | dl1416_reset(1); |
| 262 | | dl1416_reset(2); |
| 263 | | dl1416_reset(3); |
| 264 | | dl1416_reset(4); |
| 265 | | |
| 266 | 238 | pia_config(0, &pia); |
| 267 | 239 | |
| 268 | 240 | r6532_config(0, &r6532_interface); |