Skip to content

Commit

Permalink
fixed some bugs, persistent settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AdinAck committed Oct 29, 2022
1 parent 2f91df3 commit 999939a
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 14 deletions.
28 changes: 23 additions & 5 deletions LEGv8-Simulator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
402265AB290DE70F00CABE58 /* Registers */ = {
isa = PBXGroup;
children = (
40D605CE28E7520500654D3C /* RegisterView.swift */,
4095520928EC811E00697ED9 /* RegisterRowView.swift */,
40D605CC28E74A2F00654D3C /* FlagView.swift */,
);
path = Registers;
sourceTree = "<group>";
};
402265AC290DE71800CABE58 /* Memory */ = {
isa = PBXGroup;
children = (
40D605D028E7523500654D3C /* MemoryView.swift */,
4095520D28ED0F6D00697ED9 /* MemoryValueColumnView.swift */,
);
path = Memory;
sourceTree = "<group>";
};
403941F22904A63C005403A7 /* LEGv8-Simulator-CLI */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -168,12 +187,9 @@
isa = PBXGroup;
children = (
4043649528E0C4020052F25D /* ContentView.swift */,
40D605D028E7523500654D3C /* MemoryView.swift */,
4095520D28ED0F6D00697ED9 /* MemoryValueColumnView.swift */,
407923F329071E06000CA218 /* HistoryView.swift */,
40D605CE28E7520500654D3C /* RegisterView.swift */,
4095520928EC811E00697ED9 /* RegisterRowView.swift */,
40D605CC28E74A2F00654D3C /* FlagView.swift */,
402265AB290DE70F00CABE58 /* Registers */,
402265AC290DE71800CABE58 /* Memory */,
4080D12928E40CAD00DCA947 /* Console */,
4080D12828E40CA500DCA947 /* Settings */,
);
Expand Down Expand Up @@ -513,6 +529,7 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "LEGv8-Simulator/Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -545,6 +562,7 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "LEGv8-Simulator/Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
6 changes: 5 additions & 1 deletion LEGv8-Simulator/Models/SettingsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import Foundation

class SettingsModel: ObservableObject {
class SettingsModel: ObservableObject, Equatable {
@Published var executionLimit: Int = 1000
@Published var buildOnType: Bool = false

static func == (lhs: SettingsModel, rhs: SettingsModel) -> Bool {
lhs.executionLimit == rhs.executionLimit && lhs.buildOnType == rhs.buildOnType
}
}
7 changes: 4 additions & 3 deletions LEGv8-Simulator/Utils/Interpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Interpreter: ObservableObject {
@Published var programCounter: Int = 0
var executionLimit: Int = 0

@Published var lastInstruction: String = ""
@Published var lastTouchedRegister: String?
@Published var lastTouchedMemory: Int64?
@Published var lastUsedRegisters: [String] = []
Expand All @@ -55,7 +56,7 @@ class Interpreter: ObservableObject {
var labelMap: [String: Int] = [:]
var dataMap: [String: Int64] = [:]

private var dataPointer: Int64 = 1
private var dataPointer: Int64 = 0

func goToEntryPoint() {
lexer.cursor = labelMap["main"]!
Expand Down Expand Up @@ -100,7 +101,7 @@ class Interpreter: ObservableObject {
programCounter = 0
log = []
history = History()
dataPointer = 1
dataPointer = 0

running = true
}
Expand Down Expand Up @@ -158,7 +159,6 @@ class Interpreter: ObservableObject {
private func loadLong(_ number: Int64, _ label: String, _ offset: Int64) {
let address = dataMap[label]! + offset * 8
cpu.memory[address] = Memory(id: address, value: number)
// dataPointer += 8 // long is 8 bytes
}

// branching
Expand Down Expand Up @@ -260,6 +260,7 @@ class Interpreter: ObservableObject {

do {
let (instruction, arguments) = try lexer.parseNextLine()
lastInstruction = instruction

print("[Interpreter] [\(mode)] Instruction: \(instruction), Arguments: \(arguments)")

Expand Down
1 change: 1 addition & 0 deletions LEGv8-Simulator/Views/Console/ConsoleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct ConsoleView: View {
.padding(.leading, 8)
.padding(.top, 8)
.help("Step over")
.disabled(interpreter.lastInstruction != "bl")

Spacer()
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion LEGv8-Simulator/Views/Settings/AboutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct AboutView: View {
let version: String = "0.1.5 (Beta)"
let version: String = "0.1.6 (Beta)"

var body: some View {
HStack {
Expand Down
17 changes: 14 additions & 3 deletions LEGv8-Simulator/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ struct SettingsView: View {
@EnvironmentObject var model: SettingsModel
@State var execLimitString: String = ""

@AppStorage("executionLimit") var executionLimit: Int = 1000
@AppStorage("buildOnType") var buildOnType: Bool = false

var body: some View {
TabView() {
List {
Expand All @@ -22,20 +25,28 @@ struct SettingsView: View {
.frame(width: 100)
.onChange(of: execLimitString) { newValue in
if let val = Int(newValue) {
model.executionLimit = val
executionLimit = val
}
}
}

Toggle("Build on type", isOn: $model.buildOnType)
Toggle("Build on type", isOn: $buildOnType)
.toggleStyle(.switch)
}
.frame(width: 400, height: 400)
.tabItem {
Label("Settings", systemImage: "gear")
}
.onAppear {
execLimitString = String(model.executionLimit)
execLimitString = String(executionLimit)
model.executionLimit = executionLimit
model.buildOnType = buildOnType
}
.onChange(of: executionLimit) { newValue in
model.executionLimit = executionLimit
}
.onChange(of: buildOnType) { newValue in
model.buildOnType = buildOnType
}

AboutView()
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ The execution of the file is extremely verbose and any assembly or runtime error

# TODO
- Line by line execution in monaco editor (hard)
- User settings
- *Build on type* is a bit laggy, perhaps make emulation async

## Unimplemented instructions
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 999939a

Please sign in to comment.