Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions src/DebugInterface/CDebuggerApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "CSlrTextParser.h"
#include <sstream>
#include <cstring>
#include <cctype>
#include <cstdlib>

// static factory
CDebuggerApi *CDebuggerApi::GetDebuggerApi(u8 emulatorType)
Expand Down Expand Up @@ -539,6 +541,11 @@ void CDebuggerApi::SetWarpSpeed(bool isWarpSpeed)
debugInterface->SetSettingIsWarpSpeed(isWarpSpeed);
}

bool CDebuggerApi::GetWarpSpeed()
{
return debugInterface->GetSettingIsWarpSpeed();
}

bool CDebuggerApi::KeyboardDown(u32 mtKeyCode)
{
return debugInterface->KeyboardDown(mtKeyCode);
Expand Down Expand Up @@ -842,8 +849,24 @@ json CDebuggerApi::AssembleCode(int startAddr, const std::string &code)
strncpy(lineBuf, lines[i].c_str(), sizeof(lineBuf) - 1);
lineBuf[sizeof(lineBuf) - 1] = 0;

// Strip '$' for the assembler (it expects bare hex)
// Actually the assembler handles '$' by stripping it internally via token parsing
// Remove '$' characters (assembler is hex-only), same as CViewMonitorConsole does.
// '$' is the canonical 6502 notation, so clients send "lda #$07" and used to get
// "Not a number after #" back. Stripping here keeps the shared assembler grammar
// untouched, so a malformed "lda #$" still fails instead of silently assembling.
{
char *src = lineBuf;
char *dst = lineBuf;
while (*src)
{
if (*src != '$')
{
*dst = *src;
dst++;
}
src++;
}
*dst = 0x00;
}

int instructionOpcode = -1;
uint16 instructionValue = 0;
Expand Down Expand Up @@ -1040,10 +1063,25 @@ json CDebuggerApi::SearchOpcodePattern(const std::string &pattern, int startAddr

// Build set of matching opcodes
std::vector<u8> matchingOpcodes;
for (int op = 0; op < 256; op++)

// A first token of exactly two hex digits is a raw opcode byte ("a9 ??"), not a
// mnemonic. Hex bytes are the most common way to write a pattern by hand, and this
// cannot collide with a mnemonic: every name in the opcode table is 3 characters
// long (ADC, BCC and DEC look hex-ish but are 3 chars, not 2).
bool isOpcodeByte = (strlen(mnemonicBuf) == 2
&& isxdigit((unsigned char)mnemonicBuf[0])
&& isxdigit((unsigned char)mnemonicBuf[1]));
if (isOpcodeByte)
{
if (strcmp(opcodes[op].name, mnemonicBuf) == 0)
matchingOpcodes.push_back(op);
matchingOpcodes.push_back((u8)strtol(mnemonicBuf, NULL, 16));
}
else
{
for (int op = 0; op < 256; op++)
{
if (strcmp(opcodes[op].name, mnemonicBuf) == 0)
matchingOpcodes.push_back(op);
}
}

if (matchingOpcodes.empty())
Expand Down
1 change: 1 addition & 0 deletions src/DebugInterface/CDebuggerApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class CDebuggerApi

//
virtual void SetWarpSpeed(bool isWarpSpeed);
virtual bool GetWarpSpeed();

// input
virtual bool KeyboardDown(u32 mtKeyCode);
Expand Down
21 changes: 17 additions & 4 deletions src/Emulators/atari800/AtariInterface/CDebuggerServerApiAtari.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "CDebuggerServerApiAtari.h"
#include "CDebugInterfaceAtari.h"
#include "CDebuggerServer.h"
#include "SYS_Funct.h"

using namespace std;
using namespace nlohmann;
Expand Down Expand Up @@ -155,7 +156,10 @@ void CDebuggerServerApiAtari::RegisterEndpoints(CDebuggerServer *server)
CDebugInterfaceMutexGuard lock(debugInterfaceAtari);
for (auto &[key, value] : params["registers"].items())
{
int regNum = stoi(key);
// stoi() is base-10 only: "0x18" silently parsed as register 0,
// landing the write on the wrong register with no error. Use the
// same dec/hex parser the C64 endpoints use.
int regNum = (int)FUN_DecOrHexStrWithPrefixToU64(key.c_str());
u8 val = value.get<int>();
debugInterfaceAtari->SetAnticRegister(regNum, val);
}
Expand All @@ -176,7 +180,10 @@ void CDebuggerServerApiAtari::RegisterEndpoints(CDebuggerServer *server)
CDebugInterfaceMutexGuard lock(debugInterfaceAtari);
for (auto &[key, value] : params["registers"].items())
{
int regNum = stoi(key);
// stoi() is base-10 only: "0x18" silently parsed as register 0,
// landing the write on the wrong register with no error. Use the
// same dec/hex parser the C64 endpoints use.
int regNum = (int)FUN_DecOrHexStrWithPrefixToU64(key.c_str());
u8 val = value.get<int>();
debugInterfaceAtari->SetGtiaRegister(regNum, val);
}
Expand All @@ -197,7 +204,10 @@ void CDebuggerServerApiAtari::RegisterEndpoints(CDebuggerServer *server)
CDebugInterfaceMutexGuard lock(debugInterfaceAtari);
for (auto &[key, value] : params["registers"].items())
{
int regNum = stoi(key);
// stoi() is base-10 only: "0x18" silently parsed as register 0,
// landing the write on the wrong register with no error. Use the
// same dec/hex parser the C64 endpoints use.
int regNum = (int)FUN_DecOrHexStrWithPrefixToU64(key.c_str());
u8 val = value.get<int>();
debugInterfaceAtari->SetPokeyRegister(regNum, val);
}
Expand All @@ -218,7 +228,10 @@ void CDebuggerServerApiAtari::RegisterEndpoints(CDebuggerServer *server)
CDebugInterfaceMutexGuard lock(debugInterfaceAtari);
for (auto &[key, value] : params["registers"].items())
{
int regNum = stoi(key);
// stoi() is base-10 only: "0x18" silently parsed as register 0,
// landing the write on the wrong register with no error. Use the
// same dec/hex parser the C64 endpoints use.
int regNum = (int)FUN_DecOrHexStrWithPrefixToU64(key.c_str());
u8 val = value.get<int>();
debugInterfaceAtari->SetPiaRegister(regNum, val);
}
Expand Down
Loading
Loading