src/mess/video/sed1330.c
| r0 | r4833 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | SED1330 LCD Timing Controller 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 | - everything |
| 15 | |
| 16 | */ |
| 17 | |
| 18 | #include "driver.h" |
| 19 | #include "sed1330.h" |
| 20 | |
| 21 | /*************************************************************************** |
| 22 | PARAMETERS |
| 23 | ***************************************************************************/ |
| 24 | |
| 25 | #define LOG 1 |
| 26 | |
| 27 | #define SED1330_INSTRUCTION_SYSTEM_SET 0x40 |
| 28 | #define SED1330_INSTRUCTION_SLEEP_IN 0x53 |
| 29 | #define SED1330_INSTRUCTION_DISP_ON 0x58 |
| 30 | #define SED1330_INSTRUCTION_DISP_OFF 0x59 |
| 31 | #define SED1330_INSTRUCTION_SCROLL 0x44 |
| 32 | #define SED1330_INSTRUCTION_CSRFORM 0x5d |
| 33 | #define SED1330_INSTRUCTION_CGRAM_ADR 0x5c |
| 34 | #define SED1330_INSTRUCTION_CSRDIR_RIGHT 0x4c |
| 35 | #define SED1330_INSTRUCTION_CSRDIR_LEFT 0x4d |
| 36 | #define SED1330_INSTRUCTION_CSRDIR_UP 0x4e |
| 37 | #define SED1330_INSTRUCTION_CSRDIR_DOWN 0x4f |
| 38 | #define SED1330_INSTRUCTION_HDOT_SCR 0x5a |
| 39 | #define SED1330_INSTRUCTION_OVLAY 0x5b |
| 40 | #define SED1330_INSTRUCTION_CSRW 0x46 |
| 41 | #define SED1330_INSTRUCTION_CSRR 0x47 |
| 42 | #define SED1330_INSTRUCTION_MWRITE 0x42 |
| 43 | #define SED1330_INSTRUCTION_MREAD 0x43 |
| 44 | |
| 45 | #define SED1330_CSRDIR_RIGHT 0x00 |
| 46 | #define SED1330_CSRDIR_LEFT 0x01 |
| 47 | #define SED1330_CSRDIR_UP 0x10 |
| 48 | #define SED1330_CSRDIR_DOWN 0x11 |
| 49 | |
| 50 | static const int SED1330_CYCLES[] = { |
| 51 | 4, 4, 4, 4, 4, -1, -1, -1, 4, 4, 4, 4, 6, 6, 36, 36 |
| 52 | }; |
| 53 | |
| 54 | #define SED1330_MODE_EXTERNAL_CG 0x01 /* not supported */ |
| 55 | #define SED1330_MODE_GRAPHIC 0x02 /* text mode not supported */ |
| 56 | #define SED1330_MODE_CURSOR 0x04 /* not supported */ |
| 57 | #define SED1330_MODE_BLINK 0x08 /* not supported */ |
| 58 | #define SED1330_MODE_MASTER 0x10 /* not supported */ |
| 59 | #define SED1330_MODE_DISPLAY_ON 0x20 |
| 60 | |
| 61 | /*************************************************************************** |
| 62 | TYPE DEFINITIONS |
| 63 | ***************************************************************************/ |
| 64 | |
| 65 | typedef struct _sed1330_t sed1330_t; |
| 66 | struct _sed1330_t |
| 67 | { |
| 68 | devcb_resolved_read8 in_vd_func; |
| 69 | devcb_resolved_write8 out_vd_func; |
| 70 | |
| 71 | int bf; /* busy flag */ |
| 72 | |
| 73 | UINT8 ir; /* instruction register */ |
| 74 | |
| 75 | int m0; /* */ |
| 76 | int m1; /* */ |
| 77 | int m2; /* */ |
| 78 | int ws; /* */ |
| 79 | int iv; /* */ |
| 80 | int fx; /* horizontal character size */ |
| 81 | int fy; /* vertical character size */ |
| 82 | int wf; /* AC frame drive waveform period */ |
| 83 | int cr; /* address range covered by 1 display line */ |
| 84 | int tcr; /* line length (including horizontal blanking) */ |
| 85 | int lf; /* frame height in lines */ |
| 86 | UINT16 ap; /* horizontal address range of the virtual screen */ |
| 87 | |
| 88 | int hdotscr; /* horizontal dot scroll */ |
| 89 | |
| 90 | UINT16 csr; /* cursor address register */ |
| 91 | int csrdir; /* cursor direction */ |
| 92 | |
| 93 | int pbc; /* parameter byte counter */ |
| 94 | |
| 95 | /* devices */ |
| 96 | const device_config *screen; |
| 97 | |
| 98 | /* timers */ |
| 99 | emu_timer *busy_timer; |
| 100 | }; |
| 101 | |
| 102 | /*************************************************************************** |
| 103 | INLINE FUNCTIONS |
| 104 | ***************************************************************************/ |
| 105 | |
| 106 | INLINE sed1330_t *get_safe_token(const device_config *device) |
| 107 | { |
| 108 | assert(device != NULL); |
| 109 | assert(device->token != NULL); |
| 110 | return (sed1330_t *)device->token; |
| 111 | } |
| 112 | |
| 113 | INLINE const sed1330_interface *get_interface(const device_config *device) |
| 114 | { |
| 115 | assert(device != NULL); |
| 116 | assert((device->type == SED1330)); |
| 117 | return (const sed1330_interface *) device->static_config; |
| 118 | } |
| 119 | |
| 120 | /*************************************************************************** |
| 121 | IMPLEMENTATION |
| 122 | ***************************************************************************/ |
| 123 | |
| 124 | /*------------------------------------------------- |
| 125 | TIMER_CALLBACK( busy_tick ) |
| 126 | -------------------------------------------------*/ |
| 127 | |
| 128 | static TIMER_CALLBACK( busy_tick ) |
| 129 | { |
| 130 | const device_config *device = ptr; |
| 131 | sed1330_t *sed1330 = get_safe_token(device); |
| 132 | |
| 133 | /* clear busy flag */ |
| 134 | sed1330->bf = 0; |
| 135 | } |
| 136 | |
| 137 | /*------------------------------------------------- |
| 138 | set_busy_flag - set busy flag and arm timer |
| 139 | to clear it later |
| 140 | -------------------------------------------------*/ |
| 141 | #ifdef UNUSED_FUNCTION |
| 142 | static void set_busy_flag(sed1330_t *sed1330, int period) |
| 143 | { |
| 144 | /* set busy flag */ |
| 145 | sed1330->bf = 1; |
| 146 | |
| 147 | /* adjust busy timer */ |
| 148 | timer_adjust_oneshot(sed1330->busy_timer, ATTOTIME_IN_USEC(period), 0); |
| 149 | } |
| 150 | #endif |
| 151 | /*------------------------------------------------- |
| 152 | sed1330_status_r - status read |
| 153 | -------------------------------------------------*/ |
| 154 | |
| 155 | READ8_DEVICE_HANDLER( sed1330_status_r ) |
| 156 | { |
| 157 | sed1330_t *sed1330 = get_safe_token(device); |
| 158 | |
| 159 | if (LOG) logerror("SED1330 '%s' Status Read: %s\n", device->tag, sed1330->bf ? "busy" : "ready"); |
| 160 | |
| 161 | return sed1330->bf << 6; |
| 162 | } |
| 163 | |
| 164 | /*------------------------------------------------- |
| 165 | sed1330_control_w - control write |
| 166 | -------------------------------------------------*/ |
| 167 | |
| 168 | WRITE8_DEVICE_HANDLER( sed1330_command_w ) |
| 169 | { |
| 170 | sed1330_t *sed1330 = get_safe_token(device); |
| 171 | |
| 172 | sed1330->ir = data; |
| 173 | sed1330->pbc = 0; |
| 174 | } |
| 175 | |
| 176 | /*------------------------------------------------- |
| 177 | sed1330_data_r - data read |
| 178 | -------------------------------------------------*/ |
| 179 | |
| 180 | READ8_DEVICE_HANDLER( sed1330_data_r ) |
| 181 | { |
| 182 | // sed1330_t *sed1330 = get_safe_token(device); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | /*------------------------------------------------- |
| 188 | sed1330_data_w - data write |
| 189 | -------------------------------------------------*/ |
| 190 | |
| 191 | WRITE8_DEVICE_HANDLER( sed1330_data_w ) |
| 192 | { |
| 193 | sed1330_t *sed1330 = get_safe_token(device); |
| 194 | |
| 195 | switch (sed1330->ir) |
| 196 | { |
| 197 | case SED1330_INSTRUCTION_SYSTEM_SET: |
| 198 | switch (sed1330->pbc) |
| 199 | { |
| 200 | case 0: |
| 201 | sed1330->m0 = BIT(data, 0); |
| 202 | sed1330->m1 = BIT(data, 1); |
| 203 | sed1330->m2 = BIT(data, 2); |
| 204 | sed1330->ws = BIT(data, 3); |
| 205 | sed1330->iv = BIT(data, 5); |
| 206 | |
| 207 | if (LOG) |
| 208 | { |
| 209 | logerror("SED1330 '%s' %s CG ROM\n", device->tag, BIT(data, 0) ? "External" : "Internal"); |
| 210 | logerror("SED1330 '%s' D6 Correction %s\n", device->tag, BIT(data, 1) ? "enabled" : "disabled"); |
| 211 | logerror("SED1330 '%s' Character Height: %u\n", device->tag, BIT(data, 2) ? 16 : 8); |
| 212 | logerror("SED1330 '%s' %s Panel Drive\n", device->tag, BIT(data, 3) ? "Dual" : "Single"); |
| 213 | logerror("SED1330 '%s' Screen Top-Line Correction: %s\n", device->tag, BIT(data, 5) ? "disabled" : "enabled"); |
| 214 | } |
| 215 | break; |
| 216 | |
| 217 | case 1: |
| 218 | sed1330->fx = (data & 0x07) + 1; |
| 219 | sed1330->wf = BIT(data, 7); |
| 220 | |
| 221 | if (LOG) |
| 222 | { |
| 223 | logerror("SED1330 '%s' Horizontal Character Size: %u\n", device->tag, sed1330->fx); |
| 224 | logerror("SED1330 '%s' %s AC Drive\n", device->tag, BIT(data, 7) ? "2-frame" : "16-line"); |
| 225 | } |
| 226 | break; |
| 227 | |
| 228 | case 2: |
| 229 | sed1330->fy = (data & 0x0f) + 1; |
| 230 | if (LOG) logerror("SED1330 '%s' Vertical Character Size: %u\n", device->tag, sed1330->fy); |
| 231 | break; |
| 232 | |
| 233 | case 3: |
| 234 | sed1330->cr = data + 1; |
| 235 | break; |
| 236 | |
| 237 | case 4: |
| 238 | sed1330->tcr = data + 1; |
| 239 | break; |
| 240 | |
| 241 | case 5: |
| 242 | sed1330->lf = data + 1; |
| 243 | break; |
| 244 | |
| 245 | case 6: |
| 246 | sed1330->ap = (sed1330->ap & 0xff00) | data; |
| 247 | break; |
| 248 | |
| 249 | case 7: |
| 250 | sed1330->ap = (data << 8) | (sed1330->ap & 0xff); |
| 251 | break; |
| 252 | |
| 253 | default: |
| 254 | logerror("SED1330 '%s' Invalid parameter byte %02x\n", device->tag, data); |
| 255 | } |
| 256 | break; |
| 257 | /* |
| 258 | case SED1330_INSTRUCTION_SLEEP_IN: |
| 259 | break; |
| 260 | |
| 261 | case SED1330_INSTRUCTION_DISP_ON: |
| 262 | break; |
| 263 | |
| 264 | case SED1330_INSTRUCTION_DISP_OFF: |
| 265 | break; |
| 266 | |
| 267 | case SED1330_INSTRUCTION_SCROLL: |
| 268 | break; |
| 269 | |
| 270 | case SED1330_INSTRUCTION_CSRFORM: |
| 271 | break; |
| 272 | |
| 273 | case SED1330_INSTRUCTION_CGRAM_ADR: |
| 274 | break; |
| 275 | */ |
| 276 | case SED1330_INSTRUCTION_CSRDIR_RIGHT: |
| 277 | sed1330->csrdir = data & 0x03; |
| 278 | if (LOG) logerror("SED1330 '%s' Cursor Direction: Right\n", device->tag); |
| 279 | break; |
| 280 | /* |
| 281 | case SED1330_INSTRUCTION_CSRDIR_LEFT: |
| 282 | sed1330->csrdir = data & 0x03; |
| 283 | if (LOG) logerror("SED1330 '%s' Cursor Direction: Left\n", device->tag); |
| 284 | break; |
| 285 | |
| 286 | case SED1330_INSTRUCTION_CSRDIR_UP: |
| 287 | sed1330->csrdir = data & 0x03; |
| 288 | if (LOG) logerror("SED1330 '%s' Cursor Direction: Up\n", device->tag); |
| 289 | break; |
| 290 | |
| 291 | case SED1330_INSTRUCTION_CSRDIR_DOWN: |
| 292 | sed1330->csrdir = data & 0x03; |
| 293 | if (LOG) logerror("SED1330 '%s' Cursor Direction: Down\n", device->tag); |
| 294 | break; |
| 295 | */ |
| 296 | case SED1330_INSTRUCTION_HDOT_SCR: |
| 297 | sed1330->hdotscr = data & 0x07; |
| 298 | if (LOG) logerror("SED1330 '%s' Horizontal Dot Scroll: %u\n", device->tag, sed1330->hdotscr); |
| 299 | break; |
| 300 | /* |
| 301 | case SED1330_INSTRUCTION_OVLAY: |
| 302 | break; |
| 303 | */ |
| 304 | case SED1330_INSTRUCTION_CSRW: |
| 305 | switch (sed1330->pbc) |
| 306 | { |
| 307 | case 0: |
| 308 | sed1330->csr = (sed1330->csr & 0xff00) | data; |
| 309 | if (LOG) logerror("SED1330 '%s' Cursor Address %04x\n", device->tag, sed1330->csr); |
| 310 | break; |
| 311 | |
| 312 | case 1: |
| 313 | sed1330->csr = (data << 8) | (sed1330->csr & 0xff); |
| 314 | if (LOG) logerror("SED1330 '%s' Cursor Address %04x\n", device->tag, sed1330->csr); |
| 315 | break; |
| 316 | |
| 317 | default: |
| 318 | logerror("SED1330 '%s' Invalid parameter byte %02x\n", device->tag, data); |
| 319 | } |
| 320 | break; |
| 321 | /* |
| 322 | case SED1330_INSTRUCTION_CSRR: |
| 323 | break; |
| 324 | */ |
| 325 | case SED1330_INSTRUCTION_MWRITE: |
| 326 | devcb_call_write8(&sed1330->out_vd_func, sed1330->csr, data); |
| 327 | |
| 328 | switch (sed1330->csrdir) |
| 329 | { |
| 330 | case SED1330_CSRDIR_RIGHT: |
| 331 | sed1330->csr++; |
| 332 | break; |
| 333 | |
| 334 | default: |
| 335 | logerror("SED1330 '%s' Unsupported cursor direction\n", device->tag); |
| 336 | } |
| 337 | |
| 338 | break; |
| 339 | /* |
| 340 | case SED1330_INSTRUCTION_MREAD: |
| 341 | break; |
| 342 | */ |
| 343 | default: |
| 344 | logerror("SED1330 '%s' Unsupported instruction %02x\n", device->tag, sed1330->ir); |
| 345 | } |
| 346 | |
| 347 | sed1330->pbc++; |
| 348 | } |
| 349 | #ifdef UNUSED_FUNCTION |
| 350 | /*------------------------------------------------- |
| 351 | draw_scanline - draw one scanline |
| 352 | -------------------------------------------------*/ |
| 353 | |
| 354 | static void draw_scanline(sed1330_t *sed1330, bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ra) |
| 355 | { |
| 356 | } |
| 357 | |
| 358 | /*------------------------------------------------- |
| 359 | update_graphics - draw graphics mode screen |
| 360 | -------------------------------------------------*/ |
| 361 | |
| 362 | static void update_graphics(sed1330_t *sed1330, bitmap_t *bitmap, const rectangle *cliprect) |
| 363 | { |
| 364 | } |
| 365 | #endif |
| 366 | /*------------------------------------------------- |
| 367 | sed1330_update - update screen |
| 368 | -------------------------------------------------*/ |
| 369 | |
| 370 | void sed1330_update(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 371 | { |
| 372 | } |
| 373 | |
| 374 | /*------------------------------------------------- |
| 375 | DEVICE_START( sed1330 ) |
| 376 | -------------------------------------------------*/ |
| 377 | |
| 378 | static DEVICE_START( sed1330 ) |
| 379 | { |
| 380 | sed1330_t *sed1330 = get_safe_token(device); |
| 381 | const sed1330_interface *intf = get_interface(device); |
| 382 | |
| 383 | /* resolve callbacks */ |
| 384 | devcb_resolve_read8(&sed1330->in_vd_func, &intf->in_vd_func, device); |
| 385 | devcb_resolve_write8(&sed1330->out_vd_func, &intf->out_vd_func, device); |
| 386 | |
| 387 | /* get the screen device */ |
| 388 | sed1330->screen = devtag_get_device(device->machine, intf->screen_tag); |
| 389 | assert(sed1330->screen != NULL); |
| 390 | |
| 391 | /* create the busy timer */ |
| 392 | sed1330->busy_timer = timer_alloc(device->machine, busy_tick, (void *)device); |
| 393 | |
| 394 | /* register for state saving */ |
| 395 | // state_save_register_device_item(device, 0, sed1330->); |
| 396 | } |
| 397 | |
| 398 | /*------------------------------------------------- |
| 399 | DEVICE_RESET( sed1330 ) |
| 400 | -------------------------------------------------*/ |
| 401 | |
| 402 | static DEVICE_RESET( sed1330 ) |
| 403 | { |
| 404 | // sed1330_t *sed1330 = get_safe_token(device); |
| 405 | |
| 406 | } |
| 407 | |
| 408 | /*------------------------------------------------- |
| 409 | DEVICE_GET_INFO( sed1330 ) |
| 410 | -------------------------------------------------*/ |
| 411 | |
| 412 | DEVICE_GET_INFO( sed1330 ) |
| 413 | { |
| 414 | switch (state) |
| 415 | { |
| 416 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 417 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(sed1330_t); break; |
| 418 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 419 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 420 | |
| 421 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 422 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(sed1330); break; |
| 423 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 424 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(sed1330); break; |
| 425 | |
| 426 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 427 | case DEVINFO_STR_NAME: strcpy(info->s, " SED1330"); break; |
| 428 | case DEVINFO_STR_FAMILY: strcpy(info->s, " SED1330"); break; |
| 429 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 430 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 431 | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 432 | } |
| 433 | } |