static void galpani2_mcu_nmi(void) { UINT32 mcu_list, mcu_command, mcu_address, mcu_src, mcu_dst, mcu_size; /* "Last Check" */ galpani2_write_kaneko(); for ( mcu_list = 0x100020; mcu_list < (0x100020 + 0x40); mcu_list += 4 ) { mcu_command = cpunum_read_byte(0, mcu_list + 1 ); mcu_address = 0x100000 + (cpunum_read_byte(0, mcu_list + 2)<<8) + (cpunum_read_byte(0, mcu_list + 3)<<0) ; switch (mcu_command) { case 0x00: break; case 0x0a: // Copy N bytes from RAM1 to RAM2 mcu_src = (cpunum_read_byte(0, mcu_address + 2)<<8) + (cpunum_read_byte(0, mcu_address + 3)<<0) ; mcu_dst = (cpunum_read_byte(0, mcu_address + 6)<<8) + (cpunum_read_byte(0, mcu_address + 7)<<0) ; mcu_size = (cpunum_read_byte(0, mcu_address + 8)<<8) + (cpunum_read_byte(0, mcu_address + 9)<<0) ; logerror("CPU #0 PC %06X : MCU executes command $A, %04X %02X-> %04x\n",activecpu_get_pc(),mcu_src,mcu_size,mcu_dst); for( ; mcu_size > 0 ; mcu_size-- ) { mcu_src &= 0xffff; mcu_dst &= 0xffff; cpunum_write_byte(1,0x100000 + mcu_dst,cpunum_read_byte(0,0x100000 + mcu_src)); mcu_src ++; mcu_dst ++; } /* Raise a "job done" flag */ cpunum_write_byte(0,mcu_address+0,0xff); cpunum_write_byte(0,mcu_address+1,0xff); break; default: /* Raise a "job done" flag */ cpunum_write_byte(0,mcu_address+0,0xff); cpunum_write_byte(0,mcu_address+1,0xff); logerror("CPU #0 PC %06X : MCU ERROR, unknown command %02X\n",activecpu_get_pc(),mcu_command); } /* Erase command? */ cpunum_write_byte(0,mcu_list + 1,0x00); } }
static void copy_from_memory (int cpu, int addr, UINT8 *dest, int num_bytes) { int i; for (i=0; i<num_bytes; i++) { dest[i] = cpunum_read_byte (cpu, addr+i); } }
/* safe_to_load checks the start and end values of each memory range */ static int safe_to_load (void) { struct mem_range *mem_range = state.mem_range; while (mem_range) { if (cpunum_read_byte (mem_range->cpu, mem_range->addr) != mem_range->start_value) { return 0; } if (cpunum_read_byte (mem_range->cpu, mem_range->addr + mem_range->num_bytes - 1) != mem_range->end_value) { return 0; } mem_range = mem_range->next; } return 1; }
static void read_buffer_from_dma(struct ide_state *ide) { int bytesleft = IDE_DISK_SECTOR_SIZE; UINT8 *data = ide->buffer; // LOG(("Reading sector from %08X\n", ide->dma_address)); /* loop until we've consumed all bytes */ while (bytesleft--) { /* if we're out of space, grab the next descriptor */ if (ide->dma_bytes_left == 0) { /* if we're out of buffer space, that's bad */ if (ide->dma_last_buffer) { LOG(("DMA Out of buffer space!\n")); return; } /* fetch the address */ ide->dma_address = cpunum_read_byte(ide->dma_cpu, ide->dma_descriptor++ ^ ide->dma_address_xor); ide->dma_address |= cpunum_read_byte(ide->dma_cpu, ide->dma_descriptor++ ^ ide->dma_address_xor) << 8; ide->dma_address |= cpunum_read_byte(ide->dma_cpu, ide->dma_descriptor++ ^ ide->dma_address_xor) << 16; ide->dma_address |= cpunum_read_byte(ide->dma_cpu, ide->dma_descriptor++ ^ ide->dma_address_xor) << 24; ide->dma_address &= 0xfffffffe; /* fetch the length */ ide->dma_bytes_left = cpunum_read_byte(ide->dma_cpu, ide->dma_descriptor++ ^ ide->dma_address_xor); ide->dma_bytes_left |= cpunum_read_byte(ide->dma_cpu, ide->dma_descriptor++ ^ ide->dma_address_xor) << 8; ide->dma_bytes_left |= cpunum_read_byte(ide->dma_cpu, ide->dma_descriptor++ ^ ide->dma_address_xor) << 16; ide->dma_bytes_left |= cpunum_read_byte(ide->dma_cpu, ide->dma_descriptor++ ^ ide->dma_address_xor) << 24; ide->dma_last_buffer = (ide->dma_bytes_left >> 31) & 1; ide->dma_bytes_left &= 0xfffe; if (ide->dma_bytes_left == 0) ide->dma_bytes_left = 0x10000; // LOG(("New DMA descriptor: address = %08X bytes = %04X last = %d\n", ide->dma_address, ide->dma_bytes_left, ide->dma_last_buffer)); } /* read the next byte */ *data++ = cpunum_read_byte(ide->dma_cpu, ide->dma_address++); ide->dma_bytes_left--; } }
void galpani2_mcu_run(void) { int i,x; /* Write "KANEKO" to 100000-100005, but do not clash with ram test */ x = 0; for (i = 0x100000; i < 0x100007; i++) x |= cpunum_read_byte(0,i); if ( x == 0 ) { galpani2_write_kaneko(); cpunum_write_byte(1,0x100006,1); logerror("MCU executes CHECK0\n"); } }