2 * FM77AV/FM16β ALU [mb61vh010.cpp]
3 * of Fujitsu MB61VH010/011
5 * Author: K.Ohta <whatisthis.sowhat _at_ gmail.com>
8 * Mar 28, 2015 : Initial
12 #include "mb61vh010.h"
15 MB61VH010::MB61VH010(VM *parent_vm, EMU *parent_emu) : DEVICE(parent_vm, parent_emu)
21 MB61VH010::~MB61VH010()
25 uint8 MB61VH010::do_read(uint32 addr, uint32 bank)
30 if(((1 << bank) & read_signal(SIG_DISPLAY_MULTIPAGE)) != 0) return 0xff;
31 //if(is_400line) offset = 0x8000;
34 if((addr & 0xffff) < 0x8000) {
35 raddr = (addr & 0x7fff) | (0x8000 * bank);
36 return target->read_data8(raddr + DISPLAY_VRAM_DIRECT_ACCESS);
40 raddr = (addr & 0x3fff) | (0x4000 * bank);
41 return target->read_data8(raddr + DISPLAY_VRAM_DIRECT_ACCESS);
46 uint8 MB61VH010::do_write(uint32 addr, uint32 bank, uint8 data)
51 if(((1 << bank) & read_signal(SIG_DISPLAY_MULTIPAGE)) != 0) return 0xff;
52 if((command_reg & 0x40) != 0) { // Calculate before writing
53 readdata = do_read(addr, bank);
55 if((command_reg & 0x20) != 0) { // NAND
56 readdata = readdata & cmp_status_reg;
57 data = data & ~cmp_status_reg;
58 readdata = readdata | data;
60 readdata = readdata & ~cmp_status_reg;
61 data = data & cmp_status_reg;
62 readdata = readdata | data;
68 if((addr & 0xffff) < 0x8000) {
69 raddr = (addr & 0x7fff) | (0x8000 * bank);
70 target->write_data8(raddr + DISPLAY_VRAM_DIRECT_ACCESS, readdata);
73 raddr = (addr & 0x3fff) | (0x4000 * bank);
74 target->write_data8(raddr + DISPLAY_VRAM_DIRECT_ACCESS, readdata);
80 uint8 MB61VH010::do_pset(uint32 addr)
83 uint32 raddr = addr; // Use banked ram.
86 int planes_b = planes;
88 if(planes_b >= 4) planes_b = 4;
89 for(i = 0; i < planes_b; i++) {
90 if((bank_disable_reg & (1 << i)) != 0) {
93 if((color_reg & (1 << i)) == 0) {
99 srcdata = do_read(addr, i);
100 bitmask = bitmask & ~mask_reg;
101 srcdata = srcdata & mask_reg;
102 srcdata = srcdata | bitmask;
103 do_write(addr, i, srcdata);
108 uint8 MB61VH010::do_blank(uint32 addr)
113 if(planes >= 4) planes = 4;
114 for(i = 0; i < planes; i++) {
115 if((bank_disable_reg & (1 << i)) != 0) {
118 srcdata = do_read(addr, i);
119 srcdata = srcdata & mask_reg;
120 do_write(addr, i, srcdata);
125 uint8 MB61VH010::do_or(uint32 addr)
131 if(planes >= 4) planes = 4;
132 for(i = 0; i < planes; i++) {
133 if((bank_disable_reg & (1 << i)) != 0) {
136 srcdata = do_read(addr, i);
137 if((color_reg & (1 << i)) == 0) {
138 bitmask = srcdata; // srcdata | 0x00
140 bitmask = 0xff; // srcdata | 0xff
142 bitmask = bitmask & ~mask_reg;
143 srcdata = (srcdata & mask_reg) | bitmask;
144 do_write(addr, i, srcdata);
149 uint8 MB61VH010::do_and(uint32 addr)
155 if(planes >= 4) planes = 4;
156 for(i = 0; i < planes; i++) {
157 if((bank_disable_reg & (1 << i)) != 0) {
160 srcdata = do_read(addr, i);
161 if((color_reg & (1 << i)) == 0) {
162 bitmask = 0x00; // srcdata & 0x00
164 bitmask = srcdata; // srcdata & 0xff;
166 bitmask = bitmask & ~mask_reg;
167 srcdata = (srcdata & mask_reg) | bitmask;
168 do_write(addr, i, srcdata);
173 uint8 MB61VH010::do_xor(uint32 addr)
179 if(planes >= 4) planes = 4;
180 for(i = 0; i < planes; i++) {
181 if((bank_disable_reg & (1 << i)) != 0) {
184 srcdata = do_read(addr, i);
185 if((color_reg & (1 << i)) == 0) {
186 bitmask = srcdata ^ 0x00;
188 bitmask = srcdata ^ 0xff;
190 bitmask = bitmask & ~mask_reg;
191 srcdata = (srcdata & mask_reg) | bitmask;
192 do_write(addr, i, srcdata);
197 uint8 MB61VH010::do_not(uint32 addr)
203 if(planes >= 4) planes = 4;
204 for(i = 0; i < planes; i++) {
205 if((bank_disable_reg & (1 << i)) != 0) {
208 srcdata = do_read(addr, i);
211 bitmask = bitmask & ~mask_reg;
212 srcdata = (srcdata & mask_reg) | bitmask;
213 do_write(addr, i, srcdata);
219 uint8 MB61VH010::do_tilepaint(uint32 addr)
224 //printf("Tilepaint CMD=%02x, ADDR=%04x Planes=%d, tile_reg=(%02x %02x %02x %02x)\n",
225 // command_reg, addr, planes, tile_reg[0], tile_reg[1], tile_reg[2], tile_reg[3]);
226 if(planes >= 4) planes = 4;
227 for(i = 0; i < planes; i++) {
228 if((bank_disable_reg & (1 << i)) != 0) {
231 srcdata = do_read(addr, i);
232 bitmask = tile_reg[i] & ~mask_reg;
233 srcdata = (srcdata & mask_reg) | bitmask;
234 do_write(addr, i, srcdata);
239 uint8 MB61VH010::do_compare(uint32 addr)
241 uint32 offset = 0x4000;
243 uint8 disables = ~bank_disable_reg;
248 //printf("Compare CMD=%02x, ADDR=%04x\n", command_reg, addr);
249 b = do_read(addr, 0);
250 r = do_read(addr, 1);
251 g = do_read(addr, 2);
253 t = do_read(addr, 3);
254 disables = disables & 0x0f;
257 disables = disables & 0x07;
259 for(i = 7; i >= 0; i--) {
260 tmpcol = ((b & 0x80) != 0) ? 1 : 0;
261 tmpcol |= ((r & 0x80) != 0) ? 2 : 0;
262 tmpcol |= ((g & 0x80) != 0) ? 4 : 0;
263 tmpcol |= ((t & 0x80) != 0) ? 8 : 0;
264 tmpcol = tmpcol & disables;
265 for(j = 0; j < 8; j++) {
266 if((cmp_color_data[j] & 0x80) == 0) {
267 if((cmp_color_data[j] & disables) == tmpcol) {
268 tmp_stat = tmp_stat | (1 << i);
278 cmp_status_reg = tmp_stat;
282 void MB61VH010::do_alucmds_dmyread(uint32 addr)
286 addr = addr & 0x3fff;
292 addr = addr & 0x7fff;
294 printf("ALU DMYREAD: CMD %02x ADDR=%04x CMP[]=", command_reg, addr);
295 for(i = 0; i < 8; i++) printf("[%02x]", cmp_color_data[i]);
296 if((command_reg & 0x80) == 0) {
300 if(((command_reg & 0x40) != 0) && ((command_reg & 0x07) != 7)) do_compare(addr);
301 switch(command_reg & 0x07) {
327 printf(" CMP STATUS=%02x\n", cmp_status_reg);
330 uint8 MB61VH010::do_alucmds(uint32 addr)
333 addr = addr & 0x3fff;
339 addr = addr & 0x7fff;
341 if((command_reg & 0x07) != 0x00) printf("ALU: CMD %02x ADDR=%08x\n", command_reg, addr);
342 if(((command_reg & 0x40) != 0) && ((command_reg & 0x07) != 7)) do_compare(addr);
343 switch(command_reg & 0x07) {
345 return do_pset(addr);
348 return do_blank(addr);
363 return do_tilepaint(addr);
366 return do_compare(addr);
372 void MB61VH010::do_line(void)
374 int x_begin = line_xbegin.w.l;
375 int x_end = line_xend.w.l;
376 int y_begin = line_ybegin.w.l;
377 int y_end = line_yend.w.l;
381 int ax = x_end - x_begin;
382 int ay = y_end - y_begin;
385 uint8 mask_bak = mask_reg;
386 //printf("Line: (%d,%d) - (%d,%d) CMD=%02x\n", x_begin, y_begin, x_end, y_end, command_reg);
388 bool lastflag = false;
390 is_400line = (target->read_signal(SIG_DISPLAY_MODE_IS_400LINE) != 0) ? true : false;
391 planes = target->read_signal(SIG_DISPLAY_PLANES) & 0x07;
392 screen_width = target->read_signal(SIG_DISPLAY_X_WIDTH) * 8;
393 screen_height = target->read_signal(SIG_DISPLAY_Y_HEIGHT);
395 //if((command_reg & 0x80) == 0) return;
396 oldaddr = 0xffffffff;
397 alu_addr = 0xffffffff;
400 line_style = line_pattern;
405 //mask_reg = 0xff & ~vmask[x_begin & 7];
407 // Got from HD63484.cpp .
408 if(abs(ax) >= abs(ay)) {
410 diff = ((abs(ay) + 1) * 1024) / abs(ax);
411 for(; cpx_t != x_end; ) {
412 lastflag = put_dot(cpx_t, cpy_t);
416 lastflag = put_dot(cpx_t + 1, cpy_t);
418 lastflag = put_dot(cpx_t - 1, cpy_t);
433 lastflag = put_dot(cpx_t, cpy_t);
434 } else { // ax = ay = 0
435 lastflag = put_dot(cpx_t, cpy_t);
438 } else { // (abs(ax) < abs(ay)
439 diff = ((abs(ax) + 1) * 1024) / abs(ay);
440 for(; cpy_t != y_end; ) {
441 lastflag = put_dot(cpx_t, cpy_t);
445 lastflag = put_dot(cpx_t, cpy_t + 1);
447 lastflag = put_dot(cpx_t, cpy_t - 1);
462 lastflag = put_dot(cpx_t, cpy_t);
464 do_alucmds(alu_addr);
466 usec = (double)total_bytes / 16.0;
467 //if(usec >= 1.0) { // 1MHz
468 register_event(this, EVENT_MB61VH010_BUSY_OFF, usec, false, &eventid_busy) ;
473 line_pattern = line_style;
476 bool MB61VH010::put_dot(int x, int y)
478 uint8 vmask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
483 if((x < 0) || (y < 0)) return flag;
484 if((x >= screen_width) || (y >= screen_height)) return flag;
485 if((command_reg & 0x80) == 0) return flag;
487 alu_addr = ((y * screen_width) >> 3) + (x >> 3);
488 alu_addr = alu_addr + (line_addr_offset.w.l << 1);
489 alu_addr = alu_addr & 0x7fff;
490 if(!is_400line) alu_addr = alu_addr & 0x3fff;
491 if(oldaddr == 0xffffffff) oldaddr = alu_addr;
493 if(oldaddr != alu_addr) {
501 if((line_style.b.h & 0x80) != 0) {
502 mask_reg &= ~vmask[x & 7];
504 tmp8a = (line_style.w.l & 0x8000) >> 15;
505 line_style.w.l = (line_style.w.l << 1) | tmp8a;
509 void MB61VH010::write_data8(uint32 id, uint32 data)
511 //printf("ALU: ADDR=%02x DATA=%02x\n", id, data);
512 if(id == ALU_CMDREG) {
516 //if((command_reg & 0x80) == 0) return;
518 case ALU_LOGICAL_COLOR:
521 case ALU_WRITE_MASKREG:
524 case ALU_BANK_DISABLE:
525 bank_disable_reg = data;
527 case ALU_TILEPAINT_B:
530 case ALU_TILEPAINT_R:
533 case ALU_TILEPAINT_G:
536 case ALU_TILEPAINT_L:
539 case ALU_OFFSET_REG_HIGH:
540 line_addr_offset.b.h = data;
542 case ALU_OFFSET_REG_LO:
543 line_addr_offset.b.l = data;
545 case ALU_LINEPATTERN_REG_HIGH:
546 line_pattern.b.h = data;
548 case ALU_LINEPATTERN_REG_LO:
549 line_pattern.b.l = data;
551 case ALU_LINEPOS_START_X_HIGH:
552 line_xbegin.b.h = data;
554 case ALU_LINEPOS_START_X_LOW:
555 line_xbegin.b.l = data;
557 case ALU_LINEPOS_START_Y_HIGH:
558 line_ybegin.b.h = data;
560 case ALU_LINEPOS_START_Y_LOW:
561 line_ybegin.b.l = data;
563 case ALU_LINEPOS_END_X_HIGH:
564 line_xend.b.h = data;
566 case ALU_LINEPOS_END_X_LOW:
567 line_xend.b.l = data;
569 case ALU_LINEPOS_END_Y_HIGH:
570 line_yend.b.h = data;
572 case ALU_LINEPOS_END_Y_LOW:
573 line_yend.b.l = data;
577 if((id >= (ALU_CMPDATA_REG + 0)) && (id < (ALU_CMPDATA_REG + 8))) {
578 cmp_color_data[id - ALU_CMPDATA_REG] = data;
579 } else if((id >= ALU_WRITE_PROXY) && (id < (ALU_WRITE_PROXY + 0x18000))) {
580 is_400line = (target->read_signal(SIG_DISPLAY_MODE_IS_400LINE) != 0) ? true : false;
581 do_alucmds_dmyread(id - ALU_WRITE_PROXY);
587 uint32 MB61VH010::read_data8(uint32 id)
592 return (uint32)command_reg;
594 case ALU_LOGICAL_COLOR:
595 return (uint32)color_reg;
597 case ALU_WRITE_MASKREG:
598 return (uint32)mask_reg;
600 case ALU_CMP_STATUS_REG:
601 return (uint32)cmp_status_reg;
603 case ALU_BANK_DISABLE:
604 return (uint32)bank_disable_reg;
607 if((id >= ALU_WRITE_PROXY) && (id < (ALU_WRITE_PROXY + 0x18000))) {
608 is_400line = (target->read_signal(SIG_DISPLAY_MODE_IS_400LINE) != 0) ? true : false;
609 do_alucmds_dmyread(id - ALU_WRITE_PROXY);
616 uint32 MB61VH010::read_signal(int id)
618 uint32 val = 0x00000000;
620 case SIG_ALU_BUSYSTAT:
621 if(busy_flag) val = 0xffffffff;
627 void MB61VH010::event_callback(int event_id, int err)
630 case EVENT_MB61VH010_BUSY_ON:
632 if(eventid_busy >= 0) cancel_event(this, eventid_busy);
635 case EVENT_MB61VH010_BUSY_OFF:
642 void MB61VH010::initialize(void)
648 void MB61VH010::reset(void)
652 if(eventid_busy >= 0) cancel_event(this, eventid_busy);
655 command_reg = 0; // D410 (RW)
656 color_reg = 0; // D411 (RW)
657 mask_reg = 0; // D412 (RW)
658 cmp_status_reg = 0; // D413 (RO)
659 for(i = 0; i < 8; i++) cmp_color_data[i] = 0x80; // D413-D41A (WO)
660 bank_disable_reg = 0; // D41B (RW)
661 for(i = 0; i < 4; i++) tile_reg[i] = 0; // D41C-D41F (WO)
663 line_addr_offset.d = 0; // D420-D421 (WO)
664 line_pattern.d = 0; // D422-D423 (WO)
665 line_xbegin.d = 0; // D424-D425 (WO)
666 line_ybegin.d = 0; // D426-D427 (WO)
667 line_xend.d = 0; // D428-D429 (WO)
668 line_yend.d = 0; // D42A-D42B (WO)
670 oldaddr = 0xffffffff;
672 planes = target->read_signal(SIG_DISPLAY_PLANES) & 0x07;
673 is_400line = (target->read_signal(SIG_DISPLAY_MODE_IS_400LINE) != 0) ? true : false;
675 screen_width = target->read_signal(SIG_DISPLAY_X_WIDTH) * 8;
676 screen_height = target->read_signal(SIG_DISPLAY_Y_HEIGHT);