--- trunk/src/devices/dev_bebox.c 2007/10/08 16:19:16 19 +++ trunk/src/devices/dev_bebox.c 2007/10/08 16:19:23 20 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: dev_bebox.c,v 1.4 2005/10/26 14:37:03 debug Exp $ + * $Id: dev_bebox.c,v 1.7 2005/11/16 21:15:18 debug Exp $ * * Emulation of BeBox motherboard registers. See the following URL for more * information: @@ -39,19 +39,27 @@ #include "cpu.h" #include "device.h" +#include "devices.h" #include "machine.h" #include "memory.h" #include "misc.h" -struct bebox_data { - /* The 5 motherboard registers: */ - uint32_t cpu0_intmask; - uint32_t cpu1_intmask; - uint32_t int_source; - uint32_t xpi; - uint32_t resets; -}; +/* + * check_cpu_masks(): + * + * BeBox interrupt enable bits are not allowed to be present in + * both CPUs at the same time. + */ +static void check_cpu_masks(struct cpu *cpu, struct bebox_data *d) +{ + d->cpu0_int_mask &= 0x7fffffff; + d->cpu1_int_mask &= 0x7fffffff; + if ((d->cpu0_int_mask | d->cpu1_int_mask) != + (d->cpu0_int_mask ^ d->cpu1_int_mask)) + fatal("check_cpu_masks(): BeBox cpu int masks" + " collide!\n"); +} /* @@ -68,6 +76,43 @@ idata = memory_readmax64(cpu, data, len); switch (relative_addr) { + + case 0x0f0: + if (writeflag == MEM_READ) + odata = d->cpu0_int_mask; + else { + if (idata & 0x80000000) + d->cpu0_int_mask |= idata; + else + d->cpu0_int_mask &= ~idata; + check_cpu_masks(cpu, d); + } + break; + + case 0x1f0: + if (writeflag == MEM_READ) + odata = d->cpu1_int_mask; + else { + if (idata & 0x80000000) + d->cpu1_int_mask |= idata; + else + d->cpu1_int_mask &= ~idata; + check_cpu_masks(cpu, d); + } + break; + + case 0x2f0: + if (writeflag == MEM_READ) + odata = d->int_status; + else { + if (idata & 0x80000000) + d->int_status |= idata; + else + d->int_status &= ~idata; + d->int_status &= 0x7fffffff; + } + break; + case 0x3f0: if (writeflag == MEM_READ) { odata = d->xpi; @@ -113,7 +158,9 @@ memset(d, 0, sizeof(struct bebox_data)); memory_device_register(devinit->machine->memory, devinit->name, - 0x7ffff000, 0x500, dev_bebox_access, d, MEM_DEFAULT, NULL); + 0x7ffff000, 0x500, dev_bebox_access, d, DM_DEFAULT, NULL); + + devinit->return_ptr = d; return 1; }