src/mess/video/fmtowns.c
| r0 | r6600 | |
| 1 | |
| 2 | /* |
| 3 | * FM Towns video hardware |
| 4 | * |
| 5 | * Resolution: from 320x200 to 640x400 |
| 6 | * |
| 7 | * Up to two graphics layers |
| 8 | * |
| 9 | * Sprites |
| 10 | * |
| 11 | * CRTC registers: |
| 12 | * |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include "driver.h" |
| 17 | #include "machine/pic8259.h" |
| 18 | #include "devices/messram.h" |
| 19 | #include "includes/fmtowns.h" |
| 20 | |
| 21 | static UINT8 towns_vram_wplane; |
| 22 | static UINT8 towns_vram_rplane; |
| 23 | static UINT8 towns_vram_page_sel; |
| 24 | static UINT8 towns_palette_select; |
| 25 | static UINT8 towns_palette_r[256]; |
| 26 | static UINT8 towns_palette_g[256]; |
| 27 | static UINT8 towns_palette_b[256]; |
| 28 | static UINT8 towns_degipal[8]; |
| 29 | static UINT8 towns_crtc_mix; |
| 30 | static UINT8 towns_crtc_sel; // selected CRTC register |
| 31 | static UINT16 towns_crtc_reg[32]; |
| 32 | static UINT8 towns_tvram_enable; |
| 33 | static UINT16 towns_kanji_offset; |
| 34 | static UINT8 towns_kanji_code_h; |
| 35 | static UINT8 towns_kanji_code_l; |
| 36 | |
| 37 | extern UINT32* towns_vram; |
| 38 | extern UINT8* towns_gfxvram; |
| 39 | extern UINT8* towns_txtvram; |
| 40 | |
| 41 | extern UINT32 towns_mainmem_enable; |
| 42 | extern UINT32 towns_ankcg_enable; |
| 43 | |
| 44 | READ8_HANDLER( towns_gfx_high_r ) |
| 45 | { |
| 46 | return towns_gfxvram[offset]; |
| 47 | } |
| 48 | |
| 49 | WRITE8_HANDLER( towns_gfx_high_w ) |
| 50 | { |
| 51 | towns_gfxvram[offset] = data; |
| 52 | } |
| 53 | |
| 54 | READ8_HANDLER( towns_gfx_r ) |
| 55 | { |
| 56 | if(towns_mainmem_enable != 0) |
| 57 | return messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xc0000]; |
| 58 | |
| 59 | if(towns_vram_page_sel != 0) |
| 60 | offset += 0x20000; |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | WRITE8_HANDLER( towns_gfx_w ) |
| 66 | { |
| 67 | if(towns_mainmem_enable != 0) |
| 68 | { |
| 69 | messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xc0000] = data; |
| 70 | return; |
| 71 | } |
| 72 | offset = offset << 2; |
| 73 | if(towns_vram_page_sel != 0) |
| 74 | offset += 0x20000; |
| 75 | if(towns_vram_wplane & 0x08) |
| 76 | { |
| 77 | towns_gfxvram[offset] &= ~0x88; |
| 78 | towns_gfxvram[offset] |= ((data & 0x80) >> 4) | ((data & 0x40) << 1); |
| 79 | towns_gfxvram[offset + 1] &= ~0x88; |
| 80 | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 2) | ((data & 0x10) << 3); |
| 81 | towns_gfxvram[offset + 2] &= ~0x88; |
| 82 | towns_gfxvram[offset + 2] |= ((data & 0x08)) | ((data & 0x04) << 5); |
| 83 | towns_gfxvram[offset + 3] &= ~0x88; |
| 84 | towns_gfxvram[offset + 3] |= ((data & 0x02) << 2) | ((data & 0x01) << 7); |
| 85 | } |
| 86 | if(towns_vram_wplane & 0x04) |
| 87 | { |
| 88 | towns_gfxvram[offset] &= ~0x44; |
| 89 | towns_gfxvram[offset] |= ((data & 0x80) >> 5) | ((data & 0x40)); |
| 90 | towns_gfxvram[offset + 1] &= ~0x44; |
| 91 | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 3) | ((data & 0x10) << 2); |
| 92 | towns_gfxvram[offset + 2] &= ~0x44; |
| 93 | towns_gfxvram[offset + 2] |= ((data & 0x08) >> 1) | ((data & 0x04) << 4); |
| 94 | towns_gfxvram[offset + 3] &= ~0x44; |
| 95 | towns_gfxvram[offset + 3] |= ((data & 0x02) << 1) | ((data & 0x01) << 6); |
| 96 | } |
| 97 | if(towns_vram_wplane & 0x02) |
| 98 | { |
| 99 | towns_gfxvram[offset] &= ~0x22; |
| 100 | towns_gfxvram[offset] |= ((data & 0x80) >> 6) | ((data & 0x40) >> 1); |
| 101 | towns_gfxvram[offset + 1] &= ~0x22; |
| 102 | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 4) | ((data & 0x10) << 1); |
| 103 | towns_gfxvram[offset + 2] &= ~0x22; |
| 104 | towns_gfxvram[offset + 2] |= ((data & 0x08) >> 2) | ((data & 0x04) << 3); |
| 105 | towns_gfxvram[offset + 3] &= ~0x22; |
| 106 | towns_gfxvram[offset + 3] |= ((data & 0x02)) | ((data & 0x01) << 5); |
| 107 | } |
| 108 | if(towns_vram_wplane & 0x01) |
| 109 | { |
| 110 | towns_gfxvram[offset] &= ~0x11; |
| 111 | towns_gfxvram[offset] |= ((data & 0x80) >> 7) | ((data & 0x40) >> 2); |
| 112 | towns_gfxvram[offset + 1] &= ~0x11; |
| 113 | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 5) | ((data & 0x10)); |
| 114 | towns_gfxvram[offset + 2] &= ~0x11; |
| 115 | towns_gfxvram[offset + 2] |= ((data & 0x08) >> 3) | ((data & 0x04) << 2); |
| 116 | towns_gfxvram[offset + 3] &= ~0x11; |
| 117 | towns_gfxvram[offset + 3] |= ((data & 0x02) >> 1) | ((data & 0x01) << 4); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | READ8_HANDLER( towns_video_cff80_r ) |
| 122 | { |
| 123 | UINT8* ROM = memory_region(space->machine,"user"); |
| 124 | if(towns_mainmem_enable != 0) |
| 125 | return messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xcff80]; |
| 126 | |
| 127 | switch(offset) |
| 128 | { |
| 129 | case 0x00: // mix register |
| 130 | return towns_crtc_mix; |
| 131 | case 0x01: // read/write plane select (bit 0-3 write, bit 6-7 read) |
| 132 | return ((towns_vram_rplane << 6) & 0xc0) | towns_vram_wplane; |
| 133 | case 0x03: // VRAM page select (bit 5) |
| 134 | if(towns_vram_page_sel != 0) |
| 135 | return 0x10; |
| 136 | else |
| 137 | return 0x00; |
| 138 | case 0x16: // Kanji character data |
| 139 | return ROM[(towns_kanji_offset << 1) + 0x180000]; |
| 140 | case 0x17: // Kanji character data |
| 141 | return ROM[(towns_kanji_offset++ << 1) + 0x180001]; |
| 142 | case 0x19: // ANK CG ROM |
| 143 | if(towns_ankcg_enable != 0) |
| 144 | return 0x01; |
| 145 | else |
| 146 | return 0x00; |
| 147 | default: |
| 148 | logerror("VGA: read from invalid or unimplemented memory-mapped port %05x\n",0xcff80+offset*4); |
| 149 | } |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | WRITE8_HANDLER( towns_video_cff80_w ) |
| 155 | { |
| 156 | if(towns_mainmem_enable != 0) |
| 157 | { |
| 158 | messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xcff80] = data; |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | switch(offset) |
| 163 | { |
| 164 | case 0x00: // mix register |
| 165 | towns_crtc_mix = data; |
| 166 | break; |
| 167 | case 0x01: // read/write plane select (bit 0-3 write, bit 6-7 read) |
| 168 | towns_vram_wplane = data & 0x0f; |
| 169 | towns_vram_rplane = (data & 0xc0) >> 6; |
| 170 | towns_update_video_banks(space); |
| 171 | logerror("VGA: VRAM wplane select = 0x%02x\n",towns_vram_wplane); |
| 172 | break; |
| 173 | case 0x03: // VRAM page select (bit 5) |
| 174 | towns_vram_page_sel = data & 0x10; |
| 175 | break; |
| 176 | case 0x14: // Kanji offset (high) |
| 177 | towns_kanji_code_h = data & 0x7f; |
| 178 | break; |
| 179 | case 0x15: // Kanji offset (low) |
| 180 | towns_kanji_code_l = data & 0x7f; |
| 181 | // this is a little over the top... |
| 182 | if(towns_kanji_code_h < 0x30) |
| 183 | { |
| 184 | towns_kanji_offset = ((towns_kanji_code_l & 0x1f) << 4) |
| 185 | | (((towns_kanji_code_l - 0x20) & 0x20) << 8) |
| 186 | | (((towns_kanji_code_l - 0x20) & 0x40) << 6) |
| 187 | | ((towns_kanji_code_h & 0x07) << 9); |
| 188 | } |
| 189 | else if(towns_kanji_code_h < 0x70) |
| 190 | { |
| 191 | towns_kanji_offset = ((towns_kanji_code_l & 0x1f) << 4) |
| 192 | + (((towns_kanji_code_l - 0x20) & 0x60) << 8) |
| 193 | + ((towns_kanji_code_h & 0x0f) << 9) |
| 194 | + (((towns_kanji_code_h - 0x30) & 0x70) * 0xc00) |
| 195 | + 0x8000; |
| 196 | } |
| 197 | else |
| 198 | { |
| 199 | towns_kanji_offset = ((towns_kanji_code_l & 0x1f) << 4) |
| 200 | | (((towns_kanji_code_l - 0x20) & 0x20) << 8) |
| 201 | | (((towns_kanji_code_l - 0x20) & 0x40) << 6) |
| 202 | | ((towns_kanji_code_h & 0x07) << 9) |
| 203 | | 0x38000; |
| 204 | } |
| 205 | break; |
| 206 | case 0x19: // ANK CG ROM |
| 207 | towns_ankcg_enable = data & 0x01; |
| 208 | towns_update_video_banks(space); |
| 209 | break; |
| 210 | default: |
| 211 | logerror("VGA: write %08x to invalid or unimplemented memory-mapped port %05x\n",data,0xcff80+offset); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | * port 0x440-0x443 - CRTC |
| 217 | * 0x440 = register select |
| 218 | * 0x442/3 = register data (16-bit) |
| 219 | * |
| 220 | */ |
| 221 | READ8_HANDLER(towns_video_440_r) |
| 222 | { |
| 223 | switch(offset) |
| 224 | { |
| 225 | case 0x00: |
| 226 | return towns_crtc_sel; |
| 227 | case 0x02: |
| 228 | logerror("CRTC: reading register %i (0x442) [%04x]\n",towns_crtc_sel,towns_crtc_reg[towns_crtc_sel]); |
| 229 | return towns_crtc_reg[towns_crtc_sel] & 0x00ff; |
| 230 | case 0x03: |
| 231 | logerror("CRTC: reading register %i (0x443) [%04x]\n",towns_crtc_sel,towns_crtc_reg[towns_crtc_sel]); |
| 232 | return (towns_crtc_reg[towns_crtc_sel] & 0xff00) >> 8; |
| 233 | default: |
| 234 | logerror("VID: read port %04x\n",offset+0x440); |
| 235 | } |
| 236 | return 0x00; |
| 237 | } |
| 238 | |
| 239 | WRITE8_HANDLER(towns_video_440_w) |
| 240 | { |
| 241 | switch(offset) |
| 242 | { |
| 243 | case 0x00: |
| 244 | towns_crtc_sel = data; |
| 245 | break; |
| 246 | case 0x02: |
| 247 | logerror("CRTC: writing register %i (0x442) [%02x]\n",towns_crtc_sel,data); |
| 248 | towns_crtc_reg[towns_crtc_sel] = |
| 249 | (towns_crtc_reg[towns_crtc_sel] & 0xff00) | data; |
| 250 | break; |
| 251 | case 0x03: |
| 252 | logerror("CRTC: writing register %i (0x443) [%02x]\n",towns_crtc_sel,data); |
| 253 | towns_crtc_reg[towns_crtc_sel] = |
| 254 | (towns_crtc_reg[towns_crtc_sel] & 0x00ff) | (data << 8); |
| 255 | break; |
| 256 | default: |
| 257 | logerror("VID: wrote 0x%02x to port %04x\n",data,offset+0x440); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | READ8_HANDLER(towns_video_5c8_r) |
| 262 | { |
| 263 | logerror("VID: read port %04x\n",offset+0x5c8); |
| 264 | switch(offset) |
| 265 | { |
| 266 | case 0x00: // 0x5c8 - disable TVRAM? |
| 267 | if(towns_tvram_enable != 0) |
| 268 | { |
| 269 | towns_tvram_enable = 0; |
| 270 | return 0x80; |
| 271 | } |
| 272 | else |
| 273 | return 0x00; |
| 274 | } |
| 275 | return 0x00; |
| 276 | } |
| 277 | |
| 278 | WRITE8_HANDLER(towns_video_5c8_w) |
| 279 | { |
| 280 | const device_config* dev = devtag_get_device(space->machine,"pic8259_slave"); |
| 281 | switch(offset) |
| 282 | { |
| 283 | case 0x02: // 0x5ca - VSync clear? |
| 284 | pic8259_set_irq_line(dev,3,0); |
| 285 | break; |
| 286 | } |
| 287 | logerror("VID: wrote 0x%02x to port %04x\n",data,offset+0x5c8); |
| 288 | } |
| 289 | |
| 290 | /* Video/CRTC |
| 291 | * |
| 292 | * 0xfd90 - palette colour select |
| 293 | * 0xfd92/4/6 - BRG value |
| 294 | * 0xfd98-9f - degipal(?) |
| 295 | */ |
| 296 | READ8_HANDLER(towns_video_fd90_r) |
| 297 | { |
| 298 | switch(offset) |
| 299 | { |
| 300 | case 0x00: |
| 301 | return towns_palette_select; |
| 302 | case 0x02: |
| 303 | return towns_palette_b[towns_palette_select]; |
| 304 | case 0x04: |
| 305 | return towns_palette_r[towns_palette_select]; |
| 306 | case 0x06: |
| 307 | return towns_palette_g[towns_palette_select]; |
| 308 | case 0x08: |
| 309 | case 0x09: |
| 310 | case 0x0a: |
| 311 | case 0x0b: |
| 312 | case 0x0c: |
| 313 | case 0x0d: |
| 314 | case 0x0e: |
| 315 | case 0x0f: |
| 316 | return towns_degipal[offset-0x08]; |
| 317 | } |
| 318 | // logerror("VID: read port %04x\n",offset+0xfd90); |
| 319 | return 0x00; |
| 320 | } |
| 321 | |
| 322 | WRITE8_HANDLER(towns_video_fd90_w) |
| 323 | { |
| 324 | switch(offset) |
| 325 | { |
| 326 | case 0x00: |
| 327 | towns_palette_select = data; |
| 328 | break; |
| 329 | case 0x02: |
| 330 | towns_palette_b[towns_palette_select] = data; |
| 331 | break; |
| 332 | case 0x04: |
| 333 | towns_palette_r[towns_palette_select] = data; |
| 334 | break; |
| 335 | case 0x06: |
| 336 | towns_palette_g[towns_palette_select] = data; |
| 337 | break; |
| 338 | case 0x08: |
| 339 | case 0x09: |
| 340 | case 0x0a: |
| 341 | case 0x0b: |
| 342 | case 0x0c: |
| 343 | case 0x0d: |
| 344 | case 0x0e: |
| 345 | case 0x0f: |
| 346 | towns_degipal[offset-0x08] = data; |
| 347 | break; |
| 348 | } |
| 349 | logerror("VID: wrote 0x%02x to port %04x\n",data,offset+0xfd90); |
| 350 | } |
| 351 | |
| 352 | READ8_HANDLER(towns_video_ff81_r) |
| 353 | { |
| 354 | return ((towns_vram_rplane << 6) & 0xc0) | towns_vram_wplane; |
| 355 | } |
| 356 | |
| 357 | WRITE8_HANDLER(towns_video_ff81_w) |
| 358 | { |
| 359 | towns_vram_wplane = data & 0x0f; |
| 360 | towns_vram_rplane = (data & 0xc0) >> 6; |
| 361 | towns_update_video_banks(space); |
| 362 | logerror("VGA: VRAM wplane select (I/O) = 0x%02x\n",towns_vram_wplane); |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * Sprite RAM, low memory |
| 367 | * Writing to 0xc8xxx or 0xcaxxx activates TVRAM mode |
| 368 | * Writing to I/O port 0x5c8 disables TVRAM mode |
| 369 | * (bit 7 returns high is TVRAM mode was previously active) |
| 370 | * |
| 371 | * In TVRAM mode: |
| 372 | * 0xc8000-0xc8fff: ASCII text (2 bytes each: ISO646 code, then attribute) |
| 373 | * 0xca000-0xcafff: JIS code |
| 374 | */ |
| 375 | READ8_HANDLER(towns_spriteram_low_r) |
| 376 | { |
| 377 | UINT8* RAM = messram_get_ptr(devtag_get_device(space->machine, "messram")); |
| 378 | UINT8* ROM = memory_region(space->machine,"user"); |
| 379 | |
| 380 | if(offset < 0x1000) |
| 381 | { // 0xc8000-0xc8fff |
| 382 | if(towns_mainmem_enable == 0) |
| 383 | return towns_txtvram[offset]; |
| 384 | else |
| 385 | return RAM[offset + 0xc8000]; |
| 386 | } |
| 387 | if(offset >= 0x1000 && offset < 0x2000) |
| 388 | { // 0xc9000-0xc9fff |
| 389 | return RAM[offset + 0xc9000]; |
| 390 | } |
| 391 | if(offset >= 0x2000 && offset < 0x3000) |
| 392 | { // 0xca000-0xcafff |
| 393 | if(towns_mainmem_enable == 0) |
| 394 | { |
| 395 | if(towns_ankcg_enable != 0 && offset < 0x2800) |
| 396 | return ROM[0x180000 + 0x3d000 + (offset-0x2000)]; |
| 397 | return towns_txtvram[offset]; |
| 398 | } |
| 399 | else |
| 400 | return RAM[offset + 0xca000]; |
| 401 | } |
| 402 | return 0x00; |
| 403 | } |
| 404 | |
| 405 | WRITE8_HANDLER(towns_spriteram_low_w) |
| 406 | { |
| 407 | UINT8* RAM = messram_get_ptr(devtag_get_device(space->machine, "messram")); |
| 408 | if(offset < 0x1000) |
| 409 | { // 0xc8000-0xc8fff |
| 410 | towns_tvram_enable = 1; |
| 411 | if(towns_mainmem_enable == 0) |
| 412 | towns_txtvram[offset] = data; |
| 413 | else |
| 414 | RAM[offset + 0xc8000] = data; |
| 415 | } |
| 416 | if(offset >= 0x1000 && offset < 0x2000) |
| 417 | { |
| 418 | RAM[offset + 0xc9000] = data; |
| 419 | } |
| 420 | if(offset >= 0x2000 && offset < 0x3000) |
| 421 | { // 0xca000-0xcafff |
| 422 | towns_tvram_enable = 1; |
| 423 | if(towns_mainmem_enable == 0) |
| 424 | towns_txtvram[offset] = data; |
| 425 | else |
| 426 | RAM[offset + 0xca000] = data; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | VIDEO_START( towns ) |
| 431 | { |
| 432 | towns_vram_wplane = 0x00; |
| 433 | } |
| 434 | |
| 435 | VIDEO_UPDATE( towns ) |
| 436 | { |
| 437 | int x,y; |
| 438 | UINT8 colour; |
| 439 | UINT32 colourcode; |
| 440 | UINT8 row; // JIS row number |
| 441 | UINT16 code; |
| 442 | int off = 0; |
| 443 | |
| 444 | if(towns_vram_page_sel != 0) |
| 445 | off = 0x20000; |
| 446 | for(y=0;y<480;y++) |
| 447 | { |
| 448 | // off = 0x50 * y; |
| 449 | for(x=0;x<640;x+=2) |
| 450 | { |
| 451 | colour = towns_gfxvram[off] >> 4; |
| 452 | *BITMAP_ADDR32(bitmap,y,x+1) = |
| 453 | (towns_palette_r[colour] << 16) |
| 454 | | (towns_palette_g[colour] << 8) |
| 455 | | (towns_palette_b[colour]); |
| 456 | colour = towns_gfxvram[off] & 0x0f; |
| 457 | *BITMAP_ADDR32(bitmap,y,x) = |
| 458 | (towns_palette_r[colour] << 16) |
| 459 | | (towns_palette_g[colour] << 8) |
| 460 | | (towns_palette_b[colour]); |
| 461 | off++; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | // draw text layer |
| 466 | /* |
| 467 | * Text layer format |
| 468 | * 2 bytes per character at both 0xc8000 and 0xca000 |
| 469 | * 0xc8xxx: Byte 1: ASCII character |
| 470 | * Byte 2: Attributes |
| 471 | * bits 2-0: GRB (or is it BRG?) |
| 472 | * bit 3: Inverse |
| 473 | * bit 4: Blink |
| 474 | * bit 5: high brightness |
| 475 | * bits 7-6: Kanji high/low |
| 476 | * |
| 477 | * If either bits 6 or 7 are high, then a fullwidth Kanji character is displayed |
| 478 | * at this location. The character displayed is represented by a 2-byte |
| 479 | * JIS code at the same offset at 0xca000. |
| 480 | */ |
| 481 | if(towns_tvram_enable != 0) |
| 482 | { |
| 483 | for(y=0;y<40;y++) |
| 484 | { |
| 485 | off = 160 * y; |
| 486 | for(x=0;x<80;x++) |
| 487 | { |
| 488 | colour = towns_txtvram[off+1] & 0x07; |
| 489 | if(towns_txtvram[off+1] & 0x20) |
| 490 | { // Bright |
| 491 | colourcode = (((colour & 0x02) ? 0xfe : 0x00) << 16) |
| 492 | | (((colour & 0x04) ? 0xfe : 0x00) << 8) |
| 493 | | ((colour & 0x01) ? 0xfe : 0x00); |
| 494 | } |
| 495 | else |
| 496 | { |
| 497 | colourcode = (((colour & 0x02) ? 0x7f : 0x00) << 16) |
| 498 | | (((colour & 0x04) ? 0x7f : 0x00) << 8) |
| 499 | | ((colour & 0x01) ? 0x7f : 0x00); |
| 500 | } |
| 501 | |
| 502 | if((towns_txtvram[off+1] & 0xc0) != 0) |
| 503 | { // double width |
| 504 | if(towns_txtvram[off+1] & 0x40) |
| 505 | { |
| 506 | row = (towns_txtvram[off+0x2000] - 32); |
| 507 | code = 0; |
| 508 | if(row <= 8) |
| 509 | { |
| 510 | code = (row & 0x07) * 0x20; |
| 511 | code += ((towns_txtvram[off+0x2001]-32) & 0x1f) |
| 512 | | (((towns_txtvram[off+0x2001]-32) & 0x40) << 2) |
| 513 | | (((towns_txtvram[off+0x2001]-32) & 0x20) << 4); |
| 514 | } |
| 515 | if(row >= 16) // Kanji |
| 516 | { |
| 517 | code = 0x400; |
| 518 | code += ((towns_txtvram[off+0x2001]) & 0x1f) |
| 519 | + (((towns_txtvram[off+0x2001]-32) & 0x60) << 4) |
| 520 | + ((row & 0x0f) << 5) |
| 521 | + (((row-16) & 0x70) * 0x60); |
| 522 | } |
| 523 | drawgfx_transpen_raw(bitmap,cliprect,screen->machine->gfx[1],code, |
| 524 | colourcode, 0,0,x*8,y*16,0); |
| 525 | } |
| 526 | } |
| 527 | else |
| 528 | { |
| 529 | drawgfx_transpen_raw(bitmap,cliprect,screen->machine->gfx[0],towns_txtvram[off], |
| 530 | colourcode, 0,0,x*8,y*16,0); |
| 531 | } |
| 532 | off += 2; |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
src/mess/drivers/fmtowns.c
| r6599 | r6600 | |
| 121 | 121 | #include "devices/flopdrv.h" |
| 122 | 122 | #include "machine/upd71071.h" |
| 123 | 123 | #include "devices/messram.h" |
| 124 | #include "includes/fmtowns.h" |
| 124 | 125 | |
| 125 | 126 | // CD controller IRQ types |
| 126 | 127 | #define TOWNS_CD_IRQ_MPU 1 |
| r6599 | r6600 | |
| 130 | 131 | static UINT8 nmi_mask; |
| 131 | 132 | static UINT8 compat_mode; |
| 132 | 133 | static UINT8 towns_system_port; |
| 133 | | static UINT32 towns_ankcg_enable; |
| 134 | | static UINT32 towns_mainmem_enable; |
| 134 | UINT32 towns_ankcg_enable; |
| 135 | UINT32 towns_mainmem_enable; |
| 135 | 136 | static UINT32 towns_ram_enable; |
| 136 | | static UINT32* towns_vram; |
| 137 | 137 | static UINT8* towns_cmos; |
| 138 | | static UINT8* towns_gfxvram; |
| 139 | | static UINT8* towns_txtvram; |
| 140 | | static UINT8 towns_vram_wplane; |
| 141 | | static UINT8 towns_vram_rplane; |
| 142 | | static UINT8 towns_vram_page_sel; |
| 143 | | static UINT8 towns_palette_select; |
| 144 | | static UINT8 towns_palette_r[256]; |
| 145 | | static UINT8 towns_palette_g[256]; |
| 146 | | static UINT8 towns_palette_b[256]; |
| 147 | | static UINT8 towns_degipal[8]; |
| 148 | | static UINT16 towns_kanji_offset; |
| 149 | | static UINT8 towns_kanji_code_h; |
| 150 | | static UINT8 towns_kanji_code_l; |
| 138 | UINT32* towns_vram; |
| 139 | UINT8* towns_gfxvram; |
| 140 | UINT8* towns_txtvram; |
| 151 | 141 | static int towns_selected_drive; |
| 152 | 142 | static UINT8 towns_fdc_irq6mask; |
| 153 | 143 | static UINT8* towns_serial_rom; |
| r6599 | r6600 | |
| 159 | 149 | static UINT8 towns_rtc_reg[16]; |
| 160 | 150 | static emu_timer* towns_rtc_timer; |
| 161 | 151 | static UINT8 towns_timer_mask; |
| 162 | | static UINT8 towns_crtc_mix; |
| 163 | 152 | static UINT16 towns_machine_id; // default is 0x0101 |
| 164 | 153 | static UINT8 towns_kb_status; |
| 165 | 154 | static UINT8 towns_kb_irq1_enable; |
| 166 | 155 | static UINT8 towns_kb_output; // key output |
| 167 | 156 | static UINT8 towns_kb_extend; // extended key output |
| 168 | 157 | static emu_timer* towns_kb_timer; |
| 169 | | static UINT8 towns_crtc_sel; // selected CRTC register |
| 170 | | static UINT16 towns_crtc_reg[32]; |
| 171 | | static UINT8 towns_tvram_enable; |
| 172 | 158 | |
| 173 | 159 | static struct towns_cdrom_controller |
| 174 | 160 | { |
| r6599 | r6600 | |
| 189 | 175 | emu_timer* read_timer; |
| 190 | 176 | } towns_cd; |
| 191 | 177 | |
| 192 | | static void towns_update_video_banks(const address_space* space); |
| 193 | 178 | static PIC8259_SET_INT_LINE( towns_pic_irq ); |
| 194 | 179 | |
| 195 | 180 | INLINE UINT8 byte_to_bcd(UINT8 val) |
| r6599 | r6600 | |
| 512 | 497 | } |
| 513 | 498 | |
| 514 | 499 | /* |
| 515 | | * port 0x440-0x443 - CRTC |
| 516 | | * 0x440 = register select |
| 517 | | * 0x442/3 = register data (16-bit) |
| 518 | | * |
| 519 | | */ |
| 520 | | static READ8_HANDLER(towns_video_440_r) |
| 521 | | { |
| 522 | | switch(offset) |
| 523 | | { |
| 524 | | case 0x00: |
| 525 | | return towns_crtc_sel; |
| 526 | | case 0x02: |
| 527 | | logerror("CRTC: reading register %i (0x442) [%04x]\n",towns_crtc_sel,towns_crtc_reg[towns_crtc_sel]); |
| 528 | | return towns_crtc_reg[towns_crtc_sel] & 0x00ff; |
| 529 | | case 0x03: |
| 530 | | logerror("CRTC: reading register %i (0x443) [%04x]\n",towns_crtc_sel,towns_crtc_reg[towns_crtc_sel]); |
| 531 | | return (towns_crtc_reg[towns_crtc_sel] & 0xff00) >> 8; |
| 532 | | default: |
| 533 | | logerror("VID: read port %04x\n",offset+0x440); |
| 534 | | } |
| 535 | | return 0x00; |
| 536 | | } |
| 537 | | |
| 538 | | static WRITE8_HANDLER(towns_video_440_w) |
| 539 | | { |
| 540 | | switch(offset) |
| 541 | | { |
| 542 | | case 0x00: |
| 543 | | towns_crtc_sel = data; |
| 544 | | break; |
| 545 | | case 0x02: |
| 546 | | logerror("CRTC: writing register %i (0x442) [%02x]\n",towns_crtc_sel,data); |
| 547 | | towns_crtc_reg[towns_crtc_sel] = |
| 548 | | (towns_crtc_reg[towns_crtc_sel] & 0xff00) | data; |
| 549 | | break; |
| 550 | | case 0x03: |
| 551 | | logerror("CRTC: writing register %i (0x443) [%02x]\n",towns_crtc_sel,data); |
| 552 | | towns_crtc_reg[towns_crtc_sel] = |
| 553 | | (towns_crtc_reg[towns_crtc_sel] & 0x00ff) | (data << 8); |
| 554 | | break; |
| 555 | | default: |
| 556 | | logerror("VID: wrote 0x%02x to port %04x\n",data,offset+0x440); |
| 557 | | } |
| 558 | | } |
| 559 | | |
| 560 | | static READ8_HANDLER(towns_video_5c8_r) |
| 561 | | { |
| 562 | | logerror("VID: read port %04x\n",offset+0x5c8); |
| 563 | | switch(offset) |
| 564 | | { |
| 565 | | case 0x00: // 0x5c8 - disable TVRAM? |
| 566 | | if(towns_tvram_enable != 0) |
| 567 | | { |
| 568 | | towns_tvram_enable = 0; |
| 569 | | return 0x80; |
| 570 | | } |
| 571 | | else |
| 572 | | return 0x00; |
| 573 | | } |
| 574 | | return 0x00; |
| 575 | | } |
| 576 | | |
| 577 | | static WRITE8_HANDLER(towns_video_5c8_w) |
| 578 | | { |
| 579 | | const device_config* dev = devtag_get_device(space->machine,"pic8259_slave"); |
| 580 | | switch(offset) |
| 581 | | { |
| 582 | | case 0x02: // 0x5ca - VSync clear? |
| 583 | | pic8259_set_irq_line(dev,3,0); |
| 584 | | break; |
| 585 | | } |
| 586 | | logerror("VID: wrote 0x%02x to port %04x\n",data,offset+0x5c8); |
| 587 | | } |
| 588 | | |
| 589 | | /* Video/CRTC |
| 590 | | * |
| 591 | | * 0xfd90 - palette colour select |
| 592 | | * 0xfd92/4/6 - BRG value |
| 593 | | * 0xfd98-9f - degipal(?) |
| 594 | | */ |
| 595 | | static READ8_HANDLER(towns_video_fd90_r) |
| 596 | | { |
| 597 | | switch(offset) |
| 598 | | { |
| 599 | | case 0x00: |
| 600 | | return towns_palette_select; |
| 601 | | case 0x02: |
| 602 | | return towns_palette_b[towns_palette_select]; |
| 603 | | case 0x04: |
| 604 | | return towns_palette_r[towns_palette_select]; |
| 605 | | case 0x06: |
| 606 | | return towns_palette_g[towns_palette_select]; |
| 607 | | case 0x08: |
| 608 | | case 0x09: |
| 609 | | case 0x0a: |
| 610 | | case 0x0b: |
| 611 | | case 0x0c: |
| 612 | | case 0x0d: |
| 613 | | case 0x0e: |
| 614 | | case 0x0f: |
| 615 | | return towns_degipal[offset-0x08]; |
| 616 | | } |
| 617 | | // logerror("VID: read port %04x\n",offset+0xfd90); |
| 618 | | return 0x00; |
| 619 | | } |
| 620 | | |
| 621 | | static WRITE8_HANDLER(towns_video_fd90_w) |
| 622 | | { |
| 623 | | switch(offset) |
| 624 | | { |
| 625 | | case 0x00: |
| 626 | | towns_palette_select = data; |
| 627 | | break; |
| 628 | | case 0x02: |
| 629 | | towns_palette_b[towns_palette_select] = data; |
| 630 | | break; |
| 631 | | case 0x04: |
| 632 | | towns_palette_r[towns_palette_select] = data; |
| 633 | | break; |
| 634 | | case 0x06: |
| 635 | | towns_palette_g[towns_palette_select] = data; |
| 636 | | break; |
| 637 | | case 0x08: |
| 638 | | case 0x09: |
| 639 | | case 0x0a: |
| 640 | | case 0x0b: |
| 641 | | case 0x0c: |
| 642 | | case 0x0d: |
| 643 | | case 0x0e: |
| 644 | | case 0x0f: |
| 645 | | towns_degipal[offset-0x08] = data; |
| 646 | | break; |
| 647 | | } |
| 648 | | logerror("VID: wrote 0x%02x to port %04x\n",data,offset+0xfd90); |
| 649 | | } |
| 650 | | |
| 651 | | /* |
| 652 | 500 | * Port 0x600-0x607 - Keyboard controller (8042 MCU) |
| 653 | 501 | * |
| 654 | 502 | * Sends two-byte code on each key press and release. |
| r6599 | r6600 | |
| 895 | 743 | towns_cmos[offset] = data; |
| 896 | 744 | } |
| 897 | 745 | |
| 898 | | static READ8_HANDLER( towns_gfx_r ) |
| 746 | void towns_update_video_banks(const address_space* space) |
| 899 | 747 | { |
| 900 | | if(towns_mainmem_enable != 0) |
| 901 | | return messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xc0000]; |
| 902 | | |
| 903 | | if(towns_vram_page_sel != 0) |
| 904 | | offset += 0x20000; |
| 905 | | |
| 906 | | return 0; |
| 907 | | } |
| 908 | | |
| 909 | | static WRITE8_HANDLER( towns_gfx_w ) |
| 910 | | { |
| 911 | | if(towns_mainmem_enable != 0) |
| 912 | | { |
| 913 | | messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xc0000] = data; |
| 914 | | return; |
| 915 | | } |
| 916 | | offset = offset << 2; |
| 917 | | if(towns_vram_page_sel != 0) |
| 918 | | offset += 0x20000; |
| 919 | | if(towns_vram_wplane & 0x08) |
| 920 | | { |
| 921 | | towns_gfxvram[offset] &= ~0x88; |
| 922 | | towns_gfxvram[offset] |= ((data & 0x80) >> 4) | ((data & 0x40) << 1); |
| 923 | | towns_gfxvram[offset + 1] &= ~0x88; |
| 924 | | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 2) | ((data & 0x10) << 3); |
| 925 | | towns_gfxvram[offset + 2] &= ~0x88; |
| 926 | | towns_gfxvram[offset + 2] |= ((data & 0x08)) | ((data & 0x04) << 5); |
| 927 | | towns_gfxvram[offset + 3] &= ~0x88; |
| 928 | | towns_gfxvram[offset + 3] |= ((data & 0x02) << 2) | ((data & 0x01) << 7); |
| 929 | | } |
| 930 | | if(towns_vram_wplane & 0x04) |
| 931 | | { |
| 932 | | towns_gfxvram[offset] &= ~0x44; |
| 933 | | towns_gfxvram[offset] |= ((data & 0x80) >> 5) | ((data & 0x40)); |
| 934 | | towns_gfxvram[offset + 1] &= ~0x44; |
| 935 | | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 3) | ((data & 0x10) << 2); |
| 936 | | towns_gfxvram[offset + 2] &= ~0x44; |
| 937 | | towns_gfxvram[offset + 2] |= ((data & 0x08) >> 1) | ((data & 0x04) << 4); |
| 938 | | towns_gfxvram[offset + 3] &= ~0x44; |
| 939 | | towns_gfxvram[offset + 3] |= ((data & 0x02) << 1) | ((data & 0x01) << 6); |
| 940 | | } |
| 941 | | if(towns_vram_wplane & 0x02) |
| 942 | | { |
| 943 | | towns_gfxvram[offset] &= ~0x22; |
| 944 | | towns_gfxvram[offset] |= ((data & 0x80) >> 6) | ((data & 0x40) >> 1); |
| 945 | | towns_gfxvram[offset + 1] &= ~0x22; |
| 946 | | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 4) | ((data & 0x10) << 1); |
| 947 | | towns_gfxvram[offset + 2] &= ~0x22; |
| 948 | | towns_gfxvram[offset + 2] |= ((data & 0x08) >> 2) | ((data & 0x04) << 3); |
| 949 | | towns_gfxvram[offset + 3] &= ~0x22; |
| 950 | | towns_gfxvram[offset + 3] |= ((data & 0x02)) | ((data & 0x01) << 5); |
| 951 | | } |
| 952 | | if(towns_vram_wplane & 0x01) |
| 953 | | { |
| 954 | | towns_gfxvram[offset] &= ~0x11; |
| 955 | | towns_gfxvram[offset] |= ((data & 0x80) >> 7) | ((data & 0x40) >> 2); |
| 956 | | towns_gfxvram[offset + 1] &= ~0x11; |
| 957 | | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 5) | ((data & 0x10)); |
| 958 | | towns_gfxvram[offset + 2] &= ~0x11; |
| 959 | | towns_gfxvram[offset + 2] |= ((data & 0x08) >> 3) | ((data & 0x04) << 2); |
| 960 | | towns_gfxvram[offset + 3] &= ~0x11; |
| 961 | | towns_gfxvram[offset + 3] |= ((data & 0x02) >> 1) | ((data & 0x01) << 4); |
| 962 | | } |
| 963 | | } |
| 964 | | |
| 965 | | static READ8_HANDLER( towns_video_cff80_r ) |
| 966 | | { |
| 967 | | UINT8* ROM = memory_region(space->machine,"user"); |
| 968 | | if(towns_mainmem_enable != 0) |
| 969 | | return messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xcff80]; |
| 970 | | |
| 971 | | switch(offset) |
| 972 | | { |
| 973 | | case 0x00: // mix register |
| 974 | | return towns_crtc_mix; |
| 975 | | case 0x01: // read/write plane select (bit 0-3 write, bit 6-7 read) |
| 976 | | return ((towns_vram_rplane << 6) & 0xc0) | towns_vram_wplane; |
| 977 | | case 0x03: // VRAM page select (bit 5) |
| 978 | | if(towns_vram_page_sel != 0) |
| 979 | | return 0x10; |
| 980 | | else |
| 981 | | return 0x00; |
| 982 | | case 0x16: // Kanji character data |
| 983 | | return ROM[(towns_kanji_offset << 1) + 0x180000]; |
| 984 | | case 0x17: // Kanji character data |
| 985 | | return ROM[(towns_kanji_offset++ << 1) + 0x180001]; |
| 986 | | case 0x19: // ANK CG ROM |
| 987 | | if(towns_ankcg_enable != 0) |
| 988 | | return 0x01; |
| 989 | | else |
| 990 | | return 0x00; |
| 991 | | default: |
| 992 | | logerror("VGA: read from invalid or unimplemented memory-mapped port %05x\n",0xcff80+offset*4); |
| 993 | | } |
| 994 | | |
| 995 | | return 0; |
| 996 | | } |
| 997 | | |
| 998 | | static WRITE8_HANDLER( towns_video_cff80_w ) |
| 999 | | { |
| 1000 | | if(towns_mainmem_enable != 0) |
| 1001 | | { |
| 1002 | | messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xcff80] = data; |
| 1003 | | return; |
| 1004 | | } |
| 1005 | | |
| 1006 | | switch(offset) |
| 1007 | | { |
| 1008 | | case 0x00: // mix register |
| 1009 | | towns_crtc_mix = data; |
| 1010 | | break; |
| 1011 | | case 0x01: // read/write plane select (bit 0-3 write, bit 6-7 read) |
| 1012 | | towns_vram_wplane = data & 0x0f; |
| 1013 | | towns_vram_rplane = (data & 0xc0) >> 6; |
| 1014 | | towns_update_video_banks(space); |
| 1015 | | logerror("VGA: VRAM wplane select = 0x%02x\n",towns_vram_wplane); |
| 1016 | | break; |
| 1017 | | case 0x03: // VRAM page select (bit 5) |
| 1018 | | towns_vram_page_sel = data & 0x10; |
| 1019 | | break; |
| 1020 | | case 0x14: // Kanji offset (high) |
| 1021 | | towns_kanji_code_h = data & 0x7f; |
| 1022 | | break; |
| 1023 | | case 0x15: // Kanji offset (low) |
| 1024 | | towns_kanji_code_l = data & 0x7f; |
| 1025 | | // this is a little over the top... |
| 1026 | | if(towns_kanji_code_h < 0x30) |
| 1027 | | { |
| 1028 | | towns_kanji_offset = ((towns_kanji_code_l & 0x1f) << 4) |
| 1029 | | | (((towns_kanji_code_l - 0x20) & 0x20) << 8) |
| 1030 | | | (((towns_kanji_code_l - 0x20) & 0x40) << 6) |
| 1031 | | | ((towns_kanji_code_h & 0x07) << 9); |
| 1032 | | } |
| 1033 | | else if(towns_kanji_code_h < 0x70) |
| 1034 | | { |
| 1035 | | towns_kanji_offset = ((towns_kanji_code_l & 0x1f) << 4) |
| 1036 | | + (((towns_kanji_code_l - 0x20) & 0x60) << 8) |
| 1037 | | + ((towns_kanji_code_h & 0x0f) << 9) |
| 1038 | | + (((towns_kanji_code_h - 0x30) & 0x70) * 0xc00) |
| 1039 | | + 0x8000; |
| 1040 | | } |
| 1041 | | else |
| 1042 | | { |
| 1043 | | towns_kanji_offset = ((towns_kanji_code_l & 0x1f) << 4) |
| 1044 | | | (((towns_kanji_code_l - 0x20) & 0x20) << 8) |
| 1045 | | | (((towns_kanji_code_l - 0x20) & 0x40) << 6) |
| 1046 | | | ((towns_kanji_code_h & 0x07) << 9) |
| 1047 | | | 0x38000; |
| 1048 | | } |
| 1049 | | break; |
| 1050 | | case 0x19: // ANK CG ROM |
| 1051 | | towns_ankcg_enable = data & 0x01; |
| 1052 | | towns_update_video_banks(space); |
| 1053 | | break; |
| 1054 | | default: |
| 1055 | | logerror("VGA: write %08x to invalid or unimplemented memory-mapped port %05x\n",data,0xcff80+offset); |
| 1056 | | } |
| 1057 | | } |
| 1058 | | |
| 1059 | | static void towns_update_video_banks(const address_space* space) |
| 1060 | | { |
| 1061 | 748 | UINT8* ROM; |
| 1062 | 749 | |
| 1063 | 750 | if(towns_mainmem_enable != 0) // first MB is RAM |
| r6599 | r6600 | |
| 1108 | 795 | } |
| 1109 | 796 | } |
| 1110 | 797 | |
| 1111 | | static READ8_HANDLER( towns_gfx_high_r ) |
| 1112 | | { |
| 1113 | | return towns_gfxvram[offset]; |
| 1114 | | } |
| 1115 | | |
| 1116 | | static WRITE8_HANDLER( towns_gfx_high_w ) |
| 1117 | | { |
| 1118 | | towns_gfxvram[offset] = data; |
| 1119 | | } |
| 1120 | | |
| 1121 | 798 | static READ8_HANDLER( towns_sys480_r ) |
| 1122 | 799 | { |
| 1123 | 800 | if(towns_system_port & 0x02) |
| r6599 | r6600 | |
| 1152 | 829 | return 0; |
| 1153 | 830 | } |
| 1154 | 831 | |
| 1155 | | static READ8_HANDLER(towns_video_ff81_r) |
| 1156 | | { |
| 1157 | | return ((towns_vram_rplane << 6) & 0xc0) | towns_vram_wplane; |
| 1158 | | } |
| 1159 | | |
| 1160 | | static WRITE8_HANDLER(towns_video_ff81_w) |
| 1161 | | { |
| 1162 | | towns_vram_wplane = data & 0x0f; |
| 1163 | | towns_vram_rplane = (data & 0xc0) >> 6; |
| 1164 | | towns_update_video_banks(space); |
| 1165 | | logerror("VGA: VRAM wplane select (I/O) = 0x%02x\n",towns_vram_wplane); |
| 1166 | | } |
| 1167 | | |
| 1168 | 832 | /* |
| 1169 | 833 | * I/O ports 0x4c0-0x4cf |
| 1170 | 834 | * CD-ROM driver (custom?) |
| r6599 | r6600 | |
| 1727 | 1391 | } |
| 1728 | 1392 | |
| 1729 | 1393 | |
| 1730 | | /* |
| 1731 | | * Sprite RAM, low memory |
| 1732 | | * Writing to 0xc8xxx or 0xcaxxx activates TVRAM mode |
| 1733 | | * Writing to I/O port 0x5c8 disables TVRAM mode |
| 1734 | | * (bit 7 returns high is TVRAM mode was previously active) |
| 1735 | | * |
| 1736 | | * In TVRAM mode: |
| 1737 | | * 0xc8000-0xc8fff: ASCII text (2 bytes each: ISO646 code, then attribute) |
| 1738 | | * 0xca000-0xcafff: JIS code |
| 1739 | | */ |
| 1740 | | static READ8_HANDLER(towns_spriteram_low_r) |
| 1741 | | { |
| 1742 | | UINT8* RAM = messram_get_ptr(devtag_get_device(space->machine, "messram")); |
| 1743 | | UINT8* ROM = memory_region(space->machine,"user"); |
| 1744 | | |
| 1745 | | if(offset < 0x1000) |
| 1746 | | { // 0xc8000-0xc8fff |
| 1747 | | if(towns_mainmem_enable == 0) |
| 1748 | | return towns_txtvram[offset]; |
| 1749 | | else |
| 1750 | | return RAM[offset + 0xc8000]; |
| 1751 | | } |
| 1752 | | if(offset >= 0x1000 && offset < 0x2000) |
| 1753 | | { // 0xc9000-0xc9fff |
| 1754 | | return RAM[offset + 0xc9000]; |
| 1755 | | } |
| 1756 | | if(offset >= 0x2000 && offset < 0x3000) |
| 1757 | | { // 0xca000-0xcafff |
| 1758 | | if(towns_mainmem_enable == 0) |
| 1759 | | { |
| 1760 | | if(towns_ankcg_enable != 0 && offset < 0x2800) |
| 1761 | | return ROM[0x180000 + 0x3d000 + (offset-0x2000)]; |
| 1762 | | return towns_txtvram[offset]; |
| 1763 | | } |
| 1764 | | else |
| 1765 | | return RAM[offset + 0xca000]; |
| 1766 | | } |
| 1767 | | return 0x00; |
| 1768 | | } |
| 1769 | | |
| 1770 | | static WRITE8_HANDLER(towns_spriteram_low_w) |
| 1771 | | { |
| 1772 | | UINT8* RAM = messram_get_ptr(devtag_get_device(space->machine, "messram")); |
| 1773 | | if(offset < 0x1000) |
| 1774 | | { // 0xc8000-0xc8fff |
| 1775 | | towns_tvram_enable = 1; |
| 1776 | | if(towns_mainmem_enable == 0) |
| 1777 | | towns_txtvram[offset] = data; |
| 1778 | | else |
| 1779 | | RAM[offset + 0xc8000] = data; |
| 1780 | | } |
| 1781 | | if(offset >= 0x1000 && offset < 0x2000) |
| 1782 | | { |
| 1783 | | RAM[offset + 0xc9000] = data; |
| 1784 | | } |
| 1785 | | if(offset >= 0x2000 && offset < 0x3000) |
| 1786 | | { // 0xca000-0xcafff |
| 1787 | | towns_tvram_enable = 1; |
| 1788 | | if(towns_mainmem_enable == 0) |
| 1789 | | towns_txtvram[offset] = data; |
| 1790 | | else |
| 1791 | | RAM[offset + 0xca000] = data; |
| 1792 | | } |
| 1793 | | } |
| 1794 | | |
| 1795 | | |
| 1796 | 1394 | /* CMOS RTC |
| 1797 | 1395 | * 0x70: Data port |
| 1798 | 1396 | * 0x80: Register select |
| r6599 | r6600 | |
| 2231 | 1829 | towns_mainmem_enable = 0x00; |
| 2232 | 1830 | towns_ram_enable = 0x00; |
| 2233 | 1831 | towns_update_video_banks(cpu_get_address_space(cputag_get_cpu(machine,"maincpu"),ADDRESS_SPACE_PROGRAM)); |
| 2234 | | towns_vram_wplane = 0x00; |
| 2235 | 1832 | towns_kb_status = 0x18; |
| 2236 | 1833 | towns_kb_irq1_enable = 0; |
| 2237 | 1834 | towns_cd.status = 0x01; // CDROM controller ready |
| r6599 | r6600 | |
| 2240 | 1837 | timer_adjust_periodic(towns_kb_timer,attotime_zero,0,ATTOTIME_IN_MSEC(10)); |
| 2241 | 1838 | } |
| 2242 | 1839 | |
| 2243 | | static VIDEO_START( towns ) |
| 2244 | | { |
| 2245 | | } |
| 2246 | | |
| 2247 | | static VIDEO_UPDATE( towns ) |
| 2248 | | { |
| 2249 | | int x,y; |
| 2250 | | UINT8 colour; |
| 2251 | | UINT32 colourcode; |
| 2252 | | UINT8 row; // JIS row number |
| 2253 | | UINT16 code; |
| 2254 | | int off = 0; |
| 2255 | | |
| 2256 | | if(towns_vram_page_sel != 0) |
| 2257 | | off = 0x20000; |
| 2258 | | for(y=0;y<480;y++) |
| 2259 | | { |
| 2260 | | // off = 0x50 * y; |
| 2261 | | for(x=0;x<640;x+=2) |
| 2262 | | { |
| 2263 | | colour = towns_gfxvram[off] >> 4; |
| 2264 | | *BITMAP_ADDR32(bitmap,y,x+1) = |
| 2265 | | (towns_palette_r[colour] << 16) |
| 2266 | | | (towns_palette_g[colour] << 8) |
| 2267 | | | (towns_palette_b[colour]); |
| 2268 | | colour = towns_gfxvram[off] & 0x0f; |
| 2269 | | *BITMAP_ADDR32(bitmap,y,x) = |
| 2270 | | (towns_palette_r[colour] << 16) |
| 2271 | | | (towns_palette_g[colour] << 8) |
| 2272 | | | (towns_palette_b[colour]); |
| 2273 | | off++; |
| 2274 | | } |
| 2275 | | } |
| 2276 | | |
| 2277 | | // draw text layer |
| 2278 | | /* |
| 2279 | | * Text layer format |
| 2280 | | * 2 bytes per character at both 0xc8000 and 0xca000 |
| 2281 | | * 0xc8xxx: Byte 1: ASCII character |
| 2282 | | * Byte 2: Attributes |
| 2283 | | * bits 2-0: GRB (or is it BRG?) |
| 2284 | | * bit 3: Inverse |
| 2285 | | * bit 4: Blink |
| 2286 | | * bit 5: high brightness |
| 2287 | | * bits 7-6: Kanji high/low |
| 2288 | | * |
| 2289 | | * If either bits 6 or 7 are high, then a fullwidth Kanji character is displayed |
| 2290 | | * at this location. The character displayed is represented by a 2-byte |
| 2291 | | * JIS code at the same offset at 0xca000. |
| 2292 | | */ |
| 2293 | | if(towns_tvram_enable != 0) |
| 2294 | | { |
| 2295 | | for(y=0;y<40;y++) |
| 2296 | | { |
| 2297 | | off = 160 * y; |
| 2298 | | for(x=0;x<80;x++) |
| 2299 | | { |
| 2300 | | colour = towns_txtvram[off+1] & 0x07; |
| 2301 | | if(towns_txtvram[off+1] & 0x20) |
| 2302 | | { // Bright |
| 2303 | | colourcode = (((colour & 0x02) ? 0xfe : 0x00) << 16) |
| 2304 | | | (((colour & 0x04) ? 0xfe : 0x00) << 8) |
| 2305 | | | ((colour & 0x01) ? 0xfe : 0x00); |
| 2306 | | } |
| 2307 | | else |
| 2308 | | { |
| 2309 | | colourcode = (((colour & 0x02) ? 0x7f : 0x00) << 16) |
| 2310 | | | (((colour & 0x04) ? 0x7f : 0x00) << 8) |
| 2311 | | | ((colour & 0x01) ? 0x7f : 0x00); |
| 2312 | | } |
| 2313 | | |
| 2314 | | if((towns_txtvram[off+1] & 0xc0) != 0) |
| 2315 | | { // double width |
| 2316 | | if(towns_txtvram[off+1] & 0x40) |
| 2317 | | { |
| 2318 | | row = (towns_txtvram[off+0x2000] - 32); |
| 2319 | | code = 0; |
| 2320 | | if(row <= 8) |
| 2321 | | { |
| 2322 | | code = (row & 0x07) * 0x20; |
| 2323 | | code += ((towns_txtvram[off+0x2001]-32) & 0x1f) |
| 2324 | | | (((towns_txtvram[off+0x2001]-32) & 0x40) << 2) |
| 2325 | | | (((towns_txtvram[off+0x2001]-32) & 0x20) << 4); |
| 2326 | | } |
| 2327 | | if(row >= 16) // Kanji |
| 2328 | | { |
| 2329 | | code = 0x400; |
| 2330 | | code += ((towns_txtvram[off+0x2001]) & 0x1f) |
| 2331 | | + (((towns_txtvram[off+0x2001]-32) & 0x60) << 4) |
| 2332 | | + ((row & 0x0f) << 5) |
| 2333 | | + (((row-16) & 0x70) * 0x60); |
| 2334 | | } |
| 2335 | | drawgfx_transpen_raw(bitmap,cliprect,screen->machine->gfx[1],code, |
| 2336 | | colourcode, 0,0,x*8,y*16,0); |
| 2337 | | } |
| 2338 | | } |
| 2339 | | else |
| 2340 | | { |
| 2341 | | drawgfx_transpen_raw(bitmap,cliprect,screen->machine->gfx[0],towns_txtvram[off], |
| 2342 | | colourcode, 0,0,x*8,y*16,0); |
| 2343 | | } |
| 2344 | | off += 2; |
| 2345 | | } |
| 2346 | | } |
| 2347 | | } |
| 2348 | | |
| 2349 | | return 0; |
| 2350 | | } |
| 2351 | | |
| 2352 | 1840 | static const struct pit8253_config towns_pit8253_config = |
| 2353 | 1841 | { |
| 2354 | 1842 | { |