Skip to content

Commit

Permalink
Merge branch 'master' of github.com:parraman/asm-simulator
Browse files Browse the repository at this point in the history
Initial commit of the events log service.
  • Loading branch information
parraman committed Dec 7, 2017
2 parents 63b4414 + 710cc34 commit e554114
Show file tree
Hide file tree
Showing 27 changed files with 1,271 additions and 1,003 deletions.
345 changes: 175 additions & 170 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asm-simulator",
"version": "1.3",
"version": "1.3.0",
"license": "MIT",
"scripts": {
"ng": "ng",
Expand Down
7 changes: 6 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<h4>Code <small>(<a style="cursor: pointer" (click)="setCodeSample(1)">Sample 1</a>, <a style="cursor: pointer" (click)="setCodeSample(2)">Sample 2</a>, <a style="cursor: pointer" (click)="setCodeSample(3)">Sample 3</a>, <a style="cursor: pointer" (click)="setCodeSample(4)">Sample 4</a>, <a style="cursor: pointer" (click)="setCodeSample(5)">Sample 5</a>)</small></h4>
<h4>Code <small>(<a (click)="setCodeSample(1)">Sample 1</a>, <a (click)="setCodeSample(2)">Sample 2</a>, <a (click)="setCodeSample(3)">Sample 3</a>, <a (click)="setCodeSample(4)">Sample 4</a>, <a (click)="setCodeSample(5)">Sample 5</a>)</small></h4>
<form>
<textarea #codeTextArea name="code" class="source-code"></textarea>
<button class="btn btn-default btn-secondary" type="button" style="background-image:none;" (click)="assemble()">Assemble </button>
</form>
</div>
</div>
<div class="panel panel-default">
<div class="panel-body" style="padding-bottom: 10px">
<app-events-log-viewer [isRunning]="isRunning"></app-events-log-viewer>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
Expand Down
37 changes: 22 additions & 15 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { Subscription } from 'rxjs/Subscription';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/timer';

import { CPURegisterIndex, CPURegisterOperation, CPURegisterOperationType, SRBit } from './cpuregs';
import {
CPURegisterIndex, CPURegisterOperation, CPURegisterOperationType, SRBit,
CPURegisterRegularOpParams, CPURegisterBitOpParams
} from './cpuregs';
import { IrqCtrlService } from './irqctrl.service';
import { TimerService } from './timer.service';
import { KeypadComponent } from './keypad/keypad.component';
Expand All @@ -17,7 +20,7 @@ import { TextualDisplayComponent } from './textual-display/textual-display.compo
import { ErrorBarComponent } from './error-bar/error-bar.component';

import * as CodeMirror from 'codemirror';
import {InstructionSet, instructionSet} from './instrset';
import { instructionSet } from './instrset';

const WRAP_CLS = 'CodeMirror-activeline';
const BACK_CLS = 'CodeMirror-activeline-background';
Expand Down Expand Up @@ -263,8 +266,6 @@ export class AppComponent implements AfterViewInit {
this.instance.state.activeLine = undefined;
this.instance.on('beforeSelectionChange', () => {

const mode = this.instance.getMode();

if (this.instance.state.activeLine) {

this.instance.removeLineClass(this.instance.state.activeLine, 'wrap', WRAP_CLS);
Expand All @@ -283,16 +284,16 @@ export class AppComponent implements AfterViewInit {

private processCPURegisterOperation(cpuRegisterOperation: CPURegisterOperation) {

if (cpuRegisterOperation.index === CPURegisterIndex.IP &&
cpuRegisterOperation.operationType === CPURegisterOperationType.WRITE) {
if (cpuRegisterOperation.operationType === CPURegisterOperationType.WRITE &&
cpuRegisterOperation.data.index === CPURegisterIndex.IP) {

this.currentIP = cpuRegisterOperation.value;
this.currentIP = cpuRegisterOperation.data.value;

if (this.isRunning === true) {

if (this.mapping && this.mapping.has(cpuRegisterOperation.value)) {
if (this.mapping && this.mapping.has(this.currentIP)) {

const lineNumber = this.mapping.get(cpuRegisterOperation.value);
const lineNumber = this.mapping.get(this.currentIP);
const info = this.instance.lineInfo(lineNumber);

if (info.gutterMarkers) {
Expand All @@ -310,9 +311,9 @@ export class AppComponent implements AfterViewInit {

if (this.isRunning === false) {

if (this.mapping && this.mapping.has(cpuRegisterOperation.value)) {
if (this.mapping && this.mapping.has(this.currentIP)) {

const line = this.mapping.get(cpuRegisterOperation.value);
const line = this.mapping.get(this.currentIP);
this.markLine(line);

const clientHeight = this.instance.getScrollInfo().clientHeight;
Expand All @@ -331,10 +332,16 @@ export class AppComponent implements AfterViewInit {
}
}

} else if (cpuRegisterOperation.index === CPURegisterIndex.SR &&
cpuRegisterOperation.operationType === CPURegisterOperationType.WRITE) {
} else if (cpuRegisterOperation.operationType === CPURegisterOperationType.WRITE &&
(<CPURegisterRegularOpParams>cpuRegisterOperation.data).index === CPURegisterIndex.SR) {

this.isCPUHalted = (cpuRegisterOperation.data.value & (1 << SRBit.HALT)) !== 0;

} else if (cpuRegisterOperation.operationType === CPURegisterOperationType.WRITE_BIT &&
(<CPURegisterBitOpParams>cpuRegisterOperation.data).index === CPURegisterIndex.SR &&
(<CPURegisterBitOpParams>cpuRegisterOperation.data).bitNumber === SRBit.HALT) {

this.isCPUHalted = (cpuRegisterOperation.value & (1 << SRBit.HALT)) !== 0;
this.isCPUHalted = cpuRegisterOperation.data.value === 1;

}

Expand Down Expand Up @@ -424,7 +431,7 @@ export class AppComponent implements AfterViewInit {
this.isRunning = true;

this.timerSubscription = Observable.timer(1, this.speed).subscribe(
(ticks: any) => {
() => {

try {

Expand Down
10 changes: 8 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { IrqCtrlService } from './irqctrl.service';
import { CPUService } from './cpu.service';
import { PreventScrollDirective } from './prevent-scroll.directive';
import { TimerService } from './timer.service';
import { EventsLogViewerComponent } from './events-log-viewer/events-log-viewer.component';
import { ClockService } from './clock.service';
import { EventsLogService } from './events-log.service';

@NgModule({
declarations: [
Expand All @@ -32,7 +35,8 @@ import { TimerService } from './timer.service';
IORegistersViewComponent,
ErrorBarComponent,
AutofocusDirective,
PreventScrollDirective
PreventScrollDirective,
EventsLogViewerComponent
],
imports: [
BrowserModule,
Expand All @@ -45,7 +49,9 @@ import { TimerService } from './timer.service';
ErrorBarService,
IrqCtrlService,
CPUService,
TimerService
TimerService,
ClockService,
EventsLogService
],
bootstrap: [AppComponent]
})
Expand Down
15 changes: 15 additions & 0 deletions src/app/clock.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { TestBed, inject } from '@angular/core/testing';

import { ClockService } from './clock.service';

describe('ClockService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ClockService]
});
});

it('should be created', inject([ClockService], (service: ClockService) => {
expect(service).toBeTruthy();
}));
});
33 changes: 33 additions & 0 deletions src/app/clock.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable } from '@angular/core';

import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class ClockService {

protected clockConsumeTicksSource = new Subject<number>();
public clockConsumeTicks$: Observable<number>;

private ticks = 0;

constructor() {

this.clockConsumeTicks$ = this.clockConsumeTicksSource.asObservable();

}

public consumeTicks(ticks: number) {

this.ticks += ticks;

this.clockConsumeTicksSource.next(ticks);

}
public getClock(): number {

return this.ticks;

}

}
Loading

0 comments on commit e554114

Please sign in to comment.