src/mess/video/upd3301.c
| r6352 | r6353 | |
| 7 | 7 | |
| 8 | 8 | **********************************************************************/
|
| 9 | 9 | |
| 10 | /*
|
| 11 | |
| 12 | TODO:
|
| 13 | |
| 14 | - FIFO
|
| 15 | - screen display
|
| 16 | - set_drq
|
| 17 | - dack_w
|
| 18 | - interrupts
|
| 19 | - light pen
|
| 20 | - reset counters
|
| 21 | |
| 22 | */
|
| 23 | |
| 10 | 24 | #include "driver.h"
|
| 11 | 25 | #include "upd3301.h"
|
| 12 | 26 | |
| r6352 | r6353 | |
| 14 | 28 | PARAMETERS
|
| 15 | 29 | ***************************************************************************/
|
| 16 | 30 | |
| 17 | | #define LOG 0
|
| 31 | #define LOG 1
|
| 18 | 32 | |
| 33 | #define UPD3301_COMMAND_MASK 0xe0
|
| 34 | #define UPD3301_COMMAND_RESET 0x00
|
| 35 | #define UPD3301_COMMAND_START_DISPLAY 0x20
|
| 36 | #define UPD3301_COMMAND_SET_INTERRUPT_MASK 0x40
|
| 37 | #define UPD3301_COMMAND_READ_LIGHT_PEN 0x60
|
| 38 | #define UPD3301_COMMAND_LOAD_CURSOR_POSITION 0x80
|
| 39 | #define UPD3301_COMMAND_RESET_INTERRUPT 0xa0
|
| 40 | #define UPD3301_COMMAND_RESET_COUNTERS 0xc0
|
| 41 | |
| 42 | #define UPD3301_STATUS_VE 0x10
|
| 43 | #define UPD3301_STATUS_U 0x08 /* not supported */
|
| 44 | #define UPD3301_STATUS_N 0x04 /* not supported */
|
| 45 | #define UPD3301_STATUS_E 0x02 /* not supported */
|
| 46 | #define UPD3301_STATUS_LP 0x01 /* not supported */
|
| 47 | |
| 48 | enum
|
| 49 | {
|
| 50 | MODE_NONE,
|
| 51 | MODE_RESET,
|
| 52 | MODE_READ_LIGHT_PEN,
|
| 53 | MODE_LOAD_CURSOR_POSITION
|
| 54 | };
|
| 55 | |
| 19 | 56 | /***************************************************************************
|
| 20 | 57 | TYPE DEFINITIONS
|
| 21 | 58 | ***************************************************************************/
|
| r6352 | r6353 | |
| 30 | 67 | |
| 31 | 68 | const device_config *screen; /* screen */
|
| 32 | 69 | |
| 70 | int disp;
|
| 71 | int mode;
|
| 72 | UINT8 status;
|
| 73 | int param_count;
|
| 74 | |
| 75 | UINT8 row_buffer[80][2]; /* row buffer */
|
| 76 | UINT8 fifo[20][2]; /* FIFO */
|
| 77 | |
| 78 | int dma_mode; /* DMA mode */
|
| 79 | int h; /* characters per line */
|
| 80 | int b; /* cursor blink time */
|
| 81 | int l; /* lines per screen */
|
| 82 | int s; /* display every other line */
|
| 83 | int c; /* cursor mode */
|
| 84 | int r; /* lines per character */
|
| 85 | int v; /* vertical blanking height */
|
| 86 | int z; /* horizontal blanking width */
|
| 87 | int at1; /* */
|
| 88 | int at0; /* */
|
| 89 | int sc; /* */
|
| 90 | int a; /* attributes per row */
|
| 91 | int mn; /* disable special character interrupt */
|
| 92 | int me; /* disable end of screen interrupt */
|
| 93 | int cm; /* cursor visible */
|
| 94 | int cx; /* cursor column */
|
| 95 | int cy; /* cursor row */
|
| 96 | |
| 33 | 97 | /* timers */
|
| 34 | 98 | emu_timer *vrtc_timer; /* vertical sync timer */
|
| 35 | 99 | emu_timer *hrtc_timer; /* horizontal sync timer */
|
| r6352 | r6353 | |
| 59 | 123 | ***************************************************************************/
|
| 60 | 124 | |
| 61 | 125 | /*-------------------------------------------------
|
| 126 | set_interrupt - set interrupt line state
|
| 127 | -------------------------------------------------*/
|
| 128 | |
| 129 | static void set_interrupt(const device_config *device, int state)
|
| 130 | {
|
| 131 | upd3301_t *upd3301 = get_safe_token(device);
|
| 132 | |
| 133 | if (LOG) logerror("UPD3301 '%s' Interrupt: %u\n", device->tag, state);
|
| 134 | |
| 135 | devcb_call_write_line(&upd3301->out_int_func, state);
|
| 136 | }
|
| 137 | |
| 138 | /*-------------------------------------------------
|
| 139 | set_display - set display state
|
| 140 | -------------------------------------------------*/
|
| 141 | |
| 142 | static void set_display(const device_config *device, int state)
|
| 143 | {
|
| 144 | upd3301_t *upd3301 = get_safe_token(device);
|
| 145 | |
| 146 | if (state)
|
| 147 | {
|
| 148 | upd3301->status |= UPD3301_STATUS_VE;
|
| 149 | }
|
| 150 | else
|
| 151 | {
|
| 152 | upd3301->status &= ~UPD3301_STATUS_VE;
|
| 153 | }
|
| 154 | |
| 155 | upd3301->disp = state;
|
| 156 | }
|
| 157 | |
| 158 | /*-------------------------------------------------
|
| 159 | reset_counters - reset screen counters
|
| 160 | -------------------------------------------------*/
|
| 161 | |
| 162 | static void reset_counters(const device_config *device)
|
| 163 | {
|
| 164 | set_interrupt(device, 0);
|
| 165 | }
|
| 166 | |
| 167 | /*-------------------------------------------------
|
| 168 | update_hrtc_timer -
|
| 169 | -------------------------------------------------*/
|
| 170 | |
| 171 | static void update_hrtc_timer(upd3301_t *upd3301, int state)
|
| 172 | {
|
| 173 | int y = video_screen_get_vpos(upd3301->screen);
|
| 174 | |
| 175 | int next_x = state ? upd3301->h : 0;
|
| 176 | int next_y = state ? y : ((y + 1) % ((upd3301->l + upd3301->v) * 8));
|
| 177 | |
| 178 | attotime duration = video_screen_get_time_until_pos(upd3301->screen, next_y, next_x);
|
| 179 | |
| 180 | timer_adjust_oneshot(upd3301->hrtc_timer, duration, !state);
|
| 181 | }
|
| 182 | |
| 183 | /*-------------------------------------------------
|
| 184 | update_vrtc_timer -
|
| 185 | -------------------------------------------------*/
|
| 186 | |
| 187 | static void update_vrtc_timer(upd3301_t *upd3301, int state)
|
| 188 | {
|
| 189 | int next_y = state ? (upd3301->l * upd3301->r) : 0;
|
| 190 | |
| 191 | attotime duration = video_screen_get_time_until_pos(upd3301->screen, next_y, 0);
|
| 192 | |
| 193 | timer_adjust_oneshot(upd3301->vrtc_timer, duration, !state);
|
| 194 | }
|
| 195 | |
| 196 | /*-------------------------------------------------
|
| 197 | recompute_parameters -
|
| 198 | -------------------------------------------------*/
|
| 199 | |
| 200 | static void recompute_parameters(const device_config *device)
|
| 201 | {
|
| 202 | upd3301_t *upd3301 = get_safe_token(device);
|
| 203 | |
| 204 | int horiz_pix_total = (upd3301->h + upd3301->z) * 8;
|
| 205 | int vert_pix_total = (upd3301->l + upd3301->v) * upd3301->r;
|
| 206 | |
| 207 | attoseconds_t refresh = HZ_TO_ATTOSECONDS(device->clock) * horiz_pix_total * vert_pix_total;
|
| 208 |
|
| 209 | rectangle visarea;
|
| 210 | |
| 211 | visarea.min_x = 0;
|
| 212 | visarea.min_y = 0;
|
| 213 | visarea.max_x = (upd3301->h * 8) - 1;
|
| 214 | visarea.max_y = (upd3301->l * upd3301->r) - 1;
|
| 215 | |
| 216 | if (LOG)
|
| 217 | {
|
| 218 | if (LOG) logerror("UPD3301 '%s' Screen: %u x %u @ %f Hz\n", device->tag, horiz_pix_total, vert_pix_total, 1 / ATTOSECONDS_TO_DOUBLE(refresh));
|
| 219 | if (LOG) logerror("UPD3301 '%s' Visible Area: (%u, %u) - (%u, %u)\n", device->tag, visarea.min_x, visarea.min_y, visarea.max_x, visarea.max_y);
|
| 220 | }
|
| 221 | |
| 222 | video_screen_configure(upd3301->screen, horiz_pix_total, vert_pix_total, &visarea, refresh);
|
| 223 |
|
| 224 | update_hrtc_timer(upd3301, 0);
|
| 225 | update_vrtc_timer(upd3301, 0);
|
| 226 | }
|
| 227 | |
| 228 | /*-------------------------------------------------
|
| 62 | 229 | TIMER_CALLBACK( vrtc_tick )
|
| 63 | 230 | -------------------------------------------------*/
|
| 64 | 231 | |
| 65 | 232 | static TIMER_CALLBACK( vrtc_tick )
|
| 66 | 233 | {
|
| 67 | | // const device_config *device = ptr;
|
| 68 | | // upd3301_t *upd3301 = get_safe_token(device);
|
| 234 | const device_config *device = ptr;
|
| 235 | upd3301_t *upd3301 = get_safe_token(device);
|
| 236 | |
| 237 | //if (LOG) logerror("UPD3301 '%s' VRTC: %u\n", device->tag, param);
|
| 238 | |
| 239 | devcb_call_write_line(&upd3301->out_vrtc_func, param);
|
| 240 | |
| 241 | update_vrtc_timer(upd3301, param);
|
| 69 | 242 | }
|
| 70 | 243 | |
| 71 | 244 | /*-------------------------------------------------
|
| r6352 | r6353 | |
| 74 | 247 | |
| 75 | 248 | static TIMER_CALLBACK( hrtc_tick )
|
| 76 | 249 | {
|
| 77 | | // const device_config *device = ptr;
|
| 78 | | // upd3301_t *upd3301 = get_safe_token(device);
|
| 250 | const device_config *device = ptr;
|
| 251 | upd3301_t *upd3301 = get_safe_token(device);
|
| 252 | |
| 253 | //if (LOG) logerror("UPD3301 '%s' HRTC: %u\n", device->tag, param);
|
| 254 | |
| 255 | devcb_call_write_line(&upd3301->out_hrtc_func, param);
|
| 256 | |
| 257 | update_hrtc_timer(upd3301, param);
|
| 79 | 258 | }
|
| 80 | 259 | |
| 81 | 260 | /*-------------------------------------------------
|
| r6352 | r6353 | |
| 84 | 263 | |
| 85 | 264 | READ8_DEVICE_HANDLER( upd3301_r )
|
| 86 | 265 | {
|
| 87 | | return 0;
|
| 266 | upd3301_t *upd3301 = get_safe_token(device);
|
| 267 | UINT8 data = 0;
|
| 268 | |
| 269 | switch (offset & 0x01)
|
| 270 | {
|
| 271 | case 0: /* data */
|
| 272 | break;
|
| 273 | |
| 274 | case 1: /* status */
|
| 275 | data = upd3301->status;
|
| 276 | break;
|
| 277 | }
|
| 278 | |
| 279 | return data;
|
| 88 | 280 | }
|
| 89 | 281 | |
| 90 | 282 | /*-------------------------------------------------
|
| r6352 | r6353 | |
| 93 | 285 | |
| 94 | 286 | WRITE8_DEVICE_HANDLER( upd3301_w )
|
| 95 | 287 | {
|
| 288 | upd3301_t *upd3301 = get_safe_token(device);
|
| 289 | |
| 290 | switch (offset & 0x01)
|
| 291 | {
|
| 292 | case 0: /* data */
|
| 293 | switch (upd3301->mode)
|
| 294 | {
|
| 295 | case MODE_RESET:
|
| 296 | switch (upd3301->param_count)
|
| 297 | {
|
| 298 | case 0:
|
| 299 | upd3301->dma_mode = BIT(data, 7);
|
| 300 | upd3301->h = (data & 0x7f) + 2;
|
| 301 | if (LOG) logerror("UPD3301 '%s' DMA Mode: %s\n", device->tag, upd3301->dma_mode ? "character" : "burst");
|
| 302 | if (LOG) logerror("UPD3301 '%s' H: %u\n", device->tag, upd3301->h);
|
| 303 | break;
|
| 304 | |
| 305 | case 1:
|
| 306 | upd3301->b = ((data >> 6) + 1) * 16;
|
| 307 | upd3301->l = (data & 0x3f) + 1;
|
| 308 | if (LOG) logerror("UPD3301 '%s' B: %u\n", device->tag, upd3301->b);
|
| 309 | if (LOG) logerror("UPD3301 '%s' L: %u\n", device->tag, upd3301->l);
|
| 310 | break;
|
| 311 | |
| 312 | case 2:
|
| 313 | upd3301->s = BIT(data, 7);
|
| 314 | upd3301->c = (data >> 4) & 0x03;
|
| 315 | upd3301->r = (data & 0x1f) + 1;
|
| 316 | if (LOG) logerror("UPD3301 '%s' S: %u\n", device->tag, upd3301->s);
|
| 317 | if (LOG) logerror("UPD3301 '%s' C: %u\n", device->tag, upd3301->c);
|
| 318 | if (LOG) logerror("UPD3301 '%s' R: %u\n", device->tag, upd3301->r);
|
| 319 | break;
|
| 320 | |
| 321 | case 3:
|
| 322 | upd3301->v = (data >> 5) + 1;
|
| 323 | upd3301->z = (data & 0x1f) + 2;
|
| 324 | if (LOG) logerror("UPD3301 '%s' V: %u\n", device->tag, upd3301->v);
|
| 325 | if (LOG) logerror("UPD3301 '%s' Z: %u\n", device->tag, upd3301->z);
|
| 326 | recompute_parameters(device);
|
| 327 | break;
|
| 328 | |
| 329 | case 4:
|
| 330 | upd3301->at1 = BIT(data, 7);
|
| 331 | upd3301->at0 = BIT(data, 6);
|
| 332 | upd3301->sc = BIT(data, 5);
|
| 333 | upd3301->a = (data & 0x1f) + 1;
|
| 334 | if (LOG) logerror("UPD3301 '%s' AT1: %u\n", device->tag, upd3301->at1);
|
| 335 | if (LOG) logerror("UPD3301 '%s' AT0: %u\n", device->tag, upd3301->at0);
|
| 336 | if (LOG) logerror("UPD3301 '%s' SC: %u\n", device->tag, upd3301->sc);
|
| 337 | if (LOG) logerror("UPD3301 '%s' A: %u\n", device->tag, upd3301->a);
|
| 338 | |
| 339 | upd3301->mode = MODE_NONE;
|
| 340 | break;
|
| 341 | }
|
| 342 | |
| 343 | upd3301->param_count++;
|
| 344 | break;
|
| 345 | |
| 346 | case MODE_LOAD_CURSOR_POSITION:
|
| 347 | switch (upd3301->param_count)
|
| 348 | {
|
| 349 | case 0:
|
| 350 | upd3301->cx = data & 0x7f;
|
| 351 | if (LOG) logerror("UPD3301 '%s' CX: %u\n", device->tag, upd3301->cx);
|
| 352 | break;
|
| 353 | |
| 354 | case 1:
|
| 355 | upd3301->cy = data & 0x3f;
|
| 356 | if (LOG) logerror("UPD3301 '%s' CY: %u\n", device->tag, upd3301->cy);
|
| 357 | |
| 358 | upd3301->mode = MODE_NONE;
|
| 359 | break;
|
| 360 | }
|
| 361 | |
| 362 | upd3301->param_count++;
|
| 363 | break;
|
| 364 | |
| 365 | default:
|
| 366 | if (LOG) logerror("UPD3301 '%s' Invalid Parameter Byte %02x!\n", device->tag, data);
|
| 367 | }
|
| 368 | break;
|
| 369 | |
| 370 | case 1: /* command */
|
| 371 | upd3301->mode = MODE_NONE;
|
| 372 | upd3301->param_count = 0;
|
| 373 | |
| 374 | switch (data & 0xe0)
|
| 375 | {
|
| 376 | case UPD3301_COMMAND_RESET:
|
| 377 | if (LOG) logerror("UPD3301 '%s' Reset\n", device->tag);
|
| 378 | upd3301->mode = MODE_RESET;
|
| 379 | set_display(device, 0);
|
| 380 | set_interrupt(device, 0);
|
| 381 | break;
|
| 382 | |
| 383 | case UPD3301_COMMAND_START_DISPLAY:
|
| 384 | if (LOG) logerror("UPD3301 '%s' Start Display\n", device->tag);
|
| 385 | set_display(device, 1);
|
| 386 | reset_counters(device);
|
| 387 | break;
|
| 388 | |
| 389 | case UPD3301_COMMAND_SET_INTERRUPT_MASK:
|
| 390 | if (LOG) logerror("UPD3301 '%s' Set Interrupt Mask\n", device->tag);
|
| 391 | upd3301->me = BIT(data, 0);
|
| 392 | upd3301->mn = BIT(data, 1);
|
| 393 | if (LOG) logerror("UPD3301 '%s' ME: %u\n", device->tag, upd3301->me);
|
| 394 | if (LOG) logerror("UPD3301 '%s' MN: %u\n", device->tag, upd3301->mn);
|
| 395 | break;
|
| 396 | |
| 397 | case UPD3301_COMMAND_READ_LIGHT_PEN:
|
| 398 | if (LOG) logerror("UPD3301 '%s' Read Light Pen\n", device->tag);
|
| 399 | upd3301->mode = MODE_READ_LIGHT_PEN;
|
| 400 | break;
|
| 401 | |
| 402 | case UPD3301_COMMAND_LOAD_CURSOR_POSITION:
|
| 403 | if (LOG) logerror("UPD3301 '%s' Load Cursor Position\n", device->tag);
|
| 404 | upd3301->mode = MODE_LOAD_CURSOR_POSITION;
|
| 405 | upd3301->cm = BIT(data, 0);
|
| 406 | if (LOG) logerror("UPD3301 '%s' CM: %u\n", device->tag, upd3301->cm);
|
| 407 | break;
|
| 408 | |
| 409 | case UPD3301_COMMAND_RESET_INTERRUPT:
|
| 410 | if (LOG) logerror("UPD3301 '%s' Reset Interrupt\n", device->tag);
|
| 411 | set_interrupt(device, 0);
|
| 412 | break;
|
| 413 | |
| 414 | case UPD3301_COMMAND_RESET_COUNTERS:
|
| 415 | if (LOG) logerror("UPD3301 '%s' Reset Counters\n", device->tag);
|
| 416 | reset_counters(device);
|
| 417 | break;
|
| 418 | }
|
| 419 | break;
|
| 420 | }
|
| 96 | 421 | }
|
| 97 | 422 | |
| 98 | 423 | /*-------------------------------------------------
|