Skip to content

Commit e873ff7

Browse files
committed
Improve timing
1 parent beda965 commit e873ff7

File tree

17 files changed

+335
-186
lines changed

17 files changed

+335
-186
lines changed

platforms/shared/desktop/mcp/mcp_debug_adapter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void DebugAdapter::ClearBreakpointByAddress(u16 address, u16 end_address)
148148
{
149149
M6502::GLYNX_Breakpoint& bp = (*breakpoints)[i];
150150

151-
if (end_address > 0 && end_address > address)
151+
if (end_address > 0 && end_address >= address)
152152
{
153153
if (bp.range && bp.address1 == address && bp.address2 == end_address)
154154
breakpoints->erase(breakpoints->begin() + i);
@@ -613,6 +613,10 @@ json DebugAdapter::Get6502Status()
613613
// CPU IRQ line status
614614
status["IRQ_line_asserted"] = cpu->irq_asserted;
615615

616+
// Last instruction ticks
617+
status["last_ticks"] = cpu->last_ticks;
618+
status["total_ticks"] = cpu->total_ticks;
619+
616620
return status;
617621
}
618622

src/bus.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class Bus
3636
u32 m_cycles;
3737
};
3838

39-
static const u32 k_bus_cycles_suzy_read = 7; // Suzy register read (9-15 ticks, base 5 + 4-10 extra)
40-
static const u32 k_bus_cycles_suzy_write = 0; // Suzy register write (blind write, 5 ticks)
39+
static const u32 k_bus_cycles_suzy_read = 3; // Suzy register read
40+
static const u32 k_bus_cycles_suzy_write = 0; // Suzy register write
4141
static const u32 k_bus_cycles_cart_read = 3; // Cart read
4242
static const u32 k_bus_cycles_mikey_read = 0; // Mikey register read
4343
static const u32 k_bus_cycles_mikey_write = 0; // Mikey register write
4444
static const u32 k_bus_cycles_int_tick_factor = 5; // Internal CPU cycle to tick scaling
45-
static const u32 k_bus_cycles_timer = 2;
45+
static const u32 k_bus_cycles_timer = 7;
4646
static const u32 k_bus_cycles_audio = 7;
4747

4848
#endif /* BUS_H */

src/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
#define GLYNX_BIOS_SIZE 0x200
5353

54-
#define GLYNX_SAVESTATE_VERSION 6
54+
#define GLYNX_SAVESTATE_VERSION 7
5555
#define GLYNX_SAVESTATE_MAGIC 0x56191212
5656

5757
#if !defined(NULL)

src/lcd_screen.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,19 @@ void LcdScreen::Reset()
5050
memset(m_screen_buffer, 0, sizeof(m_screen_buffer));
5151
memset(m_current_palette, 0, sizeof(m_current_palette));
5252
memset(m_dma_buffer, 0, sizeof(m_dma_buffer));
53-
5453
m_current_cycle = 0;
5554
m_current_line = 0;
5655
m_rendering_offset = 80;
5756
m_line_cycles = 0;
58-
5957
m_dma_next_at = 0;
6058
m_dma_current_src_addr = 0;
6159
m_dma_burst_count = 0;
6260
m_dma_buffer_half = 0;
63-
6461
m_pixel_next_at = 0;
6562
m_pixel_count = 0;
6663
m_pixel_buffer_read_pos = 0;
6764
m_line_dst_offset = 0;
65+
m_in_vblank = false;
6866
}
6967

7068
void LcdScreen::InitPalettes()
@@ -208,4 +206,5 @@ void LcdScreen::Serialize(StateSerializer& s)
208206
G_SERIALIZE(s, m_pixel_count);
209207
G_SERIALIZE(s, m_pixel_buffer_read_pos);
210208
G_SERIALIZE(s, m_line_dst_offset);
209+
G_SERIALIZE(s, m_in_vblank);
211210
}

src/lcd_screen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class LcdScreen
3838
void Reset();
3939
void Update(u32 cycles);
4040
void ResetLine(u8 line);
41+
void ClearLine(u8 line);
4142
void FirstDMA();
4243
void ConfigureLineTiming();
4344
void UpdatePalette(int index, u16 color);
@@ -48,6 +49,7 @@ class LcdScreen
4849
u16* GetRGB565Palette();
4950
GLYNX_Pixel_Format GetPixelFormat();
5051
void RenderNoBiosScreen(u8* frame_buffer);
52+
void SetVBlank(bool vblank);
5153
void SaveState(std::ostream& stream);
5254
void LoadState(std::istream& stream);
5355

@@ -80,6 +82,7 @@ class LcdScreen
8082
u32 m_pixel_count;
8183
u32 m_pixel_buffer_read_pos;
8284
u32 m_line_dst_offset;
85+
bool m_in_vblank;
8386
GLYNX_Pixel_Format m_pixel_format;
8487
u32 m_rgba8888_palette[4096] = {};
8588
u16 m_rgb565_palette[4096] = {};

src/lcd_screen_inline.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
INLINE void LcdScreen::Update(u32 cycles)
2929
{
30+
if (m_in_vblank)
31+
return;
32+
3033
m_current_cycle += cycles;
3134

3235
if (m_dma_burst_count >= k_dma_bursts_per_line && m_pixel_count >= GLYNX_SCREEN_WIDTH)
@@ -59,6 +62,12 @@ INLINE void LcdScreen::ResetLine(u8 line)
5962
m_line_dst_offset = m_current_line * GLYNX_SCREEN_WIDTH;
6063
}
6164

65+
INLINE void LcdScreen::ClearLine(u8 line)
66+
{
67+
u32 offset = line * GLYNX_SCREEN_WIDTH;
68+
memset(&m_screen_buffer[offset], 0, GLYNX_SCREEN_WIDTH * sizeof(u16));
69+
}
70+
6271
INLINE void LcdScreen::FirstDMA()
6372
{
6473
m_dma_current_src_addr = m_mikey->GetState()->dispadr_latch;
@@ -107,6 +116,11 @@ INLINE GLYNX_Pixel_Format LcdScreen::GetPixelFormat()
107116
return m_pixel_format;
108117
}
109118

119+
INLINE void LcdScreen::SetVBlank(bool vblank)
120+
{
121+
m_in_vblank = vblank;
122+
}
123+
110124
INLINE void LcdScreen::DoDMA()
111125
{
112126
u8* dst = &m_dma_buffer[m_dma_buffer_half];

src/m6502.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ M6502::M6502(Bus* bus)
3939
m_s.debug_next_irq = 0;
4040
m_s.debug_irq_mask = 0;
4141
m_s.halted = false;
42+
m_s.onebyte_un_nop = false;
43+
m_s.page_mode_discounts = 0;
44+
m_s.last_ticks = 0;
45+
m_s.total_ticks = 0;
4246
m_breakpoints_enabled = false;
4347
m_breakpoints_irq_enabled = 0;
4448
m_cpu_breakpoint_hit = false;
@@ -48,6 +52,8 @@ M6502::M6502(Bus* bus)
4852
m_disassembler_call_stack_size = 0;
4953
m_reset_value = -1;
5054
m_prev_opcode_address = 0xFFFF;
55+
m_stream_open = false;
56+
m_page_mode_tick_discount = 0;
5157
}
5258

5359
M6502::~M6502()
@@ -93,11 +99,17 @@ void M6502::Reset()
9399
m_s.irq_pending = 0;
94100
m_s.debug_irq_mask = 0;
95101
m_s.halted = false;
102+
m_s.onebyte_un_nop = false;
103+
m_s.page_mode_discounts = 0;
104+
m_s.last_ticks = 0;
105+
m_s.total_ticks = 0;
96106
m_cpu_breakpoint_hit = false;
97107
m_memory_breakpoint_hit = false;
98108
m_run_to_breakpoint_hit = false;
99109
m_run_to_breakpoint_requested = false;
100110
m_prev_opcode_address = 0xFFFF;
111+
m_stream_open = false;
112+
m_page_mode_tick_discount = 0;
101113
ClearDisassemblerCallStack();
102114
}
103115

@@ -344,4 +356,8 @@ void M6502::Serialize(StateSerializer& s)
344356
G_SERIALIZE(s, m_s.debug_next_irq);
345357
G_SERIALIZE(s, m_s.debug_irq_mask);
346358
G_SERIALIZE(s, m_s.halted);
359+
G_SERIALIZE(s, m_s.onebyte_un_nop);
360+
G_SERIALIZE(s, m_s.page_mode_discounts);
361+
G_SERIALIZE(s, m_stream_open);
362+
G_SERIALIZE(s, m_page_mode_tick_discount);
347363
}

src/m6502.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class M6502
6262
s32 debug_irq_mask;
6363
bool halted;
6464
bool onebyte_un_nop;
65+
u8 page_mode_discounts;
66+
u32 last_ticks;
67+
u64 total_ticks;
6568
};
6669

6770
struct GLYNX_Breakpoint
@@ -108,6 +111,7 @@ class M6502
108111
void ClearDisassemblerCallStack();
109112
std::stack<GLYNX_CallStackEntry>* GetDisassemblerCallStack();
110113
void CheckMemoryBreakpoints(u16 address, bool read);
114+
void SetPageModeEnabled(bool enabled);
111115
void SaveState(std::ostream& stream);
112116
void LoadState(std::istream& stream);
113117

@@ -129,7 +133,9 @@ class M6502
129133
std::stack<GLYNX_CallStackEntry> m_disassembler_call_stack;
130134
int m_disassembler_call_stack_size;
131135
int m_reset_value;
136+
bool m_stream_open;
132137
u16 m_prev_opcode_address;
138+
u8 m_page_mode_tick_discount;
133139

134140
private:
135141
void HandleIRQ();
@@ -139,8 +145,12 @@ class M6502
139145
void PushCallStack(u16 src, u16 dest, u16 back);
140146
void PopCallStack();
141147

142-
u8 Fetch8();
143-
u16 Fetch16();
148+
u8 FetchOpcode8();
149+
u8 FetchOperand8();
150+
u16 FetchOperand16();
151+
void NotifyBusBreak();
152+
u8 MemRead8(u16 address);
153+
void MemWrite8(u16 address, u8 value);
144154
u16 Address16(u8 high, u8 low);
145155
bool PageCrossed(u16 old_address, u16 new_address);
146156
u16 ZeroPageX();

0 commit comments

Comments
 (0)