Skip to content

Commit

Permalink
updated Musashi code base to 2158f7081001f89145283d291ee501321e8dc26d…
Browse files Browse the repository at this point in the history
… from 2024-02-08
  • Loading branch information
cnvogelg committed Feb 18, 2024
1 parent 9b2f615 commit 49dd1cc
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 63 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [0.2.0][1] (2024-02-18)

* Updated musashi code base to 2158f7081001f89145283d291ee501321e8dc26d
from (2024-02-08)

## [0.1.0][1] (2023-12-31)

* First public release
Expand Down
14 changes: 12 additions & 2 deletions src/musashi/m68k.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,22 @@ void m68k_set_fc_callback(void (*callback)(unsigned int new_fc));
*/
void m68k_set_instr_hook_callback(void (*callback)(unsigned int pc));

/* CV: operation done after aline callback */
/* Operation done after aline callback.
* Normal behaviour is triggering a CPU exception.
* If you use the aline hook for own emulator traps
* then you can decide to do nothing in CPU emulation
* or perform an automatic RTS instruction afterwards.
*/
#define M68K_ALINE_NONE 0
#define M68K_ALINE_EXCEPT 1
#define M68K_ALINE_RTS 2

/* CV: call callback with (opcode, pc) */
/* Set the aline callback. It will be executed every
* time an 0xaxxx opcode is encountered. Parameters are
* (opcode, current_pc). The return value is one of
* M68K_ALINE_* (see above).
* Default behaviour: CPU exception.
*/
void m68k_set_aline_hook_callback(int (*callback)(unsigned int, unsigned int));

/* ======================================================================== */
Expand Down
124 changes: 91 additions & 33 deletions src/musashi/m68k_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ void m68ki_build_opcode_table(void)
m68ki_instruction_jump_table[instr] = ostruct->opcode_handler;
for(k=0;k<NUM_CPU_TYPES;k++)
m68ki_cycles[k][instr] = ostruct->cycles[k];
/* SBF: don't add it here or the costs are added twice!
// For all shift operations with known shift distance (encoded in instruction word)
if((instr & 0xf000) == 0xe000 && (!(instr & 0x20)))
{
Expand All @@ -226,6 +227,7 @@ void m68ki_build_opcode_table(void)
// On the 68020 shift distance does not affect execution time
m68ki_cycles[2][instr] += 0;
}
*/
}
}
ostruct++;
Expand Down Expand Up @@ -719,10 +721,10 @@ moves 8 . . 0000111000...... A+-DXWL... . S S S S . 14 5
moves 16 . . 0000111001...... A+-DXWL... . S S S S . 14 5 5 5
moves 32 . . 0000111010...... A+-DXWL... . S S S S . 16 5 5 5
move16 32 . . 1111011000100... .......... . . . . U . . . . 4 TODO: correct timing
muls 16 . d 1100...111000... .......... U U U U U 54 32 27 27 27
muls 16 . . 1100...111...... A+-DXWLdxI U U U U U 54 32 27 27 27
mulu 16 . d 1100...011000... .......... U U U U U 54 30 27 27 27
mulu 16 . . 1100...011...... A+-DXWLdxI U U U U U 54 30 27 27 27
muls 16 . d 1100...111000... .......... U U U U U 38 32 27 27 27
muls 16 . . 1100...111...... A+-DXWLdxI U U U U U 38 32 27 27 27
mulu 16 . d 1100...011000... .......... U U U U U 38 30 27 27 27
mulu 16 . . 1100...011...... A+-DXWLdxI U U U U U 38 30 27 27 27
mull 32 . d 0100110000000... .......... . . U U U . . 43 43 43
mull 32 . . 0100110000...... A+-DXWLdxI . . U U U . . 43 43 43
nbcd 8 . d 0100100000000... .......... U U U U U 6 6 6 6 6
Expand Down Expand Up @@ -1866,7 +1868,7 @@ M68KMAKE_OP(asr, 8, s, .)
uint src = MASK_OUT_ABOVE_8(*r_dst);
uint res = src >> shift;

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(GET_MSB_8(src))
Expand All @@ -1888,7 +1890,7 @@ M68KMAKE_OP(asr, 16, s, .)
uint src = MASK_OUT_ABOVE_16(*r_dst);
uint res = src >> shift;

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(GET_MSB_16(src))
Expand All @@ -1910,7 +1912,7 @@ M68KMAKE_OP(asr, 32, s, .)
uint src = *r_dst;
uint res = src >> shift;

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(GET_MSB_32(src))
Expand All @@ -1932,9 +1934,10 @@ M68KMAKE_OP(asr, 8, r, .)
uint src = MASK_OUT_ABOVE_8(*r_dst);
uint res = src >> shift;

if(shift != 0)
if(shift != 0 )
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift < 8)
{
Expand Down Expand Up @@ -1986,7 +1989,8 @@ M68KMAKE_OP(asr, 16, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift < 16)
{
Expand Down Expand Up @@ -2038,7 +2042,8 @@ M68KMAKE_OP(asr, 32, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift < 32)
{
Expand Down Expand Up @@ -2106,7 +2111,7 @@ M68KMAKE_OP(asl, 8, s, .)
uint src = MASK_OUT_ABOVE_8(*r_dst);
uint res = MASK_OUT_ABOVE_8(src << shift);

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
Expand All @@ -2126,7 +2131,7 @@ M68KMAKE_OP(asl, 16, s, .)
uint src = MASK_OUT_ABOVE_16(*r_dst);
uint res = MASK_OUT_ABOVE_16(src << shift);

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
Expand All @@ -2146,7 +2151,7 @@ M68KMAKE_OP(asl, 32, s, .)
uint src = *r_dst;
uint res = MASK_OUT_ABOVE_32(src << shift);

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

*r_dst = res;
Expand All @@ -2168,7 +2173,8 @@ M68KMAKE_OP(asl, 8, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift < 8)
{
Expand Down Expand Up @@ -2205,7 +2211,8 @@ M68KMAKE_OP(asl, 16, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift < 16)
{
Expand Down Expand Up @@ -2242,7 +2249,8 @@ M68KMAKE_OP(asl, 32, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift < 32)
{
Expand Down Expand Up @@ -5300,7 +5308,7 @@ M68KMAKE_OP(lsr, 8, s, .)
uint src = MASK_OUT_ABOVE_8(*r_dst);
uint res = src >> shift;

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
Expand All @@ -5319,7 +5327,7 @@ M68KMAKE_OP(lsr, 16, s, .)
uint src = MASK_OUT_ABOVE_16(*r_dst);
uint res = src >> shift;

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
Expand All @@ -5338,7 +5346,7 @@ M68KMAKE_OP(lsr, 32, s, .)
uint src = *r_dst;
uint res = src >> shift;

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

*r_dst = res;
Expand All @@ -5359,7 +5367,8 @@ M68KMAKE_OP(lsr, 8, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift <= 8)
{
Expand Down Expand Up @@ -5396,7 +5405,8 @@ M68KMAKE_OP(lsr, 16, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift <= 16)
{
Expand Down Expand Up @@ -5433,7 +5443,8 @@ M68KMAKE_OP(lsr, 32, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift < 32)
{
Expand Down Expand Up @@ -5482,7 +5493,7 @@ M68KMAKE_OP(lsl, 8, s, .)
uint src = MASK_OUT_ABOVE_8(*r_dst);
uint res = MASK_OUT_ABOVE_8(src << shift);

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

*r_dst = MASK_OUT_BELOW_8(*r_dst) | res;
Expand All @@ -5501,7 +5512,7 @@ M68KMAKE_OP(lsl, 16, s, .)
uint src = MASK_OUT_ABOVE_16(*r_dst);
uint res = MASK_OUT_ABOVE_16(src << shift);

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

*r_dst = MASK_OUT_BELOW_16(*r_dst) | res;
Expand All @@ -5520,7 +5531,7 @@ M68KMAKE_OP(lsl, 32, s, .)
uint src = *r_dst;
uint res = MASK_OUT_ABOVE_32(src << shift);

if(shift != 0)
if(shift != 0 && CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

*r_dst = res;
Expand All @@ -5541,7 +5552,8 @@ M68KMAKE_OP(lsl, 8, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift <= 8)
{
Expand Down Expand Up @@ -5578,7 +5590,8 @@ M68KMAKE_OP(lsl, 16, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift <= 16)
{
Expand Down Expand Up @@ -5615,7 +5628,8 @@ M68KMAKE_OP(lsl, 32, r, .)

if(shift != 0)
{
USE_CYCLES(shift<<CYC_SHIFT);
if (CPU_TYPE_IS_010_LESS(CPU_TYPE))
USE_CYCLES(shift<<CYC_SHIFT);

if(shift < 32)
{
Expand Down Expand Up @@ -7440,7 +7454,19 @@ M68KMAKE_OP(move16, 32, ., .)
M68KMAKE_OP(muls, 16, ., d)
{
uint* r_dst = &DX;
uint res = MASK_OUT_ABOVE_32(MAKE_INT_16(DY) * MAKE_INT_16(MASK_OUT_ABOVE_16(*r_dst)));
uint x = MAKE_INT_16(DY);
if(CPU_TYPE_IS_010_LESS(CPU_TYPE)) {
uint c = 0;
for (uint y = x, f = 0; y; y>>=1) {
if ((y&1) != f) {
c += 2;
f = 1 - f;
}
}
USE_CYCLES(c);
}

uint res = MASK_OUT_ABOVE_32(x * MAKE_INT_16(MASK_OUT_ABOVE_16(*r_dst)));

*r_dst = res;

Expand All @@ -7454,7 +7480,18 @@ M68KMAKE_OP(muls, 16, ., d)
M68KMAKE_OP(muls, 16, ., .)
{
uint* r_dst = &DX;
uint res = MASK_OUT_ABOVE_32(MAKE_INT_16(M68KMAKE_GET_OPER_AY_16) * MAKE_INT_16(MASK_OUT_ABOVE_16(*r_dst)));
uint x = MAKE_INT_16(M68KMAKE_GET_OPER_AY_16);
if(CPU_TYPE_IS_010_LESS(CPU_TYPE)) {
uint c = 0;
for (uint y = x, f = 0; y; y>>=1) {
if ((y&1) != f) {
c += 2;
f = 1 - f;
}
}
USE_CYCLES(c);
}
uint res = MASK_OUT_ABOVE_32(x * MAKE_INT_16(MASK_OUT_ABOVE_16(*r_dst)));

*r_dst = res;

Expand All @@ -7468,7 +7505,17 @@ M68KMAKE_OP(muls, 16, ., .)
M68KMAKE_OP(mulu, 16, ., d)
{
uint* r_dst = &DX;
uint res = MASK_OUT_ABOVE_16(DY) * MASK_OUT_ABOVE_16(*r_dst);
uint x = MASK_OUT_ABOVE_16(DY);
if(CPU_TYPE_IS_010_LESS(CPU_TYPE)) {
uint c = 0;
for (uint y = x; y; y>>=1) {
if ((y&1)) {
c += 2;
}
}
USE_CYCLES(c);
}
uint res = x * MASK_OUT_ABOVE_16(*r_dst);

*r_dst = res;

Expand All @@ -7482,7 +7529,18 @@ M68KMAKE_OP(mulu, 16, ., d)
M68KMAKE_OP(mulu, 16, ., .)
{
uint* r_dst = &DX;
uint res = M68KMAKE_GET_OPER_AY_16 * MASK_OUT_ABOVE_16(*r_dst);
uint x = M68KMAKE_GET_OPER_AY_16;
if(CPU_TYPE_IS_010_LESS(CPU_TYPE)) {
uint c = 0;
for (uint y = x; y; y>>=1) {
if ((y&1)) {
c += 2;
}
}
USE_CYCLES(c);
}

uint res = x * MASK_OUT_ABOVE_16(*r_dst);

*r_dst = res;

Expand Down
Loading

0 comments on commit 49dd1cc

Please sign in to comment.