IWM faker. Need VIA now.

This commit is contained in:
Jeroen Domburg 2017-03-03 19:42:48 +08:00
parent 1dd8ded327
commit 5ac2e47a73
4 changed files with 88 additions and 11 deletions

View File

@ -1,6 +1,6 @@
TARGET:=tme
MUSASHI_GEN_SRC:=musashi/m68kops.c musashi/m68kopac.c musashi/m68kopdm.c musashi/m68kopnz.c
OBJ:=$(MUSASHI_GEN_SRC:%.x=%.o) musashi/m68kcpu.o main.o emu.o disp.o
OBJ:=$(MUSASHI_GEN_SRC:%.x=%.o) musashi/m68kcpu.o main.o emu.o disp.o iwm.o
#musashi/m68kdasm.o
CFLAGS=-Wall -I. -I./musashi -ggdb `sdl2-config --cflags`
LDFLAGS=`sdl2-config --libs`

41
emu.c
View File

@ -12,25 +12,42 @@
unsigned char *macRom;
unsigned char *macRam;
void viaWrite(unsigned int addr, unsigned int val) {
printf("VIA write %x val %x\n", addr, val);
}
unsigned int viaRead(unsigned int addr) {
unsigned int val=0;
printf("VIA read %x val %x\n", addr, val);
return val;
}
int rom_remap;
unsigned int m68k_read_memory_8(unsigned int address) {
unsigned int ret;
unsigned int pc=m68k_get_reg(NULL, M68K_REG_PC);
if (rom_remap && address < 0x400000) {
ret=macRom[address & (TME_ROMSIZE-1)];
} else if (rom_remap && address > 0x600000 && address <= 0xA00000) {
if (address < 0x400000) {
if (rom_remap) {
ret=macRom[address & (TME_ROMSIZE-1)];
} else {
ret=macRam[address & (TME_RAMSIZE-1)];
}
} else if (address >= 0x600000 && address < 0xA00000) {
ret=macRam[address & (TME_RAMSIZE-1)];
} else if (address < 0x400000) {
ret=macRam[address & (TME_RAMSIZE-1)];
} else if (address>0x400000 && address<0x41FFFF) {
} else if (address >= 0x400000 && address<0x41FFFF) {
int romAdr=address-0x400000;
if (romAdr>TME_ROMSIZE) printf("PC %x:Huh? Read from ROM mirror (%x)\n", pc, address);
ret=macRom[romAdr&(TME_ROMSIZE-1)];
// rom_remap=0; //HACK
} else if (address >= 0xE80000 && address < 0xf00000) {
ret=viaRead((address>>8)&0xf);
} else if (address >= 0xc00000 && address < 0xe00000) {
ret=iwmRead((address>>8)&0xf);
} else {
printf("PC %x: Read from %x\n", pc, address);
ret=rand();
ret=0xaa;
}
// printf("Rd %x = %x\n", address, ret);
return ret;
@ -40,8 +57,12 @@ void m68k_write_memory_8(unsigned int address, unsigned int value) {
unsigned int pc=m68k_get_reg(NULL, M68K_REG_PC);
if (address < 0x400000) {
macRam[address & (TME_RAMSIZE-1)]=value;
} else if (rom_remap && address > 0x600000 && address <= 0xA00000) {
} else if (address >= 0x600000 && address < 0xA00000) {
macRam[address & (TME_RAMSIZE-1)]=value;
} else if (address >= 0xE80000 && address < 0xf00000) {
viaWrite((address>>8)&0xf, value);
} else if (address >= 0xc00000 && address < 0xe00000) {
iwmWrite((address>>8)&0xf, value);
} else {
printf("PC %x: Write to %x: %x\n", pc, address, value);
}
@ -60,13 +81,13 @@ void tmeStartEmu(void *rom) {
while(1) {
m68k_execute(8000000/60);
dispDraw(&macRam[0x1A700]);
printf("Int!\n");
// printf("Int!\n");
// m68k_set_irq(2);
}
}
//Mac uses an 68008, which has an external 8-bit bus. Hence, it should be okay to do everything using 8-bit
//Mac uses an 68008, which has an external 16-bit bus. Hence, it should be okay to do everything using 16-bit
//reads/writes.
unsigned int m68k_read_memory_32(unsigned int address) {
unsigned int ret;

54
iwm.c Normal file
View File

@ -0,0 +1,54 @@
#include <stdio.h>
/*
At the moment, this only emulates enough of the IWM to make the Plus boot.
*/
#define IWM_CA0 (1<<0)
#define IWM_CA1 (1<<1)
#define IWM_CA2 (1<<2)
#define IWM_LSTRB (1<<3)
#define IWM_ENABLE (1<<4)
#define IWM_SELECT (1<<5)
#define IWM_Q6 (1<<6)
#define IWM_Q7 (1<<7)
int iwmLines, iwmModeReg;
void iwmAccess(unsigned int addr) {
if (addr&1) {
iwmLines|=(1<<(addr>>1));
} else {
iwmLines&=~(1<<(addr>>1));
}
}
void iwmWrite(unsigned int addr, unsigned int val) {
iwmAccess(addr);
int reg=iwmLines&(IWM_Q7|IWM_Q6);
if (reg==0xC0) iwmModeReg=val;
printf("IWM write %x (iwm reg %x) val %x\n", addr, reg, val);
}
unsigned int iwmRead(unsigned int addr) {
unsigned int val=0;
iwmAccess(addr);
int reg=iwmLines&(IWM_Q7|IWM_Q6);
if (reg==0) {
//Data register
val=0;
} else if (reg==IWM_Q6) {
//Status register
if (iwmLines&IWM_ENABLE) val|=0x20; //enable
val|=iwmModeReg&0x1F;
} else if (reg==IWM_Q7) {
//Read handshake register
val=0xC0;
} else {
//Mode reg?
if (iwmLines&IWM_ENABLE) val|=0x20; //enable
val|=iwmModeReg&0x1F;
}
printf("IWM read %x (iwm reg %x) val %x\n", addr, reg, val);
return val;
}

2
iwm.h Normal file
View File

@ -0,0 +1,2 @@
void iwmWrite(unsigned int addr, unsigned int val);
unsigned int iwmRead(unsigned int addr);