initial commit

Sat, 27 Nov 2010 01:13:12 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Sat, 27 Nov 2010 01:13:12 +0000
changeset 0
8bf1bf91a36d
child 1
bef9f24c0085

initial commit

.hgignore file | annotate | diff | revisions
Makefile file | annotate | diff | revisions
dep/.keepme file | annotate | diff | revisions
dep/musashi/.keepme file | annotate | diff | revisions
obj/.keepme file | annotate | diff | revisions
obj/musashi/.keepme file | annotate | diff | revisions
src/main.c file | annotate | diff | revisions
src/musashi/LICENSE file | annotate | diff | revisions
src/musashi/example/Makefile file | annotate | diff | revisions
src/musashi/example/example.txt file | annotate | diff | revisions
src/musashi/example/history.txt file | annotate | diff | revisions
src/musashi/example/program.bin file | annotate | diff | revisions
src/musashi/example/readme.txt file | annotate | diff | revisions
src/musashi/example/sim.c file | annotate | diff | revisions
src/musashi/example/sim.h file | annotate | diff | revisions
src/musashi/history.txt file | annotate | diff | revisions
src/musashi/m68k.h file | annotate | diff | revisions
src/musashi/m68k_in.c file | annotate | diff | revisions
src/musashi/m68kconf.h file | annotate | diff | revisions
src/musashi/m68kcpu.c file | annotate | diff | revisions
src/musashi/m68kcpu.h file | annotate | diff | revisions
src/musashi/m68kdasm.c file | annotate | diff | revisions
src/musashi/m68kmake.c file | annotate | diff | revisions
src/musashi/readme.txt file | annotate | diff | revisions
src/version.h.in file | annotate | diff | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Sat Nov 27 01:13:12 2010 +0000
     1.3 @@ -0,0 +1,7 @@
     1.4 +syntax: glob
     1.5 +obj/*.o
     1.6 +dep/*.d
     1.7 +*~
     1.8 +.*.sw?
     1.9 +.~lock*
    1.10 +.buildnum
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile	Sat Nov 27 01:13:12 2010 +0000
     2.3 @@ -0,0 +1,454 @@
     2.4 +# Phil's multiplatform makefile template
     2.5 +# With auto-incrementing build number and automatic version.h generation
     2.6 +# Version 1.8, 2010-02-15
     2.7 +#
     2.8 +# The latest version of this Makefile can be found at http://www.philpem.me.uk/
     2.9 +#
    2.10 +#
    2.11 +# Copyright (c) 2010 Philip Pemberton <code@philpem.me.uk>
    2.12 +#
    2.13 +# Permission is hereby granted, free of charge, to any person obtaining a copy
    2.14 +# of this software and associated documentation files (the "Software"), to deal
    2.15 +# in the Software without restriction, including without limitation the rights
    2.16 +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    2.17 +# copies of the Software, and to permit persons to whom the Software is
    2.18 +# furnished to do so, subject to the following conditions:
    2.19 +#
    2.20 +# The above copyright notice and this permission notice shall be included in
    2.21 +# all copies or substantial portions of the Software.
    2.22 +#
    2.23 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    2.24 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    2.25 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    2.26 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    2.27 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    2.28 +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    2.29 +# THE SOFTWARE.
    2.30 +#
    2.31 +#
    2.32 +# Instructions for use:
    2.33 +#   Run 'make init' to create the required directories
    2.34 +#   Add your source files to the 'SOURCES' list, and change the TARGET filename
    2.35 +#   Set the desired build type and platform in the BUILD_TYPE and PLATFORM
    2.36 +#     variables respectively
    2.37 +#   Set your project type (C only, or C++) in the SRC_TYPE variable
    2.38 +#   Add any libraries you need to link against to the 'LIB' list
    2.39 +#   Run 'make'
    2.40 +#
    2.41 +# Object files are created in the 'obj' subdirectory, from source code in the
    2.42 +# 'src' directory. Dependency files are created in the 'dep' directory from
    2.43 +# the same source code the object files are created from.
    2.44 +#
    2.45 +# Supported targets are:
    2.46 +#   all                 Build everything.
    2.47 +#   update-revision     Increment the build number without building anything.
    2.48 +#   clean-versioninfo   Delete src/version.h (will be rebuilt on the next
    2.49 +#                       'make all').
    2.50 +#   init                Initialise the build system for a new project.
    2.51 +#                       WARNING: overwrites .buildnum and src/version.h.in!
    2.52 +#   cleandep            Delete all dependency files.
    2.53 +#   clean               Delete all dependency, intermediate and target files.
    2.54 +#   tidy                Delete all dependency and intermediate files, leaving
    2.55 +#                       the target file intact.
    2.56 +#
    2.57 +# If you want to reset the build number to zero, delete '.buildnum'. This
    2.58 +# should be done whenever the major or minor version changes. Excluding
    2.59 +# .buildnum from version control may also be a good idea, depending on how
    2.60 +# you want your build numbers to work.
    2.61 +#
    2.62 +# The BUILD_TYPE variable contains the current build type. There are two
    2.63 +# supported build types:
    2.64 +#   debug       Debug mode - object files are compiled with debug information
    2.65 +#               and the target is left unstripped.
    2.66 +#   release     Release mode - object files are not compiled with debug info,
    2.67 +#               and the target is fed through strip to remove redundant
    2.68 +#               data.
    2.69 +#
    2.70 +# The PLATFORM variable contains the current target platform. There are two
    2.71 +# supported platforms:
    2.72 +#   linux       GNU/Linux with GNU Compiler Collection
    2.73 +#   win32       Windows 32-bit with MinGW
    2.74 +#
    2.75 +# The EXTSRC variable is used to specify other files to build. It is typically
    2.76 +# used to specify platform or build-type specific source files, e.g.
    2.77 +#
    2.78 +# ifeq ($(BUILD_TYPE),debug-memwatch)
    2.79 +#   CFLAGS += -g -ggdb
    2.80 +#   CPPFLAGS += -DMEMWATCH
    2.81 +#   INCPATH += ./memwatch
    2.82 +#   EXTSRC += memwatch/memwatch.c
    2.83 +# endif
    2.84 +#
    2.85 +# (example taken from one of my projects that allowed the use of Memwatch to
    2.86 +#  track down memory allocation/deallocation bugs)
    2.87 +#
    2.88 +#
    2.89 +# Change history:
    2.90 +#   1.8 - Now supports the use of the wxWidgets GUI framework. To turn
    2.91 +#         this on, set ENABLE_WX to "yes".
    2.92 +#   1.7 - Now creates a basic Hgignore file and directory keepers for the
    2.93 +#         dep and obj directories.
    2.94 +#   1.6 - Added CFLAGS and CXXFLAGS to the command-lines for the dependency
    2.95 +#         building commands. This was causing issues with C99 / C++0x mode.
    2.96 +#   1.5 - Added support for Mercurial revision (changeset ID) display
    2.97 +#         Fixed a few issues with Subversion support (svn: and version 0 would
    2.98 +#         be displayed for exported code)
    2.99 +#
   2.100 +
   2.101 +####
   2.102 +# Build configuration
   2.103 +####
   2.104 +
   2.105 +# version information -- major.minor.extra
   2.106 +# note that VER_EXTRA can be overridden on the command line, e.g.:
   2.107 +# make VER_EXTRA=12345 all
   2.108 +VER_MAJOR	= 0
   2.109 +VER_MINOR	= 0
   2.110 +VER_EXTRA	?= 
   2.111 +
   2.112 +# build platform: win32 or linux
   2.113 +PLATFORM	?=	linux
   2.114 +# build type: release or debug
   2.115 +BUILD_TYPE	?=	debug
   2.116 +
   2.117 +# target executable
   2.118 +TARGET		=	3b1emu
   2.119 +
   2.120 +# source files that produce object files
   2.121 +SRC			=	main.c musashi/m68kcpu.c musashi/m68kops.c
   2.122 +
   2.123 +# source type - either "c" or "cpp" (C or C++)
   2.124 +SRC_TYPE	=	c
   2.125 +
   2.126 +# additional object files that don't necessarily include source
   2.127 +EXT_OBJ		=
   2.128 +# libraries to link in -- these will be specified as "-l" parameters, the -l
   2.129 +# is prepended automatically
   2.130 +LIB			=	sdl
   2.131 +# library paths -- where to search for the above libraries
   2.132 +LIBPATH		=	musashi
   2.133 +# include paths -- where to search for #include files (in addition to the
   2.134 +# standard paths
   2.135 +INCPATH		=	musashi
   2.136 +# garbage files that should be deleted on a 'make clean' or 'make tidy'
   2.137 +GARBAGE		=	obj/musashi/m68kmake obj/musashi/m68kmake.exe obj/musashi/m68kmake.o
   2.138 +
   2.139 +# extra dependencies - files that we don't necessarily know how to build, but
   2.140 +# that are required for building the application; e.g. object files or
   2.141 +# libraries in sub or parent directories
   2.142 +EXTDEP		=
   2.143 +
   2.144 +# Extra libraries
   2.145 +# wxWidgets: set to "yes" to enable, anything else to disable
   2.146 +ENABLE_WX	=	no
   2.147 +# wxWidgets: list of wxWidgets libraries to enable
   2.148 +WX_LIBS		=	std
   2.149 +
   2.150 +####
   2.151 +# Win32 target-specific settings
   2.152 +####
   2.153 +ifeq ($(strip $(PLATFORM)),win32)
   2.154 +	# windows executables have a .exe suffix
   2.155 +	TARGET := $(addsuffix .exe,$(TARGET))
   2.156 +	# console mode application
   2.157 +	EXT_CFLAGS = -mconsole
   2.158 +endif
   2.159 +
   2.160 +
   2.161 +####
   2.162 +# Tool setup
   2.163 +####
   2.164 +MAKE	=	make
   2.165 +CC		=	gcc
   2.166 +CXX		=	g++
   2.167 +CFLAGS	=	-Wall -pedantic -std=gnu99 $(EXT_CFLAGS)
   2.168 +CXXFLAGS=	-Wall -pedantic -std=gnu++0x $(EXT_CXXFLAGS)
   2.169 +LDFLAGS	=	$(EXT_LDFLAGS)
   2.170 +RM		=	rm
   2.171 +STRIP	=	strip
   2.172 +
   2.173 +###############################################################################
   2.174 +# You should not need to touch anything below here, unless you're adding a new
   2.175 +# platform or build type (or changing the version string format)
   2.176 +###############################################################################
   2.177 +
   2.178 +####
   2.179 +# A quick sanity check on the platform type
   2.180 +####
   2.181 +ifneq ($(PLATFORM),linux)
   2.182 +ifneq ($(PLATFORM),win32)
   2.183 +    $(error Platform '$(PLATFORM)' not supported. Supported platforms are: linux, win32)
   2.184 +endif
   2.185 +endif
   2.186 +
   2.187 +####
   2.188 +# Version info generation
   2.189 +####
   2.190 +# get the current build number
   2.191 +VER_BUILDNUM	= $(shell cat .buildnum)
   2.192 +
   2.193 +#### --- begin Subversion revision grabber ---
   2.194 +# there are two ways to get the SVN revision - use svnversion, or use svn info
   2.195 +# then pipe through awk. which one you use is up to you.
   2.196 +VER_SVNREV		= $(shell LANG=C svn info 2>/dev/null || echo 'Revision: exported' | awk '/^Revision:/ { print$$2 }' )
   2.197 +#VER_SVNREV		= $(shell svnversion .)
   2.198 +
   2.199 +# if the version string is "exported", then the CSD was not checked out of SVN
   2.200 +# note that if the CSD is not an SVN checkout, then @@svnrev@@ will be set to
   2.201 +# zero.
   2.202 +ifeq ($(VER_SVNREV),exported)
   2.203 +    VER_VCS		= none
   2.204 +    VER_VCSREV	= 0
   2.205 +else
   2.206 +    VER_VCS		= svn
   2.207 +    VER_VCSREV	= $(VER_SVNREV)
   2.208 +endif
   2.209 +
   2.210 +#### --- begin Mercurial revision grabber ---
   2.211 +# If SVN didn't give us a revision, try Mercurial instead
   2.212 +ifeq ($(VER_VCS),none)
   2.213 +    # get the current Mercurial changeset number
   2.214 +	VER_HGREV=$(shell ((hg tip --template "{node|short}") || echo "000000000000") 2>/dev/null)
   2.215 +    ifneq ($(VER_HGREV),000000000000)
   2.216 +        # a non-empty repo
   2.217 +        VER_VCS		= hg
   2.218 +        VER_VCSREV	= $(VER_HGREV)
   2.219 +    else
   2.220 +        # either an empty Hg repo, or no repo at all
   2.221 +        VER_VCS		= none
   2.222 +        VER_VCSREV	= 0
   2.223 +    endif
   2.224 +endif
   2.225 +
   2.226 +#### --- end version grabbers ---
   2.227 +
   2.228 +# start creating the revision string
   2.229 +VER_FULLSTR		= $(VER_MAJOR).$(VER_MINOR).$(VER_BUILDNUM)$(VER_EXTRA)
   2.230 +
   2.231 +# if this is a VCS release, include the SVN revision in the version string
   2.232 +# also create a revision string that is either "svn:12345", "hg:12345" or
   2.233 +# blank
   2.234 +ifneq ($(VER_VCS),none)
   2.235 +    VER_FULLSTR	+= ($(VER_VCS) $(VER_VCSREV))
   2.236 +    VER_VCSSTR	= $(VER_VCS):$(VER_VCSREV)
   2.237 +else
   2.238 +    VER_VCSSTR	=
   2.239 +endif
   2.240 +
   2.241 +
   2.242 +####
   2.243 +# Build-type specific configuration
   2.244 +####
   2.245 +ifeq ($(BUILD_TYPE),debug)
   2.246 +	CFLAGS		+= -g -ggdb -DDEBUG
   2.247 +	CXXFLAGS	+= -g -ggdb -DDEBUG
   2.248 +else
   2.249 + ifeq ($(BUILD_TYPE),release)
   2.250 +	CFLAGS		+= -O2
   2.251 +	CXXFLAGS	+= -O2
   2.252 + else
   2.253 + 	$(error Unsupported build type: '$(BUILD_TYPE)')
   2.254 + endif
   2.255 +endif
   2.256 +
   2.257 +####
   2.258 +# wxWidgets support
   2.259 +####
   2.260 +ifeq ($(ENABLE_WX),yes)
   2.261 +	ifeq ($(BUILD_TYPE),debug)
   2.262 +		LIBLNK		+=	`wx-config --debug --libs $(WX_LIBS)`
   2.263 +		CFLAGS		+=	`wx-config --debug --cflags $(WX_LIBS)`
   2.264 +		CXXFLAGS	+=	`wx-config --debug --cxxflags $(WX_LIBS)`
   2.265 +		CPPFLAGS	+=	`wx-config --debug --cppflags $(WX_LIBS)`
   2.266 +	else
   2.267 +		ifeq ($(BUILD_TYPE),release)
   2.268 +			LIBLNK		+=	`wx-config --libs $(WX_LIBS)`
   2.269 +			CFLAGS		+=	`wx-config --cflags $(WX_LIBS)`
   2.270 +			CPPFLAGS	+=	`wx-config --cppflags $(WX_LIBS)`
   2.271 +			CXXFLAGS	+=	`wx-config --cxxflags $(WX_LIBS)`
   2.272 +		else
   2.273 +			$(error Unsupported build type: '$(BUILD_TYPE)')
   2.274 +		endif
   2.275 +	endif
   2.276 +endif
   2.277 +
   2.278 +####
   2.279 +# rules
   2.280 +####
   2.281 +
   2.282 +# object files
   2.283 +OBJ		=	$(addprefix obj/, $(addsuffix .o, $(basename $(SRC))) $(EXT_OBJ)) $(addsuffix .o, $(basename $(EXTSRC)))
   2.284 +
   2.285 +# dependency files
   2.286 +DEPFILES =	$(addprefix dep/, $(addsuffix .d, $(basename $(SRC))) $(EXT_OBJ)) $(addsuffix .d, $(basename $(EXTSRC)))
   2.287 +
   2.288 +# path commands
   2.289 +LIBLNK	+=	$(addprefix -l, $(LIB))
   2.290 +LIBPTH	+=	$(addprefix -L, $(LIBPATH))
   2.291 +INCPTH	+=	$(addprefix -I, $(INCPATH))
   2.292 +
   2.293 +CPPFLAGS +=	$(INCPTH)
   2.294 +
   2.295 +####
   2.296 +# Make sure there is at least one object file to be linked in
   2.297 +####
   2.298 +ifeq ($(strip $(OBJ)),)
   2.299 +    $(error Unable to build: no object or source files specified in Makefile)
   2.300 +endif
   2.301 +
   2.302 +####
   2.303 +# targets
   2.304 +####
   2.305 +.PHONY:	default all update-revision versionheader clean-versioninfo init cleandep clean tidy
   2.306 +
   2.307 +all:	update-revision
   2.308 +	@$(MAKE) versionheader
   2.309 +	$(MAKE) $(TARGET)
   2.310 +
   2.311 +# increment the current build number
   2.312 +NEWBUILD=$(shell expr $(VER_BUILDNUM) + 1)
   2.313 +update-revision:
   2.314 +	@echo $(NEWBUILD) > .buildnum
   2.315 +
   2.316 +versionheader:
   2.317 +	@sed -e 's/@@date@@/$(shell LC_ALL=C date)/g'			\
   2.318 +		 -e 's/@@time@@/$(shell LC_ALL=C date +%T)/g'		\
   2.319 +		 -e 's/@@whoami@@/$(shell whoami)/g'				\
   2.320 +		 -e 's/@@hostname@@/$(shell hostname)/g'			\
   2.321 +		 -e 's|@@compiler@@|$(shell $(CC) $(CFLAGS) -v 2>&1 | tail -n 1 | sed -e "s;|;/;")|g'	\
   2.322 +		 -e 's/@@majorver@@/$(VER_MAJOR)/g'					\
   2.323 +		 -e 's/@@minorver@@/$(VER_MINOR)/g'					\
   2.324 +		 -e 's/@@extraver@@/$(subst \",,$(VER_EXTRA))/g'	\
   2.325 +		 -e 's/@@buildnum@@/$(VER_BUILDNUM)/g'				\
   2.326 +		 -e 's/@@buildtype@@/$(BUILD_TYPE)/g'				\
   2.327 +		 -e 's/@@vcs@@/$(VER_VCS)/g'						\
   2.328 +		 -e 's/@@vcsrev@@/$(VER_VCSREV)/g'					\
   2.329 +		 -e 's/@@vcsstr@@/$(VER_VCSSTR)/g'					\
   2.330 +		 -e 's/@@fullverstr@@/$(VER_FULLSTR)/g'				\
   2.331 +		 -e 's/@@cflags@@/$(CFLAGS)/g'						\
   2.332 +		 < src/version.h.in > src/version.h
   2.333 +
   2.334 +# version.h creation stuff based on code from the Xen makefile
   2.335 +clean-versioninfo:
   2.336 +	@if [ ! -r src/version.h -o -O src/version.h ]; then \
   2.337 +		rm -f src/version.h; \
   2.338 +	fi
   2.339 +	@echo 0 > .buildnum
   2.340 +
   2.341 +# initialise the build system for a new project
   2.342 +init:
   2.343 +	@mkdir -p src dep obj
   2.344 +	@echo "This file is a directory-keeper. Do not delete it." > dep/.keepme
   2.345 +	@echo "This file is a directory-keeper. Do not delete it." > obj/.keepme
   2.346 +	@echo 0 > .buildnum
   2.347 +	@echo 'syntax: glob' > .hgignore
   2.348 +	@echo 'obj/*.o' >> .hgignore
   2.349 +	@echo 'dep/*.d' >> .hgignore
   2.350 +	@echo '*~' >> .hgignore
   2.351 +	@echo '.*.sw?' >> .hgignore
   2.352 +	@echo '#define VER_COMPILE_DATE	"@@date@@"'				> src/version.h.in
   2.353 +	@echo '#define VER_COMPILE_TIME	"@@time@@"'				>> src/version.h.in
   2.354 +	@echo '#define VER_COMPILE_BY		"@@whoami@@"'		>> src/version.h.in
   2.355 +	@echo '#define VER_COMPILE_HOST	"@@hostname@@"'			>> src/version.h.in
   2.356 +	@echo '#define VER_COMPILER		"@@compiler@@"'			>> src/version.h.in
   2.357 +	@echo '#define VER_BUILD_TYPE		"@@buildtype@@"'	>> src/version.h.in
   2.358 +	@echo '#define VER_CFLAGS			"@@cflags@@"'		>> src/version.h.in
   2.359 +	@echo ''												>> src/version.h.in
   2.360 +	@echo '#define VER_MAJOR			@@majorver@@'		>> src/version.h.in
   2.361 +	@echo '#define VER_MINOR			@@minorver@@'		>> src/version.h.in
   2.362 +	@echo '#define VER_BUILDNUM		@@buildnum@@'			>> src/version.h.in
   2.363 +	@echo '#define VER_EXTRA			"@@extraver@@"'		>> src/version.h.in
   2.364 +	@echo '#define VER_VCSREV			"@@vcsstr@@"'		>> src/version.h.in
   2.365 +	@echo ''												>> src/version.h.in
   2.366 +	@echo '#define VER_FULLSTR			"@@fullverstr@@"'	>> src/version.h.in
   2.367 +	@echo ''												>> src/version.h.in
   2.368 +	@echo Build system initialised
   2.369 +
   2.370 +# remove the dependency files
   2.371 +cleandep:
   2.372 +	-rm $(DEPFILES)
   2.373 +
   2.374 +# remove the dependency files and any target or intermediate build files
   2.375 +clean:	cleandep clean-versioninfo
   2.376 +	-rm $(OBJ) $(TARGET) $(GARBAGE)
   2.377 +
   2.378 +# remove any dependency or intermediate build files
   2.379 +tidy:	cleandep clean-versioninfo
   2.380 +	-rm $(OBJ) $(GARBAGE)
   2.381 +
   2.382 +#################################
   2.383 +
   2.384 +$(TARGET):	$(OBJ) $(EXTDEP)
   2.385 +ifeq ($(SRC_TYPE),c)
   2.386 +	$(CC) $(CXXFLAGS) $(LDFLAGS) $(OBJ) $(LIBPTH) $(LIBLNK) -o $@
   2.387 +else
   2.388 +	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJ) $(LIBPTH) $(LIBLNK) -o $@
   2.389 +endif
   2.390 +ifeq ($(BUILD_TYPE),release)
   2.391 +	$(STRIP) $(TARGET)
   2.392 +endif
   2.393 +
   2.394 +###
   2.395 +# extra rules
   2.396 +# example:
   2.397 +#src/parser.c:	src/parser.h
   2.398 +
   2.399 +
   2.400 +####
   2.401 +## musashi build rules
   2.402 +# 68k CPU builder
   2.403 +obj/musashi/m68kmake:	obj/musashi/m68kmake.o
   2.404 +	$(CC) $(CFLAGS) $(CPPFLAGS) obj/musashi/m68kmake.o -o $@
   2.405 +# 68k CPU sources
   2.406 +src/musashi/m68kops.h src/musashi/m68kops.c:	obj/musashi/m68kmake src/musashi/m68k_in.c
   2.407 +	./obj/musashi/m68kmake src/musashi src/musashi/m68k_in.c
   2.408 +
   2.409 +####
   2.410 +# make object files from C source files
   2.411 +obj/%.o:	src/%.c
   2.412 +	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
   2.413 +
   2.414 +##
   2.415 +# make object files from C++ source files
   2.416 +obj/%.o:	src/%.cc
   2.417 +	$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
   2.418 +
   2.419 +obj/%.o:	src/%.cpp
   2.420 +	$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
   2.421 +
   2.422 +###
   2.423 +# make C files from yacc/bison source
   2.424 +src/%.h src/%.c:	src/%.y
   2.425 +	$(YACC) $(YFLAGS) -d $<
   2.426 +	mv -f y.tab.c $*.c
   2.427 +	mv -f y.tab.h $*.h
   2.428 +
   2.429 +###
   2.430 +# make C files from lex/flex source
   2.431 +src/%.c:	src/%.l
   2.432 +	$(LEX) $(LFLAGS) -o$@ $<
   2.433 +
   2.434 +###
   2.435 +# make dependencies for our source files
   2.436 +dep/%.d:	src/%.c
   2.437 +	$(CC) -MM $(CFLAGS) $(CPPFLAGS) $< > $@.$$$$; \
   2.438 +		sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
   2.439 +		rm -f $@.$$$$
   2.440 +
   2.441 +dep/%.d:	src/%.cpp
   2.442 +	$(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $< > $@.$$$$; \
   2.443 +		sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
   2.444 +		rm -f $@.$$$$
   2.445 +
   2.446 +dep/%.d:	src/%.cc
   2.447 +	$(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $< > $@.$$$$; \
   2.448 +		sed 's,\($*\)\.o[ :]*,obj/\1.o $@ : ,g' < $@.$$$$ > $@; \
   2.449 +		rm -f $@.$$$$
   2.450 +
   2.451 +####
   2.452 +# pull in the dependency files, but only for 'make $(TARGET)'
   2.453 +####
   2.454 +
   2.455 +ifeq ($(MAKECMDGOALS),$(TARGET))
   2.456 +  -include $(DEPFILES)
   2.457 +endif
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/dep/.keepme	Sat Nov 27 01:13:12 2010 +0000
     3.3 @@ -0,0 +1,1 @@
     3.4 +This file is a directory-keeper. Do not delete it.
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/obj/.keepme	Sat Nov 27 01:13:12 2010 +0000
     5.3 @@ -0,0 +1,1 @@
     5.4 +This file is a directory-keeper. Do not delete it.
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/main.c	Sat Nov 27 01:13:12 2010 +0000
     7.3 @@ -0,0 +1,6 @@
     7.4 +#include <stdio.h>
     7.5 +
     7.6 +int main(void)
     7.7 +{
     7.8 +	return 0;
     7.9 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/musashi/LICENSE	Sat Nov 27 01:13:12 2010 +0000
     8.3 @@ -0,0 +1,16 @@
     8.4 +From private email, dated 2010-Nov-26, 20:43 GMT:
     8.5 +
     8.6 +From: Karl Stenerud <kstenerud@gmail.com>
     8.7 +Subject: Re: Musashi 68k emulator
     8.8 +
     8.9 +On 2010-11-26, at 12:36 PM, Philip Pemberton wrote:
    8.10 +
    8.11 +> > I do have one question, though more related to licensing than the core itself...
    8.12 +> > 
    8.13 +> > I was planning to release my emulator under an open-source licence, probably the GPL or something along those lines (the worst case scenario IMO would be someone adding a ton of nice features then refusing to release the source).
    8.14 +> > 
    8.15 +> > The "non-commercial use only" restriction in the Musashi license would seem to be at odds with the GPL, and would make it somewhat more difficult to tie in GPL-licensed libraries. Is there any possibility of getting v3.31 released under a less restrictive license, maybe GPL or LGPL?
    8.16 +> > 
    8.17 +
    8.18 +Sure, no problem.  I usually release stuff under an Apache license nowadays, but feel free to pick any FOSS license.
    8.19 +
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/musashi/example/Makefile	Sat Nov 27 01:13:12 2010 +0000
     9.3 @@ -0,0 +1,40 @@
     9.4 +CC =     gcc
     9.5 +WARNINGS = -Wall -pedantic
     9.6 +CFLAGS = $(WARNINGS) -c -Iobj -I. -I..
     9.7 +LFLAGS = $(WARNINGS)
     9.8 +
     9.9 +all: obj sim
    9.10 +
    9.11 +clean:
    9.12 +	rm -rf obj
    9.13 +	rm -f sim
    9.14 +
    9.15 +obj:
    9.16 +	mkdir obj
    9.17 +
    9.18 +sim: obj/sim.o obj/m68kcpu.o obj/m68kops.o obj/m68kopac.o obj/m68kopdm.o obj/m68kopnz.o
    9.19 +	$(CC) $(LFLAGS) obj/sim.o obj/m68kcpu.o obj/m68kops.o obj/m68kopac.o obj/m68kopdm.o obj/m68kopnz.o -o sim
    9.20 +
    9.21 +obj/sim.o: sim.c sim.h ../m68k.h ../m68kconf.h
    9.22 +	$(CC) $(CFLAGS) sim.c -o obj/sim.o
    9.23 +
    9.24 +obj/m68kcpu.o: sim.h obj/m68kops.h sim.h ../m68k.h ../m68kconf.h
    9.25 +	$(CC) $(CFLAGS) ../m68kcpu.c -o obj/m68kcpu.o
    9.26 +
    9.27 +obj/m68kops.o: obj/m68kmake obj/m68kops.h obj/m68kops.c sim.h ../m68k.h ../m68kconf.h
    9.28 +	$(CC) $(CFLAGS) obj/m68kops.c -o obj/m68kops.o
    9.29 +
    9.30 +obj/m68kopac.o: obj/m68kmake obj/m68kops.h obj/m68kopac.c sim.h ../m68k.h ../m68kconf.h
    9.31 +	$(CC) $(CFLAGS) obj/m68kopac.c -o obj/m68kopac.o
    9.32 +
    9.33 +obj/m68kopdm.o: obj/m68kmake obj/m68kops.h obj/m68kopdm.c sim.h ../m68k.h ../m68kconf.h
    9.34 +	$(CC) $(CFLAGS) obj/m68kopdm.c -o obj/m68kopdm.o
    9.35 +
    9.36 +obj/m68kopnz.o: obj/m68kmake obj/m68kops.h obj/m68kopnz.c sim.h ../m68k.h ../m68kconf.h
    9.37 +	$(CC) $(CFLAGS) obj/m68kopnz.c -o obj/m68kopnz.o
    9.38 +
    9.39 +obj/m68kops.h: obj/m68kmake
    9.40 +	obj/m68kmake obj ../m68k_in.c
    9.41 +
    9.42 +obj/m68kmake: ../m68kmake.c ../m68k_in.c
    9.43 +	$(CC) $(WARNINGS) ../m68kmake.c -o obj/m68kmake
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/musashi/example/example.txt	Sat Nov 27 01:13:12 2010 +0000
    10.3 @@ -0,0 +1,301 @@
    10.4 +EXAMPLE:
    10.5 +-------
    10.6 +As an example, I'll build an imaginary hardware platform.
    10.7 +
    10.8 +
    10.9 +The system is fairly simple, comprising of a 000, an input device, an output
   10.10 +device, a non-maskable-interrupt device, and an interrupt controller.
   10.11 +
   10.12 +
   10.13 +The input device receives input from the user and asserts its interrupt
   10.14 +request line until its value is read.  Reading from the input device's
   10.15 +memory-mapped port will both clear its interrupt request and read an ASCII
   10.16 +representation (8 bits) of what the user entered.
   10.17 +
   10.18 +The output device reads value when it is selected through its memory-mapped
   10.19 +port and outputs it to a display.  The value it reads will be interpreted as
   10.20 +an ASCII value and output to the display. The output device is fairly slow
   10.21 +(it can only process 1 byte per second), and so it asserts its interrupt
   10.22 +request line when it is ready to receive a byte.  Writing to the output device
   10.23 +sends a byte to it.  If the output device is not ready, the write is ignored.
   10.24 +Reading from the output device returns 0 and clears its interrupt request line
   10.25 +until another byte is written to it and 1 second elapses.
   10.26 +
   10.27 +The non-maskable-interrupt (NMI) device, as can be surmised from the name,
   10.28 +generates a non-maskable-interrupt.  This is connected to some kind of external
   10.29 +switch that the user can push to generate a NMI.
   10.30 +
   10.31 +Since there are 3 devices interrupting the CPU, an interrupt controller is
   10.32 +needed.  The interrupt controller takes 7 inputs and encodes the highest
   10.33 +priority asserted line on the 3 output pins.  the input device is wired to IN2
   10.34 +and the output device is wired to IN1 on the controller.  The NMI device is
   10.35 +wired to IN7 and all the other inputs are wired low.
   10.36 +
   10.37 +The bus is also connected to a 1K ROM and a 256 byte RAM.
   10.38 +Beware: This platform places ROM and RAM in the same address range and uses
   10.39 +        the FC pins to select the correct address space!
   10.40 +        (You didn't expect me to make it easy, did you? =)
   10.41 +
   10.42 +There are two ways to handle address spaces with Musashi:
   10.43 +
   10.44 +1. Enable M68K_SEPARATE_READS and make handler functions for immediate and
   10.45 +   pc-relative reads.
   10.46 +
   10.47 +2. Enable M68K_EMULATE_FC and make a callback function for function code
   10.48 +   changes.
   10.49 +
   10.50 +Both methods will work in this case, but I've opted for the "more correct"
   10.51 +function code pin emulation for this example.
   10.52 +
   10.53 +
   10.54 +
   10.55 +Here is the schematic in all its ASCII splendour:
   10.56 +-------------------------------------------------
   10.57 +
   10.58 +     NMI     TIED
   10.59 +    SWITCH   LOW
   10.60 +      |       |
   10.61 +      | +-+-+-+
   10.62 +      | | | | | +------------------------------------------------+
   10.63 +      | | | | | | +------------------------------------+         |
   10.64 +      | | | | | | |                                    |         |
   10.65 +     +-------------+                                   |         |
   10.66 +     |7 6 5 4 3 2 1|                                   |         |
   10.67 +     |             |                                   |         |
   10.68 +     | INT CONTRLR |                                   |         |
   10.69 +     |             |                                   |         |
   10.70 +     |i i i        |                                   |         |
   10.71 +     |2 1 0        |                                   |         |
   10.72 +     +-------------+                                   |         |
   10.73 +      | | |                                            |         |
   10.74 +      | | |     +--------------------------------+--+  |         |
   10.75 +      o o o     |                                |  |  |         |
   10.76 +    +--------------+  +-------+  +----------+  +---------+  +----------+
   10.77 +    | I I I     a  |  |       |  |          |  | r  a  i |  |    i     |
   10.78 +    | 2 1 0    23  |  |       |  |          |  | e  c    |  |          |
   10.79 +    |              |  |       |  |          |  | a  k    |  |          |
   10.80 +    |              |  |       |  |          |  | d       |  |          |
   10.81 +    |              |  |       |  |          |  |         |  |          |
   10.82 +    |    M68000    |  |  ROM  |  |   RAM    |  |   IN    |  |   OUT    |
   10.83 +    |              |  |       |  |          |  |         |  |          |
   10.84 +    |            a9|--|a9     |--|          |--|         |--|          |
   10.85 +    |            a8|--|a8     |--|          |--|         |--|          |
   10.86 +    |            a7|--|a7     |--|a7        |--|         |--|          |
   10.87 +    |            a6|--|a6     |--|a6        |--|         |--|          |
   10.88 +    |            a5|--|a5     |--|a5        |--|         |--|          |
   10.89 +    |            a4|--|a4     |--|a4        |--|         |--|          |
   10.90 +    |            a3|--|a3     |--|a3        |--|         |--|          |
   10.91 +    |            a2|--|a2     |--|a2        |--|         |--|          |
   10.92 +    |            a1|--|a1     |--|a1        |--|         |--|          |
   10.93 +    |            a0|--|a0     |--|a0        |--|         |--|          |
   10.94 +    |              |  |       |  |          |  |         |  |          |
   10.95 +    |           d15|--|d15    |--|d15       |--|         |--|          |
   10.96 +    |           d14|--|d14    |--|d14       |--|         |--|          |
   10.97 +    |           d13|--|d13    |--|d13       |--|         |--|          |
   10.98 +    |           d12|--|d12    |--|d12       |--|         |--|          |
   10.99 +    |           d11|--|d11    |--|d11       |--|         |--|          |
  10.100 +    |           d10|--|d10    |--|d10       |--|         |--|          |
  10.101 +    |            d9|--|d9     |--|d9        |--|         |--|          |
  10.102 +    |            d8|--|d8     |--|d8        |--|         |--|          |
  10.103 +    |            d7|--|d7     |--|d7        |--|d7       |--|d7        |
  10.104 +    |            d6|--|d6     |--|d6        |--|d6       |--|d6        |
  10.105 +    |            d5|--|d5     |--|d5        |--|d5       |--|d5        |
  10.106 +    |            d4|--|d4     |--|d4        |--|d4       |--|d4        |
  10.107 +    |            d3|--|d3     |--|d3        |--|d3       |--|d3        |
  10.108 +    |            d2|--|d2     |--|d2        |--|d2       |--|d2        |
  10.109 +    |            d1|--|d1     |--|d1        |--|d1       |--|d1  w     |
  10.110 +    |            d0|--|d0     |--|d0        |--|d0       |--|d0  r     |
  10.111 +    |              |  |       |  |          |  |         |  |    i   a |
  10.112 +    | a      F F F |  |       |  |          |  |         |  |    t   c |
  10.113 +    |22  rW  2 1 0 |  |  cs   |  | cs   rW  |  |         |  |    e   k |
  10.114 +    +--------------+  +-------+  +----------+  +---------+  +----------+
  10.115 +      |   |  | | |        |         |    |                       |   |
  10.116 +      |   |  | | |        |         |    |                       |   |
  10.117 +      |   |  | | |    +-------+  +-----+ |                     +---+ |
  10.118 +      |   |  | | |    |  IC1  |  | IC2 | |                     |AND| |
  10.119 +      |   |  | | |    |a b c d|  |a b c| |                     +---+ |
  10.120 +      |   |  | | |    +-------+  +-----+ |                      | |  |
  10.121 +      |   |  | | |     | | | |    | | |  |                      | +--+
  10.122 +      |   |  | | |     | | | |    | | |  |                      | |
  10.123 +      |   |  | | |     | | | |    | | |  |                      | |
  10.124 +      |   |  | | |     | | | |    | | |  |                      | |
  10.125 +      |   |  | | +-----)-)-+-)----)-)-+  |                      | |
  10.126 +      |   |  | +-------)-+---)----)-+    |                      | |
  10.127 +      |   |  +---------+-----)----+      |                      | |
  10.128 +      |   |                  |           |                      | |
  10.129 +      |   +------------------+-----------+----------------------+ |
  10.130 +      |                                                           |
  10.131 +      +-----------------------------------------------------------+
  10.132 +
  10.133 +IC1: output=1 if a=0 and b=1 and c=0 and d=0
  10.134 +IC2: output=1 if a=0 and b=0 and c=1
  10.135 +
  10.136 +
  10.137 +
  10.138 +Here is the listing for program.bin:
  10.139 +-----------------------------------
  10.140 +
  10.141 +                        INPUT_ADDRESS   equ $800000
  10.142 +                        OUTPUT_ADDRESS  equ $400000
  10.143 +                        CIRCULAR_BUFFER equ $c0
  10.144 +                        CAN_OUTPUT      equ $d0
  10.145 +                        STACK_AREA      equ $100
  10.146 +                        
  10.147 +                        vector_table:
  10.148 +00000000 0000 0100      	dc.l STACK_AREA				*  0: SP
  10.149 +00000004 0000 00c0      	dc.l init					*  1: PC
  10.150 +00000008 0000 0148      	dc.l unhandled_exception	*  2: bus error
  10.151 +0000000c 0000 0148      	dc.l unhandled_exception	*  3: address error
  10.152 +00000010 0000 0148      	dc.l unhandled_exception	*  4: illegal instruction
  10.153 +00000014 0000 0148      	dc.l unhandled_exception	*  5: zero divide
  10.154 +00000018 0000 0148      	dc.l unhandled_exception	*  6: chk
  10.155 +0000001c 0000 0148      	dc.l unhandled_exception	*  7: trapv
  10.156 +00000020 0000 0148      	dc.l unhandled_exception	*  8: privilege violation
  10.157 +00000024 0000 0148      	dc.l unhandled_exception	*  9: trace
  10.158 +00000028 0000 0148      	dc.l unhandled_exception	* 10: 1010
  10.159 +0000002c 0000 0148      	dc.l unhandled_exception	* 11: 1111
  10.160 +00000030 0000 0148      	dc.l unhandled_exception	* 12: -
  10.161 +00000034 0000 0148      	dc.l unhandled_exception	* 13: -
  10.162 +00000038 0000 0148      	dc.l unhandled_exception	* 14: -
  10.163 +0000003c 0000 0148      	dc.l unhandled_exception	* 15: uninitialized interrupt
  10.164 +00000040 0000 0148      	dc.l unhandled_exception	* 16: -
  10.165 +00000044 0000 0148      	dc.l unhandled_exception	* 17: -
  10.166 +00000048 0000 0148      	dc.l unhandled_exception	* 18: -
  10.167 +0000004c 0000 0148      	dc.l unhandled_exception	* 19: -
  10.168 +00000050 0000 0148      	dc.l unhandled_exception	* 20: -
  10.169 +00000054 0000 0148      	dc.l unhandled_exception	* 21: -
  10.170 +00000058 0000 0148      	dc.l unhandled_exception	* 22: -
  10.171 +0000005c 0000 0148      	dc.l unhandled_exception	* 23: -
  10.172 +00000060 0000 0148      	dc.l unhandled_exception	* 24: spurious interrupt
  10.173 +00000064 0000 0136      	dc.l output_ready			* 25: l1 irq
  10.174 +00000068 0000 010e      	dc.l input_ready			* 26: l2 irq
  10.175 +0000006c 0000 0148      	dc.l unhandled_exception	* 27: l3 irq
  10.176 +00000070 0000 0148      	dc.l unhandled_exception	* 28: l4 irq
  10.177 +00000074 0000 0148      	dc.l unhandled_exception	* 29: l5 irq
  10.178 +00000078 0000 0148      	dc.l unhandled_exception	* 30: l6 irq
  10.179 +0000007c 0000 014e      	dc.l nmi					* 31: l7 irq
  10.180 +00000080 0000 0148      	dc.l unhandled_exception	* 32: trap 0
  10.181 +00000084 0000 0148      	dc.l unhandled_exception	* 33: trap 1
  10.182 +00000088 0000 0148      	dc.l unhandled_exception	* 34: trap 2
  10.183 +0000008c 0000 0148      	dc.l unhandled_exception	* 35: trap 3
  10.184 +00000090 0000 0148      	dc.l unhandled_exception	* 36: trap 4
  10.185 +00000094 0000 0148      	dc.l unhandled_exception	* 37: trap 5
  10.186 +00000098 0000 0148      	dc.l unhandled_exception	* 38: trap 6
  10.187 +0000009c 0000 0148      	dc.l unhandled_exception	* 39: trap 7
  10.188 +000000a0 0000 0148      	dc.l unhandled_exception	* 40: trap 8
  10.189 +000000a4 0000 0148      	dc.l unhandled_exception	* 41: trap 9
  10.190 +000000a8 0000 0148      	dc.l unhandled_exception	* 42: trap 10
  10.191 +000000ac 0000 0148      	dc.l unhandled_exception	* 43: trap 11
  10.192 +000000b0 0000 0148      	dc.l unhandled_exception	* 44: trap 12
  10.193 +000000b4 0000 0148      	dc.l unhandled_exception	* 45: trap 13
  10.194 +000000b8 0000 0148      	dc.l unhandled_exception	* 46: trap 14
  10.195 +000000bc 0000 0148      	dc.l unhandled_exception	* 47: trap 15
  10.196 +                        * This is the end of the useful part of the table.
  10.197 +                        * We will now do the Capcom thing and put code starting at $c0.
  10.198 +                        
  10.199 +                        init:
  10.200 +                        * Copy the exception vector table to RAM.
  10.201 +000000c0 227c 0000 0000 	move.l  #0, a1						* a1 is RAM index
  10.202 +000000c6 303c 002f      	move.w  #47, d0						* d0 is counter (48 vectors)
  10.203 +000000ca 41fa 0006      	lea.l   (copy_table,PC), a0			* a0 is scratch
  10.204 +000000ce 2208           	move.l  a0, d1						* d1 is ROM index
  10.205 +000000d0 4481           	neg.l   d1
  10.206 +                        copy_table:
  10.207 +000000d2 22fb 18fe      	dc.l    $22fb18fe					* #%#$ as68k generates 020 code here
  10.208 +                        *	move.l  (copy_table,PC,d1.l), (a1)+
  10.209 +000000d6 5841           	addq    #4, d1
  10.210 +000000d8 51c8 fff8      	dbf     d0, copy_table
  10.211 +                        
  10.212 +                        main_init:
  10.213 +                        * Initialize main program
  10.214 +000000dc 11fc 0000 00d0 	move.b  #0, CAN_OUTPUT
  10.215 +000000e2 4df8 00c0      	lea.l   CIRCULAR_BUFFER, a6
  10.216 +000000e6 7c00           	moveq   #0, d6						* output buffer ptr
  10.217 +000000e8 7e00           	moveq   #0, d7						* input buffer ptr
  10.218 +000000ea 027c f8ff      	andi    #$f8ff, SR					* clear interrupt mask
  10.219 +                        main:
  10.220 +                        * Main program
  10.221 +000000ee 4a38 00d0      	tst.b   CAN_OUTPUT					* can we output?
  10.222 +000000f2 67fa           	beq     main
  10.223 +000000f4 be06           	cmp.b   d6, d7						* is there data?
  10.224 +000000f6 67f6           	beq     main
  10.225 +000000f8 11fc 0000 00d0 	move.b  #0, CAN_OUTPUT
  10.226 +000000fe 13f6 6000 0040 	move.b  (0,a6,d6.w), OUTPUT_ADDRESS	* write data
  10.227 +         0000
  10.228 +00000106 5246           	addq    #1, d6
  10.229 +00000108 0206 000f      	andi.b  #15, d6						* update circular buffer
  10.230 +0000010c 60e0           	bra     main
  10.231 +                        
  10.232 +                        
  10.233 +                        input_ready:
  10.234 +0000010e 2f00           	move.l  d0, -(a7)
  10.235 +00000110 2f01           	move.l  d1, -(a7)
  10.236 +00000112 1239 0080 0000 	move.b  INPUT_ADDRESS, d1			* read data
  10.237 +00000118 1007           	move.b  d7, d0						* check if buffer full
  10.238 +0000011a 5240           	addq    #1, d0
  10.239 +0000011c 0200 000f      	andi.b  #15, d0
  10.240 +00000120 bc00           	cmp.b   d0, d6
  10.241 +00000122 6700 000c      	beq     input_ready_quit			* throw away if full
  10.242 +00000126 1d81 7000      	move.b  d1, (0,a6,d7.w)				* store the data
  10.243 +0000012a 5247           	addq    #1, d7
  10.244 +0000012c 0207 000f      	andi.b  #15, d7						* update circular buffer
  10.245 +                        input_ready_quit:
  10.246 +00000130 221f           	move.l  (a7)+, d1
  10.247 +00000132 201f           	move.l  (a7)+, d0
  10.248 +00000134 4e73           	rte
  10.249 +                        
  10.250 +                        output_ready:
  10.251 +00000136 2f00           	move.l  d0, -(a7)
  10.252 +00000138 11fc 0001 00d0 	move.b  #1, CAN_OUTPUT
  10.253 +0000013e 1039 0040 0000 	move.b  OUTPUT_ADDRESS, d0			* acknowledge the interrupt
  10.254 +00000144 201f           	move.l  (a7)+, d0
  10.255 +00000146 4e73           	rte
  10.256 +                        
  10.257 +                        unhandled_exception:
  10.258 +00000148 4e72 2700      	stop	#$2700						* wait for NMI
  10.259 +0000014c 60fa           	bra     unhandled_exception			* shouldn't get here
  10.260 +                        
  10.261 +                        nmi:
  10.262 +                        * perform a soft reset
  10.263 +0000014e 46fc 2700      	move    #$2700, SR					* set status register
  10.264 +00000152 2e7a feac      	move.l  (vector_table,PC), a7		* reset stack pointer
  10.265 +00000156 4e70           	reset								* reset peripherals
  10.266 +00000158 4efa feaa      	jmp     (vector_table+4,PC)			* reset program counter
  10.267 +                        
  10.268 +                        END
  10.269 +
  10.270 +
  10.271 +
  10.272 +Compiling the example host environment:
  10.273 +--------------------------------------
  10.274 +
  10.275 +The following assumes that you are using a GNU-based compiler such as gcc or
  10.276 +djgpp for DOS (available free from www.delorie.com).
  10.277 +If you are using a commercial compiler, you may have to modify the makefile
  10.278 +or generate your own project file.
  10.279 +Also note that part of the compilation process involves the compilation and
  10.280 +invokation of the m68kmake program.
  10.281 +
  10.282 +- Copy the m68k files to a directory.  Then copy the host environment files to
  10.283 +  the same directory, overwriting m68kconf.h.  program.bin is the actual 68000
  10.284 +  program you will be running.
  10.285 +- Modify osd_get_key() in sim.c to suit your environment (currently set for
  10.286 +  the free djgpp compiler, available from www.delorie.com, under DOS).
  10.287 +- Type make
  10.288 +- Perform the necessary animal sacrifices.
  10.289 +- Type sim program.bin
  10.290 +
  10.291 +
  10.292 +Keys:
  10.293 +	ESC           - quits the simulator
  10.294 +	~             - generates an NMI interrupt
  10.295 +	Any other key - Genearate input for the input device
  10.296 +
  10.297 +
  10.298 +Note: I've cheated a bit in the emulation.  There is no speed control
  10.299 +      to set the speed the CPU runs at; it simply runs as fast as your
  10.300 +      processor can run it.
  10.301 +      To add speed control, you will need a high-precision timestamp
  10.302 +      function (like the RDTSC instruction for newer Pentium CPUs)
  10.303 +      and a bit of arithmetic to make the cycles argument for m68k_execute().
  10.304 +      I'll leave that as an excercise to the reader.
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/musashi/example/history.txt	Sat Nov 27 01:13:12 2010 +0000
    11.3 @@ -0,0 +1,114 @@
    11.4 +The history of Musashi for anyone who might be interested:
    11.5 +---------------------------------------------------------
    11.6 +
    11.7 +Musashi was born out of sheer boredom.
    11.8 +I needed something to code, and so having had fun with a few of the emulators
    11.9 +around, I decided to try my hand at CPU emulation.
   11.10 +I had owned an Amiga for many years and had done some assembly coding on it so
   11.11 +I figured it would be the ideal chip to cut my teeth on.
   11.12 +Had I known then how much work was involved in emulating a chip like this, I
   11.13 +may not have even started ;-)
   11.14 +
   11.15 +
   11.16 +
   11.17 +12-May-1998: First outline
   11.18 +
   11.19 +11-Jun-1998: Early disassembler
   11.20 +
   11.21 +20-Nov-1998: First prototype v0.1
   11.22 +
   11.23 +04-Dec-1998: Final prototype v0.4
   11.24 +
   11.25 +20-Dec-1998: Beta release of Musashi v0.5 that could run Rastan Saga under MAME
   11.26 +             (barely).
   11.27 +
   11.28 +06-Jan-1999: Musashi 1.0 released
   11.29 +
   11.30 +17-Mar-1999: Musashi 2.0 released
   11.31 +             - Major code overhaul.
   11.32 +             - Replaced monolithic codebase with a code generator program.
   11.33 +             - Added correct m68000 timing.
   11.34 +             - Moved timing into the opcode handlers.
   11.35 +
   11.36 +25-Mar-1999: Musashi 2.1 released
   11.37 +             - Added support for m68010.
   11.38 +             - Many bugfixes.
   11.39 +
   11.40 +13-May-1999: Musashi 2.2 released
   11.41 +             - Added support for m68020.
   11.42 +             - Lots of bugfixes.
   11.43 +
   11.44 +05-Apr-2000: Musashi 3.0 released
   11.45 +             - Major code overhaul.
   11.46 +             - Rewrote code generator program and changed the format of
   11.47 +               m68k_in.c.
   11.48 +             - Added support for m68ec020.
   11.49 +             - Removed timing from the opcode handlers.
   11.50 +             - Added correct timing for m68000, m68010, and m68020.
   11.51 +               Note: 68020 timing is the cache timing from the manual.
   11.52 +             - Removed the m68k_peek_xxx() and m68k_poke_xxx() instructions and
   11.53 +               replaced them with m68k_get_reg() and m68k_set_reg().
   11.54 +             - Added support for function codes.
   11.55 +             - Revamped m68kconf.h to be easier to configure and more powerful.
   11.56 +             - Added option to separate immediate and normal reads.
   11.57 +             - Added support for (undocumented) m68000 instruction prefetch.
   11.58 +             - Rewrote indexed addressing mode handling.
   11.59 +             - Rewrote interrupt handling.
   11.60 +             - Fixed a masking bug for m68k_get_reg() when requesting the PC.
   11.61 +             - Moved the instruction table sorting routine to m68kmake.c so
   11.62 +               that it is invoked at compile time rather than at runtime.
   11.63 +             - Rewrote the exception handling routines to support different
   11.64 +               stack frames (needed for m68020 emulation).
   11.65 +             - Rewrote faster status register and condition code flag handling
   11.66 +               functions / macros.
   11.67 +             - Fixed function code handling to fetch from program space when
   11.68 +               using pc-relative addressing.
   11.69 +             - Fixed initial program counter and stack pointer fetching on
   11.70 +               reset (loads from program space now).
   11.71 +             - A lot of code cleanup.
   11.72 +             - LOTS of bugfixes (especially in the m68020 code).
   11.73 +
   11.74 +28-May-2000: Musashi 3.1 released
   11.75 +             - Fixed bug in m68k_get_reg() that retrieved the wrong value for
   11.76 +               the status register.
   11.77 +             - Fixed register bug in movec.
   11.78 +             - Fixed cpu type comparison problem that caused indexed
   11.79 +               addressing modes to be incorrectly interpreted when in m68ec020
   11.80 +               mode.
   11.81 +             - Added code to speed up busy waiting on some branch instructions.
   11.82 +             - Fixed some bfxxx opcode bugs.
   11.83 +
   11.84 +14-Aug-2000: Musashi 3.2 released
   11.85 +             - Fixed RTE bug that killed the program counter when in m68020
   11.86 +               mode.
   11.87 +             - Minor fixes in negx and nbcd.
   11.88 +             - renamed d68k.c to m68kdasm.c and merged d68k.h into m68k.h.
   11.89 +               d68k_read_xxx() instructions have been renamed to
   11.90 +               m68k_read_xxx_disassembler().
   11.91 +             - Rewrote exception processing and fixed 68020 stack frame
   11.92 +               problems.
   11.93 +             - FINALLY fixed the mull and divl instructions.
   11.94 +             - Added 64-bit safe code fixes.
   11.95 +             - Added 64-bit optimizations (these will only  be ANSI compliant
   11.96 +               under c9x, and so to use them you must turn on M68K_USE_64_BIT
   11.97 +               in m68kconf.h).
   11.98 +
   11.99 +27-Jan-2001: Musashi 3.3 released
  11.100 +             Note: This is the last release of Musashi before I separate the
  11.101 +                   68020 core.
  11.102 +             - Fixed problem when displaying negative numbers in disassembler
  11.103 +             - Fixed cpu type selector - was allowing 020 instructions to be
  11.104 +               disassembled when in 000 mode.
  11.105 +             - Fixed opcode jumptable generator (ambiguous operators in the
  11.106 +               test for f-line ops)
  11.107 +             - Fixed signed/unsigned problem in divl and mull opcodes (not
  11.108 +               sure if this was causing an error but best to be sure)
  11.109 +             - Cleaned up the naming scheme for the opcode handlers
  11.110 +
  11.111 +02-Feb-2001: Musashi 3.3.1 released
  11.112 +             Note: due to the pc-relative requirement for some new drivers
  11.113 +                   in MAME, I've released this small update.
  11.114 +             - Added pc-relative read modes
  11.115 +             - small optimizations to the exception handling that will help
  11.116 +               when splitting the cores
  11.117 +             - Updated the example (oops!)
    12.1 Binary file src/musashi/example/program.bin has changed
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/musashi/example/readme.txt	Sat Nov 27 01:13:12 2010 +0000
    13.3 @@ -0,0 +1,315 @@
    13.4 +                                    MUSASHI
    13.5 +                                    =======
    13.6 +
    13.7 +                                  Version 3.3
    13.8 +
    13.9 +             A portable Motorola M680x0 processor emulation engine.
   13.10 +            Copyright 1998-2001 Karl Stenerud.  All rights reserved.
   13.11 +
   13.12 +
   13.13 +
   13.14 +INTRODUCTION:
   13.15 +------------
   13.16 +
   13.17 +Musashi is a Motorola 68000, 68010, 68EC020, and 68020 emulator written in C.
   13.18 +This emulator was written with two goals in mind: portability and speed.
   13.19 +
   13.20 +The emulator is written to ANSI C specifications with the exception that I use
   13.21 +inline functions.  This is not compliant to the ANSI spec, but will be
   13.22 +compliant to the ANSI C9X spec.
   13.23 +
   13.24 +It has been successfully running in the MAME project (www.mame.net) for over 2
   13.25 +years and so has had time to mature.
   13.26 +
   13.27 +
   13.28 +
   13.29 +LICENSE AND COPYRIGHT:
   13.30 +---------------------
   13.31 +
   13.32 +The Musashi M680x0 emulator is copyright 1998-2001 Karl Stenerud.
   13.33 +
   13.34 +The source code included in this archive is provided AS-IS, free for any
   13.35 +non-commercial purpose.
   13.36 +
   13.37 +If you build a program using this core, please give credit to the author.
   13.38 +
   13.39 +If you wish to use this core in a commercial environment, please contact
   13.40 +the author to discuss commercial licensing.
   13.41 +
   13.42 +
   13.43 +
   13.44 +AVAILABILITY:
   13.45 +------------
   13.46 +The latest version of this code can be obtained at:
   13.47 +http://kstenerud.cjb.net
   13.48 +
   13.49 +
   13.50 +
   13.51 +CONTACTING THE AUTHOR:
   13.52 +---------------------
   13.53 +I can be reached at kstenerud@mame.net
   13.54 +
   13.55 +
   13.56 +
   13.57 +BASIC CONFIGURATION:
   13.58 +-------------------
   13.59 +The basic configuration will give you a standard 68000 that has sufficient
   13.60 +functionality to work in a primitive environment.
   13.61 +
   13.62 +This setup assumes that you only have 1 device interrupting it, that the
   13.63 +device will always request an autovectored interrupt, and it will always clear
   13.64 +the interrupt before the interrupt service routine finishes (but could
   13.65 +possibly re-assert the interrupt).
   13.66 +You will have only one address space, no tracing, and no instruction prefetch.
   13.67 +
   13.68 +To implement the basic configuration:
   13.69 +
   13.70 +- Open m68kconf.h and verify that the settings for INLINE and DECL_SPEC will
   13.71 +  work with your compiler. (They are set for gcc)
   13.72 +
   13.73 +- In your host program, implement the following functions:
   13.74 +    unsigned int  m68k_read_memory_8(unsigned int address);
   13.75 +    unsigned int  m68k_read_memory_16(unsigned int address);
   13.76 +    unsigned int  m68k_read_memory_32(unsigned int address);
   13.77 +    void m68k_write_memory_8(unsigned int address, unsigned int value);
   13.78 +    void m68k_write_memory_16(unsigned int address, unsigned int value);
   13.79 +    void m68k_write_memory_32(unsigned int address, unsigned int value);
   13.80 +
   13.81 +- In your host program, be sure to call m68k_pulse_reset() once before calling
   13.82 +  any of the other functions as this initializes the core.
   13.83 +
   13.84 +- Use m68k_execute() to execute instructions and m68k_set_irq() to cause an
   13.85 +  interrupt.
   13.86 +
   13.87 +
   13.88 +
   13.89 +ADDING PROPER INTERRUPT HANDLING:
   13.90 +--------------------------------
   13.91 +The interrupt handling in the basic configuration doesn't emulate the
   13.92 +interrupt acknowledge phase of the CPU and automatically clears an interrupt
   13.93 +request during interrupt processing.
   13.94 +While this works for most systems, you may need more accurate interrupt
   13.95 +handling.
   13.96 +
   13.97 +To add proper interrupt handling:
   13.98 +
   13.99 +- In m68kconf.h, set M68K_EMULATE_INT_ACK to OPT_SPECIFY_HANDLER
  13.100 +
  13.101 +- In m68kconf.h, set M68K_INT_ACK_CALLBACK(A) to your interrupt acknowledge
  13.102 +  routine
  13.103 +
  13.104 +- Your interrupt acknowledge routine must return an interrupt vector,
  13.105 +  M68K_INT_ACK_AUTOVECTOR, or M68K_INT_ACK_SPURIOUS.  most m68k
  13.106 +  implementations just use autovectored interrupts.
  13.107 +
  13.108 +- When the interrupting device is satisfied, you must call m68k_set_irq(0) to
  13.109 +  remove the interrupt request.
  13.110 +
  13.111 +
  13.112 +
  13.113 +MULTIPLE INTERRUPTS:
  13.114 +-------------------
  13.115 +The above system will work if you have only one device interrupting the CPU,
  13.116 +but if you have more than one device, you must do a bit more.
  13.117 +
  13.118 +To add multiple interrupts:
  13.119 +
  13.120 +- You must make an interrupt arbitration device that will take the highest
  13.121 +  priority interrupt and encode it onto the IRQ pins on the CPU.
  13.122 +
  13.123 +- The interrupt arbitration device should use m68k_set_irq() to set the
  13.124 +  highest pending interrupt, or 0 for no interrupts pending.
  13.125 +
  13.126 +
  13.127 +
  13.128 +SEPARATE IMMEDIATE AND PC-RELATIVE READS:
  13.129 +----------------------------------------
  13.130 +You can write faster memory access functions if you know whether you are
  13.131 +fetching from ROM or RAM.  Immediate reads are always from the program space
  13.132 +(Always in ROM unless it is running self-modifying code).
  13.133 +This will also separate the pc-relative reads, since some systems treat
  13.134 +PROGRAM mode reads and DATA mode reads differently (for program encryption,
  13.135 +for instance).  See the section below (ADDRESS SPACE) for an explanation of
  13.136 +PROGRAM and DATA mode.
  13.137 +
  13.138 +To enable separate reads:
  13.139 +
  13.140 +- In m68kconf.h, turn on M68K_SEPARATE_READS.
  13.141 +
  13.142 +- In your host program, implement the following functions:
  13.143 +    unsigned int  m68k_read_immediate_16(unsigned int address);
  13.144 +    unsigned int  m68k_read_immediate_32(unsigned int address);
  13.145 +
  13.146 +    unsigned int  m68k_read_pcrelative_8(unsigned int address);
  13.147 +    unsigned int  m68k_read_pcrelative_16(unsigned int address);
  13.148 +    unsigned int  m68k_read_pcrelative_32(unsigned int address);
  13.149 +
  13.150 +- If you need to know the current PC (for banking and such), set
  13.151 +  M68K_MONITOR_PC to OPT_SPECIFY_HANDLER, and set M68K_SET_PC_CALLBACK(A) to
  13.152 +  your routine.
  13.153 +
  13.154 +
  13.155 +
  13.156 +ADDRESS SPACES:
  13.157 +--------------
  13.158 +Most systems will only implement one address space, placing ROM at the lower
  13.159 +addresses and RAM at the higher.  However, there is the possibility that a
  13.160 +system will implement ROM and RAM in the same address range, but in different
  13.161 +address spaces, or will have different mamory types that require different
  13.162 +handling for the program and the data.
  13.163 +
  13.164 +The 68k accomodates this by allowing different program spaces, the most
  13.165 +important to us being PROGRAM and DATA space.  Here is a breakdown of
  13.166 +how information is fetched:
  13.167 +
  13.168 +- All immediate reads are fetched from PROGRAM space.
  13.169 +
  13.170 +- All PC-relative reads are fetched from PROGRAM space.
  13.171 +
  13.172 +- The initial stack pointer and program counter are fetched from PROGRAM space.
  13.173 +
  13.174 +- All other reads (except for those from the moves instruction for 68020)
  13.175 +   are fetched from DATA space.
  13.176 +
  13.177 +The m68k deals with this by encoding the requested address space on the
  13.178 +function code pins:
  13.179 +
  13.180 +                       FC
  13.181 +    Address Space      210
  13.182 +    ------------------ ---
  13.183 +    USER DATA          001
  13.184 +    USER PROGRAM       010
  13.185 +    SUPERVISOR DATA    101
  13.186 +    SUPERVISOR PROGRAM 110
  13.187 +    CPU SPACE          111 <-- not emulated in this core since we emulate
  13.188 +                               interrupt acknowledge in another way.
  13.189 +
  13.190 +Problems arise here if you need to emulate this distinction (if, for example,
  13.191 +your ROM and RAM are at the same address range, with RAM and ROM enable
  13.192 +wired to the function code pins).
  13.193 +
  13.194 +There are 2 ways to deal with this situation using Musashi:
  13.195 +
  13.196 +1. If you only need the distinction between PROGRAM and DATA (the most common),
  13.197 +   you can just separate the reads (see the preceeding section).  This is the
  13.198 +   faster solution.
  13.199 +
  13.200 +2. You can emulate the function code pins entirely.
  13.201 +
  13.202 +To emulate the function code pins:
  13.203 +
  13.204 +- In m68kconf.h, set M68K_EMULATE_FC to OPT_SPECIFY_HANDLER and set
  13.205 +  M68K_SET_FC_CALLBACK(A) to your function code handler function.
  13.206 +
  13.207 +- Your function code handler should select the proper address space for
  13.208 +  subsequent calls to m68k_read_xx (and m68k_write_xx for 68010+).
  13.209 +
  13.210 +Note: immediate reads are always done from program space, so technically you
  13.211 +      don't need to implement the separate immediate reads, although you could
  13.212 +      gain more speed improvements leaving them in and doing some clever
  13.213 +      programming.
  13.214 +
  13.215 +
  13.216 +
  13.217 +USING DIFFERENT CPU TYPES:
  13.218 +-------------------------
  13.219 +The default is to enable only the 68000 cpu type.  To change this, change the
  13.220 +settings for M68K_EMULATE_010 etc in m68kconf.h.
  13.221 +
  13.222 +To set the CPU type you want to use:
  13.223 +
  13.224 +- Make sure it is enabled in m68kconf.h.  Current switches are:
  13.225 +    M68K_EMULATE_010
  13.226 +    M68K_EMULATE_EC020
  13.227 +    M68K_EMULATE_020
  13.228 +
  13.229 +- In your host program, call m68k_set_cpu_type() and then call
  13.230 +  m68k_pulse_reset().  Valid CPU types are:
  13.231 +    M68K_CPU_TYPE_68000,
  13.232 +    M68K_CPU_TYPE_68010,
  13.233 +    M68K_CPU_TYPE_68EC020,
  13.234 +    M68K_CPU_TYPE_68020
  13.235 +
  13.236 +
  13.237 +
  13.238 +CLOCK FREQUENCY:
  13.239 +---------------
  13.240 +In order to emulate the correct clock frequency, you will have to calculate
  13.241 +how long it takes the emulation to execute a certain number of "cycles" and
  13.242 +vary your calls to m68k_execute() accordingly.
  13.243 +As well, it is a good idea to take away the CPU's timeslice when it writes to
  13.244 +a memory-mapped port in order to give the device it wrote to a chance to
  13.245 +react.
  13.246 +
  13.247 +You can use the functions m68k_cycles_run(), m68k_cycles_remaining(),
  13.248 +m68k_modify_timeslice(), and m68k_end_timeslice() to do this.
  13.249 +Try to use large cycle values in your calls to m68k_execute() since it will
  13.250 +increase throughput.  You can always take away the timeslice later.
  13.251 +
  13.252 +
  13.253 +
  13.254 +MORE CORRECT EMULATION:
  13.255 +----------------------
  13.256 +You may need to enable these in order to properly emulate some of the more
  13.257 +obscure functions of the m68k:
  13.258 +
  13.259 +- M68K_EMULATE_BKPT_ACK causes the CPU to call a breakpoint handler on a BKPT
  13.260 +  instruction
  13.261 +
  13.262 +- M68K_EMULATE_TRACE causes the CPU to generate trace exceptions when the
  13.263 +  trace bits are set
  13.264 +
  13.265 +- M68K_EMULATE_RESET causes the CPU to call a reset handler on a RESET
  13.266 +  instruction.
  13.267 +
  13.268 +- M68K_EMULATE_PREFETCH emulates the 4-word instruction prefetch that is part
  13.269 +  of the 68000/68010 (needed for Amiga emulation).
  13.270 +
  13.271 +- call m68k_pulse_halt() to emulate the HALT pin.
  13.272 +
  13.273 +
  13.274 +
  13.275 +CONVENIENCE FUNCTIONS:
  13.276 +---------------------
  13.277 +These are in here for programmer convenience:
  13.278 +
  13.279 +- M68K_INSTRUCTION_HOOK lets you call a handler before each instruction.
  13.280 +
  13.281 +- M68K_LOG_ENABLE and M68K_LOG_1010_1111 lets you log illegal and A/F-line
  13.282 +  instructions.
  13.283 +
  13.284 +
  13.285 +
  13.286 +MULTIPLE CPU EMULATION:
  13.287 +----------------------
  13.288 +The default is to use only one CPU.  To use more than one CPU in this core,
  13.289 +there are some things to keep in mind:
  13.290 +
  13.291 +- To have different cpus call different functions, use OPT_ON instead of
  13.292 +  OPT_SPECIFY_HANDLER, and use the m68k_set_xxx_callback() functions to set
  13.293 +  your callback handlers on a per-cpu basis.
  13.294 +
  13.295 +- Be sure to call set_cpu_type() for each CPU you use.
  13.296 +
  13.297 +- Use m68k_set_context() and m68k_get_context() to switch to another CPU.
  13.298 +
  13.299 +
  13.300 +
  13.301 +LOAD AND SAVE CPU CONTEXTS FROM DISK:
  13.302 +------------------------------------
  13.303 +You can use them68k_load_context() and m68k_save_context() functions to load
  13.304 +and save the CPU state to disk.
  13.305 +
  13.306 +
  13.307 +
  13.308 +GET/SET INFORMATION FROM THE CPU:
  13.309 +--------------------------------
  13.310 +You can use m68k_get_reg() and m68k_set_reg() to gain access to the internals
  13.311 +of the CPU.
  13.312 +
  13.313 +
  13.314 +
  13.315 +EXAMPLE:
  13.316 +-------
  13.317 +
  13.318 +I have included a file example.zip that contains a full example.
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/musashi/example/sim.c	Sat Nov 27 01:13:12 2010 +0000
    14.3 @@ -0,0 +1,478 @@
    14.4 +#include <stdio.h>
    14.5 +#include <stdlib.h>
    14.6 +#include <stdarg.h>
    14.7 +#include <time.h>
    14.8 +#include "sim.h"
    14.9 +#include "m68k.h"
   14.10 +
   14.11 +/* Memory-mapped IO ports */
   14.12 +#define INPUT_ADDRESS 0x800000
   14.13 +#define OUTPUT_ADDRESS 0x400000
   14.14 +
   14.15 +/* IRQ connections */
   14.16 +#define IRQ_NMI_DEVICE 7
   14.17 +#define IRQ_INPUT_DEVICE 2
   14.18 +#define IRQ_OUTPUT_DEVICE 1
   14.19 +
   14.20 +/* Time between characters sent to output device (seconds) */
   14.21 +#define OUTPUT_DEVICE_PERIOD 1
   14.22 +
   14.23 +/* ROM and RAM sizes */
   14.24 +#define MAX_ROM 0xfff
   14.25 +#define MAX_RAM 0xff
   14.26 +
   14.27 +
   14.28 +/* Read/write macros */
   14.29 +#define READ_BYTE(BASE, ADDR) (BASE)[ADDR]
   14.30 +#define READ_WORD(BASE, ADDR) (((BASE)[ADDR]<<8) |			\
   14.31 +							  (BASE)[(ADDR)+1])
   14.32 +#define READ_LONG(BASE, ADDR) (((BASE)[ADDR]<<24) |			\
   14.33 +							  ((BASE)[(ADDR)+1]<<16) |		\
   14.34 +							  ((BASE)[(ADDR)+2]<<8) |		\
   14.35 +							  (BASE)[(ADDR)+3])
   14.36 +
   14.37 +#define WRITE_BYTE(BASE, ADDR, VAL) (BASE)[ADDR] = (VAL)%0xff
   14.38 +#define WRITE_WORD(BASE, ADDR, VAL) (BASE)[ADDR] = ((VAL)>>8) & 0xff;		\
   14.39 +									(BASE)[(ADDR)+1] = (VAL)&0xff
   14.40 +#define WRITE_LONG(BASE, ADDR, VAL) (BASE)[ADDR] = ((VAL)>>24) & 0xff;		\
   14.41 +									(BASE)[(ADDR)+1] = ((VAL)>>16)&0xff;	\
   14.42 +									(BASE)[(ADDR)+2] = ((VAL)>>8)&0xff;		\
   14.43 +									(BASE)[(ADDR)+3] = (VAL)&0xff
   14.44 +
   14.45 +
   14.46 +/* Prototypes */
   14.47 +void exit_error(char* fmt, ...);
   14.48 +int osd_get_char(void);
   14.49 +
   14.50 +unsigned int m68k_read_memory_8(unsigned int address);
   14.51 +unsigned int m68k_read_memory_16(unsigned int address);
   14.52 +unsigned int m68k_read_memory_32(unsigned int address);
   14.53 +void m68k_write_memory_8(unsigned int address, unsigned int value);
   14.54 +void m68k_write_memory_16(unsigned int address, unsigned int value);
   14.55 +void m68k_write_memory_32(unsigned int address, unsigned int value);
   14.56 +void cpu_pulse_reset(void);
   14.57 +void cpu_set_fc(unsigned int fc);
   14.58 +int cpu_irq_ack(int level);
   14.59 +
   14.60 +void nmi_device_reset(void);
   14.61 +void nmi_device_update(void);
   14.62 +int nmi_device_ack(void);
   14.63 +
   14.64 +void input_device_reset(void);
   14.65 +void input_device_update(void);
   14.66 +int input_device_ack(void);
   14.67 +unsigned int input_device_read(void);
   14.68 +void input_device_write(unsigned int value);
   14.69 +
   14.70 +void output_device_reset(void);
   14.71 +void output_device_update(void);
   14.72 +int output_device_ack(void);
   14.73 +unsigned int output_device_read(void);
   14.74 +void output_device_write(unsigned int value);
   14.75 +
   14.76 +void int_controller_set(unsigned int value);
   14.77 +void int_controller_clear(unsigned int value);
   14.78 +
   14.79 +void get_user_input(void);
   14.80 +
   14.81 +
   14.82 +/* Data */
   14.83 +unsigned int g_quit = 0;						/* 1 if we want to quit */
   14.84 +unsigned int g_nmi = 0;							/* 1 if nmi pending */
   14.85 +
   14.86 +int g_input_device_value = -1;					/* Current value in input device */
   14.87 +
   14.88 +unsigned int g_output_device_ready = 0;			/* 1 if output device is ready */
   14.89 +time_t g_output_device_last_output;				/* Time of last char output */
   14.90 +
   14.91 +unsigned int g_int_controller_pending = 0;		/* list of pending interrupts */
   14.92 +unsigned int g_int_controller_highest_int = 0;	/* Highest pending interrupt */
   14.93 +
   14.94 +unsigned char g_rom[MAX_ROM+1];					/* ROM */
   14.95 +unsigned char g_ram[MAX_RAM+1];					/* RAM */
   14.96 +unsigned int g_fc;								/* Current function code from CPU */
   14.97 +
   14.98 +
   14.99 +/* Exit with an error message.  Use printf syntax. */
  14.100 +void exit_error(char* fmt, ...)
  14.101 +{
  14.102 +	va_list args;
  14.103 +	va_start(args, fmt);
  14.104 +	vfprintf(stderr, fmt, args);
  14.105 +	va_end(args);
  14.106 +	fprintf(stderr, "\n");
  14.107 +
  14.108 +	exit(EXIT_FAILURE);
  14.109 +}
  14.110 +
  14.111 +/* OS-dependant code to get a character from the user.
  14.112 + * This function must not block, and must either return an ASCII code or -1.
  14.113 + */
  14.114 +//#include <conio.h>
  14.115 +int osd_get_char(void)
  14.116 +{
  14.117 +	int ch = -1;
  14.118 +/*	if(kbhit())
  14.119 +	{
  14.120 +		while(kbhit())
  14.121 +			ch = getch();
  14.122 +	}
  14.123 +*/	return ch;
  14.124 +}
  14.125 +
  14.126 +
  14.127 +/* Read data from RAM, ROM, or a device */
  14.128 +unsigned int m68k_read_memory_8(unsigned int address)
  14.129 +{
  14.130 +	if(g_fc & 2)	/* Program */
  14.131 +	{
  14.132 +		if(address > MAX_ROM)
  14.133 +			exit_error("Attempted to read byte from ROM address %08x", address);
  14.134 +		return READ_BYTE(g_rom, address);
  14.135 +	}
  14.136 +
  14.137 +	/* Otherwise it's data space */
  14.138 +	switch(address)
  14.139 +	{
  14.140 +		case INPUT_ADDRESS:
  14.141 +			return input_device_read();
  14.142 +		case OUTPUT_ADDRESS:
  14.143 +			return output_device_read();
  14.144 +		default:
  14.145 +			break;
  14.146 +	}
  14.147 +	if(address > MAX_RAM)
  14.148 +		exit_error("Attempted to read byte from RAM address %08x", address);
  14.149 +		return READ_BYTE(g_ram, address);
  14.150 +}
  14.151 +
  14.152 +unsigned int m68k_read_memory_16(unsigned int address)
  14.153 +{
  14.154 +	if(g_fc & 2)	/* Program */
  14.155 +	{
  14.156 +		if(address > MAX_ROM)
  14.157 +			exit_error("Attempted to read word from ROM address %08x", address);
  14.158 +		return READ_WORD(g_rom, address);
  14.159 +	}
  14.160 +
  14.161 +	/* Otherwise it's data space */
  14.162 +	switch(address)
  14.163 +	{
  14.164 +		case INPUT_ADDRESS:
  14.165 +			return input_device_read();
  14.166 +		case OUTPUT_ADDRESS:
  14.167 +			return output_device_read();
  14.168 +		default:
  14.169 +			break;
  14.170 +	}
  14.171 +	if(address > MAX_RAM)
  14.172 +		exit_error("Attempted to read word from RAM address %08x", address);
  14.173 +		return READ_WORD(g_ram, address);
  14.174 +}
  14.175 +
  14.176 +unsigned int m68k_read_memory_32(unsigned int address)
  14.177 +{
  14.178 +	if(g_fc & 2)	/* Program */
  14.179 +	{
  14.180 +		if(address > MAX_ROM)
  14.181 +			exit_error("Attempted to read long from ROM address %08x", address);
  14.182 +		return READ_LONG(g_rom, address);
  14.183 +	}
  14.184 +
  14.185 +	/* Otherwise it's data space */
  14.186 +	switch(address)
  14.187 +	{
  14.188 +		case INPUT_ADDRESS:
  14.189 +			return input_device_read();
  14.190 +		case OUTPUT_ADDRESS:
  14.191 +			return output_device_read();
  14.192 +		default:
  14.193 +			break;
  14.194 +	}
  14.195 +	if(address > MAX_RAM)
  14.196 +		exit_error("Attempted to read long from RAM address %08x", address);
  14.197 +		return READ_LONG(g_ram, address);
  14.198 +}
  14.199 +
  14.200 +
  14.201 +/* Write data to RAM or a device */
  14.202 +void m68k_write_memory_8(unsigned int address, unsigned int value)
  14.203 +{
  14.204 +	if(g_fc & 2)	/* Program */
  14.205 +		exit_error("Attempted to write %02x to ROM address %08x", value&0xff, address);
  14.206 +
  14.207 +	/* Otherwise it's data space */
  14.208 +	switch(address)
  14.209 +	{
  14.210 +		case INPUT_ADDRESS:
  14.211 +			input_device_write(value&0xff);
  14.212 +			return;
  14.213 +		case OUTPUT_ADDRESS:
  14.214 +			output_device_write(value&0xff);
  14.215 +			return;
  14.216 +		default:
  14.217 +			break;
  14.218 +	}
  14.219 +	if(address > MAX_RAM)
  14.220 +		exit_error("Attempted to write %02x to RAM address %08x", value&0xff, address);
  14.221 +	WRITE_BYTE(g_ram, address, value);
  14.222 +}
  14.223 +
  14.224 +void m68k_write_memory_16(unsigned int address, unsigned int value)
  14.225 +{
  14.226 +	if(g_fc & 2)	/* Program */
  14.227 +		exit_error("Attempted to write %04x to ROM address %08x", value&0xffff, address);
  14.228 +
  14.229 +	/* Otherwise it's data space */
  14.230 +	switch(address)
  14.231 +	{
  14.232 +		case INPUT_ADDRESS:
  14.233 +			input_device_write(value&0xffff);
  14.234 +			return;
  14.235 +		case OUTPUT_ADDRESS:
  14.236 +			output_device_write(value&0xffff);
  14.237 +			return;
  14.238 +		default:
  14.239 +			break;
  14.240 +	}
  14.241 +	if(address > MAX_RAM)
  14.242 +		exit_error("Attempted to write %04x to RAM address %08x", value&0xffff, address);
  14.243 +	WRITE_WORD(g_ram, address, value);
  14.244 +}
  14.245 +
  14.246 +void m68k_write_memory_32(unsigned int address, unsigned int value)
  14.247 +{
  14.248 +	if(g_fc & 2)	/* Program */
  14.249 +		exit_error("Attempted to write %08x to ROM address %08x", value, address);
  14.250 +
  14.251 +	/* Otherwise it's data space */
  14.252 +	switch(address)
  14.253 +	{
  14.254 +		case INPUT_ADDRESS:
  14.255 +			input_device_write(value);
  14.256 +			return;
  14.257 +		case OUTPUT_ADDRESS:
  14.258 +			output_device_write(value);
  14.259 +			return;
  14.260 +		default:
  14.261 +			break;
  14.262 +	}
  14.263 +	if(address > MAX_RAM)
  14.264 +		exit_error("Attempted to write %08x to RAM address %08x", value, address);
  14.265 +	WRITE_LONG(g_ram, address, value);
  14.266 +}
  14.267 +
  14.268 +/* Called when the CPU pulses the RESET line */
  14.269 +void cpu_pulse_reset(void)
  14.270 +{
  14.271 +	nmi_device_reset();
  14.272 +	output_device_reset();
  14.273 +	input_device_reset();
  14.274 +}
  14.275 +
  14.276 +/* Called when the CPU changes the function code pins */
  14.277 +void cpu_set_fc(unsigned int fc)
  14.278 +{
  14.279 +	g_fc = fc;
  14.280 +}
  14.281 +
  14.282 +/* Called when the CPU acknowledges an interrupt */
  14.283 +int cpu_irq_ack(int level)
  14.284 +{
  14.285 +	switch(level)
  14.286 +	{
  14.287 +		case IRQ_NMI_DEVICE:
  14.288 +			return nmi_device_ack();
  14.289 +		case IRQ_INPUT_DEVICE:
  14.290 +			return input_device_ack();
  14.291 +		case IRQ_OUTPUT_DEVICE:
  14.292 +			return output_device_ack();
  14.293 +	}
  14.294 +	return M68K_INT_ACK_SPURIOUS;
  14.295 +}
  14.296 +
  14.297 +
  14.298 +
  14.299 +
  14.300 +/* Implementation for the NMI device */
  14.301 +void nmi_device_reset(void)
  14.302 +{
  14.303 +	g_nmi = 0;
  14.304 +}
  14.305 +
  14.306 +void nmi_device_update(void)
  14.307 +{
  14.308 +	if(g_nmi)
  14.309 +	{
  14.310 +		g_nmi = 0;
  14.311 +		int_controller_set(IRQ_NMI_DEVICE);
  14.312 +	}
  14.313 +}
  14.314 +
  14.315 +int nmi_device_ack(void)
  14.316 +{
  14.317 +	printf("\nNMI\n");fflush(stdout);
  14.318 +	int_controller_clear(IRQ_NMI_DEVICE);
  14.319 +	return M68K_INT_ACK_AUTOVECTOR;
  14.320 +}
  14.321 +
  14.322 +
  14.323 +/* Implementation for the input device */
  14.324 +void input_device_reset(void)
  14.325 +{
  14.326 +	g_input_device_value = -1;
  14.327 +	int_controller_clear(IRQ_INPUT_DEVICE);
  14.328 +}
  14.329 +
  14.330 +void input_device_update(void)
  14.331 +{
  14.332 +	if(g_input_device_value >= 0)
  14.333 +		int_controller_set(IRQ_INPUT_DEVICE);
  14.334 +}
  14.335 +
  14.336 +int input_device_ack(void)
  14.337 +{
  14.338 +	return M68K_INT_ACK_AUTOVECTOR;
  14.339 +}
  14.340 +
  14.341 +unsigned int input_device_read(void)
  14.342 +{
  14.343 +	int value = g_input_device_value > 0 ? g_input_device_value : 0;
  14.344 +	int_controller_clear(IRQ_INPUT_DEVICE);
  14.345 +	g_input_device_value = -1;
  14.346 +	return value;
  14.347 +}
  14.348 +
  14.349 +void input_device_write(unsigned int value)
  14.350 +{
  14.351 +}
  14.352 +
  14.353 +
  14.354 +/* Implementation for the output device */
  14.355 +void output_device_reset(void)
  14.356 +{
  14.357 +	g_output_device_last_output = time(NULL);
  14.358 +	g_output_device_ready = 0;
  14.359 +	int_controller_clear(IRQ_OUTPUT_DEVICE);
  14.360 +}
  14.361 +
  14.362 +void output_device_update(void)
  14.363 +{
  14.364 +	if(!g_output_device_ready)
  14.365 +	{
  14.366 +		if((time(NULL) - g_output_device_last_output) >= OUTPUT_DEVICE_PERIOD)
  14.367 +		{
  14.368 +			g_output_device_ready = 1;
  14.369 +			int_controller_set(IRQ_OUTPUT_DEVICE);
  14.370 +		}
  14.371 +	}
  14.372 +}
  14.373 +
  14.374 +int output_device_ack(void)
  14.375 +{
  14.376 +	return M68K_INT_ACK_AUTOVECTOR;
  14.377 +}
  14.378 +
  14.379 +unsigned int output_device_read(void)
  14.380 +{
  14.381 +	int_controller_clear(IRQ_OUTPUT_DEVICE);
  14.382 +	return 0;
  14.383 +}
  14.384 +
  14.385 +void output_device_write(unsigned int value)
  14.386 +{
  14.387 +	char ch;
  14.388 +	if(g_output_device_ready)
  14.389 +	{
  14.390 +		ch = value & 0xff;
  14.391 +		printf("%c", ch);
  14.392 +		g_output_device_last_output = time(NULL);
  14.393 +		g_output_device_ready = 0;
  14.394 +		int_controller_clear(IRQ_OUTPUT_DEVICE);
  14.395 +	}
  14.396 +}
  14.397 +
  14.398 +
  14.399 +/* Implementation for the interrupt controller */
  14.400 +void int_controller_set(unsigned int value)
  14.401 +{
  14.402 +	unsigned int old_pending = g_int_controller_pending;
  14.403 +
  14.404 +	g_int_controller_pending |= (1<<value);
  14.405 +
  14.406 +	if(old_pending != g_int_controller_pending && value > g_int_controller_highest_int)
  14.407 +	{
  14.408 +		g_int_controller_highest_int = value;
  14.409 +		m68k_set_irq(g_int_controller_highest_int);
  14.410 +	}
  14.411 +}
  14.412 +
  14.413 +void int_controller_clear(unsigned int value)
  14.414 +{
  14.415 +	g_int_controller_pending &= ~(1<<value);
  14.416 +
  14.417 +	for(g_int_controller_highest_int = 7;g_int_controller_highest_int > 0;g_int_controller_highest_int--)
  14.418 +		if(g_int_controller_pending & (1<<g_int_controller_highest_int))
  14.419 +			break;
  14.420 +
  14.421 +	m68k_set_irq(g_int_controller_highest_int);
  14.422 +}
  14.423 +
  14.424 +
  14.425 +/* Parse user input and update any devices that need user input */
  14.426 +void get_user_input(void)
  14.427 +{
  14.428 +	static int last_ch = -1;
  14.429 +	int ch = osd_get_char();
  14.430 +
  14.431 +	if(ch >= 0)
  14.432 +	{
  14.433 +		switch(ch)
  14.434 +		{
  14.435 +			case 0x1b:
  14.436 +				g_quit = 1;
  14.437 +				break;
  14.438 +			case '~':
  14.439 +				if(last_ch != ch)
  14.440 +					g_nmi = 1;
  14.441 +				break;
  14.442 +			default:
  14.443 +				g_input_device_value = ch;
  14.444 +		}
  14.445 +	}
  14.446 +	last_ch = ch;
  14.447 +}
  14.448 +
  14.449 +
  14.450 +/* The main loop */
  14.451 +int main(int argc, char* argv[])
  14.452 +{
  14.453 +	FILE* fhandle;
  14.454 +
  14.455 +	if(argc != 2)
  14.456 +		exit_error("Usage: sim <program file>");
  14.457 +
  14.458 +	if((fhandle = fopen(argv[1], "rb")) == NULL)
  14.459 +		exit_error("Unable to open %s", argv[1]);
  14.460 +
  14.461 +	if(fread(g_rom, 1, MAX_ROM+1, fhandle) <= 0)
  14.462 +		exit_error("Error reading %s", argv[1]);
  14.463 +
  14.464 +
  14.465 +	m68k_pulse_reset();
  14.466 +	input_device_reset();
  14.467 +	output_device_reset();
  14.468 +	nmi_device_reset();
  14.469 +
  14.470 +	g_quit = 0;
  14.471 +	while(!g_quit)
  14.472 +	{
  14.473 +		get_user_input();
  14.474 +		/* Note that I am not emulating the correct clock speed! */
  14.475 +		m68k_execute(1000);
  14.476 +		output_device_update();
  14.477 +		input_device_update();
  14.478 +		nmi_device_update();
  14.479 +	}
  14.480 +	return 0;
  14.481 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/musashi/example/sim.h	Sat Nov 27 01:13:12 2010 +0000
    15.3 @@ -0,0 +1,14 @@
    15.4 +#ifndef SIM__HEADER
    15.5 +#define SIM__HEADER
    15.6 +
    15.7 +unsigned int m68k_read_memory_8(unsigned int address);
    15.8 +unsigned int m68k_read_memory_16(unsigned int address);
    15.9 +unsigned int m68k_read_memory_32(unsigned int address);
   15.10 +void m68k_write_memory_8(unsigned int address, unsigned int value);
   15.11 +void m68k_write_memory_16(unsigned int address, unsigned int value);
   15.12 +void m68k_write_memory_32(unsigned int address, unsigned int value);
   15.13 +void cpu_pulse_reset(void);
   15.14 +void cpu_set_fc(unsigned int fc);
   15.15 +int  cpu_irq_ack(int level);
   15.16 +
   15.17 +#endif /* SIM__HEADER */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/musashi/history.txt	Sat Nov 27 01:13:12 2010 +0000
    16.3 @@ -0,0 +1,114 @@
    16.4 +The history of Musashi for anyone who might be interested:
    16.5 +---------------------------------------------------------
    16.6 +
    16.7 +Musashi was born out of sheer boredom.
    16.8 +I needed something to code, and so having had fun with a few of the emulators
    16.9 +around, I decided to try my hand at CPU emulation.
   16.10 +I had owned an Amiga for many years and had done some assembly coding on it so
   16.11 +I figured it would be the ideal chip to cut my teeth on.
   16.12 +Had I known then how much work was involved in emulating a chip like this, I
   16.13 +may not have even started ;-)
   16.14 +
   16.15 +
   16.16 +
   16.17 +12-May-1998: First outline
   16.18 +
   16.19 +11-Jun-1998: Early disassembler
   16.20 +
   16.21 +20-Nov-1998: First prototype v0.1
   16.22 +
   16.23 +04-Dec-1998: Final prototype v0.4
   16.24 +
   16.25 +20-Dec-1998: Beta release of Musashi v0.5 that could run Rastan Saga under MAME
   16.26 +             (barely).
   16.27 +
   16.28 +06-Jan-1999: Musashi 1.0 released
   16.29 +
   16.30 +17-Mar-1999: Musashi 2.0 released
   16.31 +             - Major code overhaul.
   16.32 +             - Replaced monolithic codebase with a code generator program.
   16.33 +             - Added correct m68000 timing.
   16.34 +             - Moved timing into the opcode handlers.
   16.35 +
   16.36 +25-Mar-1999: Musashi 2.1 released
   16.37 +             - Added support for m68010.
   16.38 +             - Many bugfixes.
   16.39 +
   16.40 +13-May-1999: Musashi 2.2 released
   16.41 +             - Added support for m68020.
   16.42 +             - Lots of bugfixes.
   16.43 +
   16.44 +05-Apr-2000: Musashi 3.0 released
   16.45 +             - Major code overhaul.
   16.46 +             - Rewrote code generator program and changed the format of
   16.47 +               m68k_in.c.
   16.48 +             - Added support for m68ec020.
   16.49 +             - Removed timing from the opcode handlers.
   16.50 +             - Added correct timing for m68000, m68010, and m68020.
   16.51 +               Note: 68020 timing is the cache timing from the manual.
   16.52 +             - Removed the m68k_peek_xxx() and m68k_poke_xxx() instructions and
   16.53 +               replaced them with m68k_get_reg() and m68k_set_reg().
   16.54 +             - Added support for function codes.
   16.55 +             - Revamped m68kconf.h to be easier to configure and more powerful.
   16.56 +             - Added option to separate immediate and normal reads.
   16.57 +             - Added support for (undocumented) m68000 instruction prefetch.
   16.58 +             - Rewrote indexed addressing mode handling.
   16.59 +             - Rewrote interrupt handling.
   16.60 +             - Fixed a masking bug for m68k_get_reg() when requesting the PC.
   16.61 +             - Moved the instruction table sorting routine to m68kmake.c so
   16.62 +               that it is invoked at compile time rather than at runtime.
   16.63 +             - Rewrote the exception handling routines to support different
   16.64 +               stack frames (needed for m68020 emulation).
   16.65 +             - Rewrote faster status register and condition code flag handling
   16.66 +               functions / macros.
   16.67 +             - Fixed function code handling to fetch from program space when
   16.68 +               using pc-relative addressing.
   16.69 +             - Fixed initial program counter and stack pointer fetching on
   16.70 +               reset (loads from program space now).
   16.71 +             - A lot of code cleanup.
   16.72 +             - LOTS of bugfixes (especially in the m68020 code).
   16.73 +
   16.74 +28-May-2000: Musashi 3.1 released
   16.75 +             - Fixed bug in m68k_get_reg() that retrieved the wrong value for
   16.76 +               the status register.
   16.77 +             - Fixed register bug in movec.
   16.78 +             - Fixed cpu type comparison problem that caused indexed
   16.79 +               addressing modes to be incorrectly interpreted when in m68ec020
   16.80 +               mode.
   16.81 +             - Added code to speed up busy waiting on some branch instructions.
   16.82 +             - Fixed some bfxxx opcode bugs.
   16.83 +
   16.84 +14-Aug-2000: Musashi 3.2 released
   16.85 +             - Fixed RTE bug that killed the program counter when in m68020
   16.86 +               mode.
   16.87 +             - Minor fixes in negx and nbcd.
   16.88 +             - renamed d68k.c to m68kdasm.c and merged d68k.h into m68k.h.
   16.89 +               d68k_read_xxx() instructions have been renamed to
   16.90 +               m68k_read_xxx_disassembler().
   16.91 +             - Rewrote exception processing and fixed 68020 stack frame
   16.92 +               problems.
   16.93 +             - FINALLY fixed the mull and divl instructions.
   16.94 +             - Added 64-bit safe code fixes.
   16.95 +             - Added 64-bit optimizations (these will only  be ANSI compliant
   16.96 +               under c9x, and so to use them you must turn on M68K_USE_64_BIT
   16.97 +               in m68kconf.h).
   16.98 +
   16.99 +27-Jan-2001: Musashi 3.3 released
  16.100 +             Note: This is the last release of Musashi before I separate the
  16.101 +                   68020 core.
  16.102 +             - Fixed problem when displaying negative numbers in disassembler
  16.103 +             - Fixed cpu type selector - was allowing 020 instructions to be
  16.104 +               disassembled when in 000 mode.
  16.105 +             - Fixed opcode jumptable generator (ambiguous operators in the
  16.106 +               test for f-line ops)
  16.107 +             - Fixed signed/unsigned problem in divl and mull opcodes (not
  16.108 +               sure if this was causing an error but best to be sure)
  16.109 +             - Cleaned up the naming scheme for the opcode handlers
  16.110 +
  16.111 +02-Feb-2001: Musashi 3.3.1 released
  16.112 +             Note: due to the pc-relative requirement for some new drivers
  16.113 +                   in MAME, I've released this small update.
  16.114 +             - Added pc-relative read modes
  16.115 +             - small optimizations to the exception handling that will help
  16.116 +               when splitting the cores
  16.117 +             - Updated the example (oops!)
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/musashi/m68k.h	Sat Nov 27 01:13:12 2010 +0000
    17.3 @@ -0,0 +1,339 @@
    17.4 +#ifndef M68K__HEADER
    17.5 +#define M68K__HEADER
    17.6 +
    17.7 +/* ======================================================================== */
    17.8 +/* ========================= LICENSING & COPYRIGHT ======================== */
    17.9 +/* ======================================================================== */
   17.10 +/*
   17.11 + *                                  MUSASHI
   17.12 + *                                Version 3.3
   17.13 + *
   17.14 + * A portable Motorola M680x0 processor emulation engine.
   17.15 + * Copyright 1998-2001 Karl Stenerud.  All rights reserved.
   17.16 + *
   17.17 + * This code may be freely used for non-commercial purposes as long as this
   17.18 + * copyright notice remains unaltered in the source code and any binary files
   17.19 + * containing this code in compiled form.
   17.20 + *
   17.21 + * All other lisencing terms must be negotiated with the author
   17.22 + * (Karl Stenerud).
   17.23 + *
   17.24 + * The latest version of this code can be obtained at:
   17.25 + * http://kstenerud.cjb.net
   17.26 + */
   17.27 +
   17.28 +
   17.29 +
   17.30 +/* ======================================================================== */
   17.31 +/* ============================ GENERAL DEFINES =========================== */
   17.32 +
   17.33 +/* ======================================================================== */
   17.34 +
   17.35 +/* There are 7 levels of interrupt to the 68K.
   17.36 + * A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).
   17.37 + */
   17.38 +#define M68K_IRQ_NONE 0
   17.39 +#define M68K_IRQ_1    1
   17.40 +#define M68K_IRQ_2    2
   17.41 +#define M68K_IRQ_3    3
   17.42 +#define M68K_IRQ_4    4
   17.43 +#define M68K_IRQ_5    5
   17.44 +#define M68K_IRQ_6    6
   17.45 +#define M68K_IRQ_7    7
   17.46 +
   17.47 +
   17.48 +/* Special interrupt acknowledge values.
   17.49 + * Use these as special returns from the interrupt acknowledge callback
   17.50 + * (specified later in this header).
   17.51 + */
   17.52 +
   17.53 +/* Causes an interrupt autovector (0x18 + interrupt level) to be taken.
   17.54 + * This happens in a real 68K if VPA or AVEC is asserted during an interrupt
   17.55 + * acknowledge cycle instead of DTACK.
   17.56 + */
   17.57 +#define M68K_INT_ACK_AUTOVECTOR    0xffffffff
   17.58 +
   17.59 +/* Causes the spurious interrupt vector (0x18) to be taken
   17.60 + * This happens in a real 68K if BERR is asserted during the interrupt
   17.61 + * acknowledge cycle (i.e. no devices responded to the acknowledge).
   17.62 + */
   17.63 +#define M68K_INT_ACK_SPURIOUS      0xfffffffe
   17.64 +
   17.65 +
   17.66 +/* CPU types for use in m68k_set_cpu_type() */
   17.67 +enum
   17.68 +{
   17.69 +	M68K_CPU_TYPE_INVALID,
   17.70 +	M68K_CPU_TYPE_68000,
   17.71 +	M68K_CPU_TYPE_68010,
   17.72 +	M68K_CPU_TYPE_68EC020,
   17.73 +	M68K_CPU_TYPE_68020,
   17.74 +	M68K_CPU_TYPE_68030,	/* Supported by disassembler ONLY */
   17.75 +	M68K_CPU_TYPE_68040		/* Supported by disassembler ONLY */
   17.76 +};
   17.77 +
   17.78 +/* Registers used by m68k_get_reg() and m68k_set_reg() */
   17.79 +typedef enum
   17.80 +{
   17.81 +	/* Real registers */
   17.82 +	M68K_REG_D0,		/* Data registers */
   17.83 +	M68K_REG_D1,
   17.84 +	M68K_REG_D2,
   17.85 +	M68K_REG_D3,
   17.86 +	M68K_REG_D4,
   17.87 +	M68K_REG_D5,
   17.88 +	M68K_REG_D6,
   17.89 +	M68K_REG_D7,
   17.90 +	M68K_REG_A0,		/* Address registers */
   17.91 +	M68K_REG_A1,
   17.92 +	M68K_REG_A2,
   17.93 +	M68K_REG_A3,
   17.94 +	M68K_REG_A4,
   17.95 +	M68K_REG_A5,
   17.96 +	M68K_REG_A6,
   17.97 +	M68K_REG_A7,
   17.98 +	M68K_REG_PC,		/* Program Counter */
   17.99 +	M68K_REG_SR,		/* Status Register */
  17.100 +	M68K_REG_SP,		/* The current Stack Pointer (located in A7) */
  17.101 +	M68K_REG_USP,		/* User Stack Pointer */
  17.102 +	M68K_REG_ISP,		/* Interrupt Stack Pointer */
  17.103 +	M68K_REG_MSP,		/* Master Stack Pointer */
  17.104 +	M68K_REG_SFC,		/* Source Function Code */
  17.105 +	M68K_REG_DFC,		/* Destination Function Code */
  17.106 +	M68K_REG_VBR,		/* Vector Base Register */
  17.107 +	M68K_REG_CACR,		/* Cache Control Register */
  17.108 +	M68K_REG_CAAR,		/* Cache Address Register */
  17.109 +
  17.110 +	/* Assumed registers */
  17.111 +	/* These are cheat registers which emulate the 1-longword prefetch
  17.112 +	 * present in the 68000 and 68010.
  17.113 +	 */ 
  17.114 +	M68K_REG_PREF_ADDR,	/* Last prefetch address */
  17.115 +	M68K_REG_PREF_DATA,	/* Last prefetch data */
  17.116 +
  17.117 +	/* Convenience registers */
  17.118 +	M68K_REG_PPC,		/* Previous value in the program counter */
  17.119 +	M68K_REG_IR,		/* Instruction register */
  17.120 +	M68K_REG_CPU_TYPE	/* Type of CPU being run */
  17.121 +} m68k_register_t;
  17.122 +
  17.123 +/* ======================================================================== */
  17.124 +/* ====================== FUNCTIONS CALLED BY THE CPU ===================== */
  17.125 +/* ======================================================================== */
  17.126 +
  17.127 +/* You will have to implement these functions */
  17.128 +
  17.129 +/* read/write functions called by the CPU to access memory.
  17.130 + * while values used are 32 bits, only the appropriate number
  17.131 + * of bits are relevant (i.e. in write_memory_8, only the lower 8 bits
  17.132 + * of value should be written to memory).
  17.133 + *
  17.134 + * NOTE: I have separated the immediate and PC-relative memory fetches
  17.135 + *       from the other memory fetches because some systems require
  17.136 + *       differentiation between PROGRAM and DATA fetches (usually
  17.137 + *       for security setups such as encryption).
  17.138 + *       This separation can either be achieved by setting
  17.139 + *       M68K_SEPARATE_READS in m68kconf.h and defining
  17.140 + *       the read functions, or by setting M68K_EMULATE_FC and
  17.141 + *       making a function code callback function.
  17.142 + *       Using the callback offers better emulation coverage
  17.143 + *       because you can also monitor whether the CPU is in SYSTEM or
  17.144 + *       USER mode, but it is also slower.
  17.145 + */
  17.146 +
  17.147 +/* Read from anywhere */
  17.148 +unsigned int  m68k_read_memory_8(unsigned int address);
  17.149 +unsigned int  m68k_read_memory_16(unsigned int address);
  17.150 +unsigned int  m68k_read_memory_32(unsigned int address);
  17.151 +
  17.152 +/* Read data immediately following the PC */
  17.153 +unsigned int  m68k_read_immediate_16(unsigned int address);
  17.154 +unsigned int  m68k_read_immediate_32(unsigned int address);
  17.155 +
  17.156 +/* Read data relative to the PC */
  17.157 +unsigned int  m68k_read_pcrelative_8(unsigned int address);
  17.158 +unsigned int  m68k_read_pcrelative_16(unsigned int address);
  17.159 +unsigned int  m68k_read_pcrelative_32(unsigned int address);
  17.160 +
  17.161 +/* Memory access for the disassembler */
  17.162 +unsigned int m68k_read_disassembler_8  (unsigned int address);
  17.163 +unsigned int m68k_read_disassembler_16 (unsigned int address);
  17.164 +unsigned int m68k_read_disassembler_32 (unsigned int address);
  17.165 +
  17.166 +/* Write to anywhere */
  17.167 +void m68k_write_memory_8(unsigned int address, unsigned int value);
  17.168 +void m68k_write_memory_16(unsigned int address, unsigned int value);
  17.169 +void m68k_write_memory_32(unsigned int address, unsigned int value);
  17.170 +
  17.171 +
  17.172 +
  17.173 +/* ======================================================================== */
  17.174 +/* ============================== CALLBACKS =============================== */
  17.175 +/* ======================================================================== */
  17.176 +
  17.177 +/* These functions allow you to set callbacks to the host when specific events
  17.178 + * occur.  Note that you must enable the corresponding value in m68kconf.h
  17.179 + * in order for these to do anything useful.
  17.180 + * Note: I have defined default callbacks which are used if you have enabled
  17.181 + * the corresponding #define in m68kconf.h but either haven't assigned a
  17.182 + * callback or have assigned a callback of NULL.
  17.183 + */
  17.184 +
  17.185 +/* Set the callback for an interrupt acknowledge.
  17.186 + * You must enable M68K_EMULATE_INT_ACK in m68kconf.h.
  17.187 + * The CPU will call the callback with the interrupt level being acknowledged.
  17.188 + * The host program must return either a vector from 0x02-0xff, or one of the
  17.189 + * special interrupt acknowledge values specified earlier in this header.
  17.190 + * If this is not implemented, the CPU will always assume an autovectored
  17.191 + * interrupt, and will automatically clear the interrupt request when it
  17.192 + * services the interrupt.
  17.193 + * Default behavior: return M68K_INT_ACK_AUTOVECTOR.
  17.194 + */
  17.195 +void m68k_set_int_ack_callback(int  (*callback)(int int_level));
  17.196 +
  17.197 +
  17.198 +/* Set the callback for a breakpoint acknowledge (68010+).
  17.199 + * You must enable M68K_EMULATE_BKPT_ACK in m68kconf.h.
  17.200 + * The CPU will call the callback with whatever was in the data field of the
  17.201 + * BKPT instruction for 68020+, or 0 for 68010.
  17.202 + * Default behavior: do nothing.
  17.203 + */
  17.204 +void m68k_set_bkpt_ack_callback(void (*callback)(unsigned int data));
  17.205 +
  17.206 +
  17.207 +/* Set the callback for the RESET instruction.
  17.208 + * You must enable M68K_EMULATE_RESET in m68kconf.h.
  17.209 + * The CPU calls this callback every time it encounters a RESET instruction.
  17.210 + * Default behavior: do nothing.
  17.211 + */
  17.212 +void m68k_set_reset_instr_callback(void  (*callback)(void));
  17.213 +
  17.214 +
  17.215 +/* Set the callback for informing of a large PC change.
  17.216 + * You must enable M68K_MONITOR_PC in m68kconf.h.
  17.217 + * The CPU calls this callback with the new PC value every time the PC changes
  17.218 + * by a large value (currently set for changes by longwords).
  17.219 + * Default behavior: do nothing.
  17.220 + */
  17.221 +void m68k_set_pc_changed_callback(void  (*callback)(unsigned int new_pc));
  17.222 +
  17.223 +
  17.224 +/* Set the callback for CPU function code changes.
  17.225 + * You must enable M68K_EMULATE_FC in m68kconf.h.
  17.226 + * The CPU calls this callback with the function code before every memory
  17.227 + * access to set the CPU's function code according to what kind of memory
  17.228 + * access it is (supervisor/user, program/data and such).
  17.229 + * Default behavior: do nothing.
  17.230 + */
  17.231 +void m68k_set_fc_callback(void  (*callback)(unsigned int new_fc));
  17.232 +
  17.233 +
  17.234 +/* Set a callback for the instruction cycle of the CPU.
  17.235 + * You must enable M68K_INSTRUCTION_HOOK in m68kconf.h.
  17.236 + * The CPU calls this callback just before fetching the opcode in the
  17.237 + * instruction cycle.
  17.238 + * Default behavior: do nothing.
  17.239 + */
  17.240 +void m68k_set_instr_hook_callback(void  (*callback)(void));
  17.241 +
  17.242 +
  17.243 +
  17.244 +/* ======================================================================== */
  17.245 +/* ====================== FUNCTIONS TO ACCESS THE CPU ===================== */
  17.246 +/* ======================================================================== */
  17.247 +
  17.248 +/* Use this function to set the CPU type you want to emulate.
  17.249 + * Currently supported types are: M68K_CPU_TYPE_68000, M68K_CPU_TYPE_68010,
  17.250 + * M68K_CPU_TYPE_EC020, and M68K_CPU_TYPE_68020.
  17.251 + */
  17.252 +void m68k_set_cpu_type(unsigned int cpu_type);
  17.253 +
  17.254 +/* Pulse the RESET pin on the CPU.
  17.255 + * You *MUST* reset the CPU at least once to initialize the emulation
  17.256 + * Note: If you didn't call m68k_set_cpu_type() before resetting
  17.257 + *       the CPU for the first time, the CPU will be set to
  17.258 + *       M68K_CPU_TYPE_68000.
  17.259 + */
  17.260 +void m68k_pulse_reset(void);
  17.261 +
  17.262 +/* execute num_cycles worth of instructions.  returns number of cycles used */
  17.263 +int m68k_execute(int num_cycles);
  17.264 +
  17.265 +/* These functions let you read/write/modify the number of cycles left to run
  17.266 + * while m68k_execute() is running.
  17.267 + * These are useful if the 68k accesses a memory-mapped port on another device
  17.268 + * that requires immediate processing by another CPU.
  17.269 + */
  17.270 +int m68k_cycles_run(void);              /* Number of cycles run so far */
  17.271 +int m68k_cycles_remaining(void);        /* Number of cycles left */
  17.272 +void m68k_modify_timeslice(int cycles); /* Modify cycles left */
  17.273 +void m68k_end_timeslice(void);          /* End timeslice now */
  17.274 +
  17.275 +/* Set the IPL0-IPL2 pins on the CPU (IRQ).
  17.276 + * A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).
  17.277 + * Setting IRQ to 0 will clear an interrupt request.
  17.278 + */
  17.279 +void m68k_set_irq(unsigned int int_level);
  17.280 +
  17.281 +
  17.282 +/* Halt the CPU as if you pulsed the HALT pin. */
  17.283 +void m68k_pulse_halt(void);
  17.284 +
  17.285 +
  17.286 +/* Context switching to allow multiple CPUs */
  17.287 +
  17.288 +/* Get the size of the cpu context in bytes */
  17.289 +unsigned int m68k_context_size(void);
  17.290 +
  17.291 +/* Get a cpu context */
  17.292 +unsigned int m68k_get_context(void* dst);
  17.293 +
  17.294 +/* set the current cpu context */
  17.295 +void m68k_set_context(void* dst);
  17.296 +
  17.297 +/* Save the current cpu context to disk.
  17.298 + * You must provide a function pointer of the form:
  17.299 + * void save_value(char* identifier, unsigned int value)
  17.300 + */
  17.301 +void m68k_save_context(	void (*save_value)(char* identifier, unsigned int value));
  17.302 +
  17.303 +/* Load a cpu context from disk.
  17.304 + * You must provide a function pointer of the form:
  17.305 + * unsigned int load_value(char* identifier)
  17.306 + */
  17.307 +void m68k_load_context(unsigned int (*load_value)(char* identifier));
  17.308 +
  17.309 +
  17.310 +
  17.311 +/* Peek at the internals of a CPU context.  This can either be a context
  17.312 + * retrieved using m68k_get_context() or the currently running context.
  17.313 + * If context is NULL, the currently running CPU context will be used.
  17.314 + */
  17.315 +unsigned int m68k_get_reg(void* context, m68k_register_t reg);
  17.316 +
  17.317 +/* Poke values into the internals of the currently running CPU context */
  17.318 +void m68k_set_reg(m68k_register_t reg, unsigned int value);
  17.319 +
  17.320 +/* Check if an instruction is valid for the specified CPU type */
  17.321 +unsigned int m68k_is_valid_instruction(unsigned int instruction, unsigned int cpu_type);
  17.322 +
  17.323 +/* Disassemble 1 instruction using the epecified CPU type at pc.  Stores
  17.324 + * disassembly in str_buff and returns the size of the instruction in bytes.
  17.325 + */
  17.326 +unsigned int m68k_disassemble(char* str_buff, unsigned int pc, unsigned int cpu_type);
  17.327 +
  17.328 +
  17.329 +/* ======================================================================== */
  17.330 +/* ============================= CONFIGURATION ============================ */
  17.331 +/* ======================================================================== */
  17.332 +
  17.333 +/* Import the configuration for this build */
  17.334 +#include "m68kconf.h"
  17.335 +
  17.336 +
  17.337 +
  17.338 +/* ======================================================================== */
  17.339 +/* ============================== END OF FILE ============================= */
  17.340 +/* ======================================================================== */
  17.341 +
  17.342 +#endif /* M68K__HEADER */
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/musashi/m68k_in.c	Sat Nov 27 01:13:12 2010 +0000
    18.3 @@ -0,0 +1,9989 @@
    18.4 +/* ======================================================================== */
    18.5 +/* ========================= LICENSING & COPYRIGHT ======================== */
    18.6 +/* ======================================================================== */
    18.7 +/*
    18.8 + *                                  MUSASHI
    18.9 + *                                Version 3.3
   18.10 + *
   18.11 + * A portable Motorola M680x0 processor emulation engine.
   18.12 + * Copyright 1998-2001 Karl Stenerud.  All rights reserved.
   18.13 + *
   18.14 + * This code may be freely used for non-commercial purposes as long as this
   18.15 + * copyright notice remains unaltered in the source code and any binary files
   18.16 + * containing this code in compiled form.
   18.17 + *
   18.18 + * All other lisencing terms must be negotiated with the author
   18.19 + * (Karl Stenerud).
   18.20 + *
   18.21 + * The latest version of this code can be obtained at:
   18.22 + * http://kstenerud.cjb.net
   18.23 + */
   18.24 +
   18.25 +
   18.26 +
   18.27 +/* Input file for m68kmake
   18.28 + * -----------------------
   18.29 + *
   18.30 + * All sections begin with 80 X's in a row followed by an end-of-line
   18.31 + * sequence.
   18.32 + * After this, m68kmake will expect to find one of the following section
   18.33 + * identifiers:
   18.34 + *    M68KMAKE_PROTOTYPE_HEADER      - header for opcode handler prototypes
   18.35 + *    M68KMAKE_PROTOTYPE_FOOTER      - footer for opcode handler prototypes
   18.36 + *    M68KMAKE_TABLE_HEADER          - header for opcode handler jumptable
   18.37 + *    M68KMAKE_TABLE_FOOTER          - footer for opcode handler jumptable
   18.38 + *    M68KMAKE_TABLE_BODY            - the table itself
   18.39 + *    M68KMAKE_OPCODE_HANDLER_HEADER - header for opcode handler implementation
   18.40 + *    M68KMAKE_OPCODE_HANDLER_FOOTER - footer for opcode handler implementation
   18.41 + *    M68KMAKE_OPCODE_HANDLER_BODY   - body section for opcode handler implementation
   18.42 + *
   18.43 + * NOTE: M68KMAKE_OPCODE_HANDLER_BODY must be last in the file and
   18.44 + *       M68KMAKE_TABLE_BODY must be second last in the file.
   18.45 + *
   18.46 + * The M68KMAKE_OPHANDLER_BODY section contains the opcode handler
   18.47 + * primitives themselves.  Each opcode handler begins with:
   18.48 + *    M68KMAKE_OP(A, B, C, D)
   18.49 + *
   18.50 + * where A is the opcode handler name, B is the size of the operation,
   18.51 + * C denotes any special processing mode, and D denotes a specific
   18.52 + * addressing mode.
   18.53 + * For C and D where nothing is specified, use "."
   18.54 + *
   18.55 + * Example:
   18.56 + *     M68KMAKE_OP(abcd, 8, rr, .)   abcd, size 8, register to register, default EA
   18.57 + *     M68KMAKE_OP(abcd, 8, mm, ax7) abcd, size 8, memory to memory, register X is A7
   18.58 + *     M68KMAKE_OP(tst, 16, ., pcix) tst, size 16, PCIX addressing
   18.59 + *
   18.60 + * All opcode handler primitives end with a closing curly brace "}" at column 1
   18.61 + *
   18.62 + * NOTE: Do not place a M68KMAKE_OP() directive inside the opcode handler,
   18.63 + *       and do not put a closing curly brace at column 1 unless it is
   18.64 + *       marking the end of the handler!
   18.65 + *
   18.66 + * Inside the handler, m68kmake will recognize M68KMAKE_GET_OPER_xx_xx,
   18.67 + * M68KMAKE_GET_EA_xx_xx, and M68KMAKE_CC directives, and create multiple
   18.68 + * opcode handlers to handle variations in the opcode handler.
   18.69 + * Note: M68KMAKE_CC will only be interpreted in condition code opcodes.
   18.70 + * As well, M68KMAKE_GET_EA_xx_xx and M68KMAKE_GET_OPER_xx_xx will only
   18.71 + * be interpreted on instructions where the corresponding table entry
   18.72 + * specifies multiple effective addressing modes.
   18.73 + * Example:
   18.74 + * clr       32  .     .     0100001010......  A+-DXWL...  U U U   12   6   4
   18.75 + *
   18.76 + * This table entry says that the clr.l opcde has 7 variations (A+-DXWL).
   18.77 + * It is run in user or supervisor mode for all CPUs, and uses 12 cycles for
   18.78 + * 68000, 6 cycles for 68010, and 4 cycles for 68020.
   18.79 + */
   18.80 +
   18.81 +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   18.82 +M68KMAKE_PROTOTYPE_HEADER
   18.83 +
   18.84 +#ifndef M68KOPS__HEADER
   18.85 +#define M68KOPS__HEADER
   18.86 +
   18.87 +/* ======================================================================== */
   18.88 +/* ============================ OPCODE HANDLERS =========================== */
   18.89 +/* ======================================================================== */
   18.90 +
   18.91 +
   18.92 +
   18.93 +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   18.94 +M68KMAKE_PROTOTYPE_FOOTER
   18.95 +
   18.96 +
   18.97 +/* Build the opcode handler table */
   18.98 +void m68ki_build_opcode_table(void);
   18.99 +
  18.100 +extern void (*m68ki_instruction_jump_table[0x10000])(void); /* opcode handler jump table */
  18.101 +extern unsigned char m68ki_cycles[][0x10000];
  18.102 +
  18.103 +
  18.104 +/* ======================================================================== */
  18.105 +/* ============================== END OF FILE ============================= */
  18.106 +/* ======================================================================== */
  18.107 +
  18.108 +#endif /* M68KOPS__HEADER */
  18.109 +
  18.110 +
  18.111 +
  18.112 +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  18.113 +M68KMAKE_TABLE_HEADER
  18.114 +
  18.115 +/* ======================================================================== */
  18.116 +/* ========================= OPCODE TABLE BUILDER ========================= */
  18.117 +/* ======================================================================== */
  18.118 +
  18.119 +#include "m68kops.h"
  18.120 +
  18.121 +#define NUM_CPU_TYPES 3
  18.122 +
  18.123 +void  (*m68ki_instruction_jump_table[0x10000])(void); /* opcode handler jump table */
  18.124 +unsigned char m68ki_cycles[NUM_CPU_TYPES][0x10000]; /* Cycles used by CPU type */
  18.125 +
  18.126 +/* This is used to generate the opcode handler jump table */
  18.127 +typedef struct
  18.128 +{
  18.129 +	void (*opcode_handler)(void);        /* handler function */
  18.130 +	unsigned int  mask;                  /* mask on opcode */
  18.131 +	unsigned int  match;                 /* what to match after masking */
  18.132 +	unsigned char cycles[NUM_CPU_TYPES]; /* cycles each cpu type takes */
  18.133 +} opcode_handler_struct;
  18.134 +
  18.135 +
  18.136 +/* Opcode handler table */
  18.137 +static opcode_handler_struct m68k_opcode_handler_table[] =
  18.138 +{
  18.139 +/*   function                      mask    match    000  010  020 */
  18.140 +
  18.141 +
  18.142 +
  18.143 +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  18.144 +M68KMAKE_TABLE_FOOTER
  18.145 +
  18.146 +	{0, 0, 0, {0, 0, 0}}
  18.147 +};
  18.148 +
  18.149 +
  18.150 +/* Build the opcode handler jump table */
  18.151 +void m68ki_build_opcode_table(void)
  18.152 +{
  18.153 +	opcode_handler_struct *ostruct;
  18.154 +	int instr;
  18.155 +	int i;
  18.156 +	int j;
  18.157 +	int k;
  18.158 +
  18.159 +	for(i = 0; i < 0x10000; i++)
  18.160 +	{
  18.161 +		/* default to illegal */
  18.162 +		m68ki_instruction_jump_table[i] = m68k_op_illegal;
  18.163 +		for(k=0;k<NUM_CPU_TYPES;k++)
  18.164 +			m68ki_cycles[k][i] = 0;
  18.165 +	}
  18.166 +
  18.167 +	ostruct = m68k_opcode_handler_table;
  18.168 +	while(ostruct->mask != 0xff00)
  18.169 +	{
  18.170 +		for(i = 0;i < 0x10000;i++)
  18.171 +		{
  18.172 +			if((i & ostruct->mask) == ostruct->match)
  18.173 +			{
  18.174 +				m68ki_instruction_jump_table[i] = ostruct->opcode_handler;
  18.175 +				for(k=0;k<NUM_CPU_TYPES;k++)
  18.176 +					m68ki_cycles[k][i] = ostruct->cycles[k];
  18.177 +			}
  18.178 +		}
  18.179 +		ostruct++;
  18.180 +	}
  18.181 +	while(ostruct->mask == 0xff00)
  18.182 +	{
  18.183 +		for(i = 0;i <= 0xff;i++)
  18.184 +		{
  18.185 +			m68ki_instruction_jump_table[ostruct->match | i] = ostruct->opcode_handler;
  18.186 +			for(k=0;k<NUM_CPU_TYPES;k++)
  18.187 +				m68ki_cycles[k][ostruct->match | i] = ostruct->cycles[k];
  18.188 +		}
  18.189 +		ostruct++;
  18.190 +	}
  18.191 +	while(ostruct->mask == 0xf1f8)
  18.192 +	{
  18.193 +		for(i = 0;i < 8;i++)
  18.194 +		{
  18.195 +			for(j = 0;j < 8;j++)
  18.196 +			{
  18.197 +				instr = ostruct->match | (i << 9) | j;
  18.198 +				m68ki_instruction_jump_table[instr] = ostruct->opcode_handler;
  18.199 +				for(k=0;k<NUM_CPU_TYPES;k++)
  18.200 +					m68ki_cycles[k][instr] = ostruct->cycles[k];
  18.201 +				if((instr & 0xf000) == 0xe000 && (!(instr & 0x20)))
  18.202 +					m68ki_cycles[0][instr] = m68ki_cycles[1][instr] = ostruct->cycles[k] + ((((j-1)&7)+1)<<1);
  18.203 +			}
  18.204 +		}
  18.205 +		ostruct++;
  18.206 +	}
  18.207 +	while(ostruct->mask == 0xfff0)
  18.208 +	{
  18.209 +		for(i = 0;i <= 0x0f;i++)
  18.210 +		{
  18.211 +			m68ki_instruction_jump_table[ostruct->match | i] = ostruct->opcode_handler;
  18.212 +			for(k=0;k<NUM_CPU_TYPES;k++)
  18.213 +				m68ki_cycles[k][ostruct->match | i] = ostruct->cycles[k];
  18.214 +		}
  18.215 +		ostruct++;
  18.216 +	}
  18.217 +	while(ostruct->mask == 0xf1ff)
  18.218 +	{
  18.219 +		for(i = 0;i <= 0x07;i++)
  18.220 +		{
  18.221 +			m68ki_instruction_jump_table[ostruct->match | (i << 9)] = ostruct->opcode_handler;
  18.222 +			for(k=0;k<NUM_CPU_TYPES;k++)
  18.223 +				m68ki_cycles[k][ostruct->match | (i << 9)] = ostruct->cycles[k];
  18.224 +		}
  18.225 +		ostruct++;
  18.226 +	}
  18.227 +	while(ostruct->mask == 0xfff8)
  18.228 +	{
  18.229 +		for(i = 0;i <= 0x07;i++)
  18.230 +		{
  18.231 +			m68ki_instruction_jump_table[ostruct->match | i] = ostruct->opcode_handler;
  18.232 +			for(k=0;k<NUM_CPU_TYPES;k++)
  18.233 +				m68ki_cycles[k][ostruct->match | i] = ostruct->cycles[k];
  18.234 +		}
  18.235 +		ostruct++;
  18.236 +	}
  18.237 +	while(ostruct->mask == 0xffff)
  18.238 +	{
  18.239 +		m68ki_instruction_jump_table[ostruct->match] = ostruct->opcode_handler;
  18.240 +		for(k=0;k<NUM_CPU_TYPES;k++)
  18.241 +			m68ki_cycles[k][ostruct->match] = ostruct->cycles[k];
  18.242 +		ostruct++;
  18.243 +	}
  18.244 +}
  18.245 +
  18.246 +
  18.247 +/* ======================================================================== */
  18.248 +/* ============================== END OF FILE ============================= */
  18.249 +/* ======================================================================== */
  18.250 +
  18.251 +
  18.252 +
  18.253 +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  18.254 +M68KMAKE_OPCODE_HANDLER_HEADER
  18.255 +
  18.256 +#include "m68kcpu.h"
  18.257 +
  18.258 +/* ======================================================================== */
  18.259 +/* ========================= INSTRUCTION HANDLERS ========================= */
  18.260 +/* ======================================================================== */
  18.261 +
  18.262 +
  18.263 +
  18.264 +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  18.265 +M68KMAKE_OPCODE_HANDLER_FOOTER
  18.266 +
  18.267 +/* ======================================================================== */
  18.268 +/* ============================== END OF FILE ============================= */
  18.269 +/* ======================================================================== */
  18.270 +
  18.271 +
  18.272 +
  18.273 +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  18.274 +M68KMAKE_TABLE_BODY
  18.275 +
  18.276 +The following table is arranged as follows:
  18.277 +
  18.278 +name:        Opcode mnemonic
  18.279 +
  18.280 +size:        Operation size
  18.281 +
  18.282 +spec proc:   Special processing mode:
  18.283 +                 .:    normal
  18.284 +                 s:    static operand
  18.285 +                 r:    register operand
  18.286 +                 rr:   register to register
  18.287 +                 mm:   memory to memory
  18.288 +                 er:   effective address to register
  18.289 +                 re:   register to effective address
  18.290 +                 dd:   data register to data register
  18.291 +                 da:   data register to address register
  18.292 +                 aa:   address register to address register
  18.293 +                 cr:   control register to register
  18.294 +                 rc:   register to control register
  18.295 +                 toc:  to condition code register
  18.296 +                 tos:  to status register
  18.297 +                 tou:  to user stack pointer
  18.298 +                 frc:  from condition code register
  18.299 +                 frs:  from status register
  18.300 +                 fru:  from user stack pointer
  18.301 +                 * for move.x, the special processing mode is a specific
  18.302 +                   destination effective addressing mode.
  18.303 +
  18.304 +spec ea:     Specific effective addressing mode:
  18.305 +                 .:    normal
  18.306 +                 i:    immediate
  18.307 +                 d:    data register
  18.308 +                 a:    address register
  18.309 +                 ai:   address register indirect
  18.310 +                 pi:   address register indirect with postincrement
  18.311 +                 pd:   address register indirect with predecrement
  18.312 +                 di:   address register indirect with displacement
  18.313 +                 ix:   address register indirect with index
  18.314 +                 aw:   absolute word address
  18.315 +                 al:   absolute long address
  18.316 +                 pcdi: program counter relative with displacement
  18.317 +                 pcix: program counter relative with index
  18.318 +                 a7:   register specified in instruction is A7
  18.319 +                 ax7:  register field X of instruction is A7
  18.320 +                 ay7:  register field Y of instruction is A7
  18.321 +                 axy7: register fields X and Y of instruction are A7
  18.322 +
  18.323 +bit pattern: Pattern to recognize this opcode.  "." means don't care.
  18.324 +
  18.325 +allowed ea:  List of allowed addressing modes:
  18.326 +                 .: not present
  18.327 +                 A: address register indirect
  18.328 +                 +: ARI (address register indirect) with postincrement
  18.329 +                 -: ARI with predecrement
  18.330 +                 D: ARI with displacement
  18.331 +                 X: ARI with index
  18.332 +                 W: absolute word address
  18.333 +                 L: absolute long address
  18.334 +                 d: program counter indirect with displacement
  18.335 +                 x: program counter indirect with index
  18.336 +                 I: immediate
  18.337 +mode:        CPU operating mode for each cpu type.  U = user or supervisor,
  18.338 +             S = supervisor only, "." = opcode not present.
  18.339 +
  18.340 +cpu cycles:  Base number of cycles required to execute this opcode on the
  18.341 +             specified CPU type.
  18.342 +             Use "." if CPU does not have this opcode.
  18.343 +
  18.344 +
  18.345 +
  18.346 +              spec  spec                    allowed ea  mode   cpu cycles
  18.347 +name    size  proc   ea   bit pattern       A+-DXWLdxI  0 1 2  000 010 020  comments
  18.348 +======  ====  ====  ====  ================  ==========  = = =  === === ===  =============
  18.349 +M68KMAKE_TABLE_START
  18.350 +1010       0  .     .     1010............  ..........  U U U    4   4   4
  18.351 +1111       0  .     .     1111............  ..........  U U U    4   4   4
  18.352 +abcd       8  rr    .     1100...100000...  ..........  U U U    6   6   4
  18.353 +abcd       8  mm    ax7   1100111100001...  ..........  U U U   18  18  16
  18.354 +abcd       8  mm    ay7   1100...100001111  ..........  U U U   18  18  16
  18.355 +abcd       8  mm    axy7  1100111100001111  ..........  U U U   18  18  16
  18.356 +abcd       8  mm    .     1100...100001...  ..........  U U U   18  18  16
  18.357 +add        8  er    d     1101...000000...  ..........  U U U    4   4   2
  18.358 +add        8  er    .     1101...000......  A+-DXWLdxI  U U U    4   4   2
  18.359 +add       16  er    d     1101...001000...  ..........  U U U    4   4   2
  18.360 +add       16  er    a     1101...001001...  ..........  U U U    4   4   2
  18.361 +add       16  er    .     1101...001......  A+-DXWLdxI  U U U    4   4   2
  18.362 +add       32  er    d     1101...010000...  ..........  U U U    6   6   2
  18.363 +add       32  er    a     1101...010001...  ..........  U U U    6   6   2
  18.364 +add       32  er    .     1101...010......  A+-DXWLdxI  U U U    6   6   2
  18.365 +add        8  re    .     1101...100......  A+-DXWL...  U U U    8   8   4
  18.366 +add       16  re    .     1101...101......  A+-DXWL...  U U U    8   8   4
  18.367 +add       32  re    .     1101...110......  A+-DXWL...  U U U   12  12   4
  18.368 +adda      16  .     d     1101...011000...  ..........  U U U    8   8   2
  18.369 +adda      16  .     a     1101...011001...  ..........  U U U    8   8   2
  18.370 +adda      16  .     .     1101...011......  A+-DXWLdxI  U U U    8   8   2
  18.371 +adda      32  .     d     1101...111000...  ..........  U U U    6   6   2
  18.372 +adda      32  .     a     1101...111001...  ..........  U U U    6   6   2
  18.373 +adda      32  .     .     1101...111......  A+-DXWLdxI  U U U    6   6   2
  18.374 +addi       8  .     d     0000011000000...  ..........  U U U    8   8   2
  18.375 +addi       8  .     .     0000011000......  A+-DXWL...  U U U   12  12   4
  18.376 +addi      16  .     d     0000011001000...  ..........  U U U    8   8   2
  18.377 +addi      16  .     .     0000011001......  A+-DXWL...  U U U   12  12   4
  18.378 +addi      32  .     d     0000011010000...  ..........  U U U   16  14   2
  18.379 +addi      32  .     .     0000011010......  A+-DXWL...  U U U   20  20   4
  18.380 +addq       8  .     d     0101...000000...  ..........  U U U    4   4   2
  18.381 +addq       8  .     .     0101...000......  A+-DXWL...  U U U    8   8   4
  18.382 +addq      16  .     d     0101...001000...  ..........  U U U    4   4   2
  18.383 +addq      16  .     a     0101...001001...  ..........  U U U    4   4   2
  18.384 +addq      16  .     .     0101...001......  A+-DXWL...  U U U    8   8   4
  18.385 +addq      32  .     d     0101...010000...  ..........  U U U    8   8   2
  18.386 +addq      32  .     a     0101...010001...  ..........  U U U    8   8   2
  18.387 +addq      32  .     .     0101...010......  A+-DXWL...  U U U   12  12   4
  18.388 +addx       8  rr    .     1101...100000...  ..........  U U U    4   4   2
  18.389 +addx      16  rr    .     1101...101000...  ..........  U U U    4   4   2
  18.390 +addx      32  rr    .     1101...110000...  ..........  U U U    8   6   2
  18.391 +addx       8  mm    ax7   1101111100001...  ..........  U U U   18  18  12
  18.392 +addx       8  mm    ay7   1101...100001111  ..........  U U U   18  18  12
  18.393 +addx       8  mm    axy7  1101111100001111  ..........  U U U   18  18  12
  18.394 +addx       8  mm    .     1101...100001...  ..........  U U U   18  18  12
  18.395 +addx      16  mm    .     1101...101001...  ..........  U U U   18  18  12
  18.396 +addx      32  mm    .     1101...110001...  ..........  U U U   30  30  12
  18.397 +and        8  er    d     1100...000000...  ..........  U U U    4   4   2
  18.398 +and        8  er    .     1100...000......  A+-DXWLdxI  U U U    4   4   2
  18.399 +and       16  er    d     1100...001000...  ..........  U U U    4   4   2
  18.400 +and       16  er    .     1100...001......  A+-DXWLdxI  U U U    4   4   2
  18.401 +and       32  er    d     1100...010000...  ..........  U U U    6   6   2
  18.402 +and       32  er    .     1100...010......  A+-DXWLdxI  U U U    6   6   2
  18.403 +and        8  re    .     1100...100......  A+-DXWL...  U U U    8   8   4
  18.404 +and       16  re    .     1100...101......  A+-DXWL...  U U U    8   8   4
  18.405 +and       32  re    .     1100...110......  A+-DXWL...  U U U   12  12   4
  18.406 +andi      16  toc   .     0000001000111100  ..........  U U U   20  16  12
  18.407 +andi      16  tos   .     0000001001111100  ..........  S S S   20  16  12
  18.408 +andi       8  .     d     0000001000000...  ..........  U U U    8   8   2
  18.409 +andi       8  .     .     0000001000......  A+-DXWL...  U U U   12  12   4
  18.410 +andi      16  .     d     0000001001000...  ..........  U U U    8   8   2
  18.411 +andi      16  .     .     0000001001......  A+-DXWL...  U U U   12  12   4
  18.412 +andi      32  .     d     0000001010000...  ..........  U U U   14  14   2
  18.413 +andi      32  .     .     0000001010......  A+-DXWL...  U U U   20  20   4
  18.414 +asr        8  s     .     1110...000000...  ..........  U U U    6   6   6
  18.415 +asr       16  s     .     1110...001000...  ..........  U U U    6   6   6
  18.416 +asr       32  s     .     1110...010000...  ..........  U U U    8   8   6
  18.417 +asr        8  r     .     1110...000100...  ..........  U U U    6   6   6
  18.418 +asr       16  r     .     1110...001100...  ..........  U U U    6   6   6
  18.419 +asr       32  r     .     1110...010100...  ..........  U U U    8   8   6
  18.420 +asr       16  .     .     1110000011......  A+-DXWL...  U U U    8   8   5
  18.421 +asl        8  s     .     1110...100000...  ..........  U U U    6   6   8
  18.422 +asl       16  s     .     1110...101000...  ..........  U U U    6   6   8
  18.423 +asl       32  s     .     1110...110000...  ..........  U U U    8   8   8
  18.424 +asl        8  r     .     1110...100100...  ..........  U U U    6   6   8
  18.425 +asl       16  r     .     1110...101100...  ..........  U U U    6   6   8
  18.426 +asl       32  r     .     1110...110100...  ..........  U U U    8   8   8
  18.427 +asl       16  .     .     1110000111......  A+-DXWL...  U U U    8   8   6
  18.428 +bcc        8  .     .     0110............  ..........  U U U    8   8   6
  18.429 +bcc       16  .     .     0110....00000000  ..........  U U U   10  10   6
  18.430 +bcc       32  .     .     0110....11111111  ..........  . . U    .   .   6
  18.431 +bchg       8  r     .     0000...101......  A+-DXWL...  U U U    8   8   4
  18.432 +bchg      32  r     d     0000...101000...  ..........  U U U    8   8   4
  18.433 +bchg       8  s     .     0000100001......  A+-DXWL...  U U U   12  12   4
  18.434 +bchg      32  s     d     0000100001000...  ..........  U U U   12  12   4
  18.435 +bclr       8  r     .     0000...110......  A+-DXWL...  U U U    8  10   4
  18.436 +bclr      32  r     d     0000...110000...  ..........  U U U   10  10   4
  18.437 +bclr       8  s     .     0000100010......  A+-DXWL...  U U U   12  12   4
  18.438 +bclr      32  s     d     0000100010000...  ..........  U U U   14  14   4
  18.439 +bfchg     32  .     d     1110101011000...  ..........  . . U    .   .  12  timing not quite correct
  18.440 +bfchg     32  .     .     1110101011......  A..DXWL...  . . U    .   .  20
  18.441 +bfclr     32  .     d     1110110011000...  ..........  . . U    .   .  12
  18.442 +bfclr     32  .     .     1110110011......  A..DXWL...  . . U    .   .  20
  18.443 +bfexts    32  .     d     1110101111000...  ..........  . . U    .   .   8
  18.444 +bfexts    32  .     .     1110101111......  A..DXWLdx.  . . U    .   .  15
  18.445 +bfextu    32  .     d     1110100111000...  ..........  . . U    .   .   8
  18.446 +bfextu    32  .     .     1110100111......  A..DXWLdx.  . . U    .   .  15
  18.447 +bfffo     32  .     d     1110110111000...  ..........  . . U    .   .  18
  18.448 +bfffo     32  .     .     1110110111......  A..DXWLdx.  . . U    .   .  28
  18.449 +bfins     32  .     d     1110111111000...  ..........  . . U    .   .  10
  18.450 +bfins     32  .     .     1110111111......  A..DXWL...  . . U    .   .  17
  18.451 +bfset     32  .     d     1110111011000...  ..........  . . U    .   .  12
  18.452 +bfset     32  .     .     1110111011......  A..DXWL...  . . U    .   .  20
  18.453 +bftst     32  .     d     1110100011000...  ..........  . . U    .   .   6
  18.454 +bftst     32  .     .     1110100011......  A..DXWLdx.  . . U    .   .  13
  18.455 +bkpt       0  .     .     0100100001001...  ..........  . U U    .  10  10
  18.456 +bra        8  .     .     01100000........  ..........  U U U   10  10  10
  18.457 +bra       16  .     .     0110000000000000  ..........  U U U   10  10  10
  18.458 +bra       32  .     .     0110000011111111  ..........  U U U    .   .  10
  18.459 +bset      32  r     d     0000...111000...  ..........  U U U    8   8   4
  18.460 +bset       8  r     .     0000...111......  A+-DXWL...  U U U    8   8   4
  18.461 +bset       8  s     .     0000100011......  A+-DXWL...  U U U   12  12   4
  18.462 +bset      32  s     d     0000100011000...  ..........  U U U   12  12   4
  18.463 +bsr        8  .     .     01100001........  ..........  U U U   18  18   7
  18.464 +bsr       16  .     .     0110000100000000  ..........  U U U   18  18   7
  18.465 +bsr       32  .     .     0110000111111111  ..........  . . U    .   .   7
  18.466 +btst       8  r     .     0000...100......  A+-DXWLdxI  U U U    4   4   4
  18.467 +btst      32  r     d     0000...100000...  ..........  U U U    6   6   4
  18.468 +btst       8  s     .     0000100000......  A+-DXWLdx.  U U U    8   8   4
  18.469 +btst      32  s     d     0000100000000...  ..........  U U U   10  10   4
  18.470 +callm     32  .     .     0000011011......  A..DXWLdx.  . . U    .   .  60  not properly emulated
  18.471 +cas        8  .     .     0000101011......  A+-DXWL...  . . U    .   .  12
  18.472 +cas       16  .     .     0000110011......  A+-DXWL...  . . U    .   .  12
  18.473 +cas       32  .     .     0000111011......  A+-DXWL...  . . U    .   .  12
  18.474 +cas2      16  .     .     0000110011111100  ..........  . . U    .   .  12
  18.475 +cas2      32  .     .     0000111011111100  ..........  . . U    .   .  12
  18.476 +chk       16  .     d     0100...110000...  ..........  U U U   10   8   8
  18.477 +chk       16  .     .     0100...110......  A+-DXWLdxI  U U U   10   8   8
  18.478 +chk       32  .     d     0100...100000...  ..........  . . U    .   .   8
  18.479 +chk       32  .     .     0100...100......  A+-DXWLdxI  . . U    .   .   8
  18.480 +chk2cmp2   8  .     .     0000000011......  A..DXWLdx.  . . U    .   .  18
  18.481 +chk2cmp2  16  .     .     0000001011......  A..DXWLdx.  . . U    .   .  18
  18.482 +chk2cmp2  32  .     .     0000010011......  A..DXWLdx.  . . U    .   .  18
  18.483 +clr        8  .     d     0100001000000...  ..........  U U U    4   4   2
  18.484 +clr        8  .     .     0100001000......  A+-DXWL...  U U U    8   4   4
  18.485 +clr       16  .     d     0100001001000...  ..........  U U U    4   4   2
  18.486 +clr       16  .     .     0100001001......  A+-DXWL...  U U U    8   4   4
  18.487 +clr       32  .     d     0100001010000...  ..........  U U U    6   6   2
  18.488 +clr       32  .     .     0100001010......  A+-DXWL...  U U U   12   6   4
  18.489 +cmp        8  .     d     1011...000000...  ..........  U U U    4   4   2
  18.490 +cmp        8  .     .     1011...000......  A+-DXWLdxI  U U U    4   4   2
  18.491 +cmp       16  .     d     1011...001000...  ..........  U U U    4   4   2
  18.492 +cmp       16  .     a     1011...001001...  ..........  U U U    4   4   2
  18.493 +cmp       16  .     .     1011...001......  A+-DXWLdxI  U U U    4   4   2
  18.494 +cmp       32  .     d     1011...010000...  ..........  U U U    6   6   2
  18.495 +cmp       32  .     a     1011...010001...  ..........  U U U    6   6   2
  18.496 +cmp       32  .     .     1011...010......  A+-DXWLdxI  U U U    6   6   2
  18.497 +cmpa      16  .     d     1011...011000...  ..........  U U U    6   6   4
  18.498 +cmpa      16  .     a     1011...011001...  ..........  U U U    6   6   4
  18.499 +cmpa      16  .     .     1011...011......  A+-DXWLdxI  U U U    6   6   4
  18.500 +cmpa      32  .     d     1011...111000...  ..........  U U U    6   6   4
  18.501 +cmpa      32  .     a     1011...111001...  ..........  U U U    6   6   4
  18.502 +cmpa      32  .     .     1011...111......  A+-DXWLdxI  U U U    6   6   4
  18.503 +cmpi       8  .     d     0000110000000...  ..........  U U U    8   8   2
  18.504 +cmpi       8  .     .     0000110000......  A+-DXWL...  U U U    8   8   2
  18.505 +cmpi       8  .     pcdi  0000110000111010  ..........  . . U    .   .   7
  18.506 +cmpi       8  .     pcix  0000110000111011  ..........  . . U    .   .   9
  18.507 +cmpi      16  .     d     0000110001000...  ..........  U U U    8   8   2
  18.508 +cmpi      16  .     .     0000110001......  A+-DXWL...  U U U    8   8   2
  18.509 +cmpi      16  .     pcdi  0000110001111010  ..........  . . U    .   .   7
  18.510 +cmpi      16  .     pcix  0000110001111011  ..........  . . U    .   .   9
  18.511 +cmpi      32  .     d     0000110010000...  ..........  U U U   14  12   2
  18.512 +cmpi      32  .     .     0000110010......  A+-DXWL...  U U U   12  12   2
  18.513 +cmpi      32  .     pcdi  0000110010111010  ..........  . . U    .   .   7
  18.514 +cmpi      32  .     pcix  0000110010111011  ..........  . . U    .   .   9
  18.515 +cmpm       8  .     ax7   1011111100001...  ..........  U U U   12  12   9
  18.516 +cmpm       8  .     ay7   1011...100001111  ..........  U U U   12  12   9
  18.517 +cmpm       8  .     axy7  1011111100001111  ..........  U U U   12  12   9
  18.518 +cmpm       8  .     .     1011...100001...  ..........  U U U   12  12   9
  18.519 +cmpm      16  .     .     1011...101001...  ..........  U U U   12  12   9
  18.520 +cmpm      32  .     .     1011...110001...  ..........  U U U   20  20   9
  18.521 +cpbcc     32  .     .     1111...01.......  ..........  . . U    .   .   4  unemulated
  18.522 +cpdbcc    32  .     .     1111...001001...  ..........  . . U    .   .   4  unemulated
  18.523 +cpgen     32  .     .     1111...000......  ..........  . . U    .   .   4  unemulated
  18.524 +cpscc     32  .     .     1111...001......  ..........  . . U    .   .   4  unemulated
  18.525 +cptrapcc  32  .     .     1111...001111...  ..........  . . U    .   .   4  unemulated
  18.526 +dbt       16  .     .     0101000011001...  ..........  U U U   12  12   6
  18.527 +dbf       16  .     .     0101000111001...  ..........  U U U   14  14   6
  18.528 +dbcc      16  .     .     0101....11001...  ..........  U U U   12  12   6
  18.529 +divs      16  .     d     1000...111000...  ..........  U U U  158 122  56
  18.530 +divs      16  .     .     1000...111......  A+-DXWLdxI  U U U  158 122  56
  18.531 +divu      16  .     d     1000...011000...  ..........  U U U  140 108  44
  18.532 +divu      16  .     .     1000...011......  A+-DXWLdxI  U U U  140 108  44
  18.533 +divl      32  .     d     0100110001000...  ..........  . . U    .   .  84
  18.534 +divl      32  .     .     0100110001......  A+-DXWLdxI  . . U    .   .  84
  18.535 +eor        8  .     d     1011...100000...  ..........  U U U    4   4   2
  18.536 +eor        8  .     .     1011...100......  A+-DXWL...  U U U    8   8   4
  18.537 +eor       16  .     d     1011...101000...  ..........  U U U    4   4   2
  18.538 +eor       16  .     .     1011...101......  A+-DXWL...  U U U    8   8   4
  18.539 +eor       32  .     d     1011...110000...  ..........  U U U    8   6   2
  18.540 +eor       32  .     .     1011...110......  A+-DXWL...  U U U   12  12   4
  18.541 +eori      16  toc   .     0000101000111100  ..........  U U U   20  16  12
  18.542 +eori      16  tos   .     0000101001111100  ..........  S S S   20  16  12
  18.543 +eori       8  .     d     0000101000000...  ..........  U U U    8   8   2
  18.544 +eori       8  .     .     0000101000......  A+-DXWL...  U U U   12  12   4
  18.545 +eori      16  .     d     0000101001000...  ..........  U U U    8   8   2
  18.546 +eori      16  .     .     0000101001......  A+-DXWL...  U U U   12  12   4
  18.547 +eori      32  .     d     0000101010000...  ..........  U U U   16  14   2
  18.548 +eori      32  .     .     0000101010......  A+-DXWL...  U U U   20  20   4
  18.549 +exg       32  dd    .     1100...101000...  ..........  U U U    6   6   2
  18.550 +exg       32  aa    .     1100...101001...  ..........  U U U    6   6   2
  18.551 +exg       32  da    .     1100...110001...  ..........  U U U    6   6   2
  18.552 +ext       16  .     .     0100100010000...  ..........  U U U    4   4   4
  18.553 +ext       32  .     .     0100100011000...  ..........  U U U    4   4   4
  18.554 +extb      32  .     .     0100100111000...  ..........  . . U    .   .   4
  18.555 +illegal    0  .     .     0100101011111100  ..........  U U U    4   4   4
  18.556 +jmp       32  .     .     0100111011......  A..DXWLdx.  U U U    4   4   0
  18.557 +jsr       32  .     .     0100111010......  A..DXWLdx.  U U U   12  12   0
  18.558 +lea       32  .     .     0100...111......  A..DXWLdx.  U U U    0   0   2
  18.559 +link      16  .     a7    0100111001010111  ..........  U U U   16  16   5
  18.560 +link      16  .     .     0100111001010...  ..........  U U U   16  16   5
  18.561 +link      32  .     a7    0100100000001111  ..........  . . U    .   .   6
  18.562 +link      32  .     .     0100100000001...  ..........  . . U    .   .   6
  18.563 +lsr        8  s     .     1110...000001...  ..........  U U U    6   6   4
  18.564 +lsr       16  s     .     1110...001001...  ..........  U U U    6   6   4
  18.565 +lsr       32  s     .     1110...010001...  ..........  U U U    8   8   4
  18.566 +lsr        8  r     .     1110...000101...  ..........  U U U    6   6   6
  18.567 +lsr       16  r     .     1110...001101...  ..........  U U U    6   6   6
  18.568 +lsr       32  r     .     1110...010101...  ..........  U U U    8   8   6
  18.569 +lsr       16  .     .     1110001011......  A+-DXWL...  U U U    8   8   5
  18.570 +lsl        8  s     .     1110...100001...  ..........  U U U    6   6   4
  18.571 +lsl       16  s     .     1110...101001...  ..........  U U U    6   6   4
  18.572 +lsl       32  s     .     1110...110001...  ..........  U U U    8   8   4
  18.573 +lsl        8  r     .     1110...100101...  ..........  U U U    6   6   6
  18.574 +lsl       16  r     .     1110...101101...  ..........  U U U    6   6   6
  18.575 +lsl       32  r     .     1110...110101...  ..........  U U U    8   8   6
  18.576 +lsl       16  .     .     1110001111......  A+-DXWL...  U U U    8   8   5
  18.577 +move       8  d     d     0001...000000...  ..........  U U U    4   4   2
  18.578 +move       8  d     .     0001...000......  A+-DXWLdxI  U U U    4   4   2
  18.579 +move       8  ai    d     0001...010000...  ..........  U U U    8   8   4
  18.580 +move       8  ai    .     0001...010......  A+-DXWLdxI  U U U    8   8   4
  18.581 +move       8  pi    d     0001...011000...  ..........  U U U    8   8   4
  18.582 +move       8  pi    .     0001...011......  A+-DXWLdxI  U U U    8   8   4
  18.583 +move       8  pi7   d     0001111011000...  ..........  U U U    8   8   4
  18.584 +move       8  pi7   .     0001111011......  A+-DXWLdxI  U U U    8   8   4
  18.585 +move       8  pd    d     0001...100000...  ..........  U U U    8   8   5
  18.586 +move       8  pd    .     0001...100......  A+-DXWLdxI  U U U    8   8   5
  18.587 +move       8  pd7   d     0001111100000...  ..........  U U U    8   8   5
  18.588 +move       8  pd7   .     0001111100......  A+-DXWLdxI  U U U    8   8   5
  18.589 +move       8  di    d     0001...101000...  ..........  U U U   12  12   5
  18.590 +move       8  di    .     0001...101......  A+-DXWLdxI  U U U   12  12   5
  18.591 +move       8  ix    d     0001...110000...  ..........  U U U   14  14   7
  18.592 +move       8  ix    .     0001...110......  A+-DXWLdxI  U U U   14  14   7
  18.593 +move       8  aw    d     0001000111000...  ..........  U U U   12  12   4
  18.594 +move       8  aw    .     0001000111......  A+-DXWLdxI  U U U   12  12   4
  18.595 +move       8  al    d     0001001111000...  ..........  U U U   16  16   6
  18.596 +move       8  al    .     0001001111......  A+-DXWLdxI  U U U   16  16   6
  18.597 +move      16  d     d     0011...000000...  ..........  U U U    4   4   2
  18.598 +move      16  d     a     0011...000001...  ..........  U U U    4   4   2
  18.599 +move      16  d     .     0011...000......  A+-DXWLdxI  U U U    4   4   2
  18.600 +move      16  ai    d     0011...010000...  ..........  U U U    8   8   4
  18.601 +move      16  ai    a     0011...010001...  ..........  U U U    8   8   4
  18.602 +move      16  ai    .     0011...010......  A+-DXWLdxI  U U U    8   8   4
  18.603 +move      16  pi    d     0011...011000...  ..........  U U U    8   8   4
  18.604 +move      16  pi    a     0011...011001...  ..........  U U U    8   8   4
  18.605 +move      16  pi    .     0011...011......  A+-DXWLdxI  U U U    8   8   4
  18.606 +move      16  pd    d     0011...100000...  ..........  U U U    8   8   5
  18.607 +move      16  pd    a     0011...100001...  ..........  U U U    8   8   5
  18.608 +move      16  pd    .     0011...100......  A+-DXWLdxI  U U U    8   8   5
  18.609 +move      16  di    d     0011...101000...  ..........  U U U   12  12   5
  18.610 +move      16  di    a     0011...101001...  ..........  U U U   12  12   5
  18.611 +move      16  di    .     0011...101......  A+-DXWLdxI  U U U   12  12   5
  18.612 +move      16  ix    d     0011...110000...  ..........  U U U   14  14   7
  18.613 +move      16  ix    a     0011...110001...  ..........  U U U   14  14   7
  18.614 +move      16  ix    .     0011...110......  A+-DXWLdxI  U U U   14  14   7
  18.615 +move      16  aw    d     0011000111000...  ..........  U U U   12  12   4
  18.616 +move      16  aw    a     0011000111001...  ..........  U U U   12  12   4
  18.617 +move      16  aw    .     0011000111......  A+-DXWLdxI  U U U   12  12   4
  18.618 +move      16  al    d     0011001111000...  ..........  U U U   16  16   6
  18.619 +move      16  al    a     0011001111001...  ..........  U U U   16  16   6
  18.620 +move      16  al    .     0011001111......  A+-DXWLdxI  U U U   16  16   6
  18.621 +move      32  d     d     0010...000000...  ..........  U U U    4   4   2
  18.622 +move      32  d     a     0010...000001...  ..........  U U U    4   4   2
  18.623 +move      32  d     .     0010...000......  A+-DXWLdxI  U U U    4   4   2
  18.624 +move      32  ai    d     0010...010000...  ..........  U U U   12  12   4
  18.625 +move      32  ai    a     0010...010001...  ..........  U U U   12  12   4
  18.626 +move      32  ai    .     0010...010......  A+-DXWLdxI  U U U   12  12   4
  18.627 +move      32  pi    d     0010...011000...  ..........  U U U   12  12   4
  18.628 +move      32  pi    a     0010...011001...  ..........  U U U   12  12   4
  18.629 +move      32  pi    .     0010...011......  A+-DXWLdxI  U U U   12  12   4
  18.630 +move      32  pd    d     0010...100000...  ..........  U U U   12  14   5
  18.631 +move      32  pd    a     0010...100001...  ..........  U U U   12  14   5
  18.632 +move      32  pd    .     0010...100......  A+-DXWLdxI  U U U   12  14   5
  18.633 +move      32  di    d     0010...101000...  ..........  U U U   16  16   5
  18.634 +move      32  di    a     0010...101001...  ..........  U U U   16  16   5
  18.635 +move      32  di    .     0010...101......  A+-DXWLdxI  U U U   16  16   5
  18.636 +move      32  ix    d     0010...110000...  ..........  U U U   18  18   7
  18.637 +move      32  ix    a     0010...110001...  ..........  U U U   18  18   7
  18.638 +move      32  ix    .     0010...110......  A+-DXWLdxI  U U U   18  18   7
  18.639 +move      32  aw    d     0010000111000...  ..........  U U U   16  16   4
  18.640 +move      32  aw    a     0010000111001...  ..........  U U U   16  16   4
  18.641 +move      32  aw    .     0010000111......  A+-DXWLdxI  U U U   16  16   4
  18.642 +move      32  al    d     0010001111000...  ..........  U U U   20  20   6
  18.643 +move      32  al    a     0010001111001...  ..........  U U U   20  20   6
  18.644 +move      32  al    .     0010001111......  A+-DXWLdxI  U U U   20  20   6
  18.645 +movea     16  .     d     0011...001000...  ..........  U U U    4   4   2
  18.646 +movea     16  .     a     0011...001001...  ..........  U U U    4   4   2
  18.647 +movea     16  .     .     0011...001......  A+-DXWLdxI  U U U    4   4   2
  18.648 +movea     32  .     d     0010...001000...  ..........  U U U    4   4   2
  18.649 +movea     32  .     a     0010...001001...  ..........  U U U    4   4   2
  18.650 +movea     32  .     .     0010...001......  A+-DXWLdxI  U U U    4   4   2
  18.651 +move      16  frc   d     0100001011000...  ..........  . U U    .   4   4
  18.652 +move      16  frc   .     0100001011......  A+-DXWL...  . U U    .   8   4
  18.653 +move      16  toc   d     0100010011000...  ..........  U U U   12  12   4
  18.654 +move      16  toc   .     0100010011......  A+-DXWLdxI  U U U   12  12   4
  18.655 +move      16  frs   d     0100000011000...  ..........  U S S    6   4   8 U only for 000
  18.656 +move      16  frs   .     0100000011......  A+-DXWL...  U S S    8   8   8 U only for 000
  18.657 +move      16  tos   d     0100011011000...  ..........  S S S   12  12   8
  18.658 +move      16  tos   .     0100011011......  A+-DXWLdxI  S S S   12  12   8
  18.659 +move      32  fru   .     0100111001101...  ..........  S S S    4   6   2
  18.660 +move      32  tou   .     0100111001100...  ..........  S S S    4   6   2
  18.661 +movec     32  cr    .     0100111001111010  ..........  . S S    .  12   6
  18.662 +movec     32  rc    .     0100111001111011  ..........  . S S    .  10  12
  18.663 +movem     16  re    pd    0100100010100...  ..........  U U U    8   8   4
  18.664 +movem     16  re    .     0100100010......  A..DXWL...  U U U    8   8   4
  18.665 +movem     32  re    pd    0100100011100...  ..........  U U U    8   8   4
  18.666 +movem     32  re    .     0100100011......  A..DXWL...  U U U    8   8   4
  18.667 +movem     16  er    pi    0100110010011...  ..........  U U U   12  12   8
  18.668 +movem     16  er    .     0100110010......  A..DXWLdx.  U U U   12  12   8
  18.669 +movem     32  er    pi    0100110011011...  ..........  U U U   12  12   8
  18.670 +movem     32  er    .     0100110011......  A..DXWLdx.  U U U   12  12   8
  18.671 +movep     16  er    .     0000...100001...  ..........  U U U   16  16  12
  18.672 +movep     32  er    .     0000...101001...  ..........  U U U   24  24  18
  18.673 +movep     16  re    .     0000...110001...  ..........  U U U   16  16  11
  18.674 +movep     32  re    .     0000...111001...  ..........  U U U   24  24  17
  18.675 +moveq     32  .     .     0111...0........  ..........  U U U    4   4   2
  18.676 +moves      8  .     .     0000111000......  A+-DXWL...  . S S    .  14   5
  18.677 +moves     16  .     .     0000111001......  A+-DXWL...  . S S    .  14   5
  18.678 +moves     32  .     .     0000111010......  A+-DXWL...  . S S    .  16   5
  18.679 +muls      16  .     d     1100...111000...  ..........  U U U   54  32  27
  18.680 +muls      16  .     .     1100...111......  A+-DXWLdxI  U U U   54  32  27
  18.681 +mulu      16  .     d     1100...011000...  ..........  U U U   54  30  27
  18.682 +mulu      16  .     .     1100...011......  A+-DXWLdxI  U U U   54  30  27
  18.683 +mull      32  .     d     0100110000000...  ..........  . . U    .   .  43
  18.684 +mull      32  .     .     0100110000......  A+-DXWLdxI  . . U    .   .  43
  18.685 +nbcd       8  .     d     0100100000000...  ..........  U U U    6   6   6
  18.686 +nbcd       8  .     .     0100100000......  A+-DXWL...  U U U    8   8   6
  18.687 +neg        8  .     d     0100010000000...  ..........  U U U    4   4   2
  18.688 +neg        8  .     .     0100010000......  A+-DXWL...  U U U    8   8   4
  18.689 +neg       16  .     d     0100010001000...  ..........  U U U    4   4   2
  18.690 +neg       16  .     .     0100010001......  A+-DXWL...  U U U    8   8   4
  18.691 +neg       32  .     d     0100010010000...  ..........  U U U    6   6   2
  18.692 +neg       32  .     .     0100010010......  A+-DXWL...  U U U   12  12   4
  18.693 +negx       8  .     d     0100000000000...  ..........  U U U    4   4   2
  18.694 +negx       8  .     .     0100000000......  A+-DXWL...  U U U    8   8   4
  18.695 +negx      16  .     d     0100000001000...  ..........  U U U    4   4   2
  18.696 +negx      16  .     .     0100000001......  A+-DXWL...  U U U    8   8   4
  18.697 +negx      32  .     d     0100000010000...  ..........  U U U    6   6   2
  18.698 +negx      32  .     .     0100000010......  A+-DXWL...  U U U   12  12   4
  18.699 +nop        0  .     .     0100111001110001  ..........  U U U    4   4   2
  18.700 +not        8  .     d     0100011000000...  ..........  U U U    4   4   2
  18.701 +not        8  .     .     0100011000......  A+-DXWL...  U U U    8   8   4
  18.702 +not       16  .     d     0100011001000...  ..........  U U U    4   4   2
  18.703 +not       16  .     .     0100011001......  A+-DXWL...  U U U    8   8   4
  18.704 +not       32  .     d     0100011010000...  ..........  U U U    6   6   2
  18.705 +not       32  .     .     0100011010......  A+-DXWL...  U U U   12  12   4
  18.706 +or         8  er    d     1000...000000...  ..........  U U U    4   4   2
  18.707 +or         8  er    .     1000...000......  A+-DXWLdxI  U U U    4   4   2
  18.708 +or        16  er    d     1000...001000...  ..........  U U U    4   4   2
  18.709 +or        16  er    .     1000...001......  A+-DXWLdxI  U U U    4   4   2
  18.710 +or        32  er    d     1000...010000...  ..........  U U U    6   6   2
  18.711 +or        32  er    .     1000...010......  A+-DXWLdxI  U U U    6   6   2
  18.712 +or         8  re    .     1000...100......  A+-DXWL...  U U U    8   8   4
  18.713 +or        16  re    .     1000...101......  A+-DXWL...  U U U    8   8   4
  18.714 +or        32  re    .     1000...110......  A+-DXWL...  U U U   12  12   4
  18.715 +ori       16  toc   .     0000000000111100  ..........  U U U   20  16  12
  18.716 +ori       16  tos   .     0000000001111100  ..........  S S S   20  16  12
  18.717 +ori        8  .     d     0000000000000...  ..........  U U U    8   8   2
  18.718 +ori        8  .     .     0000000000......  A+-DXWL...  U U U   12  12   4
  18.719 +ori       16  .     d     0000000001000...  ..........  U U U    8   8   2
  18.720 +ori       16  .     .     0000000001......  A+-DXWL...  U U U   12  12   4
  18.721 +ori       32  .     d     0000000010000...  ..........  U U U   16  14   2
  18.722 +ori       32  .     .     0000000010......  A+-DXWL...  U U U   20  20   4
  18.723 +pack      16  rr    .     1000...101000...  ..........  . . U    .   .   6
  18.724 +pack      16  mm    ax7   1000111101001...  ..........  . . U    .   .  13
  18.725 +pack      16  mm    ay7   1000...101001111  ..........  . . U    .   .  13
  18.726 +pack      16  mm    axy7  1000111101001111  ..........  . . U    .   .  13
  18.727 +pack      16  mm    .     1000...101001...  ..........  . . U    .   .  13
  18.728 +pea       32  .     .     0100100001......  A..DXWLdx.  U U U    6   6   5
  18.729 +reset      0  .     .     0100111001110000  ..........  S S S    0   0   0
  18.730 +ror        8  s     .     1110...000011...  ..........  U U U    6   6   8
  18.731 +ror       16  s     .     1110...001011...  ..........  U U U    6   6   8
  18.732 +ror       32  s     .     1110...010011...  ..........  U U U    8   8   8
  18.733 +ror        8  r     .     1110...000111...  ..........  U U U    6   6   8
  18.734 +ror       16  r     .     1110...001111...  ..........  U U U    6   6   8
  18.735 +ror       32  r     .     1110...010111...  ..........  U U U    8   8   8
  18.736 +ror       16  .     .     1110011011......  A+-DXWL...  U U U    8   8   7
  18.737 +rol        8  s     .     1110...100011...  ..........  U U U    6   6   8
  18.738 +rol       16  s     .     1110...101011...  ..........  U U U    6   6   8
  18.739 +rol       32  s     .     1110...110011...  ..........  U U U    8   8   8
  18.740 +rol        8  r     .     1110...100111...  ..........  U U U    6   6   8
  18.741 +rol       16  r     .     1110...101111...  ..........  U U U    6   6   8
  18.742 +rol       32  r     .     1110...110111...  ..........  U U U    8   8   8
  18.743 +rol       16  .     .     1110011111......  A+-DXWL...  U U U    8   8   7
  18.744 +roxr       8  s     .     1110...000010...  ..........  U U U    6   6  12
  18.745 +roxr      16  s     .     1110...001010...  ..........  U U U    6   6  12
  18.746 +roxr      32  s     .     1110...010010...  ..........  U U U    8   8  12
  18.747 +roxr       8  r     .     1110...000110...  ..........  U U U    6   6  12
  18.748 +roxr      16  r     .     1110...001110...  ..........  U U U    6   6  12
  18.749 +roxr      32  r     .     1110...010110...  ..........  U U U    8   8  12
  18.750 +roxr      16  .     .     1110010011......  A+-DXWL...  U U U    8   8   5
  18.751 +roxl       8  s     .     1110...100010...  ..........  U U U    6   6  12
  18.752 +roxl      16  s     .     1110...101010...  ..........  U U U    6   6  12
  18.753 +roxl      32  s     .     1110...110010...  ..........  U U U    8   8  12
  18.754 +roxl       8  r     .     1110...100110...  ..........  U U U    6   6  12
  18.755 +roxl      16  r     .     1110...101110...  ..........  U U U    6   6  12
  18.756 +roxl      32  r     .     1110...110110...  ..........  U U U    8   8  12
  18.757 +roxl      16  .     .     1110010111......  A+-DXWL...  U U U    8   8   5
  18.758 +rtd       32  .     .     0100111001110100  ..........  . U U    .  16  10
  18.759 +rte       32  .     .     0100111001110011  ..........  S S S   20  24  20  bus fault not emulated
  18.760 +rtm       32  .     .     000001101100....  ..........  . . U    .   .  19  not properly emulated
  18.761 +rtr       32  .     .     0100111001110111  ..........  U U U   20  20  14
  18.762 +rts       32  .     .     0100111001110101  ..........  U U U   16  16  10
  18.763 +sbcd       8  rr    .     1000...100000...  ..........  U U U    6   6   4
  18.764 +sbcd       8  mm    ax7   1000111100001...  ..........  U U U   18  18  16
  18.765 +sbcd       8  mm    ay7   1000...100001111  ..........  U U U   18  18  16
  18.766 +sbcd       8  mm    axy7  1000111100001111  ..........  U U U   18  18  16
  18.767 +sbcd       8  mm    .     1000...100001...  ..........  U U U   18  18  16
  18.768 +st         8  .     d     0101000011000...  ..........  U U U    6   4   4
  18.769 +st         8  .     .     0101000011......  A+-DXWL...  U U U    8   8   6
  18.770 +sf         8  .     d     0101000111000...  ..........  U U U    4   4   4
  18.771 +sf         8  .     .     0101000111......  A+-DXWL...  U U U    8   8   6
  18.772 +scc        8  .     d     0101....11000...  ..........  U U U    4   4   4
  18.773 +scc        8  .     .     0101....11......  A+-DXWL...  U U U    8   8   6
  18.774 +stop       0  .     .     0100111001110010  ..........  S S S    4   4   8
  18.775 +sub        8  er    d     1001...000000...  ..........  U U U    4   4   2
  18.776 +sub        8  er    .     1001...000......  A+-DXWLdxI  U U U    4   4   2
  18.777 +sub       16  er    d     1001...001000...  ..........  U U U    4   4   2
  18.778 +sub       16  er    a     1001...001001...  ..........  U U U    4   4   2
  18.779 +sub       16  er    .     1001...001......  A+-DXWLdxI  U U U    4   4   2
  18.780 +sub       32  er    d     1001...010000...  ..........  U U U    6   6   2
  18.781 +sub       32  er    a     1001...010001...  ..........  U U U    6   6   2
  18.782 +sub       32  er    .     1001...010......  A+-DXWLdxI  U U U    6   6   2
  18.783 +sub        8  re    .     1001...100......  A+-DXWL...  U U U    8   8   4
  18.784 +sub       16  re    .     1001...101......  A+-DXWL...  U U U    8   8   4
  18.785 +sub       32  re    .     1001...110......  A+-DXWL...  U U U   12  12   4
  18.786 +suba      16  .     d     1001...011000...  ..........  U U U    8   8   2
  18.787 +suba      16  .     a     1001...011001...  ..........  U U U    8   8   2
  18.788 +suba      16  .     .     1001...011......  A+-DXWLdxI  U U U    8   8   2
  18.789 +suba      32  .     d     1001...111000...  ..........  U U U    6   6   2
  18.790 +suba      32  .     a     1001...111001...  ..........  U U U    6   6   2
  18.791 +suba      32  .     .     1001...111......  A+-DXWLdxI  U U U    6   6   2
  18.792 +subi       8  .     d     0000010000000...  ..........  U U U    8   8   2
  18.793 +subi       8  .     .     0000010000......  A+-DXWL...  U U U   12  12   4
  18.794 +subi      16  .     d     0000010001000...  ..........  U U U    8   8   2
  18.795 +subi      16  .     .     0000010001......  A+-DXWL...  U U U   12  12   4
  18.796 +subi      32  .     d     0000010010000...  ..........  U U U   16  14   2
  18.797 +subi      32  .     .     0000010010......  A+-DXWL...  U U U   20  20   4
  18.798 +subq       8  .     d     0101...100000...  ..........  U U U    4   4   2
  18.799 +subq       8  .     .     0101...100......  A+-DXWL...  U U U    8   8   4
  18.800 +subq      16  .     d     0101...101000...  ..........  U U U    4   4   2
  18.801 +subq      16  .     a     0101...101001...  ..........  U U U    8   4   2
  18.802 +subq      16  .     .     0101...101......  A+-DXWL...  U U U    8   8   4
  18.803 +subq      32  .     d     0101...110000...  ..........  U U U    8   8   2
  18.804 +subq      32  .     a     0101...110001...  ..........  U U U    8   8   2
  18.805 +subq      32  .     .     0101...110......  A+-DXWL...  U U U   12  12   4
  18.806 +subx       8  rr    .     1001...100000...  ..........  U U U    4   4   2
  18.807 +subx      16  rr    .     1001...101000...  ..........  U U U    4   4   2
  18.808 +subx      32  rr    .     1001...110000...  ..........  U U U    8   6   2
  18.809 +subx       8  mm    ax7   1001111100001...  ..........  U U U   18  18  12
  18.810 +subx       8  mm    ay7   1001...100001111  ..........  U U U   18  18  12
  18.811 +subx       8  mm    axy7  1001111100001111  ..........  U U U   18  18  12
  18.812 +subx       8  mm    .     1001...100001...  ..........  U U U   18  18  12
  18.813 +subx      16  mm    .     1001...101001...  ..........  U U U   18  18  12
  18.814 +subx      32  mm    .     1001...110001...  ..........  U U U   30  30  12
  18.815 +swap      32  .     .     0100100001000...  ..........  U U U    4   4   4
  18.816 +tas        8  .     d     0100101011000...  ..........  U U U    4   4   4
  18.817 +tas        8  .     .     0100101011......  A+-DXWL...  U U U   14  14  12
  18.818 +trap       0  .     .     010011100100....  ..........  U U U    4   4   4
  18.819 +trapt      0  .     .     0101000011111100  ..........  . . U    .   .   4
  18.820 +trapt     16  .     .     0101000011111010  ..........  . . U    .   .   6
  18.821 +trapt     32  .     .     0101000011111011  ..........  . . U    .   .   8
  18.822 +trapf      0  .     .     0101000111111100  ..........  . . U    .   .   4
  18.823 +trapf     16  .     .     0101000111111010  ..........  . . U    .   .   6
  18.824 +trapf     32  .     .     0101000111111011  ..........  . . U    .   .   8
  18.825 +trapcc     0  .     .     0101....11111100  ..........  . . U    .   .   4
  18.826 +trapcc    16  .     .     0101....11111010  ..........  . . U    .   .   6
  18.827 +trapcc    32  .     .     0101....11111011  ..........  . . U    .   .   8
  18.828 +trapv      0  .     .     0100111001110110  ..........  U U U    4   4   4
  18.829 +tst        8  .     d     0100101000000...  ..........  U U U    4   4   2
  18.830 +tst        8  .     .     0100101000......  A+-DXWL...  U U U    4   4   2
  18.831 +tst        8  .     pcdi  0100101000111010  ..........  . . U    .   .   7
  18.832 +tst        8  .     pcix  0100101000111011  ..........  . . U    .   .   9
  18.833 +tst        8  .     i     0100101000111100  ..........  . . U    .   .   6
  18.834 +tst       16  .     d     0100101001000...  ..........  U U U    4   4   2
  18.835 +tst       16  .     a     0100101001001...  ..........  . . U    .   .   2
  18.836 +tst       16  .     .     0100101001......  A+-DXWL...  U U U    4   4   2
  18.837 +tst       16  .     pcdi  0100101001111010  ..........  . . U    .   .   7
  18.838 +tst       16  .     pcix  0100101001111011  ..........  . . U    .   .   9
  18.839 +tst       16  .     i     0100101001111100  ..........  . . U    .   .   6
  18.840 +tst       32  .     d     0100101010000...  ..........  U U U    4   4   2
  18.841 +tst       32  .     a     0100101010001...  ..........  . . U    .   .   2
  18.842 +tst       32  .     .     0100101010......  A+-DXWL...  U U U    4   4   2
  18.843 +tst       32  .     pcdi  0100101010111010  ..........  . . U    .   .   7
  18.844 +tst       32  .     pcix  0100101010111011  ..........  . . U    .   .   9
  18.845 +tst       32  .     i     0100101010111100  ..........  . . U    .   .   6
  18.846 +unlk      32  .     a7    0100111001011111  ..........  U U U   12  12   6
  18.847 +unlk      32  .     .     0100111001011...  ..........  U U U   12  12   6
  18.848 +unpk      16  rr    .     1000...110000...  ..........  . . U    .   .   8
  18.849 +unpk      16  mm    ax7   1000111110001...  ..........  . . U    .   .  13
  18.850 +unpk      16  mm    ay7   1000...110001111  ..........  . . U    .   .  13
  18.851 +unpk      16  mm    axy7  1000111110001111  ..........  . . U    .   .  13
  18.852 +unpk      16  mm    .     1000...110001...  ..........  . . U    .   .  13
  18.853 +
  18.854 +
  18.855 +
  18.856 +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  18.857 +M68KMAKE_OPCODE_HANDLER_BODY
  18.858 +
  18.859 +M68KMAKE_OP(1010, 0, ., .)
  18.860 +{
  18.861 +	m68ki_exception_1010();
  18.862 +}
  18.863 +
  18.864 +
  18.865 +M68KMAKE_OP(1111, 0, ., .)
  18.866 +{
  18.867 +	m68ki_exception_1111();
  18.868 +}
  18.869 +
  18.870 +
  18.871 +M68KMAKE_OP(abcd, 8, rr, .)
  18.872 +{
  18.873 +	uint* r_dst = &DX;
  18.874 +	uint src = DY;
  18.875 +	uint dst = *r_dst;
  18.876 +	uint res = LOW_NIBBLE(src) + LOW_NIBBLE(dst) + XFLAG_AS_1();
  18.877 +
  18.878 +	if(res > 9)
  18.879 +		res += 6;
  18.880 +	res += HIGH_NIBBLE(src) + HIGH_NIBBLE(dst);
  18.881 +	FLAG_X = FLAG_C = (res > 0x99) << 8;
  18.882 +	if(FLAG_C)
  18.883 +		res -= 0xa0;
  18.884 +
  18.885 +	FLAG_N = NFLAG_8(res); /* officially undefined */
  18.886 +
  18.887 +	res = MASK_OUT_ABOVE_8(res);
  18.888 +	FLAG_Z |= res;
  18.889 +
  18.890 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
  18.891 +}
  18.892 +
  18.893 +
  18.894 +M68KMAKE_OP(abcd, 8, mm, ax7)
  18.895 +{
  18.896 +	uint src = OPER_AY_PD_8();
  18.897 +	uint ea  = EA_A7_PD_8();
  18.898 +	uint dst = m68ki_read_8(ea);
  18.899 +	uint res = LOW_NIBBLE(src) + LOW_NIBBLE(dst) + XFLAG_AS_1();
  18.900 +
  18.901 +	if(res > 9)
  18.902 +		res += 6;
  18.903 +	res += HIGH_NIBBLE(src) + HIGH_NIBBLE(dst);
  18.904 +	FLAG_X = FLAG_C = (res > 0x99) << 8;
  18.905 +	if(FLAG_C)
  18.906 +		res -= 0xa0;
  18.907 +
  18.908 +	FLAG_N = NFLAG_8(res); /* officially undefined */
  18.909 +
  18.910 +	res = MASK_OUT_ABOVE_8(res);
  18.911 +	FLAG_Z |= res;
  18.912 +
  18.913 +	m68ki_write_8(ea, res);
  18.914 +}
  18.915 +
  18.916 +
  18.917 +M68KMAKE_OP(abcd, 8, mm, ay7)
  18.918 +{
  18.919 +	uint src = OPER_A7_PD_8();
  18.920 +	uint ea  = EA_AX_PD_8();
  18.921 +	uint dst = m68ki_read_8(ea);
  18.922 +	uint res = LOW_NIBBLE(src) + LOW_NIBBLE(dst) + XFLAG_AS_1();
  18.923 +
  18.924 +	if(res > 9)
  18.925 +		res += 6;
  18.926 +	res += HIGH_NIBBLE(src) + HIGH_NIBBLE(dst);
  18.927 +	FLAG_X = FLAG_C = (res > 0x99) << 8;
  18.928 +	if(FLAG_C)
  18.929 +		res -= 0xa0;
  18.930 +
  18.931 +	FLAG_N = NFLAG_8(res); /* officially undefined */
  18.932 +
  18.933 +	res = MASK_OUT_ABOVE_8(res);
  18.934 +	FLAG_Z |= res;
  18.935 +
  18.936 +	m68ki_write_8(ea, res);
  18.937 +}
  18.938 +
  18.939 +
  18.940 +M68KMAKE_OP(abcd, 8, mm, axy7)
  18.941 +{
  18.942 +	uint src = OPER_A7_PD_8();
  18.943 +	uint ea  = EA_A7_PD_8();
  18.944 +	uint dst = m68ki_read_8(ea);
  18.945 +	uint res = LOW_NIBBLE(src) + LOW_NIBBLE(dst) + XFLAG_AS_1();
  18.946 +
  18.947 +	if(res > 9)
  18.948 +		res += 6;
  18.949 +	res += HIGH_NIBBLE(src) + HIGH_NIBBLE(dst);
  18.950 +	FLAG_X = FLAG_C = (res > 0x99) << 8;
  18.951 +	if(FLAG_C)
  18.952 +		res -= 0xa0;
  18.953 +
  18.954 +	FLAG_N = NFLAG_8(res); /* officially undefined */
  18.955 +
  18.956 +	res = MASK_OUT_ABOVE_8(res);
  18.957 +	FLAG_Z |= res;
  18.958 +
  18.959 +	m68ki_write_8(ea, res);
  18.960 +}
  18.961 +
  18.962 +
  18.963 +M68KMAKE_OP(abcd, 8, mm, .)
  18.964 +{
  18.965 +	uint src = OPER_AY_PD_8();
  18.966 +	uint ea  = EA_AX_PD_8();
  18.967 +	uint dst = m68ki_read_8(ea);
  18.968 +	uint res = LOW_NIBBLE(src) + LOW_NIBBLE(dst) + XFLAG_AS_1();
  18.969 +
  18.970 +	if(res > 9)
  18.971 +		res += 6;
  18.972 +	res += HIGH_NIBBLE(src) + HIGH_NIBBLE(dst);
  18.973 +	FLAG_X = FLAG_C = (res > 0x99) << 8;
  18.974 +	if(FLAG_C)
  18.975 +		res -= 0xa0;
  18.976 +
  18.977 +	FLAG_N = NFLAG_8(res); /* officially undefined */
  18.978 +
  18.979 +	res = MASK_OUT_ABOVE_8(res);
  18.980 +	FLAG_Z |= res;
  18.981 +
  18.982 +	m68ki_write_8(ea, res);
  18.983 +}
  18.984 +
  18.985 +
  18.986 +M68KMAKE_OP(add, 8, er, d)
  18.987 +{
  18.988 +	uint* r_dst = &DX;
  18.989 +	uint src = MASK_OUT_ABOVE_8(DY);
  18.990 +	uint dst = MASK_OUT_ABOVE_8(*r_dst);
  18.991 +	uint res = src + dst;
  18.992 +
  18.993 +	FLAG_N = NFLAG_8(res);
  18.994 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
  18.995 +	FLAG_X = FLAG_C = CFLAG_8(res);
  18.996 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
  18.997 +
  18.998 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | FLAG_Z;
  18.999 +}
 18.1000 +
 18.1001 +
 18.1002 +M68KMAKE_OP(add, 8, er, .)
 18.1003 +{
 18.1004 +	uint* r_dst = &DX;
 18.1005 +	uint src = M68KMAKE_GET_OPER_AY_8;
 18.1006 +	uint dst = MASK_OUT_ABOVE_8(*r_dst);
 18.1007 +	uint res = src + dst;
 18.1008 +
 18.1009 +	FLAG_N = NFLAG_8(res);
 18.1010 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1011 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1012 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.1013 +
 18.1014 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | FLAG_Z;
 18.1015 +}
 18.1016 +
 18.1017 +
 18.1018 +M68KMAKE_OP(add, 16, er, d)
 18.1019 +{
 18.1020 +	uint* r_dst = &DX;
 18.1021 +	uint src = MASK_OUT_ABOVE_16(DY);
 18.1022 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.1023 +	uint res = src + dst;
 18.1024 +
 18.1025 +	FLAG_N = NFLAG_16(res);
 18.1026 +	FLAG_V = VFLAG_ADD_16(src, dst, res);
 18.1027 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.1028 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.1029 +
 18.1030 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.1031 +}
 18.1032 +
 18.1033 +
 18.1034 +M68KMAKE_OP(add, 16, er, a)
 18.1035 +{
 18.1036 +	uint* r_dst = &DX;
 18.1037 +	uint src = MASK_OUT_ABOVE_16(AY);
 18.1038 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.1039 +	uint res = src + dst;
 18.1040 +
 18.1041 +	FLAG_N = NFLAG_16(res);
 18.1042 +	FLAG_V = VFLAG_ADD_16(src, dst, res);
 18.1043 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.1044 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.1045 +
 18.1046 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.1047 +}
 18.1048 +
 18.1049 +
 18.1050 +M68KMAKE_OP(add, 16, er, .)
 18.1051 +{
 18.1052 +	uint* r_dst = &DX;
 18.1053 +	uint src = M68KMAKE_GET_OPER_AY_16;
 18.1054 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.1055 +	uint res = src + dst;
 18.1056 +
 18.1057 +	FLAG_N = NFLAG_16(res);
 18.1058 +	FLAG_V = VFLAG_ADD_16(src, dst, res);
 18.1059 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.1060 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.1061 +
 18.1062 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.1063 +}
 18.1064 +
 18.1065 +
 18.1066 +M68KMAKE_OP(add, 32, er, d)
 18.1067 +{
 18.1068 +	uint* r_dst = &DX;
 18.1069 +	uint src = DY;
 18.1070 +	uint dst = *r_dst;
 18.1071 +	uint res = src + dst;
 18.1072 +
 18.1073 +	FLAG_N = NFLAG_32(res);
 18.1074 +	FLAG_V = VFLAG_ADD_32(src, dst, res);
 18.1075 +	FLAG_X = FLAG_C = CFLAG_ADD_32(src, dst, res);
 18.1076 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.1077 +
 18.1078 +	*r_dst = FLAG_Z;
 18.1079 +}
 18.1080 +
 18.1081 +
 18.1082 +M68KMAKE_OP(add, 32, er, a)
 18.1083 +{
 18.1084 +	uint* r_dst = &DX;
 18.1085 +	uint src = AY;
 18.1086 +	uint dst = *r_dst;
 18.1087 +	uint res = src + dst;
 18.1088 +
 18.1089 +	FLAG_N = NFLAG_32(res);
 18.1090 +	FLAG_V = VFLAG_ADD_32(src, dst, res);
 18.1091 +	FLAG_X = FLAG_C = CFLAG_ADD_32(src, dst, res);
 18.1092 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.1093 +
 18.1094 +	*r_dst = FLAG_Z;
 18.1095 +}
 18.1096 +
 18.1097 +
 18.1098 +M68KMAKE_OP(add, 32, er, .)
 18.1099 +{
 18.1100 +	uint* r_dst = &DX;
 18.1101 +	uint src = M68KMAKE_GET_OPER_AY_32;
 18.1102 +	uint dst = *r_dst;
 18.1103 +	uint res = src + dst;
 18.1104 +
 18.1105 +	FLAG_N = NFLAG_32(res);
 18.1106 +	FLAG_V = VFLAG_ADD_32(src, dst, res);
 18.1107 +	FLAG_X = FLAG_C = CFLAG_ADD_32(src, dst, res);
 18.1108 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.1109 +
 18.1110 +	*r_dst = FLAG_Z;
 18.1111 +}
 18.1112 +
 18.1113 +
 18.1114 +M68KMAKE_OP(add, 8, re, .)
 18.1115 +{
 18.1116 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.1117 +	uint src = MASK_OUT_ABOVE_8(DX);
 18.1118 +	uint dst = m68ki_read_8(ea);
 18.1119 +	uint res = src + dst;
 18.1120 +
 18.1121 +	FLAG_N = NFLAG_8(res);
 18.1122 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1123 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1124 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.1125 +
 18.1126 +	m68ki_write_8(ea, FLAG_Z);
 18.1127 +}
 18.1128 +
 18.1129 +
 18.1130 +M68KMAKE_OP(add, 16, re, .)
 18.1131 +{
 18.1132 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.1133 +	uint src = MASK_OUT_ABOVE_16(DX);
 18.1134 +	uint dst = m68ki_read_16(ea);
 18.1135 +	uint res = src + dst;
 18.1136 +
 18.1137 +	FLAG_N = NFLAG_16(res);
 18.1138 +	FLAG_V = VFLAG_ADD_16(src, dst, res);
 18.1139 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.1140 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.1141 +
 18.1142 +	m68ki_write_16(ea, FLAG_Z);
 18.1143 +}
 18.1144 +
 18.1145 +
 18.1146 +M68KMAKE_OP(add, 32, re, .)
 18.1147 +{
 18.1148 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.1149 +	uint src = DX;
 18.1150 +	uint dst = m68ki_read_32(ea);
 18.1151 +	uint res = src + dst;
 18.1152 +
 18.1153 +	FLAG_N = NFLAG_32(res);
 18.1154 +	FLAG_V = VFLAG_ADD_32(src, dst, res);
 18.1155 +	FLAG_X = FLAG_C = CFLAG_ADD_32(src, dst, res);
 18.1156 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.1157 +
 18.1158 +	m68ki_write_32(ea, FLAG_Z);
 18.1159 +}
 18.1160 +
 18.1161 +
 18.1162 +M68KMAKE_OP(adda, 16, ., d)
 18.1163 +{
 18.1164 +	uint* r_dst = &AX;
 18.1165 +
 18.1166 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst + MAKE_INT_16(DY));
 18.1167 +}
 18.1168 +
 18.1169 +
 18.1170 +M68KMAKE_OP(adda, 16, ., a)
 18.1171 +{
 18.1172 +	uint* r_dst = &AX;
 18.1173 +
 18.1174 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst + MAKE_INT_16(AY));
 18.1175 +}
 18.1176 +
 18.1177 +
 18.1178 +M68KMAKE_OP(adda, 16, ., .)
 18.1179 +{
 18.1180 +	uint* r_dst = &AX;
 18.1181 +
 18.1182 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst + MAKE_INT_16(M68KMAKE_GET_OPER_AY_16));
 18.1183 +}
 18.1184 +
 18.1185 +
 18.1186 +M68KMAKE_OP(adda, 32, ., d)
 18.1187 +{
 18.1188 +	uint* r_dst = &AX;
 18.1189 +
 18.1190 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst + DY);
 18.1191 +}
 18.1192 +
 18.1193 +
 18.1194 +M68KMAKE_OP(adda, 32, ., a)
 18.1195 +{
 18.1196 +	uint* r_dst = &AX;
 18.1197 +
 18.1198 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst + AY);
 18.1199 +}
 18.1200 +
 18.1201 +
 18.1202 +M68KMAKE_OP(adda, 32, ., .)
 18.1203 +{
 18.1204 +	uint* r_dst = &AX;
 18.1205 +
 18.1206 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst + M68KMAKE_GET_OPER_AY_32);
 18.1207 +}
 18.1208 +
 18.1209 +
 18.1210 +M68KMAKE_OP(addi, 8, ., d)
 18.1211 +{
 18.1212 +	uint* r_dst = &DY;
 18.1213 +	uint src = OPER_I_8();
 18.1214 +	uint dst = MASK_OUT_ABOVE_8(*r_dst);
 18.1215 +	uint res = src + dst;
 18.1216 +
 18.1217 +	FLAG_N = NFLAG_8(res);
 18.1218 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1219 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1220 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.1221 +
 18.1222 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | FLAG_Z;
 18.1223 +}
 18.1224 +
 18.1225 +
 18.1226 +M68KMAKE_OP(addi, 8, ., .)
 18.1227 +{
 18.1228 +	uint src = OPER_I_8();
 18.1229 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.1230 +	uint dst = m68ki_read_8(ea);
 18.1231 +	uint res = src + dst;
 18.1232 +
 18.1233 +	FLAG_N = NFLAG_8(res);
 18.1234 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1235 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1236 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.1237 +
 18.1238 +	m68ki_write_8(ea, FLAG_Z);
 18.1239 +}
 18.1240 +
 18.1241 +
 18.1242 +M68KMAKE_OP(addi, 16, ., d)
 18.1243 +{
 18.1244 +	uint* r_dst = &DY;
 18.1245 +	uint src = OPER_I_16();
 18.1246 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.1247 +	uint res = src + dst;
 18.1248 +
 18.1249 +	FLAG_N = NFLAG_16(res);
 18.1250 +	FLAG_V = VFLAG_ADD_16(src, dst, res);
 18.1251 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.1252 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.1253 +
 18.1254 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.1255 +}
 18.1256 +
 18.1257 +
 18.1258 +M68KMAKE_OP(addi, 16, ., .)
 18.1259 +{
 18.1260 +	uint src = OPER_I_16();
 18.1261 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.1262 +	uint dst = m68ki_read_16(ea);
 18.1263 +	uint res = src + dst;
 18.1264 +
 18.1265 +	FLAG_N = NFLAG_16(res);
 18.1266 +	FLAG_V = VFLAG_ADD_16(src, dst, res);
 18.1267 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.1268 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.1269 +
 18.1270 +	m68ki_write_16(ea, FLAG_Z);
 18.1271 +}
 18.1272 +
 18.1273 +
 18.1274 +M68KMAKE_OP(addi, 32, ., d)
 18.1275 +{
 18.1276 +	uint* r_dst = &DY;
 18.1277 +	uint src = OPER_I_32();
 18.1278 +	uint dst = *r_dst;
 18.1279 +	uint res = src + dst;
 18.1280 +
 18.1281 +	FLAG_N = NFLAG_32(res);
 18.1282 +	FLAG_V = VFLAG_ADD_32(src, dst, res);
 18.1283 +	FLAG_X = FLAG_C = CFLAG_ADD_32(src, dst, res);
 18.1284 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.1285 +
 18.1286 +	*r_dst = FLAG_Z;
 18.1287 +}
 18.1288 +
 18.1289 +
 18.1290 +M68KMAKE_OP(addi, 32, ., .)
 18.1291 +{
 18.1292 +	uint src = OPER_I_32();
 18.1293 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.1294 +	uint dst = m68ki_read_32(ea);
 18.1295 +	uint res = src + dst;
 18.1296 +
 18.1297 +	FLAG_N = NFLAG_32(res);
 18.1298 +	FLAG_V = VFLAG_ADD_32(src, dst, res);
 18.1299 +	FLAG_X = FLAG_C = CFLAG_ADD_32(src, dst, res);
 18.1300 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.1301 +
 18.1302 +	m68ki_write_32(ea, FLAG_Z);
 18.1303 +}
 18.1304 +
 18.1305 +
 18.1306 +M68KMAKE_OP(addq, 8, ., d)
 18.1307 +{
 18.1308 +	uint* r_dst = &DY;
 18.1309 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.1310 +	uint dst = MASK_OUT_ABOVE_8(*r_dst);
 18.1311 +	uint res = src + dst;
 18.1312 +
 18.1313 +	FLAG_N = NFLAG_8(res);
 18.1314 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1315 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1316 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.1317 +
 18.1318 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | FLAG_Z;
 18.1319 +}
 18.1320 +
 18.1321 +
 18.1322 +M68KMAKE_OP(addq, 8, ., .)
 18.1323 +{
 18.1324 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.1325 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.1326 +	uint dst = m68ki_read_8(ea);
 18.1327 +	uint res = src + dst;
 18.1328 +
 18.1329 +	FLAG_N = NFLAG_8(res);
 18.1330 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1331 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1332 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.1333 +
 18.1334 +	m68ki_write_8(ea, FLAG_Z);
 18.1335 +}
 18.1336 +
 18.1337 +
 18.1338 +M68KMAKE_OP(addq, 16, ., d)
 18.1339 +{
 18.1340 +	uint* r_dst = &DY;
 18.1341 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.1342 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.1343 +	uint res = src + dst;
 18.1344 +
 18.1345 +	FLAG_N = NFLAG_16(res);
 18.1346 +	FLAG_V = VFLAG_ADD_16(src, dst, res);
 18.1347 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.1348 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.1349 +
 18.1350 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.1351 +}
 18.1352 +
 18.1353 +
 18.1354 +M68KMAKE_OP(addq, 16, ., a)
 18.1355 +{
 18.1356 +	uint* r_dst = &AY;
 18.1357 +
 18.1358 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst + (((REG_IR >> 9) - 1) & 7) + 1);
 18.1359 +}
 18.1360 +
 18.1361 +
 18.1362 +M68KMAKE_OP(addq, 16, ., .)
 18.1363 +{
 18.1364 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.1365 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.1366 +	uint dst = m68ki_read_16(ea);
 18.1367 +	uint res = src + dst;
 18.1368 +
 18.1369 +	FLAG_N = NFLAG_16(res);
 18.1370 +	FLAG_V = VFLAG_ADD_16(src, dst, res);
 18.1371 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.1372 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.1373 +
 18.1374 +	m68ki_write_16(ea, FLAG_Z);
 18.1375 +}
 18.1376 +
 18.1377 +
 18.1378 +M68KMAKE_OP(addq, 32, ., d)
 18.1379 +{
 18.1380 +	uint* r_dst = &DY;
 18.1381 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.1382 +	uint dst = *r_dst;
 18.1383 +	uint res = src + dst;
 18.1384 +
 18.1385 +	FLAG_N = NFLAG_32(res);
 18.1386 +	FLAG_V = VFLAG_ADD_32(src, dst, res);
 18.1387 +	FLAG_X = FLAG_C = CFLAG_ADD_32(src, dst, res);
 18.1388 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.1389 +
 18.1390 +	*r_dst = FLAG_Z;
 18.1391 +}
 18.1392 +
 18.1393 +
 18.1394 +M68KMAKE_OP(addq, 32, ., a)
 18.1395 +{
 18.1396 +	uint* r_dst = &AY;
 18.1397 +
 18.1398 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst + (((REG_IR >> 9) - 1) & 7) + 1);
 18.1399 +}
 18.1400 +
 18.1401 +
 18.1402 +M68KMAKE_OP(addq, 32, ., .)
 18.1403 +{
 18.1404 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.1405 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.1406 +	uint dst = m68ki_read_32(ea);
 18.1407 +	uint res = src + dst;
 18.1408 +
 18.1409 +
 18.1410 +	FLAG_N = NFLAG_32(res);
 18.1411 +	FLAG_V = VFLAG_ADD_32(src, dst, res);
 18.1412 +	FLAG_X = FLAG_C = CFLAG_ADD_32(src, dst, res);
 18.1413 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.1414 +
 18.1415 +	m68ki_write_32(ea, FLAG_Z);
 18.1416 +}
 18.1417 +
 18.1418 +
 18.1419 +M68KMAKE_OP(addx, 8, rr, .)
 18.1420 +{
 18.1421 +	uint* r_dst = &DX;
 18.1422 +	uint src = MASK_OUT_ABOVE_8(DY);
 18.1423 +	uint dst = MASK_OUT_ABOVE_8(*r_dst);
 18.1424 +	uint res = src + dst + XFLAG_AS_1();
 18.1425 +
 18.1426 +	FLAG_N = NFLAG_8(res);
 18.1427 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1428 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1429 +
 18.1430 +	res = MASK_OUT_ABOVE_8(res);
 18.1431 +	FLAG_Z |= res;
 18.1432 +
 18.1433 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.1434 +}
 18.1435 +
 18.1436 +
 18.1437 +M68KMAKE_OP(addx, 16, rr, .)
 18.1438 +{
 18.1439 +	uint* r_dst = &DX;
 18.1440 +	uint src = MASK_OUT_ABOVE_16(DY);
 18.1441 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.1442 +	uint res = src + dst + XFLAG_AS_1();
 18.1443 +
 18.1444 +	FLAG_N = NFLAG_16(res);
 18.1445 +	FLAG_V = VFLAG_ADD_16(src, dst, res);
 18.1446 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.1447 +
 18.1448 +	res = MASK_OUT_ABOVE_16(res);
 18.1449 +	FLAG_Z |= res;
 18.1450 +
 18.1451 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.1452 +}
 18.1453 +
 18.1454 +
 18.1455 +M68KMAKE_OP(addx, 32, rr, .)
 18.1456 +{
 18.1457 +	uint* r_dst = &DX;
 18.1458 +	uint src = DY;
 18.1459 +	uint dst = *r_dst;
 18.1460 +	uint res = src + dst + XFLAG_AS_1();
 18.1461 +
 18.1462 +	FLAG_N = NFLAG_32(res);
 18.1463 +	FLAG_V = VFLAG_ADD_32(src, dst, res);
 18.1464 +	FLAG_X = FLAG_C = CFLAG_ADD_32(src, dst, res);
 18.1465 +
 18.1466 +	res = MASK_OUT_ABOVE_32(res);
 18.1467 +	FLAG_Z |= res;
 18.1468 +
 18.1469 +	*r_dst = res;
 18.1470 +}
 18.1471 +
 18.1472 +
 18.1473 +M68KMAKE_OP(addx, 8, mm, ax7)
 18.1474 +{
 18.1475 +	uint src = OPER_AY_PD_8();
 18.1476 +	uint ea  = EA_A7_PD_8();
 18.1477 +	uint dst = m68ki_read_8(ea);
 18.1478 +	uint res = src + dst + XFLAG_AS_1();
 18.1479 +
 18.1480 +	FLAG_N = NFLAG_8(res);
 18.1481 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1482 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1483 +
 18.1484 +	res = MASK_OUT_ABOVE_8(res);
 18.1485 +	FLAG_Z |= res;
 18.1486 +
 18.1487 +	m68ki_write_8(ea, res);
 18.1488 +}
 18.1489 +
 18.1490 +
 18.1491 +M68KMAKE_OP(addx, 8, mm, ay7)
 18.1492 +{
 18.1493 +	uint src = OPER_A7_PD_8();
 18.1494 +	uint ea  = EA_AX_PD_8();
 18.1495 +	uint dst = m68ki_read_8(ea);
 18.1496 +	uint res = src + dst + XFLAG_AS_1();
 18.1497 +
 18.1498 +	FLAG_N = NFLAG_8(res);
 18.1499 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1500 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1501 +
 18.1502 +	res = MASK_OUT_ABOVE_8(res);
 18.1503 +	FLAG_Z |= res;
 18.1504 +
 18.1505 +	m68ki_write_8(ea, res);
 18.1506 +}
 18.1507 +
 18.1508 +
 18.1509 +M68KMAKE_OP(addx, 8, mm, axy7)
 18.1510 +{
 18.1511 +	uint src = OPER_A7_PD_8();
 18.1512 +	uint ea  = EA_A7_PD_8();
 18.1513 +	uint dst = m68ki_read_8(ea);
 18.1514 +	uint res = src + dst + XFLAG_AS_1();
 18.1515 +
 18.1516 +	FLAG_N = NFLAG_8(res);
 18.1517 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1518 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1519 +
 18.1520 +	res = MASK_OUT_ABOVE_8(res);
 18.1521 +	FLAG_Z |= res;
 18.1522 +
 18.1523 +	m68ki_write_8(ea, res);
 18.1524 +}
 18.1525 +
 18.1526 +
 18.1527 +M68KMAKE_OP(addx, 8, mm, .)
 18.1528 +{
 18.1529 +	uint src = OPER_AY_PD_8();
 18.1530 +	uint ea  = EA_AX_PD_8();
 18.1531 +	uint dst = m68ki_read_8(ea);
 18.1532 +	uint res = src + dst + XFLAG_AS_1();
 18.1533 +
 18.1534 +	FLAG_N = NFLAG_8(res);
 18.1535 +	FLAG_V = VFLAG_ADD_8(src, dst, res);
 18.1536 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.1537 +
 18.1538 +	res = MASK_OUT_ABOVE_8(res);
 18.1539 +	FLAG_Z |= res;
 18.1540 +
 18.1541 +	m68ki_write_8(ea, res);
 18.1542 +}
 18.1543 +
 18.1544 +
 18.1545 +M68KMAKE_OP(addx, 16, mm, .)
 18.1546 +{
 18.1547 +	uint src = OPER_AY_PD_16();
 18.1548 +	uint ea  = EA_AX_PD_16();
 18.1549 +	uint dst = m68ki_read_16(ea);
 18.1550 +	uint res = src + dst + XFLAG_AS_1();
 18.1551 +
 18.1552 +	FLAG_N = NFLAG_16(res);
 18.1553 +	FLAG_V = VFLAG_ADD_16(src, dst, res);
 18.1554 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.1555 +
 18.1556 +	res = MASK_OUT_ABOVE_16(res);
 18.1557 +	FLAG_Z |= res;
 18.1558 +
 18.1559 +	m68ki_write_16(ea, res);
 18.1560 +}
 18.1561 +
 18.1562 +
 18.1563 +M68KMAKE_OP(addx, 32, mm, .)
 18.1564 +{
 18.1565 +	uint src = OPER_AY_PD_32();
 18.1566 +	uint ea  = EA_AX_PD_32();
 18.1567 +	uint dst = m68ki_read_32(ea);
 18.1568 +	uint res = src + dst + XFLAG_AS_1();
 18.1569 +
 18.1570 +	FLAG_N = NFLAG_32(res);
 18.1571 +	FLAG_V = VFLAG_ADD_32(src, dst, res);
 18.1572 +	FLAG_X = FLAG_C = CFLAG_ADD_32(src, dst, res);
 18.1573 +
 18.1574 +	res = MASK_OUT_ABOVE_32(res);
 18.1575 +	FLAG_Z |= res;
 18.1576 +
 18.1577 +	m68ki_write_32(ea, res);
 18.1578 +}
 18.1579 +
 18.1580 +
 18.1581 +M68KMAKE_OP(and, 8, er, d)
 18.1582 +{
 18.1583 +	FLAG_Z = MASK_OUT_ABOVE_8(DX &= (DY | 0xffffff00));
 18.1584 +
 18.1585 +	FLAG_N = NFLAG_8(FLAG_Z);
 18.1586 +	FLAG_C = CFLAG_CLEAR;
 18.1587 +	FLAG_V = VFLAG_CLEAR;
 18.1588 +}
 18.1589 +
 18.1590 +
 18.1591 +M68KMAKE_OP(and, 8, er, .)
 18.1592 +{
 18.1593 +	FLAG_Z = MASK_OUT_ABOVE_8(DX &= (M68KMAKE_GET_OPER_AY_8 | 0xffffff00));
 18.1594 +
 18.1595 +	FLAG_N = NFLAG_8(FLAG_Z);
 18.1596 +	FLAG_C = CFLAG_CLEAR;
 18.1597 +	FLAG_V = VFLAG_CLEAR;
 18.1598 +}
 18.1599 +
 18.1600 +
 18.1601 +M68KMAKE_OP(and, 16, er, d)
 18.1602 +{
 18.1603 +	FLAG_Z = MASK_OUT_ABOVE_16(DX &= (DY | 0xffff0000));
 18.1604 +
 18.1605 +	FLAG_N = NFLAG_16(FLAG_Z);
 18.1606 +	FLAG_C = CFLAG_CLEAR;
 18.1607 +	FLAG_V = VFLAG_CLEAR;
 18.1608 +}
 18.1609 +
 18.1610 +
 18.1611 +M68KMAKE_OP(and, 16, er, .)
 18.1612 +{
 18.1613 +	FLAG_Z = MASK_OUT_ABOVE_16(DX &= (M68KMAKE_GET_OPER_AY_16 | 0xffff0000));
 18.1614 +
 18.1615 +	FLAG_N = NFLAG_16(FLAG_Z);
 18.1616 +	FLAG_C = CFLAG_CLEAR;
 18.1617 +	FLAG_V = VFLAG_CLEAR;
 18.1618 +}
 18.1619 +
 18.1620 +
 18.1621 +M68KMAKE_OP(and, 32, er, d)
 18.1622 +{
 18.1623 +	FLAG_Z = DX &= DY;
 18.1624 +
 18.1625 +	FLAG_N = NFLAG_32(FLAG_Z);
 18.1626 +	FLAG_C = CFLAG_CLEAR;
 18.1627 +	FLAG_V = VFLAG_CLEAR;
 18.1628 +}
 18.1629 +
 18.1630 +
 18.1631 +M68KMAKE_OP(and, 32, er, .)
 18.1632 +{
 18.1633 +	FLAG_Z = DX &= M68KMAKE_GET_OPER_AY_32;
 18.1634 +
 18.1635 +	FLAG_N = NFLAG_32(FLAG_Z);
 18.1636 +	FLAG_C = CFLAG_CLEAR;
 18.1637 +	FLAG_V = VFLAG_CLEAR;
 18.1638 +}
 18.1639 +
 18.1640 +
 18.1641 +M68KMAKE_OP(and, 8, re, .)
 18.1642 +{
 18.1643 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.1644 +	uint res = DX & m68ki_read_8(ea);
 18.1645 +
 18.1646 +	FLAG_N = NFLAG_8(res);
 18.1647 +	FLAG_C = CFLAG_CLEAR;
 18.1648 +	FLAG_V = VFLAG_CLEAR;
 18.1649 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.1650 +
 18.1651 +	m68ki_write_8(ea, FLAG_Z);
 18.1652 +}
 18.1653 +
 18.1654 +
 18.1655 +M68KMAKE_OP(and, 16, re, .)
 18.1656 +{
 18.1657 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.1658 +	uint res = DX & m68ki_read_16(ea);
 18.1659 +
 18.1660 +	FLAG_N = NFLAG_16(res);
 18.1661 +	FLAG_C = CFLAG_CLEAR;
 18.1662 +	FLAG_V = VFLAG_CLEAR;
 18.1663 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.1664 +
 18.1665 +	m68ki_write_16(ea, FLAG_Z);
 18.1666 +}
 18.1667 +
 18.1668 +
 18.1669 +M68KMAKE_OP(and, 32, re, .)
 18.1670 +{
 18.1671 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.1672 +	uint res = DX & m68ki_read_32(ea);
 18.1673 +
 18.1674 +	FLAG_N = NFLAG_32(res);
 18.1675 +	FLAG_Z = res;
 18.1676 +	FLAG_C = CFLAG_CLEAR;
 18.1677 +	FLAG_V = VFLAG_CLEAR;
 18.1678 +
 18.1679 +	m68ki_write_32(ea, res);
 18.1680 +}
 18.1681 +
 18.1682 +
 18.1683 +M68KMAKE_OP(andi, 8, ., d)
 18.1684 +{
 18.1685 +	FLAG_Z = MASK_OUT_ABOVE_8(DY &= (OPER_I_8() | 0xffffff00));
 18.1686 +
 18.1687 +	FLAG_N = NFLAG_8(FLAG_Z);
 18.1688 +	FLAG_C = CFLAG_CLEAR;
 18.1689 +	FLAG_V = VFLAG_CLEAR;
 18.1690 +}
 18.1691 +
 18.1692 +
 18.1693 +M68KMAKE_OP(andi, 8, ., .)
 18.1694 +{
 18.1695 +	uint src = OPER_I_8();
 18.1696 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.1697 +	uint res = src & m68ki_read_8(ea);
 18.1698 +
 18.1699 +	FLAG_N = NFLAG_8(res);
 18.1700 +	FLAG_Z = res;
 18.1701 +	FLAG_C = CFLAG_CLEAR;
 18.1702 +	FLAG_V = VFLAG_CLEAR;
 18.1703 +
 18.1704 +	m68ki_write_8(ea, res);
 18.1705 +}
 18.1706 +
 18.1707 +
 18.1708 +M68KMAKE_OP(andi, 16, ., d)
 18.1709 +{
 18.1710 +	FLAG_Z = MASK_OUT_ABOVE_16(DY &= (OPER_I_16() | 0xffff0000));
 18.1711 +
 18.1712 +	FLAG_N = NFLAG_16(FLAG_Z);
 18.1713 +	FLAG_C = CFLAG_CLEAR;
 18.1714 +	FLAG_V = VFLAG_CLEAR;
 18.1715 +}
 18.1716 +
 18.1717 +
 18.1718 +M68KMAKE_OP(andi, 16, ., .)
 18.1719 +{
 18.1720 +	uint src = OPER_I_16();
 18.1721 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.1722 +	uint res = src & m68ki_read_16(ea);
 18.1723 +
 18.1724 +	FLAG_N = NFLAG_16(res);
 18.1725 +	FLAG_Z = res;
 18.1726 +	FLAG_C = CFLAG_CLEAR;
 18.1727 +	FLAG_V = VFLAG_CLEAR;
 18.1728 +
 18.1729 +	m68ki_write_16(ea, res);
 18.1730 +}
 18.1731 +
 18.1732 +
 18.1733 +M68KMAKE_OP(andi, 32, ., d)
 18.1734 +{
 18.1735 +	FLAG_Z = DY &= (OPER_I_32());
 18.1736 +
 18.1737 +	FLAG_N = NFLAG_32(FLAG_Z);
 18.1738 +	FLAG_C = CFLAG_CLEAR;
 18.1739 +	FLAG_V = VFLAG_CLEAR;
 18.1740 +}
 18.1741 +
 18.1742 +
 18.1743 +M68KMAKE_OP(andi, 32, ., .)
 18.1744 +{
 18.1745 +	uint src = OPER_I_32();
 18.1746 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.1747 +	uint res = src & m68ki_read_32(ea);
 18.1748 +
 18.1749 +	FLAG_N = NFLAG_32(res);
 18.1750 +	FLAG_Z = res;
 18.1751 +	FLAG_C = CFLAG_CLEAR;
 18.1752 +	FLAG_V = VFLAG_CLEAR;
 18.1753 +
 18.1754 +	m68ki_write_32(ea, res);
 18.1755 +}
 18.1756 +
 18.1757 +
 18.1758 +M68KMAKE_OP(andi, 16, toc, .)
 18.1759 +{
 18.1760 +	m68ki_set_ccr(m68ki_get_ccr() & OPER_I_16());
 18.1761 +}
 18.1762 +
 18.1763 +
 18.1764 +M68KMAKE_OP(andi, 16, tos, .)
 18.1765 +{
 18.1766 +	if(FLAG_S)
 18.1767 +	{
 18.1768 +		uint src = OPER_I_16();
 18.1769 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.1770 +		m68ki_set_sr(m68ki_get_sr() & src);
 18.1771 +		return;
 18.1772 +	}
 18.1773 +	m68ki_exception_privilege_violation();
 18.1774 +}
 18.1775 +
 18.1776 +
 18.1777 +M68KMAKE_OP(asr, 8, s, .)
 18.1778 +{
 18.1779 +	uint* r_dst = &DY;
 18.1780 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.1781 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.1782 +	uint res = src >> shift;
 18.1783 +
 18.1784 +	if(GET_MSB_8(src))
 18.1785 +		res |= m68ki_shift_8_table[shift];
 18.1786 +
 18.1787 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.1788 +
 18.1789 +	FLAG_N = NFLAG_8(res);
 18.1790 +	FLAG_Z = res;
 18.1791 +	FLAG_V = VFLAG_CLEAR;
 18.1792 +	FLAG_X = FLAG_C = src << (9-shift);
 18.1793 +}
 18.1794 +
 18.1795 +
 18.1796 +M68KMAKE_OP(asr, 16, s, .)
 18.1797 +{
 18.1798 +	uint* r_dst = &DY;
 18.1799 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.1800 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.1801 +	uint res = src >> shift;
 18.1802 +
 18.1803 +	if(GET_MSB_16(src))
 18.1804 +		res |= m68ki_shift_16_table[shift];
 18.1805 +
 18.1806 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.1807 +
 18.1808 +	FLAG_N = NFLAG_16(res);
 18.1809 +	FLAG_Z = res;
 18.1810 +	FLAG_V = VFLAG_CLEAR;
 18.1811 +	FLAG_X = FLAG_C = src << (9-shift);
 18.1812 +}
 18.1813 +
 18.1814 +
 18.1815 +M68KMAKE_OP(asr, 32, s, .)
 18.1816 +{
 18.1817 +	uint* r_dst = &DY;
 18.1818 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.1819 +	uint src = *r_dst;
 18.1820 +	uint res = src >> shift;
 18.1821 +
 18.1822 +	if(GET_MSB_32(src))
 18.1823 +		res |= m68ki_shift_32_table[shift];
 18.1824 +
 18.1825 +	*r_dst = res;
 18.1826 +
 18.1827 +	FLAG_N = NFLAG_32(res);
 18.1828 +	FLAG_Z = res;
 18.1829 +	FLAG_V = VFLAG_CLEAR;
 18.1830 +	FLAG_X = FLAG_C = src << (9-shift);
 18.1831 +}
 18.1832 +
 18.1833 +
 18.1834 +M68KMAKE_OP(asr, 8, r, .)
 18.1835 +{
 18.1836 +	uint* r_dst = &DY;
 18.1837 +	uint shift = DX & 0x3f;
 18.1838 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.1839 +	uint res = src >> shift;
 18.1840 +
 18.1841 +	if(shift != 0)
 18.1842 +	{
 18.1843 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.1844 +
 18.1845 +		if(shift < 8)
 18.1846 +		{
 18.1847 +			if(GET_MSB_8(src))
 18.1848 +				res |= m68ki_shift_8_table[shift];
 18.1849 +
 18.1850 +			*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.1851 +
 18.1852 +			FLAG_X = FLAG_C = src << (9-shift);
 18.1853 +			FLAG_N = NFLAG_8(res);
 18.1854 +			FLAG_Z = res;
 18.1855 +			FLAG_V = VFLAG_CLEAR;
 18.1856 +			return;
 18.1857 +		}
 18.1858 +
 18.1859 +		if(GET_MSB_8(src))
 18.1860 +		{
 18.1861 +			*r_dst |= 0xff;
 18.1862 +			FLAG_C = CFLAG_SET;
 18.1863 +			FLAG_X = XFLAG_SET;
 18.1864 +			FLAG_N = NFLAG_SET;
 18.1865 +			FLAG_Z = ZFLAG_CLEAR;
 18.1866 +			FLAG_V = VFLAG_CLEAR;
 18.1867 +			return;
 18.1868 +		}
 18.1869 +
 18.1870 +		*r_dst &= 0xffffff00;
 18.1871 +		FLAG_C = CFLAG_CLEAR;
 18.1872 +		FLAG_X = XFLAG_CLEAR;
 18.1873 +		FLAG_N = NFLAG_CLEAR;
 18.1874 +		FLAG_Z = ZFLAG_SET;
 18.1875 +		FLAG_V = VFLAG_CLEAR;
 18.1876 +		return;
 18.1877 +	}
 18.1878 +
 18.1879 +	FLAG_C = CFLAG_CLEAR;
 18.1880 +	FLAG_N = NFLAG_8(src);
 18.1881 +	FLAG_Z = src;
 18.1882 +	FLAG_V = VFLAG_CLEAR;
 18.1883 +}
 18.1884 +
 18.1885 +
 18.1886 +M68KMAKE_OP(asr, 16, r, .)
 18.1887 +{
 18.1888 +	uint* r_dst = &DY;
 18.1889 +	uint shift = DX & 0x3f;
 18.1890 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.1891 +	uint res = src >> shift;
 18.1892 +
 18.1893 +	if(shift != 0)
 18.1894 +	{
 18.1895 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.1896 +
 18.1897 +		if(shift < 16)
 18.1898 +		{
 18.1899 +			if(GET_MSB_16(src))
 18.1900 +				res |= m68ki_shift_16_table[shift];
 18.1901 +
 18.1902 +			*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.1903 +
 18.1904 +			FLAG_C = FLAG_X = (src >> (shift - 1))<<8;
 18.1905 +			FLAG_N = NFLAG_16(res);
 18.1906 +			FLAG_Z = res;
 18.1907 +			FLAG_V = VFLAG_CLEAR;
 18.1908 +			return;
 18.1909 +		}
 18.1910 +
 18.1911 +		if(GET_MSB_16(src))
 18.1912 +		{
 18.1913 +			*r_dst |= 0xffff;
 18.1914 +			FLAG_C = CFLAG_SET;
 18.1915 +			FLAG_X = XFLAG_SET;
 18.1916 +			FLAG_N = NFLAG_SET;
 18.1917 +			FLAG_Z = ZFLAG_CLEAR;
 18.1918 +			FLAG_V = VFLAG_CLEAR;
 18.1919 +			return;
 18.1920 +		}
 18.1921 +
 18.1922 +		*r_dst &= 0xffff0000;
 18.1923 +		FLAG_C = CFLAG_CLEAR;
 18.1924 +		FLAG_X = XFLAG_CLEAR;
 18.1925 +		FLAG_N = NFLAG_CLEAR;
 18.1926 +		FLAG_Z = ZFLAG_SET;
 18.1927 +		FLAG_V = VFLAG_CLEAR;
 18.1928 +		return;
 18.1929 +	}
 18.1930 +
 18.1931 +	FLAG_C = CFLAG_CLEAR;
 18.1932 +	FLAG_N = NFLAG_16(src);
 18.1933 +	FLAG_Z = src;
 18.1934 +	FLAG_V = VFLAG_CLEAR;
 18.1935 +}
 18.1936 +
 18.1937 +
 18.1938 +M68KMAKE_OP(asr, 32, r, .)
 18.1939 +{
 18.1940 +	uint* r_dst = &DY;
 18.1941 +	uint shift = DX & 0x3f;
 18.1942 +	uint src = *r_dst;
 18.1943 +	uint res = src >> shift;
 18.1944 +
 18.1945 +	if(shift != 0)
 18.1946 +	{
 18.1947 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.1948 +
 18.1949 +		if(shift < 32)
 18.1950 +		{
 18.1951 +			if(GET_MSB_32(src))
 18.1952 +				res |= m68ki_shift_32_table[shift];
 18.1953 +
 18.1954 +			*r_dst = res;
 18.1955 +
 18.1956 +			FLAG_C = FLAG_X = (src >> (shift - 1))<<8;
 18.1957 +			FLAG_N = NFLAG_32(res);
 18.1958 +			FLAG_Z = res;
 18.1959 +			FLAG_V = VFLAG_CLEAR;
 18.1960 +			return;
 18.1961 +		}
 18.1962 +
 18.1963 +		if(GET_MSB_32(src))
 18.1964 +		{
 18.1965 +			*r_dst = 0xffffffff;
 18.1966 +			FLAG_C = CFLAG_SET;
 18.1967 +			FLAG_X = XFLAG_SET;
 18.1968 +			FLAG_N = NFLAG_SET;
 18.1969 +			FLAG_Z = ZFLAG_CLEAR;
 18.1970 +			FLAG_V = VFLAG_CLEAR;
 18.1971 +			return;
 18.1972 +		}
 18.1973 +
 18.1974 +		*r_dst = 0;
 18.1975 +		FLAG_C = CFLAG_CLEAR;
 18.1976 +		FLAG_X = XFLAG_CLEAR;
 18.1977 +		FLAG_N = NFLAG_CLEAR;
 18.1978 +		FLAG_Z = ZFLAG_SET;
 18.1979 +		FLAG_V = VFLAG_CLEAR;
 18.1980 +		return;
 18.1981 +	}
 18.1982 +
 18.1983 +	FLAG_C = CFLAG_CLEAR;
 18.1984 +	FLAG_N = NFLAG_32(src);
 18.1985 +	FLAG_Z = src;
 18.1986 +	FLAG_V = VFLAG_CLEAR;
 18.1987 +}
 18.1988 +
 18.1989 +
 18.1990 +M68KMAKE_OP(asr, 16, ., .)
 18.1991 +{
 18.1992 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.1993 +	uint src = m68ki_read_16(ea);
 18.1994 +	uint res = src >> 1;
 18.1995 +
 18.1996 +	if(GET_MSB_16(src))
 18.1997 +		res |= 0x8000;
 18.1998 +
 18.1999 +	m68ki_write_16(ea, res);
 18.2000 +
 18.2001 +	FLAG_N = NFLAG_16(res);
 18.2002 +	FLAG_Z = res;
 18.2003 +	FLAG_V = VFLAG_CLEAR;
 18.2004 +	FLAG_C = FLAG_X = src << 8;
 18.2005 +}
 18.2006 +
 18.2007 +
 18.2008 +M68KMAKE_OP(asl, 8, s, .)
 18.2009 +{
 18.2010 +	uint* r_dst = &DY;
 18.2011 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.2012 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.2013 +	uint res = MASK_OUT_ABOVE_8(src << shift);
 18.2014 +
 18.2015 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.2016 +
 18.2017 +	FLAG_X = FLAG_C = src << shift;
 18.2018 +	FLAG_N = NFLAG_8(res);
 18.2019 +	FLAG_Z = res;
 18.2020 +	src &= m68ki_shift_8_table[shift + 1];
 18.2021 +	FLAG_V = (!(src == 0 || (src == m68ki_shift_8_table[shift + 1] && shift < 8)))<<7;
 18.2022 +}
 18.2023 +
 18.2024 +
 18.2025 +M68KMAKE_OP(asl, 16, s, .)
 18.2026 +{
 18.2027 +	uint* r_dst = &DY;
 18.2028 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.2029 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.2030 +	uint res = MASK_OUT_ABOVE_16(src << shift);
 18.2031 +
 18.2032 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.2033 +
 18.2034 +	FLAG_N = NFLAG_16(res);
 18.2035 +	FLAG_Z = res;
 18.2036 +	FLAG_X = FLAG_C = src >> (8-shift);
 18.2037 +	src &= m68ki_shift_16_table[shift + 1];
 18.2038 +	FLAG_V = (!(src == 0 || src == m68ki_shift_16_table[shift + 1]))<<7;
 18.2039 +}
 18.2040 +
 18.2041 +
 18.2042 +M68KMAKE_OP(asl, 32, s, .)
 18.2043 +{
 18.2044 +	uint* r_dst = &DY;
 18.2045 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.2046 +	uint src = *r_dst;
 18.2047 +	uint res = MASK_OUT_ABOVE_32(src << shift);
 18.2048 +
 18.2049 +	*r_dst = res;
 18.2050 +
 18.2051 +	FLAG_N = NFLAG_32(res);
 18.2052 +	FLAG_Z = res;
 18.2053 +	FLAG_X = FLAG_C = src >> (24-shift);
 18.2054 +	src &= m68ki_shift_32_table[shift + 1];
 18.2055 +	FLAG_V = (!(src == 0 || src == m68ki_shift_32_table[shift + 1]))<<7;
 18.2056 +}
 18.2057 +
 18.2058 +
 18.2059 +M68KMAKE_OP(asl, 8, r, .)
 18.2060 +{
 18.2061 +	uint* r_dst = &DY;
 18.2062 +	uint shift = DX & 0x3f;
 18.2063 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.2064 +	uint res = MASK_OUT_ABOVE_8(src << shift);
 18.2065 +
 18.2066 +	if(shift != 0)
 18.2067 +	{
 18.2068 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.2069 +
 18.2070 +		if(shift < 8)
 18.2071 +		{
 18.2072 +			*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.2073 +			FLAG_X = FLAG_C = src << shift;
 18.2074 +			FLAG_N = NFLAG_8(res);
 18.2075 +			FLAG_Z = res;
 18.2076 +			src &= m68ki_shift_8_table[shift + 1];
 18.2077 +			FLAG_V = (!(src == 0 || src == m68ki_shift_8_table[shift + 1]))<<7;
 18.2078 +			return;
 18.2079 +		}
 18.2080 +
 18.2081 +		*r_dst &= 0xffffff00;
 18.2082 +		FLAG_X = FLAG_C = ((shift == 8 ? src & 1 : 0))<<8;
 18.2083 +		FLAG_N = NFLAG_CLEAR;
 18.2084 +		FLAG_Z = ZFLAG_SET;
 18.2085 +		FLAG_V = (!(src == 0))<<7;
 18.2086 +		return;
 18.2087 +	}
 18.2088 +
 18.2089 +	FLAG_C = CFLAG_CLEAR;
 18.2090 +	FLAG_N = NFLAG_8(src);
 18.2091 +	FLAG_Z = src;
 18.2092 +	FLAG_V = VFLAG_CLEAR;
 18.2093 +}
 18.2094 +
 18.2095 +
 18.2096 +M68KMAKE_OP(asl, 16, r, .)
 18.2097 +{
 18.2098 +	uint* r_dst = &DY;
 18.2099 +	uint shift = DX & 0x3f;
 18.2100 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.2101 +	uint res = MASK_OUT_ABOVE_16(src << shift);
 18.2102 +
 18.2103 +	if(shift != 0)
 18.2104 +	{
 18.2105 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.2106 +
 18.2107 +		if(shift < 16)
 18.2108 +		{
 18.2109 +			*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.2110 +			FLAG_X = FLAG_C = (src << shift) >> 8;
 18.2111 +			FLAG_N = NFLAG_16(res);
 18.2112 +			FLAG_Z = res;
 18.2113 +			src &= m68ki_shift_16_table[shift + 1];
 18.2114 +			FLAG_V = (!(src == 0 || src == m68ki_shift_16_table[shift + 1]))<<7;
 18.2115 +			return;
 18.2116 +		}
 18.2117 +
 18.2118 +		*r_dst &= 0xffff0000;
 18.2119 +		FLAG_X = FLAG_C = ((shift == 16 ? src & 1 : 0))<<8;
 18.2120 +		FLAG_N = NFLAG_CLEAR;
 18.2121 +		FLAG_Z = ZFLAG_SET;
 18.2122 +		FLAG_V = (!(src == 0))<<7;
 18.2123 +		return;
 18.2124 +	}
 18.2125 +
 18.2126 +	FLAG_C = CFLAG_CLEAR;
 18.2127 +	FLAG_N = NFLAG_16(src);
 18.2128 +	FLAG_Z = src;
 18.2129 +	FLAG_V = VFLAG_CLEAR;
 18.2130 +}
 18.2131 +
 18.2132 +
 18.2133 +M68KMAKE_OP(asl, 32, r, .)
 18.2134 +{
 18.2135 +	uint* r_dst = &DY;
 18.2136 +	uint shift = DX & 0x3f;
 18.2137 +	uint src = *r_dst;
 18.2138 +	uint res = MASK_OUT_ABOVE_32(src << shift);
 18.2139 +
 18.2140 +	if(shift != 0)
 18.2141 +	{
 18.2142 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.2143 +
 18.2144 +		if(shift < 32)
 18.2145 +		{
 18.2146 +			*r_dst = res;
 18.2147 +			FLAG_X = FLAG_C = (src >> (32 - shift)) << 8;
 18.2148 +			FLAG_N = NFLAG_32(res);
 18.2149 +			FLAG_Z = res;
 18.2150 +			src &= m68ki_shift_32_table[shift + 1];
 18.2151 +			FLAG_V = (!(src == 0 || src == m68ki_shift_32_table[shift + 1]))<<7;
 18.2152 +			return;
 18.2153 +		}
 18.2154 +
 18.2155 +		*r_dst = 0;
 18.2156 +		FLAG_X = FLAG_C = ((shift == 32 ? src & 1 : 0))<<8;
 18.2157 +		FLAG_N = NFLAG_CLEAR;
 18.2158 +		FLAG_Z = ZFLAG_SET;
 18.2159 +		FLAG_V = (!(src == 0))<<7;
 18.2160 +		return;
 18.2161 +	}
 18.2162 +
 18.2163 +	FLAG_C = CFLAG_CLEAR;
 18.2164 +	FLAG_N = NFLAG_32(src);
 18.2165 +	FLAG_Z = src;
 18.2166 +	FLAG_V = VFLAG_CLEAR;
 18.2167 +}
 18.2168 +
 18.2169 +
 18.2170 +M68KMAKE_OP(asl, 16, ., .)
 18.2171 +{
 18.2172 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.2173 +	uint src = m68ki_read_16(ea);
 18.2174 +	uint res = MASK_OUT_ABOVE_16(src << 1);
 18.2175 +
 18.2176 +	m68ki_write_16(ea, res);
 18.2177 +
 18.2178 +	FLAG_N = NFLAG_16(res);
 18.2179 +	FLAG_Z = res;
 18.2180 +	FLAG_X = FLAG_C = src >> 7;
 18.2181 +	src &= 0xc000;
 18.2182 +	FLAG_V = (!(src == 0 || src == 0xc000))<<7;
 18.2183 +}
 18.2184 +
 18.2185 +
 18.2186 +M68KMAKE_OP(bcc, 8, ., .)
 18.2187 +{
 18.2188 +	if(M68KMAKE_CC)
 18.2189 +	{
 18.2190 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.2191 +		m68ki_branch_8(MASK_OUT_ABOVE_8(REG_IR));
 18.2192 +		return;
 18.2193 +	}
 18.2194 +	USE_CYCLES(CYC_BCC_NOTAKE_B);
 18.2195 +}
 18.2196 +
 18.2197 +
 18.2198 +M68KMAKE_OP(bcc, 16, ., .)
 18.2199 +{
 18.2200 +	if(M68KMAKE_CC)
 18.2201 +	{
 18.2202 +		uint offset = OPER_I_16();
 18.2203 +		REG_PC -= 2;
 18.2204 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.2205 +		m68ki_branch_16(offset);
 18.2206 +		return;
 18.2207 +	}
 18.2208 +	REG_PC += 2;
 18.2209 +	USE_CYCLES(CYC_BCC_NOTAKE_W);
 18.2210 +}
 18.2211 +
 18.2212 +
 18.2213 +M68KMAKE_OP(bcc, 32, ., .)
 18.2214 +{
 18.2215 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2216 +	{
 18.2217 +		if(M68KMAKE_CC)
 18.2218 +		{
 18.2219 +			uint offset = OPER_I_32();
 18.2220 +			REG_PC -= 4;
 18.2221 +			m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.2222 +			m68ki_branch_32(offset);
 18.2223 +			return;
 18.2224 +		}
 18.2225 +		REG_PC += 4;
 18.2226 +		return;
 18.2227 +	}
 18.2228 +	m68ki_exception_illegal();
 18.2229 +}
 18.2230 +
 18.2231 +
 18.2232 +M68KMAKE_OP(bchg, 32, r, d)
 18.2233 +{
 18.2234 +	uint* r_dst = &DY;
 18.2235 +	uint mask = 1 << (DX & 0x1f);
 18.2236 +
 18.2237 +	FLAG_Z = *r_dst & mask;
 18.2238 +	*r_dst ^= mask;
 18.2239 +}
 18.2240 +
 18.2241 +
 18.2242 +M68KMAKE_OP(bchg, 8, r, .)
 18.2243 +{
 18.2244 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.2245 +	uint src = m68ki_read_8(ea);
 18.2246 +	uint mask = 1 << (DX & 7);
 18.2247 +
 18.2248 +	FLAG_Z = src & mask;
 18.2249 +	m68ki_write_8(ea, src ^ mask);
 18.2250 +}
 18.2251 +
 18.2252 +
 18.2253 +M68KMAKE_OP(bchg, 32, s, d)
 18.2254 +{
 18.2255 +	uint* r_dst = &DY;
 18.2256 +	uint mask = 1 << (OPER_I_8() & 0x1f);
 18.2257 +
 18.2258 +	FLAG_Z = *r_dst & mask;
 18.2259 +	*r_dst ^= mask;
 18.2260 +}
 18.2261 +
 18.2262 +
 18.2263 +M68KMAKE_OP(bchg, 8, s, .)
 18.2264 +{
 18.2265 +	uint mask = 1 << (OPER_I_8() & 7);
 18.2266 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.2267 +	uint src = m68ki_read_8(ea);
 18.2268 +
 18.2269 +	FLAG_Z = src & mask;
 18.2270 +	m68ki_write_8(ea, src ^ mask);
 18.2271 +}
 18.2272 +
 18.2273 +
 18.2274 +M68KMAKE_OP(bclr, 32, r, d)
 18.2275 +{
 18.2276 +	uint* r_dst = &DY;
 18.2277 +	uint mask = 1 << (DX & 0x1f);
 18.2278 +
 18.2279 +	FLAG_Z = *r_dst & mask;
 18.2280 +	*r_dst &= ~mask;
 18.2281 +}
 18.2282 +
 18.2283 +
 18.2284 +M68KMAKE_OP(bclr, 8, r, .)
 18.2285 +{
 18.2286 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.2287 +	uint src = m68ki_read_8(ea);
 18.2288 +	uint mask = 1 << (DX & 7);
 18.2289 +
 18.2290 +	FLAG_Z = src & mask;
 18.2291 +	m68ki_write_8(ea, src & ~mask);
 18.2292 +}
 18.2293 +
 18.2294 +
 18.2295 +M68KMAKE_OP(bclr, 32, s, d)
 18.2296 +{
 18.2297 +	uint* r_dst = &DY;
 18.2298 +	uint mask = 1 << (OPER_I_8() & 0x1f);
 18.2299 +
 18.2300 +	FLAG_Z = *r_dst & mask;
 18.2301 +	*r_dst &= ~mask;
 18.2302 +}
 18.2303 +
 18.2304 +
 18.2305 +M68KMAKE_OP(bclr, 8, s, .)
 18.2306 +{
 18.2307 +	uint mask = 1 << (OPER_I_8() & 7);
 18.2308 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.2309 +	uint src = m68ki_read_8(ea);
 18.2310 +
 18.2311 +	FLAG_Z = src & mask;
 18.2312 +	m68ki_write_8(ea, src & ~mask);
 18.2313 +}
 18.2314 +
 18.2315 +
 18.2316 +M68KMAKE_OP(bfchg, 32, ., d)
 18.2317 +{
 18.2318 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2319 +	{
 18.2320 +		uint word2 = OPER_I_16();
 18.2321 +		uint offset = (word2>>6)&31;
 18.2322 +		uint width = word2;
 18.2323 +		uint* data = &DY;
 18.2324 +		uint64 mask;
 18.2325 +
 18.2326 +
 18.2327 +		if(BIT_B(word2))
 18.2328 +			offset = REG_D[offset&7];
 18.2329 +		if(BIT_5(word2))
 18.2330 +			width = REG_D[width&7];
 18.2331 +
 18.2332 +		offset &= 31;
 18.2333 +		width = ((width-1) & 31) + 1;
 18.2334 +
 18.2335 +		mask = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
 18.2336 +		mask = ROR_32(mask, offset);
 18.2337 +
 18.2338 +		FLAG_N = NFLAG_32(*data<<offset);
 18.2339 +		FLAG_Z = *data & mask;
 18.2340 +		FLAG_V = VFLAG_CLEAR;
 18.2341 +		FLAG_C = CFLAG_CLEAR;
 18.2342 +
 18.2343 +		*data ^= mask;
 18.2344 +
 18.2345 +		return;
 18.2346 +	}
 18.2347 +	m68ki_exception_illegal();
 18.2348 +}
 18.2349 +
 18.2350 +
 18.2351 +M68KMAKE_OP(bfchg, 32, ., .)
 18.2352 +{
 18.2353 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2354 +	{
 18.2355 +		uint word2 = OPER_I_16();
 18.2356 +		sint offset = (word2>>6)&31;
 18.2357 +		uint width = word2;
 18.2358 +		uint mask_base;
 18.2359 +		uint data_long;
 18.2360 +		uint mask_long;
 18.2361 +		uint data_byte = 0;
 18.2362 +		uint mask_byte = 0;
 18.2363 +		uint ea = M68KMAKE_GET_EA_AY_8;
 18.2364 +
 18.2365 +
 18.2366 +		if(BIT_B(word2))
 18.2367 +			offset = MAKE_INT_32(REG_D[offset&7]);
 18.2368 +		if(BIT_5(word2))
 18.2369 +			width = REG_D[width&7];
 18.2370 +
 18.2371 +		/* Offset is signed so we have to use ugly math =( */
 18.2372 +		ea += offset / 8;
 18.2373 +		offset %= 8;
 18.2374 +		if(offset < 0)
 18.2375 +		{
 18.2376 +			offset += 8;
 18.2377 +			ea--;
 18.2378 +		}
 18.2379 +		width = ((width-1) & 31) + 1;
 18.2380 +
 18.2381 +		mask_base = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
 18.2382 +		mask_long = mask_base >> offset;
 18.2383 +
 18.2384 +		data_long = m68ki_read_32(ea);
 18.2385 +		FLAG_N = NFLAG_32(data_long << offset);
 18.2386 +		FLAG_Z = data_long & mask_long;
 18.2387 +		FLAG_V = VFLAG_CLEAR;
 18.2388 +		FLAG_C = CFLAG_CLEAR;
 18.2389 +
 18.2390 +		m68ki_write_32(ea, data_long ^ mask_long);
 18.2391 +
 18.2392 +		if((width + offset) > 32)
 18.2393 +		{
 18.2394 +			mask_byte = MASK_OUT_ABOVE_8(mask_base);
 18.2395 +			data_byte = m68ki_read_8(ea+4);
 18.2396 +			FLAG_Z |= (data_byte & mask_byte);
 18.2397 +			m68ki_write_8(ea+4, data_byte ^ mask_byte);
 18.2398 +		}
 18.2399 +		return;
 18.2400 +	}
 18.2401 +	m68ki_exception_illegal();
 18.2402 +}
 18.2403 +
 18.2404 +
 18.2405 +M68KMAKE_OP(bfclr, 32, ., d)
 18.2406 +{
 18.2407 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2408 +	{
 18.2409 +		uint word2 = OPER_I_16();
 18.2410 +		uint offset = (word2>>6)&31;
 18.2411 +		uint width = word2;
 18.2412 +		uint* data = &DY;
 18.2413 +		uint64 mask;
 18.2414 +
 18.2415 +
 18.2416 +		if(BIT_B(word2))
 18.2417 +			offset = REG_D[offset&7];
 18.2418 +		if(BIT_5(word2))
 18.2419 +			width = REG_D[width&7];
 18.2420 +
 18.2421 +
 18.2422 +		offset &= 31;
 18.2423 +		width = ((width-1) & 31) + 1;
 18.2424 +
 18.2425 +
 18.2426 +		mask = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
 18.2427 +		mask = ROR_32(mask, offset);
 18.2428 +
 18.2429 +		FLAG_N = NFLAG_32(*data<<offset);
 18.2430 +		FLAG_Z = *data & mask;
 18.2431 +		FLAG_V = VFLAG_CLEAR;
 18.2432 +		FLAG_C = CFLAG_CLEAR;
 18.2433 +
 18.2434 +		*data &= ~mask;
 18.2435 +
 18.2436 +		return;
 18.2437 +	}
 18.2438 +	m68ki_exception_illegal();
 18.2439 +}
 18.2440 +
 18.2441 +
 18.2442 +M68KMAKE_OP(bfclr, 32, ., .)
 18.2443 +{
 18.2444 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2445 +	{
 18.2446 +		uint word2 = OPER_I_16();
 18.2447 +		sint offset = (word2>>6)&31;
 18.2448 +		uint width = word2;
 18.2449 +		uint mask_base;
 18.2450 +		uint data_long;
 18.2451 +		uint mask_long;
 18.2452 +		uint data_byte = 0;
 18.2453 +		uint mask_byte = 0;
 18.2454 +		uint ea = M68KMAKE_GET_EA_AY_8;
 18.2455 +
 18.2456 +
 18.2457 +		if(BIT_B(word2))
 18.2458 +			offset = MAKE_INT_32(REG_D[offset&7]);
 18.2459 +		if(BIT_5(word2))
 18.2460 +			width = REG_D[width&7];
 18.2461 +
 18.2462 +		/* Offset is signed so we have to use ugly math =( */
 18.2463 +		ea += offset / 8;
 18.2464 +		offset %= 8;
 18.2465 +		if(offset < 0)
 18.2466 +		{
 18.2467 +			offset += 8;
 18.2468 +			ea--;
 18.2469 +		}
 18.2470 +		width = ((width-1) & 31) + 1;
 18.2471 +
 18.2472 +		mask_base = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
 18.2473 +		mask_long = mask_base >> offset;
 18.2474 +
 18.2475 +		data_long = m68ki_read_32(ea);
 18.2476 +		FLAG_N = NFLAG_32(data_long << offset);
 18.2477 +		FLAG_Z = data_long & mask_long;
 18.2478 +		FLAG_V = VFLAG_CLEAR;
 18.2479 +		FLAG_C = CFLAG_CLEAR;
 18.2480 +
 18.2481 +		m68ki_write_32(ea, data_long & ~mask_long);
 18.2482 +
 18.2483 +		if((width + offset) > 32)
 18.2484 +		{
 18.2485 +			mask_byte = MASK_OUT_ABOVE_8(mask_base);
 18.2486 +			data_byte = m68ki_read_8(ea+4);
 18.2487 +			FLAG_Z |= (data_byte & mask_byte);
 18.2488 +			m68ki_write_8(ea+4, data_byte & ~mask_byte);
 18.2489 +		}
 18.2490 +		return;
 18.2491 +	}
 18.2492 +	m68ki_exception_illegal();
 18.2493 +}
 18.2494 +
 18.2495 +
 18.2496 +M68KMAKE_OP(bfexts, 32, ., d)
 18.2497 +{
 18.2498 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2499 +	{
 18.2500 +		uint word2 = OPER_I_16();
 18.2501 +		uint offset = (word2>>6)&31;
 18.2502 +		uint width = word2;
 18.2503 +		uint64 data = DY;
 18.2504 +
 18.2505 +
 18.2506 +		if(BIT_B(word2))
 18.2507 +			offset = REG_D[offset&7];
 18.2508 +		if(BIT_5(word2))
 18.2509 +			width = REG_D[width&7];
 18.2510 +
 18.2511 +		offset &= 31;
 18.2512 +		width = ((width-1) & 31) + 1;
 18.2513 +
 18.2514 +		data = ROL_32(data, offset);
 18.2515 +		FLAG_N = NFLAG_32(data);
 18.2516 +		data = MAKE_INT_32(data) >> (32 - width);
 18.2517 +
 18.2518 +		FLAG_Z = data;
 18.2519 +		FLAG_V = VFLAG_CLEAR;
 18.2520 +		FLAG_C = CFLAG_CLEAR;
 18.2521 +
 18.2522 +		REG_D[(word2>>12)&7] = data;
 18.2523 +
 18.2524 +		return;
 18.2525 +	}
 18.2526 +	m68ki_exception_illegal();
 18.2527 +}
 18.2528 +
 18.2529 +
 18.2530 +M68KMAKE_OP(bfexts, 32, ., .)
 18.2531 +{
 18.2532 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2533 +	{
 18.2534 +		uint word2 = OPER_I_16();
 18.2535 +		sint offset = (word2>>6)&31;
 18.2536 +		uint width = word2;
 18.2537 +		uint data;
 18.2538 +		uint ea = M68KMAKE_GET_EA_AY_8;
 18.2539 +
 18.2540 +
 18.2541 +		if(BIT_B(word2))
 18.2542 +			offset = MAKE_INT_32(REG_D[offset&7]);
 18.2543 +		if(BIT_5(word2))
 18.2544 +			width = REG_D[width&7];
 18.2545 +
 18.2546 +		/* Offset is signed so we have to use ugly math =( */
 18.2547 +		ea += offset / 8;
 18.2548 +		offset %= 8;
 18.2549 +		if(offset < 0)
 18.2550 +		{
 18.2551 +			offset += 8;
 18.2552 +			ea--;
 18.2553 +		}
 18.2554 +		width = ((width-1) & 31) + 1;
 18.2555 +
 18.2556 +		data = m68ki_read_32(ea);
 18.2557 +
 18.2558 +		data = MASK_OUT_ABOVE_32(data<<offset);
 18.2559 +
 18.2560 +		if((offset+width) > 32)
 18.2561 +			data |= (m68ki_read_8(ea+4) << offset) >> 8;
 18.2562 +
 18.2563 +		FLAG_N = NFLAG_32(data);
 18.2564 +		data  = MAKE_INT_32(data) >> (32 - width);
 18.2565 +
 18.2566 +		FLAG_Z = data;
 18.2567 +		FLAG_V = VFLAG_CLEAR;
 18.2568 +		FLAG_C = CFLAG_CLEAR;
 18.2569 +
 18.2570 +		REG_D[(word2 >> 12) & 7] = data;
 18.2571 +
 18.2572 +		return;
 18.2573 +	}
 18.2574 +	m68ki_exception_illegal();
 18.2575 +}
 18.2576 +
 18.2577 +
 18.2578 +M68KMAKE_OP(bfextu, 32, ., d)
 18.2579 +{
 18.2580 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2581 +	{
 18.2582 +		uint word2 = OPER_I_16();
 18.2583 +		uint offset = (word2>>6)&31;
 18.2584 +		uint width = word2;
 18.2585 +		uint64 data = DY;
 18.2586 +
 18.2587 +
 18.2588 +		if(BIT_B(word2))
 18.2589 +			offset = REG_D[offset&7];
 18.2590 +		if(BIT_5(word2))
 18.2591 +			width = REG_D[width&7];
 18.2592 +
 18.2593 +		offset &= 31;
 18.2594 +		width = ((width-1) & 31) + 1;
 18.2595 +
 18.2596 +		data = ROL_32(data, offset);
 18.2597 +		FLAG_N = NFLAG_32(data);
 18.2598 +		data >>= 32 - width;
 18.2599 +
 18.2600 +		FLAG_Z = data;
 18.2601 +		FLAG_V = VFLAG_CLEAR;
 18.2602 +		FLAG_C = CFLAG_CLEAR;
 18.2603 +
 18.2604 +		REG_D[(word2>>12)&7] = data;
 18.2605 +
 18.2606 +		return;
 18.2607 +	}
 18.2608 +	m68ki_exception_illegal();
 18.2609 +}
 18.2610 +
 18.2611 +
 18.2612 +M68KMAKE_OP(bfextu, 32, ., .)
 18.2613 +{
 18.2614 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2615 +	{
 18.2616 +		uint word2 = OPER_I_16();
 18.2617 +		sint offset = (word2>>6)&31;
 18.2618 +		uint width = word2;
 18.2619 +		uint data;
 18.2620 +		uint ea = M68KMAKE_GET_EA_AY_8;
 18.2621 +
 18.2622 +
 18.2623 +		if(BIT_B(word2))
 18.2624 +		offset = MAKE_INT_32(REG_D[offset&7]);
 18.2625 +		if(BIT_5(word2))
 18.2626 +			width = REG_D[width&7];
 18.2627 +
 18.2628 +		/* Offset is signed so we have to use ugly math =( */
 18.2629 +		ea += offset / 8;
 18.2630 +		offset %= 8;
 18.2631 +		if(offset < 0)
 18.2632 +		{
 18.2633 +			offset += 8;
 18.2634 +			ea--;
 18.2635 +		}
 18.2636 +		width = ((width-1) & 31) + 1;
 18.2637 +
 18.2638 +		data = m68ki_read_32(ea);
 18.2639 +		data = MASK_OUT_ABOVE_32(data<<offset);
 18.2640 +
 18.2641 +		if((offset+width) > 32)
 18.2642 +			data |= (m68ki_read_8(ea+4) << offset) >> 8;
 18.2643 +
 18.2644 +		FLAG_N = NFLAG_32(data);
 18.2645 +		data  >>= (32 - width);
 18.2646 +
 18.2647 +		FLAG_Z = data;
 18.2648 +		FLAG_V = VFLAG_CLEAR;
 18.2649 +		FLAG_C = CFLAG_CLEAR;
 18.2650 +
 18.2651 +		REG_D[(word2 >> 12) & 7] = data;
 18.2652 +
 18.2653 +		return;
 18.2654 +	}
 18.2655 +	m68ki_exception_illegal();
 18.2656 +}
 18.2657 +
 18.2658 +
 18.2659 +M68KMAKE_OP(bfffo, 32, ., d)
 18.2660 +{
 18.2661 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2662 +	{
 18.2663 +		uint word2 = OPER_I_16();
 18.2664 +		uint offset = (word2>>6)&31;
 18.2665 +		uint width = word2;
 18.2666 +		uint64 data = DY;
 18.2667 +		uint bit;
 18.2668 +
 18.2669 +
 18.2670 +		if(BIT_B(word2))
 18.2671 +			offset = REG_D[offset&7];
 18.2672 +		if(BIT_5(word2))
 18.2673 +			width = REG_D[width&7];
 18.2674 +
 18.2675 +		offset &= 31;
 18.2676 +		width = ((width-1) & 31) + 1;
 18.2677 +
 18.2678 +		data = ROL_32(data, offset);
 18.2679 +		FLAG_N = NFLAG_32(data);
 18.2680 +		data >>= 32 - width;
 18.2681 +
 18.2682 +		FLAG_Z = data;
 18.2683 +		FLAG_V = VFLAG_CLEAR;
 18.2684 +		FLAG_C = CFLAG_CLEAR;
 18.2685 +
 18.2686 +		for(bit = 1<<(width-1);bit && !(data & bit);bit>>= 1)
 18.2687 +			offset++;
 18.2688 +
 18.2689 +		REG_D[(word2>>12)&7] = offset;
 18.2690 +
 18.2691 +		return;
 18.2692 +	}
 18.2693 +	m68ki_exception_illegal();
 18.2694 +}
 18.2695 +
 18.2696 +
 18.2697 +M68KMAKE_OP(bfffo, 32, ., .)
 18.2698 +{
 18.2699 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2700 +	{
 18.2701 +		uint word2 = OPER_I_16();
 18.2702 +		sint offset = (word2>>6)&31;
 18.2703 +		sint local_offset;
 18.2704 +		uint width = word2;
 18.2705 +		uint data;
 18.2706 +		uint bit;
 18.2707 +		uint ea = M68KMAKE_GET_EA_AY_8;
 18.2708 +
 18.2709 +
 18.2710 +		if(BIT_B(word2))
 18.2711 +			offset = MAKE_INT_32(REG_D[offset&7]);
 18.2712 +		if(BIT_5(word2))
 18.2713 +			width = REG_D[width&7];
 18.2714 +
 18.2715 +		/* Offset is signed so we have to use ugly math =( */
 18.2716 +		ea += offset / 8;
 18.2717 +		local_offset = offset % 8;
 18.2718 +		if(local_offset < 0)
 18.2719 +		{
 18.2720 +			local_offset += 8;
 18.2721 +			ea--;
 18.2722 +		}
 18.2723 +		width = ((width-1) & 31) + 1;
 18.2724 +
 18.2725 +		data = m68ki_read_32(ea);
 18.2726 +		data = MASK_OUT_ABOVE_32(data<<local_offset);
 18.2727 +
 18.2728 +		if((local_offset+width) > 32)
 18.2729 +			data |= (m68ki_read_8(ea+4) << local_offset) >> 8;
 18.2730 +
 18.2731 +		FLAG_N = NFLAG_32(data);
 18.2732 +		data  >>= (32 - width);
 18.2733 +
 18.2734 +		FLAG_Z = data;
 18.2735 +		FLAG_V = VFLAG_CLEAR;
 18.2736 +		FLAG_C = CFLAG_CLEAR;
 18.2737 +
 18.2738 +		for(bit = 1<<(width-1);bit && !(data & bit);bit>>= 1)
 18.2739 +			offset++;
 18.2740 +
 18.2741 +		REG_D[(word2>>12)&7] = offset;
 18.2742 +
 18.2743 +		return;
 18.2744 +	}
 18.2745 +	m68ki_exception_illegal();
 18.2746 +}
 18.2747 +
 18.2748 +
 18.2749 +M68KMAKE_OP(bfins, 32, ., d)
 18.2750 +{
 18.2751 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2752 +	{
 18.2753 +		uint word2 = OPER_I_16();
 18.2754 +		uint offset = (word2>>6)&31;
 18.2755 +		uint width = word2;
 18.2756 +		uint* data = &DY;
 18.2757 +		uint64 mask;
 18.2758 +		uint64 insert = REG_D[(word2>>12)&7];
 18.2759 +
 18.2760 +
 18.2761 +		if(BIT_B(word2))
 18.2762 +			offset = REG_D[offset&7];
 18.2763 +		if(BIT_5(word2))
 18.2764 +			width = REG_D[width&7];
 18.2765 +
 18.2766 +
 18.2767 +		offset &= 31;
 18.2768 +		width = ((width-1) & 31) + 1;
 18.2769 +
 18.2770 +
 18.2771 +		mask = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
 18.2772 +		mask = ROR_32(mask, offset);
 18.2773 +
 18.2774 +		insert = MASK_OUT_ABOVE_32(insert << (32 - width));
 18.2775 +		FLAG_N = NFLAG_32(insert);
 18.2776 +		FLAG_Z = insert;
 18.2777 +		insert = ROR_32(insert, offset);
 18.2778 +
 18.2779 +		FLAG_V = VFLAG_CLEAR;
 18.2780 +		FLAG_C = CFLAG_CLEAR;
 18.2781 +
 18.2782 +		*data &= ~mask;
 18.2783 +		*data |= insert;
 18.2784 +
 18.2785 +		return;
 18.2786 +	}
 18.2787 +	m68ki_exception_illegal();
 18.2788 +}
 18.2789 +
 18.2790 +
 18.2791 +M68KMAKE_OP(bfins, 32, ., .)
 18.2792 +{
 18.2793 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2794 +	{
 18.2795 +		uint word2 = OPER_I_16();
 18.2796 +		sint offset = (word2>>6)&31;
 18.2797 +		uint width = word2;
 18.2798 +		uint insert_base = REG_D[(word2>>12)&7];
 18.2799 +		uint insert_long;
 18.2800 +		uint insert_byte;
 18.2801 +		uint mask_base;
 18.2802 +		uint data_long;
 18.2803 +		uint mask_long;
 18.2804 +		uint data_byte = 0;
 18.2805 +		uint mask_byte = 0;
 18.2806 +		uint ea = M68KMAKE_GET_EA_AY_8;
 18.2807 +
 18.2808 +
 18.2809 +		if(BIT_B(word2))
 18.2810 +			offset = MAKE_INT_32(REG_D[offset&7]);
 18.2811 +		if(BIT_5(word2))
 18.2812 +			width = REG_D[width&7];
 18.2813 +
 18.2814 +		/* Offset is signed so we have to use ugly math =( */
 18.2815 +		ea += offset / 8;
 18.2816 +		offset %= 8;
 18.2817 +		if(offset < 0)
 18.2818 +		{
 18.2819 +			offset += 8;
 18.2820 +			ea--;
 18.2821 +		}
 18.2822 +		width = ((width-1) & 31) + 1;
 18.2823 +
 18.2824 +		mask_base = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
 18.2825 +		mask_long = mask_base >> offset;
 18.2826 +
 18.2827 +		insert_base = MASK_OUT_ABOVE_32(insert_base << (32 - width));
 18.2828 +		FLAG_N = NFLAG_32(insert_base);
 18.2829 +		FLAG_Z = insert_base;
 18.2830 +		insert_long = insert_base >> offset;
 18.2831 +
 18.2832 +		data_long = m68ki_read_32(ea);
 18.2833 +		FLAG_V = VFLAG_CLEAR;
 18.2834 +		FLAG_C = CFLAG_CLEAR;
 18.2835 +
 18.2836 +		m68ki_write_32(ea, (data_long & ~mask_long) | insert_long);
 18.2837 +
 18.2838 +		if((width + offset) > 32)
 18.2839 +		{
 18.2840 +			mask_byte = MASK_OUT_ABOVE_8(mask_base);
 18.2841 +			insert_byte = MASK_OUT_ABOVE_8(insert_base);
 18.2842 +			data_byte = m68ki_read_8(ea+4);
 18.2843 +			FLAG_Z |= (data_byte & mask_byte);
 18.2844 +			m68ki_write_8(ea+4, (data_byte & ~mask_byte) | insert_byte);
 18.2845 +		}
 18.2846 +		return;
 18.2847 +	}
 18.2848 +	m68ki_exception_illegal();
 18.2849 +}
 18.2850 +
 18.2851 +
 18.2852 +M68KMAKE_OP(bfset, 32, ., d)
 18.2853 +{
 18.2854 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2855 +	{
 18.2856 +		uint word2 = OPER_I_16();
 18.2857 +		uint offset = (word2>>6)&31;
 18.2858 +		uint width = word2;
 18.2859 +		uint* data = &DY;
 18.2860 +		uint64 mask;
 18.2861 +
 18.2862 +
 18.2863 +		if(BIT_B(word2))
 18.2864 +			offset = REG_D[offset&7];
 18.2865 +		if(BIT_5(word2))
 18.2866 +			width = REG_D[width&7];
 18.2867 +
 18.2868 +
 18.2869 +		offset &= 31;
 18.2870 +		width = ((width-1) & 31) + 1;
 18.2871 +
 18.2872 +
 18.2873 +		mask = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
 18.2874 +		mask = ROR_32(mask, offset);
 18.2875 +
 18.2876 +		FLAG_N = NFLAG_32(*data<<offset);
 18.2877 +		FLAG_Z = *data & mask;
 18.2878 +		FLAG_V = VFLAG_CLEAR;
 18.2879 +		FLAG_C = CFLAG_CLEAR;
 18.2880 +
 18.2881 +		*data |= mask;
 18.2882 +
 18.2883 +		return;
 18.2884 +	}
 18.2885 +	m68ki_exception_illegal();
 18.2886 +}
 18.2887 +
 18.2888 +
 18.2889 +M68KMAKE_OP(bfset, 32, ., .)
 18.2890 +{
 18.2891 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2892 +	{
 18.2893 +		uint word2 = OPER_I_16();
 18.2894 +		sint offset = (word2>>6)&31;
 18.2895 +		uint width = word2;
 18.2896 +		uint mask_base;
 18.2897 +		uint data_long;
 18.2898 +		uint mask_long;
 18.2899 +		uint data_byte = 0;
 18.2900 +		uint mask_byte = 0;
 18.2901 +		uint ea = M68KMAKE_GET_EA_AY_8;
 18.2902 +
 18.2903 +
 18.2904 +		if(BIT_B(word2))
 18.2905 +			offset = MAKE_INT_32(REG_D[offset&7]);
 18.2906 +		if(BIT_5(word2))
 18.2907 +			width = REG_D[width&7];
 18.2908 +
 18.2909 +		/* Offset is signed so we have to use ugly math =( */
 18.2910 +		ea += offset / 8;
 18.2911 +		offset %= 8;
 18.2912 +		if(offset < 0)
 18.2913 +		{
 18.2914 +			offset += 8;
 18.2915 +			ea--;
 18.2916 +		}
 18.2917 +		width = ((width-1) & 31) + 1;
 18.2918 +
 18.2919 +
 18.2920 +		mask_base = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
 18.2921 +		mask_long = mask_base >> offset;
 18.2922 +
 18.2923 +		data_long = m68ki_read_32(ea);
 18.2924 +		FLAG_N = NFLAG_32(data_long << offset);
 18.2925 +		FLAG_Z = data_long & mask_long;
 18.2926 +		FLAG_V = VFLAG_CLEAR;
 18.2927 +		FLAG_C = CFLAG_CLEAR;
 18.2928 +
 18.2929 +		m68ki_write_32(ea, data_long | mask_long);
 18.2930 +
 18.2931 +		if((width + offset) > 32)
 18.2932 +		{
 18.2933 +			mask_byte = MASK_OUT_ABOVE_8(mask_base);
 18.2934 +			data_byte = m68ki_read_8(ea+4);
 18.2935 +			FLAG_Z |= (data_byte & mask_byte);
 18.2936 +			m68ki_write_8(ea+4, data_byte | mask_byte);
 18.2937 +		}
 18.2938 +		return;
 18.2939 +	}
 18.2940 +	m68ki_exception_illegal();
 18.2941 +}
 18.2942 +
 18.2943 +
 18.2944 +M68KMAKE_OP(bftst, 32, ., d)
 18.2945 +{
 18.2946 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2947 +	{
 18.2948 +		uint word2 = OPER_I_16();
 18.2949 +		uint offset = (word2>>6)&31;
 18.2950 +		uint width = word2;
 18.2951 +		uint* data = &DY;
 18.2952 +		uint64 mask;
 18.2953 +
 18.2954 +
 18.2955 +		if(BIT_B(word2))
 18.2956 +			offset = REG_D[offset&7];
 18.2957 +		if(BIT_5(word2))
 18.2958 +			width = REG_D[width&7];
 18.2959 +
 18.2960 +
 18.2961 +		offset &= 31;
 18.2962 +		width = ((width-1) & 31) + 1;
 18.2963 +
 18.2964 +
 18.2965 +		mask = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
 18.2966 +		mask = ROR_32(mask, offset);
 18.2967 +
 18.2968 +		FLAG_N = NFLAG_32(*data<<offset);
 18.2969 +		FLAG_Z = *data & mask;
 18.2970 +		FLAG_V = VFLAG_CLEAR;
 18.2971 +		FLAG_C = CFLAG_CLEAR;
 18.2972 +
 18.2973 +		return;
 18.2974 +	}
 18.2975 +	m68ki_exception_illegal();
 18.2976 +}
 18.2977 +
 18.2978 +
 18.2979 +M68KMAKE_OP(bftst, 32, ., .)
 18.2980 +{
 18.2981 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.2982 +	{
 18.2983 +		uint word2 = OPER_I_16();
 18.2984 +		sint offset = (word2>>6)&31;
 18.2985 +		uint width = word2;
 18.2986 +		uint mask_base;
 18.2987 +		uint data_long;
 18.2988 +		uint mask_long;
 18.2989 +		uint data_byte = 0;
 18.2990 +		uint mask_byte = 0;
 18.2991 +		uint ea = M68KMAKE_GET_EA_AY_8;
 18.2992 +
 18.2993 +		if(BIT_B(word2))
 18.2994 +			offset = MAKE_INT_32(REG_D[offset&7]);
 18.2995 +		if(BIT_5(word2))
 18.2996 +			width = REG_D[width&7];
 18.2997 +
 18.2998 +		/* Offset is signed so we have to use ugly math =( */
 18.2999 +		ea += offset / 8;
 18.3000 +		offset %= 8;
 18.3001 +		if(offset < 0)
 18.3002 +		{
 18.3003 +			offset += 8;
 18.3004 +			ea--;
 18.3005 +		}
 18.3006 +		width = ((width-1) & 31) + 1;
 18.3007 +
 18.3008 +
 18.3009 +		mask_base = MASK_OUT_ABOVE_32(0xffffffff << (32 - width));
 18.3010 +		mask_long = mask_base >> offset;
 18.3011 +
 18.3012 +		data_long = m68ki_read_32(ea);
 18.3013 +		FLAG_N = ((data_long & (0x80000000 >> offset))<<offset)>>24;
 18.3014 +		FLAG_Z = data_long & mask_long;
 18.3015 +		FLAG_V = VFLAG_CLEAR;
 18.3016 +		FLAG_C = CFLAG_CLEAR;
 18.3017 +
 18.3018 +		if((width + offset) > 32)
 18.3019 +		{
 18.3020 +			mask_byte = MASK_OUT_ABOVE_8(mask_base);
 18.3021 +			data_byte = m68ki_read_8(ea+4);
 18.3022 +			FLAG_Z |= (data_byte & mask_byte);
 18.3023 +		}
 18.3024 +		return;
 18.3025 +	}
 18.3026 +	m68ki_exception_illegal();
 18.3027 +}
 18.3028 +
 18.3029 +
 18.3030 +M68KMAKE_OP(bkpt, 0, ., .)
 18.3031 +{
 18.3032 +	if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
 18.3033 +	{
 18.3034 +		m68ki_bkpt_ack(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE) ? REG_IR & 7 : 0);	/* auto-disable (see m68kcpu.h) */
 18.3035 +	}
 18.3036 +	m68ki_exception_illegal();
 18.3037 +}
 18.3038 +
 18.3039 +
 18.3040 +M68KMAKE_OP(bra, 8, ., .)
 18.3041 +{
 18.3042 +	m68ki_trace_t0();				   /* auto-disable (see m68kcpu.h) */
 18.3043 +	m68ki_branch_8(MASK_OUT_ABOVE_8(REG_IR));
 18.3044 +	if(REG_PC == REG_PPC)
 18.3045 +		USE_ALL_CYCLES();
 18.3046 +}
 18.3047 +
 18.3048 +
 18.3049 +M68KMAKE_OP(bra, 16, ., .)
 18.3050 +{
 18.3051 +	uint offset = OPER_I_16();
 18.3052 +	REG_PC -= 2;
 18.3053 +	m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.3054 +	m68ki_branch_16(offset);
 18.3055 +	if(REG_PC == REG_PPC)
 18.3056 +		USE_ALL_CYCLES();
 18.3057 +}
 18.3058 +
 18.3059 +
 18.3060 +M68KMAKE_OP(bra, 32, ., .)
 18.3061 +{
 18.3062 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3063 +	{
 18.3064 +		uint offset = OPER_I_32();
 18.3065 +		REG_PC -= 4;
 18.3066 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.3067 +		m68ki_branch_32(offset);
 18.3068 +		if(REG_PC == REG_PPC)
 18.3069 +			USE_ALL_CYCLES();
 18.3070 +		return;
 18.3071 +	}
 18.3072 +	m68ki_exception_illegal();
 18.3073 +}
 18.3074 +
 18.3075 +
 18.3076 +M68KMAKE_OP(bset, 32, r, d)
 18.3077 +{
 18.3078 +	uint* r_dst = &DY;
 18.3079 +	uint mask = 1 << (DX & 0x1f);
 18.3080 +
 18.3081 +	FLAG_Z = *r_dst & mask;
 18.3082 +	*r_dst |= mask;
 18.3083 +}
 18.3084 +
 18.3085 +
 18.3086 +M68KMAKE_OP(bset, 8, r, .)
 18.3087 +{
 18.3088 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.3089 +	uint src = m68ki_read_8(ea);
 18.3090 +	uint mask = 1 << (DX & 7);
 18.3091 +
 18.3092 +	FLAG_Z = src & mask;
 18.3093 +	m68ki_write_8(ea, src | mask);
 18.3094 +}
 18.3095 +
 18.3096 +
 18.3097 +M68KMAKE_OP(bset, 32, s, d)
 18.3098 +{
 18.3099 +	uint* r_dst = &DY;
 18.3100 +	uint mask = 1 << (OPER_I_8() & 0x1f);
 18.3101 +
 18.3102 +	FLAG_Z = *r_dst & mask;
 18.3103 +	*r_dst |= mask;
 18.3104 +}
 18.3105 +
 18.3106 +
 18.3107 +M68KMAKE_OP(bset, 8, s, .)
 18.3108 +{
 18.3109 +	uint mask = 1 << (OPER_I_8() & 7);
 18.3110 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.3111 +	uint src = m68ki_read_8(ea);
 18.3112 +
 18.3113 +	FLAG_Z = src & mask;
 18.3114 +	m68ki_write_8(ea, src | mask);
 18.3115 +}
 18.3116 +
 18.3117 +
 18.3118 +M68KMAKE_OP(bsr, 8, ., .)
 18.3119 +{
 18.3120 +	m68ki_trace_t0();				   /* auto-disable (see m68kcpu.h) */
 18.3121 +	m68ki_push_32(REG_PC);
 18.3122 +	m68ki_branch_8(MASK_OUT_ABOVE_8(REG_IR));
 18.3123 +}
 18.3124 +
 18.3125 +
 18.3126 +M68KMAKE_OP(bsr, 16, ., .)
 18.3127 +{
 18.3128 +	uint offset = OPER_I_16();
 18.3129 +	m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.3130 +	m68ki_push_32(REG_PC);
 18.3131 +	REG_PC -= 2;
 18.3132 +	m68ki_branch_16(offset);
 18.3133 +}
 18.3134 +
 18.3135 +
 18.3136 +M68KMAKE_OP(bsr, 32, ., .)
 18.3137 +{
 18.3138 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3139 +	{
 18.3140 +		uint offset = OPER_I_32();
 18.3141 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.3142 +		m68ki_push_32(REG_PC);
 18.3143 +		REG_PC -= 4;
 18.3144 +		m68ki_branch_32(offset);
 18.3145 +		return;
 18.3146 +	}
 18.3147 +	m68ki_exception_illegal();
 18.3148 +}
 18.3149 +
 18.3150 +
 18.3151 +M68KMAKE_OP(btst, 32, r, d)
 18.3152 +{
 18.3153 +	FLAG_Z = DY & (1 << (DX & 0x1f));
 18.3154 +}
 18.3155 +
 18.3156 +
 18.3157 +M68KMAKE_OP(btst, 8, r, .)
 18.3158 +{
 18.3159 +	FLAG_Z = M68KMAKE_GET_OPER_AY_8 & (1 << (DX & 7));
 18.3160 +}
 18.3161 +
 18.3162 +
 18.3163 +M68KMAKE_OP(btst, 32, s, d)
 18.3164 +{
 18.3165 +	FLAG_Z = DY & (1 << (OPER_I_8() & 0x1f));
 18.3166 +}
 18.3167 +
 18.3168 +
 18.3169 +M68KMAKE_OP(btst, 8, s, .)
 18.3170 +{
 18.3171 +	uint bit = OPER_I_8() & 7;
 18.3172 +
 18.3173 +	FLAG_Z = M68KMAKE_GET_OPER_AY_8 & (1 << bit);
 18.3174 +}
 18.3175 +
 18.3176 +
 18.3177 +M68KMAKE_OP(callm, 32, ., .)
 18.3178 +{
 18.3179 +	if(CPU_TYPE_IS_020_VARIANT(CPU_TYPE))
 18.3180 +	{
 18.3181 +		uint ea = M68KMAKE_GET_EA_AY_32;
 18.3182 +
 18.3183 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.3184 +		REG_PC += 2;
 18.3185 +(void)ea;	/* just to avoid an 'unused variable' warning */
 18.3186 +		M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n",
 18.3187 +					 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PC - 2), REG_IR,
 18.3188 +					 m68k_disassemble_quick(ADDRESS_68K(REG_PC - 2))));
 18.3189 +		return;
 18.3190 +	}
 18.3191 +	m68ki_exception_illegal();
 18.3192 +}
 18.3193 +
 18.3194 +
 18.3195 +M68KMAKE_OP(cas, 8, ., .)
 18.3196 +{
 18.3197 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3198 +	{
 18.3199 +		uint word2 = OPER_I_16();
 18.3200 +		uint ea = M68KMAKE_GET_EA_AY_8;
 18.3201 +		uint dest = m68ki_read_8(ea);
 18.3202 +		uint* compare = &REG_D[word2 & 7];
 18.3203 +		uint res = dest - MASK_OUT_ABOVE_8(*compare);
 18.3204 +
 18.3205 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.3206 +		FLAG_N = NFLAG_8(res);
 18.3207 +		FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.3208 +		FLAG_V = VFLAG_SUB_8(*compare, dest, res);
 18.3209 +		FLAG_C = CFLAG_8(res);
 18.3210 +
 18.3211 +		if(COND_NE())
 18.3212 +			*compare = MASK_OUT_BELOW_8(*compare) | dest;
 18.3213 +		else
 18.3214 +		{
 18.3215 +			USE_CYCLES(3);
 18.3216 +			m68ki_write_8(ea, MASK_OUT_ABOVE_8(REG_D[(word2 >> 6) & 7]));
 18.3217 +		}
 18.3218 +		return;
 18.3219 +	}
 18.3220 +	m68ki_exception_illegal();
 18.3221 +}
 18.3222 +
 18.3223 +
 18.3224 +M68KMAKE_OP(cas, 16, ., .)
 18.3225 +{
 18.3226 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3227 +	{
 18.3228 +		uint word2 = OPER_I_16();
 18.3229 +		uint ea = M68KMAKE_GET_EA_AY_16;
 18.3230 +		uint dest = m68ki_read_16(ea);
 18.3231 +		uint* compare = &REG_D[word2 & 7];
 18.3232 +		uint res = dest - MASK_OUT_ABOVE_16(*compare);
 18.3233 +
 18.3234 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.3235 +		FLAG_N = NFLAG_16(res);
 18.3236 +		FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.3237 +		FLAG_V = VFLAG_SUB_16(*compare, dest, res);
 18.3238 +		FLAG_C = CFLAG_16(res);
 18.3239 +
 18.3240 +		if(COND_NE())
 18.3241 +			*compare = MASK_OUT_BELOW_16(*compare) | dest;
 18.3242 +		else
 18.3243 +		{
 18.3244 +			USE_CYCLES(3);
 18.3245 +			m68ki_write_16(ea, MASK_OUT_ABOVE_16(REG_D[(word2 >> 6) & 7]));
 18.3246 +		}
 18.3247 +		return;
 18.3248 +	}
 18.3249 +	m68ki_exception_illegal();
 18.3250 +}
 18.3251 +
 18.3252 +
 18.3253 +M68KMAKE_OP(cas, 32, ., .)
 18.3254 +{
 18.3255 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3256 +	{
 18.3257 +		uint word2 = OPER_I_16();
 18.3258 +		uint ea = M68KMAKE_GET_EA_AY_32;
 18.3259 +		uint dest = m68ki_read_32(ea);
 18.3260 +		uint* compare = &REG_D[word2 & 7];
 18.3261 +		uint res = dest - *compare;
 18.3262 +
 18.3263 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.3264 +		FLAG_N = NFLAG_32(res);
 18.3265 +		FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3266 +		FLAG_V = VFLAG_SUB_32(*compare, dest, res);
 18.3267 +		FLAG_C = CFLAG_SUB_32(*compare, dest, res);
 18.3268 +
 18.3269 +		if(COND_NE())
 18.3270 +			*compare = dest;
 18.3271 +		else
 18.3272 +		{
 18.3273 +			USE_CYCLES(3);
 18.3274 +			m68ki_write_32(ea, REG_D[(word2 >> 6) & 7]);
 18.3275 +		}
 18.3276 +		return;
 18.3277 +	}
 18.3278 +	m68ki_exception_illegal();
 18.3279 +}
 18.3280 +
 18.3281 +
 18.3282 +M68KMAKE_OP(cas2, 16, ., .)
 18.3283 +{
 18.3284 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3285 +	{
 18.3286 +		uint word2 = OPER_I_32();
 18.3287 +		uint* compare1 = &REG_D[(word2 >> 16) & 7];
 18.3288 +		uint ea1 = REG_DA[(word2 >> 28) & 15];
 18.3289 +		uint dest1 = m68ki_read_16(ea1);
 18.3290 +		uint res1 = dest1 - MASK_OUT_ABOVE_16(*compare1);
 18.3291 +		uint* compare2 = &REG_D[word2 & 7];
 18.3292 +		uint ea2 = REG_DA[(word2 >> 12) & 15];
 18.3293 +		uint dest2 = m68ki_read_16(ea2);
 18.3294 +		uint res2;
 18.3295 +
 18.3296 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.3297 +		FLAG_N = NFLAG_16(res1);
 18.3298 +		FLAG_Z = MASK_OUT_ABOVE_16(res1);
 18.3299 +		FLAG_V = VFLAG_SUB_16(*compare1, dest1, res1);
 18.3300 +		FLAG_C = CFLAG_16(res1);
 18.3301 +
 18.3302 +		if(COND_EQ())
 18.3303 +		{
 18.3304 +			res2 = dest2 - MASK_OUT_ABOVE_16(*compare2);
 18.3305 +
 18.3306 +			FLAG_N = NFLAG_16(res2);
 18.3307 +			FLAG_Z = MASK_OUT_ABOVE_16(res2);
 18.3308 +			FLAG_V = VFLAG_SUB_16(*compare2, dest2, res2);
 18.3309 +			FLAG_C = CFLAG_16(res2);
 18.3310 +
 18.3311 +			if(COND_EQ())
 18.3312 +			{
 18.3313 +				USE_CYCLES(3);
 18.3314 +				m68ki_write_16(ea1, REG_D[(word2 >> 22) & 7]);
 18.3315 +				m68ki_write_16(ea2, REG_D[(word2 >> 6) & 7]);
 18.3316 +				return;
 18.3317 +			}
 18.3318 +		}
 18.3319 +		*compare1 = BIT_1F(word2) ? MAKE_INT_16(dest1) : MASK_OUT_BELOW_16(*compare1) | dest1;
 18.3320 +		*compare2 = BIT_F(word2) ? MAKE_INT_16(dest2) : MASK_OUT_BELOW_16(*compare2) | dest2;
 18.3321 +		return;
 18.3322 +	}
 18.3323 +	m68ki_exception_illegal();
 18.3324 +}
 18.3325 +
 18.3326 +
 18.3327 +M68KMAKE_OP(cas2, 32, ., .)
 18.3328 +{
 18.3329 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3330 +	{
 18.3331 +		uint word2 = OPER_I_32();
 18.3332 +		uint* compare1 = &REG_D[(word2 >> 16) & 7];
 18.3333 +		uint ea1 = REG_DA[(word2 >> 28) & 15];
 18.3334 +		uint dest1 = m68ki_read_32(ea1);
 18.3335 +		uint res1 = dest1 - *compare1;
 18.3336 +		uint* compare2 = &REG_D[word2 & 7];
 18.3337 +		uint ea2 = REG_DA[(word2 >> 12) & 15];
 18.3338 +		uint dest2 = m68ki_read_32(ea2);
 18.3339 +		uint res2;
 18.3340 +
 18.3341 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.3342 +		FLAG_N = NFLAG_32(res1);
 18.3343 +		FLAG_Z = MASK_OUT_ABOVE_32(res1);
 18.3344 +		FLAG_V = VFLAG_SUB_32(*compare1, dest1, res1);
 18.3345 +		FLAG_C = CFLAG_SUB_32(*compare1, dest1, res1);
 18.3346 +
 18.3347 +		if(COND_EQ())
 18.3348 +		{
 18.3349 +			res2 = dest2 - *compare2;
 18.3350 +
 18.3351 +			FLAG_N = NFLAG_32(res2);
 18.3352 +			FLAG_Z = MASK_OUT_ABOVE_32(res2);
 18.3353 +			FLAG_V = VFLAG_SUB_32(*compare2, dest2, res2);
 18.3354 +			FLAG_C = CFLAG_SUB_32(*compare2, dest2, res2);
 18.3355 +
 18.3356 +			if(COND_EQ())
 18.3357 +			{
 18.3358 +				USE_CYCLES(3);
 18.3359 +				m68ki_write_32(ea1, REG_D[(word2 >> 22) & 7]);
 18.3360 +				m68ki_write_32(ea2, REG_D[(word2 >> 6) & 7]);
 18.3361 +				return;
 18.3362 +			}
 18.3363 +		}
 18.3364 +		*compare1 = dest1;
 18.3365 +		*compare2 = dest2;
 18.3366 +		return;
 18.3367 +	}
 18.3368 +	m68ki_exception_illegal();
 18.3369 +}
 18.3370 +
 18.3371 +
 18.3372 +M68KMAKE_OP(chk, 16, ., d)
 18.3373 +{
 18.3374 +	sint src = MAKE_INT_16(DX);
 18.3375 +	sint bound = MAKE_INT_16(DY);
 18.3376 +
 18.3377 +	if(src >= 0 && src <= bound)
 18.3378 +	{
 18.3379 +		return;
 18.3380 +	}
 18.3381 +	FLAG_N = (src < 0)<<7;
 18.3382 +	m68ki_exception_trap(EXCEPTION_CHK);
 18.3383 +}
 18.3384 +
 18.3385 +
 18.3386 +M68KMAKE_OP(chk, 16, ., .)
 18.3387 +{
 18.3388 +	sint src = MAKE_INT_16(DX);
 18.3389 +	sint bound = MAKE_INT_16(M68KMAKE_GET_OPER_AY_16);
 18.3390 +
 18.3391 +	if(src >= 0 && src <= bound)
 18.3392 +	{
 18.3393 +		return;
 18.3394 +	}
 18.3395 +	FLAG_N = (src < 0)<<7;
 18.3396 +	m68ki_exception_trap(EXCEPTION_CHK);
 18.3397 +}
 18.3398 +
 18.3399 +
 18.3400 +M68KMAKE_OP(chk, 32, ., d)
 18.3401 +{
 18.3402 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3403 +	{
 18.3404 +		sint src = MAKE_INT_32(DX);
 18.3405 +		sint bound = MAKE_INT_32(DY);
 18.3406 +
 18.3407 +		if(src >= 0 && src <= bound)
 18.3408 +		{
 18.3409 +			return;
 18.3410 +		}
 18.3411 +		FLAG_N = (src < 0)<<7;
 18.3412 +		m68ki_exception_trap(EXCEPTION_CHK);
 18.3413 +		return;
 18.3414 +	}
 18.3415 +	m68ki_exception_illegal();
 18.3416 +}
 18.3417 +
 18.3418 +
 18.3419 +M68KMAKE_OP(chk, 32, ., .)
 18.3420 +{
 18.3421 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3422 +	{
 18.3423 +		sint src = MAKE_INT_32(DX);
 18.3424 +		sint bound = MAKE_INT_32(M68KMAKE_GET_OPER_AY_32);
 18.3425 +
 18.3426 +		if(src >= 0 && src <= bound)
 18.3427 +		{
 18.3428 +			return;
 18.3429 +		}
 18.3430 +		FLAG_N = (src < 0)<<7;
 18.3431 +		m68ki_exception_trap(EXCEPTION_CHK);
 18.3432 +		return;
 18.3433 +	}
 18.3434 +	m68ki_exception_illegal();
 18.3435 +}
 18.3436 +
 18.3437 +
 18.3438 +M68KMAKE_OP(chk2cmp2, 8, ., .)
 18.3439 +{
 18.3440 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3441 +	{
 18.3442 +		uint word2 = OPER_I_16();
 18.3443 +		uint compare = REG_DA[(word2 >> 12) & 15];
 18.3444 +		uint ea = M68KMAKE_GET_EA_AY_8;
 18.3445 +		uint lower_bound = m68ki_read_8(ea);
 18.3446 +		uint upper_bound = m68ki_read_8(ea + 1);
 18.3447 +
 18.3448 +		if(!BIT_F(word2))
 18.3449 +			compare = MAKE_INT_8(compare);
 18.3450 +
 18.3451 +		FLAG_C = compare - lower_bound;
 18.3452 +		FLAG_Z = MASK_OUT_ABOVE_8(FLAG_C);
 18.3453 +		if(COND_CS())
 18.3454 +		{
 18.3455 +			if(BIT_B(word2))
 18.3456 +				m68ki_exception_trap(EXCEPTION_CHK);
 18.3457 +			return;
 18.3458 +		}
 18.3459 +
 18.3460 +		FLAG_C = upper_bound - compare;
 18.3461 +		FLAG_Z = MASK_OUT_ABOVE_8(FLAG_C);
 18.3462 +		if(COND_CS() && BIT_B(word2))
 18.3463 +				m68ki_exception_trap(EXCEPTION_CHK);
 18.3464 +
 18.3465 +		return;
 18.3466 +	}
 18.3467 +	m68ki_exception_illegal();
 18.3468 +}
 18.3469 +
 18.3470 +
 18.3471 +M68KMAKE_OP(chk2cmp2, 16, ., .)
 18.3472 +{
 18.3473 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3474 +	{
 18.3475 +		uint word2 = OPER_I_16();
 18.3476 +		uint compare = REG_DA[(word2 >> 12) & 15];
 18.3477 +		uint ea = M68KMAKE_GET_EA_AY_16;
 18.3478 +		uint lower_bound = m68ki_read_16(ea);
 18.3479 +		uint upper_bound = m68ki_read_16(ea + 1);
 18.3480 +
 18.3481 +		if(!BIT_F(word2))
 18.3482 +			compare = MAKE_INT_16(compare);
 18.3483 +
 18.3484 +		FLAG_C = compare - lower_bound;
 18.3485 +		FLAG_Z = MASK_OUT_ABOVE_16(FLAG_C);
 18.3486 +		FLAG_C = CFLAG_16(FLAG_C);
 18.3487 +		if(COND_CS())
 18.3488 +		{
 18.3489 +			if(BIT_B(word2))
 18.3490 +				m68ki_exception_trap(EXCEPTION_CHK);
 18.3491 +			return;
 18.3492 +		}
 18.3493 +
 18.3494 +		FLAG_C = upper_bound - compare;
 18.3495 +		FLAG_Z = MASK_OUT_ABOVE_16(FLAG_C);
 18.3496 +		FLAG_C = CFLAG_16(FLAG_C);
 18.3497 +		if(COND_CS() && BIT_B(word2))
 18.3498 +				m68ki_exception_trap(EXCEPTION_CHK);
 18.3499 +
 18.3500 +		return;
 18.3501 +	}
 18.3502 +	m68ki_exception_illegal();
 18.3503 +}
 18.3504 +
 18.3505 +
 18.3506 +M68KMAKE_OP(chk2cmp2, 32, ., .)
 18.3507 +{
 18.3508 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3509 +	{
 18.3510 +		uint word2 = OPER_I_16();
 18.3511 +		uint compare = REG_DA[(word2 >> 12) & 15];
 18.3512 +		uint ea = M68KMAKE_GET_EA_AY_32;
 18.3513 +		uint lower_bound = m68ki_read_32(ea);
 18.3514 +		uint upper_bound = m68ki_read_32(ea + 1);
 18.3515 +
 18.3516 +		FLAG_C = compare - lower_bound;
 18.3517 +		FLAG_Z = MASK_OUT_ABOVE_32(FLAG_C);
 18.3518 +		FLAG_C = CFLAG_SUB_32(lower_bound, compare, FLAG_C);
 18.3519 +		if(COND_CS())
 18.3520 +		{
 18.3521 +			if(BIT_B(word2))
 18.3522 +				m68ki_exception_trap(EXCEPTION_CHK);
 18.3523 +			return;
 18.3524 +		}
 18.3525 +
 18.3526 +		FLAG_C = upper_bound - compare;
 18.3527 +		FLAG_Z = MASK_OUT_ABOVE_32(FLAG_C);
 18.3528 +		FLAG_C = CFLAG_SUB_32(compare, upper_bound, FLAG_C);
 18.3529 +		if(COND_CS() && BIT_B(word2))
 18.3530 +				m68ki_exception_trap(EXCEPTION_CHK);
 18.3531 +
 18.3532 +		return;
 18.3533 +	}
 18.3534 +	m68ki_exception_illegal();
 18.3535 +}
 18.3536 +
 18.3537 +
 18.3538 +M68KMAKE_OP(clr, 8, ., d)
 18.3539 +{
 18.3540 +	DY &= 0xffffff00;
 18.3541 +
 18.3542 +	FLAG_N = NFLAG_CLEAR;
 18.3543 +	FLAG_V = VFLAG_CLEAR;
 18.3544 +	FLAG_C = CFLAG_CLEAR;
 18.3545 +	FLAG_Z = ZFLAG_SET;
 18.3546 +}
 18.3547 +
 18.3548 +
 18.3549 +M68KMAKE_OP(clr, 8, ., .)
 18.3550 +{
 18.3551 +	m68ki_write_8(M68KMAKE_GET_EA_AY_8, 0);
 18.3552 +
 18.3553 +	FLAG_N = NFLAG_CLEAR;
 18.3554 +	FLAG_V = VFLAG_CLEAR;
 18.3555 +	FLAG_C = CFLAG_CLEAR;
 18.3556 +	FLAG_Z = ZFLAG_SET;
 18.3557 +}
 18.3558 +
 18.3559 +
 18.3560 +M68KMAKE_OP(clr, 16, ., d)
 18.3561 +{
 18.3562 +	DY &= 0xffff0000;
 18.3563 +
 18.3564 +	FLAG_N = NFLAG_CLEAR;
 18.3565 +	FLAG_V = VFLAG_CLEAR;
 18.3566 +	FLAG_C = CFLAG_CLEAR;
 18.3567 +	FLAG_Z = ZFLAG_SET;
 18.3568 +}
 18.3569 +
 18.3570 +
 18.3571 +M68KMAKE_OP(clr, 16, ., .)
 18.3572 +{
 18.3573 +	m68ki_write_16(M68KMAKE_GET_EA_AY_16, 0);
 18.3574 +
 18.3575 +	FLAG_N = NFLAG_CLEAR;
 18.3576 +	FLAG_V = VFLAG_CLEAR;
 18.3577 +	FLAG_C = CFLAG_CLEAR;
 18.3578 +	FLAG_Z = ZFLAG_SET;
 18.3579 +}
 18.3580 +
 18.3581 +
 18.3582 +M68KMAKE_OP(clr, 32, ., d)
 18.3583 +{
 18.3584 +	DY = 0;
 18.3585 +
 18.3586 +	FLAG_N = NFLAG_CLEAR;
 18.3587 +	FLAG_V = VFLAG_CLEAR;
 18.3588 +	FLAG_C = CFLAG_CLEAR;
 18.3589 +	FLAG_Z = ZFLAG_SET;
 18.3590 +}
 18.3591 +
 18.3592 +
 18.3593 +M68KMAKE_OP(clr, 32, ., .)
 18.3594 +{
 18.3595 +	m68ki_write_32(M68KMAKE_GET_EA_AY_32, 0);
 18.3596 +
 18.3597 +	FLAG_N = NFLAG_CLEAR;
 18.3598 +	FLAG_V = VFLAG_CLEAR;
 18.3599 +	FLAG_C = CFLAG_CLEAR;
 18.3600 +	FLAG_Z = ZFLAG_SET;
 18.3601 +}
 18.3602 +
 18.3603 +
 18.3604 +M68KMAKE_OP(cmp, 8, ., d)
 18.3605 +{
 18.3606 +	uint src = MASK_OUT_ABOVE_8(DY);
 18.3607 +	uint dst = MASK_OUT_ABOVE_8(DX);
 18.3608 +	uint res = dst - src;
 18.3609 +
 18.3610 +	FLAG_N = NFLAG_8(res);
 18.3611 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.3612 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.3613 +	FLAG_C = CFLAG_8(res);
 18.3614 +}
 18.3615 +
 18.3616 +
 18.3617 +M68KMAKE_OP(cmp, 8, ., .)
 18.3618 +{
 18.3619 +	uint src = M68KMAKE_GET_OPER_AY_8;
 18.3620 +	uint dst = MASK_OUT_ABOVE_8(DX);
 18.3621 +	uint res = dst - src;
 18.3622 +
 18.3623 +	FLAG_N = NFLAG_8(res);
 18.3624 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.3625 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.3626 +	FLAG_C = CFLAG_8(res);
 18.3627 +}
 18.3628 +
 18.3629 +
 18.3630 +M68KMAKE_OP(cmp, 16, ., d)
 18.3631 +{
 18.3632 +	uint src = MASK_OUT_ABOVE_16(DY);
 18.3633 +	uint dst = MASK_OUT_ABOVE_16(DX);
 18.3634 +	uint res = dst - src;
 18.3635 +
 18.3636 +	FLAG_N = NFLAG_16(res);
 18.3637 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.3638 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.3639 +	FLAG_C = CFLAG_16(res);
 18.3640 +}
 18.3641 +
 18.3642 +
 18.3643 +M68KMAKE_OP(cmp, 16, ., a)
 18.3644 +{
 18.3645 +	uint src = MASK_OUT_ABOVE_16(AY);
 18.3646 +	uint dst = MASK_OUT_ABOVE_16(DX);
 18.3647 +	uint res = dst - src;
 18.3648 +
 18.3649 +	FLAG_N = NFLAG_16(res);
 18.3650 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.3651 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.3652 +	FLAG_C = CFLAG_16(res);
 18.3653 +}
 18.3654 +
 18.3655 +
 18.3656 +M68KMAKE_OP(cmp, 16, ., .)
 18.3657 +{
 18.3658 +	uint src = M68KMAKE_GET_OPER_AY_16;
 18.3659 +	uint dst = MASK_OUT_ABOVE_16(DX);
 18.3660 +	uint res = dst - src;
 18.3661 +
 18.3662 +	FLAG_N = NFLAG_16(res);
 18.3663 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.3664 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.3665 +	FLAG_C = CFLAG_16(res);
 18.3666 +}
 18.3667 +
 18.3668 +
 18.3669 +M68KMAKE_OP(cmp, 32, ., d)
 18.3670 +{
 18.3671 +	uint src = DY;
 18.3672 +	uint dst = DX;
 18.3673 +	uint res = dst - src;
 18.3674 +
 18.3675 +	FLAG_N = NFLAG_32(res);
 18.3676 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3677 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3678 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3679 +}
 18.3680 +
 18.3681 +
 18.3682 +M68KMAKE_OP(cmp, 32, ., a)
 18.3683 +{
 18.3684 +	uint src = AY;
 18.3685 +	uint dst = DX;
 18.3686 +	uint res = dst - src;
 18.3687 +
 18.3688 +	FLAG_N = NFLAG_32(res);
 18.3689 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3690 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3691 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3692 +}
 18.3693 +
 18.3694 +
 18.3695 +M68KMAKE_OP(cmp, 32, ., .)
 18.3696 +{
 18.3697 +	uint src = M68KMAKE_GET_OPER_AY_32;
 18.3698 +	uint dst = DX;
 18.3699 +	uint res = dst - src;
 18.3700 +
 18.3701 +	FLAG_N = NFLAG_32(res);
 18.3702 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3703 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3704 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3705 +}
 18.3706 +
 18.3707 +
 18.3708 +M68KMAKE_OP(cmpa, 16, ., d)
 18.3709 +{
 18.3710 +	uint src = MAKE_INT_16(DY);
 18.3711 +	uint dst = AX;
 18.3712 +	uint res = dst - src;
 18.3713 +
 18.3714 +	FLAG_N = NFLAG_32(res);
 18.3715 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3716 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3717 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3718 +}
 18.3719 +
 18.3720 +
 18.3721 +M68KMAKE_OP(cmpa, 16, ., a)
 18.3722 +{
 18.3723 +	uint src = MAKE_INT_16(AY);
 18.3724 +	uint dst = AX;
 18.3725 +	uint res = dst - src;
 18.3726 +
 18.3727 +	FLAG_N = NFLAG_32(res);
 18.3728 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3729 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3730 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3731 +}
 18.3732 +
 18.3733 +
 18.3734 +M68KMAKE_OP(cmpa, 16, ., .)
 18.3735 +{
 18.3736 +	uint src = MAKE_INT_16(M68KMAKE_GET_OPER_AY_16);
 18.3737 +	uint dst = AX;
 18.3738 +	uint res = dst - src;
 18.3739 +
 18.3740 +	FLAG_N = NFLAG_32(res);
 18.3741 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3742 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3743 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3744 +}
 18.3745 +
 18.3746 +
 18.3747 +M68KMAKE_OP(cmpa, 32, ., d)
 18.3748 +{
 18.3749 +	uint src = DY;
 18.3750 +	uint dst = AX;
 18.3751 +	uint res = dst - src;
 18.3752 +
 18.3753 +	FLAG_N = NFLAG_32(res);
 18.3754 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3755 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3756 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3757 +}
 18.3758 +
 18.3759 +
 18.3760 +M68KMAKE_OP(cmpa, 32, ., a)
 18.3761 +{
 18.3762 +	uint src = AY;
 18.3763 +	uint dst = AX;
 18.3764 +	uint res = dst - src;
 18.3765 +
 18.3766 +	FLAG_N = NFLAG_32(res);
 18.3767 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3768 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3769 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3770 +}
 18.3771 +
 18.3772 +
 18.3773 +M68KMAKE_OP(cmpa, 32, ., .)
 18.3774 +{
 18.3775 +	uint src = M68KMAKE_GET_OPER_AY_32;
 18.3776 +	uint dst = AX;
 18.3777 +	uint res = dst - src;
 18.3778 +
 18.3779 +	FLAG_N = NFLAG_32(res);
 18.3780 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3781 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3782 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3783 +}
 18.3784 +
 18.3785 +
 18.3786 +M68KMAKE_OP(cmpi, 8, ., d)
 18.3787 +{
 18.3788 +	uint src = OPER_I_8();
 18.3789 +	uint dst = MASK_OUT_ABOVE_8(DY);
 18.3790 +	uint res = dst - src;
 18.3791 +
 18.3792 +	FLAG_N = NFLAG_8(res);
 18.3793 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.3794 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.3795 +	FLAG_C = CFLAG_8(res);
 18.3796 +}
 18.3797 +
 18.3798 +
 18.3799 +M68KMAKE_OP(cmpi, 8, ., .)
 18.3800 +{
 18.3801 +	uint src = OPER_I_8();
 18.3802 +	uint dst = M68KMAKE_GET_OPER_AY_8;
 18.3803 +	uint res = dst - src;
 18.3804 +
 18.3805 +	FLAG_N = NFLAG_8(res);
 18.3806 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.3807 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.3808 +	FLAG_C = CFLAG_8(res);
 18.3809 +}
 18.3810 +
 18.3811 +
 18.3812 +M68KMAKE_OP(cmpi, 8, ., pcdi)
 18.3813 +{
 18.3814 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3815 +	{
 18.3816 +		uint src = OPER_I_8();
 18.3817 +		uint dst = OPER_PCDI_8();
 18.3818 +		uint res = dst - src;
 18.3819 +
 18.3820 +		FLAG_N = NFLAG_8(res);
 18.3821 +		FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.3822 +		FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.3823 +		FLAG_C = CFLAG_8(res);
 18.3824 +		return;
 18.3825 +	}
 18.3826 +	m68ki_exception_illegal();
 18.3827 +}
 18.3828 +
 18.3829 +
 18.3830 +M68KMAKE_OP(cmpi, 8, ., pcix)
 18.3831 +{
 18.3832 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3833 +	{
 18.3834 +		uint src = OPER_I_8();
 18.3835 +		uint dst = OPER_PCIX_8();
 18.3836 +		uint res = dst - src;
 18.3837 +
 18.3838 +		FLAG_N = NFLAG_8(res);
 18.3839 +		FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.3840 +		FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.3841 +		FLAG_C = CFLAG_8(res);
 18.3842 +		return;
 18.3843 +	}
 18.3844 +	m68ki_exception_illegal();
 18.3845 +}
 18.3846 +
 18.3847 +
 18.3848 +M68KMAKE_OP(cmpi, 16, ., d)
 18.3849 +{
 18.3850 +	uint src = OPER_I_16();
 18.3851 +	uint dst = MASK_OUT_ABOVE_16(DY);
 18.3852 +	uint res = dst - src;
 18.3853 +
 18.3854 +	FLAG_N = NFLAG_16(res);
 18.3855 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.3856 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.3857 +	FLAG_C = CFLAG_16(res);
 18.3858 +}
 18.3859 +
 18.3860 +
 18.3861 +M68KMAKE_OP(cmpi, 16, ., .)
 18.3862 +{
 18.3863 +	uint src = OPER_I_16();
 18.3864 +	uint dst = M68KMAKE_GET_OPER_AY_16;
 18.3865 +	uint res = dst - src;
 18.3866 +
 18.3867 +	FLAG_N = NFLAG_16(res);
 18.3868 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.3869 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.3870 +	FLAG_C = CFLAG_16(res);
 18.3871 +}
 18.3872 +
 18.3873 +
 18.3874 +M68KMAKE_OP(cmpi, 16, ., pcdi)
 18.3875 +{
 18.3876 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3877 +	{
 18.3878 +		uint src = OPER_I_16();
 18.3879 +		uint dst = OPER_PCDI_16();
 18.3880 +		uint res = dst - src;
 18.3881 +
 18.3882 +		FLAG_N = NFLAG_16(res);
 18.3883 +		FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.3884 +		FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.3885 +		FLAG_C = CFLAG_16(res);
 18.3886 +		return;
 18.3887 +	}
 18.3888 +	m68ki_exception_illegal();
 18.3889 +}
 18.3890 +
 18.3891 +
 18.3892 +M68KMAKE_OP(cmpi, 16, ., pcix)
 18.3893 +{
 18.3894 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3895 +	{
 18.3896 +		uint src = OPER_I_16();
 18.3897 +		uint dst = OPER_PCIX_16();
 18.3898 +		uint res = dst - src;
 18.3899 +
 18.3900 +		FLAG_N = NFLAG_16(res);
 18.3901 +		FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.3902 +		FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.3903 +		FLAG_C = CFLAG_16(res);
 18.3904 +		return;
 18.3905 +	}
 18.3906 +	m68ki_exception_illegal();
 18.3907 +}
 18.3908 +
 18.3909 +
 18.3910 +M68KMAKE_OP(cmpi, 32, ., d)
 18.3911 +{
 18.3912 +	uint src = OPER_I_32();
 18.3913 +	uint dst = DY;
 18.3914 +	uint res = dst - src;
 18.3915 +
 18.3916 +	FLAG_N = NFLAG_32(res);
 18.3917 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3918 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3919 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3920 +}
 18.3921 +
 18.3922 +
 18.3923 +M68KMAKE_OP(cmpi, 32, ., .)
 18.3924 +{
 18.3925 +	uint src = OPER_I_32();
 18.3926 +	uint dst = M68KMAKE_GET_OPER_AY_32;
 18.3927 +	uint res = dst - src;
 18.3928 +
 18.3929 +	FLAG_N = NFLAG_32(res);
 18.3930 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3931 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3932 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3933 +}
 18.3934 +
 18.3935 +
 18.3936 +M68KMAKE_OP(cmpi, 32, ., pcdi)
 18.3937 +{
 18.3938 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3939 +	{
 18.3940 +		uint src = OPER_I_32();
 18.3941 +		uint dst = OPER_PCDI_32();
 18.3942 +		uint res = dst - src;
 18.3943 +
 18.3944 +		FLAG_N = NFLAG_32(res);
 18.3945 +		FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3946 +		FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3947 +		FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3948 +		return;
 18.3949 +	}
 18.3950 +	m68ki_exception_illegal();
 18.3951 +}
 18.3952 +
 18.3953 +
 18.3954 +M68KMAKE_OP(cmpi, 32, ., pcix)
 18.3955 +{
 18.3956 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.3957 +	{
 18.3958 +		uint src = OPER_I_32();
 18.3959 +		uint dst = OPER_PCIX_32();
 18.3960 +		uint res = dst - src;
 18.3961 +
 18.3962 +		FLAG_N = NFLAG_32(res);
 18.3963 +		FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.3964 +		FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.3965 +		FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.3966 +		return;
 18.3967 +	}
 18.3968 +	m68ki_exception_illegal();
 18.3969 +}
 18.3970 +
 18.3971 +
 18.3972 +M68KMAKE_OP(cmpm, 8, ., ax7)
 18.3973 +{
 18.3974 +	uint src = OPER_AY_PI_8();
 18.3975 +	uint dst = OPER_A7_PI_8();
 18.3976 +	uint res = dst - src;
 18.3977 +
 18.3978 +	FLAG_N = NFLAG_8(res);
 18.3979 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.3980 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.3981 +	FLAG_C = CFLAG_8(res);
 18.3982 +}
 18.3983 +
 18.3984 +
 18.3985 +M68KMAKE_OP(cmpm, 8, ., ay7)
 18.3986 +{
 18.3987 +	uint src = OPER_A7_PI_8();
 18.3988 +	uint dst = OPER_AX_PI_8();
 18.3989 +	uint res = dst - src;
 18.3990 +
 18.3991 +	FLAG_N = NFLAG_8(res);
 18.3992 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.3993 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.3994 +	FLAG_C = CFLAG_8(res);
 18.3995 +}
 18.3996 +
 18.3997 +
 18.3998 +M68KMAKE_OP(cmpm, 8, ., axy7)
 18.3999 +{
 18.4000 +	uint src = OPER_A7_PI_8();
 18.4001 +	uint dst = OPER_A7_PI_8();
 18.4002 +	uint res = dst - src;
 18.4003 +
 18.4004 +	FLAG_N = NFLAG_8(res);
 18.4005 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.4006 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.4007 +	FLAG_C = CFLAG_8(res);
 18.4008 +}
 18.4009 +
 18.4010 +
 18.4011 +M68KMAKE_OP(cmpm, 8, ., .)
 18.4012 +{
 18.4013 +	uint src = OPER_AY_PI_8();
 18.4014 +	uint dst = OPER_AX_PI_8();
 18.4015 +	uint res = dst - src;
 18.4016 +
 18.4017 +	FLAG_N = NFLAG_8(res);
 18.4018 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.4019 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.4020 +	FLAG_C = CFLAG_8(res);
 18.4021 +}
 18.4022 +
 18.4023 +
 18.4024 +M68KMAKE_OP(cmpm, 16, ., .)
 18.4025 +{
 18.4026 +	uint src = OPER_AY_PI_16();
 18.4027 +	uint dst = OPER_AX_PI_16();
 18.4028 +	uint res = dst - src;
 18.4029 +
 18.4030 +	FLAG_N = NFLAG_16(res);
 18.4031 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.4032 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.4033 +	FLAG_C = CFLAG_16(res);
 18.4034 +}
 18.4035 +
 18.4036 +
 18.4037 +M68KMAKE_OP(cmpm, 32, ., .)
 18.4038 +{
 18.4039 +	uint src = OPER_AY_PI_32();
 18.4040 +	uint dst = OPER_AX_PI_32();
 18.4041 +	uint res = dst - src;
 18.4042 +
 18.4043 +	FLAG_N = NFLAG_32(res);
 18.4044 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.4045 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.4046 +	FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.4047 +}
 18.4048 +
 18.4049 +
 18.4050 +M68KMAKE_OP(cpbcc, 32, ., .)
 18.4051 +{
 18.4052 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.4053 +	{
 18.4054 +		M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n",
 18.4055 +					 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PC - 2), REG_IR,
 18.4056 +					 m68k_disassemble_quick(ADDRESS_68K(REG_PC - 2))));
 18.4057 +		return;
 18.4058 +	}
 18.4059 +	m68ki_exception_1111();
 18.4060 +}
 18.4061 +
 18.4062 +
 18.4063 +M68KMAKE_OP(cpdbcc, 32, ., .)
 18.4064 +{
 18.4065 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.4066 +	{
 18.4067 +		M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n",
 18.4068 +					 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PC - 2), REG_IR,
 18.4069 +					 m68k_disassemble_quick(ADDRESS_68K(REG_PC - 2))));
 18.4070 +		return;
 18.4071 +	}
 18.4072 +	m68ki_exception_1111();
 18.4073 +}
 18.4074 +
 18.4075 +
 18.4076 +M68KMAKE_OP(cpgen, 32, ., .)
 18.4077 +{
 18.4078 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.4079 +	{
 18.4080 +		M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n",
 18.4081 +					 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PC - 2), REG_IR,
 18.4082 +					 m68k_disassemble_quick(ADDRESS_68K(REG_PC - 2))));
 18.4083 +		return;
 18.4084 +	}
 18.4085 +	m68ki_exception_1111();
 18.4086 +}
 18.4087 +
 18.4088 +
 18.4089 +M68KMAKE_OP(cpscc, 32, ., .)
 18.4090 +{
 18.4091 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.4092 +	{
 18.4093 +		M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n",
 18.4094 +					 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PC - 2), REG_IR,
 18.4095 +					 m68k_disassemble_quick(ADDRESS_68K(REG_PC - 2))));
 18.4096 +		return;
 18.4097 +	}
 18.4098 +	m68ki_exception_1111();
 18.4099 +}
 18.4100 +
 18.4101 +
 18.4102 +M68KMAKE_OP(cptrapcc, 32, ., .)
 18.4103 +{
 18.4104 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.4105 +	{
 18.4106 +		M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n",
 18.4107 +					 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PC - 2), REG_IR,
 18.4108 +					 m68k_disassemble_quick(ADDRESS_68K(REG_PC - 2))));
 18.4109 +		return;
 18.4110 +	}
 18.4111 +	m68ki_exception_1111();
 18.4112 +}
 18.4113 +
 18.4114 +
 18.4115 +M68KMAKE_OP(dbt, 16, ., .)
 18.4116 +{
 18.4117 +	REG_PC += 2;
 18.4118 +}
 18.4119 +
 18.4120 +
 18.4121 +M68KMAKE_OP(dbf, 16, ., .)
 18.4122 +{
 18.4123 +	uint* r_dst = &DY;
 18.4124 +	uint res = MASK_OUT_ABOVE_16(*r_dst - 1);
 18.4125 +
 18.4126 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.4127 +	if(res != 0xffff)
 18.4128 +	{
 18.4129 +		uint offset = OPER_I_16();
 18.4130 +		REG_PC -= 2;
 18.4131 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.4132 +		m68ki_branch_16(offset);
 18.4133 +		return;
 18.4134 +	}
 18.4135 +	REG_PC += 2;
 18.4136 +}
 18.4137 +
 18.4138 +
 18.4139 +M68KMAKE_OP(dbcc, 16, ., .)
 18.4140 +{
 18.4141 +	if(M68KMAKE_NOT_CC)
 18.4142 +	{
 18.4143 +		uint* r_dst = &DY;
 18.4144 +		uint res = MASK_OUT_ABOVE_16(*r_dst - 1);
 18.4145 +
 18.4146 +		*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.4147 +		if(res != 0xffff)
 18.4148 +		{
 18.4149 +			uint offset = OPER_I_16();
 18.4150 +			REG_PC -= 2;
 18.4151 +			m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.4152 +			m68ki_branch_16(offset);
 18.4153 +			USE_CYCLES(CYC_DBCC_F_NOEXP);
 18.4154 +			return;
 18.4155 +		}
 18.4156 +		REG_PC += 2;
 18.4157 +		USE_CYCLES(CYC_DBCC_F_EXP);
 18.4158 +		return;
 18.4159 +	}
 18.4160 +	REG_PC += 2;
 18.4161 +}
 18.4162 +
 18.4163 +
 18.4164 +M68KMAKE_OP(divs, 16, ., d)
 18.4165 +{
 18.4166 +	uint* r_dst = &DX;
 18.4167 +	sint src = MAKE_INT_16(DY);
 18.4168 +	sint quotient;
 18.4169 +	sint remainder;
 18.4170 +
 18.4171 +	if(src != 0)
 18.4172 +	{
 18.4173 +		if((uint32)*r_dst == 0x80000000 && src == -1)
 18.4174 +		{
 18.4175 +			FLAG_Z = 0;
 18.4176 +			FLAG_N = NFLAG_CLEAR;
 18.4177 +			FLAG_V = VFLAG_CLEAR;
 18.4178 +			FLAG_C = CFLAG_CLEAR;
 18.4179 +			*r_dst = 0;
 18.4180 +			return;
 18.4181 +		}
 18.4182 +
 18.4183 +		quotient = MAKE_INT_32(*r_dst) / src;
 18.4184 +		remainder = MAKE_INT_32(*r_dst) % src;
 18.4185 +
 18.4186 +		if(quotient == MAKE_INT_16(quotient))
 18.4187 +		{
 18.4188 +			FLAG_Z = quotient;
 18.4189 +			FLAG_N = NFLAG_16(quotient);
 18.4190 +			FLAG_V = VFLAG_CLEAR;
 18.4191 +			FLAG_C = CFLAG_CLEAR;
 18.4192 +			*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
 18.4193 +			return;
 18.4194 +		}
 18.4195 +		FLAG_V = VFLAG_SET;
 18.4196 +		return;
 18.4197 +	}
 18.4198 +	m68ki_exception_trap(EXCEPTION_ZERO_DIVIDE);
 18.4199 +}
 18.4200 +
 18.4201 +
 18.4202 +M68KMAKE_OP(divs, 16, ., .)
 18.4203 +{
 18.4204 +	uint* r_dst = &DX;
 18.4205 +	sint src = MAKE_INT_16(M68KMAKE_GET_OPER_AY_16);
 18.4206 +	sint quotient;
 18.4207 +	sint remainder;
 18.4208 +
 18.4209 +	if(src != 0)
 18.4210 +	{
 18.4211 +		if((uint32)*r_dst == 0x80000000 && src == -1)
 18.4212 +		{
 18.4213 +			FLAG_Z = 0;
 18.4214 +			FLAG_N = NFLAG_CLEAR;
 18.4215 +			FLAG_V = VFLAG_CLEAR;
 18.4216 +			FLAG_C = CFLAG_CLEAR;
 18.4217 +			*r_dst = 0;
 18.4218 +			return;
 18.4219 +		}
 18.4220 +
 18.4221 +		quotient = MAKE_INT_32(*r_dst) / src;
 18.4222 +		remainder = MAKE_INT_32(*r_dst) % src;
 18.4223 +
 18.4224 +		if(quotient == MAKE_INT_16(quotient))
 18.4225 +		{
 18.4226 +			FLAG_Z = quotient;
 18.4227 +			FLAG_N = NFLAG_16(quotient);
 18.4228 +			FLAG_V = VFLAG_CLEAR;
 18.4229 +			FLAG_C = CFLAG_CLEAR;
 18.4230 +			*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
 18.4231 +			return;
 18.4232 +		}
 18.4233 +		FLAG_V = VFLAG_SET;
 18.4234 +		return;
 18.4235 +	}
 18.4236 +	m68ki_exception_trap(EXCEPTION_ZERO_DIVIDE);
 18.4237 +}
 18.4238 +
 18.4239 +
 18.4240 +M68KMAKE_OP(divu, 16, ., d)
 18.4241 +{
 18.4242 +	uint* r_dst = &DX;
 18.4243 +	uint src = MASK_OUT_ABOVE_16(DY);
 18.4244 +
 18.4245 +	if(src != 0)
 18.4246 +	{
 18.4247 +		uint quotient = *r_dst / src;
 18.4248 +		uint remainder = *r_dst % src;
 18.4249 +
 18.4250 +		if(quotient < 0x10000)
 18.4251 +		{
 18.4252 +			FLAG_Z = quotient;
 18.4253 +			FLAG_N = NFLAG_16(quotient);
 18.4254 +			FLAG_V = VFLAG_CLEAR;
 18.4255 +			FLAG_C = CFLAG_CLEAR;
 18.4256 +			*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
 18.4257 +			return;
 18.4258 +		}
 18.4259 +		FLAG_V = VFLAG_SET;
 18.4260 +		return;
 18.4261 +	}
 18.4262 +	m68ki_exception_trap(EXCEPTION_ZERO_DIVIDE);
 18.4263 +}
 18.4264 +
 18.4265 +
 18.4266 +M68KMAKE_OP(divu, 16, ., .)
 18.4267 +{
 18.4268 +	uint* r_dst = &DX;
 18.4269 +	uint src = M68KMAKE_GET_OPER_AY_16;
 18.4270 +
 18.4271 +	if(src != 0)
 18.4272 +	{
 18.4273 +		uint quotient = *r_dst / src;
 18.4274 +		uint remainder = *r_dst % src;
 18.4275 +
 18.4276 +		if(quotient < 0x10000)
 18.4277 +		{
 18.4278 +			FLAG_Z = quotient;
 18.4279 +			FLAG_N = NFLAG_16(quotient);
 18.4280 +			FLAG_V = VFLAG_CLEAR;
 18.4281 +			FLAG_C = CFLAG_CLEAR;
 18.4282 +			*r_dst = MASK_OUT_ABOVE_32(MASK_OUT_ABOVE_16(quotient) | (remainder << 16));
 18.4283 +			return;
 18.4284 +		}
 18.4285 +		FLAG_V = VFLAG_SET;
 18.4286 +		return;
 18.4287 +	}
 18.4288 +	m68ki_exception_trap(EXCEPTION_ZERO_DIVIDE);
 18.4289 +}
 18.4290 +
 18.4291 +
 18.4292 +M68KMAKE_OP(divl, 32, ., d)
 18.4293 +{
 18.4294 +#if M68K_USE_64_BIT
 18.4295 +
 18.4296 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.4297 +	{
 18.4298 +		uint word2 = OPER_I_16();
 18.4299 +		uint64 divisor   = DY;
 18.4300 +		uint64 dividend  = 0;
 18.4301 +		uint64 quotient  = 0;
 18.4302 +		uint64 remainder = 0;
 18.4303 +
 18.4304 +		if(divisor != 0)
 18.4305 +		{
 18.4306 +			if(BIT_A(word2))	/* 64 bit */
 18.4307 +			{
 18.4308 +				dividend = REG_D[word2 & 7];
 18.4309 +				dividend <<= 32;
 18.4310 +				dividend |= REG_D[(word2 >> 12) & 7];
 18.4311 +
 18.4312 +				if(BIT_B(word2))	   /* signed */
 18.4313 +				{
 18.4314 +					quotient  = (uint64)((sint64)dividend / (sint64)((sint32)divisor));
 18.4315 +					remainder = (uint64)((sint64)dividend % (sint64)((sint32)divisor));
 18.4316 +					if((sint64)quotient != (sint64)((sint32)quotient))
 18.4317 +					{
 18.4318 +						FLAG_V = VFLAG_SET;
 18.4319 +						return;
 18.4320 +					}
 18.4321 +				}
 18.4322 +				else					/* unsigned */
 18.4323 +				{
 18.4324 +					quotient = dividend / divisor;
 18.4325 +					if(quotient > 0xffffffff)
 18.4326 +					{
 18.4327 +						FLAG_V = VFLAG_SET;
 18.4328 +						return;
 18.4329 +					}
 18.4330 +					remainder = dividend % divisor;
 18.4331 +				}
 18.4332 +			}
 18.4333 +			else	/* 32 bit */
 18.4334 +			{
 18.4335 +				dividend = REG_D[(word2 >> 12) & 7];
 18.4336 +				if(BIT_B(word2))	   /* signed */
 18.4337 +				{
 18.4338 +					quotient  = (uint64)((sint64)((sint32)dividend) / (sint64)((sint32)divisor));
 18.4339 +					remainder = (uint64)((sint64)((sint32)dividend) % (sint64)((sint32)divisor));
 18.4340 +				}
 18.4341 +				else					/* unsigned */
 18.4342 +				{
 18.4343 +					quotient = dividend / divisor;
 18.4344 +					remainder = dividend % divisor;
 18.4345 +				}
 18.4346 +			}
 18.4347 +
 18.4348 +			REG_D[word2 & 7] = remainder;
 18.4349 +			REG_D[(word2 >> 12) & 7] = quotient;
 18.4350 +
 18.4351 +			FLAG_N = NFLAG_32(quotient);
 18.4352 +			FLAG_Z = quotient;
 18.4353 +			FLAG_V = VFLAG_CLEAR;
 18.4354 +			FLAG_C = CFLAG_CLEAR;
 18.4355 +			return;
 18.4356 +		}
 18.4357 +		m68ki_exception_trap(EXCEPTION_ZERO_DIVIDE);
 18.4358 +		return;
 18.4359 +	}
 18.4360 +	m68ki_exception_illegal();
 18.4361 +
 18.4362 +#else
 18.4363 +
 18.4364 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.4365 +	{
 18.4366 +		uint word2 = OPER_I_16();
 18.4367 +		uint divisor = DY;
 18.4368 +		uint dividend_hi = REG_D[word2 & 7];
 18.4369 +		uint dividend_lo = REG_D[(word2 >> 12) & 7];
 18.4370 +		uint quotient = 0;
 18.4371 +		uint remainder = 0;
 18.4372 +		uint dividend_neg = 0;
 18.4373 +		uint divisor_neg = 0;
 18.4374 +		sint i;
 18.4375 +		uint overflow;
 18.4376 +
 18.4377 +		if(divisor != 0)
 18.4378 +		{
 18.4379 +			/* quad / long : long quotient, long remainder */
 18.4380 +			if(BIT_A(word2))
 18.4381 +			{
 18.4382 +				if(BIT_B(word2))	   /* signed */
 18.4383 +				{
 18.4384 +					/* special case in signed divide */
 18.4385 +					if(dividend_hi == 0 && dividend_lo == 0x80000000 && divisor == 0xffffffff)
 18.4386 +					{
 18.4387 +						REG_D[word2 & 7] = 0;
 18.4388 +						REG_D[(word2 >> 12) & 7] = 0x80000000;
 18.4389 +
 18.4390 +						FLAG_N = NFLAG_SET;
 18.4391 +						FLAG_Z = ZFLAG_CLEAR;
 18.4392 +						FLAG_V = VFLAG_CLEAR;
 18.4393 +						FLAG_C = CFLAG_CLEAR;
 18.4394 +						return;
 18.4395 +					}
 18.4396 +					if(GET_MSB_32(dividend_hi))
 18.4397 +					{
 18.4398 +						dividend_neg = 1;
 18.4399 +						dividend_hi = (uint)MASK_OUT_ABOVE_32((-(sint)dividend_hi) - (dividend_lo != 0));
 18.4400 +						dividend_lo = (uint)MASK_OUT_ABOVE_32(-(sint)dividend_lo);
 18.4401 +					}
 18.4402 +					if(GET_MSB_32(divisor))
 18.4403 +					{
 18.4404 +						divisor_neg = 1;
 18.4405 +						divisor = (uint)MASK_OUT_ABOVE_32(-(sint)divisor);
 18.4406 +
 18.4407 +					}
 18.4408 +				}
 18.4409 +
 18.4410 +				/* if the upper long is greater than the divisor, we're overflowing. */
 18.4411 +				if(dividend_hi >= divisor)
 18.4412 +				{
 18.4413 +					FLAG_V = VFLAG_SET;
 18.4414 +					return;
 18.4415 +				}
 18.4416 +
 18.4417 +				for(i = 31; i >= 0; i--)
 18.4418 +				{
 18.4419 +					quotient <<= 1;
 18.4420 +					remainder = (remainder << 1) + ((dividend_hi >> i) & 1);
 18.4421 +					if(remainder >= divisor)
 18.4422 +					{
 18.4423 +						remainder -= divisor;
 18.4424 +						quotient++;
 18.4425 +					}
 18.4426 +				}
 18.4427 +				for(i = 31; i >= 0; i--)
 18.4428 +				{
 18.4429 +					quotient <<= 1;
 18.4430 +					overflow = GET_MSB_32(remainder);
 18.4431 +					remainder = (remainder << 1) + ((dividend_lo >> i) & 1);
 18.4432 +					if(remainder >= divisor || overflow)
 18.4433 +					{
 18.4434 +						remainder -= divisor;
 18.4435 +						quotient++;
 18.4436 +					}
 18.4437 +				}
 18.4438 +
 18.4439 +				if(BIT_B(word2))	   /* signed */
 18.4440 +				{
 18.4441 +					if(quotient > 0x7fffffff)
 18.4442 +					{
 18.4443 +						FLAG_V = VFLAG_SET;
 18.4444 +						return;
 18.4445 +					}
 18.4446 +					if(dividend_neg)
 18.4447 +					{
 18.4448 +						remainder = (uint)MASK_OUT_ABOVE_32(-(sint)remainder);
 18.4449 +						quotient = (uint)MASK_OUT_ABOVE_32(-(sint)quotient);
 18.4450 +					}
 18.4451 +					if(divisor_neg)
 18.4452 +						quotient = (uint)MASK_OUT_ABOVE_32(-(sint)quotient);
 18.4453 +				}
 18.4454 +
 18.4455 +				REG_D[word2 & 7] = remainder;
 18.4456 +				REG_D[(word2 >> 12) & 7] = quotient;
 18.4457 +
 18.4458 +				FLAG_N = NFLAG_32(quotient);
 18.4459 +				FLAG_Z = quotient;
 18.4460 +				FLAG_V = VFLAG_CLEAR;
 18.4461 +				FLAG_C = CFLAG_CLEAR;
 18.4462 +				return;
 18.4463 +			}
 18.4464 +
 18.4465 +			/* long / long: long quotient, maybe long remainder */
 18.4466 +			if(BIT_B(word2))	   /* signed */
 18.4467 +			{
 18.4468 +				/* Special case in divide */
 18.4469 +				if(dividend_lo == 0x80000000 && divisor == 0xffffffff)
 18.4470 +				{
 18.4471 +					FLAG_N = NFLAG_SET;
 18.4472 +					FLAG_Z = ZFLAG_CLEAR;
 18.4473 +					FLAG_V = VFLAG_CLEAR;
 18.4474 +					FLAG_C = CFLAG_CLEAR;
 18.4475 +					REG_D[(word2 >> 12) & 7] = 0x80000000;
 18.4476 +					REG_D[word2 & 7] = 0;
 18.4477 +					return;
 18.4478 +				}
 18.4479 +				REG_D[word2 & 7] = MAKE_INT_32(dividend_lo) % MAKE_INT_32(divisor);
 18.4480 +				quotient = REG_D[(word2 >> 12) & 7] = MAKE_INT_32(dividend_lo) / MAKE_INT_32(divisor);
 18.4481 +			}
 18.4482 +			else
 18.4483 +			{
 18.4484 +				REG_D[word2 & 7] = MASK_OUT_ABOVE_32(dividend_lo) % MASK_OUT_ABOVE_32(divisor);
 18.4485 +				quotient = REG_D[(word2 >> 12) & 7] = MASK_OUT_ABOVE_32(dividend_lo) / MASK_OUT_ABOVE_32(divisor);
 18.4486 +			}
 18.4487 +
 18.4488 +			FLAG_N = NFLAG_32(quotient);
 18.4489 +			FLAG_Z = quotient;
 18.4490 +			FLAG_V = VFLAG_CLEAR;
 18.4491 +			FLAG_C = CFLAG_CLEAR;
 18.4492 +			return;
 18.4493 +		}
 18.4494 +		m68ki_exception_trap(EXCEPTION_ZERO_DIVIDE);
 18.4495 +		return;
 18.4496 +	}
 18.4497 +	m68ki_exception_illegal();
 18.4498 +
 18.4499 +#endif
 18.4500 +}
 18.4501 +
 18.4502 +
 18.4503 +M68KMAKE_OP(divl, 32, ., .)
 18.4504 +{
 18.4505 +#if M68K_USE_64_BIT
 18.4506 +
 18.4507 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.4508 +	{
 18.4509 +		uint word2 = OPER_I_16();
 18.4510 +		uint64 divisor = M68KMAKE_GET_OPER_AY_32;
 18.4511 +		uint64 dividend  = 0;
 18.4512 +		uint64 quotient  = 0;
 18.4513 +		uint64 remainder = 0;
 18.4514 +
 18.4515 +		if(divisor != 0)
 18.4516 +		{
 18.4517 +			if(BIT_A(word2))	/* 64 bit */
 18.4518 +			{
 18.4519 +				dividend = REG_D[word2 & 7];
 18.4520 +				dividend <<= 32;
 18.4521 +				dividend |= REG_D[(word2 >> 12) & 7];
 18.4522 +
 18.4523 +				if(BIT_B(word2))	   /* signed */
 18.4524 +				{
 18.4525 +					quotient  = (uint64)((sint64)dividend / (sint64)((sint32)divisor));
 18.4526 +					remainder = (uint64)((sint64)dividend % (sint64)((sint32)divisor));
 18.4527 +					if((sint64)quotient != (sint64)((sint32)quotient))
 18.4528 +					{
 18.4529 +						FLAG_V = VFLAG_SET;
 18.4530 +						return;
 18.4531 +					}
 18.4532 +				}
 18.4533 +				else					/* unsigned */
 18.4534 +				{
 18.4535 +					quotient = dividend / divisor;
 18.4536 +					if(quotient > 0xffffffff)
 18.4537 +					{
 18.4538 +						FLAG_V = VFLAG_SET;
 18.4539 +						return;
 18.4540 +					}
 18.4541 +					remainder = dividend % divisor;
 18.4542 +				}
 18.4543 +			}
 18.4544 +			else	/* 32 bit */
 18.4545 +			{
 18.4546 +				dividend = REG_D[(word2 >> 12) & 7];
 18.4547 +				if(BIT_B(word2))	   /* signed */
 18.4548 +				{
 18.4549 +					quotient  = (uint64)((sint64)((sint32)dividend) / (sint64)((sint32)divisor));
 18.4550 +					remainder = (uint64)((sint64)((sint32)dividend) % (sint64)((sint32)divisor));
 18.4551 +				}
 18.4552 +				else					/* unsigned */
 18.4553 +				{
 18.4554 +					quotient = dividend / divisor;
 18.4555 +					remainder = dividend % divisor;
 18.4556 +				}
 18.4557 +			}
 18.4558 +
 18.4559 +			REG_D[word2 & 7] = remainder;
 18.4560 +			REG_D[(word2 >> 12) & 7] = quotient;
 18.4561 +
 18.4562 +			FLAG_N = NFLAG_32(quotient);
 18.4563 +			FLAG_Z = quotient;
 18.4564 +			FLAG_V = VFLAG_CLEAR;
 18.4565 +			FLAG_C = CFLAG_CLEAR;
 18.4566 +			return;
 18.4567 +		}
 18.4568 +		m68ki_exception_trap(EXCEPTION_ZERO_DIVIDE);
 18.4569 +		return;
 18.4570 +	}
 18.4571 +	m68ki_exception_illegal();
 18.4572 +
 18.4573 +#else
 18.4574 +
 18.4575 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.4576 +	{
 18.4577 +		uint word2 = OPER_I_16();
 18.4578 +		uint divisor = M68KMAKE_GET_OPER_AY_32;
 18.4579 +		uint dividend_hi = REG_D[word2 & 7];
 18.4580 +		uint dividend_lo = REG_D[(word2 >> 12) & 7];
 18.4581 +		uint quotient = 0;
 18.4582 +		uint remainder = 0;
 18.4583 +		uint dividend_neg = 0;
 18.4584 +		uint divisor_neg = 0;
 18.4585 +		sint i;
 18.4586 +		uint overflow;
 18.4587 +
 18.4588 +		if(divisor != 0)
 18.4589 +		{
 18.4590 +			/* quad / long : long quotient, long remainder */
 18.4591 +			if(BIT_A(word2))
 18.4592 +			{
 18.4593 +				if(BIT_B(word2))	   /* signed */
 18.4594 +				{
 18.4595 +					/* special case in signed divide */
 18.4596 +					if(dividend_hi == 0 && dividend_lo == 0x80000000 && divisor == 0xffffffff)
 18.4597 +					{
 18.4598 +						REG_D[word2 & 7] = 0;
 18.4599 +						REG_D[(word2 >> 12) & 7] = 0x80000000;
 18.4600 +
 18.4601 +						FLAG_N = NFLAG_SET;
 18.4602 +						FLAG_Z = ZFLAG_CLEAR;
 18.4603 +						FLAG_V = VFLAG_CLEAR;
 18.4604 +						FLAG_C = CFLAG_CLEAR;
 18.4605 +						return;
 18.4606 +					}
 18.4607 +					if(GET_MSB_32(dividend_hi))
 18.4608 +					{
 18.4609 +						dividend_neg = 1;
 18.4610 +						dividend_hi = (uint)MASK_OUT_ABOVE_32((-(sint)dividend_hi) - (dividend_lo != 0));
 18.4611 +						dividend_lo = (uint)MASK_OUT_ABOVE_32(-(sint)dividend_lo);
 18.4612 +					}
 18.4613 +					if(GET_MSB_32(divisor))
 18.4614 +					{
 18.4615 +						divisor_neg = 1;
 18.4616 +						divisor = (uint)MASK_OUT_ABOVE_32(-(sint)divisor);
 18.4617 +
 18.4618 +					}
 18.4619 +				}
 18.4620 +
 18.4621 +				/* if the upper long is greater than the divisor, we're overflowing. */
 18.4622 +				if(dividend_hi >= divisor)
 18.4623 +				{
 18.4624 +					FLAG_V = VFLAG_SET;
 18.4625 +					return;
 18.4626 +				}
 18.4627 +
 18.4628 +				for(i = 31; i >= 0; i--)
 18.4629 +				{
 18.4630 +					quotient <<= 1;
 18.4631 +					remainder = (remainder << 1) + ((dividend_hi >> i) & 1);
 18.4632 +					if(remainder >= divisor)
 18.4633 +					{
 18.4634 +						remainder -= divisor;
 18.4635 +						quotient++;
 18.4636 +					}
 18.4637 +				}
 18.4638 +				for(i = 31; i >= 0; i--)
 18.4639 +				{
 18.4640 +					quotient <<= 1;
 18.4641 +					overflow = GET_MSB_32(remainder);
 18.4642 +					remainder = (remainder << 1) + ((dividend_lo >> i) & 1);
 18.4643 +					if(remainder >= divisor || overflow)
 18.4644 +					{
 18.4645 +						remainder -= divisor;
 18.4646 +						quotient++;
 18.4647 +					}
 18.4648 +				}
 18.4649 +
 18.4650 +				if(BIT_B(word2))	   /* signed */
 18.4651 +				{
 18.4652 +					if(quotient > 0x7fffffff)
 18.4653 +					{
 18.4654 +						FLAG_V = VFLAG_SET;
 18.4655 +						return;
 18.4656 +					}
 18.4657 +					if(dividend_neg)
 18.4658 +					{
 18.4659 +						remainder = (uint)MASK_OUT_ABOVE_32(-(sint)remainder);
 18.4660 +						quotient = (uint)MASK_OUT_ABOVE_32(-(sint)quotient);
 18.4661 +					}
 18.4662 +					if(divisor_neg)
 18.4663 +						quotient = (uint)MASK_OUT_ABOVE_32(-(sint)quotient);
 18.4664 +				}
 18.4665 +
 18.4666 +				REG_D[word2 & 7] = remainder;
 18.4667 +				REG_D[(word2 >> 12) & 7] = quotient;
 18.4668 +
 18.4669 +				FLAG_N = NFLAG_32(quotient);
 18.4670 +				FLAG_Z = quotient;
 18.4671 +				FLAG_V = VFLAG_CLEAR;
 18.4672 +				FLAG_C = CFLAG_CLEAR;
 18.4673 +				return;
 18.4674 +			}
 18.4675 +
 18.4676 +			/* long / long: long quotient, maybe long remainder */
 18.4677 +			if(BIT_B(word2))	   /* signed */
 18.4678 +			{
 18.4679 +				/* Special case in divide */
 18.4680 +				if(dividend_lo == 0x80000000 && divisor == 0xffffffff)
 18.4681 +				{
 18.4682 +					FLAG_N = NFLAG_SET;
 18.4683 +					FLAG_Z = ZFLAG_CLEAR;
 18.4684 +					FLAG_V = VFLAG_CLEAR;
 18.4685 +					FLAG_C = CFLAG_CLEAR;
 18.4686 +					REG_D[(word2 >> 12) & 7] = 0x80000000;
 18.4687 +					REG_D[word2 & 7] = 0;
 18.4688 +					return;
 18.4689 +				}
 18.4690 +				REG_D[word2 & 7] = MAKE_INT_32(dividend_lo) % MAKE_INT_32(divisor);
 18.4691 +				quotient = REG_D[(word2 >> 12) & 7] = MAKE_INT_32(dividend_lo) / MAKE_INT_32(divisor);
 18.4692 +			}
 18.4693 +			else
 18.4694 +			{
 18.4695 +				REG_D[word2 & 7] = MASK_OUT_ABOVE_32(dividend_lo) % MASK_OUT_ABOVE_32(divisor);
 18.4696 +				quotient = REG_D[(word2 >> 12) & 7] = MASK_OUT_ABOVE_32(dividend_lo) / MASK_OUT_ABOVE_32(divisor);
 18.4697 +			}
 18.4698 +
 18.4699 +			FLAG_N = NFLAG_32(quotient);
 18.4700 +			FLAG_Z = quotient;
 18.4701 +			FLAG_V = VFLAG_CLEAR;
 18.4702 +			FLAG_C = CFLAG_CLEAR;
 18.4703 +			return;
 18.4704 +		}
 18.4705 +		m68ki_exception_trap(EXCEPTION_ZERO_DIVIDE);
 18.4706 +		return;
 18.4707 +	}
 18.4708 +	m68ki_exception_illegal();
 18.4709 +
 18.4710 +#endif
 18.4711 +}
 18.4712 +
 18.4713 +
 18.4714 +M68KMAKE_OP(eor, 8, ., d)
 18.4715 +{
 18.4716 +	uint res = MASK_OUT_ABOVE_8(DY ^= MASK_OUT_ABOVE_8(DX));
 18.4717 +
 18.4718 +	FLAG_N = NFLAG_8(res);
 18.4719 +	FLAG_Z = res;
 18.4720 +	FLAG_C = CFLAG_CLEAR;
 18.4721 +	FLAG_V = VFLAG_CLEAR;
 18.4722 +}
 18.4723 +
 18.4724 +
 18.4725 +M68KMAKE_OP(eor, 8, ., .)
 18.4726 +{
 18.4727 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.4728 +	uint res = MASK_OUT_ABOVE_8(DX ^ m68ki_read_8(ea));
 18.4729 +
 18.4730 +	m68ki_write_8(ea, res);
 18.4731 +
 18.4732 +	FLAG_N = NFLAG_8(res);
 18.4733 +	FLAG_Z = res;
 18.4734 +	FLAG_C = CFLAG_CLEAR;
 18.4735 +	FLAG_V = VFLAG_CLEAR;
 18.4736 +}
 18.4737 +
 18.4738 +
 18.4739 +M68KMAKE_OP(eor, 16, ., d)
 18.4740 +{
 18.4741 +	uint res = MASK_OUT_ABOVE_16(DY ^= MASK_OUT_ABOVE_16(DX));
 18.4742 +
 18.4743 +	FLAG_N = NFLAG_16(res);
 18.4744 +	FLAG_Z = res;
 18.4745 +	FLAG_C = CFLAG_CLEAR;
 18.4746 +	FLAG_V = VFLAG_CLEAR;
 18.4747 +}
 18.4748 +
 18.4749 +
 18.4750 +M68KMAKE_OP(eor, 16, ., .)
 18.4751 +{
 18.4752 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.4753 +	uint res = MASK_OUT_ABOVE_16(DX ^ m68ki_read_16(ea));
 18.4754 +
 18.4755 +	m68ki_write_16(ea, res);
 18.4756 +
 18.4757 +	FLAG_N = NFLAG_16(res);
 18.4758 +	FLAG_Z = res;
 18.4759 +	FLAG_C = CFLAG_CLEAR;
 18.4760 +	FLAG_V = VFLAG_CLEAR;
 18.4761 +}
 18.4762 +
 18.4763 +
 18.4764 +M68KMAKE_OP(eor, 32, ., d)
 18.4765 +{
 18.4766 +	uint res = DY ^= DX;
 18.4767 +
 18.4768 +	FLAG_N = NFLAG_32(res);
 18.4769 +	FLAG_Z = res;
 18.4770 +	FLAG_C = CFLAG_CLEAR;
 18.4771 +	FLAG_V = VFLAG_CLEAR;
 18.4772 +}
 18.4773 +
 18.4774 +
 18.4775 +M68KMAKE_OP(eor, 32, ., .)
 18.4776 +{
 18.4777 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.4778 +	uint res = DX ^ m68ki_read_32(ea);
 18.4779 +
 18.4780 +	m68ki_write_32(ea, res);
 18.4781 +
 18.4782 +	FLAG_N = NFLAG_32(res);
 18.4783 +	FLAG_Z = res;
 18.4784 +	FLAG_C = CFLAG_CLEAR;
 18.4785 +	FLAG_V = VFLAG_CLEAR;
 18.4786 +}
 18.4787 +
 18.4788 +
 18.4789 +M68KMAKE_OP(eori, 8, ., d)
 18.4790 +{
 18.4791 +	uint res = MASK_OUT_ABOVE_8(DY ^= OPER_I_8());
 18.4792 +
 18.4793 +	FLAG_N = NFLAG_8(res);
 18.4794 +	FLAG_Z = res;
 18.4795 +	FLAG_C = CFLAG_CLEAR;
 18.4796 +	FLAG_V = VFLAG_CLEAR;
 18.4797 +}
 18.4798 +
 18.4799 +
 18.4800 +M68KMAKE_OP(eori, 8, ., .)
 18.4801 +{
 18.4802 +	uint src = OPER_I_8();
 18.4803 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.4804 +	uint res = src ^ m68ki_read_8(ea);
 18.4805 +
 18.4806 +	m68ki_write_8(ea, res);
 18.4807 +
 18.4808 +	FLAG_N = NFLAG_8(res);
 18.4809 +	FLAG_Z = res;
 18.4810 +	FLAG_C = CFLAG_CLEAR;
 18.4811 +	FLAG_V = VFLAG_CLEAR;
 18.4812 +}
 18.4813 +
 18.4814 +
 18.4815 +M68KMAKE_OP(eori, 16, ., d)
 18.4816 +{
 18.4817 +	uint res = MASK_OUT_ABOVE_16(DY ^= OPER_I_16());
 18.4818 +
 18.4819 +	FLAG_N = NFLAG_16(res);
 18.4820 +	FLAG_Z = res;
 18.4821 +	FLAG_C = CFLAG_CLEAR;
 18.4822 +	FLAG_V = VFLAG_CLEAR;
 18.4823 +}
 18.4824 +
 18.4825 +
 18.4826 +M68KMAKE_OP(eori, 16, ., .)
 18.4827 +{
 18.4828 +	uint src = OPER_I_16();
 18.4829 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.4830 +	uint res = src ^ m68ki_read_16(ea);
 18.4831 +
 18.4832 +	m68ki_write_16(ea, res);
 18.4833 +
 18.4834 +	FLAG_N = NFLAG_16(res);
 18.4835 +	FLAG_Z = res;
 18.4836 +	FLAG_C = CFLAG_CLEAR;
 18.4837 +	FLAG_V = VFLAG_CLEAR;
 18.4838 +}
 18.4839 +
 18.4840 +
 18.4841 +M68KMAKE_OP(eori, 32, ., d)
 18.4842 +{
 18.4843 +	uint res = DY ^= OPER_I_32();
 18.4844 +
 18.4845 +	FLAG_N = NFLAG_32(res);
 18.4846 +	FLAG_Z = res;
 18.4847 +	FLAG_C = CFLAG_CLEAR;
 18.4848 +	FLAG_V = VFLAG_CLEAR;
 18.4849 +}
 18.4850 +
 18.4851 +
 18.4852 +M68KMAKE_OP(eori, 32, ., .)
 18.4853 +{
 18.4854 +	uint src = OPER_I_32();
 18.4855 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.4856 +	uint res = src ^ m68ki_read_32(ea);
 18.4857 +
 18.4858 +	m68ki_write_32(ea, res);
 18.4859 +
 18.4860 +	FLAG_N = NFLAG_32(res);
 18.4861 +	FLAG_Z = res;
 18.4862 +	FLAG_C = CFLAG_CLEAR;
 18.4863 +	FLAG_V = VFLAG_CLEAR;
 18.4864 +}
 18.4865 +
 18.4866 +
 18.4867 +M68KMAKE_OP(eori, 16, toc, .)
 18.4868 +{
 18.4869 +	m68ki_set_ccr(m68ki_get_ccr() ^ OPER_I_16());
 18.4870 +}
 18.4871 +
 18.4872 +
 18.4873 +M68KMAKE_OP(eori, 16, tos, .)
 18.4874 +{
 18.4875 +	if(FLAG_S)
 18.4876 +	{
 18.4877 +		uint src = OPER_I_16();
 18.4878 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.4879 +		m68ki_set_sr(m68ki_get_sr() ^ src);
 18.4880 +		return;
 18.4881 +	}
 18.4882 +	m68ki_exception_privilege_violation();
 18.4883 +}
 18.4884 +
 18.4885 +
 18.4886 +M68KMAKE_OP(exg, 32, dd, .)
 18.4887 +{
 18.4888 +	uint* reg_a = &DX;
 18.4889 +	uint* reg_b = &DY;
 18.4890 +	uint tmp = *reg_a;
 18.4891 +	*reg_a = *reg_b;
 18.4892 +	*reg_b = tmp;
 18.4893 +}
 18.4894 +
 18.4895 +
 18.4896 +M68KMAKE_OP(exg, 32, aa, .)
 18.4897 +{
 18.4898 +	uint* reg_a = &AX;
 18.4899 +	uint* reg_b = &AY;
 18.4900 +	uint tmp = *reg_a;
 18.4901 +	*reg_a = *reg_b;
 18.4902 +	*reg_b = tmp;
 18.4903 +}
 18.4904 +
 18.4905 +
 18.4906 +M68KMAKE_OP(exg, 32, da, .)
 18.4907 +{
 18.4908 +	uint* reg_a = &DX;
 18.4909 +	uint* reg_b = &AY;
 18.4910 +	uint tmp = *reg_a;
 18.4911 +	*reg_a = *reg_b;
 18.4912 +	*reg_b = tmp;
 18.4913 +}
 18.4914 +
 18.4915 +
 18.4916 +M68KMAKE_OP(ext, 16, ., .)
 18.4917 +{
 18.4918 +	uint* r_dst = &DY;
 18.4919 +
 18.4920 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | MASK_OUT_ABOVE_8(*r_dst) | (GET_MSB_8(*r_dst) ? 0xff00 : 0);
 18.4921 +
 18.4922 +	FLAG_N = NFLAG_16(*r_dst);
 18.4923 +	FLAG_Z = MASK_OUT_ABOVE_16(*r_dst);
 18.4924 +	FLAG_V = VFLAG_CLEAR;
 18.4925 +	FLAG_C = CFLAG_CLEAR;
 18.4926 +}
 18.4927 +
 18.4928 +
 18.4929 +M68KMAKE_OP(ext, 32, ., .)
 18.4930 +{
 18.4931 +	uint* r_dst = &DY;
 18.4932 +
 18.4933 +	*r_dst = MASK_OUT_ABOVE_16(*r_dst) | (GET_MSB_16(*r_dst) ? 0xffff0000 : 0);
 18.4934 +
 18.4935 +	FLAG_N = NFLAG_32(*r_dst);
 18.4936 +	FLAG_Z = *r_dst;
 18.4937 +	FLAG_V = VFLAG_CLEAR;
 18.4938 +	FLAG_C = CFLAG_CLEAR;
 18.4939 +}
 18.4940 +
 18.4941 +
 18.4942 +M68KMAKE_OP(extb, 32, ., .)
 18.4943 +{
 18.4944 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.4945 +	{
 18.4946 +		uint* r_dst = &DY;
 18.4947 +
 18.4948 +		*r_dst = MASK_OUT_ABOVE_8(*r_dst) | (GET_MSB_8(*r_dst) ? 0xffffff00 : 0);
 18.4949 +
 18.4950 +		FLAG_N = NFLAG_32(*r_dst);
 18.4951 +		FLAG_Z = *r_dst;
 18.4952 +		FLAG_V = VFLAG_CLEAR;
 18.4953 +		FLAG_C = CFLAG_CLEAR;
 18.4954 +		return;
 18.4955 +	}
 18.4956 +	m68ki_exception_illegal();
 18.4957 +}
 18.4958 +
 18.4959 +
 18.4960 +M68KMAKE_OP(illegal, 0, ., .)
 18.4961 +{
 18.4962 +	m68ki_exception_illegal();
 18.4963 +}
 18.4964 +
 18.4965 +M68KMAKE_OP(jmp, 32, ., .)
 18.4966 +{
 18.4967 +	m68ki_jump(M68KMAKE_GET_EA_AY_32);
 18.4968 +	m68ki_trace_t0();				   /* auto-disable (see m68kcpu.h) */
 18.4969 +	if(REG_PC == REG_PPC)
 18.4970 +		USE_ALL_CYCLES();
 18.4971 +}
 18.4972 +
 18.4973 +
 18.4974 +M68KMAKE_OP(jsr, 32, ., .)
 18.4975 +{
 18.4976 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.4977 +	m68ki_trace_t0();				   /* auto-disable (see m68kcpu.h) */
 18.4978 +	m68ki_push_32(REG_PC);
 18.4979 +	m68ki_jump(ea);
 18.4980 +}
 18.4981 +
 18.4982 +
 18.4983 +M68KMAKE_OP(lea, 32, ., .)
 18.4984 +{
 18.4985 +	AX = M68KMAKE_GET_EA_AY_32;
 18.4986 +}
 18.4987 +
 18.4988 +
 18.4989 +M68KMAKE_OP(link, 16, ., a7)
 18.4990 +{
 18.4991 +	REG_A[7] -= 4;
 18.4992 +	m68ki_write_32(REG_A[7], REG_A[7]);
 18.4993 +	REG_A[7] = MASK_OUT_ABOVE_32(REG_A[7] + MAKE_INT_16(OPER_I_16()));
 18.4994 +}
 18.4995 +
 18.4996 +
 18.4997 +M68KMAKE_OP(link, 16, ., .)
 18.4998 +{
 18.4999 +	uint* r_dst = &AY;
 18.5000 +
 18.5001 +	m68ki_push_32(*r_dst);
 18.5002 +	*r_dst = REG_A[7];
 18.5003 +	REG_A[7] = MASK_OUT_ABOVE_32(REG_A[7] + MAKE_INT_16(OPER_I_16()));
 18.5004 +}
 18.5005 +
 18.5006 +
 18.5007 +M68KMAKE_OP(link, 32, ., a7)
 18.5008 +{
 18.5009 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.5010 +	{
 18.5011 +		REG_A[7] -= 4;
 18.5012 +		m68ki_write_32(REG_A[7], REG_A[7]);
 18.5013 +		REG_A[7] = MASK_OUT_ABOVE_32(REG_A[7] + OPER_I_32());
 18.5014 +		return;
 18.5015 +	}
 18.5016 +	m68ki_exception_illegal();
 18.5017 +}
 18.5018 +
 18.5019 +
 18.5020 +M68KMAKE_OP(link, 32, ., .)
 18.5021 +{
 18.5022 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.5023 +	{
 18.5024 +		uint* r_dst = &AY;
 18.5025 +
 18.5026 +		m68ki_push_32(*r_dst);
 18.5027 +		*r_dst = REG_A[7];
 18.5028 +		REG_A[7] = MASK_OUT_ABOVE_32(REG_A[7] + OPER_I_32());
 18.5029 +		return;
 18.5030 +	}
 18.5031 +	m68ki_exception_illegal();
 18.5032 +}
 18.5033 +
 18.5034 +
 18.5035 +M68KMAKE_OP(lsr, 8, s, .)
 18.5036 +{
 18.5037 +	uint* r_dst = &DY;
 18.5038 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.5039 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.5040 +	uint res = src >> shift;
 18.5041 +
 18.5042 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.5043 +
 18.5044 +	FLAG_N = NFLAG_CLEAR;
 18.5045 +	FLAG_Z = res;
 18.5046 +	FLAG_X = FLAG_C = src << (9-shift);
 18.5047 +	FLAG_V = VFLAG_CLEAR;
 18.5048 +}
 18.5049 +
 18.5050 +
 18.5051 +M68KMAKE_OP(lsr, 16, s, .)
 18.5052 +{
 18.5053 +	uint* r_dst = &DY;
 18.5054 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.5055 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.5056 +	uint res = src >> shift;
 18.5057 +
 18.5058 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.5059 +
 18.5060 +	FLAG_N = NFLAG_CLEAR;
 18.5061 +	FLAG_Z = res;
 18.5062 +	FLAG_X = FLAG_C = src << (9-shift);
 18.5063 +	FLAG_V = VFLAG_CLEAR;
 18.5064 +}
 18.5065 +
 18.5066 +
 18.5067 +M68KMAKE_OP(lsr, 32, s, .)
 18.5068 +{
 18.5069 +	uint* r_dst = &DY;
 18.5070 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.5071 +	uint src = *r_dst;
 18.5072 +	uint res = src >> shift;
 18.5073 +
 18.5074 +	*r_dst = res;
 18.5075 +
 18.5076 +	FLAG_N = NFLAG_CLEAR;
 18.5077 +	FLAG_Z = res;
 18.5078 +	FLAG_X = FLAG_C = src << (9-shift);
 18.5079 +	FLAG_V = VFLAG_CLEAR;
 18.5080 +}
 18.5081 +
 18.5082 +
 18.5083 +M68KMAKE_OP(lsr, 8, r, .)
 18.5084 +{
 18.5085 +	uint* r_dst = &DY;
 18.5086 +	uint shift = DX & 0x3f;
 18.5087 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.5088 +	uint res = src >> shift;
 18.5089 +
 18.5090 +	if(shift != 0)
 18.5091 +	{
 18.5092 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.5093 +
 18.5094 +		if(shift <= 8)
 18.5095 +		{
 18.5096 +			*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.5097 +			FLAG_X = FLAG_C = src << (9-shift);
 18.5098 +			FLAG_N = NFLAG_CLEAR;
 18.5099 +			FLAG_Z = res;
 18.5100 +			FLAG_V = VFLAG_CLEAR;
 18.5101 +			return;
 18.5102 +		}
 18.5103 +
 18.5104 +		*r_dst &= 0xffffff00;
 18.5105 +		FLAG_X = XFLAG_CLEAR;
 18.5106 +		FLAG_C = CFLAG_CLEAR;
 18.5107 +		FLAG_N = NFLAG_CLEAR;
 18.5108 +		FLAG_Z = ZFLAG_SET;
 18.5109 +		FLAG_V = VFLAG_CLEAR;
 18.5110 +		return;
 18.5111 +	}
 18.5112 +
 18.5113 +	FLAG_C = CFLAG_CLEAR;
 18.5114 +	FLAG_N = NFLAG_8(src);
 18.5115 +	FLAG_Z = src;
 18.5116 +	FLAG_V = VFLAG_CLEAR;
 18.5117 +}
 18.5118 +
 18.5119 +
 18.5120 +M68KMAKE_OP(lsr, 16, r, .)
 18.5121 +{
 18.5122 +	uint* r_dst = &DY;
 18.5123 +	uint shift = DX & 0x3f;
 18.5124 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.5125 +	uint res = src >> shift;
 18.5126 +
 18.5127 +	if(shift != 0)
 18.5128 +	{
 18.5129 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.5130 +
 18.5131 +		if(shift <= 16)
 18.5132 +		{
 18.5133 +			*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.5134 +			FLAG_C = FLAG_X = (src >> (shift - 1))<<8;
 18.5135 +			FLAG_N = NFLAG_CLEAR;
 18.5136 +			FLAG_Z = res;
 18.5137 +			FLAG_V = VFLAG_CLEAR;
 18.5138 +			return;
 18.5139 +		}
 18.5140 +
 18.5141 +		*r_dst &= 0xffff0000;
 18.5142 +		FLAG_X = XFLAG_CLEAR;
 18.5143 +		FLAG_C = CFLAG_CLEAR;
 18.5144 +		FLAG_N = NFLAG_CLEAR;
 18.5145 +		FLAG_Z = ZFLAG_SET;
 18.5146 +		FLAG_V = VFLAG_CLEAR;
 18.5147 +		return;
 18.5148 +	}
 18.5149 +
 18.5150 +	FLAG_C = CFLAG_CLEAR;
 18.5151 +	FLAG_N = NFLAG_16(src);
 18.5152 +	FLAG_Z = src;
 18.5153 +	FLAG_V = VFLAG_CLEAR;
 18.5154 +}
 18.5155 +
 18.5156 +
 18.5157 +M68KMAKE_OP(lsr, 32, r, .)
 18.5158 +{
 18.5159 +	uint* r_dst = &DY;
 18.5160 +	uint shift = DX & 0x3f;
 18.5161 +	uint src = *r_dst;
 18.5162 +	uint res = src >> shift;
 18.5163 +
 18.5164 +	if(shift != 0)
 18.5165 +	{
 18.5166 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.5167 +
 18.5168 +		if(shift < 32)
 18.5169 +		{
 18.5170 +			*r_dst = res;
 18.5171 +			FLAG_C = FLAG_X = (src >> (shift - 1))<<8;
 18.5172 +			FLAG_N = NFLAG_CLEAR;
 18.5173 +			FLAG_Z = res;
 18.5174 +			FLAG_V = VFLAG_CLEAR;
 18.5175 +			return;
 18.5176 +		}
 18.5177 +
 18.5178 +		*r_dst = 0;
 18.5179 +		FLAG_X = FLAG_C = (shift == 32 ? GET_MSB_32(src)>>23 : 0);
 18.5180 +		FLAG_N = NFLAG_CLEAR;
 18.5181 +		FLAG_Z = ZFLAG_SET;
 18.5182 +		FLAG_V = VFLAG_CLEAR;
 18.5183 +		return;
 18.5184 +	}
 18.5185 +
 18.5186 +	FLAG_C = CFLAG_CLEAR;
 18.5187 +	FLAG_N = NFLAG_32(src);
 18.5188 +	FLAG_Z = src;
 18.5189 +	FLAG_V = VFLAG_CLEAR;
 18.5190 +}
 18.5191 +
 18.5192 +
 18.5193 +M68KMAKE_OP(lsr, 16, ., .)
 18.5194 +{
 18.5195 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.5196 +	uint src = m68ki_read_16(ea);
 18.5197 +	uint res = src >> 1;
 18.5198 +
 18.5199 +	m68ki_write_16(ea, res);
 18.5200 +
 18.5201 +	FLAG_N = NFLAG_CLEAR;
 18.5202 +	FLAG_Z = res;
 18.5203 +	FLAG_C = FLAG_X = src << 8;
 18.5204 +	FLAG_V = VFLAG_CLEAR;
 18.5205 +}
 18.5206 +
 18.5207 +
 18.5208 +M68KMAKE_OP(lsl, 8, s, .)
 18.5209 +{
 18.5210 +	uint* r_dst = &DY;
 18.5211 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.5212 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.5213 +	uint res = MASK_OUT_ABOVE_8(src << shift);
 18.5214 +
 18.5215 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.5216 +
 18.5217 +	FLAG_N = NFLAG_8(res);
 18.5218 +	FLAG_Z = res;
 18.5219 +	FLAG_X = FLAG_C = src << shift;
 18.5220 +	FLAG_V = VFLAG_CLEAR;
 18.5221 +}
 18.5222 +
 18.5223 +
 18.5224 +M68KMAKE_OP(lsl, 16, s, .)
 18.5225 +{
 18.5226 +	uint* r_dst = &DY;
 18.5227 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.5228 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.5229 +	uint res = MASK_OUT_ABOVE_16(src << shift);
 18.5230 +
 18.5231 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.5232 +
 18.5233 +	FLAG_N = NFLAG_16(res);
 18.5234 +	FLAG_Z = res;
 18.5235 +	FLAG_X = FLAG_C = src >> (8-shift);
 18.5236 +	FLAG_V = VFLAG_CLEAR;
 18.5237 +}
 18.5238 +
 18.5239 +
 18.5240 +M68KMAKE_OP(lsl, 32, s, .)
 18.5241 +{
 18.5242 +	uint* r_dst = &DY;
 18.5243 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.5244 +	uint src = *r_dst;
 18.5245 +	uint res = MASK_OUT_ABOVE_32(src << shift);
 18.5246 +
 18.5247 +	*r_dst = res;
 18.5248 +
 18.5249 +	FLAG_N = NFLAG_32(res);
 18.5250 +	FLAG_Z = res;
 18.5251 +	FLAG_X = FLAG_C = src >> (24-shift);
 18.5252 +	FLAG_V = VFLAG_CLEAR;
 18.5253 +}
 18.5254 +
 18.5255 +
 18.5256 +M68KMAKE_OP(lsl, 8, r, .)
 18.5257 +{
 18.5258 +	uint* r_dst = &DY;
 18.5259 +	uint shift = DX & 0x3f;
 18.5260 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.5261 +	uint res = MASK_OUT_ABOVE_8(src << shift);
 18.5262 +
 18.5263 +	if(shift != 0)
 18.5264 +	{
 18.5265 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.5266 +
 18.5267 +		if(shift <= 8)
 18.5268 +		{
 18.5269 +			*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.5270 +			FLAG_X = FLAG_C = src << shift;
 18.5271 +			FLAG_N = NFLAG_8(res);
 18.5272 +			FLAG_Z = res;
 18.5273 +			FLAG_V = VFLAG_CLEAR;
 18.5274 +			return;
 18.5275 +		}
 18.5276 +
 18.5277 +		*r_dst &= 0xffffff00;
 18.5278 +		FLAG_X = XFLAG_CLEAR;
 18.5279 +		FLAG_C = CFLAG_CLEAR;
 18.5280 +		FLAG_N = NFLAG_CLEAR;
 18.5281 +		FLAG_Z = ZFLAG_SET;
 18.5282 +		FLAG_V = VFLAG_CLEAR;
 18.5283 +		return;
 18.5284 +	}
 18.5285 +
 18.5286 +	FLAG_C = CFLAG_CLEAR;
 18.5287 +	FLAG_N = NFLAG_8(src);
 18.5288 +	FLAG_Z = src;
 18.5289 +	FLAG_V = VFLAG_CLEAR;
 18.5290 +}
 18.5291 +
 18.5292 +
 18.5293 +M68KMAKE_OP(lsl, 16, r, .)
 18.5294 +{
 18.5295 +	uint* r_dst = &DY;
 18.5296 +	uint shift = DX & 0x3f;
 18.5297 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.5298 +	uint res = MASK_OUT_ABOVE_16(src << shift);
 18.5299 +
 18.5300 +	if(shift != 0)
 18.5301 +	{
 18.5302 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.5303 +
 18.5304 +		if(shift <= 16)
 18.5305 +		{
 18.5306 +			*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.5307 +			FLAG_X = FLAG_C = (src << shift) >> 8;
 18.5308 +			FLAG_N = NFLAG_16(res);
 18.5309 +			FLAG_Z = res;
 18.5310 +			FLAG_V = VFLAG_CLEAR;
 18.5311 +			return;
 18.5312 +		}
 18.5313 +
 18.5314 +		*r_dst &= 0xffff0000;
 18.5315 +		FLAG_X = XFLAG_CLEAR;
 18.5316 +		FLAG_C = CFLAG_CLEAR;
 18.5317 +		FLAG_N = NFLAG_CLEAR;
 18.5318 +		FLAG_Z = ZFLAG_SET;
 18.5319 +		FLAG_V = VFLAG_CLEAR;
 18.5320 +		return;
 18.5321 +	}
 18.5322 +
 18.5323 +	FLAG_C = CFLAG_CLEAR;
 18.5324 +	FLAG_N = NFLAG_16(src);
 18.5325 +	FLAG_Z = src;
 18.5326 +	FLAG_V = VFLAG_CLEAR;
 18.5327 +}
 18.5328 +
 18.5329 +
 18.5330 +M68KMAKE_OP(lsl, 32, r, .)
 18.5331 +{
 18.5332 +	uint* r_dst = &DY;
 18.5333 +	uint shift = DX & 0x3f;
 18.5334 +	uint src = *r_dst;
 18.5335 +	uint res = MASK_OUT_ABOVE_32(src << shift);
 18.5336 +
 18.5337 +	if(shift != 0)
 18.5338 +	{
 18.5339 +		USE_CYCLES(shift<<CYC_SHIFT);
 18.5340 +
 18.5341 +		if(shift < 32)
 18.5342 +		{
 18.5343 +			*r_dst = res;
 18.5344 +			FLAG_X = FLAG_C = (src >> (32 - shift)) << 8;
 18.5345 +			FLAG_N = NFLAG_32(res);
 18.5346 +			FLAG_Z = res;
 18.5347 +			FLAG_V = VFLAG_CLEAR;
 18.5348 +			return;
 18.5349 +		}
 18.5350 +
 18.5351 +		*r_dst = 0;
 18.5352 +		FLAG_X = FLAG_C = ((shift == 32 ? src & 1 : 0))<<8;
 18.5353 +		FLAG_N = NFLAG_CLEAR;
 18.5354 +		FLAG_Z = ZFLAG_SET;
 18.5355 +		FLAG_V = VFLAG_CLEAR;
 18.5356 +		return;
 18.5357 +	}
 18.5358 +
 18.5359 +	FLAG_C = CFLAG_CLEAR;
 18.5360 +	FLAG_N = NFLAG_32(src);
 18.5361 +	FLAG_Z = src;
 18.5362 +	FLAG_V = VFLAG_CLEAR;
 18.5363 +}
 18.5364 +
 18.5365 +
 18.5366 +M68KMAKE_OP(lsl, 16, ., .)
 18.5367 +{
 18.5368 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.5369 +	uint src = m68ki_read_16(ea);
 18.5370 +	uint res = MASK_OUT_ABOVE_16(src << 1);
 18.5371 +
 18.5372 +	m68ki_write_16(ea, res);
 18.5373 +
 18.5374 +	FLAG_N = NFLAG_16(res);
 18.5375 +	FLAG_Z = res;
 18.5376 +	FLAG_X = FLAG_C = src >> 7;
 18.5377 +	FLAG_V = VFLAG_CLEAR;
 18.5378 +}
 18.5379 +
 18.5380 +
 18.5381 +M68KMAKE_OP(move, 8, d, d)
 18.5382 +{
 18.5383 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.5384 +	uint* r_dst = &DX;
 18.5385 +
 18.5386 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.5387 +
 18.5388 +	FLAG_N = NFLAG_8(res);
 18.5389 +	FLAG_Z = res;
 18.5390 +	FLAG_V = VFLAG_CLEAR;
 18.5391 +	FLAG_C = CFLAG_CLEAR;
 18.5392 +}
 18.5393 +
 18.5394 +
 18.5395 +M68KMAKE_OP(move, 8, d, .)
 18.5396 +{
 18.5397 +	uint res = M68KMAKE_GET_OPER_AY_8;
 18.5398 +	uint* r_dst = &DX;
 18.5399 +
 18.5400 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.5401 +
 18.5402 +	FLAG_N = NFLAG_8(res);
 18.5403 +	FLAG_Z = res;
 18.5404 +	FLAG_V = VFLAG_CLEAR;
 18.5405 +	FLAG_C = CFLAG_CLEAR;
 18.5406 +}
 18.5407 +
 18.5408 +
 18.5409 +M68KMAKE_OP(move, 8, ai, d)
 18.5410 +{
 18.5411 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.5412 +	uint ea = EA_AX_AI_8();
 18.5413 +
 18.5414 +	m68ki_write_8(ea, res);
 18.5415 +
 18.5416 +	FLAG_N = NFLAG_8(res);
 18.5417 +	FLAG_Z = res;
 18.5418 +	FLAG_V = VFLAG_CLEAR;
 18.5419 +	FLAG_C = CFLAG_CLEAR;
 18.5420 +}
 18.5421 +
 18.5422 +
 18.5423 +M68KMAKE_OP(move, 8, ai, .)
 18.5424 +{
 18.5425 +	uint res = M68KMAKE_GET_OPER_AY_8;
 18.5426 +	uint ea = EA_AX_AI_8();
 18.5427 +
 18.5428 +	m68ki_write_8(ea, res);
 18.5429 +
 18.5430 +	FLAG_N = NFLAG_8(res);
 18.5431 +	FLAG_Z = res;
 18.5432 +	FLAG_V = VFLAG_CLEAR;
 18.5433 +	FLAG_C = CFLAG_CLEAR;
 18.5434 +}
 18.5435 +
 18.5436 +
 18.5437 +M68KMAKE_OP(move, 8, pi7, d)
 18.5438 +{
 18.5439 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.5440 +	uint ea = EA_A7_PI_8();
 18.5441 +
 18.5442 +	m68ki_write_8(ea, res);
 18.5443 +
 18.5444 +	FLAG_N = NFLAG_8(res);
 18.5445 +	FLAG_Z = res;
 18.5446 +	FLAG_V = VFLAG_CLEAR;
 18.5447 +	FLAG_C = CFLAG_CLEAR;
 18.5448 +}
 18.5449 +
 18.5450 +
 18.5451 +M68KMAKE_OP(move, 8, pi, d)
 18.5452 +{
 18.5453 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.5454 +	uint ea = EA_AX_PI_8();
 18.5455 +
 18.5456 +	m68ki_write_8(ea, res);
 18.5457 +
 18.5458 +	FLAG_N = NFLAG_8(res);
 18.5459 +	FLAG_Z = res;
 18.5460 +	FLAG_V = VFLAG_CLEAR;
 18.5461 +	FLAG_C = CFLAG_CLEAR;
 18.5462 +}
 18.5463 +
 18.5464 +
 18.5465 +M68KMAKE_OP(move, 8, pi7, .)
 18.5466 +{
 18.5467 +	uint res = M68KMAKE_GET_OPER_AY_8;
 18.5468 +	uint ea = EA_A7_PI_8();
 18.5469 +
 18.5470 +	m68ki_write_8(ea, res);
 18.5471 +
 18.5472 +	FLAG_N = NFLAG_8(res);
 18.5473 +	FLAG_Z = res;
 18.5474 +	FLAG_V = VFLAG_CLEAR;
 18.5475 +	FLAG_C = CFLAG_CLEAR;
 18.5476 +}
 18.5477 +
 18.5478 +
 18.5479 +M68KMAKE_OP(move, 8, pi, .)
 18.5480 +{
 18.5481 +	uint res = M68KMAKE_GET_OPER_AY_8;
 18.5482 +	uint ea = EA_AX_PI_8();
 18.5483 +
 18.5484 +	m68ki_write_8(ea, res);
 18.5485 +
 18.5486 +	FLAG_N = NFLAG_8(res);
 18.5487 +	FLAG_Z = res;
 18.5488 +	FLAG_V = VFLAG_CLEAR;
 18.5489 +	FLAG_C = CFLAG_CLEAR;
 18.5490 +}
 18.5491 +
 18.5492 +
 18.5493 +M68KMAKE_OP(move, 8, pd7, d)
 18.5494 +{
 18.5495 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.5496 +	uint ea = EA_A7_PD_8();
 18.5497 +
 18.5498 +	m68ki_write_8(ea, res);
 18.5499 +
 18.5500 +	FLAG_N = NFLAG_8(res);
 18.5501 +	FLAG_Z = res;
 18.5502 +	FLAG_V = VFLAG_CLEAR;
 18.5503 +	FLAG_C = CFLAG_CLEAR;
 18.5504 +}
 18.5505 +
 18.5506 +
 18.5507 +M68KMAKE_OP(move, 8, pd, d)
 18.5508 +{
 18.5509 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.5510 +	uint ea = EA_AX_PD_8();
 18.5511 +
 18.5512 +	m68ki_write_8(ea, res);
 18.5513 +
 18.5514 +	FLAG_N = NFLAG_8(res);
 18.5515 +	FLAG_Z = res;
 18.5516 +	FLAG_V = VFLAG_CLEAR;
 18.5517 +	FLAG_C = CFLAG_CLEAR;
 18.5518 +}
 18.5519 +
 18.5520 +
 18.5521 +M68KMAKE_OP(move, 8, pd7, .)
 18.5522 +{
 18.5523 +	uint res = M68KMAKE_GET_OPER_AY_8;
 18.5524 +	uint ea = EA_A7_PD_8();
 18.5525 +
 18.5526 +	m68ki_write_8(ea, res);
 18.5527 +
 18.5528 +	FLAG_N = NFLAG_8(res);
 18.5529 +	FLAG_Z = res;
 18.5530 +	FLAG_V = VFLAG_CLEAR;
 18.5531 +	FLAG_C = CFLAG_CLEAR;
 18.5532 +}
 18.5533 +
 18.5534 +
 18.5535 +M68KMAKE_OP(move, 8, pd, .)
 18.5536 +{
 18.5537 +	uint res = M68KMAKE_GET_OPER_AY_8;
 18.5538 +	uint ea = EA_AX_PD_8();
 18.5539 +
 18.5540 +	m68ki_write_8(ea, res);
 18.5541 +
 18.5542 +	FLAG_N = NFLAG_8(res);
 18.5543 +	FLAG_Z = res;
 18.5544 +	FLAG_V = VFLAG_CLEAR;
 18.5545 +	FLAG_C = CFLAG_CLEAR;
 18.5546 +}
 18.5547 +
 18.5548 +
 18.5549 +M68KMAKE_OP(move, 8, di, d)
 18.5550 +{
 18.5551 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.5552 +	uint ea = EA_AX_DI_8();
 18.5553 +
 18.5554 +	m68ki_write_8(ea, res);
 18.5555 +
 18.5556 +	FLAG_N = NFLAG_8(res);
 18.5557 +	FLAG_Z = res;
 18.5558 +	FLAG_V = VFLAG_CLEAR;
 18.5559 +	FLAG_C = CFLAG_CLEAR;
 18.5560 +}
 18.5561 +
 18.5562 +
 18.5563 +M68KMAKE_OP(move, 8, di, .)
 18.5564 +{
 18.5565 +	uint res = M68KMAKE_GET_OPER_AY_8;
 18.5566 +	uint ea = EA_AX_DI_8();
 18.5567 +
 18.5568 +	m68ki_write_8(ea, res);
 18.5569 +
 18.5570 +	FLAG_N = NFLAG_8(res);
 18.5571 +	FLAG_Z = res;
 18.5572 +	FLAG_V = VFLAG_CLEAR;
 18.5573 +	FLAG_C = CFLAG_CLEAR;
 18.5574 +}
 18.5575 +
 18.5576 +
 18.5577 +M68KMAKE_OP(move, 8, ix, d)
 18.5578 +{
 18.5579 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.5580 +	uint ea = EA_AX_IX_8();
 18.5581 +
 18.5582 +	m68ki_write_8(ea, res);
 18.5583 +
 18.5584 +	FLAG_N = NFLAG_8(res);
 18.5585 +	FLAG_Z = res;
 18.5586 +	FLAG_V = VFLAG_CLEAR;
 18.5587 +	FLAG_C = CFLAG_CLEAR;
 18.5588 +}
 18.5589 +
 18.5590 +
 18.5591 +M68KMAKE_OP(move, 8, ix, .)
 18.5592 +{
 18.5593 +	uint res = M68KMAKE_GET_OPER_AY_8;
 18.5594 +	uint ea = EA_AX_IX_8();
 18.5595 +
 18.5596 +	m68ki_write_8(ea, res);
 18.5597 +
 18.5598 +	FLAG_N = NFLAG_8(res);
 18.5599 +	FLAG_Z = res;
 18.5600 +	FLAG_V = VFLAG_CLEAR;
 18.5601 +	FLAG_C = CFLAG_CLEAR;
 18.5602 +}
 18.5603 +
 18.5604 +
 18.5605 +M68KMAKE_OP(move, 8, aw, d)
 18.5606 +{
 18.5607 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.5608 +	uint ea = EA_AW_8();
 18.5609 +
 18.5610 +	m68ki_write_8(ea, res);
 18.5611 +
 18.5612 +	FLAG_N = NFLAG_8(res);
 18.5613 +	FLAG_Z = res;
 18.5614 +	FLAG_V = VFLAG_CLEAR;
 18.5615 +	FLAG_C = CFLAG_CLEAR;
 18.5616 +}
 18.5617 +
 18.5618 +
 18.5619 +M68KMAKE_OP(move, 8, aw, .)
 18.5620 +{
 18.5621 +	uint res = M68KMAKE_GET_OPER_AY_8;
 18.5622 +	uint ea = EA_AW_8();
 18.5623 +
 18.5624 +	m68ki_write_8(ea, res);
 18.5625 +
 18.5626 +	FLAG_N = NFLAG_8(res);
 18.5627 +	FLAG_Z = res;
 18.5628 +	FLAG_V = VFLAG_CLEAR;
 18.5629 +	FLAG_C = CFLAG_CLEAR;
 18.5630 +}
 18.5631 +
 18.5632 +
 18.5633 +M68KMAKE_OP(move, 8, al, d)
 18.5634 +{
 18.5635 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.5636 +	uint ea = EA_AL_8();
 18.5637 +
 18.5638 +	m68ki_write_8(ea, res);
 18.5639 +
 18.5640 +	FLAG_N = NFLAG_8(res);
 18.5641 +	FLAG_Z = res;
 18.5642 +	FLAG_V = VFLAG_CLEAR;
 18.5643 +	FLAG_C = CFLAG_CLEAR;
 18.5644 +}
 18.5645 +
 18.5646 +
 18.5647 +M68KMAKE_OP(move, 8, al, .)
 18.5648 +{
 18.5649 +	uint res = M68KMAKE_GET_OPER_AY_8;
 18.5650 +	uint ea = EA_AL_8();
 18.5651 +
 18.5652 +	m68ki_write_8(ea, res);
 18.5653 +
 18.5654 +	FLAG_N = NFLAG_8(res);
 18.5655 +	FLAG_Z = res;
 18.5656 +	FLAG_V = VFLAG_CLEAR;
 18.5657 +	FLAG_C = CFLAG_CLEAR;
 18.5658 +}
 18.5659 +
 18.5660 +
 18.5661 +M68KMAKE_OP(move, 16, d, d)
 18.5662 +{
 18.5663 +	uint res = MASK_OUT_ABOVE_16(DY);
 18.5664 +	uint* r_dst = &DX;
 18.5665 +
 18.5666 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.5667 +
 18.5668 +	FLAG_N = NFLAG_16(res);
 18.5669 +	FLAG_Z = res;
 18.5670 +	FLAG_V = VFLAG_CLEAR;
 18.5671 +	FLAG_C = CFLAG_CLEAR;
 18.5672 +}
 18.5673 +
 18.5674 +
 18.5675 +M68KMAKE_OP(move, 16, d, a)
 18.5676 +{
 18.5677 +	uint res = MASK_OUT_ABOVE_16(AY);
 18.5678 +	uint* r_dst = &DX;
 18.5679 +
 18.5680 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.5681 +
 18.5682 +	FLAG_N = NFLAG_16(res);
 18.5683 +	FLAG_Z = res;
 18.5684 +	FLAG_V = VFLAG_CLEAR;
 18.5685 +	FLAG_C = CFLAG_CLEAR;
 18.5686 +}
 18.5687 +
 18.5688 +
 18.5689 +M68KMAKE_OP(move, 16, d, .)
 18.5690 +{
 18.5691 +	uint res = M68KMAKE_GET_OPER_AY_16;
 18.5692 +	uint* r_dst = &DX;
 18.5693 +
 18.5694 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.5695 +
 18.5696 +	FLAG_N = NFLAG_16(res);
 18.5697 +	FLAG_Z = res;
 18.5698 +	FLAG_V = VFLAG_CLEAR;
 18.5699 +	FLAG_C = CFLAG_CLEAR;
 18.5700 +}
 18.5701 +
 18.5702 +
 18.5703 +M68KMAKE_OP(move, 16, ai, d)
 18.5704 +{
 18.5705 +	uint res = MASK_OUT_ABOVE_16(DY);
 18.5706 +	uint ea = EA_AX_AI_16();
 18.5707 +
 18.5708 +	m68ki_write_16(ea, res);
 18.5709 +
 18.5710 +	FLAG_N = NFLAG_16(res);
 18.5711 +	FLAG_Z = res;
 18.5712 +	FLAG_V = VFLAG_CLEAR;
 18.5713 +	FLAG_C = CFLAG_CLEAR;
 18.5714 +}
 18.5715 +
 18.5716 +
 18.5717 +M68KMAKE_OP(move, 16, ai, a)
 18.5718 +{
 18.5719 +	uint res = MASK_OUT_ABOVE_16(AY);
 18.5720 +	uint ea = EA_AX_AI_16();
 18.5721 +
 18.5722 +	m68ki_write_16(ea, res);
 18.5723 +
 18.5724 +	FLAG_N = NFLAG_16(res);
 18.5725 +	FLAG_Z = res;
 18.5726 +	FLAG_V = VFLAG_CLEAR;
 18.5727 +	FLAG_C = CFLAG_CLEAR;
 18.5728 +}
 18.5729 +
 18.5730 +
 18.5731 +M68KMAKE_OP(move, 16, ai, .)
 18.5732 +{
 18.5733 +	uint res = M68KMAKE_GET_OPER_AY_16;
 18.5734 +	uint ea = EA_AX_AI_16();
 18.5735 +
 18.5736 +	m68ki_write_16(ea, res);
 18.5737 +
 18.5738 +	FLAG_N = NFLAG_16(res);
 18.5739 +	FLAG_Z = res;
 18.5740 +	FLAG_V = VFLAG_CLEAR;
 18.5741 +	FLAG_C = CFLAG_CLEAR;
 18.5742 +}
 18.5743 +
 18.5744 +
 18.5745 +M68KMAKE_OP(move, 16, pi, d)
 18.5746 +{
 18.5747 +	uint res = MASK_OUT_ABOVE_16(DY);
 18.5748 +	uint ea = EA_AX_PI_16();
 18.5749 +
 18.5750 +	m68ki_write_16(ea, res);
 18.5751 +
 18.5752 +	FLAG_N = NFLAG_16(res);
 18.5753 +	FLAG_Z = res;
 18.5754 +	FLAG_V = VFLAG_CLEAR;
 18.5755 +	FLAG_C = CFLAG_CLEAR;
 18.5756 +}
 18.5757 +
 18.5758 +
 18.5759 +M68KMAKE_OP(move, 16, pi, a)
 18.5760 +{
 18.5761 +	uint res = MASK_OUT_ABOVE_16(AY);
 18.5762 +	uint ea = EA_AX_PI_16();
 18.5763 +
 18.5764 +	m68ki_write_16(ea, res);
 18.5765 +
 18.5766 +	FLAG_N = NFLAG_16(res);
 18.5767 +	FLAG_Z = res;
 18.5768 +	FLAG_V = VFLAG_CLEAR;
 18.5769 +	FLAG_C = CFLAG_CLEAR;
 18.5770 +}
 18.5771 +
 18.5772 +
 18.5773 +M68KMAKE_OP(move, 16, pi, .)
 18.5774 +{
 18.5775 +	uint res = M68KMAKE_GET_OPER_AY_16;
 18.5776 +	uint ea = EA_AX_PI_16();
 18.5777 +
 18.5778 +	m68ki_write_16(ea, res);
 18.5779 +
 18.5780 +	FLAG_N = NFLAG_16(res);
 18.5781 +	FLAG_Z = res;
 18.5782 +	FLAG_V = VFLAG_CLEAR;
 18.5783 +	FLAG_C = CFLAG_CLEAR;
 18.5784 +}
 18.5785 +
 18.5786 +
 18.5787 +M68KMAKE_OP(move, 16, pd, d)
 18.5788 +{
 18.5789 +	uint res = MASK_OUT_ABOVE_16(DY);
 18.5790 +	uint ea = EA_AX_PD_16();
 18.5791 +
 18.5792 +	m68ki_write_16(ea, res);
 18.5793 +
 18.5794 +	FLAG_N = NFLAG_16(res);
 18.5795 +	FLAG_Z = res;
 18.5796 +	FLAG_V = VFLAG_CLEAR;
 18.5797 +	FLAG_C = CFLAG_CLEAR;
 18.5798 +}
 18.5799 +
 18.5800 +
 18.5801 +M68KMAKE_OP(move, 16, pd, a)
 18.5802 +{
 18.5803 +	uint res = MASK_OUT_ABOVE_16(AY);
 18.5804 +	uint ea = EA_AX_PD_16();
 18.5805 +
 18.5806 +	m68ki_write_16(ea, res);
 18.5807 +
 18.5808 +	FLAG_N = NFLAG_16(res);
 18.5809 +	FLAG_Z = res;
 18.5810 +	FLAG_V = VFLAG_CLEAR;
 18.5811 +	FLAG_C = CFLAG_CLEAR;
 18.5812 +}
 18.5813 +
 18.5814 +
 18.5815 +M68KMAKE_OP(move, 16, pd, .)
 18.5816 +{
 18.5817 +	uint res = M68KMAKE_GET_OPER_AY_16;
 18.5818 +	uint ea = EA_AX_PD_16();
 18.5819 +
 18.5820 +	m68ki_write_16(ea, res);
 18.5821 +
 18.5822 +	FLAG_N = NFLAG_16(res);
 18.5823 +	FLAG_Z = res;
 18.5824 +	FLAG_V = VFLAG_CLEAR;
 18.5825 +	FLAG_C = CFLAG_CLEAR;
 18.5826 +}
 18.5827 +
 18.5828 +
 18.5829 +M68KMAKE_OP(move, 16, di, d)
 18.5830 +{
 18.5831 +	uint res = MASK_OUT_ABOVE_16(DY);
 18.5832 +	uint ea = EA_AX_DI_16();
 18.5833 +
 18.5834 +	m68ki_write_16(ea, res);
 18.5835 +
 18.5836 +	FLAG_N = NFLAG_16(res);
 18.5837 +	FLAG_Z = res;
 18.5838 +	FLAG_V = VFLAG_CLEAR;
 18.5839 +	FLAG_C = CFLAG_CLEAR;
 18.5840 +}
 18.5841 +
 18.5842 +
 18.5843 +M68KMAKE_OP(move, 16, di, a)
 18.5844 +{
 18.5845 +	uint res = MASK_OUT_ABOVE_16(AY);
 18.5846 +	uint ea = EA_AX_DI_16();
 18.5847 +
 18.5848 +	m68ki_write_16(ea, res);
 18.5849 +
 18.5850 +	FLAG_N = NFLAG_16(res);
 18.5851 +	FLAG_Z = res;
 18.5852 +	FLAG_V = VFLAG_CLEAR;
 18.5853 +	FLAG_C = CFLAG_CLEAR;
 18.5854 +}
 18.5855 +
 18.5856 +
 18.5857 +M68KMAKE_OP(move, 16, di, .)
 18.5858 +{
 18.5859 +	uint res = M68KMAKE_GET_OPER_AY_16;
 18.5860 +	uint ea = EA_AX_DI_16();
 18.5861 +
 18.5862 +	m68ki_write_16(ea, res);
 18.5863 +
 18.5864 +	FLAG_N = NFLAG_16(res);
 18.5865 +	FLAG_Z = res;
 18.5866 +	FLAG_V = VFLAG_CLEAR;
 18.5867 +	FLAG_C = CFLAG_CLEAR;
 18.5868 +}
 18.5869 +
 18.5870 +
 18.5871 +M68KMAKE_OP(move, 16, ix, d)
 18.5872 +{
 18.5873 +	uint res = MASK_OUT_ABOVE_16(DY);
 18.5874 +	uint ea = EA_AX_IX_16();
 18.5875 +
 18.5876 +	m68ki_write_16(ea, res);
 18.5877 +
 18.5878 +	FLAG_N = NFLAG_16(res);
 18.5879 +	FLAG_Z = res;
 18.5880 +	FLAG_V = VFLAG_CLEAR;
 18.5881 +	FLAG_C = CFLAG_CLEAR;
 18.5882 +}
 18.5883 +
 18.5884 +
 18.5885 +M68KMAKE_OP(move, 16, ix, a)
 18.5886 +{
 18.5887 +	uint res = MASK_OUT_ABOVE_16(AY);
 18.5888 +	uint ea = EA_AX_IX_16();
 18.5889 +
 18.5890 +	m68ki_write_16(ea, res);
 18.5891 +
 18.5892 +	FLAG_N = NFLAG_16(res);
 18.5893 +	FLAG_Z = res;
 18.5894 +	FLAG_V = VFLAG_CLEAR;
 18.5895 +	FLAG_C = CFLAG_CLEAR;
 18.5896 +}
 18.5897 +
 18.5898 +
 18.5899 +M68KMAKE_OP(move, 16, ix, .)
 18.5900 +{
 18.5901 +	uint res = M68KMAKE_GET_OPER_AY_16;
 18.5902 +	uint ea = EA_AX_IX_16();
 18.5903 +
 18.5904 +	m68ki_write_16(ea, res);
 18.5905 +
 18.5906 +	FLAG_N = NFLAG_16(res);
 18.5907 +	FLAG_Z = res;
 18.5908 +	FLAG_V = VFLAG_CLEAR;
 18.5909 +	FLAG_C = CFLAG_CLEAR;
 18.5910 +}
 18.5911 +
 18.5912 +
 18.5913 +M68KMAKE_OP(move, 16, aw, d)
 18.5914 +{
 18.5915 +	uint res = MASK_OUT_ABOVE_16(DY);
 18.5916 +	uint ea = EA_AW_16();
 18.5917 +
 18.5918 +	m68ki_write_16(ea, res);
 18.5919 +
 18.5920 +	FLAG_N = NFLAG_16(res);
 18.5921 +	FLAG_Z = res;
 18.5922 +	FLAG_V = VFLAG_CLEAR;
 18.5923 +	FLAG_C = CFLAG_CLEAR;
 18.5924 +}
 18.5925 +
 18.5926 +
 18.5927 +M68KMAKE_OP(move, 16, aw, a)
 18.5928 +{
 18.5929 +	uint res = MASK_OUT_ABOVE_16(AY);
 18.5930 +	uint ea = EA_AW_16();
 18.5931 +
 18.5932 +	m68ki_write_16(ea, res);
 18.5933 +
 18.5934 +	FLAG_N = NFLAG_16(res);
 18.5935 +	FLAG_Z = res;
 18.5936 +	FLAG_V = VFLAG_CLEAR;
 18.5937 +	FLAG_C = CFLAG_CLEAR;
 18.5938 +}
 18.5939 +
 18.5940 +
 18.5941 +M68KMAKE_OP(move, 16, aw, .)
 18.5942 +{
 18.5943 +	uint res = M68KMAKE_GET_OPER_AY_16;
 18.5944 +	uint ea = EA_AW_16();
 18.5945 +
 18.5946 +	m68ki_write_16(ea, res);
 18.5947 +
 18.5948 +	FLAG_N = NFLAG_16(res);
 18.5949 +	FLAG_Z = res;
 18.5950 +	FLAG_V = VFLAG_CLEAR;
 18.5951 +	FLAG_C = CFLAG_CLEAR;
 18.5952 +}
 18.5953 +
 18.5954 +
 18.5955 +M68KMAKE_OP(move, 16, al, d)
 18.5956 +{
 18.5957 +	uint res = MASK_OUT_ABOVE_16(DY);
 18.5958 +	uint ea = EA_AL_16();
 18.5959 +
 18.5960 +	m68ki_write_16(ea, res);
 18.5961 +
 18.5962 +	FLAG_N = NFLAG_16(res);
 18.5963 +	FLAG_Z = res;
 18.5964 +	FLAG_V = VFLAG_CLEAR;
 18.5965 +	FLAG_C = CFLAG_CLEAR;
 18.5966 +}
 18.5967 +
 18.5968 +
 18.5969 +M68KMAKE_OP(move, 16, al, a)
 18.5970 +{
 18.5971 +	uint res = MASK_OUT_ABOVE_16(AY);
 18.5972 +	uint ea = EA_AL_16();
 18.5973 +
 18.5974 +	m68ki_write_16(ea, res);
 18.5975 +
 18.5976 +	FLAG_N = NFLAG_16(res);
 18.5977 +	FLAG_Z = res;
 18.5978 +	FLAG_V = VFLAG_CLEAR;
 18.5979 +	FLAG_C = CFLAG_CLEAR;
 18.5980 +}
 18.5981 +
 18.5982 +
 18.5983 +M68KMAKE_OP(move, 16, al, .)
 18.5984 +{
 18.5985 +	uint res = M68KMAKE_GET_OPER_AY_16;
 18.5986 +	uint ea = EA_AL_16();
 18.5987 +
 18.5988 +	m68ki_write_16(ea, res);
 18.5989 +
 18.5990 +	FLAG_N = NFLAG_16(res);
 18.5991 +	FLAG_Z = res;
 18.5992 +	FLAG_V = VFLAG_CLEAR;
 18.5993 +	FLAG_C = CFLAG_CLEAR;
 18.5994 +}
 18.5995 +
 18.5996 +
 18.5997 +M68KMAKE_OP(move, 32, d, d)
 18.5998 +{
 18.5999 +	uint res = DY;
 18.6000 +	uint* r_dst = &DX;
 18.6001 +
 18.6002 +	*r_dst = res;
 18.6003 +
 18.6004 +	FLAG_N = NFLAG_32(res);
 18.6005 +	FLAG_Z = res;
 18.6006 +	FLAG_V = VFLAG_CLEAR;
 18.6007 +	FLAG_C = CFLAG_CLEAR;
 18.6008 +}
 18.6009 +
 18.6010 +
 18.6011 +M68KMAKE_OP(move, 32, d, a)
 18.6012 +{
 18.6013 +	uint res = AY;
 18.6014 +	uint* r_dst = &DX;
 18.6015 +
 18.6016 +	*r_dst = res;
 18.6017 +
 18.6018 +	FLAG_N = NFLAG_32(res);
 18.6019 +	FLAG_Z = res;
 18.6020 +	FLAG_V = VFLAG_CLEAR;
 18.6021 +	FLAG_C = CFLAG_CLEAR;
 18.6022 +}
 18.6023 +
 18.6024 +
 18.6025 +M68KMAKE_OP(move, 32, d, .)
 18.6026 +{
 18.6027 +	uint res = M68KMAKE_GET_OPER_AY_32;
 18.6028 +	uint* r_dst = &DX;
 18.6029 +
 18.6030 +	*r_dst = res;
 18.6031 +
 18.6032 +	FLAG_N = NFLAG_32(res);
 18.6033 +	FLAG_Z = res;
 18.6034 +	FLAG_V = VFLAG_CLEAR;
 18.6035 +	FLAG_C = CFLAG_CLEAR;
 18.6036 +}
 18.6037 +
 18.6038 +
 18.6039 +M68KMAKE_OP(move, 32, ai, d)
 18.6040 +{
 18.6041 +	uint res = DY;
 18.6042 +	uint ea = EA_AX_AI_32();
 18.6043 +
 18.6044 +	m68ki_write_32(ea, res);
 18.6045 +
 18.6046 +	FLAG_N = NFLAG_32(res);
 18.6047 +	FLAG_Z = res;
 18.6048 +	FLAG_V = VFLAG_CLEAR;
 18.6049 +	FLAG_C = CFLAG_CLEAR;
 18.6050 +}
 18.6051 +
 18.6052 +
 18.6053 +M68KMAKE_OP(move, 32, ai, a)
 18.6054 +{
 18.6055 +	uint res = AY;
 18.6056 +	uint ea = EA_AX_AI_32();
 18.6057 +
 18.6058 +	m68ki_write_32(ea, res);
 18.6059 +
 18.6060 +	FLAG_N = NFLAG_32(res);
 18.6061 +	FLAG_Z = res;
 18.6062 +	FLAG_V = VFLAG_CLEAR;
 18.6063 +	FLAG_C = CFLAG_CLEAR;
 18.6064 +}
 18.6065 +
 18.6066 +
 18.6067 +M68KMAKE_OP(move, 32, ai, .)
 18.6068 +{
 18.6069 +	uint res = M68KMAKE_GET_OPER_AY_32;
 18.6070 +	uint ea = EA_AX_AI_32();
 18.6071 +
 18.6072 +	m68ki_write_32(ea, res);
 18.6073 +
 18.6074 +	FLAG_N = NFLAG_32(res);
 18.6075 +	FLAG_Z = res;
 18.6076 +	FLAG_V = VFLAG_CLEAR;
 18.6077 +	FLAG_C = CFLAG_CLEAR;
 18.6078 +}
 18.6079 +
 18.6080 +
 18.6081 +M68KMAKE_OP(move, 32, pi, d)
 18.6082 +{
 18.6083 +	uint res = DY;
 18.6084 +	uint ea = EA_AX_PI_32();
 18.6085 +
 18.6086 +	m68ki_write_32(ea, res);
 18.6087 +
 18.6088 +	FLAG_N = NFLAG_32(res);
 18.6089 +	FLAG_Z = res;
 18.6090 +	FLAG_V = VFLAG_CLEAR;
 18.6091 +	FLAG_C = CFLAG_CLEAR;
 18.6092 +}
 18.6093 +
 18.6094 +
 18.6095 +M68KMAKE_OP(move, 32, pi, a)
 18.6096 +{
 18.6097 +	uint res = AY;
 18.6098 +	uint ea = EA_AX_PI_32();
 18.6099 +
 18.6100 +	m68ki_write_32(ea, res);
 18.6101 +
 18.6102 +	FLAG_N = NFLAG_32(res);
 18.6103 +	FLAG_Z = res;
 18.6104 +	FLAG_V = VFLAG_CLEAR;
 18.6105 +	FLAG_C = CFLAG_CLEAR;
 18.6106 +}
 18.6107 +
 18.6108 +
 18.6109 +M68KMAKE_OP(move, 32, pi, .)
 18.6110 +{
 18.6111 +	uint res = M68KMAKE_GET_OPER_AY_32;
 18.6112 +	uint ea = EA_AX_PI_32();
 18.6113 +
 18.6114 +	m68ki_write_32(ea, res);
 18.6115 +
 18.6116 +	FLAG_N = NFLAG_32(res);
 18.6117 +	FLAG_Z = res;
 18.6118 +	FLAG_V = VFLAG_CLEAR;
 18.6119 +	FLAG_C = CFLAG_CLEAR;
 18.6120 +}
 18.6121 +
 18.6122 +
 18.6123 +M68KMAKE_OP(move, 32, pd, d)
 18.6124 +{
 18.6125 +	uint res = DY;
 18.6126 +	uint ea = EA_AX_PD_32();
 18.6127 +
 18.6128 +	m68ki_write_32(ea, res);
 18.6129 +
 18.6130 +	FLAG_N = NFLAG_32(res);
 18.6131 +	FLAG_Z = res;
 18.6132 +	FLAG_V = VFLAG_CLEAR;
 18.6133 +	FLAG_C = CFLAG_CLEAR;
 18.6134 +}
 18.6135 +
 18.6136 +
 18.6137 +M68KMAKE_OP(move, 32, pd, a)
 18.6138 +{
 18.6139 +	uint res = AY;
 18.6140 +	uint ea = EA_AX_PD_32();
 18.6141 +
 18.6142 +	m68ki_write_32(ea, res);
 18.6143 +
 18.6144 +	FLAG_N = NFLAG_32(res);
 18.6145 +	FLAG_Z = res;
 18.6146 +	FLAG_V = VFLAG_CLEAR;
 18.6147 +	FLAG_C = CFLAG_CLEAR;
 18.6148 +}
 18.6149 +
 18.6150 +
 18.6151 +M68KMAKE_OP(move, 32, pd, .)
 18.6152 +{
 18.6153 +	uint res = M68KMAKE_GET_OPER_AY_32;
 18.6154 +	uint ea = EA_AX_PD_32();
 18.6155 +
 18.6156 +	m68ki_write_32(ea, res);
 18.6157 +
 18.6158 +	FLAG_N = NFLAG_32(res);
 18.6159 +	FLAG_Z = res;
 18.6160 +	FLAG_V = VFLAG_CLEAR;
 18.6161 +	FLAG_C = CFLAG_CLEAR;
 18.6162 +}
 18.6163 +
 18.6164 +
 18.6165 +M68KMAKE_OP(move, 32, di, d)
 18.6166 +{
 18.6167 +	uint res = DY;
 18.6168 +	uint ea = EA_AX_DI_32();
 18.6169 +
 18.6170 +	m68ki_write_32(ea, res);
 18.6171 +
 18.6172 +	FLAG_N = NFLAG_32(res);
 18.6173 +	FLAG_Z = res;
 18.6174 +	FLAG_V = VFLAG_CLEAR;
 18.6175 +	FLAG_C = CFLAG_CLEAR;
 18.6176 +}
 18.6177 +
 18.6178 +
 18.6179 +M68KMAKE_OP(move, 32, di, a)
 18.6180 +{
 18.6181 +	uint res = AY;
 18.6182 +	uint ea = EA_AX_DI_32();
 18.6183 +
 18.6184 +	m68ki_write_32(ea, res);
 18.6185 +
 18.6186 +	FLAG_N = NFLAG_32(res);
 18.6187 +	FLAG_Z = res;
 18.6188 +	FLAG_V = VFLAG_CLEAR;
 18.6189 +	FLAG_C = CFLAG_CLEAR;
 18.6190 +}
 18.6191 +
 18.6192 +
 18.6193 +M68KMAKE_OP(move, 32, di, .)
 18.6194 +{
 18.6195 +	uint res = M68KMAKE_GET_OPER_AY_32;
 18.6196 +	uint ea = EA_AX_DI_32();
 18.6197 +
 18.6198 +	m68ki_write_32(ea, res);
 18.6199 +
 18.6200 +	FLAG_N = NFLAG_32(res);
 18.6201 +	FLAG_Z = res;
 18.6202 +	FLAG_V = VFLAG_CLEAR;
 18.6203 +	FLAG_C = CFLAG_CLEAR;
 18.6204 +}
 18.6205 +
 18.6206 +
 18.6207 +M68KMAKE_OP(move, 32, ix, d)
 18.6208 +{
 18.6209 +	uint res = DY;
 18.6210 +	uint ea = EA_AX_IX_32();
 18.6211 +
 18.6212 +	m68ki_write_32(ea, res);
 18.6213 +
 18.6214 +	FLAG_N = NFLAG_32(res);
 18.6215 +	FLAG_Z = res;
 18.6216 +	FLAG_V = VFLAG_CLEAR;
 18.6217 +	FLAG_C = CFLAG_CLEAR;
 18.6218 +}
 18.6219 +
 18.6220 +
 18.6221 +M68KMAKE_OP(move, 32, ix, a)
 18.6222 +{
 18.6223 +	uint res = AY;
 18.6224 +	uint ea = EA_AX_IX_32();
 18.6225 +
 18.6226 +	m68ki_write_32(ea, res);
 18.6227 +
 18.6228 +	FLAG_N = NFLAG_32(res);
 18.6229 +	FLAG_Z = res;
 18.6230 +	FLAG_V = VFLAG_CLEAR;
 18.6231 +	FLAG_C = CFLAG_CLEAR;
 18.6232 +}
 18.6233 +
 18.6234 +
 18.6235 +M68KMAKE_OP(move, 32, ix, .)
 18.6236 +{
 18.6237 +	uint res = M68KMAKE_GET_OPER_AY_32;
 18.6238 +	uint ea = EA_AX_IX_32();
 18.6239 +
 18.6240 +	m68ki_write_32(ea, res);
 18.6241 +
 18.6242 +	FLAG_N = NFLAG_32(res);
 18.6243 +	FLAG_Z = res;
 18.6244 +	FLAG_V = VFLAG_CLEAR;
 18.6245 +	FLAG_C = CFLAG_CLEAR;
 18.6246 +}
 18.6247 +
 18.6248 +
 18.6249 +M68KMAKE_OP(move, 32, aw, d)
 18.6250 +{
 18.6251 +	uint res = DY;
 18.6252 +	uint ea = EA_AW_32();
 18.6253 +
 18.6254 +	m68ki_write_32(ea, res);
 18.6255 +
 18.6256 +	FLAG_N = NFLAG_32(res);
 18.6257 +	FLAG_Z = res;
 18.6258 +	FLAG_V = VFLAG_CLEAR;
 18.6259 +	FLAG_C = CFLAG_CLEAR;
 18.6260 +}
 18.6261 +
 18.6262 +
 18.6263 +M68KMAKE_OP(move, 32, aw, a)
 18.6264 +{
 18.6265 +	uint res = AY;
 18.6266 +	uint ea = EA_AW_32();
 18.6267 +
 18.6268 +	m68ki_write_32(ea, res);
 18.6269 +
 18.6270 +	FLAG_N = NFLAG_32(res);
 18.6271 +	FLAG_Z = res;
 18.6272 +	FLAG_V = VFLAG_CLEAR;
 18.6273 +	FLAG_C = CFLAG_CLEAR;
 18.6274 +}
 18.6275 +
 18.6276 +
 18.6277 +M68KMAKE_OP(move, 32, aw, .)
 18.6278 +{
 18.6279 +	uint res = M68KMAKE_GET_OPER_AY_32;
 18.6280 +	uint ea = EA_AW_32();
 18.6281 +
 18.6282 +	m68ki_write_32(ea, res);
 18.6283 +
 18.6284 +	FLAG_N = NFLAG_32(res);
 18.6285 +	FLAG_Z = res;
 18.6286 +	FLAG_V = VFLAG_CLEAR;
 18.6287 +	FLAG_C = CFLAG_CLEAR;
 18.6288 +}
 18.6289 +
 18.6290 +
 18.6291 +M68KMAKE_OP(move, 32, al, d)
 18.6292 +{
 18.6293 +	uint res = DY;
 18.6294 +	uint ea = EA_AL_32();
 18.6295 +
 18.6296 +	m68ki_write_32(ea, res);
 18.6297 +
 18.6298 +	FLAG_N = NFLAG_32(res);
 18.6299 +	FLAG_Z = res;
 18.6300 +	FLAG_V = VFLAG_CLEAR;
 18.6301 +	FLAG_C = CFLAG_CLEAR;
 18.6302 +}
 18.6303 +
 18.6304 +
 18.6305 +M68KMAKE_OP(move, 32, al, a)
 18.6306 +{
 18.6307 +	uint res = AY;
 18.6308 +	uint ea = EA_AL_32();
 18.6309 +
 18.6310 +	m68ki_write_32(ea, res);
 18.6311 +
 18.6312 +	FLAG_N = NFLAG_32(res);
 18.6313 +	FLAG_Z = res;
 18.6314 +	FLAG_V = VFLAG_CLEAR;
 18.6315 +	FLAG_C = CFLAG_CLEAR;
 18.6316 +}
 18.6317 +
 18.6318 +
 18.6319 +M68KMAKE_OP(move, 32, al, .)
 18.6320 +{
 18.6321 +	uint res = M68KMAKE_GET_OPER_AY_32;
 18.6322 +	uint ea = EA_AL_32();
 18.6323 +
 18.6324 +	m68ki_write_32(ea, res);
 18.6325 +
 18.6326 +	FLAG_N = NFLAG_32(res);
 18.6327 +	FLAG_Z = res;
 18.6328 +	FLAG_V = VFLAG_CLEAR;
 18.6329 +	FLAG_C = CFLAG_CLEAR;
 18.6330 +}
 18.6331 +
 18.6332 +
 18.6333 +M68KMAKE_OP(movea, 16, ., d)
 18.6334 +{
 18.6335 +	AX = MAKE_INT_16(DY);
 18.6336 +}
 18.6337 +
 18.6338 +
 18.6339 +M68KMAKE_OP(movea, 16, ., a)
 18.6340 +{
 18.6341 +	AX = MAKE_INT_16(AY);
 18.6342 +}
 18.6343 +
 18.6344 +
 18.6345 +M68KMAKE_OP(movea, 16, ., .)
 18.6346 +{
 18.6347 +	AX = MAKE_INT_16(M68KMAKE_GET_OPER_AY_16);
 18.6348 +}
 18.6349 +
 18.6350 +
 18.6351 +M68KMAKE_OP(movea, 32, ., d)
 18.6352 +{
 18.6353 +	AX = DY;
 18.6354 +}
 18.6355 +
 18.6356 +
 18.6357 +M68KMAKE_OP(movea, 32, ., a)
 18.6358 +{
 18.6359 +	AX = AY;
 18.6360 +}
 18.6361 +
 18.6362 +
 18.6363 +M68KMAKE_OP(movea, 32, ., .)
 18.6364 +{
 18.6365 +	AX = M68KMAKE_GET_OPER_AY_32;
 18.6366 +}
 18.6367 +
 18.6368 +
 18.6369 +M68KMAKE_OP(move, 16, frc, d)
 18.6370 +{
 18.6371 +	if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
 18.6372 +	{
 18.6373 +		DY = MASK_OUT_BELOW_16(DY) | m68ki_get_ccr();
 18.6374 +		return;
 18.6375 +	}
 18.6376 +	m68ki_exception_illegal();
 18.6377 +}
 18.6378 +
 18.6379 +
 18.6380 +M68KMAKE_OP(move, 16, frc, .)
 18.6381 +{
 18.6382 +	if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
 18.6383 +	{
 18.6384 +		m68ki_write_16(M68KMAKE_GET_EA_AY_16, m68ki_get_ccr());
 18.6385 +		return;
 18.6386 +	}
 18.6387 +	m68ki_exception_illegal();
 18.6388 +}
 18.6389 +
 18.6390 +
 18.6391 +M68KMAKE_OP(move, 16, toc, d)
 18.6392 +{
 18.6393 +	m68ki_set_ccr(DY);
 18.6394 +}
 18.6395 +
 18.6396 +
 18.6397 +M68KMAKE_OP(move, 16, toc, .)
 18.6398 +{
 18.6399 +	m68ki_set_ccr(M68KMAKE_GET_OPER_AY_16);
 18.6400 +}
 18.6401 +
 18.6402 +
 18.6403 +M68KMAKE_OP(move, 16, frs, d)
 18.6404 +{
 18.6405 +	if(CPU_TYPE_IS_000(CPU_TYPE) || FLAG_S)	/* NS990408 */
 18.6406 +	{
 18.6407 +		DY = MASK_OUT_BELOW_16(DY) | m68ki_get_sr();
 18.6408 +		return;
 18.6409 +	}
 18.6410 +	m68ki_exception_privilege_violation();
 18.6411 +}
 18.6412 +
 18.6413 +
 18.6414 +M68KMAKE_OP(move, 16, frs, .)
 18.6415 +{
 18.6416 +	if(CPU_TYPE_IS_000(CPU_TYPE) || FLAG_S)	/* NS990408 */
 18.6417 +	{
 18.6418 +		uint ea = M68KMAKE_GET_EA_AY_16;
 18.6419 +		m68ki_write_16(ea, m68ki_get_sr());
 18.6420 +		return;
 18.6421 +	}
 18.6422 +	m68ki_exception_privilege_violation();
 18.6423 +}
 18.6424 +
 18.6425 +
 18.6426 +M68KMAKE_OP(move, 16, tos, d)
 18.6427 +{
 18.6428 +	if(FLAG_S)
 18.6429 +	{
 18.6430 +		m68ki_set_sr(DY);
 18.6431 +		return;
 18.6432 +	}
 18.6433 +	m68ki_exception_privilege_violation();
 18.6434 +}
 18.6435 +
 18.6436 +
 18.6437 +M68KMAKE_OP(move, 16, tos, .)
 18.6438 +{
 18.6439 +	if(FLAG_S)
 18.6440 +	{
 18.6441 +		uint new_sr = M68KMAKE_GET_OPER_AY_16;
 18.6442 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.6443 +		m68ki_set_sr(new_sr);
 18.6444 +		return;
 18.6445 +	}
 18.6446 +	m68ki_exception_privilege_violation();
 18.6447 +}
 18.6448 +
 18.6449 +
 18.6450 +M68KMAKE_OP(move, 32, fru, .)
 18.6451 +{
 18.6452 +	if(FLAG_S)
 18.6453 +	{
 18.6454 +		AY = REG_USP;
 18.6455 +		return;
 18.6456 +	}
 18.6457 +	m68ki_exception_privilege_violation();
 18.6458 +}
 18.6459 +
 18.6460 +
 18.6461 +M68KMAKE_OP(move, 32, tou, .)
 18.6462 +{
 18.6463 +	if(FLAG_S)
 18.6464 +	{
 18.6465 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.6466 +		REG_USP = AY;
 18.6467 +		return;
 18.6468 +	}
 18.6469 +	m68ki_exception_privilege_violation();
 18.6470 +}
 18.6471 +
 18.6472 +
 18.6473 +M68KMAKE_OP(movec, 32, cr, .)
 18.6474 +{
 18.6475 +	if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
 18.6476 +	{
 18.6477 +		if(FLAG_S)
 18.6478 +		{
 18.6479 +			uint word2 = OPER_I_16();
 18.6480 +
 18.6481 +			m68ki_trace_t0();		   /* auto-disable (see m68kcpu.h) */
 18.6482 +			switch (word2 & 0xfff)
 18.6483 +			{
 18.6484 +			case 0x000:			   /* SFC */
 18.6485 +				REG_DA[(word2 >> 12) & 15] = REG_SFC;
 18.6486 +				return;
 18.6487 +			case 0x001:			   /* DFC */
 18.6488 +				REG_DA[(word2 >> 12) & 15] = REG_DFC;
 18.6489 +				return;
 18.6490 +			case 0x002:			   /* CACR */
 18.6491 +				if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.6492 +				{
 18.6493 +					REG_DA[(word2 >> 12) & 15] = REG_CACR;
 18.6494 +					return;
 18.6495 +				}
 18.6496 +				return;
 18.6497 +			case 0x800:			   /* USP */
 18.6498 +				REG_DA[(word2 >> 12) & 15] = REG_USP;
 18.6499 +				return;
 18.6500 +			case 0x801:			   /* VBR */
 18.6501 +				REG_DA[(word2 >> 12) & 15] = REG_VBR;
 18.6502 +				return;
 18.6503 +			case 0x802:			   /* CAAR */
 18.6504 +				if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.6505 +				{
 18.6506 +					REG_DA[(word2 >> 12) & 15] = REG_CAAR;
 18.6507 +					return;
 18.6508 +				}
 18.6509 +				m68ki_exception_illegal();
 18.6510 +				break;
 18.6511 +			case 0x803:			   /* MSP */
 18.6512 +				if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.6513 +				{
 18.6514 +					REG_DA[(word2 >> 12) & 15] = FLAG_M ? REG_SP : REG_MSP;
 18.6515 +					return;
 18.6516 +				}
 18.6517 +				m68ki_exception_illegal();
 18.6518 +				return;
 18.6519 +			case 0x804:			   /* ISP */
 18.6520 +				if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.6521 +				{
 18.6522 +					REG_DA[(word2 >> 12) & 15] = FLAG_M ? REG_ISP : REG_SP;
 18.6523 +					return;
 18.6524 +				}
 18.6525 +				m68ki_exception_illegal();
 18.6526 +				return;
 18.6527 +			default:
 18.6528 +				m68ki_exception_illegal();
 18.6529 +				return;
 18.6530 +			}
 18.6531 +		}
 18.6532 +		m68ki_exception_privilege_violation();
 18.6533 +		return;
 18.6534 +	}
 18.6535 +	m68ki_exception_illegal();
 18.6536 +}
 18.6537 +
 18.6538 +
 18.6539 +M68KMAKE_OP(movec, 32, rc, .)
 18.6540 +{
 18.6541 +	if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
 18.6542 +	{
 18.6543 +		if(FLAG_S)
 18.6544 +		{
 18.6545 +			uint word2 = OPER_I_16();
 18.6546 +
 18.6547 +			m68ki_trace_t0();		   /* auto-disable (see m68kcpu.h) */
 18.6548 +			switch (word2 & 0xfff)
 18.6549 +			{
 18.6550 +			case 0x000:			   /* SFC */
 18.6551 +				REG_SFC = REG_DA[(word2 >> 12) & 15] & 7;
 18.6552 +				return;
 18.6553 +			case 0x001:			   /* DFC */
 18.6554 +				REG_DFC = REG_DA[(word2 >> 12) & 15] & 7;
 18.6555 +				return;
 18.6556 +			case 0x002:			   /* CACR */
 18.6557 +				if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.6558 +				{
 18.6559 +					REG_CACR = REG_DA[(word2 >> 12) & 15];
 18.6560 +					return;
 18.6561 +				}
 18.6562 +				m68ki_exception_illegal();
 18.6563 +				return;
 18.6564 +			case 0x800:			   /* USP */
 18.6565 +				REG_USP = REG_DA[(word2 >> 12) & 15];
 18.6566 +				return;
 18.6567 +			case 0x801:			   /* VBR */
 18.6568 +				REG_VBR = REG_DA[(word2 >> 12) & 15];
 18.6569 +				return;
 18.6570 +			case 0x802:			   /* CAAR */
 18.6571 +				if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.6572 +				{
 18.6573 +					REG_CAAR = REG_DA[(word2 >> 12) & 15];
 18.6574 +					return;
 18.6575 +				}
 18.6576 +				m68ki_exception_illegal();
 18.6577 +				return;
 18.6578 +			case 0x803:			   /* MSP */
 18.6579 +				if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.6580 +				{
 18.6581 +					/* we are in supervisor mode so just check for M flag */
 18.6582 +					if(!FLAG_M)
 18.6583 +					{
 18.6584 +						REG_MSP = REG_DA[(word2 >> 12) & 15];
 18.6585 +						return;
 18.6586 +					}
 18.6587 +					REG_SP = REG_DA[(word2 >> 12) & 15];
 18.6588 +					return;
 18.6589 +				}
 18.6590 +				m68ki_exception_illegal();
 18.6591 +				return;
 18.6592 +			case 0x804:			   /* ISP */
 18.6593 +				if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.6594 +				{
 18.6595 +					if(!FLAG_M)
 18.6596 +					{
 18.6597 +						REG_SP = REG_DA[(word2 >> 12) & 15];
 18.6598 +						return;
 18.6599 +					}
 18.6600 +					REG_ISP = REG_DA[(word2 >> 12) & 15];
 18.6601 +					return;
 18.6602 +				}
 18.6603 +				m68ki_exception_illegal();
 18.6604 +				return;
 18.6605 +			default:
 18.6606 +				m68ki_exception_illegal();
 18.6607 +				return;
 18.6608 +			}
 18.6609 +		}
 18.6610 +		m68ki_exception_privilege_violation();
 18.6611 +		return;
 18.6612 +	}
 18.6613 +	m68ki_exception_illegal();
 18.6614 +}
 18.6615 +
 18.6616 +
 18.6617 +M68KMAKE_OP(movem, 16, re, pd)
 18.6618 +{
 18.6619 +	uint i = 0;
 18.6620 +	uint register_list = OPER_I_16();
 18.6621 +	uint ea = AY;
 18.6622 +	uint count = 0;
 18.6623 +
 18.6624 +	for(; i < 16; i++)
 18.6625 +		if(register_list & (1 << i))
 18.6626 +		{
 18.6627 +			ea -= 2;
 18.6628 +			m68ki_write_16(ea, MASK_OUT_ABOVE_16(REG_DA[15-i]));
 18.6629 +			count++;
 18.6630 +		}
 18.6631 +	AY = ea;
 18.6632 +
 18.6633 +	USE_CYCLES(count<<CYC_MOVEM_W);
 18.6634 +}
 18.6635 +
 18.6636 +
 18.6637 +M68KMAKE_OP(movem, 16, re, .)
 18.6638 +{
 18.6639 +	uint i = 0;
 18.6640 +	uint register_list = OPER_I_16();
 18.6641 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.6642 +	uint count = 0;
 18.6643 +
 18.6644 +	for(; i < 16; i++)
 18.6645 +		if(register_list & (1 << i))
 18.6646 +		{
 18.6647 +			m68ki_write_16(ea, MASK_OUT_ABOVE_16(REG_DA[i]));
 18.6648 +			ea += 2;
 18.6649 +			count++;
 18.6650 +		}
 18.6651 +
 18.6652 +	USE_CYCLES(count<<CYC_MOVEM_W);
 18.6653 +}
 18.6654 +
 18.6655 +
 18.6656 +M68KMAKE_OP(movem, 32, re, pd)
 18.6657 +{
 18.6658 +	uint i = 0;
 18.6659 +	uint register_list = OPER_I_16();
 18.6660 +	uint ea = AY;
 18.6661 +	uint count = 0;
 18.6662 +
 18.6663 +	for(; i < 16; i++)
 18.6664 +		if(register_list & (1 << i))
 18.6665 +		{
 18.6666 +			ea -= 4;
 18.6667 +			m68ki_write_32(ea, REG_DA[15-i]);
 18.6668 +			count++;
 18.6669 +		}
 18.6670 +	AY = ea;
 18.6671 +
 18.6672 +	USE_CYCLES(count<<CYC_MOVEM_L);
 18.6673 +}
 18.6674 +
 18.6675 +
 18.6676 +M68KMAKE_OP(movem, 32, re, .)
 18.6677 +{
 18.6678 +	uint i = 0;
 18.6679 +	uint register_list = OPER_I_16();
 18.6680 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.6681 +	uint count = 0;
 18.6682 +
 18.6683 +	for(; i < 16; i++)
 18.6684 +		if(register_list & (1 << i))
 18.6685 +		{
 18.6686 +			m68ki_write_32(ea, REG_DA[i]);
 18.6687 +			ea += 4;
 18.6688 +			count++;
 18.6689 +		}
 18.6690 +
 18.6691 +	USE_CYCLES(count<<CYC_MOVEM_L);
 18.6692 +}
 18.6693 +
 18.6694 +
 18.6695 +M68KMAKE_OP(movem, 16, er, pi)
 18.6696 +{
 18.6697 +	uint i = 0;
 18.6698 +	uint register_list = OPER_I_16();
 18.6699 +	uint ea = AY;
 18.6700 +	uint count = 0;
 18.6701 +
 18.6702 +	for(; i < 16; i++)
 18.6703 +		if(register_list & (1 << i))
 18.6704 +		{
 18.6705 +			REG_DA[i] = MAKE_INT_16(MASK_OUT_ABOVE_16(m68ki_read_16(ea)));
 18.6706 +			ea += 2;
 18.6707 +			count++;
 18.6708 +		}
 18.6709 +	AY = ea;
 18.6710 +
 18.6711 +	USE_CYCLES(count<<CYC_MOVEM_W);
 18.6712 +}
 18.6713 +
 18.6714 +
 18.6715 +M68KMAKE_OP(movem, 16, er, .)
 18.6716 +{
 18.6717 +	uint i = 0;
 18.6718 +	uint register_list = OPER_I_16();
 18.6719 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.6720 +	uint count = 0;
 18.6721 +
 18.6722 +	for(; i < 16; i++)
 18.6723 +		if(register_list & (1 << i))
 18.6724 +		{
 18.6725 +			REG_DA[i] = MAKE_INT_16(MASK_OUT_ABOVE_16(m68ki_read_16(ea)));
 18.6726 +			ea += 2;
 18.6727 +			count++;
 18.6728 +		}
 18.6729 +
 18.6730 +	USE_CYCLES(count<<CYC_MOVEM_W);
 18.6731 +}
 18.6732 +
 18.6733 +
 18.6734 +M68KMAKE_OP(movem, 32, er, pi)
 18.6735 +{
 18.6736 +	uint i = 0;
 18.6737 +	uint register_list = OPER_I_16();
 18.6738 +	uint ea = AY;
 18.6739 +	uint count = 0;
 18.6740 +
 18.6741 +	for(; i < 16; i++)
 18.6742 +		if(register_list & (1 << i))
 18.6743 +		{
 18.6744 +			REG_DA[i] = m68ki_read_32(ea);
 18.6745 +			ea += 4;
 18.6746 +			count++;
 18.6747 +		}
 18.6748 +	AY = ea;
 18.6749 +
 18.6750 +	USE_CYCLES(count<<CYC_MOVEM_L);
 18.6751 +}
 18.6752 +
 18.6753 +
 18.6754 +M68KMAKE_OP(movem, 32, er, .)
 18.6755 +{
 18.6756 +	uint i = 0;
 18.6757 +	uint register_list = OPER_I_16();
 18.6758 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.6759 +	uint count = 0;
 18.6760 +
 18.6761 +	for(; i < 16; i++)
 18.6762 +		if(register_list & (1 << i))
 18.6763 +		{
 18.6764 +			REG_DA[i] = m68ki_read_32(ea);
 18.6765 +			ea += 4;
 18.6766 +			count++;
 18.6767 +		}
 18.6768 +
 18.6769 +	USE_CYCLES(count<<CYC_MOVEM_L);
 18.6770 +}
 18.6771 +
 18.6772 +
 18.6773 +M68KMAKE_OP(movep, 16, re, .)
 18.6774 +{
 18.6775 +	uint ea = EA_AY_DI_16();
 18.6776 +	uint src = DX;
 18.6777 +
 18.6778 +	m68ki_write_8(ea, MASK_OUT_ABOVE_8(src >> 8));
 18.6779 +	m68ki_write_8(ea += 2, MASK_OUT_ABOVE_8(src));
 18.6780 +}
 18.6781 +
 18.6782 +
 18.6783 +M68KMAKE_OP(movep, 32, re, .)
 18.6784 +{
 18.6785 +	uint ea = EA_AY_DI_32();
 18.6786 +	uint src = DX;
 18.6787 +
 18.6788 +	m68ki_write_8(ea, MASK_OUT_ABOVE_8(src >> 24));
 18.6789 +	m68ki_write_8(ea += 2, MASK_OUT_ABOVE_8(src >> 16));
 18.6790 +	m68ki_write_8(ea += 2, MASK_OUT_ABOVE_8(src >> 8));
 18.6791 +	m68ki_write_8(ea += 2, MASK_OUT_ABOVE_8(src));
 18.6792 +}
 18.6793 +
 18.6794 +
 18.6795 +M68KMAKE_OP(movep, 16, er, .)
 18.6796 +{
 18.6797 +	uint ea = EA_AY_DI_16();
 18.6798 +	uint* r_dst = &DX;
 18.6799 +
 18.6800 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | ((m68ki_read_8(ea) << 8) + m68ki_read_8(ea + 2));
 18.6801 +}
 18.6802 +
 18.6803 +
 18.6804 +M68KMAKE_OP(movep, 32, er, .)
 18.6805 +{
 18.6806 +	uint ea = EA_AY_DI_32();
 18.6807 +
 18.6808 +	DX = (m68ki_read_8(ea) << 24) + (m68ki_read_8(ea + 2) << 16)
 18.6809 +		+ (m68ki_read_8(ea + 4) << 8) + m68ki_read_8(ea + 6);
 18.6810 +}
 18.6811 +
 18.6812 +
 18.6813 +M68KMAKE_OP(moves, 8, ., .)
 18.6814 +{
 18.6815 +	if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
 18.6816 +	{
 18.6817 +		if(FLAG_S)
 18.6818 +		{
 18.6819 +			uint word2 = OPER_I_16();
 18.6820 +			uint ea = M68KMAKE_GET_EA_AY_8;
 18.6821 +
 18.6822 +			m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.6823 +			if(BIT_B(word2))		   /* Register to memory */
 18.6824 +			{
 18.6825 +				m68ki_write_8_fc(ea, REG_DFC, MASK_OUT_ABOVE_8(REG_DA[(word2 >> 12) & 15]));
 18.6826 +				return;
 18.6827 +			}
 18.6828 +			if(BIT_F(word2))		   /* Memory to address register */
 18.6829 +			{
 18.6830 +				REG_A[(word2 >> 12) & 7] = MAKE_INT_8(m68ki_read_8_fc(ea, REG_SFC));
 18.6831 +				if(CPU_TYPE_IS_020_VARIANT(CPU_TYPE))
 18.6832 +					USE_CYCLES(2);
 18.6833 +				return;
 18.6834 +			}
 18.6835 +			/* Memory to data register */
 18.6836 +			REG_D[(word2 >> 12) & 7] = MASK_OUT_BELOW_8(REG_D[(word2 >> 12) & 7]) | m68ki_read_8_fc(ea, REG_SFC);
 18.6837 +			if(CPU_TYPE_IS_020_VARIANT(CPU_TYPE))
 18.6838 +				USE_CYCLES(2);
 18.6839 +			return;
 18.6840 +		}
 18.6841 +		m68ki_exception_privilege_violation();
 18.6842 +		return;
 18.6843 +	}
 18.6844 +	m68ki_exception_illegal();
 18.6845 +}
 18.6846 +
 18.6847 +
 18.6848 +M68KMAKE_OP(moves, 16, ., .)
 18.6849 +{
 18.6850 +	if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
 18.6851 +	{
 18.6852 +		if(FLAG_S)
 18.6853 +		{
 18.6854 +			uint word2 = OPER_I_16();
 18.6855 +			uint ea = M68KMAKE_GET_EA_AY_16;
 18.6856 +
 18.6857 +			m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.6858 +			if(BIT_B(word2))		   /* Register to memory */
 18.6859 +			{
 18.6860 +				m68ki_write_16_fc(ea, REG_DFC, MASK_OUT_ABOVE_16(REG_DA[(word2 >> 12) & 15]));
 18.6861 +				return;
 18.6862 +			}
 18.6863 +			if(BIT_F(word2))		   /* Memory to address register */
 18.6864 +			{
 18.6865 +				REG_A[(word2 >> 12) & 7] = MAKE_INT_16(m68ki_read_16_fc(ea, REG_SFC));
 18.6866 +				if(CPU_TYPE_IS_020_VARIANT(CPU_TYPE))
 18.6867 +					USE_CYCLES(2);
 18.6868 +				return;
 18.6869 +			}
 18.6870 +			/* Memory to data register */
 18.6871 +			REG_D[(word2 >> 12) & 7] = MASK_OUT_BELOW_16(REG_D[(word2 >> 12) & 7]) | m68ki_read_16_fc(ea, REG_SFC);
 18.6872 +			if(CPU_TYPE_IS_020_VARIANT(CPU_TYPE))
 18.6873 +				USE_CYCLES(2);
 18.6874 +			return;
 18.6875 +		}
 18.6876 +		m68ki_exception_privilege_violation();
 18.6877 +		return;
 18.6878 +	}
 18.6879 +	m68ki_exception_illegal();
 18.6880 +}
 18.6881 +
 18.6882 +
 18.6883 +M68KMAKE_OP(moves, 32, ., .)
 18.6884 +{
 18.6885 +	if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
 18.6886 +	{
 18.6887 +		if(FLAG_S)
 18.6888 +		{
 18.6889 +			uint word2 = OPER_I_16();
 18.6890 +			uint ea = M68KMAKE_GET_EA_AY_32;
 18.6891 +
 18.6892 +			m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.6893 +			if(BIT_B(word2))		   /* Register to memory */
 18.6894 +			{
 18.6895 +				m68ki_write_32_fc(ea, REG_DFC, REG_DA[(word2 >> 12) & 15]);
 18.6896 +				if(CPU_TYPE_IS_020_VARIANT(CPU_TYPE))
 18.6897 +					USE_CYCLES(2);
 18.6898 +				return;
 18.6899 +			}
 18.6900 +			/* Memory to register */
 18.6901 +			REG_DA[(word2 >> 12) & 15] = m68ki_read_32_fc(ea, REG_SFC);
 18.6902 +			if(CPU_TYPE_IS_020_VARIANT(CPU_TYPE))
 18.6903 +				USE_CYCLES(2);
 18.6904 +			return;
 18.6905 +		}
 18.6906 +		m68ki_exception_privilege_violation();
 18.6907 +		return;
 18.6908 +	}
 18.6909 +	m68ki_exception_illegal();
 18.6910 +}
 18.6911 +
 18.6912 +
 18.6913 +M68KMAKE_OP(moveq, 32, ., .)
 18.6914 +{
 18.6915 +	uint res = DX = MAKE_INT_8(MASK_OUT_ABOVE_8(REG_IR));
 18.6916 +
 18.6917 +	FLAG_N = NFLAG_32(res);
 18.6918 +	FLAG_Z = res;
 18.6919 +	FLAG_V = VFLAG_CLEAR;
 18.6920 +	FLAG_C = CFLAG_CLEAR;
 18.6921 +}
 18.6922 +
 18.6923 +
 18.6924 +M68KMAKE_OP(muls, 16, ., d)
 18.6925 +{
 18.6926 +	uint* r_dst = &DX;
 18.6927 +	uint res = MASK_OUT_ABOVE_32(MAKE_INT_16(DY) * MAKE_INT_16(MASK_OUT_ABOVE_16(*r_dst)));
 18.6928 +
 18.6929 +	*r_dst = res;
 18.6930 +
 18.6931 +	FLAG_Z = res;
 18.6932 +	FLAG_N = NFLAG_32(res);
 18.6933 +	FLAG_V = VFLAG_CLEAR;
 18.6934 +	FLAG_C = CFLAG_CLEAR;
 18.6935 +}
 18.6936 +
 18.6937 +
 18.6938 +M68KMAKE_OP(muls, 16, ., .)
 18.6939 +{
 18.6940 +	uint* r_dst = &DX;
 18.6941 +	uint res = MASK_OUT_ABOVE_32(MAKE_INT_16(M68KMAKE_GET_OPER_AY_16) * MAKE_INT_16(MASK_OUT_ABOVE_16(*r_dst)));
 18.6942 +
 18.6943 +	*r_dst = res;
 18.6944 +
 18.6945 +	FLAG_Z = res;
 18.6946 +	FLAG_N = NFLAG_32(res);
 18.6947 +	FLAG_V = VFLAG_CLEAR;
 18.6948 +	FLAG_C = CFLAG_CLEAR;
 18.6949 +}
 18.6950 +
 18.6951 +
 18.6952 +M68KMAKE_OP(mulu, 16, ., d)
 18.6953 +{
 18.6954 +	uint* r_dst = &DX;
 18.6955 +	uint res = MASK_OUT_ABOVE_16(DY) * MASK_OUT_ABOVE_16(*r_dst);
 18.6956 +
 18.6957 +	*r_dst = res;
 18.6958 +
 18.6959 +	FLAG_Z = res;
 18.6960 +	FLAG_N = NFLAG_32(res);
 18.6961 +	FLAG_V = VFLAG_CLEAR;
 18.6962 +	FLAG_C = CFLAG_CLEAR;
 18.6963 +}
 18.6964 +
 18.6965 +
 18.6966 +M68KMAKE_OP(mulu, 16, ., .)
 18.6967 +{
 18.6968 +	uint* r_dst = &DX;
 18.6969 +	uint res = M68KMAKE_GET_OPER_AY_16 * MASK_OUT_ABOVE_16(*r_dst);
 18.6970 +
 18.6971 +	*r_dst = res;
 18.6972 +
 18.6973 +	FLAG_Z = res;
 18.6974 +	FLAG_N = NFLAG_32(res);
 18.6975 +	FLAG_V = VFLAG_CLEAR;
 18.6976 +	FLAG_C = CFLAG_CLEAR;
 18.6977 +}
 18.6978 +
 18.6979 +
 18.6980 +M68KMAKE_OP(mull, 32, ., d)
 18.6981 +{
 18.6982 +#if M68K_USE_64_BIT
 18.6983 +
 18.6984 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.6985 +	{
 18.6986 +		uint word2 = OPER_I_16();
 18.6987 +		uint64 src = DY;
 18.6988 +		uint64 dst = REG_D[(word2 >> 12) & 7];
 18.6989 +		uint64 res;
 18.6990 +
 18.6991 +		FLAG_C = CFLAG_CLEAR;
 18.6992 +
 18.6993 +		if(BIT_B(word2))			   /* signed */
 18.6994 +		{
 18.6995 +			res = (sint64)((sint32)src) * (sint64)((sint32)dst);
 18.6996 +			if(!BIT_A(word2))
 18.6997 +			{
 18.6998 +				FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.6999 +				FLAG_N = NFLAG_32(res);
 18.7000 +				FLAG_V = ((sint64)res != (sint32)res)<<7;
 18.7001 +				REG_D[(word2 >> 12) & 7] = FLAG_Z;
 18.7002 +				return;
 18.7003 +			}
 18.7004 +			FLAG_Z = MASK_OUT_ABOVE_32(res) | (res>>32);
 18.7005 +			FLAG_N = NFLAG_64(res);
 18.7006 +			FLAG_V = VFLAG_CLEAR;
 18.7007 +			REG_D[word2 & 7] = (res >> 32);
 18.7008 +			REG_D[(word2 >> 12) & 7] = MASK_OUT_ABOVE_32(res);
 18.7009 +			return;
 18.7010 +		}
 18.7011 +
 18.7012 +		res = src * dst;
 18.7013 +		if(!BIT_A(word2))
 18.7014 +		{
 18.7015 +			FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.7016 +			FLAG_N = NFLAG_32(res);
 18.7017 +			FLAG_V = (res > 0xffffffff)<<7;
 18.7018 +			REG_D[(word2 >> 12) & 7] = FLAG_Z;
 18.7019 +			return;
 18.7020 +		}
 18.7021 +		FLAG_Z = MASK_OUT_ABOVE_32(res) | (res>>32);
 18.7022 +		FLAG_N = NFLAG_64(res);
 18.7023 +		FLAG_V = VFLAG_CLEAR;
 18.7024 +		REG_D[word2 & 7] = (res >> 32);
 18.7025 +		REG_D[(word2 >> 12) & 7] = MASK_OUT_ABOVE_32(res);
 18.7026 +		return;
 18.7027 +	}
 18.7028 +	m68ki_exception_illegal();
 18.7029 +
 18.7030 +#else
 18.7031 +
 18.7032 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.7033 +	{
 18.7034 +		uint word2 = OPER_I_16();
 18.7035 +		uint src = DY;
 18.7036 +		uint dst = REG_D[(word2 >> 12) & 7];
 18.7037 +		uint neg = GET_MSB_32(src ^ dst);
 18.7038 +		uint src1;
 18.7039 +		uint src2;
 18.7040 +		uint dst1;
 18.7041 +		uint dst2;
 18.7042 +		uint r1;
 18.7043 +		uint r2;
 18.7044 +		uint r3;
 18.7045 +		uint r4;
 18.7046 +		uint lo;
 18.7047 +		uint hi;
 18.7048 +
 18.7049 +		FLAG_C = CFLAG_CLEAR;
 18.7050 +
 18.7051 +		if(BIT_B(word2))			   /* signed */
 18.7052 +		{
 18.7053 +			if(GET_MSB_32(src))
 18.7054 +				src = (uint)MASK_OUT_ABOVE_32(-(sint)src);
 18.7055 +			if(GET_MSB_32(dst))
 18.7056 +				dst = (uint)MASK_OUT_ABOVE_32(-(sint)dst);
 18.7057 +		}
 18.7058 +
 18.7059 +		src1 = MASK_OUT_ABOVE_16(src);
 18.7060 +		src2 = src>>16;
 18.7061 +		dst1 = MASK_OUT_ABOVE_16(dst);
 18.7062 +		dst2 = dst>>16;
 18.7063 +
 18.7064 +
 18.7065 +		r1 = src1 * dst1;
 18.7066 +		r2 = src1 * dst2;
 18.7067 +		r3 = src2 * dst1;
 18.7068 +		r4 = src2 * dst2;
 18.7069 +
 18.7070 +		lo = r1 + (MASK_OUT_ABOVE_16(r2)<<16) + (MASK_OUT_ABOVE_16(r3)<<16);
 18.7071 +		hi = r4 + (r2>>16) + (r3>>16) + (((r1>>16) + MASK_OUT_ABOVE_16(r2) + MASK_OUT_ABOVE_16(r3)) >> 16);
 18.7072 +
 18.7073 +		if(BIT_B(word2) && neg)
 18.7074 +		{
 18.7075 +			hi = (uint)MASK_OUT_ABOVE_32((-(sint)hi) - (lo != 0));
 18.7076 +			lo = (uint)MASK_OUT_ABOVE_32(-(sint)lo);
 18.7077 +		}
 18.7078 +
 18.7079 +		if(BIT_A(word2))
 18.7080 +		{
 18.7081 +			REG_D[word2 & 7] = hi;
 18.7082 +			REG_D[(word2 >> 12) & 7] = lo;
 18.7083 +			FLAG_N = NFLAG_32(hi);
 18.7084 +			FLAG_Z = hi | lo;
 18.7085 +			FLAG_V = VFLAG_CLEAR;
 18.7086 +			return;
 18.7087 +		}
 18.7088 +
 18.7089 +		REG_D[(word2 >> 12) & 7] = lo;
 18.7090 +		FLAG_N = NFLAG_32(lo);
 18.7091 +		FLAG_Z = lo;
 18.7092 +		if(BIT_B(word2))
 18.7093 +			FLAG_V = (!((GET_MSB_32(lo) && hi == 0xffffffff) || (!GET_MSB_32(lo) && !hi)))<<7;
 18.7094 +		else
 18.7095 +			FLAG_V = (hi != 0) << 7;
 18.7096 +		return;
 18.7097 +	}
 18.7098 +	m68ki_exception_illegal();
 18.7099 +
 18.7100 +#endif
 18.7101 +}
 18.7102 +
 18.7103 +
 18.7104 +M68KMAKE_OP(mull, 32, ., .)
 18.7105 +{
 18.7106 +#if M68K_USE_64_BIT
 18.7107 +
 18.7108 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.7109 +	{
 18.7110 +		uint word2 = OPER_I_16();
 18.7111 +		uint64 src = M68KMAKE_GET_OPER_AY_32;
 18.7112 +		uint64 dst = REG_D[(word2 >> 12) & 7];
 18.7113 +		uint64 res;
 18.7114 +
 18.7115 +		FLAG_C = CFLAG_CLEAR;
 18.7116 +
 18.7117 +		if(BIT_B(word2))			   /* signed */
 18.7118 +		{
 18.7119 +			res = (sint64)((sint32)src) * (sint64)((sint32)dst);
 18.7120 +			if(!BIT_A(word2))
 18.7121 +			{
 18.7122 +				FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.7123 +				FLAG_N = NFLAG_32(res);
 18.7124 +				FLAG_V = ((sint64)res != (sint32)res)<<7;
 18.7125 +				REG_D[(word2 >> 12) & 7] = FLAG_Z;
 18.7126 +				return;
 18.7127 +			}
 18.7128 +			FLAG_Z = MASK_OUT_ABOVE_32(res) | (res>>32);
 18.7129 +			FLAG_N = NFLAG_64(res);
 18.7130 +			FLAG_V = VFLAG_CLEAR;
 18.7131 +			REG_D[word2 & 7] = (res >> 32);
 18.7132 +			REG_D[(word2 >> 12) & 7] = MASK_OUT_ABOVE_32(res);
 18.7133 +			return;
 18.7134 +		}
 18.7135 +
 18.7136 +		res = src * dst;
 18.7137 +		if(!BIT_A(word2))
 18.7138 +		{
 18.7139 +			FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.7140 +			FLAG_N = NFLAG_32(res);
 18.7141 +			FLAG_V = (res > 0xffffffff)<<7;
 18.7142 +			REG_D[(word2 >> 12) & 7] = FLAG_Z;
 18.7143 +			return;
 18.7144 +		}
 18.7145 +		FLAG_Z = MASK_OUT_ABOVE_32(res) | (res>>32);
 18.7146 +		FLAG_N = NFLAG_64(res);
 18.7147 +		FLAG_V = VFLAG_CLEAR;
 18.7148 +		REG_D[word2 & 7] = (res >> 32);
 18.7149 +		REG_D[(word2 >> 12) & 7] = MASK_OUT_ABOVE_32(res);
 18.7150 +		return;
 18.7151 +	}
 18.7152 +	m68ki_exception_illegal();
 18.7153 +
 18.7154 +#else
 18.7155 +
 18.7156 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.7157 +	{
 18.7158 +		uint word2 = OPER_I_16();
 18.7159 +		uint src = M68KMAKE_GET_OPER_AY_32;
 18.7160 +		uint dst = REG_D[(word2 >> 12) & 7];
 18.7161 +		uint neg = GET_MSB_32(src ^ dst);
 18.7162 +		uint src1;
 18.7163 +		uint src2;
 18.7164 +		uint dst1;
 18.7165 +		uint dst2;
 18.7166 +		uint r1;
 18.7167 +		uint r2;
 18.7168 +		uint r3;
 18.7169 +		uint r4;
 18.7170 +		uint lo;
 18.7171 +		uint hi;
 18.7172 +
 18.7173 +		FLAG_C = CFLAG_CLEAR;
 18.7174 +
 18.7175 +		if(BIT_B(word2))			   /* signed */
 18.7176 +		{
 18.7177 +			if(GET_MSB_32(src))
 18.7178 +				src = (uint)MASK_OUT_ABOVE_32(-(sint)src);
 18.7179 +			if(GET_MSB_32(dst))
 18.7180 +				dst = (uint)MASK_OUT_ABOVE_32(-(sint)dst);
 18.7181 +		}
 18.7182 +
 18.7183 +		src1 = MASK_OUT_ABOVE_16(src);
 18.7184 +		src2 = src>>16;
 18.7185 +		dst1 = MASK_OUT_ABOVE_16(dst);
 18.7186 +		dst2 = dst>>16;
 18.7187 +
 18.7188 +
 18.7189 +		r1 = src1 * dst1;
 18.7190 +		r2 = src1 * dst2;
 18.7191 +		r3 = src2 * dst1;
 18.7192 +		r4 = src2 * dst2;
 18.7193 +
 18.7194 +		lo = r1 + (MASK_OUT_ABOVE_16(r2)<<16) + (MASK_OUT_ABOVE_16(r3)<<16);
 18.7195 +		hi = r4 + (r2>>16) + (r3>>16) + (((r1>>16) + MASK_OUT_ABOVE_16(r2) + MASK_OUT_ABOVE_16(r3)) >> 16);
 18.7196 +
 18.7197 +		if(BIT_B(word2) && neg)
 18.7198 +		{
 18.7199 +			hi = (uint)MASK_OUT_ABOVE_32((-(sint)hi) - (lo != 0));
 18.7200 +			lo = (uint)MASK_OUT_ABOVE_32(-(sint)lo);
 18.7201 +		}
 18.7202 +
 18.7203 +		if(BIT_A(word2))
 18.7204 +		{
 18.7205 +			REG_D[word2 & 7] = hi;
 18.7206 +			REG_D[(word2 >> 12) & 7] = lo;
 18.7207 +			FLAG_N = NFLAG_32(hi);
 18.7208 +			FLAG_Z = hi | lo;
 18.7209 +			FLAG_V = VFLAG_CLEAR;
 18.7210 +			return;
 18.7211 +		}
 18.7212 +
 18.7213 +		REG_D[(word2 >> 12) & 7] = lo;
 18.7214 +		FLAG_N = NFLAG_32(lo);
 18.7215 +		FLAG_Z = lo;
 18.7216 +		if(BIT_B(word2))
 18.7217 +			FLAG_V = (!((GET_MSB_32(lo) && hi == 0xffffffff) || (!GET_MSB_32(lo) && !hi)))<<7;
 18.7218 +		else
 18.7219 +			FLAG_V = (hi != 0) << 7;
 18.7220 +		return;
 18.7221 +	}
 18.7222 +	m68ki_exception_illegal();
 18.7223 +
 18.7224 +#endif
 18.7225 +}
 18.7226 +
 18.7227 +
 18.7228 +M68KMAKE_OP(nbcd, 8, ., d)
 18.7229 +{
 18.7230 +	uint* r_dst = &DY;
 18.7231 +	uint dst = *r_dst;
 18.7232 +	uint res = MASK_OUT_ABOVE_8(0x9a - dst - XFLAG_AS_1());
 18.7233 +
 18.7234 +	if(res != 0x9a)
 18.7235 +	{
 18.7236 +		if((res & 0x0f) == 0xa)
 18.7237 +			res = (res & 0xf0) + 0x10;
 18.7238 +
 18.7239 +		res = MASK_OUT_ABOVE_8(res);
 18.7240 +
 18.7241 +		*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.7242 +
 18.7243 +		FLAG_Z |= res;
 18.7244 +		FLAG_C = CFLAG_SET;
 18.7245 +		FLAG_X = XFLAG_SET;
 18.7246 +	}
 18.7247 +	else
 18.7248 +	{
 18.7249 +		FLAG_C = CFLAG_CLEAR;
 18.7250 +		FLAG_X = XFLAG_CLEAR;
 18.7251 +	}
 18.7252 +	FLAG_N = NFLAG_8(res);	/* officially undefined */
 18.7253 +}
 18.7254 +
 18.7255 +
 18.7256 +M68KMAKE_OP(nbcd, 8, ., .)
 18.7257 +{
 18.7258 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.7259 +	uint dst = m68ki_read_8(ea);
 18.7260 +	uint res = MASK_OUT_ABOVE_8(0x9a - dst - XFLAG_AS_1());
 18.7261 +
 18.7262 +	if(res != 0x9a)
 18.7263 +	{
 18.7264 +		if((res & 0x0f) == 0xa)
 18.7265 +			res = (res & 0xf0) + 0x10;
 18.7266 +
 18.7267 +		res = MASK_OUT_ABOVE_8(res);
 18.7268 +
 18.7269 +		m68ki_write_8(ea, MASK_OUT_ABOVE_8(res));
 18.7270 +
 18.7271 +		FLAG_Z |= res;
 18.7272 +		FLAG_C = CFLAG_SET;
 18.7273 +		FLAG_X = XFLAG_SET;
 18.7274 +	}
 18.7275 +	else
 18.7276 +	{
 18.7277 +		FLAG_C = CFLAG_CLEAR;
 18.7278 +		FLAG_X = XFLAG_CLEAR;
 18.7279 +	}
 18.7280 +	FLAG_N = NFLAG_8(res);	/* officially undefined */
 18.7281 +}
 18.7282 +
 18.7283 +
 18.7284 +M68KMAKE_OP(neg, 8, ., d)
 18.7285 +{
 18.7286 +	uint* r_dst = &DY;
 18.7287 +	uint res = 0 - MASK_OUT_ABOVE_8(*r_dst);
 18.7288 +
 18.7289 +	FLAG_N = NFLAG_8(res);
 18.7290 +	FLAG_C = FLAG_X = CFLAG_8(res);
 18.7291 +	FLAG_V = *r_dst & res;
 18.7292 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.7293 +
 18.7294 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | FLAG_Z;
 18.7295 +}
 18.7296 +
 18.7297 +
 18.7298 +M68KMAKE_OP(neg, 8, ., .)
 18.7299 +{
 18.7300 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.7301 +	uint src = m68ki_read_8(ea);
 18.7302 +	uint res = 0 - src;
 18.7303 +
 18.7304 +	FLAG_N = NFLAG_8(res);
 18.7305 +	FLAG_C = FLAG_X = CFLAG_8(res);
 18.7306 +	FLAG_V = src & res;
 18.7307 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.7308 +
 18.7309 +	m68ki_write_8(ea, FLAG_Z);
 18.7310 +}
 18.7311 +
 18.7312 +
 18.7313 +M68KMAKE_OP(neg, 16, ., d)
 18.7314 +{
 18.7315 +	uint* r_dst = &DY;
 18.7316 +	uint res = 0 - MASK_OUT_ABOVE_16(*r_dst);
 18.7317 +
 18.7318 +	FLAG_N = NFLAG_16(res);
 18.7319 +	FLAG_C = FLAG_X = CFLAG_16(res);
 18.7320 +	FLAG_V = (*r_dst & res)>>8;
 18.7321 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.7322 +
 18.7323 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.7324 +}
 18.7325 +
 18.7326 +
 18.7327 +M68KMAKE_OP(neg, 16, ., .)
 18.7328 +{
 18.7329 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.7330 +	uint src = m68ki_read_16(ea);
 18.7331 +	uint res = 0 - src;
 18.7332 +
 18.7333 +	FLAG_N = NFLAG_16(res);
 18.7334 +	FLAG_C = FLAG_X = CFLAG_16(res);
 18.7335 +	FLAG_V = (src & res)>>8;
 18.7336 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.7337 +
 18.7338 +	m68ki_write_16(ea, FLAG_Z);
 18.7339 +}
 18.7340 +
 18.7341 +
 18.7342 +M68KMAKE_OP(neg, 32, ., d)
 18.7343 +{
 18.7344 +	uint* r_dst = &DY;
 18.7345 +	uint res = 0 - *r_dst;
 18.7346 +
 18.7347 +	FLAG_N = NFLAG_32(res);
 18.7348 +	FLAG_C = FLAG_X = CFLAG_SUB_32(*r_dst, 0, res);
 18.7349 +	FLAG_V = (*r_dst & res)>>24;
 18.7350 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.7351 +
 18.7352 +	*r_dst = FLAG_Z;
 18.7353 +}
 18.7354 +
 18.7355 +
 18.7356 +M68KMAKE_OP(neg, 32, ., .)
 18.7357 +{
 18.7358 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.7359 +	uint src = m68ki_read_32(ea);
 18.7360 +	uint res = 0 - src;
 18.7361 +
 18.7362 +	FLAG_N = NFLAG_32(res);
 18.7363 +	FLAG_C = FLAG_X = CFLAG_SUB_32(src, 0, res);
 18.7364 +	FLAG_V = (src & res)>>24;
 18.7365 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.7366 +
 18.7367 +	m68ki_write_32(ea, FLAG_Z);
 18.7368 +}
 18.7369 +
 18.7370 +
 18.7371 +M68KMAKE_OP(negx, 8, ., d)
 18.7372 +{
 18.7373 +	uint* r_dst = &DY;
 18.7374 +	uint res = 0 - MASK_OUT_ABOVE_8(*r_dst) - XFLAG_AS_1();
 18.7375 +
 18.7376 +	FLAG_N = NFLAG_8(res);
 18.7377 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.7378 +	FLAG_V = *r_dst & res;
 18.7379 +
 18.7380 +	res = MASK_OUT_ABOVE_8(res);
 18.7381 +	FLAG_Z |= res;
 18.7382 +
 18.7383 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.7384 +}
 18.7385 +
 18.7386 +
 18.7387 +M68KMAKE_OP(negx, 8, ., .)
 18.7388 +{
 18.7389 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.7390 +	uint src = m68ki_read_8(ea);
 18.7391 +	uint res = 0 - src - XFLAG_AS_1();
 18.7392 +
 18.7393 +	FLAG_N = NFLAG_8(res);
 18.7394 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.7395 +	FLAG_V = src & res;
 18.7396 +
 18.7397 +	res = MASK_OUT_ABOVE_8(res);
 18.7398 +	FLAG_Z |= res;
 18.7399 +
 18.7400 +	m68ki_write_8(ea, res);
 18.7401 +}
 18.7402 +
 18.7403 +
 18.7404 +M68KMAKE_OP(negx, 16, ., d)
 18.7405 +{
 18.7406 +	uint* r_dst = &DY;
 18.7407 +	uint res = 0 - MASK_OUT_ABOVE_16(*r_dst) - XFLAG_AS_1();
 18.7408 +
 18.7409 +	FLAG_N = NFLAG_16(res);
 18.7410 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.7411 +	FLAG_V = (*r_dst & res)>>8;
 18.7412 +
 18.7413 +	res = MASK_OUT_ABOVE_16(res);
 18.7414 +	FLAG_Z |= res;
 18.7415 +
 18.7416 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.7417 +}
 18.7418 +
 18.7419 +
 18.7420 +M68KMAKE_OP(negx, 16, ., .)
 18.7421 +{
 18.7422 +	uint ea  = M68KMAKE_GET_EA_AY_16;
 18.7423 +	uint src = m68ki_read_16(ea);
 18.7424 +	uint res = 0 - MASK_OUT_ABOVE_16(src) - XFLAG_AS_1();
 18.7425 +
 18.7426 +	FLAG_N = NFLAG_16(res);
 18.7427 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.7428 +	FLAG_V = (src & res)>>8;
 18.7429 +
 18.7430 +	res = MASK_OUT_ABOVE_16(res);
 18.7431 +	FLAG_Z |= res;
 18.7432 +
 18.7433 +	m68ki_write_16(ea, res);
 18.7434 +}
 18.7435 +
 18.7436 +
 18.7437 +M68KMAKE_OP(negx, 32, ., d)
 18.7438 +{
 18.7439 +	uint* r_dst = &DY;
 18.7440 +	uint res = 0 - MASK_OUT_ABOVE_32(*r_dst) - XFLAG_AS_1();
 18.7441 +
 18.7442 +	FLAG_N = NFLAG_32(res);
 18.7443 +	FLAG_X = FLAG_C = CFLAG_SUB_32(*r_dst, 0, res);
 18.7444 +	FLAG_V = (*r_dst & res)>>24;
 18.7445 +
 18.7446 +	res = MASK_OUT_ABOVE_32(res);
 18.7447 +	FLAG_Z |= res;
 18.7448 +
 18.7449 +	*r_dst = res;
 18.7450 +}
 18.7451 +
 18.7452 +
 18.7453 +M68KMAKE_OP(negx, 32, ., .)
 18.7454 +{
 18.7455 +	uint ea  = M68KMAKE_GET_EA_AY_32;
 18.7456 +	uint src = m68ki_read_32(ea);
 18.7457 +	uint res = 0 - MASK_OUT_ABOVE_32(src) - XFLAG_AS_1();
 18.7458 +
 18.7459 +	FLAG_N = NFLAG_32(res);
 18.7460 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, 0, res);
 18.7461 +	FLAG_V = (src & res)>>24;
 18.7462 +
 18.7463 +	res = MASK_OUT_ABOVE_32(res);
 18.7464 +	FLAG_Z |= res;
 18.7465 +
 18.7466 +	m68ki_write_32(ea, res);
 18.7467 +}
 18.7468 +
 18.7469 +
 18.7470 +M68KMAKE_OP(nop, 0, ., .)
 18.7471 +{
 18.7472 +	m68ki_trace_t0();				   /* auto-disable (see m68kcpu.h) */
 18.7473 +}
 18.7474 +
 18.7475 +
 18.7476 +M68KMAKE_OP(not, 8, ., d)
 18.7477 +{
 18.7478 +	uint* r_dst = &DY;
 18.7479 +	uint res = MASK_OUT_ABOVE_8(~*r_dst);
 18.7480 +
 18.7481 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.7482 +
 18.7483 +	FLAG_N = NFLAG_8(res);
 18.7484 +	FLAG_Z = res;
 18.7485 +	FLAG_C = CFLAG_CLEAR;
 18.7486 +	FLAG_V = VFLAG_CLEAR;
 18.7487 +}
 18.7488 +
 18.7489 +
 18.7490 +M68KMAKE_OP(not, 8, ., .)
 18.7491 +{
 18.7492 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.7493 +	uint res = MASK_OUT_ABOVE_8(~m68ki_read_8(ea));
 18.7494 +
 18.7495 +	m68ki_write_8(ea, res);
 18.7496 +
 18.7497 +	FLAG_N = NFLAG_8(res);
 18.7498 +	FLAG_Z = res;
 18.7499 +	FLAG_C = CFLAG_CLEAR;
 18.7500 +	FLAG_V = VFLAG_CLEAR;
 18.7501 +}
 18.7502 +
 18.7503 +
 18.7504 +M68KMAKE_OP(not, 16, ., d)
 18.7505 +{
 18.7506 +	uint* r_dst = &DY;
 18.7507 +	uint res = MASK_OUT_ABOVE_16(~*r_dst);
 18.7508 +
 18.7509 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.7510 +
 18.7511 +	FLAG_N = NFLAG_16(res);
 18.7512 +	FLAG_Z = res;
 18.7513 +	FLAG_C = CFLAG_CLEAR;
 18.7514 +	FLAG_V = VFLAG_CLEAR;
 18.7515 +}
 18.7516 +
 18.7517 +
 18.7518 +M68KMAKE_OP(not, 16, ., .)
 18.7519 +{
 18.7520 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.7521 +	uint res = MASK_OUT_ABOVE_16(~m68ki_read_16(ea));
 18.7522 +
 18.7523 +	m68ki_write_16(ea, res);
 18.7524 +
 18.7525 +	FLAG_N = NFLAG_16(res);
 18.7526 +	FLAG_Z = res;
 18.7527 +	FLAG_C = CFLAG_CLEAR;
 18.7528 +	FLAG_V = VFLAG_CLEAR;
 18.7529 +}
 18.7530 +
 18.7531 +
 18.7532 +M68KMAKE_OP(not, 32, ., d)
 18.7533 +{
 18.7534 +	uint* r_dst = &DY;
 18.7535 +	uint res = *r_dst = MASK_OUT_ABOVE_32(~*r_dst);
 18.7536 +
 18.7537 +	FLAG_N = NFLAG_32(res);
 18.7538 +	FLAG_Z = res;
 18.7539 +	FLAG_C = CFLAG_CLEAR;
 18.7540 +	FLAG_V = VFLAG_CLEAR;
 18.7541 +}
 18.7542 +
 18.7543 +
 18.7544 +M68KMAKE_OP(not, 32, ., .)
 18.7545 +{
 18.7546 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.7547 +	uint res = MASK_OUT_ABOVE_32(~m68ki_read_32(ea));
 18.7548 +
 18.7549 +	m68ki_write_32(ea, res);
 18.7550 +
 18.7551 +	FLAG_N = NFLAG_32(res);
 18.7552 +	FLAG_Z = res;
 18.7553 +	FLAG_C = CFLAG_CLEAR;
 18.7554 +	FLAG_V = VFLAG_CLEAR;
 18.7555 +}
 18.7556 +
 18.7557 +
 18.7558 +M68KMAKE_OP(or, 8, er, d)
 18.7559 +{
 18.7560 +	uint res = MASK_OUT_ABOVE_8((DX |= MASK_OUT_ABOVE_8(DY)));
 18.7561 +
 18.7562 +	FLAG_N = NFLAG_8(res);
 18.7563 +	FLAG_Z = res;
 18.7564 +	FLAG_C = CFLAG_CLEAR;
 18.7565 +	FLAG_V = VFLAG_CLEAR;
 18.7566 +}
 18.7567 +
 18.7568 +
 18.7569 +M68KMAKE_OP(or, 8, er, .)
 18.7570 +{
 18.7571 +	uint res = MASK_OUT_ABOVE_8((DX |= M68KMAKE_GET_OPER_AY_8));
 18.7572 +
 18.7573 +	FLAG_N = NFLAG_8(res);
 18.7574 +	FLAG_Z = res;
 18.7575 +	FLAG_C = CFLAG_CLEAR;
 18.7576 +	FLAG_V = VFLAG_CLEAR;
 18.7577 +}
 18.7578 +
 18.7579 +
 18.7580 +M68KMAKE_OP(or, 16, er, d)
 18.7581 +{
 18.7582 +	uint res = MASK_OUT_ABOVE_16((DX |= MASK_OUT_ABOVE_16(DY)));
 18.7583 +
 18.7584 +	FLAG_N = NFLAG_16(res);
 18.7585 +	FLAG_Z = res;
 18.7586 +	FLAG_C = CFLAG_CLEAR;
 18.7587 +	FLAG_V = VFLAG_CLEAR;
 18.7588 +}
 18.7589 +
 18.7590 +
 18.7591 +M68KMAKE_OP(or, 16, er, .)
 18.7592 +{
 18.7593 +	uint res = MASK_OUT_ABOVE_16((DX |= M68KMAKE_GET_OPER_AY_16));
 18.7594 +
 18.7595 +	FLAG_N = NFLAG_16(res);
 18.7596 +	FLAG_Z = res;
 18.7597 +	FLAG_C = CFLAG_CLEAR;
 18.7598 +	FLAG_V = VFLAG_CLEAR;
 18.7599 +}
 18.7600 +
 18.7601 +
 18.7602 +M68KMAKE_OP(or, 32, er, d)
 18.7603 +{
 18.7604 +	uint res = DX |= DY;
 18.7605 +
 18.7606 +	FLAG_N = NFLAG_32(res);
 18.7607 +	FLAG_Z = res;
 18.7608 +	FLAG_C = CFLAG_CLEAR;
 18.7609 +	FLAG_V = VFLAG_CLEAR;
 18.7610 +}
 18.7611 +
 18.7612 +
 18.7613 +M68KMAKE_OP(or, 32, er, .)
 18.7614 +{
 18.7615 +	uint res = DX |= M68KMAKE_GET_OPER_AY_32;
 18.7616 +
 18.7617 +	FLAG_N = NFLAG_32(res);
 18.7618 +	FLAG_Z = res;
 18.7619 +	FLAG_C = CFLAG_CLEAR;
 18.7620 +	FLAG_V = VFLAG_CLEAR;
 18.7621 +}
 18.7622 +
 18.7623 +
 18.7624 +M68KMAKE_OP(or, 8, re, .)
 18.7625 +{
 18.7626 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.7627 +	uint res = MASK_OUT_ABOVE_8(DX | m68ki_read_8(ea));
 18.7628 +
 18.7629 +	m68ki_write_8(ea, res);
 18.7630 +
 18.7631 +	FLAG_N = NFLAG_8(res);
 18.7632 +	FLAG_Z = res;
 18.7633 +	FLAG_C = CFLAG_CLEAR;
 18.7634 +	FLAG_V = VFLAG_CLEAR;
 18.7635 +}
 18.7636 +
 18.7637 +
 18.7638 +M68KMAKE_OP(or, 16, re, .)
 18.7639 +{
 18.7640 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.7641 +	uint res = MASK_OUT_ABOVE_16(DX | m68ki_read_16(ea));
 18.7642 +
 18.7643 +	m68ki_write_16(ea, res);
 18.7644 +
 18.7645 +	FLAG_N = NFLAG_16(res);
 18.7646 +	FLAG_Z = res;
 18.7647 +	FLAG_C = CFLAG_CLEAR;
 18.7648 +	FLAG_V = VFLAG_CLEAR;
 18.7649 +}
 18.7650 +
 18.7651 +
 18.7652 +M68KMAKE_OP(or, 32, re, .)
 18.7653 +{
 18.7654 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.7655 +	uint res = DX | m68ki_read_32(ea);
 18.7656 +
 18.7657 +	m68ki_write_32(ea, res);
 18.7658 +
 18.7659 +	FLAG_N = NFLAG_32(res);
 18.7660 +	FLAG_Z = res;
 18.7661 +	FLAG_C = CFLAG_CLEAR;
 18.7662 +	FLAG_V = VFLAG_CLEAR;
 18.7663 +}
 18.7664 +
 18.7665 +
 18.7666 +M68KMAKE_OP(ori, 8, ., d)
 18.7667 +{
 18.7668 +	uint res = MASK_OUT_ABOVE_8((DY |= OPER_I_8()));
 18.7669 +
 18.7670 +	FLAG_N = NFLAG_8(res);
 18.7671 +	FLAG_Z = res;
 18.7672 +	FLAG_C = CFLAG_CLEAR;
 18.7673 +	FLAG_V = VFLAG_CLEAR;
 18.7674 +}
 18.7675 +
 18.7676 +
 18.7677 +M68KMAKE_OP(ori, 8, ., .)
 18.7678 +{
 18.7679 +	uint src = OPER_I_8();
 18.7680 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.7681 +	uint res = MASK_OUT_ABOVE_8(src | m68ki_read_8(ea));
 18.7682 +
 18.7683 +	m68ki_write_8(ea, res);
 18.7684 +
 18.7685 +	FLAG_N = NFLAG_8(res);
 18.7686 +	FLAG_Z = res;
 18.7687 +	FLAG_C = CFLAG_CLEAR;
 18.7688 +	FLAG_V = VFLAG_CLEAR;
 18.7689 +}
 18.7690 +
 18.7691 +
 18.7692 +M68KMAKE_OP(ori, 16, ., d)
 18.7693 +{
 18.7694 +	uint res = MASK_OUT_ABOVE_16(DY |= OPER_I_16());
 18.7695 +
 18.7696 +	FLAG_N = NFLAG_16(res);
 18.7697 +	FLAG_Z = res;
 18.7698 +	FLAG_C = CFLAG_CLEAR;
 18.7699 +	FLAG_V = VFLAG_CLEAR;
 18.7700 +}
 18.7701 +
 18.7702 +
 18.7703 +M68KMAKE_OP(ori, 16, ., .)
 18.7704 +{
 18.7705 +	uint src = OPER_I_16();
 18.7706 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.7707 +	uint res = MASK_OUT_ABOVE_16(src | m68ki_read_16(ea));
 18.7708 +
 18.7709 +	m68ki_write_16(ea, res);
 18.7710 +
 18.7711 +	FLAG_N = NFLAG_16(res);
 18.7712 +	FLAG_Z = res;
 18.7713 +	FLAG_C = CFLAG_CLEAR;
 18.7714 +	FLAG_V = VFLAG_CLEAR;
 18.7715 +}
 18.7716 +
 18.7717 +
 18.7718 +M68KMAKE_OP(ori, 32, ., d)
 18.7719 +{
 18.7720 +	uint res = DY |= OPER_I_32();
 18.7721 +
 18.7722 +	FLAG_N = NFLAG_32(res);
 18.7723 +	FLAG_Z = res;
 18.7724 +	FLAG_C = CFLAG_CLEAR;
 18.7725 +	FLAG_V = VFLAG_CLEAR;
 18.7726 +}
 18.7727 +
 18.7728 +
 18.7729 +M68KMAKE_OP(ori, 32, ., .)
 18.7730 +{
 18.7731 +	uint src = OPER_I_32();
 18.7732 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.7733 +	uint res = src | m68ki_read_32(ea);
 18.7734 +
 18.7735 +	m68ki_write_32(ea, res);
 18.7736 +
 18.7737 +	FLAG_N = NFLAG_32(res);
 18.7738 +	FLAG_Z = res;
 18.7739 +	FLAG_C = CFLAG_CLEAR;
 18.7740 +	FLAG_V = VFLAG_CLEAR;
 18.7741 +}
 18.7742 +
 18.7743 +
 18.7744 +M68KMAKE_OP(ori, 16, toc, .)
 18.7745 +{
 18.7746 +	m68ki_set_ccr(m68ki_get_ccr() | OPER_I_16());
 18.7747 +}
 18.7748 +
 18.7749 +
 18.7750 +M68KMAKE_OP(ori, 16, tos, .)
 18.7751 +{
 18.7752 +	if(FLAG_S)
 18.7753 +	{
 18.7754 +		uint src = OPER_I_16();
 18.7755 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.7756 +		m68ki_set_sr(m68ki_get_sr() | src);
 18.7757 +		return;
 18.7758 +	}
 18.7759 +	m68ki_exception_privilege_violation();
 18.7760 +}
 18.7761 +
 18.7762 +
 18.7763 +M68KMAKE_OP(pack, 16, rr, .)
 18.7764 +{
 18.7765 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.7766 +	{
 18.7767 +		/* Note: DX and DY are reversed in Motorola's docs */
 18.7768 +		uint src = DY + OPER_I_16();
 18.7769 +		uint* r_dst = &DX;
 18.7770 +
 18.7771 +		*r_dst = MASK_OUT_BELOW_8(*r_dst) | ((src >> 4) & 0x00f0) | (src & 0x000f);
 18.7772 +		return;
 18.7773 +	}
 18.7774 +	m68ki_exception_illegal();
 18.7775 +}
 18.7776 +
 18.7777 +
 18.7778 +M68KMAKE_OP(pack, 16, mm, ax7)
 18.7779 +{
 18.7780 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.7781 +	{
 18.7782 +		/* Note: AX and AY are reversed in Motorola's docs */
 18.7783 +		uint ea_src = EA_AY_PD_8();
 18.7784 +		uint src = m68ki_read_8(ea_src);
 18.7785 +		ea_src = EA_AY_PD_8();
 18.7786 +		src = ((src << 8) | m68ki_read_8(ea_src)) + OPER_I_16();
 18.7787 +
 18.7788 +		m68ki_write_8(EA_A7_PD_8(), ((src >> 4) & 0x00f0) | (src & 0x000f));
 18.7789 +		return;
 18.7790 +	}
 18.7791 +	m68ki_exception_illegal();
 18.7792 +}
 18.7793 +
 18.7794 +
 18.7795 +M68KMAKE_OP(pack, 16, mm, ay7)
 18.7796 +{
 18.7797 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.7798 +	{
 18.7799 +		/* Note: AX and AY are reversed in Motorola's docs */
 18.7800 +		uint ea_src = EA_A7_PD_8();
 18.7801 +		uint src = m68ki_read_8(ea_src);
 18.7802 +		ea_src = EA_A7_PD_8();
 18.7803 +		src = ((src << 8) | m68ki_read_8(ea_src)) + OPER_I_16();
 18.7804 +
 18.7805 +		m68ki_write_8(EA_AX_PD_8(), ((src >> 4) & 0x00f0) | (src & 0x000f));
 18.7806 +		return;
 18.7807 +	}
 18.7808 +	m68ki_exception_illegal();
 18.7809 +}
 18.7810 +
 18.7811 +
 18.7812 +M68KMAKE_OP(pack, 16, mm, axy7)
 18.7813 +{
 18.7814 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.7815 +	{
 18.7816 +		uint ea_src = EA_A7_PD_8();
 18.7817 +		uint src = m68ki_read_8(ea_src);
 18.7818 +		ea_src = EA_A7_PD_8();
 18.7819 +		src = ((src << 8) | m68ki_read_8(ea_src)) + OPER_I_16();
 18.7820 +
 18.7821 +		m68ki_write_8(EA_A7_PD_8(), ((src >> 4) & 0x00f0) | (src & 0x000f));
 18.7822 +		return;
 18.7823 +	}
 18.7824 +	m68ki_exception_illegal();
 18.7825 +}
 18.7826 +
 18.7827 +
 18.7828 +M68KMAKE_OP(pack, 16, mm, .)
 18.7829 +{
 18.7830 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.7831 +	{
 18.7832 +		/* Note: AX and AY are reversed in Motorola's docs */
 18.7833 +		uint ea_src = EA_AY_PD_8();
 18.7834 +		uint src = m68ki_read_8(ea_src);
 18.7835 +		ea_src = EA_AY_PD_8();
 18.7836 +		src = ((src << 8) | m68ki_read_8(ea_src)) + OPER_I_16();
 18.7837 +
 18.7838 +		m68ki_write_8(EA_AX_PD_8(), ((src >> 4) & 0x00f0) | (src & 0x000f));
 18.7839 +		return;
 18.7840 +	}
 18.7841 +	m68ki_exception_illegal();
 18.7842 +}
 18.7843 +
 18.7844 +
 18.7845 +M68KMAKE_OP(pea, 32, ., .)
 18.7846 +{
 18.7847 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.7848 +
 18.7849 +	m68ki_push_32(ea);
 18.7850 +}
 18.7851 +
 18.7852 +
 18.7853 +M68KMAKE_OP(reset, 0, ., .)
 18.7854 +{
 18.7855 +	if(FLAG_S)
 18.7856 +	{
 18.7857 +		m68ki_output_reset();		   /* auto-disable (see m68kcpu.h) */
 18.7858 +		USE_CYCLES(CYC_RESET);
 18.7859 +		return;
 18.7860 +	}
 18.7861 +	m68ki_exception_privilege_violation();
 18.7862 +}
 18.7863 +
 18.7864 +
 18.7865 +M68KMAKE_OP(ror, 8, s, .)
 18.7866 +{
 18.7867 +	uint* r_dst = &DY;
 18.7868 +	uint orig_shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.7869 +	uint shift = orig_shift & 7;
 18.7870 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.7871 +	uint res = ROR_8(src, shift);
 18.7872 +
 18.7873 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.7874 +
 18.7875 +	FLAG_N = NFLAG_8(res);
 18.7876 +	FLAG_Z = res;
 18.7877 +	FLAG_C = src << (9-orig_shift);
 18.7878 +	FLAG_V = VFLAG_CLEAR;
 18.7879 +}
 18.7880 +
 18.7881 +
 18.7882 +M68KMAKE_OP(ror, 16, s, .)
 18.7883 +{
 18.7884 +	uint* r_dst = &DY;
 18.7885 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.7886 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.7887 +	uint res = ROR_16(src, shift);
 18.7888 +
 18.7889 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.7890 +
 18.7891 +	FLAG_N = NFLAG_16(res);
 18.7892 +	FLAG_Z = res;
 18.7893 +	FLAG_C = src << (9-shift);
 18.7894 +	FLAG_V = VFLAG_CLEAR;
 18.7895 +}
 18.7896 +
 18.7897 +
 18.7898 +M68KMAKE_OP(ror, 32, s, .)
 18.7899 +{
 18.7900 +	uint* r_dst = &DY;
 18.7901 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.7902 +	uint64 src = *r_dst;
 18.7903 +	uint res = ROR_32(src, shift);
 18.7904 +
 18.7905 +	*r_dst = res;
 18.7906 +
 18.7907 +	FLAG_N = NFLAG_32(res);
 18.7908 +	FLAG_Z = res;
 18.7909 +	FLAG_C = src << (9-shift);
 18.7910 +	FLAG_V = VFLAG_CLEAR;
 18.7911 +}
 18.7912 +
 18.7913 +
 18.7914 +M68KMAKE_OP(ror, 8, r, .)
 18.7915 +{
 18.7916 +	uint* r_dst = &DY;
 18.7917 +	uint orig_shift = DX & 0x3f;
 18.7918 +	uint shift = orig_shift & 7;
 18.7919 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.7920 +	uint res = ROR_8(src, shift);
 18.7921 +
 18.7922 +	if(orig_shift != 0)
 18.7923 +	{
 18.7924 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.7925 +
 18.7926 +		*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.7927 +		FLAG_C = src << (8-((shift-1)&7));
 18.7928 +		FLAG_N = NFLAG_8(res);
 18.7929 +		FLAG_Z = res;
 18.7930 +		FLAG_V = VFLAG_CLEAR;
 18.7931 +		return;
 18.7932 +	}
 18.7933 +
 18.7934 +	FLAG_C = CFLAG_CLEAR;
 18.7935 +	FLAG_N = NFLAG_8(src);
 18.7936 +	FLAG_Z = src;
 18.7937 +	FLAG_V = VFLAG_CLEAR;
 18.7938 +}
 18.7939 +
 18.7940 +
 18.7941 +M68KMAKE_OP(ror, 16, r, .)
 18.7942 +{
 18.7943 +	uint* r_dst = &DY;
 18.7944 +	uint orig_shift = DX & 0x3f;
 18.7945 +	uint shift = orig_shift & 15;
 18.7946 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.7947 +	uint res = ROR_16(src, shift);
 18.7948 +
 18.7949 +	if(orig_shift != 0)
 18.7950 +	{
 18.7951 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.7952 +
 18.7953 +		*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.7954 +		FLAG_C = (src >> ((shift - 1) & 15)) << 8;
 18.7955 +		FLAG_N = NFLAG_16(res);
 18.7956 +		FLAG_Z = res;
 18.7957 +		FLAG_V = VFLAG_CLEAR;
 18.7958 +		return;
 18.7959 +	}
 18.7960 +
 18.7961 +	FLAG_C = CFLAG_CLEAR;
 18.7962 +	FLAG_N = NFLAG_16(src);
 18.7963 +	FLAG_Z = src;
 18.7964 +	FLAG_V = VFLAG_CLEAR;
 18.7965 +}
 18.7966 +
 18.7967 +
 18.7968 +M68KMAKE_OP(ror, 32, r, .)
 18.7969 +{
 18.7970 +	uint* r_dst = &DY;
 18.7971 +	uint orig_shift = DX & 0x3f;
 18.7972 +	uint shift = orig_shift & 31;
 18.7973 +	uint64 src = *r_dst;
 18.7974 +	uint res = ROR_32(src, shift);
 18.7975 +
 18.7976 +	if(orig_shift != 0)
 18.7977 +	{
 18.7978 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.7979 +
 18.7980 +		*r_dst = res;
 18.7981 +		FLAG_C = (src >> ((shift - 1) & 31)) << 8;
 18.7982 +		FLAG_N = NFLAG_32(res);
 18.7983 +		FLAG_Z = res;
 18.7984 +		FLAG_V = VFLAG_CLEAR;
 18.7985 +		return;
 18.7986 +	}
 18.7987 +
 18.7988 +	FLAG_C = CFLAG_CLEAR;
 18.7989 +	FLAG_N = NFLAG_32(src);
 18.7990 +	FLAG_Z = src;
 18.7991 +	FLAG_V = VFLAG_CLEAR;
 18.7992 +}
 18.7993 +
 18.7994 +
 18.7995 +M68KMAKE_OP(ror, 16, ., .)
 18.7996 +{
 18.7997 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.7998 +	uint src = m68ki_read_16(ea);
 18.7999 +	uint res = ROR_16(src, 1);
 18.8000 +
 18.8001 +	m68ki_write_16(ea, res);
 18.8002 +
 18.8003 +	FLAG_N = NFLAG_16(res);
 18.8004 +	FLAG_Z = res;
 18.8005 +	FLAG_C = src << 8;
 18.8006 +	FLAG_V = VFLAG_CLEAR;
 18.8007 +}
 18.8008 +
 18.8009 +
 18.8010 +M68KMAKE_OP(rol, 8, s, .)
 18.8011 +{
 18.8012 +	uint* r_dst = &DY;
 18.8013 +	uint orig_shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8014 +	uint shift = orig_shift & 7;
 18.8015 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.8016 +	uint res = ROL_8(src, shift);
 18.8017 +
 18.8018 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.8019 +
 18.8020 +	FLAG_N = NFLAG_8(res);
 18.8021 +	FLAG_Z = res;
 18.8022 +	FLAG_C = src << orig_shift;
 18.8023 +	FLAG_V = VFLAG_CLEAR;
 18.8024 +}
 18.8025 +
 18.8026 +
 18.8027 +M68KMAKE_OP(rol, 16, s, .)
 18.8028 +{
 18.8029 +	uint* r_dst = &DY;
 18.8030 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8031 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.8032 +	uint res = ROL_16(src, shift);
 18.8033 +
 18.8034 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.8035 +
 18.8036 +	FLAG_N = NFLAG_16(res);
 18.8037 +	FLAG_Z = res;
 18.8038 +	FLAG_C = src >> (8-shift);
 18.8039 +	FLAG_V = VFLAG_CLEAR;
 18.8040 +}
 18.8041 +
 18.8042 +
 18.8043 +M68KMAKE_OP(rol, 32, s, .)
 18.8044 +{
 18.8045 +	uint* r_dst = &DY;
 18.8046 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8047 +	uint64 src = *r_dst;
 18.8048 +	uint res = ROL_32(src, shift);
 18.8049 +
 18.8050 +	*r_dst = res;
 18.8051 +
 18.8052 +	FLAG_N = NFLAG_32(res);
 18.8053 +	FLAG_Z = res;
 18.8054 +	FLAG_C = src >> (24-shift);
 18.8055 +	FLAG_V = VFLAG_CLEAR;
 18.8056 +}
 18.8057 +
 18.8058 +
 18.8059 +M68KMAKE_OP(rol, 8, r, .)
 18.8060 +{
 18.8061 +	uint* r_dst = &DY;
 18.8062 +	uint orig_shift = DX & 0x3f;
 18.8063 +	uint shift = orig_shift & 7;
 18.8064 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.8065 +	uint res = ROL_8(src, shift);
 18.8066 +
 18.8067 +	if(orig_shift != 0)
 18.8068 +	{
 18.8069 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8070 +
 18.8071 +		if(shift != 0)
 18.8072 +		{
 18.8073 +			*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.8074 +			FLAG_C = src << shift;
 18.8075 +			FLAG_N = NFLAG_8(res);
 18.8076 +			FLAG_Z = res;
 18.8077 +			FLAG_V = VFLAG_CLEAR;
 18.8078 +			return;
 18.8079 +		}
 18.8080 +		FLAG_C = (src & 1)<<8;
 18.8081 +		FLAG_N = NFLAG_8(src);
 18.8082 +		FLAG_Z = src;
 18.8083 +		FLAG_V = VFLAG_CLEAR;
 18.8084 +		return;
 18.8085 +	}
 18.8086 +
 18.8087 +	FLAG_C = CFLAG_CLEAR;
 18.8088 +	FLAG_N = NFLAG_8(src);
 18.8089 +	FLAG_Z = src;
 18.8090 +	FLAG_V = VFLAG_CLEAR;
 18.8091 +}
 18.8092 +
 18.8093 +
 18.8094 +M68KMAKE_OP(rol, 16, r, .)
 18.8095 +{
 18.8096 +	uint* r_dst = &DY;
 18.8097 +	uint orig_shift = DX & 0x3f;
 18.8098 +	uint shift = orig_shift & 15;
 18.8099 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.8100 +	uint res = MASK_OUT_ABOVE_16(ROL_16(src, shift));
 18.8101 +
 18.8102 +	if(orig_shift != 0)
 18.8103 +	{
 18.8104 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8105 +
 18.8106 +		if(shift != 0)
 18.8107 +		{
 18.8108 +			*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.8109 +			FLAG_C = (src << shift) >> 8;
 18.8110 +			FLAG_N = NFLAG_16(res);
 18.8111 +			FLAG_Z = res;
 18.8112 +			FLAG_V = VFLAG_CLEAR;
 18.8113 +			return;
 18.8114 +		}
 18.8115 +		FLAG_C = (src & 1)<<8;
 18.8116 +		FLAG_N = NFLAG_16(src);
 18.8117 +		FLAG_Z = src;
 18.8118 +		FLAG_V = VFLAG_CLEAR;
 18.8119 +		return;
 18.8120 +	}
 18.8121 +
 18.8122 +	FLAG_C = CFLAG_CLEAR;
 18.8123 +	FLAG_N = NFLAG_16(src);
 18.8124 +	FLAG_Z = src;
 18.8125 +	FLAG_V = VFLAG_CLEAR;
 18.8126 +}
 18.8127 +
 18.8128 +
 18.8129 +M68KMAKE_OP(rol, 32, r, .)
 18.8130 +{
 18.8131 +	uint* r_dst = &DY;
 18.8132 +	uint orig_shift = DX & 0x3f;
 18.8133 +	uint shift = orig_shift & 31;
 18.8134 +	uint64 src = *r_dst;
 18.8135 +	uint res = ROL_32(src, shift);
 18.8136 +
 18.8137 +	if(orig_shift != 0)
 18.8138 +	{
 18.8139 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8140 +
 18.8141 +		*r_dst = res;
 18.8142 +
 18.8143 +		FLAG_C = (src >> (32 - shift)) << 8;
 18.8144 +		FLAG_N = NFLAG_32(res);
 18.8145 +		FLAG_Z = res;
 18.8146 +		FLAG_V = VFLAG_CLEAR;
 18.8147 +		return;
 18.8148 +	}
 18.8149 +
 18.8150 +	FLAG_C = CFLAG_CLEAR;
 18.8151 +	FLAG_N = NFLAG_32(src);
 18.8152 +	FLAG_Z = src;
 18.8153 +	FLAG_V = VFLAG_CLEAR;
 18.8154 +}
 18.8155 +
 18.8156 +
 18.8157 +M68KMAKE_OP(rol, 16, ., .)
 18.8158 +{
 18.8159 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.8160 +	uint src = m68ki_read_16(ea);
 18.8161 +	uint res = MASK_OUT_ABOVE_16(ROL_16(src, 1));
 18.8162 +
 18.8163 +	m68ki_write_16(ea, res);
 18.8164 +
 18.8165 +	FLAG_N = NFLAG_16(res);
 18.8166 +	FLAG_Z = res;
 18.8167 +	FLAG_C = src >> 7;
 18.8168 +	FLAG_V = VFLAG_CLEAR;
 18.8169 +}
 18.8170 +
 18.8171 +
 18.8172 +M68KMAKE_OP(roxr, 8, s, .)
 18.8173 +{
 18.8174 +	uint* r_dst = &DY;
 18.8175 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8176 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.8177 +	uint res = ROR_9(src | (XFLAG_AS_1() << 8), shift);
 18.8178 +
 18.8179 +	FLAG_C = FLAG_X = res;
 18.8180 +	res = MASK_OUT_ABOVE_8(res);
 18.8181 +
 18.8182 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.8183 +
 18.8184 +	FLAG_N = NFLAG_8(res);
 18.8185 +	FLAG_Z = res;
 18.8186 +	FLAG_V = VFLAG_CLEAR;
 18.8187 +}
 18.8188 +
 18.8189 +
 18.8190 +M68KMAKE_OP(roxr, 16, s, .)
 18.8191 +{
 18.8192 +	uint* r_dst = &DY;
 18.8193 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8194 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.8195 +	uint res = ROR_17(src | (XFLAG_AS_1() << 16), shift);
 18.8196 +
 18.8197 +	FLAG_C = FLAG_X = res >> 8;
 18.8198 +	res = MASK_OUT_ABOVE_16(res);
 18.8199 +
 18.8200 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.8201 +
 18.8202 +	FLAG_N = NFLAG_16(res);
 18.8203 +	FLAG_Z = res;
 18.8204 +	FLAG_V = VFLAG_CLEAR;
 18.8205 +}
 18.8206 +
 18.8207 +
 18.8208 +M68KMAKE_OP(roxr, 32, s, .)
 18.8209 +{
 18.8210 +#if M68K_USE_64_BIT
 18.8211 +
 18.8212 +	uint*  r_dst = &DY;
 18.8213 +	uint   shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8214 +	uint64 src   = *r_dst;
 18.8215 +	uint64 res   = src | (((uint64)XFLAG_AS_1()) << 32);
 18.8216 +
 18.8217 +	res = ROR_33_64(res, shift);
 18.8218 +
 18.8219 +	FLAG_C = FLAG_X = res >> 24;
 18.8220 +	res = MASK_OUT_ABOVE_32(res);
 18.8221 +
 18.8222 +	*r_dst =  res;
 18.8223 +
 18.8224 +	FLAG_N = NFLAG_32(res);
 18.8225 +	FLAG_Z = res;
 18.8226 +	FLAG_V = VFLAG_CLEAR;
 18.8227 +
 18.8228 +#else
 18.8229 +
 18.8230 +	uint* r_dst = &DY;
 18.8231 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8232 +	uint src = *r_dst;
 18.8233 +	uint res = MASK_OUT_ABOVE_32((ROR_33(src, shift) & ~(1 << (32 - shift))) | (XFLAG_AS_1() << (32 - shift)));
 18.8234 +	uint new_x_flag = src & (1 << (shift - 1));
 18.8235 +
 18.8236 +	*r_dst = res;
 18.8237 +
 18.8238 +	FLAG_C = FLAG_X = (new_x_flag != 0)<<8;
 18.8239 +	FLAG_N = NFLAG_32(res);
 18.8240 +	FLAG_Z = res;
 18.8241 +	FLAG_V = VFLAG_CLEAR;
 18.8242 +
 18.8243 +#endif
 18.8244 +}
 18.8245 +
 18.8246 +
 18.8247 +M68KMAKE_OP(roxr, 8, r, .)
 18.8248 +{
 18.8249 +	uint* r_dst = &DY;
 18.8250 +	uint orig_shift = DX & 0x3f;
 18.8251 +
 18.8252 +	if(orig_shift != 0)
 18.8253 +	{
 18.8254 +		uint shift = orig_shift % 9;
 18.8255 +		uint src   = MASK_OUT_ABOVE_8(*r_dst);
 18.8256 +		uint res   = ROR_9(src | (XFLAG_AS_1() << 8), shift);
 18.8257 +
 18.8258 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8259 +
 18.8260 +		FLAG_C = FLAG_X = res;
 18.8261 +		res = MASK_OUT_ABOVE_8(res);
 18.8262 +
 18.8263 +		*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.8264 +		FLAG_N = NFLAG_8(res);
 18.8265 +		FLAG_Z = res;
 18.8266 +		FLAG_V = VFLAG_CLEAR;
 18.8267 +		return;
 18.8268 +	}
 18.8269 +
 18.8270 +	FLAG_C = FLAG_X;
 18.8271 +	FLAG_N = NFLAG_8(*r_dst);
 18.8272 +	FLAG_Z = MASK_OUT_ABOVE_8(*r_dst);
 18.8273 +	FLAG_V = VFLAG_CLEAR;
 18.8274 +}
 18.8275 +
 18.8276 +
 18.8277 +M68KMAKE_OP(roxr, 16, r, .)
 18.8278 +{
 18.8279 +	uint* r_dst = &DY;
 18.8280 +	uint orig_shift = DX & 0x3f;
 18.8281 +
 18.8282 +	if(orig_shift != 0)
 18.8283 +	{
 18.8284 +		uint shift = orig_shift % 17;
 18.8285 +		uint src   = MASK_OUT_ABOVE_16(*r_dst);
 18.8286 +		uint res   = ROR_17(src | (XFLAG_AS_1() << 16), shift);
 18.8287 +
 18.8288 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8289 +
 18.8290 +		FLAG_C = FLAG_X = res >> 8;
 18.8291 +		res = MASK_OUT_ABOVE_16(res);
 18.8292 +
 18.8293 +		*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.8294 +		FLAG_N = NFLAG_16(res);
 18.8295 +		FLAG_Z = res;
 18.8296 +		FLAG_V = VFLAG_CLEAR;
 18.8297 +		return;
 18.8298 +	}
 18.8299 +
 18.8300 +	FLAG_C = FLAG_X;
 18.8301 +	FLAG_N = NFLAG_16(*r_dst);
 18.8302 +	FLAG_Z = MASK_OUT_ABOVE_16(*r_dst);
 18.8303 +	FLAG_V = VFLAG_CLEAR;
 18.8304 +}
 18.8305 +
 18.8306 +
 18.8307 +M68KMAKE_OP(roxr, 32, r, .)
 18.8308 +{
 18.8309 +#if M68K_USE_64_BIT
 18.8310 +
 18.8311 +	uint*  r_dst = &DY;
 18.8312 +	uint   orig_shift = DX & 0x3f;
 18.8313 +
 18.8314 +	if(orig_shift != 0)
 18.8315 +	{
 18.8316 +		uint   shift = orig_shift % 33;
 18.8317 +		uint64 src   = *r_dst;
 18.8318 +		uint64 res   = src | (((uint64)XFLAG_AS_1()) << 32);
 18.8319 +
 18.8320 +		res = ROR_33_64(res, shift);
 18.8321 +
 18.8322 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8323 +
 18.8324 +		FLAG_C = FLAG_X = res >> 24;
 18.8325 +		res = MASK_OUT_ABOVE_32(res);
 18.8326 +
 18.8327 +		*r_dst = res;
 18.8328 +		FLAG_N = NFLAG_32(res);
 18.8329 +		FLAG_Z = res;
 18.8330 +		FLAG_V = VFLAG_CLEAR;
 18.8331 +		return;
 18.8332 +	}
 18.8333 +
 18.8334 +	FLAG_C = FLAG_X;
 18.8335 +	FLAG_N = NFLAG_32(*r_dst);
 18.8336 +	FLAG_Z = *r_dst;
 18.8337 +	FLAG_V = VFLAG_CLEAR;
 18.8338 +
 18.8339 +#else
 18.8340 +
 18.8341 +	uint* r_dst = &DY;
 18.8342 +	uint orig_shift = DX & 0x3f;
 18.8343 +	uint shift = orig_shift % 33;
 18.8344 +	uint src = *r_dst;
 18.8345 +	uint res = MASK_OUT_ABOVE_32((ROR_33(src, shift) & ~(1 << (32 - shift))) | (XFLAG_AS_1() << (32 - shift)));
 18.8346 +	uint new_x_flag = src & (1 << (shift - 1));
 18.8347 +
 18.8348 +	if(orig_shift != 0)
 18.8349 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8350 +
 18.8351 +	if(shift != 0)
 18.8352 +	{
 18.8353 +		*r_dst = res;
 18.8354 +		FLAG_X = (new_x_flag != 0)<<8;
 18.8355 +	}
 18.8356 +	else
 18.8357 +		res = src;
 18.8358 +	FLAG_C = FLAG_X;
 18.8359 +	FLAG_N = NFLAG_32(res);
 18.8360 +	FLAG_Z = res;
 18.8361 +	FLAG_V = VFLAG_CLEAR;
 18.8362 +
 18.8363 +#endif
 18.8364 +}
 18.8365 +
 18.8366 +
 18.8367 +M68KMAKE_OP(roxr, 16, ., .)
 18.8368 +{
 18.8369 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.8370 +	uint src = m68ki_read_16(ea);
 18.8371 +	uint res = ROR_17(src | (XFLAG_AS_1() << 16), 1);
 18.8372 +
 18.8373 +	FLAG_C = FLAG_X = res >> 8;
 18.8374 +	res = MASK_OUT_ABOVE_16(res);
 18.8375 +
 18.8376 +	m68ki_write_16(ea, res);
 18.8377 +
 18.8378 +	FLAG_N = NFLAG_16(res);
 18.8379 +	FLAG_Z = res;
 18.8380 +	FLAG_V = VFLAG_CLEAR;
 18.8381 +}
 18.8382 +
 18.8383 +
 18.8384 +M68KMAKE_OP(roxl, 8, s, .)
 18.8385 +{
 18.8386 +	uint* r_dst = &DY;
 18.8387 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8388 +	uint src = MASK_OUT_ABOVE_8(*r_dst);
 18.8389 +	uint res = ROL_9(src | (XFLAG_AS_1() << 8), shift);
 18.8390 +
 18.8391 +	FLAG_C = FLAG_X = res;
 18.8392 +	res = MASK_OUT_ABOVE_8(res);
 18.8393 +
 18.8394 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.8395 +
 18.8396 +	FLAG_N = NFLAG_8(res);
 18.8397 +	FLAG_Z = res;
 18.8398 +	FLAG_V = VFLAG_CLEAR;
 18.8399 +}
 18.8400 +
 18.8401 +
 18.8402 +M68KMAKE_OP(roxl, 16, s, .)
 18.8403 +{
 18.8404 +	uint* r_dst = &DY;
 18.8405 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8406 +	uint src = MASK_OUT_ABOVE_16(*r_dst);
 18.8407 +	uint res = ROL_17(src | (XFLAG_AS_1() << 16), shift);
 18.8408 +
 18.8409 +	FLAG_C = FLAG_X = res >> 8;
 18.8410 +	res = MASK_OUT_ABOVE_16(res);
 18.8411 +
 18.8412 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.8413 +
 18.8414 +	FLAG_N = NFLAG_16(res);
 18.8415 +	FLAG_Z = res;
 18.8416 +	FLAG_V = VFLAG_CLEAR;
 18.8417 +}
 18.8418 +
 18.8419 +
 18.8420 +M68KMAKE_OP(roxl, 32, s, .)
 18.8421 +{
 18.8422 +#if M68K_USE_64_BIT
 18.8423 +
 18.8424 +	uint*  r_dst = &DY;
 18.8425 +	uint   shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8426 +	uint64 src   = *r_dst;
 18.8427 +	uint64 res   = src | (((uint64)XFLAG_AS_1()) << 32);
 18.8428 +
 18.8429 +	res = ROL_33_64(res, shift);
 18.8430 +
 18.8431 +	FLAG_C = FLAG_X = res >> 24;
 18.8432 +	res = MASK_OUT_ABOVE_32(res);
 18.8433 +
 18.8434 +	*r_dst = res;
 18.8435 +
 18.8436 +	FLAG_N = NFLAG_32(res);
 18.8437 +	FLAG_Z = res;
 18.8438 +	FLAG_V = VFLAG_CLEAR;
 18.8439 +
 18.8440 +#else
 18.8441 +
 18.8442 +	uint* r_dst = &DY;
 18.8443 +	uint shift = (((REG_IR >> 9) - 1) & 7) + 1;
 18.8444 +	uint src = *r_dst;
 18.8445 +	uint res = MASK_OUT_ABOVE_32((ROL_33(src, shift) & ~(1 << (shift - 1))) | (XFLAG_AS_1() << (shift - 1)));
 18.8446 +	uint new_x_flag = src & (1 << (32 - shift));
 18.8447 +
 18.8448 +	*r_dst = res;
 18.8449 +
 18.8450 +	FLAG_C = FLAG_X = (new_x_flag != 0)<<8;
 18.8451 +	FLAG_N = NFLAG_32(res);
 18.8452 +	FLAG_Z = res;
 18.8453 +	FLAG_V = VFLAG_CLEAR;
 18.8454 +
 18.8455 +#endif
 18.8456 +}
 18.8457 +
 18.8458 +
 18.8459 +M68KMAKE_OP(roxl, 8, r, .)
 18.8460 +{
 18.8461 +	uint* r_dst = &DY;
 18.8462 +	uint orig_shift = DX & 0x3f;
 18.8463 +
 18.8464 +
 18.8465 +	if(orig_shift != 0)
 18.8466 +	{
 18.8467 +		uint shift = orig_shift % 9;
 18.8468 +		uint src   = MASK_OUT_ABOVE_8(*r_dst);
 18.8469 +		uint res   = ROL_9(src | (XFLAG_AS_1() << 8), shift);
 18.8470 +
 18.8471 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8472 +
 18.8473 +		FLAG_C = FLAG_X = res;
 18.8474 +		res = MASK_OUT_ABOVE_8(res);
 18.8475 +
 18.8476 +		*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.8477 +		FLAG_N = NFLAG_8(res);
 18.8478 +		FLAG_Z = res;
 18.8479 +		FLAG_V = VFLAG_CLEAR;
 18.8480 +		return;
 18.8481 +	}
 18.8482 +
 18.8483 +	FLAG_C = FLAG_X;
 18.8484 +	FLAG_N = NFLAG_8(*r_dst);
 18.8485 +	FLAG_Z = MASK_OUT_ABOVE_8(*r_dst);
 18.8486 +	FLAG_V = VFLAG_CLEAR;
 18.8487 +}
 18.8488 +
 18.8489 +
 18.8490 +M68KMAKE_OP(roxl, 16, r, .)
 18.8491 +{
 18.8492 +	uint* r_dst = &DY;
 18.8493 +	uint orig_shift = DX & 0x3f;
 18.8494 +
 18.8495 +	if(orig_shift != 0)
 18.8496 +	{
 18.8497 +		uint shift = orig_shift % 17;
 18.8498 +		uint src   = MASK_OUT_ABOVE_16(*r_dst);
 18.8499 +		uint res   = ROL_17(src | (XFLAG_AS_1() << 16), shift);
 18.8500 +
 18.8501 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8502 +
 18.8503 +		FLAG_C = FLAG_X = res >> 8;
 18.8504 +		res = MASK_OUT_ABOVE_16(res);
 18.8505 +
 18.8506 +		*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.8507 +		FLAG_N = NFLAG_16(res);
 18.8508 +		FLAG_Z = res;
 18.8509 +		FLAG_V = VFLAG_CLEAR;
 18.8510 +		return;
 18.8511 +	}
 18.8512 +
 18.8513 +	FLAG_C = FLAG_X;
 18.8514 +	FLAG_N = NFLAG_16(*r_dst);
 18.8515 +	FLAG_Z = MASK_OUT_ABOVE_16(*r_dst);
 18.8516 +	FLAG_V = VFLAG_CLEAR;
 18.8517 +}
 18.8518 +
 18.8519 +
 18.8520 +M68KMAKE_OP(roxl, 32, r, .)
 18.8521 +{
 18.8522 +#if M68K_USE_64_BIT
 18.8523 +
 18.8524 +	uint*  r_dst = &DY;
 18.8525 +	uint   orig_shift = DX & 0x3f;
 18.8526 +
 18.8527 +	if(orig_shift != 0)
 18.8528 +	{
 18.8529 +		uint   shift = orig_shift % 33;
 18.8530 +		uint64 src   = *r_dst;
 18.8531 +		uint64 res   = src | (((uint64)XFLAG_AS_1()) << 32);
 18.8532 +
 18.8533 +		res = ROL_33_64(res, shift);
 18.8534 +
 18.8535 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8536 +
 18.8537 +		FLAG_C = FLAG_X = res >> 24;
 18.8538 +		res = MASK_OUT_ABOVE_32(res);
 18.8539 +
 18.8540 +		*r_dst = res;
 18.8541 +		FLAG_N = NFLAG_32(res);
 18.8542 +		FLAG_Z = res;
 18.8543 +		FLAG_V = VFLAG_CLEAR;
 18.8544 +		return;
 18.8545 +	}
 18.8546 +
 18.8547 +	FLAG_C = FLAG_X;
 18.8548 +	FLAG_N = NFLAG_32(*r_dst);
 18.8549 +	FLAG_Z = *r_dst;
 18.8550 +	FLAG_V = VFLAG_CLEAR;
 18.8551 +
 18.8552 +#else
 18.8553 +
 18.8554 +	uint* r_dst = &DY;
 18.8555 +	uint orig_shift = DX & 0x3f;
 18.8556 +	uint shift = orig_shift % 33;
 18.8557 +	uint src = *r_dst;
 18.8558 +	uint res = MASK_OUT_ABOVE_32((ROL_33(src, shift) & ~(1 << (shift - 1))) | (XFLAG_AS_1() << (shift - 1)));
 18.8559 +	uint new_x_flag = src & (1 << (32 - shift));
 18.8560 +
 18.8561 +	if(orig_shift != 0)
 18.8562 +		USE_CYCLES(orig_shift<<CYC_SHIFT);
 18.8563 +
 18.8564 +	if(shift != 0)
 18.8565 +	{
 18.8566 +		*r_dst = res;
 18.8567 +		FLAG_X = (new_x_flag != 0)<<8;
 18.8568 +	}
 18.8569 +	else
 18.8570 +		res = src;
 18.8571 +	FLAG_C = FLAG_X;
 18.8572 +	FLAG_N = NFLAG_32(res);
 18.8573 +	FLAG_Z = res;
 18.8574 +	FLAG_V = VFLAG_CLEAR;
 18.8575 +
 18.8576 +#endif
 18.8577 +}
 18.8578 +
 18.8579 +
 18.8580 +M68KMAKE_OP(roxl, 16, ., .)
 18.8581 +{
 18.8582 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.8583 +	uint src = m68ki_read_16(ea);
 18.8584 +	uint res = ROL_17(src | (XFLAG_AS_1() << 16), 1);
 18.8585 +
 18.8586 +	FLAG_C = FLAG_X = res >> 8;
 18.8587 +	res = MASK_OUT_ABOVE_16(res);
 18.8588 +
 18.8589 +	m68ki_write_16(ea, res);
 18.8590 +
 18.8591 +	FLAG_N = NFLAG_16(res);
 18.8592 +	FLAG_Z = res;
 18.8593 +	FLAG_V = VFLAG_CLEAR;
 18.8594 +}
 18.8595 +
 18.8596 +
 18.8597 +M68KMAKE_OP(rtd, 32, ., .)
 18.8598 +{
 18.8599 +	if(CPU_TYPE_IS_010_PLUS(CPU_TYPE))
 18.8600 +	{
 18.8601 +		uint new_pc = m68ki_pull_32();
 18.8602 +
 18.8603 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.8604 +		REG_A[7] = MASK_OUT_ABOVE_32(REG_A[7] + MAKE_INT_16(OPER_I_16()));
 18.8605 +		m68ki_jump(new_pc);
 18.8606 +		return;
 18.8607 +	}
 18.8608 +	m68ki_exception_illegal();
 18.8609 +}
 18.8610 +
 18.8611 +
 18.8612 +M68KMAKE_OP(rte, 32, ., .)
 18.8613 +{
 18.8614 +	if(FLAG_S)
 18.8615 +	{
 18.8616 +		uint new_sr;
 18.8617 +		uint new_pc;
 18.8618 +		uint format_word;
 18.8619 +
 18.8620 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.8621 +
 18.8622 +		if(CPU_TYPE_IS_000(CPU_TYPE))
 18.8623 +		{
 18.8624 +			new_sr = m68ki_pull_16();
 18.8625 +			new_pc = m68ki_pull_32();
 18.8626 +			m68ki_jump(new_pc);
 18.8627 +			m68ki_set_sr(new_sr);
 18.8628 +			return;
 18.8629 +		}
 18.8630 +
 18.8631 +		if(CPU_TYPE_IS_010(CPU_TYPE))
 18.8632 +		{
 18.8633 +			format_word = m68ki_read_16(REG_A[7]+6) >> 12;
 18.8634 +			if(format_word == 0)
 18.8635 +			{
 18.8636 +				new_sr = m68ki_pull_16();
 18.8637 +				new_pc = m68ki_pull_32();
 18.8638 +				m68ki_fake_pull_16();	/* format word */
 18.8639 +				m68ki_jump(new_pc);
 18.8640 +				m68ki_set_sr(new_sr);
 18.8641 +				return;
 18.8642 +			}
 18.8643 +			/* Not handling bus fault (9) */
 18.8644 +			m68ki_exception_format_error();
 18.8645 +			return;
 18.8646 +		}
 18.8647 +
 18.8648 +		/* Otherwise it's 020 */
 18.8649 +rte_loop:
 18.8650 +		format_word = m68ki_read_16(REG_A[7]+6) >> 12;
 18.8651 +		switch(format_word)
 18.8652 +		{
 18.8653 +			case 0: /* Normal */
 18.8654 +				new_sr = m68ki_pull_16();
 18.8655 +				new_pc = m68ki_pull_32();
 18.8656 +				m68ki_fake_pull_16();	/* format word */
 18.8657 +				m68ki_jump(new_pc);
 18.8658 +				m68ki_set_sr(new_sr);
 18.8659 +				return;
 18.8660 +			case 1: /* Throwaway */
 18.8661 +				new_sr = m68ki_pull_16();
 18.8662 +				m68ki_fake_pull_32();	/* program counter */
 18.8663 +				m68ki_fake_pull_16();	/* format word */
 18.8664 +				m68ki_set_sr_noint(new_sr);
 18.8665 +				goto rte_loop;
 18.8666 +			case 2: /* Trap */
 18.8667 +				new_sr = m68ki_pull_16();
 18.8668 +				new_pc = m68ki_pull_32();
 18.8669 +				m68ki_fake_pull_16();	/* format word */
 18.8670 +				m68ki_fake_pull_32();	/* address */
 18.8671 +				m68ki_jump(new_pc);
 18.8672 +				m68ki_set_sr(new_sr);
 18.8673 +				return;
 18.8674 +		}
 18.8675 +		/* Not handling long or short bus fault */
 18.8676 +		m68ki_exception_format_error();
 18.8677 +		return;
 18.8678 +	}
 18.8679 +	m68ki_exception_privilege_violation();
 18.8680 +}
 18.8681 +
 18.8682 +
 18.8683 +M68KMAKE_OP(rtm, 32, ., .)
 18.8684 +{
 18.8685 +	if(CPU_TYPE_IS_020_VARIANT(CPU_TYPE))
 18.8686 +	{
 18.8687 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.8688 +		M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: called unimplemented instruction %04x (%s)\n",
 18.8689 +					 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PC - 2), REG_IR,
 18.8690 +					 m68k_disassemble_quick(ADDRESS_68K(REG_PC - 2))));
 18.8691 +		return;
 18.8692 +	}
 18.8693 +	m68ki_exception_illegal();
 18.8694 +}
 18.8695 +
 18.8696 +
 18.8697 +M68KMAKE_OP(rtr, 32, ., .)
 18.8698 +{
 18.8699 +	m68ki_trace_t0();				   /* auto-disable (see m68kcpu.h) */
 18.8700 +	m68ki_set_ccr(m68ki_pull_16());
 18.8701 +	m68ki_jump(m68ki_pull_32());
 18.8702 +}
 18.8703 +
 18.8704 +
 18.8705 +M68KMAKE_OP(rts, 32, ., .)
 18.8706 +{
 18.8707 +	m68ki_trace_t0();				   /* auto-disable (see m68kcpu.h) */
 18.8708 +	m68ki_jump(m68ki_pull_32());
 18.8709 +}
 18.8710 +
 18.8711 +
 18.8712 +M68KMAKE_OP(sbcd, 8, rr, .)
 18.8713 +{
 18.8714 +	uint* r_dst = &DX;
 18.8715 +	uint src = DY;
 18.8716 +	uint dst = *r_dst;
 18.8717 +	uint res = LOW_NIBBLE(dst) - LOW_NIBBLE(src) - XFLAG_AS_1();
 18.8718 +
 18.8719 +	if(res > 9)
 18.8720 +		res -= 6;
 18.8721 +	res += HIGH_NIBBLE(dst) - HIGH_NIBBLE(src);
 18.8722 +	FLAG_X = FLAG_C = (res > 0x99) << 8;
 18.8723 +	if(FLAG_C)
 18.8724 +		res += 0xa0;
 18.8725 +
 18.8726 +	res = MASK_OUT_ABOVE_8(res);
 18.8727 +
 18.8728 +	FLAG_N = NFLAG_8(res); /* officially undefined */
 18.8729 +	FLAG_Z |= res;
 18.8730 +
 18.8731 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.8732 +}
 18.8733 +
 18.8734 +
 18.8735 +M68KMAKE_OP(sbcd, 8, mm, ax7)
 18.8736 +{
 18.8737 +	uint src = OPER_AY_PD_8();
 18.8738 +	uint ea  = EA_A7_PD_8();
 18.8739 +	uint dst = m68ki_read_8(ea);
 18.8740 +	uint res = LOW_NIBBLE(dst) - LOW_NIBBLE(src) - XFLAG_AS_1();
 18.8741 +
 18.8742 +	if(res > 9)
 18.8743 +		res -= 6;
 18.8744 +	res += HIGH_NIBBLE(dst) - HIGH_NIBBLE(src);
 18.8745 +	FLAG_X = FLAG_C = (res > 0x99) << 8;
 18.8746 +	if(FLAG_C)
 18.8747 +		res += 0xa0;
 18.8748 +
 18.8749 +	res = MASK_OUT_ABOVE_8(res);
 18.8750 +
 18.8751 +	FLAG_N = NFLAG_8(res); /* officially undefined */
 18.8752 +	FLAG_Z |= res;
 18.8753 +
 18.8754 +	m68ki_write_8(ea, res);
 18.8755 +}
 18.8756 +
 18.8757 +
 18.8758 +M68KMAKE_OP(sbcd, 8, mm, ay7)
 18.8759 +{
 18.8760 +	uint src = OPER_A7_PD_8();
 18.8761 +	uint ea  = EA_AX_PD_8();
 18.8762 +	uint dst = m68ki_read_8(ea);
 18.8763 +	uint res = LOW_NIBBLE(dst) - LOW_NIBBLE(src) - XFLAG_AS_1();
 18.8764 +
 18.8765 +	if(res > 9)
 18.8766 +		res -= 6;
 18.8767 +	res += HIGH_NIBBLE(dst) - HIGH_NIBBLE(src);
 18.8768 +	FLAG_X = FLAG_C = (res > 0x99) << 8;
 18.8769 +	if(FLAG_C)
 18.8770 +		res += 0xa0;
 18.8771 +
 18.8772 +	res = MASK_OUT_ABOVE_8(res);
 18.8773 +
 18.8774 +	FLAG_N = NFLAG_8(res); /* officially undefined */
 18.8775 +	FLAG_Z |= res;
 18.8776 +
 18.8777 +	m68ki_write_8(ea, res);
 18.8778 +}
 18.8779 +
 18.8780 +
 18.8781 +M68KMAKE_OP(sbcd, 8, mm, axy7)
 18.8782 +{
 18.8783 +	uint src = OPER_A7_PD_8();
 18.8784 +	uint ea  = EA_A7_PD_8();
 18.8785 +	uint dst = m68ki_read_8(ea);
 18.8786 +	uint res = LOW_NIBBLE(dst) - LOW_NIBBLE(src) - XFLAG_AS_1();
 18.8787 +
 18.8788 +	if(res > 9)
 18.8789 +		res -= 6;
 18.8790 +	res += HIGH_NIBBLE(dst) - HIGH_NIBBLE(src);
 18.8791 +	FLAG_X = FLAG_C = (res > 0x99) << 8;
 18.8792 +	if(FLAG_C)
 18.8793 +		res += 0xa0;
 18.8794 +
 18.8795 +	res = MASK_OUT_ABOVE_8(res);
 18.8796 +
 18.8797 +	FLAG_N = NFLAG_8(res); /* officially undefined */
 18.8798 +	FLAG_Z |= res;
 18.8799 +
 18.8800 +	m68ki_write_8(ea, res);
 18.8801 +}
 18.8802 +
 18.8803 +
 18.8804 +M68KMAKE_OP(sbcd, 8, mm, .)
 18.8805 +{
 18.8806 +	uint src = OPER_AY_PD_8();
 18.8807 +	uint ea  = EA_AX_PD_8();
 18.8808 +	uint dst = m68ki_read_8(ea);
 18.8809 +	uint res = LOW_NIBBLE(dst) - LOW_NIBBLE(src) - XFLAG_AS_1();
 18.8810 +
 18.8811 +	if(res > 9)
 18.8812 +		res -= 6;
 18.8813 +	res += HIGH_NIBBLE(dst) - HIGH_NIBBLE(src);
 18.8814 +	FLAG_X = FLAG_C = (res > 0x99) << 8;
 18.8815 +	if(FLAG_C)
 18.8816 +		res += 0xa0;
 18.8817 +
 18.8818 +	res = MASK_OUT_ABOVE_8(res);
 18.8819 +
 18.8820 +	FLAG_N = NFLAG_8(res); /* officially undefined */
 18.8821 +	FLAG_Z |= res;
 18.8822 +
 18.8823 +	m68ki_write_8(ea, res);
 18.8824 +}
 18.8825 +
 18.8826 +
 18.8827 +M68KMAKE_OP(st, 8, ., d)
 18.8828 +{
 18.8829 +	DY |= 0xff;
 18.8830 +}
 18.8831 +
 18.8832 +
 18.8833 +M68KMAKE_OP(st, 8, ., .)
 18.8834 +{
 18.8835 +	m68ki_write_8(M68KMAKE_GET_EA_AY_8, 0xff);
 18.8836 +}
 18.8837 +
 18.8838 +
 18.8839 +M68KMAKE_OP(sf, 8, ., d)
 18.8840 +{
 18.8841 +	DY &= 0xffffff00;
 18.8842 +}
 18.8843 +
 18.8844 +
 18.8845 +M68KMAKE_OP(sf, 8, ., .)
 18.8846 +{
 18.8847 +	m68ki_write_8(M68KMAKE_GET_EA_AY_8, 0);
 18.8848 +}
 18.8849 +
 18.8850 +
 18.8851 +M68KMAKE_OP(scc, 8, ., d)
 18.8852 +{
 18.8853 +	if(M68KMAKE_CC)
 18.8854 +	{
 18.8855 +		DY |= 0xff;
 18.8856 +		return;
 18.8857 +	}
 18.8858 +	DY &= 0xffffff00;
 18.8859 +}
 18.8860 +
 18.8861 +
 18.8862 +M68KMAKE_OP(scc, 8, ., .)
 18.8863 +{
 18.8864 +	m68ki_write_8(M68KMAKE_GET_EA_AY_8, M68KMAKE_CC ? 0xff : 0);
 18.8865 +}
 18.8866 +
 18.8867 +
 18.8868 +M68KMAKE_OP(stop, 0, ., .)
 18.8869 +{
 18.8870 +	if(FLAG_S)
 18.8871 +	{
 18.8872 +		uint new_sr = OPER_I_16();
 18.8873 +		m68ki_trace_t0();			   /* auto-disable (see m68kcpu.h) */
 18.8874 +		CPU_STOPPED |= STOP_LEVEL_STOP;
 18.8875 +		m68ki_set_sr(new_sr);
 18.8876 +		m68ki_remaining_cycles = 0;
 18.8877 +		return;
 18.8878 +	}
 18.8879 +	m68ki_exception_privilege_violation();
 18.8880 +}
 18.8881 +
 18.8882 +
 18.8883 +M68KMAKE_OP(sub, 8, er, d)
 18.8884 +{
 18.8885 +	uint* r_dst = &DX;
 18.8886 +	uint src = MASK_OUT_ABOVE_8(DY);
 18.8887 +	uint dst = MASK_OUT_ABOVE_8(*r_dst);
 18.8888 +	uint res = dst - src;
 18.8889 +
 18.8890 +	FLAG_N = NFLAG_8(res);
 18.8891 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.8892 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.8893 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.8894 +
 18.8895 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | FLAG_Z;
 18.8896 +}
 18.8897 +
 18.8898 +
 18.8899 +M68KMAKE_OP(sub, 8, er, .)
 18.8900 +{
 18.8901 +	uint* r_dst = &DX;
 18.8902 +	uint src = M68KMAKE_GET_OPER_AY_8;
 18.8903 +	uint dst = MASK_OUT_ABOVE_8(*r_dst);
 18.8904 +	uint res = dst - src;
 18.8905 +
 18.8906 +	FLAG_N = NFLAG_8(res);
 18.8907 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.8908 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.8909 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.8910 +
 18.8911 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | FLAG_Z;
 18.8912 +}
 18.8913 +
 18.8914 +
 18.8915 +M68KMAKE_OP(sub, 16, er, d)
 18.8916 +{
 18.8917 +	uint* r_dst = &DX;
 18.8918 +	uint src = MASK_OUT_ABOVE_16(DY);
 18.8919 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.8920 +	uint res = dst - src;
 18.8921 +
 18.8922 +	FLAG_N = NFLAG_16(res);
 18.8923 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.8924 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.8925 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.8926 +
 18.8927 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.8928 +}
 18.8929 +
 18.8930 +
 18.8931 +M68KMAKE_OP(sub, 16, er, a)
 18.8932 +{
 18.8933 +	uint* r_dst = &DX;
 18.8934 +	uint src = MASK_OUT_ABOVE_16(AY);
 18.8935 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.8936 +	uint res = dst - src;
 18.8937 +
 18.8938 +	FLAG_N = NFLAG_16(res);
 18.8939 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.8940 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.8941 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.8942 +
 18.8943 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.8944 +}
 18.8945 +
 18.8946 +
 18.8947 +M68KMAKE_OP(sub, 16, er, .)
 18.8948 +{
 18.8949 +	uint* r_dst = &DX;
 18.8950 +	uint src = M68KMAKE_GET_OPER_AY_16;
 18.8951 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.8952 +	uint res = dst - src;
 18.8953 +
 18.8954 +	FLAG_N = NFLAG_16(res);
 18.8955 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.8956 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.8957 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.8958 +
 18.8959 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.8960 +}
 18.8961 +
 18.8962 +
 18.8963 +M68KMAKE_OP(sub, 32, er, d)
 18.8964 +{
 18.8965 +	uint* r_dst = &DX;
 18.8966 +	uint src = DY;
 18.8967 +	uint dst = *r_dst;
 18.8968 +	uint res = dst - src;
 18.8969 +
 18.8970 +	FLAG_N = NFLAG_32(res);
 18.8971 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.8972 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.8973 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.8974 +
 18.8975 +	*r_dst = FLAG_Z;
 18.8976 +}
 18.8977 +
 18.8978 +
 18.8979 +M68KMAKE_OP(sub, 32, er, a)
 18.8980 +{
 18.8981 +	uint* r_dst = &DX;
 18.8982 +	uint src = AY;
 18.8983 +	uint dst = *r_dst;
 18.8984 +	uint res = dst - src;
 18.8985 +
 18.8986 +	FLAG_N = NFLAG_32(res);
 18.8987 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.8988 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.8989 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.8990 +
 18.8991 +	*r_dst = FLAG_Z;
 18.8992 +}
 18.8993 +
 18.8994 +
 18.8995 +M68KMAKE_OP(sub, 32, er, .)
 18.8996 +{
 18.8997 +	uint* r_dst = &DX;
 18.8998 +	uint src = M68KMAKE_GET_OPER_AY_32;
 18.8999 +	uint dst = *r_dst;
 18.9000 +	uint res = dst - src;
 18.9001 +
 18.9002 +	FLAG_N = NFLAG_32(res);
 18.9003 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.9004 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.9005 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.9006 +
 18.9007 +	*r_dst = FLAG_Z;
 18.9008 +}
 18.9009 +
 18.9010 +
 18.9011 +M68KMAKE_OP(sub, 8, re, .)
 18.9012 +{
 18.9013 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.9014 +	uint src = MASK_OUT_ABOVE_8(DX);
 18.9015 +	uint dst = m68ki_read_8(ea);
 18.9016 +	uint res = dst - src;
 18.9017 +
 18.9018 +	FLAG_N = NFLAG_8(res);
 18.9019 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.9020 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.9021 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.9022 +
 18.9023 +	m68ki_write_8(ea, FLAG_Z);
 18.9024 +}
 18.9025 +
 18.9026 +
 18.9027 +M68KMAKE_OP(sub, 16, re, .)
 18.9028 +{
 18.9029 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.9030 +	uint src = MASK_OUT_ABOVE_16(DX);
 18.9031 +	uint dst = m68ki_read_16(ea);
 18.9032 +	uint res = dst - src;
 18.9033 +
 18.9034 +	FLAG_N = NFLAG_16(res);
 18.9035 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.9036 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.9037 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.9038 +
 18.9039 +	m68ki_write_16(ea, FLAG_Z);
 18.9040 +}
 18.9041 +
 18.9042 +
 18.9043 +M68KMAKE_OP(sub, 32, re, .)
 18.9044 +{
 18.9045 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.9046 +	uint src = DX;
 18.9047 +	uint dst = m68ki_read_32(ea);
 18.9048 +	uint res = dst - src;
 18.9049 +
 18.9050 +	FLAG_N = NFLAG_32(res);
 18.9051 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.9052 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.9053 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.9054 +
 18.9055 +	m68ki_write_32(ea, FLAG_Z);
 18.9056 +}
 18.9057 +
 18.9058 +
 18.9059 +M68KMAKE_OP(suba, 16, ., d)
 18.9060 +{
 18.9061 +	uint* r_dst = &AX;
 18.9062 +
 18.9063 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst - MAKE_INT_16(DY));
 18.9064 +}
 18.9065 +
 18.9066 +
 18.9067 +M68KMAKE_OP(suba, 16, ., a)
 18.9068 +{
 18.9069 +	uint* r_dst = &AX;
 18.9070 +
 18.9071 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst - MAKE_INT_16(AY));
 18.9072 +}
 18.9073 +
 18.9074 +
 18.9075 +M68KMAKE_OP(suba, 16, ., .)
 18.9076 +{
 18.9077 +	uint* r_dst = &AX;
 18.9078 +
 18.9079 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst - MAKE_INT_16(M68KMAKE_GET_OPER_AY_16));
 18.9080 +}
 18.9081 +
 18.9082 +
 18.9083 +M68KMAKE_OP(suba, 32, ., d)
 18.9084 +{
 18.9085 +	uint* r_dst = &AX;
 18.9086 +
 18.9087 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst - DY);
 18.9088 +}
 18.9089 +
 18.9090 +
 18.9091 +M68KMAKE_OP(suba, 32, ., a)
 18.9092 +{
 18.9093 +	uint* r_dst = &AX;
 18.9094 +
 18.9095 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst - AY);
 18.9096 +}
 18.9097 +
 18.9098 +
 18.9099 +M68KMAKE_OP(suba, 32, ., .)
 18.9100 +{
 18.9101 +	uint* r_dst = &AX;
 18.9102 +
 18.9103 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst - M68KMAKE_GET_OPER_AY_32);
 18.9104 +}
 18.9105 +
 18.9106 +
 18.9107 +M68KMAKE_OP(subi, 8, ., d)
 18.9108 +{
 18.9109 +	uint* r_dst = &DY;
 18.9110 +	uint src = OPER_I_8();
 18.9111 +	uint dst = MASK_OUT_ABOVE_8(*r_dst);
 18.9112 +	uint res = dst - src;
 18.9113 +
 18.9114 +	FLAG_N = NFLAG_8(res);
 18.9115 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.9116 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.9117 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.9118 +
 18.9119 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | FLAG_Z;
 18.9120 +}
 18.9121 +
 18.9122 +
 18.9123 +M68KMAKE_OP(subi, 8, ., .)
 18.9124 +{
 18.9125 +	uint src = OPER_I_8();
 18.9126 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.9127 +	uint dst = m68ki_read_8(ea);
 18.9128 +	uint res = dst - src;
 18.9129 +
 18.9130 +	FLAG_N = NFLAG_8(res);
 18.9131 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.9132 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.9133 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.9134 +
 18.9135 +	m68ki_write_8(ea, FLAG_Z);
 18.9136 +}
 18.9137 +
 18.9138 +
 18.9139 +M68KMAKE_OP(subi, 16, ., d)
 18.9140 +{
 18.9141 +	uint* r_dst = &DY;
 18.9142 +	uint src = OPER_I_16();
 18.9143 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.9144 +	uint res = dst - src;
 18.9145 +
 18.9146 +	FLAG_N = NFLAG_16(res);
 18.9147 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.9148 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.9149 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.9150 +
 18.9151 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.9152 +}
 18.9153 +
 18.9154 +
 18.9155 +M68KMAKE_OP(subi, 16, ., .)
 18.9156 +{
 18.9157 +	uint src = OPER_I_16();
 18.9158 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.9159 +	uint dst = m68ki_read_16(ea);
 18.9160 +	uint res = dst - src;
 18.9161 +
 18.9162 +	FLAG_N = NFLAG_16(res);
 18.9163 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.9164 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.9165 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.9166 +
 18.9167 +	m68ki_write_16(ea, FLAG_Z);
 18.9168 +}
 18.9169 +
 18.9170 +
 18.9171 +M68KMAKE_OP(subi, 32, ., d)
 18.9172 +{
 18.9173 +	uint* r_dst = &DY;
 18.9174 +	uint src = OPER_I_32();
 18.9175 +	uint dst = *r_dst;
 18.9176 +	uint res = dst - src;
 18.9177 +
 18.9178 +	FLAG_N = NFLAG_32(res);
 18.9179 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.9180 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.9181 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.9182 +
 18.9183 +	*r_dst = FLAG_Z;
 18.9184 +}
 18.9185 +
 18.9186 +
 18.9187 +M68KMAKE_OP(subi, 32, ., .)
 18.9188 +{
 18.9189 +	uint src = OPER_I_32();
 18.9190 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.9191 +	uint dst = m68ki_read_32(ea);
 18.9192 +	uint res = dst - src;
 18.9193 +
 18.9194 +	FLAG_N = NFLAG_32(res);
 18.9195 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.9196 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.9197 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.9198 +
 18.9199 +	m68ki_write_32(ea, FLAG_Z);
 18.9200 +}
 18.9201 +
 18.9202 +
 18.9203 +M68KMAKE_OP(subq, 8, ., d)
 18.9204 +{
 18.9205 +	uint* r_dst = &DY;
 18.9206 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.9207 +	uint dst = MASK_OUT_ABOVE_8(*r_dst);
 18.9208 +	uint res = dst - src;
 18.9209 +
 18.9210 +	FLAG_N = NFLAG_8(res);
 18.9211 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.9212 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.9213 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.9214 +
 18.9215 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | FLAG_Z;
 18.9216 +}
 18.9217 +
 18.9218 +
 18.9219 +M68KMAKE_OP(subq, 8, ., .)
 18.9220 +{
 18.9221 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.9222 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.9223 +	uint dst = m68ki_read_8(ea);
 18.9224 +	uint res = dst - src;
 18.9225 +
 18.9226 +	FLAG_N = NFLAG_8(res);
 18.9227 +	FLAG_Z = MASK_OUT_ABOVE_8(res);
 18.9228 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.9229 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.9230 +
 18.9231 +	m68ki_write_8(ea, FLAG_Z);
 18.9232 +}
 18.9233 +
 18.9234 +
 18.9235 +M68KMAKE_OP(subq, 16, ., d)
 18.9236 +{
 18.9237 +	uint* r_dst = &DY;
 18.9238 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.9239 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.9240 +	uint res = dst - src;
 18.9241 +
 18.9242 +	FLAG_N = NFLAG_16(res);
 18.9243 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.9244 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.9245 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.9246 +
 18.9247 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | FLAG_Z;
 18.9248 +}
 18.9249 +
 18.9250 +
 18.9251 +M68KMAKE_OP(subq, 16, ., a)
 18.9252 +{
 18.9253 +	uint* r_dst = &AY;
 18.9254 +
 18.9255 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst - ((((REG_IR >> 9) - 1) & 7) + 1));
 18.9256 +}
 18.9257 +
 18.9258 +
 18.9259 +M68KMAKE_OP(subq, 16, ., .)
 18.9260 +{
 18.9261 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.9262 +	uint ea = M68KMAKE_GET_EA_AY_16;
 18.9263 +	uint dst = m68ki_read_16(ea);
 18.9264 +	uint res = dst - src;
 18.9265 +
 18.9266 +	FLAG_N = NFLAG_16(res);
 18.9267 +	FLAG_Z = MASK_OUT_ABOVE_16(res);
 18.9268 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.9269 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.9270 +
 18.9271 +	m68ki_write_16(ea, FLAG_Z);
 18.9272 +}
 18.9273 +
 18.9274 +
 18.9275 +M68KMAKE_OP(subq, 32, ., d)
 18.9276 +{
 18.9277 +	uint* r_dst = &DY;
 18.9278 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.9279 +	uint dst = *r_dst;
 18.9280 +	uint res = dst - src;
 18.9281 +
 18.9282 +	FLAG_N = NFLAG_32(res);
 18.9283 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.9284 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.9285 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.9286 +
 18.9287 +	*r_dst = FLAG_Z;
 18.9288 +}
 18.9289 +
 18.9290 +
 18.9291 +M68KMAKE_OP(subq, 32, ., a)
 18.9292 +{
 18.9293 +	uint* r_dst = &AY;
 18.9294 +
 18.9295 +	*r_dst = MASK_OUT_ABOVE_32(*r_dst - ((((REG_IR >> 9) - 1) & 7) + 1));
 18.9296 +}
 18.9297 +
 18.9298 +
 18.9299 +M68KMAKE_OP(subq, 32, ., .)
 18.9300 +{
 18.9301 +	uint src = (((REG_IR >> 9) - 1) & 7) + 1;
 18.9302 +	uint ea = M68KMAKE_GET_EA_AY_32;
 18.9303 +	uint dst = m68ki_read_32(ea);
 18.9304 +	uint res = dst - src;
 18.9305 +
 18.9306 +	FLAG_N = NFLAG_32(res);
 18.9307 +	FLAG_Z = MASK_OUT_ABOVE_32(res);
 18.9308 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.9309 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.9310 +
 18.9311 +	m68ki_write_32(ea, FLAG_Z);
 18.9312 +}
 18.9313 +
 18.9314 +
 18.9315 +M68KMAKE_OP(subx, 8, rr, .)
 18.9316 +{
 18.9317 +	uint* r_dst = &DX;
 18.9318 +	uint src = MASK_OUT_ABOVE_8(DY);
 18.9319 +	uint dst = MASK_OUT_ABOVE_8(*r_dst);
 18.9320 +	uint res = dst - src - XFLAG_AS_1();
 18.9321 +
 18.9322 +	FLAG_N = NFLAG_8(res);
 18.9323 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.9324 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.9325 +
 18.9326 +	res = MASK_OUT_ABOVE_8(res);
 18.9327 +	FLAG_Z |= res;
 18.9328 +
 18.9329 +	*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
 18.9330 +}
 18.9331 +
 18.9332 +
 18.9333 +M68KMAKE_OP(subx, 16, rr, .)
 18.9334 +{
 18.9335 +	uint* r_dst = &DX;
 18.9336 +	uint src = MASK_OUT_ABOVE_16(DY);
 18.9337 +	uint dst = MASK_OUT_ABOVE_16(*r_dst);
 18.9338 +	uint res = dst - src - XFLAG_AS_1();
 18.9339 +
 18.9340 +	FLAG_N = NFLAG_16(res);
 18.9341 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.9342 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.9343 +
 18.9344 +	res = MASK_OUT_ABOVE_16(res);
 18.9345 +	FLAG_Z |= res;
 18.9346 +
 18.9347 +	*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
 18.9348 +}
 18.9349 +
 18.9350 +
 18.9351 +M68KMAKE_OP(subx, 32, rr, .)
 18.9352 +{
 18.9353 +	uint* r_dst = &DX;
 18.9354 +	uint src = DY;
 18.9355 +	uint dst = *r_dst;
 18.9356 +	uint res = dst - src - XFLAG_AS_1();
 18.9357 +
 18.9358 +	FLAG_N = NFLAG_32(res);
 18.9359 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.9360 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.9361 +
 18.9362 +	res = MASK_OUT_ABOVE_32(res);
 18.9363 +	FLAG_Z |= res;
 18.9364 +
 18.9365 +	*r_dst = res;
 18.9366 +}
 18.9367 +
 18.9368 +
 18.9369 +M68KMAKE_OP(subx, 8, mm, ax7)
 18.9370 +{
 18.9371 +	uint src = OPER_AY_PD_8();
 18.9372 +	uint ea  = EA_A7_PD_8();
 18.9373 +	uint dst = m68ki_read_8(ea);
 18.9374 +	uint res = dst - src - XFLAG_AS_1();
 18.9375 +
 18.9376 +	FLAG_N = NFLAG_8(res);
 18.9377 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.9378 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.9379 +
 18.9380 +	res = MASK_OUT_ABOVE_8(res);
 18.9381 +	FLAG_Z |= res;
 18.9382 +
 18.9383 +	m68ki_write_8(ea, res);
 18.9384 +}
 18.9385 +
 18.9386 +
 18.9387 +M68KMAKE_OP(subx, 8, mm, ay7)
 18.9388 +{
 18.9389 +	uint src = OPER_A7_PD_8();
 18.9390 +	uint ea  = EA_AX_PD_8();
 18.9391 +	uint dst = m68ki_read_8(ea);
 18.9392 +	uint res = dst - src - XFLAG_AS_1();
 18.9393 +
 18.9394 +	FLAG_N = NFLAG_8(res);
 18.9395 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.9396 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.9397 +
 18.9398 +	res = MASK_OUT_ABOVE_8(res);
 18.9399 +	FLAG_Z |= res;
 18.9400 +
 18.9401 +	m68ki_write_8(ea, res);
 18.9402 +}
 18.9403 +
 18.9404 +
 18.9405 +M68KMAKE_OP(subx, 8, mm, axy7)
 18.9406 +{
 18.9407 +	uint src = OPER_A7_PD_8();
 18.9408 +	uint ea  = EA_A7_PD_8();
 18.9409 +	uint dst = m68ki_read_8(ea);
 18.9410 +	uint res = dst - src - XFLAG_AS_1();
 18.9411 +
 18.9412 +	FLAG_N = NFLAG_8(res);
 18.9413 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.9414 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.9415 +
 18.9416 +	res = MASK_OUT_ABOVE_8(res);
 18.9417 +	FLAG_Z |= res;
 18.9418 +
 18.9419 +	m68ki_write_8(ea, res);
 18.9420 +}
 18.9421 +
 18.9422 +
 18.9423 +M68KMAKE_OP(subx, 8, mm, .)
 18.9424 +{
 18.9425 +	uint src = OPER_AY_PD_8();
 18.9426 +	uint ea  = EA_AX_PD_8();
 18.9427 +	uint dst = m68ki_read_8(ea);
 18.9428 +	uint res = dst - src - XFLAG_AS_1();
 18.9429 +
 18.9430 +	FLAG_N = NFLAG_8(res);
 18.9431 +	FLAG_X = FLAG_C = CFLAG_8(res);
 18.9432 +	FLAG_V = VFLAG_SUB_8(src, dst, res);
 18.9433 +
 18.9434 +	res = MASK_OUT_ABOVE_8(res);
 18.9435 +	FLAG_Z |= res;
 18.9436 +
 18.9437 +	m68ki_write_8(ea, res);
 18.9438 +}
 18.9439 +
 18.9440 +
 18.9441 +M68KMAKE_OP(subx, 16, mm, .)
 18.9442 +{
 18.9443 +	uint src = OPER_AY_PD_16();
 18.9444 +	uint ea  = EA_AX_PD_16();
 18.9445 +	uint dst = m68ki_read_16(ea);
 18.9446 +	uint res = dst - src - XFLAG_AS_1();
 18.9447 +
 18.9448 +	FLAG_N = NFLAG_16(res);
 18.9449 +	FLAG_X = FLAG_C = CFLAG_16(res);
 18.9450 +	FLAG_V = VFLAG_SUB_16(src, dst, res);
 18.9451 +
 18.9452 +	res = MASK_OUT_ABOVE_16(res);
 18.9453 +	FLAG_Z |= res;
 18.9454 +
 18.9455 +	m68ki_write_16(ea, res);
 18.9456 +}
 18.9457 +
 18.9458 +
 18.9459 +M68KMAKE_OP(subx, 32, mm, .)
 18.9460 +{
 18.9461 +	uint src = OPER_AY_PD_32();
 18.9462 +	uint ea  = EA_AX_PD_32();
 18.9463 +	uint dst = m68ki_read_32(ea);
 18.9464 +	uint res = dst - src - XFLAG_AS_1();
 18.9465 +
 18.9466 +	FLAG_N = NFLAG_32(res);
 18.9467 +	FLAG_X = FLAG_C = CFLAG_SUB_32(src, dst, res);
 18.9468 +	FLAG_V = VFLAG_SUB_32(src, dst, res);
 18.9469 +
 18.9470 +	res = MASK_OUT_ABOVE_32(res);
 18.9471 +	FLAG_Z |= res;
 18.9472 +
 18.9473 +	m68ki_write_32(ea, res);
 18.9474 +}
 18.9475 +
 18.9476 +
 18.9477 +M68KMAKE_OP(swap, 32, ., .)
 18.9478 +{
 18.9479 +	uint* r_dst = &DY;
 18.9480 +
 18.9481 +	FLAG_Z = MASK_OUT_ABOVE_32(*r_dst<<16);
 18.9482 +	*r_dst = (*r_dst>>16) | FLAG_Z;
 18.9483 +
 18.9484 +	FLAG_Z = *r_dst;
 18.9485 +	FLAG_N = NFLAG_32(*r_dst);
 18.9486 +	FLAG_C = CFLAG_CLEAR;
 18.9487 +	FLAG_V = VFLAG_CLEAR;
 18.9488 +}
 18.9489 +
 18.9490 +
 18.9491 +M68KMAKE_OP(tas, 8, ., d)
 18.9492 +{
 18.9493 +	uint* r_dst = &DY;
 18.9494 +
 18.9495 +	FLAG_Z = MASK_OUT_ABOVE_8(*r_dst);
 18.9496 +	FLAG_N = NFLAG_8(*r_dst);
 18.9497 +	FLAG_V = VFLAG_CLEAR;
 18.9498 +	FLAG_C = CFLAG_CLEAR;
 18.9499 +	*r_dst |= 0x80;
 18.9500 +}
 18.9501 +
 18.9502 +
 18.9503 +M68KMAKE_OP(tas, 8, ., .)
 18.9504 +{
 18.9505 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.9506 +	uint dst = m68ki_read_8(ea);
 18.9507 +
 18.9508 +	FLAG_Z = dst;
 18.9509 +	FLAG_N = NFLAG_8(dst);
 18.9510 +	FLAG_V = VFLAG_CLEAR;
 18.9511 +	FLAG_C = CFLAG_CLEAR;
 18.9512 +	m68ki_write_8(ea, dst | 0x80);
 18.9513 +}
 18.9514 +
 18.9515 +
 18.9516 +M68KMAKE_OP(trap, 0, ., .)
 18.9517 +{
 18.9518 +	/* Trap#n stacks exception frame type 0 */
 18.9519 +	m68ki_exception_trapN(EXCEPTION_TRAP_BASE + (REG_IR & 0xf));	/* HJB 990403 */
 18.9520 +}
 18.9521 +
 18.9522 +
 18.9523 +M68KMAKE_OP(trapt, 0, ., .)
 18.9524 +{
 18.9525 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9526 +	{
 18.9527 +		m68ki_exception_trap(EXCEPTION_TRAPV);	/* HJB 990403 */
 18.9528 +		return;
 18.9529 +	}
 18.9530 +	m68ki_exception_illegal();
 18.9531 +}
 18.9532 +
 18.9533 +
 18.9534 +M68KMAKE_OP(trapt, 16, ., .)
 18.9535 +{
 18.9536 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9537 +	{
 18.9538 +		m68ki_exception_trap(EXCEPTION_TRAPV);	/* HJB 990403 */
 18.9539 +		return;
 18.9540 +	}
 18.9541 +	m68ki_exception_illegal();
 18.9542 +}
 18.9543 +
 18.9544 +
 18.9545 +M68KMAKE_OP(trapt, 32, ., .)
 18.9546 +{
 18.9547 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9548 +	{
 18.9549 +		m68ki_exception_trap(EXCEPTION_TRAPV);	/* HJB 990403 */
 18.9550 +		return;
 18.9551 +	}
 18.9552 +	m68ki_exception_illegal();
 18.9553 +}
 18.9554 +
 18.9555 +
 18.9556 +M68KMAKE_OP(trapf, 0, ., .)
 18.9557 +{
 18.9558 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9559 +	{
 18.9560 +		return;
 18.9561 +	}
 18.9562 +	m68ki_exception_illegal();
 18.9563 +}
 18.9564 +
 18.9565 +
 18.9566 +M68KMAKE_OP(trapf, 16, ., .)
 18.9567 +{
 18.9568 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9569 +	{
 18.9570 +		REG_PC += 2;
 18.9571 +		return;
 18.9572 +	}
 18.9573 +	m68ki_exception_illegal();
 18.9574 +}
 18.9575 +
 18.9576 +
 18.9577 +M68KMAKE_OP(trapf, 32, ., .)
 18.9578 +{
 18.9579 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9580 +	{
 18.9581 +		REG_PC += 4;
 18.9582 +		return;
 18.9583 +	}
 18.9584 +	m68ki_exception_illegal();
 18.9585 +}
 18.9586 +
 18.9587 +
 18.9588 +M68KMAKE_OP(trapcc, 0, ., .)
 18.9589 +{
 18.9590 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9591 +	{
 18.9592 +		if(M68KMAKE_CC)
 18.9593 +			m68ki_exception_trap(EXCEPTION_TRAPV);	/* HJB 990403 */
 18.9594 +		return;
 18.9595 +	}
 18.9596 +	m68ki_exception_illegal();
 18.9597 +}
 18.9598 +
 18.9599 +
 18.9600 +M68KMAKE_OP(trapcc, 16, ., .)
 18.9601 +{
 18.9602 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9603 +	{
 18.9604 +		if(M68KMAKE_CC)
 18.9605 +		{
 18.9606 +			m68ki_exception_trap(EXCEPTION_TRAPV);	/* HJB 990403 */
 18.9607 +			return;
 18.9608 +		}
 18.9609 +		REG_PC += 2;
 18.9610 +		return;
 18.9611 +	}
 18.9612 +	m68ki_exception_illegal();
 18.9613 +}
 18.9614 +
 18.9615 +
 18.9616 +M68KMAKE_OP(trapcc, 32, ., .)
 18.9617 +{
 18.9618 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9619 +	{
 18.9620 +		if(M68KMAKE_CC)
 18.9621 +		{
 18.9622 +			m68ki_exception_trap(EXCEPTION_TRAPV);	/* HJB 990403 */
 18.9623 +			return;
 18.9624 +		}
 18.9625 +		REG_PC += 4;
 18.9626 +		return;
 18.9627 +	}
 18.9628 +	m68ki_exception_illegal();
 18.9629 +}
 18.9630 +
 18.9631 +
 18.9632 +M68KMAKE_OP(trapv, 0, ., .)
 18.9633 +{
 18.9634 +	if(COND_VC())
 18.9635 +	{
 18.9636 +		return;
 18.9637 +	}
 18.9638 +	m68ki_exception_trap(EXCEPTION_TRAPV);  /* HJB 990403 */
 18.9639 +}
 18.9640 +
 18.9641 +
 18.9642 +M68KMAKE_OP(tst, 8, ., d)
 18.9643 +{
 18.9644 +	uint res = MASK_OUT_ABOVE_8(DY);
 18.9645 +
 18.9646 +	FLAG_N = NFLAG_8(res);
 18.9647 +	FLAG_Z = res;
 18.9648 +	FLAG_V = VFLAG_CLEAR;
 18.9649 +	FLAG_C = CFLAG_CLEAR;
 18.9650 +}
 18.9651 +
 18.9652 +
 18.9653 +M68KMAKE_OP(tst, 8, ., .)
 18.9654 +{
 18.9655 +	uint ea = M68KMAKE_GET_EA_AY_8;
 18.9656 +	uint res = m68ki_read_8(ea);
 18.9657 +
 18.9658 +	FLAG_N = NFLAG_8(res);
 18.9659 +	FLAG_Z = res;
 18.9660 +	FLAG_V = VFLAG_CLEAR;
 18.9661 +	FLAG_C = CFLAG_CLEAR;
 18.9662 +}
 18.9663 +
 18.9664 +
 18.9665 +M68KMAKE_OP(tst, 8, ., pcdi)
 18.9666 +{
 18.9667 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9668 +	{
 18.9669 +		uint res = OPER_PCDI_8();
 18.9670 +
 18.9671 +		FLAG_N = NFLAG_8(res);
 18.9672 +		FLAG_Z = res;
 18.9673 +		FLAG_V = VFLAG_CLEAR;
 18.9674 +		FLAG_C = CFLAG_CLEAR;
 18.9675 +		return;
 18.9676 +	}
 18.9677 +	m68ki_exception_illegal();
 18.9678 +}
 18.9679 +
 18.9680 +
 18.9681 +M68KMAKE_OP(tst, 8, ., pcix)
 18.9682 +{
 18.9683 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9684 +	{
 18.9685 +		uint res = OPER_PCIX_8();
 18.9686 +
 18.9687 +		FLAG_N = NFLAG_8(res);
 18.9688 +		FLAG_Z = res;
 18.9689 +		FLAG_V = VFLAG_CLEAR;
 18.9690 +		FLAG_C = CFLAG_CLEAR;
 18.9691 +		return;
 18.9692 +	}
 18.9693 +	m68ki_exception_illegal();
 18.9694 +}
 18.9695 +
 18.9696 +
 18.9697 +M68KMAKE_OP(tst, 8, ., i)
 18.9698 +{
 18.9699 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9700 +	{
 18.9701 +		uint res = OPER_I_8();
 18.9702 +
 18.9703 +		FLAG_N = NFLAG_8(res);
 18.9704 +		FLAG_Z = res;
 18.9705 +		FLAG_V = VFLAG_CLEAR;
 18.9706 +		FLAG_C = CFLAG_CLEAR;
 18.9707 +		return;
 18.9708 +	}
 18.9709 +	m68ki_exception_illegal();
 18.9710 +}
 18.9711 +
 18.9712 +
 18.9713 +M68KMAKE_OP(tst, 16, ., d)
 18.9714 +{
 18.9715 +	uint res = MASK_OUT_ABOVE_16(DY);
 18.9716 +
 18.9717 +	FLAG_N = NFLAG_16(res);
 18.9718 +	FLAG_Z = res;
 18.9719 +	FLAG_V = VFLAG_CLEAR;
 18.9720 +	FLAG_C = CFLAG_CLEAR;
 18.9721 +}
 18.9722 +
 18.9723 +
 18.9724 +M68KMAKE_OP(tst, 16, ., a)
 18.9725 +{
 18.9726 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9727 +	{
 18.9728 +		uint res = MAKE_INT_16(AY);
 18.9729 +
 18.9730 +		FLAG_N = NFLAG_16(res);
 18.9731 +		FLAG_Z = res;
 18.9732 +		FLAG_V = VFLAG_CLEAR;
 18.9733 +		FLAG_C = CFLAG_CLEAR;
 18.9734 +		return;
 18.9735 +	}
 18.9736 +	m68ki_exception_illegal();
 18.9737 +}
 18.9738 +
 18.9739 +
 18.9740 +M68KMAKE_OP(tst, 16, ., .)
 18.9741 +{
 18.9742 +	uint res = M68KMAKE_GET_OPER_AY_16;
 18.9743 +
 18.9744 +	FLAG_N = NFLAG_16(res);
 18.9745 +	FLAG_Z = res;
 18.9746 +	FLAG_V = VFLAG_CLEAR;
 18.9747 +	FLAG_C = CFLAG_CLEAR;
 18.9748 +}
 18.9749 +
 18.9750 +
 18.9751 +M68KMAKE_OP(tst, 16, ., pcdi)
 18.9752 +{
 18.9753 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9754 +	{
 18.9755 +		uint res = OPER_PCDI_16();
 18.9756 +
 18.9757 +		FLAG_N = NFLAG_16(res);
 18.9758 +		FLAG_Z = res;
 18.9759 +		FLAG_V = VFLAG_CLEAR;
 18.9760 +		FLAG_C = CFLAG_CLEAR;
 18.9761 +		return;
 18.9762 +	}
 18.9763 +	m68ki_exception_illegal();
 18.9764 +}
 18.9765 +
 18.9766 +
 18.9767 +M68KMAKE_OP(tst, 16, ., pcix)
 18.9768 +{
 18.9769 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9770 +	{
 18.9771 +		uint res = OPER_PCIX_16();
 18.9772 +
 18.9773 +		FLAG_N = NFLAG_16(res);
 18.9774 +		FLAG_Z = res;
 18.9775 +		FLAG_V = VFLAG_CLEAR;
 18.9776 +		FLAG_C = CFLAG_CLEAR;
 18.9777 +		return;
 18.9778 +	}
 18.9779 +	m68ki_exception_illegal();
 18.9780 +}
 18.9781 +
 18.9782 +
 18.9783 +M68KMAKE_OP(tst, 16, ., i)
 18.9784 +{
 18.9785 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9786 +	{
 18.9787 +		uint res = OPER_I_16();
 18.9788 +
 18.9789 +		FLAG_N = NFLAG_16(res);
 18.9790 +		FLAG_Z = res;
 18.9791 +		FLAG_V = VFLAG_CLEAR;
 18.9792 +		FLAG_C = CFLAG_CLEAR;
 18.9793 +		return;
 18.9794 +	}
 18.9795 +	m68ki_exception_illegal();
 18.9796 +}
 18.9797 +
 18.9798 +
 18.9799 +M68KMAKE_OP(tst, 32, ., d)
 18.9800 +{
 18.9801 +	uint res = DY;
 18.9802 +
 18.9803 +	FLAG_N = NFLAG_32(res);
 18.9804 +	FLAG_Z = res;
 18.9805 +	FLAG_V = VFLAG_CLEAR;
 18.9806 +	FLAG_C = CFLAG_CLEAR;
 18.9807 +}
 18.9808 +
 18.9809 +
 18.9810 +M68KMAKE_OP(tst, 32, ., a)
 18.9811 +{
 18.9812 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9813 +	{
 18.9814 +		uint res = AY;
 18.9815 +
 18.9816 +		FLAG_N = NFLAG_32(res);
 18.9817 +		FLAG_Z = res;
 18.9818 +		FLAG_V = VFLAG_CLEAR;
 18.9819 +		FLAG_C = CFLAG_CLEAR;
 18.9820 +		return;
 18.9821 +	}
 18.9822 +	m68ki_exception_illegal();
 18.9823 +}
 18.9824 +
 18.9825 +
 18.9826 +M68KMAKE_OP(tst, 32, ., .)
 18.9827 +{
 18.9828 +	uint res = M68KMAKE_GET_OPER_AY_32;
 18.9829 +
 18.9830 +	FLAG_N = NFLAG_32(res);
 18.9831 +	FLAG_Z = res;
 18.9832 +	FLAG_V = VFLAG_CLEAR;
 18.9833 +	FLAG_C = CFLAG_CLEAR;
 18.9834 +}
 18.9835 +
 18.9836 +
 18.9837 +M68KMAKE_OP(tst, 32, ., pcdi)
 18.9838 +{
 18.9839 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9840 +	{
 18.9841 +		uint res = OPER_PCDI_32();
 18.9842 +
 18.9843 +		FLAG_N = NFLAG_32(res);
 18.9844 +		FLAG_Z = res;
 18.9845 +		FLAG_V = VFLAG_CLEAR;
 18.9846 +		FLAG_C = CFLAG_CLEAR;
 18.9847 +		return;
 18.9848 +	}
 18.9849 +	m68ki_exception_illegal();
 18.9850 +}
 18.9851 +
 18.9852 +
 18.9853 +M68KMAKE_OP(tst, 32, ., pcix)
 18.9854 +{
 18.9855 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9856 +	{
 18.9857 +		uint res = OPER_PCIX_32();
 18.9858 +
 18.9859 +		FLAG_N = NFLAG_32(res);
 18.9860 +		FLAG_Z = res;
 18.9861 +		FLAG_V = VFLAG_CLEAR;
 18.9862 +		FLAG_C = CFLAG_CLEAR;
 18.9863 +		return;
 18.9864 +	}
 18.9865 +	m68ki_exception_illegal();
 18.9866 +}
 18.9867 +
 18.9868 +
 18.9869 +M68KMAKE_OP(tst, 32, ., i)
 18.9870 +{
 18.9871 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9872 +	{
 18.9873 +		uint res = OPER_I_32();
 18.9874 +
 18.9875 +		FLAG_N = NFLAG_32(res);
 18.9876 +		FLAG_Z = res;
 18.9877 +		FLAG_V = VFLAG_CLEAR;
 18.9878 +		FLAG_C = CFLAG_CLEAR;
 18.9879 +		return;
 18.9880 +	}
 18.9881 +	m68ki_exception_illegal();
 18.9882 +}
 18.9883 +
 18.9884 +
 18.9885 +M68KMAKE_OP(unlk, 32, ., a7)
 18.9886 +{
 18.9887 +	REG_A[7] = m68ki_read_32(REG_A[7]);
 18.9888 +}
 18.9889 +
 18.9890 +
 18.9891 +M68KMAKE_OP(unlk, 32, ., .)
 18.9892 +{
 18.9893 +	uint* r_dst = &AY;
 18.9894 +
 18.9895 +	REG_A[7] = *r_dst;
 18.9896 +	*r_dst = m68ki_pull_32();
 18.9897 +}
 18.9898 +
 18.9899 +
 18.9900 +M68KMAKE_OP(unpk, 16, rr, .)
 18.9901 +{
 18.9902 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9903 +	{
 18.9904 +		/* Note: DX and DY are reversed in Motorola's docs */
 18.9905 +		uint src = DY;
 18.9906 +		uint* r_dst = &DX;
 18.9907 +
 18.9908 +		*r_dst = MASK_OUT_BELOW_16(*r_dst) | (((((src << 4) & 0x0f00) | (src & 0x000f)) + OPER_I_16()) & 0xffff);
 18.9909 +		return;
 18.9910 +	}
 18.9911 +	m68ki_exception_illegal();
 18.9912 +}
 18.9913 +
 18.9914 +
 18.9915 +M68KMAKE_OP(unpk, 16, mm, ax7)
 18.9916 +{
 18.9917 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9918 +	{
 18.9919 +		/* Note: AX and AY are reversed in Motorola's docs */
 18.9920 +		uint src = OPER_AY_PD_8();
 18.9921 +		uint ea_dst;
 18.9922 +
 18.9923 +		src = (((src << 4) & 0x0f00) | (src & 0x000f)) + OPER_I_16();
 18.9924 +		ea_dst = EA_A7_PD_8();
 18.9925 +		m68ki_write_8(ea_dst, (src >> 8) & 0xff);
 18.9926 +		ea_dst = EA_A7_PD_8();
 18.9927 +		m68ki_write_8(ea_dst, src & 0xff);
 18.9928 +		return;
 18.9929 +	}
 18.9930 +	m68ki_exception_illegal();
 18.9931 +}
 18.9932 +
 18.9933 +
 18.9934 +M68KMAKE_OP(unpk, 16, mm, ay7)
 18.9935 +{
 18.9936 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9937 +	{
 18.9938 +		/* Note: AX and AY are reversed in Motorola's docs */
 18.9939 +		uint src = OPER_A7_PD_8();
 18.9940 +		uint ea_dst;
 18.9941 +
 18.9942 +		src = (((src << 4) & 0x0f00) | (src & 0x000f)) + OPER_I_16();
 18.9943 +		ea_dst = EA_AX_PD_8();
 18.9944 +		m68ki_write_8(ea_dst, (src >> 8) & 0xff);
 18.9945 +		ea_dst = EA_AX_PD_8();
 18.9946 +		m68ki_write_8(ea_dst, src & 0xff);
 18.9947 +		return;
 18.9948 +	}
 18.9949 +	m68ki_exception_illegal();
 18.9950 +}
 18.9951 +
 18.9952 +
 18.9953 +M68KMAKE_OP(unpk, 16, mm, axy7)
 18.9954 +{
 18.9955 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9956 +	{
 18.9957 +		uint src = OPER_A7_PD_8();
 18.9958 +		uint ea_dst;
 18.9959 +
 18.9960 +		src = (((src << 4) & 0x0f00) | (src & 0x000f)) + OPER_I_16();
 18.9961 +		ea_dst = EA_A7_PD_8();
 18.9962 +		m68ki_write_8(ea_dst, (src >> 8) & 0xff);
 18.9963 +		ea_dst = EA_A7_PD_8();
 18.9964 +		m68ki_write_8(ea_dst, src & 0xff);
 18.9965 +		return;
 18.9966 +	}
 18.9967 +	m68ki_exception_illegal();
 18.9968 +}
 18.9969 +
 18.9970 +
 18.9971 +M68KMAKE_OP(unpk, 16, mm, .)
 18.9972 +{
 18.9973 +	if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 18.9974 +	{
 18.9975 +		/* Note: AX and AY are reversed in Motorola's docs */
 18.9976 +		uint src = OPER_AY_PD_8();
 18.9977 +		uint ea_dst;
 18.9978 +
 18.9979 +		src = (((src << 4) & 0x0f00) | (src & 0x000f)) + OPER_I_16();
 18.9980 +		ea_dst = EA_AX_PD_8();
 18.9981 +		m68ki_write_8(ea_dst, (src >> 8) & 0xff);
 18.9982 +		ea_dst = EA_AX_PD_8();
 18.9983 +		m68ki_write_8(ea_dst, src & 0xff);
 18.9984 +		return;
 18.9985 +	}
 18.9986 +	m68ki_exception_illegal();
 18.9987 +}
 18.9988 +
 18.9989 +
 18.9990 +
 18.9991 +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 18.9992 +M68KMAKE_END
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/musashi/m68kconf.h	Sat Nov 27 01:13:12 2010 +0000
    19.3 @@ -0,0 +1,183 @@
    19.4 +/* ======================================================================== */
    19.5 +/* ========================= LICENSING & COPYRIGHT ======================== */
    19.6 +/* ======================================================================== */
    19.7 +/*
    19.8 + *                                  MUSASHI
    19.9 + *                                Version 3.3
   19.10 + *
   19.11 + * A portable Motorola M680x0 processor emulation engine.
   19.12 + * Copyright 1998-2001 Karl Stenerud.  All rights reserved.
   19.13 + *
   19.14 + * This code may be freely used for non-commercial purposes as long as this
   19.15 + * copyright notice remains unaltered in the source code and any binary files
   19.16 + * containing this code in compiled form.
   19.17 + *
   19.18 + * All other lisencing terms must be negotiated with the author
   19.19 + * (Karl Stenerud).
   19.20 + *
   19.21 + * The latest version of this code can be obtained at:
   19.22 + * http://kstenerud.cjb.net
   19.23 + */
   19.24 +
   19.25 +
   19.26 +
   19.27 +#ifndef M68KCONF__HEADER
   19.28 +#define M68KCONF__HEADER
   19.29 +
   19.30 +
   19.31 +/* Configuration switches.
   19.32 + * Use OPT_SPECIFY_HANDLER for configuration options that allow callbacks.
   19.33 + * OPT_SPECIFY_HANDLER causes the core to link directly to the function
   19.34 + * or macro you specify, rather than using callback functions whose pointer
   19.35 + * must be passed in using m68k_set_xxx_callback().
   19.36 + */
   19.37 +#define OPT_OFF             0
   19.38 +#define OPT_ON              1
   19.39 +#define OPT_SPECIFY_HANDLER 2
   19.40 +
   19.41 +
   19.42 +/* ======================================================================== */
   19.43 +/* ============================== MAME STUFF ============================== */
   19.44 +/* ======================================================================== */
   19.45 +
   19.46 +/* If you're compiling this for MAME, only change M68K_COMPILE_FOR_MAME
   19.47 + * to OPT_ON and use m68kmame.h to configure the 68k core.
   19.48 + */
   19.49 +#ifndef M68K_COMPILE_FOR_MAME
   19.50 +#define M68K_COMPILE_FOR_MAME      OPT_OFF
   19.51 +#endif /* M68K_COMPILE_FOR_MAME */
   19.52 +
   19.53 +#if M68K_COMPILE_FOR_MAME == OPT_ON
   19.54 +#include "m68kmame.h"
   19.55 +#else
   19.56 +
   19.57 +
   19.58 +
   19.59 +/* ======================================================================== */
   19.60 +/* ============================= CONFIGURATION ============================ */
   19.61 +/* ======================================================================== */
   19.62 +
   19.63 +/* Turn on if you want to use the following M68K variants */
   19.64 +#define M68K_EMULATE_010            OPT_ON
   19.65 +#define M68K_EMULATE_EC020          OPT_ON
   19.66 +#define M68K_EMULATE_020            OPT_ON
   19.67 +
   19.68 +
   19.69 +/* If on, the CPU will call m68k_read_immediate_xx() for immediate addressing
   19.70 + * and m68k_read_pcrelative_xx() for PC-relative addressing.
   19.71 + * If off, all read requests from the CPU will be redirected to m68k_read_xx()
   19.72 + */
   19.73 +#define M68K_SEPARATE_READS         OPT_OFF
   19.74 +
   19.75 +
   19.76 +/* If on, CPU will call the interrupt acknowledge callback when it services an
   19.77 + * interrupt.
   19.78 + * If off, all interrupts will be autovectored and all interrupt requests will
   19.79 + * auto-clear when the interrupt is serviced.
   19.80 + */
   19.81 +#define M68K_EMULATE_INT_ACK        OPT_OFF
   19.82 +#define M68K_INT_ACK_CALLBACK(A)    your_int_ack_handler_function(A)
   19.83 +
   19.84 +
   19.85 +/* If on, CPU will call the breakpoint acknowledge callback when it encounters
   19.86 + * a breakpoint instruction and it is running a 68010+.
   19.87 + */
   19.88 +#define M68K_EMULATE_BKPT_ACK       OPT_OFF
   19.89 +#define M68K_BKPT_ACK_CALLBACK()    your_bkpt_ack_handler_function()
   19.90 +
   19.91 +
   19.92 +/* If on, the CPU will monitor the trace flags and take trace exceptions
   19.93 + */
   19.94 +#define M68K_EMULATE_TRACE          OPT_OFF
   19.95 +
   19.96 +
   19.97 +/* If on, CPU will call the output reset callback when it encounters a reset
   19.98 + * instruction.
   19.99 + */
  19.100 +#define M68K_EMULATE_RESET          OPT_OFF
  19.101 +#define M68K_RESET_CALLBACK()       your_reset_handler_function()
  19.102 +
  19.103 +
  19.104 +/* If on, CPU will call the set fc callback on every memory access to
  19.105 + * differentiate between user/supervisor, program/data access like a real
  19.106 + * 68000 would.  This should be enabled and the callback should be set if you
  19.107 + * want to properly emulate the m68010 or higher. (moves uses function codes
  19.108 + * to read/write data from different address spaces)
  19.109 + */
  19.110 +#define M68K_EMULATE_FC             OPT_OFF
  19.111 +#define M68K_SET_FC_CALLBACK(A)     your_set_fc_handler_function(A)
  19.112 +
  19.113 +
  19.114 +/* If on, CPU will call the pc changed callback when it changes the PC by a
  19.115 + * large value.  This allows host programs to be nicer when it comes to
  19.116 + * fetching immediate data and instructions on a banked memory system.
  19.117 + */
  19.118 +#define M68K_MONITOR_PC             OPT_OFF
  19.119 +#define M68K_SET_PC_CALLBACK(A)     your_pc_changed_handler_function(A)
  19.120 +
  19.121 +
  19.122 +/* If on, CPU will call the instruction hook callback before every
  19.123 + * instruction.
  19.124 + */
  19.125 +#define M68K_INSTRUCTION_HOOK       OPT_OFF
  19.126 +#define M68K_INSTRUCTION_CALLBACK() your_instruction_hook_function()
  19.127 +
  19.128 +
  19.129 +/* If on, the CPU will emulate the 4-byte prefetch queue of a real 68000 */
  19.130 +#define M68K_EMULATE_PREFETCH       OPT_OFF
  19.131 +
  19.132 +
  19.133 +/* If on, the CPU will generate address error exceptions if it tries to
  19.134 + * access a word or longword at an odd address.
  19.135 + * NOTE: Do not enable this!  It is not working!
  19.136 + */
  19.137 +#define M68K_EMULATE_ADDRESS_ERROR  OPT_OFF
  19.138 +
  19.139 +
  19.140 +/* Turn on to enable logging of illegal instruction calls.
  19.141 + * M68K_LOG_FILEHANDLE must be #defined to a stdio file stream.
  19.142 + * Turn on M68K_LOG_1010_1111 to log all 1010 and 1111 calls.
  19.143 + */
  19.144 +#define M68K_LOG_ENABLE             OPT_OFF
  19.145 +#define M68K_LOG_1010_1111          OPT_OFF
  19.146 +#define M68K_LOG_FILEHANDLE         some_file_handle
  19.147 +
  19.148 +
  19.149 +/* ----------------------------- COMPATIBILITY ---------------------------- */
  19.150 +
  19.151 +/* The following options set optimizations that violate the current ANSI
  19.152 + * standard, but will be compliant under the forthcoming C9X standard.
  19.153 + */
  19.154 +
  19.155 +
  19.156 +/* If on, the enulation core will use 64-bit integers to speed up some
  19.157 + * operations.
  19.158 +*/
  19.159 +#define M68K_USE_64_BIT  OPT_OFF
  19.160 +
  19.161 +
  19.162 +/* Set to your compiler's static inline keyword to enable it, or
  19.163 + * set it to blank to disable it.
  19.164 + * If you define INLINE in the makefile, it will override this value.
  19.165 + * NOTE: not enabling inline functions will SEVERELY slow down emulation.
  19.166 + */
  19.167 +#ifndef INLINE
  19.168 +#define INLINE static __inline__
  19.169 +#endif /* INLINE */
  19.170 +
  19.171 +
  19.172 +/* If your environment requires special prefixes for system callback functions
  19.173 + * such as the argument to qsort(), then set them here or in the makefile.
  19.174 + */
  19.175 +#ifndef DECL_SPEC
  19.176 +#define DECL_SPEC
  19.177 +#endif
  19.178 +
  19.179 +#endif /* M68K_COMPILE_FOR_MAME */
  19.180 +
  19.181 +
  19.182 +/* ======================================================================== */
  19.183 +/* ============================== END OF FILE ============================= */
  19.184 +/* ======================================================================== */
  19.185 +
  19.186 +#endif /* M68KCONF__HEADER */
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/musashi/m68kcpu.c	Sat Nov 27 01:13:12 2010 +0000
    20.3 @@ -0,0 +1,894 @@
    20.4 +/* ======================================================================== */
    20.5 +/* ========================= LICENSING & COPYRIGHT ======================== */
    20.6 +/* ======================================================================== */
    20.7 +
    20.8 +#if 0
    20.9 +static const char* copyright_notice =
   20.10 +"MUSASHI\n"
   20.11 +"Version 3.3 (2001-01-29)\n"
   20.12 +"A portable Motorola M680x0 processor emulation engine.\n"
   20.13 +"Copyright 1998-2001 Karl Stenerud.  All rights reserved.\n"
   20.14 +"\n"
   20.15 +"This code may be freely used for non-commercial purpooses as long as this\n"
   20.16 +"copyright notice remains unaltered in the source code and any binary files\n"
   20.17 +"containing this code in compiled form.\n"
   20.18 +"\n"
   20.19 +"All other lisencing terms must be negotiated with the author\n"
   20.20 +"(Karl Stenerud).\n"
   20.21 +"\n"
   20.22 +"The latest version of this code can be obtained at:\n"
   20.23 +"http://kstenerud.cjb.net\n"
   20.24 +;
   20.25 +#endif
   20.26 +
   20.27 +
   20.28 +/* ======================================================================== */
   20.29 +/* ================================= NOTES ================================ */
   20.30 +/* ======================================================================== */
   20.31 +
   20.32 +
   20.33 +
   20.34 +/* ======================================================================== */
   20.35 +/* ================================ INCLUDES ============================== */
   20.36 +/* ======================================================================== */
   20.37 +
   20.38 +#include "m68kops.h"
   20.39 +#include "m68kcpu.h"
   20.40 +
   20.41 +/* ======================================================================== */
   20.42 +/* ================================= DATA ================================= */
   20.43 +/* ======================================================================== */
   20.44 +
   20.45 +int  m68ki_initial_cycles;
   20.46 +int  m68ki_remaining_cycles = 0;                     /* Number of clocks remaining */
   20.47 +uint m68ki_tracing = 0;
   20.48 +uint m68ki_address_space;
   20.49 +
   20.50 +#ifdef M68K_LOG_ENABLE
   20.51 +char* m68ki_cpu_names[9] =
   20.52 +{
   20.53 +	"Invalid CPU",
   20.54 +	"M68000",
   20.55 +	"M68010",
   20.56 +	"Invalid CPU",
   20.57 +	"M68EC020"
   20.58 +	"Invalid CPU",
   20.59 +	"Invalid CPU",
   20.60 +	"Invalid CPU",
   20.61 +	"M68020"
   20.62 +};
   20.63 +#endif /* M68K_LOG_ENABLE */
   20.64 +
   20.65 +/* The CPU core */
   20.66 +m68ki_cpu_core m68ki_cpu = {0};
   20.67 +
   20.68 +#if M68K_EMULATE_ADDRESS_ERROR
   20.69 +jmp_buf m68ki_address_error_trap;
   20.70 +#endif /* M68K_EMULATE_ADDRESS_ERROR */
   20.71 +
   20.72 +/* Used by shift & rotate instructions */
   20.73 +uint8 m68ki_shift_8_table[65] =
   20.74 +{
   20.75 +	0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0xff,
   20.76 +	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   20.77 +	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   20.78 +	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   20.79 +	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   20.80 +	0xff, 0xff, 0xff, 0xff, 0xff
   20.81 +};
   20.82 +uint16 m68ki_shift_16_table[65] =
   20.83 +{
   20.84 +	0x0000, 0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
   20.85 +	0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff, 0xffff,
   20.86 +	0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
   20.87 +	0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
   20.88 +	0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
   20.89 +	0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
   20.90 +	0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
   20.91 +	0xffff, 0xffff
   20.92 +};
   20.93 +uint m68ki_shift_32_table[65] =
   20.94 +{
   20.95 +	0x00000000, 0x80000000, 0xc0000000, 0xe0000000, 0xf0000000, 0xf8000000,
   20.96 +	0xfc000000, 0xfe000000, 0xff000000, 0xff800000, 0xffc00000, 0xffe00000,
   20.97 +	0xfff00000, 0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000, 0xffff8000,
   20.98 +	0xffffc000, 0xffffe000, 0xfffff000, 0xfffff800, 0xfffffc00, 0xfffffe00,
   20.99 +	0xffffff00, 0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0, 0xfffffff8,
  20.100 +	0xfffffffc, 0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
  20.101 +	0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
  20.102 +	0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
  20.103 +	0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
  20.104 +	0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
  20.105 +	0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
  20.106 +};
  20.107 +
  20.108 +
  20.109 +/* Number of clock cycles to use for exception processing.
  20.110 + * I used 4 for any vectors that are undocumented for processing times.
  20.111 + */
  20.112 +uint8 m68ki_exception_cycle_table[3][256] =
  20.113 +{
  20.114 +	{ /* 000 */
  20.115 +		  4, /*  0: Reset - Initial Stack Pointer                      */
  20.116 +		  4, /*  1: Reset - Initial Program Counter                    */
  20.117 +		 50, /*  2: Bus Error                             (unemulated) */
  20.118 +		 50, /*  3: Address Error                         (unemulated) */
  20.119 +		 34, /*  4: Illegal Instruction                                */
  20.120 +		 38, /*  5: Divide by Zero -- ASG: changed from 42             */
  20.121 +		 40, /*  6: CHK -- ASG: chanaged from 44                       */
  20.122 +		 34, /*  7: TRAPV                                              */
  20.123 +		 34, /*  8: Privilege Violation                                */
  20.124 +		 34, /*  9: Trace                                              */
  20.125 +		  4, /* 10: 1010                                               */
  20.126 +		  4, /* 11: 1111                                               */
  20.127 +		  4, /* 12: RESERVED                                           */
  20.128 +		  4, /* 13: Coprocessor Protocol Violation        (unemulated) */
  20.129 +		  4, /* 14: Format Error                                       */
  20.130 +		 44, /* 15: Uninitialized Interrupt                            */
  20.131 +		  4, /* 16: RESERVED                                           */
  20.132 +		  4, /* 17: RESERVED                                           */
  20.133 +		  4, /* 18: RESERVED                                           */
  20.134 +		  4, /* 19: RESERVED                                           */
  20.135 +		  4, /* 20: RESERVED                                           */
  20.136 +		  4, /* 21: RESERVED                                           */
  20.137 +		  4, /* 22: RESERVED                                           */
  20.138 +		  4, /* 23: RESERVED                                           */
  20.139 +		 44, /* 24: Spurious Interrupt                                 */
  20.140 +		 44, /* 25: Level 1 Interrupt Autovector                       */
  20.141 +		 44, /* 26: Level 2 Interrupt Autovector                       */
  20.142 +		 44, /* 27: Level 3 Interrupt Autovector                       */
  20.143 +		 44, /* 28: Level 4 Interrupt Autovector                       */
  20.144 +		 44, /* 29: Level 5 Interrupt Autovector                       */
  20.145 +		 44, /* 30: Level 6 Interrupt Autovector                       */
  20.146 +		 44, /* 31: Level 7 Interrupt Autovector                       */
  20.147 +		 34, /* 32: TRAP #0 -- ASG: chanaged from 38                   */
  20.148 +		 34, /* 33: TRAP #1                                            */
  20.149 +		 34, /* 34: TRAP #2                                            */
  20.150 +		 34, /* 35: TRAP #3                                            */
  20.151 +		 34, /* 36: TRAP #4                                            */
  20.152 +		 34, /* 37: TRAP #5                                            */
  20.153 +		 34, /* 38: TRAP #6                                            */
  20.154 +		 34, /* 39: TRAP #7                                            */
  20.155 +		 34, /* 40: TRAP #8                                            */
  20.156 +		 34, /* 41: TRAP #9                                            */
  20.157 +		 34, /* 42: TRAP #10                                           */
  20.158 +		 34, /* 43: TRAP #11                                           */
  20.159 +		 34, /* 44: TRAP #12                                           */
  20.160 +		 34, /* 45: TRAP #13                                           */
  20.161 +		 34, /* 46: TRAP #14                                           */
  20.162 +		 34, /* 47: TRAP #15                                           */
  20.163 +		  4, /* 48: FP Branch or Set on Unknown Condition (unemulated) */
  20.164 +		  4, /* 49: FP Inexact Result                     (unemulated) */
  20.165 +		  4, /* 50: FP Divide by Zero                     (unemulated) */
  20.166 +		  4, /* 51: FP Underflow                          (unemulated) */
  20.167 +		  4, /* 52: FP Operand Error                      (unemulated) */
  20.168 +		  4, /* 53: FP Overflow                           (unemulated) */
  20.169 +		  4, /* 54: FP Signaling NAN                      (unemulated) */
  20.170 +		  4, /* 55: FP Unimplemented Data Type            (unemulated) */
  20.171 +		  4, /* 56: MMU Configuration Error               (unemulated) */
  20.172 +		  4, /* 57: MMU Illegal Operation Error           (unemulated) */
  20.173 +		  4, /* 58: MMU Access Level Violation Error      (unemulated) */
  20.174 +		  4, /* 59: RESERVED                                           */
  20.175 +		  4, /* 60: RESERVED                                           */
  20.176 +		  4, /* 61: RESERVED                                           */
  20.177 +		  4, /* 62: RESERVED                                           */
  20.178 +		  4, /* 63: RESERVED                                           */
  20.179 +		     /* 64-255: User Defined                                   */
  20.180 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.181 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.182 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.183 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.184 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.185 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
  20.186 +	},
  20.187 +	{ /* 010 */
  20.188 +		  4, /*  0: Reset - Initial Stack Pointer                      */
  20.189 +		  4, /*  1: Reset - Initial Program Counter                    */
  20.190 +		126, /*  2: Bus Error                             (unemulated) */
  20.191 +		126, /*  3: Address Error                         (unemulated) */
  20.192 +		 38, /*  4: Illegal Instruction                                */
  20.193 +		 44, /*  5: Divide by Zero                                     */
  20.194 +		 44, /*  6: CHK                                                */
  20.195 +		 34, /*  7: TRAPV                                              */
  20.196 +		 38, /*  8: Privilege Violation                                */
  20.197 +		 38, /*  9: Trace                                              */
  20.198 +		  4, /* 10: 1010                                               */
  20.199 +		  4, /* 11: 1111                                               */
  20.200 +		  4, /* 12: RESERVED                                           */
  20.201 +		  4, /* 13: Coprocessor Protocol Violation        (unemulated) */
  20.202 +		  4, /* 14: Format Error                                       */
  20.203 +		 44, /* 15: Uninitialized Interrupt                            */
  20.204 +		  4, /* 16: RESERVED                                           */
  20.205 +		  4, /* 17: RESERVED                                           */
  20.206 +		  4, /* 18: RESERVED                                           */
  20.207 +		  4, /* 19: RESERVED                                           */
  20.208 +		  4, /* 20: RESERVED                                           */
  20.209 +		  4, /* 21: RESERVED                                           */
  20.210 +		  4, /* 22: RESERVED                                           */
  20.211 +		  4, /* 23: RESERVED                                           */
  20.212 +		 46, /* 24: Spurious Interrupt                                 */
  20.213 +		 46, /* 25: Level 1 Interrupt Autovector                       */
  20.214 +		 46, /* 26: Level 2 Interrupt Autovector                       */
  20.215 +		 46, /* 27: Level 3 Interrupt Autovector                       */
  20.216 +		 46, /* 28: Level 4 Interrupt Autovector                       */
  20.217 +		 46, /* 29: Level 5 Interrupt Autovector                       */
  20.218 +		 46, /* 30: Level 6 Interrupt Autovector                       */
  20.219 +		 46, /* 31: Level 7 Interrupt Autovector                       */
  20.220 +		 38, /* 32: TRAP #0                                            */
  20.221 +		 38, /* 33: TRAP #1                                            */
  20.222 +		 38, /* 34: TRAP #2                                            */
  20.223 +		 38, /* 35: TRAP #3                                            */
  20.224 +		 38, /* 36: TRAP #4                                            */
  20.225 +		 38, /* 37: TRAP #5                                            */
  20.226 +		 38, /* 38: TRAP #6                                            */
  20.227 +		 38, /* 39: TRAP #7                                            */
  20.228 +		 38, /* 40: TRAP #8                                            */
  20.229 +		 38, /* 41: TRAP #9                                            */
  20.230 +		 38, /* 42: TRAP #10                                           */
  20.231 +		 38, /* 43: TRAP #11                                           */
  20.232 +		 38, /* 44: TRAP #12                                           */
  20.233 +		 38, /* 45: TRAP #13                                           */
  20.234 +		 38, /* 46: TRAP #14                                           */
  20.235 +		 38, /* 47: TRAP #15                                           */
  20.236 +		  4, /* 48: FP Branch or Set on Unknown Condition (unemulated) */
  20.237 +		  4, /* 49: FP Inexact Result                     (unemulated) */
  20.238 +		  4, /* 50: FP Divide by Zero                     (unemulated) */
  20.239 +		  4, /* 51: FP Underflow                          (unemulated) */
  20.240 +		  4, /* 52: FP Operand Error                      (unemulated) */
  20.241 +		  4, /* 53: FP Overflow                           (unemulated) */
  20.242 +		  4, /* 54: FP Signaling NAN                      (unemulated) */
  20.243 +		  4, /* 55: FP Unimplemented Data Type            (unemulated) */
  20.244 +		  4, /* 56: MMU Configuration Error               (unemulated) */
  20.245 +		  4, /* 57: MMU Illegal Operation Error           (unemulated) */
  20.246 +		  4, /* 58: MMU Access Level Violation Error      (unemulated) */
  20.247 +		  4, /* 59: RESERVED                                           */
  20.248 +		  4, /* 60: RESERVED                                           */
  20.249 +		  4, /* 61: RESERVED                                           */
  20.250 +		  4, /* 62: RESERVED                                           */
  20.251 +		  4, /* 63: RESERVED                                           */
  20.252 +		     /* 64-255: User Defined                                   */
  20.253 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.254 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.255 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.256 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.257 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.258 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
  20.259 +	},
  20.260 +	{ /* 020 */
  20.261 +		  4, /*  0: Reset - Initial Stack Pointer                      */
  20.262 +		  4, /*  1: Reset - Initial Program Counter                    */
  20.263 +		 50, /*  2: Bus Error                             (unemulated) */
  20.264 +		 50, /*  3: Address Error                         (unemulated) */
  20.265 +		 20, /*  4: Illegal Instruction                                */
  20.266 +		 38, /*  5: Divide by Zero                                     */
  20.267 +		 40, /*  6: CHK                                                */
  20.268 +		 20, /*  7: TRAPV                                              */
  20.269 +		 34, /*  8: Privilege Violation                                */
  20.270 +		 25, /*  9: Trace                                              */
  20.271 +		 20, /* 10: 1010                                               */
  20.272 +		 20, /* 11: 1111                                               */
  20.273 +		  4, /* 12: RESERVED                                           */
  20.274 +		  4, /* 13: Coprocessor Protocol Violation        (unemulated) */
  20.275 +		  4, /* 14: Format Error                                       */
  20.276 +		 30, /* 15: Uninitialized Interrupt                            */
  20.277 +		  4, /* 16: RESERVED                                           */
  20.278 +		  4, /* 17: RESERVED                                           */
  20.279 +		  4, /* 18: RESERVED                                           */
  20.280 +		  4, /* 19: RESERVED                                           */
  20.281 +		  4, /* 20: RESERVED                                           */
  20.282 +		  4, /* 21: RESERVED                                           */
  20.283 +		  4, /* 22: RESERVED                                           */
  20.284 +		  4, /* 23: RESERVED                                           */
  20.285 +		 30, /* 24: Spurious Interrupt                                 */
  20.286 +		 30, /* 25: Level 1 Interrupt Autovector                       */
  20.287 +		 30, /* 26: Level 2 Interrupt Autovector                       */
  20.288 +		 30, /* 27: Level 3 Interrupt Autovector                       */
  20.289 +		 30, /* 28: Level 4 Interrupt Autovector                       */
  20.290 +		 30, /* 29: Level 5 Interrupt Autovector                       */
  20.291 +		 30, /* 30: Level 6 Interrupt Autovector                       */
  20.292 +		 30, /* 31: Level 7 Interrupt Autovector                       */
  20.293 +		 20, /* 32: TRAP #0                                            */
  20.294 +		 20, /* 33: TRAP #1                                            */
  20.295 +		 20, /* 34: TRAP #2                                            */
  20.296 +		 20, /* 35: TRAP #3                                            */
  20.297 +		 20, /* 36: TRAP #4                                            */
  20.298 +		 20, /* 37: TRAP #5                                            */
  20.299 +		 20, /* 38: TRAP #6                                            */
  20.300 +		 20, /* 39: TRAP #7                                            */
  20.301 +		 20, /* 40: TRAP #8                                            */
  20.302 +		 20, /* 41: TRAP #9                                            */
  20.303 +		 20, /* 42: TRAP #10                                           */
  20.304 +		 20, /* 43: TRAP #11                                           */
  20.305 +		 20, /* 44: TRAP #12                                           */
  20.306 +		 20, /* 45: TRAP #13                                           */
  20.307 +		 20, /* 46: TRAP #14                                           */
  20.308 +		 20, /* 47: TRAP #15                                           */
  20.309 +		  4, /* 48: FP Branch or Set on Unknown Condition (unemulated) */
  20.310 +		  4, /* 49: FP Inexact Result                     (unemulated) */
  20.311 +		  4, /* 50: FP Divide by Zero                     (unemulated) */
  20.312 +		  4, /* 51: FP Underflow                          (unemulated) */
  20.313 +		  4, /* 52: FP Operand Error                      (unemulated) */
  20.314 +		  4, /* 53: FP Overflow                           (unemulated) */
  20.315 +		  4, /* 54: FP Signaling NAN                      (unemulated) */
  20.316 +		  4, /* 55: FP Unimplemented Data Type            (unemulated) */
  20.317 +		  4, /* 56: MMU Configuration Error               (unemulated) */
  20.318 +		  4, /* 57: MMU Illegal Operation Error           (unemulated) */
  20.319 +		  4, /* 58: MMU Access Level Violation Error      (unemulated) */
  20.320 +		  4, /* 59: RESERVED                                           */
  20.321 +		  4, /* 60: RESERVED                                           */
  20.322 +		  4, /* 61: RESERVED                                           */
  20.323 +		  4, /* 62: RESERVED                                           */
  20.324 +		  4, /* 63: RESERVED                                           */
  20.325 +		     /* 64-255: User Defined                                   */
  20.326 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.327 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.328 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.329 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.330 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
  20.331 +		  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
  20.332 +	}
  20.333 +};
  20.334 +
  20.335 +uint8 m68ki_ea_idx_cycle_table[64] =
  20.336 +{
  20.337 +	 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  20.338 +	 0, /* ..01.000 no memory indirect, base NULL             */
  20.339 +	 5, /* ..01..01 memory indirect,    base NULL, outer NULL */
  20.340 +	 7, /* ..01..10 memory indirect,    base NULL, outer 16   */
  20.341 +	 7, /* ..01..11 memory indirect,    base NULL, outer 32   */
  20.342 +	 0,  5,  7,  7,  0,  5,  7,  7,  0,  5,  7,  7,
  20.343 +	 2, /* ..10.000 no memory indirect, base 16               */
  20.344 +	 7, /* ..10..01 memory indirect,    base 16,   outer NULL */
  20.345 +	 9, /* ..10..10 memory indirect,    base 16,   outer 16   */
  20.346 +	 9, /* ..10..11 memory indirect,    base 16,   outer 32   */
  20.347 +	 0,  7,  9,  9,  0,  7,  9,  9,  0,  7,  9,  9,
  20.348 +	 6, /* ..11.000 no memory indirect, base 32               */
  20.349 +	11, /* ..11..01 memory indirect,    base 32,   outer NULL */
  20.350 +	13, /* ..11..10 memory indirect,    base 32,   outer 16   */
  20.351 +	13, /* ..11..11 memory indirect,    base 32,   outer 32   */
  20.352 +	 0, 11, 13, 13,  0, 11, 13, 13,  0, 11, 13, 13
  20.353 +};
  20.354 +
  20.355 +
  20.356 +
  20.357 +/* ======================================================================== */
  20.358 +/* =============================== CALLBACKS ============================== */
  20.359 +/* ======================================================================== */
  20.360 +
  20.361 +/* Default callbacks used if the callback hasn't been set yet, or if the
  20.362 + * callback is set to NULL
  20.363 + */
  20.364 +
  20.365 +/* Interrupt acknowledge */
  20.366 +static int default_int_ack_callback_data;
  20.367 +static int default_int_ack_callback(int int_level)
  20.368 +{
  20.369 +	default_int_ack_callback_data = int_level;
  20.370 +	CPU_INT_LEVEL = 0;
  20.371 +	return M68K_INT_ACK_AUTOVECTOR;
  20.372 +}
  20.373 +
  20.374 +/* Breakpoint acknowledge */
  20.375 +static unsigned int default_bkpt_ack_callback_data;
  20.376 +static void default_bkpt_ack_callback(unsigned int data)
  20.377 +{
  20.378 +	default_bkpt_ack_callback_data = data;
  20.379 +}
  20.380 +
  20.381 +/* Called when a reset instruction is executed */
  20.382 +static void default_reset_instr_callback(void)
  20.383 +{
  20.384 +}
  20.385 +
  20.386 +/* Called when the program counter changed by a large value */
  20.387 +static unsigned int default_pc_changed_callback_data;
  20.388 +static void default_pc_changed_callback(unsigned int new_pc)
  20.389 +{
  20.390 +	default_pc_changed_callback_data = new_pc;
  20.391 +}
  20.392 +
  20.393 +/* Called every time there's bus activity (read/write to/from memory */
  20.394 +static unsigned int default_set_fc_callback_data;
  20.395 +static void default_set_fc_callback(unsigned int new_fc)
  20.396 +{
  20.397 +	default_set_fc_callback_data = new_fc;
  20.398 +}
  20.399 +
  20.400 +/* Called every instruction cycle prior to execution */
  20.401 +static void default_instr_hook_callback(void)
  20.402 +{
  20.403 +}
  20.404 +
  20.405 +
  20.406 +
  20.407 +/* ======================================================================== */
  20.408 +/* ================================= API ================================== */
  20.409 +/* ======================================================================== */
  20.410 +
  20.411 +/* Access the internals of the CPU */
  20.412 +unsigned int m68k_get_reg(void* context, m68k_register_t regnum)
  20.413 +{
  20.414 +	m68ki_cpu_core* cpu = context != NULL ?(m68ki_cpu_core*)context : &m68ki_cpu;
  20.415 +
  20.416 +	switch(regnum)
  20.417 +	{
  20.418 +		case M68K_REG_D0:	return cpu->dar[0];
  20.419 +		case M68K_REG_D1:	return cpu->dar[1];
  20.420 +		case M68K_REG_D2:	return cpu->dar[2];
  20.421 +		case M68K_REG_D3:	return cpu->dar[3];
  20.422 +		case M68K_REG_D4:	return cpu->dar[4];
  20.423 +		case M68K_REG_D5:	return cpu->dar[5];
  20.424 +		case M68K_REG_D6:	return cpu->dar[6];
  20.425 +		case M68K_REG_D7:	return cpu->dar[7];
  20.426 +		case M68K_REG_A0:	return cpu->dar[8];
  20.427 +		case M68K_REG_A1:	return cpu->dar[9];
  20.428 +		case M68K_REG_A2:	return cpu->dar[10];
  20.429 +		case M68K_REG_A3:	return cpu->dar[11];
  20.430 +		case M68K_REG_A4:	return cpu->dar[12];
  20.431 +		case M68K_REG_A5:	return cpu->dar[13];
  20.432 +		case M68K_REG_A6:	return cpu->dar[14];
  20.433 +		case M68K_REG_A7:	return cpu->dar[15];
  20.434 +		case M68K_REG_PC:	return MASK_OUT_ABOVE_32(cpu->pc);
  20.435 +		case M68K_REG_SR:	return	cpu->t1_flag						|
  20.436 +									cpu->t0_flag						|
  20.437 +									(cpu->s_flag << 11)					|
  20.438 +									(cpu->m_flag << 11)					|
  20.439 +									cpu->int_mask						|
  20.440 +									((cpu->x_flag & XFLAG_SET) >> 4)	|
  20.441 +									((cpu->n_flag & NFLAG_SET) >> 4)	|
  20.442 +									((!cpu->not_z_flag) << 2)			|
  20.443 +									((cpu->v_flag & VFLAG_SET) >> 6)	|
  20.444 +									((cpu->c_flag & CFLAG_SET) >> 8);
  20.445 +		case M68K_REG_SP:	return cpu->dar[15];
  20.446 +		case M68K_REG_USP:	return cpu->s_flag ? cpu->sp[0] : cpu->dar[15];
  20.447 +		case M68K_REG_ISP:	return cpu->s_flag && !cpu->m_flag ? cpu->dar[15] : cpu->sp[4];
  20.448 +		case M68K_REG_MSP:	return cpu->s_flag && cpu->m_flag ? cpu->dar[15] : cpu->sp[6];
  20.449 +		case M68K_REG_SFC:	return cpu->sfc;
  20.450 +		case M68K_REG_DFC:	return cpu->dfc;
  20.451 +		case M68K_REG_VBR:	return cpu->vbr;
  20.452 +		case M68K_REG_CACR:	return cpu->cacr;
  20.453 +		case M68K_REG_CAAR:	return cpu->caar;
  20.454 +		case M68K_REG_PREF_ADDR:	return cpu->pref_addr;
  20.455 +		case M68K_REG_PREF_DATA:	return cpu->pref_data;
  20.456 +		case M68K_REG_PPC:	return MASK_OUT_ABOVE_32(cpu->ppc);
  20.457 +		case M68K_REG_IR:	return cpu->ir;
  20.458 +		case M68K_REG_CPU_TYPE:
  20.459 +			switch(cpu->cpu_type)
  20.460 +			{
  20.461 +				case CPU_TYPE_000:		return (unsigned int)M68K_CPU_TYPE_68000;
  20.462 +				case CPU_TYPE_010:		return (unsigned int)M68K_CPU_TYPE_68010;
  20.463 +				case CPU_TYPE_EC020:	return (unsigned int)M68K_CPU_TYPE_68EC020;
  20.464 +				case CPU_TYPE_020:		return (unsigned int)M68K_CPU_TYPE_68020;
  20.465 +			}
  20.466 +			return M68K_CPU_TYPE_INVALID;
  20.467 +		default:			return 0;
  20.468 +	}
  20.469 +	return 0;
  20.470 +}
  20.471 +
  20.472 +void m68k_set_reg(m68k_register_t regnum, unsigned int value)
  20.473 +{
  20.474 +	switch(regnum)
  20.475 +	{
  20.476 +		case M68K_REG_D0:	REG_D[0] = MASK_OUT_ABOVE_32(value); return;
  20.477 +		case M68K_REG_D1:	REG_D[1] = MASK_OUT_ABOVE_32(value); return;
  20.478 +		case M68K_REG_D2:	REG_D[2] = MASK_OUT_ABOVE_32(value); return;
  20.479 +		case M68K_REG_D3:	REG_D[3] = MASK_OUT_ABOVE_32(value); return;
  20.480 +		case M68K_REG_D4:	REG_D[4] = MASK_OUT_ABOVE_32(value); return;
  20.481 +		case M68K_REG_D5:	REG_D[5] = MASK_OUT_ABOVE_32(value); return;
  20.482 +		case M68K_REG_D6:	REG_D[6] = MASK_OUT_ABOVE_32(value); return;
  20.483 +		case M68K_REG_D7:	REG_D[7] = MASK_OUT_ABOVE_32(value); return;
  20.484 +		case M68K_REG_A0:	REG_A[0] = MASK_OUT_ABOVE_32(value); return;
  20.485 +		case M68K_REG_A1:	REG_A[1] = MASK_OUT_ABOVE_32(value); return;
  20.486 +		case M68K_REG_A2:	REG_A[2] = MASK_OUT_ABOVE_32(value); return;
  20.487 +		case M68K_REG_A3:	REG_A[3] = MASK_OUT_ABOVE_32(value); return;
  20.488 +		case M68K_REG_A4:	REG_A[4] = MASK_OUT_ABOVE_32(value); return;
  20.489 +		case M68K_REG_A5:	REG_A[5] = MASK_OUT_ABOVE_32(value); return;
  20.490 +		case M68K_REG_A6:	REG_A[6] = MASK_OUT_ABOVE_32(value); return;
  20.491 +		case M68K_REG_A7:	REG_A[7] = MASK_OUT_ABOVE_32(value); return;
  20.492 +		case M68K_REG_PC:	m68ki_jump(MASK_OUT_ABOVE_32(value)); return;
  20.493 +		case M68K_REG_SR:	m68ki_set_sr(value); return;
  20.494 +		case M68K_REG_SP:	REG_SP = MASK_OUT_ABOVE_32(value); return;
  20.495 +		case M68K_REG_USP:	if(FLAG_S)
  20.496 +								REG_USP = MASK_OUT_ABOVE_32(value);
  20.497 +							else
  20.498 +								REG_SP = MASK_OUT_ABOVE_32(value);
  20.499 +							return;
  20.500 +		case M68K_REG_ISP:	if(FLAG_S && !FLAG_M)
  20.501 +								REG_SP = MASK_OUT_ABOVE_32(value);
  20.502 +							else
  20.503 +								REG_ISP = MASK_OUT_ABOVE_32(value);
  20.504 +							return;
  20.505 +		case M68K_REG_MSP:	if(FLAG_S && FLAG_M)
  20.506 +								REG_SP = MASK_OUT_ABOVE_32(value);
  20.507 +							else
  20.508 +								REG_MSP = MASK_OUT_ABOVE_32(value);
  20.509 +							return;
  20.510 +		case M68K_REG_VBR:	REG_VBR = MASK_OUT_ABOVE_32(value); return;
  20.511 +		case M68K_REG_SFC:	REG_SFC = value & 7; return;
  20.512 +		case M68K_REG_DFC:	REG_DFC = value & 7; return;
  20.513 +		case M68K_REG_CACR:	REG_CACR = MASK_OUT_ABOVE_32(value); return;
  20.514 +		case M68K_REG_CAAR:	REG_CAAR = MASK_OUT_ABOVE_32(value); return;
  20.515 +		case M68K_REG_PPC:	REG_PPC = MASK_OUT_ABOVE_32(value); return;
  20.516 +		case M68K_REG_IR:	REG_IR = MASK_OUT_ABOVE_16(value); return;
  20.517 +		case M68K_REG_CPU_TYPE: m68k_set_cpu_type(value); return;
  20.518 +		default:			return;
  20.519 +	}
  20.520 +}
  20.521 +
  20.522 +/* Set the callbacks */
  20.523 +void m68k_set_int_ack_callback(int  (*callback)(int int_level))
  20.524 +{
  20.525 +	CALLBACK_INT_ACK = callback ? callback : default_int_ack_callback;
  20.526 +}
  20.527 +
  20.528 +void m68k_set_bkpt_ack_callback(void  (*callback)(unsigned int data))
  20.529 +{
  20.530 +	CALLBACK_BKPT_ACK = callback ? callback : default_bkpt_ack_callback;
  20.531 +}
  20.532 +
  20.533 +void m68k_set_reset_instr_callback(void  (*callback)(void))
  20.534 +{
  20.535 +	CALLBACK_RESET_INSTR = callback ? callback : default_reset_instr_callback;
  20.536 +}
  20.537 +
  20.538 +void m68k_set_pc_changed_callback(void  (*callback)(unsigned int new_pc))
  20.539 +{
  20.540 +	CALLBACK_PC_CHANGED = callback ? callback : default_pc_changed_callback;
  20.541 +}
  20.542 +
  20.543 +void m68k_set_fc_callback(void  (*callback)(unsigned int new_fc))
  20.544 +{
  20.545 +	CALLBACK_SET_FC = callback ? callback : default_set_fc_callback;
  20.546 +}
  20.547 +
  20.548 +void m68k_set_instr_hook_callback(void  (*callback)(void))
  20.549 +{
  20.550 +	CALLBACK_INSTR_HOOK = callback ? callback : default_instr_hook_callback;
  20.551 +}
  20.552 +
  20.553 +#include <stdio.h>
  20.554 +/* Set the CPU type. */
  20.555 +void m68k_set_cpu_type(unsigned int cpu_type)
  20.556 +{
  20.557 +	switch(cpu_type)
  20.558 +	{
  20.559 +		case M68K_CPU_TYPE_68000:
  20.560 +			CPU_TYPE         = CPU_TYPE_000;
  20.561 +			CPU_ADDRESS_MASK = 0x00ffffff;
  20.562 +			CPU_SR_MASK      = 0xa71f; /* T1 -- S  -- -- I2 I1 I0 -- -- -- X  N  Z  V  C  */
  20.563 +			CYC_INSTRUCTION  = m68ki_cycles[0];
  20.564 +			CYC_EXCEPTION    = m68ki_exception_cycle_table[0];
  20.565 +			CYC_BCC_NOTAKE_B = -2;
  20.566 +			CYC_BCC_NOTAKE_W = 2;
  20.567 +			CYC_DBCC_F_NOEXP = -2;
  20.568 +			CYC_DBCC_F_EXP   = 2;
  20.569 +			CYC_SCC_R_FALSE  = 2;
  20.570 +			CYC_MOVEM_W      = 2;
  20.571 +			CYC_MOVEM_L      = 3;
  20.572 +			CYC_SHIFT        = 1;
  20.573 +			CYC_RESET        = 132;
  20.574 +			return;
  20.575 +		case M68K_CPU_TYPE_68010:
  20.576 +			CPU_TYPE         = CPU_TYPE_010;
  20.577 +			CPU_ADDRESS_MASK = 0x00ffffff;
  20.578 +			CPU_SR_MASK      = 0xa71f; /* T1 -- S  -- -- I2 I1 I0 -- -- -- X  N  Z  V  C  */
  20.579 +			CYC_INSTRUCTION  = m68ki_cycles[1];
  20.580 +			CYC_EXCEPTION    = m68ki_exception_cycle_table[1];
  20.581 +			CYC_BCC_NOTAKE_B = -4;
  20.582 +			CYC_BCC_NOTAKE_W = 0;
  20.583 +			CYC_DBCC_F_NOEXP = 0;
  20.584 +			CYC_DBCC_F_EXP   = 6;
  20.585 +			CYC_SCC_R_FALSE  = 0;
  20.586 +			CYC_MOVEM_W      = 2;
  20.587 +			CYC_MOVEM_L      = 3;
  20.588 +			CYC_SHIFT        = 1;
  20.589 +			CYC_RESET        = 130;
  20.590 +			return;
  20.591 +		case M68K_CPU_TYPE_68EC020:
  20.592 +			CPU_TYPE         = CPU_TYPE_EC020;
  20.593 +			CPU_ADDRESS_MASK = 0x00ffffff;
  20.594 +			CPU_SR_MASK      = 0xf71f; /* T1 T0 S  M  -- I2 I1 I0 -- -- -- X  N  Z  V  C  */
  20.595 +			CYC_INSTRUCTION  = m68ki_cycles[2];
  20.596 +			CYC_EXCEPTION    = m68ki_exception_cycle_table[2];
  20.597 +			CYC_BCC_NOTAKE_B = -2;
  20.598 +			CYC_BCC_NOTAKE_W = 0;
  20.599 +			CYC_DBCC_F_NOEXP = 0;
  20.600 +			CYC_DBCC_F_EXP   = 4;
  20.601 +			CYC_SCC_R_FALSE  = 0;
  20.602 +			CYC_MOVEM_W      = 2;
  20.603 +			CYC_MOVEM_L      = 2; 
  20.604 +			CYC_SHIFT        = 0;
  20.605 +			CYC_RESET        = 518;
  20.606 +			return;
  20.607 +		case M68K_CPU_TYPE_68020:
  20.608 +			CPU_TYPE         = CPU_TYPE_020;
  20.609 +			CPU_ADDRESS_MASK = 0xffffffff;
  20.610 +			CPU_SR_MASK      = 0xf71f; /* T1 T0 S  M  -- I2 I1 I0 -- -- -- X  N  Z  V  C  */
  20.611 +			CYC_INSTRUCTION  = m68ki_cycles[2];
  20.612 +			CYC_EXCEPTION    = m68ki_exception_cycle_table[2];
  20.613 +			CYC_BCC_NOTAKE_B = -2;
  20.614 +			CYC_BCC_NOTAKE_W = 0;
  20.615 +			CYC_DBCC_F_NOEXP = 0;
  20.616 +			CYC_DBCC_F_EXP   = 4;
  20.617 +			CYC_SCC_R_FALSE  = 0;
  20.618 +			CYC_MOVEM_W      = 2;
  20.619 +			CYC_MOVEM_L      = 2;
  20.620 +			CYC_SHIFT        = 0;
  20.621 +			CYC_RESET        = 518;
  20.622 +			return;
  20.623 +	}
  20.624 +}
  20.625 +
  20.626 +/* Execute some instructions until we use up num_cycles clock cycles */
  20.627 +/* ASG: removed per-instruction interrupt checks */
  20.628 +int m68k_execute(int num_cycles)
  20.629 +{
  20.630 +	/* Make sure we're not stopped */
  20.631 +	if(!CPU_STOPPED)
  20.632 +	{
  20.633 +		/* Set our pool of clock cycles available */
  20.634 +		SET_CYCLES(num_cycles);
  20.635 +		m68ki_initial_cycles = num_cycles;
  20.636 +
  20.637 +		/* ASG: update cycles */
  20.638 +		USE_CYCLES(CPU_INT_CYCLES);
  20.639 +		CPU_INT_CYCLES = 0;
  20.640 +
  20.641 +		/* Return point if we had an address error */
  20.642 +		m68ki_set_address_error_trap(); /* auto-disable (see m68kcpu.h) */
  20.643 +
  20.644 +		/* Main loop.  Keep going until we run out of clock cycles */
  20.645 +		do
  20.646 +		{
  20.647 +			/* Set tracing accodring to T1. (T0 is done inside instruction) */
  20.648 +			m68ki_trace_t1(); /* auto-disable (see m68kcpu.h) */
  20.649 +
  20.650 +			/* Set the address space for reads */
  20.651 +			m68ki_use_data_space(); /* auto-disable (see m68kcpu.h) */
  20.652 +
  20.653 +			/* Call external hook to peek at CPU */
  20.654 +			m68ki_instr_hook(); /* auto-disable (see m68kcpu.h) */
  20.655 +
  20.656 +			/* Record previous program counter */
  20.657 +			REG_PPC = REG_PC;
  20.658 +
  20.659 +			/* Read an instruction and call its handler */
  20.660 +			REG_IR = m68ki_read_imm_16();
  20.661 +			m68ki_instruction_jump_table[REG_IR]();
  20.662 +			USE_CYCLES(CYC_INSTRUCTION[REG_IR]);
  20.663 +
  20.664 +			/* Trace m68k_exception, if necessary */
  20.665 +			m68ki_exception_if_trace(); /* auto-disable (see m68kcpu.h) */
  20.666 +		} while(GET_CYCLES() > 0);
  20.667 +
  20.668 +		/* set previous PC to current PC for the next entry into the loop */
  20.669 +		REG_PPC = REG_PC;
  20.670 +
  20.671 +		/* ASG: update cycles */
  20.672 +		USE_CYCLES(CPU_INT_CYCLES);
  20.673 +		CPU_INT_CYCLES = 0;
  20.674 +
  20.675 +		/* return how many clocks we used */
  20.676 +		return m68ki_initial_cycles - GET_CYCLES();
  20.677 +	}
  20.678 +
  20.679 +	/* We get here if the CPU is stopped or halted */
  20.680 +	SET_CYCLES(0);
  20.681 +	CPU_INT_CYCLES = 0;
  20.682 +
  20.683 +	return num_cycles;
  20.684 +}
  20.685 +
  20.686 +
  20.687 +int m68k_cycles_run(void)
  20.688 +{
  20.689 +	return m68ki_initial_cycles - GET_CYCLES();
  20.690 +}
  20.691 +
  20.692 +int m68k_cycles_remaining(void)
  20.693 +{
  20.694 +	return GET_CYCLES();
  20.695 +}
  20.696 +
  20.697 +/* Change the timeslice */
  20.698 +void m68k_modify_timeslice(int cycles)
  20.699 +{
  20.700 +	m68ki_initial_cycles += cycles;
  20.701 +	ADD_CYCLES(cycles);
  20.702 +}
  20.703 +
  20.704 +
  20.705 +void m68k_end_timeslice(void)
  20.706 +{
  20.707 +	m68ki_initial_cycles = GET_CYCLES();
  20.708 +	SET_CYCLES(0);
  20.709 +}
  20.710 +
  20.711 +
  20.712 +/* ASG: rewrote so that the int_level is a mask of the IPL0/IPL1/IPL2 bits */
  20.713 +/* KS: Modified so that IPL* bits match with mask positions in the SR
  20.714 + *     and cleaned out remenants of the interrupt controller.
  20.715 + */
  20.716 +void m68k_set_irq(unsigned int int_level)
  20.717 +{
  20.718 +	uint old_level = CPU_INT_LEVEL;
  20.719 +	CPU_INT_LEVEL = int_level << 8;
  20.720 +
  20.721 +	/* A transition from < 7 to 7 always interrupts (NMI) */
  20.722 +	/* Note: Level 7 can also level trigger like a normal IRQ */
  20.723 +	if(old_level != 0x0700 && CPU_INT_LEVEL == 0x0700)
  20.724 +		m68ki_exception_interrupt(7); /* Edge triggered level 7 (NMI) */
  20.725 +	else
  20.726 +		m68ki_check_interrupts(); /* Level triggered (IRQ) */
  20.727 +}
  20.728 +
  20.729 +
  20.730 +/* Pulse the RESET line on the CPU */
  20.731 +void m68k_pulse_reset(void)
  20.732 +{
  20.733 +	static uint emulation_initialized = 0;
  20.734 +
  20.735 +	/* The first call to this function initializes the opcode handler jump table */
  20.736 +	if(!emulation_initialized)
  20.737 +	{
  20.738 +		m68ki_build_opcode_table();
  20.739 +		m68k_set_int_ack_callback(NULL);
  20.740 +		m68k_set_bkpt_ack_callback(NULL);
  20.741 +		m68k_set_reset_instr_callback(NULL);
  20.742 +		m68k_set_pc_changed_callback(NULL);
  20.743 +		m68k_set_fc_callback(NULL);
  20.744 +		m68k_set_instr_hook_callback(NULL);
  20.745 +
  20.746 +		emulation_initialized = 1;
  20.747 +	}
  20.748 +
  20.749 +
  20.750 +	if(CPU_TYPE == 0)	/* KW 990319 */
  20.751 +		m68k_set_cpu_type(M68K_CPU_TYPE_68000);
  20.752 +
  20.753 +	/* Clear all stop levels and eat up all remaining cycles */
  20.754 +	CPU_STOPPED = 0;
  20.755 +	SET_CYCLES(0);
  20.756 +
  20.757 +	/* Turn off tracing */
  20.758 +	FLAG_T1 = FLAG_T0 = 0;
  20.759 +	m68ki_clear_trace();
  20.760 +	/* Interrupt mask to level 7 */
  20.761 +	FLAG_INT_MASK = 0x0700;
  20.762 +	/* Reset VBR */
  20.763 +	REG_VBR = 0;
  20.764 +	/* Go to supervisor mode */
  20.765 +	m68ki_set_sm_flag(SFLAG_SET | MFLAG_CLEAR);
  20.766 +
  20.767 +	/* Invalidate the prefetch queue */
  20.768 +#if M68K_EMULATE_PREFETCH
  20.769 +	/* Set to arbitrary number since our first fetch is from 0 */
  20.770 +	CPU_PREF_ADDR = 0x1000;
  20.771 +#endif /* M68K_EMULATE_PREFETCH */
  20.772 +
  20.773 +	/* Read the initial stack pointer and program counter */
  20.774 +	m68ki_jump(0);
  20.775 +	REG_SP = m68ki_read_imm_32();
  20.776 +	REG_PC = m68ki_read_imm_32();
  20.777 +	m68ki_jump(REG_PC);
  20.778 +}
  20.779 +
  20.780 +/* Pulse the HALT line on the CPU */
  20.781 +void m68k_pulse_halt(void)
  20.782 +{
  20.783 +	CPU_STOPPED |= STOP_LEVEL_HALT;
  20.784 +}
  20.785 +
  20.786 +
  20.787 +/* Get and set the current CPU context */
  20.788 +/* This is to allow for multiple CPUs */
  20.789 +unsigned int m68k_context_size()
  20.790 +{
  20.791 +	return sizeof(m68ki_cpu_core);
  20.792 +}
  20.793 +
  20.794 +unsigned int m68k_get_context(void* dst)
  20.795 +{
  20.796 +	if(dst) *(m68ki_cpu_core*)dst = m68ki_cpu;
  20.797 +	return sizeof(m68ki_cpu_core);
  20.798 +}
  20.799 +
  20.800 +void m68k_set_context(void* src)
  20.801 +{
  20.802 +	if(src) m68ki_cpu = *(m68ki_cpu_core*)src;
  20.803 +}
  20.804 +
  20.805 +void m68k_save_context(	void (*save_value)(char*, unsigned int))
  20.806 +{
  20.807 +	if(!save_value)
  20.808 +		return;
  20.809 +
  20.810 +	save_value("CPU_TYPE"  , m68k_get_reg(NULL, M68K_REG_CPU_TYPE));
  20.811 +	save_value("D0"        , REG_D[0]);
  20.812 +	save_value("D1"        , REG_D[1]);
  20.813 +	save_value("D2"        , REG_D[2]);
  20.814 +	save_value("D3"        , REG_D[3]);
  20.815 +	save_value("D4"        , REG_D[4]);
  20.816 +	save_value("D5"        , REG_D[5]);
  20.817 +	save_value("D6"        , REG_D[6]);
  20.818 +	save_value("D7"        , REG_D[7]);
  20.819 +	save_value("A0"        , REG_A[0]);
  20.820 +	save_value("A1"        , REG_A[1]);
  20.821 +	save_value("A2"        , REG_A[2]);
  20.822 +	save_value("A3"        , REG_A[3]);
  20.823 +	save_value("A4"        , REG_A[4]);
  20.824 +	save_value("A5"        , REG_A[5]);
  20.825 +	save_value("A6"        , REG_A[6]);
  20.826 +	save_value("A7"        , REG_A[7]);
  20.827 +	save_value("PPC"       , REG_PPC);
  20.828 +	save_value("PC"        , REG_PC);
  20.829 +	save_value("USP"       , REG_USP);
  20.830 +	save_value("ISP"       , REG_ISP);
  20.831 +	save_value("MSP"       , REG_MSP);
  20.832 +	save_value("VBR"       , REG_VBR);
  20.833 +	save_value("SFC"       , REG_SFC);
  20.834 +	save_value("DFC"       , REG_DFC);
  20.835 +	save_value("CACR"      , REG_CACR);
  20.836 +	save_value("CAAR"      , REG_CAAR);
  20.837 +	save_value("SR"        , m68ki_get_sr());
  20.838 +	save_value("INT_LEVEL" , CPU_INT_LEVEL);
  20.839 +	save_value("INT_CYCLES", CPU_INT_CYCLES);
  20.840 +	save_value("STOPPED"   , (CPU_STOPPED & STOP_LEVEL_STOP) != 0);
  20.841 +	save_value("HALTED"    , (CPU_STOPPED & STOP_LEVEL_HALT) != 0);
  20.842 +	save_value("PREF_ADDR" , CPU_PREF_ADDR);
  20.843 +	save_value("PREF_DATA" , CPU_PREF_DATA);
  20.844 +}
  20.845 +
  20.846 +void m68k_load_context(unsigned int (*load_value)(char*))
  20.847 +{
  20.848 +	unsigned int temp;
  20.849 +
  20.850 +	m68k_set_cpu_type(load_value("CPU_TYPE"));
  20.851 +	REG_PPC = load_value("PPC");
  20.852 +	REG_PC = load_value("PC");
  20.853 +	m68ki_jump(REG_PC);
  20.854 +	CPU_INT_LEVEL = 0;
  20.855 +	m68ki_set_sr_noint(load_value("SR"));
  20.856 +	REG_D[0]       = load_value("D0");
  20.857 +	REG_D[1]       = load_value("D1");
  20.858 +	REG_D[2]       = load_value("D2");
  20.859 +	REG_D[3]       = load_value("D3");
  20.860 +	REG_D[4]       = load_value("D4");
  20.861 +	REG_D[5]       = load_value("D5");
  20.862 +	REG_D[6]       = load_value("D6");
  20.863 +	REG_D[7]       = load_value("D7");
  20.864 +	REG_A[0]       = load_value("A0");
  20.865 +	REG_A[1]       = load_value("A1");
  20.866 +	REG_A[2]       = load_value("A2");
  20.867 +	REG_A[3]       = load_value("A3");
  20.868 +	REG_A[4]       = load_value("A4");
  20.869 +	REG_A[5]       = load_value("A5");
  20.870 +	REG_A[6]       = load_value("A6");
  20.871 +	REG_A[7]       = load_value("A7");
  20.872 +	REG_USP        = load_value("USP");
  20.873 +	REG_ISP        = load_value("ISP");
  20.874 +	REG_MSP        = load_value("MSP");
  20.875 +	REG_VBR        = load_value("VBR");
  20.876 +	REG_SFC        = load_value("SFC");
  20.877 +	REG_DFC        = load_value("DFC");
  20.878 +	REG_CACR       = load_value("CACR");
  20.879 +	REG_CAAR       = load_value("CAAR");
  20.880 +	CPU_INT_LEVEL  = load_value("INT_LEVEL");
  20.881 +	CPU_INT_CYCLES = load_value("INT_CYCLES");
  20.882 +
  20.883 +	CPU_STOPPED = 0;
  20.884 +	temp           = load_value("STOPPED");
  20.885 +	if(temp) CPU_STOPPED |= STOP_LEVEL_STOP;
  20.886 +	temp           = load_value("HALTED");
  20.887 +	if(temp) CPU_STOPPED |= STOP_LEVEL_HALT;
  20.888 +
  20.889 +	CPU_PREF_ADDR  = load_value("PREF_ADDR");
  20.890 +	CPU_PREF_DATA  = load_value("PREF_DATA");
  20.891 +}
  20.892 +
  20.893 +
  20.894 +
  20.895 +/* ======================================================================== */
  20.896 +/* ============================== END OF FILE ============================= */
  20.897 +/* ======================================================================== */
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/musashi/m68kcpu.h	Sat Nov 27 01:13:12 2010 +0000
    21.3 @@ -0,0 +1,1838 @@
    21.4 +#include <stdio.h>
    21.5 +/* ======================================================================== */
    21.6 +/* ========================= LICENSING & COPYRIGHT ======================== */
    21.7 +/* ======================================================================== */
    21.8 +/*
    21.9 + *                                  MUSASHI
   21.10 + *                                Version 3.3
   21.11 + *
   21.12 + * A portable Motorola M680x0 processor emulation engine.
   21.13 + * Copyright 1998-2001 Karl Stenerud.  All rights reserved.
   21.14 + *
   21.15 + * This code may be freely used for non-commercial purposes as long as this
   21.16 + * copyright notice remains unaltered in the source code and any binary files
   21.17 + * containing this code in compiled form.
   21.18 + *
   21.19 + * All other lisencing terms must be negotiated with the author
   21.20 + * (Karl Stenerud).
   21.21 + *
   21.22 + * The latest version of this code can be obtained at:
   21.23 + * http://kstenerud.cjb.net
   21.24 + */
   21.25 +
   21.26 +
   21.27 +
   21.28 +
   21.29 +#ifndef M68KCPU__HEADER
   21.30 +#define M68KCPU__HEADER
   21.31 +
   21.32 +#include "m68k.h"
   21.33 +#include <limits.h>
   21.34 +
   21.35 +#if M68K_EMULATE_ADDRESS_ERROR
   21.36 +#include <setjmp.h>
   21.37 +#endif /* M68K_EMULATE_ADDRESS_ERROR */
   21.38 +
   21.39 +/* ======================================================================== */
   21.40 +/* ==================== ARCHITECTURE-DEPENDANT DEFINES ==================== */
   21.41 +/* ======================================================================== */
   21.42 +
   21.43 +/* Check for > 32bit sizes */
   21.44 +#if UINT_MAX > 0xffffffff
   21.45 +	#define M68K_INT_GT_32_BIT  1
   21.46 +#endif
   21.47 +
   21.48 +/* Data types used in this emulation core */
   21.49 +#undef sint8
   21.50 +#undef sint16
   21.51 +#undef sint32
   21.52 +#undef sint64
   21.53 +#undef uint8
   21.54 +#undef uint16
   21.55 +#undef uint32
   21.56 +#undef uint64
   21.57 +#undef sint
   21.58 +#undef uint
   21.59 +
   21.60 +#define sint8  signed   char			/* ASG: changed from char to signed char */
   21.61 +#define sint16 signed   short
   21.62 +#define sint32 signed   long
   21.63 +#define uint8  unsigned char
   21.64 +#define uint16 unsigned short
   21.65 +#define uint32 unsigned long
   21.66 +
   21.67 +/* signed and unsigned int must be at least 32 bits wide */
   21.68 +#define sint   signed   int
   21.69 +#define uint   unsigned int
   21.70 +
   21.71 +
   21.72 +#if M68K_USE_64_BIT
   21.73 +#define sint64 signed   long long
   21.74 +#define uint64 unsigned long long
   21.75 +#else
   21.76 +#define sint64 sint32
   21.77 +#define uint64 uint32
   21.78 +#endif /* M68K_USE_64_BIT */
   21.79 +
   21.80 +
   21.81 +
   21.82 +/* Allow for architectures that don't have 8-bit sizes */
   21.83 +#if UCHAR_MAX == 0xff
   21.84 +	#define MAKE_INT_8(A) (sint8)(A)
   21.85 +#else
   21.86 +	#undef  sint8
   21.87 +	#define sint8  signed   int
   21.88 +	#undef  uint8
   21.89 +	#define uint8  unsigned int
   21.90 +	INLINE sint MAKE_INT_8(uint value)
   21.91 +	{
   21.92 +		return (value & 0x80) ? value | ~0xff : value & 0xff;
   21.93 +	}
   21.94 +#endif /* UCHAR_MAX == 0xff */
   21.95 +
   21.96 +
   21.97 +/* Allow for architectures that don't have 16-bit sizes */
   21.98 +#if USHRT_MAX == 0xffff
   21.99 +	#define MAKE_INT_16(A) (sint16)(A)
  21.100 +#else
  21.101 +	#undef  sint16
  21.102 +	#define sint16 signed   int
  21.103 +	#undef  uint16
  21.104 +	#define uint16 unsigned int
  21.105 +	INLINE sint MAKE_INT_16(uint value)
  21.106 +	{
  21.107 +		return (value & 0x8000) ? value | ~0xffff : value & 0xffff;
  21.108 +	}
  21.109 +#endif /* USHRT_MAX == 0xffff */
  21.110 +
  21.111 +
  21.112 +/* Allow for architectures that don't have 32-bit sizes */
  21.113 +#if ULONG_MAX == 0xffffffff
  21.114 +	#define MAKE_INT_32(A) (sint32)(A)
  21.115 +#else
  21.116 +	#undef  sint32
  21.117 +	#define sint32  signed   int
  21.118 +	#undef  uint32
  21.119 +	#define uint32  unsigned int
  21.120 +	INLINE sint MAKE_INT_32(uint value)
  21.121 +	{
  21.122 +		return (value & 0x80000000) ? value | ~0xffffffff : value & 0xffffffff;
  21.123 +	}
  21.124 +#endif /* ULONG_MAX == 0xffffffff */
  21.125 +
  21.126 +
  21.127 +
  21.128 +
  21.129 +/* ======================================================================== */
  21.130 +/* ============================ GENERAL DEFINES =========================== */
  21.131 +/* ======================================================================== */
  21.132 +
  21.133 +/* Exception Vectors handled by emulation */
  21.134 +#define EXCEPTION_BUS_ERROR                2 /* This one is not emulated! */
  21.135 +#define EXCEPTION_ADDRESS_ERROR            3 /* This one is partially emulated (doesn't stack a proper frame yet) */
  21.136 +#define EXCEPTION_ILLEGAL_INSTRUCTION      4
  21.137 +#define EXCEPTION_ZERO_DIVIDE              5
  21.138 +#define EXCEPTION_CHK                      6
  21.139 +#define EXCEPTION_TRAPV                    7
  21.140 +#define EXCEPTION_PRIVILEGE_VIOLATION      8
  21.141 +#define EXCEPTION_TRACE                    9
  21.142 +#define EXCEPTION_1010                    10
  21.143 +#define EXCEPTION_1111                    11
  21.144 +#define EXCEPTION_FORMAT_ERROR            14
  21.145 +#define EXCEPTION_UNINITIALIZED_INTERRUPT 15
  21.146 +#define EXCEPTION_SPURIOUS_INTERRUPT      24
  21.147 +#define EXCEPTION_INTERRUPT_AUTOVECTOR    24
  21.148 +#define EXCEPTION_TRAP_BASE               32
  21.149 +
  21.150 +/* Function codes set by CPU during data/address bus activity */
  21.151 +#define FUNCTION_CODE_USER_DATA          1
  21.152 +#define FUNCTION_CODE_USER_PROGRAM       2
  21.153 +#define FUNCTION_CODE_SUPERVISOR_DATA    5
  21.154 +#define FUNCTION_CODE_SUPERVISOR_PROGRAM 6
  21.155 +#define FUNCTION_CODE_CPU_SPACE          7
  21.156 +
  21.157 +/* CPU types for deciding what to emulate */
  21.158 +#define CPU_TYPE_000   1
  21.159 +#define CPU_TYPE_010   2
  21.160 +#define CPU_TYPE_EC020 4
  21.161 +#define CPU_TYPE_020   8
  21.162 +
  21.163 +/* Different ways to stop the CPU */
  21.164 +#define STOP_LEVEL_STOP 1
  21.165 +#define STOP_LEVEL_HALT 2
  21.166 +
  21.167 +#ifndef NULL
  21.168 +#define NULL ((void*)0)
  21.169 +#endif
  21.170 +
  21.171 +/* ======================================================================== */
  21.172 +/* ================================ MACROS ================================ */
  21.173 +/* ======================================================================== */
  21.174 +
  21.175 +
  21.176 +/* ---------------------------- General Macros ---------------------------- */
  21.177 +
  21.178 +/* Bit Isolation Macros */
  21.179 +#define BIT_0(A)  ((A) & 0x00000001)
  21.180 +#define BIT_1(A)  ((A) & 0x00000002)
  21.181 +#define BIT_2(A)  ((A) & 0x00000004)
  21.182 +#define BIT_3(A)  ((A) & 0x00000008)
  21.183 +#define BIT_4(A)  ((A) & 0x00000010)
  21.184 +#define BIT_5(A)  ((A) & 0x00000020)
  21.185 +#define BIT_6(A)  ((A) & 0x00000040)
  21.186 +#define BIT_7(A)  ((A) & 0x00000080)
  21.187 +#define BIT_8(A)  ((A) & 0x00000100)
  21.188 +#define BIT_9(A)  ((A) & 0x00000200)
  21.189 +#define BIT_A(A)  ((A) & 0x00000400)
  21.190 +#define BIT_B(A)  ((A) & 0x00000800)
  21.191 +#define BIT_C(A)  ((A) & 0x00001000)
  21.192 +#define BIT_D(A)  ((A) & 0x00002000)
  21.193 +#define BIT_E(A)  ((A) & 0x00004000)
  21.194 +#define BIT_F(A)  ((A) & 0x00008000)
  21.195 +#define BIT_10(A) ((A) & 0x00010000)
  21.196 +#define BIT_11(A) ((A) & 0x00020000)
  21.197 +#define BIT_12(A) ((A) & 0x00040000)
  21.198 +#define BIT_13(A) ((A) & 0x00080000)
  21.199 +#define BIT_14(A) ((A) & 0x00100000)
  21.200 +#define BIT_15(A) ((A) & 0x00200000)
  21.201 +#define BIT_16(A) ((A) & 0x00400000)
  21.202 +#define BIT_17(A) ((A) & 0x00800000)
  21.203 +#define BIT_18(A) ((A) & 0x01000000)
  21.204 +#define BIT_19(A) ((A) & 0x02000000)
  21.205 +#define BIT_1A(A) ((A) & 0x04000000)
  21.206 +#define BIT_1B(A) ((A) & 0x08000000)
  21.207 +#define BIT_1C(A) ((A) & 0x10000000)
  21.208 +#define BIT_1D(A) ((A) & 0x20000000)
  21.209 +#define BIT_1E(A) ((A) & 0x40000000)
  21.210 +#define BIT_1F(A) ((A) & 0x80000000)
  21.211 +
  21.212 +/* Get the most significant bit for specific sizes */
  21.213 +#define GET_MSB_8(A)  ((A) & 0x80)
  21.214 +#define GET_MSB_9(A)  ((A) & 0x100)
  21.215 +#define GET_MSB_16(A) ((A) & 0x8000)
  21.216 +#define GET_MSB_17(A) ((A) & 0x10000)
  21.217 +#define GET_MSB_32(A) ((A) & 0x80000000)
  21.218 +#if M68K_USE_64_BIT
  21.219 +#define GET_MSB_33(A) ((A) & 0x100000000)
  21.220 +#endif /* M68K_USE_64_BIT */
  21.221 +
  21.222 +/* Isolate nibbles */
  21.223 +#define LOW_NIBBLE(A)  ((A) & 0x0f)
  21.224 +#define HIGH_NIBBLE(A) ((A) & 0xf0)
  21.225 +
  21.226 +/* These are used to isolate 8, 16, and 32 bit sizes */
  21.227 +#define MASK_OUT_ABOVE_2(A)  ((A) & 3)
  21.228 +#define MASK_OUT_ABOVE_8(A)  ((A) & 0xff)
  21.229 +#define MASK_OUT_ABOVE_16(A) ((A) & 0xffff)
  21.230 +#define MASK_OUT_BELOW_2(A)  ((A) & ~3)
  21.231 +#define MASK_OUT_BELOW_8(A)  ((A) & ~0xff)
  21.232 +#define MASK_OUT_BELOW_16(A) ((A) & ~0xffff)
  21.233 +
  21.234 +/* No need to mask if we are 32 bit */
  21.235 +#if M68K_INT_GT_32BIT || M68K_USE_64_BIT
  21.236 +	#define MASK_OUT_ABOVE_32(A) ((A) & 0xffffffff)
  21.237 +	#define MASK_OUT_BELOW_32(A) ((A) & ~0xffffffff)
  21.238 +#else
  21.239 +	#define MASK_OUT_ABOVE_32(A) (A)
  21.240 +	#define MASK_OUT_BELOW_32(A) 0
  21.241 +#endif /* M68K_INT_GT_32BIT || M68K_USE_64_BIT */
  21.242 +
  21.243 +/* Simulate address lines of 68k family */
  21.244 +#define ADDRESS_68K(A) ((A)&CPU_ADDRESS_MASK)
  21.245 +
  21.246 +
  21.247 +/* Shift & Rotate Macros. */
  21.248 +#define LSL(A, C) ((A) << (C))
  21.249 +#define LSR(A, C) ((A) >> (C))
  21.250 +
  21.251 +/* Some > 32-bit optimizations */
  21.252 +#if M68K_INT_GT_32BIT
  21.253 +	/* Shift left and right */
  21.254 +	#define LSR_32(A, C) ((A) >> (C))
  21.255 +	#define LSL_32(A, C) ((A) << (C))
  21.256 +#else
  21.257 +	/* We have to do this because the morons at ANSI decided that shifts
  21.258 +	 * by >= data size are undefined.
  21.259 +	 */
  21.260 +	#define LSR_32(A, C) ((C) < 32 ? (A) >> (C) : 0)
  21.261 +	#define LSL_32(A, C) ((C) < 32 ? (A) << (C) : 0)
  21.262 +#endif /* M68K_INT_GT_32BIT */
  21.263 +
  21.264 +#if M68K_USE_64_BIT
  21.265 +	#define LSL_32_64(A, C) ((A) << (C))
  21.266 +	#define LSR_32_64(A, C) ((A) >> (C))
  21.267 +	#define ROL_33_64(A, C) (LSL_32_64(A, C) | LSR_32_64(A, 33-(C)))
  21.268 +	#define ROR_33_64(A, C) (LSR_32_64(A, C) | LSL_32_64(A, 33-(C)))
  21.269 +#endif /* M68K_USE_64_BIT */
  21.270 +
  21.271 +#define ROL_8(A, C)      MASK_OUT_ABOVE_8(LSL(A, C) | LSR(A, 8-(C)))
  21.272 +#define ROL_9(A, C)                      (LSL(A, C) | LSR(A, 9-(C)))
  21.273 +#define ROL_16(A, C)    MASK_OUT_ABOVE_16(LSL(A, C) | LSR(A, 16-(C)))
  21.274 +#define ROL_17(A, C)                     (LSL(A, C) | LSR(A, 17-(C)))
  21.275 +#define ROL_32(A, C)    MASK_OUT_ABOVE_32(LSL_32(A, C) | LSR_32(A, 32-(C)))
  21.276 +#define ROL_33(A, C)                     (LSL_32(A, C) | LSR_32(A, 33-(C)))
  21.277 +
  21.278 +#define ROR_8(A, C)      MASK_OUT_ABOVE_8(LSR(A, C) | LSL(A, 8-(C)))
  21.279 +#define ROR_9(A, C)                      (LSR(A, C) | LSL(A, 9-(C)))
  21.280 +#define ROR_16(A, C)    MASK_OUT_ABOVE_16(LSR(A, C) | LSL(A, 16-(C)))
  21.281 +#define ROR_17(A, C)                     (LSR(A, C) | LSL(A, 17-(C)))
  21.282 +#define ROR_32(A, C)    MASK_OUT_ABOVE_32(LSR_32(A, C) | LSL_32(A, 32-(C)))
  21.283 +#define ROR_33(A, C)                     (LSR_32(A, C) | LSL_32(A, 33-(C)))
  21.284 +
  21.285 +
  21.286 +
  21.287 +/* ------------------------------ CPU Access ------------------------------ */
  21.288 +
  21.289 +/* Access the CPU registers */
  21.290 +#define CPU_TYPE         m68ki_cpu.cpu_type
  21.291 +
  21.292 +#define REG_DA           m68ki_cpu.dar /* easy access to data and address regs */
  21.293 +#define REG_D            m68ki_cpu.dar
  21.294 +#define REG_A            (m68ki_cpu.dar+8)
  21.295 +#define REG_PPC 		 m68ki_cpu.ppc
  21.296 +#define REG_PC           m68ki_cpu.pc
  21.297 +#define REG_SP_BASE      m68ki_cpu.sp
  21.298 +#define REG_USP          m68ki_cpu.sp[0]
  21.299 +#define REG_ISP          m68ki_cpu.sp[4]
  21.300 +#define REG_MSP          m68ki_cpu.sp[6]
  21.301 +#define REG_SP           m68ki_cpu.dar[15]
  21.302 +#define REG_VBR          m68ki_cpu.vbr
  21.303 +#define REG_SFC          m68ki_cpu.sfc
  21.304 +#define REG_DFC          m68ki_cpu.dfc
  21.305 +#define REG_CACR         m68ki_cpu.cacr
  21.306 +#define REG_CAAR         m68ki_cpu.caar
  21.307 +#define REG_IR           m68ki_cpu.ir
  21.308 +
  21.309 +#define FLAG_T1          m68ki_cpu.t1_flag
  21.310 +#define FLAG_T0          m68ki_cpu.t0_flag
  21.311 +#define FLAG_S           m68ki_cpu.s_flag
  21.312 +#define FLAG_M           m68ki_cpu.m_flag
  21.313 +#define FLAG_X           m68ki_cpu.x_flag
  21.314 +#define FLAG_N           m68ki_cpu.n_flag
  21.315 +#define FLAG_Z           m68ki_cpu.not_z_flag
  21.316 +#define FLAG_V           m68ki_cpu.v_flag
  21.317 +#define FLAG_C           m68ki_cpu.c_flag
  21.318 +#define FLAG_INT_MASK    m68ki_cpu.int_mask
  21.319 +
  21.320 +#define CPU_INT_LEVEL    m68ki_cpu.int_level /* ASG: changed from CPU_INTS_PENDING */
  21.321 +#define CPU_INT_CYCLES   m68ki_cpu.int_cycles /* ASG */
  21.322 +#define CPU_STOPPED      m68ki_cpu.stopped
  21.323 +#define CPU_PREF_ADDR    m68ki_cpu.pref_addr
  21.324 +#define CPU_PREF_DATA    m68ki_cpu.pref_data
  21.325 +#define CPU_ADDRESS_MASK m68ki_cpu.address_mask
  21.326 +#define CPU_SR_MASK      m68ki_cpu.sr_mask
  21.327 +
  21.328 +#define CYC_INSTRUCTION  m68ki_cpu.cyc_instruction
  21.329 +#define CYC_EXCEPTION    m68ki_cpu.cyc_exception
  21.330 +#define CYC_BCC_NOTAKE_B m68ki_cpu.cyc_bcc_notake_b
  21.331 +#define CYC_BCC_NOTAKE_W m68ki_cpu.cyc_bcc_notake_w
  21.332 +#define CYC_DBCC_F_NOEXP m68ki_cpu.cyc_dbcc_f_noexp
  21.333 +#define CYC_DBCC_F_EXP   m68ki_cpu.cyc_dbcc_f_exp
  21.334 +#define CYC_SCC_R_FALSE  m68ki_cpu.cyc_scc_r_false
  21.335 +#define CYC_MOVEM_W      m68ki_cpu.cyc_movem_w
  21.336 +#define CYC_MOVEM_L      m68ki_cpu.cyc_movem_l
  21.337 +#define CYC_SHIFT        m68ki_cpu.cyc_shift
  21.338 +#define CYC_RESET        m68ki_cpu.cyc_reset
  21.339 +
  21.340 +
  21.341 +#define CALLBACK_INT_ACK     m68ki_cpu.int_ack_callback
  21.342 +#define CALLBACK_BKPT_ACK    m68ki_cpu.bkpt_ack_callback
  21.343 +#define CALLBACK_RESET_INSTR m68ki_cpu.reset_instr_callback
  21.344 +#define CALLBACK_PC_CHANGED  m68ki_cpu.pc_changed_callback
  21.345 +#define CALLBACK_SET_FC      m68ki_cpu.set_fc_callback
  21.346 +#define CALLBACK_INSTR_HOOK  m68ki_cpu.instr_hook_callback
  21.347 +
  21.348 +
  21.349 +
  21.350 +/* ----------------------------- Configuration ---------------------------- */
  21.351 +
  21.352 +/* These defines are dependant on the configuration defines in m68kconf.h */
  21.353 +
  21.354 +/* Disable certain comparisons if we're not using all CPU types */
  21.355 +#if M68K_EMULATE_020
  21.356 +	#define CPU_TYPE_IS_020_PLUS(A)    ((A) & CPU_TYPE_020)
  21.357 +	#define CPU_TYPE_IS_020_LESS(A)    1
  21.358 +#else
  21.359 +	#define CPU_TYPE_IS_020_PLUS(A)    0
  21.360 +	#define CPU_TYPE_IS_020_LESS(A)    1
  21.361 +#endif
  21.362 +
  21.363 +#if M68K_EMULATE_EC020
  21.364 +	#define CPU_TYPE_IS_EC020_PLUS(A)  ((A) & (CPU_TYPE_EC020 | CPU_TYPE_020))
  21.365 +	#define CPU_TYPE_IS_EC020_LESS(A)  ((A) & (CPU_TYPE_000 | CPU_TYPE_010 | CPU_TYPE_EC020))
  21.366 +#else
  21.367 +	#define CPU_TYPE_IS_EC020_PLUS(A)  CPU_TYPE_IS_020_PLUS(A)
  21.368 +	#define CPU_TYPE_IS_EC020_LESS(A)  CPU_TYPE_IS_020_LESS(A)
  21.369 +#endif
  21.370 +
  21.371 +#if M68K_EMULATE_010
  21.372 +	#define CPU_TYPE_IS_010(A)         ((A) == CPU_TYPE_010)
  21.373 +	#define CPU_TYPE_IS_010_PLUS(A)    ((A) & (CPU_TYPE_010 | CPU_TYPE_EC020 | CPU_TYPE_020))
  21.374 +	#define CPU_TYPE_IS_010_LESS(A)    ((A) & (CPU_TYPE_000 | CPU_TYPE_010))
  21.375 +#else
  21.376 +	#define CPU_TYPE_IS_010(A)         0
  21.377 +	#define CPU_TYPE_IS_010_PLUS(A)    CPU_TYPE_IS_EC020_PLUS(A)
  21.378 +	#define CPU_TYPE_IS_010_LESS(A)    CPU_TYPE_IS_EC020_LESS(A)
  21.379 +#endif
  21.380 +
  21.381 +#if M68K_EMULATE_020 || M68K_EMULATE_EC020
  21.382 +	#define CPU_TYPE_IS_020_VARIANT(A) ((A) & (CPU_TYPE_EC020 | CPU_TYPE_020))
  21.383 +#else
  21.384 +	#define CPU_TYPE_IS_020_VARIANT(A) 0
  21.385 +#endif
  21.386 +
  21.387 +#if M68K_EMULATE_020 || M68K_EMULATE_EC020 || M68K_EMULATE_010
  21.388 +	#define CPU_TYPE_IS_000(A)         ((A) == CPU_TYPE_000)
  21.389 +#else
  21.390 +	#define CPU_TYPE_IS_000(A)         1
  21.391 +#endif
  21.392 +
  21.393 +
  21.394 +#if !M68K_SEPARATE_READS
  21.395 +#define m68k_read_immediate_16(A) m68ki_read_program_16(A)
  21.396 +#define m68k_read_immediate_32(A) m68ki_read_program_32(A)
  21.397 +
  21.398 +#define m68k_read_pcrelative_8(A) m68ki_read_program_8(A)
  21.399 +#define m68k_read_pcrelative_16(A) m68ki_read_program_16(A)
  21.400 +#define m68k_read_pcrelative_32(A) m68ki_read_program_32(A)
  21.401 +#endif /* M68K_SEPARATE_READS */
  21.402 +
  21.403 +
  21.404 +/* Enable or disable callback functions */
  21.405 +#if M68K_EMULATE_INT_ACK
  21.406 +	#if M68K_EMULATE_INT_ACK == OPT_SPECIFY_HANDLER
  21.407 +		#define m68ki_int_ack(A) M68K_INT_ACK_CALLBACK(A)
  21.408 +	#else
  21.409 +		#define m68ki_int_ack(A) CALLBACK_INT_ACK(A)
  21.410 +	#endif
  21.411 +#else
  21.412 +	/* Default action is to used autovector mode, which is most common */
  21.413 +	#define m68ki_int_ack(A) M68K_INT_ACK_AUTOVECTOR
  21.414 +#endif /* M68K_EMULATE_INT_ACK */
  21.415 +
  21.416 +#if M68K_EMULATE_BKPT_ACK
  21.417 +	#if M68K_EMULATE_BKPT_ACK == OPT_SPECIFY_HANDLER
  21.418 +		#define m68ki_bkpt_ack(A) M68K_BKPT_ACK_CALLBACK(A)
  21.419 +	#else
  21.420 +		#define m68ki_bkpt_ack(A) CALLBACK_BKPT_ACK(A)
  21.421 +	#endif
  21.422 +#else
  21.423 +	#define m68ki_bkpt_ack(A)
  21.424 +#endif /* M68K_EMULATE_BKPT_ACK */
  21.425 +
  21.426 +#if M68K_EMULATE_RESET
  21.427 +	#if M68K_EMULATE_RESET == OPT_SPECIFY_HANDLER
  21.428 +		#define m68ki_output_reset() M68K_RESET_CALLBACK()
  21.429 +	#else
  21.430 +		#define m68ki_output_reset() CALLBACK_RESET_INSTR()
  21.431 +	#endif
  21.432 +#else
  21.433 +	#define m68ki_output_reset()
  21.434 +#endif /* M68K_EMULATE_RESET */
  21.435 +
  21.436 +#if M68K_INSTRUCTION_HOOK
  21.437 +	#if M68K_INSTRUCTION_HOOK == OPT_SPECIFY_HANDLER
  21.438 +		#define m68ki_instr_hook() M68K_INSTRUCTION_CALLBACK()
  21.439 +	#else
  21.440 +		#define m68ki_instr_hook() CALLBACK_INSTR_HOOK()
  21.441 +	#endif
  21.442 +#else
  21.443 +	#define m68ki_instr_hook()
  21.444 +#endif /* M68K_INSTRUCTION_HOOK */
  21.445 +
  21.446 +#if M68K_MONITOR_PC
  21.447 +	#if M68K_MONITOR_PC == OPT_SPECIFY_HANDLER
  21.448 +		#define m68ki_pc_changed(A) M68K_SET_PC_CALLBACK(ADDRESS_68K(A))
  21.449 +	#else
  21.450 +		#define m68ki_pc_changed(A) CALLBACK_PC_CHANGED(ADDRESS_68K(A))
  21.451 +	#endif
  21.452 +#else
  21.453 +	#define m68ki_pc_changed(A)
  21.454 +#endif /* M68K_MONITOR_PC */
  21.455 +
  21.456 +
  21.457 +/* Enable or disable function code emulation */
  21.458 +#if M68K_EMULATE_FC
  21.459 +	#if M68K_EMULATE_FC == OPT_SPECIFY_HANDLER
  21.460 +		#define m68ki_set_fc(A) M68K_SET_FC_CALLBACK(A)
  21.461 +	#else
  21.462 +		#define m68ki_set_fc(A) CALLBACK_SET_FC(A)
  21.463 +	#endif
  21.464 +	#define m68ki_use_data_space() m68ki_address_space = FUNCTION_CODE_USER_DATA
  21.465 +	#define m68ki_use_program_space() m68ki_address_space = FUNCTION_CODE_USER_PROGRAM
  21.466 +	#define m68ki_get_address_space() m68ki_address_space
  21.467 +#else
  21.468 +	#define m68ki_set_fc(A)
  21.469 +	#define m68ki_use_data_space()
  21.470 +	#define m68ki_use_program_space()
  21.471 +	#define m68ki_get_address_space() FUNCTION_CODE_USER_DATA
  21.472 +#endif /* M68K_EMULATE_FC */
  21.473 +
  21.474 +
  21.475 +/* Enable or disable trace emulation */
  21.476 +#if M68K_EMULATE_TRACE
  21.477 +	/* Initiates trace checking before each instruction (t1) */
  21.478 +	#define m68ki_trace_t1() m68ki_tracing = FLAG_T1
  21.479 +	/* adds t0 to trace checking if we encounter change of flow */
  21.480 +	#define m68ki_trace_t0() m68ki_tracing |= FLAG_T0
  21.481 +	/* Clear all tracing */
  21.482 +	#define m68ki_clear_trace() m68ki_tracing = 0
  21.483 +	/* Cause a trace exception if we are tracing */
  21.484 +	#define m68ki_exception_if_trace() if(m68ki_tracing) m68ki_exception_trace()
  21.485 +#else
  21.486 +	#define m68ki_trace_t1()
  21.487 +	#define m68ki_trace_t0()
  21.488 +	#define m68ki_clear_trace()
  21.489 +	#define m68ki_exception_if_trace()
  21.490 +#endif /* M68K_EMULATE_TRACE */
  21.491 +
  21.492 +
  21.493 +
  21.494 +/* Address error */
  21.495 +#if M68K_EMULATE_ADDRESS_ERROR
  21.496 +	extern jmp_buf m68ki_address_error_trap;
  21.497 +	#define m68ki_set_address_error_trap() if(setjmp(m68ki_address_error_trap)) m68ki_exception_address_error();
  21.498 +	#define m68ki_check_address_error(A) if((A)&1) longjmp(m68ki_address_error_jump, 1);
  21.499 +#else
  21.500 +	#define m68ki_set_address_error_trap()
  21.501 +	#define m68ki_check_address_error(A)
  21.502 +#endif /* M68K_ADDRESS_ERROR */
  21.503 +
  21.504 +/* Logging */
  21.505 +#if M68K_LOG_ENABLE
  21.506 +	#include <stdio.h>
  21.507 +	extern FILE* M68K_LOG_FILEHANDLE
  21.508 +	extern char* m68ki_cpu_names[];
  21.509 +
  21.510 +	#define M68K_DO_LOG(A) if(M68K_LOG_FILEHANDLE) fprintf A
  21.511 +	#if M68K_LOG_1010_1111
  21.512 +		#define M68K_DO_LOG_EMU(A) if(M68K_LOG_FILEHANDLE) fprintf A
  21.513 +	#else
  21.514 +		#define M68K_DO_LOG_EMU(A)
  21.515 +	#endif
  21.516 +#else
  21.517 +	#define M68K_DO_LOG(A)
  21.518 +	#define M68K_DO_LOG_EMU(A)
  21.519 +#endif
  21.520 +
  21.521 +
  21.522 +
  21.523 +/* -------------------------- EA / Operand Access ------------------------- */
  21.524 +
  21.525 +/*
  21.526 + * The general instruction format follows this pattern:
  21.527 + * .... XXX. .... .YYY
  21.528 + * where XXX is register X and YYY is register Y
  21.529 + */
  21.530 +/* Data Register Isolation */
  21.531 +#define DX (REG_D[(REG_IR >> 9) & 7])
  21.532 +#define DY (REG_D[REG_IR & 7])
  21.533 +/* Address Register Isolation */
  21.534 +#define AX (REG_A[(REG_IR >> 9) & 7])
  21.535 +#define AY (REG_A[REG_IR & 7])
  21.536 +
  21.537 +
  21.538 +/* Effective Address Calculations */
  21.539 +#define EA_AY_AI_8()   AY                                    /* address register indirect */
  21.540 +#define EA_AY_AI_16()  EA_AY_AI_8()
  21.541 +#define EA_AY_AI_32()  EA_AY_AI_8()
  21.542 +#define EA_AY_PI_8()   (AY++)                                /* postincrement (size = byte) */
  21.543 +#define EA_AY_PI_16()  ((AY+=2)-2)                           /* postincrement (size = word) */
  21.544 +#define EA_AY_PI_32()  ((AY+=4)-4)                           /* postincrement (size = long) */
  21.545 +#define EA_AY_PD_8()   (--AY)                                /* predecrement (size = byte) */
  21.546 +#define EA_AY_PD_16()  (AY-=2)                               /* predecrement (size = word) */
  21.547 +#define EA_AY_PD_32()  (AY-=4)                               /* predecrement (size = long) */
  21.548 +#define EA_AY_DI_8()   (AY+MAKE_INT_16(m68ki_read_imm_16())) /* displacement */
  21.549 +#define EA_AY_DI_16()  EA_AY_DI_8()
  21.550 +#define EA_AY_DI_32()  EA_AY_DI_8()
  21.551 +#define EA_AY_IX_8()   m68ki_get_ea_ix(AY)                   /* indirect + index */
  21.552 +#define EA_AY_IX_16()  EA_AY_IX_8()
  21.553 +#define EA_AY_IX_32()  EA_AY_IX_8()
  21.554 +
  21.555 +#define EA_AX_AI_8()   AX
  21.556 +#define EA_AX_AI_16()  EA_AX_AI_8()
  21.557 +#define EA_AX_AI_32()  EA_AX_AI_8()
  21.558 +#define EA_AX_PI_8()   (AX++)
  21.559 +#define EA_AX_PI_16()  ((AX+=2)-2)
  21.560 +#define EA_AX_PI_32()  ((AX+=4)-4)
  21.561 +#define EA_AX_PD_8()   (--AX)
  21.562 +#define EA_AX_PD_16()  (AX-=2)
  21.563 +#define EA_AX_PD_32()  (AX-=4)
  21.564 +#define EA_AX_DI_8()   (AX+MAKE_INT_16(m68ki_read_imm_16()))
  21.565 +#define EA_AX_DI_16()  EA_AX_DI_8()
  21.566 +#define EA_AX_DI_32()  EA_AX_DI_8()
  21.567 +#define EA_AX_IX_8()   m68ki_get_ea_ix(AX)
  21.568 +#define EA_AX_IX_16()  EA_AX_IX_8()
  21.569 +#define EA_AX_IX_32()  EA_AX_IX_8()
  21.570 +
  21.571 +#define EA_A7_PI_8()   ((REG_A[7]+=2)-2)
  21.572 +#define EA_A7_PD_8()   (REG_A[7]-=2)
  21.573 +
  21.574 +#define EA_AW_8()      MAKE_INT_16(m68ki_read_imm_16())      /* absolute word */
  21.575 +#define EA_AW_16()     EA_AW_8()
  21.576 +#define EA_AW_32()     EA_AW_8()
  21.577 +#define EA_AL_8()      m68ki_read_imm_32()                   /* absolute long */
  21.578 +#define EA_AL_16()     EA_AL_8()
  21.579 +#define EA_AL_32()     EA_AL_8()
  21.580 +#define EA_PCDI_8()    m68ki_get_ea_pcdi()                   /* pc indirect + displacement */
  21.581 +#define EA_PCDI_16()   EA_PCDI_8()
  21.582 +#define EA_PCDI_32()   EA_PCDI_8()
  21.583 +#define EA_PCIX_8()    m68ki_get_ea_pcix()                   /* pc indirect + index */
  21.584 +#define EA_PCIX_16()   EA_PCIX_8()
  21.585 +#define EA_PCIX_32()   EA_PCIX_8()
  21.586 +
  21.587 +
  21.588 +#define OPER_I_8()     m68ki_read_imm_8()
  21.589 +#define OPER_I_16()    m68ki_read_imm_16()
  21.590 +#define OPER_I_32()    m68ki_read_imm_32()
  21.591 +
  21.592 +
  21.593 +
  21.594 +/* --------------------------- Status Register ---------------------------- */
  21.595 +
  21.596 +/* Flag Calculation Macros */
  21.597 +#define CFLAG_8(A) (A)
  21.598 +#define CFLAG_16(A) ((A)>>8)
  21.599 +
  21.600 +#if M68K_INT_GT_32_BIT
  21.601 +	#define CFLAG_ADD_32(S, D, R) ((R)>>24)
  21.602 +	#define CFLAG_SUB_32(S, D, R) ((R)>>24)
  21.603 +#else
  21.604 +	#define CFLAG_ADD_32(S, D, R) (((S & D) | (~R & (S | D)))>>23)
  21.605 +	#define CFLAG_SUB_32(S, D, R) (((S & R) | (~D & (S | R)))>>23)
  21.606 +#endif /* M68K_INT_GT_32_BIT */
  21.607 +
  21.608 +#define VFLAG_ADD_8(S, D, R) ((S^R) & (D^R))
  21.609 +#define VFLAG_ADD_16(S, D, R) (((S^R) & (D^R))>>8)
  21.610 +#define VFLAG_ADD_32(S, D, R) (((S^R) & (D^R))>>24)
  21.611 +
  21.612 +#define VFLAG_SUB_8(S, D, R) ((S^D) & (R^D))
  21.613 +#define VFLAG_SUB_16(S, D, R) (((S^D) & (R^D))>>8)
  21.614 +#define VFLAG_SUB_32(S, D, R) (((S^D) & (R^D))>>24)
  21.615 +
  21.616 +#define NFLAG_8(A) (A)
  21.617 +#define NFLAG_16(A) ((A)>>8)
  21.618 +#define NFLAG_32(A) ((A)>>24)
  21.619 +#define NFLAG_64(A) ((A)>>56)
  21.620 +
  21.621 +#define ZFLAG_8(A) MASK_OUT_ABOVE_8(A)
  21.622 +#define ZFLAG_16(A) MASK_OUT_ABOVE_16(A)
  21.623 +#define ZFLAG_32(A) MASK_OUT_ABOVE_32(A)
  21.624 +
  21.625 +
  21.626 +/* Flag values */
  21.627 +#define NFLAG_SET   0x80
  21.628 +#define NFLAG_CLEAR 0
  21.629 +#define CFLAG_SET   0x100
  21.630 +#define CFLAG_CLEAR 0
  21.631 +#define XFLAG_SET   0x100
  21.632 +#define XFLAG_CLEAR 0
  21.633 +#define VFLAG_SET   0x80
  21.634 +#define VFLAG_CLEAR 0
  21.635 +#define ZFLAG_SET   0
  21.636 +#define ZFLAG_CLEAR 0xffffffff
  21.637 +
  21.638 +#define SFLAG_SET   4
  21.639 +#define SFLAG_CLEAR 0
  21.640 +#define MFLAG_SET   2
  21.641 +#define MFLAG_CLEAR 0
  21.642 +
  21.643 +/* Turn flag values into 1 or 0 */
  21.644 +#define XFLAG_AS_1() ((FLAG_X>>8)&1)
  21.645 +#define NFLAG_AS_1() ((FLAG_N>>7)&1)
  21.646 +#define VFLAG_AS_1() ((FLAG_V>>7)&1)
  21.647 +#define ZFLAG_AS_1() (!FLAG_Z)
  21.648 +#define CFLAG_AS_1() ((FLAG_C>>8)&1)
  21.649 +
  21.650 +
  21.651 +/* Conditions */
  21.652 +#define COND_CS() (FLAG_C&0x100)
  21.653 +#define COND_CC() (!COND_CS())
  21.654 +#define COND_VS() (FLAG_V&0x80)
  21.655 +#define COND_VC() (!COND_VS())
  21.656 +#define COND_NE() FLAG_Z
  21.657 +#define COND_EQ() (!COND_NE())
  21.658 +#define COND_MI() (FLAG_N&0x80)
  21.659 +#define COND_PL() (!COND_MI())
  21.660 +#define COND_LT() ((FLAG_N^FLAG_V)&0x80)
  21.661 +#define COND_GE() (!COND_LT())
  21.662 +#define COND_HI() (COND_CC() && COND_NE())
  21.663 +#define COND_LS() (COND_CS() || COND_EQ())
  21.664 +#define COND_GT() (COND_GE() && COND_NE())
  21.665 +#define COND_LE() (COND_LT() || COND_EQ())
  21.666 +
  21.667 +/* Reversed conditions */
  21.668 +#define COND_NOT_CS() COND_CC()
  21.669 +#define COND_NOT_CC() COND_CS()
  21.670 +#define COND_NOT_VS() COND_VC()
  21.671 +#define COND_NOT_VC() COND_VS()
  21.672 +#define COND_NOT_NE() COND_EQ()
  21.673 +#define COND_NOT_EQ() COND_NE()
  21.674 +#define COND_NOT_MI() COND_PL()
  21.675 +#define COND_NOT_PL() COND_MI()
  21.676 +#define COND_NOT_LT() COND_GE()
  21.677 +#define COND_NOT_GE() COND_LT()
  21.678 +#define COND_NOT_HI() COND_LS()
  21.679 +#define COND_NOT_LS() COND_HI()
  21.680 +#define COND_NOT_GT() COND_LE()
  21.681 +#define COND_NOT_LE() COND_GT()
  21.682 +
  21.683 +/* Not real conditions, but here for convenience */
  21.684 +#define COND_XS() (FLAG_X&0x100)
  21.685 +#define COND_XC() (!COND_XS)
  21.686 +
  21.687 +
  21.688 +/* Get the condition code register */
  21.689 +#define m68ki_get_ccr() ((COND_XS() >> 4) | \
  21.690 +						 (COND_MI() >> 4) | \
  21.691 +						 (COND_EQ() << 2) | \
  21.692 +						 (COND_VS() >> 6) | \
  21.693 +						 (COND_CS() >> 8))
  21.694 +
  21.695 +/* Get the status register */
  21.696 +#define m68ki_get_sr() ( FLAG_T1              | \
  21.697 +						 FLAG_T0              | \
  21.698 +						(FLAG_S        << 11) | \
  21.699 +						(FLAG_M        << 11) | \
  21.700 +						 FLAG_INT_MASK        | \
  21.701 +						 m68ki_get_ccr())
  21.702 +
  21.703 +
  21.704 +
  21.705 +/* ---------------------------- Cycle Counting ---------------------------- */
  21.706 +
  21.707 +#define ADD_CYCLES(A)    m68ki_remaining_cycles += (A)
  21.708 +#define USE_CYCLES(A)    m68ki_remaining_cycles -= (A)
  21.709 +#define SET_CYCLES(A)    m68ki_remaining_cycles = A
  21.710 +#define GET_CYCLES()     m68ki_remaining_cycles
  21.711 +#define USE_ALL_CYCLES() m68ki_remaining_cycles = 0
  21.712 +
  21.713 +
  21.714 +
  21.715 +/* ----------------------------- Read / Write ----------------------------- */
  21.716 +
  21.717 +/* Read from the current address space */
  21.718 +#define m68ki_read_8(A)  m68ki_read_8_fc (A, FLAG_S | m68ki_get_address_space())
  21.719 +#define m68ki_read_16(A) m68ki_read_16_fc(A, FLAG_S | m68ki_get_address_space())
  21.720 +#define m68ki_read_32(A) m68ki_read_32_fc(A, FLAG_S | m68ki_get_address_space())
  21.721 +
  21.722 +/* Write to the current data space */
  21.723 +#define m68ki_write_8(A, V)  m68ki_write_8_fc (A, FLAG_S | FUNCTION_CODE_USER_DATA, V)
  21.724 +#define m68ki_write_16(A, V) m68ki_write_16_fc(A, FLAG_S | FUNCTION_CODE_USER_DATA, V)
  21.725 +#define m68ki_write_32(A, V) m68ki_write_32_fc(A, FLAG_S | FUNCTION_CODE_USER_DATA, V)
  21.726 +
  21.727 +/* map read immediate 8 to read immediate 16 */
  21.728 +#define m68ki_read_imm_8() MASK_OUT_ABOVE_8(m68ki_read_imm_16())
  21.729 +
  21.730 +/* Map PC-relative reads */
  21.731 +#define m68ki_read_pcrel_8(A) m68k_read_pcrelative_8(A)
  21.732 +#define m68ki_read_pcrel_16(A) m68k_read_pcrelative_16(A)
  21.733 +#define m68ki_read_pcrel_32(A) m68k_read_pcrelative_32(A)
  21.734 +
  21.735 +/* Read from the program space */
  21.736 +#define m68ki_read_program_8(A) 	m68ki_read_8_fc(A, FLAG_S | FUNCTION_CODE_USER_PROGRAM)
  21.737 +#define m68ki_read_program_16(A) 	m68ki_read_16_fc(A, FLAG_S | FUNCTION_CODE_USER_PROGRAM)
  21.738 +#define m68ki_read_program_32(A) 	m68ki_read_32_fc(A, FLAG_S | FUNCTION_CODE_USER_PROGRAM)
  21.739 +
  21.740 +/* Read from the data space */
  21.741 +#define m68ki_read_data_8(A) 	m68ki_read_8_fc(A, FLAG_S | FUNCTION_CODE_USER_DATA)
  21.742 +#define m68ki_read_data_16(A) 	m68ki_read_16_fc(A, FLAG_S | FUNCTION_CODE_USER_DATA)
  21.743 +#define m68ki_read_data_32(A) 	m68ki_read_32_fc(A, FLAG_S | FUNCTION_CODE_USER_DATA)
  21.744 +
  21.745 +
  21.746 +
  21.747 +/* ======================================================================== */
  21.748 +/* =============================== PROTOTYPES ============================= */
  21.749 +/* ======================================================================== */
  21.750 +
  21.751 +typedef struct
  21.752 +{
  21.753 +	uint cpu_type;     /* CPU Type: 68000, 68010, 68EC020, or 68020 */
  21.754 +	uint dar[16];      /* Data and Address Registers */
  21.755 +	uint ppc;		   /* Previous program counter */
  21.756 +	uint pc;           /* Program Counter */
  21.757 +	uint sp[7];        /* User, Interrupt, and Master Stack Pointers */
  21.758 +	uint vbr;          /* Vector Base Register (m68010+) */
  21.759 +	uint sfc;          /* Source Function Code Register (m68010+) */
  21.760 +	uint dfc;          /* Destination Function Code Register (m68010+) */
  21.761 +	uint cacr;         /* Cache Control Register (m68020, unemulated) */
  21.762 +	uint caar;         /* Cache Address Register (m68020, unemulated) */
  21.763 +	uint ir;           /* Instruction Register */
  21.764 +	uint t1_flag;      /* Trace 1 */
  21.765 +	uint t0_flag;      /* Trace 0 */
  21.766 +	uint s_flag;       /* Supervisor */
  21.767 +	uint m_flag;       /* Master/Interrupt state */
  21.768 +	uint x_flag;       /* Extend */
  21.769 +	uint n_flag;       /* Negative */
  21.770 +	uint not_z_flag;   /* Zero, inverted for speedups */
  21.771 +	uint v_flag;       /* Overflow */
  21.772 +	uint c_flag;       /* Carry */
  21.773 +	uint int_mask;     /* I0-I2 */
  21.774 +	uint int_level;    /* State of interrupt pins IPL0-IPL2 -- ASG: changed from ints_pending */
  21.775 +	uint int_cycles;   /* ASG: extra cycles from generated interrupts */
  21.776 +	uint stopped;      /* Stopped state */
  21.777 +	uint pref_addr;    /* Last prefetch address */
  21.778 +	uint pref_data;    /* Data in the prefetch queue */
  21.779 +	uint address_mask; /* Available address pins */
  21.780 +	uint sr_mask;      /* Implemented status register bits */
  21.781 +
  21.782 +	/* Clocks required for instructions / exceptions */
  21.783 +	uint cyc_bcc_notake_b;
  21.784 +	uint cyc_bcc_notake_w;
  21.785 +	uint cyc_dbcc_f_noexp;
  21.786 +	uint cyc_dbcc_f_exp;
  21.787 +	uint cyc_scc_r_false;
  21.788 +	uint cyc_movem_w;
  21.789 +	uint cyc_movem_l;
  21.790 +	uint cyc_shift;
  21.791 +	uint cyc_reset;
  21.792 +	uint8* cyc_instruction;
  21.793 +	uint8* cyc_exception;
  21.794 +
  21.795 +	/* Callbacks to host */
  21.796 +	int  (*int_ack_callback)(int int_line);           /* Interrupt Acknowledge */
  21.797 +	void (*bkpt_ack_callback)(unsigned int data);     /* Breakpoint Acknowledge */
  21.798 +	void (*reset_instr_callback)(void);               /* Called when a RESET instruction is encountered */
  21.799 +	void (*pc_changed_callback)(unsigned int new_pc); /* Called when the PC changes by a large amount */
  21.800 +	void (*set_fc_callback)(unsigned int new_fc);     /* Called when the CPU function code changes */
  21.801 +	void (*instr_hook_callback)(void);                /* Called every instruction cycle prior to execution */
  21.802 +
  21.803 +} m68ki_cpu_core;
  21.804 +
  21.805 +
  21.806 +extern m68ki_cpu_core m68ki_cpu;
  21.807 +extern sint           m68ki_remaining_cycles;
  21.808 +extern uint           m68ki_tracing;
  21.809 +extern uint8          m68ki_shift_8_table[];
  21.810 +extern uint16         m68ki_shift_16_table[];
  21.811 +extern uint           m68ki_shift_32_table[];
  21.812 +extern uint8          m68ki_exception_cycle_table[][256];
  21.813 +extern uint           m68ki_address_space;
  21.814 +extern uint8          m68ki_ea_idx_cycle_table[];
  21.815 +
  21.816 +
  21.817 +/* Read data immediately after the program counter */
  21.818 +INLINE uint m68ki_read_imm_16(void);
  21.819 +INLINE uint m68ki_read_imm_32(void);
  21.820 +
  21.821 +/* Read data with specific function code */
  21.822 +INLINE uint m68ki_read_8_fc  (uint address, uint fc);
  21.823 +INLINE uint m68ki_read_16_fc (uint address, uint fc);
  21.824 +INLINE uint m68ki_read_32_fc (uint address, uint fc);
  21.825 +
  21.826 +/* Write data with specific function code */
  21.827 +INLINE void m68ki_write_8_fc (uint address, uint fc, uint value);
  21.828 +INLINE void m68ki_write_16_fc(uint address, uint fc, uint value);
  21.829 +INLINE void m68ki_write_32_fc(uint address, uint fc, uint value);
  21.830 +
  21.831 +/* Indexed and PC-relative ea fetching */
  21.832 +INLINE uint m68ki_get_ea_pcdi(void);
  21.833 +INLINE uint m68ki_get_ea_pcix(void);
  21.834 +INLINE uint m68ki_get_ea_ix(uint An);
  21.835 +
  21.836 +/* Operand fetching */
  21.837 +INLINE uint OPER_AY_AI_8(void);
  21.838 +INLINE uint OPER_AY_AI_16(void);
  21.839 +INLINE uint OPER_AY_AI_32(void);
  21.840 +INLINE uint OPER_AY_PI_8(void);
  21.841 +INLINE uint OPER_AY_PI_16(void);
  21.842 +INLINE uint OPER_AY_PI_32(void);
  21.843 +INLINE uint OPER_AY_PD_8(void);
  21.844 +INLINE uint OPER_AY_PD_16(void);
  21.845 +INLINE uint OPER_AY_PD_32(void);
  21.846 +INLINE uint OPER_AY_DI_8(void);
  21.847 +INLINE uint OPER_AY_DI_16(void);
  21.848 +INLINE uint OPER_AY_DI_32(void);
  21.849 +INLINE uint OPER_AY_IX_8(void);
  21.850 +INLINE uint OPER_AY_IX_16(void);
  21.851 +INLINE uint OPER_AY_IX_32(void);
  21.852 +
  21.853 +INLINE uint OPER_AX_AI_8(void);
  21.854 +INLINE uint OPER_AX_AI_16(void);
  21.855 +INLINE uint OPER_AX_AI_32(void);
  21.856 +INLINE uint OPER_AX_PI_8(void);
  21.857 +INLINE uint OPER_AX_PI_16(void);
  21.858 +INLINE uint OPER_AX_PI_32(void);
  21.859 +INLINE uint OPER_AX_PD_8(void);
  21.860 +INLINE uint OPER_AX_PD_16(void);
  21.861 +INLINE uint OPER_AX_PD_32(void);
  21.862 +INLINE uint OPER_AX_DI_8(void);
  21.863 +INLINE uint OPER_AX_DI_16(void);
  21.864 +INLINE uint OPER_AX_DI_32(void);
  21.865 +INLINE uint OPER_AX_IX_8(void);
  21.866 +INLINE uint OPER_AX_IX_16(void);
  21.867 +INLINE uint OPER_AX_IX_32(void);
  21.868 +
  21.869 +INLINE uint OPER_A7_PI_8(void);
  21.870 +INLINE uint OPER_A7_PD_8(void);
  21.871 +
  21.872 +INLINE uint OPER_AW_8(void);
  21.873 +INLINE uint OPER_AW_16(void);
  21.874 +INLINE uint OPER_AW_32(void);
  21.875 +INLINE uint OPER_AL_8(void);
  21.876 +INLINE uint OPER_AL_16(void);
  21.877 +INLINE uint OPER_AL_32(void);
  21.878 +INLINE uint OPER_PCDI_8(void);
  21.879 +INLINE uint OPER_PCDI_16(void);
  21.880 +INLINE uint OPER_PCDI_32(void);
  21.881 +INLINE uint OPER_PCIX_8(void);
  21.882 +INLINE uint OPER_PCIX_16(void);
  21.883 +INLINE uint OPER_PCIX_32(void);
  21.884 +
  21.885 +/* Stack operations */
  21.886 +INLINE void m68ki_push_16(uint value);
  21.887 +INLINE void m68ki_push_32(uint value);
  21.888 +INLINE uint m68ki_pull_16(void);
  21.889 +INLINE uint m68ki_pull_32(void);
  21.890 +
  21.891 +/* Program flow operations */
  21.892 +INLINE void m68ki_jump(uint new_pc);
  21.893 +INLINE void m68ki_jump_vector(uint vector);
  21.894 +INLINE void m68ki_branch_8(uint offset);
  21.895 +INLINE void m68ki_branch_16(uint offset);
  21.896 +INLINE void m68ki_branch_32(uint offset);
  21.897 +
  21.898 +/* Status register operations. */
  21.899 +INLINE void m68ki_set_s_flag(uint value);            /* Only bit 2 of value should be set (i.e. 4 or 0) */
  21.900 +INLINE void m68ki_set_sm_flag(uint value);           /* only bits 1 and 2 of value should be set */
  21.901 +INLINE void m68ki_set_ccr(uint value);               /* set the condition code register */
  21.902 +INLINE void m68ki_set_sr(uint value);                /* set the status register */
  21.903 +INLINE void m68ki_set_sr_noint(uint value);          /* set the status register */
  21.904 +
  21.905 +/* Exception processing */
  21.906 +INLINE uint m68ki_init_exception(void);              /* Initial exception processing */
  21.907 +
  21.908 +INLINE void m68ki_stack_frame_3word(uint pc, uint sr); /* Stack various frame types */
  21.909 +INLINE void m68ki_stack_frame_buserr(uint pc, uint sr, uint address, uint write, uint instruction, uint fc);
  21.910 +
  21.911 +INLINE void m68ki_stack_frame_0000(uint pc, uint sr, uint vector);
  21.912 +INLINE void m68ki_stack_frame_0001(uint pc, uint sr, uint vector);
  21.913 +INLINE void m68ki_stack_frame_0010(uint sr, uint vector);
  21.914 +INLINE void m68ki_stack_frame_1000(uint pc, uint sr, uint vector);
  21.915 +INLINE void m68ki_stack_frame_1010(uint sr, uint vector, uint pc);
  21.916 +INLINE void m68ki_stack_frame_1011(uint sr, uint vector, uint pc);
  21.917 +
  21.918 +INLINE void m68ki_exception_trap(uint vector);
  21.919 +INLINE void m68ki_exception_trapN(uint vector);
  21.920 +INLINE void m68ki_exception_trace(void);
  21.921 +INLINE void m68ki_exception_privilege_violation(void);
  21.922 +INLINE void m68ki_exception_1010(void);
  21.923 +INLINE void m68ki_exception_1111(void);
  21.924 +INLINE void m68ki_exception_illegal(void);
  21.925 +INLINE void m68ki_exception_format_error(void);
  21.926 +INLINE void m68ki_exception_address_error(void);
  21.927 +INLINE void m68ki_exception_interrupt(uint int_level);
  21.928 +INLINE void m68ki_check_interrupts(void);            /* ASG: check for interrupts */
  21.929 +
  21.930 +/* quick disassembly (used for logging) */
  21.931 +char* m68ki_disassemble_quick(unsigned int pc, unsigned int cpu_type);
  21.932 +
  21.933 +
  21.934 +/* ======================================================================== */
  21.935 +/* =========================== UTILITY FUNCTIONS ========================== */
  21.936 +/* ======================================================================== */
  21.937 +
  21.938 +
  21.939 +/* ---------------------------- Read Immediate ---------------------------- */
  21.940 +
  21.941 +/* Handles all immediate reads, does address error check, function code setting,
  21.942 + * and prefetching if they are enabled in m68kconf.h
  21.943 + */
  21.944 +INLINE uint m68ki_read_imm_16(void)
  21.945 +{
  21.946 +	m68ki_set_fc(FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */
  21.947 +	m68ki_check_address_error(REG_PC); /* auto-disable (see m68kcpu.h) */
  21.948 +#if M68K_EMULATE_PREFETCH
  21.949 +	if(MASK_OUT_BELOW_2(REG_PC) != CPU_PREF_ADDR)
  21.950 +	{
  21.951 +		CPU_PREF_ADDR = MASK_OUT_BELOW_2(REG_PC);
  21.952 +		CPU_PREF_DATA = m68k_read_immediate_32(ADDRESS_68K(CPU_PREF_ADDR));
  21.953 +	}
  21.954 +	REG_PC += 2;
  21.955 +	return MASK_OUT_ABOVE_16(CPU_PREF_DATA >> ((2-((REG_PC-2)&2))<<3));
  21.956 +#else
  21.957 +	REG_PC += 2;
  21.958 +	return m68k_read_immediate_16(ADDRESS_68K(REG_PC-2));
  21.959 +#endif /* M68K_EMULATE_PREFETCH */
  21.960 +}
  21.961 +INLINE uint m68ki_read_imm_32(void)
  21.962 +{
  21.963 +#if M68K_EMULATE_PREFETCH
  21.964 +	uint temp_val;
  21.965 +
  21.966 +	m68ki_set_fc(FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */
  21.967 +	m68ki_check_address_error(REG_PC); /* auto-disable (see m68kcpu.h) */
  21.968 +	if(MASK_OUT_BELOW_2(REG_PC) != CPU_PREF_ADDR)
  21.969 +	{
  21.970 +		CPU_PREF_ADDR = MASK_OUT_BELOW_2(REG_PC);
  21.971 +		CPU_PREF_DATA = m68k_read_immediate_32(ADDRESS_68K(CPU_PREF_ADDR));
  21.972 +	}
  21.973 +	temp_val = CPU_PREF_DATA;
  21.974 +	REG_PC += 2;
  21.975 +	if(MASK_OUT_BELOW_2(REG_PC) != CPU_PREF_ADDR)
  21.976 +	{
  21.977 +		CPU_PREF_ADDR = MASK_OUT_BELOW_2(REG_PC);
  21.978 +		CPU_PREF_DATA = m68k_read_immediate_32(ADDRESS_68K(CPU_PREF_ADDR));
  21.979 +		temp_val = MASK_OUT_ABOVE_32((temp_val << 16) | (CPU_PREF_DATA >> 16));
  21.980 +	}
  21.981 +	REG_PC += 2;
  21.982 +
  21.983 +	return temp_val;
  21.984 +#else
  21.985 +	m68ki_set_fc(FLAG_S | FUNCTION_CODE_USER_PROGRAM); /* auto-disable (see m68kcpu.h) */
  21.986 +	m68ki_check_address_error(REG_PC); /* auto-disable (see m68kcpu.h) */
  21.987 +	REG_PC += 4;
  21.988 +	return m68k_read_immediate_32(ADDRESS_68K(REG_PC-4));
  21.989 +#endif /* M68K_EMULATE_PREFETCH */
  21.990 +}
  21.991 +
  21.992 +
  21.993 +
  21.994 +/* ------------------------- Top level read/write ------------------------- */
  21.995 +
  21.996 +/* Handles all memory accesses (except for immediate reads if they are
  21.997 + * configured to use separate functions in m68kconf.h).
  21.998 + * All memory accesses must go through these top level functions.
  21.999 + * These functions will also check for address error and set the function
 21.1000 + * code if they are enabled in m68kconf.h.
 21.1001 + */
 21.1002 +INLINE uint m68ki_read_8_fc(uint address, uint fc)
 21.1003 +{
 21.1004 +	m68ki_set_fc(fc); /* auto-disable (see m68kcpu.h) */
 21.1005 +	return m68k_read_memory_8(ADDRESS_68K(address));
 21.1006 +}
 21.1007 +INLINE uint m68ki_read_16_fc(uint address, uint fc)
 21.1008 +{
 21.1009 +	m68ki_set_fc(fc); /* auto-disable (see m68kcpu.h) */
 21.1010 +	m68ki_check_address_error(address); /* auto-disable (see m68kcpu.h) */
 21.1011 +	return m68k_read_memory_16(ADDRESS_68K(address));
 21.1012 +}
 21.1013 +INLINE uint m68ki_read_32_fc(uint address, uint fc)
 21.1014 +{
 21.1015 +	m68ki_set_fc(fc); /* auto-disable (see m68kcpu.h) */
 21.1016 +	m68ki_check_address_error(address); /* auto-disable (see m68kcpu.h) */
 21.1017 +	return m68k_read_memory_32(ADDRESS_68K(address));
 21.1018 +}
 21.1019 +
 21.1020 +INLINE void m68ki_write_8_fc(uint address, uint fc, uint value)
 21.1021 +{
 21.1022 +	m68ki_set_fc(fc); /* auto-disable (see m68kcpu.h) */
 21.1023 +	m68k_write_memory_8(ADDRESS_68K(address), value);
 21.1024 +}
 21.1025 +INLINE void m68ki_write_16_fc(uint address, uint fc, uint value)
 21.1026 +{
 21.1027 +	m68ki_set_fc(fc); /* auto-disable (see m68kcpu.h) */
 21.1028 +	m68ki_check_address_error(address); /* auto-disable (see m68kcpu.h) */
 21.1029 +	m68k_write_memory_16(ADDRESS_68K(address), value);
 21.1030 +}
 21.1031 +INLINE void m68ki_write_32_fc(uint address, uint fc, uint value)
 21.1032 +{
 21.1033 +	m68ki_set_fc(fc); /* auto-disable (see m68kcpu.h) */
 21.1034 +	m68ki_check_address_error(address); /* auto-disable (see m68kcpu.h) */
 21.1035 +	m68k_write_memory_32(ADDRESS_68K(address), value);
 21.1036 +}
 21.1037 +
 21.1038 +
 21.1039 +
 21.1040 +/* --------------------- Effective Address Calculation -------------------- */
 21.1041 +
 21.1042 +/* The program counter relative addressing modes cause operands to be
 21.1043 + * retrieved from program space, not data space.
 21.1044 + */
 21.1045 +INLINE uint m68ki_get_ea_pcdi(void)
 21.1046 +{
 21.1047 +	uint old_pc = REG_PC;
 21.1048 +	m68ki_use_program_space(); /* auto-disable */
 21.1049 +	return old_pc + MAKE_INT_16(m68ki_read_imm_16());
 21.1050 +}
 21.1051 +
 21.1052 +
 21.1053 +INLINE uint m68ki_get_ea_pcix(void)
 21.1054 +{
 21.1055 +	m68ki_use_program_space(); /* auto-disable */
 21.1056 +	return m68ki_get_ea_ix(REG_PC);
 21.1057 +}
 21.1058 +
 21.1059 +/* Indexed addressing modes are encoded as follows:
 21.1060 + *
 21.1061 + * Base instruction format:
 21.1062 + * F E D C B A 9 8 7 6 | 5 4 3 | 2 1 0
 21.1063 + * x x x x x x x x x x | 1 1 0 | BASE REGISTER      (An)
 21.1064 + *
 21.1065 + * Base instruction format for destination EA in move instructions:
 21.1066 + * F E D C | B A 9    | 8 7 6 | 5 4 3 2 1 0
 21.1067 + * x x x x | BASE REG | 1 1 0 | X X X X X X       (An)
 21.1068 + *
 21.1069 + * Brief extension format:
 21.1070 + *  F  |  E D C   |  B  |  A 9  | 8 | 7 6 5 4 3 2 1 0
 21.1071 + * D/A | REGISTER | W/L | SCALE | 0 |  DISPLACEMENT
 21.1072 + *
 21.1073 + * Full extension format:
 21.1074 + *  F     E D C      B     A 9    8   7    6    5 4       3   2 1 0
 21.1075 + * D/A | REGISTER | W/L | SCALE | 1 | BS | IS | BD SIZE | 0 | I/IS
 21.1076 + * BASE DISPLACEMENT (0, 16, 32 bit)                (bd)
 21.1077 + * OUTER DISPLACEMENT (0, 16, 32 bit)               (od)
 21.1078 + *
 21.1079 + * D/A:     0 = Dn, 1 = An                          (Xn)
 21.1080 + * W/L:     0 = W (sign extend), 1 = L              (.SIZE)
 21.1081 + * SCALE:   00=1, 01=2, 10=4, 11=8                  (*SCALE)
 21.1082 + * BS:      0=add base reg, 1=suppress base reg     (An suppressed)
 21.1083 + * IS:      0=add index, 1=suppress index           (Xn suppressed)
 21.1084 + * BD SIZE: 00=reserved, 01=NULL, 10=Word, 11=Long  (size of bd)
 21.1085 + *
 21.1086 + * IS I/IS Operation
 21.1087 + * 0  000  No Memory Indirect
 21.1088 + * 0  001  indir prex with null outer
 21.1089 + * 0  010  indir prex with word outer
 21.1090 + * 0  011  indir prex with long outer
 21.1091 + * 0  100  reserved
 21.1092 + * 0  101  indir postx with null outer
 21.1093 + * 0  110  indir postx with word outer
 21.1094 + * 0  111  indir postx with long outer
 21.1095 + * 1  000  no memory indirect
 21.1096 + * 1  001  mem indir with null outer
 21.1097 + * 1  010  mem indir with word outer
 21.1098 + * 1  011  mem indir with long outer
 21.1099 + * 1  100-111  reserved
 21.1100 + */
 21.1101 +INLINE uint m68ki_get_ea_ix(uint An)
 21.1102 +{
 21.1103 +	/* An = base register */
 21.1104 +	uint extension = m68ki_read_imm_16();
 21.1105 +	uint Xn = 0;                        /* Index register */
 21.1106 +	uint bd = 0;                        /* Base Displacement */
 21.1107 +	uint od = 0;                        /* Outer Displacement */
 21.1108 +
 21.1109 +	if(CPU_TYPE_IS_010_LESS(CPU_TYPE))
 21.1110 +	{
 21.1111 +		/* Calculate index */
 21.1112 +		Xn = REG_DA[extension>>12];     /* Xn */
 21.1113 +		if(!BIT_B(extension))           /* W/L */
 21.1114 +			Xn = MAKE_INT_16(Xn);
 21.1115 +
 21.1116 +		/* Add base register and displacement and return */
 21.1117 +		return An + Xn + MAKE_INT_8(extension);
 21.1118 +	}
 21.1119 +
 21.1120 +	/* Brief extension format */
 21.1121 +	if(!BIT_8(extension))
 21.1122 +	{
 21.1123 +		/* Calculate index */
 21.1124 +		Xn = REG_DA[extension>>12];     /* Xn */
 21.1125 +		if(!BIT_B(extension))           /* W/L */
 21.1126 +			Xn = MAKE_INT_16(Xn);
 21.1127 +		/* Add scale if proper CPU type */
 21.1128 +		if(CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 21.1129 +			Xn <<= (extension>>9) & 3;  /* SCALE */
 21.1130 +
 21.1131 +		/* Add base register and displacement and return */
 21.1132 +		return An + Xn + MAKE_INT_8(extension);
 21.1133 +	}
 21.1134 +
 21.1135 +	/* Full extension format */
 21.1136 +
 21.1137 +	USE_CYCLES(m68ki_ea_idx_cycle_table[extension&0x3f]);
 21.1138 +
 21.1139 +	/* Check if base register is present */
 21.1140 +	if(BIT_7(extension))                /* BS */
 21.1141 +		An = 0;                         /* An */
 21.1142 +
 21.1143 +	/* Check if index is present */
 21.1144 +	if(!BIT_6(extension))               /* IS */
 21.1145 +	{
 21.1146 +		Xn = REG_DA[extension>>12];     /* Xn */
 21.1147 +		if(!BIT_B(extension))           /* W/L */
 21.1148 +			Xn = MAKE_INT_16(Xn);
 21.1149 +		Xn <<= (extension>>9) & 3;      /* SCALE */
 21.1150 +	}
 21.1151 +
 21.1152 +	/* Check if base displacement is present */
 21.1153 +	if(BIT_5(extension))                /* BD SIZE */
 21.1154 +		bd = BIT_4(extension) ? m68ki_read_imm_32() : MAKE_INT_16(m68ki_read_imm_16());
 21.1155 +
 21.1156 +	/* If no indirect action, we are done */
 21.1157 +	if(!(extension&7))                  /* No Memory Indirect */
 21.1158 +		return An + bd + Xn;
 21.1159 +
 21.1160 +	/* Check if outer displacement is present */
 21.1161 +	if(BIT_1(extension))                /* I/IS:  od */
 21.1162 +		od = BIT_0(extension) ? m68ki_read_imm_32() : MAKE_INT_16(m68ki_read_imm_16());
 21.1163 +
 21.1164 +	/* Postindex */
 21.1165 +	if(BIT_2(extension))                /* I/IS:  0 = preindex, 1 = postindex */
 21.1166 +		return m68ki_read_32(An + bd) + Xn + od;
 21.1167 +
 21.1168 +	/* Preindex */
 21.1169 +	return m68ki_read_32(An + bd + Xn) + od;
 21.1170 +}
 21.1171 +
 21.1172 +
 21.1173 +/* Fetch operands */
 21.1174 +INLINE uint OPER_AY_AI_8(void)  {uint ea = EA_AY_AI_8();  return m68ki_read_8(ea); }
 21.1175 +INLINE uint OPER_AY_AI_16(void) {uint ea = EA_AY_AI_16(); return m68ki_read_16(ea);}
 21.1176 +INLINE uint OPER_AY_AI_32(void) {uint ea = EA_AY_AI_32(); return m68ki_read_32(ea);}
 21.1177 +INLINE uint OPER_AY_PI_8(void)  {uint ea = EA_AY_PI_8();  return m68ki_read_8(ea); }
 21.1178 +INLINE uint OPER_AY_PI_16(void) {uint ea = EA_AY_PI_16(); return m68ki_read_16(ea);}
 21.1179 +INLINE uint OPER_AY_PI_32(void) {uint ea = EA_AY_PI_32(); return m68ki_read_32(ea);}
 21.1180 +INLINE uint OPER_AY_PD_8(void)  {uint ea = EA_AY_PD_8();  return m68ki_read_8(ea); }
 21.1181 +INLINE uint OPER_AY_PD_16(void) {uint ea = EA_AY_PD_16(); return m68ki_read_16(ea);}
 21.1182 +INLINE uint OPER_AY_PD_32(void) {uint ea = EA_AY_PD_32(); return m68ki_read_32(ea);}
 21.1183 +INLINE uint OPER_AY_DI_8(void)  {uint ea = EA_AY_DI_8();  return m68ki_read_8(ea); }
 21.1184 +INLINE uint OPER_AY_DI_16(void) {uint ea = EA_AY_DI_16(); return m68ki_read_16(ea);}
 21.1185 +INLINE uint OPER_AY_DI_32(void) {uint ea = EA_AY_DI_32(); return m68ki_read_32(ea);}
 21.1186 +INLINE uint OPER_AY_IX_8(void)  {uint ea = EA_AY_IX_8();  return m68ki_read_8(ea); }
 21.1187 +INLINE uint OPER_AY_IX_16(void) {uint ea = EA_AY_IX_16(); return m68ki_read_16(ea);}
 21.1188 +INLINE uint OPER_AY_IX_32(void) {uint ea = EA_AY_IX_32(); return m68ki_read_32(ea);}
 21.1189 +
 21.1190 +INLINE uint OPER_AX_AI_8(void)  {uint ea = EA_AX_AI_8();  return m68ki_read_8(ea); }
 21.1191 +INLINE uint OPER_AX_AI_16(void) {uint ea = EA_AX_AI_16(); return m68ki_read_16(ea);}
 21.1192 +INLINE uint OPER_AX_AI_32(void) {uint ea = EA_AX_AI_32(); return m68ki_read_32(ea);}
 21.1193 +INLINE uint OPER_AX_PI_8(void)  {uint ea = EA_AX_PI_8();  return m68ki_read_8(ea); }
 21.1194 +INLINE uint OPER_AX_PI_16(void) {uint ea = EA_AX_PI_16(); return m68ki_read_16(ea);}
 21.1195 +INLINE uint OPER_AX_PI_32(void) {uint ea = EA_AX_PI_32(); return m68ki_read_32(ea);}
 21.1196 +INLINE uint OPER_AX_PD_8(void)  {uint ea = EA_AX_PD_8();  return m68ki_read_8(ea); }
 21.1197 +INLINE uint OPER_AX_PD_16(void) {uint ea = EA_AX_PD_16(); return m68ki_read_16(ea);}
 21.1198 +INLINE uint OPER_AX_PD_32(void) {uint ea = EA_AX_PD_32(); return m68ki_read_32(ea);}
 21.1199 +INLINE uint OPER_AX_DI_8(void)  {uint ea = EA_AX_DI_8();  return m68ki_read_8(ea); }
 21.1200 +INLINE uint OPER_AX_DI_16(void) {uint ea = EA_AX_DI_16(); return m68ki_read_16(ea);}
 21.1201 +INLINE uint OPER_AX_DI_32(void) {uint ea = EA_AX_DI_32(); return m68ki_read_32(ea);}
 21.1202 +INLINE uint OPER_AX_IX_8(void)  {uint ea = EA_AX_IX_8();  return m68ki_read_8(ea); }
 21.1203 +INLINE uint OPER_AX_IX_16(void) {uint ea = EA_AX_IX_16(); return m68ki_read_16(ea);}
 21.1204 +INLINE uint OPER_AX_IX_32(void) {uint ea = EA_AX_IX_32(); return m68ki_read_32(ea);}
 21.1205 +
 21.1206 +INLINE uint OPER_A7_PI_8(void)  {uint ea = EA_A7_PI_8();  return m68ki_read_8(ea); }
 21.1207 +INLINE uint OPER_A7_PD_8(void)  {uint ea = EA_A7_PD_8();  return m68ki_read_8(ea); }
 21.1208 +
 21.1209 +INLINE uint OPER_AW_8(void)     {uint ea = EA_AW_8();     return m68ki_read_8(ea); }
 21.1210 +INLINE uint OPER_AW_16(void)    {uint ea = EA_AW_16();    return m68ki_read_16(ea);}
 21.1211 +INLINE uint OPER_AW_32(void)    {uint ea = EA_AW_32();    return m68ki_read_32(ea);}
 21.1212 +INLINE uint OPER_AL_8(void)     {uint ea = EA_AL_8();     return m68ki_read_8(ea); }
 21.1213 +INLINE uint OPER_AL_16(void)    {uint ea = EA_AL_16();    return m68ki_read_16(ea);}
 21.1214 +INLINE uint OPER_AL_32(void)    {uint ea = EA_AL_32();    return m68ki_read_32(ea);}
 21.1215 +INLINE uint OPER_PCDI_8(void)   {uint ea = EA_PCDI_8();   return m68ki_read_pcrel_8(ea); }
 21.1216 +INLINE uint OPER_PCDI_16(void)  {uint ea = EA_PCDI_16();  return m68ki_read_pcrel_16(ea);}
 21.1217 +INLINE uint OPER_PCDI_32(void)  {uint ea = EA_PCDI_32();  return m68ki_read_pcrel_32(ea);}
 21.1218 +INLINE uint OPER_PCIX_8(void)   {uint ea = EA_PCIX_8();   return m68ki_read_pcrel_8(ea); }
 21.1219 +INLINE uint OPER_PCIX_16(void)  {uint ea = EA_PCIX_16();  return m68ki_read_pcrel_16(ea);}
 21.1220 +INLINE uint OPER_PCIX_32(void)  {uint ea = EA_PCIX_32();  return m68ki_read_pcrel_32(ea);}
 21.1221 +
 21.1222 +
 21.1223 +
 21.1224 +/* ---------------------------- Stack Functions --------------------------- */
 21.1225 +
 21.1226 +/* Push/pull data from the stack */
 21.1227 +INLINE void m68ki_push_16(uint value)
 21.1228 +{
 21.1229 +	REG_SP = MASK_OUT_ABOVE_32(REG_SP - 2);
 21.1230 +	m68ki_write_16(REG_SP, value);
 21.1231 +}
 21.1232 +
 21.1233 +INLINE void m68ki_push_32(uint value)
 21.1234 +{
 21.1235 +	REG_SP = MASK_OUT_ABOVE_32(REG_SP - 4);
 21.1236 +	m68ki_write_32(REG_SP, value);
 21.1237 +}
 21.1238 +
 21.1239 +INLINE uint m68ki_pull_16(void)
 21.1240 +{
 21.1241 +	REG_SP = MASK_OUT_ABOVE_32(REG_SP + 2);
 21.1242 +	return m68ki_read_16(REG_SP-2);
 21.1243 +}
 21.1244 +
 21.1245 +INLINE uint m68ki_pull_32(void)
 21.1246 +{
 21.1247 +	REG_SP = MASK_OUT_ABOVE_32(REG_SP + 4);
 21.1248 +	return m68ki_read_32(REG_SP-4);
 21.1249 +}
 21.1250 +
 21.1251 +
 21.1252 +/* Increment/decrement the stack as if doing a push/pull but
 21.1253 + * don't do any memory access.
 21.1254 + */
 21.1255 +INLINE void m68ki_fake_push_16(void)
 21.1256 +{
 21.1257 +	REG_SP = MASK_OUT_ABOVE_32(REG_SP - 2);
 21.1258 +}
 21.1259 +
 21.1260 +INLINE void m68ki_fake_push_32(void)
 21.1261 +{
 21.1262 +	REG_SP = MASK_OUT_ABOVE_32(REG_SP - 4);
 21.1263 +}
 21.1264 +
 21.1265 +INLINE void m68ki_fake_pull_16(void)
 21.1266 +{
 21.1267 +	REG_SP = MASK_OUT_ABOVE_32(REG_SP + 2);
 21.1268 +}
 21.1269 +
 21.1270 +INLINE void m68ki_fake_pull_32(void)
 21.1271 +{
 21.1272 +	REG_SP = MASK_OUT_ABOVE_32(REG_SP + 4);
 21.1273 +}
 21.1274 +
 21.1275 +
 21.1276 +/* ----------------------------- Program Flow ----------------------------- */
 21.1277 +
 21.1278 +/* Jump to a new program location or vector.
 21.1279 + * These functions will also call the pc_changed callback if it was enabled
 21.1280 + * in m68kconf.h.
 21.1281 + */
 21.1282 +INLINE void m68ki_jump(uint new_pc)
 21.1283 +{
 21.1284 +	REG_PC = new_pc;
 21.1285 +	m68ki_pc_changed(REG_PC);
 21.1286 +}
 21.1287 +
 21.1288 +INLINE void m68ki_jump_vector(uint vector)
 21.1289 +{
 21.1290 +	REG_PC = (vector<<2) + REG_VBR;
 21.1291 +	REG_PC = m68ki_read_data_32(REG_PC);
 21.1292 +	m68ki_pc_changed(REG_PC);
 21.1293 +}
 21.1294 +
 21.1295 +
 21.1296 +/* Branch to a new memory location.
 21.1297 + * The 32-bit branch will call pc_changed if it was enabled in m68kconf.h.
 21.1298 + * So far I've found no problems with not calling pc_changed for 8 or 16
 21.1299 + * bit branches.
 21.1300 + */
 21.1301 +INLINE void m68ki_branch_8(uint offset)
 21.1302 +{
 21.1303 +	REG_PC += MAKE_INT_8(offset);
 21.1304 +}
 21.1305 +
 21.1306 +INLINE void m68ki_branch_16(uint offset)
 21.1307 +{
 21.1308 +	REG_PC += MAKE_INT_16(offset);
 21.1309 +}
 21.1310 +
 21.1311 +INLINE void m68ki_branch_32(uint offset)
 21.1312 +{
 21.1313 +	REG_PC += offset;
 21.1314 +	m68ki_pc_changed(REG_PC);
 21.1315 +}
 21.1316 +
 21.1317 +
 21.1318 +
 21.1319 +/* ---------------------------- Status Register --------------------------- */
 21.1320 +
 21.1321 +/* Set the S flag and change the active stack pointer.
 21.1322 + * Note that value MUST be 4 or 0.
 21.1323 + */
 21.1324 +INLINE void m68ki_set_s_flag(uint value)
 21.1325 +{
 21.1326 +	/* Backup the old stack pointer */
 21.1327 +	REG_SP_BASE[FLAG_S | ((FLAG_S>>1) & FLAG_M)] = REG_SP;
 21.1328 +	/* Set the S flag */
 21.1329 +	FLAG_S = value;
 21.1330 +	/* Set the new stack pointer */
 21.1331 +	REG_SP = REG_SP_BASE[FLAG_S | ((FLAG_S>>1) & FLAG_M)];
 21.1332 +}
 21.1333 +
 21.1334 +/* Set the S and M flags and change the active stack pointer.
 21.1335 + * Note that value MUST be 0, 2, 4, or 6 (bit2 = S, bit1 = M).
 21.1336 + */
 21.1337 +INLINE void m68ki_set_sm_flag(uint value)
 21.1338 +{
 21.1339 +	/* Backup the old stack pointer */
 21.1340 +	REG_SP_BASE[FLAG_S | ((FLAG_S>>1) & FLAG_M)] = REG_SP;
 21.1341 +	/* Set the S and M flags */
 21.1342 +	FLAG_S = value & SFLAG_SET;
 21.1343 +	FLAG_M = value & MFLAG_SET;
 21.1344 +	/* Set the new stack pointer */
 21.1345 +	REG_SP = REG_SP_BASE[FLAG_S | ((FLAG_S>>1) & FLAG_M)];
 21.1346 +}
 21.1347 +
 21.1348 +
 21.1349 +/* Set the condition code register */
 21.1350 +INLINE void m68ki_set_ccr(uint value)
 21.1351 +{
 21.1352 +	FLAG_X = BIT_4(value)  << 4;
 21.1353 +	FLAG_N = BIT_3(value)  << 4;
 21.1354 +	FLAG_Z = !BIT_2(value);
 21.1355 +	FLAG_V = BIT_1(value)  << 6;
 21.1356 +	FLAG_C = BIT_0(value)  << 8;
 21.1357 +}
 21.1358 +
 21.1359 +/* Set the status register but don't check for interrupts */
 21.1360 +INLINE void m68ki_set_sr_noint(uint value)
 21.1361 +{
 21.1362 +	/* Mask out the "unimplemented" bits */
 21.1363 +	value &= CPU_SR_MASK;
 21.1364 +
 21.1365 +	/* Now set the status register */
 21.1366 +	FLAG_T1 = BIT_F(value);
 21.1367 +	FLAG_T0 = BIT_E(value);
 21.1368 +	FLAG_INT_MASK = value & 0x0700;
 21.1369 +	m68ki_set_ccr(value);
 21.1370 +	m68ki_set_sm_flag((value >> 11) & 6);
 21.1371 +}
 21.1372 +
 21.1373 +/* Set the status register and check for interrupts */
 21.1374 +INLINE void m68ki_set_sr(uint value)
 21.1375 +{
 21.1376 +	m68ki_set_sr_noint(value);
 21.1377 +	m68ki_check_interrupts();
 21.1378 +}
 21.1379 +
 21.1380 +
 21.1381 +/* ------------------------- Exception Processing ------------------------- */
 21.1382 +
 21.1383 +/* Initiate exception processing */
 21.1384 +INLINE uint m68ki_init_exception(void)
 21.1385 +{
 21.1386 +	/* Save the old status register */
 21.1387 +	uint sr = m68ki_get_sr();
 21.1388 +
 21.1389 +	/* Turn off trace flag, clear pending traces */
 21.1390 +	FLAG_T1 = FLAG_T0 = 0;
 21.1391 +	m68ki_clear_trace();
 21.1392 +	/* Enter supervisor mode */
 21.1393 +	m68ki_set_s_flag(SFLAG_SET);
 21.1394 +
 21.1395 +	return sr;
 21.1396 +}
 21.1397 +
 21.1398 +/* 3 word stack frame (68000 only) */
 21.1399 +INLINE void m68ki_stack_frame_3word(uint pc, uint sr)
 21.1400 +{
 21.1401 +	m68ki_push_32(pc);
 21.1402 +	m68ki_push_16(sr);
 21.1403 +}
 21.1404 +
 21.1405 +/* Format 0 stack frame.
 21.1406 + * This is the standard stack frame for 68010+.
 21.1407 + */
 21.1408 +INLINE void m68ki_stack_frame_0000(uint pc, uint sr, uint vector)
 21.1409 +{
 21.1410 +	/* Stack a 3-word frame if we are 68000 */
 21.1411 +	if(CPU_TYPE == CPU_TYPE_000)
 21.1412 +	{
 21.1413 +		m68ki_stack_frame_3word(pc, sr);
 21.1414 +		return;
 21.1415 +	}
 21.1416 +	m68ki_push_16(vector<<2);
 21.1417 +	m68ki_push_32(pc);
 21.1418 +	m68ki_push_16(sr);
 21.1419 +}
 21.1420 +
 21.1421 +/* Format 1 stack frame (68020).
 21.1422 + * For 68020, this is the 4 word throwaway frame.
 21.1423 + */
 21.1424 +INLINE void m68ki_stack_frame_0001(uint pc, uint sr, uint vector)
 21.1425 +{
 21.1426 +	m68ki_push_16(0x1000 | (vector<<2));
 21.1427 +	m68ki_push_32(pc);
 21.1428 +	m68ki_push_16(sr);
 21.1429 +}
 21.1430 +
 21.1431 +/* Format 2 stack frame.
 21.1432 + * This is used only by 68020 for trap exceptions.
 21.1433 + */
 21.1434 +INLINE void m68ki_stack_frame_0010(uint sr, uint vector)
 21.1435 +{
 21.1436 +	m68ki_push_32(REG_PPC);
 21.1437 +	m68ki_push_16(0x2000 | (vector<<2));
 21.1438 +	m68ki_push_32(REG_PC);
 21.1439 +	m68ki_push_16(sr);
 21.1440 +}
 21.1441 +
 21.1442 +
 21.1443 +/* Bus error stack frame (68000 only).
 21.1444 + */
 21.1445 +INLINE void m68ki_stack_frame_buserr(uint pc, uint sr, uint address, uint write, uint instruction, uint fc)
 21.1446 +{
 21.1447 +	m68ki_push_32(pc);
 21.1448 +	m68ki_push_16(sr);
 21.1449 +	m68ki_push_16(REG_IR);
 21.1450 +	m68ki_push_32(address);	/* access address */
 21.1451 +	/* 0 0 0 0 0 0 0 0 0 0 0 R/W I/N FC
 21.1452 +	 * R/W  0 = write, 1 = read
 21.1453 +	 * I/N  0 = instruction, 1 = not
 21.1454 +	 * FC   3-bit function code
 21.1455 +	 */
 21.1456 +	m68ki_push_16(((!write)<<4) | ((!instruction)<<3) | fc);
 21.1457 +}
 21.1458 +
 21.1459 +/* Format 8 stack frame (68010).
 21.1460 + * 68010 only.  This is the 29 word bus/address error frame.
 21.1461 + */
 21.1462 +void m68ki_stack_frame_1000(uint pc, uint sr, uint vector)
 21.1463 +{
 21.1464 +	/* VERSION
 21.1465 +	 * NUMBER
 21.1466 +	 * INTERNAL INFORMATION, 16 WORDS
 21.1467 +	 */
 21.1468 +	m68ki_fake_push_32();
 21.1469 +	m68ki_fake_push_32();
 21.1470 +	m68ki_fake_push_32();
 21.1471 +	m68ki_fake_push_32();
 21.1472 +	m68ki_fake_push_32();
 21.1473 +	m68ki_fake_push_32();
 21.1474 +	m68ki_fake_push_32();
 21.1475 +	m68ki_fake_push_32();
 21.1476 +
 21.1477 +	/* INSTRUCTION INPUT BUFFER */
 21.1478 +	m68ki_push_16(0);
 21.1479 +
 21.1480 +	/* UNUSED, RESERVED (not written) */
 21.1481 +	m68ki_fake_push_16();
 21.1482 +
 21.1483 +	/* DATA INPUT BUFFER */
 21.1484 +	m68ki_push_16(0);
 21.1485 +
 21.1486 +	/* UNUSED, RESERVED (not written) */
 21.1487 +	m68ki_fake_push_16();
 21.1488 +
 21.1489 +	/* DATA OUTPUT BUFFER */
 21.1490 +	m68ki_push_16(0);
 21.1491 +
 21.1492 +	/* UNUSED, RESERVED (not written) */
 21.1493 +	m68ki_fake_push_16();
 21.1494 +
 21.1495 +	/* FAULT ADDRESS */
 21.1496 +	m68ki_push_32(0);
 21.1497 +
 21.1498 +	/* SPECIAL STATUS WORD */
 21.1499 +	m68ki_push_16(0);
 21.1500 +
 21.1501 +	/* 1000, VECTOR OFFSET */
 21.1502 +	m68ki_push_16(0x8000 | (vector<<2));
 21.1503 +
 21.1504 +	/* PROGRAM COUNTER */
 21.1505 +	m68ki_push_32(pc);
 21.1506 +
 21.1507 +	/* STATUS REGISTER */
 21.1508 +	m68ki_push_16(sr);
 21.1509 +}
 21.1510 +
 21.1511 +/* Format A stack frame (short bus fault).
 21.1512 + * This is used only by 68020 for bus fault and address error
 21.1513 + * if the error happens at an instruction boundary.
 21.1514 + * PC stacked is address of next instruction.
 21.1515 + */
 21.1516 +void m68ki_stack_frame_1010(uint sr, uint vector, uint pc)
 21.1517 +{
 21.1518 +	/* INTERNAL REGISTER */
 21.1519 +	m68ki_push_16(0);
 21.1520 +
 21.1521 +	/* INTERNAL REGISTER */
 21.1522 +	m68ki_push_16(0);
 21.1523 +
 21.1524 +	/* DATA OUTPUT BUFFER (2 words) */
 21.1525 +	m68ki_push_32(0);
 21.1526 +
 21.1527 +	/* INTERNAL REGISTER */
 21.1528 +	m68ki_push_16(0);
 21.1529 +
 21.1530 +	/* INTERNAL REGISTER */
 21.1531 +	m68ki_push_16(0);
 21.1532 +
 21.1533 +	/* DATA CYCLE FAULT ADDRESS (2 words) */
 21.1534 +	m68ki_push_32(0);
 21.1535 +
 21.1536 +	/* INSTRUCTION PIPE STAGE B */
 21.1537 +	m68ki_push_16(0);
 21.1538 +
 21.1539 +	/* INSTRUCTION PIPE STAGE C */
 21.1540 +	m68ki_push_16(0);
 21.1541 +
 21.1542 +	/* SPECIAL STATUS REGISTER */
 21.1543 +	m68ki_push_16(0);
 21.1544 +
 21.1545 +	/* INTERNAL REGISTER */
 21.1546 +	m68ki_push_16(0);
 21.1547 +
 21.1548 +	/* 1010, VECTOR OFFSET */
 21.1549 +	m68ki_push_16(0xa000 | (vector<<2));
 21.1550 +
 21.1551 +	/* PROGRAM COUNTER */
 21.1552 +	m68ki_push_32(pc);
 21.1553 +
 21.1554 +	/* STATUS REGISTER */
 21.1555 +	m68ki_push_16(sr);
 21.1556 +}
 21.1557 +
 21.1558 +/* Format B stack frame (long bus fault).
 21.1559 + * This is used only by 68020 for bus fault and address error
 21.1560 + * if the error happens during instruction execution.
 21.1561 + * PC stacked is address of instruction in progress.
 21.1562 + */
 21.1563 +void m68ki_stack_frame_1011(uint sr, uint vector, uint pc)
 21.1564 +{
 21.1565 +	/* INTERNAL REGISTERS (18 words) */
 21.1566 +	m68ki_push_32(0);
 21.1567 +	m68ki_push_32(0);
 21.1568 +	m68ki_push_32(0);
 21.1569 +	m68ki_push_32(0);
 21.1570 +	m68ki_push_32(0);
 21.1571 +	m68ki_push_32(0);
 21.1572 +	m68ki_push_32(0);
 21.1573 +	m68ki_push_32(0);
 21.1574 +	m68ki_push_32(0);
 21.1575 +
 21.1576 +	/* VERSION# (4 bits), INTERNAL INFORMATION */
 21.1577 +	m68ki_push_16(0);
 21.1578 +
 21.1579 +	/* INTERNAL REGISTERS (3 words) */
 21.1580 +	m68ki_push_32(0);
 21.1581 +	m68ki_push_16(0);
 21.1582 +
 21.1583 +	/* DATA INTPUT BUFFER (2 words) */
 21.1584 +	m68ki_push_32(0);
 21.1585 +
 21.1586 +	/* INTERNAL REGISTERS (2 words) */
 21.1587 +	m68ki_push_32(0);
 21.1588 +
 21.1589 +	/* STAGE B ADDRESS (2 words) */
 21.1590 +	m68ki_push_32(0);
 21.1591 +
 21.1592 +	/* INTERNAL REGISTER (4 words) */
 21.1593 +	m68ki_push_32(0);
 21.1594 +	m68ki_push_32(0);
 21.1595 +
 21.1596 +	/* DATA OUTPUT BUFFER (2 words) */
 21.1597 +	m68ki_push_32(0);
 21.1598 +
 21.1599 +	/* INTERNAL REGISTER */
 21.1600 +	m68ki_push_16(0);
 21.1601 +
 21.1602 +	/* INTERNAL REGISTER */
 21.1603 +	m68ki_push_16(0);
 21.1604 +
 21.1605 +	/* DATA CYCLE FAULT ADDRESS (2 words) */
 21.1606 +	m68ki_push_32(0);
 21.1607 +
 21.1608 +	/* INSTRUCTION PIPE STAGE B */
 21.1609 +	m68ki_push_16(0);
 21.1610 +
 21.1611 +	/* INSTRUCTION PIPE STAGE C */
 21.1612 +	m68ki_push_16(0);
 21.1613 +
 21.1614 +	/* SPECIAL STATUS REGISTER */
 21.1615 +	m68ki_push_16(0);
 21.1616 +
 21.1617 +	/* INTERNAL REGISTER */
 21.1618 +	m68ki_push_16(0);
 21.1619 +
 21.1620 +	/* 1011, VECTOR OFFSET */
 21.1621 +	m68ki_push_16(0xb000 | (vector<<2));
 21.1622 +
 21.1623 +	/* PROGRAM COUNTER */
 21.1624 +	m68ki_push_32(pc);
 21.1625 +
 21.1626 +	/* STATUS REGISTER */
 21.1627 +	m68ki_push_16(sr);
 21.1628 +}
 21.1629 +
 21.1630 +
 21.1631 +/* Used for Group 2 exceptions.
 21.1632 + * These stack a type 2 frame on the 020.
 21.1633 + */
 21.1634 +INLINE void m68ki_exception_trap(uint vector)
 21.1635 +{
 21.1636 +	uint sr = m68ki_init_exception();
 21.1637 +
 21.1638 +	if(CPU_TYPE_IS_010_LESS(CPU_TYPE))
 21.1639 +		m68ki_stack_frame_0000(REG_PC, sr, vector);
 21.1640 +	else
 21.1641 +		m68ki_stack_frame_0010(sr, vector);
 21.1642 +
 21.1643 +	m68ki_jump_vector(vector);
 21.1644 +
 21.1645 +	/* Use up some clock cycles */
 21.1646 +	USE_CYCLES(CYC_EXCEPTION[vector]);
 21.1647 +}
 21.1648 +
 21.1649 +/* Trap#n stacks a 0 frame but behaves like group2 otherwise */
 21.1650 +INLINE void m68ki_exception_trapN(uint vector)
 21.1651 +{
 21.1652 +	uint sr = m68ki_init_exception();
 21.1653 +	m68ki_stack_frame_0000(REG_PC, sr, vector);
 21.1654 +	m68ki_jump_vector(vector);
 21.1655 +
 21.1656 +	/* Use up some clock cycles */
 21.1657 +	USE_CYCLES(CYC_EXCEPTION[vector]);
 21.1658 +}
 21.1659 +
 21.1660 +/* Exception for trace mode */
 21.1661 +INLINE void m68ki_exception_trace(void)
 21.1662 +{
 21.1663 +	uint sr = m68ki_init_exception();
 21.1664 +
 21.1665 +	if(CPU_TYPE_IS_010_LESS(CPU_TYPE))
 21.1666 +		m68ki_stack_frame_0000(REG_PC, sr, EXCEPTION_TRACE);
 21.1667 +	else
 21.1668 +		m68ki_stack_frame_0010(sr, EXCEPTION_TRACE);
 21.1669 +
 21.1670 +	m68ki_jump_vector(EXCEPTION_TRACE);
 21.1671 +
 21.1672 +	/* Trace nullifies a STOP instruction */
 21.1673 +	CPU_STOPPED &= ~STOP_LEVEL_STOP;
 21.1674 +
 21.1675 +	/* Use up some clock cycles */
 21.1676 +	USE_CYCLES(CYC_EXCEPTION[EXCEPTION_TRACE]);
 21.1677 +}
 21.1678 +
 21.1679 +/* Exception for privilege violation */
 21.1680 +INLINE void m68ki_exception_privilege_violation(void)
 21.1681 +{
 21.1682 +	uint sr = m68ki_init_exception();
 21.1683 +	m68ki_stack_frame_0000(REG_PC, sr, EXCEPTION_PRIVILEGE_VIOLATION);
 21.1684 +	m68ki_jump_vector(EXCEPTION_PRIVILEGE_VIOLATION);
 21.1685 +
 21.1686 +	/* Use up some clock cycles and undo the instruction's cycles */
 21.1687 +	USE_CYCLES(CYC_EXCEPTION[EXCEPTION_PRIVILEGE_VIOLATION] - CYC_INSTRUCTION[REG_IR]);
 21.1688 +}
 21.1689 +
 21.1690 +/* Exception for A-Line instructions */
 21.1691 +INLINE void m68ki_exception_1010(void)
 21.1692 +{
 21.1693 +	uint sr;
 21.1694 +#if M68K_LOG_1010_1111 == OPT_ON
 21.1695 +	M68K_DO_LOG_EMU((M68K_LOG_FILEHANDLE "%s at %08x: called 1010 instruction %04x (%s)\n",
 21.1696 +					 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PPC), REG_IR,
 21.1697 +					 m68ki_disassemble_quick(ADDRESS_68K(REG_PPC))));
 21.1698 +#endif
 21.1699 +
 21.1700 +	sr = m68ki_init_exception();
 21.1701 +	m68ki_stack_frame_0000(REG_PC-2, sr, EXCEPTION_1010);
 21.1702 +	m68ki_jump_vector(EXCEPTION_1010);
 21.1703 +
 21.1704 +	/* Use up some clock cycles and undo the instruction's cycles */
 21.1705 +	USE_CYCLES(CYC_EXCEPTION[EXCEPTION_1010] - CYC_INSTRUCTION[REG_IR]);
 21.1706 +}
 21.1707 +
 21.1708 +/* Exception for F-Line instructions */
 21.1709 +INLINE void m68ki_exception_1111(void)
 21.1710 +{
 21.1711 +	uint sr;
 21.1712 +
 21.1713 +#if M68K_LOG_1010_1111 == OPT_ON
 21.1714 +	M68K_DO_LOG_EMU((M68K_LOG_FILEHANDLE "%s at %08x: called 1111 instruction %04x (%s)\n",
 21.1715 +					 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PPC), REG_IR,
 21.1716 +					 m68ki_disassemble_quick(ADDRESS_68K(REG_PPC))));
 21.1717 +#endif
 21.1718 +
 21.1719 +	sr = m68ki_init_exception();
 21.1720 +	m68ki_stack_frame_0000(REG_PC-2, sr, EXCEPTION_1111);
 21.1721 +	m68ki_jump_vector(EXCEPTION_1111);
 21.1722 +
 21.1723 +	/* Use up some clock cycles and undo the instruction's cycles */
 21.1724 +	USE_CYCLES(CYC_EXCEPTION[EXCEPTION_1111] - CYC_INSTRUCTION[REG_IR]);
 21.1725 +}
 21.1726 +
 21.1727 +/* Exception for illegal instructions */
 21.1728 +INLINE void m68ki_exception_illegal(void)
 21.1729 +{
 21.1730 +	uint sr;
 21.1731 +
 21.1732 +	M68K_DO_LOG((M68K_LOG_FILEHANDLE "%s at %08x: illegal instruction %04x (%s)\n",
 21.1733 +				 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PPC), REG_IR,
 21.1734 +				 m68ki_disassemble_quick(ADDRESS_68K(REG_PPC))));
 21.1735 +
 21.1736 +	sr = m68ki_init_exception();
 21.1737 +	m68ki_stack_frame_0000(REG_PC, sr, EXCEPTION_ILLEGAL_INSTRUCTION);
 21.1738 +	m68ki_jump_vector(EXCEPTION_ILLEGAL_INSTRUCTION);
 21.1739 +
 21.1740 +	/* Use up some clock cycles and undo the instruction's cycles */
 21.1741 +	USE_CYCLES(CYC_EXCEPTION[EXCEPTION_ILLEGAL_INSTRUCTION] - CYC_INSTRUCTION[REG_IR]);
 21.1742 +}
 21.1743 +
 21.1744 +/* Exception for format errror in RTE */
 21.1745 +INLINE void m68ki_exception_format_error(void)
 21.1746 +{
 21.1747 +	uint sr = m68ki_init_exception();
 21.1748 +	m68ki_stack_frame_0000(REG_PC, sr, EXCEPTION_FORMAT_ERROR);
 21.1749 +	m68ki_jump_vector(EXCEPTION_FORMAT_ERROR);
 21.1750 +
 21.1751 +	/* Use up some clock cycles and undo the instruction's cycles */
 21.1752 +	USE_CYCLES(CYC_EXCEPTION[EXCEPTION_FORMAT_ERROR] - CYC_INSTRUCTION[REG_IR]);
 21.1753 +}
 21.1754 +
 21.1755 +/* Exception for address error */
 21.1756 +INLINE void m68ki_exception_address_error(void)
 21.1757 +{
 21.1758 +	/* Not emulated yet */
 21.1759 +}
 21.1760 +
 21.1761 +
 21.1762 +/* Service an interrupt request and start exception processing */
 21.1763 +void m68ki_exception_interrupt(uint int_level)
 21.1764 +{
 21.1765 +	uint vector;
 21.1766 +	uint sr;
 21.1767 +	uint new_pc;
 21.1768 +
 21.1769 +	/* Turn off the stopped state */
 21.1770 +	CPU_STOPPED &= ~STOP_LEVEL_STOP;
 21.1771 +
 21.1772 +	/* If we are halted, don't do anything */
 21.1773 +	if(CPU_STOPPED)
 21.1774 +		return;
 21.1775 +
 21.1776 +	/* Acknowledge the interrupt */
 21.1777 +	vector = m68ki_int_ack(int_level);
 21.1778 +
 21.1779 +	/* Get the interrupt vector */
 21.1780 +	if(vector == M68K_INT_ACK_AUTOVECTOR)
 21.1781 +		/* Use the autovectors.  This is the most commonly used implementation */
 21.1782 +		vector = EXCEPTION_INTERRUPT_AUTOVECTOR+int_level;
 21.1783 +	else if(vector == M68K_INT_ACK_SPURIOUS)
 21.1784 +		/* Called if no devices respond to the interrupt acknowledge */
 21.1785 +		vector = EXCEPTION_SPURIOUS_INTERRUPT;
 21.1786 +	else if(vector > 255)
 21.1787 +	{
 21.1788 +		M68K_DO_LOG_EMU((M68K_LOG_FILEHANDLE "%s at %08x: Interrupt acknowledge returned invalid vector $%x\n",
 21.1789 +				 m68ki_cpu_names[CPU_TYPE], ADDRESS_68K(REG_PC), vector));
 21.1790 +		return;
 21.1791 +	}
 21.1792 +
 21.1793 +	/* Start exception processing */
 21.1794 +	sr = m68ki_init_exception();
 21.1795 +
 21.1796 +	/* Set the interrupt mask to the level of the one being serviced */
 21.1797 +	FLAG_INT_MASK = int_level<<8;
 21.1798 +
 21.1799 +	/* Get the new PC */
 21.1800 +	new_pc = m68ki_read_data_32((vector<<2) + REG_VBR);
 21.1801 +
 21.1802 +	/* If vector is uninitialized, call the uninitialized interrupt vector */
 21.1803 +	if(new_pc == 0)
 21.1804 +		new_pc = m68ki_read_data_32((EXCEPTION_UNINITIALIZED_INTERRUPT<<2) + REG_VBR);
 21.1805 +
 21.1806 +	/* Generate a stack frame */
 21.1807 +	m68ki_stack_frame_0000(REG_PC, sr, vector);
 21.1808 +	if(FLAG_M && CPU_TYPE_IS_EC020_PLUS(CPU_TYPE))
 21.1809 +	{
 21.1810 +		/* Create throwaway frame */
 21.1811 +		m68ki_set_sm_flag(FLAG_S);	/* clear M */
 21.1812 +		sr |= 0x2000; /* Same as SR in master stack frame except S is forced high */
 21.1813 +		m68ki_stack_frame_0001(REG_PC, sr, vector);
 21.1814 +	}
 21.1815 +
 21.1816 +	m68ki_jump(new_pc);
 21.1817 +
 21.1818 +	/* Defer cycle counting until later */
 21.1819 +	CPU_INT_CYCLES += CYC_EXCEPTION[vector];
 21.1820 +
 21.1821 +#if !M68K_EMULATE_INT_ACK
 21.1822 +	/* Automatically clear IRQ if we are not using an acknowledge scheme */
 21.1823 +	CPU_INT_LEVEL = 0;
 21.1824 +#endif /* M68K_EMULATE_INT_ACK */
 21.1825 +}
 21.1826 +
 21.1827 +
 21.1828 +/* ASG: Check for interrupts */
 21.1829 +INLINE void m68ki_check_interrupts(void)
 21.1830 +{
 21.1831 +	if(CPU_INT_LEVEL > FLAG_INT_MASK)
 21.1832 +		m68ki_exception_interrupt(CPU_INT_LEVEL>>8);
 21.1833 +}
 21.1834 +
 21.1835 +
 21.1836 +
 21.1837 +/* ======================================================================== */
 21.1838 +/* ============================== END OF FILE ============================= */
 21.1839 +/* ======================================================================== */
 21.1840 +
 21.1841 +#endif /* M68KCPU__HEADER */
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/musashi/m68kdasm.c	Sat Nov 27 01:13:12 2010 +0000
    22.3 @@ -0,0 +1,3443 @@
    22.4 +/* ======================================================================== */
    22.5 +/* ========================= LICENSING & COPYRIGHT ======================== */
    22.6 +/* ======================================================================== */
    22.7 +/*
    22.8 + *                                  MUSASHI
    22.9 + *                                Version 3.3
   22.10 + *
   22.11 + * A portable Motorola M680x0 processor emulation engine.
   22.12 + * Copyright 1998-2001 Karl Stenerud.  All rights reserved.
   22.13 + *
   22.14 + * This code may be freely used for non-commercial purposes as long as this
   22.15 + * copyright notice remains unaltered in the source code and any binary files
   22.16 + * containing this code in compiled form.
   22.17 + *
   22.18 + * All other lisencing terms must be negotiated with the author
   22.19 + * (Karl Stenerud).
   22.20 + *
   22.21 + * The latest version of this code can be obtained at:
   22.22 + * http://kstenerud.cjb.net
   22.23 + */
   22.24 +
   22.25 +
   22.26 +
   22.27 +/* ======================================================================== */
   22.28 +/* ================================ INCLUDES ============================== */
   22.29 +/* ======================================================================== */
   22.30 +
   22.31 +#include <stdlib.h>
   22.32 +#include <stdio.h>
   22.33 +#include <string.h>
   22.34 +#include "m68k.h"
   22.35 +
   22.36 +/* ======================================================================== */
   22.37 +/* ============================ GENERAL DEFINES =========================== */
   22.38 +/* ======================================================================== */
   22.39 +
   22.40 +/* unsigned int and int must be at least 32 bits wide */
   22.41 +#undef uint
   22.42 +#define uint unsigned int
   22.43 +
   22.44 +/* Bit Isolation Functions */
   22.45 +#define BIT_0(A)  ((A) & 0x00000001)
   22.46 +#define BIT_1(A)  ((A) & 0x00000002)
   22.47 +#define BIT_2(A)  ((A) & 0x00000004)
   22.48 +#define BIT_3(A)  ((A) & 0x00000008)
   22.49 +#define BIT_4(A)  ((A) & 0x00000010)
   22.50 +#define BIT_5(A)  ((A) & 0x00000020)
   22.51 +#define BIT_6(A)  ((A) & 0x00000040)
   22.52 +#define BIT_7(A)  ((A) & 0x00000080)
   22.53 +#define BIT_8(A)  ((A) & 0x00000100)
   22.54 +#define BIT_9(A)  ((A) & 0x00000200)
   22.55 +#define BIT_A(A)  ((A) & 0x00000400)
   22.56 +#define BIT_B(A)  ((A) & 0x00000800)
   22.57 +#define BIT_C(A)  ((A) & 0x00001000)
   22.58 +#define BIT_D(A)  ((A) & 0x00002000)
   22.59 +#define BIT_E(A)  ((A) & 0x00004000)
   22.60 +#define BIT_F(A)  ((A) & 0x00008000)
   22.61 +#define BIT_10(A) ((A) & 0x00010000)
   22.62 +#define BIT_11(A) ((A) & 0x00020000)
   22.63 +#define BIT_12(A) ((A) & 0x00040000)
   22.64 +#define BIT_13(A) ((A) & 0x00080000)
   22.65 +#define BIT_14(A) ((A) & 0x00100000)
   22.66 +#define BIT_15(A) ((A) & 0x00200000)
   22.67 +#define BIT_16(A) ((A) & 0x00400000)
   22.68 +#define BIT_17(A) ((A) & 0x00800000)
   22.69 +#define BIT_18(A) ((A) & 0x01000000)
   22.70 +#define BIT_19(A) ((A) & 0x02000000)
   22.71 +#define BIT_1A(A) ((A) & 0x04000000)
   22.72 +#define BIT_1B(A) ((A) & 0x08000000)
   22.73 +#define BIT_1C(A) ((A) & 0x10000000)
   22.74 +#define BIT_1D(A) ((A) & 0x20000000)
   22.75 +#define BIT_1E(A) ((A) & 0x40000000)
   22.76 +#define BIT_1F(A) ((A) & 0x80000000)
   22.77 +
   22.78 +/* These are the CPU types understood by this disassembler */
   22.79 +#define TYPE_68000 1
   22.80 +#define TYPE_68010 2
   22.81 +#define TYPE_68020 4
   22.82 +#define TYPE_68030 8
   22.83 +#define TYPE_68040 16
   22.84 +
   22.85 +#define M68000_ONLY		TYPE_68000
   22.86 +
   22.87 +#define M68010_ONLY		TYPE_68010
   22.88 +#define M68010_LESS		(TYPE_68000 | TYPE_68010)
   22.89 +#define M68010_PLUS		(TYPE_68010 | TYPE_68020 | TYPE_68030 | TYPE_68040)
   22.90 +
   22.91 +#define M68020_ONLY 	TYPE_68020
   22.92 +#define M68020_LESS 	(TYPE_68010 | TYPE_68020)
   22.93 +#define M68020_PLUS		(TYPE_68020 | TYPE_68030 | TYPE_68040)
   22.94 +
   22.95 +#define M68030_ONLY 	TYPE_68030
   22.96 +#define M68030_LESS 	(TYPE_68010 | TYPE_68020 | TYPE_68030)
   22.97 +#define M68030_PLUS		(TYPE_68030 | TYPE_68040)
   22.98 +
   22.99 +#define M68040_PLUS		TYPE_68040
  22.100 +
  22.101 +
  22.102 +/* Extension word formats */
  22.103 +#define EXT_8BIT_DISPLACEMENT(A)          ((A)&0xff)
  22.104 +#define EXT_FULL(A)                       BIT_8(A)
  22.105 +#define EXT_EFFECTIVE_ZERO(A)             (((A)&0xe4) == 0xc4 || ((A)&0xe2) == 0xc0)
  22.106 +#define EXT_BASE_REGISTER_PRESENT(A)      (!BIT_7(A))
  22.107 +#define EXT_INDEX_REGISTER_PRESENT(A)     (!BIT_6(A))
  22.108 +#define EXT_INDEX_REGISTER(A)             (((A)>>12)&7)
  22.109 +#define EXT_INDEX_PRE_POST(A)             (EXT_INDEX_PRESENT(A) && (A)&3)
  22.110 +#define EXT_INDEX_PRE(A)                  (EXT_INDEX_PRESENT(A) && ((A)&7) < 4 && ((A)&7) != 0)
  22.111 +#define EXT_INDEX_POST(A)                 (EXT_INDEX_PRESENT(A) && ((A)&7) > 4)
  22.112 +#define EXT_INDEX_SCALE(A)                (((A)>>9)&3)
  22.113 +#define EXT_INDEX_LONG(A)                 BIT_B(A)
  22.114 +#define EXT_INDEX_AR(A)                   BIT_F(A)
  22.115 +#define EXT_BASE_DISPLACEMENT_PRESENT(A)  (((A)&0x30) > 0x10)
  22.116 +#define EXT_BASE_DISPLACEMENT_WORD(A)     (((A)&0x30) == 0x20)
  22.117 +#define EXT_BASE_DISPLACEMENT_LONG(A)     (((A)&0x30) == 0x30)
  22.118 +#define EXT_OUTER_DISPLACEMENT_PRESENT(A) (((A)&3) > 1 && ((A)&0x47) < 0x44)
  22.119 +#define EXT_OUTER_DISPLACEMENT_WORD(A)    (((A)&3) == 2 && ((A)&0x47) < 0x44)
  22.120 +#define EXT_OUTER_DISPLACEMENT_LONG(A)    (((A)&3) == 3 && ((A)&0x47) < 0x44)
  22.121 +
  22.122 +
  22.123 +
  22.124 +/* ======================================================================== */
  22.125 +/* =============================== PROTOTYPES ============================= */
  22.126 +/* ======================================================================== */
  22.127 +
  22.128 +/* Read data at the PC and increment PC */
  22.129 +uint  read_imm_8(void);
  22.130 +uint  read_imm_16(void);
  22.131 +uint  read_imm_32(void);
  22.132 +
  22.133 +/* Read data at the PC but don't imcrement the PC */
  22.134 +uint  peek_imm_8(void);
  22.135 +uint  peek_imm_16(void);
  22.136 +uint  peek_imm_32(void);
  22.137 +
  22.138 +/* make signed integers 100% portably */
  22.139 +static int make_int_8(int value);
  22.140 +static int make_int_16(int value);
  22.141 +
  22.142 +/* make a string of a hex value */
  22.143 +static char* make_signed_hex_str_8(uint val);
  22.144 +static char* make_signed_hex_str_16(uint val);
  22.145 +static char* make_signed_hex_str_32(uint val);
  22.146 +
  22.147 +/* make string of ea mode */
  22.148 +static char* get_ea_mode_str(uint instruction, uint size);
  22.149 +
  22.150 +char* get_ea_mode_str_8(uint instruction);
  22.151 +char* get_ea_mode_str_16(uint instruction);
  22.152 +char* get_ea_mode_str_32(uint instruction);
  22.153 +
  22.154 +/* make string of immediate value */
  22.155 +static char* get_imm_str_s(uint size);
  22.156 +static char* get_imm_str_u(uint size);
  22.157 +
  22.158 +char* get_imm_str_s8(void);
  22.159 +char* get_imm_str_s16(void);
  22.160 +char* get_imm_str_s32(void);
  22.161 +
  22.162 +/* Stuff to build the opcode handler jump table */
  22.163 +static void  build_opcode_table(void);
  22.164 +static int   valid_ea(uint opcode, uint mask);
  22.165 +static int DECL_SPEC compare_nof_true_bits(const void *aptr, const void *bptr);
  22.166 +
  22.167 +/* used to build opcode handler jump table */
  22.168 +typedef struct
  22.169 +{
  22.170 +	void (*opcode_handler)(void); /* handler function */
  22.171 +	uint mask;                    /* mask on opcode */
  22.172 +	uint match;                   /* what to match after masking */
  22.173 +	uint ea_mask;                 /* what ea modes are allowed */
  22.174 +} opcode_struct;
  22.175 +
  22.176 +
  22.177 +
  22.178 +/* ======================================================================== */
  22.179 +/* ================================= DATA ================================= */
  22.180 +/* ======================================================================== */
  22.181 +
  22.182 +/* Opcode handler jump table */
  22.183 +static void (*g_instruction_table[0x10000])(void);
  22.184 +/* Flag if disassembler initialized */
  22.185 +static int  g_initialized = 0;
  22.186 +
  22.187 +/* Address mask to simulate address lines */
  22.188 +static unsigned int g_address_mask = 0xffffffff;
  22.189 +
  22.190 +static char g_dasm_str[100]; /* string to hold disassembly */
  22.191 +static char g_helper_str[100]; /* string to hold helpful info */
  22.192 +static uint g_cpu_pc;        /* program counter */
  22.193 +static uint g_cpu_ir;        /* instruction register */
  22.194 +static uint g_cpu_type;
  22.195 +
  22.196 +/* used by ops like asr, ror, addq, etc */
  22.197 +static uint g_3bit_qdata_table[8] = {8, 1, 2, 3, 4, 5, 6, 7};
  22.198 +
  22.199 +static uint g_5bit_data_table[32] =
  22.200 +{
  22.201 +	32,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
  22.202 +	16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
  22.203 +};
  22.204 +
  22.205 +static char* g_cc[16] =
  22.206 +{"t", "f", "hi", "ls", "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi", "ge", "lt", "gt", "le"};
  22.207 +
  22.208 +static char* g_cpcc[64] =
  22.209 +{/* 000    001    010    011    100    101    110    111 */
  22.210 +	  "f",  "eq", "ogt", "oge", "olt", "ole", "ogl",  "or", /* 000 */
  22.211 +	 "un", "ueq", "ugt", "uge", "ult", "ule",  "ne",   "t", /* 001 */
  22.212 +	 "sf", "seq",  "gt",  "ge",  "lt",  "le",  "gl"  "gle", /* 010 */
  22.213 +  "ngle", "ngl", "nle", "nlt", "nge", "ngt", "sne",  "st", /* 011 */
  22.214 +	  "?",   "?",   "?",   "?",   "?",   "?",   "?",   "?", /* 100 */
  22.215 +	  "?",   "?",   "?",   "?",   "?",   "?",   "?",   "?", /* 101 */
  22.216 +	  "?",   "?",   "?",   "?",   "?",   "?",   "?",   "?", /* 110 */
  22.217 +	  "?",   "?",   "?",   "?",   "?",   "?",   "?",   "?"  /* 111 */
  22.218 +};
  22.219 +
  22.220 +
  22.221 +/* ======================================================================== */
  22.222 +/* =========================== UTILITY FUNCTIONS ========================== */
  22.223 +/* ======================================================================== */
  22.224 +
  22.225 +#define LIMIT_CPU_TYPES(ALLOWED_CPU_TYPES)	\
  22.226 +	if(!(g_cpu_type & ALLOWED_CPU_TYPES))	\
  22.227 +	{										\
  22.228 +		d68000_illegal();					\
  22.229 +		return;								\
  22.230 +	}
  22.231 +
  22.232 +#define read_imm_8()  (m68k_read_disassembler_16(((g_cpu_pc+=2)-2)&g_address_mask)&0xff)
  22.233 +#define read_imm_16() m68k_read_disassembler_16(((g_cpu_pc+=2)-2)&g_address_mask)
  22.234 +#define read_imm_32() m68k_read_disassembler_32(((g_cpu_pc+=4)-4)&g_address_mask)
  22.235 +
  22.236 +#define peek_imm_8()  (m68k_read_disassembler_16(g_cpu_pc & g_address_mask)&0xff)
  22.237 +#define peek_imm_16() m68k_read_disassembler_16(g_cpu_pc & g_address_mask)
  22.238 +#define peek_imm_32() m68k_read_disassembler_32(g_cpu_pc & g_address_mask)
  22.239 +
  22.240 +/* Fake a split interface */
  22.241 +#define get_ea_mode_str_8(instruction) get_ea_mode_str(instruction, 0)
  22.242 +#define get_ea_mode_str_16(instruction) get_ea_mode_str(instruction, 1)
  22.243 +#define get_ea_mode_str_32(instruction) get_ea_mode_str(instruction, 2)
  22.244 +
  22.245 +#define get_imm_str_s8() get_imm_str_s(0)
  22.246 +#define get_imm_str_s16() get_imm_str_s(1)
  22.247 +#define get_imm_str_s32() get_imm_str_s(2)
  22.248 +
  22.249 +#define get_imm_str_u8() get_imm_str_u(0)
  22.250 +#define get_imm_str_u16() get_imm_str_u(1)
  22.251 +#define get_imm_str_u32() get_imm_str_u(2)
  22.252 +
  22.253 +
  22.254 +/* 100% portable signed int generators */
  22.255 +static int make_int_8(int value)
  22.256 +{
  22.257 +	return (value & 0x80) ? value | ~0xff : value & 0xff;
  22.258 +}
  22.259 +
  22.260 +static int make_int_16(int value)
  22.261 +{
  22.262 +	return (value & 0x8000) ? value | ~0xffff : value & 0xffff;
  22.263 +}
  22.264 +
  22.265 +
  22.266 +/* Get string representation of hex values */
  22.267 +static char* make_signed_hex_str_8(uint val)
  22.268 +{
  22.269 +	static char str[20];
  22.270 +
  22.271 +	val &= 0xff;
  22.272 +
  22.273 +	if(val == 0x80)
  22.274 +		sprintf(str, "-$80");
  22.275 +	else if(val & 0x80)
  22.276 +		sprintf(str, "-$%x", (0-val) & 0x7f);
  22.277 +	else
  22.278 +		sprintf(str, "$%x", val & 0x7f);
  22.279 +
  22.280 +	return str;
  22.281 +}
  22.282 +
  22.283 +static char* make_signed_hex_str_16(uint val)
  22.284 +{
  22.285 +	static char str[20];
  22.286 +
  22.287 +	val &= 0xffff;
  22.288 +
  22.289 +	if(val == 0x8000)
  22.290 +		sprintf(str, "-$8000");
  22.291 +	else if(val & 0x8000)
  22.292 +		sprintf(str, "-$%x", (0-val) & 0x7fff);
  22.293 +	else
  22.294 +		sprintf(str, "$%x", val & 0x7fff);
  22.295 +
  22.296 +	return str;
  22.297 +}
  22.298 +
  22.299 +static char* make_signed_hex_str_32(uint val)
  22.300 +{
  22.301 +	static char str[20];
  22.302 +
  22.303 +	val &= 0xffffffff;
  22.304 +
  22.305 +	if(val == 0x80000000)
  22.306 +		sprintf(str, "-$80000000");
  22.307 +	else if(val & 0x80000000)
  22.308 +		sprintf(str, "-$%x", (0-val) & 0x7fffffff);
  22.309 +	else
  22.310 +		sprintf(str, "$%x", val & 0x7fffffff);
  22.311 +
  22.312 +	return str;
  22.313 +}
  22.314 +
  22.315 +
  22.316 +/* make string of immediate value */
  22.317 +static char* get_imm_str_s(uint size)
  22.318 +{
  22.319 +	static char str[15];
  22.320 +	if(size == 0)
  22.321 +		sprintf(str, "#%s", make_signed_hex_str_8(read_imm_8()));
  22.322 +	else if(size == 1)
  22.323 +		sprintf(str, "#%s", make_signed_hex_str_16(read_imm_16()));
  22.324 +	else
  22.325 +		sprintf(str, "#%s", make_signed_hex_str_32(read_imm_32()));
  22.326 +	return str;
  22.327 +}
  22.328 +
  22.329 +static char* get_imm_str_u(uint size)
  22.330 +{
  22.331 +	static char str[15];
  22.332 +	if(size == 0)
  22.333 +		sprintf(str, "#$%x", read_imm_8() & 0xff);
  22.334 +	else if(size == 1)
  22.335 +		sprintf(str, "#$%x", read_imm_16() & 0xffff);
  22.336 +	else
  22.337 +		sprintf(str, "#$%x", read_imm_32() & 0xffffffff);
  22.338 +	return str;
  22.339 +}
  22.340 +
  22.341 +/* Make string of effective address mode */
  22.342 +static char* get_ea_mode_str(uint instruction, uint size)
  22.343 +{
  22.344 +	static char b1[64];
  22.345 +	static char b2[64];
  22.346 +	static char* mode = b2;
  22.347 +	uint extension;
  22.348 +	uint base;
  22.349 +	uint outer;
  22.350 +	char base_reg[4];
  22.351 +	char index_reg[8];
  22.352 +	uint preindex;
  22.353 +	uint postindex;
  22.354 +	uint comma = 0;
  22.355 +	uint temp_value;
  22.356 +
  22.357 +	/* Switch buffers so we don't clobber on a double-call to this function */
  22.358 +	mode = mode == b1 ? b2 : b1;
  22.359 +
  22.360 +	switch(instruction & 0x3f)
  22.361 +	{
  22.362 +		case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
  22.363 +		/* data register direct */
  22.364 +			sprintf(mode, "D%d", instruction&7);
  22.365 +			break;
  22.366 +		case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
  22.367 +		/* address register direct */
  22.368 +			sprintf(mode, "A%d", instruction&7);
  22.369 +			break;
  22.370 +		case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
  22.371 +		/* address register indirect */
  22.372 +			sprintf(mode, "(A%d)", instruction&7);
  22.373 +			break;
  22.374 +		case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
  22.375 +		/* address register indirect with postincrement */
  22.376 +			sprintf(mode, "(A%d)+", instruction&7);
  22.377 +			break;
  22.378 +		case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
  22.379 +		/* address register indirect with predecrement */
  22.380 +			sprintf(mode, "-(A%d)", instruction&7);
  22.381 +			break;
  22.382 +		case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
  22.383 +		/* address register indirect with displacement*/
  22.384 +			sprintf(mode, "(%s,A%d)", make_signed_hex_str_16(read_imm_16()), instruction&7);
  22.385 +			break;
  22.386 +		case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
  22.387 +		/* address register indirect with index */
  22.388 +			extension = read_imm_16();
  22.389 +
  22.390 +			if(EXT_FULL(extension))
  22.391 +			{
  22.392 +				if(EXT_EFFECTIVE_ZERO(extension))
  22.393 +				{
  22.394 +					strcpy(mode, "0");
  22.395 +					break;
  22.396 +				}
  22.397 +				base = EXT_BASE_DISPLACEMENT_PRESENT(extension) ? (EXT_BASE_DISPLACEMENT_LONG(extension) ? read_imm_32() : read_imm_16()) : 0;
  22.398 +				outer = EXT_OUTER_DISPLACEMENT_PRESENT(extension) ? (EXT_OUTER_DISPLACEMENT_LONG(extension) ? read_imm_32() : read_imm_16()) : 0;
  22.399 +				if(EXT_BASE_REGISTER_PRESENT(extension))
  22.400 +					sprintf(base_reg, "A%d", instruction&7);
  22.401 +				else
  22.402 +					*base_reg = 0;
  22.403 +				if(EXT_INDEX_REGISTER_PRESENT(extension))
  22.404 +				{
  22.405 +					sprintf(index_reg, "%c%d.%c", EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
  22.406 +					if(EXT_INDEX_SCALE(extension))
  22.407 +						sprintf(index_reg+strlen(index_reg), "*%d", 1 << EXT_INDEX_SCALE(extension));
  22.408 +				}
  22.409 +				else
  22.410 +					*index_reg = 0;
  22.411 +				preindex = (extension&7) > 0 && (extension&7) < 4;
  22.412 +				postindex = (extension&7) > 4;
  22.413 +
  22.414 +				strcpy(mode, "(");
  22.415 +				if(preindex || postindex)
  22.416 +					strcat(mode, "[");
  22.417 +				if(base)
  22.418 +				{
  22.419 +					strcat(mode, make_signed_hex_str_16(base));
  22.420 +					comma = 1;
  22.421 +				}
  22.422 +				if(*base_reg)
  22.423 +				{
  22.424 +					if(comma)
  22.425 +						strcat(mode, ",");
  22.426 +					strcat(mode, base_reg);
  22.427 +					comma = 1;
  22.428 +				}
  22.429 +				if(postindex)
  22.430 +				{
  22.431 +					strcat(mode, "]");
  22.432 +					comma = 1;
  22.433 +				}
  22.434 +				if(*index_reg)
  22.435 +				{
  22.436 +					if(comma)
  22.437 +						strcat(mode, ",");
  22.438 +					strcat(mode, index_reg);
  22.439 +					comma = 1;
  22.440 +				}
  22.441 +				if(preindex)
  22.442 +				{
  22.443 +					strcat(mode, "]");
  22.444 +					comma = 1;
  22.445 +				}
  22.446 +				if(outer)
  22.447 +				{
  22.448 +					if(comma)
  22.449 +						strcat(mode, ",");
  22.450 +					strcat(mode, make_signed_hex_str_16(outer));
  22.451 +				}
  22.452 +				strcat(mode, ")");
  22.453 +				break;
  22.454 +			}
  22.455 +
  22.456 +			if(EXT_8BIT_DISPLACEMENT(extension) == 0)
  22.457 +				sprintf(mode, "(A%d,%c%d.%c", instruction&7, EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
  22.458 +			else
  22.459 +				sprintf(mode, "(%s,A%d,%c%d.%c", make_signed_hex_str_8(extension), instruction&7, EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
  22.460 +			if(EXT_INDEX_SCALE(extension))
  22.461 +				sprintf(mode+strlen(mode), "*%d", 1 << EXT_INDEX_SCALE(extension));
  22.462 +			strcat(mode, ")");
  22.463 +			break;
  22.464 +		case 0x38:
  22.465 +		/* absolute short address */
  22.466 +			sprintf(mode, "$%x.w", read_imm_16());
  22.467 +			break;
  22.468 +		case 0x39:
  22.469 +		/* absolute long address */
  22.470 +			sprintf(mode, "$%x.l", read_imm_32());
  22.471 +			break;
  22.472 +		case 0x3a:
  22.473 +		/* program counter with displacement */
  22.474 +			temp_value = read_imm_16();
  22.475 +			sprintf(mode, "(%s,PC)", make_signed_hex_str_16(temp_value));
  22.476 +			sprintf(g_helper_str, "; ($%x)", (make_int_16(temp_value) + g_cpu_pc-2) & 0xffffffff);
  22.477 +			break;
  22.478 +		case 0x3b:
  22.479 +		/* program counter with index */
  22.480 +			extension = read_imm_16();
  22.481 +
  22.482 +			if(EXT_FULL(extension))
  22.483 +			{
  22.484 +				if(EXT_EFFECTIVE_ZERO(extension))
  22.485 +				{
  22.486 +					strcpy(mode, "0");
  22.487 +					break;
  22.488 +				}
  22.489 +				base = EXT_BASE_DISPLACEMENT_PRESENT(extension) ? (EXT_BASE_DISPLACEMENT_LONG(extension) ? read_imm_32() : read_imm_16()) : 0;
  22.490 +				outer = EXT_OUTER_DISPLACEMENT_PRESENT(extension) ? (EXT_OUTER_DISPLACEMENT_LONG(extension) ? read_imm_32() : read_imm_16()) : 0;
  22.491 +				if(EXT_BASE_REGISTER_PRESENT(extension))
  22.492 +					strcpy(base_reg, "PC");
  22.493 +				else
  22.494 +					*base_reg = 0;
  22.495 +				if(EXT_INDEX_REGISTER_PRESENT(extension))
  22.496 +				{
  22.497 +					sprintf(index_reg, "%c%d.%c", EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
  22.498 +					if(EXT_INDEX_SCALE(extension))
  22.499 +						sprintf(index_reg+strlen(index_reg), "*%d", 1 << EXT_INDEX_SCALE(extension));
  22.500 +				}
  22.501 +				else
  22.502 +					*index_reg = 0;
  22.503 +				preindex = (extension&7) > 0 && (extension&7) < 4;
  22.504 +				postindex = (extension&7) > 4;
  22.505 +
  22.506 +				strcpy(mode, "(");
  22.507 +				if(preindex || postindex)
  22.508 +					strcat(mode, "[");
  22.509 +				if(base)
  22.510 +				{
  22.511 +					strcat(mode, make_signed_hex_str_16(base));
  22.512 +					comma = 1;
  22.513 +				}
  22.514 +				if(*base_reg)
  22.515 +				{
  22.516 +					if(comma)
  22.517 +						strcat(mode, ",");
  22.518 +					strcat(mode, base_reg);
  22.519 +					comma = 1;
  22.520 +				}
  22.521 +				if(postindex)
  22.522 +				{
  22.523 +					strcat(mode, "]");
  22.524 +					comma = 1;
  22.525 +				}
  22.526 +				if(*index_reg)
  22.527 +				{
  22.528 +					if(comma)
  22.529 +						strcat(mode, ",");
  22.530 +					strcat(mode, index_reg);
  22.531 +					comma = 1;
  22.532 +				}
  22.533 +				if(preindex)
  22.534 +				{
  22.535 +					strcat(mode, "]");
  22.536 +					comma = 1;
  22.537 +				}
  22.538 +				if(outer)
  22.539 +				{
  22.540 +					if(comma)
  22.541 +						strcat(mode, ",");
  22.542 +					strcat(mode, make_signed_hex_str_16(outer));
  22.543 +				}
  22.544 +				strcat(mode, ")");
  22.545 +				break;
  22.546 +			}
  22.547 +
  22.548 +			if(EXT_8BIT_DISPLACEMENT(extension) == 0)
  22.549 +				sprintf(mode, "(PC,%c%d.%c", EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
  22.550 +			else
  22.551 +				sprintf(mode, "(%s,PC,%c%d.%c", make_signed_hex_str_8(extension), EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
  22.552 +			if(EXT_INDEX_SCALE(extension))
  22.553 +				sprintf(mode+strlen(mode), "*%d", 1 << EXT_INDEX_SCALE(extension));
  22.554 +			strcat(mode, ")");
  22.555 +			break;
  22.556 +		case 0x3c:
  22.557 +		/* Immediate */
  22.558 +			sprintf(mode, "%s", get_imm_str_u(size));
  22.559 +			break;
  22.560 +		default:
  22.561 +			sprintf(mode, "INVALID %x", instruction & 0x3f);
  22.562 +	}
  22.563 +	return mode;
  22.564 +}
  22.565 +
  22.566 +
  22.567 +
  22.568 +/* ======================================================================== */
  22.569 +/* ========================= INSTRUCTION HANDLERS ========================= */
  22.570 +/* ======================================================================== */
  22.571 +/* Instruction handler function names follow this convention:
  22.572 + *
  22.573 + * d68000_NAME_EXTENSIONS(void)
  22.574 + * where NAME is the name of the opcode it handles and EXTENSIONS are any
  22.575 + * extensions for special instances of that opcode.
  22.576 + *
  22.577 + * Examples:
  22.578 + *   d68000_add_er_8(): add opcode, from effective address to register,
  22.579 + *                      size = byte
  22.580 + *
  22.581 + *   d68000_asr_s_8(): arithmetic shift right, static count, size = byte
  22.582 + *
  22.583 + *
  22.584 + * Common extensions:
  22.585 + * 8   : size = byte
  22.586 + * 16  : size = word
  22.587 + * 32  : size = long
  22.588 + * rr  : register to register
  22.589 + * mm  : memory to memory
  22.590 + * r   : register
  22.591 + * s   : static
  22.592 + * er  : effective address -> register
  22.593 + * re  : register -> effective address
  22.594 + * ea  : using effective address mode of operation
  22.595 + * d   : data register direct
  22.596 + * a   : address register direct
  22.597 + * ai  : address register indirect
  22.598 + * pi  : address register indirect with postincrement
  22.599 + * pd  : address register indirect with predecrement
  22.600 + * di  : address register indirect with displacement
  22.601 + * ix  : address register indirect with index
  22.602 + * aw  : absolute word
  22.603 + * al  : absolute long
  22.604 + */
  22.605 +
  22.606 +static void d68000_illegal(void)
  22.607 +{
  22.608 +	sprintf(g_dasm_str, "dc.w $%04x; ILLEGAL", g_cpu_ir);
  22.609 +}
  22.610 +
  22.611 +static void d68000_1010(void)
  22.612 +{
  22.613 +	sprintf(g_dasm_str, "dc.w    $%04x; opcode 1010", g_cpu_ir);
  22.614 +}
  22.615 +
  22.616 +
  22.617 +static void d68000_1111(void)
  22.618 +{
  22.619 +	sprintf(g_dasm_str, "dc.w    $%04x; opcode 1111", g_cpu_ir);
  22.620 +}
  22.621 +
  22.622 +
  22.623 +static void d68000_abcd_rr(void)
  22.624 +{
  22.625 +	sprintf(g_dasm_str, "abcd    D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
  22.626 +}
  22.627 +
  22.628 +
  22.629 +static void d68000_abcd_mm(void)
  22.630 +{
  22.631 +	sprintf(g_dasm_str, "abcd    -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
  22.632 +}
  22.633 +
  22.634 +static void d68000_add_er_8(void)
  22.635 +{
  22.636 +	sprintf(g_dasm_str, "add.b   %s, D%d", get_ea_mode_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
  22.637 +}
  22.638 +
  22.639 +
  22.640 +static void d68000_add_er_16(void)
  22.641 +{
  22.642 +	sprintf(g_dasm_str, "add.w   %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
  22.643 +}
  22.644 +
  22.645 +static void d68000_add_er_32(void)
  22.646 +{
  22.647 +	sprintf(g_dasm_str, "add.l   %s, D%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
  22.648 +}
  22.649 +
  22.650 +static void d68000_add_re_8(void)
  22.651 +{
  22.652 +	sprintf(g_dasm_str, "add.b   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
  22.653 +}
  22.654 +
  22.655 +static void d68000_add_re_16(void)
  22.656 +{
  22.657 +	sprintf(g_dasm_str, "add.w   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_16(g_cpu_ir));
  22.658 +}
  22.659 +
  22.660 +static void d68000_add_re_32(void)
  22.661 +{
  22.662 +	sprintf(g_dasm_str, "add.l   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_32(g_cpu_ir));
  22.663 +}
  22.664 +
  22.665 +static void d68000_adda_16(void)
  22.666 +{
  22.667 +	sprintf(g_dasm_str, "adda.w  %s, A%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
  22.668 +}
  22.669 +
  22.670 +static void d68000_adda_32(void)
  22.671 +{
  22.672 +	sprintf(g_dasm_str, "adda.l  %s, A%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
  22.673 +}
  22.674 +
  22.675 +static void d68000_addi_8(void)
  22.676 +{
  22.677 +	char* str = get_imm_str_s8();
  22.678 +	sprintf(g_dasm_str, "addi.b  %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
  22.679 +}
  22.680 +
  22.681 +static void d68000_addi_16(void)
  22.682 +{
  22.683 +	char* str = get_imm_str_s16();
  22.684 +	sprintf(g_dasm_str, "addi.w  %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
  22.685 +}
  22.686 +
  22.687 +static void d68000_addi_32(void)
  22.688 +{
  22.689 +	char* str = get_imm_str_s32();
  22.690 +	sprintf(g_dasm_str, "addi.l  %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
  22.691 +}
  22.692 +
  22.693 +static void d68000_addq_8(void)
  22.694 +{
  22.695 +	sprintf(g_dasm_str, "addq.b  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_8(g_cpu_ir));
  22.696 +}
  22.697 +
  22.698 +static void d68000_addq_16(void)
  22.699 +{
  22.700 +	sprintf(g_dasm_str, "addq.w  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_16(g_cpu_ir));
  22.701 +}
  22.702 +
  22.703 +static void d68000_addq_32(void)
  22.704 +{
  22.705 +	sprintf(g_dasm_str, "addq.l  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_32(g_cpu_ir));
  22.706 +}
  22.707 +
  22.708 +static void d68000_addx_rr_8(void)
  22.709 +{
  22.710 +	sprintf(g_dasm_str, "addx.b  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
  22.711 +}
  22.712 +
  22.713 +static void d68000_addx_rr_16(void)
  22.714 +{
  22.715 +	sprintf(g_dasm_str, "addx.w  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
  22.716 +}
  22.717 +
  22.718 +static void d68000_addx_rr_32(void)
  22.719 +{
  22.720 +	sprintf(g_dasm_str, "addx.l  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
  22.721 +}
  22.722 +
  22.723 +static void d68000_addx_mm_8(void)
  22.724 +{
  22.725 +	sprintf(g_dasm_str, "addx.b  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
  22.726 +}
  22.727 +
  22.728 +static void d68000_addx_mm_16(void)
  22.729 +{
  22.730 +	sprintf(g_dasm_str, "addx.w  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
  22.731 +}
  22.732 +
  22.733 +static void d68000_addx_mm_32(void)
  22.734 +{
  22.735 +	sprintf(g_dasm_str, "addx.l  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
  22.736 +}
  22.737 +
  22.738 +static void d68000_and_er_8(void)
  22.739 +{
  22.740 +	sprintf(g_dasm_str, "and.b   %s, D%d", get_ea_mode_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
  22.741 +}
  22.742 +
  22.743 +static void d68000_and_er_16(void)
  22.744 +{
  22.745 +	sprintf(g_dasm_str, "and.w   %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
  22.746 +}
  22.747 +
  22.748 +static void d68000_and_er_32(void)
  22.749 +{
  22.750 +	sprintf(g_dasm_str, "and.l   %s, D%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
  22.751 +}
  22.752 +
  22.753 +static void d68000_and_re_8(void)
  22.754 +{
  22.755 +	sprintf(g_dasm_str, "and.b   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
  22.756 +}
  22.757 +
  22.758 +static void d68000_and_re_16(void)
  22.759 +{
  22.760 +	sprintf(g_dasm_str, "and.w   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_16(g_cpu_ir));
  22.761 +}
  22.762 +
  22.763 +static void d68000_and_re_32(void)
  22.764 +{
  22.765 +	sprintf(g_dasm_str, "and.l   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_32(g_cpu_ir));
  22.766 +}
  22.767 +
  22.768 +static void d68000_andi_8(void)
  22.769 +{
  22.770 +	char* str = get_imm_str_u8();
  22.771 +	sprintf(g_dasm_str, "andi.b  %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
  22.772 +}
  22.773 +
  22.774 +static void d68000_andi_16(void)
  22.775 +{
  22.776 +	char* str = get_imm_str_u16();
  22.777 +	sprintf(g_dasm_str, "andi.w  %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
  22.778 +}
  22.779 +
  22.780 +static void d68000_andi_32(void)
  22.781 +{
  22.782 +	char* str = get_imm_str_u32();
  22.783 +	sprintf(g_dasm_str, "andi.l  %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
  22.784 +}
  22.785 +
  22.786 +static void d68000_andi_to_ccr(void)
  22.787 +{
  22.788 +	sprintf(g_dasm_str, "andi    %s, CCR", get_imm_str_u8());
  22.789 +}
  22.790 +
  22.791 +static void d68000_andi_to_sr(void)
  22.792 +{
  22.793 +	sprintf(g_dasm_str, "andi    %s, SR", get_imm_str_u16());
  22.794 +}
  22.795 +
  22.796 +static void d68000_asr_s_8(void)
  22.797 +{
  22.798 +	sprintf(g_dasm_str, "asr.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
  22.799 +}
  22.800 +
  22.801 +static void d68000_asr_s_16(void)
  22.802 +{
  22.803 +	sprintf(g_dasm_str, "asr.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
  22.804 +}
  22.805 +
  22.806 +static void d68000_asr_s_32(void)
  22.807 +{
  22.808 +	sprintf(g_dasm_str, "asr.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
  22.809 +}
  22.810 +
  22.811 +static void d68000_asr_r_8(void)
  22.812 +{
  22.813 +	sprintf(g_dasm_str, "asr.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
  22.814 +}
  22.815 +
  22.816 +static void d68000_asr_r_16(void)
  22.817 +{
  22.818 +	sprintf(g_dasm_str, "asr.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
  22.819 +}
  22.820 +
  22.821 +static void d68000_asr_r_32(void)
  22.822 +{
  22.823 +	sprintf(g_dasm_str, "asr.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
  22.824 +}
  22.825 +
  22.826 +static void d68000_asr_ea(void)
  22.827 +{
  22.828 +	sprintf(g_dasm_str, "asr.w   %s", get_ea_mode_str_16(g_cpu_ir));
  22.829 +}
  22.830 +
  22.831 +static void d68000_asl_s_8(void)
  22.832 +{
  22.833 +	sprintf(g_dasm_str, "asl.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
  22.834 +}
  22.835 +
  22.836 +static void d68000_asl_s_16(void)
  22.837 +{
  22.838 +	sprintf(g_dasm_str, "asl.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
  22.839 +}
  22.840 +
  22.841 +static void d68000_asl_s_32(void)
  22.842 +{
  22.843 +	sprintf(g_dasm_str, "asl.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
  22.844 +}
  22.845 +
  22.846 +static void d68000_asl_r_8(void)
  22.847 +{
  22.848 +	sprintf(g_dasm_str, "asl.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
  22.849 +}
  22.850 +
  22.851 +static void d68000_asl_r_16(void)
  22.852 +{
  22.853 +	sprintf(g_dasm_str, "asl.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
  22.854 +}
  22.855 +
  22.856 +static void d68000_asl_r_32(void)
  22.857 +{
  22.858 +	sprintf(g_dasm_str, "asl.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
  22.859 +}
  22.860 +
  22.861 +static void d68000_asl_ea(void)
  22.862 +{
  22.863 +	sprintf(g_dasm_str, "asl.w   %s", get_ea_mode_str_16(g_cpu_ir));
  22.864 +}
  22.865 +
  22.866 +static void d68000_bcc_8(void)
  22.867 +{
  22.868 +	uint temp_pc = g_cpu_pc;
  22.869 +	sprintf(g_dasm_str, "b%-2s     %x", g_cc[(g_cpu_ir>>8)&0xf], temp_pc + make_int_8(g_cpu_ir));
  22.870 +}
  22.871 +
  22.872 +static void d68000_bcc_16(void)
  22.873 +{
  22.874 +	uint temp_pc = g_cpu_pc;
  22.875 +	sprintf(g_dasm_str, "b%-2s     %x", g_cc[(g_cpu_ir>>8)&0xf], temp_pc + make_int_16(read_imm_16()));
  22.876 +}
  22.877 +
  22.878 +static void d68020_bcc_32(void)
  22.879 +{
  22.880 +	uint temp_pc = g_cpu_pc;
  22.881 +	LIMIT_CPU_TYPES(M68020_PLUS);
  22.882 +	sprintf(g_dasm_str, "b%-2s     %x; (2+)", g_cc[(g_cpu_ir>>8)&0xf], temp_pc + read_imm_32());
  22.883 +}
  22.884 +
  22.885 +static void d68000_bchg_r(void)
  22.886 +{
  22.887 +	sprintf(g_dasm_str, "bchg    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
  22.888 +}
  22.889 +
  22.890 +static void d68000_bchg_s(void)
  22.891 +{
  22.892 +	char* str = get_imm_str_u8();
  22.893 +	sprintf(g_dasm_str, "bchg    %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
  22.894 +}
  22.895 +
  22.896 +static void d68000_bclr_r(void)
  22.897 +{
  22.898 +	sprintf(g_dasm_str, "bclr    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
  22.899 +}
  22.900 +
  22.901 +static void d68000_bclr_s(void)
  22.902 +{
  22.903 +	char* str = get_imm_str_u8();
  22.904 +	sprintf(g_dasm_str, "bclr    %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
  22.905 +}
  22.906 +
  22.907 +static void d68010_bkpt(void)
  22.908 +{
  22.909 +	LIMIT_CPU_TYPES(M68010_PLUS);
  22.910 +	sprintf(g_dasm_str, "bkpt #%d; (1+)", g_cpu_ir&7);
  22.911 +}
  22.912 +
  22.913 +static void d68020_bfchg(void)
  22.914 +{
  22.915 +	uint extension;
  22.916 +	char offset[3];
  22.917 +	char width[3];
  22.918 +
  22.919 +	LIMIT_CPU_TYPES(M68020_PLUS);
  22.920 +
  22.921 +	extension = read_imm_16();
  22.922 +
  22.923 +	if(BIT_B(extension))
  22.924 +		sprintf(offset, "D%d", (extension>>6)&7);
  22.925 +	else
  22.926 +		sprintf(offset, "%d", (extension>>6)&31);
  22.927 +	if(BIT_5(extension))
  22.928 +		sprintf(width, "D%d", extension&7);
  22.929 +	else
  22.930 +		sprintf(width, "%d", g_5bit_data_table[extension&31]);
  22.931 +	sprintf(g_dasm_str, "bfchg   %s {%s:%s}; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width);
  22.932 +}
  22.933 +
  22.934 +static void d68020_bfclr(void)
  22.935 +{
  22.936 +	uint extension;
  22.937 +	char offset[3];
  22.938 +	char width[3];
  22.939 +
  22.940 +	LIMIT_CPU_TYPES(M68020_PLUS);
  22.941 +
  22.942 +	extension = read_imm_16();
  22.943 +
  22.944 +	if(BIT_B(extension))
  22.945 +		sprintf(offset, "D%d", (extension>>6)&7);
  22.946 +	else
  22.947 +		sprintf(offset, "%d", (extension>>6)&31);
  22.948 +	if(BIT_5(extension))
  22.949 +		sprintf(width, "D%d", extension&7);
  22.950 +	else
  22.951 +		sprintf(width, "%d", g_5bit_data_table[extension&31]);
  22.952 +	sprintf(g_dasm_str, "bfclr   %s {%s:%s}; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width);
  22.953 +}
  22.954 +
  22.955 +static void d68020_bfexts(void)
  22.956 +{
  22.957 +	uint extension;
  22.958 +	char offset[3];
  22.959 +	char width[3];
  22.960 +
  22.961 +	LIMIT_CPU_TYPES(M68020_PLUS);
  22.962 +
  22.963 +	extension = read_imm_16();
  22.964 +
  22.965 +	if(BIT_B(extension))
  22.966 +		sprintf(offset, "D%d", (extension>>6)&7);
  22.967 +	else
  22.968 +		sprintf(offset, "%d", (extension>>6)&31);
  22.969 +	if(BIT_5(extension))
  22.970 +		sprintf(width, "D%d", extension&7);
  22.971 +	else
  22.972 +		sprintf(width, "%d", g_5bit_data_table[extension&31]);
  22.973 +	sprintf(g_dasm_str, "bfexts  D%d, %s {%s:%s}; (2+)", (extension>>12)&7, get_ea_mode_str_8(g_cpu_ir), offset, width);
  22.974 +}
  22.975 +
  22.976 +static void d68020_bfextu(void)
  22.977 +{
  22.978 +	uint extension;
  22.979 +	char offset[3];
  22.980 +	char width[3];
  22.981 +
  22.982 +	LIMIT_CPU_TYPES(M68020_PLUS);
  22.983 +
  22.984 +	extension = read_imm_16();
  22.985 +
  22.986 +	if(BIT_B(extension))
  22.987 +		sprintf(offset, "D%d", (extension>>6)&7);
  22.988 +	else
  22.989 +		sprintf(offset, "%d", (extension>>6)&31);
  22.990 +	if(BIT_5(extension))
  22.991 +		sprintf(width, "D%d", extension&7);
  22.992 +	else
  22.993 +		sprintf(width, "%d", g_5bit_data_table[extension&31]);
  22.994 +	sprintf(g_dasm_str, "bfextu  D%d, %s {%s:%s}; (2+)", (extension>>12)&7, get_ea_mode_str_8(g_cpu_ir), offset, width);
  22.995 +}
  22.996 +
  22.997 +static void d68020_bfffo(void)
  22.998 +{
  22.999 +	uint extension;
 22.1000 +	char offset[3];
 22.1001 +	char width[3];
 22.1002 +
 22.1003 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1004 +
 22.1005 +	extension = read_imm_16();
 22.1006 +
 22.1007 +	if(BIT_B(extension))
 22.1008 +		sprintf(offset, "D%d", (extension>>6)&7);
 22.1009 +	else
 22.1010 +		sprintf(offset, "%d", (extension>>6)&31);
 22.1011 +	if(BIT_5(extension))
 22.1012 +		sprintf(width, "D%d", extension&7);
 22.1013 +	else
 22.1014 +		sprintf(width, "%d", g_5bit_data_table[extension&31]);
 22.1015 +	sprintf(g_dasm_str, "bfffo   D%d, %s {%s:%s}; (2+)", (extension>>12)&7, get_ea_mode_str_8(g_cpu_ir), offset, width);
 22.1016 +}
 22.1017 +
 22.1018 +static void d68020_bfins(void)
 22.1019 +{
 22.1020 +	uint extension;
 22.1021 +	char offset[3];
 22.1022 +	char width[3];
 22.1023 +
 22.1024 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1025 +
 22.1026 +	extension = read_imm_16();
 22.1027 +
 22.1028 +	if(BIT_B(extension))
 22.1029 +		sprintf(offset, "D%d", (extension>>6)&7);
 22.1030 +	else
 22.1031 +		sprintf(offset, "%d", (extension>>6)&31);
 22.1032 +	if(BIT_5(extension))
 22.1033 +		sprintf(width, "D%d", extension&7);
 22.1034 +	else
 22.1035 +		sprintf(width, "%d", g_5bit_data_table[extension&31]);
 22.1036 +	sprintf(g_dasm_str, "bfins   D%d, %s {%s:%s}; (2+)", (extension>>12)&7, get_ea_mode_str_8(g_cpu_ir), offset, width);
 22.1037 +}
 22.1038 +
 22.1039 +static void d68020_bfset(void)
 22.1040 +{
 22.1041 +	uint extension;
 22.1042 +	char offset[3];
 22.1043 +	char width[3];
 22.1044 +
 22.1045 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1046 +
 22.1047 +	extension = read_imm_16();
 22.1048 +
 22.1049 +	if(BIT_B(extension))
 22.1050 +		sprintf(offset, "D%d", (extension>>6)&7);
 22.1051 +	else
 22.1052 +		sprintf(offset, "%d", (extension>>6)&31);
 22.1053 +	if(BIT_5(extension))
 22.1054 +		sprintf(width, "D%d", extension&7);
 22.1055 +	else
 22.1056 +		sprintf(width, "%d", g_5bit_data_table[extension&31]);
 22.1057 +	sprintf(g_dasm_str, "bfset   %s {%s:%s}; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width);
 22.1058 +}
 22.1059 +
 22.1060 +static void d68020_bftst(void)
 22.1061 +{
 22.1062 +	uint extension;
 22.1063 +	char offset[3];
 22.1064 +	char width[3];
 22.1065 +
 22.1066 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1067 +
 22.1068 +	extension = read_imm_16();
 22.1069 +
 22.1070 +	if(BIT_B(extension))
 22.1071 +		sprintf(offset, "D%d", (extension>>6)&7);
 22.1072 +	else
 22.1073 +		sprintf(offset, "%d", (extension>>6)&31);
 22.1074 +	if(BIT_5(extension))
 22.1075 +		sprintf(width, "D%d", extension&7);
 22.1076 +	else
 22.1077 +		sprintf(width, "%d", g_5bit_data_table[extension&31]);
 22.1078 +	sprintf(g_dasm_str, "bftst   %s {%s:%s}; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width);
 22.1079 +}
 22.1080 +
 22.1081 +static void d68000_bra_8(void)
 22.1082 +{
 22.1083 +	uint temp_pc = g_cpu_pc;
 22.1084 +	sprintf(g_dasm_str, "bra     %x", temp_pc + make_int_8(g_cpu_ir));
 22.1085 +}
 22.1086 +
 22.1087 +static void d68000_bra_16(void)
 22.1088 +{
 22.1089 +	uint temp_pc = g_cpu_pc;
 22.1090 +	sprintf(g_dasm_str, "bra     %x", temp_pc + make_int_16(read_imm_16()));
 22.1091 +}
 22.1092 +
 22.1093 +static void d68020_bra_32(void)
 22.1094 +{
 22.1095 +	uint temp_pc = g_cpu_pc;
 22.1096 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1097 +	sprintf(g_dasm_str, "bra     %x; (2+)", temp_pc + read_imm_32());
 22.1098 +}
 22.1099 +
 22.1100 +static void d68000_bset_r(void)
 22.1101 +{
 22.1102 +	sprintf(g_dasm_str, "bset    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
 22.1103 +}
 22.1104 +
 22.1105 +static void d68000_bset_s(void)
 22.1106 +{
 22.1107 +	char* str = get_imm_str_u8();
 22.1108 +	sprintf(g_dasm_str, "bset    %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
 22.1109 +}
 22.1110 +
 22.1111 +static void d68000_bsr_8(void)
 22.1112 +{
 22.1113 +	uint temp_pc = g_cpu_pc;
 22.1114 +	sprintf(g_dasm_str, "bsr     %x", temp_pc + make_int_8(g_cpu_ir));
 22.1115 +}
 22.1116 +
 22.1117 +static void d68000_bsr_16(void)
 22.1118 +{
 22.1119 +	uint temp_pc = g_cpu_pc;
 22.1120 +	sprintf(g_dasm_str, "bsr     %x", temp_pc + make_int_16(read_imm_16()));
 22.1121 +}
 22.1122 +
 22.1123 +static void d68020_bsr_32(void)
 22.1124 +{
 22.1125 +	uint temp_pc = g_cpu_pc;
 22.1126 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1127 +	sprintf(g_dasm_str, "bsr     %x; (2+)", temp_pc + peek_imm_32());
 22.1128 +}
 22.1129 +
 22.1130 +static void d68000_btst_r(void)
 22.1131 +{
 22.1132 +	sprintf(g_dasm_str, "btst    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
 22.1133 +}
 22.1134 +
 22.1135 +static void d68000_btst_s(void)
 22.1136 +{
 22.1137 +	char* str = get_imm_str_u8();
 22.1138 +	sprintf(g_dasm_str, "btst    %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
 22.1139 +}
 22.1140 +
 22.1141 +static void d68020_callm(void)
 22.1142 +{
 22.1143 +	char* str;
 22.1144 +	LIMIT_CPU_TYPES(M68020_ONLY);
 22.1145 +	str = get_imm_str_u8();
 22.1146 +
 22.1147 +	sprintf(g_dasm_str, "callm   %s, %s; (2)", str, get_ea_mode_str_8(g_cpu_ir));
 22.1148 +}
 22.1149 +
 22.1150 +static void d68020_cas_8(void)
 22.1151 +{
 22.1152 +	uint extension;
 22.1153 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1154 +	extension = read_imm_16();
 22.1155 +	sprintf(g_dasm_str, "cas.b   D%d, D%d, %s; (2+)", extension&7, (extension>>8)&7, get_ea_mode_str_8(g_cpu_ir));
 22.1156 +}
 22.1157 +
 22.1158 +static void d68020_cas_16(void)
 22.1159 +{
 22.1160 +	uint extension;
 22.1161 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1162 +	extension = read_imm_16();
 22.1163 +	sprintf(g_dasm_str, "cas.w   D%d, D%d, %s; (2+)", extension&7, (extension>>8)&7, get_ea_mode_str_16(g_cpu_ir));
 22.1164 +}
 22.1165 +
 22.1166 +static void d68020_cas_32(void)
 22.1167 +{
 22.1168 +	uint extension;
 22.1169 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1170 +	extension = read_imm_16();
 22.1171 +	sprintf(g_dasm_str, "cas.l   D%d, D%d, %s; (2+)", extension&7, (extension>>8)&7, get_ea_mode_str_32(g_cpu_ir));
 22.1172 +}
 22.1173 +
 22.1174 +static void d68020_cas2_16(void)
 22.1175 +{
 22.1176 +/* CAS2 Dc1:Dc2,Du1:Dc2:(Rn1):(Rn2)
 22.1177 +f e d c b a 9 8 7 6 5 4 3 2 1 0
 22.1178 + DARn1  0 0 0  Du1  0 0 0  Dc1
 22.1179 + DARn2  0 0 0  Du2  0 0 0  Dc2
 22.1180 +*/
 22.1181 +
 22.1182 +	uint extension;
 22.1183 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1184 +	extension = read_imm_32();
 22.1185 +	sprintf(g_dasm_str, "cas2.w  D%d:D%d:D%d:D%d, (%c%d):(%c%d); (2+)",
 22.1186 +		(extension>>16)&7, extension&7, (extension>>22)&7, (extension>>6)&7,
 22.1187 +		BIT_1F(extension) ? 'A' : 'D', (extension>>28)&7,
 22.1188 +		BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
 22.1189 +}
 22.1190 +
 22.1191 +static void d68020_cas2_32(void)
 22.1192 +{
 22.1193 +	uint extension;
 22.1194 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1195 +	extension = read_imm_32();
 22.1196 +	sprintf(g_dasm_str, "cas2.l  D%d:D%d:D%d:D%d, (%c%d):(%c%d); (2+)",
 22.1197 +		(extension>>16)&7, extension&7, (extension>>22)&7, (extension>>6)&7,
 22.1198 +		BIT_1F(extension) ? 'A' : 'D', (extension>>28)&7,
 22.1199 +		BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
 22.1200 +}
 22.1201 +
 22.1202 +static void d68000_chk_16(void)
 22.1203 +{
 22.1204 +	sprintf(g_dasm_str, "chk.w   %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1205 +}
 22.1206 +
 22.1207 +static void d68020_chk_32(void)
 22.1208 +{
 22.1209 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1210 +	sprintf(g_dasm_str, "chk.l   %s, D%d; (2+)", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1211 +}
 22.1212 +
 22.1213 +static void d68020_chk2_cmp2_8(void)
 22.1214 +{
 22.1215 +	uint extension;
 22.1216 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1217 +	extension = read_imm_16();
 22.1218 +	sprintf(g_dasm_str, "%s.b  %s, %c%d; (2+)", BIT_B(extension) ? "chk2" : "cmp2", get_ea_mode_str_8(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
 22.1219 +}
 22.1220 +
 22.1221 +static void d68020_chk2_cmp2_16(void)
 22.1222 +{
 22.1223 +	uint extension;
 22.1224 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1225 +	extension = read_imm_16();
 22.1226 +	sprintf(g_dasm_str, "%s.w  %s, %c%d; (2+)", BIT_B(extension) ? "chk2" : "cmp2", get_ea_mode_str_16(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
 22.1227 +}
 22.1228 +
 22.1229 +static void d68020_chk2_cmp2_32(void)
 22.1230 +{
 22.1231 +	uint extension;
 22.1232 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1233 +	extension = read_imm_16();
 22.1234 +	sprintf(g_dasm_str, "%s.l  %s, %c%d; (2+)", BIT_B(extension) ? "chk2" : "cmp2", get_ea_mode_str_32(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
 22.1235 +}
 22.1236 +
 22.1237 +static void d68040_cinv(void)
 22.1238 +{
 22.1239 +	LIMIT_CPU_TYPES(M68040_PLUS);
 22.1240 +	switch((g_cpu_ir>>3)&3)
 22.1241 +	{
 22.1242 +		case 0:
 22.1243 +			sprintf(g_dasm_str, "cinv (illegal scope); (4)");
 22.1244 +			break;
 22.1245 +		case 1:
 22.1246 +			sprintf(g_dasm_str, "cinvl   %d, (A%d); (4)", (g_cpu_ir>>6)&3, g_cpu_ir&7);
 22.1247 +			break;
 22.1248 +		case 2:
 22.1249 +			sprintf(g_dasm_str, "cinvp   %d, (A%d); (4)", (g_cpu_ir>>6)&3, g_cpu_ir&7);
 22.1250 +			break;
 22.1251 +		case 3:
 22.1252 +			sprintf(g_dasm_str, "cinva   %d; (4)", (g_cpu_ir>>6)&3);
 22.1253 +			break;
 22.1254 +	}
 22.1255 +}
 22.1256 +
 22.1257 +static void d68000_clr_8(void)
 22.1258 +{
 22.1259 +	sprintf(g_dasm_str, "clr.b   %s", get_ea_mode_str_8(g_cpu_ir));
 22.1260 +}
 22.1261 +
 22.1262 +static void d68000_clr_16(void)
 22.1263 +{
 22.1264 +	sprintf(g_dasm_str, "clr.w   %s", get_ea_mode_str_16(g_cpu_ir));
 22.1265 +}
 22.1266 +
 22.1267 +static void d68000_clr_32(void)
 22.1268 +{
 22.1269 +	sprintf(g_dasm_str, "clr.l   %s", get_ea_mode_str_32(g_cpu_ir));
 22.1270 +}
 22.1271 +
 22.1272 +static void d68000_cmp_8(void)
 22.1273 +{
 22.1274 +	sprintf(g_dasm_str, "cmp.b   %s, D%d", get_ea_mode_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1275 +}
 22.1276 +
 22.1277 +static void d68000_cmp_16(void)
 22.1278 +{
 22.1279 +	sprintf(g_dasm_str, "cmp.w   %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1280 +}
 22.1281 +
 22.1282 +static void d68000_cmp_32(void)
 22.1283 +{
 22.1284 +	sprintf(g_dasm_str, "cmp.l   %s, D%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1285 +}
 22.1286 +
 22.1287 +static void d68000_cmpa_16(void)
 22.1288 +{
 22.1289 +	sprintf(g_dasm_str, "cmpa.w  %s, A%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1290 +}
 22.1291 +
 22.1292 +static void d68000_cmpa_32(void)
 22.1293 +{
 22.1294 +	sprintf(g_dasm_str, "cmpa.l  %s, A%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1295 +}
 22.1296 +
 22.1297 +static void d68000_cmpi_8(void)
 22.1298 +{
 22.1299 +	char* str = get_imm_str_s8();
 22.1300 +	sprintf(g_dasm_str, "cmpi.b  %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
 22.1301 +}
 22.1302 +
 22.1303 +static void d68020_cmpi_pcdi_8(void)
 22.1304 +{
 22.1305 +	char* str;
 22.1306 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1307 +	str = get_imm_str_s8();
 22.1308 +	sprintf(g_dasm_str, "cmpi.b  %s, %s; (2+)", str, get_ea_mode_str_8(g_cpu_ir));
 22.1309 +}
 22.1310 +
 22.1311 +static void d68020_cmpi_pcix_8(void)
 22.1312 +{
 22.1313 +	char* str;
 22.1314 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1315 +	str = get_imm_str_s8();
 22.1316 +	sprintf(g_dasm_str, "cmpi.b  %s, %s; (2+)", str, get_ea_mode_str_8(g_cpu_ir));
 22.1317 +}
 22.1318 +
 22.1319 +static void d68000_cmpi_16(void)
 22.1320 +{
 22.1321 +	char* str;
 22.1322 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1323 +	str = get_imm_str_s16();
 22.1324 +	sprintf(g_dasm_str, "cmpi.w  %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
 22.1325 +}
 22.1326 +
 22.1327 +static void d68020_cmpi_pcdi_16(void)
 22.1328 +{
 22.1329 +	char* str;
 22.1330 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1331 +	str = get_imm_str_s16();
 22.1332 +	sprintf(g_dasm_str, "cmpi.w  %s, %s; (2+)", str, get_ea_mode_str_16(g_cpu_ir));
 22.1333 +}
 22.1334 +
 22.1335 +static void d68020_cmpi_pcix_16(void)
 22.1336 +{
 22.1337 +	char* str;
 22.1338 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1339 +	str = get_imm_str_s16();
 22.1340 +	sprintf(g_dasm_str, "cmpi.w  %s, %s; (2+)", str, get_ea_mode_str_16(g_cpu_ir));
 22.1341 +}
 22.1342 +
 22.1343 +static void d68000_cmpi_32(void)
 22.1344 +{
 22.1345 +	char* str;
 22.1346 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1347 +	str = get_imm_str_s32();
 22.1348 +	sprintf(g_dasm_str, "cmpi.l  %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
 22.1349 +}
 22.1350 +
 22.1351 +static void d68020_cmpi_pcdi_32(void)
 22.1352 +{
 22.1353 +	char* str;
 22.1354 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1355 +	str = get_imm_str_s32();
 22.1356 +	sprintf(g_dasm_str, "cmpi.l  %s, %s; (2+)", str, get_ea_mode_str_32(g_cpu_ir));
 22.1357 +}
 22.1358 +
 22.1359 +static void d68020_cmpi_pcix_32(void)
 22.1360 +{
 22.1361 +	char* str;
 22.1362 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1363 +	str = get_imm_str_s32();
 22.1364 +	sprintf(g_dasm_str, "cmpi.l  %s, %s; (2+)", str, get_ea_mode_str_32(g_cpu_ir));
 22.1365 +}
 22.1366 +
 22.1367 +static void d68000_cmpm_8(void)
 22.1368 +{
 22.1369 +	sprintf(g_dasm_str, "cmpm.b  (A%d)+, (A%d)+", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.1370 +}
 22.1371 +
 22.1372 +static void d68000_cmpm_16(void)
 22.1373 +{
 22.1374 +	sprintf(g_dasm_str, "cmpm.w  (A%d)+, (A%d)+", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.1375 +}
 22.1376 +
 22.1377 +static void d68000_cmpm_32(void)
 22.1378 +{
 22.1379 +	sprintf(g_dasm_str, "cmpm.l  (A%d)+, (A%d)+", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.1380 +}
 22.1381 +
 22.1382 +static void d68020_cpbcc_16(void)
 22.1383 +{
 22.1384 +	uint extension;
 22.1385 +	uint new_pc = g_cpu_pc;
 22.1386 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1387 +	extension = read_imm_16();
 22.1388 +	new_pc += make_int_16(peek_imm_16());
 22.1389 +	sprintf(g_dasm_str, "%db%-4s  %s; %x (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[g_cpu_ir&0x3f], get_imm_str_s16(), new_pc, extension);
 22.1390 +}
 22.1391 +
 22.1392 +static void d68020_cpbcc_32(void)
 22.1393 +{
 22.1394 +	uint extension;
 22.1395 +	uint new_pc = g_cpu_pc;
 22.1396 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1397 +	extension = read_imm_16();
 22.1398 +	new_pc += peek_imm_32();
 22.1399 +	sprintf(g_dasm_str, "%db%-4s  %s; %x (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[g_cpu_ir&0x3f], get_imm_str_s16(), new_pc, extension);
 22.1400 +}
 22.1401 +
 22.1402 +static void d68020_cpdbcc(void)
 22.1403 +{
 22.1404 +	uint extension1;
 22.1405 +	uint extension2;
 22.1406 +	uint new_pc = g_cpu_pc;
 22.1407 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1408 +	extension1 = read_imm_16();
 22.1409 +	extension2 = read_imm_16();
 22.1410 +	new_pc += make_int_16(peek_imm_16());
 22.1411 +	sprintf(g_dasm_str, "%ddb%-4s D%d,%s; %x (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[extension1&0x3f], g_cpu_ir&7, get_imm_str_s16(), new_pc, extension2);
 22.1412 +}
 22.1413 +
 22.1414 +static void d68020_cpgen(void)
 22.1415 +{
 22.1416 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1417 +	sprintf(g_dasm_str, "%dgen    %s; (2-3)", (g_cpu_ir>>9)&7, get_imm_str_u32());
 22.1418 +}
 22.1419 +
 22.1420 +static void d68020_cprestore(void)
 22.1421 +{
 22.1422 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1423 +	sprintf(g_dasm_str, "%drestore %s; (2-3)", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
 22.1424 +}
 22.1425 +
 22.1426 +static void d68020_cpsave(void)
 22.1427 +{
 22.1428 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1429 +	sprintf(g_dasm_str, "%dsave   %s; (2-3)", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
 22.1430 +}
 22.1431 +
 22.1432 +static void d68020_cpscc(void)
 22.1433 +{
 22.1434 +	uint extension1;
 22.1435 +	uint extension2;
 22.1436 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1437 +	extension1 = read_imm_16();
 22.1438 +	extension2 = read_imm_16();
 22.1439 +	sprintf(g_dasm_str, "%ds%-4s  %s; (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[extension1&0x3f], get_ea_mode_str_8(g_cpu_ir), extension2);
 22.1440 +}
 22.1441 +
 22.1442 +static void d68020_cptrapcc_0(void)
 22.1443 +{
 22.1444 +	uint extension1;
 22.1445 +	uint extension2;
 22.1446 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1447 +	extension1 = read_imm_16();
 22.1448 +	extension2 = read_imm_16();
 22.1449 +	sprintf(g_dasm_str, "%dtrap%-4s; (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[extension1&0x3f], extension2);
 22.1450 +}
 22.1451 +
 22.1452 +static void d68020_cptrapcc_16(void)
 22.1453 +{
 22.1454 +	uint extension1;
 22.1455 +	uint extension2;
 22.1456 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1457 +	extension1 = read_imm_16();
 22.1458 +	extension2 = read_imm_16();
 22.1459 +	sprintf(g_dasm_str, "%dtrap%-4s %s; (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[extension1&0x3f], get_imm_str_u16(), extension2);
 22.1460 +}
 22.1461 +
 22.1462 +static void d68020_cptrapcc_32(void)
 22.1463 +{
 22.1464 +	uint extension1;
 22.1465 +	uint extension2;
 22.1466 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1467 +	extension1 = read_imm_16();
 22.1468 +	extension2 = read_imm_16();
 22.1469 +	sprintf(g_dasm_str, "%dtrap%-4s %s; (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[extension1&0x3f], get_imm_str_u32(), extension2);
 22.1470 +}
 22.1471 +
 22.1472 +static void d68040_cpush(void)
 22.1473 +{
 22.1474 +	LIMIT_CPU_TYPES(M68040_PLUS);
 22.1475 +	switch((g_cpu_ir>>3)&3)
 22.1476 +	{
 22.1477 +		case 0:
 22.1478 +			sprintf(g_dasm_str, "cpush (illegal scope); (4)");
 22.1479 +			break;
 22.1480 +		case 1:
 22.1481 +			sprintf(g_dasm_str, "cpushl  %d, (A%d); (4)", (g_cpu_ir>>6)&3, g_cpu_ir&7);
 22.1482 +			break;
 22.1483 +		case 2:
 22.1484 +			sprintf(g_dasm_str, "cpushp  %d, (A%d); (4)", (g_cpu_ir>>6)&3, g_cpu_ir&7);
 22.1485 +			break;
 22.1486 +		case 3:
 22.1487 +			sprintf(g_dasm_str, "cpusha  %d; (4)", (g_cpu_ir>>6)&3);
 22.1488 +			break;
 22.1489 +	}
 22.1490 +}
 22.1491 +
 22.1492 +static void d68000_dbra(void)
 22.1493 +{
 22.1494 +	uint temp_pc = g_cpu_pc;
 22.1495 +	sprintf(g_dasm_str, "dbra    D%d, %x", g_cpu_ir & 7, temp_pc + make_int_16(read_imm_16()));
 22.1496 +}
 22.1497 +
 22.1498 +static void d68000_dbcc(void)
 22.1499 +{
 22.1500 +	uint temp_pc = g_cpu_pc;
 22.1501 +	sprintf(g_dasm_str, "db%-2s    D%d, %x", g_cc[(g_cpu_ir>>8)&0xf], g_cpu_ir & 7, temp_pc + make_int_16(read_imm_16()));
 22.1502 +}
 22.1503 +
 22.1504 +static void d68000_divs(void)
 22.1505 +{
 22.1506 +	sprintf(g_dasm_str, "divs.w  %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1507 +}
 22.1508 +
 22.1509 +static void d68000_divu(void)
 22.1510 +{
 22.1511 +	sprintf(g_dasm_str, "divu.w  %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1512 +}
 22.1513 +
 22.1514 +static void d68020_divl(void)
 22.1515 +{
 22.1516 +	uint extension;
 22.1517 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1518 +	extension = read_imm_16();
 22.1519 +
 22.1520 +	if(BIT_A(extension))
 22.1521 +		sprintf(g_dasm_str, "div%c.l  %s, D%d:D%d; (2+)", BIT_B(extension) ? 's' : 'u', get_ea_mode_str_32(g_cpu_ir), extension&7, (extension>>12)&7);
 22.1522 +	else if((extension&7) == ((extension>>12)&7))
 22.1523 +		sprintf(g_dasm_str, "div%c.l  %s, D%d; (2+)", BIT_B(extension) ? 's' : 'u', get_ea_mode_str_32(g_cpu_ir), (extension>>12)&7);
 22.1524 +	else
 22.1525 +		sprintf(g_dasm_str, "div%cl.l %s, D%d:D%d; (2+)", BIT_B(extension) ? 's' : 'u', get_ea_mode_str_32(g_cpu_ir), extension&7, (extension>>12)&7);
 22.1526 +}
 22.1527 +
 22.1528 +static void d68000_eor_8(void)
 22.1529 +{
 22.1530 +	sprintf(g_dasm_str, "eor.b   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
 22.1531 +}
 22.1532 +
 22.1533 +static void d68000_eor_16(void)
 22.1534 +{
 22.1535 +	sprintf(g_dasm_str, "eor.w   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_16(g_cpu_ir));
 22.1536 +}
 22.1537 +
 22.1538 +static void d68000_eor_32(void)
 22.1539 +{
 22.1540 +	sprintf(g_dasm_str, "eor.l   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_32(g_cpu_ir));
 22.1541 +}
 22.1542 +
 22.1543 +static void d68000_eori_8(void)
 22.1544 +{
 22.1545 +	char* str = get_imm_str_u8();
 22.1546 +	sprintf(g_dasm_str, "eori.b  %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
 22.1547 +}
 22.1548 +
 22.1549 +static void d68000_eori_16(void)
 22.1550 +{
 22.1551 +	char* str = get_imm_str_u16();
 22.1552 +	sprintf(g_dasm_str, "eori.w  %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
 22.1553 +}
 22.1554 +
 22.1555 +static void d68000_eori_32(void)
 22.1556 +{
 22.1557 +	char* str = get_imm_str_u32();
 22.1558 +	sprintf(g_dasm_str, "eori.l  %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
 22.1559 +}
 22.1560 +
 22.1561 +static void d68000_eori_to_ccr(void)
 22.1562 +{
 22.1563 +	sprintf(g_dasm_str, "eori    %s, CCR", get_imm_str_u8());
 22.1564 +}
 22.1565 +
 22.1566 +static void d68000_eori_to_sr(void)
 22.1567 +{
 22.1568 +	sprintf(g_dasm_str, "eori    %s, SR", get_imm_str_u16());
 22.1569 +}
 22.1570 +
 22.1571 +static void d68000_exg_dd(void)
 22.1572 +{
 22.1573 +	sprintf(g_dasm_str, "exg     D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.1574 +}
 22.1575 +
 22.1576 +static void d68000_exg_aa(void)
 22.1577 +{
 22.1578 +	sprintf(g_dasm_str, "exg     A%d, A%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.1579 +}
 22.1580 +
 22.1581 +static void d68000_exg_da(void)
 22.1582 +{
 22.1583 +	sprintf(g_dasm_str, "exg     D%d, A%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.1584 +}
 22.1585 +
 22.1586 +static void d68000_ext_16(void)
 22.1587 +{
 22.1588 +	sprintf(g_dasm_str, "ext.w   D%d", g_cpu_ir&7);
 22.1589 +}
 22.1590 +
 22.1591 +static void d68000_ext_32(void)
 22.1592 +{
 22.1593 +	sprintf(g_dasm_str, "ext.l   D%d", g_cpu_ir&7);
 22.1594 +}
 22.1595 +
 22.1596 +static void d68020_extb_32(void)
 22.1597 +{
 22.1598 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1599 +	sprintf(g_dasm_str, "extb.l  D%d; (2+)", g_cpu_ir&7);
 22.1600 +}
 22.1601 +
 22.1602 +static void d68000_jmp(void)
 22.1603 +{
 22.1604 +	sprintf(g_dasm_str, "jmp     %s", get_ea_mode_str_32(g_cpu_ir));
 22.1605 +}
 22.1606 +
 22.1607 +static void d68000_jsr(void)
 22.1608 +{
 22.1609 +	sprintf(g_dasm_str, "jsr     %s", get_ea_mode_str_32(g_cpu_ir));
 22.1610 +}
 22.1611 +
 22.1612 +static void d68000_lea(void)
 22.1613 +{
 22.1614 +	sprintf(g_dasm_str, "lea     %s, A%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1615 +}
 22.1616 +
 22.1617 +static void d68000_link_16(void)
 22.1618 +{
 22.1619 +	sprintf(g_dasm_str, "link    A%d, %s", g_cpu_ir&7, get_imm_str_s16());
 22.1620 +}
 22.1621 +
 22.1622 +static void d68020_link_32(void)
 22.1623 +{
 22.1624 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.1625 +	sprintf(g_dasm_str, "link    A%d, %s; (2+)", g_cpu_ir&7, get_imm_str_s32());
 22.1626 +}
 22.1627 +
 22.1628 +static void d68000_lsr_s_8(void)
 22.1629 +{
 22.1630 +	sprintf(g_dasm_str, "lsr.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.1631 +}
 22.1632 +
 22.1633 +static void d68000_lsr_s_16(void)
 22.1634 +{
 22.1635 +	sprintf(g_dasm_str, "lsr.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.1636 +}
 22.1637 +
 22.1638 +static void d68000_lsr_s_32(void)
 22.1639 +{
 22.1640 +	sprintf(g_dasm_str, "lsr.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.1641 +}
 22.1642 +
 22.1643 +static void d68000_lsr_r_8(void)
 22.1644 +{
 22.1645 +	sprintf(g_dasm_str, "lsr.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.1646 +}
 22.1647 +
 22.1648 +static void d68000_lsr_r_16(void)
 22.1649 +{
 22.1650 +	sprintf(g_dasm_str, "lsr.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.1651 +}
 22.1652 +
 22.1653 +static void d68000_lsr_r_32(void)
 22.1654 +{
 22.1655 +	sprintf(g_dasm_str, "lsr.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.1656 +}
 22.1657 +
 22.1658 +static void d68000_lsr_ea(void)
 22.1659 +{
 22.1660 +	sprintf(g_dasm_str, "lsr.w   %s", get_ea_mode_str_32(g_cpu_ir));
 22.1661 +}
 22.1662 +
 22.1663 +static void d68000_lsl_s_8(void)
 22.1664 +{
 22.1665 +	sprintf(g_dasm_str, "lsl.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.1666 +}
 22.1667 +
 22.1668 +static void d68000_lsl_s_16(void)
 22.1669 +{
 22.1670 +	sprintf(g_dasm_str, "lsl.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.1671 +}
 22.1672 +
 22.1673 +static void d68000_lsl_s_32(void)
 22.1674 +{
 22.1675 +	sprintf(g_dasm_str, "lsl.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.1676 +}
 22.1677 +
 22.1678 +static void d68000_lsl_r_8(void)
 22.1679 +{
 22.1680 +	sprintf(g_dasm_str, "lsl.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.1681 +}
 22.1682 +
 22.1683 +static void d68000_lsl_r_16(void)
 22.1684 +{
 22.1685 +	sprintf(g_dasm_str, "lsl.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.1686 +}
 22.1687 +
 22.1688 +static void d68000_lsl_r_32(void)
 22.1689 +{
 22.1690 +	sprintf(g_dasm_str, "lsl.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.1691 +}
 22.1692 +
 22.1693 +static void d68000_lsl_ea(void)
 22.1694 +{
 22.1695 +	sprintf(g_dasm_str, "lsl.w   %s", get_ea_mode_str_32(g_cpu_ir));
 22.1696 +}
 22.1697 +
 22.1698 +static void d68000_move_8(void)
 22.1699 +{
 22.1700 +	char* str = get_ea_mode_str_8(g_cpu_ir);
 22.1701 +	sprintf(g_dasm_str, "move.b  %s, %s", str, get_ea_mode_str_8(((g_cpu_ir>>9) & 7) | ((g_cpu_ir>>3) & 0x38)));
 22.1702 +}
 22.1703 +
 22.1704 +static void d68000_move_16(void)
 22.1705 +{
 22.1706 +	char* str = get_ea_mode_str_16(g_cpu_ir);
 22.1707 +	sprintf(g_dasm_str, "move.w  %s, %s", str, get_ea_mode_str_16(((g_cpu_ir>>9) & 7) | ((g_cpu_ir>>3) & 0x38)));
 22.1708 +}
 22.1709 +
 22.1710 +static void d68000_move_32(void)
 22.1711 +{
 22.1712 +	char* str = get_ea_mode_str_32(g_cpu_ir);
 22.1713 +	sprintf(g_dasm_str, "move.l  %s, %s", str, get_ea_mode_str_32(((g_cpu_ir>>9) & 7) | ((g_cpu_ir>>3) & 0x38)));
 22.1714 +}
 22.1715 +
 22.1716 +static void d68000_movea_16(void)
 22.1717 +{
 22.1718 +	sprintf(g_dasm_str, "movea.w %s, A%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1719 +}
 22.1720 +
 22.1721 +static void d68000_movea_32(void)
 22.1722 +{
 22.1723 +	sprintf(g_dasm_str, "movea.l %s, A%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.1724 +}
 22.1725 +
 22.1726 +static void d68000_move_to_ccr(void)
 22.1727 +{
 22.1728 +	sprintf(g_dasm_str, "move    %s, CCR", get_ea_mode_str_8(g_cpu_ir));
 22.1729 +}
 22.1730 +
 22.1731 +static void d68010_move_fr_ccr(void)
 22.1732 +{
 22.1733 +	LIMIT_CPU_TYPES(M68010_PLUS);
 22.1734 +	sprintf(g_dasm_str, "move    CCR, %s; (1+)", get_ea_mode_str_8(g_cpu_ir));
 22.1735 +}
 22.1736 +
 22.1737 +static void d68000_move_fr_sr(void)
 22.1738 +{
 22.1739 +	sprintf(g_dasm_str, "move    SR, %s", get_ea_mode_str_16(g_cpu_ir));
 22.1740 +}
 22.1741 +
 22.1742 +static void d68000_move_to_sr(void)
 22.1743 +{
 22.1744 +	sprintf(g_dasm_str, "move    %s, SR", get_ea_mode_str_16(g_cpu_ir));
 22.1745 +}
 22.1746 +
 22.1747 +static void d68000_move_fr_usp(void)
 22.1748 +{
 22.1749 +	sprintf(g_dasm_str, "move    USP, A%d", g_cpu_ir&7);
 22.1750 +}
 22.1751 +
 22.1752 +static void d68000_move_to_usp(void)
 22.1753 +{
 22.1754 +	sprintf(g_dasm_str, "move    A%d, USP", g_cpu_ir&7);
 22.1755 +}
 22.1756 +
 22.1757 +static void d68010_movec(void)
 22.1758 +{
 22.1759 +	uint extension;
 22.1760 +	char* reg_name;
 22.1761 +	char* processor;
 22.1762 +	LIMIT_CPU_TYPES(M68010_PLUS);
 22.1763 +	extension = read_imm_16();
 22.1764 +
 22.1765 +	switch(extension & 0xfff)
 22.1766 +	{
 22.1767 +		case 0x000:
 22.1768 +			reg_name = "SFC";
 22.1769 +			processor = "1+";
 22.1770 +			break;
 22.1771 +		case 0x001:
 22.1772 +			reg_name = "DFC";
 22.1773 +			processor = "1+";
 22.1774 +			break;
 22.1775 +		case 0x800:
 22.1776 +			reg_name = "USP";
 22.1777 +			processor = "1+";
 22.1778 +			break;
 22.1779 +		case 0x801:
 22.1780 +			reg_name = "VBR";
 22.1781 +			processor = "1+";
 22.1782 +			break;
 22.1783 +		case 0x002:
 22.1784 +			reg_name = "CACR";
 22.1785 +			processor = "2+";
 22.1786 +			break;
 22.1787 +		case 0x802:
 22.1788 +			reg_name = "CAAR";
 22.1789 +			processor = "2,3";
 22.1790 +			break;
 22.1791 +		case 0x803:
 22.1792 +			reg_name = "MSP";
 22.1793 +			processor = "2+";
 22.1794 +			break;
 22.1795 +		case 0x804:
 22.1796 +			reg_name = "ISP";
 22.1797 +			processor = "2+";
 22.1798 +			break;
 22.1799 +		case 0x003:
 22.1800 +			reg_name = "TC";
 22.1801 +			processor = "4+";
 22.1802 +			break;
 22.1803 +		case 0x004:
 22.1804 +			reg_name = "ITT0";
 22.1805 +			processor = "4+";
 22.1806 +			break;
 22.1807 +		case 0x005:
 22.1808 +			reg_name = "ITT1";
 22.1809 +			processor = "4+";
 22.1810 +			break;
 22.1811 +		case 0x006:
 22.1812 +			reg_name = "DTT0";
 22.1813 +			processor = "4+";
 22.1814 +			break;
 22.1815 +		case 0x007:
 22.1816 +			reg_name = "DTT1";
 22.1817 +			processor = "4+";
 22.1818 +			break;
 22.1819 +		case 0x805:
 22.1820 +			reg_name = "MMUSR";
 22.1821 +			processor = "4+";
 22.1822 +			break;
 22.1823 +		case 0x806:
 22.1824 +			reg_name = "URP";
 22.1825 +			processor = "4+";
 22.1826 +			break;
 22.1827 +		case 0x807:
 22.1828 +			reg_name = "SRP";
 22.1829 +			processor = "4+";
 22.1830 +			break;
 22.1831 +		default:
 22.1832 +			reg_name = make_signed_hex_str_16(extension & 0xfff);
 22.1833 +			processor = "?";
 22.1834 +	}
 22.1835 +
 22.1836 +	if(BIT_1(g_cpu_ir))
 22.1837 +		sprintf(g_dasm_str, "movec %c%d, %s; (%s)", BIT_F(extension) ? 'A' : 'D', (extension>>12)&7, reg_name, processor);
 22.1838 +	else
 22.1839 +		sprintf(g_dasm_str, "movec %s, %c%d; (%s)", reg_name, BIT_F(extension) ? 'A' : 'D', (extension>>12)&7, processor);
 22.1840 +}
 22.1841 +
 22.1842 +static void d68000_movem_pd_16(void)
 22.1843 +{
 22.1844 +	uint data = read_imm_16();
 22.1845 +	char buffer[40];
 22.1846 +	uint first;
 22.1847 +	uint run_length;
 22.1848 +	uint i;
 22.1849 +
 22.1850 +	buffer[0] = 0;
 22.1851 +	for(i=0;i<8;i++)
 22.1852 +	{
 22.1853 +		if(data&(1<<(15-i)))
 22.1854 +		{
 22.1855 +			first = i;
 22.1856 +			run_length = 0;
 22.1857 +			for(i++;i<8;i++)
 22.1858 +				if(data&(1<<(15-i)))
 22.1859 +					run_length++;
 22.1860 +			if(buffer[0] != 0)
 22.1861 +				strcat(buffer, "/");
 22.1862 +			sprintf(buffer+strlen(buffer), "D%d", first);
 22.1863 +			if(run_length > 0)
 22.1864 +				sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
 22.1865 +		}
 22.1866 +	}
 22.1867 +	for(i=0;i<8;i++)
 22.1868 +	{
 22.1869 +		if(data&(1<<(7-i)))
 22.1870 +		{
 22.1871 +			first = i;
 22.1872 +			run_length = 0;
 22.1873 +			for(i++;i<8;i++)
 22.1874 +				if(data&(1<<(7-i)))
 22.1875 +					run_length++;
 22.1876 +			if(buffer[0] != 0)
 22.1877 +				strcat(buffer, "/");
 22.1878 +			sprintf(buffer+strlen(buffer), "A%d", first);
 22.1879 +			if(run_length > 0)
 22.1880 +				sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
 22.1881 +		}
 22.1882 +	}
 22.1883 +	sprintf(g_dasm_str, "movem.w %s, %s", buffer, get_ea_mode_str_16(g_cpu_ir));
 22.1884 +}
 22.1885 +
 22.1886 +static void d68000_movem_pd_32(void)
 22.1887 +{
 22.1888 +	uint data = read_imm_16();
 22.1889 +	char buffer[40];
 22.1890 +	uint first;
 22.1891 +	uint run_length;
 22.1892 +	uint i;
 22.1893 +
 22.1894 +	buffer[0] = 0;
 22.1895 +	for(i=0;i<8;i++)
 22.1896 +	{
 22.1897 +		if(data&(1<<(15-i)))
 22.1898 +		{
 22.1899 +			first = i;
 22.1900 +			run_length = 0;
 22.1901 +			for(i++;i<8;i++)
 22.1902 +				if(data&(1<<(15-i)))
 22.1903 +					run_length++;
 22.1904 +			if(buffer[0] != 0)
 22.1905 +				strcat(buffer, "/");
 22.1906 +			sprintf(buffer+strlen(buffer), "D%d", first);
 22.1907 +			if(run_length > 0)
 22.1908 +				sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
 22.1909 +		}
 22.1910 +	}
 22.1911 +	for(i=0;i<8;i++)
 22.1912 +	{
 22.1913 +		if(data&(1<<(7-i)))
 22.1914 +		{
 22.1915 +			first = i;
 22.1916 +			run_length = 0;
 22.1917 +			for(i++;i<8;i++)
 22.1918 +				if(data&(1<<(7-i)))
 22.1919 +					run_length++;
 22.1920 +			if(buffer[0] != 0)
 22.1921 +				strcat(buffer, "/");
 22.1922 +			sprintf(buffer+strlen(buffer), "A%d", first);
 22.1923 +			if(run_length > 0)
 22.1924 +				sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
 22.1925 +		}
 22.1926 +	}
 22.1927 +	sprintf(g_dasm_str, "movem.l %s, %s", buffer, get_ea_mode_str_32(g_cpu_ir));
 22.1928 +}
 22.1929 +
 22.1930 +static void d68000_movem_er_16(void)
 22.1931 +{
 22.1932 +	uint data = read_imm_16();
 22.1933 +	char buffer[40];
 22.1934 +	uint first;
 22.1935 +	uint run_length;
 22.1936 +	uint i;
 22.1937 +
 22.1938 +	buffer[0] = 0;
 22.1939 +	for(i=0;i<8;i++)
 22.1940 +	{
 22.1941 +		if(data&(1<<i))
 22.1942 +		{
 22.1943 +			first = i;
 22.1944 +			run_length = 0;
 22.1945 +			for(i++;i<8;i++)
 22.1946 +				if(data&(1<<i))
 22.1947 +					run_length++;
 22.1948 +			if(buffer[0] != 0)
 22.1949 +				strcat(buffer, "/");
 22.1950 +			sprintf(buffer+strlen(buffer), "D%d", first);
 22.1951 +			if(run_length > 0)
 22.1952 +				sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
 22.1953 +		}
 22.1954 +	}
 22.1955 +	for(i=0;i<8;i++)
 22.1956 +	{
 22.1957 +		if(data&(1<<(i+8)))
 22.1958 +		{
 22.1959 +			first = i;
 22.1960 +			run_length = 0;
 22.1961 +			for(i++;i<8;i++)
 22.1962 +				if(data&(1<<(i+8)))
 22.1963 +					run_length++;
 22.1964 +			if(buffer[0] != 0)
 22.1965 +				strcat(buffer, "/");
 22.1966 +			sprintf(buffer+strlen(buffer), "A%d", first);
 22.1967 +			if(run_length > 0)
 22.1968 +				sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
 22.1969 +		}
 22.1970 +	}
 22.1971 +	sprintf(g_dasm_str, "movem.w %s, %s", get_ea_mode_str_16(g_cpu_ir), buffer);
 22.1972 +}
 22.1973 +
 22.1974 +static void d68000_movem_er_32(void)
 22.1975 +{
 22.1976 +	uint data = read_imm_16();
 22.1977 +	char buffer[40];
 22.1978 +	uint first;
 22.1979 +	uint run_length;
 22.1980 +	uint i;
 22.1981 +
 22.1982 +	buffer[0] = 0;
 22.1983 +	for(i=0;i<8;i++)
 22.1984 +	{
 22.1985 +		if(data&(1<<i))
 22.1986 +		{
 22.1987 +			first = i;
 22.1988 +			run_length = 0;
 22.1989 +			for(i++;i<8;i++)
 22.1990 +				if(data&(1<<i))
 22.1991 +					run_length++;
 22.1992 +			if(buffer[0] != 0)
 22.1993 +				strcat(buffer, "/");
 22.1994 +			sprintf(buffer+strlen(buffer), "D%d", first);
 22.1995 +			if(run_length > 0)
 22.1996 +				sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
 22.1997 +		}
 22.1998 +	}
 22.1999 +	for(i=0;i<8;i++)
 22.2000 +	{
 22.2001 +		if(data&(1<<(i+8)))
 22.2002 +		{
 22.2003 +			first = i;
 22.2004 +			run_length = 0;
 22.2005 +			for(i++;i<8;i++)
 22.2006 +				if(data&(1<<(i+8)))
 22.2007 +					run_length++;
 22.2008 +			if(buffer[0] != 0)
 22.2009 +				strcat(buffer, "/");
 22.2010 +			sprintf(buffer+strlen(buffer), "A%d", first);
 22.2011 +			if(run_length > 0)
 22.2012 +				sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
 22.2013 +		}
 22.2014 +	}
 22.2015 +	sprintf(g_dasm_str, "movem.l %s, %s", get_ea_mode_str_32(g_cpu_ir), buffer);
 22.2016 +}
 22.2017 +
 22.2018 +static void d68000_movem_re_16(void)
 22.2019 +{
 22.2020 +	uint data = read_imm_16();
 22.2021 +	char buffer[40];
 22.2022 +	uint first;
 22.2023 +	uint run_length;
 22.2024 +	uint i;
 22.2025 +
 22.2026 +	buffer[0] = 0;
 22.2027 +	for(i=0;i<8;i++)
 22.2028 +	{
 22.2029 +		if(data&(1<<i))
 22.2030 +		{
 22.2031 +			first = i;
 22.2032 +			run_length = 0;
 22.2033 +			for(i++;i<8;i++)
 22.2034 +				if(data&(1<<i))
 22.2035 +					run_length++;
 22.2036 +			if(buffer[0] != 0)
 22.2037 +				strcat(buffer, "/");
 22.2038 +			sprintf(buffer+strlen(buffer), "D%d", first);
 22.2039 +			if(run_length > 0)
 22.2040 +				sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
 22.2041 +		}
 22.2042 +	}
 22.2043 +	for(i=0;i<8;i++)
 22.2044 +	{
 22.2045 +		if(data&(1<<(i+8)))
 22.2046 +		{
 22.2047 +			first = i;
 22.2048 +			run_length = 0;
 22.2049 +			for(i++;i<8;i++)
 22.2050 +				if(data&(1<<(i+8)))
 22.2051 +					run_length++;
 22.2052 +			if(buffer[0] != 0)
 22.2053 +				strcat(buffer, "/");
 22.2054 +			sprintf(buffer+strlen(buffer), "A%d", first);
 22.2055 +			if(run_length > 0)
 22.2056 +				sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
 22.2057 +		}
 22.2058 +	}
 22.2059 +	sprintf(g_dasm_str, "movem.w %s, %s", buffer, get_ea_mode_str_16(g_cpu_ir));
 22.2060 +}
 22.2061 +
 22.2062 +static void d68000_movem_re_32(void)
 22.2063 +{
 22.2064 +	uint data = read_imm_16();
 22.2065 +	char buffer[40];
 22.2066 +	uint first;
 22.2067 +	uint run_length;
 22.2068 +	uint i;
 22.2069 +
 22.2070 +	buffer[0] = 0;
 22.2071 +	for(i=0;i<8;i++)
 22.2072 +	{
 22.2073 +		if(data&(1<<i))
 22.2074 +		{
 22.2075 +			first = i;
 22.2076 +			run_length = 0;
 22.2077 +			for(i++;i<8;i++)
 22.2078 +				if(data&(1<<i))
 22.2079 +					run_length++;
 22.2080 +			if(buffer[0] != 0)
 22.2081 +				strcat(buffer, "/");
 22.2082 +			sprintf(buffer+strlen(buffer), "D%d", first);
 22.2083 +			if(run_length > 0)
 22.2084 +				sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
 22.2085 +		}
 22.2086 +	}
 22.2087 +	for(i=0;i<8;i++)
 22.2088 +	{
 22.2089 +		if(data&(1<<(i+8)))
 22.2090 +		{
 22.2091 +			first = i;
 22.2092 +			run_length = 0;
 22.2093 +			for(i++;i<8;i++)
 22.2094 +				if(data&(1<<(i+8)))
 22.2095 +					run_length++;
 22.2096 +			if(buffer[0] != 0)
 22.2097 +				strcat(buffer, "/");
 22.2098 +			sprintf(buffer+strlen(buffer), "A%d", first);
 22.2099 +			if(run_length > 0)
 22.2100 +				sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
 22.2101 +		}
 22.2102 +	}
 22.2103 +	sprintf(g_dasm_str, "movem.l %s, %s", buffer, get_ea_mode_str_32(g_cpu_ir));
 22.2104 +}
 22.2105 +
 22.2106 +static void d68000_movep_re_16(void)
 22.2107 +{
 22.2108 +	sprintf(g_dasm_str, "movep.w D%d, ($%x,A%d)", (g_cpu_ir>>9)&7, read_imm_16(), g_cpu_ir&7);
 22.2109 +}
 22.2110 +
 22.2111 +static void d68000_movep_re_32(void)
 22.2112 +{
 22.2113 +	sprintf(g_dasm_str, "movep.l D%d, ($%x,A%d)", (g_cpu_ir>>9)&7, read_imm_16(), g_cpu_ir&7);
 22.2114 +}
 22.2115 +
 22.2116 +static void d68000_movep_er_16(void)
 22.2117 +{
 22.2118 +	sprintf(g_dasm_str, "movep.w ($%x,A%d), D%d", read_imm_16(), g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.2119 +}
 22.2120 +
 22.2121 +static void d68000_movep_er_32(void)
 22.2122 +{
 22.2123 +	sprintf(g_dasm_str, "movep.l ($%x,A%d), D%d", read_imm_16(), g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.2124 +}
 22.2125 +
 22.2126 +static void d68010_moves_8(void)
 22.2127 +{
 22.2128 +	uint extension;
 22.2129 +	LIMIT_CPU_TYPES(M68010_PLUS);
 22.2130 +	extension = read_imm_16();
 22.2131 +	if(BIT_B(extension))
 22.2132 +		sprintf(g_dasm_str, "moves.b %c%d, %s; (1+)", BIT_F(extension) ? 'A' : 'D', (extension>>12)&7, get_ea_mode_str_8(g_cpu_ir));
 22.2133 +	else
 22.2134 +		sprintf(g_dasm_str, "moves.b %s, %c%d; (1+)", get_ea_mode_str_8(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
 22.2135 +}
 22.2136 +
 22.2137 +static void d68010_moves_16(void)
 22.2138 +{
 22.2139 +	uint extension;
 22.2140 +	LIMIT_CPU_TYPES(M68010_PLUS);
 22.2141 +	extension = read_imm_16();
 22.2142 +	if(BIT_B(extension))
 22.2143 +		sprintf(g_dasm_str, "moves.w %c%d, %s; (1+)", BIT_F(extension) ? 'A' : 'D', (extension>>12)&7, get_ea_mode_str_16(g_cpu_ir));
 22.2144 +	else
 22.2145 +		sprintf(g_dasm_str, "moves.w %s, %c%d; (1+)", get_ea_mode_str_16(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
 22.2146 +}
 22.2147 +
 22.2148 +static void d68010_moves_32(void)
 22.2149 +{
 22.2150 +	uint extension;
 22.2151 +	LIMIT_CPU_TYPES(M68010_PLUS);
 22.2152 +	extension = read_imm_16();
 22.2153 +	if(BIT_B(extension))
 22.2154 +		sprintf(g_dasm_str, "moves.l %c%d, %s; (1+)", BIT_F(extension) ? 'A' : 'D', (extension>>12)&7, get_ea_mode_str_32(g_cpu_ir));
 22.2155 +	else
 22.2156 +		sprintf(g_dasm_str, "moves.l %s, %c%d; (1+)", get_ea_mode_str_32(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
 22.2157 +}
 22.2158 +
 22.2159 +static void d68000_moveq(void)
 22.2160 +{
 22.2161 +	sprintf(g_dasm_str, "moveq   #%s, D%d", make_signed_hex_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2162 +}
 22.2163 +
 22.2164 +static void d68040_move16_pi_pi(void)
 22.2165 +{
 22.2166 +	LIMIT_CPU_TYPES(M68040_PLUS);
 22.2167 +	sprintf(g_dasm_str, "move16  (A%d)+, (A%d)+; (4)", g_cpu_ir&7, (read_imm_16()>>12)&7);
 22.2168 +}
 22.2169 +
 22.2170 +static void d68040_move16_pi_al(void)
 22.2171 +{
 22.2172 +	LIMIT_CPU_TYPES(M68040_PLUS);
 22.2173 +	sprintf(g_dasm_str, "move16  (A%d)+, %s; (4)", g_cpu_ir&7, get_imm_str_u32());
 22.2174 +}
 22.2175 +
 22.2176 +static void d68040_move16_al_pi(void)
 22.2177 +{
 22.2178 +	LIMIT_CPU_TYPES(M68040_PLUS);
 22.2179 +	sprintf(g_dasm_str, "move16  %s, (A%d)+; (4)", get_imm_str_u32(), g_cpu_ir&7);
 22.2180 +}
 22.2181 +
 22.2182 +static void d68040_move16_ai_al(void)
 22.2183 +{
 22.2184 +	LIMIT_CPU_TYPES(M68040_PLUS);
 22.2185 +	sprintf(g_dasm_str, "move16  (A%d), %s; (4)", g_cpu_ir&7, get_imm_str_u32());
 22.2186 +}
 22.2187 +
 22.2188 +static void d68040_move16_al_ai(void)
 22.2189 +{
 22.2190 +	LIMIT_CPU_TYPES(M68040_PLUS);
 22.2191 +	sprintf(g_dasm_str, "move16  %s, (A%d); (4)", get_imm_str_u32(), g_cpu_ir&7);
 22.2192 +}
 22.2193 +
 22.2194 +static void d68000_muls(void)
 22.2195 +{
 22.2196 +	sprintf(g_dasm_str, "muls.w  %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2197 +}
 22.2198 +
 22.2199 +static void d68000_mulu(void)
 22.2200 +{
 22.2201 +	sprintf(g_dasm_str, "mulu.w  %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2202 +}
 22.2203 +
 22.2204 +static void d68020_mull(void)
 22.2205 +{
 22.2206 +	uint extension;
 22.2207 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2208 +	extension = read_imm_16();
 22.2209 +
 22.2210 +	if(BIT_A(extension))
 22.2211 +		sprintf(g_dasm_str, "mul%c.l %s, D%d-D%d; (2+)", BIT_B(extension) ? 's' : 'u', get_ea_mode_str_32(g_cpu_ir), extension&7, (extension>>12)&7);
 22.2212 +	else
 22.2213 +		sprintf(g_dasm_str, "mul%c.l  %s, D%d; (2+)", BIT_B(extension) ? 's' : 'u', get_ea_mode_str_32(g_cpu_ir), (extension>>12)&7);
 22.2214 +}
 22.2215 +
 22.2216 +static void d68000_nbcd(void)
 22.2217 +{
 22.2218 +	sprintf(g_dasm_str, "nbcd    %s", get_ea_mode_str_8(g_cpu_ir));
 22.2219 +}
 22.2220 +
 22.2221 +static void d68000_neg_8(void)
 22.2222 +{
 22.2223 +	sprintf(g_dasm_str, "neg.b   %s", get_ea_mode_str_8(g_cpu_ir));
 22.2224 +}
 22.2225 +
 22.2226 +static void d68000_neg_16(void)
 22.2227 +{
 22.2228 +	sprintf(g_dasm_str, "neg.w   %s", get_ea_mode_str_16(g_cpu_ir));
 22.2229 +}
 22.2230 +
 22.2231 +static void d68000_neg_32(void)
 22.2232 +{
 22.2233 +	sprintf(g_dasm_str, "neg.l   %s", get_ea_mode_str_32(g_cpu_ir));
 22.2234 +}
 22.2235 +
 22.2236 +static void d68000_negx_8(void)
 22.2237 +{
 22.2238 +	sprintf(g_dasm_str, "negx.b  %s", get_ea_mode_str_8(g_cpu_ir));
 22.2239 +}
 22.2240 +
 22.2241 +static void d68000_negx_16(void)
 22.2242 +{
 22.2243 +	sprintf(g_dasm_str, "negx.w  %s", get_ea_mode_str_16(g_cpu_ir));
 22.2244 +}
 22.2245 +
 22.2246 +static void d68000_negx_32(void)
 22.2247 +{
 22.2248 +	sprintf(g_dasm_str, "negx.l  %s", get_ea_mode_str_32(g_cpu_ir));
 22.2249 +}
 22.2250 +
 22.2251 +static void d68000_nop(void)
 22.2252 +{
 22.2253 +	sprintf(g_dasm_str, "nop");
 22.2254 +}
 22.2255 +
 22.2256 +static void d68000_not_8(void)
 22.2257 +{
 22.2258 +	sprintf(g_dasm_str, "not.b   %s", get_ea_mode_str_8(g_cpu_ir));
 22.2259 +}
 22.2260 +
 22.2261 +static void d68000_not_16(void)
 22.2262 +{
 22.2263 +	sprintf(g_dasm_str, "not.w   %s", get_ea_mode_str_16(g_cpu_ir));
 22.2264 +}
 22.2265 +
 22.2266 +static void d68000_not_32(void)
 22.2267 +{
 22.2268 +	sprintf(g_dasm_str, "not.l   %s", get_ea_mode_str_32(g_cpu_ir));
 22.2269 +}
 22.2270 +
 22.2271 +static void d68000_or_er_8(void)
 22.2272 +{
 22.2273 +	sprintf(g_dasm_str, "or.b    %s, D%d", get_ea_mode_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2274 +}
 22.2275 +
 22.2276 +static void d68000_or_er_16(void)
 22.2277 +{
 22.2278 +	sprintf(g_dasm_str, "or.w    %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2279 +}
 22.2280 +
 22.2281 +static void d68000_or_er_32(void)
 22.2282 +{
 22.2283 +	sprintf(g_dasm_str, "or.l    %s, D%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2284 +}
 22.2285 +
 22.2286 +static void d68000_or_re_8(void)
 22.2287 +{
 22.2288 +	sprintf(g_dasm_str, "or.b    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
 22.2289 +}
 22.2290 +
 22.2291 +static void d68000_or_re_16(void)
 22.2292 +{
 22.2293 +	sprintf(g_dasm_str, "or.w    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_16(g_cpu_ir));
 22.2294 +}
 22.2295 +
 22.2296 +static void d68000_or_re_32(void)
 22.2297 +{
 22.2298 +	sprintf(g_dasm_str, "or.l    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_32(g_cpu_ir));
 22.2299 +}
 22.2300 +
 22.2301 +static void d68000_ori_8(void)
 22.2302 +{
 22.2303 +	char* str = get_imm_str_u8();
 22.2304 +	sprintf(g_dasm_str, "ori.b   %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
 22.2305 +}
 22.2306 +
 22.2307 +static void d68000_ori_16(void)
 22.2308 +{
 22.2309 +	char* str = get_imm_str_u16();
 22.2310 +	sprintf(g_dasm_str, "ori.w   %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
 22.2311 +}
 22.2312 +
 22.2313 +static void d68000_ori_32(void)
 22.2314 +{
 22.2315 +	char* str = get_imm_str_u32();
 22.2316 +	sprintf(g_dasm_str, "ori.l   %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
 22.2317 +}
 22.2318 +
 22.2319 +static void d68000_ori_to_ccr(void)
 22.2320 +{
 22.2321 +	sprintf(g_dasm_str, "ori     %s, CCR", get_imm_str_u8());
 22.2322 +}
 22.2323 +
 22.2324 +static void d68000_ori_to_sr(void)
 22.2325 +{
 22.2326 +	sprintf(g_dasm_str, "ori     %s, SR", get_imm_str_u16());
 22.2327 +}
 22.2328 +
 22.2329 +static void d68020_pack_rr(void)
 22.2330 +{
 22.2331 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2332 +	sprintf(g_dasm_str, "pack    D%d, D%d, %s; (2+)", g_cpu_ir&7, (g_cpu_ir>>9)&7, get_imm_str_u16());
 22.2333 +}
 22.2334 +
 22.2335 +static void d68020_pack_mm(void)
 22.2336 +{
 22.2337 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2338 +	sprintf(g_dasm_str, "pack    -(A%d), -(A%d), %s; (2+)", g_cpu_ir&7, (g_cpu_ir>>9)&7, get_imm_str_u16());
 22.2339 +}
 22.2340 +
 22.2341 +static void d68000_pea(void)
 22.2342 +{
 22.2343 +	sprintf(g_dasm_str, "pea     %s", get_ea_mode_str_32(g_cpu_ir));
 22.2344 +}
 22.2345 +
 22.2346 +static void d68000_reset(void)
 22.2347 +{
 22.2348 +	sprintf(g_dasm_str, "reset");
 22.2349 +}
 22.2350 +
 22.2351 +static void d68000_ror_s_8(void)
 22.2352 +{
 22.2353 +	sprintf(g_dasm_str, "ror.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2354 +}
 22.2355 +
 22.2356 +static void d68000_ror_s_16(void)
 22.2357 +{
 22.2358 +	sprintf(g_dasm_str, "ror.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7],g_cpu_ir&7);
 22.2359 +}
 22.2360 +
 22.2361 +static void d68000_ror_s_32(void)
 22.2362 +{
 22.2363 +	sprintf(g_dasm_str, "ror.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2364 +}
 22.2365 +
 22.2366 +static void d68000_ror_r_8(void)
 22.2367 +{
 22.2368 +	sprintf(g_dasm_str, "ror.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2369 +}
 22.2370 +
 22.2371 +static void d68000_ror_r_16(void)
 22.2372 +{
 22.2373 +	sprintf(g_dasm_str, "ror.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2374 +}
 22.2375 +
 22.2376 +static void d68000_ror_r_32(void)
 22.2377 +{
 22.2378 +	sprintf(g_dasm_str, "ror.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2379 +}
 22.2380 +
 22.2381 +static void d68000_ror_ea(void)
 22.2382 +{
 22.2383 +	sprintf(g_dasm_str, "ror.w   %s", get_ea_mode_str_32(g_cpu_ir));
 22.2384 +}
 22.2385 +
 22.2386 +static void d68000_rol_s_8(void)
 22.2387 +{
 22.2388 +	sprintf(g_dasm_str, "rol.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2389 +}
 22.2390 +
 22.2391 +static void d68000_rol_s_16(void)
 22.2392 +{
 22.2393 +	sprintf(g_dasm_str, "rol.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2394 +}
 22.2395 +
 22.2396 +static void d68000_rol_s_32(void)
 22.2397 +{
 22.2398 +	sprintf(g_dasm_str, "rol.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2399 +}
 22.2400 +
 22.2401 +static void d68000_rol_r_8(void)
 22.2402 +{
 22.2403 +	sprintf(g_dasm_str, "rol.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2404 +}
 22.2405 +
 22.2406 +static void d68000_rol_r_16(void)
 22.2407 +{
 22.2408 +	sprintf(g_dasm_str, "rol.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2409 +}
 22.2410 +
 22.2411 +static void d68000_rol_r_32(void)
 22.2412 +{
 22.2413 +	sprintf(g_dasm_str, "rol.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2414 +}
 22.2415 +
 22.2416 +static void d68000_rol_ea(void)
 22.2417 +{
 22.2418 +	sprintf(g_dasm_str, "rol.w   %s", get_ea_mode_str_32(g_cpu_ir));
 22.2419 +}
 22.2420 +
 22.2421 +static void d68000_roxr_s_8(void)
 22.2422 +{
 22.2423 +	sprintf(g_dasm_str, "roxr.b  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2424 +}
 22.2425 +
 22.2426 +static void d68000_roxr_s_16(void)
 22.2427 +{
 22.2428 +	sprintf(g_dasm_str, "roxr.w  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2429 +}
 22.2430 +
 22.2431 +
 22.2432 +static void d68000_roxr_s_32(void)
 22.2433 +{
 22.2434 +	sprintf(g_dasm_str, "roxr.l  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2435 +}
 22.2436 +
 22.2437 +static void d68000_roxr_r_8(void)
 22.2438 +{
 22.2439 +	sprintf(g_dasm_str, "roxr.b  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2440 +}
 22.2441 +
 22.2442 +static void d68000_roxr_r_16(void)
 22.2443 +{
 22.2444 +	sprintf(g_dasm_str, "roxr.w  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2445 +}
 22.2446 +
 22.2447 +static void d68000_roxr_r_32(void)
 22.2448 +{
 22.2449 +	sprintf(g_dasm_str, "roxr.l  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2450 +}
 22.2451 +
 22.2452 +static void d68000_roxr_ea(void)
 22.2453 +{
 22.2454 +	sprintf(g_dasm_str, "roxr.w  %s", get_ea_mode_str_32(g_cpu_ir));
 22.2455 +}
 22.2456 +
 22.2457 +static void d68000_roxl_s_8(void)
 22.2458 +{
 22.2459 +	sprintf(g_dasm_str, "roxl.b  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2460 +}
 22.2461 +
 22.2462 +static void d68000_roxl_s_16(void)
 22.2463 +{
 22.2464 +	sprintf(g_dasm_str, "roxl.w  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2465 +}
 22.2466 +
 22.2467 +static void d68000_roxl_s_32(void)
 22.2468 +{
 22.2469 +	sprintf(g_dasm_str, "roxl.l  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
 22.2470 +}
 22.2471 +
 22.2472 +static void d68000_roxl_r_8(void)
 22.2473 +{
 22.2474 +	sprintf(g_dasm_str, "roxl.b  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2475 +}
 22.2476 +
 22.2477 +static void d68000_roxl_r_16(void)
 22.2478 +{
 22.2479 +	sprintf(g_dasm_str, "roxl.w  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2480 +}
 22.2481 +
 22.2482 +static void d68000_roxl_r_32(void)
 22.2483 +{
 22.2484 +	sprintf(g_dasm_str, "roxl.l  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
 22.2485 +}
 22.2486 +
 22.2487 +static void d68000_roxl_ea(void)
 22.2488 +{
 22.2489 +	sprintf(g_dasm_str, "roxl.w  %s", get_ea_mode_str_32(g_cpu_ir));
 22.2490 +}
 22.2491 +
 22.2492 +static void d68010_rtd(void)
 22.2493 +{
 22.2494 +	LIMIT_CPU_TYPES(M68010_PLUS);
 22.2495 +	sprintf(g_dasm_str, "rtd     %s; (1+)", get_imm_str_s16());
 22.2496 +}
 22.2497 +
 22.2498 +static void d68000_rte(void)
 22.2499 +{
 22.2500 +	sprintf(g_dasm_str, "rte");
 22.2501 +}
 22.2502 +
 22.2503 +static void d68020_rtm(void)
 22.2504 +{
 22.2505 +	LIMIT_CPU_TYPES(M68020_ONLY);
 22.2506 +	sprintf(g_dasm_str, "rtm     %c%d; (2+)", BIT_3(g_cpu_ir) ? 'A' : 'D', g_cpu_ir&7);
 22.2507 +}
 22.2508 +
 22.2509 +static void d68000_rtr(void)
 22.2510 +{
 22.2511 +	sprintf(g_dasm_str, "rtr");
 22.2512 +}
 22.2513 +
 22.2514 +static void d68000_rts(void)
 22.2515 +{
 22.2516 +	sprintf(g_dasm_str, "rts");
 22.2517 +}
 22.2518 +
 22.2519 +static void d68000_sbcd_rr(void)
 22.2520 +{
 22.2521 +	sprintf(g_dasm_str, "sbcd    D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.2522 +}
 22.2523 +
 22.2524 +static void d68000_sbcd_mm(void)
 22.2525 +{
 22.2526 +	sprintf(g_dasm_str, "sbcd    -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.2527 +}
 22.2528 +
 22.2529 +static void d68000_scc(void)
 22.2530 +{
 22.2531 +	sprintf(g_dasm_str, "s%-2s     %s", g_cc[(g_cpu_ir>>8)&0xf], get_ea_mode_str_8(g_cpu_ir));
 22.2532 +}
 22.2533 +
 22.2534 +static void d68000_stop(void)
 22.2535 +{
 22.2536 +	sprintf(g_dasm_str, "stop    %s", get_imm_str_s16());
 22.2537 +}
 22.2538 +
 22.2539 +static void d68000_sub_er_8(void)
 22.2540 +{
 22.2541 +	sprintf(g_dasm_str, "sub.b   %s, D%d", get_ea_mode_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2542 +}
 22.2543 +
 22.2544 +static void d68000_sub_er_16(void)
 22.2545 +{
 22.2546 +	sprintf(g_dasm_str, "sub.w   %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2547 +}
 22.2548 +
 22.2549 +static void d68000_sub_er_32(void)
 22.2550 +{
 22.2551 +	sprintf(g_dasm_str, "sub.l   %s, D%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2552 +}
 22.2553 +
 22.2554 +static void d68000_sub_re_8(void)
 22.2555 +{
 22.2556 +	sprintf(g_dasm_str, "sub.b   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
 22.2557 +}
 22.2558 +
 22.2559 +static void d68000_sub_re_16(void)
 22.2560 +{
 22.2561 +	sprintf(g_dasm_str, "sub.w   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_16(g_cpu_ir));
 22.2562 +}
 22.2563 +
 22.2564 +static void d68000_sub_re_32(void)
 22.2565 +{
 22.2566 +	sprintf(g_dasm_str, "sub.l   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_32(g_cpu_ir));
 22.2567 +}
 22.2568 +
 22.2569 +static void d68000_suba_16(void)
 22.2570 +{
 22.2571 +	sprintf(g_dasm_str, "suba.w  %s, A%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2572 +}
 22.2573 +
 22.2574 +static void d68000_suba_32(void)
 22.2575 +{
 22.2576 +	sprintf(g_dasm_str, "suba.l  %s, A%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
 22.2577 +}
 22.2578 +
 22.2579 +static void d68000_subi_8(void)
 22.2580 +{
 22.2581 +	char* str = get_imm_str_s8();
 22.2582 +	sprintf(g_dasm_str, "subi.b  %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
 22.2583 +}
 22.2584 +
 22.2585 +static void d68000_subi_16(void)
 22.2586 +{
 22.2587 +	char* str = get_imm_str_s16();
 22.2588 +	sprintf(g_dasm_str, "subi.w  %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
 22.2589 +}
 22.2590 +
 22.2591 +static void d68000_subi_32(void)
 22.2592 +{
 22.2593 +	char* str = get_imm_str_s32();
 22.2594 +	sprintf(g_dasm_str, "subi.l  %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
 22.2595 +}
 22.2596 +
 22.2597 +static void d68000_subq_8(void)
 22.2598 +{
 22.2599 +	sprintf(g_dasm_str, "subq.b  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_8(g_cpu_ir));
 22.2600 +}
 22.2601 +
 22.2602 +static void d68000_subq_16(void)
 22.2603 +{
 22.2604 +	sprintf(g_dasm_str, "subq.w  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_16(g_cpu_ir));
 22.2605 +}
 22.2606 +
 22.2607 +static void d68000_subq_32(void)
 22.2608 +{
 22.2609 +	sprintf(g_dasm_str, "subq.l  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_32(g_cpu_ir));
 22.2610 +}
 22.2611 +
 22.2612 +static void d68000_subx_rr_8(void)
 22.2613 +{
 22.2614 +	sprintf(g_dasm_str, "subx.b  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.2615 +}
 22.2616 +
 22.2617 +static void d68000_subx_rr_16(void)
 22.2618 +{
 22.2619 +	sprintf(g_dasm_str, "subx.w  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.2620 +}
 22.2621 +
 22.2622 +static void d68000_subx_rr_32(void)
 22.2623 +{
 22.2624 +	sprintf(g_dasm_str, "subx.l  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.2625 +}
 22.2626 +
 22.2627 +static void d68000_subx_mm_8(void)
 22.2628 +{
 22.2629 +	sprintf(g_dasm_str, "subx.b  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.2630 +}
 22.2631 +
 22.2632 +static void d68000_subx_mm_16(void)
 22.2633 +{
 22.2634 +	sprintf(g_dasm_str, "subx.w  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.2635 +}
 22.2636 +
 22.2637 +static void d68000_subx_mm_32(void)
 22.2638 +{
 22.2639 +	sprintf(g_dasm_str, "subx.l  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
 22.2640 +}
 22.2641 +
 22.2642 +static void d68000_swap(void)
 22.2643 +{
 22.2644 +	sprintf(g_dasm_str, "swap    D%d", g_cpu_ir&7);
 22.2645 +}
 22.2646 +
 22.2647 +static void d68000_tas(void)
 22.2648 +{
 22.2649 +	sprintf(g_dasm_str, "tas     %s", get_ea_mode_str_8(g_cpu_ir));
 22.2650 +}
 22.2651 +
 22.2652 +static void d68000_trap(void)
 22.2653 +{
 22.2654 +	sprintf(g_dasm_str, "trap    #$%x", g_cpu_ir&0xf);
 22.2655 +}
 22.2656 +
 22.2657 +static void d68020_trapcc_0(void)
 22.2658 +{
 22.2659 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2660 +	sprintf(g_dasm_str, "trap%-2s; (2+)", g_cc[(g_cpu_ir>>8)&0xf]);
 22.2661 +}
 22.2662 +
 22.2663 +static void d68020_trapcc_16(void)
 22.2664 +{
 22.2665 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2666 +	sprintf(g_dasm_str, "trap%-2s  %s; (2+)", g_cc[(g_cpu_ir>>8)&0xf], get_imm_str_u16());
 22.2667 +}
 22.2668 +
 22.2669 +static void d68020_trapcc_32(void)
 22.2670 +{
 22.2671 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2672 +	sprintf(g_dasm_str, "trap%-2s  %s; (2+)", g_cc[(g_cpu_ir>>8)&0xf], get_imm_str_u32());
 22.2673 +}
 22.2674 +
 22.2675 +static void d68000_trapv(void)
 22.2676 +{
 22.2677 +	sprintf(g_dasm_str, "trapv");
 22.2678 +}
 22.2679 +
 22.2680 +static void d68000_tst_8(void)
 22.2681 +{
 22.2682 +	sprintf(g_dasm_str, "tst.b   %s", get_ea_mode_str_8(g_cpu_ir));
 22.2683 +}
 22.2684 +
 22.2685 +static void d68020_tst_pcdi_8(void)
 22.2686 +{
 22.2687 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2688 +	sprintf(g_dasm_str, "tst.b   %s; (2+)", get_ea_mode_str_8(g_cpu_ir));
 22.2689 +}
 22.2690 +
 22.2691 +static void d68020_tst_pcix_8(void)
 22.2692 +{
 22.2693 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2694 +	sprintf(g_dasm_str, "tst.b   %s; (2+)", get_ea_mode_str_8(g_cpu_ir));
 22.2695 +}
 22.2696 +
 22.2697 +static void d68020_tst_i_8(void)
 22.2698 +{
 22.2699 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2700 +	sprintf(g_dasm_str, "tst.b   %s; (2+)", get_ea_mode_str_8(g_cpu_ir));
 22.2701 +}
 22.2702 +
 22.2703 +static void d68000_tst_16(void)
 22.2704 +{
 22.2705 +	sprintf(g_dasm_str, "tst.w   %s", get_ea_mode_str_16(g_cpu_ir));
 22.2706 +}
 22.2707 +
 22.2708 +static void d68020_tst_a_16(void)
 22.2709 +{
 22.2710 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2711 +	sprintf(g_dasm_str, "tst.w   %s; (2+)", get_ea_mode_str_16(g_cpu_ir));
 22.2712 +}
 22.2713 +
 22.2714 +static void d68020_tst_pcdi_16(void)
 22.2715 +{
 22.2716 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2717 +	sprintf(g_dasm_str, "tst.w   %s; (2+)", get_ea_mode_str_16(g_cpu_ir));
 22.2718 +}
 22.2719 +
 22.2720 +static void d68020_tst_pcix_16(void)
 22.2721 +{
 22.2722 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2723 +	sprintf(g_dasm_str, "tst.w   %s; (2+)", get_ea_mode_str_16(g_cpu_ir));
 22.2724 +}
 22.2725 +
 22.2726 +static void d68020_tst_i_16(void)
 22.2727 +{
 22.2728 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2729 +	sprintf(g_dasm_str, "tst.w   %s; (2+)", get_ea_mode_str_16(g_cpu_ir));
 22.2730 +}
 22.2731 +
 22.2732 +static void d68000_tst_32(void)
 22.2733 +{
 22.2734 +	sprintf(g_dasm_str, "tst.l   %s", get_ea_mode_str_32(g_cpu_ir));
 22.2735 +}
 22.2736 +
 22.2737 +static void d68020_tst_a_32(void)
 22.2738 +{
 22.2739 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2740 +	sprintf(g_dasm_str, "tst.l   %s; (2+)", get_ea_mode_str_32(g_cpu_ir));
 22.2741 +}
 22.2742 +
 22.2743 +static void d68020_tst_pcdi_32(void)
 22.2744 +{
 22.2745 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2746 +	sprintf(g_dasm_str, "tst.l   %s; (2+)", get_ea_mode_str_32(g_cpu_ir));
 22.2747 +}
 22.2748 +
 22.2749 +static void d68020_tst_pcix_32(void)
 22.2750 +{
 22.2751 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2752 +	sprintf(g_dasm_str, "tst.l   %s; (2+)", get_ea_mode_str_32(g_cpu_ir));
 22.2753 +}
 22.2754 +
 22.2755 +static void d68020_tst_i_32(void)
 22.2756 +{
 22.2757 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2758 +	sprintf(g_dasm_str, "tst.l   %s; (2+)", get_ea_mode_str_32(g_cpu_ir));
 22.2759 +}
 22.2760 +
 22.2761 +static void d68000_unlk(void)
 22.2762 +{
 22.2763 +	sprintf(g_dasm_str, "unlk    A%d", g_cpu_ir&7);
 22.2764 +}
 22.2765 +
 22.2766 +static void d68020_unpk_rr(void)
 22.2767 +{
 22.2768 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2769 +	sprintf(g_dasm_str, "unpk    D%d, D%d, %s; (2+)", g_cpu_ir&7, (g_cpu_ir>>9)&7, get_imm_str_u16());
 22.2770 +}
 22.2771 +
 22.2772 +static void d68020_unpk_mm(void)
 22.2773 +{
 22.2774 +	LIMIT_CPU_TYPES(M68020_PLUS);
 22.2775 +	sprintf(g_dasm_str, "unpk    -(A%d), -(A%d), %s; (2+)", g_cpu_ir&7, (g_cpu_ir>>9)&7, get_imm_str_u16());
 22.2776 +}
 22.2777 +
 22.2778 +
 22.2779 +
 22.2780 +/* ======================================================================== */
 22.2781 +/* ======================= INSTRUCTION TABLE BUILDER ====================== */
 22.2782 +/* ======================================================================== */
 22.2783 +
 22.2784 +/* EA Masks:
 22.2785 +800 = data register direct
 22.2786 +400 = address register direct
 22.2787 +200 = address register indirect
 22.2788 +100 = ARI postincrement
 22.2789 + 80 = ARI pre-decrement
 22.2790 + 40 = ARI displacement
 22.2791 + 20 = ARI index
 22.2792 + 10 = absolute short
 22.2793 +  8 = absolute long
 22.2794 +  4 = immediate / sr
 22.2795 +  2 = pc displacement
 22.2796 +  1 = pc idx
 22.2797 +*/
 22.2798 +
 22.2799 +static opcode_struct g_opcode_info[] =
 22.2800 +{
 22.2801 +/*  opcode handler    mask    match   ea mask */
 22.2802 +	{d68000_1010         , 0xf000, 0xa000, 0x000},
 22.2803 +	{d68000_1111         , 0xf000, 0xf000, 0x000},
 22.2804 +	{d68000_abcd_rr      , 0xf1f8, 0xc100, 0x000},
 22.2805 +	{d68000_abcd_mm      , 0xf1f8, 0xc108, 0x000},
 22.2806 +	{d68000_add_er_8     , 0xf1c0, 0xd000, 0xbff},
 22.2807 +	{d68000_add_er_16    , 0xf1c0, 0xd040, 0xfff},
 22.2808 +	{d68000_add_er_32    , 0xf1c0, 0xd080, 0xfff},
 22.2809 +	{d68000_add_re_8     , 0xf1c0, 0xd100, 0x3f8},
 22.2810 +	{d68000_add_re_16    , 0xf1c0, 0xd140, 0x3f8},
 22.2811 +	{d68000_add_re_32    , 0xf1c0, 0xd180, 0x3f8},
 22.2812 +	{d68000_adda_16      , 0xf1c0, 0xd0c0, 0xfff},
 22.2813 +	{d68000_adda_32      , 0xf1c0, 0xd1c0, 0xfff},
 22.2814 +	{d68000_addi_8       , 0xffc0, 0x0600, 0xbf8},
 22.2815 +	{d68000_addi_16      , 0xffc0, 0x0640, 0xbf8},
 22.2816 +	{d68000_addi_32      , 0xffc0, 0x0680, 0xbf8},
 22.2817 +	{d68000_addq_8       , 0xf1c0, 0x5000, 0xbf8},
 22.2818 +	{d68000_addq_16      , 0xf1c0, 0x5040, 0xff8},
 22.2819 +	{d68000_addq_32      , 0xf1c0, 0x5080, 0xff8},
 22.2820 +	{d68000_addx_rr_8    , 0xf1f8, 0xd100, 0x000},
 22.2821 +	{d68000_addx_rr_16   , 0xf1f8, 0xd140, 0x000},
 22.2822 +	{d68000_addx_rr_32   , 0xf1f8, 0xd180, 0x000},
 22.2823 +	{d68000_addx_mm_8    , 0xf1f8, 0xd108, 0x000},
 22.2824 +	{d68000_addx_mm_16   , 0xf1f8, 0xd148, 0x000},
 22.2825 +	{d68000_addx_mm_32   , 0xf1f8, 0xd188, 0x000},
 22.2826 +	{d68000_and_er_8     , 0xf1c0, 0xc000, 0xbff},
 22.2827 +	{d68000_and_er_16    , 0xf1c0, 0xc040, 0xbff},
 22.2828 +	{d68000_and_er_32    , 0xf1c0, 0xc080, 0xbff},
 22.2829 +	{d68000_and_re_8     , 0xf1c0, 0xc100, 0x3f8},
 22.2830 +	{d68000_and_re_16    , 0xf1c0, 0xc140, 0x3f8},
 22.2831 +	{d68000_and_re_32    , 0xf1c0, 0xc180, 0x3f8},
 22.2832 +	{d68000_andi_to_ccr  , 0xffff, 0x023c, 0x000},
 22.2833 +	{d68000_andi_to_sr   , 0xffff, 0x027c, 0x000},
 22.2834 +	{d68000_andi_8       , 0xffc0, 0x0200, 0xbf8},
 22.2835 +	{d68000_andi_16      , 0xffc0, 0x0240, 0xbf8},
 22.2836 +	{d68000_andi_32      , 0xffc0, 0x0280, 0xbf8},
 22.2837 +	{d68000_asr_s_8      , 0xf1f8, 0xe000, 0x000},
 22.2838 +	{d68000_asr_s_16     , 0xf1f8, 0xe040, 0x000},
 22.2839 +	{d68000_asr_s_32     , 0xf1f8, 0xe080, 0x000},
 22.2840 +	{d68000_asr_r_8      , 0xf1f8, 0xe020, 0x000},
 22.2841 +	{d68000_asr_r_16     , 0xf1f8, 0xe060, 0x000},
 22.2842 +	{d68000_asr_r_32     , 0xf1f8, 0xe0a0, 0x000},
 22.2843 +	{d68000_asr_ea       , 0xffc0, 0xe0c0, 0x3f8},
 22.2844 +	{d68000_asl_s_8      , 0xf1f8, 0xe100, 0x000},
 22.2845 +	{d68000_asl_s_16     , 0xf1f8, 0xe140, 0x000},
 22.2846 +	{d68000_asl_s_32     , 0xf1f8, 0xe180, 0x000},
 22.2847 +	{d68000_asl_r_8      , 0xf1f8, 0xe120, 0x000},
 22.2848 +	{d68000_asl_r_16     , 0xf1f8, 0xe160, 0x000},
 22.2849 +	{d68000_asl_r_32     , 0xf1f8, 0xe1a0, 0x000},
 22.2850 +	{d68000_asl_ea       , 0xffc0, 0xe1c0, 0x3f8},
 22.2851 +	{d68000_bcc_8        , 0xf000, 0x6000, 0x000},
 22.2852 +	{d68000_bcc_16       , 0xf0ff, 0x6000, 0x000},
 22.2853 +	{d68020_bcc_32       , 0xf0ff, 0x60ff, 0x000},
 22.2854 +	{d68000_bchg_r       , 0xf1c0, 0x0140, 0xbf8},
 22.2855 +	{d68000_bchg_s       , 0xffc0, 0x0840, 0xbf8},
 22.2856 +	{d68000_bclr_r       , 0xf1c0, 0x0180, 0xbf8},
 22.2857 +	{d68000_bclr_s       , 0xffc0, 0x0880, 0xbf8},
 22.2858 +	{d68020_bfchg        , 0xffc0, 0xeac0, 0xa78},
 22.2859 +	{d68020_bfclr        , 0xffc0, 0xecc0, 0xa78},
 22.2860 +	{d68020_bfexts       , 0xffc0, 0xebc0, 0xa7b},
 22.2861 +	{d68020_bfextu       , 0xffc0, 0xe9c0, 0xa7b},
 22.2862 +	{d68020_bfffo        , 0xffc0, 0xedc0, 0xa7b},
 22.2863 +	{d68020_bfins        , 0xffc0, 0xefc0, 0xa78},
 22.2864 +	{d68020_bfset        , 0xffc0, 0xeec0, 0xa78},
 22.2865 +	{d68020_bftst        , 0xffc0, 0xe8c0, 0xa7b},
 22.2866 +	{d68010_bkpt         , 0xfff8, 0x4848, 0x000},
 22.2867 +	{d68000_bra_8        , 0xff00, 0x6000, 0x000},
 22.2868 +	{d68000_bra_16       , 0xffff, 0x6000, 0x000},
 22.2869 +	{d68020_bra_32       , 0xffff, 0x60ff, 0x000},
 22.2870 +	{d68000_bset_r       , 0xf1c0, 0x01c0, 0xbf8},
 22.2871 +	{d68000_bset_s       , 0xffc0, 0x08c0, 0xbf8},
 22.2872 +	{d68000_bsr_8        , 0xff00, 0x6100, 0x000},
 22.2873 +	{d68000_bsr_16       , 0xffff, 0x6100, 0x000},
 22.2874 +	{d68020_bsr_32       , 0xffff, 0x61ff, 0x000},
 22.2875 +	{d68000_btst_r       , 0xf1c0, 0x0100, 0xbff},
 22.2876 +	{d68000_btst_s       , 0xffc0, 0x0800, 0xbfb},
 22.2877 +	{d68020_callm        , 0xffc0, 0x06c0, 0x27b},
 22.2878 +	{d68020_cas_8        , 0xffc0, 0x0ac0, 0x3f8},
 22.2879 +	{d68020_cas_16       , 0xffc0, 0x0cc0, 0x3f8},
 22.2880 +	{d68020_cas_32       , 0xffc0, 0x0ec0, 0x3f8},
 22.2881 +	{d68020_cas2_16      , 0xffff, 0x0cfc, 0x000},
 22.2882 +	{d68020_cas2_32      , 0xffff, 0x0efc, 0x000},
 22.2883 +	{d68000_chk_16       , 0xf1c0, 0x4180, 0xbff},
 22.2884 +	{d68020_chk_32       , 0xf1c0, 0x4100, 0xbff},
 22.2885 +	{d68020_chk2_cmp2_8  , 0xffc0, 0x00c0, 0x27b},
 22.2886 +	{d68020_chk2_cmp2_16 , 0xffc0, 0x02c0, 0x27b},
 22.2887 +	{d68020_chk2_cmp2_32 , 0xffc0, 0x04c0, 0x27b},
 22.2888 +	{d68040_cinv         , 0xff20, 0xf400, 0x000},
 22.2889 +	{d68000_clr_8        , 0xffc0, 0x4200, 0xbf8},
 22.2890 +	{d68000_clr_16       , 0xffc0, 0x4240, 0xbf8},
 22.2891 +	{d68000_clr_32       , 0xffc0, 0x4280, 0xbf8},
 22.2892 +	{d68000_cmp_8        , 0xf1c0, 0xb000, 0xbff},
 22.2893 +	{d68000_cmp_16       , 0xf1c0, 0xb040, 0xfff},
 22.2894 +	{d68000_cmp_32       , 0xf1c0, 0xb080, 0xfff},
 22.2895 +	{d68000_cmpa_16      , 0xf1c0, 0xb0c0, 0xfff},
 22.2896 +	{d68000_cmpa_32      , 0xf1c0, 0xb1c0, 0xfff},
 22.2897 +	{d68000_cmpi_8       , 0xffc0, 0x0c00, 0xbf8},
 22.2898 +	{d68020_cmpi_pcdi_8  , 0xffff, 0x0c3a, 0x000},
 22.2899 +	{d68020_cmpi_pcix_8  , 0xffff, 0x0c3b, 0x000},
 22.2900 +	{d68000_cmpi_16      , 0xffc0, 0x0c40, 0xbf8},
 22.2901 +	{d68020_cmpi_pcdi_16 , 0xffff, 0x0c7a, 0x000},
 22.2902 +	{d68020_cmpi_pcix_16 , 0xffff, 0x0c7b, 0x000},
 22.2903 +	{d68000_cmpi_32      , 0xffc0, 0x0c80, 0xbf8},
 22.2904 +	{d68020_cmpi_pcdi_32 , 0xffff, 0x0cba, 0x000},
 22.2905 +	{d68020_cmpi_pcix_32 , 0xffff, 0x0cbb, 0x000},
 22.2906 +	{d68000_cmpm_8       , 0xf1f8, 0xb108, 0x000},
 22.2907 +	{d68000_cmpm_16      , 0xf1f8, 0xb148, 0x000},
 22.2908 +	{d68000_cmpm_32      , 0xf1f8, 0xb188, 0x000},
 22.2909 +	{d68020_cpbcc_16     , 0xf1c0, 0xf080, 0x000},
 22.2910 +	{d68020_cpbcc_32     , 0xf1c0, 0xf0c0, 0x000},
 22.2911 +	{d68020_cpdbcc       , 0xf1f8, 0xf048, 0x000},
 22.2912 +	{d68020_cpgen        , 0xf1c0, 0xf000, 0x000},
 22.2913 +	{d68020_cprestore    , 0xf1c0, 0xf140, 0x37f},
 22.2914 +	{d68020_cpsave       , 0xf1c0, 0xf100, 0x2f8},
 22.2915 +	{d68020_cpscc        , 0xf1c0, 0xf040, 0xbf8},
 22.2916 +	{d68020_cptrapcc_0   , 0xf1ff, 0xf07c, 0x000},
 22.2917 +	{d68020_cptrapcc_16  , 0xf1ff, 0xf07a, 0x000},
 22.2918 +	{d68020_cptrapcc_32  , 0xf1ff, 0xf07b, 0x000},
 22.2919 +	{d68040_cpush        , 0xff20, 0xf420, 0x000},
 22.2920 +	{d68000_dbcc         , 0xf0f8, 0x50c8, 0x000},
 22.2921 +	{d68000_dbra         , 0xfff8, 0x51c8, 0x000},
 22.2922 +	{d68000_divs         , 0xf1c0, 0x81c0, 0xbff},
 22.2923 +	{d68000_divu         , 0xf1c0, 0x80c0, 0xbff},
 22.2924 +	{d68020_divl         , 0xffc0, 0x4c40, 0xbff},
 22.2925 +	{d68000_eor_8        , 0xf1c0, 0xb100, 0xbf8},
 22.2926 +	{d68000_eor_16       , 0xf1c0, 0xb140, 0xbf8},
 22.2927 +	{d68000_eor_32       , 0xf1c0, 0xb180, 0xbf8},
 22.2928 +	{d68000_eori_to_ccr  , 0xffff, 0x0a3c, 0x000},
 22.2929 +	{d68000_eori_to_sr   , 0xffff, 0x0a7c, 0x000},
 22.2930 +	{d68000_eori_8       , 0xffc0, 0x0a00, 0xbf8},
 22.2931 +	{d68000_eori_16      , 0xffc0, 0x0a40, 0xbf8},
 22.2932 +	{d68000_eori_32      , 0xffc0, 0x0a80, 0xbf8},
 22.2933 +	{d68000_exg_dd       , 0xf1f8, 0xc140, 0x000},
 22.2934 +	{d68000_exg_aa       , 0xf1f8, 0xc148, 0x000},
 22.2935 +	{d68000_exg_da       , 0xf1f8, 0xc188, 0x000},
 22.2936 +	{d68020_extb_32      , 0xfff8, 0x49c0, 0x000},
 22.2937 +	{d68000_ext_16       , 0xfff8, 0x4880, 0x000},
 22.2938 +	{d68000_ext_32       , 0xfff8, 0x48c0, 0x000},
 22.2939 +	{d68000_illegal      , 0xffff, 0x4afc, 0x000},
 22.2940 +	{d68000_jmp          , 0xffc0, 0x4ec0, 0x27b},
 22.2941 +	{d68000_jsr          , 0xffc0, 0x4e80, 0x27b},
 22.2942 +	{d68000_lea          , 0xf1c0, 0x41c0, 0x27b},
 22.2943 +	{d68000_link_16      , 0xfff8, 0x4e50, 0x000},
 22.2944 +	{d68020_link_32      , 0xfff8, 0x4808, 0x000},
 22.2945 +	{d68000_lsr_s_8      , 0xf1f8, 0xe008, 0x000},
 22.2946 +	{d68000_lsr_s_16     , 0xf1f8, 0xe048, 0x000},
 22.2947 +	{d68000_lsr_s_32     , 0xf1f8, 0xe088, 0x000},
 22.2948 +	{d68000_lsr_r_8      , 0xf1f8, 0xe028, 0x000},
 22.2949 +	{d68000_lsr_r_16     , 0xf1f8, 0xe068, 0x000},
 22.2950 +	{d68000_lsr_r_32     , 0xf1f8, 0xe0a8, 0x000},
 22.2951 +	{d68000_lsr_ea       , 0xffc0, 0xe2c0, 0x3f8},
 22.2952 +	{d68000_lsl_s_8      , 0xf1f8, 0xe108, 0x000},
 22.2953 +	{d68000_lsl_s_16     , 0xf1f8, 0xe148, 0x000},
 22.2954 +	{d68000_lsl_s_32     , 0xf1f8, 0xe188, 0x000},
 22.2955 +	{d68000_lsl_r_8      , 0xf1f8, 0xe128, 0x000},
 22.2956 +	{d68000_lsl_r_16     , 0xf1f8, 0xe168, 0x000},
 22.2957 +	{d68000_lsl_r_32     , 0xf1f8, 0xe1a8, 0x000},
 22.2958 +	{d68000_lsl_ea       , 0xffc0, 0xe3c0, 0x3f8},
 22.2959 +	{d68000_move_8       , 0xf000, 0x1000, 0xbff},
 22.2960 +	{d68000_move_16      , 0xf000, 0x3000, 0xfff},
 22.2961 +	{d68000_move_32      , 0xf000, 0x2000, 0xfff},
 22.2962 +	{d68000_movea_16     , 0xf1c0, 0x3040, 0xfff},
 22.2963 +	{d68000_movea_32     , 0xf1c0, 0x2040, 0xfff},
 22.2964 +	{d68000_move_to_ccr  , 0xffc0, 0x44c0, 0xbff},
 22.2965 +	{d68010_move_fr_ccr  , 0xffc0, 0x42c0, 0xbf8},
 22.2966 +	{d68000_move_to_sr   , 0xffc0, 0x46c0, 0xbff},
 22.2967 +	{d68000_move_fr_sr   , 0xffc0, 0x40c0, 0xbf8},
 22.2968 +	{d68000_move_to_usp  , 0xfff8, 0x4e60, 0x000},
 22.2969 +	{d68000_move_fr_usp  , 0xfff8, 0x4e68, 0x000},
 22.2970 +	{d68010_movec        , 0xfffe, 0x4e7a, 0x000},
 22.2971 +	{d68000_movem_pd_16  , 0xfff8, 0x48a0, 0x000},
 22.2972 +	{d68000_movem_pd_32  , 0xfff8, 0x48e0, 0x000},
 22.2973 +	{d68000_movem_re_16  , 0xffc0, 0x4880, 0x2f8},
 22.2974 +	{d68000_movem_re_32  , 0xffc0, 0x48c0, 0x2f8},
 22.2975 +	{d68000_movem_er_16  , 0xffc0, 0x4c80, 0x37b},
 22.2976 +	{d68000_movem_er_32  , 0xffc0, 0x4cc0, 0x37b},
 22.2977 +	{d68000_movep_er_16  , 0xf1f8, 0x0108, 0x000},
 22.2978 +	{d68000_movep_er_32  , 0xf1f8, 0x0148, 0x000},
 22.2979 +	{d68000_movep_re_16  , 0xf1f8, 0x0188, 0x000},
 22.2980 +	{d68000_movep_re_32  , 0xf1f8, 0x01c8, 0x000},
 22.2981 +	{d68010_moves_8      , 0xffc0, 0x0e00, 0x3f8},
 22.2982 +	{d68010_moves_16     , 0xffc0, 0x0e40, 0x3f8},
 22.2983 +	{d68010_moves_32     , 0xffc0, 0x0e80, 0x3f8},
 22.2984 +	{d68000_moveq        , 0xf100, 0x7000, 0x000},
 22.2985 +	{d68040_move16_pi_pi , 0xfff8, 0xf620, 0x000},
 22.2986 +	{d68040_move16_pi_al , 0xfff8, 0xf600, 0x000},
 22.2987 +	{d68040_move16_al_pi , 0xfff8, 0xf608, 0x000},
 22.2988 +	{d68040_move16_ai_al , 0xfff8, 0xf610, 0x000},
 22.2989 +	{d68040_move16_al_ai , 0xfff8, 0xf618, 0x000},
 22.2990 +	{d68000_muls         , 0xf1c0, 0xc1c0, 0xbff},
 22.2991 +	{d68000_mulu         , 0xf1c0, 0xc0c0, 0xbff},
 22.2992 +	{d68020_mull         , 0xffc0, 0x4c00, 0xbff},
 22.2993 +	{d68000_nbcd         , 0xffc0, 0x4800, 0xbf8},
 22.2994 +	{d68000_neg_8        , 0xffc0, 0x4400, 0xbf8},
 22.2995 +	{d68000_neg_16       , 0xffc0, 0x4440, 0xbf8},
 22.2996 +	{d68000_neg_32       , 0xffc0, 0x4480, 0xbf8},
 22.2997 +	{d68000_negx_8       , 0xffc0, 0x4000, 0xbf8},
 22.2998 +	{d68000_negx_16      , 0xffc0, 0x4040, 0xbf8},
 22.2999 +	{d68000_negx_32      , 0xffc0, 0x4080, 0xbf8},
 22.3000 +	{d68000_nop          , 0xffff, 0x4e71, 0x000},
 22.3001 +	{d68000_not_8        , 0xffc0, 0x4600, 0xbf8},
 22.3002 +	{d68000_not_16       , 0xffc0, 0x4640, 0xbf8},
 22.3003 +	{d68000_not_32       , 0xffc0, 0x4680, 0xbf8},
 22.3004 +	{d68000_or_er_8      , 0xf1c0, 0x8000, 0xbff},
 22.3005 +	{d68000_or_er_16     , 0xf1c0, 0x8040, 0xbff},
 22.3006 +	{d68000_or_er_32     , 0xf1c0, 0x8080, 0xbff},
 22.3007 +	{d68000_or_re_8      , 0xf1c0, 0x8100, 0x3f8},
 22.3008 +	{d68000_or_re_16     , 0xf1c0, 0x8140, 0x3f8},
 22.3009 +	{d68000_or_re_32     , 0xf1c0, 0x8180, 0x3f8},
 22.3010 +	{d68000_ori_to_ccr   , 0xffff, 0x003c, 0x000},
 22.3011 +	{d68000_ori_to_sr    , 0xffff, 0x007c, 0x000},
 22.3012 +	{d68000_ori_8        , 0xffc0, 0x0000, 0xbf8},
 22.3013 +	{d68000_ori_16       , 0xffc0, 0x0040, 0xbf8},
 22.3014 +	{d68000_ori_32       , 0xffc0, 0x0080, 0xbf8},
 22.3015 +	{d68020_pack_rr      , 0xf1f8, 0x8140, 0x000},
 22.3016 +	{d68020_pack_mm      , 0xf1f8, 0x8148, 0x000},
 22.3017 +	{d68000_pea          , 0xffc0, 0x4840, 0x27b},
 22.3018 +	{d68000_reset        , 0xffff, 0x4e70, 0x000},
 22.3019 +	{d68000_ror_s_8      , 0xf1f8, 0xe018, 0x000},
 22.3020 +	{d68000_ror_s_16     , 0xf1f8, 0xe058, 0x000},
 22.3021 +	{d68000_ror_s_32     , 0xf1f8, 0xe098, 0x000},
 22.3022 +	{d68000_ror_r_8      , 0xf1f8, 0xe038, 0x000},
 22.3023 +	{d68000_ror_r_16     , 0xf1f8, 0xe078, 0x000},
 22.3024 +	{d68000_ror_r_32     , 0xf1f8, 0xe0b8, 0x000},
 22.3025 +	{d68000_ror_ea       , 0xffc0, 0xe6c0, 0x3f8},
 22.3026 +	{d68000_rol_s_8      , 0xf1f8, 0xe118, 0x000},
 22.3027 +	{d68000_rol_s_16     , 0xf1f8, 0xe158, 0x000},
 22.3028 +	{d68000_rol_s_32     , 0xf1f8, 0xe198, 0x000},
 22.3029 +	{d68000_rol_r_8      , 0xf1f8, 0xe138, 0x000},
 22.3030 +	{d68000_rol_r_16     , 0xf1f8, 0xe178, 0x000},
 22.3031 +	{d68000_rol_r_32     , 0xf1f8, 0xe1b8, 0x000},
 22.3032 +	{d68000_rol_ea       , 0xffc0, 0xe7c0, 0x3f8},
 22.3033 +	{d68000_roxr_s_8     , 0xf1f8, 0xe010, 0x000},
 22.3034 +	{d68000_roxr_s_16    , 0xf1f8, 0xe050, 0x000},
 22.3035 +	{d68000_roxr_s_32    , 0xf1f8, 0xe090, 0x000},
 22.3036 +	{d68000_roxr_r_8     , 0xf1f8, 0xe030, 0x000},
 22.3037 +	{d68000_roxr_r_16    , 0xf1f8, 0xe070, 0x000},
 22.3038 +	{d68000_roxr_r_32    , 0xf1f8, 0xe0b0, 0x000},
 22.3039 +	{d68000_roxr_ea      , 0xffc0, 0xe4c0, 0x3f8},
 22.3040 +	{d68000_roxl_s_8     , 0xf1f8, 0xe110, 0x000},
 22.3041 +	{d68000_roxl_s_16    , 0xf1f8, 0xe150, 0x000},
 22.3042 +	{d68000_roxl_s_32    , 0xf1f8, 0xe190, 0x000},
 22.3043 +	{d68000_roxl_r_8     , 0xf1f8, 0xe130, 0x000},
 22.3044 +	{d68000_roxl_r_16    , 0xf1f8, 0xe170, 0x000},
 22.3045 +	{d68000_roxl_r_32    , 0xf1f8, 0xe1b0, 0x000},
 22.3046 +	{d68000_roxl_ea      , 0xffc0, 0xe5c0, 0x3f8},
 22.3047 +	{d68010_rtd          , 0xffff, 0x4e74, 0x000},
 22.3048 +	{d68000_rte          , 0xffff, 0x4e73, 0x000},
 22.3049 +	{d68020_rtm          , 0xfff0, 0x06c0, 0x000},
 22.3050 +	{d68000_rtr          , 0xffff, 0x4e77, 0x000},
 22.3051 +	{d68000_rts          , 0xffff, 0x4e75, 0x000},
 22.3052 +	{d68000_sbcd_rr      , 0xf1f8, 0x8100, 0x000},
 22.3053 +	{d68000_sbcd_mm      , 0xf1f8, 0x8108, 0x000},
 22.3054 +	{d68000_scc          , 0xf0c0, 0x50c0, 0xbf8},
 22.3055 +	{d68000_stop         , 0xffff, 0x4e72, 0x000},
 22.3056 +	{d68000_sub_er_8     , 0xf1c0, 0x9000, 0xbff},
 22.3057 +	{d68000_sub_er_16    , 0xf1c0, 0x9040, 0xfff},
 22.3058 +	{d68000_sub_er_32    , 0xf1c0, 0x9080, 0xfff},
 22.3059 +	{d68000_sub_re_8     , 0xf1c0, 0x9100, 0x3f8},
 22.3060 +	{d68000_sub_re_16    , 0xf1c0, 0x9140, 0x3f8},
 22.3061 +	{d68000_sub_re_32    , 0xf1c0, 0x9180, 0x3f8},
 22.3062 +	{d68000_suba_16      , 0xf1c0, 0x90c0, 0xfff},
 22.3063 +	{d68000_suba_32      , 0xf1c0, 0x91c0, 0xfff},
 22.3064 +	{d68000_subi_8       , 0xffc0, 0x0400, 0xbf8},
 22.3065 +	{d68000_subi_16      , 0xffc0, 0x0440, 0xbf8},
 22.3066 +	{d68000_subi_32      , 0xffc0, 0x0480, 0xbf8},
 22.3067 +	{d68000_subq_8       , 0xf1c0, 0x5100, 0xbf8},
 22.3068 +	{d68000_subq_16      , 0xf1c0, 0x5140, 0xff8},
 22.3069 +	{d68000_subq_32      , 0xf1c0, 0x5180, 0xff8},
 22.3070 +	{d68000_subx_rr_8    , 0xf1f8, 0x9100, 0x000},
 22.3071 +	{d68000_subx_rr_16   , 0xf1f8, 0x9140, 0x000},
 22.3072 +	{d68000_subx_rr_32   , 0xf1f8, 0x9180, 0x000},
 22.3073 +	{d68000_subx_mm_8    , 0xf1f8, 0x9108, 0x000},
 22.3074 +	{d68000_subx_mm_16   , 0xf1f8, 0x9148, 0x000},
 22.3075 +	{d68000_subx_mm_32   , 0xf1f8, 0x9188, 0x000},
 22.3076 +	{d68000_swap         , 0xfff8, 0x4840, 0x000},
 22.3077 +	{d68000_tas          , 0xffc0, 0x4ac0, 0xbf8},
 22.3078 +	{d68000_trap         , 0xfff0, 0x4e40, 0x000},
 22.3079 +	{d68020_trapcc_0     , 0xf0ff, 0x50fc, 0x000},
 22.3080 +	{d68020_trapcc_16    , 0xf0ff, 0x50fa, 0x000},
 22.3081 +	{d68020_trapcc_32    , 0xf0ff, 0x50fb, 0x000},
 22.3082 +	{d68000_trapv        , 0xffff, 0x4e76, 0x000},
 22.3083 +	{d68000_tst_8        , 0xffc0, 0x4a00, 0xbf8},
 22.3084 +	{d68020_tst_pcdi_8   , 0xffff, 0x4a3a, 0x000},
 22.3085 +	{d68020_tst_pcix_8   , 0xffff, 0x4a3b, 0x000},
 22.3086 +	{d68020_tst_i_8      , 0xffff, 0x4a3c, 0x000},
 22.3087 +	{d68000_tst_16       , 0xffc0, 0x4a40, 0xbf8},
 22.3088 +	{d68020_tst_a_16     , 0xfff8, 0x4a48, 0x000},
 22.3089 +	{d68020_tst_pcdi_16  , 0xffff, 0x4a7a, 0x000},
 22.3090 +	{d68020_tst_pcix_16  , 0xffff, 0x4a7b, 0x000},
 22.3091 +	{d68020_tst_i_16     , 0xffff, 0x4a7c, 0x000},
 22.3092 +	{d68000_tst_32       , 0xffc0, 0x4a80, 0xbf8},
 22.3093 +	{d68020_tst_a_32     , 0xfff8, 0x4a88, 0x000},
 22.3094 +	{d68020_tst_pcdi_32  , 0xffff, 0x4aba, 0x000},
 22.3095 +	{d68020_tst_pcix_32  , 0xffff, 0x4abb, 0x000},
 22.3096 +	{d68020_tst_i_32     , 0xffff, 0x4abc, 0x000},
 22.3097 +	{d68000_unlk         , 0xfff8, 0x4e58, 0x000},
 22.3098 +	{d68020_unpk_rr      , 0xf1f8, 0x8180, 0x000},
 22.3099 +	{d68020_unpk_mm      , 0xf1f8, 0x8188, 0x000},
 22.3100 +	{0, 0, 0, 0}
 22.3101 +};
 22.3102 +
 22.3103 +/* Check if opcode is using a valid ea mode */
 22.3104 +static int valid_ea(uint opcode, uint mask)
 22.3105 +{
 22.3106 +	if(mask == 0)
 22.3107 +		return 1;
 22.3108 +
 22.3109 +	switch(opcode & 0x3f)
 22.3110 +	{
 22.3111 +		case 0x00: case 0x01: case 0x02: case 0x03:
 22.3112 +		case 0x04: case 0x05: case 0x06: case 0x07:
 22.3113 +			return (mask & 0x800) != 0;
 22.3114 +		case 0x08: case 0x09: case 0x0a: case 0x0b:
 22.3115 +		case 0x0c: case 0x0d: case 0x0e: case 0x0f:
 22.3116 +			return (mask & 0x400) != 0;
 22.3117 +		case 0x10: case 0x11: case 0x12: case 0x13:
 22.3118 +		case 0x14: case 0x15: case 0x16: case 0x17:
 22.3119 +			return (mask & 0x200) != 0;
 22.3120 +		case 0x18: case 0x19: case 0x1a: case 0x1b:
 22.3121 +		case 0x1c: case 0x1d: case 0x1e: case 0x1f:
 22.3122 +			return (mask & 0x100) != 0;
 22.3123 +		case 0x20: case 0x21: case 0x22: case 0x23:
 22.3124 +		case 0x24: case 0x25: case 0x26: case 0x27:
 22.3125 +			return (mask & 0x080) != 0;
 22.3126 +		case 0x28: case 0x29: case 0x2a: case 0x2b:
 22.3127 +		case 0x2c: case 0x2d: case 0x2e: case 0x2f:
 22.3128 +			return (mask & 0x040) != 0;
 22.3129 +		case 0x30: case 0x31: case 0x32: case 0x33:
 22.3130 +		case 0x34: case 0x35: case 0x36: case 0x37:
 22.3131 +			return (mask & 0x020) != 0;
 22.3132 +		case 0x38:
 22.3133 +			return (mask & 0x010) != 0;
 22.3134 +		case 0x39:
 22.3135 +			return (mask & 0x008) != 0;
 22.3136 +		case 0x3a:
 22.3137 +			return (mask & 0x002) != 0;
 22.3138 +		case 0x3b:
 22.3139 +			return (mask & 0x001) != 0;
 22.3140 +		case 0x3c:
 22.3141 +			return (mask & 0x004) != 0;
 22.3142 +	}
 22.3143 +	return 0;
 22.3144 +
 22.3145 +}
 22.3146 +
 22.3147 +/* Used by qsort */
 22.3148 +static int DECL_SPEC compare_nof_true_bits(const void *aptr, const void *bptr)
 22.3149 +{
 22.3150 +	uint a = ((const opcode_struct*)aptr)->mask;
 22.3151 +	uint b = ((const opcode_struct*)bptr)->mask;
 22.3152 +
 22.3153 +	a = ((a & 0xAAAA) >> 1) + (a & 0x5555);
 22.3154 +	a = ((a & 0xCCCC) >> 2) + (a & 0x3333);
 22.3155 +	a = ((a & 0xF0F0) >> 4) + (a & 0x0F0F);
 22.3156 +	a = ((a & 0xFF00) >> 8) + (a & 0x00FF);
 22.3157 +
 22.3158 +	b = ((b & 0xAAAA) >> 1) + (b & 0x5555);
 22.3159 +	b = ((b & 0xCCCC) >> 2) + (b & 0x3333);
 22.3160 +	b = ((b & 0xF0F0) >> 4) + (b & 0x0F0F);
 22.3161 +	b = ((b & 0xFF00) >> 8) + (b & 0x00FF);
 22.3162 +
 22.3163 +	return b - a; /* reversed to get greatest to least sorting */
 22.3164 +}
 22.3165 +
 22.3166 +/* build the opcode handler jump table */
 22.3167 +static void build_opcode_table(void)
 22.3168 +{
 22.3169 +	uint i;
 22.3170 +	uint opcode;
 22.3171 +	opcode_struct* ostruct;
 22.3172 +	uint opcode_info_length = 0;
 22.3173 +
 22.3174 +	for(ostruct = g_opcode_info;ostruct->opcode_handler != 0;ostruct++)
 22.3175 +		opcode_info_length++;
 22.3176 +
 22.3177 +	qsort((void *)g_opcode_info, opcode_info_length, sizeof(g_opcode_info[0]), compare_nof_true_bits);
 22.3178 +
 22.3179 +	for(i=0;i<0x10000;i++)
 22.3180 +	{
 22.3181 +		g_instruction_table[i] = d68000_illegal; /* default to illegal */
 22.3182 +		opcode = i;
 22.3183 +		/* search through opcode info for a match */
 22.3184 +		for(ostruct = g_opcode_info;ostruct->opcode_handler != 0;ostruct++)
 22.3185 +		{
 22.3186 +			/* match opcode mask and allowed ea modes */
 22.3187 +			if((opcode & ostruct->mask) == ostruct->match)
 22.3188 +			{
 22.3189 +				/* Handle destination ea for move instructions */
 22.3190 +				if((ostruct->opcode_handler == d68000_move_8 ||
 22.3191 +					 ostruct->opcode_handler == d68000_move_16 ||
 22.3192 +					 ostruct->opcode_handler == d68000_move_32) &&
 22.3193 +					 !valid_ea(((opcode>>9)&7) | ((opcode>>3)&0x38), 0xbf8))
 22.3194 +						continue;
 22.3195 +				if(valid_ea(opcode, ostruct->ea_mask))
 22.3196 +				{
 22.3197 +					g_instruction_table[i] = ostruct->opcode_handler;
 22.3198 +					break;
 22.3199 +				}
 22.3200 +			}
 22.3201 +		}
 22.3202 +	}
 22.3203 +}
 22.3204 +
 22.3205 +
 22.3206 +
 22.3207 +/* ======================================================================== */
 22.3208 +/* ================================= API ================================== */
 22.3209 +/* ======================================================================== */
 22.3210 +
 22.3211 +/* Disasemble one instruction at pc and store in str_buff */
 22.3212 +unsigned int m68k_disassemble(char* str_buff, unsigned int pc, unsigned int cpu_type)
 22.3213 +{
 22.3214 +	if(!g_initialized)
 22.3215 +	{
 22.3216 +		build_opcode_table();
 22.3217 +		g_initialized = 1;
 22.3218 +	}
 22.3219 +	switch(cpu_type)
 22.3220 +	{
 22.3221 +		case M68K_CPU_TYPE_68000:
 22.3222 +			g_cpu_type = TYPE_68000;
 22.3223 +			g_address_mask = 0x00ffffff;
 22.3224 +			break;
 22.3225 +		case M68K_CPU_TYPE_68010:
 22.3226 +			g_cpu_type = TYPE_68010;
 22.3227 +			g_address_mask = 0x00ffffff;
 22.3228 +			break;
 22.3229 +		case M68K_CPU_TYPE_68EC020:
 22.3230 +			g_cpu_type = TYPE_68020;
 22.3231 +			g_address_mask = 0x00ffffff;
 22.3232 +			break;
 22.3233 +		case M68K_CPU_TYPE_68020:
 22.3234 +			g_cpu_type = TYPE_68020;
 22.3235 +			g_address_mask = 0xffffffff;
 22.3236 +			break;
 22.3237 +		case M68K_CPU_TYPE_68030:
 22.3238 +			g_cpu_type = TYPE_68030;
 22.3239 +			g_address_mask = 0xffffffff;
 22.3240 +			break;
 22.3241 +		case M68K_CPU_TYPE_68040:
 22.3242 +			g_cpu_type = TYPE_68040;
 22.3243 +			g_address_mask = 0xffffffff;
 22.3244 +			break;
 22.3245 +		default:
 22.3246 +			return 0;
 22.3247 +	}
 22.3248 +
 22.3249 +	g_cpu_pc = pc;
 22.3250 +	g_helper_str[0] = 0;
 22.3251 +	g_cpu_ir = read_imm_16();
 22.3252 +	g_instruction_table[g_cpu_ir]();
 22.3253 +	sprintf(str_buff, "%s%s", g_dasm_str, g_helper_str);
 22.3254 +	return g_cpu_pc - pc;
 22.3255 +}
 22.3256 +
 22.3257 +char* m68ki_disassemble_quick(unsigned int pc, unsigned int cpu_type)
 22.3258 +{
 22.3259 +	static char buff[100];
 22.3260 +	buff[0] = 0;
 22.3261 +	m68k_disassemble(buff, pc, cpu_type);
 22.3262 +	return buff;
 22.3263 +}
 22.3264 +
 22.3265 +/* Check if the instruction is a valid one */
 22.3266 +unsigned int m68k_is_valid_instruction(unsigned int instruction, unsigned int cpu_type)
 22.3267 +{
 22.3268 +	if(!g_initialized)
 22.3269 +	{
 22.3270 +		build_opcode_table();
 22.3271 +		g_initialized = 1;
 22.3272 +	}
 22.3273 +
 22.3274 +	instruction &= 0xffff;
 22.3275 +	if(g_instruction_table[instruction] == d68000_illegal)
 22.3276 +		return 0;
 22.3277 +
 22.3278 +	switch(cpu_type)
 22.3279 +	{
 22.3280 +		case M68K_CPU_TYPE_68000:
 22.3281 +			if(g_instruction_table[instruction] == d68010_bkpt)
 22.3282 +				return 0;
 22.3283 +			if(g_instruction_table[instruction] == d68010_move_fr_ccr)
 22.3284 +				return 0;
 22.3285 +			if(g_instruction_table[instruction] == d68010_movec)
 22.3286 +				return 0;
 22.3287 +			if(g_instruction_table[instruction] == d68010_moves_8)
 22.3288 +				return 0;
 22.3289 +			if(g_instruction_table[instruction] == d68010_moves_16)
 22.3290 +				return 0;
 22.3291 +			if(g_instruction_table[instruction] == d68010_moves_32)
 22.3292 +				return 0;
 22.3293 +			if(g_instruction_table[instruction] == d68010_rtd)
 22.3294 +				return 0;
 22.3295 +		case M68K_CPU_TYPE_68010:
 22.3296 +			if(g_instruction_table[instruction] == d68020_bcc_32)
 22.3297 +				return 0;
 22.3298 +			if(g_instruction_table[instruction] == d68020_bfchg)
 22.3299 +				return 0;
 22.3300 +			if(g_instruction_table[instruction] == d68020_bfclr)
 22.3301 +				return 0;
 22.3302 +			if(g_instruction_table[instruction] == d68020_bfexts)
 22.3303 +				return 0;
 22.3304 +			if(g_instruction_table[instruction] == d68020_bfextu)
 22.3305 +				return 0;
 22.3306 +			if(g_instruction_table[instruction] == d68020_bfffo)
 22.3307 +				return 0;
 22.3308 +			if(g_instruction_table[instruction] == d68020_bfins)
 22.3309 +				return 0;
 22.3310 +			if(g_instruction_table[instruction] == d68020_bfset)
 22.3311 +				return 0;
 22.3312 +			if(g_instruction_table[instruction] == d68020_bftst)
 22.3313 +				return 0;
 22.3314 +			if(g_instruction_table[instruction] == d68020_bra_32)
 22.3315 +				return 0;
 22.3316 +			if(g_instruction_table[instruction] == d68020_bsr_32)
 22.3317 +				return 0;
 22.3318 +			if(g_instruction_table[instruction] == d68020_callm)
 22.3319 +				return 0;
 22.3320 +			if(g_instruction_table[instruction] == d68020_cas_8)
 22.3321 +				return 0;
 22.3322 +			if(g_instruction_table[instruction] == d68020_cas_16)
 22.3323 +				return 0;
 22.3324 +			if(g_instruction_table[instruction] == d68020_cas_32)
 22.3325 +				return 0;
 22.3326 +			if(g_instruction_table[instruction] == d68020_cas2_16)
 22.3327 +				return 0;
 22.3328 +			if(g_instruction_table[instruction] == d68020_cas2_32)
 22.3329 +				return 0;
 22.3330 +			if(g_instruction_table[instruction] == d68020_chk_32)
 22.3331 +				return 0;
 22.3332 +			if(g_instruction_table[instruction] == d68020_chk2_cmp2_8)
 22.3333 +				return 0;
 22.3334 +			if(g_instruction_table[instruction] == d68020_chk2_cmp2_16)
 22.3335 +				return 0;
 22.3336 +			if(g_instruction_table[instruction] == d68020_chk2_cmp2_32)
 22.3337 +				return 0;
 22.3338 +			if(g_instruction_table[instruction] == d68020_cmpi_pcdi_8)
 22.3339 +				return 0;
 22.3340 +			if(g_instruction_table[instruction] == d68020_cmpi_pcix_8)
 22.3341 +				return 0;
 22.3342 +			if(g_instruction_table[instruction] == d68020_cmpi_pcdi_16)
 22.3343 +				return 0;
 22.3344 +			if(g_instruction_table[instruction] == d68020_cmpi_pcix_16)
 22.3345 +				return 0;
 22.3346 +			if(g_instruction_table[instruction] == d68020_cmpi_pcdi_32)
 22.3347 +				return 0;
 22.3348 +			if(g_instruction_table[instruction] == d68020_cmpi_pcix_32)
 22.3349 +				return 0;
 22.3350 +			if(g_instruction_table[instruction] == d68020_cpbcc_16)
 22.3351 +				return 0;
 22.3352 +			if(g_instruction_table[instruction] == d68020_cpbcc_32)
 22.3353 +				return 0;
 22.3354 +			if(g_instruction_table[instruction] == d68020_cpdbcc)
 22.3355 +				return 0;
 22.3356 +			if(g_instruction_table[instruction] == d68020_cpgen)
 22.3357 +				return 0;
 22.3358 +			if(g_instruction_table[instruction] == d68020_cprestore)
 22.3359 +				return 0;
 22.3360 +			if(g_instruction_table[instruction] == d68020_cpsave)
 22.3361 +				return 0;
 22.3362 +			if(g_instruction_table[instruction] == d68020_cpscc)
 22.3363 +				return 0;
 22.3364 +			if(g_instruction_table[instruction] == d68020_cptrapcc_0)
 22.3365 +				return 0;
 22.3366 +			if(g_instruction_table[instruction] == d68020_cptrapcc_16)
 22.3367 +				return 0;
 22.3368 +			if(g_instruction_table[instruction] == d68020_cptrapcc_32)
 22.3369 +				return 0;
 22.3370 +			if(g_instruction_table[instruction] == d68020_divl)
 22.3371 +				return 0;
 22.3372 +			if(g_instruction_table[instruction] == d68020_extb_32)
 22.3373 +				return 0;
 22.3374 +			if(g_instruction_table[instruction] == d68020_link_32)
 22.3375 +				return 0;
 22.3376 +			if(g_instruction_table[instruction] == d68020_mull)
 22.3377 +				return 0;
 22.3378 +			if(g_instruction_table[instruction] == d68020_pack_rr)
 22.3379 +				return 0;
 22.3380 +			if(g_instruction_table[instruction] == d68020_pack_mm)
 22.3381 +				return 0;
 22.3382 +			if(g_instruction_table[instruction] == d68020_rtm)
 22.3383 +				return 0;
 22.3384 +			if(g_instruction_table[instruction] == d68020_trapcc_0)
 22.3385 +				return 0;
 22.3386 +			if(g_instruction_table[instruction] == d68020_trapcc_16)
 22.3387 +				return 0;
 22.3388 +			if(g_instruction_table[instruction] == d68020_trapcc_32)
 22.3389 +				return 0;
 22.3390 +			if(g_instruction_table[instruction] == d68020_tst_pcdi_8)
 22.3391 +				return 0;
 22.3392 +			if(g_instruction_table[instruction] == d68020_tst_pcix_8)
 22.3393 +				return 0;
 22.3394 +			if(g_instruction_table[instruction] == d68020_tst_i_8)
 22.3395 +				return 0;
 22.3396 +			if(g_instruction_table[instruction] == d68020_tst_a_16)
 22.3397 +				return 0;
 22.3398 +			if(g_instruction_table[instruction] == d68020_tst_pcdi_16)
 22.3399 +				return 0;
 22.3400 +			if(g_instruction_table[instruction] == d68020_tst_pcix_16)
 22.3401 +				return 0;
 22.3402 +			if(g_instruction_table[instruction] == d68020_tst_i_16)
 22.3403 +				return 0;
 22.3404 +			if(g_instruction_table[instruction] == d68020_tst_a_32)
 22.3405 +				return 0;
 22.3406 +			if(g_instruction_table[instruction] == d68020_tst_pcdi_32)
 22.3407 +				return 0;
 22.3408 +			if(g_instruction_table[instruction] == d68020_tst_pcix_32)
 22.3409 +				return 0;
 22.3410 +			if(g_instruction_table[instruction] == d68020_tst_i_32)
 22.3411 +				return 0;
 22.3412 +			if(g_instruction_table[instruction] == d68020_unpk_rr)
 22.3413 +				return 0;
 22.3414 +			if(g_instruction_table[instruction] == d68020_unpk_mm)
 22.3415 +				return 0;
 22.3416 +		case M68K_CPU_TYPE_68EC020:
 22.3417 +		case M68K_CPU_TYPE_68020:
 22.3418 +		case M68K_CPU_TYPE_68030:
 22.3419 +			if(g_instruction_table[instruction] == d68040_cinv)
 22.3420 +				return 0;
 22.3421 +			if(g_instruction_table[instruction] == d68040_cpush)
 22.3422 +				return 0;
 22.3423 +			if(g_instruction_table[instruction] == d68040_move16_pi_pi)
 22.3424 +				return 0;
 22.3425 +			if(g_instruction_table[instruction] == d68040_move16_pi_al)
 22.3426 +				return 0;
 22.3427 +			if(g_instruction_table[instruction] == d68040_move16_al_pi)
 22.3428 +				return 0;
 22.3429 +			if(g_instruction_table[instruction] == d68040_move16_ai_al)
 22.3430 +				return 0;
 22.3431 +			if(g_instruction_table[instruction] == d68040_move16_al_ai)
 22.3432 +				return 0;
 22.3433 +	}
 22.3434 +	if(cpu_type != M68K_CPU_TYPE_68020 && cpu_type != M68K_CPU_TYPE_68EC020 &&
 22.3435 +	  (g_instruction_table[instruction] == d68020_callm ||
 22.3436 +	  g_instruction_table[instruction] == d68020_rtm))
 22.3437 +		return 0;
 22.3438 +
 22.3439 +	return 1;
 22.3440 +}
 22.3441 +
 22.3442 +
 22.3443 +
 22.3444 +/* ======================================================================== */
 22.3445 +/* ============================== END OF FILE ============================= */
 22.3446 +/* ======================================================================== */
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/musashi/m68kmake.c	Sat Nov 27 01:13:12 2010 +0000
    23.3 @@ -0,0 +1,1414 @@
    23.4 +/* ======================================================================== */
    23.5 +/* ========================= LICENSING & COPYRIGHT ======================== */
    23.6 +/* ======================================================================== */
    23.7 +/*
    23.8 + *                                  MUSASHI
    23.9 + *                                Version 3.3
   23.10 + *
   23.11 + * A portable Motorola M680x0 processor emulation engine.
   23.12 + * Copyright 1998-2001 Karl Stenerud.  All rights reserved.
   23.13 + *
   23.14 + * This code may be freely used for non-commercial purposes as long as this
   23.15 + * copyright notice remains unaltered in the source code and any binary files
   23.16 + * containing this code in compiled form.
   23.17 + *
   23.18 + * All other lisencing terms must be negotiated with the author
   23.19 + * (Karl Stenerud).
   23.20 + *
   23.21 + * The latest version of this code can be obtained at:
   23.22 + * http://kstenerud.cjb.net
   23.23 + */
   23.24 +
   23.25 +
   23.26 +
   23.27 +/* ======================================================================== */
   23.28 +/* ============================ CODE GENERATOR ============================ */
   23.29 +/* ======================================================================== */
   23.30 +/*
   23.31 + * This is the code generator program which will generate the opcode table
   23.32 + * and the final opcode handlers.
   23.33 + *
   23.34 + * It requires an input file to function (default m68k_in.c), but you can
   23.35 + * specify your own like so:
   23.36 + *
   23.37 + * m68kmake <output path> <input file>
   23.38 + *
   23.39 + * where output path is the path where the output files should be placed, and
   23.40 + * input file is the file to use for input.
   23.41 + *
   23.42 + * If you modify the input file greatly from its released form, you may have
   23.43 + * to tweak the configuration section a bit since I'm using static allocation
   23.44 + * to keep things simple.
   23.45 + *
   23.46 + *
   23.47 + * TODO: - build a better code generator for the move instruction.
   23.48 + *       - Add callm and rtm instructions
   23.49 + *       - Fix RTE to handle other format words
   23.50 + *       - Add address error (and bus error?) handling
   23.51 + */
   23.52 +
   23.53 +
   23.54 +char* g_version = "3.3";
   23.55 +
   23.56 +/* ======================================================================== */
   23.57 +/* =============================== INCLUDES =============================== */
   23.58 +/* ======================================================================== */
   23.59 +
   23.60 +#include <stdio.h>
   23.61 +#include <stdlib.h>
   23.62 +#include <string.h>
   23.63 +#include <ctype.h>
   23.64 +#include <stdarg.h>
   23.65 +
   23.66 +
   23.67 +
   23.68 +/* ======================================================================== */
   23.69 +/* ============================= CONFIGURATION ============================ */
   23.70 +/* ======================================================================== */
   23.71 +
   23.72 +#define MAX_PATH 1024
   23.73 +#define MAX_DIR  1024
   23.74 +
   23.75 +#define NUM_CPUS                          3	/* 000, 010, 020 */
   23.76 +#define MAX_LINE_LENGTH                 200	/* length of 1 line */
   23.77 +#define MAX_BODY_LENGTH                 300	/* Number of lines in 1 function */
   23.78 +#define MAX_REPLACE_LENGTH               30	/* Max number of replace strings */
   23.79 +#define MAX_INSERT_LENGTH              5000	/* Max size of insert piece */
   23.80 +#define MAX_NAME_LENGTH                  30	/* Max length of ophandler name */
   23.81 +#define MAX_SPEC_PROC_LENGTH              4	/* Max length of special processing str */
   23.82 +#define MAX_SPEC_EA_LENGTH                5	/* Max length of specified EA str */
   23.83 +#define EA_ALLOWED_LENGTH                11	/* Max length of ea allowed str */
   23.84 +#define MAX_OPCODE_INPUT_TABLE_LENGTH  1000	/* Max length of opcode handler tbl */
   23.85 +#define MAX_OPCODE_OUTPUT_TABLE_LENGTH 3000	/* Max length of opcode handler tbl */
   23.86 +
   23.87 +/* Default filenames */
   23.88 +#define FILENAME_INPUT      "m68k_in.c"
   23.89 +#define FILENAME_PROTOTYPE  "m68kops.h"
   23.90 +#define FILENAME_TABLE      "m68kops.c"
   23.91 +#define FILENAME_OPS_AC     "m68kopac.c"
   23.92 +#define FILENAME_OPS_DM     "m68kopdm.c"
   23.93 +#define FILENAME_OPS_NZ     "m68kopnz.c"
   23.94 +
   23.95 +
   23.96 +/* Identifier sequences recognized by this program */
   23.97 +
   23.98 +#define ID_INPUT_SEPARATOR "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
   23.99 +
  23.100 +#define ID_BASE                 "M68KMAKE"
  23.101 +#define ID_PROTOTYPE_HEADER     ID_BASE "_PROTOTYPE_HEADER"
  23.102 +#define ID_PROTOTYPE_FOOTER     ID_BASE "_PROTOTYPE_FOOTER"
  23.103 +#define ID_TABLE_HEADER         ID_BASE "_TABLE_HEADER"
  23.104 +#define ID_TABLE_FOOTER         ID_BASE "_TABLE_FOOTER"
  23.105 +#define ID_TABLE_BODY           ID_BASE "_TABLE_BODY"
  23.106 +#define ID_TABLE_START          ID_BASE "_TABLE_START"
  23.107 +#define ID_OPHANDLER_HEADER     ID_BASE "_OPCODE_HANDLER_HEADER"
  23.108 +#define ID_OPHANDLER_FOOTER     ID_BASE "_OPCODE_HANDLER_FOOTER"
  23.109 +#define ID_OPHANDLER_BODY       ID_BASE "_OPCODE_HANDLER_BODY"
  23.110 +#define ID_END                  ID_BASE "_END"
  23.111 +
  23.112 +#define ID_OPHANDLER_NAME       ID_BASE "_OP"
  23.113 +#define ID_OPHANDLER_EA_AY_8    ID_BASE "_GET_EA_AY_8"
  23.114 +#define ID_OPHANDLER_EA_AY_16   ID_BASE "_GET_EA_AY_16"
  23.115 +#define ID_OPHANDLER_EA_AY_32   ID_BASE "_GET_EA_AY_32"
  23.116 +#define ID_OPHANDLER_OPER_AY_8  ID_BASE "_GET_OPER_AY_8"
  23.117 +#define ID_OPHANDLER_OPER_AY_16 ID_BASE "_GET_OPER_AY_16"
  23.118 +#define ID_OPHANDLER_OPER_AY_32 ID_BASE "_GET_OPER_AY_32"
  23.119 +#define ID_OPHANDLER_CC         ID_BASE "_CC"
  23.120 +#define ID_OPHANDLER_NOT_CC     ID_BASE "_NOT_CC"
  23.121 +
  23.122 +
  23.123 +#ifndef DECL_SPEC
  23.124 +#define DECL_SPEC
  23.125 +#endif /* DECL_SPEC */
  23.126 +
  23.127 +
  23.128 +
  23.129 +/* ======================================================================== */
  23.130 +/* ============================== PROTOTYPES ============================== */
  23.131 +/* ======================================================================== */
  23.132 +
  23.133 +#define CPU_TYPE_000 0
  23.134 +#define CPU_TYPE_010 1
  23.135 +#define CPU_TYPE_020 2
  23.136 +
  23.137 +#define UNSPECIFIED "."
  23.138 +#define UNSPECIFIED_CH '.'
  23.139 +
  23.140 +#define HAS_NO_EA_MODE(A) (strcmp(A, "..........") == 0)
  23.141 +#define HAS_EA_AI(A)   ((A)[0] == 'A')
  23.142 +#define HAS_EA_PI(A)   ((A)[1] == '+')
  23.143 +#define HAS_EA_PD(A)   ((A)[2] == '-')
  23.144 +#define HAS_EA_DI(A)   ((A)[3] == 'D')
  23.145 +#define HAS_EA_IX(A)   ((A)[4] == 'X')
  23.146 +#define HAS_EA_AW(A)   ((A)[5] == 'W')
  23.147 +#define HAS_EA_AL(A)   ((A)[6] == 'L')
  23.148 +#define HAS_EA_PCDI(A) ((A)[7] == 'd')
  23.149 +#define HAS_EA_PCIX(A) ((A)[8] == 'x')
  23.150 +#define HAS_EA_I(A)    ((A)[9] == 'I')
  23.151 +
  23.152 +enum
  23.153 +{
  23.154 +	EA_MODE_NONE,	/* No special addressing mode */
  23.155 +	EA_MODE_AI,		/* Address register indirect */
  23.156 +	EA_MODE_PI,		/* Address register indirect with postincrement */
  23.157 +	EA_MODE_PI7,	/* Address register 7 indirect with postincrement */
  23.158 +	EA_MODE_PD,		/* Address register indirect with predecrement */
  23.159 +	EA_MODE_PD7,	/* Address register 7 indirect with predecrement */
  23.160 +	EA_MODE_DI,		/* Address register indirect with displacement */
  23.161 +	EA_MODE_IX,		/* Address register indirect with index */
  23.162 +	EA_MODE_AW,		/* Absolute word */
  23.163 +	EA_MODE_AL,		/* Absolute long */
  23.164 +	EA_MODE_PCDI,	/* Program counter indirect with displacement */
  23.165 +	EA_MODE_PCIX,	/* Program counter indirect with index */
  23.166 +	EA_MODE_I		/* Immediate */
  23.167 +};
  23.168 +
  23.169 +
  23.170 +/* Everything we need to know about an opcode */
  23.171 +typedef struct
  23.172 +{
  23.173 +	char name[MAX_NAME_LENGTH];           /* opcode handler name */
  23.174 +	unsigned int size;                    /* Size of operation */
  23.175 +	char spec_proc[MAX_SPEC_PROC_LENGTH]; /* Special processing mode */
  23.176 +	char spec_ea[MAX_SPEC_EA_LENGTH];     /* Specified effective addressing mode */
  23.177 +	unsigned int bits;                    /* Number of significant bits (used for sorting the table) */
  23.178 +	unsigned int op_mask;                 /* Mask to apply for matching an opcode to a handler */
  23.179 +	unsigned int op_match;                /* Value to match after masking */
  23.180 +	char ea_allowed[EA_ALLOWED_LENGTH];   /* Effective addressing modes allowed */
  23.181 +	char cpu_mode[NUM_CPUS];              /* User or supervisor mode */
  23.182 +	char cpus[NUM_CPUS+1];                /* Allowed CPUs */
  23.183 +	unsigned int cycles[NUM_CPUS];        /* cycles for 000, 010, 020 */
  23.184 +} opcode_struct;
  23.185 +
  23.186 +
  23.187 +/* All modifications necessary for a specific EA mode of an instruction */
  23.188 +typedef struct
  23.189 +{
  23.190 +	char* fname_add;
  23.191 +	char* ea_add;
  23.192 +	unsigned int mask_add;
  23.193 +	unsigned int match_add;
  23.194 +} ea_info_struct;
  23.195 +
  23.196 +
  23.197 +/* Holds the body of a function */
  23.198 +typedef struct
  23.199 +{
  23.200 +	char body[MAX_BODY_LENGTH][MAX_LINE_LENGTH+1];
  23.201 +	int length;
  23.202 +} body_struct;
  23.203 +
  23.204 +
  23.205 +/* Holds a sequence of search / replace strings */
  23.206 +typedef struct
  23.207 +{
  23.208 +	char replace[MAX_REPLACE_LENGTH][2][MAX_LINE_LENGTH+1];
  23.209 +	int length;
  23.210 +} replace_struct;
  23.211 +
  23.212 +
  23.213 +/* Function Prototypes */
  23.214 +void error_exit(char* fmt, ...);
  23.215 +void perror_exit(char* fmt, ...);
  23.216 +int check_strsncpy(char* dst, char* src, int maxlength);
  23.217 +int check_atoi(char* str, int *result);
  23.218 +int skip_spaces(char* str);
  23.219 +int num_bits(int value);
  23.220 +int atoh(char* buff);
  23.221 +int fgetline(char* buff, int nchars, FILE* file);
  23.222 +int get_oper_cycles(opcode_struct* op, int ea_mode, int cpu_type);
  23.223 +opcode_struct* find_opcode(char* name, int size, char* spec_proc, char* spec_ea);
  23.224 +opcode_struct* find_illegal_opcode(void);
  23.225 +int extract_opcode_info(char* src, char* name, int* size, char* spec_proc, char* spec_ea);
  23.226 +void add_replace_string(replace_struct* replace, char* search_str, char* replace_str);
  23.227 +void write_body(FILE* filep, body_struct* body, replace_struct* replace);
  23.228 +void get_base_name(char* base_name, opcode_struct* op);
  23.229 +void write_prototype(FILE* filep, char* base_name);
  23.230 +void write_function_name(FILE* filep, char* base_name);
  23.231 +void add_opcode_output_table_entry(opcode_struct* op, char* name);
  23.232 +static int DECL_SPEC compare_nof_true_bits(const void* aptr, const void* bptr);
  23.233 +void print_opcode_output_table(FILE* filep);
  23.234 +void write_table_entry(FILE* filep, opcode_struct* op);
  23.235 +void set_opcode_struct(opcode_struct* src, opcode_struct* dst, int ea_mode);
  23.236 +void generate_opcode_handler(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* opinfo, int ea_mode);
  23.237 +void generate_opcode_ea_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op);
  23.238 +void generate_opcode_cc_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op_in, int offset);
  23.239 +void process_opcode_handlers(void);
  23.240 +void populate_table(void);
  23.241 +void read_insert(char* insert);
  23.242 +
  23.243 +
  23.244 +
  23.245 +/* ======================================================================== */
  23.246 +/* ================================= DATA ================================= */
  23.247 +/* ======================================================================== */
  23.248 +
  23.249 +/* Name of the input file */
  23.250 +char g_input_filename[MAX_PATH] = FILENAME_INPUT;
  23.251 +
  23.252 +/* File handles */
  23.253 +FILE* g_input_file = NULL;
  23.254 +FILE* g_prototype_file = NULL;
  23.255 +FILE* g_table_file = NULL;
  23.256 +FILE* g_ops_ac_file = NULL;
  23.257 +FILE* g_ops_dm_file = NULL;
  23.258 +FILE* g_ops_nz_file = NULL;
  23.259 +
  23.260 +int g_num_functions = 0;  /* Number of functions processed */
  23.261 +int g_num_primitives = 0; /* Number of function primitives read */
  23.262 +int g_line_number = 1;    /* Current line number */
  23.263 +
  23.264 +/* Opcode handler table */
  23.265 +opcode_struct g_opcode_input_table[MAX_OPCODE_INPUT_TABLE_LENGTH];
  23.266 +
  23.267 +opcode_struct g_opcode_output_table[MAX_OPCODE_OUTPUT_TABLE_LENGTH];
  23.268 +int g_opcode_output_table_length = 0;
  23.269 +
  23.270 +ea_info_struct g_ea_info_table[13] =
  23.271 +{/* fname    ea        mask  match */
  23.272 +	{"",     "",       0x00, 0x00}, /* EA_MODE_NONE */
  23.273 +	{"ai",   "AY_AI",  0x38, 0x10}, /* EA_MODE_AI   */
  23.274 +	{"pi",   "AY_PI",  0x38, 0x18}, /* EA_MODE_PI   */
  23.275 +	{"pi7",  "A7_PI",  0x3f, 0x1f}, /* EA_MODE_PI7  */
  23.276 +	{"pd",   "AY_PD",  0x38, 0x20}, /* EA_MODE_PD   */
  23.277 +	{"pd7",  "A7_PD",  0x3f, 0x27}, /* EA_MODE_PD7  */
  23.278 +	{"di",   "AY_DI",  0x38, 0x28}, /* EA_MODE_DI   */
  23.279 +	{"ix",   "AY_IX",  0x38, 0x30}, /* EA_MODE_IX   */
  23.280 +	{"aw",   "AW",     0x3f, 0x38}, /* EA_MODE_AW   */
  23.281 +	{"al",   "AL",     0x3f, 0x39}, /* EA_MODE_AL   */
  23.282 +	{"pcdi", "PCDI",   0x3f, 0x3a}, /* EA_MODE_PCDI */
  23.283 +	{"pcix", "PCIX",   0x3f, 0x3b}, /* EA_MODE_PCIX */
  23.284 +	{"i",    "I",      0x3f, 0x3c}, /* EA_MODE_I    */
  23.285 +};
  23.286 +
  23.287 +
  23.288 +char* g_cc_table[16][2] =
  23.289 +{
  23.290 +	{ "t",  "T"}, /* 0000 */
  23.291 +	{ "f",  "F"}, /* 0001 */
  23.292 +	{"hi", "HI"}, /* 0010 */
  23.293 +	{"ls", "LS"}, /* 0011 */
  23.294 +	{"cc", "CC"}, /* 0100 */
  23.295 +	{"cs", "CS"}, /* 0101 */
  23.296 +	{"ne", "NE"}, /* 0110 */
  23.297 +	{"eq", "EQ"}, /* 0111 */
  23.298 +	{"vc", "VC"}, /* 1000 */
  23.299 +	{"vs", "VS"}, /* 1001 */
  23.300 +	{"pl", "PL"}, /* 1010 */
  23.301 +	{"mi", "MI"}, /* 1011 */
  23.302 +	{"ge", "GE"}, /* 1100 */
  23.303 +	{"lt", "LT"}, /* 1101 */
  23.304 +	{"gt", "GT"}, /* 1110 */
  23.305 +	{"le", "LE"}, /* 1111 */
  23.306 +};
  23.307 +
  23.308 +/* size to index translator (0 -> 0, 8 and 16 -> 1, 32 -> 2) */
  23.309 +int g_size_select_table[33] =
  23.310 +{
  23.311 +	0,												/* unsized */
  23.312 +	0, 0, 0, 0, 0, 0, 0, 1,							/*    8    */
  23.313 +	0, 0, 0, 0, 0, 0, 0, 1,							/*   16    */
  23.314 +	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2	/*   32    */
  23.315 +};
  23.316 +
  23.317 +/* Extra cycles required for certain EA modes */
  23.318 +int g_ea_cycle_table[13][NUM_CPUS][3] =
  23.319 +{/*       000           010           020   */
  23.320 +	{{ 0,  0,  0}, { 0,  0,  0}, { 0,  0,  0}}, /* EA_MODE_NONE */
  23.321 +	{{ 0,  4,  8}, { 0,  4,  8}, { 0,  4,  4}}, /* EA_MODE_AI   */
  23.322 +	{{ 0,  4,  8}, { 0,  4,  8}, { 0,  4,  4}}, /* EA_MODE_PI   */
  23.323 +	{{ 0,  4,  8}, { 0,  4,  8}, { 0,  4,  4}}, /* EA_MODE_PI7  */
  23.324 +	{{ 0,  6, 10}, { 0,  6, 10}, { 0,  5,  5}}, /* EA_MODE_PD   */
  23.325 +	{{ 0,  6, 10}, { 0,  6, 10}, { 0,  5,  5}}, /* EA_MODE_PD7  */
  23.326 +	{{ 0,  8, 12}, { 0,  8, 12}, { 0,  5,  5}}, /* EA_MODE_DI   */
  23.327 +	{{ 0, 10, 14}, { 0, 10, 14}, { 0,  7,  7}}, /* EA_MODE_IX   */
  23.328 +	{{ 0,  8, 12}, { 0,  8, 12}, { 0,  4,  4}}, /* EA_MODE_AW   */
  23.329 +	{{ 0, 12, 16}, { 0, 12, 16}, { 0,  4,  4}}, /* EA_MODE_AL   */
  23.330 +	{{ 0,  8, 12}, { 0,  8, 12}, { 0,  5,  5}}, /* EA_MODE_PCDI */
  23.331 +	{{ 0, 10, 14}, { 0, 10, 14}, { 0,  7,  7}}, /* EA_MODE_PCIX */
  23.332 +	{{ 0,  4,  8}, { 0,  4,  8}, { 0,  2,  4}}, /* EA_MODE_I    */
  23.333 +};
  23.334 +
  23.335 +/* Extra cycles for JMP instruction (000, 010) */
  23.336 +int g_jmp_cycle_table[13] =
  23.337 +{
  23.338 +	 0, /* EA_MODE_NONE */
  23.339 +	 4, /* EA_MODE_AI   */
  23.340 +	 0, /* EA_MODE_PI   */
  23.341 +	 0, /* EA_MODE_PI7  */
  23.342 +	 0, /* EA_MODE_PD   */
  23.343 +	 0, /* EA_MODE_PD7  */
  23.344 +	 6, /* EA_MODE_DI   */
  23.345 +	 8, /* EA_MODE_IX   */
  23.346 +	 6, /* EA_MODE_AW   */
  23.347 +	 8, /* EA_MODE_AL   */
  23.348 +	 6, /* EA_MODE_PCDI */
  23.349 +	10, /* EA_MODE_PCIX */
  23.350 +	 0, /* EA_MODE_I    */
  23.351 +};
  23.352 +
  23.353 +/* Extra cycles for JSR instruction (000, 010) */
  23.354 +int g_jsr_cycle_table[13] =
  23.355 +{
  23.356 +	 0, /* EA_MODE_NONE */
  23.357 +	 4, /* EA_MODE_AI   */
  23.358 +	 0, /* EA_MODE_PI   */
  23.359 +	 0, /* EA_MODE_PI7  */
  23.360 +	 0, /* EA_MODE_PD   */
  23.361 +	 0, /* EA_MODE_PD7  */
  23.362 +	 6, /* EA_MODE_DI   */
  23.363 +	10, /* EA_MODE_IX   */
  23.364 +	 6, /* EA_MODE_AW   */
  23.365 +	 8, /* EA_MODE_AL   */
  23.366 +	 6, /* EA_MODE_PCDI */
  23.367 +	10, /* EA_MODE_PCIX */
  23.368 +	 0, /* EA_MODE_I    */
  23.369 +};
  23.370 +
  23.371 +/* Extra cycles for LEA instruction (000, 010) */
  23.372 +int g_lea_cycle_table[13] =
  23.373 +{
  23.374 +	 0, /* EA_MODE_NONE */
  23.375 +	 4, /* EA_MODE_AI   */
  23.376 +	 0, /* EA_MODE_PI   */
  23.377 +	 0, /* EA_MODE_PI7  */
  23.378 +	 0, /* EA_MODE_PD   */
  23.379 +	 0, /* EA_MODE_PD7  */
  23.380 +	 8, /* EA_MODE_DI   */
  23.381 +	12, /* EA_MODE_IX   */
  23.382 +	 8, /* EA_MODE_AW   */
  23.383 +	12, /* EA_MODE_AL   */
  23.384 +	 8, /* EA_MODE_PCDI */
  23.385 +	12, /* EA_MODE_PCIX */
  23.386 +	 0, /* EA_MODE_I    */
  23.387 +};
  23.388 +
  23.389 +/* Extra cycles for PEA instruction (000, 010) */
  23.390 +int g_pea_cycle_table[13] =
  23.391 +{
  23.392 +	 0, /* EA_MODE_NONE */
  23.393 +	 4, /* EA_MODE_AI   */
  23.394 +	 0, /* EA_MODE_PI   */
  23.395 +	 0, /* EA_MODE_PI7  */
  23.396 +	 0, /* EA_MODE_PD   */
  23.397 +	 0, /* EA_MODE_PD7  */
  23.398 +	10, /* EA_MODE_DI   */
  23.399 +	14, /* EA_MODE_IX   */
  23.400 +	10, /* EA_MODE_AW   */
  23.401 +	14, /* EA_MODE_AL   */
  23.402 +	10, /* EA_MODE_PCDI */
  23.403 +	14, /* EA_MODE_PCIX */
  23.404 +	 0, /* EA_MODE_I    */
  23.405 +};
  23.406 +
  23.407 +/* Extra cycles for MOVES instruction (010) */
  23.408 +int g_moves_cycle_table[13][3] =
  23.409 +{
  23.410 +	{ 0,  0,  0}, /* EA_MODE_NONE */
  23.411 +	{ 0,  4,  6}, /* EA_MODE_AI   */
  23.412 +	{ 0,  4,  6}, /* EA_MODE_PI   */
  23.413 +	{ 0,  4,  6}, /* EA_MODE_PI7  */
  23.414 +	{ 0,  6, 12}, /* EA_MODE_PD   */
  23.415 +	{ 0,  6, 12}, /* EA_MODE_PD7  */
  23.416 +	{ 0, 12, 16}, /* EA_MODE_DI   */
  23.417 +	{ 0, 16, 20}, /* EA_MODE_IX   */
  23.418 +	{ 0, 12, 16}, /* EA_MODE_AW   */
  23.419 +	{ 0, 16, 20}, /* EA_MODE_AL   */
  23.420 +	{ 0,  0,  0}, /* EA_MODE_PCDI */
  23.421 +	{ 0,  0,  0}, /* EA_MODE_PCIX */
  23.422 +	{ 0,  0,  0}, /* EA_MODE_I    */
  23.423 +};
  23.424 +
  23.425 +/* Extra cycles for CLR instruction (010) */
  23.426 +int g_clr_cycle_table[13][3] =
  23.427 +{
  23.428 +	{ 0,  0,  0}, /* EA_MODE_NONE */
  23.429 +	{ 0,  4,  6}, /* EA_MODE_AI   */
  23.430 +	{ 0,  4,  6}, /* EA_MODE_PI   */
  23.431 +	{ 0,  4,  6}, /* EA_MODE_PI7  */
  23.432 +	{ 0,  6,  8}, /* EA_MODE_PD   */
  23.433 +	{ 0,  6,  8}, /* EA_MODE_PD7  */
  23.434 +	{ 0,  8, 10}, /* EA_MODE_DI   */
  23.435 +	{ 0, 10, 14}, /* EA_MODE_IX   */
  23.436 +	{ 0,  8, 10}, /* EA_MODE_AW   */
  23.437 +	{ 0, 10, 14}, /* EA_MODE_AL   */
  23.438 +	{ 0,  0,  0}, /* EA_MODE_PCDI */
  23.439 +	{ 0,  0,  0}, /* EA_MODE_PCIX */
  23.440 +	{ 0,  0,  0}, /* EA_MODE_I    */
  23.441 +};
  23.442 +
  23.443 +
  23.444 +
  23.445 +/* ======================================================================== */
  23.446 +/* =========================== UTILITY FUNCTIONS ========================== */
  23.447 +/* ======================================================================== */
  23.448 +
  23.449 +/* Print an error message and exit with status error */
  23.450 +void error_exit(char* fmt, ...)
  23.451 +{
  23.452 +	va_list args;
  23.453 +	fprintf(stderr, "In %s, near or on line %d:\n\t", g_input_filename, g_line_number);
  23.454 +	va_start(args, fmt);
  23.455 +	vfprintf(stderr, fmt, args);
  23.456 +	va_end(args);
  23.457 +	fprintf(stderr, "\n");
  23.458 +
  23.459 +	if(g_prototype_file) fclose(g_prototype_file);
  23.460 +	if(g_table_file) fclose(g_table_file);
  23.461 +	if(g_ops_ac_file) fclose(g_ops_ac_file);
  23.462 +	if(g_ops_dm_file) fclose(g_ops_dm_file);
  23.463 +	if(g_ops_nz_file) fclose(g_ops_nz_file);
  23.464 +	if(g_input_file) fclose(g_input_file);
  23.465 +
  23.466 +	exit(EXIT_FAILURE);
  23.467 +}
  23.468 +
  23.469 +/* Print an error message, call perror(), and exit with status error */
  23.470 +void perror_exit(char* fmt, ...)
  23.471 +{
  23.472 +	va_list args;
  23.473 +	va_start(args, fmt);
  23.474 +	vfprintf(stderr, fmt, args);
  23.475 +	va_end(args);
  23.476 +	perror("");
  23.477 +
  23.478 +	if(g_prototype_file) fclose(g_prototype_file);
  23.479 +	if(g_table_file) fclose(g_table_file);
  23.480 +	if(g_ops_ac_file) fclose(g_ops_ac_file);
  23.481 +	if(g_ops_dm_file) fclose(g_ops_dm_file);
  23.482 +	if(g_ops_nz_file) fclose(g_ops_nz_file);
  23.483 +	if(g_input_file) fclose(g_input_file);
  23.484 +
  23.485 +	exit(EXIT_FAILURE);
  23.486 +}
  23.487 +
  23.488 +
  23.489 +/* copy until 0 or space and exit with error if we read too far */
  23.490 +int check_strsncpy(char* dst, char* src, int maxlength)
  23.491 +{
  23.492 +	char* p = dst;
  23.493 +	while(*src && *src != ' ')
  23.494 +	{
  23.495 +		*p++ = *src++;
  23.496 +		if(p - dst > maxlength)
  23.497 +			error_exit("Field too long");
  23.498 +	}
  23.499 +	*p = 0;
  23.500 +	return p - dst;
  23.501 +}
  23.502 +
  23.503 +/* copy until 0 or specified character and exit with error if we read too far */
  23.504 +int check_strcncpy(char* dst, char* src, char delim, int maxlength)
  23.505 +{
  23.506 +	char* p = dst;
  23.507 +	while(*src && *src != delim)
  23.508 +	{
  23.509 +		*p++ = *src++;
  23.510 +		if(p - dst > maxlength)
  23.511 +			error_exit("Field too long");
  23.512 +	}
  23.513 +	*p = 0;
  23.514 +	return p - dst;
  23.515 +}
  23.516 +
  23.517 +/* convert ascii to integer and exit with error if we find invalid data */
  23.518 +int check_atoi(char* str, int *result)
  23.519 +{
  23.520 +	int accum = 0;
  23.521 +	char* p = str;
  23.522 +	while(*p >= '0' && *p <= '9')
  23.523 +	{
  23.524 +		accum *= 10;
  23.525 +		accum += *p++ - '0';
  23.526 +	}
  23.527 +	if(*p != ' ' && *p != 0)
  23.528 +		error_exit("Malformed integer value (%c)", *p);
  23.529 +	*result = accum;
  23.530 +	return p - str;
  23.531 +}
  23.532 +
  23.533 +/* Skip past spaces in a string */
  23.534 +int skip_spaces(char* str)
  23.535 +{
  23.536 +	char* p = str;
  23.537 +
  23.538 +	while(*p == ' ')
  23.539 +		p++;
  23.540 +
  23.541 +	return p - str;
  23.542 +}
  23.543 +
  23.544 +/* Count the number of set bits in a value */
  23.545 +int num_bits(int value)
  23.546 +{
  23.547 +    value = ((value & 0xaaaa) >> 1) + (value & 0x5555);
  23.548 +    value = ((value & 0xcccc) >> 2) + (value & 0x3333);
  23.549 +    value = ((value & 0xf0f0) >> 4) + (value & 0x0f0f);
  23.550 +    value = ((value & 0xff00) >> 8) + (value & 0x00ff);
  23.551 +	return value;
  23.552 +}
  23.553 +
  23.554 +/* Convert a hex value written in ASCII */
  23.555 +int atoh(char* buff)
  23.556 +{
  23.557 +	int accum = 0;
  23.558 +
  23.559 +	for(;;buff++)
  23.560 +	{
  23.561 +		if(*buff >= '0' && *buff <= '9')
  23.562 +		{
  23.563 +			accum <<= 4;
  23.564 +			accum += *buff - '0';
  23.565 +		}
  23.566 +		else if(*buff >= 'a' && *buff <= 'f')
  23.567 +		{
  23.568 +			accum <<= 4;
  23.569 +			accum += *buff - 'a' + 10;
  23.570 +		}
  23.571 +		else break;
  23.572 +	}
  23.573 +	return accum;
  23.574 +}
  23.575 +
  23.576 +/* Get a line of text from a file, discarding any end-of-line characters */
  23.577 +int fgetline(char* buff, int nchars, FILE* file)
  23.578 +{
  23.579 +	int length;
  23.580 +
  23.581 +	if(fgets(buff, nchars, file) == NULL)
  23.582 +		return -1;
  23.583 +	if(buff[0] == '\r')
  23.584 +		memcpy(buff, buff + 1, nchars - 1);
  23.585 +
  23.586 +	length = strlen(buff);
  23.587 +	while(length && (buff[length-1] == '\r' || buff[length-1] == '\n'))
  23.588 +		length--;
  23.589 +	buff[length] = 0;
  23.590 +	g_line_number++;
  23.591 +
  23.592 +	return length;
  23.593 +}
  23.594 +
  23.595 +
  23.596 +
  23.597 +/* ======================================================================== */
  23.598 +/* =========================== HELPER FUNCTIONS =========================== */
  23.599 +/* ======================================================================== */
  23.600 +
  23.601 +/* Calculate the number of cycles an opcode requires */
  23.602 +int get_oper_cycles(opcode_struct* op, int ea_mode, int cpu_type)
  23.603 +{
  23.604 +	int size = g_size_select_table[op->size];
  23.605 +
  23.606 +	if(op->cpus[cpu_type] == '.')
  23.607 +		return 0;
  23.608 +
  23.609 +	if(cpu_type < CPU_TYPE_020)
  23.610 +	{
  23.611 +		if(cpu_type == CPU_TYPE_010)
  23.612 +		{
  23.613 +			if(strcmp(op->name, "moves") == 0)
  23.614 +				return op->cycles[cpu_type] + g_moves_cycle_table[ea_mode][size];
  23.615 +			if(strcmp(op->name, "clr") == 0)
  23.616 +				return op->cycles[cpu_type] + g_clr_cycle_table[ea_mode][size];
  23.617 +		}
  23.618 +
  23.619 +		/* ASG: added these cases -- immediate modes take 2 extra cycles here */
  23.620 +		if(cpu_type == CPU_TYPE_000 && ea_mode == EA_MODE_I &&
  23.621 +		   ((strcmp(op->name, "add") == 0 && strcmp(op->spec_proc, "er") == 0) ||
  23.622 +			strcmp(op->name, "adda")   == 0                                    ||
  23.623 +			(strcmp(op->name, "and") == 0 && strcmp(op->spec_proc, "er") == 0) ||
  23.624 +			(strcmp(op->name, "or") == 0 && strcmp(op->spec_proc, "er") == 0)  ||
  23.625 +			(strcmp(op->name, "sub") == 0 && strcmp(op->spec_proc, "er") == 0) ||
  23.626 +			strcmp(op->name, "suba")   == 0))
  23.627 +			return op->cycles[cpu_type] + g_ea_cycle_table[ea_mode][cpu_type][size] + 2;
  23.628 +
  23.629 +		if(strcmp(op->name, "jmp") == 0)
  23.630 +			return op->cycles[cpu_type] + g_jmp_cycle_table[ea_mode];
  23.631 +		if(strcmp(op->name, "jsr") == 0)
  23.632 +			return op->cycles[cpu_type] + g_jsr_cycle_table[ea_mode];
  23.633 +		if(strcmp(op->name, "lea") == 0)
  23.634 +			return op->cycles[cpu_type] + g_lea_cycle_table[ea_mode];
  23.635 +		if(strcmp(op->name, "pea") == 0)
  23.636 +			return op->cycles[cpu_type] + g_pea_cycle_table[ea_mode];
  23.637 +	}
  23.638 +	return op->cycles[cpu_type] + g_ea_cycle_table[ea_mode][cpu_type][size];
  23.639 +}
  23.640 +
  23.641 +/* Find an opcode in the opcode handler list */
  23.642 +opcode_struct* find_opcode(char* name, int size, char* spec_proc, char* spec_ea)
  23.643 +{
  23.644 +	opcode_struct* op;
  23.645 +
  23.646 +
  23.647 +	for(op = g_opcode_input_table;op->name != NULL;op++)
  23.648 +	{
  23.649 +		if(	strcmp(name, op->name) == 0 &&
  23.650 +			(size == (int)op->size) &&
  23.651 +			strcmp(spec_proc, op->spec_proc) == 0 &&
  23.652 +			strcmp(spec_ea, op->spec_ea) == 0)
  23.653 +				return op;
  23.654 +	}
  23.655 +	return NULL;
  23.656 +}
  23.657 +
  23.658 +/* Specifically find the illegal opcode in the list */
  23.659 +opcode_struct* find_illegal_opcode(void)
  23.660 +{
  23.661 +	opcode_struct* op;
  23.662 +
  23.663 +	for(op = g_opcode_input_table;op->name != NULL;op++)
  23.664 +	{
  23.665 +		if(strcmp(op->name, "illegal") == 0)
  23.666 +			return op;
  23.667 +	}
  23.668 +	return NULL;
  23.669 +}
  23.670 +
  23.671 +/* Parse an opcode handler name */
  23.672 +int extract_opcode_info(char* src, char* name, int* size, char* spec_proc, char* spec_ea)
  23.673 +{
  23.674 +	char* ptr = strstr(src, ID_OPHANDLER_NAME);
  23.675 +
  23.676 +	if(ptr == NULL)
  23.677 +		return 0;
  23.678 +
  23.679 +	ptr += strlen(ID_OPHANDLER_NAME) + 1;
  23.680 +
  23.681 +	ptr += check_strcncpy(name, ptr, ',', MAX_NAME_LENGTH);
  23.682 +	if(*ptr != ',') return 0;
  23.683 +	ptr++;
  23.684 +	ptr += skip_spaces(ptr);
  23.685 +
  23.686 +	*size = atoi(ptr);
  23.687 +	ptr = strstr(ptr, ",");
  23.688 +	if(ptr == NULL) return 0;
  23.689 +    ptr++;
  23.690 +	ptr += skip_spaces(ptr);
  23.691 +
  23.692 +	ptr += check_strcncpy(spec_proc, ptr, ',', MAX_SPEC_PROC_LENGTH);
  23.693 +	if(*ptr != ',') return 0;
  23.694 +	ptr++;
  23.695 +	ptr += skip_spaces(ptr);
  23.696 +
  23.697 +	ptr += check_strcncpy(spec_ea, ptr, ')', MAX_SPEC_EA_LENGTH);
  23.698 +	if(*ptr != ')') return 0;
  23.699 +
  23.700 +	return 1;
  23.701 +}
  23.702 +
  23.703 +
  23.704 +/* Add a search/replace pair to a replace structure */
  23.705 +void add_replace_string(replace_struct* replace, char* search_str, char* replace_str)
  23.706 +{
  23.707 +	if(replace->length >= MAX_REPLACE_LENGTH)
  23.708 +		error_exit("overflow in replace structure");
  23.709 +
  23.710 +	strcpy(replace->replace[replace->length][0], search_str);
  23.711 +	strcpy(replace->replace[replace->length++][1], replace_str);
  23.712 +}
  23.713 +
  23.714 +/* Write a function body while replacing any selected strings */
  23.715 +void write_body(FILE* filep, body_struct* body, replace_struct* replace)
  23.716 +{
  23.717 +	int i;
  23.718 +	int j;
  23.719 +	char* ptr;
  23.720 +	char output[MAX_LINE_LENGTH+1];
  23.721 +	char temp_buff[MAX_LINE_LENGTH+1];
  23.722 +	int found;
  23.723 +
  23.724 +	for(i=0;i<body->length;i++)
  23.725 +	{
  23.726 +		strcpy(output, body->body[i]);
  23.727 +		/* Check for the base directive header */
  23.728 +		if(strstr(output, ID_BASE) != NULL)
  23.729 +		{
  23.730 +			/* Search for any text we need to replace */
  23.731 +			found = 0;
  23.732 +			for(j=0;j<replace->length;j++)
  23.733 +			{
  23.734 +				ptr = strstr(output, replace->replace[j][0]);
  23.735 +				if(ptr)
  23.736 +				{
  23.737 +					/* We found something to replace */
  23.738 +					found = 1;
  23.739 +					strcpy(temp_buff, ptr+strlen(replace->replace[j][0]));
  23.740 +					strcpy(ptr, replace->replace[j][1]);
  23.741 +					strcat(ptr, temp_buff);
  23.742 +				}
  23.743 +			}
  23.744 +			/* Found a directive with no matching replace string */
  23.745 +			if(!found)
  23.746 +				error_exit("Unknown " ID_BASE " directive");
  23.747 +		}
  23.748 +		fprintf(filep, "%s\n", output);
  23.749 +	}
  23.750 +	fprintf(filep, "\n\n");
  23.751 +}
  23.752 +
  23.753 +/* Generate a base function name from an opcode struct */
  23.754 +void get_base_name(char* base_name, opcode_struct* op)
  23.755 +{
  23.756 +	sprintf(base_name, "m68k_op_%s", op->name);
  23.757 +	if(op->size > 0)
  23.758 +		sprintf(base_name+strlen(base_name), "_%d", op->size);
  23.759 +	if(strcmp(op->spec_proc, UNSPECIFIED) != 0)
  23.760 +		sprintf(base_name+strlen(base_name), "_%s", op->spec_proc);
  23.761 +	if(strcmp(op->spec_ea, UNSPECIFIED) != 0)
  23.762 +		sprintf(base_name+strlen(base_name), "_%s", op->spec_ea);
  23.763 +}
  23.764 +
  23.765 +/* Write the prototype of an opcode handler function */
  23.766 +void write_prototype(FILE* filep, char* base_name)
  23.767 +{
  23.768 +	fprintf(filep, "void %s(void);\n", base_name);
  23.769 +}
  23.770 +
  23.771 +/* Write the name of an opcode handler function */
  23.772 +void write_function_name(FILE* filep, char* base_name)
  23.773 +{
  23.774 +	fprintf(filep, "void %s(void)\n", base_name);
  23.775 +}
  23.776 +
  23.777 +void add_opcode_output_table_entry(opcode_struct* op, char* name)
  23.778 +{
  23.779 +	opcode_struct* ptr;
  23.780 +	if(g_opcode_output_table_length > MAX_OPCODE_OUTPUT_TABLE_LENGTH)
  23.781 +		error_exit("Opcode output table overflow");
  23.782 +
  23.783 +	ptr = g_opcode_output_table + g_opcode_output_table_length++;
  23.784 +
  23.785 +	*ptr = *op;
  23.786 +	strcpy(ptr->name, name);
  23.787 +	ptr->bits = num_bits(ptr->op_mask);
  23.788 +}
  23.789 +
  23.790 +/*
  23.791 + * Comparison function for qsort()
  23.792 + * For entries with an equal number of set bits in
  23.793 + * the mask compare the match values
  23.794 + */
  23.795 +static int DECL_SPEC compare_nof_true_bits(const void* aptr, const void* bptr)
  23.796 +{
  23.797 +	const opcode_struct *a = aptr, *b = bptr;
  23.798 +	if(a->bits != b->bits)
  23.799 +		return a->bits - b->bits;
  23.800 +	if(a->op_mask != b->op_mask)
  23.801 +		return a->op_mask - b->op_mask;
  23.802 +	return a->op_match - b->op_match;
  23.803 +}
  23.804 +
  23.805 +void print_opcode_output_table(FILE* filep)
  23.806 +{
  23.807 +	int i;
  23.808 +	qsort((void *)g_opcode_output_table, g_opcode_output_table_length, sizeof(g_opcode_output_table[0]), compare_nof_true_bits);
  23.809 +
  23.810 +	for(i=0;i<g_opcode_output_table_length;i++)
  23.811 +		write_table_entry(filep, g_opcode_output_table+i);
  23.812 +}
  23.813 +
  23.814 +/* Write an entry in the opcode handler table */
  23.815 +void write_table_entry(FILE* filep, opcode_struct* op)
  23.816 +{
  23.817 +	int i;
  23.818 +
  23.819 +	fprintf(filep, "\t{%-28s, 0x%04x, 0x%04x, {",
  23.820 +		op->name, op->op_mask, op->op_match);
  23.821 +
  23.822 +	for(i=0;i<NUM_CPUS;i++)
  23.823 +	{
  23.824 +		fprintf(filep, "%3d", op->cycles[i]);
  23.825 +		if(i < NUM_CPUS-1)
  23.826 +			fprintf(filep, ", ");
  23.827 +	}
  23.828 +
  23.829 +	fprintf(filep, "}},\n");
  23.830 +}
  23.831 +
  23.832 +/* Fill out an opcode struct with a specific addressing mode of the source opcode struct */
  23.833 +void set_opcode_struct(opcode_struct* src, opcode_struct* dst, int ea_mode)
  23.834 +{
  23.835 +	int i;
  23.836 +
  23.837 +	*dst = *src;
  23.838 +
  23.839 +	for(i=0;i<NUM_CPUS;i++)
  23.840 +		dst->cycles[i] = get_oper_cycles(dst, ea_mode, i);
  23.841 +	if(strcmp(dst->spec_ea, UNSPECIFIED) == 0 && ea_mode != EA_MODE_NONE)
  23.842 +		sprintf(dst->spec_ea, "%s", g_ea_info_table[ea_mode].fname_add);
  23.843 +	dst->op_mask |= g_ea_info_table[ea_mode].mask_add;
  23.844 +	dst->op_match |= g_ea_info_table[ea_mode].match_add;
  23.845 +}
  23.846 +
  23.847 +
  23.848 +/* Generate a final opcode handler from the provided data */
  23.849 +void generate_opcode_handler(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* opinfo, int ea_mode)
  23.850 +{
  23.851 +	char str[MAX_LINE_LENGTH+1];
  23.852 +	opcode_struct* op = malloc(sizeof(opcode_struct));
  23.853 +
  23.854 +	/* Set the opcode structure and write the tables, prototypes, etc */
  23.855 +	set_opcode_struct(opinfo, op, ea_mode);
  23.856 +	get_base_name(str, op);
  23.857 +	write_prototype(g_prototype_file, str);
  23.858 +	add_opcode_output_table_entry(op, str);
  23.859 +	write_function_name(filep, str);
  23.860 +
  23.861 +	/* Add any replace strings needed */
  23.862 +	if(ea_mode != EA_MODE_NONE)
  23.863 +	{
  23.864 +		sprintf(str, "EA_%s_8()", g_ea_info_table[ea_mode].ea_add);
  23.865 +		add_replace_string(replace, ID_OPHANDLER_EA_AY_8, str);
  23.866 +		sprintf(str, "EA_%s_16()", g_ea_info_table[ea_mode].ea_add);
  23.867 +		add_replace_string(replace, ID_OPHANDLER_EA_AY_16, str);
  23.868 +		sprintf(str, "EA_%s_32()", g_ea_info_table[ea_mode].ea_add);
  23.869 +		add_replace_string(replace, ID_OPHANDLER_EA_AY_32, str);
  23.870 +		sprintf(str, "OPER_%s_8()", g_ea_info_table[ea_mode].ea_add);
  23.871 +		add_replace_string(replace, ID_OPHANDLER_OPER_AY_8, str);
  23.872 +		sprintf(str, "OPER_%s_16()", g_ea_info_table[ea_mode].ea_add);
  23.873 +		add_replace_string(replace, ID_OPHANDLER_OPER_AY_16, str);
  23.874 +		sprintf(str, "OPER_%s_32()", g_ea_info_table[ea_mode].ea_add);
  23.875 +		add_replace_string(replace, ID_OPHANDLER_OPER_AY_32, str);
  23.876 +	}
  23.877 +
  23.878 +	/* Now write the function body with the selected replace strings */
  23.879 +	write_body(filep, body, replace);
  23.880 +	g_num_functions++;
  23.881 +	free(op);
  23.882 +}
  23.883 +
  23.884 +/* Generate opcode variants based on available addressing modes */
  23.885 +void generate_opcode_ea_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op)
  23.886 +{
  23.887 +	int old_length = replace->length;
  23.888 +
  23.889 +	/* No ea modes available for this opcode */
  23.890 +	if(HAS_NO_EA_MODE(op->ea_allowed))
  23.891 +	{
  23.892 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_NONE);
  23.893 +		return;
  23.894 +	}
  23.895 +
  23.896 +	/* Check for and create specific opcodes for each available addressing mode */
  23.897 +	if(HAS_EA_AI(op->ea_allowed))
  23.898 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_AI);
  23.899 +	replace->length = old_length;
  23.900 +	if(HAS_EA_PI(op->ea_allowed))
  23.901 +	{
  23.902 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_PI);
  23.903 +		replace->length = old_length;
  23.904 +		if(op->size == 8)
  23.905 +			generate_opcode_handler(filep, body, replace, op, EA_MODE_PI7);
  23.906 +	}
  23.907 +	replace->length = old_length;
  23.908 +	if(HAS_EA_PD(op->ea_allowed))
  23.909 +	{
  23.910 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_PD);
  23.911 +		replace->length = old_length;
  23.912 +		if(op->size == 8)
  23.913 +			generate_opcode_handler(filep, body, replace, op, EA_MODE_PD7);
  23.914 +	}
  23.915 +	replace->length = old_length;
  23.916 +	if(HAS_EA_DI(op->ea_allowed))
  23.917 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_DI);
  23.918 +	replace->length = old_length;
  23.919 +	if(HAS_EA_IX(op->ea_allowed))
  23.920 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_IX);
  23.921 +	replace->length = old_length;
  23.922 +	if(HAS_EA_AW(op->ea_allowed))
  23.923 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_AW);
  23.924 +	replace->length = old_length;
  23.925 +	if(HAS_EA_AL(op->ea_allowed))
  23.926 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_AL);
  23.927 +	replace->length = old_length;
  23.928 +	if(HAS_EA_PCDI(op->ea_allowed))
  23.929 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_PCDI);
  23.930 +	replace->length = old_length;
  23.931 +	if(HAS_EA_PCIX(op->ea_allowed))
  23.932 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_PCIX);
  23.933 +	replace->length = old_length;
  23.934 +	if(HAS_EA_I(op->ea_allowed))
  23.935 +		generate_opcode_handler(filep, body, replace, op, EA_MODE_I);
  23.936 +	replace->length = old_length;
  23.937 +}
  23.938 +
  23.939 +/* Generate variants of condition code opcodes */
  23.940 +void generate_opcode_cc_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op_in, int offset)
  23.941 +{
  23.942 +	char repl[20];
  23.943 +	char replnot[20];
  23.944 +	int i;
  23.945 +	int old_length = replace->length;
  23.946 +	opcode_struct* op = malloc(sizeof(opcode_struct));
  23.947 +
  23.948 +	*op = *op_in;
  23.949 +
  23.950 +	op->op_mask |= 0x0f00;
  23.951 +
  23.952 +	/* Do all condition codes except t and f */
  23.953 +	for(i=2;i<16;i++)
  23.954 +	{
  23.955 +		/* Add replace strings for this condition code */
  23.956 +		sprintf(repl, "COND_%s()", g_cc_table[i][1]);
  23.957 +		sprintf(replnot, "COND_NOT_%s()", g_cc_table[i][1]);
  23.958 +
  23.959 +		add_replace_string(replace, ID_OPHANDLER_CC, repl);
  23.960 +		add_replace_string(replace, ID_OPHANDLER_NOT_CC, replnot);
  23.961 +
  23.962 +		/* Set the new opcode info */
  23.963 +		strcpy(op->name+offset, g_cc_table[i][0]);
  23.964 +
  23.965 +		op->op_match = (op->op_match & 0xf0ff) | (i<<8);
  23.966 +
  23.967 +		/* Generate all opcode variants for this modified opcode */
  23.968 +		generate_opcode_ea_variants(filep, body, replace, op);
  23.969 +		/* Remove the above replace strings */
  23.970 +		replace->length = old_length;
  23.971 +	}
  23.972 +	free(op);
  23.973 +}
  23.974 +
  23.975 +/* Process the opcode handlers section of the input file */
  23.976 +void process_opcode_handlers(void)
  23.977 +{
  23.978 +	FILE* input_file = g_input_file;
  23.979 +	FILE* output_file;
  23.980 +	char func_name[MAX_LINE_LENGTH+1];
  23.981 +	char oper_name[MAX_LINE_LENGTH+1];
  23.982 +	int  oper_size;
  23.983 +	char oper_spec_proc[MAX_LINE_LENGTH+1];
  23.984 +	char oper_spec_ea[MAX_LINE_LENGTH+1];
  23.985 +	opcode_struct* opinfo;
  23.986 +	replace_struct* replace = malloc(sizeof(replace_struct));
  23.987 +	body_struct* body = malloc(sizeof(body_struct));
  23.988 +
  23.989 +
  23.990 +	output_file = g_ops_ac_file;
  23.991 +
  23.992 +	for(;;)
  23.993 +	{
  23.994 +		/* Find the first line of the function */
  23.995 +		func_name[0] = 0;
  23.996 +		while(strstr(func_name, ID_OPHANDLER_NAME) == NULL)
  23.997 +		{
  23.998 +			if(strcmp(func_name, ID_INPUT_SEPARATOR) == 0)
  23.999 +			{
 23.1000 +				free(replace);
 23.1001 +				free(body);
 23.1002 +				return; /* all done */
 23.1003 +			}
 23.1004 +			if(fgetline(func_name, MAX_LINE_LENGTH, input_file) < 0)
 23.1005 +				error_exit("Premature end of file when getting function name");
 23.1006 +		}
 23.1007 +		/* Get the rest of the function */
 23.1008 +		for(body->length=0;;body->length++)
 23.1009 +		{
 23.1010 +			if(body->length > MAX_BODY_LENGTH)
 23.1011 +				error_exit("Function too long");
 23.1012 +
 23.1013 +			if(fgetline(body->body[body->length], MAX_LINE_LENGTH, input_file) < 0)
 23.1014 +				error_exit("Premature end of file when getting function body");
 23.1015 +
 23.1016 +			if(body->body[body->length][0] == '}')
 23.1017 +			{
 23.1018 +				body->length++;
 23.1019 +				break;
 23.1020 +			}
 23.1021 +		}
 23.1022 +
 23.1023 +		g_num_primitives++;
 23.1024 +
 23.1025 +		/* Extract the function name information */
 23.1026 +		if(!extract_opcode_info(func_name, oper_name, &oper_size, oper_spec_proc, oper_spec_ea))
 23.1027 +			error_exit("Invalid " ID_OPHANDLER_NAME " format");
 23.1028 +
 23.1029 +		/* Find the corresponding table entry */
 23.1030 +		opinfo = find_opcode(oper_name, oper_size, oper_spec_proc, oper_spec_ea);
 23.1031 +		if(opinfo == NULL)
 23.1032 +			error_exit("Unable to find matching table entry for %s", func_name);
 23.1033 +
 23.1034 +        /* Change output files if we pass 'c' or 'n' */
 23.1035 +		if(output_file == g_ops_ac_file && oper_name[0] > 'c')
 23.1036 +			output_file = g_ops_dm_file;
 23.1037 +		else if(output_file == g_ops_dm_file && oper_name[0] > 'm')
 23.1038 +			output_file = g_ops_nz_file;
 23.1039 +
 23.1040 +		replace->length = 0;
 23.1041 +
 23.1042 +		/* Generate opcode variants */
 23.1043 +		if(strcmp(opinfo->name, "bcc") == 0 || strcmp(opinfo->name, "scc") == 0)
 23.1044 +			generate_opcode_cc_variants(output_file, body, replace, opinfo, 1);
 23.1045 +		else if(strcmp(opinfo->name, "dbcc") == 0)
 23.1046 +			generate_opcode_cc_variants(output_file, body, replace, opinfo, 2);
 23.1047 +		else if(strcmp(opinfo->name, "trapcc") == 0)
 23.1048 +			generate_opcode_cc_variants(output_file, body, replace, opinfo, 4);
 23.1049 +		else
 23.1050 +			generate_opcode_ea_variants(output_file, body, replace, opinfo);
 23.1051 +	}
 23.1052 +}
 23.1053 +
 23.1054 +
 23.1055 +/* Populate the opcode handler table from the input file */
 23.1056 +void populate_table(void)
 23.1057 +{
 23.1058 +	char* ptr;
 23.1059 +	char bitpattern[17];
 23.1060 +	opcode_struct* op;
 23.1061 +	char buff[MAX_LINE_LENGTH];
 23.1062 +	int i;
 23.1063 +	int temp;
 23.1064 +
 23.1065 +	buff[0] = 0;
 23.1066 +
 23.1067 +	/* Find the start of the table */
 23.1068 +	while(strcmp(buff, ID_TABLE_START) != 0)
 23.1069 +		if(fgetline(buff, MAX_LINE_LENGTH, g_input_file) < 0)
 23.1070 +			error_exit("Premature EOF while reading table");
 23.1071 +
 23.1072 +	/* Process the entire table */
 23.1073 +	for(op = g_opcode_input_table;;op++)
 23.1074 +	{
 23.1075 +		if(fgetline(buff, MAX_LINE_LENGTH, g_input_file) < 0)
 23.1076 +			error_exit("Premature EOF while reading table");
 23.1077 +		if(strlen(buff) == 0)
 23.1078 +			continue;
 23.1079 +		/* We finish when we find an input separator */
 23.1080 +		if(strcmp(buff, ID_INPUT_SEPARATOR) == 0)
 23.1081 +			break;
 23.1082 +
 23.1083 +		/* Extract the info from the table */
 23.1084 +		ptr = buff;
 23.1085 +
 23.1086 +		/* Name */
 23.1087 +		ptr += skip_spaces(ptr);
 23.1088 +		ptr += check_strsncpy(op->name, ptr, MAX_NAME_LENGTH);
 23.1089 +
 23.1090 +		/* Size */
 23.1091 +		ptr += skip_spaces(ptr);
 23.1092 +		ptr += check_atoi(ptr, &temp);
 23.1093 +		op->size = (unsigned char)temp;
 23.1094 +
 23.1095 +		/* Special processing */
 23.1096 +		ptr += skip_spaces(ptr);
 23.1097 +		ptr += check_strsncpy(op->spec_proc, ptr, MAX_SPEC_PROC_LENGTH);
 23.1098 +
 23.1099 +		/* Specified EA Mode */
 23.1100 +		ptr += skip_spaces(ptr);
 23.1101 +		ptr += check_strsncpy(op->spec_ea, ptr, MAX_SPEC_EA_LENGTH);
 23.1102 +
 23.1103 +		/* Bit Pattern (more processing later) */
 23.1104 +		ptr += skip_spaces(ptr);
 23.1105 +		ptr += check_strsncpy(bitpattern, ptr, 17);
 23.1106 +
 23.1107 +		/* Allowed Addressing Mode List */
 23.1108 +		ptr += skip_spaces(ptr);
 23.1109 +		ptr += check_strsncpy(op->ea_allowed, ptr, EA_ALLOWED_LENGTH);
 23.1110 +
 23.1111 +		/* CPU operating mode (U = user or supervisor, S = supervisor only */
 23.1112 +		ptr += skip_spaces(ptr);
 23.1113 +		for(i=0;i<NUM_CPUS;i++)
 23.1114 +		{
 23.1115 +			op->cpu_mode[i] = *ptr++;
 23.1116 +			ptr += skip_spaces(ptr);
 23.1117 +		}
 23.1118 +
 23.1119 +		/* Allowed CPUs for this instruction */
 23.1120 +		for(i=0;i<NUM_CPUS;i++)
 23.1121 +		{
 23.1122 +			ptr += skip_spaces(ptr);
 23.1123 +			if(*ptr == UNSPECIFIED_CH)
 23.1124 +			{
 23.1125 +				op->cpus[i] = UNSPECIFIED_CH;
 23.1126 +				op->cycles[i] = 0;
 23.1127 +				ptr++;
 23.1128 +			}
 23.1129 +			else
 23.1130 +			{
 23.1131 +				op->cpus[i] = (char)('0' + i);
 23.1132 +				ptr += check_atoi(ptr, &temp);
 23.1133 +				op->cycles[i] = (unsigned char)temp;
 23.1134 +			}
 23.1135 +		}
 23.1136 +
 23.1137 +		/* generate mask and match from bitpattern */
 23.1138 +		op->op_mask = 0;
 23.1139 +		op->op_match = 0;
 23.1140 +		for(i=0;i<16;i++)
 23.1141 +		{
 23.1142 +			op->op_mask |= (bitpattern[i] != '.') << (15-i);
 23.1143 +			op->op_match |= (bitpattern[i] == '1') << (15-i);
 23.1144 +		}
 23.1145 +	}
 23.1146 +	/* Terminate the list */
 23.1147 +	op->name[0] = 0;
 23.1148 +}
 23.1149 +
 23.1150 +/* Read a header or footer insert from the input file */
 23.1151 +void read_insert(char* insert)
 23.1152 +{
 23.1153 +	char* ptr = insert;
 23.1154 +	char* overflow = insert + MAX_INSERT_LENGTH - MAX_LINE_LENGTH;
 23.1155 +	int length;
 23.1156 +	char* first_blank = NULL;
 23.1157 +
 23.1158 +	/* Skip any leading blank lines */
 23.1159 +	for(length = 0;length == 0;length = fgetline(ptr, MAX_LINE_LENGTH, g_input_file))
 23.1160 +		if(ptr >= overflow)
 23.1161 +			error_exit("Buffer overflow reading inserts");
 23.1162 +	if(length < 0)
 23.1163 +		error_exit("Premature EOF while reading inserts");
 23.1164 +
 23.1165 +	/* Advance and append newline */
 23.1166 +	ptr += length;
 23.1167 +	strcpy(ptr++, "\n");
 23.1168 +
 23.1169 +	/* Read until next separator */
 23.1170 +	for(;;)
 23.1171 +	{
 23.1172 +		/* Read a new line */
 23.1173 +		if(ptr >= overflow)
 23.1174 +			error_exit("Buffer overflow reading inserts");
 23.1175 +		if((length = fgetline(ptr, MAX_LINE_LENGTH, g_input_file)) < 0)
 23.1176 +			error_exit("Premature EOF while reading inserts");
 23.1177 +
 23.1178 +		/* Stop if we read a separator */
 23.1179 +		if(strcmp(ptr, ID_INPUT_SEPARATOR) == 0)
 23.1180 +			break;
 23.1181 +
 23.1182 +		/* keep track in case there are trailing blanks */
 23.1183 +		if(length == 0)
 23.1184 +		{
 23.1185 +			if(first_blank == NULL)
 23.1186 +				first_blank = ptr;
 23.1187 +		}
 23.1188 +		else
 23.1189 +			first_blank = NULL;
 23.1190 +
 23.1191 +		/* Advance and append newline */
 23.1192 +		ptr += length;
 23.1193 +		strcpy(ptr++, "\n");
 23.1194 +	}
 23.1195 +
 23.1196 +	/* kill any trailing blank lines */
 23.1197 +	if(first_blank)
 23.1198 +		ptr = first_blank;
 23.1199 +	*ptr = 0;
 23.1200 +}
 23.1201 +
 23.1202 +
 23.1203 +
 23.1204 +/* ======================================================================== */
 23.1205 +/* ============================= MAIN FUNCTION ============================ */
 23.1206 +/* ======================================================================== */
 23.1207 +
 23.1208 +int main(int argc, char **argv)
 23.1209 +{
 23.1210 +	/* File stuff */
 23.1211 +	char output_path[MAX_DIR] = "";
 23.1212 +	char filename[MAX_PATH];
 23.1213 +	/* Section identifier */
 23.1214 +	char section_id[MAX_LINE_LENGTH+1];
 23.1215 +	/* Inserts */
 23.1216 +	char temp_insert[MAX_INSERT_LENGTH+1];
 23.1217 +	char prototype_footer_insert[MAX_INSERT_LENGTH+1];
 23.1218 +	char table_footer_insert[MAX_INSERT_LENGTH+1];
 23.1219 +	char ophandler_footer_insert[MAX_INSERT_LENGTH+1];
 23.1220 +	/* Flags if we've processed certain parts already */
 23.1221 +	int prototype_header_read = 0;
 23.1222 +	int prototype_footer_read = 0;
 23.1223 +	int table_header_read = 0;
 23.1224 +	int table_footer_read = 0;
 23.1225 +	int ophandler_header_read = 0;
 23.1226 +	int ophandler_footer_read = 0;
 23.1227 +	int table_body_read = 0;
 23.1228 +	int ophandler_body_read = 0;
 23.1229 +
 23.1230 +	printf("\n\t\tMusashi v%s 68000, 68010, 68EC020, 68020 emulator\n", g_version);
 23.1231 +	printf("\t\tCopyright 1998-2000 Karl Stenerud (karl@mame.net)\n\n");
 23.1232 +
 23.1233 +	/* Check if output path and source for the input file are given */
 23.1234 +    if(argc > 1)
 23.1235 +	{
 23.1236 +		char *ptr;
 23.1237 +		strcpy(output_path, argv[1]);
 23.1238 +
 23.1239 +		for(ptr = strchr(output_path, '\\'); ptr; ptr = strchr(ptr, '\\'))
 23.1240 +			*ptr = '/';
 23.1241 +        if(output_path[strlen(output_path)-1] != '/')
 23.1242 +			strcat(output_path, "/");
 23.1243 +		if(argc > 2)
 23.1244 +			strcpy(g_input_filename, argv[2]);
 23.1245 +	}
 23.1246 +
 23.1247 +
 23.1248 +	/* Open the files we need */
 23.1249 +	sprintf(filename, "%s%s", output_path, FILENAME_PROTOTYPE);
 23.1250 +	if((g_prototype_file = fopen(filename, "wt")) == NULL)
 23.1251 +		perror_exit("Unable to create prototype file (%s)\n", filename);
 23.1252 +
 23.1253 +	sprintf(filename, "%s%s", output_path, FILENAME_TABLE);
 23.1254 +	if((g_table_file = fopen(filename, "wt")) == NULL)
 23.1255 +		perror_exit("Unable to create table file (%s)\n", filename);
 23.1256 +
 23.1257 +	sprintf(filename, "%s%s", output_path, FILENAME_OPS_AC);
 23.1258 +	if((g_ops_ac_file = fopen(filename, "wt")) == NULL)
 23.1259 +		perror_exit("Unable to create ops ac file (%s)\n", filename);
 23.1260 +
 23.1261 +	sprintf(filename, "%s%s", output_path, FILENAME_OPS_DM);
 23.1262 +	if((g_ops_dm_file = fopen(filename, "wt")) == NULL)
 23.1263 +		perror_exit("Unable to create ops dm file (%s)\n", filename);
 23.1264 +
 23.1265 +	sprintf(filename, "%s%s", output_path, FILENAME_OPS_NZ);
 23.1266 +	if((g_ops_nz_file = fopen(filename, "wt")) == NULL)
 23.1267 +		perror_exit("Unable to create ops nz file (%s)\n", filename);
 23.1268 +
 23.1269 +	if((g_input_file=fopen(g_input_filename, "rt")) == NULL)
 23.1270 +		perror_exit("can't open %s for input", g_input_filename);
 23.1271 +
 23.1272 +
 23.1273 +	/* Get to the first section of the input file */
 23.1274 +	section_id[0] = 0;
 23.1275 +	while(strcmp(section_id, ID_INPUT_SEPARATOR) != 0)
 23.1276 +		if(fgetline(section_id, MAX_LINE_LENGTH, g_input_file) < 0)
 23.1277 +			error_exit("Premature EOF while reading input file");
 23.1278 +
 23.1279 +	/* Now process all sections */
 23.1280 +	for(;;)
 23.1281 +	{
 23.1282 +		if(fgetline(section_id, MAX_LINE_LENGTH, g_input_file) < 0)
 23.1283 +			error_exit("Premature EOF while reading input file");
 23.1284 +		if(strcmp(section_id, ID_PROTOTYPE_HEADER) == 0)
 23.1285 +		{
 23.1286 +			if(prototype_header_read)
 23.1287 +				error_exit("Duplicate prototype header");
 23.1288 +			read_insert(temp_insert);
 23.1289 +			fprintf(g_prototype_file, "%s\n\n", temp_insert);
 23.1290 +			prototype_header_read = 1;
 23.1291 +		}
 23.1292 +		else if(strcmp(section_id, ID_TABLE_HEADER) == 0)
 23.1293 +		{
 23.1294 +			if(table_header_read)
 23.1295 +				error_exit("Duplicate table header");
 23.1296 +			read_insert(temp_insert);
 23.1297 +			fprintf(g_table_file, "%s", temp_insert);
 23.1298 +			table_header_read = 1;
 23.1299 +		}
 23.1300 +		else if(strcmp(section_id, ID_OPHANDLER_HEADER) == 0)
 23.1301 +		{
 23.1302 +			if(ophandler_header_read)
 23.1303 +				error_exit("Duplicate opcode handler header");
 23.1304 +			read_insert(temp_insert);
 23.1305 +			fprintf(g_ops_ac_file, "%s\n\n", temp_insert);
 23.1306 +			fprintf(g_ops_dm_file, "%s\n\n", temp_insert);
 23.1307 +			fprintf(g_ops_nz_file, "%s\n\n", temp_insert);
 23.1308 +			ophandler_header_read = 1;
 23.1309 +		}
 23.1310 +		else if(strcmp(section_id, ID_PROTOTYPE_FOOTER) == 0)
 23.1311 +		{
 23.1312 +			if(prototype_footer_read)
 23.1313 +				error_exit("Duplicate prototype footer");
 23.1314 +			read_insert(prototype_footer_insert);
 23.1315 +			prototype_footer_read = 1;
 23.1316 +		}
 23.1317 +		else if(strcmp(section_id, ID_TABLE_FOOTER) == 0)
 23.1318 +		{
 23.1319 +			if(table_footer_read)
 23.1320 +				error_exit("Duplicate table footer");
 23.1321 +			read_insert(table_footer_insert);
 23.1322 +			table_footer_read = 1;
 23.1323 +		}
 23.1324 +		else if(strcmp(section_id, ID_OPHANDLER_FOOTER) == 0)
 23.1325 +		{
 23.1326 +			if(ophandler_footer_read)
 23.1327 +				error_exit("Duplicate opcode handler footer");
 23.1328 +			read_insert(ophandler_footer_insert);
 23.1329 +			ophandler_footer_read = 1;
 23.1330 +		}
 23.1331 +		else if(strcmp(section_id, ID_TABLE_BODY) == 0)
 23.1332 +		{
 23.1333 +			if(!prototype_header_read)
 23.1334 +				error_exit("Table body encountered before prototype header");
 23.1335 +			if(!table_header_read)
 23.1336 +				error_exit("Table body encountered before table header");
 23.1337 +			if(!ophandler_header_read)
 23.1338 +				error_exit("Table body encountered before opcode handler header");
 23.1339 +
 23.1340 +			if(table_body_read)
 23.1341 +				error_exit("Duplicate table body");
 23.1342 +
 23.1343 +			populate_table();
 23.1344 +			table_body_read = 1;
 23.1345 +		}
 23.1346 +		else if(strcmp(section_id, ID_OPHANDLER_BODY) == 0)
 23.1347 +		{
 23.1348 +			if(!prototype_header_read)
 23.1349 +				error_exit("Opcode handlers encountered before prototype header");
 23.1350 +			if(!table_header_read)
 23.1351 +				error_exit("Opcode handlers encountered before table header");
 23.1352 +			if(!ophandler_header_read)
 23.1353 +				error_exit("Opcode handlers encountered before opcode handler header");
 23.1354 +			if(!table_body_read)
 23.1355 +				error_exit("Opcode handlers encountered before table body");
 23.1356 +
 23.1357 +			if(ophandler_body_read)
 23.1358 +				error_exit("Duplicate opcode handler section");
 23.1359 +
 23.1360 +			process_opcode_handlers();
 23.1361 +
 23.1362 +			ophandler_body_read = 1;
 23.1363 +		}
 23.1364 +		else if(strcmp(section_id, ID_END) == 0)
 23.1365 +		{
 23.1366 +			/* End of input file.  Do a sanity check and then write footers */
 23.1367 +			if(!prototype_header_read)
 23.1368 +				error_exit("Missing prototype header");
 23.1369 +			if(!prototype_footer_read)
 23.1370 +				error_exit("Missing prototype footer");
 23.1371 +			if(!table_header_read)
 23.1372 +				error_exit("Missing table header");
 23.1373 +			if(!table_footer_read)
 23.1374 +				error_exit("Missing table footer");
 23.1375 +			if(!table_body_read)
 23.1376 +				error_exit("Missing table body");
 23.1377 +			if(!ophandler_header_read)
 23.1378 +				error_exit("Missing opcode handler header");
 23.1379 +			if(!ophandler_footer_read)
 23.1380 +				error_exit("Missing opcode handler footer");
 23.1381 +			if(!ophandler_body_read)
 23.1382 +				error_exit("Missing opcode handler body");
 23.1383 +
 23.1384 +			print_opcode_output_table(g_table_file);
 23.1385 +
 23.1386 +			fprintf(g_prototype_file, "%s\n\n", prototype_footer_insert);
 23.1387 +			fprintf(g_table_file, "%s\n\n", table_footer_insert);
 23.1388 +			fprintf(g_ops_ac_file, "%s\n\n", ophandler_footer_insert);
 23.1389 +			fprintf(g_ops_dm_file, "%s\n\n", ophandler_footer_insert);
 23.1390 +			fprintf(g_ops_nz_file, "%s\n\n", ophandler_footer_insert);
 23.1391 +
 23.1392 +			break;
 23.1393 +		}
 23.1394 +		else
 23.1395 +		{
 23.1396 +			error_exit("Unknown section identifier: %s", section_id);
 23.1397 +		}
 23.1398 +	}
 23.1399 +
 23.1400 +	/* Close all files and exit */
 23.1401 +	fclose(g_prototype_file);
 23.1402 +	fclose(g_table_file);
 23.1403 +	fclose(g_ops_ac_file);
 23.1404 +	fclose(g_ops_dm_file);
 23.1405 +	fclose(g_ops_nz_file);
 23.1406 +	fclose(g_input_file);
 23.1407 +
 23.1408 +	printf("Generated %d opcode handlers from %d primitives\n", g_num_functions, g_num_primitives);
 23.1409 +
 23.1410 +	return 0;
 23.1411 +}
 23.1412 +
 23.1413 +
 23.1414 +
 23.1415 +/* ======================================================================== */
 23.1416 +/* ============================== END OF FILE ============================= */
 23.1417 +/* ======================================================================== */
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/musashi/readme.txt	Sat Nov 27 01:13:12 2010 +0000
    24.3 @@ -0,0 +1,315 @@
    24.4 +                                    MUSASHI
    24.5 +                                    =======
    24.6 +
    24.7 +                                  Version 3.3
    24.8 +
    24.9 +             A portable Motorola M680x0 processor emulation engine.
   24.10 +            Copyright 1998-2001 Karl Stenerud.  All rights reserved.
   24.11 +
   24.12 +
   24.13 +
   24.14 +INTRODUCTION:
   24.15 +------------
   24.16 +
   24.17 +Musashi is a Motorola 68000, 68010, 68EC020, and 68020 emulator written in C.
   24.18 +This emulator was written with two goals in mind: portability and speed.
   24.19 +
   24.20 +The emulator is written to ANSI C specifications with the exception that I use
   24.21 +inline functions.  This is not compliant to the ANSI spec, but will be
   24.22 +compliant to the ANSI C9X spec.
   24.23 +
   24.24 +It has been successfully running in the MAME project (www.mame.net) for over 2
   24.25 +years and so has had time to mature.
   24.26 +
   24.27 +
   24.28 +
   24.29 +LICENSE AND COPYRIGHT:
   24.30 +---------------------
   24.31 +
   24.32 +The Musashi M680x0 emulator is copyright 1998-2001 Karl Stenerud.
   24.33 +
   24.34 +The source code included in this archive is provided AS-IS, free for any
   24.35 +non-commercial purpose.
   24.36 +
   24.37 +If you build a program using this core, please give credit to the author.
   24.38 +
   24.39 +If you wish to use this core in a commercial environment, please contact
   24.40 +the author to discuss commercial licensing.
   24.41 +
   24.42 +
   24.43 +
   24.44 +AVAILABILITY:
   24.45 +------------
   24.46 +The latest version of this code can be obtained at:
   24.47 +http://kstenerud.cjb.net
   24.48 +
   24.49 +
   24.50 +
   24.51 +CONTACTING THE AUTHOR:
   24.52 +---------------------
   24.53 +I can be reached at kstenerud@mame.net
   24.54 +
   24.55 +
   24.56 +
   24.57 +BASIC CONFIGURATION:
   24.58 +-------------------
   24.59 +The basic configuration will give you a standard 68000 that has sufficient
   24.60 +functionality to work in a primitive environment.
   24.61 +
   24.62 +This setup assumes that you only have 1 device interrupting it, that the
   24.63 +device will always request an autovectored interrupt, and it will always clear
   24.64 +the interrupt before the interrupt service routine finishes (but could
   24.65 +possibly re-assert the interrupt).
   24.66 +You will have only one address space, no tracing, and no instruction prefetch.
   24.67 +
   24.68 +To implement the basic configuration:
   24.69 +
   24.70 +- Open m68kconf.h and verify that the settings for INLINE and DECL_SPEC will
   24.71 +  work with your compiler. (They are set for gcc)
   24.72 +
   24.73 +- In your host program, implement the following functions:
   24.74 +    unsigned int  m68k_read_memory_8(unsigned int address);
   24.75 +    unsigned int  m68k_read_memory_16(unsigned int address);
   24.76 +    unsigned int  m68k_read_memory_32(unsigned int address);
   24.77 +    void m68k_write_memory_8(unsigned int address, unsigned int value);
   24.78 +    void m68k_write_memory_16(unsigned int address, unsigned int value);
   24.79 +    void m68k_write_memory_32(unsigned int address, unsigned int value);
   24.80 +
   24.81 +- In your host program, be sure to call m68k_pulse_reset() once before calling
   24.82 +  any of the other functions as this initializes the core.
   24.83 +
   24.84 +- Use m68k_execute() to execute instructions and m68k_set_irq() to cause an
   24.85 +  interrupt.
   24.86 +
   24.87 +
   24.88 +
   24.89 +ADDING PROPER INTERRUPT HANDLING:
   24.90 +--------------------------------
   24.91 +The interrupt handling in the basic configuration doesn't emulate the
   24.92 +interrupt acknowledge phase of the CPU and automatically clears an interrupt
   24.93 +request during interrupt processing.
   24.94 +While this works for most systems, you may need more accurate interrupt
   24.95 +handling.
   24.96 +
   24.97 +To add proper interrupt handling:
   24.98 +
   24.99 +- In m68kconf.h, set M68K_EMULATE_INT_ACK to OPT_SPECIFY_HANDLER
  24.100 +
  24.101 +- In m68kconf.h, set M68K_INT_ACK_CALLBACK(A) to your interrupt acknowledge
  24.102 +  routine
  24.103 +
  24.104 +- Your interrupt acknowledge routine must return an interrupt vector,
  24.105 +  M68K_INT_ACK_AUTOVECTOR, or M68K_INT_ACK_SPURIOUS.  most m68k
  24.106 +  implementations just use autovectored interrupts.
  24.107 +
  24.108 +- When the interrupting device is satisfied, you must call m68k_set_irq(0) to
  24.109 +  remove the interrupt request.
  24.110 +
  24.111 +
  24.112 +
  24.113 +MULTIPLE INTERRUPTS:
  24.114 +-------------------
  24.115 +The above system will work if you have only one device interrupting the CPU,
  24.116 +but if you have more than one device, you must do a bit more.
  24.117 +
  24.118 +To add multiple interrupts:
  24.119 +
  24.120 +- You must make an interrupt arbitration device that will take the highest
  24.121 +  priority interrupt and encode it onto the IRQ pins on the CPU.
  24.122 +
  24.123 +- The interrupt arbitration device should use m68k_set_irq() to set the
  24.124 +  highest pending interrupt, or 0 for no interrupts pending.
  24.125 +
  24.126 +
  24.127 +
  24.128 +SEPARATE IMMEDIATE AND PC-RELATIVE READS:
  24.129 +----------------------------------------
  24.130 +You can write faster memory access functions if you know whether you are
  24.131 +fetching from ROM or RAM.  Immediate reads are always from the program space
  24.132 +(Always in ROM unless it is running self-modifying code).
  24.133 +This will also separate the pc-relative reads, since some systems treat
  24.134 +PROGRAM mode reads and DATA mode reads differently (for program encryption,
  24.135 +for instance).  See the section below (ADDRESS SPACE) for an explanation of
  24.136 +PROGRAM and DATA mode.
  24.137 +
  24.138 +To enable separate reads:
  24.139 +
  24.140 +- In m68kconf.h, turn on M68K_SEPARATE_READS.
  24.141 +
  24.142 +- In your host program, implement the following functions:
  24.143 +    unsigned int  m68k_read_immediate_16(unsigned int address);
  24.144 +    unsigned int  m68k_read_immediate_32(unsigned int address);
  24.145 +
  24.146 +    unsigned int  m68k_read_pcrelative_8(unsigned int address);
  24.147 +    unsigned int  m68k_read_pcrelative_16(unsigned int address);
  24.148 +    unsigned int  m68k_read_pcrelative_32(unsigned int address);
  24.149 +
  24.150 +- If you need to know the current PC (for banking and such), set
  24.151 +  M68K_MONITOR_PC to OPT_SPECIFY_HANDLER, and set M68K_SET_PC_CALLBACK(A) to
  24.152 +  your routine.
  24.153 +
  24.154 +
  24.155 +
  24.156 +ADDRESS SPACES:
  24.157 +--------------
  24.158 +Most systems will only implement one address space, placing ROM at the lower
  24.159 +addresses and RAM at the higher.  However, there is the possibility that a
  24.160 +system will implement ROM and RAM in the same address range, but in different
  24.161 +address spaces, or will have different mamory types that require different
  24.162 +handling for the program and the data.
  24.163 +
  24.164 +The 68k accomodates this by allowing different program spaces, the most
  24.165 +important to us being PROGRAM and DATA space.  Here is a breakdown of
  24.166 +how information is fetched:
  24.167 +
  24.168 +- All immediate reads are fetched from PROGRAM space.
  24.169 +
  24.170 +- All PC-relative reads are fetched from PROGRAM space.
  24.171 +
  24.172 +- The initial stack pointer and program counter are fetched from PROGRAM space.
  24.173 +
  24.174 +- All other reads (except for those from the moves instruction for 68020)
  24.175 +   are fetched from DATA space.
  24.176 +
  24.177 +The m68k deals with this by encoding the requested address space on the
  24.178 +function code pins:
  24.179 +
  24.180 +                       FC
  24.181 +    Address Space      210
  24.182 +    ------------------ ---
  24.183 +    USER DATA          001
  24.184 +    USER PROGRAM       010
  24.185 +    SUPERVISOR DATA    101
  24.186 +    SUPERVISOR PROGRAM 110
  24.187 +    CPU SPACE          111 <-- not emulated in this core since we emulate
  24.188 +                               interrupt acknowledge in another way.
  24.189 +
  24.190 +Problems arise here if you need to emulate this distinction (if, for example,
  24.191 +your ROM and RAM are at the same address range, with RAM and ROM enable
  24.192 +wired to the function code pins).
  24.193 +
  24.194 +There are 2 ways to deal with this situation using Musashi:
  24.195 +
  24.196 +1. If you only need the distinction between PROGRAM and DATA (the most common),
  24.197 +   you can just separate the reads (see the preceeding section).  This is the
  24.198 +   faster solution.
  24.199 +
  24.200 +2. You can emulate the function code pins entirely.
  24.201 +
  24.202 +To emulate the function code pins:
  24.203 +
  24.204 +- In m68kconf.h, set M68K_EMULATE_FC to OPT_SPECIFY_HANDLER and set
  24.205 +  M68K_SET_FC_CALLBACK(A) to your function code handler function.
  24.206 +
  24.207 +- Your function code handler should select the proper address space for
  24.208 +  subsequent calls to m68k_read_xx (and m68k_write_xx for 68010+).
  24.209 +
  24.210 +Note: immediate reads are always done from program space, so technically you
  24.211 +      don't need to implement the separate immediate reads, although you could
  24.212 +      gain more speed improvements leaving them in and doing some clever
  24.213 +      programming.
  24.214 +
  24.215 +
  24.216 +
  24.217 +USING DIFFERENT CPU TYPES:
  24.218 +-------------------------
  24.219 +The default is to enable only the 68000 cpu type.  To change this, change the
  24.220 +settings for M68K_EMULATE_010 etc in m68kconf.h.
  24.221 +
  24.222 +To set the CPU type you want to use:
  24.223 +
  24.224 +- Make sure it is enabled in m68kconf.h.  Current switches are:
  24.225 +    M68K_EMULATE_010
  24.226 +    M68K_EMULATE_EC020
  24.227 +    M68K_EMULATE_020
  24.228 +
  24.229 +- In your host program, call m68k_set_cpu_type() and then call
  24.230 +  m68k_pulse_reset().  Valid CPU types are:
  24.231 +    M68K_CPU_TYPE_68000,
  24.232 +    M68K_CPU_TYPE_68010,
  24.233 +    M68K_CPU_TYPE_68EC020,
  24.234 +    M68K_CPU_TYPE_68020
  24.235 +
  24.236 +
  24.237 +
  24.238 +CLOCK FREQUENCY:
  24.239 +---------------
  24.240 +In order to emulate the correct clock frequency, you will have to calculate
  24.241 +how long it takes the emulation to execute a certain number of "cycles" and
  24.242 +vary your calls to m68k_execute() accordingly.
  24.243 +As well, it is a good idea to take away the CPU's timeslice when it writes to
  24.244 +a memory-mapped port in order to give the device it wrote to a chance to
  24.245 +react.
  24.246 +
  24.247 +You can use the functions m68k_cycles_run(), m68k_cycles_remaining(),
  24.248 +m68k_modify_timeslice(), and m68k_end_timeslice() to do this.
  24.249 +Try to use large cycle values in your calls to m68k_execute() since it will
  24.250 +increase throughput.  You can always take away the timeslice later.
  24.251 +
  24.252 +
  24.253 +
  24.254 +MORE CORRECT EMULATION:
  24.255 +----------------------
  24.256 +You may need to enable these in order to properly emulate some of the more
  24.257 +obscure functions of the m68k:
  24.258 +
  24.259 +- M68K_EMULATE_BKPT_ACK causes the CPU to call a breakpoint handler on a BKPT
  24.260 +  instruction
  24.261 +
  24.262 +- M68K_EMULATE_TRACE causes the CPU to generate trace exceptions when the
  24.263 +  trace bits are set
  24.264 +
  24.265 +- M68K_EMULATE_RESET causes the CPU to call a reset handler on a RESET
  24.266 +  instruction.
  24.267 +
  24.268 +- M68K_EMULATE_PREFETCH emulates the 4-word instruction prefetch that is part
  24.269 +  of the 68000/68010 (needed for Amiga emulation).
  24.270 +
  24.271 +- call m68k_pulse_halt() to emulate the HALT pin.
  24.272 +
  24.273 +
  24.274 +
  24.275 +CONVENIENCE FUNCTIONS:
  24.276 +---------------------
  24.277 +These are in here for programmer convenience:
  24.278 +
  24.279 +- M68K_INSTRUCTION_HOOK lets you call a handler before each instruction.
  24.280 +
  24.281 +- M68K_LOG_ENABLE and M68K_LOG_1010_1111 lets you log illegal and A/F-line
  24.282 +  instructions.
  24.283 +
  24.284 +
  24.285 +
  24.286 +MULTIPLE CPU EMULATION:
  24.287 +----------------------
  24.288 +The default is to use only one CPU.  To use more than one CPU in this core,
  24.289 +there are some things to keep in mind:
  24.290 +
  24.291 +- To have different cpus call different functions, use OPT_ON instead of
  24.292 +  OPT_SPECIFY_HANDLER, and use the m68k_set_xxx_callback() functions to set
  24.293 +  your callback handlers on a per-cpu basis.
  24.294 +
  24.295 +- Be sure to call set_cpu_type() for each CPU you use.
  24.296 +
  24.297 +- Use m68k_set_context() and m68k_get_context() to switch to another CPU.
  24.298 +
  24.299 +
  24.300 +
  24.301 +LOAD AND SAVE CPU CONTEXTS FROM DISK:
  24.302 +------------------------------------
  24.303 +You can use them68k_load_context() and m68k_save_context() functions to load
  24.304 +and save the CPU state to disk.
  24.305 +
  24.306 +
  24.307 +
  24.308 +GET/SET INFORMATION FROM THE CPU:
  24.309 +--------------------------------
  24.310 +You can use m68k_get_reg() and m68k_set_reg() to gain access to the internals
  24.311 +of the CPU.
  24.312 +
  24.313 +
  24.314 +
  24.315 +EXAMPLE:
  24.316 +-------
  24.317 +
  24.318 +I have included a file example.zip that contains a full example.
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/src/version.h.in	Sat Nov 27 01:13:12 2010 +0000
    25.3 @@ -0,0 +1,16 @@
    25.4 +#define VER_COMPILE_DATE	"@@date@@"
    25.5 +#define VER_COMPILE_TIME	"@@time@@"
    25.6 +#define VER_COMPILE_BY		"@@whoami@@"
    25.7 +#define VER_COMPILE_HOST	"@@hostname@@"
    25.8 +#define VER_COMPILER		"@@compiler@@"
    25.9 +#define VER_BUILD_TYPE		"@@buildtype@@"
   25.10 +#define VER_CFLAGS			"@@cflags@@"
   25.11 +
   25.12 +#define VER_MAJOR			@@majorver@@
   25.13 +#define VER_MINOR			@@minorver@@
   25.14 +#define VER_BUILDNUM		@@buildnum@@
   25.15 +#define VER_EXTRA			"@@extraver@@"
   25.16 +#define VER_VCSREV			"@@vcsstr@@"
   25.17 +
   25.18 +#define VER_FULLSTR			"@@fullverstr@@"
   25.19 +