refactoring and small tweaks in cpu

This commit is contained in:
Sergio Martin 2024-01-19 21:14:18 +01:00
parent 58bc38688e
commit b970262005
34 changed files with 58 additions and 60 deletions

View File

@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#include "audio/apu.h" #include "apu/apu.h"
#include "Nes_Cpu.h" #include "Nes_Cpu.h"
#include "Nes_Ppu.h" #include "Nes_Ppu.h"
#include "mappers/mapper.h" #include "mappers/mapper.h"

View File

@ -118,11 +118,10 @@ imm##op: \
{ \ { \
pc++; \ pc++; \
int offset = (int8_t) data; \ int offset = (int8_t) data; \
int extra_clock = (pc & 0xFF) + offset; \
if ( !(cond) ) {clock_count--; goto loop; } \ if ( !(cond) ) {clock_count--; goto loop; } \
pc += offset; \ pc += offset; \
pc = uint16_t( pc ); \ pc = uint16_t( pc ); \
clock_count += (extra_clock >> 8) & 1; \ clock_count += (((pc & 0xFF) + offset) >> 8) & 1; \
goto loop; \ goto loop; \
} }
@ -198,27 +197,7 @@ inline void Nes_Cpu::write( nes_addr_t addr, int value )
} }
// status flags // status flags
extern uint8_t clock_table [256];
constexpr uint8_t clock_table [256] = {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
7,6,2,8,3,3,5,5,3,2,2,2,4,4,6,6,// 0
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 1
6,6,2,8,3,3,5,5,4,2,2,2,4,4,6,6,// 2
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 3
6,6,2,8,3,3,5,5,3,2,2,2,3,4,6,6,// 4
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 5
6,6,2,8,3,3,5,5,4,2,2,2,5,4,6,6,// 6
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 7
2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,// 8
3,6,2,6,4,4,4,4,2,5,2,5,5,5,5,5,// 9
2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,// A
3,5,2,5,4,4,4,4,2,4,2,4,4,4,4,4,// B
2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,// C
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// D
2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,// E
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7 // F
};
__attribute__((optimize("align-functions=" _PAGE_SIZE))) __attribute__((optimize("align-functions=" _PAGE_SIZE)))
Nes_Cpu::result_t Nes_Cpu::run ( nes_time_t end ) Nes_Cpu::result_t Nes_Cpu::run ( nes_time_t end )
@ -1166,3 +1145,23 @@ end:
return result; return result;
} }
uint8_t clock_table [256] = {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
7,6,2,8,3,3,5,5,3,2,2,2,4,4,6,6,// 0
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 1
6,6,2,8,3,3,5,5,4,2,2,2,4,4,6,6,// 2
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 3
6,6,2,8,3,3,5,5,3,2,2,2,3,4,6,6,// 4
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 5
6,6,2,8,3,3,5,5,4,2,2,2,5,4,6,6,// 6
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 7
2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,// 8
3,6,2,6,4,4,4,4,2,5,2,5,5,5,5,5,// 9
2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,// A
3,5,2,5,4,4,4,4,2,4,2,4,4,4,4,4,// B
2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,// C
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// D
2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,// E
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7 // F
};

View File

@ -4,7 +4,7 @@
// Nes_Emu 0.7.0 // Nes_Emu 0.7.0
#include "audio/Multi_Buffer.h" #include "apu/Multi_Buffer.h"
#include "Nes_Cart.h" #include "Nes_Cart.h"
#include "Nes_Core.h" #include "Nes_Core.h"

View File

@ -1,7 +1,7 @@
// Nes_Emu 0.7.0. http://www.slack.net/~ant/libs/ // Nes_Emu 0.7.0. http://www.slack.net/~ant/libs/
#include "audio/Nes_Buffer.h" #include "apu/Nes_Buffer.h"
#include "audio/apu.h" #include "apu/apu.h"
/* Library Copyright (C) 2003-2006 Shay Green. This library is free software; /* Library Copyright (C) 2003-2006 Shay Green. This library is free software;
you can redistribute it and/or modify it under the terms of the GNU Lesser you can redistribute it and/or modify it under the terms of the GNU Lesser

View File

@ -1,8 +1,8 @@
// Nes_Emu 0.7.0. http://www.slack.net/~ant/libs/ // Nes_Emu 0.7.0. http://www.slack.net/~ant/libs/
#include "audio/Nes_Effects_Buffer.h" #include "apu/Nes_Effects_Buffer.h"
#include "audio/apu.h" #include "apu/apu.h"
/* Copyright (C) 2004-2006 Shay Green. This module is free software; you /* Copyright (C) 2004-2006 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser can redistribute it and/or modify it under the terms of the GNU Lesser

View File

@ -1,7 +1,7 @@
// Nes_Emu 0.7.0. http://www.slack.net/~ant/ // Nes_Emu 0.7.0. http://www.slack.net/~ant/
#include "audio/fme7/apu.h" #include "apu/fme7/apu.h"
#include <cstring> #include <cstring>
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you /* Copyright (C) 2003-2006 Shay Green. This module is free software; you

View File

@ -4,7 +4,7 @@
// Nes_Emu 0.7.0 // Nes_Emu 0.7.0
#include <cstdint> #include <cstdint>
#include "audio/Blip_Buffer.h" #include "apu/Blip_Buffer.h"
struct fme7_apu_state_t struct fme7_apu_state_t
{ {

View File

@ -1,8 +1,8 @@
// Nes_Snd_Emu 0.1.7. http://www.slack.net/~ant/ // Nes_Snd_Emu 0.1.7. http://www.slack.net/~ant/
#include "audio/Blip_Buffer.h" #include "apu/Blip_Buffer.h"
#include "audio/namco/apu.h" #include "apu/namco/apu.h"
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you /* Copyright (C) 2003-2006 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser can redistribute it and/or modify it under the terms of the GNU Lesser

View File

@ -4,7 +4,7 @@
// Nes_Snd_Emu 0.1.7 // Nes_Snd_Emu 0.1.7
#include <cstdint> #include <cstdint>
#include "audio/apu.h" #include "apu/apu.h"
struct namco_state_t struct namco_state_t
{ {

View File

@ -1,7 +1,7 @@
// Nes_Snd_Emu 0.1.7. http://www.slack.net/~ant/ // Nes_Snd_Emu 0.1.7. http://www.slack.net/~ant/
#include "audio/vrc6/apu.h" #include "apu/vrc6/apu.h"
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you /* Copyright (C) 2003-2006 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser can redistribute it and/or modify it under the terms of the GNU Lesser

View File

@ -5,8 +5,8 @@
// Nes_Snd_Emu 0.1.7 // Nes_Snd_Emu 0.1.7
#include <cstdint> #include <cstdint>
#include "audio/apu.h" #include "apu/apu.h"
#include "audio/Blip_Buffer.h" #include "apu/Blip_Buffer.h"
struct vrc6_apu_state_t; struct vrc6_apu_state_t;

View File

@ -1,5 +1,5 @@
#include "audio/vrc7/apu.h" #include "apu/vrc7/apu.h"
#include "audio/vrc7/emu2413.h" #include "apu/vrc7/emu2413.h"
#include <cstring> #include <cstring>
#define BYTESWAP(xxxx) {uint32_t _temp = (uint32_t)(xxxx);\ #define BYTESWAP(xxxx) {uint32_t _temp = (uint32_t)(xxxx);\

View File

@ -5,8 +5,8 @@
// Nes_Snd_Emu 0.1.7. Copyright (C) 2003-2005 Shay Green. GNU LGPL license. // Nes_Snd_Emu 0.1.7. Copyright (C) 2003-2005 Shay Green. GNU LGPL license.
#include <cstdint> #include <cstdint>
#include "audio/vrc7/emu2413_state.h" #include "apu/vrc7/emu2413_state.h"
#include "audio/Blip_Buffer.h" #include "apu/Blip_Buffer.h"
struct vrc7_snapshot_t; struct vrc7_snapshot_t;
typedef long nes_time_t; typedef long nes_time_t;

View File

@ -5,7 +5,7 @@
// Nes_Emu 0.7.0. http://www.slack.net/~ant/ // Nes_Emu 0.7.0. http://www.slack.net/~ant/
#include "mappers/mapper.h" #include "mappers/mapper.h"
#include "audio/namco/apu.h" #include "apu/namco/apu.h"
/* Copyright (C) 2004-2006 Shay Green. This module is free software; you /* Copyright (C) 2004-2006 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser can redistribute it and/or modify it under the terms of the GNU Lesser

View File

@ -3,10 +3,9 @@
// Konami VRC6 mapper // Konami VRC6 mapper
// Nes_Emu 0.7.0. http://www.slack.net/~ant/ // Nes_Emu 0.7.0. http://www.slack.net/~ant/
#include <cstring>
#include "mappers/mapper.h" #include "mappers/mapper.h"
#include "apu/vrc6/apu.h"
#include <string.h>
#include "audio/vrc6/apu.h"
/* Copyright (C) 2004-2006 Shay Green. This module is free software; you /* Copyright (C) 2004-2006 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser can redistribute it and/or modify it under the terms of the GNU Lesser

View File

@ -5,7 +5,7 @@
// Nes_Emu 0.7.0. http://www.slack.net/~ant/libs/ // Nes_Emu 0.7.0. http://www.slack.net/~ant/libs/
#include "mappers/mapper.h" #include "mappers/mapper.h"
#include "audio/fme7/apu.h" #include "apu/fme7/apu.h"
/* Copyright (C) 2005 Chris Moeller */ /* Copyright (C) 2005 Chris Moeller */
/* Copyright (C) 2005-2006 Shay Green. This module is free software; you /* Copyright (C) 2005-2006 Shay Green. This module is free software; you

View File

@ -4,7 +4,7 @@
#include <cstring> #include <cstring>
#include "mappers/mapper.h" #include "mappers/mapper.h"
#include "audio/vrc7/apu.h" #include "apu/vrc7/apu.h"
/* Copyright (C) 2004-2005 Shay Green. This module is free software; you /* Copyright (C) 2004-2005 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser can redistribute it and/or modify it under the terms of the GNU Lesser

View File

@ -1,19 +1,19 @@
# quickerNES Core sources # quickerNES Core sources
quickerNESAudioSrc = [ quickerNESAudioSrc = [
'audio/apu.cpp', 'apu/apu.cpp',
'audio/Nes_Oscs.cpp', 'apu/Nes_Oscs.cpp',
'audio/Nes_Buffer.cpp', 'apu/Nes_Buffer.cpp',
'audio/Blip_Buffer.cpp', 'apu/Blip_Buffer.cpp',
'audio/Effects_Buffer.cpp', 'apu/Effects_Buffer.cpp',
'audio/Nes_Effects_Buffer.cpp', 'apu/Nes_Effects_Buffer.cpp',
'audio/Multi_Buffer.cpp', 'apu/Multi_Buffer.cpp',
'audio/namco/apu.cpp', 'apu/namco/apu.cpp',
'audio/vrc6/apu.cpp', 'apu/vrc6/apu.cpp',
'audio/vrc7/emu2413.cpp', 'apu/vrc7/emu2413.cpp',
'audio/vrc7/emu2413_state.cpp', 'apu/vrc7/emu2413_state.cpp',
'audio/vrc7/apu.cpp', 'apu/vrc7/apu.cpp',
'audio/fme7/apu.cpp', 'apu/fme7/apu.cpp',
] ]
quickerNESSrc = quickerNESAudioSrc + [ quickerNESSrc = quickerNESAudioSrc + [