src/emu/video/crt9021.c
| r0 | r10969 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | SMC CRT9021 Video Attributes Controller (VAC) emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | /* |
| 11 | |
| 12 | TODO: |
| 13 | |
| 14 | - attributes |
| 15 | - reverse video |
| 16 | - character blank |
| 17 | - character blink |
| 18 | - underline |
| 19 | - full/half intensity |
| 20 | - operation modes |
| 21 | - wide graphics |
| 22 | - thin graphics |
| 23 | - character mode w/o underline |
| 24 | - character mode w/underline |
| 25 | - double height characters |
| 26 | - double width characters |
| 27 | - parallel scan line |
| 28 | - serial scan line |
| 29 | - cursor |
| 30 | - underline |
| 31 | - blinking underline |
| 32 | - reverse video |
| 33 | - blinking reverse video |
| 34 | - programmable character blink rate (75/25 duty) |
| 35 | - programmable cursor blink rate (50/50 duty) |
| 36 | - data/attribute latches |
| 37 | |
| 38 | */ |
| 39 | |
| 40 | #include "emu.h" |
| 41 | #include "crt9021.h" |
| 42 | |
| 43 | |
| 44 | |
| 45 | //************************************************************************** |
| 46 | // MACROS / CONSTANTS |
| 47 | //************************************************************************** |
| 48 | |
| 49 | #define LOG 1 |
| 50 | |
| 51 | |
| 52 | // attributes |
| 53 | enum |
| 54 | { |
| 55 | ATTRIBUTE_REVID = 0x80, |
| 56 | ATTRIBUTE_INT = 0x40, |
| 57 | ATTRIBUTE_BLINK = 0x20, |
| 58 | ATTRIBUTE_MS1 = 0x10, |
| 59 | ATTRIBUTE_MS0 = 0x08, |
| 60 | ATTRIBUTE_CHABL = 0x04, |
| 61 | ATTRIBUTE_BKC = 0x02, |
| 62 | ATTRIBUTE_BLC = 0x01 |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | //************************************************************************** |
| 67 | // GLOBAL VARIABLES |
| 68 | //************************************************************************** |
| 69 | |
| 70 | // devices |
| 71 | const device_type CRT9021 = crt9021_device_config::static_alloc_device_config; |
| 72 | |
| 73 | |
| 74 | |
| 75 | //************************************************************************** |
| 76 | // DEVICE CONFIGURATION |
| 77 | //************************************************************************** |
| 78 | |
| 79 | //------------------------------------------------- |
| 80 | // crt9021_device_config - constructor |
| 81 | //------------------------------------------------- |
| 82 | |
| 83 | crt9021_device_config::crt9021_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 84 | : device_config(mconfig, static_alloc_device_config, "SMC CRT9021", tag, owner, clock) |
| 85 | { |
| 86 | } |
| 87 | |
| 88 | |
| 89 | //------------------------------------------------- |
| 90 | // static_alloc_device_config - allocate a new |
| 91 | // configuration object |
| 92 | //------------------------------------------------- |
| 93 | |
| 94 | device_config *crt9021_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 95 | { |
| 96 | return global_alloc(crt9021_device_config(mconfig, tag, owner, clock)); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | //------------------------------------------------- |
| 101 | // alloc_device - allocate a new device object |
| 102 | //------------------------------------------------- |
| 103 | |
| 104 | device_t *crt9021_device_config::alloc_device(running_machine &machine) const |
| 105 | { |
| 106 | return auto_alloc(&machine, crt9021_device(machine, *this)); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | //------------------------------------------------- |
| 111 | // device_config_complete - perform any |
| 112 | // operations now that the configuration is |
| 113 | // complete |
| 114 | //------------------------------------------------- |
| 115 | |
| 116 | void crt9021_device_config::device_config_complete() |
| 117 | { |
| 118 | // inherit a copy of the static data |
| 119 | const crt9021_interface *intf = reinterpret_cast<const crt9021_interface *>(static_config()); |
| 120 | if (intf != NULL) |
| 121 | *static_cast<crt9021_interface *>(this) = *intf; |
| 122 | |
| 123 | // or initialize to defaults if none provided |
| 124 | else |
| 125 | { |
| 126 | memset(&in_data_func, 0, sizeof(in_data_func)); |
| 127 | memset(&in_attr_func, 0, sizeof(in_attr_func)); |
| 128 | memset(&in_atten_func, 0, sizeof(in_atten_func)); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | |
| 133 | |
| 134 | //************************************************************************** |
| 135 | // INLINE HELPERS |
| 136 | //************************************************************************** |
| 137 | |
| 138 | |
| 139 | |
| 140 | //************************************************************************** |
| 141 | // LIVE DEVICE |
| 142 | //************************************************************************** |
| 143 | |
| 144 | //------------------------------------------------- |
| 145 | // crt9021_device - constructor |
| 146 | //------------------------------------------------- |
| 147 | |
| 148 | crt9021_device::crt9021_device(running_machine &_machine, const crt9021_device_config &config) |
| 149 | : device_t(_machine, config), |
| 150 | m_config(config) |
| 151 | { |
| 152 | } |
| 153 | |
| 154 | |
| 155 | //------------------------------------------------- |
| 156 | // device_start - device-specific startup |
| 157 | //------------------------------------------------- |
| 158 | |
| 159 | void crt9021_device::device_start() |
| 160 | { |
| 161 | // allocate timers |
| 162 | |
| 163 | // resolve callbacks |
| 164 | devcb_resolve_read8(&m_in_data_func, &m_config.in_data_func, this); |
| 165 | devcb_resolve_read8(&m_in_attr_func, &m_config.in_attr_func, this); |
| 166 | devcb_resolve_read_line(&m_in_atten_func, &m_config.in_atten_func, this); |
| 167 | |
| 168 | // get the screen device |
| 169 | m_screen = machine->device<screen_device>(m_config.screen_tag); |
| 170 | assert(m_screen != NULL); |
| 171 | |
| 172 | // register for state saving |
| 173 | save_item(NAME(m_slg)); |
| 174 | save_item(NAME(m_sld)); |
| 175 | save_item(NAME(m_cursor)); |
| 176 | save_item(NAME(m_retbl)); |
| 177 | save_item(NAME(m_vsync)); |
| 178 | } |
| 179 | |
| 180 | |
| 181 | //------------------------------------------------- |
| 182 | // device_clock_changed - handle clock change |
| 183 | //------------------------------------------------- |
| 184 | |
| 185 | void crt9021_device::device_clock_changed() |
| 186 | { |
| 187 | } |
| 188 | |
| 189 | |
| 190 | //------------------------------------------------- |
| 191 | // device_timer - handle timer events |
| 192 | //------------------------------------------------- |
| 193 | |
| 194 | void crt9021_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 195 | { |
| 196 | } |
| 197 | |
| 198 | |
| 199 | //------------------------------------------------- |
| 200 | // slg_w - scan line gate |
| 201 | //------------------------------------------------- |
| 202 | |
| 203 | WRITE_LINE_MEMBER( crt9021_device::slg_w ) |
| 204 | { |
| 205 | if (LOG) logerror("CRT9021 '%s' SLG: %u\n", tag(), state); |
| 206 | |
| 207 | m_slg = state; |
| 208 | } |
| 209 | |
| 210 | |
| 211 | //------------------------------------------------- |
| 212 | // sld_w - scan line data |
| 213 | //------------------------------------------------- |
| 214 | |
| 215 | WRITE_LINE_MEMBER( crt9021_device::sld_w ) |
| 216 | { |
| 217 | if (LOG) logerror("CRT9021 '%s' SLG: %u\n", tag(), state); |
| 218 | |
| 219 | if (!m_slg) |
| 220 | { |
| 221 | m_sld <<= 1; |
| 222 | m_sld |= state; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | |
| 227 | //------------------------------------------------- |
| 228 | // cursor_w - cursor |
| 229 | //------------------------------------------------- |
| 230 | |
| 231 | WRITE_LINE_MEMBER( crt9021_device::cursor_w ) |
| 232 | { |
| 233 | if (LOG) logerror("CRT9021 '%s' CURSOR: %u\n", tag(), state); |
| 234 | |
| 235 | m_cursor = state; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | //------------------------------------------------- |
| 240 | // retbl_w - retrace blank |
| 241 | //------------------------------------------------- |
| 242 | |
| 243 | WRITE_LINE_MEMBER( crt9021_device::retbl_w ) |
| 244 | { |
| 245 | if (LOG) logerror("CRT9021 '%s' RETBL: %u\n", tag(), state); |
| 246 | |
| 247 | m_retbl = state; |
| 248 | } |
| 249 | |
| 250 | |
| 251 | //------------------------------------------------- |
| 252 | // vsync_w - vertical sync |
| 253 | //------------------------------------------------- |
| 254 | |
| 255 | WRITE_LINE_MEMBER( crt9021_device::vsync_w ) |
| 256 | { |
| 257 | if (LOG) logerror("CRT9021 '%s' VSYNC: %u\n", tag(), state); |
| 258 | |
| 259 | m_vsync = state; |
| 260 | } |
| 261 | |
| 262 | |
| 263 | //------------------------------------------------- |
| 264 | // update_screen - update screen |
| 265 | //------------------------------------------------- |
| 266 | |
| 267 | void crt9021_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect) |
| 268 | { |
| 269 | } |
src/emu/video/crt9007.c
| r0 | r10969 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | SMC CRT9007 CRT Video Processor and Controller (VPAC) emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | /* |
| 11 | |
| 12 | TODO: |
| 13 | |
| 14 | - cursor timer |
| 15 | - interrupts |
| 16 | - light pen |
| 17 | - frame timer |
| 18 | - non-DMA mode |
| 19 | - DMA mode |
| 20 | - cursor/blank skew |
| 21 | - sequential breaks |
| 22 | - interlaced mode |
| 23 | - smooth scroll |
| 24 | - page blank |
| 25 | - double height cursor |
| 26 | - row attributes |
| 27 | - pin configuration |
| 28 | - operation modes 0,4,7 |
| 29 | - address modes 1,2,3 |
| 30 | - light pen |
| 31 | - state saving |
| 32 | |
| 33 | */ |
| 34 | |
| 35 | #include "emu.h" |
| 36 | #include "crt9007.h" |
| 37 | |
| 38 | |
| 39 | |
| 40 | //************************************************************************** |
| 41 | // MACROS / CONSTANTS |
| 42 | //************************************************************************** |
| 43 | |
| 44 | #define LOG 1 |
| 45 | |
| 46 | #define HAS_VALID_PARAMETERS \ |
| 47 | (m_reg[0x00] && m_reg[0x01] && m_reg[0x07] && m_reg[0x08] && m_reg[0x09]) |
| 48 | |
| 49 | #define CHARACTERS_PER_HORIZONTAL_PERIOD \ |
| 50 | m_reg[0x00] |
| 51 | |
| 52 | #define CHARACTERS_PER_DATA_ROW \ |
| 53 | (m_reg[0x01] + 1) |
| 54 | |
| 55 | #define HORIZONTAL_DELAY \ |
| 56 | m_reg[0x02] |
| 57 | |
| 58 | #define HORIZONTAL_SYNC_WIDTH \ |
| 59 | m_reg[0x03] |
| 60 | |
| 61 | #define VERTICAL_SYNC_WIDTH \ |
| 62 | m_reg[0x04] |
| 63 | |
| 64 | #define VERTICAL_DELAY \ |
| 65 | (m_reg[0x05] - 1) |
| 66 | |
| 67 | #define PIN_CONFIGURATION \ |
| 68 | (m_reg[0x06] >> 6) |
| 69 | |
| 70 | #define CURSOR_SKEW \ |
| 71 | ((m_reg[0x06] >> 3) & 0x07) |
| 72 | |
| 73 | #define BLANK_SKEW \ |
| 74 | (m_reg[0x06] & 0x07) |
| 75 | |
| 76 | #define VISIBLE_DATA_ROWS_PER_FRAME \ |
| 77 | (m_reg[0x07] + 1) |
| 78 | |
| 79 | #define SCAN_LINES_PER_DATA_ROW \ |
| 80 | ((m_reg[0x08] & 0x1f) + 1) |
| 81 | |
| 82 | #define SCAN_LINES_PER_FRAME \ |
| 83 | (((m_reg[0x08] << 3) & 0x0700) | m_reg[0x09]) |
| 84 | |
| 85 | #define DMA_BURST_COUNT \ |
| 86 | ((m_reg[0x0a] & 0x0f) + 1) |
| 87 | |
| 88 | #define DMA_BURST_DELAY \ |
| 89 | ((((m_reg[0x0a] >> 4) & 0x07) + 1) % 8) |
| 90 | |
| 91 | #define DMA_DISABLE \ |
| 92 | BIT(m_reg[0x0a], 7) |
| 93 | |
| 94 | #define SINGLE_HEIGHT_CURSOR \ |
| 95 | BIT(m_reg[0x0b], 0) |
| 96 | |
| 97 | #define OPERATION_MODE \ |
| 98 | ((m_reg[0x0b] >> 1) & 0x07) |
| 99 | |
| 100 | #define INTERLACE_MODE \ |
| 101 | ((m_reg[0x0b] >> 4) & 0x03) |
| 102 | |
| 103 | #define PAGE_BLANK \ |
| 104 | BIT(m_reg[0x0b], 6) |
| 105 | |
| 106 | #define TABLE_START \ |
| 107 | (((m_reg[0x0d] << 8) & 0x3f00) | m_reg[0x0c]) |
| 108 | |
| 109 | #define ADDRESS_MODE \ |
| 110 | ((m_reg[0x0d] >> 6) & 0x03) |
| 111 | |
| 112 | #define AUXILIARY_ADDRESS_1 \ |
| 113 | (((m_reg[0x0f] << 8) & 0x3f00) | m_reg[0x0e]) |
| 114 | |
| 115 | #define ROW_ATTRIBUTES_1 \ |
| 116 | ((m_reg[0x0f] >> 6) & 0x03) |
| 117 | |
| 118 | #define SEQUENTIAL_BREAK_1 \ |
| 119 | m_reg[0x10] |
| 120 | |
| 121 | #define SEQUENTIAL_BREAK_2 \ |
| 122 | m_reg[0x12] |
| 123 | |
| 124 | #define DATA_ROW_START \ |
| 125 | m_reg[0x11] |
| 126 | |
| 127 | #define DATA_ROW_END \ |
| 128 | m_reg[0x12] |
| 129 | |
| 130 | #define AUXILIARY_ADDRESS_2 \ |
| 131 | (((m_reg[0x14] << 8) & 0x3f00) | m_reg[0x13]) |
| 132 | |
| 133 | #define ROW_ATTRIBUTES_2 \ |
| 134 | ((m_reg[0x14] >> 6) & 0x03) |
| 135 | |
| 136 | #define SMOOTH_SCROLL_OFFSET \ |
| 137 | ((m_reg[0x17] >> 1) & 0x3f) |
| 138 | |
| 139 | #define SMOOTH_SCROLL_OFFSET_OVERFLOW \ |
| 140 | BIT(m_reg[0x17], 7) |
| 141 | |
| 142 | #define VERTICAL_CURSOR \ |
| 143 | m_reg[0x18] |
| 144 | |
| 145 | #define HORIZONTAL_CURSOR \ |
| 146 | m_reg[0x19] |
| 147 | |
| 148 | #define INTERRUPT_ENABLE \ |
| 149 | m_reg[0x1a] |
| 150 | |
| 151 | #define FRAME_TIMER \ |
| 152 | BIT(m_reg[0x1a], 0) |
| 153 | |
| 154 | #define LIGHT_PEN_INTERRUPT \ |
| 155 | BIT(m_reg[0x1a], 5) |
| 156 | |
| 157 | #define VERTICAL_RETRACE_INTERRUPT \ |
| 158 | BIT(m_reg[0x1a], 6) |
| 159 | |
| 160 | #define VERTICAL_LIGHT_PEN \ |
| 161 | m_reg[0x3b] |
| 162 | |
| 163 | #define HORIZONTAL_LIGHT_PEN \ |
| 164 | m_reg[0x3c] |
| 165 | |
| 166 | |
| 167 | // interlace |
| 168 | enum |
| 169 | { |
| 170 | NON_INTERLACED = 0, |
| 171 | ENHANCED_VIDEO_INTERFACE, |
| 172 | NORMAL_VIDEO_INTERFACE, |
| 173 | }; |
| 174 | |
| 175 | |
| 176 | // operation modes |
| 177 | enum |
| 178 | { |
| 179 | OPERATION_MODE_REPETITIVE_MEMORY_ADDRESSING = 0, // not implemented |
| 180 | OPERATION_MODE_DOUBLE_ROW_BUFFER = 1, |
| 181 | OPERATION_MODE_SINGLE_ROW_BUFFER = 4, // not implemented |
| 182 | OPERATION_MODE_ATTRIBUTE_ASSEMBLE = 7 // not implemented |
| 183 | }; |
| 184 | |
| 185 | |
| 186 | // addressing modes |
| 187 | enum |
| 188 | { |
| 189 | ADDRESS_MODE_SEQUENTIAL_ADDRESSING = 0, |
| 190 | ADDRESS_MODE_SEQUENTIAL_ROLL_ADDRESSING, // not implemented |
| 191 | ADDRESS_MODE_CONTIGUOUS_ROW_TABLE, // not implemented |
| 192 | ADDRESS_MODE_LINKED_LIST_ROW_TABLE // not implemented |
| 193 | }; |
| 194 | |
| 195 | |
| 196 | // interrupt enable register bits |
| 197 | const int IE_VERTICAL_RETRACE = 0x40; |
| 198 | const int IE_LIGHT_PEN = 0x20; |
| 199 | const int IE_FRAME_TIMER = 0x01; |
| 200 | |
| 201 | // status register bits |
| 202 | const int STATUS_INTERRUPT_PENDING = 0x80; |
| 203 | const int STATUS_VERTICAL_RETRACE = 0x40; |
| 204 | const int STATUS_LIGHT_PEN_UPDATE = 0x20; |
| 205 | const int STATUS_ODD_EVEN = 0x04; |
| 206 | const int STATUS_FRAME_TIMER_OCCURRED = 0x01; |
| 207 | |
| 208 | |
| 209 | |
| 210 | //************************************************************************** |
| 211 | // GLOBAL VARIABLES |
| 212 | //************************************************************************** |
| 213 | |
| 214 | // devices |
| 215 | const device_type CRT9007 = crt9007_device_config::static_alloc_device_config; |
| 216 | |
| 217 | |
| 218 | // default address map |
| 219 | static ADDRESS_MAP_START( crt9007, AS_0, 8 ) |
| 220 | AM_RANGE(0x0000, 0x3fff) AM_RAM |
| 221 | ADDRESS_MAP_END |
| 222 | |
| 223 | |
| 224 | |
| 225 | //************************************************************************** |
| 226 | // DEVICE CONFIGURATION |
| 227 | //************************************************************************** |
| 228 | |
| 229 | //------------------------------------------------- |
| 230 | // crt9007_device_config - constructor |
| 231 | //------------------------------------------------- |
| 232 | |
| 233 | crt9007_device_config::crt9007_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 234 | : device_config(mconfig, static_alloc_device_config, "SMC CRT9007", tag, owner, clock), |
| 235 | device_config_memory_interface(mconfig, *this), |
| 236 | m_space_config("videoram", ENDIANNESS_LITTLE, 8, 14, 0, NULL, *ADDRESS_MAP_NAME(crt9007)) |
| 237 | { |
| 238 | } |
| 239 | |
| 240 | |
| 241 | //------------------------------------------------- |
| 242 | // static_alloc_device_config - allocate a new |
| 243 | // configuration object |
| 244 | //------------------------------------------------- |
| 245 | |
| 246 | device_config *crt9007_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 247 | { |
| 248 | return global_alloc(crt9007_device_config(mconfig, tag, owner, clock)); |
| 249 | } |
| 250 | |
| 251 | |
| 252 | //------------------------------------------------- |
| 253 | // alloc_device - allocate a new device object |
| 254 | //------------------------------------------------- |
| 255 | |
| 256 | device_t *crt9007_device_config::alloc_device(running_machine &machine) const |
| 257 | { |
| 258 | return auto_alloc(&machine, crt9007_device(machine, *this)); |
| 259 | } |
| 260 | |
| 261 | |
| 262 | //------------------------------------------------- |
| 263 | // memory_space_config - return a description of |
| 264 | // any address spaces owned by this device |
| 265 | //------------------------------------------------- |
| 266 | |
| 267 | const address_space_config *crt9007_device_config::memory_space_config(address_spacenum spacenum) const |
| 268 | { |
| 269 | return (spacenum == AS_0) ? &m_space_config : NULL; |
| 270 | } |
| 271 | |
| 272 | |
| 273 | //------------------------------------------------- |
| 274 | // device_config_complete - perform any |
| 275 | // operations now that the configuration is |
| 276 | // complete |
| 277 | //------------------------------------------------- |
| 278 | |
| 279 | void crt9007_device_config::device_config_complete() |
| 280 | { |
| 281 | // inherit a copy of the static data |
| 282 | const crt9007_interface *intf = reinterpret_cast<const crt9007_interface *>(static_config()); |
| 283 | if (intf != NULL) |
| 284 | *static_cast<crt9007_interface *>(this) = *intf; |
| 285 | |
| 286 | // or initialize to defaults if none provided |
| 287 | else |
| 288 | { |
| 289 | memset(&out_int_func, 0, sizeof(out_int_func)); |
| 290 | memset(&out_dmar_func, 0, sizeof(out_dmar_func)); |
| 291 | memset(&out_vs_func, 0, sizeof(out_vs_func)); |
| 292 | memset(&out_hs_func, 0, sizeof(out_hs_func)); |
| 293 | memset(&out_vlt_func, 0, sizeof(out_vlt_func)); |
| 294 | memset(&out_curs_func, 0, sizeof(out_curs_func)); |
| 295 | memset(&out_drb_func, 0, sizeof(out_drb_func)); |
| 296 | memset(&out_cblank_func, 0, sizeof(out_cblank_func)); |
| 297 | memset(&out_slg_func, 0, sizeof(out_slg_func)); |
| 298 | memset(&out_sld_func, 0, sizeof(out_sld_func)); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | |
| 303 | |
| 304 | //************************************************************************** |
| 305 | // INLINE HELPERS |
| 306 | //************************************************************************** |
| 307 | |
| 308 | //------------------------------------------------- |
| 309 | // readbyte - read a byte at the given address |
| 310 | //------------------------------------------------- |
| 311 | |
| 312 | inline UINT8 crt9007_device::readbyte(offs_t address) |
| 313 | { |
| 314 | return space()->read_byte(address); |
| 315 | } |
| 316 | |
| 317 | |
| 318 | //------------------------------------------------- |
| 319 | // trigger_interrupt - |
| 320 | //------------------------------------------------- |
| 321 | |
| 322 | inline void crt9007_device::trigger_interrupt(int line) |
| 323 | { |
| 324 | if (INTERRUPT_ENABLE & line) |
| 325 | { |
| 326 | int status = m_status; |
| 327 | |
| 328 | m_status |= STATUS_INTERRUPT_PENDING | line; |
| 329 | |
| 330 | if (!(status & STATUS_INTERRUPT_PENDING)) |
| 331 | { |
| 332 | if (LOG) logerror("CRT9007 '%s' INT 1\n", tag()); |
| 333 | devcb_call_write_line(&m_out_int_func, ASSERT_LINE); |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | |
| 339 | //------------------------------------------------- |
| 340 | // update_cblank_line - |
| 341 | //------------------------------------------------- |
| 342 | |
| 343 | inline void crt9007_device::update_cblank_line() |
| 344 | { |
| 345 | int x = m_screen->hpos(); |
| 346 | int y = m_screen->vpos(); |
| 347 | |
| 348 | // composite blank |
| 349 | int cblank = !(m_hs & m_vs); |
| 350 | |
| 351 | if (m_cblank != cblank) |
| 352 | { |
| 353 | m_cblank = cblank; |
| 354 | |
| 355 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : CBLANK %u\n", tag(), y, x, m_cblank); |
| 356 | |
| 357 | devcb_call_write_line(&m_out_cblank_func, m_cblank); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | |
| 362 | //------------------------------------------------- |
| 363 | // update_hsync_timer - |
| 364 | //------------------------------------------------- |
| 365 | |
| 366 | inline void crt9007_device::update_hsync_timer(int state) |
| 367 | { |
| 368 | int y = m_screen->vpos(); |
| 369 | |
| 370 | int next_x = state ? m_hsync_start : m_hsync_end; |
| 371 | int next_y = state ? (y + 1) % SCAN_LINES_PER_FRAME : y; |
| 372 | |
| 373 | attotime duration = m_screen->time_until_pos(next_y, next_x); |
| 374 | |
| 375 | m_hsync_timer->adjust(duration, !state); |
| 376 | } |
| 377 | |
| 378 | |
| 379 | //------------------------------------------------- |
| 380 | // update_vsync_timer - |
| 381 | //------------------------------------------------- |
| 382 | |
| 383 | inline void crt9007_device::update_vsync_timer(int state) |
| 384 | { |
| 385 | int next_y = state ? m_vsync_start : m_vsync_end; |
| 386 | |
| 387 | attotime duration = m_screen->time_until_pos(next_y, 0); |
| 388 | |
| 389 | m_vsync_timer->adjust(duration, !state); |
| 390 | } |
| 391 | |
| 392 | |
| 393 | //------------------------------------------------- |
| 394 | // update_vlt_timer - |
| 395 | //------------------------------------------------- |
| 396 | |
| 397 | inline void crt9007_device::update_vlt_timer(int state) |
| 398 | { |
| 399 | // this signal is active during all visible scan lines and during the horizontal trace at vertical retrace |
| 400 | int y = m_screen->vpos(); |
| 401 | |
| 402 | int next_x = state ? m_vlt_end : m_vlt_start; |
| 403 | int next_y = state ? y : ((y == m_vlt_bottom) ? 0 : (y + 1)); |
| 404 | |
| 405 | attotime duration = m_screen->time_until_pos(next_y, next_x); |
| 406 | |
| 407 | m_vlt_timer->adjust(duration, !state); |
| 408 | } |
| 409 | |
| 410 | |
| 411 | //------------------------------------------------- |
| 412 | // update_curs_timer - |
| 413 | //------------------------------------------------- |
| 414 | |
| 415 | inline void crt9007_device::update_curs_timer(int state) |
| 416 | { |
| 417 | // this signal is active for 1 character time for all scanlines within the data row |
| 418 | // TODO |
| 419 | } |
| 420 | |
| 421 | |
| 422 | //------------------------------------------------- |
| 423 | // update_drb_timer - |
| 424 | //------------------------------------------------- |
| 425 | |
| 426 | inline void crt9007_device::update_drb_timer(int state) |
| 427 | { |
| 428 | // this signal is active for 1 full scan line (VLT edge to edge) at the top scan line of each new row |
| 429 | // there is 1 extra DRB signal during the 1st scanline of the vertical retrace interval |
| 430 | int y = m_screen->vpos(); |
| 431 | |
| 432 | int next_x = m_vlt_end; |
| 433 | int next_y = y ? y + 1 : y; |
| 434 | |
| 435 | if (state) |
| 436 | { |
| 437 | if (y == 0) |
| 438 | { |
| 439 | next_y = VERTICAL_DELAY - 1; |
| 440 | } |
| 441 | else if (y == m_drb_bottom) |
| 442 | { |
| 443 | next_x = 0; |
| 444 | next_y = 0; |
| 445 | } |
| 446 | else |
| 447 | { |
| 448 | next_y = y + SCAN_LINES_PER_DATA_ROW - 1; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | attotime duration = m_screen->time_until_pos(next_y, next_x); |
| 453 | |
| 454 | m_drb_timer->adjust(duration, !state); |
| 455 | } |
| 456 | |
| 457 | |
| 458 | //------------------------------------------------- |
| 459 | // update_dma_timer - |
| 460 | //------------------------------------------------- |
| 461 | |
| 462 | inline void crt9007_device::update_dma_timer() |
| 463 | { |
| 464 | // TODO |
| 465 | } |
| 466 | |
| 467 | |
| 468 | //------------------------------------------------- |
| 469 | // recompute_parameters - |
| 470 | //------------------------------------------------- |
| 471 | |
| 472 | inline void crt9007_device::recompute_parameters() |
| 473 | { |
| 474 | // check that necessary registers have been loaded |
| 475 | if (!HAS_VALID_PARAMETERS) return; |
| 476 | |
| 477 | // screen dimensions |
| 478 | int horiz_pix_total = CHARACTERS_PER_HORIZONTAL_PERIOD * m_hpixels_per_column; |
| 479 | int vert_pix_total = SCAN_LINES_PER_FRAME; |
| 480 | |
| 481 | // refresh rate |
| 482 | attoseconds_t refresh = HZ_TO_ATTOSECONDS(clock()) * horiz_pix_total * vert_pix_total; |
| 483 | |
| 484 | // horizontal sync |
| 485 | m_hsync_start = 0; |
| 486 | m_hsync_end = HORIZONTAL_SYNC_WIDTH * m_hpixels_per_column; |
| 487 | |
| 488 | // visible line time |
| 489 | m_vlt_start = HORIZONTAL_DELAY * m_hpixels_per_column; |
| 490 | m_vlt_end = (HORIZONTAL_DELAY + CHARACTERS_PER_DATA_ROW) * m_hpixels_per_column; |
| 491 | m_vlt_bottom = VERTICAL_DELAY + (VISIBLE_DATA_ROWS_PER_FRAME * SCAN_LINES_PER_DATA_ROW) - 1; |
| 492 | |
| 493 | // data row boundary |
| 494 | m_drb_bottom = VERTICAL_DELAY + (VISIBLE_DATA_ROWS_PER_FRAME * SCAN_LINES_PER_DATA_ROW) - SCAN_LINES_PER_DATA_ROW; |
| 495 | |
| 496 | // vertical sync |
| 497 | m_vsync_start = 0; |
| 498 | m_vsync_end = VERTICAL_SYNC_WIDTH; |
| 499 | |
| 500 | // visible area |
| 501 | rectangle visarea; |
| 502 | |
| 503 | visarea.min_x = m_hsync_end; |
| 504 | visarea.max_x = horiz_pix_total - 1; |
| 505 | |
| 506 | visarea.min_y = m_vsync_end; |
| 507 | visarea.max_y = vert_pix_total - 1; |
| 508 | |
| 509 | if (LOG) |
| 510 | { |
| 511 | logerror("CRT9007 '%s' Screen: %u x %u @ %f Hz\n", tag(), horiz_pix_total, vert_pix_total, 1 / ATTOSECONDS_TO_DOUBLE(refresh)); |
| 512 | logerror("CRT9007 '%s' Visible Area: (%u, %u) - (%u, %u)\n", tag(), visarea.min_x, visarea.min_y, visarea.max_x, visarea.max_y); |
| 513 | } |
| 514 | |
| 515 | m_screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh); |
| 516 | |
| 517 | m_hsync_timer->adjust(m_screen->time_until_pos(0, 0)); |
| 518 | m_vsync_timer->adjust(m_screen->time_until_pos(0, 0)); |
| 519 | m_vlt_timer->adjust(m_screen->time_until_pos(0, m_vlt_start), 1); |
| 520 | m_drb_timer->adjust(m_screen->time_until_pos(0, 0)); |
| 521 | } |
| 522 | |
| 523 | |
| 524 | //************************************************************************** |
| 525 | // LIVE DEVICE |
| 526 | //************************************************************************** |
| 527 | |
| 528 | //------------------------------------------------- |
| 529 | // crt9007_device - constructor |
| 530 | //------------------------------------------------- |
| 531 | |
| 532 | crt9007_device::crt9007_device(running_machine &_machine, const crt9007_device_config &config) |
| 533 | : device_t(_machine, config), |
| 534 | device_memory_interface(_machine, config, *this), |
| 535 | m_config(config) |
| 536 | { |
| 537 | for (int i = 0; i < 0x3d; i++) |
| 538 | m_reg[i] = 0; |
| 539 | } |
| 540 | |
| 541 | |
| 542 | //------------------------------------------------- |
| 543 | // device_start - device-specific startup |
| 544 | //------------------------------------------------- |
| 545 | |
| 546 | void crt9007_device::device_start() |
| 547 | { |
| 548 | // allocate timers |
| 549 | m_hsync_timer = timer_alloc(TIMER_HSYNC); |
| 550 | m_vsync_timer = timer_alloc(TIMER_VSYNC); |
| 551 | m_vlt_timer = timer_alloc(TIMER_VLT); |
| 552 | m_curs_timer = timer_alloc(TIMER_CURS); |
| 553 | m_drb_timer = timer_alloc(TIMER_DRB); |
| 554 | m_dma_timer = timer_alloc(TIMER_DMA); |
| 555 | |
| 556 | // resolve callbacks |
| 557 | devcb_resolve_write_line(&m_out_int_func, &m_config.out_int_func, this); |
| 558 | devcb_resolve_write_line(&m_out_dmar_func, &m_config.out_dmar_func, this); |
| 559 | devcb_resolve_write_line(&m_out_hs_func, &m_config.out_hs_func, this); |
| 560 | devcb_resolve_write_line(&m_out_vs_func, &m_config.out_vs_func, this); |
| 561 | devcb_resolve_write_line(&m_out_vlt_func, &m_config.out_vlt_func, this); |
| 562 | devcb_resolve_write_line(&m_out_curs_func, &m_config.out_curs_func, this); |
| 563 | devcb_resolve_write_line(&m_out_drb_func, &m_config.out_drb_func, this); |
| 564 | devcb_resolve_write_line(&m_out_cblank_func, &m_config.out_cblank_func, this); |
| 565 | devcb_resolve_write_line(&m_out_slg_func, &m_config.out_slg_func, this); |
| 566 | devcb_resolve_write_line(&m_out_sld_func, &m_config.out_sld_func, this); |
| 567 | |
| 568 | // get the screen device |
| 569 | m_screen = machine->device<screen_device>(m_config.screen_tag); |
| 570 | assert(m_screen != NULL); |
| 571 | |
| 572 | // set horizontal pixels per column |
| 573 | m_hpixels_per_column = m_config.hpixels_per_column; |
| 574 | |
| 575 | // register for state saving |
| 576 | // state_save_register_device_item(this, 0, ); |
| 577 | } |
| 578 | |
| 579 | |
| 580 | //------------------------------------------------- |
| 581 | // device_reset - device-specific reset |
| 582 | //------------------------------------------------- |
| 583 | |
| 584 | void crt9007_device::device_reset() |
| 585 | { |
| 586 | m_disp = 0; |
| 587 | |
| 588 | // HS = 1 |
| 589 | devcb_call_write_line(&m_out_hs_func, 1); |
| 590 | |
| 591 | // VS = 1 |
| 592 | devcb_call_write_line(&m_out_vs_func, 1); |
| 593 | |
| 594 | // CBLANK = 1 |
| 595 | devcb_call_write_line(&m_out_cblank_func, 0); |
| 596 | |
| 597 | // CURS = 0 |
| 598 | devcb_call_write_line(&m_out_curs_func, 0); |
| 599 | |
| 600 | // VLT = 0 |
| 601 | devcb_call_write_line(&m_out_vlt_func, 0); |
| 602 | |
| 603 | // DRB = 1 |
| 604 | devcb_call_write_line(&m_out_drb_func, 1); |
| 605 | |
| 606 | // INT = 0 |
| 607 | devcb_call_write_line(&m_out_int_func, CLEAR_LINE); |
| 608 | |
| 609 | // 28 (DMAR) = 0 |
| 610 | devcb_call_write_line(&m_out_dmar_func, CLEAR_LINE); |
| 611 | |
| 612 | // 29 (WBEN) = 0 |
| 613 | |
| 614 | // 30 (SLG) = 0 |
| 615 | devcb_call_write_line(&m_out_slg_func, 0); |
| 616 | |
| 617 | // 31 (SLD) = 0 |
| 618 | devcb_call_write_line(&m_out_sld_func, 0); |
| 619 | |
| 620 | // 32 (LPSTB) = 0 |
| 621 | } |
| 622 | |
| 623 | |
| 624 | //------------------------------------------------- |
| 625 | // device_clock_changed - handle clock change |
| 626 | //------------------------------------------------- |
| 627 | |
| 628 | void crt9007_device::device_clock_changed() |
| 629 | { |
| 630 | recompute_parameters(); |
| 631 | } |
| 632 | |
| 633 | |
| 634 | //------------------------------------------------- |
| 635 | // device_timer - handle timer events |
| 636 | //------------------------------------------------- |
| 637 | |
| 638 | void crt9007_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 639 | { |
| 640 | int x = m_screen->hpos(); |
| 641 | int y = m_screen->vpos(); |
| 642 | |
| 643 | switch (id) |
| 644 | { |
| 645 | case TIMER_HSYNC: |
| 646 | m_hs = param; |
| 647 | |
| 648 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : HS %u\n", tag(), y, x, m_hs); |
| 649 | |
| 650 | devcb_call_write_line(&m_out_hs_func, m_hs); |
| 651 | |
| 652 | update_cblank_line(); |
| 653 | |
| 654 | update_hsync_timer(param); |
| 655 | break; |
| 656 | |
| 657 | case TIMER_VSYNC: |
| 658 | m_vs = param; |
| 659 | |
| 660 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : VS %u\n", tag(), y, x, m_vs); |
| 661 | |
| 662 | devcb_call_write_line(&m_out_vs_func, param); |
| 663 | |
| 664 | if (m_vs) |
| 665 | { |
| 666 | // reset all other bits except Light Pen Update to logic 0 |
| 667 | m_status &= STATUS_LIGHT_PEN_UPDATE; |
| 668 | } |
| 669 | else |
| 670 | { |
| 671 | trigger_interrupt(IE_VERTICAL_RETRACE); |
| 672 | |
| 673 | update_cblank_line(); |
| 674 | } |
| 675 | |
| 676 | update_vsync_timer(param); |
| 677 | break; |
| 678 | |
| 679 | case TIMER_VLT: |
| 680 | m_vlt = param; |
| 681 | |
| 682 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : VLT %u\n", tag(), y, x, m_vlt); |
| 683 | |
| 684 | devcb_call_write_line(&m_out_vlt_func, param); |
| 685 | |
| 686 | update_vlt_timer(param); |
| 687 | break; |
| 688 | |
| 689 | case TIMER_CURS: |
| 690 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : CURS %u\n", tag(), y, x, param); |
| 691 | |
| 692 | devcb_call_write_line(&m_out_curs_func, param); |
| 693 | |
| 694 | update_curs_timer(param); |
| 695 | break; |
| 696 | |
| 697 | case TIMER_DRB: |
| 698 | m_drb = param; |
| 699 | |
| 700 | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : DRB %u\n", tag(), y, x, m_drb); |
| 701 | |
| 702 | devcb_call_write_line(&m_out_drb_func, param); |
| 703 | |
| 704 | if (!m_drb && !DMA_DISABLE) |
| 705 | { |
| 706 | // start DMA burst sequence |
| 707 | m_dma_count = CHARACTERS_PER_DATA_ROW; |
| 708 | m_dma_burst = DMA_BURST_COUNT ? (DMA_BURST_COUNT * 4) : CHARACTERS_PER_DATA_ROW; |
| 709 | m_dma_delay = DMA_BURST_DELAY; |
| 710 | m_dmar = 1; |
| 711 | |
| 712 | if (LOG) logerror("CRT9007 '%s' DMAR 1\n", tag()); |
| 713 | devcb_call_write_line(&m_out_dmar_func, ASSERT_LINE); |
| 714 | } |
| 715 | |
| 716 | update_drb_timer(param); |
| 717 | break; |
| 718 | |
| 719 | case TIMER_DMA: |
| 720 | readbyte(AUXILIARY_ADDRESS_2); |
| 721 | |
| 722 | update_dma_timer(); |
| 723 | break; |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | |
| 728 | //------------------------------------------------- |
| 729 | // read - register read |
| 730 | //------------------------------------------------- |
| 731 | |
| 732 | READ8_MEMBER( crt9007_device::read ) |
| 733 | { |
| 734 | UINT8 data = 0; |
| 735 | |
| 736 | switch (offset) |
| 737 | { |
| 738 | case 0x15: |
| 739 | if (LOG) logerror("CRT9007 '%s' Start\n", tag()); |
| 740 | m_disp = 1; |
| 741 | break; |
| 742 | |
| 743 | case 0x16: |
| 744 | if (LOG) logerror("CRT9007 '%s' Reset\n", tag()); |
| 745 | device_reset(); |
| 746 | break; |
| 747 | |
| 748 | case 0x38: |
| 749 | data = VERTICAL_CURSOR; |
| 750 | break; |
| 751 | |
| 752 | case 0x39: |
| 753 | data = HORIZONTAL_CURSOR; |
| 754 | break; |
| 755 | |
| 756 | case 0x3a: |
| 757 | data = m_status; |
| 758 | |
| 759 | // reset interrupt pending bit |
| 760 | m_status &= ~STATUS_INTERRUPT_PENDING; |
| 761 | if (LOG) logerror("CRT9007 '%s' INT 0\n", tag()); |
| 762 | devcb_call_write_line(&m_out_int_func, CLEAR_LINE); |
| 763 | break; |
| 764 | |
| 765 | case 0x3b: |
| 766 | data = VERTICAL_LIGHT_PEN; |
| 767 | break; |
| 768 | |
| 769 | case 0x3c: |
| 770 | data = HORIZONTAL_LIGHT_PEN; |
| 771 | |
| 772 | // reset light pen update bit |
| 773 | m_status &= ~STATUS_LIGHT_PEN_UPDATE; |
| 774 | break; |
| 775 | |
| 776 | default: |
| 777 | logerror("CRT9007 '%s' Read from Invalid Register: %02x!\n", tag(), offset); |
| 778 | } |
| 779 | |
| 780 | return data; |
| 781 | } |
| 782 | |
| 783 | |
| 784 | //------------------------------------------------- |
| 785 | // write - register write |
| 786 | //------------------------------------------------- |
| 787 | |
| 788 | WRITE8_MEMBER( crt9007_device::write ) |
| 789 | { |
| 790 | m_reg[offset] = data; |
| 791 | |
| 792 | switch (offset) |
| 793 | { |
| 794 | case 0x00: |
| 795 | recompute_parameters(); |
| 796 | if (LOG) logerror("CRT9007 '%s' Characters per Horizontal Period: %u\n", tag(), CHARACTERS_PER_HORIZONTAL_PERIOD); |
| 797 | break; |
| 798 | |
| 799 | case 0x01: |
| 800 | recompute_parameters(); |
| 801 | if (LOG) logerror("CRT9007 '%s' Characters per Data Row: %u\n", tag(), CHARACTERS_PER_DATA_ROW); |
| 802 | break; |
| 803 | |
| 804 | case 0x02: |
| 805 | recompute_parameters(); |
| 806 | if (LOG) logerror("CRT9007 '%s' Horizontal Delay: %u\n", tag(), HORIZONTAL_DELAY); |
| 807 | break; |
| 808 | |
| 809 | case 0x03: |
| 810 | recompute_parameters(); |
| 811 | if (LOG) logerror("CRT9007 '%s' Horizontal Sync Width: %u\n", tag(), HORIZONTAL_SYNC_WIDTH); |
| 812 | break; |
| 813 | |
| 814 | case 0x04: |
| 815 | recompute_parameters(); |
| 816 | if (LOG) logerror("CRT9007 '%s' Vertical Sync Width: %u\n", tag(), VERTICAL_SYNC_WIDTH); |
| 817 | break; |
| 818 | |
| 819 | case 0x05: |
| 820 | recompute_parameters(); |
| 821 | if (LOG) logerror("CRT9007 '%s' Vertical Delay: %u\n", tag(), VERTICAL_DELAY); |
| 822 | break; |
| 823 | |
| 824 | case 0x06: |
| 825 | recompute_parameters(); |
| 826 | if (LOG) |
| 827 | { |
| 828 | logerror("CRT9007 '%s' Pin Configuration: %u\n", tag(), PIN_CONFIGURATION); |
| 829 | logerror("CRT9007 '%s' Cursor Skew: %u\n", tag(), CURSOR_SKEW); |
| 830 | logerror("CRT9007 '%s' Blank Skew: %u\n", tag(), BLANK_SKEW); |
| 831 | } |
| 832 | break; |
| 833 | |
| 834 | case 0x07: |
| 835 | recompute_parameters(); |
| 836 | if (LOG) logerror("CRT9007 '%s' Visible Data Rows per Frame: %u\n", tag(), VISIBLE_DATA_ROWS_PER_FRAME); |
| 837 | break; |
| 838 | |
| 839 | case 0x08: |
| 840 | recompute_parameters(); |
| 841 | if (LOG) logerror("CRT9007 '%s' Scan Lines per Data Row: %u\n", tag(), SCAN_LINES_PER_DATA_ROW); |
| 842 | break; |
| 843 | |
| 844 | case 0x09: |
| 845 | recompute_parameters(); |
| 846 | if (LOG) logerror("CRT9007 '%s' Scan Lines per Frame: %u\n", tag(), SCAN_LINES_PER_FRAME); |
| 847 | break; |
| 848 | |
| 849 | case 0x0a: |
| 850 | if (LOG) |
| 851 | { |
| 852 | logerror("CRT9007 '%s' DMA Burst Count: %u\n", tag(), DMA_BURST_COUNT); |
| 853 | logerror("CRT9007 '%s' DMA Burst Delay: %u\n", tag(), DMA_BURST_DELAY); |
| 854 | logerror("CRT9007 '%s' DMA Disable: %u\n", tag(), DMA_DISABLE); |
| 855 | } |
| 856 | break; |
| 857 | |
| 858 | case 0x0b: |
| 859 | if (LOG) |
| 860 | { |
| 861 | logerror("CRT9007 '%s' %s Height Cursor\n", tag(), SINGLE_HEIGHT_CURSOR ? "Single" : "Double"); |
| 862 | logerror("CRT9007 '%s' Operation Mode: %u\n", tag(), OPERATION_MODE); |
| 863 | logerror("CRT9007 '%s' Interlace Mode: %u\n", tag(), INTERLACE_MODE); |
| 864 | logerror("CRT9007 '%s' %s Mechanism\n", tag(), PAGE_BLANK ? "Page Blank" : "Smooth Scroll"); |
| 865 | } |
| 866 | break; |
| 867 | |
| 868 | case 0x0c: |
| 869 | break; |
| 870 | |
| 871 | case 0x0d: |
| 872 | if (LOG) |
| 873 | { |
| 874 | logerror("CRT9007 '%s' Table Start Register: %04x\n", tag(), TABLE_START); |
| 875 | logerror("CRT9007 '%s' Address Mode: %u\n", tag(), ADDRESS_MODE); |
| 876 | } |
| 877 | break; |
| 878 | |
| 879 | case 0x0e: |
| 880 | break; |
| 881 | |
| 882 | case 0x0f: |
| 883 | if (LOG) |
| 884 | { |
| 885 | logerror("CRT9007 '%s' Auxialiary Address Register 1: %04x\n", tag(), AUXILIARY_ADDRESS_1); |
| 886 | logerror("CRT9007 '%s' Row Attributes: %u\n", tag(), ROW_ATTRIBUTES_1); |
| 887 | } |
| 888 | break; |
| 889 | |
| 890 | case 0x10: |
| 891 | if (LOG) logerror("CRT9007 '%s' Sequential Break Register 1: %u\n", tag(), SEQUENTIAL_BREAK_1); |
| 892 | break; |
| 893 | |
| 894 | case 0x11: |
| 895 | if (LOG) logerror("CRT9007 '%s' Data Row Start Register: %u\n", tag(), DATA_ROW_START); |
| 896 | break; |
| 897 | |
| 898 | case 0x12: |
| 899 | if (LOG) logerror("CRT9007 '%s' Data Row End/Sequential Break Register 2: %u\n", tag(), SEQUENTIAL_BREAK_2); |
| 900 | break; |
| 901 | |
| 902 | case 0x13: |
| 903 | break; |
| 904 | |
| 905 | case 0x14: |
| 906 | if (LOG) |
| 907 | { |
| 908 | logerror("CRT9007 '%s' Auxiliary Address Register 2: %04x\n", tag(), AUXILIARY_ADDRESS_2); |
| 909 | logerror("CRT9007 '%s' Row Attributes: %u\n", tag(), ROW_ATTRIBUTES_2); |
| 910 | } |
| 911 | break; |
| 912 | |
| 913 | case 0x15: |
| 914 | if (LOG) logerror("CRT9007 '%s' Start\n", tag()); |
| 915 | m_disp = 1; |
| 916 | break; |
| 917 | |
| 918 | case 0x16: |
| 919 | if (LOG) logerror("CRT9007 '%s' Reset\n", tag()); |
| 920 | device_reset(); |
| 921 | break; |
| 922 | |
| 923 | case 0x17: |
| 924 | if (LOG) |
| 925 | { |
| 926 | logerror("CRT9007 '%s' Smooth Scroll Offset: %u\n", tag(), SMOOTH_SCROLL_OFFSET); |
| 927 | logerror("CRT9007 '%s' Smooth Scroll Offset Overflow: %u\n", tag(), SMOOTH_SCROLL_OFFSET_OVERFLOW); |
| 928 | } |
| 929 | break; |
| 930 | |
| 931 | case 0x18: |
| 932 | if (LOG) logerror("CRT9007 '%s' Vertical Cursor Register: %u\n", tag(), VERTICAL_CURSOR); |
| 933 | break; |
| 934 | |
| 935 | case 0x19: |
| 936 | if (LOG) logerror("CRT9007 '%s' Horizontal Cursor Register: %u\n", tag(), HORIZONTAL_CURSOR); |
| 937 | break; |
| 938 | |
| 939 | case 0x1a: |
| 940 | if (LOG) |
| 941 | { |
| 942 | logerror("CRT9007 '%s' Frame Timer: %u\n", tag(), FRAME_TIMER); |
| 943 | logerror("CRT9007 '%s' Light Pen Interrupt: %u\n", tag(), LIGHT_PEN_INTERRUPT); |
| 944 | logerror("CRT9007 '%s' Vertical Retrace Interrupt: %u\n", tag(), VERTICAL_RETRACE_INTERRUPT); |
| 945 | } |
| 946 | break; |
| 947 | |
| 948 | default: |
| 949 | logerror("CRT9007 '%s' Write to Invalid Register: %02x!\n", tag(), offset); |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | |
| 954 | //------------------------------------------------- |
| 955 | // ack_w - DMA acknowledge |
| 956 | //------------------------------------------------- |
| 957 | |
| 958 | WRITE_LINE_MEMBER( crt9007_device::ack_w ) |
| 959 | { |
| 960 | if (LOG) logerror("CRT9007 '%s' ACK: %u\n", tag(), state); |
| 961 | |
| 962 | if (m_dmar && !m_ack && state) |
| 963 | { |
| 964 | // start DMA transfer |
| 965 | m_dma_timer->adjust(attotime::from_hz(clock())); |
| 966 | } |
| 967 | |
| 968 | m_ack = state; |
| 969 | } |
| 970 | |
| 971 | |
| 972 | //------------------------------------------------- |
| 973 | // lpstb_w - light pen strobe |
| 974 | //------------------------------------------------- |
| 975 | |
| 976 | WRITE_LINE_MEMBER( crt9007_device::lpstb_w ) |
| 977 | { |
| 978 | if (LOG) logerror("CRT9007 '%s' LPSTB: %u\n", tag(), state); |
| 979 | |
| 980 | if (!m_lpstb && state) |
| 981 | { |
| 982 | // TODO latch current row/column position |
| 983 | } |
| 984 | |
| 985 | m_lpstb = state; |
| 986 | } |
| 987 | |
| 988 | |
| 989 | //------------------------------------------------- |
| 990 | // vlt_r - |
| 991 | //------------------------------------------------- |
| 992 | |
| 993 | READ_LINE_MEMBER( crt9007_device::vlt_r ) |
| 994 | { |
| 995 | return m_vlt; |
| 996 | } |
| 997 | |
| 998 | |
| 999 | //------------------------------------------------- |
| 1000 | // wben_r - |
| 1001 | //------------------------------------------------- |
| 1002 | |
| 1003 | READ_LINE_MEMBER( crt9007_device::wben_r ) |
| 1004 | { |
| 1005 | return m_wben; |
| 1006 | } |
| 1007 | |
| 1008 | |
| 1009 | //------------------------------------------------- |
| 1010 | // set_hpixels_per_column - |
| 1011 | //------------------------------------------------- |
| 1012 | |
| 1013 | void crt9007_device::set_hpixels_per_column(int hpixels_per_column) |
| 1014 | { |
| 1015 | m_hpixels_per_column = hpixels_per_column; |
| 1016 | recompute_parameters(); |
| 1017 | } |
src/emu/video/crt9007.h
| r0 | r10969 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | SMC CRT9007 CRT Video Processor and Controller (VPAC) emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | ********************************************************************** |
| 9 | _____ _____ |
| 10 | VA2 1 |* \_/ | 40 GND |
| 11 | VA10 2 | | 39 VA9 |
| 12 | VA3 3 | | 38 VA1 |
| 13 | VA11 4 | | 37 VA8 |
| 14 | VA12 5 | | 36 VA0 |
| 15 | VA4 6 | | 35 CBLANK |
| 16 | VA13 7 | | 34 CURS |
| 17 | VA5 8 | | 33 ACK/_TSC |
| 18 | VA6 9 | | 32 _CSYNC/LPSTB |
| 19 | VA7 10 | CRT9007 | 31 SLD/SL0 |
| 20 | VLT 11 | | 30 _SLG/SL1 |
| 21 | _VS 12 | | 29 WBEN/SL2/_CSYNC |
| 22 | _HS 13 | | 28 DMAR/SL3/VBLANK |
| 23 | _CCLK 14 | | 27 INT |
| 24 | _DRB 15 | | 26 _RST |
| 25 | VD7 16 | | 25 _CS |
| 26 | VD6 17 | | 24 VD0 |
| 27 | VD5 18 | | 23 VD1 |
| 28 | VD4 19 | | 22 VD2 |
| 29 | VD3 20 |_____________| 21 +5V |
| 30 | |
| 31 | **********************************************************************/ |
| 32 | |
| 33 | #pragma once |
| 34 | |
| 35 | #ifndef __CRT9007__ |
| 36 | #define __CRT9007__ |
| 37 | |
| 38 | #include "emu.h" |
| 39 | |
| 40 | |
| 41 | |
| 42 | //************************************************************************** |
| 43 | // MACROS / CONSTANTS |
| 44 | //************************************************************************** |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | //************************************************************************** |
| 50 | // INTERFACE CONFIGURATION MACROS |
| 51 | //************************************************************************** |
| 52 | |
| 53 | #define MCFG_CRT9007_ADD(_tag, _clock, _config, _map) \ |
| 54 | MCFG_DEVICE_ADD(_tag, CRT9007, _clock) \ |
| 55 | MCFG_DEVICE_CONFIG(_config) \ |
| 56 | MCFG_DEVICE_ADDRESS_MAP(AS_0, _map) |
| 57 | |
| 58 | |
| 59 | #define CRT9007_INTERFACE(name) \ |
| 60 | const crt9007_interface (name) = |
| 61 | |
| 62 | |
| 63 | |
| 64 | //************************************************************************** |
| 65 | // TYPE DEFINITIONS |
| 66 | //************************************************************************** |
| 67 | |
| 68 | |
| 69 | // ======================> crt9007_interface |
| 70 | |
| 71 | struct crt9007_interface |
| 72 | { |
| 73 | const char *screen_tag; /* screen we are acting on */ |
| 74 | int hpixels_per_column; /* number of pixels per video memory address */ |
| 75 | |
| 76 | devcb_write_line out_int_func; |
| 77 | devcb_write_line out_dmar_func; |
| 78 | |
| 79 | devcb_write_line out_vs_func; |
| 80 | devcb_write_line out_hs_func; |
| 81 | |
| 82 | devcb_write_line out_vlt_func; |
| 83 | devcb_write_line out_curs_func; |
| 84 | devcb_write_line out_drb_func; |
| 85 | devcb_write_line out_cblank_func; |
| 86 | |
| 87 | devcb_write_line out_slg_func; |
| 88 | devcb_write_line out_sld_func; |
| 89 | }; |
| 90 | |
| 91 | |
| 92 | |
| 93 | // ======================> crt9007_device_config |
| 94 | |
| 95 | class crt9007_device_config : public device_config, |
| 96 | public device_config_memory_interface, |
| 97 | public crt9007_interface |
| 98 | { |
| 99 | friend class crt9007_device; |
| 100 | |
| 101 | // construction/destruction |
| 102 | crt9007_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 103 | |
| 104 | public: |
| 105 | // allocators |
| 106 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 107 | virtual device_t *alloc_device(running_machine &machine) const; |
| 108 | |
| 109 | protected: |
| 110 | // device_config overrides |
| 111 | virtual void device_config_complete(); |
| 112 | |
| 113 | // device_config_memory_interface overrides |
| 114 | virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const; |
| 115 | |
| 116 | // address space configurations |
| 117 | const address_space_config m_space_config; |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | |
| 122 | // ======================> crt9007_device |
| 123 | |
| 124 | class crt9007_device : public device_t, |
| 125 | public device_memory_interface |
| 126 | { |
| 127 | friend class crt9007_device_config; |
| 128 | |
| 129 | // construction/destruction |
| 130 | crt9007_device(running_machine &_machine, const crt9007_device_config &_config); |
| 131 | |
| 132 | public: |
| 133 | DECLARE_READ8_MEMBER( read ); |
| 134 | DECLARE_WRITE8_MEMBER( write ); |
| 135 | DECLARE_WRITE_LINE_MEMBER( ack_w ); |
| 136 | DECLARE_WRITE_LINE_MEMBER( lpstb_w ); |
| 137 | DECLARE_READ_LINE_MEMBER( vlt_r ); |
| 138 | DECLARE_READ_LINE_MEMBER( wben_r ); |
| 139 | |
| 140 | void set_hpixels_per_column(int hpixels_per_column); |
| 141 | |
| 142 | protected: |
| 143 | // device-level overrides |
| 144 | virtual void device_start(); |
| 145 | virtual void device_reset(); |
| 146 | virtual void device_clock_changed(); |
| 147 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 148 | |
| 149 | private: |
| 150 | static const device_timer_id TIMER_HSYNC = 0; |
| 151 | static const device_timer_id TIMER_VSYNC = 1; |
| 152 | static const device_timer_id TIMER_VLT = 2; |
| 153 | static const device_timer_id TIMER_CURS = 3; |
| 154 | static const device_timer_id TIMER_DRB = 4; |
| 155 | static const device_timer_id TIMER_DMA = 5; |
| 156 | |
| 157 | inline UINT8 readbyte(offs_t address); |
| 158 | |
| 159 | inline void trigger_interrupt(int line); |
| 160 | inline void update_cblank_line(); |
| 161 | inline void update_hsync_timer(int state); |
| 162 | inline void update_vsync_timer(int state); |
| 163 | inline void update_vlt_timer(int state); |
| 164 | inline void update_curs_timer(int state); |
| 165 | inline void update_drb_timer(int state); |
| 166 | inline void update_dma_timer(); |
| 167 | |
| 168 | inline void recompute_parameters(); |
| 169 | |
| 170 | devcb_resolved_write_line m_out_int_func; |
| 171 | devcb_resolved_write_line m_out_dmar_func; |
| 172 | devcb_resolved_write_line m_out_hs_func; |
| 173 | devcb_resolved_write_line m_out_vs_func; |
| 174 | devcb_resolved_write_line m_out_vlt_func; |
| 175 | devcb_resolved_write_line m_out_curs_func; |
| 176 | devcb_resolved_write_line m_out_drb_func; |
| 177 | devcb_resolved_write_line m_out_cblank_func; |
| 178 | devcb_resolved_write_line m_out_slg_func; |
| 179 | devcb_resolved_write_line m_out_sld_func; |
| 180 | |
| 181 | screen_device *m_screen; |
| 182 | |
| 183 | // registers |
| 184 | UINT8 m_reg[0x3d]; |
| 185 | UINT8 m_status; |
| 186 | |
| 187 | int m_disp; |
| 188 | int m_hpixels_per_column; |
| 189 | |
| 190 | // runtime variables, do not state save |
| 191 | int m_vsync_start; |
| 192 | int m_vsync_end; |
| 193 | int m_hsync_start; |
| 194 | int m_hsync_end; |
| 195 | int m_vlt_start; |
| 196 | int m_vlt_end; |
| 197 | int m_vlt_bottom; |
| 198 | int m_drb_bottom; |
| 199 | int m_hs; |
| 200 | int m_vs; |
| 201 | int m_cblank; |
| 202 | int m_vlt; |
| 203 | int m_drb; |
| 204 | int m_wben; |
| 205 | int m_slg; |
| 206 | int m_sld; |
| 207 | int m_lpstb; |
| 208 | |
| 209 | // DMA |
| 210 | int m_dmar; |
| 211 | int m_ack; |
| 212 | int m_dma_count; |
| 213 | int m_dma_burst; |
| 214 | int m_dma_delay; |
| 215 | |
| 216 | // timers |
| 217 | emu_timer *m_vsync_timer; |
| 218 | emu_timer *m_hsync_timer; |
| 219 | emu_timer *m_vlt_timer; |
| 220 | emu_timer *m_curs_timer; |
| 221 | emu_timer *m_drb_timer; |
| 222 | emu_timer *m_dma_timer; |
| 223 | |
| 224 | const crt9007_device_config &m_config; |
| 225 | }; |
| 226 | |
| 227 | |
| 228 | // device type definition |
| 229 | extern const device_type CRT9007; |
| 230 | |
| 231 | |
| 232 | |
| 233 | #endif |
src/emu/video/hd61830.c
| r0 | r10969 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | HD61830 LCD Timing Controller emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #include "emu.h" |
| 11 | #include "hd61830.h" |
| 12 | |
| 13 | |
| 14 | |
| 15 | //************************************************************************** |
| 16 | // MACROS / CONSTANTS |
| 17 | //************************************************************************** |
| 18 | |
| 19 | #define LOG 0 |
| 20 | |
| 21 | enum |
| 22 | { |
| 23 | INSTRUCTION_MODE_CONTROL = 0, |
| 24 | INSTRUCTION_CHARACTER_PITCH, |
| 25 | INSTRUCTION_NUMBER_OF_CHARACTERS, |
| 26 | INSTRUCTION_NUMBER_OF_TIME_DIVISIONS, |
| 27 | INSTRUCTION_CURSOR_POSITION, |
| 28 | INSTRUCTION_DISPLAY_START_LOW = 8, |
| 29 | INSTRUCTION_DISPLAY_START_HIGH, |
| 30 | INSTRUCTION_CURSOR_ADDRESS_LOW, |
| 31 | INSTRUCTION_CURSOR_ADDRESS_HIGH, |
| 32 | INSTRUCTION_DISPLAY_DATA_WRITE, |
| 33 | INSTRUCTION_DISPLAY_DATA_READ, |
| 34 | INSTRUCTION_CLEAR_BIT, |
| 35 | INSTRUCTION_SET_BIT |
| 36 | }; |
| 37 | |
| 38 | static const int CYCLES[] = |
| 39 | { |
| 40 | 4, 4, 4, 4, 4, -1, -1, -1, 4, 4, 4, 4, 6, 6, 36, 36 |
| 41 | }; |
| 42 | |
| 43 | const int MODE_EXTERNAL_CG = 0x01; |
| 44 | const int MODE_GRAPHIC = 0x02; |
| 45 | const int MODE_CURSOR = 0x04; |
| 46 | const int MODE_BLINK = 0x08; |
| 47 | const int MODE_MASTER = 0x10; |
| 48 | const int MODE_DISPLAY_ON = 0x20; |
| 49 | |
| 50 | |
| 51 | |
| 52 | //************************************************************************** |
| 53 | // GLOBAL VARIABLES |
| 54 | //************************************************************************** |
| 55 | |
| 56 | // devices |
| 57 | const device_type HD61830 = hd61830_device_config::static_alloc_device_config; |
| 58 | |
| 59 | |
| 60 | // default address map |
| 61 | static ADDRESS_MAP_START( hd61830, AS_0, 8 ) |
| 62 | AM_RANGE(0x0000, 0xffff) AM_RAM |
| 63 | ADDRESS_MAP_END |
| 64 | |
| 65 | |
| 66 | // internal character generator ROM |
| 67 | ROM_START( hd61830 ) |
| 68 | ROM_REGION( 0x5c0, "hd61830", ROMREGION_LOADBYNAME ) // internal 7360-bit chargen ROM |
| 69 | ROM_LOAD( "hd61830.bin", 0x000, 0x5c0, BAD_DUMP CRC(06a934da) SHA1(bf3f074db5dc92e6f530cb18d6c013563099a87d) ) // typed in from manual |
| 70 | ROM_END |
| 71 | |
| 72 | |
| 73 | |
| 74 | //************************************************************************** |
| 75 | // DEVICE CONFIGURATION |
| 76 | //************************************************************************** |
| 77 | |
| 78 | //------------------------------------------------- |
| 79 | // hd61830_device_config - constructor |
| 80 | //------------------------------------------------- |
| 81 | |
| 82 | hd61830_device_config::hd61830_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 83 | : device_config(mconfig, static_alloc_device_config, "Hitachi HD61830", tag, owner, clock), |
| 84 | device_config_memory_interface(mconfig, *this), |
| 85 | m_space_config("videoram", ENDIANNESS_LITTLE, 8, 16, 0, NULL, *ADDRESS_MAP_NAME(hd61830)) |
| 86 | { |
| 87 | m_shortname = "hd61830"; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | //------------------------------------------------- |
| 92 | // static_alloc_device_config - allocate a new |
| 93 | // configuration object |
| 94 | //------------------------------------------------- |
| 95 | |
| 96 | device_config *hd61830_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 97 | { |
| 98 | return global_alloc(hd61830_device_config(mconfig, tag, owner, clock)); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | //------------------------------------------------- |
| 103 | // alloc_device - allocate a new device object |
| 104 | //------------------------------------------------- |
| 105 | |
| 106 | device_t *hd61830_device_config::alloc_device(running_machine &machine) const |
| 107 | { |
| 108 | return auto_alloc(&machine, hd61830_device(machine, *this)); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | //------------------------------------------------- |
| 113 | // memory_space_config - return a description of |
| 114 | // any address spaces owned by this device |
| 115 | //------------------------------------------------- |
| 116 | |
| 117 | const address_space_config *hd61830_device_config::memory_space_config(address_spacenum spacenum) const |
| 118 | { |
| 119 | return (spacenum == AS_0) ? &m_space_config : NULL; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | //------------------------------------------------- |
| 124 | // rom_region - device-specific ROM region |
| 125 | //------------------------------------------------- |
| 126 | |
| 127 | const rom_entry *hd61830_device_config::rom_region() const |
| 128 | { |
| 129 | return ROM_NAME(hd61830); |
| 130 | } |
| 131 | |
| 132 | |
| 133 | //------------------------------------------------- |
| 134 | // device_config_complete - perform any |
| 135 | // operations now that the configuration is |
| 136 | // complete |
| 137 | //------------------------------------------------- |
| 138 | |
| 139 | void hd61830_device_config::device_config_complete() |
| 140 | { |
| 141 | // inherit a copy of the static data |
| 142 | const hd61830_interface *intf = reinterpret_cast<const hd61830_interface *>(static_config()); |
| 143 | if (intf != NULL) |
| 144 | *static_cast<hd61830_interface *>(this) = *intf; |
| 145 | |
| 146 | // or initialize to defaults if none provided |
| 147 | else |
| 148 | { |
| 149 | memset(&m_in_rd_func, 0, sizeof(m_in_rd_func)); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | |
| 154 | |
| 155 | //************************************************************************** |
| 156 | // INLINE HELPERS |
| 157 | //************************************************************************** |
| 158 | |
| 159 | //------------------------------------------------- |
| 160 | // readbyte - read a byte at the given address |
| 161 | //------------------------------------------------- |
| 162 | |
| 163 | inline UINT8 hd61830_device::readbyte(offs_t address) |
| 164 | { |
| 165 | return space()->read_byte(address); |
| 166 | } |
| 167 | |
| 168 | |
| 169 | //------------------------------------------------- |
| 170 | // writebyte - write a byte at the given address |
| 171 | //------------------------------------------------- |
| 172 | |
| 173 | inline void hd61830_device::writebyte(offs_t address, UINT8 data) |
| 174 | { |
| 175 | space()->write_byte(address, data); |
| 176 | } |
| 177 | |
| 178 | |
| 179 | |
| 180 | //************************************************************************** |
| 181 | // LIVE DEVICE |
| 182 | //************************************************************************** |
| 183 | |
| 184 | //------------------------------------------------- |
| 185 | // hd61830_device - constructor |
| 186 | //------------------------------------------------- |
| 187 | |
| 188 | hd61830_device::hd61830_device(running_machine &_machine, const hd61830_device_config &config) |
| 189 | : device_t(_machine, config), |
| 190 | device_memory_interface(_machine, config, *this), |
| 191 | m_bf(false), |
| 192 | m_blink(0), |
| 193 | m_config(config) |
| 194 | { |
| 195 | |
| 196 | } |
| 197 | |
| 198 | |
| 199 | //------------------------------------------------- |
| 200 | // device_start - device-specific startup |
| 201 | //------------------------------------------------- |
| 202 | |
| 203 | void hd61830_device::device_start() |
| 204 | { |
| 205 | // allocate timers |
| 206 | m_busy_timer = timer_alloc(); |
| 207 | |
| 208 | // resolve callbacks |
| 209 | devcb_resolve_read8(&m_in_rd_func, &m_config.m_in_rd_func, this); |
| 210 | |
| 211 | m_screen = machine->device<screen_device>(m_config.screen_tag); |
| 212 | |
| 213 | // register for state saving |
| 214 | save_item(NAME(m_bf)); |
| 215 | save_item(NAME(m_ir)); |
| 216 | save_item(NAME(m_mcr)); |
| 217 | save_item(NAME(m_dor)); |
| 218 | save_item(NAME(m_cac)); |
| 219 | save_item(NAME(m_dsa)); |
| 220 | save_item(NAME(m_vp)); |
| 221 | save_item(NAME(m_hp)); |
| 222 | save_item(NAME(m_hn)); |
| 223 | save_item(NAME(m_nx)); |
| 224 | save_item(NAME(m_cp)); |
| 225 | save_item(NAME(m_blink)); |
| 226 | save_item(NAME(m_cursor)); |
| 227 | } |
| 228 | |
| 229 | |
| 230 | //------------------------------------------------- |
| 231 | // device_reset - device-specific reset |
| 232 | //------------------------------------------------- |
| 233 | |
| 234 | void hd61830_device::device_reset() |
| 235 | { |
| 236 | // display off, slave mode |
| 237 | m_mcr &= ~(MODE_MASTER | MODE_DISPLAY_ON); |
| 238 | |
| 239 | // default horizontal pitch |
| 240 | m_hp = 6; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | //------------------------------------------------- |
| 245 | // device_timer - handler timer events |
| 246 | //------------------------------------------------- |
| 247 | |
| 248 | void hd61830_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 249 | { |
| 250 | // clear busy flag |
| 251 | m_bf = false; |
| 252 | } |
| 253 | |
| 254 | |
| 255 | /*------------------------------------------------- |
| 256 | set_busy_flag - set busy flag and arm timer |
| 257 | to clear it later |
| 258 | -------------------------------------------------*/ |
| 259 | |
| 260 | void hd61830_device::set_busy_flag() |
| 261 | { |
| 262 | // set busy flag |
| 263 | m_bf = true; |
| 264 | |
| 265 | // adjust busy timer |
| 266 | m_busy_timer->adjust(attotime::from_usec(CYCLES[m_ir])); |
| 267 | } |
| 268 | |
| 269 | |
| 270 | //------------------------------------------------- |
| 271 | // status_r - status register read |
| 272 | //------------------------------------------------- |
| 273 | |
| 274 | READ8_MEMBER( hd61830_device::status_r ) |
| 275 | { |
| 276 | if (LOG) logerror("HD61830 '%s' Status Read: %s\n", tag(), m_bf ? "busy" : "ready"); |
| 277 | |
| 278 | return m_bf ? 0x80 : 0; |
| 279 | } |
| 280 | |
| 281 | |
| 282 | //------------------------------------------------- |
| 283 | // control_w - instruction register write |
| 284 | //------------------------------------------------- |
| 285 | |
| 286 | WRITE8_MEMBER( hd61830_device::control_w ) |
| 287 | { |
| 288 | m_ir = data; |
| 289 | } |
| 290 | |
| 291 | |
| 292 | //------------------------------------------------- |
| 293 | // data_r - data register read |
| 294 | //------------------------------------------------- |
| 295 | |
| 296 | READ8_MEMBER( hd61830_device::data_r ) |
| 297 | { |
| 298 | UINT8 data = m_dor; |
| 299 | |
| 300 | if (LOG) logerror("HD61830 '%s' Display Data Read %02x\n", tag(), m_dor); |
| 301 | |
| 302 | m_dor = readbyte(m_cac); |
| 303 | |
| 304 | m_cac++; |
| 305 | |
| 306 | return data; |
| 307 | } |
| 308 | |
| 309 | |
| 310 | //------------------------------------------------- |
| 311 | // data_w - data register write |
| 312 | //------------------------------------------------- |
| 313 | |
| 314 | WRITE8_MEMBER( hd61830_device::data_w ) |
| 315 | { |
| 316 | if (m_bf) |
| 317 | { |
| 318 | logerror("HD61830 '%s' Ignoring data write %02x due to business\n", tag(), data); |
| 319 | return; |
| 320 | } |
| 321 | |
| 322 | switch (m_ir) |
| 323 | { |
| 324 | case INSTRUCTION_MODE_CONTROL: |
| 325 | m_mcr = data; |
| 326 | |
| 327 | if (LOG) |
| 328 | { |
| 329 | logerror("HD61830 '%s' %s CG\n", tag(), (data & MODE_EXTERNAL_CG) ? "External" : "Internal"); |
| 330 | logerror("HD61830 '%s' %s Display Mode\n", tag(), (data & MODE_GRAPHIC) ? "Graphic" : "Character"); |
| 331 | logerror("HD61830 '%s' %s Mode\n", tag(), (data & MODE_MASTER) ? "Master" : "Slave"); |
| 332 | logerror("HD61830 '%s' Cursor %s\n", tag(), (data & MODE_CURSOR) ? "On" : "Off"); |
| 333 | logerror("HD61830 '%s' Blink %s\n", tag(), (data & MODE_BLINK) ? "On" : "Off"); |
| 334 | logerror("HD61830 '%s' Display %s\n", tag(), (data & MODE_DISPLAY_ON) ? "On" : "Off"); |
| 335 | } |
| 336 | break; |
| 337 | |
| 338 | case INSTRUCTION_CHARACTER_PITCH: |
| 339 | m_hp = (data & 0x07) + 1; |
| 340 | m_vp = (data >> 4) + 1; |
| 341 | |
| 342 | if (LOG) logerror("HD61830 '%s' Horizontal Character Pitch: %u\n", tag(), m_hp); |
| 343 | if (LOG) logerror("HD61830 '%s' Vertical Character Pitch: %u\n", tag(), m_vp); |
| 344 | break; |
| 345 | |
| 346 | case INSTRUCTION_NUMBER_OF_CHARACTERS: |
| 347 | m_hn = (data & 0x7f) + 1; |
| 348 | |
| 349 | if (LOG) logerror("HD61830 '%s' Number of Characters: %u\n", tag(), m_hn); |
| 350 | break; |
| 351 | |
| 352 | case INSTRUCTION_NUMBER_OF_TIME_DIVISIONS: |
| 353 | m_nx = (data & 0x7f) + 1; |
| 354 | |
| 355 | if (LOG) logerror("HD61830 '%s' Number of Time Divisions: %u\n", tag(), m_nx); |
| 356 | break; |
| 357 | |
| 358 | case INSTRUCTION_CURSOR_POSITION: |
| 359 | m_cp = (data & 0x7f) + 1; |
| 360 | |
| 361 | if (LOG) logerror("HD61830 '%s' Cursor Position: %u\n", tag(), m_cp); |
| 362 | break; |
| 363 | |
| 364 | case INSTRUCTION_DISPLAY_START_LOW: |
| 365 | m_dsa = (m_dsa & 0xff00) | data; |
| 366 | |
| 367 | if (LOG) logerror("HD61830 '%s' Display Start Address Low %04x\n", tag(), m_dsa); |
| 368 | break; |
| 369 | |
| 370 | case INSTRUCTION_DISPLAY_START_HIGH: |
| 371 | m_dsa = (data << 8) | (m_dsa & 0xff); |
| 372 | |
| 373 | if (LOG) logerror("HD61830 '%s' Display Start Address High %04x\n", tag(), m_dsa); |
| 374 | break; |
| 375 | |
| 376 | case INSTRUCTION_CURSOR_ADDRESS_LOW: |
| 377 | if (BIT(m_cac, 7) && !BIT(data, 7)) |
| 378 | { |
| 379 | m_cac = (((m_cac >> 8) + 1) << 8) | data; |
| 380 | } |
| 381 | else |
| 382 | { |
| 383 | m_cac = (m_cac & 0xff00) | data; |
| 384 | } |
| 385 | |
| 386 | if (LOG) logerror("HD61830 '%s' Cursor Address Low %02x: %04x\n", tag(), data, m_cac); |
| 387 | break; |
| 388 | |
| 389 | case INSTRUCTION_CURSOR_ADDRESS_HIGH: |
| 390 | m_cac = (data << 8) | (m_cac & 0xff); |
| 391 | |
| 392 | if (LOG) logerror("HD61830 '%s' Cursor Address High %02x: %04x\n", tag(), data, m_cac); |
| 393 | break; |
| 394 | |
| 395 | case INSTRUCTION_DISPLAY_DATA_WRITE: |
| 396 | writebyte(m_cac, data); |
| 397 | |
| 398 | if (LOG) logerror("HD61830 '%s' Display Data Write %02x -> %04x row %u col %u\n", tag(), data, m_cac, m_cac / 40, m_cac % 40); |
| 399 | |
| 400 | m_cac++; |
| 401 | break; |
| 402 | |
| 403 | case INSTRUCTION_CLEAR_BIT: |
| 404 | { |
| 405 | int bit = data & 0x07; |
| 406 | UINT8 md = readbyte(m_cac); |
| 407 | |
| 408 | md &= ~(1 << bit); |
| 409 | |
| 410 | if (LOG) logerror("HD61830 '%s' Clear Bit %u at %04x\n", tag(), bit + 1, m_cac); |
| 411 | |
| 412 | writebyte(m_cac, md); |
| 413 | |
| 414 | m_cac++; |
| 415 | } |
| 416 | break; |
| 417 | |
| 418 | case INSTRUCTION_SET_BIT: |
| 419 | { |
| 420 | int bit = data & 0x07; |
| 421 | UINT8 md = readbyte(m_cac); |
| 422 | |
| 423 | md |= 1 << bit; |
| 424 | |
| 425 | if (LOG) logerror("HD61830 '%s' Set Bit %u at %04x\n", tag(), bit + 1, m_cac); |
| 426 | |
| 427 | writebyte(m_cac, md); |
| 428 | |
| 429 | m_cac++; |
| 430 | } |
| 431 | break; |
| 432 | |
| 433 | default: |
| 434 | logerror("HD61830 '%s' Illegal Instruction %02x!\n", tag(), m_ir); |
| 435 | return; |
| 436 | } |
| 437 | |
| 438 | // burn cycles |
| 439 | set_busy_flag(); |
| 440 | } |
| 441 | |
| 442 | |
| 443 | //------------------------------------------------- |
| 444 | // draw_scanline - draw one graphics scanline |
| 445 | //------------------------------------------------- |
| 446 | |
| 447 | void hd61830_device::draw_scanline(bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ra) |
| 448 | { |
| 449 | for (int sx = 0; sx < m_hn; sx++) |
| 450 | { |
| 451 | UINT8 data = readbyte(ra++); |
| 452 | |
| 453 | for (int x = 0; x < m_hp; x++) |
| 454 | { |
| 455 | *BITMAP_ADDR16(bitmap, y, (sx * m_hp) + x) = BIT(data, x); |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | |
| 461 | //------------------------------------------------- |
| 462 | // update_graphics - draw graphics mode screen |
| 463 | //------------------------------------------------- |
| 464 | |
| 465 | void hd61830_device::update_graphics(bitmap_t *bitmap, const rectangle *cliprect) |
| 466 | { |
| 467 | for (int y = 0; y < m_nx; y++) |
| 468 | { |
| 469 | UINT16 rac1 = m_dsa + (y * m_hn); |
| 470 | UINT16 rac2 = rac1 + (m_nx * m_hn); |
| 471 | |
| 472 | /* draw upper half scanline */ |
| 473 | draw_scanline(bitmap, cliprect, y, rac1); |
| 474 | |
| 475 | /* draw lower half scanline */ |
| 476 | draw_scanline(bitmap, cliprect, y + m_nx, rac2); |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | |
| 481 | //------------------------------------------------- |
| 482 | // draw_char - draw a char |
| 483 | //------------------------------------------------- |
| 484 | |
| 485 | void hd61830_device::draw_char(bitmap_t *bitmap, const rectangle *cliprect, UINT16 ma, int x, int y, UINT8 md) |
| 486 | { |
| 487 | for (int cl = 0; cl < m_vp; cl++) |
| 488 | { |
| 489 | for (int cr = 0; cr < m_hp; cr++) |
| 490 | { |
| 491 | int sy = y * m_vp + cl; |
| 492 | int sx = x * m_hp + cr; |
| 493 | UINT8 data = 0; |
| 494 | |
| 495 | if (m_mcr & MODE_EXTERNAL_CG) |
| 496 | { |
| 497 | data = devcb_call_read8(&m_in_rd_func, (cl << 12) | md); |
| 498 | } |
| 499 | else |
| 500 | { |
| 501 | UINT16 addr = 0; |
| 502 | |
| 503 | if (md >= 0x20 && md < 0x80 && cl < 7) |
| 504 | { |
| 505 | // 5x7 characters 0x20..0x7f |
| 506 | addr = (md - 0x20) * 7 + cl; |
| 507 | } |
| 508 | else if (md >= 0xa0 && md < 0xe0 && cl < 7) |
| 509 | { |
| 510 | // 5x7 characters 0xa0..0xdf |
| 511 | addr = 96*7 + (md - 0xa0) * 7 + cl; |
| 512 | } |
| 513 | else if (md >= 0xe0 && cl < 11) |
| 514 | { |
| 515 | // 5x11 characters 0xe0..0xff |
| 516 | addr = 160*7 + (md - 0xe0) * 11 + cl; |
| 517 | } |
| 518 | |
| 519 | data = subregion("hd61830")->u8(addr); |
| 520 | } |
| 521 | |
| 522 | int cursor = m_mcr & MODE_CURSOR; |
| 523 | int blink = m_mcr & MODE_BLINK; |
| 524 | |
| 525 | // cursor off |
| 526 | int pixel = BIT(data, cr); |
| 527 | |
| 528 | if (blink && (ma == m_cac)) |
| 529 | { |
| 530 | // cursor off, character blink |
| 531 | if (!cursor) |
| 532 | pixel = m_cursor ? pixel : 0; |
| 533 | |
| 534 | // cursor blink |
| 535 | if (cursor && (cl == m_cp)) |
| 536 | pixel = m_cursor ? 1 : 0; |
| 537 | } |
| 538 | else |
| 539 | { |
| 540 | // cursor on |
| 541 | if (cursor && (cl == m_cp)) |
| 542 | pixel = m_cursor ? 1 : 0; |
| 543 | } |
| 544 | |
| 545 | if (sy < m_screen->height() && sx < m_screen->width()) |
| 546 | *BITMAP_ADDR16(bitmap, sy, sx) = pixel; |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | |
| 552 | //------------------------------------------------- |
| 553 | // update_text - draw text mode screen |
| 554 | //------------------------------------------------- |
| 555 | |
| 556 | void hd61830_device::update_text(bitmap_t *bitmap, const rectangle *cliprect) |
| 557 | { |
| 558 | for (int y = 0; y < (m_nx / m_vp); y++) |
| 559 | { |
| 560 | for (int x = 0; x < m_hn; x++) |
| 561 | { |
| 562 | UINT16 ma = y * m_hn + x; |
| 563 | UINT8 md = readbyte(ma); |
| 564 | |
| 565 | draw_char(bitmap, cliprect, ma, x, y, md); |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | |
| 571 | //------------------------------------------------- |
| 572 | // update_screen - update screen |
| 573 | //------------------------------------------------- |
| 574 | |
| 575 | void hd61830_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect) |
| 576 | { |
| 577 | if (m_mcr & MODE_DISPLAY_ON) |
| 578 | { |
| 579 | if (m_mcr & MODE_GRAPHIC) |
| 580 | { |
| 581 | update_graphics(bitmap, cliprect); |
| 582 | } |
| 583 | else |
| 584 | { |
| 585 | update_text(bitmap, cliprect); |
| 586 | } |
| 587 | } |
| 588 | else |
| 589 | { |
| 590 | bitmap_fill(bitmap, cliprect, 0); |
| 591 | } |
| 592 | |
| 593 | m_blink++; |
| 594 | |
| 595 | if (m_blink == 0x20) |
| 596 | { |
| 597 | m_blink = 0; |
| 598 | m_cursor = !m_cursor; |
| 599 | } |
| 600 | } |
src/emu/video/crt9212.c
| r0 | r10969 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | SMC CRT9212 Double Row Buffer (DRB) emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #include "emu.h" |
| 11 | #include "crt9212.h" |
| 12 | |
| 13 | |
| 14 | |
| 15 | //************************************************************************** |
| 16 | // MACROS / CONSTANTS |
| 17 | //************************************************************************** |
| 18 | |
| 19 | #define LOG 1 |
| 20 | |
| 21 | |
| 22 | #define REN \ |
| 23 | devcb_call_read_line(&m_in_ren_func) |
| 24 | |
| 25 | #define WEN \ |
| 26 | devcb_call_read_line(&m_in_wen_func) |
| 27 | |
| 28 | #define WEN2 \ |
| 29 | devcb_call_read_line(&m_in_wen2_func) |
| 30 | |
| 31 | #define ROF(_state) \ |
| 32 | devcb_call_write_line(&m_out_rof_func, _state); |
| 33 | |
| 34 | #define WOF(_state) \ |
| 35 | devcb_call_write_line(&m_out_wof_func, _state); |
| 36 | |
| 37 | |
| 38 | |
| 39 | //************************************************************************** |
| 40 | // GLOBAL VARIABLES |
| 41 | //************************************************************************** |
| 42 | |
| 43 | // devices |
| 44 | const device_type CRT9212 = crt9212_device_config::static_alloc_device_config; |
| 45 | |
| 46 | |
| 47 | |
| 48 | //************************************************************************** |
| 49 | // DEVICE CONFIGURATION |
| 50 | //************************************************************************** |
| 51 | |
| 52 | //------------------------------------------------- |
| 53 | // crt9212_device_config - constructor |
| 54 | //------------------------------------------------- |
| 55 | |
| 56 | crt9212_device_config::crt9212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 57 | : device_config(mconfig, static_alloc_device_config, "SMC CRT9212", tag, owner, clock) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | |
| 62 | //------------------------------------------------- |
| 63 | // static_alloc_device_config - allocate a new |
| 64 | // configuration object |
| 65 | //------------------------------------------------- |
| 66 | |
| 67 | device_config *crt9212_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 68 | { |
| 69 | return global_alloc(crt9212_device_config(mconfig, tag, owner, clock)); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | //------------------------------------------------- |
| 74 | // alloc_device - allocate a new device object |
| 75 | //------------------------------------------------- |
| 76 | |
| 77 | device_t *crt9212_device_config::alloc_device(running_machine &machine) const |
| 78 | { |
| 79 | return auto_alloc(&machine, crt9212_device(machine, *this)); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | //------------------------------------------------- |
| 84 | // device_config_complete - perform any |
| 85 | // operations now that the configuration is |
| 86 | // complete |
| 87 | //------------------------------------------------- |
| 88 | |
| 89 | void crt9212_device_config::device_config_complete() |
| 90 | { |
| 91 | // inherit a copy of the static data |
| 92 | const crt9212_interface *intf = reinterpret_cast<const crt9212_interface *>(static_config()); |
| 93 | if (intf != NULL) |
| 94 | *static_cast<crt9212_interface *>(this) = *intf; |
| 95 | |
| 96 | // or initialize to defaults if none provided |
| 97 | else |
| 98 | { |
| 99 | memset(&out_rof_func, 0, sizeof(out_rof_func)); |
| 100 | memset(&out_wof_func, 0, sizeof(out_wof_func)); |
| 101 | memset(&in_ren_func, 0, sizeof(in_ren_func)); |
| 102 | memset(&in_wen_func, 0, sizeof(in_wen_func)); |
| 103 | memset(&in_wen2_func, 0, sizeof(in_wen2_func)); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | |
| 108 | |
| 109 | //************************************************************************** |
| 110 | // INLINE HELPERS |
| 111 | //************************************************************************** |
| 112 | |
| 113 | |
| 114 | //************************************************************************** |
| 115 | // LIVE DEVICE |
| 116 | //************************************************************************** |
| 117 | |
| 118 | //------------------------------------------------- |
| 119 | // crt9212_device - constructor |
| 120 | //------------------------------------------------- |
| 121 | |
| 122 | crt9212_device::crt9212_device(running_machine &_machine, const crt9212_device_config &config) |
| 123 | : device_t(_machine, config), |
| 124 | m_config(config) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | |
| 129 | //------------------------------------------------- |
| 130 | // device_start - device-specific startup |
| 131 | //------------------------------------------------- |
| 132 | |
| 133 | void crt9212_device::device_start() |
| 134 | { |
| 135 | // resolve callbacks |
| 136 | devcb_resolve_write_line(&m_out_rof_func, &m_config.out_rof_func, this); |
| 137 | devcb_resolve_write_line(&m_out_wof_func, &m_config.out_wof_func, this); |
| 138 | devcb_resolve_read_line(&m_in_ren_func, &m_config.in_ren_func, this); |
| 139 | devcb_resolve_read_line(&m_in_wen_func, &m_config.in_wen_func, this); |
| 140 | devcb_resolve_read_line(&m_in_wen2_func, &m_config.in_wen2_func, this); |
| 141 | |
| 142 | // register for state saving |
| 143 | save_item(NAME(m_input)); |
| 144 | save_item(NAME(m_output)); |
| 145 | save_item(NAME(m_buffer)); |
| 146 | save_item(NAME(m_rac)); |
| 147 | save_item(NAME(m_wac)); |
| 148 | save_item(NAME(m_tog)); |
| 149 | save_item(NAME(m_clrcnt)); |
| 150 | save_item(NAME(m_rclk)); |
| 151 | save_item(NAME(m_wclk)); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | //------------------------------------------------- |
| 156 | // read - buffer read |
| 157 | //------------------------------------------------- |
| 158 | |
| 159 | READ8_MEMBER( crt9212_device::read ) |
| 160 | { |
| 161 | return m_output; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | //------------------------------------------------- |
| 166 | // write - buffer write |
| 167 | //------------------------------------------------- |
| 168 | |
| 169 | WRITE8_MEMBER( crt9212_device::write ) |
| 170 | { |
| 171 | m_input = data; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | //------------------------------------------------- |
| 176 | // clrcnt_w - clear address counters |
| 177 | //------------------------------------------------- |
| 178 | |
| 179 | WRITE_LINE_MEMBER( crt9212_device::clrcnt_w ) |
| 180 | { |
| 181 | m_clrcnt = state; |
| 182 | } |
| 183 | |
| 184 | |
| 185 | //------------------------------------------------- |
| 186 | // tog_w - toggle buffer |
| 187 | //------------------------------------------------- |
| 188 | |
| 189 | WRITE_LINE_MEMBER( crt9212_device::tog_w ) |
| 190 | { |
| 191 | m_tog = state; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | //------------------------------------------------- |
| 196 | // rclk_w - read clock |
| 197 | //------------------------------------------------- |
| 198 | |
| 199 | WRITE_LINE_MEMBER( crt9212_device::rclk_w ) |
| 200 | { |
| 201 | if (m_rclk && !state) |
| 202 | { |
| 203 | if (!m_clrcnt) |
| 204 | { |
| 205 | if (!m_tog) |
| 206 | { |
| 207 | // switch buffer |
| 208 | m_buffer = !m_buffer; |
| 209 | |
| 210 | // clear write address counter |
| 211 | m_wac = 0; |
| 212 | WOF(0); |
| 213 | } |
| 214 | else |
| 215 | { |
| 216 | // clear read address counter |
| 217 | m_rac = 0; |
| 218 | ROF(0); |
| 219 | } |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | if (REN && (m_rac < CRT9212_RAM_SIZE)) |
| 224 | { |
| 225 | // |
| 226 | m_output = m_ram[m_rac][!m_buffer]; |
| 227 | |
| 228 | // increment read address counter |
| 229 | m_rac++; |
| 230 | |
| 231 | if (m_rac == CRT9212_RAM_SIZE) |
| 232 | { |
| 233 | // set read overflow |
| 234 | ROF(1); |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | m_rclk = state; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | //------------------------------------------------- |
| 245 | // wclk_w - write clock |
| 246 | //------------------------------------------------- |
| 247 | |
| 248 | WRITE_LINE_MEMBER( crt9212_device::wclk_w ) |
| 249 | { |
| 250 | if (!m_rclk && state) |
| 251 | { |
| 252 | if (WEN && WEN2 && (m_wac < CRT9212_RAM_SIZE)) |
| 253 | { |
| 254 | // |
| 255 | m_ram[m_rac][m_buffer] = m_input; |
| 256 | |
| 257 | // increment read address counter |
| 258 | m_wac++; |
| 259 | |
| 260 | if (m_wac == CRT9212_RAM_SIZE) |
| 261 | { |
| 262 | // set write overflow |
| 263 | WOF(1); |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | m_wclk = state; |
| 269 | } |
src/emu/emu.mak
| r10968 | r10969 | |
| 133 | 133 | $(EMUDRIVERS)/empty.o \ |
| 134 | 134 | |
| 135 | 135 | EMUMACHINEOBJS = \ |
| 136 | | $(EMUMACHINE)/53c810.o \ |
| 137 | | $(EMUMACHINE)/6522via.o \ |
| 138 | | $(EMUMACHINE)/6526cia.o \ |
| 139 | | $(EMUMACHINE)/6532riot.o \ |
| 140 | | $(EMUMACHINE)/6821pia.o \ |
| 141 | | $(EMUMACHINE)/6840ptm.o \ |
| 142 | | $(EMUMACHINE)/6850acia.o \ |
| 143 | | $(EMUMACHINE)/68681.o \ |
| 144 | | $(EMUMACHINE)/74123.o \ |
| 145 | | $(EMUMACHINE)/74148.o \ |
| 146 | | $(EMUMACHINE)/74153.o \ |
| 147 | | $(EMUMACHINE)/74181.o \ |
| 148 | | $(EMUMACHINE)/7474.o \ |
| 149 | | $(EMUMACHINE)/8042kbdc.o \ |
| 150 | | $(EMUMACHINE)/8237dma.o \ |
| 151 | | $(EMUMACHINE)/8255ppi.o \ |
| 152 | | $(EMUMACHINE)/8257dma.o \ |
| 153 | | $(EMUMACHINE)/adc083x.o \ |
| 154 | | $(EMUMACHINE)/adc1038.o \ |
| 155 | | $(EMUMACHINE)/adc1213x.o \ |
| 156 | | $(EMUMACHINE)/am53cf96.o \ |
| 157 | | $(EMUMACHINE)/at28c16.o \ |
| 158 | | $(EMUMACHINE)/cdp1852.o \ |
| 159 | | $(EMUMACHINE)/cr589.o \ |
| 160 | | $(EMUMACHINE)/ds1302.o \ |
| 161 | | $(EMUMACHINE)/ds2401.o \ |
| 162 | | $(EMUMACHINE)/ds2404.o \ |
| 163 | | $(EMUMACHINE)/eeprom.o \ |
| 164 | | $(EMUMACHINE)/er2055.o \ |
| 165 | | $(EMUMACHINE)/f3853.o \ |
| 166 | | $(EMUMACHINE)/generic.o \ |
| 167 | | $(EMUMACHINE)/i2cmem.o \ |
| 168 | | $(EMUMACHINE)/i8243.o \ |
| 169 | | $(EMUMACHINE)/i8255a.o \ |
| 170 | | $(EMUMACHINE)/idectrl.o \ |
| 171 | | $(EMUMACHINE)/ins8154.o \ |
| 172 | | $(EMUMACHINE)/ins8250.o \ |
| 173 | | $(EMUMACHINE)/intelfsh.o \ |
| 174 | | $(EMUMACHINE)/k033906.o \ |
| 175 | | $(EMUMACHINE)/k056230.o \ |
| 176 | | $(EMUMACHINE)/latch8.o \ |
| 177 | | $(EMUMACHINE)/ldcore.o \ |
| 178 | | $(EMUMACHINE)/ldpr8210.o \ |
| 179 | | $(EMUMACHINE)/ldv1000.o \ |
| 180 | | $(EMUMACHINE)/ldvp931.o \ |
| 181 | | $(EMUMACHINE)/mb14241.o \ |
| 182 | | $(EMUMACHINE)/mb3773.o \ |
| 183 | | $(EMUMACHINE)/mb87078.o \ |
| 184 | | $(EMUMACHINE)/mc146818.o \ |
| 185 | | $(EMUMACHINE)/mc68901.o \ |
| 186 | | $(EMUMACHINE)/microtch.o \ |
| 187 | | $(EMUMACHINE)/msm6242.o \ |
| 188 | | $(EMUMACHINE)/nvram.o \ |
| 189 | | $(EMUMACHINE)/pc16552d.o \ |
| 190 | | $(EMUMACHINE)/pci.o \ |
| 191 | | $(EMUMACHINE)/pd4990a.o \ |
| 192 | | $(EMUMACHINE)/pic8259.o \ |
| 193 | | $(EMUMACHINE)/pit8253.o \ |
| 194 | | $(EMUMACHINE)/ram.o \ |
| 195 | | $(EMUMACHINE)/roc10937.o \ |
| 196 | | $(EMUMACHINE)/rp5h01.o \ |
| 197 | | $(EMUMACHINE)/rtc65271.o \ |
| 198 | | $(EMUMACHINE)/s3c2400.o \ |
| 199 | | $(EMUMACHINE)/s3c2410.o \ |
| 200 | | $(EMUMACHINE)/s3c2440.o \ |
| 201 | | $(EMUMACHINE)/scsi.o \ |
| 202 | | $(EMUMACHINE)/scsicd.o \ |
| 203 | | $(EMUMACHINE)/scsidev.o \ |
| 204 | | $(EMUMACHINE)/scsihd.o \ |
| 205 | | $(EMUMACHINE)/secflash.o \ |
| 206 | | $(EMUMACHINE)/smc91c9x.o \ |
| 207 | | $(EMUMACHINE)/timekpr.o \ |
| 208 | | $(EMUMACHINE)/tmp68301.o \ |
| 209 | | $(EMUMACHINE)/tms6100.o \ |
| 210 | | $(EMUMACHINE)/upd4701.o \ |
| 211 | | $(EMUMACHINE)/wd33c93.o \ |
| 212 | | $(EMUMACHINE)/x2212.o \ |
| 213 | | $(EMUMACHINE)/x76f041.o \ |
| 214 | | $(EMUMACHINE)/x76f100.o \ |
| 215 | | $(EMUMACHINE)/z80ctc.o \ |
| 216 | | $(EMUMACHINE)/z80dart.o \ |
| 217 | | $(EMUMACHINE)/z80dma.o \ |
| 218 | | $(EMUMACHINE)/z80pio.o \ |
| 219 | | $(EMUMACHINE)/z80sio.o \ |
| 220 | | $(EMUMACHINE)/z80sti.o \ |
| 136 | $(EMUMACHINE)/53c810.o \ |
| 137 | $(EMUMACHINE)/6522via.o \ |
| 138 | $(EMUMACHINE)/6526cia.o \ |
| 139 | $(EMUMACHINE)/6532riot.o \ |
| 140 | $(EMUMACHINE)/6821pia.o \ |
| 141 | $(EMUMACHINE)/6840ptm.o \ |
| 142 | $(EMUMACHINE)/6850acia.o \ |
| 143 | $(EMUMACHINE)/68681.o \ |
| 144 | $(EMUMACHINE)/74123.o \ |
| 145 | $(EMUMACHINE)/74148.o \ |
| 146 | $(EMUMACHINE)/74153.o \ |
| 147 | $(EMUMACHINE)/74181.o \ |
| 148 | $(EMUMACHINE)/7474.o \ |
| 149 | $(EMUMACHINE)/8042kbdc.o \ |
| 150 | $(EMUMACHINE)/8237dma.o \ |
| 151 | $(EMUMACHINE)/8255ppi.o \ |
| 152 | $(EMUMACHINE)/8257dma.o \ |
| 153 | $(EMUMACHINE)/adc083x.o \ |
| 154 | $(EMUMACHINE)/adc1038.o \ |
| 155 | $(EMUMACHINE)/adc1213x.o \ |
| 156 | $(EMUMACHINE)/am53cf96.o \ |
| 157 | $(EMUMACHINE)/at28c16.o \ |
| 158 | $(EMUMACHINE)/cdp1852.o \ |
| 159 | $(EMUMACHINE)/cdp1871.o \ |
| 160 | $(EMUMACHINE)/cr589.o \ |
| 161 | $(EMUMACHINE)/ds1302.o \ |
| 162 | $(EMUMACHINE)/ds2401.o \ |
| 163 | $(EMUMACHINE)/ds2404.o \ |
| 164 | $(EMUMACHINE)/e0516.o \ |
| 165 | $(EMUMACHINE)/eeprom.o \ |
| 166 | $(EMUMACHINE)/er2055.o \ |
| 167 | $(EMUMACHINE)/f3853.o \ |
| 168 | $(EMUMACHINE)/generic.o \ |
| 169 | $(EMUMACHINE)/i2cmem.o \ |
| 170 | $(EMUMACHINE)/i8155.o \ |
| 171 | $(EMUMACHINE)/i8212.o \ |
| 172 | $(EMUMACHINE)/i8243.o \ |
| 173 | $(EMUMACHINE)/i8255a.o \ |
| 174 | $(EMUMACHINE)/i8355.o \ |
| 175 | $(EMUMACHINE)/idectrl.o \ |
| 176 | $(EMUMACHINE)/ins8154.o \ |
| 177 | $(EMUMACHINE)/ins8250.o \ |
| 178 | $(EMUMACHINE)/intelfsh.o \ |
| 179 | $(EMUMACHINE)/k033906.o \ |
| 180 | $(EMUMACHINE)/k056230.o \ |
| 181 | $(EMUMACHINE)/latch8.o \ |
| 182 | $(EMUMACHINE)/ldcore.o \ |
| 183 | $(EMUMACHINE)/ldpr8210.o \ |
| 184 | $(EMUMACHINE)/ldv1000.o \ |
| 185 | $(EMUMACHINE)/ldvp931.o \ |
| 186 | $(EMUMACHINE)/mb14241.o \ |
| 187 | $(EMUMACHINE)/mb3773.o \ |
| 188 | $(EMUMACHINE)/mb87078.o \ |
| 189 | $(EMUMACHINE)/mc146818.o \ |
| 190 | $(EMUMACHINE)/mc68901.o \ |
| 191 | $(EMUMACHINE)/microtch.o \ |
| 192 | $(EMUMACHINE)/msm6242.o \ |
| 193 | $(EMUMACHINE)/nmc9306.o \ |
| 194 | $(EMUMACHINE)/nvram.o \ |
| 195 | $(EMUMACHINE)/pc16552d.o \ |
| 196 | $(EMUMACHINE)/pci.o \ |
| 197 | $(EMUMACHINE)/pd4990a.o \ |
| 198 | $(EMUMACHINE)/pic8259.o \ |
| 199 | $(EMUMACHINE)/pit8253.o \ |
| 200 | $(EMUMACHINE)/ram.o \ |
| 201 | $(EMUMACHINE)/roc10937.o \ |
| 202 | $(EMUMACHINE)/rp5h01.o \ |
| 203 | $(EMUMACHINE)/rtc65271.o \ |
| 204 | $(EMUMACHINE)/s3c2400.o \ |
| 205 | $(EMUMACHINE)/s3c2410.o \ |
| 206 | $(EMUMACHINE)/s3c2440.o \ |
| 207 | $(EMUMACHINE)/scsi.o \ |
| 208 | $(EMUMACHINE)/scsicd.o \ |
| 209 | $(EMUMACHINE)/scsidev.o \ |
| 210 | $(EMUMACHINE)/scsihd.o \ |
| 211 | $(EMUMACHINE)/secflash.o \ |
| 212 | $(EMUMACHINE)/smc91c9x.o \ |
| 213 | $(EMUMACHINE)/timekpr.o \ |
| 214 | $(EMUMACHINE)/tmp68301.o \ |
| 215 | $(EMUMACHINE)/tms6100.o \ |
| 216 | $(EMUMACHINE)/upd4701.o \ |
| 217 | $(EMUMACHINE)/wd33c93.o \ |
| 218 | $(EMUMACHINE)/x2212.o \ |
| 219 | $(EMUMACHINE)/x76f041.o \ |
| 220 | $(EMUMACHINE)/x76f100.o \ |
| 221 | $(EMUMACHINE)/z80ctc.o \ |
| 222 | $(EMUMACHINE)/z80dart.o \ |
| 223 | $(EMUMACHINE)/z80dma.o \ |
| 224 | $(EMUMACHINE)/z80pio.o \ |
| 225 | $(EMUMACHINE)/z80sio.o \ |
| 226 | $(EMUMACHINE)/z80sti.o \ |
| 227 | $(EMUMACHINE)/z8536.o \ |
| 221 | 228 | |
| 222 | 229 | EMUVIDEOOBJS = \ |
| 223 | | $(EMUVIDEO)/generic.o \ |
| 224 | | $(EMUVIDEO)/hd63484.o \ |
| 225 | | $(EMUVIDEO)/mc6845.o \ |
| 226 | | $(EMUVIDEO)/pc_vga.o \ |
| 227 | | $(EMUVIDEO)/pc_video.o \ |
| 228 | | $(EMUVIDEO)/poly.o \ |
| 229 | | $(EMUVIDEO)/resnet.o \ |
| 230 | | $(EMUVIDEO)/rgbutil.o \ |
| 231 | | $(EMUVIDEO)/s2636.o \ |
| 232 | | $(EMUVIDEO)/saa5050.o \ |
| 233 | | $(EMUVIDEO)/tlc34076.o \ |
| 234 | | $(EMUVIDEO)/tms34061.o \ |
| 235 | | $(EMUVIDEO)/tms9927.o \ |
| 236 | | $(EMUVIDEO)/tms9928a.o \ |
| 237 | | $(EMUVIDEO)/v9938.o \ |
| 238 | | $(EMUVIDEO)/vector.o \ |
| 239 | | $(EMUVIDEO)/voodoo.o \ |
| 230 | $(EMUVIDEO)/crt9007.o \ |
| 231 | $(EMUVIDEO)/crt9021.o \ |
| 232 | $(EMUVIDEO)/crt9212.o \ |
| 233 | $(EMUVIDEO)/generic.o \ |
| 234 | $(EMUVIDEO)/hd61830.o \ |
| 235 | $(EMUVIDEO)/hd63484.o \ |
| 236 | $(EMUVIDEO)/mc6845.o \ |
| 237 | $(EMUVIDEO)/pc_vga.o \ |
| 238 | $(EMUVIDEO)/pc_video.o \ |
| 239 | $(EMUVIDEO)/poly.o \ |
| 240 | $(EMUVIDEO)/resnet.o \ |
| 241 | $(EMUVIDEO)/rgbutil.o \ |
| 242 | $(EMUVIDEO)/s2636.o \ |
| 243 | $(EMUVIDEO)/saa5050.o \ |
| 244 | $(EMUVIDEO)/tlc34076.o \ |
| 245 | $(EMUVIDEO)/tms34061.o \ |
| 246 | $(EMUVIDEO)/tms9927.o \ |
| 247 | $(EMUVIDEO)/tms9928a.o \ |
| 248 | $(EMUVIDEO)/v9938.o \ |
| 249 | $(EMUVIDEO)/vector.o \ |
| 250 | $(EMUVIDEO)/voodoo.o \ |
| 240 | 251 | |
| 241 | 252 | EMUIMAGEDEVOBJS = \ |
| 242 | 253 | $(EMUIMAGEDEV)/bitbngr.o \ |
src/emu/machine/z8536.c
| r0 | r10969 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | Zilog Z8536 Counter/Timer and Parallel I/O emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #include "emu.h" |
| 11 | #include "z8536.h" |
| 12 | #include "machine/devhelpr.h" |
| 13 | |
| 14 | |
| 15 | |
| 16 | //************************************************************************** |
| 17 | // MACROS / CONSTANTS |
| 18 | //************************************************************************** |
| 19 | |
| 20 | // states |
| 21 | enum |
| 22 | { |
| 23 | STATE_RESET = -1, |
| 24 | STATE_0, |
| 25 | STATE_1 |
| 26 | }; |
| 27 | |
| 28 | |
| 29 | // ports |
| 30 | enum |
| 31 | { |
| 32 | PORT_C = 0, |
| 33 | PORT_B, |
| 34 | PORT_A, |
| 35 | CONTROL |
| 36 | }; |
| 37 | |
| 38 | |
| 39 | // registers |
| 40 | enum |
| 41 | { |
| 42 | MASTER_INTERRUPT_CONTROL = 0, |
| 43 | MASTER_CONFIGURATION_CONTROL, |
| 44 | PORT_A_INTERRUPT_VECTOR, |
| 45 | PORT_B_INTERRUPT_VECTOR, |
| 46 | COUNTER_TIMER_INTERRUPT_VECTOR, |
| 47 | PORT_C_DATA_PATH_POLARITY, |
| 48 | PORT_C_DATA_DIRECTION, |
| 49 | PORT_C_SPECIAL_IO_CONTROL, |
| 50 | PORT_A_COMMAND_AND_STATUS, |
| 51 | PORT_B_COMMAND_AND_STATUS, |
| 52 | COUNTER_TIMER_1_COMMAND_AND_STATUS, |
| 53 | COUNTER_TIMER_2_COMMAND_AND_STATUS, |
| 54 | COUNTER_TIMER_3_COMMAND_AND_STATUS, |
| 55 | PORT_A_DATA, |
| 56 | PORT_B_DATA, |
| 57 | PORT_C_DATA, |
| 58 | COUNTER_TIMER_1_CURRENT_COUNT_MS_BYTE, |
| 59 | COUNTER_TIMER_1_CURRENT_COUNT_LS_BYTE, |
| 60 | COUNTER_TIMER_2_CURRENT_COUNT_MS_BYTE, |
| 61 | COUNTER_TIMER_2_CURRENT_COUNT_LS_BYTE, |
| 62 | COUNTER_TIMER_3_CURRENT_COUNT_MS_BYTE, |
| 63 | COUNTER_TIMER_3_CURRENT_COUNT_LS_BYTE, |
| 64 | COUNTER_TIMER_1_TIME_CONSTANT_MS_BYTE, |
| 65 | COUNTER_TIMER_1_TIME_CONSTANT_LS_BYTE, |
| 66 | COUNTER_TIMER_2_TIME_CONSTANT_MS_BYTE, |
| 67 | COUNTER_TIMER_2_TIME_CONSTANT_LS_BYTE, |
| 68 | COUNTER_TIMER_3_TIME_CONSTANT_MS_BYTE, |
| 69 | COUNTER_TIMER_3_TIME_CONSTANT_LS_BYTE, |
| 70 | COUNTER_TIMER_1_MODE_SPECIFICATION, |
| 71 | COUNTER_TIMER_2_MODE_SPECIFICATION, |
| 72 | COUNTER_TIMER_3_MODE_SPECIFICATION, |
| 73 | CURRENT_VECTOR, |
| 74 | PORT_A_MODE_SPECIFICATION, |
| 75 | PORT_A_HANDSHAKE_SPECIFICATION, |
| 76 | PORT_A_DATA_PATH_POLARITY, |
| 77 | PORT_A_DATA_DIRECTION, |
| 78 | PORT_A_SPECIAL_IO_CONTROL, |
| 79 | PORT_A_PATTERN_POLARITY, |
| 80 | PORT_A_PATTERN_TRANSITION, |
| 81 | PORT_A_PATTERN_MASK, |
| 82 | PORT_B_MODE_SPECIFICATION, |
| 83 | PORT_B_HANDSHAKE_SPECIFICATION, |
| 84 | PORT_B_DATA_PATH_POLARITY, |
| 85 | PORT_B_DATA_DIRECTION, |
| 86 | PORT_B_SPECIAL_IO_CONTROL, |
| 87 | PORT_B_PATTERN_POLARITY, |
| 88 | PORT_B_PATTERN_TRANSITION, |
| 89 | PORT_B_PATTERN_MASK |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | // counter/timer link control |
| 94 | enum |
| 95 | { |
| 96 | LC_INDEPENDENT = 0, |
| 97 | LC_CT1_GATES_CT2, |
| 98 | LC_CT1_TRIGGERS_CT2, |
| 99 | LC_CT1_COUNTS_CT2 |
| 100 | }; |
| 101 | |
| 102 | |
| 103 | // port type select |
| 104 | enum |
| 105 | { |
| 106 | PTS_BIT = 0, |
| 107 | PTS_INPUT, |
| 108 | PTS_OUTPUT, |
| 109 | PTS_BIDIRECTIONAL |
| 110 | }; |
| 111 | |
| 112 | |
| 113 | // pattern mode specification |
| 114 | enum |
| 115 | { |
| 116 | PMS_DISABLE = 0, |
| 117 | PMS_AND, |
| 118 | PMS_OR, |
| 119 | PMS_VECTOR |
| 120 | }; |
| 121 | |
| 122 | |
| 123 | // handshake specification |
| 124 | enum |
| 125 | { |
| 126 | HTS_INTERLOCKED = 0, |
| 127 | HTS_STROBED, |
| 128 | HTS_PULSED, |
| 129 | HTS_3_WIRE |
| 130 | }; |
| 131 | |
| 132 | |
| 133 | // request/wait specification |
| 134 | enum |
| 135 | { |
| 136 | RWS_DISABLED = 0, |
| 137 | RWS_OUTPUT_WAIT, |
| 138 | RWS_INPUT_WAIT = 3, |
| 139 | RWS_SPECIAL_REQUEST, |
| 140 | RWS_OUTPUT_REQUEST, |
| 141 | RWS_INPUT_REQUEST = 7 |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | // pattern specification |
| 146 | enum |
| 147 | { |
| 148 | BIT_MASKED_OFF = 0, |
| 149 | ANY_TRANSITION, |
| 150 | ZERO = 4, |
| 151 | ONE, |
| 152 | ONE_TO_ZERO, |
| 153 | ZERO_TO_ONE |
| 154 | }; |
| 155 | |
| 156 | |
| 157 | // output duty cycle |
| 158 | enum |
| 159 | { |
| 160 | DCS_PULSE, |
| 161 | DCS_ONE_SHOT, |
| 162 | DCS_SQUARE_WAVE, |
| 163 | DCS_DO_NOT_USE |
| 164 | }; |
| 165 | |
| 166 | |
| 167 | // master interrupt control register |
| 168 | #define MICR_RESET 0x01 // reset |
| 169 | #define MICR_RJA 0x02 // right justified address |
| 170 | #define MICR_CT_VIS 0x04 // counter/timer vector includes status |
| 171 | #define MICR_PB_VIS 0x08 // port B vector includes status |
| 172 | #define MICR_PA_VIS 0x10 // port A vector includes status |
| 173 | #define MICR_NV 0x20 // no vector |
| 174 | #define MICR_DLC 0x40 // disable lower chain |
| 175 | #define MICR_MIE 0x80 // master interrupt enable |
| 176 | |
| 177 | |
| 178 | // master configuration control register |
| 179 | #define MCCR_LC_MASK 0x03 // counter/timer link controls |
| 180 | #define MCCR_PAE 0x04 // port A enable |
| 181 | #define MCCR_PLC 0x08 // port link control |
| 182 | #define MCCR_PCE_CT3E 0x10 // port C and counter/timer 3 enable |
| 183 | #define MCCR_CT2E 0x20 // counter/timer 2 enable |
| 184 | #define MCCR_CT1E 0x40 // counter/timer 1 enable |
| 185 | #define MCCR_PBE 0x80 // port B enable |
| 186 | |
| 187 | |
| 188 | // port mode specification registers |
| 189 | #define PMS_LPM 0x01 // latch on pattern match |
| 190 | #define PMS_PMS_MASK 0x06 // pattern mode specification |
| 191 | #define PMS_IMO 0x08 // interrupt on match only |
| 192 | #define PMS_SB 0x10 // single buffer |
| 193 | #define PMS_ITB 0x20 // interrupt on two bytes |
| 194 | #define PMS_PTS_MASK 0xc0 // port type select |
| 195 | |
| 196 | |
| 197 | // port handshake specification registers |
| 198 | #define PHS_DTS_MASK 0x07 // deskew time specification |
| 199 | #define PHS_RWS_MASK 0x38 // request/wait specification |
| 200 | #define PHS_HTS_MASK 0xc0 // handshake type specification |
| 201 | |
| 202 | |
| 203 | // port command and status registers |
| 204 | #define PCS_IOE 0x01 // interrupt on error |
| 205 | #define PCS_PMF 0x02 // pattern match flag (read only) |
| 206 | #define PCS_IRF 0x04 // input register full (read only) |
| 207 | #define PCS_ORE 0x08 // output register empty (read only) |
| 208 | #define PCS_ERR 0x10 // interrupt error (read only) |
| 209 | #define PCS_IP 0x20 // interrupt pending |
| 210 | #define PCS_IE 0x40 // interrupt enable |
| 211 | #define PCS_IUS 0x80 // interrupt under service |
| 212 | |
| 213 | |
| 214 | // counter/timer mode specification registers |
| 215 | #define CTMS_DCS_MASK 0x03 // output duty cycle |
| 216 | #define CTMS_REB 0x04 // retrigger enable bit |
| 217 | #define CTMS_EDE 0x08 // external gate enable |
| 218 | #define CTMS_ETE 0x10 // external trigger enable |
| 219 | #define CTMS_ECE 0x20 // external count enable |
| 220 | #define CTMS_EOE 0x40 // external output enable |
| 221 | #define CTMS_CSC 0x80 // continuous single cycle |
| 222 | |
| 223 | |
| 224 | // counter/timer command and status registers |
| 225 | #define CTCS_CIP 0x01 // count in progress (read only) |
| 226 | #define CTCS_TCB 0x02 // trigger command bit (write only - read returns 0) |
| 227 | #define CTCS_GCB 0x04 // gate command bit |
| 228 | #define CTCS_RCC 0x08 // read counter control (read/set only - cleared by reading CCR LSB) |
| 229 | #define CTCS_ERR 0x10 // interrupt error (read only) |
| 230 | #define CTCS_IP 0x20 // interrupt pending |
| 231 | #define CTCS_IE 0x40 // interrupt enable |
| 232 | #define CTCS_IUS 0x80 // interrupt under service |
| 233 | |
| 234 | |
| 235 | |
| 236 | //************************************************************************** |
| 237 | // DEVICE DEFINITIONS |
| 238 | //************************************************************************** |
| 239 | |
| 240 | const device_type Z8536 = z8536_device_config::static_alloc_device_config; |
| 241 | |
| 242 | |
| 243 | |
| 244 | //************************************************************************** |
| 245 | // DEVICE CONFIGURATION |
| 246 | //************************************************************************** |
| 247 | |
| 248 | GENERIC_DEVICE_CONFIG_SETUP(z8536, "Zilog Z8536") |
| 249 | |
| 250 | |
| 251 | //------------------------------------------------- |
| 252 | // device_config_complete - perform any |
| 253 | // operations now that the configuration is |
| 254 | // complete |
| 255 | //------------------------------------------------- |
| 256 | |
| 257 | void z8536_device_config::device_config_complete() |
| 258 | { |
| 259 | // inherit a copy of the static data |
| 260 | const z8536_interface *intf = reinterpret_cast<const z8536_interface *>(static_config()); |
| 261 | if (intf != NULL) |
| 262 | *static_cast<z8536_interface *>(this) = *intf; |
| 263 | |
| 264 | // or initialize to defaults if none provided |
| 265 | else |
| 266 | { |
| 267 | memset(&m_out_int_func, 0, sizeof(m_out_int_func)); |
| 268 | memset(&m_in_pa_func, 0, sizeof(m_in_pa_func)); |
| 269 | memset(&m_out_pa_func, 0, sizeof(m_out_pa_func)); |
| 270 | memset(&m_in_pb_func, 0, sizeof(m_in_pb_func)); |
| 271 | memset(&m_out_pb_func, 0, sizeof(m_out_pb_func)); |
| 272 | memset(&m_in_pc_func, 0, sizeof(m_in_pc_func)); |
| 273 | memset(&m_out_pc_func, 0, sizeof(m_out_pc_func)); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | |
| 278 | |
| 279 | //************************************************************************** |
| 280 | // INLINE HELPERS |
| 281 | //************************************************************************** |
| 282 | |
| 283 | //------------------------------------------------- |
| 284 | // read_register - read from register |
| 285 | //------------------------------------------------- |
| 286 | |
| 287 | inline UINT8 z8536_device::read_register(offs_t offset) |
| 288 | { |
| 289 | UINT8 data = 0; |
| 290 | |
| 291 | data = m_register[offset]; // HACK |
| 292 | |
| 293 | switch (offset) |
| 294 | { |
| 295 | case PORT_A_DATA: |
| 296 | data = devcb_call_read8(&m_in_pa_func, 0); |
| 297 | break; |
| 298 | |
| 299 | case PORT_B_DATA: |
| 300 | data = devcb_call_read8(&m_in_pb_func, 0); |
| 301 | break; |
| 302 | |
| 303 | case PORT_C_DATA: |
| 304 | data = 0xf0 | (devcb_call_read8(&m_in_pc_func, 0) & 0x0f); |
| 305 | break; |
| 306 | |
| 307 | default: |
| 308 | logerror("Z8536 '%s' Unimplemented read from register %u\n", tag(), offset); |
| 309 | } |
| 310 | |
| 311 | return data; |
| 312 | } |
| 313 | |
| 314 | |
| 315 | //------------------------------------------------- |
| 316 | // read_register - masked read from register |
| 317 | //------------------------------------------------- |
| 318 | |
| 319 | inline UINT8 z8536_device::read_register(offs_t offset, UINT8 mask) |
| 320 | { |
| 321 | return read_register(offset) & mask; |
| 322 | } |
| 323 | |
| 324 | |
| 325 | //------------------------------------------------- |
| 326 | // write_register - write to register |
| 327 | //------------------------------------------------- |
| 328 | |
| 329 | inline void z8536_device::write_register(offs_t offset, UINT8 data) |
| 330 | { |
| 331 | switch (offset) |
| 332 | { |
| 333 | case MASTER_INTERRUPT_CONTROL: |
| 334 | if (data & MICR_RESET) |
| 335 | { |
| 336 | device_reset(); |
| 337 | } |
| 338 | else if (m_state == STATE_RESET) |
| 339 | { |
| 340 | m_state = STATE_0; |
| 341 | } |
| 342 | break; |
| 343 | |
| 344 | case PORT_A_DATA: |
| 345 | devcb_call_write8(&m_out_pa_func, 0, data); |
| 346 | break; |
| 347 | |
| 348 | case PORT_B_DATA: |
| 349 | devcb_call_write8(&m_out_pb_func, 0, data); |
| 350 | break; |
| 351 | |
| 352 | case PORT_C_DATA: |
| 353 | { |
| 354 | UINT8 mask = (data & 0xf0) | (data >> 4); |
| 355 | |
| 356 | m_output[PORT_C] = (m_output[PORT_C] & mask) | ((data & 0x0f) & (mask ^ 0xff)); |
| 357 | |
| 358 | devcb_call_write8(&m_out_pc_func, 0, m_output[PORT_C]); |
| 359 | } |
| 360 | break; |
| 361 | |
| 362 | default: |
| 363 | logerror("Z8536 '%s' Unimplemented write %02x to register %u\n", tag(), data, offset); |
| 364 | } |
| 365 | |
| 366 | m_register[offset] = data; // HACK |
| 367 | } |
| 368 | |
| 369 | |
| 370 | //------------------------------------------------- |
| 371 | // write_register - masked write to register |
| 372 | //------------------------------------------------- |
| 373 | |
| 374 | inline void z8536_device::write_register(offs_t offset, UINT8 data, UINT8 mask) |
| 375 | { |
| 376 | UINT8 combined_data = (data & mask) | (m_register[offset] & (mask ^ 0xff)); |
| 377 | |
| 378 | write_register(offset, combined_data); |
| 379 | } |
| 380 | |
| 381 | |
| 382 | //------------------------------------------------- |
| 383 | // count - |
| 384 | //------------------------------------------------- |
| 385 | |
| 386 | inline void z8536_device::count(device_timer_id id) |
| 387 | { |
| 388 | } |
| 389 | |
| 390 | |
| 391 | //------------------------------------------------- |
| 392 | // trigger - |
| 393 | //------------------------------------------------- |
| 394 | |
| 395 | inline void z8536_device::trigger(device_timer_id id) |
| 396 | { |
| 397 | } |
| 398 | |
| 399 | |
| 400 | //------------------------------------------------- |
| 401 | // gate - |
| 402 | //------------------------------------------------- |
| 403 | |
| 404 | inline void z8536_device::gate(device_timer_id id) |
| 405 | { |
| 406 | } |
| 407 | |
| 408 | |
| 409 | |
| 410 | //************************************************************************** |
| 411 | // LIVE DEVICE |
| 412 | //************************************************************************** |
| 413 | |
| 414 | //------------------------------------------------- |
| 415 | // z8536_device - constructor |
| 416 | //------------------------------------------------- |
| 417 | |
| 418 | z8536_device::z8536_device(running_machine &_machine, const z8536_device_config &config) |
| 419 | : device_t(_machine, config), |
| 420 | m_config(config) |
| 421 | { |
| 422 | } |
| 423 | |
| 424 | |
| 425 | //------------------------------------------------- |
| 426 | // device_start - device-specific startup |
| 427 | //------------------------------------------------- |
| 428 | |
| 429 | void z8536_device::device_start() |
| 430 | { |
| 431 | // allocate timers |
| 432 | m_timer[TIMER_1] = timer_alloc(TIMER_1); |
| 433 | m_timer[TIMER_2] = timer_alloc(TIMER_2); |
| 434 | m_timer[TIMER_3] = timer_alloc(TIMER_3); |
| 435 | |
| 436 | // resolve callbacks |
| 437 | devcb_resolve_write_line(&m_out_int_func, &m_config.m_out_int_func, this); |
| 438 | devcb_resolve_read8(&m_in_pa_func, &m_config.m_in_pa_func, this); |
| 439 | devcb_resolve_write8(&m_out_pa_func, &m_config.m_out_pa_func, this); |
| 440 | devcb_resolve_read8(&m_in_pb_func, &m_config.m_in_pb_func, this); |
| 441 | devcb_resolve_write8(&m_out_pb_func, &m_config.m_out_pb_func, this); |
| 442 | devcb_resolve_read8(&m_in_pc_func, &m_config.m_in_pc_func, this); |
| 443 | devcb_resolve_write8(&m_out_pc_func, &m_config.m_out_pc_func, this); |
| 444 | } |
| 445 | |
| 446 | |
| 447 | //------------------------------------------------- |
| 448 | // device_start - device-specific reset |
| 449 | //------------------------------------------------- |
| 450 | |
| 451 | void z8536_device::device_reset() |
| 452 | { |
| 453 | m_state = STATE_RESET; |
| 454 | |
| 455 | for (int i = 0; i < 48; i++) |
| 456 | { |
| 457 | m_register[i] = 0; |
| 458 | } |
| 459 | |
| 460 | m_register[MASTER_INTERRUPT_CONTROL] = MICR_RESET; |
| 461 | m_pointer = 0; |
| 462 | } |
| 463 | |
| 464 | |
| 465 | //------------------------------------------------- |
| 466 | // device_timer - handler timer events |
| 467 | //------------------------------------------------- |
| 468 | |
| 469 | void z8536_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 470 | { |
| 471 | switch (id) |
| 472 | { |
| 473 | case TIMER_1: |
| 474 | count(TIMER_1); |
| 475 | break; |
| 476 | |
| 477 | case TIMER_2: |
| 478 | count(TIMER_2); |
| 479 | break; |
| 480 | |
| 481 | case TIMER_3: |
| 482 | count(TIMER_3); |
| 483 | break; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | |
| 488 | //------------------------------------------------- |
| 489 | // read - register read |
| 490 | //------------------------------------------------- |
| 491 | |
| 492 | READ8_MEMBER( z8536_device::read ) |
| 493 | { |
| 494 | UINT8 data = 0; |
| 495 | |
| 496 | if (m_state == STATE_RESET) |
| 497 | { |
| 498 | // read RESET bit |
| 499 | data = read_register(m_pointer, 0x01); |
| 500 | } |
| 501 | else |
| 502 | { |
| 503 | switch (offset & 0x03) |
| 504 | { |
| 505 | case PORT_C: |
| 506 | data = read_register(PORT_C_DATA); |
| 507 | break; |
| 508 | |
| 509 | case PORT_B: |
| 510 | data = read_register(PORT_B_DATA); |
| 511 | break; |
| 512 | |
| 513 | case PORT_A: |
| 514 | data = read_register(PORT_A_DATA); |
| 515 | break; |
| 516 | |
| 517 | case CONTROL: |
| 518 | switch (m_state) |
| 519 | { |
| 520 | case STATE_1: |
| 521 | m_state = STATE_0; |
| 522 | // fallthru |
| 523 | case STATE_0: |
| 524 | data = read_register(m_pointer); |
| 525 | break; |
| 526 | } |
| 527 | break; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | return data; |
| 532 | } |
| 533 | |
| 534 | |
| 535 | //------------------------------------------------- |
| 536 | // write - register write |
| 537 | //------------------------------------------------- |
| 538 | |
| 539 | WRITE8_MEMBER( z8536_device::write ) |
| 540 | { |
| 541 | if (m_state == STATE_RESET) |
| 542 | { |
| 543 | // write RESET bit |
| 544 | write_register(m_pointer, data, 0x01); |
| 545 | } |
| 546 | else |
| 547 | { |
| 548 | switch (offset & 0x03) |
| 549 | { |
| 550 | case PORT_C: |
| 551 | write_register(PORT_C_DATA, data); |
| 552 | break; |
| 553 | |
| 554 | case PORT_B: |
| 555 | write_register(PORT_B_DATA, data); |
| 556 | break; |
| 557 | |
| 558 | case PORT_A: |
| 559 | write_register(PORT_A_DATA, data); |
| 560 | break; |
| 561 | |
| 562 | case CONTROL: |
| 563 | switch (m_state) |
| 564 | { |
| 565 | case STATE_0: |
| 566 | m_pointer = data; |
| 567 | m_state = STATE_1; |
| 568 | break; |
| 569 | |
| 570 | case STATE_1: |
| 571 | write_register(m_pointer, data); |
| 572 | m_state = STATE_0; |
| 573 | } |
| 574 | break; |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | |
| 580 | //------------------------------------------------- |
| 581 | // intack_w - interrupt acknowledge |
| 582 | //------------------------------------------------- |
| 583 | |
| 584 | WRITE_LINE_MEMBER( z8536_device::intack_w ) |
| 585 | { |
| 586 | } |
| 587 | |
| 588 | |
| 589 | //------------------------------------------------- |
| 590 | // pb*_w - port B bits 0-7 write |
| 591 | //------------------------------------------------- |
| 592 | |
| 593 | WRITE_LINE_MEMBER( z8536_device::pb0_w ) { } |
| 594 | WRITE_LINE_MEMBER( z8536_device::pb1_w ) { } |
| 595 | WRITE_LINE_MEMBER( z8536_device::pb2_w ) { } |
| 596 | WRITE_LINE_MEMBER( z8536_device::pb3_w ) { } |
| 597 | WRITE_LINE_MEMBER( z8536_device::pb4_w ) { } |
| 598 | WRITE_LINE_MEMBER( z8536_device::pb5_w ) { } |
| 599 | WRITE_LINE_MEMBER( z8536_device::pb6_w ) { } |
| 600 | WRITE_LINE_MEMBER( z8536_device::pb7_w ) { } |
| 601 | |
| 602 | |
| 603 | //------------------------------------------------- |
| 604 | // pc*_w - port C bits 0-3 write |
| 605 | //------------------------------------------------- |
| 606 | |
| 607 | WRITE_LINE_MEMBER( z8536_device::pc0_w ) { } |
| 608 | WRITE_LINE_MEMBER( z8536_device::pc1_w ) { } |
| 609 | WRITE_LINE_MEMBER( z8536_device::pc2_w ) { } |
| 610 | WRITE_LINE_MEMBER( z8536_device::pc3_w ) { } |
src/emu/machine/cdp1871.c
| r0 | r10969 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | RCA CDP1871 Keyboard Encoder emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #include "emu.h" |
| 11 | #include "cdp1871.h" |
| 12 | #include "cpu/mcs48/mcs48.h" |
| 13 | #include "machine/devhelpr.h" |
| 14 | |
| 15 | |
| 16 | |
| 17 | //************************************************************************** |
| 18 | // MACROS / CONSTANTS |
| 19 | //************************************************************************** |
| 20 | |
| 21 | static const UINT8 CDP1871_KEY_CODES[4][11][8] = |
| 22 | { |
| 23 | // normal |
| 24 | { |
| 25 | { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 }, |
| 26 | { 0x38, 0x39, 0x3a, 0x3b, 0x2c, 0x2d, 0x2e, 0x2f }, |
| 27 | { 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67 }, |
| 28 | { 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f }, |
| 29 | { 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77 }, |
| 30 | { 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f }, |
| 31 | { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f }, |
| 32 | { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 }, |
| 33 | { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f }, |
| 34 | { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 }, |
| 35 | { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f } |
| 36 | }, |
| 37 | |
| 38 | // alpha |
| 39 | { |
| 40 | { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 }, |
| 41 | { 0x38, 0x39, 0x3a, 0x3b, 0x2c, 0x2d, 0x2e, 0x2f }, |
| 42 | { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 }, |
| 43 | { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }, |
| 44 | { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 }, |
| 45 | { 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f }, |
| 46 | { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f }, |
| 47 | { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 }, |
| 48 | { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f }, |
| 49 | { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 }, |
| 50 | { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f } |
| 51 | }, |
| 52 | |
| 53 | // shift |
| 54 | { |
| 55 | { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 }, |
| 56 | { 0x28, 0x29, 0x2a, 0x2b, 0x3c, 0x3d, 0x3e, 0x3f }, |
| 57 | { 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 }, |
| 58 | { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }, |
| 59 | { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 }, |
| 60 | { 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f }, |
| 61 | { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f }, |
| 62 | { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 }, |
| 63 | { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f }, |
| 64 | { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 }, |
| 65 | { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f } |
| 66 | }, |
| 67 | |
| 68 | // control |
| 69 | { |
| 70 | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, |
| 71 | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, |
| 72 | { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, |
| 73 | { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, |
| 74 | { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }, |
| 75 | { 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, |
| 76 | { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f }, |
| 77 | { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 }, |
| 78 | { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f }, |
| 79 | { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 }, |
| 80 | { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f } |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | |
| 85 | |
| 86 | //************************************************************************** |
| 87 | // DEVICE DEFINITIONS |
| 88 | //************************************************************************** |
| 89 | |
| 90 | const device_type CDP1871 = cdp1871_device_config::static_alloc_device_config; |
| 91 | |
| 92 | |
| 93 | |
| 94 | //************************************************************************** |
| 95 | // DEVICE CONFIGURATION |
| 96 | //************************************************************************** |
| 97 | |
| 98 | GENERIC_DEVICE_CONFIG_SETUP(cdp1871, "RCA CDP1871") |
| 99 | |
| 100 | |
| 101 | //------------------------------------------------- |
| 102 | // device_config_complete - perform any |
| 103 | // operations now that the configuration is |
| 104 | // complete |
| 105 | //------------------------------------------------- |
| 106 | |
| 107 | void cdp1871_device_config::device_config_complete() |
| 108 | { |
| 109 | // inherit a copy of the static data |
| 110 | const cdp1871_interface *intf = reinterpret_cast<const cdp1871_interface *>(static_config()); |
| 111 | if (intf != NULL) |
| 112 | *static_cast<cdp1871_interface *>(this) = *intf; |
| 113 | |
| 114 | // or initialize to defaults if none provided |
| 115 | else |
| 116 | { |
| 117 | memset(&out_da_func, 0, sizeof(out_da_func)); |
| 118 | memset(&out_rpt_func, 0, sizeof(out_rpt_func)); |
| 119 | // m_in_d_func[] |
| 120 | memset(&in_shift_func, 0, sizeof(in_shift_func)); |
| 121 | memset(&in_control_func, 0, sizeof(in_control_func)); |
| 122 | memset(&in_alpha_func, 0, sizeof(in_alpha_func)); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | |
| 127 | |
| 128 | //************************************************************************** |
| 129 | // LIVE DEVICE |
| 130 | //************************************************************************** |
| 131 | |
| 132 | //------------------------------------------------- |
| 133 | // cdp1871_device - constructor |
| 134 | //------------------------------------------------- |
| 135 | |
| 136 | cdp1871_device::cdp1871_device(running_machine &_machine, const cdp1871_device_config &config) |
| 137 | : device_t(_machine, config), |
| 138 | m_inhibit(false), |
| 139 | m_sense(0), |
| 140 | m_drive(0), |
| 141 | m_next_da(CLEAR_LINE), |
| 142 | m_next_rpt(CLEAR_LINE), |
| 143 | m_config(config) |
| 144 | { |
| 145 | |
| 146 | } |
| 147 | |
| 148 | |
| 149 | //------------------------------------------------- |
| 150 | // device_start - device-specific startup |
| 151 | //------------------------------------------------- |
| 152 | |
| 153 | void cdp1871_device::device_start() |
| 154 | { |
| 155 | // resolve callbacks |
| 156 | devcb_resolve_write_line(&m_out_da_func, &m_config.out_da_func, this); |
| 157 | devcb_resolve_write_line(&m_out_rpt_func, &m_config.out_rpt_func, this); |
| 158 | devcb_resolve_read8(&m_in_d_func[0], &m_config.in_d1_func, this); |
| 159 | devcb_resolve_read8(&m_in_d_func[1], &m_config.in_d2_func, this); |
| 160 | devcb_resolve_read8(&m_in_d_func[2], &m_config.in_d3_func, this); |
| 161 | devcb_resolve_read8(&m_in_d_func[3], &m_config.in_d4_func, this); |
| 162 | devcb_resolve_read8(&m_in_d_func[4], &m_config.in_d5_func, this); |
| 163 | devcb_resolve_read8(&m_in_d_func[5], &m_config.in_d6_func, this); |
| 164 | devcb_resolve_read8(&m_in_d_func[6], &m_config.in_d7_func, this); |
| 165 | devcb_resolve_read8(&m_in_d_func[7], &m_config.in_d8_func, this); |
| 166 | devcb_resolve_read8(&m_in_d_func[8], &m_config.in_d9_func, this); |
| 167 | devcb_resolve_read8(&m_in_d_func[9], &m_config.in_d10_func, this); |
| 168 | devcb_resolve_read8(&m_in_d_func[10], &m_config.in_d11_func, this); |
| 169 | devcb_resolve_read_line(&m_in_shift_func, &m_config.in_shift_func, this); |
| 170 | devcb_resolve_read_line(&m_in_control_func, &m_config.in_control_func, this); |
| 171 | devcb_resolve_read_line(&m_in_alpha_func, &m_config.in_alpha_func, this); |
| 172 | |
| 173 | // set initial values |
| 174 | change_output_lines(); |
| 175 | |
| 176 | // allocate timers |
| 177 | m_scan_timer = timer_alloc(); |
| 178 | m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); |
| 179 | |
| 180 | // register for state saving |
| 181 | save_item(NAME(m_inhibit)); |
| 182 | save_item(NAME(m_sense)); |
| 183 | save_item(NAME(m_drive)); |
| 184 | save_item(NAME(m_shift)); |
| 185 | save_item(NAME(m_control)); |
| 186 | save_item(NAME(m_da)); |
| 187 | save_item(NAME(m_next_da)); |
| 188 | save_item(NAME(m_rpt)); |
| 189 | save_item(NAME(m_next_rpt)); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | //------------------------------------------------- |
| 194 | // device_timer - handler timer events |
| 195 | //------------------------------------------------- |
| 196 | |
| 197 | void cdp1871_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 198 | { |
| 199 | change_output_lines(); |
| 200 | clock_scan_counters(); |
| 201 | detect_keypress(); |
| 202 | } |
| 203 | |
| 204 | |
| 205 | //------------------------------------------------- |
| 206 | // change_output_lines - change output lines |
| 207 | //------------------------------------------------- |
| 208 | |
| 209 | void cdp1871_device::change_output_lines() |
| 210 | { |
| 211 | if (m_next_da != m_da) |
| 212 | { |
| 213 | m_da = m_next_da; |
| 214 | |
| 215 | devcb_call_write_line(&m_out_da_func, m_da); |
| 216 | } |
| 217 | |
| 218 | if (m_next_rpt != m_rpt) |
| 219 | { |
| 220 | m_rpt = m_next_rpt; |
| 221 | |
| 222 | devcb_call_write_line(&m_out_rpt_func, m_rpt); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | |
| 227 | //------------------------------------------------- |
| 228 | // clock_scan_counters - clock the keyboard |
| 229 | // scan counters |
| 230 | //------------------------------------------------- |
| 231 | |
| 232 | void cdp1871_device::clock_scan_counters() |
| 233 | { |
| 234 | if (!m_inhibit) |
| 235 | { |
| 236 | m_sense++; |
| 237 | |
| 238 | if (m_sense == 8) |
| 239 | { |
| 240 | m_sense = 0; |
| 241 | m_drive++; |
| 242 | |
| 243 | if (m_drive == 11) |
| 244 | { |
| 245 | m_drive = 0; |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | |
| 252 | //------------------------------------------------- |
| 253 | // detect_keypress - detect key press |
| 254 | //------------------------------------------------- |
| 255 | |
| 256 | void cdp1871_device::detect_keypress() |
| 257 | { |
| 258 | UINT8 data = 0; |
| 259 | |
| 260 | data = devcb_call_read8(&m_in_d_func[m_drive], 0); |
| 261 | |
| 262 | if (data == (1 << m_sense)) |
| 263 | { |
| 264 | if (!m_inhibit) |
| 265 | { |
| 266 | m_shift = devcb_call_read_line(&m_in_shift_func); |
| 267 | m_control = devcb_call_read_line(&m_in_control_func); |
| 268 | m_inhibit = true; |
| 269 | m_next_da = ASSERT_LINE; |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | m_next_rpt = ASSERT_LINE; |
| 274 | } |
| 275 | } |
| 276 | else |
| 277 | { |
| 278 | m_inhibit = false; |
| 279 | m_next_rpt = CLEAR_LINE; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | |
| 284 | //------------------------------------------------- |
| 285 | // data_r - keyboard data read |
| 286 | //------------------------------------------------- |
| 287 | |
| 288 | READ8_MEMBER( cdp1871_device::data_r ) |
| 289 | { |
| 290 | int table = 0; |
| 291 | int alpha = devcb_call_read_line(&m_in_alpha_func); |
| 292 | |
| 293 | if (m_control) table = 3; else if (m_shift) table = 2; else if (alpha) table = 1; |
| 294 | |
| 295 | // reset DA on next TPB |
| 296 | m_next_da = CLEAR_LINE; |
| 297 | |
| 298 | return CDP1871_KEY_CODES[table][m_drive][m_sense]; |
| 299 | } |
| 300 | |
| 301 | |
| 302 | //------------------------------------------------- |
| 303 | // da_r - data available |
| 304 | //------------------------------------------------- |
| 305 | |
| 306 | READ_LINE_MEMBER( cdp1871_device::da_r ) |
| 307 | { |
| 308 | return m_da; |
| 309 | } |
| 310 | |
| 311 | |
| 312 | //------------------------------------------------- |
| 313 | // rpt_r - keyboard repeat |
| 314 | //------------------------------------------------- |
| 315 | |
| 316 | READ_LINE_MEMBER( cdp1871_device::rpt_r ) |
| 317 | { |
| 318 | return m_rpt; |
| 319 | } |
src/emu/machine/nmc9306.c
| r0 | r10969 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | National Semiconductor NMC9306 256-Bit Serial EEPROM emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #include "emu.h" |
| 11 | #include "nmc9306.h" |
| 12 | #include "machine/devhelpr.h" |
| 13 | |
| 14 | |
| 15 | |
| 16 | //************************************************************************** |
| 17 | // MACROS / CONSTANTS |
| 18 | //************************************************************************** |
| 19 | |
| 20 | #define LOG 1 |
| 21 | |
| 22 | #define RAM_SIZE 32 |
| 23 | |
| 24 | |
| 25 | // instructions |
| 26 | enum |
| 27 | { |
| 28 | OTHER = 0, |
| 29 | WRITE, // write register A3A2A1A0 |
| 30 | READ, // read register A3A2A1A0 |
| 31 | ERASE // erase register A3A2A1A0 |
| 32 | }; |
| 33 | |
| 34 | // other instructions |
| 35 | enum |
| 36 | { |
| 37 | EWDS = 0, // erase/write disable |
| 38 | WRAL, // write all registers |
| 39 | ERAL, // erase all registers |
| 40 | EWEN, // erase/write enable |
| 41 | }; |
| 42 | |
| 43 | // states |
| 44 | enum |
| 45 | { |
| 46 | STATE_IDLE = 0, |
| 47 | STATE_COMMAND, |
| 48 | STATE_ADDRESS, |
| 49 | STATE_DATA_IN, |
| 50 | STATE_DATA_OUT, |
| 51 | STATE_ERASE |
| 52 | }; |
| 53 | |
| 54 | |
| 55 | |
| 56 | //************************************************************************** |
| 57 | // DEVICE DEFINITIONS |
| 58 | //************************************************************************** |
| 59 | |
| 60 | const device_type NMC9306 = nmc9306_device_config::static_alloc_device_config; |
| 61 | |
| 62 | |
| 63 | |
| 64 | //************************************************************************** |
| 65 | // DEVICE CONFIGURATION |
| 66 | //************************************************************************** |
| 67 | |
| 68 | //------------------------------------------------- |
| 69 | // nmc9306_device_config - constructor |
| 70 | //------------------------------------------------- |
| 71 | |
| 72 | nmc9306_device_config::nmc9306_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 73 | : device_config(mconfig, static_alloc_device_config, "NMC9306", tag, owner, clock), |
| 74 | device_config_nvram_interface(mconfig, *this) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | |
| 79 | //------------------------------------------------- |
| 80 | // static_alloc_device_config - allocate a new |
| 81 | // configuration object |
| 82 | //------------------------------------------------- |
| 83 | |
| 84 | device_config *nmc9306_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 85 | { |
| 86 | return global_alloc(nmc9306_device_config(mconfig, tag, owner, clock)); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | //------------------------------------------------- |
| 91 | // alloc_device - allocate a new device object |
| 92 | //------------------------------------------------- |
| 93 | |
| 94 | device_t *nmc9306_device_config::alloc_device(running_machine &machine) const |
| 95 | { |
| 96 | return auto_alloc(&machine, nmc9306_device(machine, *this)); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | |
| 101 | //************************************************************************** |
| 102 | // INLINE HELPERS |
| 103 | //************************************************************************** |
| 104 | |
| 105 | //------------------------------------------------- |
| 106 | // nmc9306_device - constructor |
| 107 | //------------------------------------------------- |
| 108 | |
| 109 | inline UINT16 nmc9306_device::read(offs_t offset) |
| 110 | { |
| 111 | return m_register[offset]; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | //------------------------------------------------- |
| 116 | // nmc9306_device - constructor |
| 117 | //------------------------------------------------- |
| 118 | |
| 119 | inline void nmc9306_device::write(offs_t offset, UINT16 data) |
| 120 | { |
| 121 | if (m_ewen) |
| 122 | { |
| 123 | m_register[offset] &= data; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | |
| 128 | //------------------------------------------------- |
| 129 | // nmc9306_device - constructor |
| 130 | //------------------------------------------------- |
| 131 | |
| 132 | inline void nmc9306_device::erase(offs_t offset) |
| 133 | { |
| 134 | if (m_ewen) |
| 135 | { |
| 136 | m_register[offset] = 0xffff; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | |
| 141 | |
| 142 | //************************************************************************** |
| 143 | // LIVE DEVICE |
| 144 | //************************************************************************** |
| 145 | |
| 146 | //------------------------------------------------- |
| 147 | // nmc9306_device - constructor |
| 148 | //------------------------------------------------- |
| 149 | |
| 150 | nmc9306_device::nmc9306_device(running_machine &_machine, const nmc9306_device_config &config) |
| 151 | : device_t(_machine, config), |
| 152 | device_nvram_interface(_machine, config, *this), |
| 153 | m_state(STATE_IDLE), |
| 154 | m_ewen(false), |
| 155 | m_config(config) |
| 156 | { |
| 157 | } |
| 158 | |
| 159 | |
| 160 | //------------------------------------------------- |
| 161 | // device_start - device-specific startup |
| 162 | //------------------------------------------------- |
| 163 | |
| 164 | void nmc9306_device::device_start() |
| 165 | { |
| 166 | // state saving |
| 167 | save_item(NAME(m_bits)); |
| 168 | save_item(NAME(m_state)); |
| 169 | save_item(NAME(m_command)); |
| 170 | save_item(NAME(m_address)); |
| 171 | save_item(NAME(m_data)); |
| 172 | save_item(NAME(m_ewen)); |
| 173 | save_item(NAME(m_cs)); |
| 174 | save_item(NAME(m_sk)); |
| 175 | save_item(NAME(m_do)); |
| 176 | save_item(NAME(m_di)); |
| 177 | } |
| 178 | |
| 179 | |
| 180 | //------------------------------------------------- |
| 181 | // nvram_default - called to initialize NVRAM to |
| 182 | // its default state |
| 183 | //------------------------------------------------- |
| 184 | |
| 185 | void nmc9306_device::nvram_default() |
| 186 | { |
| 187 | } |
| 188 | |
| 189 | |
| 190 | //------------------------------------------------- |
| 191 | // nvram_read - called to read NVRAM from the |
| 192 | // .nv file |
| 193 | //------------------------------------------------- |
| 194 | |
| 195 | void nmc9306_device::nvram_read(emu_file &file) |
| 196 | { |
| 197 | file.read(m_register, RAM_SIZE); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | //------------------------------------------------- |
| 202 | // nvram_write - called to write NVRAM to the |
| 203 | // .nv file |
| 204 | //------------------------------------------------- |
| 205 | |
| 206 | void nmc9306_device::nvram_write(emu_file &file) |
| 207 | { |
| 208 | file.write(m_register, RAM_SIZE); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | //------------------------------------------------- |
| 213 | // cs_w - chip select input |
| 214 | //------------------------------------------------- |
| 215 | |
| 216 | WRITE_LINE_MEMBER( nmc9306_device::cs_w ) |
| 217 | { |
| 218 | m_cs = state; |
| 219 | } |
| 220 | |
| 221 | |
| 222 | //------------------------------------------------- |
| 223 | // ck_w - serial clock input |
| 224 | //------------------------------------------------- |
| 225 | |
| 226 | WRITE_LINE_MEMBER( nmc9306_device::sk_w ) |
| 227 | { |
| 228 | m_sk = state; |
| 229 | |
| 230 | if (!m_cs || !m_sk) return; |
| 231 | |
| 232 | switch (m_state) |
| 233 | { |
| 234 | case STATE_IDLE: |
| 235 | if (LOG) logerror("NMC9306 '%s' Idle %u\n", tag(), m_di); |
| 236 | |
| 237 | if (m_di) |
| 238 | { |
| 239 | // start bit received |
| 240 | m_state = STATE_COMMAND; |
| 241 | m_bits = 0; |
| 242 | } |
| 243 | break; |
| 244 | |
| 245 | case STATE_COMMAND: |
| 246 | if (LOG) logerror("NMC9306 '%s' Command Bit %u\n", tag(), m_di); |
| 247 | |
| 248 | m_command <<= 1; |
| 249 | m_command |= m_di; |
| 250 | m_bits++; |
| 251 | |
| 252 | if (m_bits == 4) |
| 253 | { |
| 254 | m_state = STATE_ADDRESS; |
| 255 | m_bits = 0; |
| 256 | } |
| 257 | break; |
| 258 | |
| 259 | case STATE_ADDRESS: |
| 260 | if (LOG) logerror("NMC9306 '%s' Address Bit %u\n", tag(), m_di); |
| 261 | |
| 262 | m_address <<= 1; |
| 263 | m_address |= m_di; |
| 264 | m_bits++; |
| 265 | |
| 266 | if (m_bits == 4) |
| 267 | { |
| 268 | switch ((m_command >> 2) & 0x03) |
| 269 | { |
| 270 | case OTHER: |
| 271 | switch (m_command & 0x03) |
| 272 | { |
| 273 | case EWDS: |
| 274 | if (LOG) logerror("NMC9306 '%s' EWDS\n", tag()); |
| 275 | m_ewen = false; |
| 276 | m_state = STATE_IDLE; |
| 277 | break; |
| 278 | |
| 279 | case WRAL: |
| 280 | if (LOG) logerror("NMC9306 '%s' WRAL\n", tag()); |
| 281 | break; |
| 282 | |
| 283 | case ERAL: |
| 284 | if (LOG) logerror("NMC9306 '%s' ERAL\n", tag()); |
| 285 | break; |
| 286 | |
| 287 | case EWEN: |
| 288 | if (LOG) logerror("NMC9306 '%s' EWEN\n", tag()); |
| 289 | m_ewen = true; |
| 290 | m_state = STATE_IDLE; |
| 291 | break; |
| 292 | } |
| 293 | break; |
| 294 | |
| 295 | case WRITE: |
| 296 | if (LOG) logerror("NMC9306 '%s' WRITE %u\n", tag(), m_address & 0x0f); |
| 297 | m_state = STATE_DATA_IN; |
| 298 | break; |
| 299 | |
| 300 | case READ: |
| 301 | if (LOG) logerror("NMC9306 '%s' READ %u\n", tag(), m_address & 0x0f); |
| 302 | m_data = read(m_address & 0x0f); |
| 303 | m_state = STATE_DATA_OUT; |
| 304 | break; |
| 305 | |
| 306 | case ERASE: |
| 307 | if (LOG) logerror("NMC9306 '%s' ERASE %u\n", tag(), m_address & 0x0f); |
| 308 | erase(m_address & 0x0f); |
| 309 | m_state = STATE_ERASE; |
| 310 | break; |
| 311 | } |
| 312 | |
| 313 | m_bits = 0; |
| 314 | } |
| 315 | break; |
| 316 | |
| 317 | case STATE_DATA_IN: |
| 318 | if (LOG) logerror("NMC9306 '%s' Data Bit IN %u\n", tag(), m_di); |
| 319 | |
| 320 | m_data <<= 1; |
| 321 | m_data |= m_di; |
| 322 | m_bits++; |
| 323 | |
| 324 | if (m_bits == 16) |
| 325 | { |
| 326 | write(m_address & 0x0f, m_data); |
| 327 | |
| 328 | m_state = STATE_IDLE; |
| 329 | } |
| 330 | break; |
| 331 | |
| 332 | case STATE_DATA_OUT: |
| 333 | if (LOG) logerror("NMC9306 '%s' Data Bit OUT %u\n", tag(), m_di); |
| 334 | |
| 335 | m_do = BIT(m_data, 15); |
| 336 | m_data <<= 1; |
| 337 | m_bits++; |
| 338 | |
| 339 | if (m_bits == 16) |
| 340 | { |
| 341 | m_state = STATE_IDLE; |
| 342 | } |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | |
| 348 | //------------------------------------------------- |
| 349 | // di_w - serial data input |
| 350 | //------------------------------------------------- |
| 351 | |
| 352 | WRITE_LINE_MEMBER( nmc9306_device::di_w ) |
| 353 | { |
| 354 | m_di = state; |
| 355 | } |
| 356 | |
| 357 | |
| 358 | //------------------------------------------------- |
| 359 | // do_r - serial data output |
| 360 | //------------------------------------------------- |
| 361 | |
| 362 | READ_LINE_MEMBER( nmc9306_device::do_r ) |
| 363 | { |
| 364 | return m_do; |
| 365 | } |
src/emu/machine/i8155.c
| r0 | r10969 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | Intel 8155 - 2048-Bit Static MOS RAM with I/O Ports and Timer emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | /* |
| 11 | |
| 12 | TODO: |
| 13 | |
| 14 | - strobed mode |
| 15 | |
| 16 | */ |
| 17 | |
| 18 | #include "emu.h" |
| 19 | #include "i8155.h" |
| 20 | |
| 21 | |
| 22 | |
| 23 | //************************************************************************** |
| 24 | // MACROS / CONSTANTS |
| 25 | //************************************************************************** |
| 26 | |
| 27 | #define LOG 1 |
| 28 | |
| 29 | enum |
| 30 | { |
| 31 | REGISTER_COMMAND = 0, |
| 32 | REGISTER_STATUS = 0, |
| 33 | REGISTER_PORT_A, |
| 34 | REGISTER_PORT_B, |
| 35 | REGISTER_PORT_C, |
| 36 | REGISTER_TIMER_LOW, |
| 37 | REGISTER_TIMER_HIGH |
| 38 | }; |
| 39 | |
| 40 | enum |
| 41 | { |
| 42 | PORT_A = 0, |
| 43 | PORT_B, |
| 44 | PORT_C, |
| 45 | PORT_COUNT |
| 46 | }; |
| 47 | |
| 48 | enum |
| 49 | { |
| 50 | PORT_MODE_INPUT = 0, |
| 51 | PORT_MODE_OUTPUT, |
| 52 | PORT_MODE_STROBED_PORT_A, // not supported |
| 53 | PORT_MODE_STROBED // not supported |
| 54 | }; |
| 55 | |
| 56 | enum |
| 57 | { |
| 58 | MEMORY = 0, |
| 59 | IO |
| 60 | }; |
| 61 | |
| 62 | #define COMMAND_PA 0x01 |
| 63 | #define COMMAND_PB 0x02 |
| 64 | #define COMMAND_PC_MASK 0x0c |
| 65 | #define COMMAND_PC_ALT_1 0x00 |
| 66 | #define COMMAND_PC_ALT_2 0x0c |
| 67 | #define COMMAND_PC_ALT_3 0x04 // not supported |
| 68 | #define COMMAND_PC_ALT_4 0x08 // not supported |
| 69 | #define COMMAND_IEA 0x10 // not supported |
| 70 | #define COMMAND_IEB 0x20 // not supported |
| 71 | #define COMMAND_TM_MASK 0xc0 |
| 72 | #define COMMAND_TM_NOP 0x00 |
| 73 | #define COMMAND_TM_STOP 0x40 |
| 74 | #define COMMAND_TM_STOP_AFTER_TC 0x80 |
| 75 | #define COMMAND_TM_START 0xc0 |
| 76 | |
| 77 | #define STATUS_INTR_A 0x01 // not supported |
| 78 | #define STATUS_A_BF 0x02 // not supported |
| 79 | #define STATUS_INTE_A 0x04 // not supported |
| 80 | #define STATUS_INTR_B 0x08 // not supported |
| 81 | #define STATUS_B_BF 0x10 // not supported |
| 82 | #define STATUS_INTE_B 0x20 // not supported |
| 83 | #define STATUS_TIMER 0x40 |
| 84 | |
| 85 | #define TIMER_MODE_MASK 0xc0 |
| 86 | #define TIMER_MODE_LOW 0x00 |
| 87 | #define TIMER_MODE_SQUARE_WAVE 0x40 |
| 88 | #define TIMER_MODE_SINGLE_PULSE 0x80 |
| 89 | #define TIMER_MODE_AUTOMATIC_RELOAD 0xc0 |
| 90 | |
| 91 | |
| 92 | |
| 93 | //************************************************************************** |
| 94 | // GLOBAL VARIABLES |
| 95 | //************************************************************************** |
| 96 | |
| 97 | // devices |
| 98 | const device_type I8155 = i8155_device_config::static_alloc_device_config; |
| 99 | |
| 100 | |
| 101 | // default address map |
| 102 | static ADDRESS_MAP_START( i8155, AS_0, 8 ) |
| 103 | AM_RANGE(0x00, 0xff) AM_RAM |
| 104 | ADDRESS_MAP_END |
| 105 | |
| 106 | |
| 107 | |
| 108 | //************************************************************************** |
| 109 | // DEVICE CONFIGURATION |
| 110 | //************************************************************************** |
| 111 | |
| 112 | //------------------------------------------------- |
| 113 | // i8155_device_config - constructor |
| 114 | //------------------------------------------------- |
| 115 | |
| 116 | i8155_device_config::i8155_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 117 | : device_config(mconfig, static_alloc_device_config, "Intel 8155", tag, owner, clock), |
| 118 | device_config_memory_interface(mconfig, *this), |
| 119 | m_space_config("ram", ENDIANNESS_LITTLE, 8, 8, 0, NULL, *ADDRESS_MAP_NAME(i8155)) |
| 120 | { |
| 121 | } |
| 122 | |
| 123 | |
| 124 | //------------------------------------------------- |
| 125 | // static_alloc_device_config - allocate a new |
| 126 | // configuration object |
| 127 | //------------------------------------------------- |
| 128 | |
| 129 | device_config *i8155_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 130 | { |
| 131 | return global_alloc(i8155_device_config(mconfig, tag, owner, clock)); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | //------------------------------------------------- |
| 136 | // alloc_device - allocate a new device object |
| 137 | //------------------------------------------------- |
| 138 | |
| 139 | device_t *i8155_device_config::alloc_device(running_machine &machine) const |
| 140 | { |
| 141 | return auto_alloc(&machine, i8155_device(machine, *this)); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | //------------------------------------------------- |
| 146 | // memory_space_config - return a description of |
| 147 | // any address spaces owned by this device |
| 148 | //------------------------------------------------- |
| 149 | |
| 150 | const address_space_config *i8155_device_config::memory_space_config(address_spacenum spacenum) const |
| 151 | { |
| 152 | return (spacenum == AS_0) ? &m_space_config : NULL; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | //------------------------------------------------- |
| 157 | // device_config_complete - perform any |
| 158 | // operations now that the configuration is |
| 159 | // complete |
| 160 | //------------------------------------------------- |
| 161 | |
| 162 | void i8155_device_config::device_config_complete() |
| 163 | { |
| 164 | // inherit a copy of the static data |
| 165 | const i8155_interface *intf = reinterpret_cast<const i8155_interface *>(static_config()); |
| 166 | if (intf != NULL) |
| 167 | *static_cast<i8155_interface *>(this) = *intf; |
| 168 | |
| 169 | // or initialize to defaults if none provided |
| 170 | else |
| 171 | { |
| 172 | memset(&in_pa_func, 0, sizeof(in_pa_func)); |
| 173 | memset(&out_pa_func, 0, sizeof(out_pa_func)); |
| 174 | memset(&in_pb_func, 0, sizeof(in_pb_func)); |
| 175 | memset(&out_pb_func, 0, sizeof(out_pb_func)); |
| 176 | memset(&in_pc_func, 0, sizeof(in_pc_func)); |
| 177 | memset(&out_pc_func, 0, sizeof(out_pc_func)); |
| 178 | memset(&out_to_func, 0, sizeof(out_to_func)); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | |
| 183 | |
| 184 | //************************************************************************** |
| 185 | // INLINE HELPERS |
| 186 | //************************************************************************** |
| 187 | |
| 188 | inline UINT8 i8155_device::get_timer_mode() |
| 189 | { |
| 190 | return (m_count_length >> 8) & TIMER_MODE_MASK; |
| 191 | } |
| 192 | |
| 193 | inline void i8155_device::timer_output() |
| 194 | { |
| 195 | devcb_call_write_line(&m_out_to_func, m_to); |
| 196 | |
| 197 | if (LOG) logerror("8155 '%s' Timer Output: %u\n", tag(), m_to); |
| 198 | } |
| 199 | |
| 200 | inline void i8155_device::pulse_timer_output() |
| 201 | { |
| 202 | m_to = 0; timer_output(); |
| 203 | m_to = 1; timer_output(); |
| 204 | } |
| 205 | |
| 206 | inline int i8155_device::get_port_mode(int port) |
| 207 | { |
| 208 | int mode = -1; |
| 209 | |
| 210 | switch (port) |
| 211 | { |
| 212 | case PORT_A: |
| 213 | mode = (m_command & COMMAND_PA) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT; |
| 214 | break; |
| 215 | |
| 216 | case PORT_B: |
| 217 | mode = (m_command & COMMAND_PB) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT; |
| 218 | break; |
| 219 | |
| 220 | case PORT_C: |
| 221 | switch (m_command & COMMAND_PC_MASK) |
| 222 | { |
| 223 | case COMMAND_PC_ALT_1: mode = PORT_MODE_INPUT; break; |
| 224 | case COMMAND_PC_ALT_2: mode = PORT_MODE_OUTPUT; break; |
| 225 | case COMMAND_PC_ALT_3: mode = PORT_MODE_STROBED_PORT_A; break; |
| 226 | case COMMAND_PC_ALT_4: mode = PORT_MODE_STROBED; break; |
| 227 | } |
| 228 | break; |
| 229 | } |
| 230 | |
| 231 | return mode; |
| 232 | } |
| 233 | |
| 234 | inline UINT8 i8155_device::read_port(int port) |
| 235 | { |
| 236 | UINT8 data = 0; |
| 237 | |
| 238 | switch (port) |
| 239 | { |
| 240 | case PORT_A: |
| 241 | case PORT_B: |
| 242 | switch (get_port_mode(port)) |
| 243 | { |
| 244 | case PORT_MODE_INPUT: |
| 245 | data = devcb_call_read8(&m_in_port_func[port], 0); |
| 246 | break; |
| 247 | |
| 248 | case PORT_MODE_OUTPUT: |
| 249 | data = m_output[port]; |
| 250 | break; |
| 251 | } |
| 252 | break; |
| 253 | |
| 254 | case PORT_C: |
| 255 | switch (get_port_mode(PORT_C)) |
| 256 | { |
| 257 | case PORT_MODE_INPUT: |
| 258 | data = devcb_call_read8(&m_in_port_func[port], 0) & 0x3f; |
| 259 | break; |
| 260 | |
| 261 | case PORT_MODE_OUTPUT: |
| 262 | data = m_output[port] & 0x3f; |
| 263 | break; |
| 264 | |
| 265 | default: |
| 266 | logerror("8155 '%s' Unsupported Port C mode!\n", tag()); |
| 267 | } |
| 268 | break; |
| 269 | } |
| 270 | |
| 271 | return data; |
| 272 | } |
| 273 | |
| 274 | inline void i8155_device::write_port(int port, UINT8 data) |
| 275 | { |
| 276 | switch (get_port_mode(port)) |
| 277 | { |
| 278 | case PORT_MODE_OUTPUT: |
| 279 | m_output[port] = data; |
| 280 | devcb_call_write8(&m_out_port_func[port], 0, m_output[port]); |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | |
| 286 | //************************************************************************** |
| 287 | // LIVE DEVICE |
| 288 | //************************************************************************** |
| 289 | |
| 290 | //------------------------------------------------- |
| 291 | // i8155_device - constructor |
| 292 | //------------------------------------------------- |
| 293 | |
| 294 | i8155_device::i8155_device(running_machine &_machine, const i8155_device_config &config) |
| 295 | : device_t(_machine, config), |
| 296 | device_memory_interface(_machine, config, *this), |
| 297 | m_config(config) |
| 298 | { |
| 299 | |
| 300 | } |
| 301 | |
| 302 | |
| 303 | //------------------------------------------------- |
| 304 | // device_start - device-specific startup |
| 305 | //------------------------------------------------- |
| 306 | |
| 307 | void i8155_device::device_start() |
| 308 | { |
| 309 | // resolve callbacks |
| 310 | devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this); |
| 311 | devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this); |
| 312 | devcb_resolve_read8(&m_in_port_func[2], &m_config.in_pc_func, this); |
| 313 | devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this); |
| 314 | devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this); |
| 315 | devcb_resolve_write8(&m_out_port_func[2], &m_config.out_pc_func, this); |
| 316 | devcb_resolve_write_line(&m_out_to_func, &m_config.out_to_func, this); |
| 317 | |
| 318 | // allocate timers |
| 319 | m_timer = timer_alloc(); |
| 320 | |
| 321 | // register for state saving |
| 322 | save_item(NAME(m_io_m)); |
| 323 | save_item(NAME(m_ad)); |
| 324 | save_item(NAME(m_command)); |
| 325 | save_item(NAME(m_status)); |
| 326 | save_item(NAME(m_output)); |
| 327 | save_item(NAME(m_count_length)); |
| 328 | save_item(NAME(m_counter)); |
| 329 | save_item(NAME(m_to)); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | //------------------------------------------------- |
| 334 | // device_reset - device-specific reset |
| 335 | //------------------------------------------------- |
| 336 | |
| 337 | void i8155_device::device_reset() |
| 338 | { |
| 339 | // clear output registers |
| 340 | m_output[PORT_A] = 0; |
| 341 | m_output[PORT_B] = 0; |
| 342 | m_output[PORT_C] = 0; |
| 343 | |
| 344 | // set ports to input mode |
| 345 | register_w(REGISTER_COMMAND, m_command & ~(COMMAND_PA | COMMAND_PB | COMMAND_PC_MASK)); |
| 346 | |
| 347 | // clear timer flag |
| 348 | m_status &= ~STATUS_TIMER; |
| 349 | |
| 350 | // stop counting |
| 351 | m_timer->enable(0); |
| 352 | |
| 353 | // clear timer output |
| 354 | m_to = 1; |
| 355 | timer_output(); |
| 356 | } |
| 357 | |
| 358 | |
| 359 | //------------------------------------------------- |
| 360 | // device_timer - handler timer events |
| 361 | //------------------------------------------------- |
| 362 | |
| 363 | void i8155_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 364 | { |
| 365 | // count down |
| 366 | m_counter--; |
| 367 | |
| 368 | if (get_timer_mode() == TIMER_MODE_LOW) |
| 369 | { |
| 370 | // pulse on every count |
| 371 | pulse_timer_output(); |
| 372 | } |
| 373 | |
| 374 | if (m_counter == 0) |
| 375 | { |
| 376 | if (LOG) logerror("8155 '%s' Timer Count Reached\n", tag()); |
| 377 | |
| 378 | switch (m_command & COMMAND_TM_MASK) |
| 379 | { |
| 380 | case COMMAND_TM_STOP_AFTER_TC: |
| 381 | // stop timer |
| 382 | m_timer->enable(0); |
| 383 | |
| 384 | if (LOG) logerror("8155 '%s' Timer Stopped\n", tag()); |
| 385 | break; |
| 386 | } |
| 387 | |
| 388 | switch (get_timer_mode()) |
| 389 | { |
| 390 | case TIMER_MODE_SQUARE_WAVE: |
| 391 | // toggle timer output |
| 392 | m_to = !m_to; |
| 393 | timer_output(); |
| 394 | break; |
| 395 | |
| 396 | case TIMER_MODE_SINGLE_PULSE: |
| 397 | // single pulse upon TC being reached |
| 398 | pulse_timer_output(); |
| 399 | |
| 400 | // clear timer mode setting |
| 401 | m_command &= ~COMMAND_TM_MASK; |
| 402 | break; |
| 403 | |
| 404 | case TIMER_MODE_AUTOMATIC_RELOAD: |
| 405 | // automatic reload, i.e. single pulse every time TC is reached |
| 406 | pulse_timer_output(); |
| 407 | break; |
| 408 | } |
| 409 | |
| 410 | // set timer flag |
| 411 | m_status |= STATUS_TIMER; |
| 412 | |
| 413 | // reload timer counter |
| 414 | m_counter = m_count_length & 0x3fff; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | |
| 419 | //------------------------------------------------- |
| 420 | // io_r - register read |
| 421 | //------------------------------------------------- |
| 422 | |
| 423 | READ8_MEMBER( i8155_device::io_r ) |
| 424 | { |
| 425 | UINT8 data = 0; |
| 426 | |
| 427 | switch (offset & 0x03) |
| 428 | { |
| 429 | case REGISTER_STATUS: |
| 430 | data = m_status; |
| 431 | |
| 432 | // clear timer flag |
| 433 | m_status &= ~STATUS_TIMER; |
| 434 | break; |
| 435 | |
| 436 | case REGISTER_PORT_A: |
| 437 | data = read_port(PORT_A); |
| 438 | break; |
| 439 | |
| 440 | case REGISTER_PORT_B: |
| 441 | data = read_port(PORT_B); |
| 442 | break; |
| 443 | |
| 444 | case REGISTER_PORT_C: |
| 445 | data = read_port(PORT_C); |
| 446 | break; |
| 447 | } |
| 448 | |
| 449 | return data; |
| 450 | } |
| 451 | |
| 452 | |
| 453 | //------------------------------------------------- |
| 454 | // register_w - register write |
| 455 | //------------------------------------------------- |
| 456 | |
| 457 | void i8155_device::register_w(int offset, UINT8 data) |
| 458 | { |
| 459 | switch (offset & 0x07) |
| 460 | { |
| 461 | case REGISTER_COMMAND: |
| 462 | m_command = data; |
| 463 | |
| 464 | if (LOG) logerror("8155 '%s' Port A Mode: %s\n", tag(), (data & COMMAND_PA) ? "output" : "input"); |
| 465 | if (LOG) logerror("8155 '%s' Port B Mode: %s\n", tag(), (data & COMMAND_PB) ? "output" : "input"); |
| 466 | |
| 467 | if (LOG) logerror("8155 '%s' Port A Interrupt: %s\n", tag(), (data & COMMAND_IEA) ? "enabled" : "disabled"); |
| 468 | if (LOG) logerror("8155 '%s' Port B Interrupt: %s\n", tag(), (data & COMMAND_IEB) ? "enabled" : "disabled"); |
| 469 | |
| 470 | switch (data & COMMAND_PC_MASK) |
| 471 | { |
| 472 | case COMMAND_PC_ALT_1: |
| 473 | if (LOG) logerror("8155 '%s' Port C Mode: Alt 1\n", tag()); |
| 474 | break; |
| 475 | |
| 476 | case COMMAND_PC_ALT_2: |
| 477 | if (LOG) logerror("8155 '%s' Port C Mode: Alt 2\n", tag()); |
| 478 | break; |
| 479 | |
| 480 | case COMMAND_PC_ALT_3: |
| 481 | if (LOG) logerror("8155 '%s' Port C Mode: Alt 3\n", tag()); |
| 482 | break; |
| 483 | |
| 484 | case COMMAND_PC_ALT_4: |
| 485 | if (LOG) logerror("8155 '%s' Port C Mode: Alt 4\n", tag()); |
| 486 | break; |
| 487 | } |
| 488 | |
| 489 | switch (data & COMMAND_TM_MASK) |
| 490 | { |
| 491 | case COMMAND_TM_NOP: |
| 492 | // do not affect counter operation |
| 493 | break; |
| 494 | |
| 495 | case COMMAND_TM_STOP: |
| 496 | // NOP if timer has not started, stop counting if the timer is running |
| 497 | if (LOG) logerror("8155 '%s' Timer Command: Stop\n", tag()); |
| 498 | m_timer->enable(0); |
| 499 | break; |
| 500 | |
| 501 | case COMMAND_TM_STOP_AFTER_TC: |
| 502 | // stop immediately after present TC is reached (NOP if timer has not started) |
| 503 | if (LOG) logerror("8155 '%s' Timer Command: Stop after TC\n", tag()); |
| 504 | break; |
| 505 | |
| 506 | case COMMAND_TM_START: |
| 507 | if (LOG) logerror("8155 '%s' Timer Command: Start\n", tag()); |
| 508 | |
| 509 | if (m_timer->enabled()) |
| 510 | { |
| 511 | // if timer is running, start the new mode and CNT length immediately after present TC is reached |
| 512 | } |
| 513 | else |
| 514 | { |
| 515 | // load mode and CNT length and start immediately after loading (if timer is not running) |
| 516 | m_counter = m_count_length; |
| 517 | m_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); |
| 518 | } |
| 519 | break; |
| 520 | } |
| 521 | break; |
| 522 | |
| 523 | case REGISTER_PORT_A: |
| 524 | write_port(PORT_A, data); |
| 525 | break; |
| 526 | |
| 527 | case REGISTER_PORT_B: |
| 528 | write_port(PORT_B, data); |
| 529 | break; |
| 530 | |
| 531 | case REGISTER_PORT_C: |
| 532 | write_port(PORT_C, data); |
| 533 | break; |
| 534 | |
| 535 | case REGISTER_TIMER_LOW: |
| 536 | m_count_length = (m_count_length & 0xff00) | data; |
| 537 | if (LOG) logerror("8155 '%s' Count Length Low: %04x\n", tag(), m_count_length); |
| 538 | break; |
| 539 | |
| 540 | case REGISTER_TIMER_HIGH: |
| 541 | m_count_length = (data << 8) | (m_count_length & 0xff); |
| 542 | if (LOG) logerror("8155 '%s' Count Length High: %04x\n", tag(), m_count_length); |
| 543 | |
| 544 | switch (data & TIMER_MODE_MASK) |
| 545 | { |
| 546 | case TIMER_MODE_LOW: |
| 547 | // puts out LOW during second half of count |
| 548 | if (LOG) logerror("8155 '%s' Timer Mode: LOW\n", tag()); |
| 549 | break; |
| 550 | |
| 551 | case TIMER_MODE_SQUARE_WAVE: |
| 552 | // square wave, i.e. the period of the square wave equals the count length programmed with automatic reload at terminal count |
| 553 | if (LOG) logerror("8155 '%s' Timer Mode: Square wave\n", tag()); |
| 554 | break; |
| 555 | |
| 556 | case TIMER_MODE_SINGLE_PULSE: |
| 557 | // single pulse upon TC being reached |
| 558 | if (LOG) logerror("8155 '%s' Timer Mode: Single pulse\n", tag()); |
| 559 | break; |
| 560 | |
| 561 | case TIMER_MODE_AUTOMATIC_RELOAD: |
| 562 | // automatic reload, i.e. single pulse every time TC is reached |
| 563 | if (LOG) logerror("8155 '%s' Timer Mode: Automatic reload\n", tag()); |
| 564 | break; |
| 565 | } |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | //------------------------------------------------- |
| 571 | // io_w - register write |
| 572 | //------------------------------------------------- |
| 573 | |
| 574 | WRITE8_MEMBER( i8155_device::io_w ) |
| 575 | { |
| 576 | register_w(offset, data); |
| 577 | } |
| 578 | |
| 579 | |
| 580 | //------------------------------------------------- |
| 581 | // memory_r - internal RAM read |
| 582 | //------------------------------------------------- |
| 583 | |
| 584 | READ8_MEMBER( i8155_device::memory_r ) |
| 585 | { |
| 586 | return this->space()->read_byte(offset); |
| 587 | } |
| 588 | |
| 589 | |
| 590 | //------------------------------------------------- |
| 591 | // memory_w - internal RAM write |
| 592 | //------------------------------------------------- |
| 593 | |
| 594 | WRITE8_MEMBER( i8155_device::memory_w ) |
| 595 | { |
| 596 | this->space()->write_byte(offset, data); |
| 597 | } |
| 598 | |
| 599 | |
| 600 | //------------------------------------------------- |
| 601 | // ale_w - address latch write |
| 602 | //------------------------------------------------- |
| 603 | |
| 604 | WRITE8_MEMBER( i8155_device::ale_w ) |
| 605 | { |
| 606 | // I/O / memory select |
| 607 | m_io_m = BIT(offset, 0); |
| 608 | |
| 609 | // address |
| 610 | m_ad = data; |
| 611 | } |
| 612 | |
| 613 | |
| 614 | //------------------------------------------------- |
| 615 | // read - memory or I/O read |
| 616 | //------------------------------------------------- |
| 617 | |
| 618 | READ8_MEMBER( i8155_device::read ) |
| 619 | { |
| 620 | UINT8 data = 0; |
| 621 | |
| 622 | switch (m_io_m) |
| 623 | { |
| 624 | case MEMORY: |
| 625 | data = memory_r(space, m_ad); |
| 626 | break; |
| 627 | |
| 628 | case IO: |
| 629 | data = io_r(space, m_ad); |
| 630 | break; |
| 631 | } |
| 632 | |
| 633 | return data; |
| 634 | } |
| 635 | |
| 636 | |
| 637 | //------------------------------------------------- |
| 638 | // write - memory or I/O write |
| 639 | //------------------------------------------------- |
| 640 | |
| 641 | WRITE8_MEMBER( i8155_device::write ) |
| 642 | { |
| 643 | switch (m_io_m) |
| 644 | { |
| 645 | case MEMORY: |
| 646 | memory_w(space, m_ad, data); |
| 647 | break; |
| 648 | |
| 649 | case IO: |
| 650 | io_w(space, m_ad, data); |
| 651 | break; |
| 652 | } |
| 653 | } |
src/emu/machine/i8355.c
| r0 | r10969 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | Intel 8355 - 16,384-Bit ROM with I/O emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #include "emu.h" |
| 11 | #include "i8355.h" |
| 12 | |
| 13 | |
| 14 | |
| 15 | //************************************************************************** |
| 16 | // MACROS / CONSTANTS |
| 17 | //************************************************************************** |
| 18 | |
| 19 | #define LOG 0 |
| 20 | |
| 21 | enum |
| 22 | { |
| 23 | REGISTER_PORT_A = 0, |
| 24 | REGISTER_PORT_B, |
| 25 | REGISTER_PORT_A_DDR, |
| 26 | REGISTER_PORT_B_DDR |
| 27 | }; |
| 28 | |
| 29 | enum |
| 30 | { |
| 31 | PORT_A = 0, |
| 32 | PORT_B, |
| 33 | PORT_COUNT |
| 34 | }; |
| 35 | |
| 36 | |
| 37 | |
| 38 | //************************************************************************** |
| 39 | // GLOBAL VARIABLES |
| 40 | //************************************************************************** |
| 41 | |
| 42 | // devices |
| 43 | const device_type I8355 = i8355_device_config::static_alloc_device_config; |
| 44 | |
| 45 | |
| 46 | // default address map |
| 47 | static ADDRESS_MAP_START( i8355, AS_0, 8 ) |
| 48 | AM_RANGE(0x000, 0x7ff) AM_ROM |
| 49 | ADDRESS_MAP_END |
| 50 | |
| 51 | |
| 52 | |
| 53 | //************************************************************************** |
| 54 | // DEVICE CONFIGURATION |
| 55 | //************************************************************************** |
| 56 | |
| 57 | //------------------------------------------------- |
| 58 | // i8355_device_config - constructor |
| 59 | //------------------------------------------------- |
| 60 | |
| 61 | i8355_device_config::i8355_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 62 | : device_config(mconfig, static_alloc_device_config, "Intel 8355", tag, owner, clock), |
| 63 | device_config_memory_interface(mconfig, *this), |
| 64 | m_space_config("ram", ENDIANNESS_LITTLE, 8, 11, 0, NULL, *ADDRESS_MAP_NAME(i8355)) |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | |
| 69 | //------------------------------------------------- |
| 70 | // static_alloc_device_config - allocate a new |
| 71 | // configuration object |
| 72 | //------------------------------------------------- |
| 73 | |
| 74 | device_config *i8355_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 75 | { |
| 76 | return global_alloc(i8355_device_config(mconfig, tag, owner, clock)); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | //------------------------------------------------- |
| 81 | // alloc_device - allocate a new device object |
| 82 | //------------------------------------------------- |
| 83 | |
| 84 | device_t *i8355_device_config::alloc_device(running_machine &machine) const |
| 85 | { |
| 86 | return auto_alloc(&machine, i8355_device(machine, *this)); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | //------------------------------------------------- |
| 91 | // memory_space_config - return a description of |
| 92 | // any address spaces owned by this device |
| 93 | //------------------------------------------------- |
| 94 | |
| 95 | const address_space_config *i8355_device_config::memory_space_config(address_spacenum spacenum) const |
| 96 | { |
| 97 | return (spacenum == AS_0) ? &m_space_config : NULL; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | //------------------------------------------------- |
| 102 | // device_config_complete - perform any |
| 103 | // operations now that the configuration is |
| 104 | // complete |
| 105 | //------------------------------------------------- |
| 106 | |
| 107 | void i8355_device_config::device_config_complete() |
| 108 | { |
| 109 | // inherit a copy of the static data |
| 110 | const i8355_interface *intf = reinterpret_cast<const i8355_interface *>(static_config()); |
| 111 | if (intf != NULL) |
| 112 | *static_cast<i8355_interface *>(this) = *intf; |
| 113 | |
| 114 | // or initialize to defaults if none provided |
| 115 | else |
| 116 | { |
| 117 | memset(&in_pa_func, 0, sizeof(in_pa_func)); |
| 118 | memset(&out_pa_func, 0, sizeof(out_pa_func)); |
| 119 | memset(&in_pb_func, 0, sizeof(in_pb_func)); |
| 120 | memset(&out_pb_func, 0, sizeof(out_pb_func)); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | |
| 125 | |
| 126 | //************************************************************************** |
| 127 | // INLINE HELPERS |
| 128 | //************************************************************************** |
| 129 | |
| 130 | //------------------------------------------------- |
| 131 | // read_port - read from input port |
| 132 | //------------------------------------------------- |
| 133 | |
| 134 | inline UINT8 i8355_device::read_port(int port) |
| 135 | { |
| 136 | UINT8 data = m_output[port] & m_ddr[port]; |
| 137 | |
| 138 | if (m_ddr[port] != 0xff) |
| 139 | { |
| 140 | data |= devcb_call_read8(&m_in_port_func[port], 0) & ~m_ddr[port]; |
| 141 | } |
| 142 | |
| 143 | return data; |
| 144 | } |
| 145 | |
| 146 | |
| 147 | //------------------------------------------------- |
| 148 | // write_port - write to output port |
| 149 | //------------------------------------------------- |
| 150 | |
| 151 | inline void i8355_device::write_port(int port, UINT8 data) |
| 152 | { |
| 153 | m_output[port] = data; |
| 154 | |
| 155 | devcb_call_write8(&m_out_port_func[port], 0, m_output[port] & m_ddr[port]); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | |
| 160 | //************************************************************************** |
| 161 | // LIVE DEVICE |
| 162 | //************************************************************************** |
| 163 | |
| 164 | //------------------------------------------------- |
| 165 | // i8355_device - constructor |
| 166 | //------------------------------------------------- |
| 167 | |
| 168 | i8355_device::i8355_device(running_machine &_machine, const i8355_device_config &config) |
| 169 | : device_t(_machine, config), |
| 170 | device_memory_interface(_machine, config, *this), |
| 171 | m_config(config) |
| 172 | { |
| 173 | |
| 174 | } |
| 175 | |
| 176 | |
| 177 | //------------------------------------------------- |
| 178 | // device_start - device-specific startup |
| 179 | //------------------------------------------------- |
| 180 | |
| 181 | void i8355_device::device_start() |
| 182 | { |
| 183 | // resolve callbacks |
| 184 | devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this); |
| 185 | devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this); |
| 186 | devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this); |
| 187 | devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this); |
| 188 | |
| 189 | // register for state saving |
| 190 | save_item(NAME(m_output)); |
| 191 | save_item(NAME(m_ddr)); |
| 192 | } |
| 193 | |
| 194 | |
| 195 | //------------------------------------------------- |
| 196 | // device_reset - device-specific reset |
| 197 | //------------------------------------------------- |
| 198 | |
| 199 | void i8355_device::device_reset() |
| 200 | { |
| 201 | // set ports to input mode |
| 202 | m_ddr[PORT_A] = 0; |
| 203 | m_ddr[PORT_B] = 0; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | //------------------------------------------------- |
| 208 | // io_r - register read |
| 209 | //------------------------------------------------- |
| 210 | |
| 211 | READ8_MEMBER( i8355_device::io_r ) |
| 212 | { |
| 213 | int port = offset & 0x01; |
| 214 | |
| 215 | UINT8 data = 0; |
| 216 | |
| 217 | switch (offset & 0x03) |
| 218 | { |
| 219 | case REGISTER_PORT_A: |
| 220 | case REGISTER_PORT_B: |
| 221 | data = read_port(port); |
| 222 | break; |
| 223 | |
| 224 | case REGISTER_PORT_A_DDR: |
| 225 | case REGISTER_PORT_B_DDR: |
| 226 | // write only |
| 227 | break; |
| 228 | } |
| 229 | |
| 230 | return data; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | //------------------------------------------------- |
| 235 | // io_w - register write |
| 236 | //------------------------------------------------- |
| 237 | |
| 238 | WRITE8_MEMBER( i8355_device::io_w ) |
| 239 | { |
| 240 | int port = offset & 0x01; |
| 241 | |
| 242 | switch (offset & 0x03) |
| 243 | { |
| 244 | case REGISTER_PORT_A: |
| 245 | case REGISTER_PORT_B: |
| 246 | if (LOG) logerror("I8355 '%s' Port %c Write %02x\n", tag(), 'A' + port, data); |
| 247 | |
| 248 | write_port(port, data); |
| 249 | break; |
| 250 | |
| 251 | case REGISTER_PORT_A_DDR: |
| 252 | case REGISTER_PORT_B_DDR: |
| 253 | if (LOG) logerror("I8355 '%s' Port %c DDR: %02x\n", tag(), 'A' + port, data); |
| 254 | |
| 255 | m_ddr[port] = data; |
| 256 | write_port(port, data); |
| 257 | break; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | |
| 262 | //------------------------------------------------- |
| 263 | // memory_r - internal ROM read |
| 264 | //------------------------------------------------- |
| 265 | |
| 266 | READ8_MEMBER( i8355_device::memory_r ) |
| 267 | { |
| 268 | return this->space()->read_byte(offset); |
| 269 | } |
src/mess/machine/cdp1871.c
| r10968 | r10969 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | RCA CDP1871 Keyboard Encoder emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | **********************************************************************/ |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "cdp1871.h" |
| 12 | | #include "cpu/mcs48/mcs48.h" |
| 13 | | #include "machine/devhelpr.h" |
| 14 | | |
| 15 | | |
| 16 | | |
| 17 | | //************************************************************************** |
| 18 | | // MACROS / CONSTANTS |
| 19 | | //************************************************************************** |
| 20 | | |
| 21 | | static const UINT8 CDP1871_KEY_CODES[4][11][8] = |
| 22 | | { |
| 23 | | // normal |
| 24 | | { |
| 25 | | { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 }, |
| 26 | | { 0x38, 0x39, 0x3a, 0x3b, 0x2c, 0x2d, 0x2e, 0x2f }, |
| 27 | | { 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67 }, |
| 28 | | { 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f }, |
| 29 | | { 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77 }, |
| 30 | | { 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f }, |
| 31 | | { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f }, |
| 32 | | { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 }, |
| 33 | | { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f }, |
| 34 | | { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 }, |
| 35 | | { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f } |
| 36 | | }, |
| 37 | | |
| 38 | | // alpha |
| 39 | | { |
| 40 | | { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 }, |
| 41 | | { 0x38, 0x39, 0x3a, 0x3b, 0x2c, 0x2d, 0x2e, 0x2f }, |
| 42 | | { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 }, |
| 43 | | { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }, |
| 44 | | { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 }, |
| 45 | | { 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f }, |
| 46 | | { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f }, |
| 47 | | { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 }, |
| 48 | | { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f }, |
| 49 | | { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 }, |
| 50 | | { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f } |
| 51 | | }, |
| 52 | | |
| 53 | | // shift |
| 54 | | { |
| 55 | | { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 }, |
| 56 | | { 0x28, 0x29, 0x2a, 0x2b, 0x3c, 0x3d, 0x3e, 0x3f }, |
| 57 | | { 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 }, |
| 58 | | { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }, |
| 59 | | { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 }, |
| 60 | | { 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f }, |
| 61 | | { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f }, |
| 62 | | { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 }, |
| 63 | | { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f }, |
| 64 | | { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 }, |
| 65 | | { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f } |
| 66 | | }, |
| 67 | | |
| 68 | | // control |
| 69 | | { |
| 70 | | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, |
| 71 | | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, |
| 72 | | { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, |
| 73 | | { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, |
| 74 | | { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }, |
| 75 | | { 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, |
| 76 | | { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f }, |
| 77 | | { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 }, |
| 78 | | { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f }, |
| 79 | | { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 }, |
| 80 | | { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f } |
| 81 | | } |
| 82 | | }; |
| 83 | | |
| 84 | | |
| 85 | | |
| 86 | | //************************************************************************** |
| 87 | | // DEVICE DEFINITIONS |
| 88 | | //************************************************************************** |
| 89 | | |
| 90 | | const device_type CDP1871 = cdp1871_device_config::static_alloc_device_config; |
| 91 | | |
| 92 | | |
| 93 | | |
| 94 | | //************************************************************************** |
| 95 | | // DEVICE CONFIGURATION |
| 96 | | //************************************************************************** |
| 97 | | |
| 98 | | GENERIC_DEVICE_CONFIG_SETUP(cdp1871, "RCA CDP1871") |
| 99 | | |
| 100 | | |
| 101 | | //------------------------------------------------- |
| 102 | | // device_config_complete - perform any |
| 103 | | // operations now that the configuration is |
| 104 | | // complete |
| 105 | | //------------------------------------------------- |
| 106 | | |
| 107 | | void cdp1871_device_config::device_config_complete() |
| 108 | | { |
| 109 | | // inherit a copy of the static data |
| 110 | | const cdp1871_interface *intf = reinterpret_cast<const cdp1871_interface *>(static_config()); |
| 111 | | if (intf != NULL) |
| 112 | | *static_cast<cdp1871_interface *>(this) = *intf; |
| 113 | | |
| 114 | | // or initialize to defaults if none provided |
| 115 | | else |
| 116 | | { |
| 117 | | memset(&out_da_func, 0, sizeof(out_da_func)); |
| 118 | | memset(&out_rpt_func, 0, sizeof(out_rpt_func)); |
| 119 | | // m_in_d_func[] |
| 120 | | memset(&in_shift_func, 0, sizeof(in_shift_func)); |
| 121 | | memset(&in_control_func, 0, sizeof(in_control_func)); |
| 122 | | memset(&in_alpha_func, 0, sizeof(in_alpha_func)); |
| 123 | | } |
| 124 | | } |
| 125 | | |
| 126 | | |
| 127 | | |
| 128 | | //************************************************************************** |
| 129 | | // LIVE DEVICE |
| 130 | | //************************************************************************** |
| 131 | | |
| 132 | | //------------------------------------------------- |
| 133 | | // cdp1871_device - constructor |
| 134 | | //------------------------------------------------- |
| 135 | | |
| 136 | | cdp1871_device::cdp1871_device(running_machine &_machine, const cdp1871_device_config &config) |
| 137 | | : device_t(_machine, config), |
| 138 | | m_inhibit(false), |
| 139 | | m_sense(0), |
| 140 | | m_drive(0), |
| 141 | | m_next_da(CLEAR_LINE), |
| 142 | | m_next_rpt(CLEAR_LINE), |
| 143 | | m_config(config) |
| 144 | | { |
| 145 | | |
| 146 | | } |
| 147 | | |
| 148 | | |
| 149 | | //------------------------------------------------- |
| 150 | | // device_start - device-specific startup |
| 151 | | //------------------------------------------------- |
| 152 | | |
| 153 | | void cdp1871_device::device_start() |
| 154 | | { |
| 155 | | // resolve callbacks |
| 156 | | devcb_resolve_write_line(&m_out_da_func, &m_config.out_da_func, this); |
| 157 | | devcb_resolve_write_line(&m_out_rpt_func, &m_config.out_rpt_func, this); |
| 158 | | devcb_resolve_read8(&m_in_d_func[0], &m_config.in_d1_func, this); |
| 159 | | devcb_resolve_read8(&m_in_d_func[1], &m_config.in_d2_func, this); |
| 160 | | devcb_resolve_read8(&m_in_d_func[2], &m_config.in_d3_func, this); |
| 161 | | devcb_resolve_read8(&m_in_d_func[3], &m_config.in_d4_func, this); |
| 162 | | devcb_resolve_read8(&m_in_d_func[4], &m_config.in_d5_func, this); |
| 163 | | devcb_resolve_read8(&m_in_d_func[5], &m_config.in_d6_func, this); |
| 164 | | devcb_resolve_read8(&m_in_d_func[6], &m_config.in_d7_func, this); |
| 165 | | devcb_resolve_read8(&m_in_d_func[7], &m_config.in_d8_func, this); |
| 166 | | devcb_resolve_read8(&m_in_d_func[8], &m_config.in_d9_func, this); |
| 167 | | devcb_resolve_read8(&m_in_d_func[9], &m_config.in_d10_func, this); |
| 168 | | devcb_resolve_read8(&m_in_d_func[10], &m_config.in_d11_func, this); |
| 169 | | devcb_resolve_read_line(&m_in_shift_func, &m_config.in_shift_func, this); |
| 170 | | devcb_resolve_read_line(&m_in_control_func, &m_config.in_control_func, this); |
| 171 | | devcb_resolve_read_line(&m_in_alpha_func, &m_config.in_alpha_func, this); |
| 172 | | |
| 173 | | // set initial values |
| 174 | | change_output_lines(); |
| 175 | | |
| 176 | | // allocate timers |
| 177 | | m_scan_timer = timer_alloc(); |
| 178 | | m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); |
| 179 | | |
| 180 | | // register for state saving |
| 181 | | save_item(NAME(m_inhibit)); |
| 182 | | save_item(NAME(m_sense)); |
| 183 | | save_item(NAME(m_drive)); |
| 184 | | save_item(NAME(m_shift)); |
| 185 | | save_item(NAME(m_control)); |
| 186 | | save_item(NAME(m_da)); |
| 187 | | save_item(NAME(m_next_da)); |
| 188 | | save_item(NAME(m_rpt)); |
| 189 | | save_item(NAME(m_next_rpt)); |
| 190 | | } |
| 191 | | |
| 192 | | |
| 193 | | //------------------------------------------------- |
| 194 | | // device_timer - handler timer events |
| 195 | | //------------------------------------------------- |
| 196 | | |
| 197 | | void cdp1871_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 198 | | { |
| 199 | | change_output_lines(); |
| 200 | | clock_scan_counters(); |
| 201 | | detect_keypress(); |
| 202 | | } |
| 203 | | |
| 204 | | |
| 205 | | //------------------------------------------------- |
| 206 | | // change_output_lines - change output lines |
| 207 | | //------------------------------------------------- |
| 208 | | |
| 209 | | void cdp1871_device::change_output_lines() |
| 210 | | { |
| 211 | | if (m_next_da != m_da) |
| 212 | | { |
| 213 | | m_da = m_next_da; |
| 214 | | |
| 215 | | devcb_call_write_line(&m_out_da_func, m_da); |
| 216 | | } |
| 217 | | |
| 218 | | if (m_next_rpt != m_rpt) |
| 219 | | { |
| 220 | | m_rpt = m_next_rpt; |
| 221 | | |
| 222 | | devcb_call_write_line(&m_out_rpt_func, m_rpt); |
| 223 | | } |
| 224 | | } |
| 225 | | |
| 226 | | |
| 227 | | //------------------------------------------------- |
| 228 | | // clock_scan_counters - clock the keyboard |
| 229 | | // scan counters |
| 230 | | //------------------------------------------------- |
| 231 | | |
| 232 | | void cdp1871_device::clock_scan_counters() |
| 233 | | { |
| 234 | | if (!m_inhibit) |
| 235 | | { |
| 236 | | m_sense++; |
| 237 | | |
| 238 | | if (m_sense == 8) |
| 239 | | { |
| 240 | | m_sense = 0; |
| 241 | | m_drive++; |
| 242 | | |
| 243 | | if (m_drive == 11) |
| 244 | | { |
| 245 | | m_drive = 0; |
| 246 | | } |
| 247 | | } |
| 248 | | } |
| 249 | | } |
| 250 | | |
| 251 | | |
| 252 | | //------------------------------------------------- |
| 253 | | // detect_keypress - detect key press |
| 254 | | //------------------------------------------------- |
| 255 | | |
| 256 | | void cdp1871_device::detect_keypress() |
| 257 | | { |
| 258 | | UINT8 data = 0; |
| 259 | | |
| 260 | | data = devcb_call_read8(&m_in_d_func[m_drive], 0); |
| 261 | | |
| 262 | | if (data == (1 << m_sense)) |
| 263 | | { |
| 264 | | if (!m_inhibit) |
| 265 | | { |
| 266 | | m_shift = devcb_call_read_line(&m_in_shift_func); |
| 267 | | m_control = devcb_call_read_line(&m_in_control_func); |
| 268 | | m_inhibit = true; |
| 269 | | m_next_da = ASSERT_LINE; |
| 270 | | } |
| 271 | | else |
| 272 | | { |
| 273 | | m_next_rpt = ASSERT_LINE; |
| 274 | | } |
| 275 | | } |
| 276 | | else |
| 277 | | { |
| 278 | | m_inhibit = false; |
| 279 | | m_next_rpt = CLEAR_LINE; |
| 280 | | } |
| 281 | | } |
| 282 | | |
| 283 | | |
| 284 | | //------------------------------------------------- |
| 285 | | // data_r - keyboard data read |
| 286 | | //------------------------------------------------- |
| 287 | | |
| 288 | | READ8_MEMBER( cdp1871_device::data_r ) |
| 289 | | { |
| 290 | | int table = 0; |
| 291 | | int alpha = devcb_call_read_line(&m_in_alpha_func); |
| 292 | | |
| 293 | | if (m_control) table = 3; else if (m_shift) table = 2; else if (alpha) table = 1; |
| 294 | | |
| 295 | | // reset DA on next TPB |
| 296 | | m_next_da = CLEAR_LINE; |
| 297 | | |
| 298 | | return CDP1871_KEY_CODES[table][m_drive][m_sense]; |
| 299 | | } |
| 300 | | |
| 301 | | |
| 302 | | //------------------------------------------------- |
| 303 | | // da_r - data available |
| 304 | | //------------------------------------------------- |
| 305 | | |
| 306 | | READ_LINE_MEMBER( cdp1871_device::da_r ) |
| 307 | | { |
| 308 | | return m_da; |
| 309 | | } |
| 310 | | |
| 311 | | |
| 312 | | //------------------------------------------------- |
| 313 | | // rpt_r - keyboard repeat |
| 314 | | //------------------------------------------------- |
| 315 | | |
| 316 | | READ_LINE_MEMBER( cdp1871_device::rpt_r ) |
| 317 | | { |
| 318 | | return m_rpt; |
| 319 | | } |
src/mess/machine/nmc9306.c
| r10968 | r10969 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | National Semiconductor NMC9306 256-Bit Serial EEPROM emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | **********************************************************************/ |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "nmc9306.h" |
| 12 | | #include "machine/devhelpr.h" |
| 13 | | |
| 14 | | |
| 15 | | |
| 16 | | //************************************************************************** |
| 17 | | // MACROS / CONSTANTS |
| 18 | | //************************************************************************** |
| 19 | | |
| 20 | | #define LOG 1 |
| 21 | | |
| 22 | | #define RAM_SIZE 32 |
| 23 | | |
| 24 | | |
| 25 | | // instructions |
| 26 | | enum |
| 27 | | { |
| 28 | | OTHER = 0, |
| 29 | | WRITE, // write register A3A2A1A0 |
| 30 | | READ, // read register A3A2A1A0 |
| 31 | | ERASE // erase register A3A2A1A0 |
| 32 | | }; |
| 33 | | |
| 34 | | // other instructions |
| 35 | | enum |
| 36 | | { |
| 37 | | EWDS = 0, // erase/write disable |
| 38 | | WRAL, // write all registers |
| 39 | | ERAL, // erase all registers |
| 40 | | EWEN, // erase/write enable |
| 41 | | }; |
| 42 | | |
| 43 | | // states |
| 44 | | enum |
| 45 | | { |
| 46 | | STATE_IDLE = 0, |
| 47 | | STATE_COMMAND, |
| 48 | | STATE_ADDRESS, |
| 49 | | STATE_DATA_IN, |
| 50 | | STATE_DATA_OUT, |
| 51 | | STATE_ERASE |
| 52 | | }; |
| 53 | | |
| 54 | | |
| 55 | | |
| 56 | | //************************************************************************** |
| 57 | | // DEVICE DEFINITIONS |
| 58 | | //************************************************************************** |
| 59 | | |
| 60 | | const device_type NMC9306 = nmc9306_device_config::static_alloc_device_config; |
| 61 | | |
| 62 | | |
| 63 | | |
| 64 | | //************************************************************************** |
| 65 | | // DEVICE CONFIGURATION |
| 66 | | //************************************************************************** |
| 67 | | |
| 68 | | //------------------------------------------------- |
| 69 | | // nmc9306_device_config - constructor |
| 70 | | //------------------------------------------------- |
| 71 | | |
| 72 | | nmc9306_device_config::nmc9306_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 73 | | : device_config(mconfig, static_alloc_device_config, "NMC9306", tag, owner, clock), |
| 74 | | device_config_nvram_interface(mconfig, *this) |
| 75 | | { |
| 76 | | } |
| 77 | | |
| 78 | | |
| 79 | | //------------------------------------------------- |
| 80 | | // static_alloc_device_config - allocate a new |
| 81 | | // configuration object |
| 82 | | //------------------------------------------------- |
| 83 | | |
| 84 | | device_config *nmc9306_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 85 | | { |
| 86 | | return global_alloc(nmc9306_device_config(mconfig, tag, owner, clock)); |
| 87 | | } |
| 88 | | |
| 89 | | |
| 90 | | //------------------------------------------------- |
| 91 | | // alloc_device - allocate a new device object |
| 92 | | //------------------------------------------------- |
| 93 | | |
| 94 | | device_t *nmc9306_device_config::alloc_device(running_machine &machine) const |
| 95 | | { |
| 96 | | return auto_alloc(&machine, nmc9306_device(machine, *this)); |
| 97 | | } |
| 98 | | |
| 99 | | |
| 100 | | |
| 101 | | //************************************************************************** |
| 102 | | // INLINE HELPERS |
| 103 | | //************************************************************************** |
| 104 | | |
| 105 | | //------------------------------------------------- |
| 106 | | // nmc9306_device - constructor |
| 107 | | //------------------------------------------------- |
| 108 | | |
| 109 | | inline UINT16 nmc9306_device::read(offs_t offset) |
| 110 | | { |
| 111 | | return m_register[offset]; |
| 112 | | } |
| 113 | | |
| 114 | | |
| 115 | | //------------------------------------------------- |
| 116 | | // nmc9306_device - constructor |
| 117 | | //------------------------------------------------- |
| 118 | | |
| 119 | | inline void nmc9306_device::write(offs_t offset, UINT16 data) |
| 120 | | { |
| 121 | | if (m_ewen) |
| 122 | | { |
| 123 | | m_register[offset] &= data; |
| 124 | | } |
| 125 | | } |
| 126 | | |
| 127 | | |
| 128 | | //------------------------------------------------- |
| 129 | | // nmc9306_device - constructor |
| 130 | | //------------------------------------------------- |
| 131 | | |
| 132 | | inline void nmc9306_device::erase(offs_t offset) |
| 133 | | { |
| 134 | | if (m_ewen) |
| 135 | | { |
| 136 | | m_register[offset] = 0xffff; |
| 137 | | } |
| 138 | | } |
| 139 | | |
| 140 | | |
| 141 | | |
| 142 | | //************************************************************************** |
| 143 | | // LIVE DEVICE |
| 144 | | //************************************************************************** |
| 145 | | |
| 146 | | //------------------------------------------------- |
| 147 | | // nmc9306_device - constructor |
| 148 | | //------------------------------------------------- |
| 149 | | |
| 150 | | nmc9306_device::nmc9306_device(running_machine &_machine, const nmc9306_device_config &config) |
| 151 | | : device_t(_machine, config), |
| 152 | | device_nvram_interface(_machine, config, *this), |
| 153 | | m_state(STATE_IDLE), |
| 154 | | m_ewen(false), |
| 155 | | m_config(config) |
| 156 | | { |
| 157 | | } |
| 158 | | |
| 159 | | |
| 160 | | //------------------------------------------------- |
| 161 | | // device_start - device-specific startup |
| 162 | | //------------------------------------------------- |
| 163 | | |
| 164 | | void nmc9306_device::device_start() |
| 165 | | { |
| 166 | | // state saving |
| 167 | | save_item(NAME(m_bits)); |
| 168 | | save_item(NAME(m_state)); |
| 169 | | save_item(NAME(m_command)); |
| 170 | | save_item(NAME(m_address)); |
| 171 | | save_item(NAME(m_data)); |
| 172 | | save_item(NAME(m_ewen)); |
| 173 | | save_item(NAME(m_cs)); |
| 174 | | save_item(NAME(m_sk)); |
| 175 | | save_item(NAME(m_do)); |
| 176 | | save_item(NAME(m_di)); |
| 177 | | } |
| 178 | | |
| 179 | | |
| 180 | | //------------------------------------------------- |
| 181 | | // nvram_default - called to initialize NVRAM to |
| 182 | | // its default state |
| 183 | | //------------------------------------------------- |
| 184 | | |
| 185 | | void nmc9306_device::nvram_default() |
| 186 | | { |
| 187 | | } |
| 188 | | |
| 189 | | |
| 190 | | //------------------------------------------------- |
| 191 | | // nvram_read - called to read NVRAM from the |
| 192 | | // .nv file |
| 193 | | //------------------------------------------------- |
| 194 | | |
| 195 | | void nmc9306_device::nvram_read(emu_file &file) |
| 196 | | { |
| 197 | | file.read(m_register, RAM_SIZE); |
| 198 | | } |
| 199 | | |
| 200 | | |
| 201 | | //------------------------------------------------- |
| 202 | | // nvram_write - called to write NVRAM to the |
| 203 | | // .nv file |
| 204 | | //------------------------------------------------- |
| 205 | | |
| 206 | | void nmc9306_device::nvram_write(emu_file &file) |
| 207 | | { |
| 208 | | file.write(m_register, RAM_SIZE); |
| 209 | | } |
| 210 | | |
| 211 | | |
| 212 | | //------------------------------------------------- |
| 213 | | // cs_w - chip select input |
| 214 | | //------------------------------------------------- |
| 215 | | |
| 216 | | WRITE_LINE_MEMBER( nmc9306_device::cs_w ) |
| 217 | | { |
| 218 | | m_cs = state; |
| 219 | | } |
| 220 | | |
| 221 | | |
| 222 | | //------------------------------------------------- |
| 223 | | // ck_w - serial clock input |
| 224 | | //------------------------------------------------- |
| 225 | | |
| 226 | | WRITE_LINE_MEMBER( nmc9306_device::sk_w ) |
| 227 | | { |
| 228 | | m_sk = state; |
| 229 | | |
| 230 | | if (!m_cs || !m_sk) return; |
| 231 | | |
| 232 | | switch (m_state) |
| 233 | | { |
| 234 | | case STATE_IDLE: |
| 235 | | if (LOG) logerror("NMC9306 '%s' Idle %u\n", tag(), m_di); |
| 236 | | |
| 237 | | if (m_di) |
| 238 | | { |
| 239 | | // start bit received |
| 240 | | m_state = STATE_COMMAND; |
| 241 | | m_bits = 0; |
| 242 | | } |
| 243 | | break; |
| 244 | | |
| 245 | | case STATE_COMMAND: |
| 246 | | if (LOG) logerror("NMC9306 '%s' Command Bit %u\n", tag(), m_di); |
| 247 | | |
| 248 | | m_command <<= 1; |
| 249 | | m_command |= m_di; |
| 250 | | m_bits++; |
| 251 | | |
| 252 | | if (m_bits == 4) |
| 253 | | { |
| 254 | | m_state = STATE_ADDRESS; |
| 255 | | m_bits = 0; |
| 256 | | } |
| 257 | | break; |
| 258 | | |
| 259 | | case STATE_ADDRESS: |
| 260 | | if (LOG) logerror("NMC9306 '%s' Address Bit %u\n", tag(), m_di); |
| 261 | | |
| 262 | | m_address <<= 1; |
| 263 | | m_address |= m_di; |
| 264 | | m_bits++; |
| 265 | | |
| 266 | | if (m_bits == 4) |
| 267 | | { |
| 268 | | switch ((m_command >> 2) & 0x03) |
| 269 | | { |
| 270 | | case OTHER: |
| 271 | | switch (m_command & 0x03) |
| 272 | | { |
| 273 | | case EWDS: |
| 274 | | if (LOG) logerror("NMC9306 '%s' EWDS\n", tag()); |
| 275 | | m_ewen = false; |
| 276 | | m_state = STATE_IDLE; |
| 277 | | break; |
| 278 | | |
| 279 | | case WRAL: |
| 280 | | if (LOG) logerror("NMC9306 '%s' WRAL\n", tag()); |
| 281 | | break; |
| 282 | | |
| 283 | | case ERAL: |
| 284 | | if (LOG) logerror("NMC9306 '%s' ERAL\n", tag()); |
| 285 | | break; |
| 286 | | |
| 287 | | case EWEN: |
| 288 | | if (LOG) logerror("NMC9306 '%s' EWEN\n", tag()); |
| 289 | | m_ewen = true; |
| 290 | | m_state = STATE_IDLE; |
| 291 | | break; |
| 292 | | } |
| 293 | | break; |
| 294 | | |
| 295 | | case WRITE: |
| 296 | | if (LOG) logerror("NMC9306 '%s' WRITE %u\n", tag(), m_address & 0x0f); |
| 297 | | m_state = STATE_DATA_IN; |
| 298 | | break; |
| 299 | | |
| 300 | | case READ: |
| 301 | | if (LOG) logerror("NMC9306 '%s' READ %u\n", tag(), m_address & 0x0f); |
| 302 | | m_data = read(m_address & 0x0f); |
| 303 | | m_state = STATE_DATA_OUT; |
| 304 | | break; |
| 305 | | |
| 306 | | case ERASE: |
| 307 | | if (LOG) logerror("NMC9306 '%s' ERASE %u\n", tag(), m_address & 0x0f); |
| 308 | | erase(m_address & 0x0f); |
| 309 | | m_state = STATE_ERASE; |
| 310 | | break; |
| 311 | | } |
| 312 | | |
| 313 | | m_bits = 0; |
| 314 | | } |
| 315 | | break; |
| 316 | | |
| 317 | | case STATE_DATA_IN: |
| 318 | | if (LOG) logerror("NMC9306 '%s' Data Bit IN %u\n", tag(), m_di); |
| 319 | | |
| 320 | | m_data <<= 1; |
| 321 | | m_data |= m_di; |
| 322 | | m_bits++; |
| 323 | | |
| 324 | | if (m_bits == 16) |
| 325 | | { |
| 326 | | write(m_address & 0x0f, m_data); |
| 327 | | |
| 328 | | m_state = STATE_IDLE; |
| 329 | | } |
| 330 | | break; |
| 331 | | |
| 332 | | case STATE_DATA_OUT: |
| 333 | | if (LOG) logerror("NMC9306 '%s' Data Bit OUT %u\n", tag(), m_di); |
| 334 | | |
| 335 | | m_do = BIT(m_data, 15); |
| 336 | | m_data <<= 1; |
| 337 | | m_bits++; |
| 338 | | |
| 339 | | if (m_bits == 16) |
| 340 | | { |
| 341 | | m_state = STATE_IDLE; |
| 342 | | } |
| 343 | | break; |
| 344 | | } |
| 345 | | } |
| 346 | | |
| 347 | | |
| 348 | | //------------------------------------------------- |
| 349 | | // di_w - serial data input |
| 350 | | //------------------------------------------------- |
| 351 | | |
| 352 | | WRITE_LINE_MEMBER( nmc9306_device::di_w ) |
| 353 | | { |
| 354 | | m_di = state; |
| 355 | | } |
| 356 | | |
| 357 | | |
| 358 | | //------------------------------------------------- |
| 359 | | // do_r - serial data output |
| 360 | | //------------------------------------------------- |
| 361 | | |
| 362 | | READ_LINE_MEMBER( nmc9306_device::do_r ) |
| 363 | | { |
| 364 | | return m_do; |
| 365 | | } |
src/mess/machine/i8155.c
| r10968 | r10969 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | Intel 8155 - 2048-Bit Static MOS RAM with I/O Ports and Timer emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | **********************************************************************/ |
| 9 | | |
| 10 | | /* |
| 11 | | |
| 12 | | TODO: |
| 13 | | |
| 14 | | - strobed mode |
| 15 | | |
| 16 | | */ |
| 17 | | |
| 18 | | #include "emu.h" |
| 19 | | #include "i8155.h" |
| 20 | | |
| 21 | | |
| 22 | | |
| 23 | | //************************************************************************** |
| 24 | | // MACROS / CONSTANTS |
| 25 | | //************************************************************************** |
| 26 | | |
| 27 | | #define LOG 1 |
| 28 | | |
| 29 | | enum |
| 30 | | { |
| 31 | | REGISTER_COMMAND = 0, |
| 32 | | REGISTER_STATUS = 0, |
| 33 | | REGISTER_PORT_A, |
| 34 | | REGISTER_PORT_B, |
| 35 | | REGISTER_PORT_C, |
| 36 | | REGISTER_TIMER_LOW, |
| 37 | | REGISTER_TIMER_HIGH |
| 38 | | }; |
| 39 | | |
| 40 | | enum |
| 41 | | { |
| 42 | | PORT_A = 0, |
| 43 | | PORT_B, |
| 44 | | PORT_C, |
| 45 | | PORT_COUNT |
| 46 | | }; |
| 47 | | |
| 48 | | enum |
| 49 | | { |
| 50 | | PORT_MODE_INPUT = 0, |
| 51 | | PORT_MODE_OUTPUT, |
| 52 | | PORT_MODE_STROBED_PORT_A, // not supported |
| 53 | | PORT_MODE_STROBED // not supported |
| 54 | | }; |
| 55 | | |
| 56 | | enum |
| 57 | | { |
| 58 | | MEMORY = 0, |
| 59 | | IO |
| 60 | | }; |
| 61 | | |
| 62 | | #define COMMAND_PA 0x01 |
| 63 | | #define COMMAND_PB 0x02 |
| 64 | | #define COMMAND_PC_MASK 0x0c |
| 65 | | #define COMMAND_PC_ALT_1 0x00 |
| 66 | | #define COMMAND_PC_ALT_2 0x0c |
| 67 | | #define COMMAND_PC_ALT_3 0x04 // not supported |
| 68 | | #define COMMAND_PC_ALT_4 0x08 // not supported |
| 69 | | #define COMMAND_IEA 0x10 // not supported |
| 70 | | #define COMMAND_IEB 0x20 // not supported |
| 71 | | #define COMMAND_TM_MASK 0xc0 |
| 72 | | #define COMMAND_TM_NOP 0x00 |
| 73 | | #define COMMAND_TM_STOP 0x40 |
| 74 | | #define COMMAND_TM_STOP_AFTER_TC 0x80 |
| 75 | | #define COMMAND_TM_START 0xc0 |
| 76 | | |
| 77 | | #define STATUS_INTR_A 0x01 // not supported |
| 78 | | #define STATUS_A_BF 0x02 // not supported |
| 79 | | #define STATUS_INTE_A 0x04 // not supported |
| 80 | | #define STATUS_INTR_B 0x08 // not supported |
| 81 | | #define STATUS_B_BF 0x10 // not supported |
| 82 | | #define STATUS_INTE_B 0x20 // not supported |
| 83 | | #define STATUS_TIMER 0x40 |
| 84 | | |
| 85 | | #define TIMER_MODE_MASK 0xc0 |
| 86 | | #define TIMER_MODE_LOW 0x00 |
| 87 | | #define TIMER_MODE_SQUARE_WAVE 0x40 |
| 88 | | #define TIMER_MODE_SINGLE_PULSE 0x80 |
| 89 | | #define TIMER_MODE_AUTOMATIC_RELOAD 0xc0 |
| 90 | | |
| 91 | | |
| 92 | | |
| 93 | | //************************************************************************** |
| 94 | | // GLOBAL VARIABLES |
| 95 | | //************************************************************************** |
| 96 | | |
| 97 | | // devices |
| 98 | | const device_type I8155 = i8155_device_config::static_alloc_device_config; |
| 99 | | |
| 100 | | |
| 101 | | // default address map |
| 102 | | static ADDRESS_MAP_START( i8155, AS_0, 8 ) |
| 103 | | AM_RANGE(0x00, 0xff) AM_RAM |
| 104 | | ADDRESS_MAP_END |
| 105 | | |
| 106 | | |
| 107 | | |
| 108 | | //************************************************************************** |
| 109 | | // DEVICE CONFIGURATION |
| 110 | | //************************************************************************** |
| 111 | | |
| 112 | | //------------------------------------------------- |
| 113 | | // i8155_device_config - constructor |
| 114 | | //------------------------------------------------- |
| 115 | | |
| 116 | | i8155_device_config::i8155_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 117 | | : device_config(mconfig, static_alloc_device_config, "Intel 8155", tag, owner, clock), |
| 118 | | device_config_memory_interface(mconfig, *this), |
| 119 | | m_space_config("ram", ENDIANNESS_LITTLE, 8, 8, 0, NULL, *ADDRESS_MAP_NAME(i8155)) |
| 120 | | { |
| 121 | | } |
| 122 | | |
| 123 | | |
| 124 | | //------------------------------------------------- |
| 125 | | // static_alloc_device_config - allocate a new |
| 126 | | // configuration object |
| 127 | | //------------------------------------------------- |
| 128 | | |
| 129 | | device_config *i8155_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 130 | | { |
| 131 | | return global_alloc(i8155_device_config(mconfig, tag, owner, clock)); |
| 132 | | } |
| 133 | | |
| 134 | | |
| 135 | | //------------------------------------------------- |
| 136 | | // alloc_device - allocate a new device object |
| 137 | | //------------------------------------------------- |
| 138 | | |
| 139 | | device_t *i8155_device_config::alloc_device(running_machine &machine) const |
| 140 | | { |
| 141 | | return auto_alloc(&machine, i8155_device(machine, *this)); |
| 142 | | } |
| 143 | | |
| 144 | | |
| 145 | | //------------------------------------------------- |
| 146 | | // memory_space_config - return a description of |
| 147 | | // any address spaces owned by this device |
| 148 | | //------------------------------------------------- |
| 149 | | |
| 150 | | const address_space_config *i8155_device_config::memory_space_config(address_spacenum spacenum) const |
| 151 | | { |
| 152 | | return (spacenum == AS_0) ? &m_space_config : NULL; |
| 153 | | } |
| 154 | | |
| 155 | | |
| 156 | | //------------------------------------------------- |
| 157 | | // device_config_complete - perform any |
| 158 | | // operations now that the configuration is |
| 159 | | // complete |
| 160 | | //------------------------------------------------- |
| 161 | | |
| 162 | | void i8155_device_config::device_config_complete() |
| 163 | | { |
| 164 | | // inherit a copy of the static data |
| 165 | | const i8155_interface *intf = reinterpret_cast<const i8155_interface *>(static_config()); |
| 166 | | if (intf != NULL) |
| 167 | | *static_cast<i8155_interface *>(this) = *intf; |
| 168 | | |
| 169 | | // or initialize to defaults if none provided |
| 170 | | else |
| 171 | | { |
| 172 | | memset(&in_pa_func, 0, sizeof(in_pa_func)); |
| 173 | | memset(&out_pa_func, 0, sizeof(out_pa_func)); |
| 174 | | memset(&in_pb_func, 0, sizeof(in_pb_func)); |
| 175 | | memset(&out_pb_func, 0, sizeof(out_pb_func)); |
| 176 | | memset(&in_pc_func, 0, sizeof(in_pc_func)); |
| 177 | | memset(&out_pc_func, 0, sizeof(out_pc_func)); |
| 178 | | memset(&out_to_func, 0, sizeof(out_to_func)); |
| 179 | | } |
| 180 | | } |
| 181 | | |
| 182 | | |
| 183 | | |
| 184 | | //************************************************************************** |
| 185 | | // INLINE HELPERS |
| 186 | | //************************************************************************** |
| 187 | | |
| 188 | | inline UINT8 i8155_device::get_timer_mode() |
| 189 | | { |
| 190 | | return (m_count_length >> 8) & TIMER_MODE_MASK; |
| 191 | | } |
| 192 | | |
| 193 | | inline void i8155_device::timer_output() |
| 194 | | { |
| 195 | | devcb_call_write_line(&m_out_to_func, m_to); |
| 196 | | |
| 197 | | if (LOG) logerror("8155 '%s' Timer Output: %u\n", tag(), m_to); |
| 198 | | } |
| 199 | | |
| 200 | | inline void i8155_device::pulse_timer_output() |
| 201 | | { |
| 202 | | m_to = 0; timer_output(); |
| 203 | | m_to = 1; timer_output(); |
| 204 | | } |
| 205 | | |
| 206 | | inline int i8155_device::get_port_mode(int port) |
| 207 | | { |
| 208 | | int mode = -1; |
| 209 | | |
| 210 | | switch (port) |
| 211 | | { |
| 212 | | case PORT_A: |
| 213 | | mode = (m_command & COMMAND_PA) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT; |
| 214 | | break; |
| 215 | | |
| 216 | | case PORT_B: |
| 217 | | mode = (m_command & COMMAND_PB) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT; |
| 218 | | break; |
| 219 | | |
| 220 | | case PORT_C: |
| 221 | | switch (m_command & COMMAND_PC_MASK) |
| 222 | | { |
| 223 | | case COMMAND_PC_ALT_1: mode = PORT_MODE_INPUT; break; |
| 224 | | case COMMAND_PC_ALT_2: mode = PORT_MODE_OUTPUT; break; |
| 225 | | case COMMAND_PC_ALT_3: mode = PORT_MODE_STROBED_PORT_A; break; |
| 226 | | case COMMAND_PC_ALT_4: mode = PORT_MODE_STROBED; break; |
| 227 | | } |
| 228 | | break; |
| 229 | | } |
| 230 | | |
| 231 | | return mode; |
| 232 | | } |
| 233 | | |
| 234 | | inline UINT8 i8155_device::read_port(int port) |
| 235 | | { |
| 236 | | UINT8 data = 0; |
| 237 | | |
| 238 | | switch (port) |
| 239 | | { |
| 240 | | case PORT_A: |
| 241 | | case PORT_B: |
| 242 | | switch (get_port_mode(port)) |
| 243 | | { |
| 244 | | case PORT_MODE_INPUT: |
| 245 | | data = devcb_call_read8(&m_in_port_func[port], 0); |
| 246 | | break; |
| 247 | | |
| 248 | | case PORT_MODE_OUTPUT: |
| 249 | | data = m_output[port]; |
| 250 | | break; |
| 251 | | } |
| 252 | | break; |
| 253 | | |
| 254 | | case PORT_C: |
| 255 | | switch (get_port_mode(PORT_C)) |
| 256 | | { |
| 257 | | case PORT_MODE_INPUT: |
| 258 | | data = devcb_call_read8(&m_in_port_func[port], 0) & 0x3f; |
| 259 | | break; |
| 260 | | |
| 261 | | case PORT_MODE_OUTPUT: |
| 262 | | data = m_output[port] & 0x3f; |
| 263 | | break; |
| 264 | | |
| 265 | | default: |
| 266 | | logerror("8155 '%s' Unsupported Port C mode!\n", tag()); |
| 267 | | } |
| 268 | | break; |
| 269 | | } |
| 270 | | |
| 271 | | return data; |
| 272 | | } |
| 273 | | |
| 274 | | inline void i8155_device::write_port(int port, UINT8 data) |
| 275 | | { |
| 276 | | switch (get_port_mode(port)) |
| 277 | | { |
| 278 | | case PORT_MODE_OUTPUT: |
| 279 | | m_output[port] = data; |
| 280 | | devcb_call_write8(&m_out_port_func[port], 0, m_output[port]); |
| 281 | | break; |
| 282 | | } |
| 283 | | } |
| 284 | | |
| 285 | | |
| 286 | | //************************************************************************** |
| 287 | | // LIVE DEVICE |
| 288 | | //************************************************************************** |
| 289 | | |
| 290 | | //------------------------------------------------- |
| 291 | | // i8155_device - constructor |
| 292 | | //------------------------------------------------- |
| 293 | | |
| 294 | | i8155_device::i8155_device(running_machine &_machine, const i8155_device_config &config) |
| 295 | | : device_t(_machine, config), |
| 296 | | device_memory_interface(_machine, config, *this), |
| 297 | | m_config(config) |
| 298 | | { |
| 299 | | |
| 300 | | } |
| 301 | | |
| 302 | | |
| 303 | | //------------------------------------------------- |
| 304 | | // device_start - device-specific startup |
| 305 | | //------------------------------------------------- |
| 306 | | |
| 307 | | void i8155_device::device_start() |
| 308 | | { |
| 309 | | // resolve callbacks |
| 310 | | devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this); |
| 311 | | devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this); |
| 312 | | devcb_resolve_read8(&m_in_port_func[2], &m_config.in_pc_func, this); |
| 313 | | devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this); |
| 314 | | devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this); |
| 315 | | devcb_resolve_write8(&m_out_port_func[2], &m_config.out_pc_func, this); |
| 316 | | devcb_resolve_write_line(&m_out_to_func, &m_config.out_to_func, this); |
| 317 | | |
| 318 | | // allocate timers |
| 319 | | m_timer = timer_alloc(); |
| 320 | | |
| 321 | | // register for state saving |
| 322 | | save_item(NAME(m_io_m)); |
| 323 | | save_item(NAME(m_ad)); |
| 324 | | save_item(NAME(m_command)); |
| 325 | | save_item(NAME(m_status)); |
| 326 | | save_item(NAME(m_output)); |
| 327 | | save_item(NAME(m_count_length)); |
| 328 | | save_item(NAME(m_counter)); |
| 329 | | save_item(NAME(m_to)); |
| 330 | | } |
| 331 | | |
| 332 | | |
| 333 | | //------------------------------------------------- |
| 334 | | // device_reset - device-specific reset |
| 335 | | //------------------------------------------------- |
| 336 | | |
| 337 | | void i8155_device::device_reset() |
| 338 | | { |
| 339 | | // clear output registers |
| 340 | | m_output[PORT_A] = 0; |
| 341 | | m_output[PORT_B] = 0; |
| 342 | | m_output[PORT_C] = 0; |
| 343 | | |
| 344 | | // set ports to input mode |
| 345 | | register_w(REGISTER_COMMAND, m_command & ~(COMMAND_PA | COMMAND_PB | COMMAND_PC_MASK)); |
| 346 | | |
| 347 | | // clear timer flag |
| 348 | | m_status &= ~STATUS_TIMER; |
| 349 | | |
| 350 | | // stop counting |
| 351 | | m_timer->enable(0); |
| 352 | | |
| 353 | | // clear timer output |
| 354 | | m_to = 1; |
| 355 | | timer_output(); |
| 356 | | } |
| 357 | | |
| 358 | | |
| 359 | | //------------------------------------------------- |
| 360 | | // device_timer - handler timer events |
| 361 | | //------------------------------------------------- |
| 362 | | |
| 363 | | void i8155_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 364 | | { |
| 365 | | // count down |
| 366 | | m_counter--; |
| 367 | | |
| 368 | | if (get_timer_mode() == TIMER_MODE_LOW) |
| 369 | | { |
| 370 | | // pulse on every count |
| 371 | | pulse_timer_output(); |
| 372 | | } |
| 373 | | |
| 374 | | if (m_counter == 0) |
| 375 | | { |
| 376 | | if (LOG) logerror("8155 '%s' Timer Count Reached\n", tag()); |
| 377 | | |
| 378 | | switch (m_command & COMMAND_TM_MASK) |
| 379 | | { |
| 380 | | case COMMAND_TM_STOP_AFTER_TC: |
| 381 | | // stop timer |
| 382 | | m_timer->enable(0); |
| 383 | | |
| 384 | | if (LOG) logerror("8155 '%s' Timer Stopped\n", tag()); |
| 385 | | break; |
| 386 | | } |
| 387 | | |
| 388 | | switch (get_timer_mode()) |
| 389 | | { |
| 390 | | case TIMER_MODE_SQUARE_WAVE: |
| 391 | | // toggle timer output |
| 392 | | m_to = !m_to; |
| 393 | | timer_output(); |
| 394 | | break; |
| 395 | | |
| 396 | | case TIMER_MODE_SINGLE_PULSE: |
| 397 | | // single pulse upon TC being reached |
| 398 | | pulse_timer_output(); |
| 399 | | |
| 400 | | // clear timer mode setting |
| 401 | | m_command &= ~COMMAND_TM_MASK; |
| 402 | | break; |
| 403 | | |
| 404 | | case TIMER_MODE_AUTOMATIC_RELOAD: |
| 405 | | // automatic reload, i.e. single pulse every time TC is reached |
| 406 | | pulse_timer_output(); |
| 407 | | break; |
| 408 | | } |
| 409 | | |
| 410 | | // set timer flag |
| 411 | | m_status |= STATUS_TIMER; |
| 412 | | |
| 413 | | // reload timer counter |
| 414 | | m_counter = m_count_length & 0x3fff; |
| 415 | | } |
| 416 | | } |
| 417 | | |
| 418 | | |
| 419 | | //------------------------------------------------- |
| 420 | | // io_r - register read |
| 421 | | //------------------------------------------------- |
| 422 | | |
| 423 | | READ8_MEMBER( i8155_device::io_r ) |
| 424 | | { |
| 425 | | UINT8 data = 0; |
| 426 | | |
| 427 | | switch (offset & 0x03) |
| 428 | | { |
| 429 | | case REGISTER_STATUS: |
| 430 | | data = m_status; |
| 431 | | |
| 432 | | // clear timer flag |
| 433 | | m_status &= ~STATUS_TIMER; |
| 434 | | break; |
| 435 | | |
| 436 | | case REGISTER_PORT_A: |
| 437 | | data = read_port(PORT_A); |
| 438 | | break; |
| 439 | | |
| 440 | | case REGISTER_PORT_B: |
| 441 | | data = read_port(PORT_B); |
| 442 | | break; |
| 443 | | |
| 444 | | case REGISTER_PORT_C: |
| 445 | | data = read_port(PORT_C); |
| 446 | | break; |
| 447 | | } |
| 448 | | |
| 449 | | return data; |
| 450 | | } |
| 451 | | |
| 452 | | |
| 453 | | //------------------------------------------------- |
| 454 | | // register_w - register write |
| 455 | | //------------------------------------------------- |
| 456 | | |
| 457 | | void i8155_device::register_w(int offset, UINT8 data) |
| 458 | | { |
| 459 | | switch (offset & 0x07) |
| 460 | | { |
| 461 | | case REGISTER_COMMAND: |
| 462 | | m_command = data; |
| 463 | | |
| 464 | | if (LOG) logerror("8155 '%s' Port A Mode: %s\n", tag(), (data & COMMAND_PA) ? "output" : "input"); |
| 465 | | if (LOG) logerror("8155 '%s' Port B Mode: %s\n", tag(), (data & COMMAND_PB) ? "output" : "input"); |
| 466 | | |
| 467 | | if (LOG) logerror("8155 '%s' Port A Interrupt: %s\n", tag(), (data & COMMAND_IEA) ? "enabled" : "disabled"); |
| 468 | | if (LOG) logerror("8155 '%s' Port B Interrupt: %s\n", tag(), (data & COMMAND_IEB) ? "enabled" : "disabled"); |
| 469 | | |
| 470 | | switch (data & COMMAND_PC_MASK) |
| 471 | | { |
| 472 | | case COMMAND_PC_ALT_1: |
| 473 | | if (LOG) logerror("8155 '%s' Port C Mode: Alt 1\n", tag()); |
| 474 | | break; |
| 475 | | |
| 476 | | case COMMAND_PC_ALT_2: |
| 477 | | if (LOG) logerror("8155 '%s' Port C Mode: Alt 2\n", tag()); |
| 478 | | break; |
| 479 | | |
| 480 | | case COMMAND_PC_ALT_3: |
| 481 | | if (LOG) logerror("8155 '%s' Port C Mode: Alt 3\n", tag()); |
| 482 | | break; |
| 483 | | |
| 484 | | case COMMAND_PC_ALT_4: |
| 485 | | if (LOG) logerror("8155 '%s' Port C Mode: Alt 4\n", tag()); |
| 486 | | break; |
| 487 | | } |
| 488 | | |
| 489 | | switch (data & COMMAND_TM_MASK) |
| 490 | | { |
| 491 | | case COMMAND_TM_NOP: |
| 492 | | // do not affect counter operation |
| 493 | | break; |
| 494 | | |
| 495 | | case COMMAND_TM_STOP: |
| 496 | | // NOP if timer has not started, stop counting if the timer is running |
| 497 | | if (LOG) logerror("8155 '%s' Timer Command: Stop\n", tag()); |
| 498 | | m_timer->enable(0); |
| 499 | | break; |
| 500 | | |
| 501 | | case COMMAND_TM_STOP_AFTER_TC: |
| 502 | | // stop immediately after present TC is reached (NOP if timer has not started) |
| 503 | | if (LOG) logerror("8155 '%s' Timer Command: Stop after TC\n", tag()); |
| 504 | | break; |
| 505 | | |
| 506 | | case COMMAND_TM_START: |
| 507 | | if (LOG) logerror("8155 '%s' Timer Command: Start\n", tag()); |
| 508 | | |
| 509 | | if (m_timer->enabled()) |
| 510 | | { |
| 511 | | // if timer is running, start the new mode and CNT length immediately after present TC is reached |
| 512 | | } |
| 513 | | else |
| 514 | | { |
| 515 | | // load mode and CNT length and start immediately after loading (if timer is not running) |
| 516 | | m_counter = m_count_length; |
| 517 | | m_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); |
| 518 | | } |
| 519 | | break; |
| 520 | | } |
| 521 | | break; |
| 522 | | |
| 523 | | case REGISTER_PORT_A: |
| 524 | | write_port(PORT_A, data); |
| 525 | | break; |
| 526 | | |
| 527 | | case REGISTER_PORT_B: |
| 528 | | write_port(PORT_B, data); |
| 529 | | break; |
| 530 | | |
| 531 | | case REGISTER_PORT_C: |
| 532 | | write_port(PORT_C, data); |
| 533 | | break; |
| 534 | | |
| 535 | | case REGISTER_TIMER_LOW: |
| 536 | | m_count_length = (m_count_length & 0xff00) | data; |
| 537 | | if (LOG) logerror("8155 '%s' Count Length Low: %04x\n", tag(), m_count_length); |
| 538 | | break; |
| 539 | | |
| 540 | | case REGISTER_TIMER_HIGH: |
| 541 | | m_count_length = (data << 8) | (m_count_length & 0xff); |
| 542 | | if (LOG) logerror("8155 '%s' Count Length High: %04x\n", tag(), m_count_length); |
| 543 | | |
| 544 | | switch (data & TIMER_MODE_MASK) |
| 545 | | { |
| 546 | | case TIMER_MODE_LOW: |
| 547 | | // puts out LOW during second half of count |
| 548 | | if (LOG) logerror("8155 '%s' Timer Mode: LOW\n", tag()); |
| 549 | | break; |
| 550 | | |
| 551 | | case TIMER_MODE_SQUARE_WAVE: |
| 552 | | // square wave, i.e. the period of the square wave equals the count length programmed with automatic reload at terminal count |
| 553 | | if (LOG) logerror("8155 '%s' Timer Mode: Square wave\n", tag()); |
| 554 | | break; |
| 555 | | |
| 556 | | case TIMER_MODE_SINGLE_PULSE: |
| 557 | | // single pulse upon TC being reached |
| 558 | | if (LOG) logerror("8155 '%s' Timer Mode: Single pulse\n", tag()); |
| 559 | | break; |
| 560 | | |
| 561 | | case TIMER_MODE_AUTOMATIC_RELOAD: |
| 562 | | // automatic reload, i.e. single pulse every time TC is reached |
| 563 | | if (LOG) logerror("8155 '%s' Timer Mode: Automatic reload\n", tag()); |
| 564 | | break; |
| 565 | | } |
| 566 | | break; |
| 567 | | } |
| 568 | | } |
| 569 | | |
| 570 | | //------------------------------------------------- |
| 571 | | // io_w - register write |
| 572 | | //------------------------------------------------- |
| 573 | | |
| 574 | | WRITE8_MEMBER( i8155_device::io_w ) |
| 575 | | { |
| 576 | | register_w(offset, data); |
| 577 | | } |
| 578 | | |
| 579 | | |
| 580 | | //------------------------------------------------- |
| 581 | | // memory_r - internal RAM read |
| 582 | | //------------------------------------------------- |
| 583 | | |
| 584 | | READ8_MEMBER( i8155_device::memory_r ) |
| 585 | | { |
| 586 | | return this->space()->read_byte(offset); |
| 587 | | } |
| 588 | | |
| 589 | | |
| 590 | | //------------------------------------------------- |
| 591 | | // memory_w - internal RAM write |
| 592 | | //------------------------------------------------- |
| 593 | | |
| 594 | | WRITE8_MEMBER( i8155_device::memory_w ) |
| 595 | | { |
| 596 | | this->space()->write_byte(offset, data); |
| 597 | | } |
| 598 | | |
| 599 | | |
| 600 | | //------------------------------------------------- |
| 601 | | // ale_w - address latch write |
| 602 | | //------------------------------------------------- |
| 603 | | |
| 604 | | WRITE8_MEMBER( i8155_device::ale_w ) |
| 605 | | { |
| 606 | | // I/O / memory select |
| 607 | | m_io_m = BIT(offset, 0); |
| 608 | | |
| 609 | | // address |
| 610 | | m_ad = data; |
| 611 | | } |
| 612 | | |
| 613 | | |
| 614 | | //------------------------------------------------- |
| 615 | | // read - memory or I/O read |
| 616 | | //------------------------------------------------- |
| 617 | | |
| 618 | | READ8_MEMBER( i8155_device::read ) |
| 619 | | { |
| 620 | | UINT8 data = 0; |
| 621 | | |
| 622 | | switch (m_io_m) |
| 623 | | { |
| 624 | | case MEMORY: |
| 625 | | data = memory_r(space, m_ad); |
| 626 | | break; |
| 627 | | |
| 628 | | case IO: |
| 629 | | data = io_r(space, m_ad); |
| 630 | | break; |
| 631 | | } |
| 632 | | |
| 633 | | return data; |
| 634 | | } |
| 635 | | |
| 636 | | |
| 637 | | //------------------------------------------------- |
| 638 | | // write - memory or I/O write |
| 639 | | //------------------------------------------------- |
| 640 | | |
| 641 | | WRITE8_MEMBER( i8155_device::write ) |
| 642 | | { |
| 643 | | switch (m_io_m) |
| 644 | | { |
| 645 | | case MEMORY: |
| 646 | | memory_w(space, m_ad, data); |
| 647 | | break; |
| 648 | | |
| 649 | | case IO: |
| 650 | | io_w(space, m_ad, data); |
| 651 | | break; |
| 652 | | } |
| 653 | | } |
src/mess/machine/z8536.c
| r10968 | r10969 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | Zilog Z8536 Counter/Timer and Parallel I/O emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | **********************************************************************/ |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "z8536.h" |
| 12 | | #include "machine/devhelpr.h" |
| 13 | | |
| 14 | | |
| 15 | | |
| 16 | | //************************************************************************** |
| 17 | | // MACROS / CONSTANTS |
| 18 | | //************************************************************************** |
| 19 | | |
| 20 | | // states |
| 21 | | enum |
| 22 | | { |
| 23 | | STATE_RESET = -1, |
| 24 | | STATE_0, |
| 25 | | STATE_1 |
| 26 | | }; |
| 27 | | |
| 28 | | |
| 29 | | // ports |
| 30 | | enum |
| 31 | | { |
| 32 | | PORT_C = 0, |
| 33 | | PORT_B, |
| 34 | | PORT_A, |
| 35 | | CONTROL |
| 36 | | }; |
| 37 | | |
| 38 | | |
| 39 | | // registers |
| 40 | | enum |
| 41 | | { |
| 42 | | MASTER_INTERRUPT_CONTROL = 0, |
| 43 | | MASTER_CONFIGURATION_CONTROL, |
| 44 | | PORT_A_INTERRUPT_VECTOR, |
| 45 | | PORT_B_INTERRUPT_VECTOR, |
| 46 | | COUNTER_TIMER_INTERRUPT_VECTOR, |
| 47 | | PORT_C_DATA_PATH_POLARITY, |
| 48 | | PORT_C_DATA_DIRECTION, |
| 49 | | PORT_C_SPECIAL_IO_CONTROL, |
| 50 | | PORT_A_COMMAND_AND_STATUS, |
| 51 | | PORT_B_COMMAND_AND_STATUS, |
| 52 | | COUNTER_TIMER_1_COMMAND_AND_STATUS, |
| 53 | | COUNTER_TIMER_2_COMMAND_AND_STATUS, |
| 54 | | COUNTER_TIMER_3_COMMAND_AND_STATUS, |
| 55 | | PORT_A_DATA, |
| 56 | | PORT_B_DATA, |
| 57 | | PORT_C_DATA, |
| 58 | | COUNTER_TIMER_1_CURRENT_COUNT_MS_BYTE, |
| 59 | | COUNTER_TIMER_1_CURRENT_COUNT_LS_BYTE, |
| 60 | | COUNTER_TIMER_2_CURRENT_COUNT_MS_BYTE, |
| 61 | | COUNTER_TIMER_2_CURRENT_COUNT_LS_BYTE, |
| 62 | | COUNTER_TIMER_3_CURRENT_COUNT_MS_BYTE, |
| 63 | | COUNTER_TIMER_3_CURRENT_COUNT_LS_BYTE, |
| 64 | | COUNTER_TIMER_1_TIME_CONSTANT_MS_BYTE, |
| 65 | | COUNTER_TIMER_1_TIME_CONSTANT_LS_BYTE, |
| 66 | | COUNTER_TIMER_2_TIME_CONSTANT_MS_BYTE, |
| 67 | | COUNTER_TIMER_2_TIME_CONSTANT_LS_BYTE, |
| 68 | | COUNTER_TIMER_3_TIME_CONSTANT_MS_BYTE, |
| 69 | | COUNTER_TIMER_3_TIME_CONSTANT_LS_BYTE, |
| 70 | | COUNTER_TIMER_1_MODE_SPECIFICATION, |
| 71 | | COUNTER_TIMER_2_MODE_SPECIFICATION, |
| 72 | | COUNTER_TIMER_3_MODE_SPECIFICATION, |
| 73 | | CURRENT_VECTOR, |
| 74 | | PORT_A_MODE_SPECIFICATION, |
| 75 | | PORT_A_HANDSHAKE_SPECIFICATION, |
| 76 | | PORT_A_DATA_PATH_POLARITY, |
| 77 | | PORT_A_DATA_DIRECTION, |
| 78 | | PORT_A_SPECIAL_IO_CONTROL, |
| 79 | | PORT_A_PATTERN_POLARITY, |
| 80 | | PORT_A_PATTERN_TRANSITION, |
| 81 | | PORT_A_PATTERN_MASK, |
| 82 | | PORT_B_MODE_SPECIFICATION, |
| 83 | | PORT_B_HANDSHAKE_SPECIFICATION, |
| 84 | | PORT_B_DATA_PATH_POLARITY, |
| 85 | | PORT_B_DATA_DIRECTION, |
| 86 | | PORT_B_SPECIAL_IO_CONTROL, |
| 87 | | PORT_B_PATTERN_POLARITY, |
| 88 | | PORT_B_PATTERN_TRANSITION, |
| 89 | | PORT_B_PATTERN_MASK |
| 90 | | }; |
| 91 | | |
| 92 | | |
| 93 | | // counter/timer link control |
| 94 | | enum |
| 95 | | { |
| 96 | | LC_INDEPENDENT = 0, |
| 97 | | LC_CT1_GATES_CT2, |
| 98 | | LC_CT1_TRIGGERS_CT2, |
| 99 | | LC_CT1_COUNTS_CT2 |
| 100 | | }; |
| 101 | | |
| 102 | | |
| 103 | | // port type select |
| 104 | | enum |
| 105 | | { |
| 106 | | PTS_BIT = 0, |
| 107 | | PTS_INPUT, |
| 108 | | PTS_OUTPUT, |
| 109 | | PTS_BIDIRECTIONAL |
| 110 | | }; |
| 111 | | |
| 112 | | |
| 113 | | // pattern mode specification |
| 114 | | enum |
| 115 | | { |
| 116 | | PMS_DISABLE = 0, |
| 117 | | PMS_AND, |
| 118 | | PMS_OR, |
| 119 | | PMS_VECTOR |
| 120 | | }; |
| 121 | | |
| 122 | | |
| 123 | | // handshake specification |
| 124 | | enum |
| 125 | | { |
| 126 | | HTS_INTERLOCKED = 0, |
| 127 | | HTS_STROBED, |
| 128 | | HTS_PULSED, |
| 129 | | HTS_3_WIRE |
| 130 | | }; |
| 131 | | |
| 132 | | |
| 133 | | // request/wait specification |
| 134 | | enum |
| 135 | | { |
| 136 | | RWS_DISABLED = 0, |
| 137 | | RWS_OUTPUT_WAIT, |
| 138 | | RWS_INPUT_WAIT = 3, |
| 139 | | RWS_SPECIAL_REQUEST, |
| 140 | | RWS_OUTPUT_REQUEST, |
| 141 | | RWS_INPUT_REQUEST = 7 |
| 142 | | }; |
| 143 | | |
| 144 | | |
| 145 | | // pattern specification |
| 146 | | enum |
| 147 | | { |
| 148 | | BIT_MASKED_OFF = 0, |
| 149 | | ANY_TRANSITION, |
| 150 | | ZERO = 4, |
| 151 | | ONE, |
| 152 | | ONE_TO_ZERO, |
| 153 | | ZERO_TO_ONE |
| 154 | | }; |
| 155 | | |
| 156 | | |
| 157 | | // output duty cycle |
| 158 | | enum |
| 159 | | { |
| 160 | | DCS_PULSE, |
| 161 | | DCS_ONE_SHOT, |
| 162 | | DCS_SQUARE_WAVE, |
| 163 | | DCS_DO_NOT_USE |
| 164 | | }; |
| 165 | | |
| 166 | | |
| 167 | | // master interrupt control register |
| 168 | | #define MICR_RESET 0x01 // reset |
| 169 | | #define MICR_RJA 0x02 // right justified address |
| 170 | | #define MICR_CT_VIS 0x04 // counter/timer vector includes status |
| 171 | | #define MICR_PB_VIS 0x08 // port B vector includes status |
| 172 | | #define MICR_PA_VIS 0x10 // port A vector includes status |
| 173 | | #define MICR_NV 0x20 // no vector |
| 174 | | #define MICR_DLC 0x40 // disable lower chain |
| 175 | | #define MICR_MIE 0x80 // master interrupt enable |
| 176 | | |
| 177 | | |
| 178 | | // master configuration control register |
| 179 | | #define MCCR_LC_MASK 0x03 // counter/timer link controls |
| 180 | | #define MCCR_PAE 0x04 // port A enable |
| 181 | | #define MCCR_PLC 0x08 // port link control |
| 182 | | #define MCCR_PCE_CT3E 0x10 // port C and counter/timer 3 enable |
| 183 | | #define MCCR_CT2E 0x20 // counter/timer 2 enable |
| 184 | | #define MCCR_CT1E 0x40 // counter/timer 1 enable |
| 185 | | #define MCCR_PBE 0x80 // port B enable |
| 186 | | |
| 187 | | |
| 188 | | // port mode specification registers |
| 189 | | #define PMS_LPM 0x01 // latch on pattern match |
| 190 | | #define PMS_PMS_MASK 0x06 // pattern mode specification |
| 191 | | #define PMS_IMO 0x08 // interrupt on match only |
| 192 | | #define PMS_SB 0x10 // single buffer |
| 193 | | #define PMS_ITB 0x20 // interrupt on two bytes |
| 194 | | #define PMS_PTS_MASK 0xc0 // port type select |
| 195 | | |
| 196 | | |
| 197 | | // port handshake specification registers |
| 198 | | #define PHS_DTS_MASK 0x07 // deskew time specification |
| 199 | | #define PHS_RWS_MASK 0x38 // request/wait specification |
| 200 | | #define PHS_HTS_MASK 0xc0 // handshake type specification |
| 201 | | |
| 202 | | |
| 203 | | // port command and status registers |
| 204 | | #define PCS_IOE 0x01 // interrupt on error |
| 205 | | #define PCS_PMF 0x02 // pattern match flag (read only) |
| 206 | | #define PCS_IRF 0x04 // input register full (read only) |
| 207 | | #define PCS_ORE 0x08 // output register empty (read only) |
| 208 | | #define PCS_ERR 0x10 // interrupt error (read only) |
| 209 | | #define PCS_IP 0x20 // interrupt pending |
| 210 | | #define PCS_IE 0x40 // interrupt enable |
| 211 | | #define PCS_IUS 0x80 // interrupt under service |
| 212 | | |
| 213 | | |
| 214 | | // counter/timer mode specification registers |
| 215 | | #define CTMS_DCS_MASK 0x03 // output duty cycle |
| 216 | | #define CTMS_REB 0x04 // retrigger enable bit |
| 217 | | #define CTMS_EDE 0x08 // external gate enable |
| 218 | | #define CTMS_ETE 0x10 // external trigger enable |
| 219 | | #define CTMS_ECE 0x20 // external count enable |
| 220 | | #define CTMS_EOE 0x40 // external output enable |
| 221 | | #define CTMS_CSC 0x80 // continuous single cycle |
| 222 | | |
| 223 | | |
| 224 | | // counter/timer command and status registers |
| 225 | | #define CTCS_CIP 0x01 // count in progress (read only) |
| 226 | | #define CTCS_TCB 0x02 // trigger command bit (write only - read returns 0) |
| 227 | | #define CTCS_GCB 0x04 // gate command bit |
| 228 | | #define CTCS_RCC 0x08 // read counter control (read/set only - cleared by reading CCR LSB) |
| 229 | | #define CTCS_ERR 0x10 // interrupt error (read only) |
| 230 | | #define CTCS_IP 0x20 // interrupt pending |
| 231 | | #define CTCS_IE 0x40 // interrupt enable |
| 232 | | #define CTCS_IUS 0x80 // interrupt under service |
| 233 | | |
| 234 | | |
| 235 | | |
| 236 | | //************************************************************************** |
| 237 | | // DEVICE DEFINITIONS |
| 238 | | //************************************************************************** |
| 239 | | |
| 240 | | const device_type Z8536 = z8536_device_config::static_alloc_device_config; |
| 241 | | |
| 242 | | |
| 243 | | |
| 244 | | //************************************************************************** |
| 245 | | // DEVICE CONFIGURATION |
| 246 | | //************************************************************************** |
| 247 | | |
| 248 | | GENERIC_DEVICE_CONFIG_SETUP(z8536, "Zilog Z8536") |
| 249 | | |
| 250 | | |
| 251 | | //------------------------------------------------- |
| 252 | | // device_config_complete - perform any |
| 253 | | // operations now that the configuration is |
| 254 | | // complete |
| 255 | | //------------------------------------------------- |
| 256 | | |
| 257 | | void z8536_device_config::device_config_complete() |
| 258 | | { |
| 259 | | // inherit a copy of the static data |
| 260 | | const z8536_interface *intf = reinterpret_cast<const z8536_interface *>(static_config()); |
| 261 | | if (intf != NULL) |
| 262 | | *static_cast<z8536_interface *>(this) = *intf; |
| 263 | | |
| 264 | | // or initialize to defaults if none provided |
| 265 | | else |
| 266 | | { |
| 267 | | memset(&m_out_int_func, 0, sizeof(m_out_int_func)); |
| 268 | | memset(&m_in_pa_func, 0, sizeof(m_in_pa_func)); |
| 269 | | memset(&m_out_pa_func, 0, sizeof(m_out_pa_func)); |
| 270 | | memset(&m_in_pb_func, 0, sizeof(m_in_pb_func)); |
| 271 | | memset(&m_out_pb_func, 0, sizeof(m_out_pb_func)); |
| 272 | | memset(&m_in_pc_func, 0, sizeof(m_in_pc_func)); |
| 273 | | memset(&m_out_pc_func, 0, sizeof(m_out_pc_func)); |
| 274 | | } |
| 275 | | } |
| 276 | | |
| 277 | | |
| 278 | | |
| 279 | | //************************************************************************** |
| 280 | | // INLINE HELPERS |
| 281 | | //************************************************************************** |
| 282 | | |
| 283 | | //------------------------------------------------- |
| 284 | | // read_register - read from register |
| 285 | | //------------------------------------------------- |
| 286 | | |
| 287 | | inline UINT8 z8536_device::read_register(offs_t offset) |
| 288 | | { |
| 289 | | UINT8 data = 0; |
| 290 | | |
| 291 | | data = m_register[offset]; // HACK |
| 292 | | |
| 293 | | switch (offset) |
| 294 | | { |
| 295 | | case PORT_A_DATA: |
| 296 | | data = devcb_call_read8(&m_in_pa_func, 0); |
| 297 | | break; |
| 298 | | |
| 299 | | case PORT_B_DATA: |
| 300 | | data = devcb_call_read8(&m_in_pb_func, 0); |
| 301 | | break; |
| 302 | | |
| 303 | | case PORT_C_DATA: |
| 304 | | data = 0xf0 | (devcb_call_read8(&m_in_pc_func, 0) & 0x0f); |
| 305 | | break; |
| 306 | | |
| 307 | | default: |
| 308 | | logerror("Z8536 '%s' Unimplemented read from register %u\n", tag(), offset); |
| 309 | | } |
| 310 | | |
| 311 | | return data; |
| 312 | | } |
| 313 | | |
| 314 | | |
| 315 | | //------------------------------------------------- |
| 316 | | // read_register - masked read from register |
| 317 | | //------------------------------------------------- |
| 318 | | |
| 319 | | inline UINT8 z8536_device::read_register(offs_t offset, UINT8 mask) |
| 320 | | { |
| 321 | | return read_register(offset) & mask; |
| 322 | | } |
| 323 | | |
| 324 | | |
| 325 | | //------------------------------------------------- |
| 326 | | // write_register - write to register |
| 327 | | //------------------------------------------------- |
| 328 | | |
| 329 | | inline void z8536_device::write_register(offs_t offset, UINT8 data) |
| 330 | | { |
| 331 | | switch (offset) |
| 332 | | { |
| 333 | | case MASTER_INTERRUPT_CONTROL: |
| 334 | | if (data & MICR_RESET) |
| 335 | | { |
| 336 | | device_reset(); |
| 337 | | } |
| 338 | | else if (m_state == STATE_RESET) |
| 339 | | { |
| 340 | | m_state = STATE_0; |
| 341 | | } |
| 342 | | break; |
| 343 | | |
| 344 | | case PORT_A_DATA: |
| 345 | | devcb_call_write8(&m_out_pa_func, 0, data); |
| 346 | | break; |
| 347 | | |
| 348 | | case PORT_B_DATA: |
| 349 | | devcb_call_write8(&m_out_pb_func, 0, data); |
| 350 | | break; |
| 351 | | |
| 352 | | case PORT_C_DATA: |
| 353 | | { |
| 354 | | UINT8 mask = (data & 0xf0) | (data >> 4); |
| 355 | | |
| 356 | | m_output[PORT_C] = (m_output[PORT_C] & mask) | ((data & 0x0f) & (mask ^ 0xff)); |
| 357 | | |
| 358 | | devcb_call_write8(&m_out_pc_func, 0, m_output[PORT_C]); |
| 359 | | } |
| 360 | | break; |
| 361 | | |
| 362 | | default: |
| 363 | | logerror("Z8536 '%s' Unimplemented write %02x to register %u\n", tag(), data, offset); |
| 364 | | } |
| 365 | | |
| 366 | | m_register[offset] = data; // HACK |
| 367 | | } |
| 368 | | |
| 369 | | |
| 370 | | //------------------------------------------------- |
| 371 | | // write_register - masked write to register |
| 372 | | //------------------------------------------------- |
| 373 | | |
| 374 | | inline void z8536_device::write_register(offs_t offset, UINT8 data, UINT8 mask) |
| 375 | | { |
| 376 | | UINT8 combined_data = (data & mask) | (m_register[offset] & (mask ^ 0xff)); |
| 377 | | |
| 378 | | write_register(offset, combined_data); |
| 379 | | } |
| 380 | | |
| 381 | | |
| 382 | | //------------------------------------------------- |
| 383 | | // count - |
| 384 | | //------------------------------------------------- |
| 385 | | |
| 386 | | inline void z8536_device::count(device_timer_id id) |
| 387 | | { |
| 388 | | } |
| 389 | | |
| 390 | | |
| 391 | | //------------------------------------------------- |
| 392 | | // trigger - |
| 393 | | //------------------------------------------------- |
| 394 | | |
| 395 | | inline void z8536_device::trigger(device_timer_id id) |
| 396 | | { |
| 397 | | } |
| 398 | | |
| 399 | | |
| 400 | | //------------------------------------------------- |
| 401 | | // gate - |
| 402 | | //------------------------------------------------- |
| 403 | | |
| 404 | | inline void z8536_device::gate(device_timer_id id) |
| 405 | | { |
| 406 | | } |
| 407 | | |
| 408 | | |
| 409 | | |
| 410 | | //************************************************************************** |
| 411 | | // LIVE DEVICE |
| 412 | | //************************************************************************** |
| 413 | | |
| 414 | | //------------------------------------------------- |
| 415 | | // z8536_device - constructor |
| 416 | | //------------------------------------------------- |
| 417 | | |
| 418 | | z8536_device::z8536_device(running_machine &_machine, const z8536_device_config &config) |
| 419 | | : device_t(_machine, config), |
| 420 | | m_config(config) |
| 421 | | { |
| 422 | | } |
| 423 | | |
| 424 | | |
| 425 | | //------------------------------------------------- |
| 426 | | // device_start - device-specific startup |
| 427 | | //------------------------------------------------- |
| 428 | | |
| 429 | | void z8536_device::device_start() |
| 430 | | { |
| 431 | | // allocate timers |
| 432 | | m_timer[TIMER_1] = timer_alloc(TIMER_1); |
| 433 | | m_timer[TIMER_2] = timer_alloc(TIMER_2); |
| 434 | | m_timer[TIMER_3] = timer_alloc(TIMER_3); |
| 435 | | |
| 436 | | // resolve callbacks |
| 437 | | devcb_resolve_write_line(&m_out_int_func, &m_config.m_out_int_func, this); |
| 438 | | devcb_resolve_read8(&m_in_pa_func, &m_config.m_in_pa_func, this); |
| 439 | | devcb_resolve_write8(&m_out_pa_func, &m_config.m_out_pa_func, this); |
| 440 | | devcb_resolve_read8(&m_in_pb_func, &m_config.m_in_pb_func, this); |
| 441 | | devcb_resolve_write8(&m_out_pb_func, &m_config.m_out_pb_func, this); |
| 442 | | devcb_resolve_read8(&m_in_pc_func, &m_config.m_in_pc_func, this); |
| 443 | | devcb_resolve_write8(&m_out_pc_func, &m_config.m_out_pc_func, this); |
| 444 | | } |
| 445 | | |
| 446 | | |
| 447 | | //------------------------------------------------- |
| 448 | | // device_start - device-specific reset |
| 449 | | //------------------------------------------------- |
| 450 | | |
| 451 | | void z8536_device::device_reset() |
| 452 | | { |
| 453 | | m_state = STATE_RESET; |
| 454 | | |
| 455 | | for (int i = 0; i < 48; i++) |
| 456 | | { |
| 457 | | m_register[i] = 0; |
| 458 | | } |
| 459 | | |
| 460 | | m_register[MASTER_INTERRUPT_CONTROL] = MICR_RESET; |
| 461 | | m_pointer = 0; |
| 462 | | } |
| 463 | | |
| 464 | | |
| 465 | | //------------------------------------------------- |
| 466 | | // device_timer - handler timer events |
| 467 | | //------------------------------------------------- |
| 468 | | |
| 469 | | void z8536_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 470 | | { |
| 471 | | switch (id) |
| 472 | | { |
| 473 | | case TIMER_1: |
| 474 | | count(TIMER_1); |
| 475 | | break; |
| 476 | | |
| 477 | | case TIMER_2: |
| 478 | | count(TIMER_2); |
| 479 | | break; |
| 480 | | |
| 481 | | case TIMER_3: |
| 482 | | count(TIMER_3); |
| 483 | | break; |
| 484 | | } |
| 485 | | } |
| 486 | | |
| 487 | | |
| 488 | | //------------------------------------------------- |
| 489 | | // read - register read |
| 490 | | //------------------------------------------------- |
| 491 | | |
| 492 | | READ8_MEMBER( z8536_device::read ) |
| 493 | | { |
| 494 | | UINT8 data = 0; |
| 495 | | |
| 496 | | if (m_state == STATE_RESET) |
| 497 | | { |
| 498 | | // read RESET bit |
| 499 | | data = read_register(m_pointer, 0x01); |
| 500 | | } |
| 501 | | else |
| 502 | | { |
| 503 | | switch (offset & 0x03) |
| 504 | | { |
| 505 | | case PORT_C: |
| 506 | | data = read_register(PORT_C_DATA); |
| 507 | | break; |
| 508 | | |
| 509 | | case PORT_B: |
| 510 | | data = read_register(PORT_B_DATA); |
| 511 | | break; |
| 512 | | |
| 513 | | case PORT_A: |
| 514 | | data = read_register(PORT_A_DATA); |
| 515 | | break; |
| 516 | | |
| 517 | | case CONTROL: |
| 518 | | switch (m_state) |
| 519 | | { |
| 520 | | case STATE_1: |
| 521 | | m_state = STATE_0; |
| 522 | | // fallthru |
| 523 | | case STATE_0: |
| 524 | | data = read_register(m_pointer); |
| 525 | | break; |
| 526 | | } |
| 527 | | break; |
| 528 | | } |
| 529 | | } |
| 530 | | |
| 531 | | return data; |
| 532 | | } |
| 533 | | |
| 534 | | |
| 535 | | //------------------------------------------------- |
| 536 | | // write - register write |
| 537 | | //------------------------------------------------- |
| 538 | | |
| 539 | | WRITE8_MEMBER( z8536_device::write ) |
| 540 | | { |
| 541 | | if (m_state == STATE_RESET) |
| 542 | | { |
| 543 | | // write RESET bit |
| 544 | | write_register(m_pointer, data, 0x01); |
| 545 | | } |
| 546 | | else |
| 547 | | { |
| 548 | | switch (offset & 0x03) |
| 549 | | { |
| 550 | | case PORT_C: |
| 551 | | write_register(PORT_C_DATA, data); |
| 552 | | break; |
| 553 | | |
| 554 | | case PORT_B: |
| 555 | | write_register(PORT_B_DATA, data); |
| 556 | | break; |
| 557 | | |
| 558 | | case PORT_A: |
| 559 | | write_register(PORT_A_DATA, data); |
| 560 | | break; |
| 561 | | |
| 562 | | case CONTROL: |
| 563 | | switch (m_state) |
| 564 | | { |
| 565 | | case STATE_0: |
| 566 | | m_pointer = data; |
| 567 | | m_state = STATE_1; |
| 568 | | break; |
| 569 | | |
| 570 | | case STATE_1: |
| 571 | | write_register(m_pointer, data); |
| 572 | | m_state = STATE_0; |
| 573 | | } |
| 574 | | break; |
| 575 | | } |
| 576 | | } |
| 577 | | } |
| 578 | | |
| 579 | | |
| 580 | | //------------------------------------------------- |
| 581 | | // intack_w - interrupt acknowledge |
| 582 | | //------------------------------------------------- |
| 583 | | |
| 584 | | WRITE_LINE_MEMBER( z8536_device::intack_w ) |
| 585 | | { |
| 586 | | } |
| 587 | | |
| 588 | | |
| 589 | | //------------------------------------------------- |
| 590 | | // pb*_w - port B bits 0-7 write |
| 591 | | //------------------------------------------------- |
| 592 | | |
| 593 | | WRITE_LINE_MEMBER( z8536_device::pb0_w ) { } |
| 594 | | WRITE_LINE_MEMBER( z8536_device::pb1_w ) { } |
| 595 | | WRITE_LINE_MEMBER( z8536_device::pb2_w ) { } |
| 596 | | WRITE_LINE_MEMBER( z8536_device::pb3_w ) { } |
| 597 | | WRITE_LINE_MEMBER( z8536_device::pb4_w ) { } |
| 598 | | WRITE_LINE_MEMBER( z8536_device::pb5_w ) { } |
| 599 | | WRITE_LINE_MEMBER( z8536_device::pb6_w ) { } |
| 600 | | WRITE_LINE_MEMBER( z8536_device::pb7_w ) { } |
| 601 | | |
| 602 | | |
| 603 | | //------------------------------------------------- |
| 604 | | // pc*_w - port C bits 0-3 write |
| 605 | | //------------------------------------------------- |
| 606 | | |
| 607 | | WRITE_LINE_MEMBER( z8536_device::pc0_w ) { } |
| 608 | | WRITE_LINE_MEMBER( z8536_device::pc1_w ) { } |
| 609 | | WRITE_LINE_MEMBER( z8536_device::pc2_w ) { } |
| 610 | | WRITE_LINE_MEMBER( z8536_device::pc3_w ) { } |
src/mess/machine/i8355.c
| r10968 | r10969 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | Intel 8355 - 16,384-Bit ROM with I/O emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | **********************************************************************/ |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "i8355.h" |
| 12 | | |
| 13 | | |
| 14 | | |
| 15 | | //************************************************************************** |
| 16 | | // MACROS / CONSTANTS |
| 17 | | //************************************************************************** |
| 18 | | |
| 19 | | #define LOG 0 |
| 20 | | |
| 21 | | enum |
| 22 | | { |
| 23 | | REGISTER_PORT_A = 0, |
| 24 | | REGISTER_PORT_B, |
| 25 | | REGISTER_PORT_A_DDR, |
| 26 | | REGISTER_PORT_B_DDR |
| 27 | | }; |
| 28 | | |
| 29 | | enum |
| 30 | | { |
| 31 | | PORT_A = 0, |
| 32 | | PORT_B, |
| 33 | | PORT_COUNT |
| 34 | | }; |
| 35 | | |
| 36 | | |
| 37 | | |
| 38 | | //************************************************************************** |
| 39 | | // GLOBAL VARIABLES |
| 40 | | //************************************************************************** |
| 41 | | |
| 42 | | // devices |
| 43 | | const device_type I8355 = i8355_device_config::static_alloc_device_config; |
| 44 | | |
| 45 | | |
| 46 | | // default address map |
| 47 | | static ADDRESS_MAP_START( i8355, AS_0, 8 ) |
| 48 | | AM_RANGE(0x000, 0x7ff) AM_ROM |
| 49 | | ADDRESS_MAP_END |
| 50 | | |
| 51 | | |
| 52 | | |
| 53 | | //************************************************************************** |
| 54 | | // DEVICE CONFIGURATION |
| 55 | | //************************************************************************** |
| 56 | | |
| 57 | | //------------------------------------------------- |
| 58 | | // i8355_device_config - constructor |
| 59 | | //------------------------------------------------- |
| 60 | | |
| 61 | | i8355_device_config::i8355_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 62 | | : device_config(mconfig, static_alloc_device_config, "Intel 8355", tag, owner, clock), |
| 63 | | device_config_memory_interface(mconfig, *this), |
| 64 | | m_space_config("ram", ENDIANNESS_LITTLE, 8, 11, 0, NULL, *ADDRESS_MAP_NAME(i8355)) |
| 65 | | { |
| 66 | | } |
| 67 | | |
| 68 | | |
| 69 | | //------------------------------------------------- |
| 70 | | // static_alloc_device_config - allocate a new |
| 71 | | // configuration object |
| 72 | | //------------------------------------------------- |
| 73 | | |
| 74 | | device_config *i8355_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 75 | | { |
| 76 | | return global_alloc(i8355_device_config(mconfig, tag, owner, clock)); |
| 77 | | } |
| 78 | | |
| 79 | | |
| 80 | | //------------------------------------------------- |
| 81 | | // alloc_device - allocate a new device object |
| 82 | | //------------------------------------------------- |
| 83 | | |
| 84 | | device_t *i8355_device_config::alloc_device(running_machine &machine) const |
| 85 | | { |
| 86 | | return auto_alloc(&machine, i8355_device(machine, *this)); |
| 87 | | } |
| 88 | | |
| 89 | | |
| 90 | | //------------------------------------------------- |
| 91 | | // memory_space_config - return a description of |
| 92 | | // any address spaces owned by this device |
| 93 | | //------------------------------------------------- |
| 94 | | |
| 95 | | const address_space_config *i8355_device_config::memory_space_config(address_spacenum spacenum) const |
| 96 | | { |
| 97 | | return (spacenum == AS_0) ? &m_space_config : NULL; |
| 98 | | } |
| 99 | | |
| 100 | | |
| 101 | | //------------------------------------------------- |
| 102 | | // device_config_complete - perform any |
| 103 | | // operations now that the configuration is |
| 104 | | // complete |
| 105 | | //------------------------------------------------- |
| 106 | | |
| 107 | | void i8355_device_config::device_config_complete() |
| 108 | | { |
| 109 | | // inherit a copy of the static data |
| 110 | | const i8355_interface *intf = reinterpret_cast<const i8355_interface *>(static_config()); |
| 111 | | if (intf != NULL) |
| 112 | | *static_cast<i8355_interface *>(this) = *intf; |
| 113 | | |
| 114 | | // or initialize to defaults if none provided |
| 115 | | else |
| 116 | | { |
| 117 | | memset(&in_pa_func, 0, sizeof(in_pa_func)); |
| 118 | | memset(&out_pa_func, 0, sizeof(out_pa_func)); |
| 119 | | memset(&in_pb_func, 0, sizeof(in_pb_func)); |
| 120 | | memset(&out_pb_func, 0, sizeof(out_pb_func)); |
| 121 | | } |
| 122 | | } |
| 123 | | |
| 124 | | |
| 125 | | |
| 126 | | //************************************************************************** |
| 127 | | // INLINE HELPERS |
| 128 | | //************************************************************************** |
| 129 | | |
| 130 | | //------------------------------------------------- |
| 131 | | // read_port - read from input port |
| 132 | | //------------------------------------------------- |
| 133 | | |
| 134 | | inline UINT8 i8355_device::read_port(int port) |
| 135 | | { |
| 136 | | UINT8 data = m_output[port] & m_ddr[port]; |
| 137 | | |
| 138 | | if (m_ddr[port] != 0xff) |
| 139 | | { |
| 140 | | data |= devcb_call_read8(&m_in_port_func[port], 0) & ~m_ddr[port]; |
| 141 | | } |
| 142 | | |
| 143 | | return data; |
| 144 | | } |
| 145 | | |
| 146 | | |
| 147 | | //------------------------------------------------- |
| 148 | | // write_port - write to output port |
| 149 | | //------------------------------------------------- |
| 150 | | |
| 151 | | inline void i8355_device::write_port(int port, UINT8 data) |
| 152 | | { |
| 153 | | m_output[port] = data; |
| 154 | | |
| 155 | | devcb_call_write8(&m_out_port_func[port], 0, m_output[port] & m_ddr[port]); |
| 156 | | } |
| 157 | | |
| 158 | | |
| 159 | | |
| 160 | | //************************************************************************** |
| 161 | | // LIVE DEVICE |
| 162 | | //************************************************************************** |
| 163 | | |
| 164 | | //------------------------------------------------- |
| 165 | | // i8355_device - constructor |
| 166 | | //------------------------------------------------- |
| 167 | | |
| 168 | | i8355_device::i8355_device(running_machine &_machine, const i8355_device_config &config) |
| 169 | | : device_t(_machine, config), |
| 170 | | device_memory_interface(_machine, config, *this), |
| 171 | | m_config(config) |
| 172 | | { |
| 173 | | |
| 174 | | } |
| 175 | | |
| 176 | | |
| 177 | | //------------------------------------------------- |
| 178 | | // device_start - device-specific startup |
| 179 | | //------------------------------------------------- |
| 180 | | |
| 181 | | void i8355_device::device_start() |
| 182 | | { |
| 183 | | // resolve callbacks |
| 184 | | devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this); |
| 185 | | devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this); |
| 186 | | devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this); |
| 187 | | devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this); |
| 188 | | |
| 189 | | // register for state saving |
| 190 | | save_item(NAME(m_output)); |
| 191 | | save_item(NAME(m_ddr)); |
| 192 | | } |
| 193 | | |
| 194 | | |
| 195 | | //------------------------------------------------- |
| 196 | | // device_reset - device-specific reset |
| 197 | | //------------------------------------------------- |
| 198 | | |
| 199 | | void i8355_device::device_reset() |
| 200 | | { |
| 201 | | // set ports to input mode |
| 202 | | m_ddr[PORT_A] = 0; |
| 203 | | m_ddr[PORT_B] = 0; |
| 204 | | } |
| 205 | | |
| 206 | | |
| 207 | | //------------------------------------------------- |
| 208 | | // io_r - register read |
| 209 | | //------------------------------------------------- |
| 210 | | |
| 211 | | READ8_MEMBER( i8355_device::io_r ) |
| 212 | | { |
| 213 | | int port = offset & 0x01; |
| 214 | | |
| 215 | | UINT8 data = 0; |
| 216 | | |
| 217 | | switch (offset & 0x03) |
| 218 | | { |
| 219 | | case REGISTER_PORT_A: |
| 220 | | case REGISTER_PORT_B: |
| 221 | | data = read_port(port); |
| 222 | | break; |
| 223 | | |
| 224 | | case REGISTER_PORT_A_DDR: |
| 225 | | case REGISTER_PORT_B_DDR: |
| 226 | | // write only |
| 227 | | break; |
| 228 | | } |
| 229 | | |
| 230 | | return data; |
| 231 | | } |
| 232 | | |
| 233 | | |
| 234 | | //------------------------------------------------- |
| 235 | | // io_w - register write |
| 236 | | //------------------------------------------------- |
| 237 | | |
| 238 | | WRITE8_MEMBER( i8355_device::io_w ) |
| 239 | | { |
| 240 | | int port = offset & 0x01; |
| 241 | | |
| 242 | | switch (offset & 0x03) |
| 243 | | { |
| 244 | | case REGISTER_PORT_A: |
| 245 | | case REGISTER_PORT_B: |
| 246 | | if (LOG) logerror("I8355 '%s' Port %c Write %02x\n", tag(), 'A' + port, data); |
| 247 | | |
| 248 | | write_port(port, data); |
| 249 | | break; |
| 250 | | |
| 251 | | case REGISTER_PORT_A_DDR: |
| 252 | | case REGISTER_PORT_B_DDR: |
| 253 | | if (LOG) logerror("I8355 '%s' Port %c DDR: %02x\n", tag(), 'A' + port, data); |
| 254 | | |
| 255 | | m_ddr[port] = data; |
| 256 | | write_port(port, data); |
| 257 | | break; |
| 258 | | } |
| 259 | | } |
| 260 | | |
| 261 | | |
| 262 | | //------------------------------------------------- |
| 263 | | // memory_r - internal ROM read |
| 264 | | //------------------------------------------------- |
| 265 | | |
| 266 | | READ8_MEMBER( i8355_device::memory_r ) |
| 267 | | { |
| 268 | | return this->space()->read_byte(offset); |
| 269 | | } |
src/mess/video/crt9007.c
| r10968 | r10969 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | SMC CRT9007 CRT Video Processor and Controller (VPAC) emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | **********************************************************************/ |
| 9 | | |
| 10 | | /* |
| 11 | | |
| 12 | | TODO: |
| 13 | | |
| 14 | | - cursor timer |
| 15 | | - interrupts |
| 16 | | - light pen |
| 17 | | - frame timer |
| 18 | | - non-DMA mode |
| 19 | | - DMA mode |
| 20 | | - cursor/blank skew |
| 21 | | - sequential breaks |
| 22 | | - interlaced mode |
| 23 | | - smooth scroll |
| 24 | | - page blank |
| 25 | | - double height cursor |
| 26 | | - row attributes |
| 27 | | - pin configuration |
| 28 | | - operation modes 0,4,7 |
| 29 | | - address modes 1,2,3 |
| 30 | | - light pen |
| 31 | | - state saving |
| 32 | | |
| 33 | | */ |
| 34 | | |
| 35 | | #include "emu.h" |
| 36 | | #include "crt9007.h" |
| 37 | | |
| 38 | | |
| 39 | | |
| 40 | | //************************************************************************** |
| 41 | | // MACROS / CONSTANTS |
| 42 | | //************************************************************************** |
| 43 | | |
| 44 | | #define LOG 1 |
| 45 | | |
| 46 | | #define HAS_VALID_PARAMETERS \ |
| 47 | | (m_reg[0x00] && m_reg[0x01] && m_reg[0x07] && m_reg[0x08] && m_reg[0x09]) |
| 48 | | |
| 49 | | #define CHARACTERS_PER_HORIZONTAL_PERIOD \ |
| 50 | | m_reg[0x00] |
| 51 | | |
| 52 | | #define CHARACTERS_PER_DATA_ROW \ |
| 53 | | (m_reg[0x01] + 1) |
| 54 | | |
| 55 | | #define HORIZONTAL_DELAY \ |
| 56 | | m_reg[0x02] |
| 57 | | |
| 58 | | #define HORIZONTAL_SYNC_WIDTH \ |
| 59 | | m_reg[0x03] |
| 60 | | |
| 61 | | #define VERTICAL_SYNC_WIDTH \ |
| 62 | | m_reg[0x04] |
| 63 | | |
| 64 | | #define VERTICAL_DELAY \ |
| 65 | | (m_reg[0x05] - 1) |
| 66 | | |
| 67 | | #define PIN_CONFIGURATION \ |
| 68 | | (m_reg[0x06] >> 6) |
| 69 | | |
| 70 | | #define CURSOR_SKEW \ |
| 71 | | ((m_reg[0x06] >> 3) & 0x07) |
| 72 | | |
| 73 | | #define BLANK_SKEW \ |
| 74 | | (m_reg[0x06] & 0x07) |
| 75 | | |
| 76 | | #define VISIBLE_DATA_ROWS_PER_FRAME \ |
| 77 | | (m_reg[0x07] + 1) |
| 78 | | |
| 79 | | #define SCAN_LINES_PER_DATA_ROW \ |
| 80 | | ((m_reg[0x08] & 0x1f) + 1) |
| 81 | | |
| 82 | | #define SCAN_LINES_PER_FRAME \ |
| 83 | | (((m_reg[0x08] << 3) & 0x0700) | m_reg[0x09]) |
| 84 | | |
| 85 | | #define DMA_BURST_COUNT \ |
| 86 | | ((m_reg[0x0a] & 0x0f) + 1) |
| 87 | | |
| 88 | | #define DMA_BURST_DELAY \ |
| 89 | | ((((m_reg[0x0a] >> 4) & 0x07) + 1) % 8) |
| 90 | | |
| 91 | | #define DMA_DISABLE \ |
| 92 | | BIT(m_reg[0x0a], 7) |
| 93 | | |
| 94 | | #define SINGLE_HEIGHT_CURSOR \ |
| 95 | | BIT(m_reg[0x0b], 0) |
| 96 | | |
| 97 | | #define OPERATION_MODE \ |
| 98 | | ((m_reg[0x0b] >> 1) & 0x07) |
| 99 | | |
| 100 | | #define INTERLACE_MODE \ |
| 101 | | ((m_reg[0x0b] >> 4) & 0x03) |
| 102 | | |
| 103 | | #define PAGE_BLANK \ |
| 104 | | BIT(m_reg[0x0b], 6) |
| 105 | | |
| 106 | | #define TABLE_START \ |
| 107 | | (((m_reg[0x0d] << 8) & 0x3f00) | m_reg[0x0c]) |
| 108 | | |
| 109 | | #define ADDRESS_MODE \ |
| 110 | | ((m_reg[0x0d] >> 6) & 0x03) |
| 111 | | |
| 112 | | #define AUXILIARY_ADDRESS_1 \ |
| 113 | | (((m_reg[0x0f] << 8) & 0x3f00) | m_reg[0x0e]) |
| 114 | | |
| 115 | | #define ROW_ATTRIBUTES_1 \ |
| 116 | | ((m_reg[0x0f] >> 6) & 0x03) |
| 117 | | |
| 118 | | #define SEQUENTIAL_BREAK_1 \ |
| 119 | | m_reg[0x10] |
| 120 | | |
| 121 | | #define SEQUENTIAL_BREAK_2 \ |
| 122 | | m_reg[0x12] |
| 123 | | |
| 124 | | #define DATA_ROW_START \ |
| 125 | | m_reg[0x11] |
| 126 | | |
| 127 | | #define DATA_ROW_END \ |
| 128 | | m_reg[0x12] |
| 129 | | |
| 130 | | #define AUXILIARY_ADDRESS_2 \ |
| 131 | | (((m_reg[0x14] << 8) & 0x3f00) | m_reg[0x13]) |
| 132 | | |
| 133 | | #define ROW_ATTRIBUTES_2 \ |
| 134 | | ((m_reg[0x14] >> 6) & 0x03) |
| 135 | | |
| 136 | | #define SMOOTH_SCROLL_OFFSET \ |
| 137 | | ((m_reg[0x17] >> 1) & 0x3f) |
| 138 | | |
| 139 | | #define SMOOTH_SCROLL_OFFSET_OVERFLOW \ |
| 140 | | BIT(m_reg[0x17], 7) |
| 141 | | |
| 142 | | #define VERTICAL_CURSOR \ |
| 143 | | m_reg[0x18] |
| 144 | | |
| 145 | | #define HORIZONTAL_CURSOR \ |
| 146 | | m_reg[0x19] |
| 147 | | |
| 148 | | #define INTERRUPT_ENABLE \ |
| 149 | | m_reg[0x1a] |
| 150 | | |
| 151 | | #define FRAME_TIMER \ |
| 152 | | BIT(m_reg[0x1a], 0) |
| 153 | | |
| 154 | | #define LIGHT_PEN_INTERRUPT \ |
| 155 | | BIT(m_reg[0x1a], 5) |
| 156 | | |
| 157 | | #define VERTICAL_RETRACE_INTERRUPT \ |
| 158 | | BIT(m_reg[0x1a], 6) |
| 159 | | |
| 160 | | #define VERTICAL_LIGHT_PEN \ |
| 161 | | m_reg[0x3b] |
| 162 | | |
| 163 | | #define HORIZONTAL_LIGHT_PEN \ |
| 164 | | m_reg[0x3c] |
| 165 | | |
| 166 | | |
| 167 | | // interlace |
| 168 | | enum |
| 169 | | { |
| 170 | | NON_INTERLACED = 0, |
| 171 | | ENHANCED_VIDEO_INTERFACE, |
| 172 | | NORMAL_VIDEO_INTERFACE, |
| 173 | | }; |
| 174 | | |
| 175 | | |
| 176 | | // operation modes |
| 177 | | enum |
| 178 | | { |
| 179 | | OPERATION_MODE_REPETITIVE_MEMORY_ADDRESSING = 0, // not implemented |
| 180 | | OPERATION_MODE_DOUBLE_ROW_BUFFER = 1, |
| 181 | | OPERATION_MODE_SINGLE_ROW_BUFFER = 4, // not implemented |
| 182 | | OPERATION_MODE_ATTRIBUTE_ASSEMBLE = 7 // not implemented |
| 183 | | }; |
| 184 | | |
| 185 | | |
| 186 | | // addressing modes |
| 187 | | enum |
| 188 | | { |
| 189 | | ADDRESS_MODE_SEQUENTIAL_ADDRESSING = 0, |
| 190 | | ADDRESS_MODE_SEQUENTIAL_ROLL_ADDRESSING, // not implemented |
| 191 | | ADDRESS_MODE_CONTIGUOUS_ROW_TABLE, // not implemented |
| 192 | | ADDRESS_MODE_LINKED_LIST_ROW_TABLE // not implemented |
| 193 | | }; |
| 194 | | |
| 195 | | |
| 196 | | // interrupt enable register bits |
| 197 | | const int IE_VERTICAL_RETRACE = 0x40; |
| 198 | | const int IE_LIGHT_PEN = 0x20; |
| 199 | | const int IE_FRAME_TIMER = 0x01; |
| 200 | | |
| 201 | | // status register bits |
| 202 | | const int STATUS_INTERRUPT_PENDING = 0x80; |
| 203 | | const int STATUS_VERTICAL_RETRACE = 0x40; |
| 204 | | const int STATUS_LIGHT_PEN_UPDATE = 0x20; |
| 205 | | const int STATUS_ODD_EVEN = 0x04; |
| 206 | | const int STATUS_FRAME_TIMER_OCCURRED = 0x01; |
| 207 | | |
| 208 | | |
| 209 | | |
| 210 | | //************************************************************************** |
| 211 | | // GLOBAL VARIABLES |
| 212 | | //************************************************************************** |
| 213 | | |
| 214 | | // devices |
| 215 | | const device_type CRT9007 = crt9007_device_config::static_alloc_device_config; |
| 216 | | |
| 217 | | |
| 218 | | // default address map |
| 219 | | static ADDRESS_MAP_START( crt9007, AS_0, 8 ) |
| 220 | | AM_RANGE(0x0000, 0x3fff) AM_RAM |
| 221 | | ADDRESS_MAP_END |
| 222 | | |
| 223 | | |
| 224 | | |
| 225 | | //************************************************************************** |
| 226 | | // DEVICE CONFIGURATION |
| 227 | | //************************************************************************** |
| 228 | | |
| 229 | | //------------------------------------------------- |
| 230 | | // crt9007_device_config - constructor |
| 231 | | //------------------------------------------------- |
| 232 | | |
| 233 | | crt9007_device_config::crt9007_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 234 | | : device_config(mconfig, static_alloc_device_config, "SMC CRT9007", tag, owner, clock), |
| 235 | | device_config_memory_interface(mconfig, *this), |
| 236 | | m_space_config("videoram", ENDIANNESS_LITTLE, 8, 14, 0, NULL, *ADDRESS_MAP_NAME(crt9007)) |
| 237 | | { |
| 238 | | } |
| 239 | | |
| 240 | | |
| 241 | | //------------------------------------------------- |
| 242 | | // static_alloc_device_config - allocate a new |
| 243 | | // configuration object |
| 244 | | //------------------------------------------------- |
| 245 | | |
| 246 | | device_config *crt9007_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 247 | | { |
| 248 | | return global_alloc(crt9007_device_config(mconfig, tag, owner, clock)); |
| 249 | | } |
| 250 | | |
| 251 | | |
| 252 | | //------------------------------------------------- |
| 253 | | // alloc_device - allocate a new device object |
| 254 | | //------------------------------------------------- |
| 255 | | |
| 256 | | device_t *crt9007_device_config::alloc_device(running_machine &machine) const |
| 257 | | { |
| 258 | | return auto_alloc(&machine, crt9007_device(machine, *this)); |
| 259 | | } |
| 260 | | |
| 261 | | |
| 262 | | //------------------------------------------------- |
| 263 | | // memory_space_config - return a description of |
| 264 | | // any address spaces owned by this device |
| 265 | | //------------------------------------------------- |
| 266 | | |
| 267 | | const address_space_config *crt9007_device_config::memory_space_config(address_spacenum spacenum) const |
| 268 | | { |
| 269 | | return (spacenum == AS_0) ? &m_space_config : NULL; |
| 270 | | } |
| 271 | | |
| 272 | | |
| 273 | | //------------------------------------------------- |
| 274 | | // device_config_complete - perform any |
| 275 | | // operations now that the configuration is |
| 276 | | // complete |
| 277 | | //------------------------------------------------- |
| 278 | | |
| 279 | | void crt9007_device_config::device_config_complete() |
| 280 | | { |
| 281 | | // inherit a copy of the static data |
| 282 | | const crt9007_interface *intf = reinterpret_cast<const crt9007_interface *>(static_config()); |
| 283 | | if (intf != NULL) |
| 284 | | *static_cast<crt9007_interface *>(this) = *intf; |
| 285 | | |
| 286 | | // or initialize to defaults if none provided |
| 287 | | else |
| 288 | | { |
| 289 | | memset(&out_int_func, 0, sizeof(out_int_func)); |
| 290 | | memset(&out_dmar_func, 0, sizeof(out_dmar_func)); |
| 291 | | memset(&out_vs_func, 0, sizeof(out_vs_func)); |
| 292 | | memset(&out_hs_func, 0, sizeof(out_hs_func)); |
| 293 | | memset(&out_vlt_func, 0, sizeof(out_vlt_func)); |
| 294 | | memset(&out_curs_func, 0, sizeof(out_curs_func)); |
| 295 | | memset(&out_drb_func, 0, sizeof(out_drb_func)); |
| 296 | | memset(&out_cblank_func, 0, sizeof(out_cblank_func)); |
| 297 | | memset(&out_slg_func, 0, sizeof(out_slg_func)); |
| 298 | | memset(&out_sld_func, 0, sizeof(out_sld_func)); |
| 299 | | } |
| 300 | | } |
| 301 | | |
| 302 | | |
| 303 | | |
| 304 | | //************************************************************************** |
| 305 | | // INLINE HELPERS |
| 306 | | //************************************************************************** |
| 307 | | |
| 308 | | //------------------------------------------------- |
| 309 | | // readbyte - read a byte at the given address |
| 310 | | //------------------------------------------------- |
| 311 | | |
| 312 | | inline UINT8 crt9007_device::readbyte(offs_t address) |
| 313 | | { |
| 314 | | return space()->read_byte(address); |
| 315 | | } |
| 316 | | |
| 317 | | |
| 318 | | //------------------------------------------------- |
| 319 | | // trigger_interrupt - |
| 320 | | //------------------------------------------------- |
| 321 | | |
| 322 | | inline void crt9007_device::trigger_interrupt(int line) |
| 323 | | { |
| 324 | | if (INTERRUPT_ENABLE & line) |
| 325 | | { |
| 326 | | int status = m_status; |
| 327 | | |
| 328 | | m_status |= STATUS_INTERRUPT_PENDING | line; |
| 329 | | |
| 330 | | if (!(status & STATUS_INTERRUPT_PENDING)) |
| 331 | | { |
| 332 | | if (LOG) logerror("CRT9007 '%s' INT 1\n", tag()); |
| 333 | | devcb_call_write_line(&m_out_int_func, ASSERT_LINE); |
| 334 | | } |
| 335 | | } |
| 336 | | } |
| 337 | | |
| 338 | | |
| 339 | | //------------------------------------------------- |
| 340 | | // update_cblank_line - |
| 341 | | //------------------------------------------------- |
| 342 | | |
| 343 | | inline void crt9007_device::update_cblank_line() |
| 344 | | { |
| 345 | | int x = m_screen->hpos(); |
| 346 | | int y = m_screen->vpos(); |
| 347 | | |
| 348 | | // composite blank |
| 349 | | int cblank = !(m_hs & m_vs); |
| 350 | | |
| 351 | | if (m_cblank != cblank) |
| 352 | | { |
| 353 | | m_cblank = cblank; |
| 354 | | |
| 355 | | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : CBLANK %u\n", tag(), y, x, m_cblank); |
| 356 | | |
| 357 | | devcb_call_write_line(&m_out_cblank_func, m_cblank); |
| 358 | | } |
| 359 | | } |
| 360 | | |
| 361 | | |
| 362 | | //------------------------------------------------- |
| 363 | | // update_hsync_timer - |
| 364 | | //------------------------------------------------- |
| 365 | | |
| 366 | | inline void crt9007_device::update_hsync_timer(int state) |
| 367 | | { |
| 368 | | int y = m_screen->vpos(); |
| 369 | | |
| 370 | | int next_x = state ? m_hsync_start : m_hsync_end; |
| 371 | | int next_y = state ? (y + 1) % SCAN_LINES_PER_FRAME : y; |
| 372 | | |
| 373 | | attotime duration = m_screen->time_until_pos(next_y, next_x); |
| 374 | | |
| 375 | | m_hsync_timer->adjust(duration, !state); |
| 376 | | } |
| 377 | | |
| 378 | | |
| 379 | | //------------------------------------------------- |
| 380 | | // update_vsync_timer - |
| 381 | | //------------------------------------------------- |
| 382 | | |
| 383 | | inline void crt9007_device::update_vsync_timer(int state) |
| 384 | | { |
| 385 | | int next_y = state ? m_vsync_start : m_vsync_end; |
| 386 | | |
| 387 | | attotime duration = m_screen->time_until_pos(next_y, 0); |
| 388 | | |
| 389 | | m_vsync_timer->adjust(duration, !state); |
| 390 | | } |
| 391 | | |
| 392 | | |
| 393 | | //------------------------------------------------- |
| 394 | | // update_vlt_timer - |
| 395 | | //------------------------------------------------- |
| 396 | | |
| 397 | | inline void crt9007_device::update_vlt_timer(int state) |
| 398 | | { |
| 399 | | // this signal is active during all visible scan lines and during the horizontal trace at vertical retrace |
| 400 | | int y = m_screen->vpos(); |
| 401 | | |
| 402 | | int next_x = state ? m_vlt_end : m_vlt_start; |
| 403 | | int next_y = state ? y : ((y == m_vlt_bottom) ? 0 : (y + 1)); |
| 404 | | |
| 405 | | attotime duration = m_screen->time_until_pos(next_y, next_x); |
| 406 | | |
| 407 | | m_vlt_timer->adjust(duration, !state); |
| 408 | | } |
| 409 | | |
| 410 | | |
| 411 | | //------------------------------------------------- |
| 412 | | // update_curs_timer - |
| 413 | | //------------------------------------------------- |
| 414 | | |
| 415 | | inline void crt9007_device::update_curs_timer(int state) |
| 416 | | { |
| 417 | | // this signal is active for 1 character time for all scanlines within the data row |
| 418 | | // TODO |
| 419 | | } |
| 420 | | |
| 421 | | |
| 422 | | //------------------------------------------------- |
| 423 | | // update_drb_timer - |
| 424 | | //------------------------------------------------- |
| 425 | | |
| 426 | | inline void crt9007_device::update_drb_timer(int state) |
| 427 | | { |
| 428 | | // this signal is active for 1 full scan line (VLT edge to edge) at the top scan line of each new row |
| 429 | | // there is 1 extra DRB signal during the 1st scanline of the vertical retrace interval |
| 430 | | int y = m_screen->vpos(); |
| 431 | | |
| 432 | | int next_x = m_vlt_end; |
| 433 | | int next_y = y ? y + 1 : y; |
| 434 | | |
| 435 | | if (state) |
| 436 | | { |
| 437 | | if (y == 0) |
| 438 | | { |
| 439 | | next_y = VERTICAL_DELAY - 1; |
| 440 | | } |
| 441 | | else if (y == m_drb_bottom) |
| 442 | | { |
| 443 | | next_x = 0; |
| 444 | | next_y = 0; |
| 445 | | } |
| 446 | | else |
| 447 | | { |
| 448 | | next_y = y + SCAN_LINES_PER_DATA_ROW - 1; |
| 449 | | } |
| 450 | | } |
| 451 | | |
| 452 | | attotime duration = m_screen->time_until_pos(next_y, next_x); |
| 453 | | |
| 454 | | m_drb_timer->adjust(duration, !state); |
| 455 | | } |
| 456 | | |
| 457 | | |
| 458 | | //------------------------------------------------- |
| 459 | | // update_dma_timer - |
| 460 | | //------------------------------------------------- |
| 461 | | |
| 462 | | inline void crt9007_device::update_dma_timer() |
| 463 | | { |
| 464 | | // TODO |
| 465 | | } |
| 466 | | |
| 467 | | |
| 468 | | //------------------------------------------------- |
| 469 | | // recompute_parameters - |
| 470 | | //------------------------------------------------- |
| 471 | | |
| 472 | | inline void crt9007_device::recompute_parameters() |
| 473 | | { |
| 474 | | // check that necessary registers have been loaded |
| 475 | | if (!HAS_VALID_PARAMETERS) return; |
| 476 | | |
| 477 | | // screen dimensions |
| 478 | | int horiz_pix_total = CHARACTERS_PER_HORIZONTAL_PERIOD * m_hpixels_per_column; |
| 479 | | int vert_pix_total = SCAN_LINES_PER_FRAME; |
| 480 | | |
| 481 | | // refresh rate |
| 482 | | attoseconds_t refresh = HZ_TO_ATTOSECONDS(clock()) * horiz_pix_total * vert_pix_total; |
| 483 | | |
| 484 | | // horizontal sync |
| 485 | | m_hsync_start = 0; |
| 486 | | m_hsync_end = HORIZONTAL_SYNC_WIDTH * m_hpixels_per_column; |
| 487 | | |
| 488 | | // visible line time |
| 489 | | m_vlt_start = HORIZONTAL_DELAY * m_hpixels_per_column; |
| 490 | | m_vlt_end = (HORIZONTAL_DELAY + CHARACTERS_PER_DATA_ROW) * m_hpixels_per_column; |
| 491 | | m_vlt_bottom = VERTICAL_DELAY + (VISIBLE_DATA_ROWS_PER_FRAME * SCAN_LINES_PER_DATA_ROW) - 1; |
| 492 | | |
| 493 | | // data row boundary |
| 494 | | m_drb_bottom = VERTICAL_DELAY + (VISIBLE_DATA_ROWS_PER_FRAME * SCAN_LINES_PER_DATA_ROW) - SCAN_LINES_PER_DATA_ROW; |
| 495 | | |
| 496 | | // vertical sync |
| 497 | | m_vsync_start = 0; |
| 498 | | m_vsync_end = VERTICAL_SYNC_WIDTH; |
| 499 | | |
| 500 | | // visible area |
| 501 | | rectangle visarea; |
| 502 | | |
| 503 | | visarea.min_x = m_hsync_end; |
| 504 | | visarea.max_x = horiz_pix_total - 1; |
| 505 | | |
| 506 | | visarea.min_y = m_vsync_end; |
| 507 | | visarea.max_y = vert_pix_total - 1; |
| 508 | | |
| 509 | | if (LOG) |
| 510 | | { |
| 511 | | logerror("CRT9007 '%s' Screen: %u x %u @ %f Hz\n", tag(), horiz_pix_total, vert_pix_total, 1 / ATTOSECONDS_TO_DOUBLE(refresh)); |
| 512 | | logerror("CRT9007 '%s' Visible Area: (%u, %u) - (%u, %u)\n", tag(), visarea.min_x, visarea.min_y, visarea.max_x, visarea.max_y); |
| 513 | | } |
| 514 | | |
| 515 | | m_screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh); |
| 516 | | |
| 517 | | m_hsync_timer->adjust(m_screen->time_until_pos(0, 0)); |
| 518 | | m_vsync_timer->adjust(m_screen->time_until_pos(0, 0)); |
| 519 | | m_vlt_timer->adjust(m_screen->time_until_pos(0, m_vlt_start), 1); |
| 520 | | m_drb_timer->adjust(m_screen->time_until_pos(0, 0)); |
| 521 | | } |
| 522 | | |
| 523 | | |
| 524 | | //************************************************************************** |
| 525 | | // LIVE DEVICE |
| 526 | | //************************************************************************** |
| 527 | | |
| 528 | | //------------------------------------------------- |
| 529 | | // crt9007_device - constructor |
| 530 | | //------------------------------------------------- |
| 531 | | |
| 532 | | crt9007_device::crt9007_device(running_machine &_machine, const crt9007_device_config &config) |
| 533 | | : device_t(_machine, config), |
| 534 | | device_memory_interface(_machine, config, *this), |
| 535 | | m_config(config) |
| 536 | | { |
| 537 | | for (int i = 0; i < 0x3d; i++) |
| 538 | | m_reg[i] = 0; |
| 539 | | } |
| 540 | | |
| 541 | | |
| 542 | | //------------------------------------------------- |
| 543 | | // device_start - device-specific startup |
| 544 | | //------------------------------------------------- |
| 545 | | |
| 546 | | void crt9007_device::device_start() |
| 547 | | { |
| 548 | | // allocate timers |
| 549 | | m_hsync_timer = timer_alloc(TIMER_HSYNC); |
| 550 | | m_vsync_timer = timer_alloc(TIMER_VSYNC); |
| 551 | | m_vlt_timer = timer_alloc(TIMER_VLT); |
| 552 | | m_curs_timer = timer_alloc(TIMER_CURS); |
| 553 | | m_drb_timer = timer_alloc(TIMER_DRB); |
| 554 | | m_dma_timer = timer_alloc(TIMER_DMA); |
| 555 | | |
| 556 | | // resolve callbacks |
| 557 | | devcb_resolve_write_line(&m_out_int_func, &m_config.out_int_func, this); |
| 558 | | devcb_resolve_write_line(&m_out_dmar_func, &m_config.out_dmar_func, this); |
| 559 | | devcb_resolve_write_line(&m_out_hs_func, &m_config.out_hs_func, this); |
| 560 | | devcb_resolve_write_line(&m_out_vs_func, &m_config.out_vs_func, this); |
| 561 | | devcb_resolve_write_line(&m_out_vlt_func, &m_config.out_vlt_func, this); |
| 562 | | devcb_resolve_write_line(&m_out_curs_func, &m_config.out_curs_func, this); |
| 563 | | devcb_resolve_write_line(&m_out_drb_func, &m_config.out_drb_func, this); |
| 564 | | devcb_resolve_write_line(&m_out_cblank_func, &m_config.out_cblank_func, this); |
| 565 | | devcb_resolve_write_line(&m_out_slg_func, &m_config.out_slg_func, this); |
| 566 | | devcb_resolve_write_line(&m_out_sld_func, &m_config.out_sld_func, this); |
| 567 | | |
| 568 | | // get the screen device |
| 569 | | m_screen = machine->device<screen_device>(m_config.screen_tag); |
| 570 | | assert(m_screen != NULL); |
| 571 | | |
| 572 | | // set horizontal pixels per column |
| 573 | | m_hpixels_per_column = m_config.hpixels_per_column; |
| 574 | | |
| 575 | | // register for state saving |
| 576 | | // state_save_register_device_item(this, 0, ); |
| 577 | | } |
| 578 | | |
| 579 | | |
| 580 | | //------------------------------------------------- |
| 581 | | // device_reset - device-specific reset |
| 582 | | //------------------------------------------------- |
| 583 | | |
| 584 | | void crt9007_device::device_reset() |
| 585 | | { |
| 586 | | m_disp = 0; |
| 587 | | |
| 588 | | // HS = 1 |
| 589 | | devcb_call_write_line(&m_out_hs_func, 1); |
| 590 | | |
| 591 | | // VS = 1 |
| 592 | | devcb_call_write_line(&m_out_vs_func, 1); |
| 593 | | |
| 594 | | // CBLANK = 1 |
| 595 | | devcb_call_write_line(&m_out_cblank_func, 0); |
| 596 | | |
| 597 | | // CURS = 0 |
| 598 | | devcb_call_write_line(&m_out_curs_func, 0); |
| 599 | | |
| 600 | | // VLT = 0 |
| 601 | | devcb_call_write_line(&m_out_vlt_func, 0); |
| 602 | | |
| 603 | | // DRB = 1 |
| 604 | | devcb_call_write_line(&m_out_drb_func, 1); |
| 605 | | |
| 606 | | // INT = 0 |
| 607 | | devcb_call_write_line(&m_out_int_func, CLEAR_LINE); |
| 608 | | |
| 609 | | // 28 (DMAR) = 0 |
| 610 | | devcb_call_write_line(&m_out_dmar_func, CLEAR_LINE); |
| 611 | | |
| 612 | | // 29 (WBEN) = 0 |
| 613 | | |
| 614 | | // 30 (SLG) = 0 |
| 615 | | devcb_call_write_line(&m_out_slg_func, 0); |
| 616 | | |
| 617 | | // 31 (SLD) = 0 |
| 618 | | devcb_call_write_line(&m_out_sld_func, 0); |
| 619 | | |
| 620 | | // 32 (LPSTB) = 0 |
| 621 | | } |
| 622 | | |
| 623 | | |
| 624 | | //------------------------------------------------- |
| 625 | | // device_clock_changed - handle clock change |
| 626 | | //------------------------------------------------- |
| 627 | | |
| 628 | | void crt9007_device::device_clock_changed() |
| 629 | | { |
| 630 | | recompute_parameters(); |
| 631 | | } |
| 632 | | |
| 633 | | |
| 634 | | //------------------------------------------------- |
| 635 | | // device_timer - handle timer events |
| 636 | | //------------------------------------------------- |
| 637 | | |
| 638 | | void crt9007_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 639 | | { |
| 640 | | int x = m_screen->hpos(); |
| 641 | | int y = m_screen->vpos(); |
| 642 | | |
| 643 | | switch (id) |
| 644 | | { |
| 645 | | case TIMER_HSYNC: |
| 646 | | m_hs = param; |
| 647 | | |
| 648 | | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : HS %u\n", tag(), y, x, m_hs); |
| 649 | | |
| 650 | | devcb_call_write_line(&m_out_hs_func, m_hs); |
| 651 | | |
| 652 | | update_cblank_line(); |
| 653 | | |
| 654 | | update_hsync_timer(param); |
| 655 | | break; |
| 656 | | |
| 657 | | case TIMER_VSYNC: |
| 658 | | m_vs = param; |
| 659 | | |
| 660 | | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : VS %u\n", tag(), y, x, m_vs); |
| 661 | | |
| 662 | | devcb_call_write_line(&m_out_vs_func, param); |
| 663 | | |
| 664 | | if (m_vs) |
| 665 | | { |
| 666 | | // reset all other bits except Light Pen Update to logic 0 |
| 667 | | m_status &= STATUS_LIGHT_PEN_UPDATE; |
| 668 | | } |
| 669 | | else |
| 670 | | { |
| 671 | | trigger_interrupt(IE_VERTICAL_RETRACE); |
| 672 | | |
| 673 | | update_cblank_line(); |
| 674 | | } |
| 675 | | |
| 676 | | update_vsync_timer(param); |
| 677 | | break; |
| 678 | | |
| 679 | | case TIMER_VLT: |
| 680 | | m_vlt = param; |
| 681 | | |
| 682 | | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : VLT %u\n", tag(), y, x, m_vlt); |
| 683 | | |
| 684 | | devcb_call_write_line(&m_out_vlt_func, param); |
| 685 | | |
| 686 | | update_vlt_timer(param); |
| 687 | | break; |
| 688 | | |
| 689 | | case TIMER_CURS: |
| 690 | | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : CURS %u\n", tag(), y, x, param); |
| 691 | | |
| 692 | | devcb_call_write_line(&m_out_curs_func, param); |
| 693 | | |
| 694 | | update_curs_timer(param); |
| 695 | | break; |
| 696 | | |
| 697 | | case TIMER_DRB: |
| 698 | | m_drb = param; |
| 699 | | |
| 700 | | if (LOG) logerror("CRT9007 '%s' y %03u x %04u : DRB %u\n", tag(), y, x, m_drb); |
| 701 | | |
| 702 | | devcb_call_write_line(&m_out_drb_func, param); |
| 703 | | |
| 704 | | if (!m_drb && !DMA_DISABLE) |
| 705 | | { |
| 706 | | // start DMA burst sequence |
| 707 | | m_dma_count = CHARACTERS_PER_DATA_ROW; |
| 708 | | m_dma_burst = DMA_BURST_COUNT ? (DMA_BURST_COUNT * 4) : CHARACTERS_PER_DATA_ROW; |
| 709 | | m_dma_delay = DMA_BURST_DELAY; |
| 710 | | m_dmar = 1; |
| 711 | | |
| 712 | | if (LOG) logerror("CRT9007 '%s' DMAR 1\n", tag()); |
| 713 | | devcb_call_write_line(&m_out_dmar_func, ASSERT_LINE); |
| 714 | | } |
| 715 | | |
| 716 | | update_drb_timer(param); |
| 717 | | break; |
| 718 | | |
| 719 | | case TIMER_DMA: |
| 720 | | readbyte(AUXILIARY_ADDRESS_2); |
| 721 | | |
| 722 | | update_dma_timer(); |
| 723 | | break; |
| 724 | | } |
| 725 | | } |
| 726 | | |
| 727 | | |
| 728 | | //------------------------------------------------- |
| 729 | | // read - register read |
| 730 | | //------------------------------------------------- |
| 731 | | |
| 732 | | READ8_MEMBER( crt9007_device::read ) |
| 733 | | { |
| 734 | | UINT8 data = 0; |
| 735 | | |
| 736 | | switch (offset) |
| 737 | | { |
| 738 | | case 0x15: |
| 739 | | if (LOG) logerror("CRT9007 '%s' Start\n", tag()); |
| 740 | | m_disp = 1; |
| 741 | | break; |
| 742 | | |
| 743 | | case 0x16: |
| 744 | | if (LOG) logerror("CRT9007 '%s' Reset\n", tag()); |
| 745 | | device_reset(); |
| 746 | | break; |
| 747 | | |
| 748 | | case 0x38: |
| 749 | | data = VERTICAL_CURSOR; |
| 750 | | break; |
| 751 | | |
| 752 | | case 0x39: |
| 753 | | data = HORIZONTAL_CURSOR; |
| 754 | | break; |
| 755 | | |
| 756 | | case 0x3a: |
| 757 | | data = m_status; |
| 758 | | |
| 759 | | // reset interrupt pending bit |
| 760 | | m_status &= ~STATUS_INTERRUPT_PENDING; |
| 761 | | if (LOG) logerror("CRT9007 '%s' INT 0\n", tag()); |
| 762 | | devcb_call_write_line(&m_out_int_func, CLEAR_LINE); |
| 763 | | break; |
| 764 | | |
| 765 | | case 0x3b: |
| 766 | | data = VERTICAL_LIGHT_PEN; |
| 767 | | break; |
| 768 | | |
| 769 | | case 0x3c: |
| 770 | | data = HORIZONTAL_LIGHT_PEN; |
| 771 | | |
| 772 | | // reset light pen update bit |
| 773 | | m_status &= ~STATUS_LIGHT_PEN_UPDATE; |
| 774 | | break; |
| 775 | | |
| 776 | | default: |
| 777 | | logerror("CRT9007 '%s' Read from Invalid Register: %02x!\n", tag(), offset); |
| 778 | | } |
| 779 | | |
| 780 | | return data; |
| 781 | | } |
| 782 | | |
| 783 | | |
| 784 | | //------------------------------------------------- |
| 785 | | // write - register write |
| 786 | | //------------------------------------------------- |
| 787 | | |
| 788 | | WRITE8_MEMBER( crt9007_device::write ) |
| 789 | | { |
| 790 | | m_reg[offset] = data; |
| 791 | | |
| 792 | | switch (offset) |
| 793 | | { |
| 794 | | case 0x00: |
| 795 | | recompute_parameters(); |
| 796 | | if (LOG) logerror("CRT9007 '%s' Characters per Horizontal Period: %u\n", tag(), CHARACTERS_PER_HORIZONTAL_PERIOD); |
| 797 | | break; |
| 798 | | |
| 799 | | case 0x01: |
| 800 | | recompute_parameters(); |
| 801 | | if (LOG) logerror("CRT9007 '%s' Characters per Data Row: %u\n", tag(), CHARACTERS_PER_DATA_ROW); |
| 802 | | break; |
| 803 | | |
| 804 | | case 0x02: |
| 805 | | recompute_parameters(); |
| 806 | | if (LOG) logerror("CRT9007 '%s' Horizontal Delay: %u\n", tag(), HORIZONTAL_DELAY); |
| 807 | | break; |
| 808 | | |
| 809 | | case 0x03: |
| 810 | | recompute_parameters(); |
| 811 | | if (LOG) logerror("CRT9007 '%s' Horizontal Sync Width: %u\n", tag(), HORIZONTAL_SYNC_WIDTH); |
| 812 | | break; |
| 813 | | |
| 814 | | case 0x04: |
| 815 | | recompute_parameters(); |
| 816 | | if (LOG) logerror("CRT9007 '%s' Vertical Sync Width: %u\n", tag(), VERTICAL_SYNC_WIDTH); |
| 817 | | break; |
| 818 | | |
| 819 | | case 0x05: |
| 820 | | recompute_parameters(); |
| 821 | | if (LOG) logerror("CRT9007 '%s' Vertical Delay: %u\n", tag(), VERTICAL_DELAY); |
| 822 | | break; |
| 823 | | |
| 824 | | case 0x06: |
| 825 | | recompute_parameters(); |
| 826 | | if (LOG) |
| 827 | | { |
| 828 | | logerror("CRT9007 '%s' Pin Configuration: %u\n", tag(), PIN_CONFIGURATION); |
| 829 | | logerror("CRT9007 '%s' Cursor Skew: %u\n", tag(), CURSOR_SKEW); |
| 830 | | logerror("CRT9007 '%s' Blank Skew: %u\n", tag(), BLANK_SKEW); |
| 831 | | } |
| 832 | | break; |
| 833 | | |
| 834 | | case 0x07: |
| 835 | | recompute_parameters(); |
| 836 | | if (LOG) logerror("CRT9007 '%s' Visible Data Rows per Frame: %u\n", tag(), VISIBLE_DATA_ROWS_PER_FRAME); |
| 837 | | break; |
| 838 | | |
| 839 | | case 0x08: |
| 840 | | recompute_parameters(); |
| 841 | | if (LOG) logerror("CRT9007 '%s' Scan Lines per Data Row: %u\n", tag(), SCAN_LINES_PER_DATA_ROW); |
| 842 | | break; |
| 843 | | |
| 844 | | case 0x09: |
| 845 | | recompute_parameters(); |
| 846 | | if (LOG) logerror("CRT9007 '%s' Scan Lines per Frame: %u\n", tag(), SCAN_LINES_PER_FRAME); |
| 847 | | break; |
| 848 | | |
| 849 | | case 0x0a: |
| 850 | | if (LOG) |
| 851 | | { |
| 852 | | logerror("CRT9007 '%s' DMA Burst Count: %u\n", tag(), DMA_BURST_COUNT); |
| 853 | | logerror("CRT9007 '%s' DMA Burst Delay: %u\n", tag(), DMA_BURST_DELAY); |
| 854 | | logerror("CRT9007 '%s' DMA Disable: %u\n", tag(), DMA_DISABLE); |
| 855 | | } |
| 856 | | break; |
| 857 | | |
| 858 | | case 0x0b: |
| 859 | | if (LOG) |
| 860 | | { |
| 861 | | logerror("CRT9007 '%s' %s Height Cursor\n", tag(), SINGLE_HEIGHT_CURSOR ? "Single" : "Double"); |
| 862 | | logerror("CRT9007 '%s' Operation Mode: %u\n", tag(), OPERATION_MODE); |
| 863 | | logerror("CRT9007 '%s' Interlace Mode: %u\n", tag(), INTERLACE_MODE); |
| 864 | | logerror("CRT9007 '%s' %s Mechanism\n", tag(), PAGE_BLANK ? "Page Blank" : "Smooth Scroll"); |
| 865 | | } |
| 866 | | break; |
| 867 | | |
| 868 | | case 0x0c: |
| 869 | | break; |
| 870 | | |
| 871 | | case 0x0d: |
| 872 | | if (LOG) |
| 873 | | { |
| 874 | | logerror("CRT9007 '%s' Table Start Register: %04x\n", tag(), TABLE_START); |
| 875 | | logerror("CRT9007 '%s' Address Mode: %u\n", tag(), ADDRESS_MODE); |
| 876 | | } |
| 877 | | break; |
| 878 | | |
| 879 | | case 0x0e: |
| 880 | | break; |
| 881 | | |
| 882 | | case 0x0f: |
| 883 | | if (LOG) |
| 884 | | { |
| 885 | | logerror("CRT9007 '%s' Auxialiary Address Register 1: %04x\n", tag(), AUXILIARY_ADDRESS_1); |
| 886 | | logerror("CRT9007 '%s' Row Attributes: %u\n", tag(), ROW_ATTRIBUTES_1); |
| 887 | | } |
| 888 | | break; |
| 889 | | |
| 890 | | case 0x10: |
| 891 | | if (LOG) logerror("CRT9007 '%s' Sequential Break Register 1: %u\n", tag(), SEQUENTIAL_BREAK_1); |
| 892 | | break; |
| 893 | | |
| 894 | | case 0x11: |
| 895 | | if (LOG) logerror("CRT9007 '%s' Data Row Start Register: %u\n", tag(), DATA_ROW_START); |
| 896 | | break; |
| 897 | | |
| 898 | | case 0x12: |
| 899 | | if (LOG) logerror("CRT9007 '%s' Data Row End/Sequential Break Register 2: %u\n", tag(), SEQUENTIAL_BREAK_2); |
| 900 | | break; |
| 901 | | |
| 902 | | case 0x13: |
| 903 | | break; |
| 904 | | |
| 905 | | case 0x14: |
| 906 | | if (LOG) |
| 907 | | { |
| 908 | | logerror("CRT9007 '%s' Auxiliary Address Register 2: %04x\n", tag(), AUXILIARY_ADDRESS_2); |
| 909 | | logerror("CRT9007 '%s' Row Attributes: %u\n", tag(), ROW_ATTRIBUTES_2); |
| 910 | | } |
| 911 | | break; |
| 912 | | |
| 913 | | case 0x15: |
| 914 | | if (LOG) logerror("CRT9007 '%s' Start\n", tag()); |
| 915 | | m_disp = 1; |
| 916 | | break; |
| 917 | | |
| 918 | | case 0x16: |
| 919 | | if (LOG) logerror("CRT9007 '%s' Reset\n", tag()); |
| 920 | | device_reset(); |
| 921 | | break; |
| 922 | | |
| 923 | | case 0x17: |
| 924 | | if (LOG) |
| 925 | | { |
| 926 | | logerror("CRT9007 '%s' Smooth Scroll Offset: %u\n", tag(), SMOOTH_SCROLL_OFFSET); |
| 927 | | logerror("CRT9007 '%s' Smooth Scroll Offset Overflow: %u\n", tag(), SMOOTH_SCROLL_OFFSET_OVERFLOW); |
| 928 | | } |
| 929 | | break; |
| 930 | | |
| 931 | | case 0x18: |
| 932 | | if (LOG) logerror("CRT9007 '%s' Vertical Cursor Register: %u\n", tag(), VERTICAL_CURSOR); |
| 933 | | break; |
| 934 | | |
| 935 | | case 0x19: |
| 936 | | if (LOG) logerror("CRT9007 '%s' Horizontal Cursor Register: %u\n", tag(), HORIZONTAL_CURSOR); |
| 937 | | break; |
| 938 | | |
| 939 | | case 0x1a: |
| 940 | | if (LOG) |
| 941 | | { |
| 942 | | logerror("CRT9007 '%s' Frame Timer: %u\n", tag(), FRAME_TIMER); |
| 943 | | logerror("CRT9007 '%s' Light Pen Interrupt: %u\n", tag(), LIGHT_PEN_INTERRUPT); |
| 944 | | logerror("CRT9007 '%s' Vertical Retrace Interrupt: %u\n", tag(), VERTICAL_RETRACE_INTERRUPT); |
| 945 | | } |
| 946 | | break; |
| 947 | | |
| 948 | | default: |
| 949 | | logerror("CRT9007 '%s' Write to Invalid Register: %02x!\n", tag(), offset); |
| 950 | | } |
| 951 | | } |
| 952 | | |
| 953 | | |
| 954 | | //------------------------------------------------- |
| 955 | | // ack_w - DMA acknowledge |
| 956 | | //------------------------------------------------- |
| 957 | | |
| 958 | | WRITE_LINE_MEMBER( crt9007_device::ack_w ) |
| 959 | | { |
| 960 | | if (LOG) logerror("CRT9007 '%s' ACK: %u\n", tag(), state); |
| 961 | | |
| 962 | | if (m_dmar && !m_ack && state) |
| 963 | | { |
| 964 | | // start DMA transfer |
| 965 | | m_dma_timer->adjust(attotime::from_hz(clock())); |
| 966 | | } |
| 967 | | |
| 968 | | m_ack = state; |
| 969 | | } |
| 970 | | |
| 971 | | |
| 972 | | //------------------------------------------------- |
| 973 | | // lpstb_w - light pen strobe |
| 974 | | //------------------------------------------------- |
| 975 | | |
| 976 | | WRITE_LINE_MEMBER( crt9007_device::lpstb_w ) |
| 977 | | { |
| 978 | | if (LOG) logerror("CRT9007 '%s' LPSTB: %u\n", tag(), state); |
| 979 | | |
| 980 | | if (!m_lpstb && state) |
| 981 | | { |
| 982 | | // TODO latch current row/column position |
| 983 | | } |
| 984 | | |
| 985 | | m_lpstb = state; |
| 986 | | } |
| 987 | | |
| 988 | | |
| 989 | | //------------------------------------------------- |
| 990 | | // vlt_r - |
| 991 | | //------------------------------------------------- |
| 992 | | |
| 993 | | READ_LINE_MEMBER( crt9007_device::vlt_r ) |
| 994 | | { |
| 995 | | return m_vlt; |
| 996 | | } |
| 997 | | |
| 998 | | |
| 999 | | //------------------------------------------------- |
| 1000 | | // wben_r - |
| 1001 | | //------------------------------------------------- |
| 1002 | | |
| 1003 | | READ_LINE_MEMBER( crt9007_device::wben_r ) |
| 1004 | | { |
| 1005 | | return m_wben; |
| 1006 | | } |
| 1007 | | |
| 1008 | | |
| 1009 | | //------------------------------------------------- |
| 1010 | | // set_hpixels_per_column - |
| 1011 | | //------------------------------------------------- |
| 1012 | | |
| 1013 | | void crt9007_device::set_hpixels_per_column(int hpixels_per_column) |
| 1014 | | { |
| 1015 | | m_hpixels_per_column = hpixels_per_column; |
| 1016 | | recompute_parameters(); |
| 1017 | | } |
src/mess/video/crt9007.h
| r10968 | r10969 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | SMC CRT9007 CRT Video Processor and Controller (VPAC) emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | ********************************************************************** |
| 9 | | _____ _____ |
| 10 | | VA2 1 |* \_/ | 40 GND |
| 11 | | VA10 2 | | 39 VA9 |
| 12 | | VA3 3 | | 38 VA1 |
| 13 | | VA11 4 | | 37 VA8 |
| 14 | | VA12 5 | | 36 VA0 |
| 15 | | VA4 6 | | 35 CBLANK |
| 16 | | VA13 7 | | 34 CURS |
| 17 | | VA5 8 | | 33 ACK/_TSC |
| 18 | | VA6 9 | | 32 _CSYNC/LPSTB |
| 19 | | VA7 10 | CRT9007 | 31 SLD/SL0 |
| 20 | | VLT 11 | | 30 _SLG/SL1 |
| 21 | | _VS 12 | | 29 WBEN/SL2/_CSYNC |
| 22 | | _HS 13 | | 28 DMAR/SL3/VBLANK |
| 23 | | _CCLK 14 | | 27 INT |
| 24 | | _DRB 15 | | 26 _RST |
| 25 | | VD7 16 | | 25 _CS |
| 26 | | VD6 17 | | 24 VD0 |
| 27 | | VD5 18 | | 23 VD1 |
| 28 | | VD4 19 | | 22 VD2 |
| 29 | | VD3 20 |_____________| 21 +5V |
| 30 | | |
| 31 | | **********************************************************************/ |
| 32 | | |
| 33 | | #pragma once |
| 34 | | |
| 35 | | #ifndef __CRT9007__ |
| 36 | | #define __CRT9007__ |
| 37 | | |
| 38 | | #include "emu.h" |
| 39 | | |
| 40 | | |
| 41 | | |
| 42 | | //************************************************************************** |
| 43 | | // MACROS / CONSTANTS |
| 44 | | //************************************************************************** |
| 45 | | |
| 46 | | |
| 47 | | |
| 48 | | |
| 49 | | //************************************************************************** |
| 50 | | // INTERFACE CONFIGURATION MACROS |
| 51 | | //************************************************************************** |
| 52 | | |
| 53 | | #define MCFG_CRT9007_ADD(_tag, _clock, _config, _map) \ |
| 54 | | MCFG_DEVICE_ADD(_tag, CRT9007, _clock) \ |
| 55 | | MCFG_DEVICE_CONFIG(_config) \ |
| 56 | | MCFG_DEVICE_ADDRESS_MAP(AS_0, _map) |
| 57 | | |
| 58 | | |
| 59 | | #define CRT9007_INTERFACE(name) \ |
| 60 | | const crt9007_interface (name) = |
| 61 | | |
| 62 | | |
| 63 | | |
| 64 | | //************************************************************************** |
| 65 | | // TYPE DEFINITIONS |
| 66 | | //************************************************************************** |
| 67 | | |
| 68 | | |
| 69 | | // ======================> crt9007_interface |
| 70 | | |
| 71 | | struct crt9007_interface |
| 72 | | { |
| 73 | | const char *screen_tag; /* screen we are acting on */ |
| 74 | | int hpixels_per_column; /* number of pixels per video memory address */ |
| 75 | | |
| 76 | | devcb_write_line out_int_func; |
| 77 | | devcb_write_line out_dmar_func; |
| 78 | | |
| 79 | | devcb_write_line out_vs_func; |
| 80 | | devcb_write_line out_hs_func; |
| 81 | | |
| 82 | | devcb_write_line out_vlt_func; |
| 83 | | devcb_write_line out_curs_func; |
| 84 | | devcb_write_line out_drb_func; |
| 85 | | devcb_write_line out_cblank_func; |
| 86 | | |
| 87 | | devcb_write_line out_slg_func; |
| 88 | | devcb_write_line out_sld_func; |
| 89 | | }; |
| 90 | | |
| 91 | | |
| 92 | | |
| 93 | | // ======================> crt9007_device_config |
| 94 | | |
| 95 | | class crt9007_device_config : public device_config, |
| 96 | | public device_config_memory_interface, |
| 97 | | public crt9007_interface |
| 98 | | { |
| 99 | | friend class crt9007_device; |
| 100 | | |
| 101 | | // construction/destruction |
| 102 | | crt9007_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 103 | | |
| 104 | | public: |
| 105 | | // allocators |
| 106 | | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 107 | | virtual device_t *alloc_device(running_machine &machine) const; |
| 108 | | |
| 109 | | protected: |
| 110 | | // device_config overrides |
| 111 | | virtual void device_config_complete(); |
| 112 | | |
| 113 | | // device_config_memory_interface overrides |
| 114 | | virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const; |
| 115 | | |
| 116 | | // address space configurations |
| 117 | | const address_space_config m_space_config; |
| 118 | | }; |
| 119 | | |
| 120 | | |
| 121 | | |
| 122 | | // ======================> crt9007_device |
| 123 | | |
| 124 | | class crt9007_device : public device_t, |
| 125 | | public device_memory_interface |
| 126 | | { |
| 127 | | friend class crt9007_device_config; |
| 128 | | |
| 129 | | // construction/destruction |
| 130 | | crt9007_device(running_machine &_machine, const crt9007_device_config &_config); |
| 131 | | |
| 132 | | public: |
| 133 | | DECLARE_READ8_MEMBER( read ); |
| 134 | | DECLARE_WRITE8_MEMBER( write ); |
| 135 | | DECLARE_WRITE_LINE_MEMBER( ack_w ); |
| 136 | | DECLARE_WRITE_LINE_MEMBER( lpstb_w ); |
| 137 | | DECLARE_READ_LINE_MEMBER( vlt_r ); |
| 138 | | DECLARE_READ_LINE_MEMBER( wben_r ); |
| 139 | | |
| 140 | | void set_hpixels_per_column(int hpixels_per_column); |
| 141 | | |
| 142 | | protected: |
| 143 | | // device-level overrides |
| 144 | | virtual void device_start(); |
| 145 | | virtual void device_reset(); |
| 146 | | virtual void device_clock_changed(); |
| 147 | | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 148 | | |
| 149 | | private: |
| 150 | | static const device_timer_id TIMER_HSYNC = 0; |
| 151 | | static const device_timer_id TIMER_VSYNC = 1; |
| 152 | | static const device_timer_id TIMER_VLT = 2; |
| 153 | | static const device_timer_id TIMER_CURS = 3; |
| 154 | | static const device_timer_id TIMER_DRB = 4; |
| 155 | | static const device_timer_id TIMER_DMA = 5; |
| 156 | | |
| 157 | | inline UINT8 readbyte(offs_t address); |
| 158 | | |
| 159 | | inline void trigger_interrupt(int line); |
| 160 | | inline void update_cblank_line(); |
| 161 | | inline void update_hsync_timer(int state); |
| 162 | | inline void update_vsync_timer(int state); |
| 163 | | inline void update_vlt_timer(int state); |
| 164 | | inline void update_curs_timer(int state); |
| 165 | | inline void update_drb_timer(int state); |
| 166 | | inline void update_dma_timer(); |
| 167 | | |
| 168 | | inline void recompute_parameters(); |
| 169 | | |
| 170 | | devcb_resolved_write_line m_out_int_func; |
| 171 | | devcb_resolved_write_line m_out_dmar_func; |
| 172 | | devcb_resolved_write_line m_out_hs_func; |
| 173 | | devcb_resolved_write_line m_out_vs_func; |
| 174 | | devcb_resolved_write_line m_out_vlt_func; |
| 175 | | devcb_resolved_write_line m_out_curs_func; |
| 176 | | devcb_resolved_write_line m_out_drb_func; |
| 177 | | devcb_resolved_write_line m_out_cblank_func; |
| 178 | | devcb_resolved_write_line m_out_slg_func; |
| 179 | | devcb_resolved_write_line m_out_sld_func; |
| 180 | | |
| 181 | | screen_device *m_screen; |
| 182 | | |
| 183 | | // registers |
| 184 | | UINT8 m_reg[0x3d]; |
| 185 | | UINT8 m_status; |
| 186 | | |
| 187 | | int m_disp; |
| 188 | | int m_hpixels_per_column; |
| 189 | | |
| 190 | | // runtime variables, do not state save |
| 191 | | int m_vsync_start; |
| 192 | | int m_vsync_end; |
| 193 | | int m_hsync_start; |
| 194 | | int m_hsync_end; |
| 195 | | int m_vlt_start; |
| 196 | | int m_vlt_end; |
| 197 | | int m_vlt_bottom; |
| 198 | | int m_drb_bottom; |
| 199 | | int m_hs; |
| 200 | | int m_vs; |
| 201 | | int m_cblank; |
| 202 | | int m_vlt; |
| 203 | | int m_drb; |
| 204 | | int m_wben; |
| 205 | | int m_slg; |
| 206 | | int m_sld; |
| 207 | | int m_lpstb; |
| 208 | | |
| 209 | | // DMA |
| 210 | | int m_dmar; |
| 211 | | int m_ack; |
| 212 | | int m_dma_count; |
| 213 | | int m_dma_burst; |
| 214 | | int m_dma_delay; |
| 215 | | |
| 216 | | // timers |
| 217 | | emu_timer *m_vsync_timer; |
| 218 | | emu_timer *m_hsync_timer; |
| 219 | | emu_timer *m_vlt_timer; |
| 220 | | emu_timer *m_curs_timer; |
| 221 | | emu_timer *m_drb_timer; |
| 222 | | emu_timer *m_dma_timer; |
| 223 | | |
| 224 | | const crt9007_device_config &m_config; |
| 225 | | }; |
| 226 | | |
| 227 | | |
| 228 | | // device type definition |
| 229 | | extern const device_type CRT9007; |
| 230 | | |
| 231 | | |
| 232 | | |
| 233 | | #endif |
src/mess/video/crt9212.c
| r10968 | r10969 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | SMC CRT9212 Double Row Buffer (DRB) emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | **********************************************************************/ |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "crt9212.h" |
| 12 | | |
| 13 | | |
| 14 | | |
| 15 | | //************************************************************************** |
| 16 | | // MACROS / CONSTANTS |
| 17 | | //************************************************************************** |
| 18 | | |
| 19 | | #define LOG 1 |
| 20 | | |
| 21 | | |
| 22 | | #define REN \ |
| 23 | | devcb_call_read_line(&m_in_ren_func) |
| 24 | | |
| 25 | | #define WEN \ |
| 26 | | devcb_call_read_line(&m_in_wen_func) |
| 27 | | |
| 28 | | #define WEN2 \ |
| 29 | | devcb_call_read_line(&m_in_wen2_func) |
| 30 | | |
| 31 | | #define ROF(_state) \ |
| 32 | | devcb_call_write_line(&m_out_rof_func, _state); |
| 33 | | |
| 34 | | #define WOF(_state) \ |
| 35 | | devcb_call_write_line(&m_out_wof_func, _state); |
| 36 | | |
| 37 | | |
| 38 | | |
| 39 | | //************************************************************************** |
| 40 | | // GLOBAL VARIABLES |
| 41 | | //************************************************************************** |
| 42 | | |
| 43 | | // devices |
| 44 | | const device_type CRT9212 = crt9212_device_config::static_alloc_device_config; |
| 45 | | |
| 46 | | |
| 47 | | |
| 48 | | //************************************************************************** |
| 49 | | // DEVICE CONFIGURATION |
| 50 | | //************************************************************************** |
| 51 | | |
| 52 | | //------------------------------------------------- |
| 53 | | // crt9212_device_config - constructor |
| 54 | | //------------------------------------------------- |
| 55 | | |
| 56 | | crt9212_device_config::crt9212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 57 | | : device_config(mconfig, static_alloc_device_config, "SMC CRT9212", tag, owner, clock) |
| 58 | | { |
| 59 | | } |
| 60 | | |
| 61 | | |
| 62 | | //------------------------------------------------- |
| 63 | | // static_alloc_device_config - allocate a new |
| 64 | | // configuration object |
| 65 | | //------------------------------------------------- |
| 66 | | |
| 67 | | device_config *crt9212_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 68 | | { |
| 69 | | return global_alloc(crt9212_device_config(mconfig, tag, owner, clock)); |
| 70 | | } |
| 71 | | |
| 72 | | |
| 73 | | //------------------------------------------------- |
| 74 | | // alloc_device - allocate a new device object |
| 75 | | //------------------------------------------------- |
| 76 | | |
| 77 | | device_t *crt9212_device_config::alloc_device(running_machine &machine) const |
| 78 | | { |
| 79 | | return auto_alloc(&machine, crt9212_device(machine, *this)); |
| 80 | | } |
| 81 | | |
| 82 | | |
| 83 | | //------------------------------------------------- |
| 84 | | // device_config_complete - perform any |
| 85 | | // operations now that the configuration is |
| 86 | | // complete |
| 87 | | //------------------------------------------------- |
| 88 | | |
| 89 | | void crt9212_device_config::device_config_complete() |
| 90 | | { |
| 91 | | // inherit a copy of the static data |
| 92 | | const crt9212_interface *intf = reinterpret_cast<const crt9212_interface *>(static_config()); |
| 93 | | if (intf != NULL) |
| 94 | | *static_cast<crt9212_interface *>(this) = *intf; |
| 95 | | |
| 96 | | // or initialize to defaults if none provided |
| 97 | | else |
| 98 | | { |
| 99 | | memset(&out_rof_func, 0, sizeof(out_rof_func)); |
| 100 | | memset(&out_wof_func, 0, sizeof(out_wof_func)); |
| 101 | | memset(&in_ren_func, 0, sizeof(in_ren_func)); |
| 102 | | memset(&in_wen_func, 0, sizeof(in_wen_func)); |
| 103 | | memset(&in_wen2_func, 0, sizeof(in_wen2_func)); |
| 104 | | } |
| 105 | | } |
| 106 | | |
| 107 | | |
| 108 | | |
| 109 | | //************************************************************************** |
| 110 | | // INLINE HELPERS |
| 111 | | //************************************************************************** |
| 112 | | |
| 113 | | |
| 114 | | //************************************************************************** |
| 115 | | // LIVE DEVICE |
| 116 | | //************************************************************************** |
| 117 | | |
| 118 | | //------------------------------------------------- |
| 119 | | // crt9212_device - constructor |
| 120 | | //------------------------------------------------- |
| 121 | | |
| 122 | | crt9212_device::crt9212_device(running_machine &_machine, const crt9212_device_config &config) |
| 123 | | : device_t(_machine, config), |
| 124 | | m_config(config) |
| 125 | | { |
| 126 | | } |
| 127 | | |
| 128 | | |
| 129 | | //------------------------------------------------- |
| 130 | | // device_start - device-specific startup |
| 131 | | //------------------------------------------------- |
| 132 | | |
| 133 | | void crt9212_device::device_start() |
| 134 | | { |
| 135 | | // resolve callbacks |
| 136 | | devcb_resolve_write_line(&m_out_rof_func, &m_config.out_rof_func, this); |
| 137 | | devcb_resolve_write_line(&m_out_wof_func, &m_config.out_wof_func, this); |
| 138 | | devcb_resolve_read_line(&m_in_ren_func, &m_config.in_ren_func, this); |
| 139 | | devcb_resolve_read_line(&m_in_wen_func, &m_config.in_wen_func, this); |
| 140 | | devcb_resolve_read_line(&m_in_wen2_func, &m_config.in_wen2_func, this); |
| 141 | | |
| 142 | | // register for state saving |
| 143 | | save_item(NAME(m_input)); |
| 144 | | save_item(NAME(m_output)); |
| 145 | | save_item(NAME(m_buffer)); |
| 146 | | save_item(NAME(m_rac)); |
| 147 | | save_item(NAME(m_wac)); |
| 148 | | save_item(NAME(m_tog)); |
| 149 | | save_item(NAME(m_clrcnt)); |
| 150 | | save_item(NAME(m_rclk)); |
| 151 | | save_item(NAME(m_wclk)); |
| 152 | | } |
| 153 | | |
| 154 | | |
| 155 | | //------------------------------------------------- |
| 156 | | // read - buffer read |
| 157 | | //------------------------------------------------- |
| 158 | | |
| 159 | | READ8_MEMBER( crt9212_device::read ) |
| 160 | | { |
| 161 | | return m_output; |
| 162 | | } |
| 163 | | |
| 164 | | |
| 165 | | //------------------------------------------------- |
| 166 | | // write - buffer write |
| 167 | | //------------------------------------------------- |
| 168 | | |
| 169 | | WRITE8_MEMBER( crt9212_device::write ) |
| 170 | | { |
| 171 | | m_input = data; |
| 172 | | } |
| 173 | | |
| 174 | | |
| 175 | | //------------------------------------------------- |
| 176 | | // clrcnt_w - clear address counters |
| 177 | | //------------------------------------------------- |
| 178 | | |
| 179 | | WRITE_LINE_MEMBER( crt9212_device::clrcnt_w ) |
| 180 | | { |
| 181 | | m_clrcnt = state; |
| 182 | | } |
| 183 | | |
| 184 | | |
| 185 | | //------------------------------------------------- |
| 186 | | // tog_w - toggle buffer |
| 187 | | //------------------------------------------------- |
| 188 | | |
| 189 | | WRITE_LINE_MEMBER( crt9212_device::tog_w ) |
| 190 | | { |
| 191 | | m_tog = state; |
| 192 | | } |
| 193 | | |
| 194 | | |
| 195 | | //------------------------------------------------- |
| 196 | | // rclk_w - read clock |
| 197 | | //------------------------------------------------- |
| 198 | | |
| 199 | | WRITE_LINE_MEMBER( crt9212_device::rclk_w ) |
| 200 | | { |
| 201 | | if (m_rclk && !state) |
| 202 | | { |
| 203 | | if (!m_clrcnt) |
| 204 | | { |
| 205 | | if (!m_tog) |
| 206 | | { |
| 207 | | // switch buffer |
| 208 | | m_buffer = !m_buffer; |
| 209 | | |
| 210 | | // clear write address counter |
| 211 | | m_wac = 0; |
| 212 | | WOF(0); |
| 213 | | } |
| 214 | | else |
| 215 | | { |
| 216 | | // clear read address counter |
| 217 | | m_rac = 0; |
| 218 | | ROF(0); |
| 219 | | } |
| 220 | | } |
| 221 | | else |
| 222 | | { |
| 223 | | if (REN && (m_rac < CRT9212_RAM_SIZE)) |
| 224 | | { |
| 225 | | // |
| 226 | | m_output = m_ram[m_rac][!m_buffer]; |
| 227 | | |
| 228 | | // increment read address counter |
| 229 | | m_rac++; |
| 230 | | |
| 231 | | if (m_rac == CRT9212_RAM_SIZE) |
| 232 | | { |
| 233 | | // set read overflow |
| 234 | | ROF(1); |
| 235 | | } |
| 236 | | } |
| 237 | | } |
| 238 | | } |
| 239 | | |
| 240 | | m_rclk = state; |
| 241 | | } |
| 242 | | |
| 243 | | |
| 244 | | //------------------------------------------------- |
| 245 | | // wclk_w - write clock |
| 246 | | //------------------------------------------------- |
| 247 | | |
| 248 | | WRITE_LINE_MEMBER( crt9212_device::wclk_w ) |
| 249 | | { |
| 250 | | if (!m_rclk && state) |
| 251 | | { |
| 252 | | if (WEN && WEN2 && (m_wac < CRT9212_RAM_SIZE)) |
| 253 | | { |
| 254 | | // |
| 255 | | m_ram[m_rac][m_buffer] = m_input; |
| 256 | | |
| 257 | | // increment read address counter |
| 258 | | m_wac++; |
| 259 | | |
| 260 | | if (m_wac == CRT9212_RAM_SIZE) |
| 261 | | { |
| 262 | | // set write overflow |
| 263 | | WOF(1); |
| 264 | | } |
| 265 | | } |
| 266 | | } |
| 267 | | |
| 268 | | m_wclk = state; |
| 269 | | } |
src/mess/video/crt9021.c
| r10968 | r10969 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | SMC CRT9021 Video Attributes Controller (VAC) emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | **********************************************************************/ |
| 9 | | |
| 10 | | /* |
| 11 | | |
| 12 | | TODO: |
| 13 | | |
| 14 | | - attributes |
| 15 | | - reverse video |
| 16 | | - character blank |
| 17 | | - character blink |
| 18 | | - underline |
| 19 | | - full/half intensity |
| 20 | | - operation modes |
| 21 | | - wide graphics |
| 22 | | - thin graphics |
| 23 | | - character mode w/o underline |
| 24 | | - character mode w/underline |
| 25 | | - double height characters |
| 26 | | - double width characters |
| 27 | | - parallel scan line |
| 28 | | - serial scan line |
| 29 | | - cursor |
| 30 | | - underline |
| 31 | | - blinking underline |
| 32 | | - reverse video |
| 33 | | - blinking reverse video |
| 34 | | - programmable character blink rate (75/25 duty) |
| 35 | | - programmable cursor blink rate (50/50 duty) |
| 36 | | - data/attribute latches |
| 37 | | |
| 38 | | */ |
| 39 | | |
| 40 | | #include "emu.h" |
| 41 | | #include "crt9021.h" |
| 42 | | |
| 43 | | |
| 44 | | |
| 45 | | //************************************************************************** |
| 46 | | // MACROS / CONSTANTS |
| 47 | | //************************************************************************** |
| 48 | | |
| 49 | | #define LOG 1 |
| 50 | | |
| 51 | | |
| 52 | | // attributes |
| 53 | | enum |
| 54 | | { |
| 55 | | ATTRIBUTE_REVID = 0x80, |
| 56 | | ATTRIBUTE_INT = 0x40, |
| 57 | | ATTRIBUTE_BLINK = 0x20, |
| 58 | | ATTRIBUTE_MS1 = 0x10, |
| 59 | | ATTRIBUTE_MS0 = 0x08, |
| 60 | | ATTRIBUTE_CHABL = 0x04, |
| 61 | | ATTRIBUTE_BKC = 0x02, |
| 62 | | ATTRIBUTE_BLC = 0x01 |
| 63 | | }; |
| 64 | | |
| 65 | | |
| 66 | | //************************************************************************** |
| 67 | | // GLOBAL VARIABLES |
| 68 | | //************************************************************************** |
| 69 | | |
| 70 | | // devices |
| 71 | | const device_type CRT9021 = crt9021_device_config::static_alloc_device_config; |
| 72 | | |
| 73 | | |
| 74 | | |
| 75 | | //************************************************************************** |
| 76 | | // DEVICE CONFIGURATION |
| 77 | | //************************************************************************** |
| 78 | | |
| 79 | | //------------------------------------------------- |
| 80 | | // crt9021_device_config - constructor |
| 81 | | //------------------------------------------------- |
| 82 | | |
| 83 | | crt9021_device_config::crt9021_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 84 | | : device_config(mconfig, static_alloc_device_config, "SMC CRT9021", tag, owner, clock) |
| 85 | | { |
| 86 | | } |
| 87 | | |
| 88 | | |
| 89 | | //------------------------------------------------- |
| 90 | | // static_alloc_device_config - allocate a new |
| 91 | | // configuration object |
| 92 | | //------------------------------------------------- |
| 93 | | |
| 94 | | device_config *crt9021_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 95 | | { |
| 96 | | return global_alloc(crt9021_device_config(mconfig, tag, owner, clock)); |
| 97 | | } |
| 98 | | |
| 99 | | |
| 100 | | //------------------------------------------------- |
| 101 | | // alloc_device - allocate a new device object |
| 102 | | //------------------------------------------------- |
| 103 | | |
| 104 | | device_t *crt9021_device_config::alloc_device(running_machine &machine) const |
| 105 | | { |
| 106 | | return auto_alloc(&machine, crt9021_device(machine, *this)); |
| 107 | | } |
| 108 | | |
| 109 | | |
| 110 | | //------------------------------------------------- |
| 111 | | // device_config_complete - perform any |
| 112 | | // operations now that the configuration is |
| 113 | | // complete |
| 114 | | //------------------------------------------------- |
| 115 | | |
| 116 | | void crt9021_device_config::device_config_complete() |
| 117 | | { |
| 118 | | // inherit a copy of the static data |
| 119 | | const crt9021_interface *intf = reinterpret_cast<const crt9021_interface *>(static_config()); |
| 120 | | if (intf != NULL) |
| 121 | | *static_cast<crt9021_interface *>(this) = *intf; |
| 122 | | |
| 123 | | // or initialize to defaults if none provided |
| 124 | | else |
| 125 | | { |
| 126 | | memset(&in_data_func, 0, sizeof(in_data_func)); |
| 127 | | memset(&in_attr_func, 0, sizeof(in_attr_func)); |
| 128 | | memset(&in_atten_func, 0, sizeof(in_atten_func)); |
| 129 | | } |
| 130 | | } |
| 131 | | |
| 132 | | |
| 133 | | |
| 134 | | //************************************************************************** |
| 135 | | // INLINE HELPERS |
| 136 | | //************************************************************************** |
| 137 | | |
| 138 | | |
| 139 | | |
| 140 | | //************************************************************************** |
| 141 | | // LIVE DEVICE |
| 142 | | //************************************************************************** |
| 143 | | |
| 144 | | //------------------------------------------------- |
| 145 | | // crt9021_device - constructor |
| 146 | | //------------------------------------------------- |
| 147 | | |
| 148 | | crt9021_device::crt9021_device(running_machine &_machine, const crt9021_device_config &config) |
| 149 | | : device_t(_machine, config), |
| 150 | | m_config(config) |
| 151 | | { |
| 152 | | } |
| 153 | | |
| 154 | | |
| 155 | | //------------------------------------------------- |
| 156 | | // device_start - device-specific startup |
| 157 | | //------------------------------------------------- |
| 158 | | |
| 159 | | void crt9021_device::device_start() |
| 160 | | { |
| 161 | | // allocate timers |
| 162 | | |
| 163 | | // resolve callbacks |
| 164 | | devcb_resolve_read8(&m_in_data_func, &m_config.in_data_func, this); |
| 165 | | devcb_resolve_read8(&m_in_attr_func, &m_config.in_attr_func, this); |
| 166 | | devcb_resolve_read_line(&m_in_atten_func, &m_config.in_atten_func, this); |
| 167 | | |
| 168 | | // get the screen device |
| 169 | | m_screen = machine->device<screen_device>(m_config.screen_tag); |
| 170 | | assert(m_screen != NULL); |
| 171 | | |
| 172 | | // register for state saving |
| 173 | | save_item(NAME(m_slg)); |
| 174 | | save_item(NAME(m_sld)); |
| 175 | | save_item(NAME(m_cursor)); |
| 176 | | save_item(NAME(m_retbl)); |
| 177 | | save_item(NAME(m_vsync)); |
| 178 | | } |
| 179 | | |
| 180 | | |
| 181 | | //------------------------------------------------- |
| 182 | | // device_clock_changed - handle clock change |
| 183 | | //------------------------------------------------- |
| 184 | | |
| 185 | | void crt9021_device::device_clock_changed() |
| 186 | | { |
| 187 | | } |
| 188 | | |
| 189 | | |
| 190 | | //------------------------------------------------- |
| 191 | | // device_timer - handle timer events |
| 192 | | //------------------------------------------------- |
| 193 | | |
| 194 | | void crt9021_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 195 | | { |
| 196 | | } |
| 197 | | |
| 198 | | |
| 199 | | //------------------------------------------------- |
| 200 | | // slg_w - scan line gate |
| 201 | | //------------------------------------------------- |
| 202 | | |
| 203 | | WRITE_LINE_MEMBER( crt9021_device::slg_w ) |
| 204 | | { |
| 205 | | if (LOG) logerror("CRT9021 '%s' SLG: %u\n", tag(), state); |
| 206 | | |
| 207 | | m_slg = state; |
| 208 | | } |
| 209 | | |
| 210 | | |
| 211 | | //------------------------------------------------- |
| 212 | | // sld_w - scan line data |
| 213 | | //------------------------------------------------- |
| 214 | | |
| 215 | | WRITE_LINE_MEMBER( crt9021_device::sld_w ) |
| 216 | | { |
| 217 | | if (LOG) logerror("CRT9021 '%s' SLG: %u\n", tag(), state); |
| 218 | | |
| 219 | | if (!m_slg) |
| 220 | | { |
| 221 | | m_sld <<= 1; |
| 222 | | m_sld |= state; |
| 223 | | } |
| 224 | | } |
| 225 | | |
| 226 | | |
| 227 | | //------------------------------------------------- |
| 228 | | // cursor_w - cursor |
| 229 | | //------------------------------------------------- |
| 230 | | |
| 231 | | WRITE_LINE_MEMBER( crt9021_device::cursor_w ) |
| 232 | | { |
| 233 | | if (LOG) logerror("CRT9021 '%s' CURSOR: %u\n", tag(), state); |
| 234 | | |
| 235 | | m_cursor = state; |
| 236 | | } |
| 237 | | |
| 238 | | |
| 239 | | //------------------------------------------------- |
| 240 | | // retbl_w - retrace blank |
| 241 | | //------------------------------------------------- |
| 242 | | |
| 243 | | WRITE_LINE_MEMBER( crt9021_device::retbl_w ) |
| 244 | | { |
| 245 | | if (LOG) logerror("CRT9021 '%s' RETBL: %u\n", tag(), state); |
| 246 | | |
| 247 | | m_retbl = state; |
| 248 | | } |
| 249 | | |
| 250 | | |
| 251 | | //------------------------------------------------- |
| 252 | | // vsync_w - vertical sync |
| 253 | | //------------------------------------------------- |
| 254 | | |
| 255 | | WRITE_LINE_MEMBER( crt9021_device::vsync_w ) |
| 256 | | { |
| 257 | | if (LOG) logerror("CRT9021 '%s' VSYNC: %u\n", tag(), state); |
| 258 | | |
| 259 | | m_vsync = state; |
| 260 | | } |
| 261 | | |
| 262 | | |
| 263 | | //------------------------------------------------- |
| 264 | | // update_screen - update screen |
| 265 | | //------------------------------------------------- |
| 266 | | |
| 267 | | void crt9021_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect) |
| 268 | | { |
| 269 | | } |
src/mess/video/hd61830.c
| r10968 | r10969 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | HD61830 LCD Timing Controller emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | **********************************************************************/ |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "hd61830.h" |
| 12 | | |
| 13 | | |
| 14 | | |
| 15 | | //************************************************************************** |
| 16 | | // MACROS / CONSTANTS |
| 17 | | //************************************************************************** |
| 18 | | |
| 19 | | #define LOG 0 |
| 20 | | |
| 21 | | enum |
| 22 | | { |
| 23 | | INSTRUCTION_MODE_CONTROL = 0, |
| 24 | | INSTRUCTION_CHARACTER_PITCH, |
| 25 | | INSTRUCTION_NUMBER_OF_CHARACTERS, |
| 26 | | INSTRUCTION_NUMBER_OF_TIME_DIVISIONS, |
| 27 | | INSTRUCTION_CURSOR_POSITION, |
| 28 | | INSTRUCTION_DISPLAY_START_LOW = 8, |
| 29 | | INSTRUCTION_DISPLAY_START_HIGH, |
| 30 | | INSTRUCTION_CURSOR_ADDRESS_LOW, |
| 31 | | INSTRUCTION_CURSOR_ADDRESS_HIGH, |
| 32 | | INSTRUCTION_DISPLAY_DATA_WRITE, |
| 33 | | INSTRUCTION_DISPLAY_DATA_READ, |
| 34 | | INSTRUCTION_CLEAR_BIT, |
| 35 | | INSTRUCTION_SET_BIT |
| 36 | | }; |
| 37 | | |
| 38 | | static const int CYCLES[] = |
| 39 | | { |
| 40 | | 4, 4, 4, 4, 4, -1, -1, -1, 4, 4, 4, 4, 6, 6, 36, 36 |
| 41 | | }; |
| 42 | | |
| 43 | | const int MODE_EXTERNAL_CG = 0x01; |
| 44 | | const int MODE_GRAPHIC = 0x02; |
| 45 | | const int MODE_CURSOR = 0x04; |
| 46 | | const int MODE_BLINK = 0x08; |
| 47 | | const int MODE_MASTER = 0x10; |
| 48 | | const int MODE_DISPLAY_ON = 0x20; |
| 49 | | |
| 50 | | |
| 51 | | |
| 52 | | //************************************************************************** |
| 53 | | // GLOBAL VARIABLES |
| 54 | | //************************************************************************** |
| 55 | | |
| 56 | | // devices |
| 57 | | const device_type HD61830 = hd61830_device_config::static_alloc_device_config; |
| 58 | | |
| 59 | | |
| 60 | | // default address map |
| 61 | | static ADDRESS_MAP_START( hd61830, AS_0, 8 ) |
| 62 | | AM_RANGE(0x0000, 0xffff) AM_RAM |
| 63 | | ADDRESS_MAP_END |
| 64 | | |
| 65 | | |
| 66 | | // internal character generator ROM |
| 67 | | ROM_START( hd61830 ) |
| 68 | | ROM_REGION( 0x5c0, "hd61830", ROMREGION_LOADBYNAME ) // internal 7360-bit chargen ROM |
| 69 | | ROM_LOAD( "hd61830.bin", 0x000, 0x5c0, BAD_DUMP CRC(06a934da) SHA1(bf3f074db5dc92e6f530cb18d6c013563099a87d) ) // typed in from manual |
| 70 | | ROM_END |
| 71 | | |
| 72 | | |
| 73 | | |
| 74 | | //************************************************************************** |
| 75 | | // DEVICE CONFIGURATION |
| 76 | | //************************************************************************** |
| 77 | | |
| 78 | | //------------------------------------------------- |
| 79 | | // hd61830_device_config - constructor |
| 80 | | //------------------------------------------------- |
| 81 | | |
| 82 | | hd61830_device_config::hd61830_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 83 | | : device_config(mconfig, static_alloc_device_config, "Hitachi HD61830", tag, owner, clock), |
| 84 | | device_config_memory_interface(mconfig, *this), |
| 85 | | m_space_config("videoram", ENDIANNESS_LITTLE, 8, 16, 0, NULL, *ADDRESS_MAP_NAME(hd61830)) |
| 86 | | { |
| 87 | | m_shortname = "hd61830"; |
| 88 | | } |
| 89 | | |
| 90 | | |
| 91 | | //------------------------------------------------- |
| 92 | | // static_alloc_device_config - allocate a new |
| 93 | | // configuration object |
| 94 | | //------------------------------------------------- |
| 95 | | |
| 96 | | device_config *hd61830_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 97 | | { |
| 98 | | return global_alloc(hd61830_device_config(mconfig, tag, owner, clock)); |
| 99 | | } |
| 100 | | |
| 101 | | |
| 102 | | //------------------------------------------------- |
| 103 | | // alloc_device - allocate a new device object |
| 104 | | //------------------------------------------------- |
| 105 | | |
| 106 | | device_t *hd61830_device_config::alloc_device(running_machine &machine) const |
| 107 | | { |
| 108 | | return auto_alloc(&machine, hd61830_device(machine, *this)); |
| 109 | | } |
| 110 | | |
| 111 | | |
| 112 | | //------------------------------------------------- |
| 113 | | // memory_space_config - return a description of |
| 114 | | // any address spaces owned by this device |
| 115 | | //------------------------------------------------- |
| 116 | | |
| 117 | | const address_space_config *hd61830_device_config::memory_space_config(address_spacenum spacenum) const |
| 118 | | { |
| 119 | | return (spacenum == AS_0) ? &m_space_config : NULL; |
| 120 | | } |
| 121 | | |
| 122 | | |
| 123 | | //------------------------------------------------- |
| 124 | | // rom_region - device-specific ROM region |
| 125 | | //------------------------------------------------- |
| 126 | | |
| 127 | | const rom_entry *hd61830_device_config::rom_region() const |
| 128 | | { |
| 129 | | return ROM_NAME(hd61830); |
| 130 | | } |
| 131 | | |
| 132 | | |
| 133 | | //------------------------------------------------- |
| 134 | | // device_config_complete - perform any |
| 135 | | // operations now that the configuration is |
| 136 | | // complete |
| 137 | | //------------------------------------------------- |
| 138 | | |
| 139 | | void hd61830_device_config::device_config_complete() |
| 140 | | { |
| 141 | | // inherit a copy of the static data |
| 142 | | const hd61830_interface *intf = reinterpret_cast<const hd61830_interface *>(static_config()); |
| 143 | | if (intf != NULL) |
| 144 | | *static_cast<hd61830_interface *>(this) = *intf; |
| 145 | | |
| 146 | | // or initialize to defaults if none provided |
| 147 | | else |
| 148 | | { |
| 149 | | memset(&m_in_rd_func, 0, sizeof(m_in_rd_func)); |
| 150 | | } |
| 151 | | } |
| 152 | | |
| 153 | | |
| 154 | | |
| 155 | | //************************************************************************** |
| 156 | | // INLINE HELPERS |
| 157 | | //************************************************************************** |
| 158 | | |
| 159 | | //------------------------------------------------- |
| 160 | | // readbyte - read a byte at the given address |
| 161 | | //------------------------------------------------- |
| 162 | | |
| 163 | | inline UINT8 hd61830_device::readbyte(offs_t address) |
| 164 | | { |
| 165 | | return space()->read_byte(address); |
| 166 | | } |
| 167 | | |
| 168 | | |
| 169 | | //------------------------------------------------- |
| 170 | | // writebyte - write a byte at the given address |
| 171 | | //------------------------------------------------- |
| 172 | | |
| 173 | | inline void hd61830_device::writebyte(offs_t address, UINT8 data) |
| 174 | | { |
| 175 | | space()->write_byte(address, data); |
| 176 | | } |
| 177 | | |
| 178 | | |
| 179 | | |
| 180 | | //************************************************************************** |
| 181 | | // LIVE DEVICE |
| 182 | | //************************************************************************** |
| 183 | | |
| 184 | | //------------------------------------------------- |
| 185 | | // hd61830_device - constructor |
| 186 | | //------------------------------------------------- |
| 187 | | |
| 188 | | hd61830_device::hd61830_device(running_machine &_machine, const hd61830_device_config &config) |
| 189 | | : device_t(_machine, config), |
| 190 | | device_memory_interface(_machine, config, *this), |
| 191 | | m_bf(false), |
| 192 | | m_blink(0), |
| 193 | | m_config(config) |
| 194 | | { |
| 195 | | |
| 196 | | } |
| 197 | | |
| 198 | | |
| 199 | | //------------------------------------------------- |
| 200 | | // device_start - device-specific startup |
| 201 | | //------------------------------------------------- |
| 202 | | |
| 203 | | void hd61830_device::device_start() |
| 204 | | { |
| 205 | | // allocate timers |
| 206 | | m_busy_timer = timer_alloc(); |
| 207 | | |
| 208 | | // resolve callbacks |
| 209 | | devcb_resolve_read8(&m_in_rd_func, &m_config.m_in_rd_func, this); |
| 210 | | |
| 211 | | m_screen = machine->device<screen_device>(m_config.screen_tag); |
| 212 | | |
| 213 | | // register for state saving |
| 214 | | save_item(NAME(m_bf)); |
| 215 | | save_item(NAME(m_ir)); |
| 216 | | save_item(NAME(m_mcr)); |
| 217 | | save_item(NAME(m_dor)); |
| 218 | | save_item(NAME(m_cac)); |
| 219 | | save_item(NAME(m_dsa)); |
| 220 | | save_item(NAME(m_vp)); |
| 221 | | save_item(NAME(m_hp)); |
| 222 | | save_item(NAME(m_hn)); |
| 223 | | save_item(NAME(m_nx)); |
| 224 | | save_item(NAME(m_cp)); |
| 225 | | save_item(NAME(m_blink)); |
| 226 | | save_item(NAME(m_cursor)); |
| 227 | | } |
| 228 | | |
| 229 | | |
| 230 | | //------------------------------------------------- |
| 231 | | // device_reset - device-specific reset |
| 232 | | //------------------------------------------------- |
| 233 | | |
| 234 | | void hd61830_device::device_reset() |
| 235 | | { |
| 236 | | // display off, slave mode |
| 237 | | m_mcr &= ~(MODE_MASTER | MODE_DISPLAY_ON); |
| 238 | | |
| 239 | | // default horizontal pitch |
| 240 | | m_hp = 6; |
| 241 | | } |
| 242 | | |
| 243 | | |
| 244 | | //------------------------------------------------- |
| 245 | | // device_timer - handler timer events |
| 246 | | //------------------------------------------------- |
| 247 | | |
| 248 | | void hd61830_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 249 | | { |
| 250 | | // clear busy flag |
| 251 | | m_bf = false; |
| 252 | | } |
| 253 | | |
| 254 | | |
| 255 | | /*------------------------------------------------- |
| 256 | | set_busy_flag - set busy flag and arm timer |
| 257 | | to clear it later |
| 258 | | -------------------------------------------------*/ |
| 259 | | |
| 260 | | void hd61830_device::set_busy_flag() |
| 261 | | { |
| 262 | | // set busy flag |
| 263 | | m_bf = true; |
| 264 | | |
| 265 | | // adjust busy timer |
| 266 | | m_busy_timer->adjust(attotime::from_usec(CYCLES[m_ir])); |
| 267 | | } |
| 268 | | |
| 269 | | |
| 270 | | //------------------------------------------------- |
| 271 | | // status_r - status register read |
| 272 | | //------------------------------------------------- |
| 273 | | |
| 274 | | READ8_MEMBER( hd61830_device::status_r ) |
| 275 | | { |
| 276 | | if (LOG) logerror("HD61830 '%s' Status Read: %s\n", tag(), m_bf ? "busy" : "ready"); |
| 277 | | |
| 278 | | return m_bf ? 0x80 : 0; |
| 279 | | } |
| 280 | | |
| 281 | | |
| 282 | | //------------------------------------------------- |
| 283 | | // control_w - instruction register write |
| 284 | | //------------------------------------------------- |
| 285 | | |
| 286 | | WRITE8_MEMBER( hd61830_device::control_w ) |
| 287 | | { |
| 288 | | m_ir = data; |
| 289 | | } |
| 290 | | |
| 291 | | |
| 292 | | //------------------------------------------------- |
| 293 | | // data_r - data register read |
| 294 | | //------------------------------------------------- |
| 295 | | |
| 296 | | READ8_MEMBER( hd61830_device::data_r ) |
| 297 | | { |
| 298 | | UINT8 data = m_dor; |
| 299 | | |
| 300 | | if (LOG) logerror("HD61830 '%s' Display Data Read %02x\n", tag(), m_dor); |
| 301 | | |
| 302 | | m_dor = readbyte(m_cac); |
| 303 | | |
| 304 | | m_cac++; |
| 305 | | |
| 306 | | return data; |
| 307 | | } |
| 308 | | |
| 309 | | |
| 310 | | //------------------------------------------------- |
| 311 | | // data_w - data register write |
| 312 | | //------------------------------------------------- |
| 313 | | |
| 314 | | WRITE8_MEMBER( hd61830_device::data_w ) |
| 315 | | { |
| 316 | | if (m_bf) |
| 317 | | { |
| 318 | | logerror("HD61830 '%s' Ignoring data write %02x due to business\n", tag(), data); |
| 319 | | return; |
| 320 | | } |
| 321 | | |
| 322 | | switch (m_ir) |
| 323 | | { |
| 324 | | case INSTRUCTION_MODE_CONTROL: |
| 325 | | m_mcr = data; |
| 326 | | |
| 327 | | if (LOG) |
| 328 | | { |
| 329 | | logerror("HD61830 '%s' %s CG\n", tag(), (data & MODE_EXTERNAL_CG) ? "External" : "Internal"); |
| 330 | | logerror("HD61830 '%s' %s Display Mode\n", tag(), (data & MODE_GRAPHIC) ? "Graphic" : "Character"); |
| 331 | | logerror("HD61830 '%s' %s Mode\n", tag(), (data & MODE_MASTER) ? "Master" : "Slave"); |
| 332 | | logerror("HD61830 '%s' Cursor %s\n", tag(), (data & MODE_CURSOR) ? "On" : "Off"); |
| 333 | | logerror("HD61830 '%s' Blink %s\n", tag(), (data & MODE_BLINK) ? "On" : "Off"); |
| 334 | | logerror("HD61830 '%s' Display %s\n", tag(), (data & MODE_DISPLAY_ON) ? "On" : "Off"); |
| 335 | | } |
| 336 | | break; |
| 337 | | |
| 338 | | case INSTRUCTION_CHARACTER_PITCH: |
| 339 | | m_hp = (data & 0x07) + 1; |
| 340 | | m_vp = (data >> 4) + 1; |
| 341 | | |
| 342 | | if (LOG) logerror("HD61830 '%s' Horizontal Character Pitch: %u\n", tag(), m_hp); |
| 343 | | if (LOG) logerror("HD61830 '%s' Vertical Character Pitch: %u\n", tag(), m_vp); |
| 344 | | break; |
| 345 | | |
| 346 | | case INSTRUCTION_NUMBER_OF_CHARACTERS: |
| 347 | | m_hn = (data & 0x7f) + 1; |
| 348 | | |
| 349 | | if (LOG) logerror("HD61830 '%s' Number of Characters: %u\n", tag(), m_hn); |
| 350 | | break; |
| 351 | | |
| 352 | | case INSTRUCTION_NUMBER_OF_TIME_DIVISIONS: |
| 353 | | m_nx = (data & 0x7f) + 1; |
| 354 | | |
| 355 | | if (LOG) logerror("HD61830 '%s' Number of Time Divisions: %u\n", tag(), m_nx); |
| 356 | | break; |
| 357 | | |
| 358 | | case INSTRUCTION_CURSOR_POSITION: |
| 359 | | m_cp = (data & 0x7f) + 1; |
| 360 | | |
| 361 | | if (LOG) logerror("HD61830 '%s' Cursor Position: %u\n", tag(), m_cp); |
| 362 | | break; |
| 363 | | |
| 364 | | case INSTRUCTION_DISPLAY_START_LOW: |
| 365 | | m_dsa = (m_dsa & 0xff00) | data; |
| 366 | | |
| 367 | | if (LOG) logerror("HD61830 '%s' Display Start Address Low %04x\n", tag(), m_dsa); |
| 368 | | break; |
| 369 | | |
| 370 | | case INSTRUCTION_DISPLAY_START_HIGH: |
| 371 | | m_dsa = (data << 8) | (m_dsa & 0xff); |
| 372 | | |
| 373 | | if (LOG) logerror("HD61830 '%s' Display Start Address High %04x\n", tag(), m_dsa); |
| 374 | | break; |
| 375 | | |
| 376 | | case INSTRUCTION_CURSOR_ADDRESS_LOW: |
| 377 | | if (BIT(m_cac, 7) && !BIT(data, 7)) |
| 378 | | { |
| 379 | | m_cac = (((m_cac >> 8) + 1) << 8) | data; |
| 380 | | } |
| 381 | | else |
| 382 | | { |
| 383 | | m_cac = (m_cac & 0xff00) | data; |
| 384 | | } |
| 385 | | |
| 386 | | if (LOG) logerror("HD61830 '%s' Cursor Address Low %02x: %04x\n", tag(), data, m_cac); |
| 387 | | break; |
| 388 | | |
| 389 | | case INSTRUCTION_CURSOR_ADDRESS_HIGH: |
| 390 | | m_cac = (data << 8) | (m_cac & 0xff); |
| 391 | | |
| 392 | | if (LOG) logerror("HD61830 '%s' Cursor Address High %02x: %04x\n", tag(), data, m_cac); |
| 393 | | break; |
| 394 | | |
| 395 | | case INSTRUCTION_DISPLAY_DATA_WRITE: |
| 396 | | writebyte(m_cac, data); |
| 397 | | |
| 398 | | if (LOG) logerror("HD61830 '%s' Display Data Write %02x -> %04x row %u col %u\n", tag(), data, m_cac, m_cac / 40, m_cac % 40); |
| 399 | | |
| 400 | | m_cac++; |
| 401 | | break; |
| 402 | | |
| 403 | | case INSTRUCTION_CLEAR_BIT: |
| 404 | | { |
| 405 | | int bit = data & 0x07; |
| 406 | | UINT8 md = readbyte(m_cac); |
| 407 | | |
| 408 | | md &= ~(1 << bit); |
| 409 | | |
| 410 | | if (LOG) logerror("HD61830 '%s' Clear Bit %u at %04x\n", tag(), bit + 1, m_cac); |
| 411 | | |
| 412 | | writebyte(m_cac, md); |
| 413 | | |
| 414 | | m_cac++; |
| 415 | | } |
| 416 | | break; |
| 417 | | |
| 418 | | case INSTRUCTION_SET_BIT: |
| 419 | | { |
| 420 | | int bit = data & 0x07; |
| 421 | | UINT8 md = readbyte(m_cac); |
| 422 | | |
| 423 | | md |= 1 << bit; |
| 424 | | |
| 425 | | if (LOG) logerror("HD61830 '%s' Set Bit %u at %04x\n", tag(), bit + 1, m_cac); |
| 426 | | |
| 427 | | writebyte(m_cac, md); |
| 428 | | |
| 429 | | m_cac++; |
| 430 | | } |
| 431 | | break; |
| 432 | | |
| 433 | | default: |
| 434 | | logerror("HD61830 '%s' Illegal Instruction %02x!\n", tag(), m_ir); |
| 435 | | return; |
| 436 | | } |
| 437 | | |
| 438 | | // burn cycles |
| 439 | | set_busy_flag(); |
| 440 | | } |
| 441 | | |
| 442 | | |
| 443 | | //------------------------------------------------- |
| 444 | | // draw_scanline - draw one graphics scanline |
| 445 | | //------------------------------------------------- |
| 446 | | |
| 447 | | void hd61830_device::draw_scanline(bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ra) |
| 448 | | { |
| 449 | | for (int sx = 0; sx < m_hn; sx++) |
| 450 | | { |
| 451 | | UINT8 data = readbyte(ra++); |
| 452 | | |
| 453 | | for (int x = 0; x < m_hp; x++) |
| 454 | | { |
| 455 | | *BITMAP_ADDR16(bitmap, y, (sx * m_hp) + x) = BIT(data, x); |
| 456 | | } |
| 457 | | } |
| 458 | | } |
| 459 | | |
| 460 | | |
| 461 | | //------------------------------------------------- |
| 462 | | // update_graphics - draw graphics mode screen |
| 463 | | //------------------------------------------------- |
| 464 | | |
| 465 | | void hd61830_device::update_graphics(bitmap_t *bitmap, const rectangle *cliprect) |
| 466 | | { |
| 467 | | for (int y = 0; y < m_nx; y++) |
| 468 | | { |
| 469 | | UINT16 rac1 = m_dsa + (y * m_hn); |
| 470 | | UINT16 rac2 = rac1 + (m_nx * m_hn); |
| 471 | | |
| 472 | | /* draw upper half scanline */ |
| 473 | | draw_scanline(bitmap, cliprect, y, rac1); |
| 474 | | |
| 475 | | /* draw lower half scanline */ |
| 476 | | draw_scanline(bitmap, cliprect, y + m_nx, rac2); |
| 477 | | } |
| 478 | | } |
| 479 | | |
| 480 | | |
| 481 | | //------------------------------------------------- |
| 482 | | // draw_char - draw a char |
| 483 | | //------------------------------------------------- |
| 484 | | |
| 485 | | void hd61830_device::draw_char(bitmap_t *bitmap, const rectangle *cliprect, UINT16 ma, int x, int y, UINT8 md) |
| 486 | | { |
| 487 | | for (int cl = 0; cl < m_vp; cl++) |
| 488 | | { |
| 489 | | for (int cr = 0; cr < m_hp; cr++) |
| 490 | | { |
| 491 | | int sy = y * m_vp + cl; |
| 492 | | int sx = x * m_hp + cr; |
| 493 | | UINT8 data = 0; |
| 494 | | |
| 495 | | if (m_mcr & MODE_EXTERNAL_CG) |
| 496 | | { |
| 497 | | data = devcb_call_read8(&m_in_rd_func, (cl << 12) | md); |
| 498 | | } |
| 499 | | else |
| 500 | | { |
| 501 | | UINT16 addr = 0; |
| 502 | | |
| 503 | | if (md >= 0x20 && md < 0x80 && cl < 7) |
| 504 | | { |
| 505 | | // 5x7 characters 0x20..0x7f |
| 506 | | addr = (md - 0x20) * 7 + cl; |
| 507 | | } |
| 508 | | else if (md >= 0xa0 && md < 0xe0 && cl < 7) |
| 509 | | { |
| 510 | | // 5x7 characters 0xa0..0xdf |
| 511 | | addr = 96*7 + (md - 0xa0) * 7 + cl; |
| 512 | | } |
| 513 | | else if (md >= 0xe0 && cl < 11) |
| 514 | | { |
| 515 | | // 5x11 characters 0xe0..0xff |
| 516 | | addr = 160*7 + (md - 0xe0) * 11 + cl; |
| 517 | | } |
| 518 | | |
| 519 | | data = subregion("hd61830")->u8(addr); |
| 520 | | } |
| 521 | | |
| 522 | | int cursor = m_mcr & MODE_CURSOR; |
| 523 | | int blink = m_mcr & MODE_BLINK; |
| 524 | | |
| 525 | | // cursor off |
| 526 | | int pixel = BIT(data, cr); |
| 527 | | |
| 528 | | if (blink && (ma == m_cac)) |
| 529 | | { |
| 530 | | // cursor off, character blink |
| 531 | | if (!cursor) |
| 532 | | pixel = m_cursor ? pixel : 0; |
| 533 | | |
| 534 | | // cursor blink |
| 535 | | if (cursor && (cl == m_cp)) |
| 536 | | pixel = m_cursor ? 1 : 0; |
| 537 | | } |
| 538 | | else |
| 539 | | { |
| 540 | | // cursor on |
| 541 | | if (cursor && (cl == m_cp)) |
| 542 | | pixel = m_cursor ? 1 : 0; |
| 543 | | } |
| 544 | | |
| 545 | | if (sy < m_screen->height() && sx < m_screen->width()) |
| 546 | | *BITMAP_ADDR16(bitmap, sy, sx) = pixel; |
| 547 | | } |
| 548 | | } |
| 549 | | } |
| 550 | | |
| 551 | | |
| 552 | | //------------------------------------------------- |
| 553 | | // update_text - draw text mode screen |
| 554 | | //------------------------------------------------- |
| 555 | | |
| 556 | | void hd61830_device::update_text(bitmap_t *bitmap, const rectangle *cliprect) |
| 557 | | { |
| 558 | | for (int y = 0; y < (m_nx / m_vp); y++) |
| 559 | | { |
| 560 | | for (int x = 0; x < m_hn; x++) |
| 561 | | { |
| 562 | | UINT16 ma = y * m_hn + x; |
| 563 | | UINT8 md = readbyte(ma); |
| 564 | | |
| 565 | | draw_char(bitmap, cliprect, ma, x, y, md); |
| 566 | | } |
| 567 | | } |
| 568 | | } |
| 569 | | |
| 570 | | |
| 571 | | //------------------------------------------------- |
| 572 | | // update_screen - update screen |
| 573 | | //------------------------------------------------- |
| 574 | | |
| 575 | | void hd61830_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect) |
| 576 | | { |
| 577 | | if (m_mcr & MODE_DISPLAY_ON) |
| 578 | | { |
| 579 | | if (m_mcr & MODE_GRAPHIC) |
| 580 | | { |
| 581 | | update_graphics(bitmap, cliprect); |
| 582 | | } |
| 583 | | else |
| 584 | | { |
| 585 | | update_text(bitmap, cliprect); |
| 586 | | } |
| 587 | | } |
| 588 | | else |
| 589 | | { |
| 590 | | bitmap_fill(bitmap, cliprect, 0); |
| 591 | | } |
| 592 | | |
| 593 | | m_blink++; |
| 594 | | |
| 595 | | if (m_blink == 0x20) |
| 596 | | { |
| 597 | | m_blink = 0; |
| 598 | | m_cursor = !m_cursor; |
| 599 | | } |
| 600 | | } |