aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2020-06-03 21:36:56 -0700
committerAustin Adams <git@austinjadams.com>2020-06-03 21:36:56 -0700
commit77bdb81abf9106568e2ce3ea9f1bb0d54bb935ef (patch)
tree0c275cc21c32f77c4b64dc434d2e6ab46ecaed14
parent0e8ee6496d2efa3b1dc9b1171b9e0cfd663dc74a (diff)
downloadnovice-77bdb81abf9106568e2ce3ea9f1bb0d54bb935ef.tar.gz
novice-77bdb81abf9106568e2ce3ea9f1bb0d54bb935ef.tar.xz
Improve register displaying
-rw-r--r--packages/novice-web/novice-web/components/GuiDebugger.tsx28
-rw-r--r--packages/novice-web/style.css18
-rw-r--r--packages/novice/novice/index.ts7
-rw-r--r--packages/novice/novice/util.ts24
-rw-r--r--tsconfig.json3
5 files changed, 65 insertions, 15 deletions
diff --git a/packages/novice-web/novice-web/components/GuiDebugger.tsx b/packages/novice-web/novice-web/components/GuiDebugger.tsx
index 9894281..6d5ac28 100644
--- a/packages/novice-web/novice-web/components/GuiDebugger.tsx
+++ b/packages/novice-web/novice-web/components/GuiDebugger.tsx
@@ -1,4 +1,5 @@
-import { FullMachineState, getIsa, Isa, fmtHex, Symbols, BaseSymbols } from 'novice';
+import { FullMachineState, getIsa, Isa, fmtBinOrHex, fmtHex, range, Symbols,
+ BaseSymbols } from 'novice';
import * as React from 'react';
import { VariableSizeGrid as Grid } from 'react-window';
import { AssemblerFrontendMessage, AssemblerWorkerMessage } from '../workers/assembler';
@@ -58,7 +59,7 @@ export class GuiDebugger extends React.Component<GuiDebuggerProps,
}
private onError(err: ErrorEvent) {
- console.log(err);
+ console.error(err);
}
private onDebuggerMessage(msg: DebuggerWorkerMessage) {
@@ -97,10 +98,26 @@ export class GuiDebugger extends React.Component<GuiDebuggerProps,
}
public render() {
+ const registers = this.isa.spec.regs.map(reg => {
+ let values;
+
+ if (reg.kind === 'reg-range') {
+ values = range(reg.count).map(i => (<div className='reg'>{
+ reg.prefix + i + ': ' + fmtBinOrHex(this.state.state.regs.range[reg.prefix][i], reg.bits)
+ }</div>));
+ } else if (reg.kind === 'reg') {
+ values = <div className='reg'>{reg.name + ': ' + fmtBinOrHex(this.state.state.regs.solo[reg.name], reg.bits)}</div>;
+ } else {
+ const _: never = reg;
+ }
+
+ return (<div className='reg-family'>{values}</div>);
+ });
+
const rowHeight = 20;
const cols = [20, 80, 80, 80, 200];
const colVal: ((addr: number) => string)[] = [
- addr => (this.state.state.pc == addr)? '►' : '',
+ addr => (this.state.state.pc === addr)? '►' : '',
addr => this.fmtAddr(addr),
addr => this.fmtWord(this.isa.stateLoad(this.state.state, addr)),
addr => this.isa.stateLoad(this.state.state, addr).toString(10),
@@ -118,7 +135,10 @@ export class GuiDebugger extends React.Component<GuiDebuggerProps,
return (
<div className='gui-wrapper'>
- <div className='memory-view'>
+ <div className='state-view'>
+ <div className='register-view'>
+ {registers}
+ </div>
<Grid columnCount={cols.length}
columnWidth={i => cols[i]}
rowCount={Math.pow(2, this.isa.spec.mem.space)}
diff --git a/packages/novice-web/style.css b/packages/novice-web/style.css
index 7cb8c5e..9ace8ca 100644
--- a/packages/novice-web/style.css
+++ b/packages/novice-web/style.css
@@ -7,9 +7,25 @@ html, body {
margin: 0 auto;
}
-.memory-view {
+.state-view {
display: inline-block;
font-family: monospace;
+ width: 500px;
+}
+
+.state-view .register-view {
+ display: block;
+ margin: 0 0 16px 0;
+}
+
+.state-view .register-view .reg-family {
+ display: block;
+ margin: 0 0 4px 0;
+}
+
+.state-view .register-view .reg {
+ display: inline-block;
+ margin: 0 8px 0 0;
}
.assemble-form {
diff --git a/packages/novice/novice/index.ts b/packages/novice/novice/index.ts
index 241a07b..ed4301b 100644
--- a/packages/novice/novice/index.ts
+++ b/packages/novice/novice/index.ts
@@ -7,8 +7,8 @@ import { AliasContext, AliasFields, AliasSpec, Assembly, BaseSymbols, Fields,
RegIdentifier, RegisterOperand, Section, StringOperand,
Symbols, SymbTable } from './isa';
import { Debugger, Memory, Simulator } from './simulator';
-import { forceUnsigned, maskTo, maxUnsignedVal, padStr, sextTo,
- fmtHex } from './util';
+import { forceUnsigned, maskTo, maxUnsignedVal, padStr, range, sextTo,
+ fmtBin, fmtBinOrHex, fmtHex } from './util';
export { //// assembler
Assembler, AssemblerConfig, getParser, getGenerator, getOpSpec,
@@ -30,4 +30,5 @@ export { //// assembler
//// simulator
Debugger, Simulator, Memory,
//// util
- forceUnsigned, maskTo, maxUnsignedVal, sextTo, padStr, fmtHex };
+ forceUnsigned, maskTo, maxUnsignedVal, range, sextTo, padStr,
+ fmtBin, fmtBinOrHex, fmtHex };
diff --git a/packages/novice/novice/util.ts b/packages/novice/novice/util.ts
index b069fc2..8a8dc6f 100644
--- a/packages/novice/novice/util.ts
+++ b/packages/novice/novice/util.ts
@@ -1,14 +1,14 @@
-function maskTo(val: number, bits: number): number {
+export function maskTo(val: number, bits: number): number {
return val & ((bits === 32) ? -1 : ~(-1 << bits));
}
-function sextTo(val: number, bits: number): number {
+export function sextTo(val: number, bits: number): number {
return (bits === 32 || (val & (1 << (bits - 1))) === 0)
? val
: val | (-1 << bits);
}
-function maxUnsignedVal(bits: number): number {
+export function maxUnsignedVal(bits: number): number {
// Need to do this instead of using bitwise operators to get around
// the fact that js bitwise operators work on 32-bit two's complement ints
return Math.pow(2, bits) - 1;
@@ -17,11 +17,11 @@ function maxUnsignedVal(bits: number): number {
// 0x80000001 & 0xffffffff = -0x7fffffff in js. This is pretty confusing
// behavior when dealing with 32-bit addresses, so get the expected
// value by clearing the MSB and then adding 2^31 to set it again.
-function forceUnsigned(val: number, bits: number): number {
+export function forceUnsigned(val: number, bits: number): number {
return (bits < 32 || !(val & (1 << 31))) ? val : (val & ~(1 << 31)) + Math.pow(2, 31);
}
-function padStr(str: string, to: number, withChar: string, right?: boolean) {
+export function padStr(str: string, to: number, withChar: string, right?: boolean) {
const need = to - str.length;
for (let i = 0; i < need; i++) {
str = right ? str + withChar : withChar + str;
@@ -29,9 +29,19 @@ function padStr(str: string, to: number, withChar: string, right?: boolean) {
return str;
}
-function fmtHex(val: number, bits: number): string {
+export function fmtHex(val: number, bits: number): string {
return '0x' + padStr(forceUnsigned(val, bits).toString(16),
Math.ceil(bits / 4), '0');
}
-export { forceUnsigned, maskTo, maxUnsignedVal, sextTo, padStr, fmtHex };
+export function fmtBin(val: number, bits: number): string {
+ return '0b' + padStr(forceUnsigned(val, bits).toString(2), bits, '0');
+}
+
+export function fmtBinOrHex(val: number, bits: number): string {
+ return (bits <= 4) ? fmtBin(val, bits) : fmtHex(val, bits);
+}
+
+export function range(n: number): number[] {
+ return [...new Array(n).keys()];
+}
diff --git a/tsconfig.json b/tsconfig.json
index c4c9394..4ac378c 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,5 +1,8 @@
{
"compilerOptions": {
+ "target": "ES6",
+ "module": "CommonJS",
+ "moduleResolution": "Node",
"strict": true,
"lib": ["ES6"]
}