diff --git a/components/tme/Makefile b/components/tme/Makefile index c81d17a..da56f2c 100644 --- a/components/tme/Makefile +++ b/components/tme/Makefile @@ -3,7 +3,8 @@ TARGET:=tme MUSASHI_GEN_SRC:=musashi/m68kopac.c musashi/m68kopdm.c musashi/m68kopnz.c MUSASHI_OP_PREGEN_SRC:=musashi/m68kops_pre.c -OBJ:=$(MUSASHI_GEN_SRC:%.x=%.o) $(MUSASHI_OP_PREGEN_SRC:%.x=%.o) musashi/m68kcpu.o sdl/main.o emu.o sdl/disp.o iwm.o via.o rtc.o ncr.o sdl/hd.o +OBJ:=$(MUSASHI_GEN_SRC:%.x=%.o) $(MUSASHI_OP_PREGEN_SRC:%.x=%.o) musashi/m68kcpu.o sdl/main.o sdl/disp.o sdl/hd.o \ + emu.o iwm.o via.o rtc.o ncr.o scc.o mouse.o #musashi/m68kdasm.o CFLAGS=-Wall -I. -I./musashi -Og -ggdb `sdl2-config --cflags` LDFLAGS=`sdl2-config --libs` diff --git a/components/tme/component.mk b/components/tme/component.mk index 8b9c060..08c1878 100644 --- a/components/tme/component.mk +++ b/components/tme/component.mk @@ -7,7 +7,7 @@ COMPONENT_SRCDIRS := . musashi MUSASHI_GEN_SRC := musashi/m68kops_pre.c musashi/m68kopac.c musashi/m68kopdm.c musashi/m68kopnz.c MUSASHI_GEN_OBJ := $(MUSASHI_GEN_SRC:%.c=%.o) -COMPONENT_OBJS := $(MUSASHI_GEN_OBJ) musashi/m68kcpu.o emu.o iwm.o via.o rtc.o ncr.o +COMPONENT_OBJS := $(MUSASHI_GEN_OBJ) musashi/m68kcpu.o emu.o iwm.o via.o rtc.o ncr.o scc.o mouse.o CFLAGS += -Wno-error=implicit-function-declaration @@ -19,8 +19,14 @@ COMPONENT_EXTRA_CLEAN := $(addprefix $(COMPONENT_PATH)/musashi/,$(MUSASHI_GEN_SR #Using wildcard magic here because otherwise Make will invoke this multiple times. #$(COMPONENT_PATH)/musashi/ -musashi/m68kop%.c: $(COMPONENT_PATH)/musashi/m68kmake - cd $(COMPONENT_PATH)/musashi/; ./m68kmake; $(HOSTCC) -o m68kops_gen m68kops_gen.c; ./m68kops_gen > m68kops_pre.c +$(COMPONENT_PATH)/musashi/m68kop%.c: $(COMPONENT_PATH)/musashi/m68kmake + cd $(COMPONENT_PATH)/musashi/; ./m68kmake + +$(COMPONENT_PATH)/musashi/m68kops_pre.c: $(COMPONENT_PATH)/musashi/m68kops_gen + cd $(COMPONENT_PATH)/musashi/; ./m68kops_gen > m68kops_pre.c + +$(COMPONENT_PATH)/musashi/m68kops_gen: $(COMPONENT_PATH)/musashi/m68kops_gen.c + cd $(COMPONENT_PATH)/musashi/; $(HOSTCC) -o m68kops_gen m68kops.c $(COMPONENT_PATH)/musashi/m68kmake: $(COMPONENT_PATH)/musashi/m68kmake.c $(HOSTCC) -o $@ $^ diff --git a/components/tme/emu.c b/components/tme/emu.c index 2eebf51..17febfc 100644 --- a/components/tme/emu.c +++ b/components/tme/emu.c @@ -11,9 +11,11 @@ #include "disp.h" #include "iwm.h" #include "via.h" +#include "scc.h" #include "rtc.h" #include "ncr.h" #include "hd.h" +#include "mouse.h" unsigned char *macRom; unsigned char *macRam; @@ -48,7 +50,7 @@ unsigned int m68k_read_memory_8(unsigned int address) { } else { ret=macRam[address & (TME_RAMSIZE-1)]; } - } else if (address >= 0x600000 && address < 0xA00000) { + } else if (address >= 0x600000 && address < 0x700000) { ret=macRam[(address-0x600000) & (TME_RAMSIZE-1)]; } else if (address >= 0x400000 && address<0x500000) { int romAdr=address-0x400000; @@ -64,6 +66,8 @@ unsigned int m68k_read_memory_8(unsigned int address) { ret=iwmRead((address>>9)&0xf); } else if (address >= 0x580000 && address < 0x600000) { ret=ncrRead((address>>4)&0x7, (address>>9)&1); + } else if (address >= 0x800000 && address < 0xC00000) { + ret=sccRead(address); } else { printf("PC %x: Read from %x\n", pc, address); ret=0xff; @@ -84,6 +88,9 @@ void m68k_write_memory_8(unsigned int address, unsigned int value) { iwmWrite((address>>9)&0xf, value); } else if (address >= 0x580000 && address < 0x600000) { ncrWrite((address>>4)&0x7, (address>>9)&1, value); + } else if (address >= 0x800000 && address < 0xC00000) { + sccWrite(address, value); + printf("PC %x: Write to %x: %x\n", pc, address, value); } else { printf("PC %x: Write to %x: %x\n", pc, address, value); } @@ -103,29 +110,11 @@ void printFps() { oldtv.tv_usec=tv.tv_usec; } -//typedef void (m68ki_instruction_jump_call)(void); - -//m68ki_instruction_jump_call **m68ki_instruction_jump_table; -//unsigned char **m68ki_cycles; - - void tmeStartEmu(void *ram, void *rom) { int ca1=0, ca2=0; - int x, frame=0; + int x, m=0, frame=0; macRom=rom; macRam=ram; -/* - printf("Allocating mem for m68k structs\n"); - m68ki_instruction_jump_table=malloc(sizeof(*m68ki_instruction_jump_table)*0x10000); - m68ki_cycles=malloc(sizeof(*m68ki_cycles)*4); - m68ki_cycles[0]=malloc(sizeof(**m68ki_cycles)*0x10000); - m68ki_cycles[1]=malloc(sizeof(**m68ki_cycles)*0x10000); - m68ki_cycles[2]=malloc(sizeof(**m68ki_cycles)*0x10000); - if (m68ki_instruction_jump_table==NULL || m68ki_cycles[2]==NULL) { - printf("Malloc of 68k emu structs failed.\n"); - abort(); - } -*/ printf("Clearing ram...\n"); for (int x=0; x=1000) { + int r=mouseTick(); + if (r&MOUSE_BTN) viaClear(VIA_PORTB, (1<<3)); else viaSet(VIA_PORTB, (1<<3)); + if (r&MOUSE_QXB) viaClear(VIA_PORTB, (1<<4)); else viaSet(VIA_PORTB, (1<<4)); + if (r&MOUSE_QYB) viaClear(VIA_PORTB, (1<<5)); else viaSet(VIA_PORTB, (1<<5)); + sccSetDcd(SCC_CHANA, r&MOUSE_QXA); + sccSetDcd(SCC_CHANB, r&MOUSE_QYA); + m=0; + } } dispDraw(&macRam[video_remap?TME_SCREENBUF_ALT:TME_SCREENBUF]); frame++; @@ -169,6 +168,11 @@ void viaIrq(int req) { m68k_set_irq(req?1:0); } +void sccIrq(int req) { +// printf("IRQ %d\n", req); + m68k_set_irq(req?2:0); +} + //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) { diff --git a/components/tme/emu.h b/components/tme/emu.h index 45ccb6e..8c16303 100644 --- a/components/tme/emu.h +++ b/components/tme/emu.h @@ -1,3 +1,4 @@ void tmeStartEmu(void *rom, void *ram); +void tmeMouseMovement(int dx, int dy, int btn); diff --git a/components/tme/iwm.c b/components/tme/iwm.c index 7457d8b..a249588 100644 --- a/components/tme/iwm.c +++ b/components/tme/iwm.c @@ -1,7 +1,8 @@ #include /* -At the moment, this only emulates enough of the IWM to make the Plus boot. +At the moment, this only emulates enough of the IWM to make the Mac boot; it basically always reports that +there's no floppy in the drive. */ #define IWM_CA0 (1<<0) @@ -44,9 +45,9 @@ unsigned int iwmRead(unsigned int addr) { } else if (reg==IWM_Q6) { //Status register int iwmSel=iwmLines&(IWM_CA0|IWM_CA1|IWM_CA2); - if (iwmHeadSel) iwmSel|=IWM_SELECT; //Abusing this bit for the separate VIA-controlled SEL line - if (iwmSel==IWM_SELECT) val|=0x80; //No disk in drive. - if (iwmLines&IWM_ENABLE) val|=0x20; //enable + if (iwmHeadSel) iwmSel|=IWM_SELECT; //Abusing this bit for the separate VIA-controlled SEL line. This is NOT the drive select bit! + if (iwmSel==IWM_SELECT) val|=0x80; //Report: No disk in drive. + if (iwmLines&IWM_ENABLE) val|=0x20; //Report: enabled val|=iwmModeReg&0x1F; // printf("Read disk status %x\n", iwmLines); } else if (reg==IWM_Q7) { diff --git a/components/tme/sdl/disp.c b/components/tme/sdl/disp.c index 2cf6f65..c5a17a2 100644 --- a/components/tme/sdl/disp.c +++ b/components/tme/sdl/disp.c @@ -1,6 +1,7 @@ #include #include #include +#include "mouse.h" const int SCREEN_WIDTH = 512; const int SCREEN_HEIGHT = 342; @@ -23,6 +24,26 @@ void dispInit() { drwsurf=SDL_CreateRGBSurfaceWithFormat(0, SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_PIXELFORMAT_RGBA32); } +void handleInput() { + static int btn=0; + static int oldx, oldy; + SDL_Event ev; + while(SDL_PollEvent(&ev)) { + if (ev.type == SDL_QUIT ) { + exit(0); + } + if (ev.type==SDL_MOUSEMOTION || ev.type==SDL_MOUSEBUTTONDOWN || ev.type==SDL_MOUSEBUTTONUP) { + int x, y; + SDL_GetMouseState(&x, &y); + if (ev.type==SDL_MOUSEBUTTONDOWN) btn=1; + if (ev.type==SDL_MOUSEBUTTONUP) btn=0; + mouseMove(x-oldx, y-oldy, btn); + oldx=x; + oldy=y; + } + } +} + void dispDraw(uint8_t *mem) { int x, y, z; SDL_LockSurface(drwsurf); @@ -39,5 +60,8 @@ void dispDraw(uint8_t *mem) { SDL_UnlockSurface(drwsurf); SDL_BlitSurface(drwsurf, NULL, surf, NULL); SDL_UpdateWindowSurface(win); + + //Also handle mouse here. + handleInput(); } diff --git a/sdkconfig b/sdkconfig index c2c53fa..99b5908 100644 --- a/sdkconfig +++ b/sdkconfig @@ -82,8 +82,8 @@ CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" CONFIG_APP_OFFSET=0x10000 CONFIG_PHY_DATA_OFFSET= -CONFIG_OPTIMIZATION_LEVEL_DEBUG=y -# CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set +# CONFIG_OPTIMIZATION_LEVEL_DEBUG is not set +CONFIG_OPTIMIZATION_LEVEL_RELEASE=y # # Component config