~korth/gens-gs-ii.git
3 years ago[cz80] cz80_byteorder.h: Byte order definitions. feature/switch-to-CZ80-v2 github/feature/switch-to-CZ80-v2
David Korth [Tue, 5 Apr 2016 05:08:49 +0000 (01:08 -0400)] 
[cz80] cz80_byteorder.h: Byte order definitions.

Copied from libcompat/byteorder.h.

Added #include "cz80_byteorder.h" to cz80_context.h and cz80_int.h.

3 years ago[cz80] Use regparm(3) when compiling with gcc on i386.
David Korth [Tue, 5 Apr 2016 05:00:49 +0000 (01:00 -0400)] 
[cz80] Use regparm(3) when compiling with gcc on i386.

This is similar to MSVC's fastcall, except it uses different registers
(%eax, %edx, %ecx; fastcall is %ecx, %edx) and it supports up to 3,
whereas fastcall uses two.

3 years ago[cz80] cz80_conf.h: New macro CZ80_FETCH_BANK_SIZE.
David Korth [Tue, 5 Apr 2016 04:06:35 +0000 (00:06 -0400)] 
[cz80] cz80_conf.h: New macro CZ80_FETCH_BANK_SIZE.

CZ80_FETCH_BANK is the number of banks, not the size of the banks.
CZ80_FETCH_BANK_SIZE is now the bank size.

cz80.c: Cz80_dummy_fetch[] should be CZ80_FETCH_BANK_SIZE.

[libgens] Z80_MD_Mem.cpp: Use CZ80_FETCH_BANK_SIZE in the word read/write
handling functions.

3 years ago[libgens] Z80::Z80_MD_ReadW_static(): Removed a debugging message.
David Korth [Tue, 5 Apr 2016 03:44:34 +0000 (23:44 -0400)] 
[libgens] Z80::Z80_MD_ReadW_static(): Removed a debugging message.

3 years ago[cz80] Enable 16-bit memory access.
David Korth [Tue, 5 Apr 2016 02:13:06 +0000 (22:13 -0400)] 
[cz80] Enable 16-bit memory access.

This could potentially improve performance for games that use
16-bit memory access on the Z80.

[libgens] Z80: Added 16-bit memory wrappers. These wrappers currently
call the 8-bit functions twice, except when accessing Z80 memory, in
which case it's accessed directly, though with two functions and
shifting.

TODO: Use 16-bit reads/writes on unaligned LE.

3 years ago[starscream] CMakeLists.txt: Specify the target name instead of getting the location...
David Korth [Tue, 5 Apr 2016 01:46:59 +0000 (21:46 -0400)] 
[starscream] CMakeLists.txt: Specify the target name instead of getting the location property.

This is effectively the same, and it eliminates some CMake warnings:

CMake Warning (dev) at src/libgens/starscream/CMakeLists.txt:28 (GET_PROPERTY):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "star_m68k".  Use the
  target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at src/libgens/starscream/CMakeLists.txt:29 (GET_PROPERTY):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "star_s68k".  Use the
  target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

This warning is for project developers.  Use -Wno-dev to suppress it.

3 years ago[cz80] Split register accessor functions out of cz80.c.
David Korth [Tue, 5 Apr 2016 01:09:24 +0000 (21:09 -0400)] 
[cz80] Split register accessor functions out of cz80.c.

cz80.c takes a while to compile due to all of the opcodes, so split out
the register accessor functions so they can be modified without having
to recompile the entire cz80.c file.

3 years ago[cz80] Added functions Cz80_Alloc() and Cz80_Free().
David Korth [Tue, 5 Apr 2016 01:03:09 +0000 (21:03 -0400)] 
[cz80] Added functions Cz80_Alloc() and Cz80_Free().

[libgens] Z80.cpp: Use Cz80_Alloc() and Cz80_Free().
We no longer need to #include "cz80/cz80_context.h".

3 years ago[libgens] Z80::zomgSaveReg(): Actually use Cz80_Get_Status().
David Korth [Tue, 5 Apr 2016 01:02:27 +0000 (21:02 -0400)] 
[libgens] Z80::zomgSaveReg(): Actually use Cz80_Get_Status().

3 years ago[cz80] Added wrapper functions to get/set IntVect and Status.
David Korth [Tue, 5 Apr 2016 00:58:44 +0000 (20:58 -0400)] 
[cz80] Added wrapper functions to get/set IntVect and Status.

[libgens] Z80.cpp: Use the wrapper functions for IntVect and Status.

3 years ago[libgens] Z80: Save/load the WZ register.
David Korth [Tue, 5 Apr 2016 00:53:21 +0000 (20:53 -0400)] 
[libgens] Z80: Save/load the WZ register.

CZ80 supports WZ, so we should save/load it to/from the savestate.

3 years ago[libgens] Converted the Z80 class to a non-static class.
David Korth [Tue, 5 Apr 2016 00:49:52 +0000 (20:49 -0400)] 
[libgens] Converted the Z80 class to a non-static class.

The Z80_MD_Mem class has been merged into the Z80 class.
Its functions are still in Z80_MD_Mem.cpp.

Z80_MD_Mem's functions are no longer static, except for the
wrapper functions used by cz80. cz80's ctx field is now set
to the Z80 object.

TODO: Make m_ramZ80 and m_bankZ80 protected, and add accessors.

3 years ago[libgens] EmuContext.hpp: Removed some unnecessary includes.
David Korth [Tue, 5 Apr 2016 00:33:09 +0000 (20:33 -0400)] 
[libgens] EmuContext.hpp: Removed some unnecessary includes.

Added forward declarations for classes that were previously included.

Updated other files to handle this change in EmuContext.hpp.

3 years ago[libgens] Z80_MD_Mem::Z80_WriteB_68K_Rom(): Fix writing to M68K RAM.
David Korth [Tue, 5 Apr 2016 00:14:36 +0000 (20:14 -0400)] 
[libgens] Z80_MD_Mem::Z80_WriteB_68K_Rom(): Fix writing to M68K RAM.

The 'address' parameter is now uint16_t, so this would cause the
address to get truncated.

A similar change was made in Z80_ReadB_68K_Rom(), which affected
significantly more games, since pretty much every game reads from
the 68000 banking area, but very few write to it.

3 years ago[libgens] Z80.hpp: Remove ms_odometer.
David Korth [Mon, 4 Apr 2016 23:29:30 +0000 (19:29 -0400)] 
[libgens] Z80.hpp: Remove ms_odometer.

The original mdZ80 odometer code used cycleCnt, not a separate
"odometer" variable.

The cycle counting code should now be nearly identical to the
way mdZ80 handled things.

3 years ago[libgens] Removed mdZ80.
David Korth [Mon, 4 Apr 2016 23:22:32 +0000 (19:22 -0400)] 
[libgens] Removed mdZ80.

3 years ago[libgens] Switch to CZ80.
David Korth [Mon, 4 Apr 2016 23:16:34 +0000 (19:16 -0400)] 
[libgens] Switch to CZ80.

The cycle counting code isn't quite correct. mdZ80 used a "count to cycle"
setup, whereas cz80 uses "run x cycles". The current port mostly works,
but it doesn't handle BUSREQ cycles.

Interestingly, this fixes Williams/Midway Presents Arcade's Greatest Hits,
which previously hung on a black screen. (issue #53)

3 years ago[libgens/tests] Z80Test: Fix build with cz80 header changes.
David Korth [Mon, 4 Apr 2016 21:58:55 +0000 (17:58 -0400)] 
[libgens/tests] Z80Test: Fix build with cz80 header changes.

FIXME: Don't access cz80_struc data directly.

3 years ago[cz80] Split configuration, context, flags, and internal definitions out from cz80.h.
David Korth [Mon, 4 Apr 2016 21:55:41 +0000 (17:55 -0400)] 
[cz80] Split configuration, context, flags, and internal definitions out from cz80.h.

3 years ago[libgens/tests] Z80Test: Re-enable the test in CMake.
David Korth [Mon, 4 Apr 2016 21:38:37 +0000 (17:38 -0400)] 
[libgens/tests] Z80Test: Re-enable the test in CMake.

The test correctly fails if any errors are detected.

3 years ago[libgens/tests] Z80Test: Copy the BIOS and zexdoc/zexall executables.
David Korth [Mon, 4 Apr 2016 21:38:19 +0000 (17:38 -0400)] 
[libgens/tests] Z80Test: Copy the BIOS and zexdoc/zexall executables.

3 years ago[cz80] Split flag initialization into a separate file.
David Korth [Mon, 4 Apr 2016 21:31:22 +0000 (17:31 -0400)] 
[cz80] Split flag initialization into a separate file.

Only initialize flags once per process.

Initialize a dummy fetch bank and set it as the default instruction
fetch. This matches mdZ80.

Also set default IN and OUT handlers.

Marked the default "dummy" functions as static.

3 years ago[cz80] cz80jmp.inc.c: Enable relative jumptables on 64-bit and PIC.
David Korth [Mon, 4 Apr 2016 21:29:32 +0000 (17:29 -0400)] 
[cz80] cz80jmp.inc.c: Enable relative jumptables on 64-bit and PIC.

3 years ago[cz80] Renamed .inc files to .inc.c.
David Korth [Sat, 9 May 2015 15:02:11 +0000 (11:02 -0400)] 
[cz80] Renamed .inc files to .inc.c.

This helps with some text editors that use the file extension to
determine the syntax highlighter to use. (KDE's text editor component
assumes .inc is PHP (HTML).)

Added some macros to prevent the user from compiling the .inc.c files
individually. Only cz80.c should be compiled directly.

3 years ago[libgens/tests] Z80Test: Parse the output for error messages.
David Korth [Sat, 9 May 2015 14:57:43 +0000 (10:57 -0400)] 
[libgens/tests] Z80Test: Parse the output for error messages.

Colorize error messages in red. This is based on Google Test's
colorization code, and works on both Linux and Windows.

If an error occurs in a test, the test will now raise an assertion,
causing it to fail in Google Test.

3 years ago[cz80] cz80.h: Added a comment for "Emulator Configuration".
David Korth [Thu, 30 Apr 2015 03:14:54 +0000 (23:14 -0400)] 
[cz80] cz80.h: Added a comment for "Emulator Configuration".

3 years ago[cz80] Added an improved method for calculating R.
David Korth [Thu, 30 Apr 2015 03:07:49 +0000 (23:07 -0400)] 
[cz80] Added an improved method for calculating R.

R is now incremented on a per-instruction basis instead of exgtrapolating
based on the cycle count, which is usually wrong (and definitely wrong
in cases of extraneous FD/DD prefixes).

TODO: Verify the R register. Maybe a new test ROM is in order...

3 years ago[cz80] Fixed the types used by the R accessor and mutator.
David Korth [Thu, 30 Apr 2015 03:01:12 +0000 (23:01 -0400)] 
[cz80] Fixed the types used by the R accessor and mutator.

Cz80_Get_R(): zR only has the low 7 bits. zR2 has the high bit.
Cz80_Set_R(): Likewise.

3 years ago[cz80] New function Cz80_Soft_Reset().
David Korth [Thu, 30 Apr 2015 02:58:54 +0000 (22:58 -0400)] 
[cz80] New function Cz80_Soft_Reset().

This function simulates pulsing the /RESET line.

Based on z80-documented.pdf, the following registers are reset:
- PC = 0
- WZ = 0 (TODO: Is this correct?)
- AF = 0xFFFF
- SP = 0xFFFF
- R = 0
- IFF1 = IFF2 = 0
- I = 0
- IM = 0

3 years ago[libgens/tests] Z80Test.cpp: fflush(stdout) after printing each character.
David Korth [Wed, 29 Apr 2015 04:32:04 +0000 (00:32 -0400)] 
[libgens/tests] Z80Test.cpp: fflush(stdout) after printing each character.

This ensures the text is immediately visible on systems that buffer
stdout, e.g. Linux. (Windows doesn't buffer stdout by default, so
this problem didn't show up on Windows before.)

3 years ago[cz80] Don't use a separate !CZ80_EXACT version for OPXYCB_BIT_N_mXYd().
David Korth [Wed, 29 Apr 2015 04:21:47 +0000 (00:21 -0400)] 
[cz80] Don't use a separate !CZ80_EXACT version for OPXYCB_BIT_N_mXYd().

WZ is set to Ix+d, and according to http://www.z80.info/z80undoc3.txt ,
bits 5 and 3 of the high byte of (Ix+d) match the Y and X flags set
by this instruction.

Since we're setting WZ when using FD/DD instructions anyway,
just get rid of the !CZ80_EXACT version.

This fixes the following ZEXALL test with !CZ80_EXACT:
- bit n,(<ix,iy>+1).............  OK

The following ZEXALL tests still fail with !CZ80_EXACT after this change:
bit n,<b,c,d,e,h,l,(hl),a>....  ERROR **** crc expected:5e020e98 found:fe7d580c
cpd<r>........................  ERROR **** crc expected:134b622d found:5b23bf78
cpi<r>........................  ERROR **** crc expected:2da42d19 found:d9b9f4b2
ldd<r> (2)....................  ERROR **** crc expected:39dd3de1 found:5a907ed4
ldi<r> (1)....................  ERROR **** crc expected:f782b0d1 found:9abdf6b5
ldi<r> (2)....................  ERROR **** crc expected:e9ead0ae found:eb59891b

3 years ago[cz80] Moved the WZ variable behind CZ80_EXACT.
David Korth [Wed, 29 Apr 2015 04:10:48 +0000 (00:10 -0400)] 
[cz80] Moved the WZ variable behind CZ80_EXACT.

The variable is no longer included in the struct nor is it updated
by various opcodes if !CZ80_EXACT.

All ZEXDOC tests still pass.

The following ZEXALL tests failed with !CZ80_EXACT before this change:
- cpd<r>........................  ERROR **** crc expected:134b622d found:5b23bf78
- cpi<r>........................  ERROR **** crc expected:2da42d19 found:d9b9f4b2
- ldd<r> (2)....................  ERROR **** crc expected:39dd3de1 found:5a907ed4
- ldi<r> (1)....................  ERROR **** crc expected:f782b0d1 found:9abdf6b5
- ldi<r> (2)....................  ERROR **** crc expected:e9ead0ae found:eb59891b

The following ZEXALL tests fail with !CZ80_EXACT after this change:
- bit n,(<ix,iy>+1).............  ERROR **** crc expected:83534ee1 found:2b526613
- bit n,<b,c,d,e,h,l,(hl),a>....  ERROR **** crc expected:5e020e98 found:fe7d580c
- cpd<r>........................  ERROR **** crc expected:134b622d found:5b23bf78
- cpi<r>........................  ERROR **** crc expected:2da42d19 found:d9b9f4b2
- ldd<r> (2)....................  ERROR **** crc expected:39dd3de1 found:5a907ed4
- ldi<r> (1)....................  ERROR **** crc expected:f782b0d1 found:9abdf6b5
- ldi<r> (2)....................  ERROR **** crc expected:e9ead0ae found:eb59891b

3 years ago[cz80] cz80_opxycb.inc: Inlined all XYCB opcodes.
David Korth [Wed, 29 Apr 2015 03:41:42 +0000 (23:41 -0400)] 
[cz80] cz80_opxycb.inc: Inlined all XYCB opcodes.

Many of these opcodes use the exact same format but with a different
operation. To handle these, I created "UOP" macros that are specified
as a parameter for the main macro. This helps to reduce unnecessary
lines of boilerplate code.

OPXYCB_BIT_N_mXYd(): 8 parameters are needed, since jump table labels
are created using ##, and computing the labels doesn't work, since we'd
end up with completely broken labels. The switch/case version worked
fine with a single parameter and computed cases, though.

3 years ago[cz80] Inlined 8-bit INC/DEC opcodes and 8-bit FD/DD LD opcodes.
David Korth [Wed, 29 Apr 2015 03:40:50 +0000 (23:40 -0400)] 
[cz80] Inlined 8-bit INC/DEC opcodes and 8-bit FD/DD LD opcodes.

Added some extra comments about a few registers.

3 years ago[cz80] cz80_opcb.inc: Removed the OPJ_*() macros.
David Korth [Wed, 29 Apr 2015 03:30:33 +0000 (23:30 -0400)] 
[cz80] cz80_opcb.inc: Removed the OPJ_*() macros.

It's unlikely that these macros can be shared with OPXYCB due to
different addressing modes, so remove OPJ_*() to reduce clutter.

3 years ago[cz80] Rewrote the DAA instruction using a better algorithm.
David Korth [Wed, 29 Apr 2015 03:25:54 +0000 (23:25 -0400)] 
[cz80] Rewrote the DAA instruction using a better algorithm.

This algorithm uses fewer branches and is more readable.
All ZEXDOC and ZEXALL tests still pass.

Reference: http://wikiti.brandonw.net/?title=Z80_Instruction_Set

3 years ago[cz80] Synchronized opcode cycle timing with documentation.
David Korth [Wed, 29 Apr 2015 03:14:34 +0000 (23:14 -0400)] 
[cz80] Synchronized opcode cycle timing with documentation.

Among other things:
- CPIR/CPDR was off by two cycles
- DEC (Ix+d) / INC (Ix+d) was off by three cycles.

Cleaned up some opcode formatting.

References:
- http://wikiti.brandonw.net/?title=Z80_Instruction_Set
- http://www.z80.info/z80undoc.txt
- http://www.z80.info/z80undoc3.txt

3 years ago[cz80] Added (uint8_t) casts in a few places to silence MSVC warnings.
David Korth [Wed, 29 Apr 2015 03:07:28 +0000 (23:07 -0400)] 
[cz80] Added (uint8_t) casts in a few places to silence MSVC warnings.

OP_INC_R, OP_DEC_R: Change 'res' to uint8_t.

3 years ago[cz80] cz80jmp.inc: Added support for jump tables with offsets.
David Korth [Wed, 29 Apr 2015 03:02:22 +0000 (23:02 -0400)] 
[cz80] cz80jmp.inc: Added support for jump tables with offsets.

This helps for 64-bit and shared library builds because it uses
32-bit offsets instead of absolute addresses.

TODO: Enable on 64-bit and shared library builds. Currently, absolute
addresses are always used.

3 years ago[cz80] Improved WZ handling a bit for CPDR/CPIR.
David Korth [Sun, 26 Apr 2015 20:08:40 +0000 (16:08 -0400)] 
[cz80] Improved WZ handling a bit for CPDR/CPIR.

- Decrement/increment WZ in the loop unconditionally.
- After the loop, if BC == 0, set WZ = PC + 1.

3 years ago[cz80] Fix the CPIR and CPDR instructions on both ZEXDOC and ZEXALL.
David Korth [Sun, 26 Apr 2015 19:43:05 +0000 (15:43 -0400)] 
[cz80] Fix the CPIR and CPDR instructions on both ZEXDOC and ZEXALL.

CZ80 was checking for 'res == 0' in the main loop, but not when it
was determining to go to the next instruction or end execution.
This is now checked.

Note that we have to check CZ80_ZF instead of res, since res is
modified if CZ80_HF is set.

Thanks to flamewing in #SSRG for debugging this error.

All ZEXDOC and ZEXALL tests now pass!

TODO: Fix cycle counts. Several instructions have incorrect cycle timing.
 They need to be resynchronized with the official Z80 documentation.

3 years ago[cz80] CPD/CPI/CPDR/CPIR: Fixed the YF flag shift.
David Korth [Sun, 26 Apr 2015 18:25:11 +0000 (14:25 -0400)] 
[cz80] CPD/CPI/CPDR/CPIR: Fixed the YF flag shift.

Bit 1 is copied into the YF flag. Right-shifting the value by 4
results in YF always getting cleared.

This doesn't fix these instructions in either ZEXDOC or ZEXALL,
so there's still something wrong somewhere.

3 years ago[cz80] Change the MSVC FASTCALL check to only look for _M_IX86.
David Korth [Sun, 26 Apr 2015 17:55:37 +0000 (13:55 -0400)] 
[cz80] Change the MSVC FASTCALL check to only look for _M_IX86.

On MSVC, the macro is _M_IX86, not __i386__.

Don't bother with widl, since we're not using it, and I don't know
if that's the same macro used on MSVC or if it's just MinGW-w64.

3 years ago[cz80] Rename FASTCALL to CZ80CALL.
David Korth [Sun, 26 Apr 2015 17:50:35 +0000 (13:50 -0400)] 
[cz80] Rename FASTCALL to CZ80CALL.

This will make it easier to implement faster calling conventions
on non-Windows platforms and non-MSVC compilers.

[libgens/tests] Z80Test.cpp: Added CZ80CALL to Z80_OUTPort_static().
This somehow didn't break on Windows when compiled with MSVC, even
though it definitely should have broken.

3 years ago[cz80] cz80.inc: Changed most macros to use the do { } while (0) pattern.
David Korth [Sun, 26 Apr 2015 17:35:40 +0000 (13:35 -0400)] 
[cz80] cz80.inc: Changed most macros to use the do { } while (0) pattern.

Not included are macros that "return" a value.

Added empty parameters to macros that don't take parameters in order to
enforce function-like syntax.

3 years ago[cz80] Inlined the CB-prefix BIT, RES, and SET opcodes.
David Korth [Sun, 26 Apr 2015 16:57:14 +0000 (12:57 -0400)] 
[cz80] Inlined the CB-prefix BIT, RES, and SET opcodes.

3 years ago[cz80] Inlined the CB-prefix shift opcodes.
David Korth [Sun, 26 Apr 2015 16:08:30 +0000 (12:08 -0400)] 
[cz80] Inlined the CB-prefix shift opcodes.

3 years ago[cz80] Inlined the CB-prefix rotate opcodes.
David Korth [Sun, 26 Apr 2015 15:58:21 +0000 (11:58 -0400)] 
[cz80] Inlined the CB-prefix rotate opcodes.

NOTE: These have different flag semantics compared to the no-prefix rotate
opcodes, so we can't combine them.

3 years ago[cz80] Removed the "_FN" suffix from the 8-bit LD opcode macros.
David Korth [Sun, 26 Apr 2015 15:31:02 +0000 (11:31 -0400)] 
[cz80] Removed the "_FN" suffix from the 8-bit LD opcode macros.

I stopped using this after the 8-bit LD opcodes, and it just adds
clutter and isn't useful.

3 years ago[cz80] Inlined the IN R,(C) and OUT (C),R opcodes.
David Korth [Sun, 26 Apr 2015 15:25:18 +0000 (11:25 -0400)] 
[cz80] Inlined the IN R,(C) and OUT (C),R opcodes.

3 years ago[cz80] Inlined the 16-bit ADC and SBC opcodes.
David Korth [Sun, 26 Apr 2015 15:15:12 +0000 (11:15 -0400)] 
[cz80] Inlined the 16-bit ADC and SBC opcodes.

3 years ago[cz80] Inlined all NOP opcodes.
David Korth [Sun, 26 Apr 2015 04:08:43 +0000 (00:08 -0400)] 
[cz80] Inlined all NOP opcodes.

A macro isn't used here. Instead, RET(4) is placed after all of the
NOP opcode labels. This should save some space while not impacting
performance.

Macros are used elsewhere because while the code is mostly the same,
the registers are different, so the entire code block changes.

3 years ago[cz80] Inlined the 16-bit ADD opcodes.
David Korth [Sun, 26 Apr 2015 04:05:02 +0000 (00:05 -0400)] 
[cz80] Inlined the 16-bit ADD opcodes.

Note that the only valid destination registers for 16-bit ADD
are HL, IX, and IY.

3 years ago[cz80] Inlined the 16-bit INC and DEC opcodes.
David Korth [Sat, 25 Apr 2015 04:49:58 +0000 (00:49 -0400)] 
[cz80] Inlined the 16-bit INC and DEC opcodes.

These instuctions don't modify flags at all, so I just copied the code
from cz80_op.inc directly into cz80_opxy.inc without using macros.

3 years ago[cz80] Inlined the RST opcodes.
David Korth [Sat, 25 Apr 2015 04:46:57 +0000 (00:46 -0400)] 
[cz80] Inlined the RST opcodes.

3 years ago[cz80] Inlined the RET opcodes.
David Korth [Sat, 25 Apr 2015 04:42:57 +0000 (00:42 -0400)] 
[cz80] Inlined the RET opcodes.

3 years ago[cz80] Inlined the CALL opcodes.
David Korth [Sat, 25 Apr 2015 04:40:22 +0000 (00:40 -0400)] 
[cz80] Inlined the CALL opcodes.

3 years ago[cz80] Split the JP and JR logic into macros.
David Korth [Sat, 25 Apr 2015 04:04:09 +0000 (00:04 -0400)] 
[cz80] Split the JP and JR logic into macros.

DJNZ still uses its own code due to the slightly different timing.

3 years ago[cz80] Inlined the JP, JR, and DJNZ opcodes.
David Korth [Sat, 25 Apr 2015 03:56:05 +0000 (23:56 -0400)] 
[cz80] Inlined the JP, JR, and DJNZ opcodes.

TODO: Verify cycle timing for DJNZ if the jump isn't taken.
mdZ80 and CZ80 both have 10, but everything else says 8.
(I'm using 8 to match everything else.)

3 years ago[cz80] Inlined the AND, OR, and XOR opcodes
David Korth [Sat, 25 Apr 2015 03:23:55 +0000 (23:23 -0400)] 
[cz80] Inlined the AND, OR, and XOR opcodes

Fixed up comments for the 8-bit CP opcodes.

3 years ago[cz80] Inlined the 8-bit ADD, ADC, SUB, SBC, and CP opcodes.
David Korth [Sat, 25 Apr 2015 03:06:49 +0000 (23:06 -0400)] 
[cz80] Inlined the 8-bit ADD, ADC, SUB, SBC, and CP opcodes.

Not going to bother taking benchmarks until everything's done, since
it keeps alternating between ~70,000 ms and ~74,000 ms.

3 years ago[cz80] Inlined the PUSH and POP opcodes.
David Korth [Sat, 25 Apr 2015 02:55:37 +0000 (22:55 -0400)] 
[cz80] Inlined the PUSH and POP opcodes.

Benchmarks: (release build, gcc-4.9.2, i686)

              |   ZEXDOC   |   ZEXALL   |
--------------+------------+------------+
 cz80, before |  70,294 ms |  70,157 ms |
 cz80, after  |  74,071 ms |  73,437 ms |
--------------+------------+------------+
     % change |    5.3731% |    4.6752% |

3 years ago[cz80] Inline all 16-bit LD opcodes.
David Korth [Sat, 25 Apr 2015 02:49:38 +0000 (22:49 -0400)] 
[cz80] Inline all 16-bit LD opcodes.

This is going by cz80_op.inc. There's some 8-bit LD opcodes in
cz80_oped.inc for "special" registers that I haven't gotten to yet.

Benchmarks for inlining the 8-bit LD opcodes:

              |   ZEXDOC   |   ZEXALL   |
--------------+------------+------------+
 cz80, before |  70,294 ms |  70,157 ms |
 cz80, after  |  70,433 ms |  71,098 ms |
--------------+------------+------------+
     % change |    0.1977% |    1.3413% |

3 years ago[cz80] Inline all 8-bit LD opcodes.
David Korth [Sat, 25 Apr 2015 02:36:27 +0000 (22:36 -0400)] 
[cz80] Inline all 8-bit LD opcodes.

CZ80 extracts the operand IDs from the opcodes, which saves space;
however, it's slower. YAZE and mdZ80 both inline the code using
various methods, so we should also inline the code.

I'm using macros to inline the code with minimal coding overhead.

Benchmarks for inlining the 8-bit LD opcodes:

              |   ZEXDOC   |   ZEXALL   |
--------------+------------+------------+
 cz80, before |  74,291 ms |  75,449 ms |
 cz80, after  |  70,294 ms |  70,157 ms |
--------------+------------+------------+
     % change |   -5.3802% |    -7.014% |

I'm starting to think that maybe using Google Test's timer isn't the
best benchmarking method, since other stuff on my system might be
interfering with it, but it's the only one I have set up right now.

% change determined using:
- http://www.calculatorsoup.com/calculators/algebra/percent-change-calculator.php

3 years ago[cz80] cz80_op.inc: Update WZ in OP_LOAD_A_mxx and OP_LOAD_mxx_A.
David Korth [Sat, 25 Apr 2015 02:29:34 +0000 (22:29 -0400)] 
[cz80] cz80_op.inc: Update WZ in OP_LOAD_A_mxx and OP_LOAD_mxx_A.

3 years ago[cz80] cz80jmp.inc: Mark jump tables as const void* const.
David Korth [Sat, 25 Apr 2015 02:22:31 +0000 (22:22 -0400)] 
[cz80] cz80jmp.inc: Mark jump tables as const void* const.

Add another const for more constness!

3 years ago[libgens/tests] Z80Test: Build on non-x86 platforms.
David Korth [Sat, 25 Apr 2015 02:22:00 +0000 (22:22 -0400)] 
[libgens/tests] Z80Test: Build on non-x86 platforms.

CZ80 is cross-platform, so we should build the Z80 test suite
on all platforms so we can test it more thoroughly.

3 years ago[cz80] Implemented the WZ register.
David Korth [Sat, 25 Apr 2015 02:05:54 +0000 (22:05 -0400)] 
[cz80] Implemented the WZ register.

The WZ register is used for address calculations, and isn't usually
visible to the programmer. The one notable exception is the BIT n,(HL)
instruction, which leaks bits 3 and 5 of the high byte of WZ.

In order to properly emulate BIT n,(HL), the WZ register has to be
implemented. This obviously adds some overhead, but not much:

Benchmarks:
- cz80: Release build, gcc-4.9.2, i686

               |   ZEXDOC   |   ZEXALL   |
---------------+------------+------------+
 cz80, no WZ   |  73,623 ms |  72,976 ms |
 cz80, with WZ |  74,291 ms |  75,449 ms |
---------------+------------+------------+
      % change |    0.9073% |    3.3888% |

(I'm using an actual % change algorithm this time, instead of the
previous algorithms that were simply dividing one by another,
resulting in a ratio.)

The ZEXALL change is odd, since it's larger than ZEXDOC now.

WZ is now a register local variable, similar to PC, When it was
updated directly in the CPU struct, the performance was worse:

               |   ZEXDOC   |   ZEXALL   |
---------------+------------+------------+
 cz80, no WZ   |  73,623 ms |  72,976 ms |
 cz80, mem WZ  |  82,529 ms |  81,796 ms |
---------------+------------+------------+
      % change |   12.0968% |   12.0862% |

The following ZEXALL test now passes:
- bit n,<b,c,d,e,h,l,(hl),a>....  OK

These ZEXDOC tests still fail:
- cpd<r>........................  ERROR **** crc expected:a87e6cfa found:006b7379
- cpi<r>........................  ERROR **** crc expected:06deb356 found:2d8289a0

These ZEXALL tests still fail:
- cpd<r>........................  ERROR **** crc expected:134b622d found:a66e68d7
- cpi<r>........................  ERROR **** crc expected:2da42d19 found:47d7f28a

3 years agocmake/platform/gcc.cmake: Lots of LTO fixes.
David Korth [Fri, 24 Apr 2015 05:55:03 +0000 (01:55 -0400)] 
cmake/platform/gcc.cmake: Lots of LTO fixes.

Based on GCN MemCard Recover commit 57e0b696eb6617b3bdebeda7f8caab2c40442fc5.

Z80Test still doesn't compile with LTO enabled due to undefined references
to local labels, which doesn't make any sense.

3 years agoRemoved libz80.
David Korth [Fri, 24 Apr 2015 04:22:55 +0000 (00:22 -0400)] 
Removed libz80.

CZ80 is much faster and more accurate, plus it doesn't require an
opcode table generation step.

3 years ago[cz80] cz80_oped.inc::OP_SBC_HL: Added parentheses to fix the carry value.
David Korth [Fri, 24 Apr 2015 02:43:58 +0000 (22:43 -0400)] 
[cz80] cz80_oped.inc::OP_SBC_HL: Added parentheses to fix the carry value.

The carry value should be added to the source before it's subtracted,
not added to the resulting value.

The 8-bit SBC opcode had the parentheses, so it worked correctly;
the 16-bit version did not.

This fixes the following test in both ZEXDOC and ZEXALL:
- <adc,sbc> hl,<bc,de,hl,sp>....  OK

3 years ago[cz80] cz80.h: Use the jump table optimization when compiling with gcc.
David Korth [Fri, 24 Apr 2015 02:09:04 +0000 (22:09 -0400)] 
[cz80] cz80.h: Use the jump table optimization when compiling with gcc.

This uses computed gotos instead of switch/case.

I wouldn't have thought it would make much of a difference, since gcc
should optimize the switch/case into a jump table, but it does:

Benchmarks:
- cz80: Release build, gcc-4.9.2

                   |   ZEXDOC   |   ZEXALL   |
-------------------+------------+------------+
 cz80, switch/case |  81,940 ms |  81,975 ms |
 cz80, jumptable   |  74,028 ms |  73,709 ms |
-------------------+------------+------------+
     % of original |     90.34% |     89.92% |

3 years ago[libgens/tests] Z80Test: Use CZ80.
David Korth [Fri, 24 Apr 2015 02:01:48 +0000 (22:01 -0400)] 
[libgens/tests] Z80Test: Use CZ80.

CZ80 is much faster than libz80, and passes more tests in ZEXDOC and
ZEXALL; however, it's still slower than mdz80, and there's still a
few failing tests.

ZEXDOC tests that fail:
- <adc,sbc> hl,<bc,de,hl,sp>....  ERROR **** crc expected:f8b4eaa9 found:8a7f6eff
- cpd<r>........................  ERROR **** crc expected:a87e6cfa found:006b7379
- cpi<r>........................  ERROR **** crc expected:06deb356 found:2d8289a0

ZEXALL tests that fail:
- <adc,sbc> hl,<bc,de,hl,sp>....  ERROR **** crc expected:d48ad519 found:4f3658c4
- bit n,<b,c,d,e,h,l,(hl),a>....  ERROR **** crc expected:5e020e98 found:e6624aeb
- cpd<r>........................  ERROR **** crc expected:134b622d found:a66e68d7
- cpi<r>........................  ERROR **** crc expected:2da42d19 found:47d7f28a

Benchmarks:
- mdZ80: Debug build, though the actual code is optimized x86 asm.
- cz80: Release build, gcc-4.9.2.

        |   ZEXDOC   |   ZEXALL   |
--------+------------+------------+
  mdZ80 |  48,335 ms |  48,667 ms |
   cz80 |  81,940 ms |  81,975 ms |
--------+------------+------------+
 % diff |    169.52% |    168.44% |

Not too bad, especially considering there's no RAM optimizations
or 16-bit memory access optimizations right now.

3 years ago[cz80] cz80.h: Disable word access for now.
David Korth [Fri, 24 Apr 2015 02:01:00 +0000 (22:01 -0400)] 
[cz80] cz80.h: Disable word access for now.

I will probably re-enable it after implementing page tables for memory
access, but it gets in the way when doing basic testing.

3 years ago[cz80] Removed the default CZ80 instance.
David Korth [Fri, 24 Apr 2015 01:36:34 +0000 (21:36 -0400)] 
[cz80] Removed the default CZ80 instance.

We're going to define our own CZ80 instance, so there's no need to
reserve memory for a default instance.

3 years ago[cz80] Initial import of CZ80, a Z80 emulator written by Stephane Dallongeville.
David Korth [Fri, 24 Apr 2015 01:33:17 +0000 (21:33 -0400)] 
[cz80] Initial import of CZ80, a Z80 emulator written by Stephane Dallongeville.

Yes, that's the original Gens author.

This version of CZ80 is from dgen-sdl-1.33, and appears to be mostly
unchanged from the original.

3 years ago[libz80] z80.c: Moved #include <stdio.h> from z80.h to z80.c.
David Korth [Wed, 22 Apr 2015 01:20:52 +0000 (21:20 -0400)] 
[libz80] z80.c: Moved #include <stdio.h> from z80.h to z80.c.

It's not needed in z80.h.

It's used in z80.c for the debugging functions.

TODO: Use snprintf() in the debugging functions instead of sprintf().

3 years ago[libgens/test] Z80Test: Updated to use libz80.
David Korth [Wed, 22 Apr 2015 01:06:58 +0000 (21:06 -0400)] 
[libgens/test] Z80Test: Updated to use libz80.

libz80 seems to be significantly slower than mdZ80, probably due to the
use of function pointers instead of jump tables. On the flip side, most
of the tests pass with libz80, whereas all of the tests fail in mdZ80.

ZEXDOC tests that fail:
- aluop a,nn....................  ERROR **** crc expected:48799360 found:ff768382
- aluop a,<b,c,d,e,h,l,(hl),a>..  ERROR **** crc expected:fe43b016 found:a0112033
- aluop a,<ixh,ixl,iyh,iyl>.....  ERROR **** crc expected:a4026d5a found:50da5b30
- aluop a,(<ix,iy>+1)...........  ERROR **** crc expected:e849676e found:d2676fe8
- <daa,cpl,scf,ccf>.............  ERROR **** crc expected:9b4ba675 found:31255bf5
- ld <bcdexya>,<bcdexya>........  ERROR **** crc expected:478ba36b found:8088c9d9

ZEXALL tests that fail:
- aluop a,nn....................  ERROR **** crc expected:51c19c2e found:e6ce8ccc
- aluop a,<b,c,d,e,h,l,(hl),a>..  ERROR **** crc expected:06c7aa8e found:58953aab
- aluop a,<ixh,ixl,iyh,iyl>.....  ERROR **** crc expected:a886cc44 found:5c5efa2e
- aluop a,(<ix,iy>+1)...........  ERROR **** crc expected:d3f2d74a found:e9dcdfcc
- bit n,<b,c,d,e,h,l,(hl),a>....  ERROR **** crc expected:5e020e98 found:fe7d580c
- cpi<r>........................  ERROR **** crc expected:2da42d19 found:6602a286
- <daa,cpl,scf,ccf>.............  ERROR **** crc expected:6d2dd213 found:c7432f93
- ld <bcdexya>,<bcdexya>........  ERROR **** crc expected:478ba36b found:8088c9d9
- <rrd,rld>.....................  ERROR **** crc expected:ff823e77 found:2201b2c4

Benchmarks:
- mdZ80: Debug build, though the actual code is optimized x86 asm.
- libz80: Release build, gcc-4.9.2.

          |   ZEXDOC   |   ZEXALL   |
----------+------------+------------+
    mdZ80 |  48,335 ms |  48,667 ms |
   libz80 | 226,966 ms | 227,679 ms |
----------+------------+------------+
 Slowdown |      4.70x |      4.68x |

This will definitely need some optimization in order to be usable.
Among other things, getting rid of function pointers and using
inline functions in switch/case should help.

3 years ago.gitignore: Also commit this, not just the Makefiles.
David Korth [Wed, 22 Apr 2015 01:06:33 +0000 (21:06 -0400)] 
.gitignore: Also commit this, not just the Makefiles.

3 years ago[libz80] z80.h: Added extern "C" for C++ compatibility.
David Korth [Wed, 22 Apr 2015 00:57:42 +0000 (20:57 -0400)] 
[libz80] z80.h: Added extern "C" for C++ compatibility.

Added "LIBZ80" to the include guard.

3 years ago[libgens] libz80: Added the original Makefiles.
David Korth [Wed, 22 Apr 2015 00:49:42 +0000 (20:49 -0400)] 
[libgens] libz80: Added the original Makefiles.

Makefile and Makefile.in were present in .gitignore, since they were
generated by autoconf/automake, which were used in Gens/GS. Remove
them from .gitignore so we can add in libz80's original Makefiles.

3 years ago[libgens/tests] Z80Test/CMakeLists.txt: Removed Z80/ from the source code filename.
David Korth [Wed, 22 Apr 2015 00:34:13 +0000 (20:34 -0400)] 
[libgens/tests] Z80Test/CMakeLists.txt: Removed Z80/ from the source code filename.

No more subdirectories here!

3 years ago[libgens/tests] Z80Test: Renamed bdos to bios.
David Korth [Wed, 22 Apr 2015 00:33:17 +0000 (20:33 -0400)] 
[libgens/tests] Z80Test: Renamed bdos to bios.

No disk functionality is implemented here. Only some very basic
BIOS functionality is present.

3 years ago[libgens/tests] Renamed Z80Tests to Z80Test, and created its own CMakeLists.txt file.
David Korth [Wed, 22 Apr 2015 00:31:34 +0000 (20:31 -0400)] 
[libgens/tests] Renamed Z80Tests to Z80Test, and created its own CMakeLists.txt file.

3 years ago[libz80] fuse_tests/CMakeLists.txt: Added CTest handlers for libz80's included tests.
David Korth [Wed, 22 Apr 2015 00:28:03 +0000 (20:28 -0400)] 
[libz80] fuse_tests/CMakeLists.txt: Added CTest handlers for libz80's included tests.

These tests are based on tests included with FUSE.
(Free Unix Spectrum Emulator)

All tests pass. :)

3 years ago[libz80] fuse_tests/coretest: Removed a precompiled version of coretest.
David Korth [Wed, 22 Apr 2015 00:10:35 +0000 (20:10 -0400)] 
[libz80] fuse_tests/coretest: Removed a precompiled version of coretest.

It depends on libz80.so being a static library, and we should compile
the test ourselves.

3 years ago[libz80] z80.c::parityBit[]: Marked as const; reduced from int to byte.
David Korth [Wed, 22 Apr 2015 00:09:03 +0000 (20:09 -0400)] 
[libz80] z80.c::parityBit[]: Marked as const; reduced from int to byte.

Each entry is either 0 or 1, so we don't need to waste a whole int
for each bit. (Using a bitfield would reduce the table to 32 bytes,
but would require more instructions to make use of it.)

3 years ago[libz80] mktables.c: Marked generated tables as const.
David Korth [Wed, 22 Apr 2015 00:08:21 +0000 (20:08 -0400)] 
[libz80] mktables.c: Marked generated tables as const.

There's no reason for these tables to be modifyable at runtime.

z80.c: Updated for const tables.

3 years ago[libz80] mktables.c: #include <ctype.h>
David Korth [Wed, 22 Apr 2015 00:05:05 +0000 (20:05 -0400)] 
[libz80] mktables.c: #include <ctype.h>

Changed all system includes to angle brackets instead of double-quotes.

3 years ago[libz80] CMakeLists.txt: Removed some copypasta from starscream's CMakeLists.txt.
David Korth [Wed, 22 Apr 2015 00:03:37 +0000 (20:03 -0400)] 
[libz80] CMakeLists.txt: Removed some copypasta from starscream's CMakeLists.txt.

3 years ago[libz80] CMakeLists.txt: Initial CMakeLists file.
David Korth [Wed, 22 Apr 2015 00:02:53 +0000 (20:02 -0400)] 
[libz80] CMakeLists.txt: Initial CMakeLists file.

The Z80 opcode tables are generated, and libz80.a is built.

TODO:
- Include a copy of glibc's POSIX regex code for systems that
  don't have <regex.h>, i.e. MSVC.
- Generate opcodes_decl.h in mktables instead of using grep and sed.

3 years ago[libz80] Initial import of libz80 into libgens.
David Korth [Tue, 21 Apr 2015 23:36:06 +0000 (19:36 -0400)] 
[libz80] Initial import of libz80 into libgens.

libz80 is a GPL-licensed Z80 emulator written in C. It's more accurate and
supports more undocumented Z80 functionality than the old Gens Z80 code.

This is only an initial import. The code doesn't build yet, since I need
to write CMake rules to build and run the opcode table generator.

3 years agoMerge branch 'bugfix/2016-03-28.fix-compatibility' github/master
David Korth [Mon, 4 Apr 2016 15:55:53 +0000 (11:55 -0400)] 
Merge branch 'bugfix/2016-03-28.fix-compatibility'

Fixes compatibility issues with a few ROMs:
- Alien Soldier: mdZ80 error, non-standard checksum
- Alien Storm: mdZ80 error (same as Alien Soldier)
- World Series Baseball: activated 240-line mode due to an incorrect VDP mode check
- Bubba 'N' Stix: Broken menus and blackscreen due to an incorrect DMA enable check
- Cadash: Non-standard checksum

Auto-fix checksum has been disabled by default, since it seems to cause
more problems than it helps fix nowadays.

gens-qt4: Fixed the initial region code setting and PAL mode.

gens-sdl: Added command line options to set the region code, plus
auto-detection. (Auto-detection order is hard-coded to 0x4812 for now.)

Various cppcheck fixes.

3 years ago[libzomg] Metadata_ogc.cpp: Added Wii System Menu versions 544, 545, and 546. bugfix/2016-03-28.fix-compatibility github/bugfix/2016-03-28.fix-compatibility
David Korth [Sun, 3 Apr 2016 05:42:55 +0000 (01:42 -0400)] 
[libzomg] Metadata_ogc.cpp: Added Wii System Menu versions 544, 545, and 546.

The first scan these versions show up in is Wii U firmware version 4.0.0,
and they were replaced by 608/609/610 in firmware version 5.2.0.

Reference: https://yls8.mtheall.com/ninupdates/reports.php

3 years ago[libzomg] Metadata_win32.cpp::getUserName_ansi(): Only check for NULLs if cbUsername...
David Korth [Sun, 3 Apr 2016 05:35:53 +0000 (01:35 -0400)] 
[libzomg] Metadata_win32.cpp::getUserName_ansi(): Only check for NULLs if cbUsername > 0.

Found using cppcheck-1.72.

3 years ago[gens-sdl] Fixed a few errors found with cppcheck-1.72.
David Korth [Sun, 3 Apr 2016 05:31:29 +0000 (01:31 -0400)] 
[gens-sdl] Fixed a few errors found with cppcheck-1.72.

EmuLoopPrivate: Removed 'frameskip'. This variable was already
defined in EventLoopPrivate.

VBackend: Initialize m_forceFbDirty to true.

3 years ago[gens-sdl] EmuLoop::run(): Added support for ROM region auto-detection.
David Korth [Sun, 3 Apr 2016 02:29:52 +0000 (22:29 -0400)] 
[gens-sdl] EmuLoop::run(): Added support for ROM region auto-detection.

Currently always uses the 0x4812 detection order. (US, Europe, Japan, Asia)

Options.cpp: Added a region code "auto". This is now the default.

3 years ago[libgens] Moved auto-detect code from gens-qt4 to SysVersion.
David Korth [Sun, 3 Apr 2016 02:17:14 +0000 (22:17 -0400)] 
[libgens] Moved auto-detect code from gens-qt4 to SysVersion.

This will allow the auto-detect code to be reused by gens-sdl.

[gens-qt4] EmuManager.cpp:
- TODO: Remove GetLgRegionCode().

3 years ago[libgens] macros/common.h: ARRAY_SIZE(): Use (int) casts, not (size_t) casts.
David Korth [Sun, 3 Apr 2016 02:13:34 +0000 (22:13 -0400)] 
[libgens] macros/common.h: ARRAY_SIZE(): Use (int) casts, not (size_t) casts.

Fixes an issue where size_t isn't available in SysVersion.cpp, which will
be added in the next commit.

Also, it should be (int) anyway, since the first part was already (int).

3 years ago[gens-sdl] Options: Added a '--region' option.
David Korth [Sun, 3 Apr 2016 01:50:42 +0000 (21:50 -0400)] 
[gens-sdl] Options: Added a '--region' option.

Currently does not support auto-detection.

EmuLoop.cpp: Use the region specified on the command line.

This allows gens-sdl to run ROMs in PAL.