Add memory debugger

This commit is contained in:
Yoshi Sugawara 2021-01-19 11:25:44 -10:00
parent 4f468b765a
commit bb56179099
9 changed files with 313 additions and 0 deletions

View File

@ -91,6 +91,7 @@
<key>UIAppFonts</key>
<array>
<string>ShastonHi640.ttf</string>
<string>PrintChar21.ttf</string>
</array>
<key>UIFileSharingEnabled</key>
<true/>

View File

@ -247,6 +247,9 @@
928410581CA8443A00DC5D93 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 928410571CA8443A00DC5D93 /* Images.xcassets */; };
92B9EADF24D3369700E6CFB2 /* EmulatorKeyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92B9EADE24D3369700E6CFB2 /* EmulatorKeyboard.swift */; };
92E2063225AADFB000AE3F28 /* PreviewUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92E2063125AADF6E00AE3F28 /* PreviewUI.swift */; };
92FA0F2425B52EA200663577 /* EmuWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 92FA0F2325B52EA200663577 /* EmuWrapper.mm */; };
92FA0F2A25B5353D00663577 /* DebugMemoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92FA0F2925B5353D00663577 /* DebugMemoryViewController.swift */; };
92FA0F2D25B59EF100663577 /* PrintChar21.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 92FA0F2C25B59EF100663577 /* PrintChar21.ttf */; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
@ -600,6 +603,10 @@
92B9EADD24D3369600E6CFB2 /* ActiveGS-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ActiveGS-Bridging-Header.h"; sourceTree = "<group>"; };
92B9EADE24D3369700E6CFB2 /* EmulatorKeyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmulatorKeyboard.swift; sourceTree = "<group>"; };
92E2063125AADF6E00AE3F28 /* PreviewUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewUI.swift; sourceTree = "<group>"; };
92FA0F2325B52EA200663577 /* EmuWrapper.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = EmuWrapper.mm; sourceTree = "<group>"; };
92FA0F2625B52EC000663577 /* EmuWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EmuWrapper.h; sourceTree = "<group>"; };
92FA0F2925B5353D00663577 /* DebugMemoryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugMemoryViewController.swift; sourceTree = "<group>"; };
92FA0F2C25B59EF100663577 /* PrintChar21.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = PrintChar21.ttf; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -1016,6 +1023,9 @@
92B9EADE24D3369700E6CFB2 /* EmulatorKeyboard.swift */,
92E2063125AADF6E00AE3F28 /* PreviewUI.swift */,
92B9EADD24D3369600E6CFB2 /* ActiveGS-Bridging-Header.h */,
92FA0F2325B52EA200663577 /* EmuWrapper.mm */,
92FA0F2625B52EC000663577 /* EmuWrapper.h */,
92FA0F2925B5353D00663577 /* DebugMemoryViewController.swift */,
);
name = Common.iphone;
path = ../Common.iphone;
@ -1115,6 +1125,7 @@
7E5148141CA6B5CE005DA0A6 /* floppy_eject.wav */,
7E5148151CA6B5CE005DA0A6 /* logo_apple2.png */,
7E5148161CA6B5CE005DA0A6 /* logo_apple2gs.png */,
92FA0F2C25B59EF100663577 /* PrintChar21.ttf */,
7E5148171CA6B5CE005DA0A6 /* Search Skip Search 1.wav */,
7E5148181CA6B5CE005DA0A6 /* Search Skip Search 2.wav */,
7E5148191CA6B5CE005DA0A6 /* Search Skip Search 3.wav */,
@ -1306,6 +1317,7 @@
09AF980F1283F12200083D60 /* starwizard_4.png in Resources */,
09AF98101283F12200083D60 /* starwizard_5.png in Resources */,
09AF98111283F12200083D60 /* starwizard.png in Resources */,
92FA0F2D25B59EF100663577 /* PrintChar21.ttf in Resources */,
7E51482C1CA6B5CE005DA0A6 /* Search Skip Search 3.wav in Resources */,
09D8BCF91285EFE900B6D785 /* miniprix_1.png in Resources */,
09D8BCFC1285EFFA00B6D785 /* miniprix_2.png in Resources */,
@ -1341,6 +1353,7 @@
9222DD461CBECF2300B321B9 /* main.mm in Sources */,
09BB434511D92F65005ADA46 /* ActiveDownloadMac.cpp in Sources */,
09BB434711D92F65005ADA46 /* CEmulatorCtrlMac.cpp in Sources */,
92FA0F2A25B5353D00663577 /* DebugMemoryViewController.swift in Sources */,
09BB43B011D92F70005ADA46 /* activeconfig.cpp in Sources */,
09BB43B111D92F70005ADA46 /* ActiveDownload.cpp in Sources */,
92B9EADF24D3369700E6CFB2 /* EmulatorKeyboard.swift in Sources */,
@ -1429,6 +1442,7 @@
0941E6AF16720886003E0411 /* simplexml.cpp in Sources */,
09520D8316AEF8130065E84A /* driver.cpp in Sources */,
09520D8916AEF8250065E84A /* activegs_driver.cpp in Sources */,
92FA0F2425B52EA200663577 /* EmuWrapper.mm in Sources */,
09520D8E16AEF8650065E84A /* apple2e.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -3,3 +3,5 @@
//
#import "KeyMapper.h"
#import "EmuWrapper.h"

View File

@ -0,0 +1,215 @@
//
// DebugMemoryViewController.swift
// ActiveGS
//
// Created by Yoshi Sugawara on 1/17/21.
//
import Foundation
import UIKit
class EmuMemoryModel {
// make this static for now
let numToDisplayPerCell = 8
let maxMemorySize = 128 * 1024
let slowMemory = EmuWrapper.slowMemory()
func offset(for indexPath: IndexPath) -> Int {
return indexPath.row * numToDisplayPerCell
}
func hexStrings(for indexPath: IndexPath) -> [String] {
let startIndex = offset(for: indexPath)
let endIndex = min(maxMemorySize, startIndex + numToDisplayPerCell)
var row = [String]()
guard let slowMemory = slowMemory else {
return row
}
for i in startIndex..<endIndex {
row.append(String(format: "%02X", slowMemory[i]))
}
return row
}
func getMemoryHexString(at address: Int) -> String {
guard address > 0 && address < maxMemorySize else {
print("Cannot get memory: address out of range \(address) > \(maxMemorySize)")
return ""
}
guard let slowMemory = slowMemory else {
return ""
}
let value = slowMemory[address]
return String(format: "%02X", value)
}
func getMemoryHeaderString(for address: Int) -> String {
return String(format: "%02X", address)
}
func setMemory(at address:Int, value: UInt8) {
guard address > 0 && address < maxMemorySize else {
print("Cannot set memory: address out of range \(address) > \(maxMemorySize)")
return
}
guard let slowMemory = slowMemory else {
return
}
slowMemory[address] = value
}
}
class DebugMemoryCell: UITableViewCell {
static let identifier = "DebugMemoryCell"
var offset: Int?
lazy var stackView: UIStackView = {
let view = UIStackView(frame: .zero)
view.translatesAutoresizingMaskIntoConstraints = false
view.axis = .horizontal
view.spacing = 8.0
view.alignment = .center
return view
}()
let addressLabel: UILabel = {
let label = UILabel(frame: .zero)
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont(name: "Print Char 21", size: 16)
label.textColor = .yellow
label.setContentHuggingPriority(.defaultHigh, for: .horizontal)
return label
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(stackView)
stackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 8.0).isActive = true
stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 8.0).isActive = true
stackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8.0).isActive = true
stackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 8.0).isActive = true
backgroundColor = .clear
selectionStyle = .none
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func updateWith(offset: Int, hexMemoryValues: [String]) {
self.offset = offset
stackView.arrangedSubviews.forEach{ $0.removeFromSuperview() }
addressLabel.text = String(format: "%04X:", offset)
stackView.addArrangedSubview(addressLabel)
stackView.setCustomSpacing(3, after: addressLabel)
for (index, hexValue) in hexMemoryValues.enumerated() {
let button = UIButton(type: .custom)
button.setTitle(hexValue, for: .normal)
button.titleLabel?.font = UIFont(name: "Print Char 21", size: 16)
button.setTitleColor(.green, for: .normal)
button.tag = index
button.addTarget(self, action: #selector(didTapOnButton(_:)), for: .touchUpInside)
stackView.addArrangedSubview(button)
}
let spacer = UIView()
spacer.setContentHuggingPriority(.defaultLow, for: .horizontal)
stackView.addArrangedSubview(spacer)
}
@objc func didTapOnButton(_ button: UIButton) {
let memoryAddr = String(format:"%04X",(offset ?? 0) + button.tag)
print("tapped on button index \(button.tag), address: \(memoryAddr) ")
}
}
@objc class DebugMemoryViewController: UIViewController {
let memoryModel = EmuMemoryModel()
let titleLabel: UILabel = {
let label = UILabel(frame: .zero)
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont(name: "Print Char 21", size: 14)
label.textColor = .white
label.text = "Memory Debugger"
return label
}()
let dismissButton: UIButton = {
let button = UIButton(type: .custom)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("[X]", for: .normal)
button.addTarget(self, action: #selector(closeTapped(_:)), for: .touchUpInside)
button.titleLabel?.font = UIFont(name: "Print Char 21", size: 12)
button.setTitleColor(.red, for: .normal)
return button
}()
let tableView: UITableView = {
let view = UITableView(frame: .zero)
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .clear
return view
}()
init() {
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupView() {
view.addSubview(titleLabel)
view.addSubview(tableView)
view.addSubview(dismissButton)
titleLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
titleLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16).isActive = true
tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 8).isActive = true
tableView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -8).isActive = true
tableView.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 16).isActive = true
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
dismissButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -8).isActive = true
dismissButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 8.0).isActive = true
view.backgroundColor = .black
}
func setupTableView() {
tableView.dataSource = self
tableView.register(DebugMemoryCell.self, forCellReuseIdentifier: DebugMemoryCell.identifier)
}
override func viewDidLoad() {
super.viewDidLoad()
setupView()
setupTableView()
}
@objc func closeTapped(_ sender: UIButton) {
dismiss(animated: true) {
EmuWrapper.resume()
}
}
}
extension DebugMemoryViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var numRows = memoryModel.maxMemorySize / memoryModel.numToDisplayPerCell
if memoryModel.maxMemorySize % memoryModel.numToDisplayPerCell > 0 {
numRows += 1
}
return numRows
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: DebugMemoryCell.identifier, for: indexPath) as! DebugMemoryCell
let memoryVals = memoryModel.hexStrings(for: indexPath)
cell.updateWith(offset: memoryModel.offset(for: indexPath), hexMemoryValues: memoryVals)
return cell
}
}

View File

@ -0,0 +1,22 @@
//
// EmuWrapper.h
// activegs
//
// Created by Yoshi Sugawara on 1/17/21.
//
#ifndef EmuWrapper_h
#define EmuWrapper_h
#endif /* EmuWrapper_h */
#import <Foundation/Foundation.h>
@interface EmuWrapper: NSObject
+(unsigned char*) slowMemory;
+(void)pause;
+(void)resume;
@end

View File

@ -0,0 +1,29 @@
//
// EmuWrapper.m
// ActiveGS
//
// Created by Yoshi Sugawara on 1/17/21.
//
#import <Foundation/Foundation.h>
#import "EmuWrapper.h"
#include "../Common.osx/cemulatorctrlmac.h"
#include "../kegs/Src/defc.h"
#include "../kegs/Src/sim65816.h"
@implementation EmuWrapper
+(unsigned char*) slowMemory {
return g_slow_memory_ptr;
}
+(void)pause {
r_sim65816.pause();
}
+(void)resume {
r_sim65816.resume();
}
@end

View File

@ -23,6 +23,7 @@
#include "../Common/ActiveDownload.h"
#import "MfiGameControllerHandler.h"
#import "GameControllerKeyRemapController.h"
#import "ActiveGS-Swift.h"
#ifdef ACTIVEGS_CUSTOMKEYS
#include "UICustomKey.h"
@ -1115,6 +1116,12 @@ extern int x_frame_rate ;
[self presentViewController:remapController animated:YES completion:nil];
}
-(void) memoryDebuggerButtonPressed:(id)sender {
r_sim65816.pause();
DebugMemoryViewController *controller = [[DebugMemoryViewController alloc] init];
[self presentViewController:controller animated:YES completion:nil];
}
//
-(void)addRuntimeControls
{
@ -1236,6 +1243,19 @@ extern int x_frame_rate ;
[remapControlsButton addTarget:self action:@selector(remapControlsButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.runtimeControlsOptions addSubview:remapControlsButton];
l += LINEHEIGHT;
l += 2.0;
UIButton *memoryDebuggerButton = [UIButton buttonWithType:UIButtonTypeCustom];
memoryDebuggerButton.frame = CGRectMake(OPTIONMARGIN,l,OPTIONWIDTH,LINEHEIGHT);
[memoryDebuggerButton setTitle:@"Memory Debugger" forState:UIControlStateNormal];
memoryDebuggerButton.titleLabel.font = [UIFont systemFontOfSize:12*res];
memoryDebuggerButton.backgroundColor = [UIColor clearColor];
memoryDebuggerButton.layer.borderWidth = 1.0f;
memoryDebuggerButton.layer.borderColor = [self.view.tintColor CGColor];
[memoryDebuggerButton addTarget:self action:@selector(memoryDebuggerButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.runtimeControlsOptions addSubview:memoryDebuggerButton];
l += LINEHEIGHT;
nbs++;

View File

@ -370,6 +370,16 @@ void x_init_persistent_path(MyString& hp)
[[pManager getBrowserView] updateView ];
// fonts!
for (NSString *family in [UIFont familyNames]) {
NSArray *fontNames = [UIFont fontNamesForFamilyName:family];
NSLog(@"Family: %@", family);
for (NSString *name in fontNames) {
NSLog(@"Font name: %@",name);
}
NSLog(@"");
}
[self.window makeKeyAndVisible];
#ifdef HANDLE_URL

BIN
Common.res/PrintChar21.ttf Normal file

Binary file not shown.