implement HCF. Add HelloWorld. Cleanup
This commit is contained in:
parent
2e0b67b69e
commit
2207683040
BIN
HelloWorld.bin
Normal file
BIN
HelloWorld.bin
Normal file
Binary file not shown.
|
@ -85,7 +85,7 @@ export class Computer {
|
|||
if (this.current_instr === null) {
|
||||
const parsed_instruction = Computer.parse_instruction(current_byte);
|
||||
if (parsed_instruction === null) {
|
||||
console.log("invalid instruction");
|
||||
// console.log("invalid instruction");
|
||||
this.step_forward();
|
||||
return;
|
||||
}
|
||||
|
@ -104,7 +104,6 @@ export class Computer {
|
|||
}
|
||||
|
||||
if (this.current_instr.params.length !== this.current_instr.params_found) {
|
||||
// console.log(`Parameter count not fulfilled. Found new parameter ${current_byte}`);
|
||||
this.current_instr.params[this.current_instr.params_found] = current_byte;
|
||||
this.current_instr.params_found += 1;
|
||||
}
|
||||
|
@ -137,12 +136,12 @@ export class Computer {
|
|||
case Instr.Print: {
|
||||
const [register_no] = inst.params;
|
||||
const value = this.registers[register_no];
|
||||
console.log(value);
|
||||
// console.log(value);
|
||||
break;
|
||||
}
|
||||
case Instr.Goto: {
|
||||
const [parameter] = inst.params;
|
||||
console.log(`Goto ${parameter}`);
|
||||
// console.log(`Goto ${parameter}`);
|
||||
this.program_counter = parameter;
|
||||
return false;
|
||||
}
|
||||
|
@ -159,7 +158,7 @@ export class Computer {
|
|||
if (register_no >= this.registers.length) {
|
||||
throw new Error(`Got register number ${register_no} in assign register`);
|
||||
}
|
||||
console.log(`Set register ${register_no} to ${new_value}`);
|
||||
// console.log(`Set register ${register_no} to ${new_value}`);
|
||||
this.registers[register_no] = new_value;
|
||||
break;
|
||||
}
|
||||
|
@ -232,10 +231,18 @@ export class Computer {
|
|||
|
||||
const char = String.fromCharCode(ASCIIbyte);
|
||||
|
||||
console.log(char);
|
||||
// console.log(char);
|
||||
$("printout").textContent += char;
|
||||
break;
|
||||
}
|
||||
case Instr.HaltCatchFire: {
|
||||
throw new Error("FIRE FIRE FIRE FIRE");
|
||||
}
|
||||
case Instr.CopyRegReg: {
|
||||
const [register_no_to, register_no_from] = inst.params;
|
||||
this.registers[register_no_to] = this.registers[register_no_from];
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ function main(): void {
|
|||
|
||||
const ui = new UI(container);
|
||||
|
||||
const computer = new Computer(ui.stateUpdateEvent.bind(ui));
|
||||
const computer = new Computer(ui.state_update_event.bind(ui));
|
||||
|
||||
computer.load_program(program);
|
||||
ui.set_step_func(computer.cycle.bind(computer));
|
||||
|
|
62
src/ui.ts
62
src/ui.ts
|
@ -28,43 +28,39 @@ export class UI {
|
|||
for (let i = 0; i < 8; i++) {
|
||||
const reg_cell = el("div", `R_${i}`);
|
||||
reg_cell.textContent = "00";
|
||||
reg_cell.setAttribute("contenteditable", "true");
|
||||
reg_cell.setAttribute("spellcheck", "false");
|
||||
// reg_cell.setAttribute("contenteditable", "true");
|
||||
// reg_cell.setAttribute("spellcheck", "false");
|
||||
registers.appendChild(reg_cell);
|
||||
this.register_cells.push(reg_cell);
|
||||
}
|
||||
// eslint-disable-next-line prefer-arrow-callback
|
||||
registers.addEventListener("input", function (e) {
|
||||
const allowed_chars = "0123456789ABCDEFG";
|
||||
const r = e.target as HTMLElement;
|
||||
let data = (r.textContent as string).toUpperCase();
|
||||
// // eslint-disable-next-line prefer-arrow-callback
|
||||
// registers.addEventListener("input", function (e) {
|
||||
// const allowed_chars = "0123456789ABCDEFG";
|
||||
// const r = e.target as HTMLElement;
|
||||
// let data = (r.textContent as string).toUpperCase();
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (!allowed_chars.includes(data[i])) {
|
||||
data = "00";
|
||||
break;
|
||||
}
|
||||
}
|
||||
// for (let i = 0; i < data.length; i++) {
|
||||
// if (!allowed_chars.includes(data[i])) {
|
||||
// data = "00";
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (data.length > 2) {
|
||||
// data = r.textContent?.substring(0, 2) ?? "00";
|
||||
}
|
||||
e.preventDefault();
|
||||
return false;
|
||||
// r.textContent = ;
|
||||
});
|
||||
// e.preventDefault();
|
||||
// return false;
|
||||
// });
|
||||
|
||||
registers.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
(e.target as HTMLElement).blur();
|
||||
}
|
||||
});
|
||||
registers.addEventListener("blur", (e) => {
|
||||
const allowed_chars = "0123456789ABCDEFG";
|
||||
const r = e.target as HTMLElement;
|
||||
const data = (r.textContent as string).toUpperCase();
|
||||
});
|
||||
// registers.addEventListener("keydown", (e) => {
|
||||
// if (e.key === "Enter") {
|
||||
// e.preventDefault();
|
||||
// (e.target as HTMLElement).blur();
|
||||
// }
|
||||
// });
|
||||
// registers.addEventListener("blur", (e) => {
|
||||
// const allowed_chars = "0123456789ABCDEFG";
|
||||
// const r = e.target as HTMLElement;
|
||||
// const data = (r.textContent as string).toUpperCase();
|
||||
// });
|
||||
|
||||
this.registers = registers;
|
||||
|
||||
|
@ -95,7 +91,7 @@ export class UI {
|
|||
});
|
||||
}
|
||||
|
||||
start_auto(speed: number = 0): void {
|
||||
start_auto(speed: number = 200): void {
|
||||
if (this.step_func === null) {
|
||||
return;
|
||||
}
|
||||
|
@ -125,7 +121,7 @@ export class UI {
|
|||
this.step_func = f;
|
||||
}
|
||||
|
||||
stateUpdateEvent(state: ComputerState): void {
|
||||
state_update_event(state: ComputerState): void {
|
||||
for (let i = 0; i < 256; i++) {
|
||||
const current = this.program_memory_cells[i];
|
||||
current.className = "";
|
||||
|
|
Loading…
Reference in a new issue