Skip to content

Commit

Permalink
68k: add musashi as a 68k core option
Browse files Browse the repository at this point in the history
  • Loading branch information
raelgc committed Nov 7, 2017
1 parent 932c9d0 commit bd57d01
Show file tree
Hide file tree
Showing 19 changed files with 57,459 additions and 1 deletion.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ before_build:
- if ["%compiler_type%"]==["msys2-mingw-w64-x86_64"] set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;C:\msys64;%PATH%
- if ["%compiler_type%"]==["msys2-mingw-w64-x86_64"] C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Sy"
- if ["%compiler_type%"]==["msys2-mingw-w64-x86_64"] C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw64/mingw-w64-x86_64-SDL2 mingw-w64-x86_64-binutils mingw64/mingw-w64-x86_64-qt5 mingw-w64-x86_64-crt-git mingw-w64-x86_64-headers-git mingw64/mingw-w64-x86_64-libwebp"
- if ["%compiler_type%"]==["msys2-mingw-w64-x86_64"] C:\msys64\usr\bin\bash -lc "cd C:/projects/yabause/yabause/build ; cmake -G\"MSYS Makefiles\" -DDirectX_INCLUDE_DIR=C:/msys64/mingw64/x86_64-w64-mingw32/include -DYAB_WANT_DIRECTSOUND=OFF -DYAB_WANT_DIRECTINPUT=OFF -DYAB_NETWORK=ON -DYAB_WANT_GDBSTUB=ON -DMSYS2_BUILD=ON -DCMAKE_PREFIX_PATH=C:/msys64/mingw64/bin -DSDL2MAIN_LIBRARY=C:/msys64/mingw64/lib/libSDL2main.a .."
- if ["%compiler_type%"]==["msys2-mingw-w64-x86_64"] C:\msys64\usr\bin\bash -lc "cd C:/projects/yabause/yabause/build ; cmake -G\"MSYS Makefiles\" -DDirectX_INCLUDE_DIR=C:/msys64/mingw64/x86_64-w64-mingw32/include -DYAB_WANT_MUSASHI=OFF -DYAB_WANT_DIRECTSOUND=OFF -DYAB_WANT_DIRECTINPUT=OFF -DYAB_NETWORK=ON -DYAB_WANT_GDBSTUB=ON -DMSYS2_BUILD=ON -DCMAKE_PREFIX_PATH=C:/msys64/mingw64/bin -DSDL2MAIN_LIBRARY=C:/msys64/mingw64/lib/libSDL2main.a .."

build_script:
- if ["%compiler_type%"]==["mingw32"] cmake --build .
Expand Down
53 changes: 53 additions & 0 deletions yabause/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,52 @@ if (YAB_WANT_C68K)
endif()
endif(YAB_WANT_C68K)

option(YAB_WANT_MUSASHI "Enable musashi 68k" ON)
#TODO cross compile builds m68kmake for the target platform instead
#of the native one, making it impossible to generate the core
if (YAB_WANT_MUSASHI AND NOT CMAKE_CROSSCOMPILING)
set (MUSASHI_GENERATED_SOURCES
${CMAKE_CURRENT_BINARY_DIR}/m68kopac.c
${CMAKE_CURRENT_BINARY_DIR}/m68kopdm.c
${CMAKE_CURRENT_BINARY_DIR}/m68kopnz.c
${CMAKE_CURRENT_BINARY_DIR}/m68kops.c)

set (MUSASHI_GENERATED_HEADERS
${CMAKE_CURRENT_BINARY_DIR}/m68kops.h)

add_executable(m68kmake musashi/m68kmake.c)
add_custom_command(OUTPUT ${MUSASHI_GENERATED_SOURCES} ${MUSASHI_GENERATED_HEADERS}
COMMAND m68kmake ${CMAKE_CURRENT_BINARY_DIR}/ ${CMAKE_CURRENT_SOURCE_DIR}/musashi/m68k_in.c
DEPENDS m68kmake
COMMENT "Generating musashi 68k core"
VERBATIM)

add_definitions(-DHAVE_MUSASHI=1)

include_directories(
${CMAKE_CURRENT_BINARY_DIR}/
${CMAKE_CURRENT_SOURCE_DIR}/musashi
)

set(yabause_SOURCES ${yabause_SOURCES}
${MUSASHI_GENERATED_SOURCES}
musashi/m68kdasm.c
musashi/m68kcpu.c
m68kmusashi.c
)

set(yabause_HEADERS
${yabause_HEADERS}
musashi/m68k.h
musashi/m68kcpu.h
${MUSASHI_GENERATED_HEADERS}
m68kmusashi.h
)

add_custom_target(musashi ALL
DEPENDS ${MUSASHI_GENERATED_FILES})
endif(YAB_WANT_MUSASHI AND NOT CMAKE_CROSSCOMPILING)

# q68
option(YAB_WANT_Q68 "enable q68 compilation" OFF)
if (YAB_WANT_Q68)
Expand Down Expand Up @@ -634,6 +680,10 @@ if (YAB_WANT_C68K)
add_dependencies(yabause c68kinc)
endif(YAB_WANT_C68K)

if (YAB_WANT_MUSASHI)
add_dependencies(yabause musashi)
endif(YAB_WANT_MUSASHI)

macro(yab_port_start)
if (YAB_PORT_BUILT AND NOT YAB_MULTIBUILD)
return()
Expand Down Expand Up @@ -670,6 +720,9 @@ endforeach(PORT)
if (YAB_WANT_C68K)
set(HAVE_C68K ON)
endif()
if (YAB_WANT_MUSASHI)
set(HAVE_MUSASHI ON)
endif()
if (YAB_WANT_Q68)
set(HAVE_Q68 ON)
endif()
Expand Down
2 changes: 2 additions & 0 deletions yabause/src/m68kcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define M68KCORE_DUMMY 0
#define M68KCORE_C68K 1
#define M68KCORE_Q68 2
#define M68KCORE_MUSASHI 3

typedef u32 FASTCALL M68K_READ(const u32 adr);
typedef void FASTCALL M68K_WRITE(const u32 adr, u32 data);
Expand Down Expand Up @@ -75,5 +76,6 @@ int M68KInit(int coreid);
extern M68K_struct M68KDummy;
extern M68K_struct M68KC68K;
extern M68K_struct M68KQ68;
extern M68K_struct M68KMusashi;

#endif
202 changes: 202 additions & 0 deletions yabause/src/m68kmusashi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/* Copyright 2007 Guillaume Duhamel
This file is part of Yabause.
Yabause is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Yabause is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Yabause; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

/*! \file m68kmusashi.c
\brief Musashi 68000 interface.
*/

#include "m68kmusashi.h"
#include "musashi/m68k.h"
#include "m68kcore.h"
#include "musashi/m68kcpu.h"

struct ReadWriteFuncs
{
M68K_READ *r_8;
M68K_READ *r_16;
M68K_WRITE *w_8;
M68K_WRITE *w_16;
}rw_funcs;

static int M68KMusashiInit(void) {

m68k_init();
m68k_set_cpu_type(M68K_CPU_TYPE_68000);

return 0;
}

static void M68KMusashiDeInit(void) {
}

static void M68KMusashiReset(void) {
m68k_pulse_reset();
}

static s32 FASTCALL M68KMusashiExec(s32 cycle) {
return m68k_execute(cycle);
}

static void M68KMusashiSync(void) {
}

static u32 M68KMusashiGetDReg(u32 num) {
return m68k_get_reg(NULL, M68K_REG_D0 + num);
}

static u32 M68KMusashiGetAReg(u32 num) {
return m68k_get_reg(NULL, M68K_REG_A0 + num);
}

static u32 M68KMusashiGetPC(void) {
return m68k_get_reg(NULL, M68K_REG_PC);
}

static u32 M68KMusashiGetSR(void) {
return m68k_get_reg(NULL, M68K_REG_SR);
}

static u32 M68KMusashiGetUSP(void) {
return m68k_get_reg(NULL, M68K_REG_USP);
}

static u32 M68KMusashiGetMSP(void) {
return m68k_get_reg(NULL, M68K_REG_MSP);
}

static void M68KMusashiSetDReg(u32 num, u32 val) {
m68k_set_reg(M68K_REG_D0 + num, val);
}

static void M68KMusashiSetAReg(u32 num, u32 val) {
m68k_set_reg(M68K_REG_A0 + num, val);
}

static void M68KMusashiSetPC(u32 val) {
m68k_set_reg(M68K_REG_PC, val);
}

static void M68KMusashiSetSR(u32 val) {
m68k_set_reg(M68K_REG_SR, val);
}

static void M68KMusashiSetUSP(u32 val) {
m68k_set_reg(M68K_REG_USP, val);
}

static void M68KMusashiSetMSP(u32 val) {
m68k_set_reg(M68K_REG_MSP, val);
}

static void M68KMusashiSetFetch(u32 low_adr, u32 high_adr, pointer fetch_adr) {
}

static void FASTCALL M68KMusashiSetIRQ(s32 level) {
if (level > 0)
m68k_set_irq(level);
}

static void FASTCALL M68KMusashiWriteNotify(u32 address, u32 size) {
}

unsigned int m68k_read_memory_8(unsigned int address)
{
return rw_funcs.r_8(address);
}

unsigned int m68k_read_memory_16(unsigned int address)
{
return rw_funcs.r_16(address);
}

unsigned int m68k_read_memory_32(unsigned int address)
{
u16 val1 = rw_funcs.r_16(address);

return (val1 << 16 | rw_funcs.r_16(address + 2));
}

void m68k_write_memory_8(unsigned int address, unsigned int value)
{
rw_funcs.w_8(address, value);
}

void m68k_write_memory_16(unsigned int address, unsigned int value)
{
rw_funcs.w_16(address, value);
}

void m68k_write_memory_32(unsigned int address, unsigned int value)
{
rw_funcs.w_16(address, value >> 16 );
rw_funcs.w_16(address + 2, value & 0xffff);
}

static void M68KMusashiSetReadB(M68K_READ *Func) {
rw_funcs.r_8 = Func;
}

static void M68KMusashiSetReadW(M68K_READ *Func) {
rw_funcs.r_16 = Func;
}

static void M68KMusashiSetWriteB(M68K_WRITE *Func) {
rw_funcs.w_8 = Func;
}

static void M68KMusashiSetWriteW(M68K_WRITE *Func) {
rw_funcs.w_16 = Func;
}

static void M68KMusashiSaveState(FILE *fp) {
}

static void M68KMusashiLoadState(FILE *fp) {
}

M68K_struct M68KMusashi = {
3,
"Musashi Interface",
M68KMusashiInit,
M68KMusashiDeInit,
M68KMusashiReset,
M68KMusashiExec,
M68KMusashiSync,
M68KMusashiGetDReg,
M68KMusashiGetAReg,
M68KMusashiGetPC,
M68KMusashiGetSR,
M68KMusashiGetUSP,
M68KMusashiGetMSP,
M68KMusashiSetDReg,
M68KMusashiSetAReg,
M68KMusashiSetPC,
M68KMusashiSetSR,
M68KMusashiSetUSP,
M68KMusashiSetMSP,
M68KMusashiSetFetch,
M68KMusashiSetIRQ,
M68KMusashiWriteNotify,
M68KMusashiSetReadB,
M68KMusashiSetReadW,
M68KMusashiSetWriteB,
M68KMusashiSetWriteW,
M68KMusashiSaveState,
M68KMusashiLoadState
};
27 changes: 27 additions & 0 deletions yabause/src/m68kmusashi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright 2007 Guillaume Duhamel
This file is part of Yabause.
Yabause is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Yabause is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Yabause; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef M68KMUSASHI_H
#define M68KMUSASHI_H

#include "m68kcore.h"

extern M68K_struct M68KMusashi;

#endif
Loading

0 comments on commit bd57d01

Please sign in to comment.