Skip to content

Commit

Permalink
Format with Prettier (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther authored Oct 27, 2023
1 parent 4a9d496 commit e1d6b26
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 32 deletions.
76 changes: 66 additions & 10 deletions components/src/chips/alu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,72 @@ export const ALUComponent = ({
<div>
<span>ALU</span>
<svg width="250" height="250" xmlns="http://www.w3.org/2000/svg">
<g>
<rect x="1" y="20" height="85" width="70" fill="black" />
<rect x="1" y="145" height="85" width="70" fill="black" />
<rect x="180" y="95" height="60" width="70" fill="black" />
<polygon points="70,10 180,85 180,165 70,240 70,135 90,125 70,115" stroke="#000" fill="#6D97AB"/>
<text xmlSpace="preserve" text-anchor="middle" font-family="Noto Sans JP" font-size="14" stroke-width="0" id="svg_9" y="63" x="35" stroke="white" fill="#ffffff">{A}</text>
<text xmlSpace="preserve" text-anchor="middle" font-family="Noto Sans JP" font-size="14" id="svg_10" y="188" x="35" stroke-width="0" stroke="white" fill="#ffffff">{D}</text>
<text xmlSpace="preserve" text-anchor="middle" font-family="Noto Sans JP" font-size="14" id="svg_11" y="125" x="215" stroke-width="0" stroke="white" fill="#ffffff">{out}</text>
<text xmlSpace="preserve" text-anchor="middle" font-family="Noto Sans JP" font-size="14" id="svg_13" y="125" x="135" stroke-width="0" stroke="white" fill="#ffffff">{COMMANDS_ALU.op[op] ?? "(??)"}</text>
</g>
<g>
<rect x="1" y="20" height="85" width="70" fill="black" />
<rect x="1" y="145" height="85" width="70" fill="black" />
<rect x="180" y="95" height="60" width="70" fill="black" />
<polygon
points="70,10 180,85 180,165 70,240 70,135 90,125 70,115"
stroke="#000"
fill="#6D97AB"
/>
<text
xmlSpace="preserve"
text-anchor="middle"
font-family="Noto Sans JP"
font-size="14"
stroke-width="0"
id="svg_9"
y="63"
x="35"
stroke="white"
fill="#ffffff"
>
{A}
</text>
<text
xmlSpace="preserve"
text-anchor="middle"
font-family="Noto Sans JP"
font-size="14"
id="svg_10"
y="188"
x="35"
stroke-width="0"
stroke="white"
fill="#ffffff"
>
{D}
</text>
<text
xmlSpace="preserve"
text-anchor="middle"
font-family="Noto Sans JP"
font-size="14"
id="svg_11"
y="125"
x="215"
stroke-width="0"
stroke="white"
fill="#ffffff"
>
{out}
</text>
<text
xmlSpace="preserve"
text-anchor="middle"
font-family="Noto Sans JP"
font-size="14"
id="svg_13"
y="125"
x="135"
stroke-width="0"
stroke="white"
fill="#ffffff"
>
{COMMANDS_ALU.op[op] ?? "(??)"}
</text>
</g>
</svg>
</div>
);
14 changes: 10 additions & 4 deletions components/src/chips/visualizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export function getBuiltinVisualization(part: Chip): ReactElement | undefined {
}
}

export function makeVisualization(chip: Chip, updateAction? : () => void): ReactElement | undefined {
export function makeVisualization(
chip: Chip,
updateAction?: () => void
): ReactElement | undefined {
if (chip instanceof ALU) {
return (
<ALUComponent
Expand Down Expand Up @@ -113,9 +116,12 @@ export function makeVisualization(chip: Chip, updateAction? : () => void): React
return vis.length > 0 ? <>{vis}</> : undefined;
}

export function makeVisualizationsWithId(chip: {
parts: Chip[];
}, updateAction? : () => void): [string, ReactElement][] {
export function makeVisualizationsWithId(
chip: {
parts: Chip[];
},
updateAction?: () => void
): [string, ReactElement][] {
return [...chip.parts]
.map((part, i): [string, ReactElement | undefined] => [
`${part.id}_${i}`,
Expand Down
8 changes: 4 additions & 4 deletions components/src/pinout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const PinoutBlock = (
enableEdit={props.enableEdit}
signed={props.displayInfo.isSigned(immPin.pin.name)}
setInputValid={props.setInputValid}
internal={props.header === "Internal pins" ? true : false }
internal={props.header === "Internal pins" ? true : false}
/>
</td>
</tr>
Expand Down Expand Up @@ -151,7 +151,7 @@ export const Pinout = ({
<tr key={immPin.pin.name}>
<td>{immPin.pin.name}</td>
<td>
<Pin pin={immPin} toggle={toggle} internal/>
<Pin pin={immPin} toggle={toggle} internal />
</td>
</tr>
))}
Expand All @@ -167,7 +167,7 @@ const Pin = ({
enableEdit = true,
signed = true,
setInputValid,
internal = false
internal = false,
}: {
pin: ImmPin;
toggle: ((pin: ChipPin, bit?: number) => void) | undefined;
Expand Down Expand Up @@ -260,7 +260,7 @@ const Pin = ({
<button
key={i}
disabled={disabled}
style={internal ? {backgroundColor: "grey"} : {}}
style={internal ? { backgroundColor: "grey" } : {}}
onClick={() => toggle?.(pin.pin, i)}
data-testid={`pin-${i}`}
>
Expand Down
2 changes: 1 addition & 1 deletion projects/src/project_05/04_screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export const hdl = `CHIP Screen {
OUT out[16];
PARTS:
}`;
}`;
2 changes: 1 addition & 1 deletion projects/src/project_05/05_keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export const hdl = `CHIP Keyboard {
OUT out[16];
PARTS:
}`;
}`;
6 changes: 3 additions & 3 deletions simulator/src/chip/chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Bus implements Pin {
for (const i of range(0, this.width)) {
this.state[i] = ((voltage & (1 << i)) >> i) as Voltage;
}
this.next.forEach((n) => (n.busVoltage = this.busVoltage));
this.next.forEach((n) => (n.busVoltage = this.busVoltage));
}

get busVoltage(): number {
Expand Down Expand Up @@ -446,8 +446,8 @@ export class Chip {
for (const chip of this.parts) {
// TODO topological sort
// eval chip input busses
TRUE_BUS.next.forEach((pin) => pin.busVoltage = TRUE_BUS.busVoltage);
FALSE_BUS.next.forEach((pin) => pin.busVoltage = FALSE_BUS.busVoltage);
TRUE_BUS.next.forEach((pin) => (pin.busVoltage = TRUE_BUS.busVoltage));
FALSE_BUS.next.forEach((pin) => (pin.busVoltage = FALSE_BUS.busVoltage));
chip.eval();
// eval output busses
}
Expand Down
8 changes: 4 additions & 4 deletions simulator/src/cpu/alu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type COMMANDS_OP =
| 0b010101;

//Usefull for the visualization of the ALU
export type COMMANDS_ALU =
export type COMMANDS_ALU =
| "0"
| "1"
| "-1"
Expand All @@ -68,7 +68,7 @@ export type COMMANDS_ALU =
| "x|y";

export const COMMANDS_ALU: {
op: Record<COMMANDS_OP, COMMANDS_ALU>
op: Record<COMMANDS_OP, COMMANDS_ALU>;
} = {
op: {
0x2a: "0",
Expand All @@ -89,8 +89,8 @@ export const COMMANDS_ALU: {
0x07: "y-x",
0x00: "x&y",
0x15: "x|y",
}
}
},
};

export const COMMANDS: {
asm: Record<COMMANDS_ASM, COMMANDS_OP>;
Expand Down
13 changes: 8 additions & 5 deletions web/src/pages/chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,14 @@ export const Chip = () => {
</fieldset>
);

const visualizations: [string, ReactNode][] = makeVisualizationsWithId({
parts: state.sim.chip,
}, () => {
dispatch.current({ action: "updateChip" });
});
const visualizations: [string, ReactNode][] = makeVisualizationsWithId(
{
parts: state.sim.chip,
},
() => {
dispatch.current({ action: "updateChip" });
}
);

const pinResetDispatcher = new PinResetDispatcher();

Expand Down

0 comments on commit e1d6b26

Please sign in to comment.