Skip to content

Commit

Permalink
Fix sign extend
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhampson committed Dec 17, 2018
1 parent 1c5ca25 commit edac682
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/ProgramRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export class ProgramRunner {
case Traps.TRAP_GETC:
/* TRAP GETC */
/* read a single ASCII char */
let inputData = this.getInputAsync();
this.registers[Registers.R_R0] = this.get_char();
break;
case Traps.TRAP_OUT:
Expand Down Expand Up @@ -284,6 +285,8 @@ export class ProgramRunner {
private sign_extend(x:number, bitCount:number):number {
if ((x >> (bitCount - 1)) & 1) {
x |= (0xFFFF << bitCount);
// Need to and it with this so we don't exceed 16-bits
x &= 0xFFFF;
}
return x;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ for (var i = 0; i < imageData.length; i += 2) {
imageDataUInt16[i/2] = uint16;
}

let runner = new ProgramRunner(['c']);
let runner = new ProgramRunner([]);
runner.readImage(imageDataUInt16);
runner.run();

0 comments on commit edac682

Please sign in to comment.