Skip to content

Commit

Permalink
API cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed May 31, 2024
1 parent dc9e105 commit 0146794
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 318 deletions.
2 changes: 1 addition & 1 deletion Emulator/Base/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef util::Exception StateChangeException;
* the basic functionality to manage the execution state. It provides functions
* to launch the emulator thread, to query it's current state, and to switch
* to another state. */
class Thread : public CoreObject, public Suspendable, Wakeable {
class Thread : public CoreObject, public Suspendable, public Wakeable {

protected:

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Components/CPU/Peddle/StrWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class StrWriter
base = ptr = p;
};

isize length() { return ptr - base; }
isize length() { return isize(ptr - base); }
void fill(isize tab) { while (ptr < base + tab) *ptr++ = ' '; }

private:
Expand Down
4 changes: 2 additions & 2 deletions Emulator/Utilities/Reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace util {
template <class T, typename E> struct Reflection {

// Returns the key including the section prefix (if any)
static const char *key(long nr) { return T::key((E)nr); }
static const char *key(isize nr) { return T::key((E)nr); }

// Returns the key without the section prefix (if any)
static const char *plainkey(long nr) {
static const char *plainkey(isize nr) {
auto *p = key(nr);
for (isize i = 0; p[i]; i++) if (p[i] == '.') return p + i + 1;
return p;
Expand Down
67 changes: 10 additions & 57 deletions Emulator/VirtualC64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,75 +310,28 @@ VirtualC64::CPUAPI::disassembleRecorded(char *dst, const char *fmt, isize nr) co
return cpu.debugger.disassRecorded(dst, fmt, nr);
}


//
// Guards
//

long
VirtualC64::GuardAPI::elements() const
{
return guards.elements();
}

Guard *
VirtualC64::GuardAPI::guardNr(long nr) const
VirtualC64::CPUAPI::breakpointNr(long nr) const
{
return guards.guardWithNr(nr);
return cpu.debugger.breakpoints.guardWithNr(nr);
}

Guard *
VirtualC64::GuardAPI::guardAt(u32 addr) const
{
return guards.guardAtAddr(addr);
}

void
VirtualC64::GuardAPI::enable(long nr)
VirtualC64::CPUAPI::breakpointAt(u32 addr) const
{
guards.enable(nr);
return cpu.debugger.breakpoints.guardAtAddr(addr);
}

void
VirtualC64::GuardAPI::disable(long nr)
{
guards.disable(nr);
}

void
VirtualC64::GuardAPI::enableAt(u32 addr)
{
guards.enableAt(addr);
}

void
VirtualC64::GuardAPI::disableAt(u32 addr)
{
guards.disableAt(addr);
}

void
VirtualC64::GuardAPI::setAt(u32 addr, long skip)
{
guards.setAt(addr, skip);
}

void
VirtualC64::GuardAPI::removeAt(u32 addr)
{
guards.removeAt(addr);
}

void
VirtualC64::GuardAPI::remove(long nr)
Guard *
VirtualC64::CPUAPI::watchpointNr(long nr) const
{
guards.remove(nr);
return cpu.debugger.watchpoints.guardWithNr(nr);
}

void
VirtualC64::GuardAPI::removeAll()
Guard *
VirtualC64::CPUAPI::watchpointAt(u32 addr) const
{
guards.removeAll();
return cpu.debugger.watchpoints.guardAtAddr(addr);
}


Expand Down
105 changes: 25 additions & 80 deletions Emulator/VirtualC64.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,92 +535,13 @@ class VirtualC64 : vc64::Emulator {
} mem;


/** API for breakpoints and watchpoints
*/
struct GuardAPI : API {

Guards &guards;
GuardAPI(Emulator &emu, Guards& guards) : API(emu), guards(guards) { }

/// @name Inspecting the guard list
/// @{

/** @brief Returns the number of guards in the guard list.
*/
long elements() const;

/** @brief Returns a guard from the guard list.
* @param nr Number of the guard.
* @return A pointer to the guard or nullptr if the guard does not exist.
*/
Guard *guardNr(long nr) const;

/** @brief Returns the guard set on a specific address.
* @param addr Memory address.
* @return A pointer to the guard or nullptr if the address is not guarded.
*/
Guard *guardAt(u32 addr) const;

/** Sets a guard on a specific memory location.
* @param addr A memory location.
* @param ignore An optional ignore counter.
*/
void setAt(u32 addr, long ignore = 0);

/** Deletes a guard from the guard list.
* @param nr A position in the guard list.
*/
void remove(long nr);

/** Deletes a guard from the guard list.
* @param addr Observed memory address of the guard to be removed.
*/
void removeAt(u32 addr);

/** Deletes the entire guard list.
*/
void removeAll();

/// @}
/// @name Enabling or disabling guards
/// @{

/** Enables a guard
* @param nr Position of the guard in the guard list.
*/
void enable(long nr);

/** Enables a guard
* @param addr Observed memory address of the guard to enable.
*/
void enableAt(u32 addr);

/** Disables a guard
* @param nr Position of the guard in the guard list.
*/
void disable(long nr);

/** Disables a guard
* @param addr Observed memory address of the guard to disable.
*/
void disableAt(u32 addr);

/// @}
};


/** CPU API
*/
struct CPUAPI : API {

using API::API;

GuardAPI breakpoints;
GuardAPI watchpoints;

CPUAPI(Emulator &emu) : API(emu),
breakpoints(emu, emu.main.cpu.debugger.breakpoints),
watchpoints(emu, emu.main.cpu.debugger.watchpoints) { }
CPUAPI(Emulator &emu) : API(emu) { }

/** @brief Returns the component's current state.
*/
Expand Down Expand Up @@ -661,6 +582,30 @@ class VirtualC64 : vc64::Emulator {
*/
isize disassembleRecorded(char *dst, const char *fmt, isize nr) const;

/** @brief Returns a breakpoint from the breakpoint list.
* @param nr Number of the breakpoint.
* @return A pointer to the breakpoint or nullptr if it does not exist.
*/
Guard *breakpointNr(long nr) const;

/** @brief Returns the breakpoint set on a specific address.
* @param addr Memory address.
* @return A pointer to the breakpoint or nullptr if it is not guarded.
*/
Guard *breakpointAt(u32 addr) const;

/** @brief Returns a breakpoint from the breakpoint list.
* @param nr Number of the breakpoint.
* @return A pointer to the breakpoint or nullptr if it does not exist.
*/
Guard *watchpointNr(long nr) const;

/** @brief Returns the breakpoint set on a specific address.
* @param addr Memory address.
* @return A pointer to the breakpoint or nullptr if it is not guarded.
*/
Guard *watchpointAt(u32 addr) const;

} cpu;


Expand Down
30 changes: 14 additions & 16 deletions GUI/Panels/Inspector/GuardTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class GuardTableView: NSTableView {
@IBOutlet weak var inspector: Inspector!
var emu: EmulatorProxy { return inspector.parent.emu }
var cpu: CPUProxy { return emu.cpu }
var breakpoints: GuardsProxy { return emu.breakpoints }
var watchpoints: GuardsProxy { return emu.watchpoints }

// Symbols
var symEnabled = "" // "\u{26D4}"
Expand Down Expand Up @@ -125,13 +123,13 @@ class BreakTableView: GuardTableView {

override func cache() {

numRows = breakpoints.elements
numRows = 0
while cpu.hasBreakpoint(withNr: numRows) {

for i in 0 ..< numRows {

let info = cpu.breakpoint(withNr: i)
disabledCache[i] = !info.enabled
addrCache[i] = Int(info.addr)
let info = cpu.breakpoint(withNr: numRows)
disabledCache[numRows] = !info.enabled
addrCache[numRows] = Int(info.addr)
numRows += 1
}
}

Expand Down Expand Up @@ -186,16 +184,16 @@ class BreakTableView: GuardTableView {
class WatchTableView: GuardTableView {

override func cache() {

numRows = watchpoints.elements

for i in 0 ..< numRows {
numRows = 0
while cpu.hasWatchpoint(withNr: numRows) {

let info = cpu.watchpoint(withNr: i)
disabledCache[i] = !info.enabled
addrCache[i] = Int(info.addr)
let info = cpu.watchpoint(withNr: numRows)
disabledCache[numRows] = !info.enabled
addrCache[numRows] = Int(info.addr)
numRows += 1
}

symEnabled = "⚠️"
}

Expand All @@ -210,7 +208,7 @@ class WatchTableView: GuardTableView {
emu.put(wp.enabled ? .WP_DISABLE_NR : .WP_ENABLE_NR, value: row)
inspector.fullRefresh()
}

if col == 2 {

// Delete
Expand Down
1 change: 0 additions & 1 deletion GUI/Panels/Inspector/InstrTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class InstrTableView: NSTableView {

var emu: EmulatorProxy { return inspector.parent.emu }
var cpu: CPUProxy { return emu.cpu }
var breakpoints: GuardsProxy { return emu.breakpoints }

enum BreakpointType {

Expand Down
2 changes: 2 additions & 0 deletions GUI/Panels/Monitor/Monitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,12 @@ class Monitor: DialogController {
}
}

/*
extension Monitor {
override func windowWillClose(_ notification: Notification) {
super.windowWillClose(notification)
}
}
*/
40 changes: 0 additions & 40 deletions Proxy/EmulatorProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ using namespace vc64;
@class ExpansionPortProxy;
@class FileSystemProxy;
@class G64FileProxy;
@class GuardsProxy;
@class IECProxy;
@class JoystickProxy;
@class KeyboardProxy;
Expand Down Expand Up @@ -120,8 +119,6 @@ using namespace vc64;
DriveProxy *drive8;
DriveProxy *drive9;
ExpansionPortProxy *expansionport;
GuardsProxy *breakpoints;
GuardsProxy *watchpoints;
IECProxy *iec;
KeyboardProxy *keyboard;
MemoryProxy *mem;
Expand All @@ -146,8 +143,6 @@ using namespace vc64;
@property (readonly, strong) DriveProxy *drive8;
@property (readonly, strong) DriveProxy *drive9;
@property (readonly, strong) ExpansionPortProxy *expansionport;
@property (readonly, strong) GuardsProxy *breakpoints;
@property (readonly, strong) GuardsProxy *watchpoints;
@property (readonly, strong) IECProxy *iec;
@property (readonly, strong) KeyboardProxy *keyboard;
@property (readonly, strong) MemoryProxy *mem;
Expand Down Expand Up @@ -265,41 +260,6 @@ using namespace vc64;
@end


//
// Guards (Breakpoints, Watchpoints)
//

@interface GuardsProxy : Proxy { }

@property (readonly) NSInteger elements;

/*
- (NSInteger)addr:(NSInteger)nr;
- (BOOL)isSet:(NSInteger)nr;
- (BOOL)isSetAt:(NSInteger)addr;
- (void)setAt:(NSInteger)addr;
*/
// - (void)remove:(NSInteger)nr;
// - (void)removeAt:(NSInteger)addr;
// - (void)removeAll;

// - (void)replace:(NSInteger)nr addr:(NSInteger)addr;

// - (BOOL)isEnabled:(NSInteger)nr;
- (BOOL)isEnabledAt:(NSInteger)addr;
// - (BOOL)isDisabled:(NSInteger)nr;
- (BOOL)isDisabledAt:(NSInteger)addr;

/*
- (void)enable:(NSInteger)nr;
- (void)enableAt:(NSInteger)addr;
- (void)disable:(NSInteger)nr;
- (void)disableAt:(NSInteger)addr;
*/

@end

//
// C64
//
Expand Down
Loading

0 comments on commit 0146794

Please sign in to comment.