Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
adb198a
Added ability to copy TextView via CMD+C
ScraperMan2002 May 16, 2025
79d6d7c
Remove TestAddCode. That was just to help me understand how everythin…
ScraperMan2002 May 16, 2025
a7dcb5e
Get rid of useless line [item setTarget: nil]; to simplify the code.
ScraperMan2002 May 16, 2025
1aea868
Added ability to "select all" for the text in Properties.
ScraperMan2002 May 17, 2025
a52ca4c
Merge branch 'ares-emulator:master' into CMDA
ScraperMan2002 May 17, 2025
d6314dc
Merge pull request #1 from ScraperMan2002/CMDA
ScraperMan2002 May 17, 2025
8bdaf1d
Moved all the Menu Item initailizations from Window to Application. W…
ScraperMan2002 May 17, 2025
991daae
Merge remote-tracking branch 'refs/remotes/PrivateAres/master'
ScraperMan2002 May 17, 2025
485df6a
Merge branch 'ares-emulator:master' into master
ScraperMan2002 May 17, 2025
6760d27
-Put constructMenu into autoreleasepool to get rid of leaked data
ScraperMan2002 May 17, 2025
df76401
Remove tracked .DS_Store and update .gitignore
ScraperMan2002 May 17, 2025
ed79e37
Remove reamining tracked .DS_Stores
ScraperMan2002 May 17, 2025
211c1b0
Merge branch 'ares-emulator:master' into master
ScraperMan2002 May 19, 2025
13bf81d
Merge branch 'ares-emulator:master' into master
ScraperMan2002 May 25, 2025
cceb52c
Change the window size of the Configuration window so that on MacOS t…
ScraperMan2002 May 25, 2025
36e0e72
Added ability for Memory Editor to switch memory value format between…
ScraperMan2002 May 26, 2025
5adf5d3
Merge branch 'ares-emulator:master' into master
ScraperMan2002 May 26, 2025
0d370ea
Added ability to switch between binary, octal, and hexidecimal in Win…
ScraperMan2002 May 27, 2025
8753f2a
Added ability for HexData to switch between Binary, Octal, and Hexade…
ScraperMan2002 May 27, 2025
1177c19
Added setBase() so the program can compile correctly.
ScraperMan2002 May 27, 2025
93469e5
Fixed further bugs with not using state().base and with to_string not…
ScraperMan2002 May 27, 2025
da4c507
Got rid of using std::invalid_argument. Might as well just simply "th…
ScraperMan2002 May 27, 2025
433da54
Major Edits to hex-edit on MacOS:
ScraperMan2002 May 29, 2025
c7fad92
Merge pull request #2 from ScraperMan2002/hexedit-edit-branch-with-si…
ScraperMan2002 May 29, 2025
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
2 changes: 1 addition & 1 deletion desktop-ui/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ SettingsWindow::SettingsWindow() {

setDismissable();
setTitle("Configuration");
setSize({700_sx, 425_sy});
setSize({775_sx, 425_sy});
setAlignment({0.0, 1.0});
setResizable(false);
}
Expand Down
17 changes: 17 additions & 0 deletions desktop-ui/tools/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ auto MemoryEditor::construct() -> void {
setVisible(false);

memoryLabel.setText("Memory Editor").setFont(Font().setBold());

base2Editor.setText("Binary").onActivate([&] {
tools.memory.base = 2;
memoryEditor.setBase(2);
});
base8Editor.setText("Octal").onActivate([&] {
tools.memory.base = 8;
memoryEditor.setBase(8);
});
base16Editor.setText("Hexadecimal").onActivate([&] {
tools.memory.base = 16;
memoryEditor.setBase(16);
});
if(tools.memory.base == 2) base2Editor.setChecked();
if(tools.memory.base == 8) base8Editor.setChecked();
if(tools.memory.base == 16) base16Editor.setChecked();

memoryList.onChange([&] { eventChange(); });
memoryEditor.setFont(Font().setFamily(Font::Mono));
memoryEditor.setRows(24);
Expand Down
1 change: 1 addition & 0 deletions desktop-ui/tools/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "properties.cpp"
#include "tracer.cpp"

Tools tools;
namespace Instances { Instance<ToolsWindow> toolsWindow; }
ToolsWindow& toolsWindow = Instances::toolsWindow();
ManifestViewer& manifestViewer = toolsWindow.manifestViewer;
Expand Down
12 changes: 12 additions & 0 deletions desktop-ui/tools/tools.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
struct Tools : Markup::Node {
struct Memory {
unsigned char base = 16;
} memory;
};

struct ManifestViewer : VerticalLayout {
auto construct() -> void;
auto reload() -> void;
Expand Down Expand Up @@ -58,6 +64,11 @@ struct MemoryEditor : VerticalLayout {

Label memoryLabel{this, Size{~0, 0}, 5};
ComboButton memoryList{this, Size{~0, 0}};
HorizontalLayout baseFormatLayout{this, Size{~0, 0}, 5};
RadioLabel base2Editor{&baseFormatLayout, Size{0, 0}};
RadioLabel base8Editor{&baseFormatLayout, Size{0, 0}};
RadioLabel base16Editor{&baseFormatLayout, Size{0, 0}};
Group renderQualityGroup{&base2Editor, &base8Editor, &base16Editor};
HexEdit memoryEditor{this, Size{~0, ~0}};
HorizontalLayout controlLayout{this, Size{~0, 0}};
Button exportButton{&controlLayout, Size{80, 0}};
Expand Down Expand Up @@ -145,6 +156,7 @@ struct ToolsWindow : Window {
HomePanel homePanel;
};

extern Tools tools;
namespace Instances { extern Instance<ToolsWindow> toolsWindow; }
extern ToolsWindow& toolsWindow;
extern CheatEditor& cheatEditor;
Expand Down
112 changes: 105 additions & 7 deletions hiro/cocoa/widget/hex-edit.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
#if defined(Hiro_HexEdit)

@implementation CocoaHexEditTableView

- (void)mouseDown:(NSEvent *)event {
NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
NSInteger row = [self rowAtPoint:point];
NSInteger column = [self columnAtPoint:point];

[super mouseDown:event]; // handle selection

if (row >= 0 && column >= 0) {
// Begin editing the clicked cell
NSTableColumn *tableColumn = [self tableColumns][column];
NSString *identifier = tableColumn.identifier;

// Skip editing if column is not editable (e.g., Address/Char)
if (![identifier isEqualToString:@"Address"] && ![identifier isEqualToString:@"Char"]) {
[self editColumn:column row:row withEvent:event select:YES];
}
}
}

@end

@implementation CocoaHexEdit

-(id) initWith:(hiro::mHexEdit&)hexEditReference {
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
hexEdit = &hexEditReference;
if (tableView = [[NSTableView alloc] initWithFrame:[self bounds]]) {
if (tableView = [[CocoaHexEditTableView alloc] initWithFrame:[self bounds]]) {
[tableView setDelegate:self];
[tableView setDataSource:self];
// [tableView setHeaderView:nil];
[tableView setUsesAlternatingRowBackgroundColors:true];
Expand Down Expand Up @@ -82,7 +106,24 @@ objectValueForTableColumn:(NSTableColumn *) tableColumn
address += columnNumber;
if (address < hexEdit->length()) {
u8 data = hexEdit->doRead(address);
return [NSString stringWithUTF8String:hex(data, 2L).data()];
switch(hexEdit->base()) {
case 2: {
NSMutableString *binary = [NSMutableString stringWithCapacity:8];
for(int bit = 7; bit >= 0; bit--) {
[binary appendFormat:@"%c", (data & (1 << bit)) ? '1' : '0'];
}
return binary;
}
case 8:
return [NSString stringWithFormat:@"%03o", data];
case 16:
return [NSString stringWithFormat:@"%02X", data];
default:
@throw [NSException exceptionWithName:@"InvalidBaseException"
reason:@"The base for the Hex Editor was neither 2, 8, nor 16."
userInfo:@{
@"filename": @"hiro/cocoa/widget/hex-edit.cpp"}];
}
} else {
return @" ";
}
Expand All @@ -98,18 +139,71 @@ objectValueForTableColumn:(NSTableColumn *) tableColumn
u32 address = row * hexEdit->columns() + colNumber;

if (address < hexEdit->length()) {
// only get the first 2 characters
NSString* newVal = [(NSString *)object substringToIndex:2];
NSScanner* hexScanner = [NSScanner scannerWithString:newVal];
NSString* newVal = (NSString *)object;
newVal = [newVal stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// Make sure code converts Single Digit by appending zero.
unsigned int data = 0;
if ([hexScanner scanHexInt:&data]) {
BOOL boolSucceed = YES;
switch(hexEdit->base()) {
case 2: {
if (newVal.length > 8) {
newVal = [newVal substringToIndex:8]; // truncate to 8 chars max for Binary
}

// Converts Binary to Integer
for (NSUInteger i = 0; i < newVal.length; i++) {
unichar digit = [newVal characterAtIndex:i];
if (digit != '0' && digit != '1') {
boolSucceed = NO; break;
}
data = data * 2 + (digit - '0');
}
break;
}
case 8:{
if (newVal.length > 3) {
newVal = [newVal substringToIndex:3]; // truncate to 3 chars max for Octal
}

// Converts Octal to Integer
for (NSUInteger i = 0; i < newVal.length; i++) {
unichar digit = [newVal characterAtIndex:i];
if (digit < '0' || digit > '7') {
boolSucceed = NO; break;
}
data = data * 8 + (digit - '0');
}
data &= 0xFF;
break;
}
case 16:{
if (newVal.length > 2) {
newVal = [newVal substringToIndex:2]; // truncate to 2 chars max
}
NSScanner* hexScanner = [NSScanner scannerWithString:newVal];

// Converts Hex to Integer
boolSucceed = [hexScanner scanHexInt:&data];
break;
}
default:
@throw [NSException exceptionWithName:@"InvalidBaseException"
reason:@"The base for the Hex Editor was neither 2, 8, nor 16."
userInfo:@{
@"filename": @"hiro/cocoa/widget/hex-edit.cpp"}];
}
if (boolSucceed) {
// this.......is probably ok....???
hexEdit->doWrite(address, (u8)data);
}
}
[tableView reloadData];
}

- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
return YES;
}

@end

namespace hiro {
Expand Down Expand Up @@ -143,7 +237,11 @@ namespace hiro {
auto pHexEdit::setBackgroundColor(Color color) -> void {
update();
}


auto pHexEdit::setBase(u8 base) -> void {
update();
}

auto pHexEdit::setColumns(u32 columns) -> void {
update();
}
Expand Down
8 changes: 6 additions & 2 deletions hiro/cocoa/widget/hex-edit.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#if defined(Hiro_HexEdit)

@interface CocoaHexEdit : NSScrollView <NSTableViewDataSource> {
@interface CocoaHexEditTableView : NSTableView
@end

@interface CocoaHexEdit : NSScrollView <NSTableViewDataSource, NSTableViewDelegate> {
// Not an NSTableViewDelegate because the table is cell-based, not view-based
@public
hiro::mHexEdit* hexEdit; // this will be the data source for tableView.
NSTableView* tableView;
CocoaHexEditTableView* tableView;
}
-(id) initWith:(hiro::mHexEdit&)hexEdit;
-(NSTableView*) tableView; // helper function used in update()
Expand All @@ -17,6 +20,7 @@ struct pHexEdit : public pWidget {
Declare(HexEdit, Widget);

auto setAddress(u32 address) -> void;
auto setBase(u8 base) -> void;
auto setBackgroundColor(Color color) -> void;
auto setColumns(u32 columns) -> void;
auto setForegroundColor(Color color) -> void;
Expand Down
2 changes: 2 additions & 0 deletions hiro/core/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ struct HexEdit : sHexEdit {

auto address() const { return self().address(); }
auto backgroundColor() const { return self().backgroundColor(); }
auto base() const { return self().base(); }
auto columns() const { return self().columns(); }
auto doRead(u32 offset) const { return self().doRead(offset); }
auto doWrite(u32 offset, u8 data) const { return self().doWrite(offset, data); }
Expand All @@ -388,6 +389,7 @@ struct HexEdit : sHexEdit {
auto rows() const { return self().rows(); }
auto setAddress(u32 address) { return self().setAddress(address), *this; }
auto setBackgroundColor(Color color = {}) { return self().setBackgroundColor(color), *this; }
auto setBase(u16 base = 16) { return self().setBase(base), *this; }
auto setColumns(u32 columns = 16) { return self().setColumns(columns), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
auto setLength(u32 length) { return self().setLength(length), *this; }
Expand Down
10 changes: 10 additions & 0 deletions hiro/core/widget/hex-edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
return state.backgroundColor;
}

auto mHexEdit::base() const -> u16 {

Check failure on line 17 in hiro/core/widget/hex-edit.cpp

View workflow job for this annotation

GitHub Actions / Build ares (primary) / ares-macos-universal

return type of out-of-line definition of 'hiro::mHexEdit::base' differs from that in the declaration
return state.base;
}

auto mHexEdit::columns() const -> u32 {
return state.columns;
}
Expand Down Expand Up @@ -55,6 +59,12 @@
return *this;
}

auto mHexEdit::setBase(u16 base) -> type& {

Check failure on line 62 in hiro/core/widget/hex-edit.cpp

View workflow job for this annotation

GitHub Actions / Build ares (primary) / ares-macos-universal

out-of-line definition of 'setBase' does not match any declaration in 'hiro::mHexEdit'
state.base = base;
signal(setBase, base);
return *this;
}

auto mHexEdit::setBackgroundColor(Color color) -> type& {
state.backgroundColor = color;
signal(setBackgroundColor, color);
Expand Down
3 changes: 3 additions & 0 deletions hiro/core/widget/hex-edit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct mHexEdit : mWidget {

auto address() const -> u32;
auto backgroundColor() const -> Color;
auto base() const -> u8;
auto columns() const -> u32;
auto doRead(u32 offset) const -> u8;
auto doWrite(u32 offset, u8 data) const -> void;
Expand All @@ -14,6 +15,7 @@ struct mHexEdit : mWidget {
auto rows() const -> u32;
auto setAddress(u32 address = 0) -> type&;
auto setBackgroundColor(Color color = {}) -> type&;
auto setBase(u8 base) -> type&;
auto setColumns(u32 columns = 16) -> type&;
auto setForegroundColor(Color color = {}) -> type&;
auto setLength(u32 length) -> type&;
Expand All @@ -24,6 +26,7 @@ struct mHexEdit : mWidget {
struct State {
u32 address = 0;
Color backgroundColor;
u8 base = 16;
u32 columns = 16;
Color foregroundColor;
u32 length = 0;
Expand Down
19 changes: 18 additions & 1 deletion hiro/gtk/widget/hex-edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ auto pHexEdit::setAddress(u32 address) -> void {
update();
}

auto pHexEdit::setBase(u8 base) -> void {
setScroll();
update();
}

auto pHexEdit::setBackgroundColor(Color color) -> void {
GdkColor gdkColor = CreateColor(color);
gtk_widget_modify_base(subWidget, GTK_STATE_NORMAL, color ? &gdkColor : nullptr);
Expand Down Expand Up @@ -138,7 +143,19 @@ auto pHexEdit::update() -> void {
for(auto column : range(state().columns)) {
if(address < state().length) {
u8 data = self().doRead(address++);
hexdata.append(hex(data, 2L));
switch (state().base) {
case 2:
hexdata.append(binary(data, 2L));
break;
case 8:
hexdata.append(octal(data, 2L));
break;
case 16:
hexdata.append(hex(data, 2L));
break;
default:
throw;
}
hexdata.append(" ");
ansidata.append(data >= 0x20 && data <= 0x7e ? (char)data : '.');
} else {
Expand Down
1 change: 1 addition & 0 deletions hiro/gtk/widget/hex-edit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct pHexEdit : pWidget {

auto focused() const -> bool override;
auto setAddress(u32 address) -> void;
auto setBase(u8 base) -> void;
auto setBackgroundColor(Color color) -> void;
auto setColumns(u32 columns) -> void;
auto setForegroundColor(Color color) -> void;
Expand Down
18 changes: 17 additions & 1 deletion hiro/qt/widget/hex-edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ auto pHexEdit::setAddress(u32 address) -> void {
_setState();
}

auto pHexEdit::setBase(u8 base) -> void {
_setState();
}

auto pHexEdit::setBackgroundColor(Color color) -> void {
static auto defaultColor = qtHexEdit->palette().color(QPalette::Base);

Expand Down Expand Up @@ -89,7 +93,19 @@ auto pHexEdit::update() -> void {
for(u32 column = 0; column < state().columns; column++) {
if(address < state().length) {
u8 data = self().doRead(address++);
hexdata.append(hex(data, 2L));
switch (state().base) {
case 2:
hexdata.append(binary(data, 2L));
break;
case 8:
hexdata.append(octal(data, 2L));
break;
case 16:
hexdata.append(hex(data, 2L));
break;
default:
throw;
}
hexdata.append(" ");
ansidata.append(data >= 0x20 && data <= 0x7e ? (char)data : '.');
} else {
Expand Down
1 change: 1 addition & 0 deletions hiro/qt/widget/hex-edit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ struct pHexEdit : pWidget {
Declare(HexEdit, Widget)

auto setAddress(u32 address) -> void;
auto setBase(u8 base) -> void;
auto setBackgroundColor(Color color) -> void;
auto setColumns(u32 columns) -> void;
auto setForegroundColor(Color color) -> void;
Expand Down
Loading
Loading