src/mess/video/hd61830.c
| r4687 | r4688 | |
| 11 | 11 | |
| 12 | 12 | TODO: |
| 13 | 13 | |
| 14 | | - clean up code |
| 15 | | - clear/set bit instructions |
| 16 | | - instruction timing |
| 17 | 14 | - text mode |
| 18 | 15 | |
| 19 | 16 | */ |
| r4687 | r4688 | |
| 29 | 26 | |
| 30 | 27 | enum |
| 31 | 28 | { |
| 32 | | HD61380_REGISTER_MODE_CONTROL = 0, |
| 33 | | HD61380_REGISTER_CHARACTER_PITCH, |
| 34 | | HD61380_REGISTER_NUMBER_OF_CHARACTERS, |
| 35 | | HD61380_REGISTER_NUMBER_OF_TIME_DIVISIONS, |
| 36 | | HD61380_REGISTER_CURSOR_POSITION, |
| 37 | | HD61380_REGISTER_DISPLAY_START_LOW = 8, |
| 38 | | HD61380_REGISTER_DISPLAY_START_HIGH, |
| 39 | | HD61380_REGISTER_CURSOR_ADDRESS_LOW, |
| 40 | | HD61380_REGISTER_CURSOR_ADDRESS_HIGH, |
| 41 | | HD61380_REGISTER_DISPLAY_DATA_WRITE, |
| 42 | | HD61380_REGISTER_DISPLAY_DATA_READ, |
| 43 | | HD61380_REGISTER_CLEAR_BIT, /* not supported */ |
| 44 | | HD61380_REGISTER_SET_BIT /* not supported */ |
| 29 | HD61380_INSTRUCTION_MODE_CONTROL = 0, |
| 30 | HD61380_INSTRUCTION_CHARACTER_PITCH, |
| 31 | HD61380_INSTRUCTION_NUMBER_OF_CHARACTERS, |
| 32 | HD61380_INSTRUCTION_NUMBER_OF_TIME_DIVISIONS, |
| 33 | HD61380_INSTRUCTION_CURSOR_POSITION, |
| 34 | HD61380_INSTRUCTION_DISPLAY_START_LOW = 8, |
| 35 | HD61380_INSTRUCTION_DISPLAY_START_HIGH, |
| 36 | HD61380_INSTRUCTION_CURSOR_ADDRESS_LOW, |
| 37 | HD61380_INSTRUCTION_CURSOR_ADDRESS_HIGH, |
| 38 | HD61380_INSTRUCTION_DISPLAY_DATA_WRITE, |
| 39 | HD61380_INSTRUCTION_DISPLAY_DATA_READ, |
| 40 | HD61380_INSTRUCTION_CLEAR_BIT, /* not supported */ |
| 41 | HD61380_INSTRUCTION_SET_BIT /* not supported */ |
| 45 | 42 | }; |
| 46 | 43 | |
| 44 | static const HD61380_CYCLES[] = { |
| 45 | 4, 4, 4, 4, 4, -1, -1, -1, 4, 4, 4, 4, 6, 6, 36, 36 |
| 46 | }; |
| 47 | |
| 47 | 48 | #define HD61380_MODE_EXTERNAL_CG 0x01 /* not supported */ |
| 48 | 49 | #define HD61380_MODE_GRAPHIC 0x02 /* text mode not supported */ |
| 49 | 50 | #define HD61380_MODE_CURSOR 0x04 /* not supported */ |
| r4687 | r4688 | |
| 61 | 62 | devcb_resolved_read8 in_rd_func; |
| 62 | 63 | devcb_resolved_write8 out_rd_func; |
| 63 | 64 | |
| 64 | | int bf; /* busy flag, not supported */ |
| 65 | int bf; /* busy flag */ |
| 65 | 66 | |
| 66 | | UINT8 ir; /* instruction register */ |
| 67 | | UINT8 mcr; /* mode control register */ |
| 68 | | UINT8 dir; /* data input register */ |
| 69 | | UINT8 dor; /* data output register */ |
| 70 | | UINT16 rac1; /* refresh address counter 1 */ |
| 71 | | UINT16 rac2; /* refresh address counter 2 */ |
| 72 | | UINT16 cac; /* cursor address counter */ |
| 73 | | UINT8 lac; /* line address counter */ |
| 67 | UINT8 ir; /* instruction register */ |
| 68 | UINT8 mcr; /* mode control register */ |
| 69 | UINT8 dor; /* data output register */ |
| 74 | 70 | |
| 75 | | UINT16 dsa; /* display start address */ |
| 71 | UINT16 dsa; /* display start address */ |
| 72 | UINT16 cac; /* cursor address counter */ |
| 76 | 73 | |
| 77 | | int vp; /* vertical character pitch */ |
| 78 | | int hp; /* horizontal character pitch */ |
| 79 | | int hn; /* horizontal number of characters */ |
| 80 | | int nx; /* number of time divisions */ |
| 81 | | int cp; /* cursor position */ |
| 74 | int vp; /* vertical character pitch */ |
| 75 | int hp; /* horizontal character pitch */ |
| 76 | int hn; /* horizontal number of characters */ |
| 77 | int nx; /* number of time divisions */ |
| 78 | int cp; /* cursor position */ |
| 82 | 79 | |
| 83 | | const device_config *screen; /* screen */ |
| 80 | /* devices */ |
| 81 | const device_config *screen; |
| 82 | |
| 83 | /* timers */ |
| 84 | emu_timer *busy_timer; |
| 84 | 85 | }; |
| 85 | 86 | |
| 86 | 87 | /*************************************************************************** |
| r4687 | r4688 | |
| 106 | 107 | ***************************************************************************/ |
| 107 | 108 | |
| 108 | 109 | /*------------------------------------------------- |
| 110 | TIMER_CALLBACK( busy_tick ) |
| 111 | -------------------------------------------------*/ |
| 112 | |
| 113 | static TIMER_CALLBACK( busy_tick ) |
| 114 | { |
| 115 | const device_config *device = ptr; |
| 116 | hd61830_t *hd61830 = get_safe_token(device); |
| 117 | |
| 118 | /* clear busy flag */ |
| 119 | hd61830->bf = 0; |
| 120 | } |
| 121 | |
| 122 | /*------------------------------------------------- |
| 123 | set_busy_flag - set busy flag and arm timer |
| 124 | to clear it later |
| 125 | -------------------------------------------------*/ |
| 126 | |
| 127 | static void set_busy_flag(hd61830_t *hd61830, int period) |
| 128 | { |
| 129 | /* set busy flag */ |
| 130 | hd61830->bf = 1; |
| 131 | |
| 132 | /* adjust busy timer */ |
| 133 | timer_adjust_oneshot(hd61830->busy_timer, ATTOTIME_IN_USEC(period), 0); |
| 134 | } |
| 135 | |
| 136 | /*------------------------------------------------- |
| 109 | 137 | hd61830_status_r - status read |
| 110 | 138 | -------------------------------------------------*/ |
| 111 | 139 | |
| r4687 | r4688 | |
| 113 | 141 | { |
| 114 | 142 | hd61830_t *hd61830 = get_safe_token(device); |
| 115 | 143 | |
| 144 | if (LOG) logerror("HD61380 '%s' Status Read: %s\n", device->tag, hd61830->bf ? "busy" : "ready"); |
| 145 | |
| 116 | 146 | return hd61830->bf << 7; |
| 117 | 147 | } |
| 118 | 148 | |
| r4687 | r4688 | |
| 156 | 186 | |
| 157 | 187 | switch (hd61830->ir) |
| 158 | 188 | { |
| 159 | | case HD61380_REGISTER_MODE_CONTROL: |
| 189 | case HD61380_INSTRUCTION_MODE_CONTROL: |
| 160 | 190 | hd61830->mcr = data; |
| 161 | 191 | |
| 162 | 192 | if (LOG) |
| r4687 | r4688 | |
| 170 | 200 | } |
| 171 | 201 | break; |
| 172 | 202 | |
| 173 | | case HD61380_REGISTER_CHARACTER_PITCH: |
| 203 | case HD61380_INSTRUCTION_CHARACTER_PITCH: |
| 174 | 204 | hd61830->hp = (data & 0x07) + 1; |
| 175 | 205 | hd61830->vp = (data >> 4) + 1; |
| 176 | 206 | |
| r4687 | r4688 | |
| 178 | 208 | if (LOG) logerror("HD61380 '%s' Vertical Character Pitch: %u\n", device->tag, hd61830->vp); |
| 179 | 209 | break; |
| 180 | 210 | |
| 181 | | case HD61380_REGISTER_NUMBER_OF_CHARACTERS: |
| 211 | case HD61380_INSTRUCTION_NUMBER_OF_CHARACTERS: |
| 182 | 212 | hd61830->hn = (data & 0x7f) + 1; |
| 183 | 213 | |
| 184 | 214 | if (LOG) logerror("HD61380 '%s' Number of Characters: %u\n", device->tag, hd61830->hn); |
| 185 | 215 | break; |
| 186 | 216 | |
| 187 | | case HD61380_REGISTER_NUMBER_OF_TIME_DIVISIONS: |
| 217 | case HD61380_INSTRUCTION_NUMBER_OF_TIME_DIVISIONS: |
| 188 | 218 | hd61830->nx = (data & 0x7f) + 1; |
| 189 | 219 | |
| 190 | 220 | if (LOG) logerror("HD61380 '%s' Number of Time Divisions: %u\n", device->tag, hd61830->nx); |
| 191 | 221 | break; |
| 192 | 222 | |
| 193 | | case HD61380_REGISTER_CURSOR_POSITION: |
| 223 | case HD61380_INSTRUCTION_CURSOR_POSITION: |
| 194 | 224 | hd61830->cp = (data & 0x7f) + 1; |
| 195 | 225 | |
| 196 | 226 | if (LOG) logerror("HD61380 '%s' Cursor Position: %u\n", device->tag, hd61830->cp); |
| 197 | 227 | break; |
| 198 | 228 | |
| 199 | | case HD61380_REGISTER_DISPLAY_START_LOW: |
| 229 | case HD61380_INSTRUCTION_DISPLAY_START_LOW: |
| 200 | 230 | hd61830->dsa = (hd61830->dsa & 0xff00) | data; |
| 201 | 231 | |
| 202 | 232 | if (LOG) logerror("HD61380 '%s' Display Start Address Low %04x\n", device->tag, hd61830->dsa); |
| 203 | 233 | break; |
| 204 | 234 | |
| 205 | | case HD61380_REGISTER_DISPLAY_START_HIGH: |
| 235 | case HD61380_INSTRUCTION_DISPLAY_START_HIGH: |
| 206 | 236 | hd61830->dsa = (data << 8) | (hd61830->dsa & 0xff); |
| 207 | 237 | |
| 208 | 238 | if (LOG) logerror("HD61380 '%s' Display Start Address High %04x\n", device->tag, hd61830->dsa); |
| 209 | 239 | break; |
| 210 | 240 | |
| 211 | | case HD61380_REGISTER_CURSOR_ADDRESS_LOW: |
| 241 | case HD61380_INSTRUCTION_CURSOR_ADDRESS_LOW: |
| 212 | 242 | if (BIT(hd61830->cac, 7) && !BIT(data, 7)) |
| 213 | 243 | { |
| 214 | | hd61830->cac = ((((hd61830->cac & 0xff00) >> 8) + 1) << 8) | data; |
| 244 | hd61830->cac = (((hd61830->cac >> 8) + 1) << 8) | data; |
| 215 | 245 | } |
| 216 | 246 | else |
| 217 | 247 | { |
| r4687 | r4688 | |
| 221 | 251 | if (LOG) logerror("HD61380 '%s' Cursor Address Low %02x: %04x\n", device->tag, data, hd61830->cac); |
| 222 | 252 | break; |
| 223 | 253 | |
| 224 | | case HD61380_REGISTER_CURSOR_ADDRESS_HIGH: |
| 254 | case HD61380_INSTRUCTION_CURSOR_ADDRESS_HIGH: |
| 225 | 255 | hd61830->cac = (data << 8) | (hd61830->cac & 0xff); |
| 226 | 256 | |
| 227 | 257 | if (LOG) logerror("HD61380 '%s' Cursor Address High %02x: %04x\n", device->tag, data, hd61830->cac); |
| 228 | 258 | break; |
| 229 | 259 | |
| 230 | | case HD61380_REGISTER_DISPLAY_DATA_WRITE: |
| 260 | case HD61380_INSTRUCTION_DISPLAY_DATA_WRITE: |
| 231 | 261 | devcb_call_write8(&hd61830->out_rd_func, hd61830->cac, data); |
| 232 | 262 | |
| 233 | 263 | if (LOG) logerror("HD61380 '%s' Display Data Write %02x -> %04x row %u col %u\n", device->tag, data, hd61830->cac, hd61830->cac / 40, hd61830->cac % 40); |
| r4687 | r4688 | |
| 235 | 265 | hd61830->cac++; |
| 236 | 266 | break; |
| 237 | 267 | |
| 238 | | case HD61380_REGISTER_CLEAR_BIT: |
| 239 | | logerror("HD61380 '%s' Clear Bit not supported!\n", device->tag); |
| 268 | case HD61380_INSTRUCTION_CLEAR_BIT: |
| 269 | { |
| 270 | int nb = data & 0x07; |
| 271 | UINT8 data = devcb_call_read8(&hd61830->in_rd_func, hd61830->cac); |
| 272 | |
| 273 | data &= ~(2 << nb); |
| 274 | |
| 275 | if (LOG) logerror("HD61380 '%s' Clear Bit %u at %04x\n", device->tag, nb + 1, hd61830->cac); |
| 276 | |
| 277 | devcb_call_write8(&hd61830->out_rd_func, hd61830->cac, data); |
| 278 | |
| 279 | hd61830->cac++; |
| 280 | } |
| 240 | 281 | break; |
| 241 | 282 | |
| 242 | | case HD61380_REGISTER_SET_BIT: |
| 243 | | logerror("HD61380 '%s' Set Bit not supported!\n", device->tag); |
| 283 | case HD61380_INSTRUCTION_SET_BIT: |
| 284 | { |
| 285 | int nb = data & 0x07; |
| 286 | UINT8 data = devcb_call_read8(&hd61830->in_rd_func, hd61830->cac); |
| 287 | |
| 288 | data |= 2 << nb; |
| 289 | |
| 290 | if (LOG) logerror("HD61380 '%s' Set Bit %u at %04x\n", device->tag, nb + 1, hd61830->cac); |
| 291 | |
| 292 | devcb_call_write8(&hd61830->out_rd_func, hd61830->cac, data); |
| 293 | |
| 294 | hd61830->cac++; |
| 295 | } |
| 244 | 296 | break; |
| 245 | 297 | |
| 246 | 298 | default: |
| 247 | 299 | logerror("HD61830 '%s' Illegal Instruction %02x!\n", device->tag, hd61830->ir); |
| 300 | return; |
| 248 | 301 | } |
| 302 | |
| 303 | /* burn cycles */ |
| 304 | set_busy_flag(hd61830, HD61380_CYCLES[hd61830->ir]); |
| 249 | 305 | } |
| 250 | 306 | |
| 251 | 307 | /*------------------------------------------------- |
| 308 | draw_scanline - draw one scanline |
| 309 | -------------------------------------------------*/ |
| 310 | |
| 311 | static void draw_scanline(hd61830_t *hd61830, bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ra) |
| 312 | { |
| 313 | int sx, x; |
| 314 | |
| 315 | for (sx = 0; sx < hd61830->hn; sx++) |
| 316 | { |
| 317 | UINT8 data = devcb_call_read8(&hd61830->in_rd_func, ra++); |
| 318 | |
| 319 | for (x = 0; x < hd61830->hp; x++) |
| 320 | { |
| 321 | *BITMAP_ADDR16(bitmap, y, (sx * hd61830->hp) + x) = BIT(data, 0); |
| 322 | data >>= 1; |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | /*------------------------------------------------- |
| 328 | update_graphics - draw graphics mode screen |
| 329 | -------------------------------------------------*/ |
| 330 | |
| 331 | static void update_graphics(hd61830_t *hd61830, bitmap_t *bitmap, const rectangle *cliprect) |
| 332 | { |
| 333 | int y; |
| 334 | |
| 335 | for (y = 0; y < hd61830->nx; y++) |
| 336 | { |
| 337 | UINT16 rac1 = hd61830->dsa + (y * hd61830->hn); |
| 338 | UINT16 rac2 = rac1 + (hd61830->nx * hd61830->hn); |
| 339 | |
| 340 | /* draw upper half scanline */ |
| 341 | draw_scanline(hd61830, bitmap, cliprect, y, rac1); |
| 342 | |
| 343 | /* draw lower half scanline */ |
| 344 | draw_scanline(hd61830, bitmap, cliprect, y + hd61830->nx, rac2); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /*------------------------------------------------- |
| 252 | 349 | hd61830_update - update screen |
| 253 | 350 | -------------------------------------------------*/ |
| 254 | 351 | |
| 255 | 352 | void hd61830_update(const device_config *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 256 | 353 | { |
| 257 | 354 | hd61830_t *hd61830 = get_safe_token(device); |
| 258 | | int y, sx, x; |
| 259 | | UINT16 lac = hd61830->dsa; |
| 260 | 355 | |
| 261 | | for (y = 0; y < (hd61830->nx * 2); y++) |
| 356 | if (hd61830->mcr & HD61380_MODE_GRAPHIC) |
| 262 | 357 | { |
| 263 | | for (sx = 0; sx < hd61830->hn; sx++) |
| 264 | | { |
| 265 | | UINT8 data = devcb_call_read8(&hd61830->in_rd_func, lac++); |
| 266 | | |
| 267 | | for (x = 0; x < hd61830->hp; x++) |
| 268 | | { |
| 269 | | *BITMAP_ADDR16(bitmap, y, (sx * hd61830->hp) + x) = BIT(data, 0); |
| 270 | | data >>= 1; |
| 271 | | } |
| 272 | | } |
| 358 | update_graphics(hd61830, bitmap, cliprect); |
| 273 | 359 | } |
| 274 | 360 | } |
| 275 | 361 | |
| r4687 | r4688 | |
| 290 | 376 | hd61830->screen = devtag_get_device(device->machine, intf->screen_tag); |
| 291 | 377 | assert(hd61830->screen != NULL); |
| 292 | 378 | |
| 379 | /* create the busy timer */ |
| 380 | hd61830->busy_timer = timer_alloc(device->machine, busy_tick, (void *)device); |
| 381 | |
| 293 | 382 | /* register for state saving */ |
| 294 | 383 | state_save_register_device_item(device, 0, hd61830->bf); |
| 295 | 384 | state_save_register_device_item(device, 0, hd61830->ir); |
| 296 | 385 | state_save_register_device_item(device, 0, hd61830->mcr); |
| 297 | | state_save_register_device_item(device, 0, hd61830->dir); |
| 298 | 386 | state_save_register_device_item(device, 0, hd61830->dor); |
| 299 | | state_save_register_device_item(device, 0, hd61830->rac1); |
| 300 | | state_save_register_device_item(device, 0, hd61830->rac2); |
| 301 | 387 | state_save_register_device_item(device, 0, hd61830->cac); |
| 302 | | state_save_register_device_item(device, 0, hd61830->lac); |
| 303 | 388 | state_save_register_device_item(device, 0, hd61830->dsa); |
| 304 | 389 | state_save_register_device_item(device, 0, hd61830->vp); |
| 305 | 390 | state_save_register_device_item(device, 0, hd61830->hp); |
| r4687 | r4688 | |
| 314 | 399 | |
| 315 | 400 | static DEVICE_RESET( hd61830 ) |
| 316 | 401 | { |
| 317 | | //hd61830_t *hd61830 = get_safe_token(device); |
| 402 | hd61830_t *hd61830 = get_safe_token(device); |
| 318 | 403 | |
| 404 | hd61830->mcr = hd61830->mcr & ~(HD61380_MODE_MASTER | HD61380_MODE_DISPLAY_ON); |
| 405 | hd61830->hp = 6; |
| 319 | 406 | } |
| 320 | 407 | |
| 321 | 408 | /*------------------------------------------------- |