diff --git a/elm.json b/elm.json index dea3450..2d0d191 100644 --- a/elm.json +++ b/elm.json @@ -8,10 +8,10 @@ "direct": { "elm/browser": "1.0.2", "elm/core": "1.0.5", - "elm/html": "1.0.0" + "elm/html": "1.0.0", + "elm/json": "1.1.3" }, "indirect": { - "elm/json": "1.1.3", "elm/time": "1.0.0", "elm/url": "1.0.0", "elm/virtual-dom": "1.0.2" diff --git a/out/css/colors-light.css b/out/css/colors-light.css index a698bcd..6726e50 100644 --- a/out/css/colors-light.css +++ b/out/css/colors-light.css @@ -73,11 +73,17 @@ --color-table-ram-head-text: var(--color-white); --color-table-ram-highlight: var(--color-ram-light2); --color-table-ram-highlight-text: var(--color-black); + --color-table-ram-select: transparent; + --color-table-ram-select-text: inherit; + --color-table-ram-select-border: var(--color-grey-light2); --color-table-cu-head: var(--color-cu-dark1); --color-table-cu-head-text: var(--color-white); --color-table-cu-highlight: var(--color-cu-light2); --color-table-cu-highlight-text: var(--color-black); + --color-table-cu-select: transparent; + --color-table-cu-select-text: inherit; + --color-table-cu-select-border: var(--color-grey-light2); --color-arrow: var(--color-arrow-main); --color-arrow-text: var(--color-white); diff --git a/out/css/style.css b/out/css/style.css index 5796e45..e045e9e 100644 --- a/out/css/style.css +++ b/out/css/style.css @@ -107,6 +107,7 @@ button { display: grid; grid-template-columns: auto auto auto; + /* grid-template-columns: max-content auto max-content; */ gap: 9px; } @@ -115,6 +116,7 @@ button { } .pc .section { + min-height: 20em; max-height: calc(80vh - 8em); min-width: 20%; @@ -274,6 +276,26 @@ th.address { width: 100%; } +.pc .ram input[type=number] { + margin: 0 .5em 0 0; + background-color: var(--color-table-ram-select); + color: var(--color-table-ram-select-text); + border-color: var(--color-table-ram-select-border); + height: max-content; +} + +.pc .ram input[type=number].instruction { + width: 5em; +} + +.pc .ram input[type=number].address { + width: 7em; +} + +.pc .ram table tr td:nth-child(2){ + text-align: left; +} + /* CONTROL UNIT */ @@ -285,6 +307,15 @@ th.address { width: 100%; } +.pc .cu select{ + margin: 0; + width: 100%; + + background-color: var(--color-table-cu-select); + color: var(--color-table-cu-select-text); + border: 1px solid var(--color-table-cu-select-border); +} + /* BUSSES */ .pc .databus, diff --git a/out/elm.js b/out/elm.js index 1267f54..cf8d5de 100644 --- a/out/elm.js +++ b/out/elm.js @@ -5163,63 +5163,13 @@ var $author$project$Main$ActDataBus2Ram = {$: 'ActDataBus2Ram'}; var $author$project$Main$ActInstructionReg2AddressBus = {$: 'ActInstructionReg2AddressBus'}; var $author$project$Main$ActInstructionReg2ProgrammCounter = {$: 'ActInstructionReg2ProgrammCounter'}; var $author$project$Main$ActInstructionReg2UCounter = {$: 'ActInstructionReg2UCounter'}; +var $author$project$Main$ActNothing = {$: 'ActNothing'}; var $author$project$Main$ActProgrammCounter2AddressBus = {$: 'ActProgrammCounter2AddressBus'}; var $author$project$Main$ActProgrammCounterIncrement = {$: 'ActProgrammCounterIncrement'}; var $author$project$Main$ActRam2DataBus = {$: 'ActRam2DataBus'}; var $author$project$Main$ActResetUCounter = {$: 'ActResetUCounter'}; var $author$project$Main$initialUCodes = _List_fromArray( - [ - $elm$core$Maybe$Just($author$project$Main$ActProgrammCounter2AddressBus), - $elm$core$Maybe$Just($author$project$Main$ActRam2DataBus), - $elm$core$Maybe$Just($author$project$Main$ActDataBus2InstructionReg), - $elm$core$Maybe$Just($author$project$Main$ActProgrammCounterIncrement), - $elm$core$Maybe$Just($author$project$Main$ActInstructionReg2UCounter), - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Just($author$project$Main$ActInstructionReg2AddressBus), - $elm$core$Maybe$Just($author$project$Main$ActRam2DataBus), - $elm$core$Maybe$Just($author$project$Main$ActDataBus2Accumulator), - $elm$core$Maybe$Just($author$project$Main$ActResetUCounter), - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Just($author$project$Main$ActAccumulator2DataBus), - $elm$core$Maybe$Just($author$project$Main$ActInstructionReg2AddressBus), - $elm$core$Maybe$Just($author$project$Main$ActDataBus2Ram), - $elm$core$Maybe$Just($author$project$Main$ActResetUCounter), - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Just($author$project$Main$ActAccumulatorIncrement), - $elm$core$Maybe$Just($author$project$Main$ActResetUCounter), - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Just($author$project$Main$ActInstructionReg2ProgrammCounter), - $elm$core$Maybe$Just($author$project$Main$ActResetUCounter), - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing, - $elm$core$Maybe$Nothing - ]); + [$author$project$Main$ActProgrammCounter2AddressBus, $author$project$Main$ActRam2DataBus, $author$project$Main$ActDataBus2InstructionReg, $author$project$Main$ActProgrammCounterIncrement, $author$project$Main$ActInstructionReg2UCounter, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActInstructionReg2AddressBus, $author$project$Main$ActRam2DataBus, $author$project$Main$ActDataBus2Accumulator, $author$project$Main$ActResetUCounter, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActAccumulator2DataBus, $author$project$Main$ActInstructionReg2AddressBus, $author$project$Main$ActDataBus2Ram, $author$project$Main$ActResetUCounter, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActAccumulatorIncrement, $author$project$Main$ActResetUCounter, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActInstructionReg2ProgrammCounter, $author$project$Main$ActResetUCounter, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing, $author$project$Main$ActNothing]); var $elm$core$Platform$Cmd$batch = _Platform_batch; var $elm$core$Platform$Cmd$none = $elm$core$Platform$Cmd$batch(_List_Nil); var $author$project$Main$init = function (flags) { @@ -5235,52 +5185,6 @@ var $author$project$Main$recieveLocalSession = _Platform_incomingPort('recieveLo var $author$project$Main$subscriptions = function (model) { return $author$project$Main$recieveLocalSession($author$project$Main$MsgLocalSessionRecieve); }; -var $elm$core$List$filter = F2( - function (isGood, list) { - return A3( - $elm$core$List$foldr, - F2( - function (x, xs) { - return isGood(x) ? A2($elm$core$List$cons, x, xs) : xs; - }), - _List_Nil, - list); - }); -var $elm$core$List$head = function (list) { - if (list.b) { - var x = list.a; - var xs = list.b; - return $elm$core$Maybe$Just(x); - } else { - return $elm$core$Maybe$Nothing; - } -}; -var $author$project$Main$ActAccumulatorDecrement = {$: 'ActAccumulatorDecrement'}; -var $author$project$Main$actAccumulator2DataBus = function (pc) { - return _Utils_update( - pc, - {dataBus: pc.accumulator}); -}; -var $author$project$Main$actAccumulatorDecrement = function (pc) { - return _Utils_update( - pc, - {accumulator: pc.accumulator - 1}); -}; -var $author$project$Main$actAccumulatorIncrement = function (pc) { - return _Utils_update( - pc, - {accumulator: pc.accumulator + 1}); -}; -var $author$project$Main$actDataBus2Accumulator = function (pc) { - return _Utils_update( - pc, - {accumulator: pc.dataBus}); -}; -var $author$project$Main$actDataBus2InstructionReg = function (pc) { - return _Utils_update( - pc, - {instructionReg: pc.dataBus}); -}; var $elm$core$List$append = F2( function (xs, ys) { if (!ys.b) { @@ -5457,8 +5361,8 @@ var $elm$core$List$take = F2( function (n, list) { return A3($elm$core$List$takeFast, 0, n, list); }); -var $author$project$Main$changeAt = F3( - function (pos, newVal, list) { +var $author$project$Main$changeAt = F4( + function (pos, newVal, _default, list) { var len = $elm$core$List$length(list); var before = A2($elm$core$List$take, pos, list); var after = A2($elm$core$List$drop, pos + 1, list); @@ -5466,7 +5370,7 @@ var $author$project$Main$changeAt = F3( var before2 = A2( $elm$core$List$append, before, - A2($elm$core$List$repeat, pos - len, 0)); + A2($elm$core$List$repeat, pos - len, _default)); return A2( $elm$core$List$append, before2, @@ -5478,26 +5382,94 @@ var $author$project$Main$changeAt = F3( A2($elm$core$List$cons, newVal, after)); } }); +var $author$project$Main$changeAtInt = F3( + function (pos, newVal, list) { + return A4($author$project$Main$changeAt, pos, newVal, 0, list); + }); +var $author$project$Main$changeAtUCode = F3( + function (pos, newVal, list) { + return A4($author$project$Main$changeAt, pos, newVal, $author$project$Main$ActNothing, list); + }); +var $elm$core$List$filter = F2( + function (isGood, list) { + return A3( + $elm$core$List$foldr, + F2( + function (x, xs) { + return isGood(x) ? A2($elm$core$List$cons, x, xs) : xs; + }), + _List_Nil, + list); + }); +var $elm$core$List$head = function (list) { + if (list.b) { + var x = list.a; + var xs = list.b; + return $elm$core$Maybe$Just(x); + } else { + return $elm$core$Maybe$Nothing; + } +}; +var $author$project$Main$ActAccumulatorDecrement = {$: 'ActAccumulatorDecrement'}; +var $author$project$Main$actAccumulator2DataBus = function (pc) { + return _Utils_update( + pc, + {dataBus: pc.accumulator}); +}; +var $author$project$Main$actAccumulatorDecrement = function (pc) { + return _Utils_update( + pc, + {accumulator: pc.accumulator - 1}); +}; +var $author$project$Main$actAccumulatorIncrement = function (pc) { + return _Utils_update( + pc, + {accumulator: pc.accumulator + 1}); +}; +var $author$project$Main$actDataBus2Accumulator = function (pc) { + return _Utils_update( + pc, + {accumulator: pc.dataBus}); +}; +var $author$project$Main$actDataBus2InstructionReg = function (pc) { + return _Utils_update( + pc, + {instructionReg: pc.dataBus}); +}; var $author$project$Main$actDataBus2Ram = function (pc) { - var newRam = A3($author$project$Main$changeAt, pc.addressBus, pc.dataBus, pc.ram); + var newRam = A3($author$project$Main$changeAtInt, pc.addressBus, pc.dataBus, pc.ram); return _Utils_update( pc, {ram: newRam}); }; +var $author$project$Main$seperateInstructionsEntry = function (i) { + var instruction = (i / 100000) | 0; + var address = i - (instruction * 100000); + return _Utils_Tuple2(instruction, address); +}; var $author$project$Main$actInstructionReg2AddressBus = function (pc) { + var _v0 = $author$project$Main$seperateInstructionsEntry(pc.instructionReg); + var instruction = _v0.a; + var address = _v0.b; return _Utils_update( pc, - {addressBus: pc.instructionReg - (((pc.instructionReg / 100000) | 0) * 100000)}); + {addressBus: address}); }; var $author$project$Main$actInstructionReg2ProgrammCounter = function (pc) { + var _v0 = $author$project$Main$seperateInstructionsEntry(pc.instructionReg); + var instruction = _v0.a; + var address = _v0.b; return _Utils_update( pc, - {programmCounter: pc.instructionReg - (((pc.instructionReg / 100000) | 0) * 100000)}); + {programmCounter: address}); }; var $author$project$Main$actInstructionReg2UCounter = function (pc) { + var _v0 = $author$project$Main$seperateInstructionsEntry(pc.instructionReg); + var instruction = _v0.a; + var address = _v0.b; return _Utils_update( pc, - {uCounter: ((pc.instructionReg / 100000) | 0) * 10}); + {uCounter: instruction * 10}); }; var $author$project$Main$actProgrammCounter2AddressBus = function (pc) { return _Utils_update( @@ -5550,7 +5522,12 @@ var $author$project$Main$uCodeMaps = _List_fromArray( _Utils_Tuple2($author$project$Main$ActProgrammCounterIncrement, $author$project$Main$actProgrammCounterIncrement), _Utils_Tuple2($author$project$Main$ActRam2DataBus, $author$project$Main$actRam2DataBus), _Utils_Tuple2($author$project$Main$ActResetUCounter, $author$project$Main$actResetUCounter), - _Utils_Tuple2($author$project$Main$ActProgrammCounter2AddressBus, $author$project$Main$actProgrammCounter2AddressBus) + _Utils_Tuple2($author$project$Main$ActProgrammCounter2AddressBus, $author$project$Main$actProgrammCounter2AddressBus), + _Utils_Tuple2( + $author$project$Main$ActNothing, + function (s) { + return s; + }) ]); var $author$project$Main$getAction = function (uAction) { var possible_instructions = A2( @@ -5574,11 +5551,48 @@ var $author$project$Main$getAction = function (uAction) { var $elm$core$Basics$not = _Basics_not; var $elm$json$Json$Encode$string = _Json_wrap; var $author$project$Main$sendUUpdate = _Platform_outgoingPort('sendUUpdate', $elm$json$Json$Encode$string); +var $elm$core$Tuple$second = function (_v0) { + var y = _v0.b; + return y; +}; +var $author$project$Main$uCodeDescriptions = _List_fromArray( + [ + _Utils_Tuple2($author$project$Main$ActAccumulator2DataBus, 'Acc -> DataBus'), + _Utils_Tuple2($author$project$Main$ActAccumulatorDecrement, 'Acc --'), + _Utils_Tuple2($author$project$Main$ActAccumulatorIncrement, 'Acc ++'), + _Utils_Tuple2($author$project$Main$ActDataBus2Accumulator, 'DataBus -> Acc'), + _Utils_Tuple2($author$project$Main$ActDataBus2InstructionReg, 'DataBus -> InstReg'), + _Utils_Tuple2($author$project$Main$ActDataBus2Ram, 'DataBus -> Ram'), + _Utils_Tuple2($author$project$Main$ActInstructionReg2AddressBus, 'InstReg -> AddrBus'), + _Utils_Tuple2($author$project$Main$ActInstructionReg2ProgrammCounter, 'InstReg -> ProgCount'), + _Utils_Tuple2($author$project$Main$ActInstructionReg2UCounter, 'InstReg -> µCounter'), + _Utils_Tuple2($author$project$Main$ActProgrammCounterIncrement, 'ProgCounter ++'), + _Utils_Tuple2($author$project$Main$ActRam2DataBus, 'Ram -> DataBus'), + _Utils_Tuple2($author$project$Main$ActResetUCounter, 'µCounter = 0'), + _Utils_Tuple2($author$project$Main$ActProgrammCounter2AddressBus, 'ProgCounter -> AddrBus'), + _Utils_Tuple2($author$project$Main$ActNothing, 'Empty') + ]); +var $author$project$Main$string2uAction = function (msg) { + var filtered_list = A2( + $elm$core$List$filter, + function (s) { + return _Utils_eq(s.b, msg); + }, + $author$project$Main$uCodeDescriptions); + var _v0 = $elm$core$List$head(filtered_list); + if (_v0.$ === 'Just') { + var _v1 = _v0.a; + var action = _v1.a; + return $elm$core$Maybe$Just(action); + } else { + return $elm$core$Maybe$Nothing; + } +}; var $author$project$Main$uStepPC = function (model) { var uCounter = model.pc.uCounter; var may_instruction = A2($author$project$Main$valueAt, uCounter, model.uCode); - if ((may_instruction.$ === 'Just') && (may_instruction.a.$ === 'Just')) { - var action = may_instruction.a.a; + if (may_instruction.$ === 'Just') { + var action = may_instruction.a; var possible_instructions = A2( $elm$core$List$filter, function (s) { @@ -5644,6 +5658,69 @@ var $author$project$Main$update = F2( pc: instruction(model.pc) }), $elm$core$Platform$Cmd$none); + case 'MsgRamEditAddress': + var addr = msg.a; + var may_int = msg.b; + var _v1 = $elm$core$String$toInt(may_int); + if (_v1.$ === 'Just') { + var _int = _v1.a; + var old_pc = model.pc; + var _v2 = $author$project$Main$seperateInstructionsEntry( + A2($author$project$Main$valueAtInt, addr, model.pc.ram)); + var inst = _v2.a; + var new_val = (inst * 100000) + _int; + var new_pc = _Utils_update( + old_pc, + { + ram: A3($author$project$Main$changeAtInt, addr, new_val, old_pc.ram) + }); + return _Utils_Tuple2( + _Utils_update( + model, + {pc: new_pc}), + $elm$core$Platform$Cmd$none); + } else { + return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + } + case 'MsgRamEditInstr': + var addr = msg.a; + var may_int = msg.b; + var _v3 = $elm$core$String$toInt(may_int); + if (_v3.$ === 'Just') { + var _int = _v3.a; + var old_pc = model.pc; + var _v4 = $author$project$Main$seperateInstructionsEntry( + A2($author$project$Main$valueAtInt, addr, model.pc.ram)); + var address = _v4.b; + var new_val = (_int * 100000) + address; + var new_pc = _Utils_update( + old_pc, + { + ram: A3($author$project$Main$changeAtInt, addr, new_val, old_pc.ram) + }); + return _Utils_Tuple2( + _Utils_update( + model, + {pc: new_pc}), + $elm$core$Platform$Cmd$none); + } else { + return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + } + case 'MsgCuEditAction': + var addr = msg.a; + var may_action = msg.b; + var _v5 = $author$project$Main$string2uAction(may_action); + if (_v5.$ === 'Just') { + var action = _v5.a; + var newCode = A3($author$project$Main$changeAtUCode, addr, action, model.uCode); + return _Utils_Tuple2( + _Utils_update( + model, + {uCode: newCode}), + $elm$core$Platform$Cmd$none); + } else { + return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + } default: return _Utils_Tuple2( _Utils_update( @@ -5676,10 +5753,6 @@ var $elm$html$Html$Attributes$stringProperty = F2( $elm$json$Json$Encode$string(string)); }); var $elm$html$Html$Attributes$class = $elm$html$Html$Attributes$stringProperty('className'); -var $elm$core$Tuple$second = function (_v0) { - var y = _v0.b; - return y; -}; var $elm$html$Html$Attributes$classList = function (classes) { return $elm$html$Html$Attributes$class( A2( @@ -5831,7 +5904,7 @@ var $author$project$Main$viewAlu = function (model) { _List_fromArray( [ $elm$html$Html$text( - 'Accumulator: ' + $elm$core$String$fromInt(model.pc.accumulator)) + 'Accumulator: ' + A2($author$project$Main$addLeadingZero, model.pc.accumulator, 8)) ])), A2( $elm$html$Html$div, @@ -5907,106 +5980,90 @@ var $elm$core$Tuple$pair = F2( }); var $elm$html$Html$tbody = _VirtualDom_node('tbody'); var $elm$html$Html$td = _VirtualDom_node('td'); -var $author$project$Main$uCodeDescriptions = _List_fromArray( - [ - _Utils_Tuple2($author$project$Main$ActAccumulator2DataBus, 'Acc -> DataBus'), - _Utils_Tuple2($author$project$Main$ActAccumulatorDecrement, 'Acc --'), - _Utils_Tuple2($author$project$Main$ActAccumulatorIncrement, 'Acc ++'), - _Utils_Tuple2($author$project$Main$ActDataBus2Accumulator, 'DataBus -> Acc'), - _Utils_Tuple2($author$project$Main$ActDataBus2InstructionReg, 'DataBus -> InstReg'), - _Utils_Tuple2($author$project$Main$ActDataBus2Ram, 'DataBus -> Ram'), - _Utils_Tuple2($author$project$Main$ActInstructionReg2AddressBus, 'InstReg -> AddrBus'), - _Utils_Tuple2($author$project$Main$ActInstructionReg2ProgrammCounter, 'InstReg -> ProgCount'), - _Utils_Tuple2($author$project$Main$ActInstructionReg2UCounter, 'InstReg -> µCounter'), - _Utils_Tuple2($author$project$Main$ActProgrammCounterIncrement, 'ProgCounter ++'), - _Utils_Tuple2($author$project$Main$ActRam2DataBus, 'Ram -> DataBus'), - _Utils_Tuple2($author$project$Main$ActResetUCounter, 'µCounter = 0'), - _Utils_Tuple2($author$project$Main$ActProgrammCounter2AddressBus, 'ProgCounter -> AddrBus') - ]); +var $author$project$Main$MsgCuEditAction = F2( + function (a, b) { + return {$: 'MsgCuEditAction', a: a, b: b}; + }); +var $elm$html$Html$option = _VirtualDom_node('option'); +var $elm$html$Html$select = _VirtualDom_node('select'); +var $elm$json$Json$Decode$field = _Json_decodeField; +var $author$project$Main$selectCuValueDecoder = A2( + $elm$json$Json$Decode$field, + 'target', + A2($elm$json$Json$Decode$field, 'value', $elm$json$Json$Decode$string)); +var $elm$html$Html$Attributes$selected = $elm$html$Html$Attributes$boolProperty('selected'); +var $author$project$Main$viewCuInstrSelect = F2( + function (id, current) { + var info2option = function (_v0) { + var action = _v0.a; + var info = _v0.b; + return A2( + $elm$html$Html$option, + _List_fromArray( + [ + $elm$html$Html$Attributes$selected( + _Utils_eq(action, current)) + ]), + _List_fromArray( + [ + $elm$html$Html$text(info) + ])); + }; + var listOptions = A2($elm$core$List$map, info2option, $author$project$Main$uCodeDescriptions); + return A2( + $elm$html$Html$select, + _List_fromArray( + [ + A2( + $elm$html$Html$Events$on, + 'change', + A2( + $elm$json$Json$Decode$map, + $author$project$Main$MsgCuEditAction(id), + $author$project$Main$selectCuValueDecoder)) + ]), + listOptions); + }); var $author$project$Main$viewCuUCodeContent = function (model) { - var list2table = function (may_t) { - var may_code = may_t.b; - var id = may_t.a; - if (may_code.$ === 'Just') { - var code = may_code.a; - var possibleDescriptions = A2( - $elm$core$List$filter, - function (s) { - return _Utils_eq(s.a, code); - }, - $author$project$Main$uCodeDescriptions); - var codeDescription = function () { - var _v1 = $elm$core$List$head(possibleDescriptions); - if (_v1.$ === 'Just') { - var _v2 = _v1.a; - var description = _v2.b; - return description; - } else { - return 'Idk what this is'; - } - }(); - return A2( - $elm$html$Html$tr, - _List_fromArray( - [ - $elm$html$Html$Attributes$classList( - _List_fromArray( - [ - _Utils_Tuple2( - 'current', - _Utils_eq(id, model.pc.uCounter)) - ])) - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$td, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('num') - ]), - _List_fromArray( - [ - $elm$html$Html$text( - A2($author$project$Main$addLeadingZero, id, 3)) - ])), - A2( - $elm$html$Html$td, - _List_Nil, - _List_fromArray( - [ - $elm$html$Html$text(codeDescription) - ])) - ])); - } else { - return A2( - $elm$html$Html$tr, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('empty') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$td, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('num') - ]), - _List_fromArray( - [ - $elm$html$Html$text( - A2($author$project$Main$addLeadingZero, id, 3)) - ])), - A2( - $elm$html$Html$td, - _List_Nil, - _List_fromArray( - [ - $elm$html$Html$text('Empty') - ])) - ])); - } + var list2table = function (t) { + var id = t.a; + var code = t.b; + return A2( + $elm$html$Html$tr, + _List_fromArray( + [ + $elm$html$Html$Attributes$classList( + _List_fromArray( + [ + _Utils_Tuple2( + 'current', + _Utils_eq(id, model.pc.uCounter)), + _Utils_Tuple2( + 'empty', + _Utils_eq(code, $author$project$Main$ActNothing)) + ])) + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$td, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('num') + ]), + _List_fromArray( + [ + $elm$html$Html$text( + A2($author$project$Main$addLeadingZero, id, 4)) + ])), + A2( + $elm$html$Html$td, + _List_Nil, + _List_fromArray( + [ + A2($author$project$Main$viewCuInstrSelect, id, code) + ])) + ])); }; var indexedList = A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, model.uCode); return A2( @@ -6056,8 +6113,9 @@ var $author$project$Main$viewCuUCode = function (model) { ])); }; var $author$project$Main$viewInstrEntry = function (i) { - var instruction = (i / 100000) | 0; - var address = i - (instruction * 100000); + var _v0 = $author$project$Main$seperateInstructionsEntry(i); + var instruction = _v0.a; + var address = _v0.b; return $elm$html$Html$text( A2($author$project$Main$addLeadingZero, instruction, 3) + (' ' + A2($author$project$Main$addLeadingZero, address, 5))); }; @@ -6242,10 +6300,53 @@ var $author$project$Main$viewDataBus = function (model) { ])) ])); }; +var $author$project$Main$MsgRamEditAddress = F2( + function (a, b) { + return {$: 'MsgRamEditAddress', a: a, b: b}; + }); +var $author$project$Main$MsgRamEditInstr = F2( + function (a, b) { + return {$: 'MsgRamEditInstr', a: a, b: b}; + }); +var $elm$html$Html$Events$alwaysStop = function (x) { + return _Utils_Tuple2(x, true); +}; +var $elm$virtual_dom$VirtualDom$MayStopPropagation = function (a) { + return {$: 'MayStopPropagation', a: a}; +}; +var $elm$html$Html$Events$stopPropagationOn = F2( + function (event, decoder) { + return A2( + $elm$virtual_dom$VirtualDom$on, + event, + $elm$virtual_dom$VirtualDom$MayStopPropagation(decoder)); + }); +var $elm$json$Json$Decode$at = F2( + function (fields, decoder) { + return A3($elm$core$List$foldr, $elm$json$Json$Decode$field, decoder, fields); + }); +var $elm$html$Html$Events$targetValue = A2( + $elm$json$Json$Decode$at, + _List_fromArray( + ['target', 'value']), + $elm$json$Json$Decode$string); +var $elm$html$Html$Events$onInput = function (tagger) { + return A2( + $elm$html$Html$Events$stopPropagationOn, + 'input', + A2( + $elm$json$Json$Decode$map, + $elm$html$Html$Events$alwaysStop, + A2($elm$json$Json$Decode$map, tagger, $elm$html$Html$Events$targetValue))); +}; +var $elm$html$Html$Attributes$value = $elm$html$Html$Attributes$stringProperty('value'); var $author$project$Main$viewRamContent = function (model) { var ram2table = function (entry) { var val = entry.b; var id = entry.a; + var _v0 = $author$project$Main$seperateInstructionsEntry(val); + var instruction = _v0.a; + var address = _v0.b; return A2( $elm$html$Html$tr, _List_fromArray( @@ -6279,7 +6380,32 @@ var $author$project$Main$viewRamContent = function (model) { ]), _List_fromArray( [ - $author$project$Main$viewInstrEntry(val) + A2( + $elm$html$Html$input, + _List_fromArray( + [ + $elm$html$Html$Attributes$type_('number'), + $elm$html$Html$Attributes$value( + A2($author$project$Main$addLeadingZero, instruction, 3)), + $elm$html$Html$Events$onInput( + $author$project$Main$MsgRamEditInstr(id)), + $elm$html$Html$Attributes$class('ram-entry'), + $elm$html$Html$Attributes$class('instruction') + ]), + _List_Nil), + A2( + $elm$html$Html$input, + _List_fromArray( + [ + $elm$html$Html$Attributes$type_('number'), + $elm$html$Html$Attributes$value( + A2($author$project$Main$addLeadingZero, address, 5)), + $elm$html$Html$Events$onInput( + $author$project$Main$MsgRamEditAddress(id)), + $elm$html$Html$Attributes$class('ram-entry'), + $elm$html$Html$Attributes$class('address') + ]), + _List_Nil) ])) ])); }; diff --git a/src/Main.elm b/src/Main.elm index edd5acb..a30ce92 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -6,11 +6,13 @@ port module Main exposing (..) import Browser import Html exposing (Html, button, div, h1, p, text) import Html.Attributes as HAttr exposing (class, classList, value) -import Html.Events exposing (onClick) +import Html.Events as HEvent exposing (onClick, onInput) import Html.Lazy exposing (lazy) import Tuple import Array exposing (get) import Html exposing (address) +import Json.Decode as JD +import Html.Events exposing (targetValue) @@ -40,7 +42,7 @@ type alias PC = type alias Model = { pc : PC - , uCode : List (Maybe UAction) + , uCode : List UAction , autoscroll : Bool } @@ -59,6 +61,7 @@ type UAction | ActRam2DataBus | ActResetUCounter | ActProgrammCounter2AddressBus + | ActNothing uCodeDescriptions : List ( UAction, String ) @@ -76,6 +79,7 @@ uCodeDescriptions = , ( ActRam2DataBus, "Ram -> DataBus" ) , ( ActResetUCounter, "µCounter = 0" ) , ( ActProgrammCounter2AddressBus, "ProgCounter -> AddrBus" ) + , ( ActNothing, "Empty" ) ] @@ -94,6 +98,7 @@ uCodeMaps = , ( ActRam2DataBus, actRam2DataBus ) , ( ActResetUCounter, actResetUCounter ) , ( ActProgrammCounter2AddressBus, actProgrammCounter2AddressBus ) + , ( ActNothing, (\s -> s)) ] @@ -125,66 +130,66 @@ initialPC = 0 -initialUCodes : List (Maybe UAction) +initialUCodes : List UAction initialUCodes = - [ Just ActProgrammCounter2AddressBus -- 000 - , Just ActRam2DataBus -- 001 - , Just ActDataBus2InstructionReg -- 002 - , Just ActProgrammCounterIncrement -- 003 - , Just ActInstructionReg2UCounter -- 004 - , Nothing -- 005 - , Nothing - , Nothing - , Nothing - , Nothing -- 009 + [ ActProgrammCounter2AddressBus -- 000 + , ActRam2DataBus -- 001 + , ActDataBus2InstructionReg -- 002 + , ActProgrammCounterIncrement -- 003 + , ActInstructionReg2UCounter -- 004 + , ActNothing -- 005 + , ActNothing + , ActNothing + , ActNothing + , ActNothing -- 009 -- 010 LOADA - , Just ActInstructionReg2AddressBus -- 010 - , Just ActRam2DataBus -- 011 - , Just ActDataBus2Accumulator -- 012 - , Just ActResetUCounter -- 013 - , Nothing -- 014 - , Nothing - , Nothing - , Nothing - , Nothing - , Nothing -- 019 + , ActInstructionReg2AddressBus -- 010 + , ActRam2DataBus -- 011 + , ActDataBus2Accumulator -- 012 + , ActResetUCounter -- 013 + , ActNothing -- 014 + , ActNothing + , ActNothing + , ActNothing + , ActNothing + , ActNothing -- 019 -- 020 STOA - , Just ActAccumulator2DataBus -- 020 - , Just ActInstructionReg2AddressBus -- 021 - , Just ActDataBus2Ram -- 022 - , Just ActResetUCounter -- 023 - , Nothing --024 - , Nothing - , Nothing - , Nothing - , Nothing - , Nothing -- 029 + , ActAccumulator2DataBus -- 020 + , ActInstructionReg2AddressBus -- 021 + , ActDataBus2Ram -- 022 + , ActResetUCounter -- 023 + , ActNothing --024 + , ActNothing + , ActNothing + , ActNothing + , ActNothing + , ActNothing -- 029 -- 030 INCA - , Just ActAccumulatorIncrement -- 030 - , Just ActResetUCounter -- 031 - , Nothing -- 032 - , Nothing - , Nothing - , Nothing - , Nothing - , Nothing - , Nothing - , Nothing -- 039 + , ActAccumulatorIncrement -- 030 + , ActResetUCounter -- 031 + , ActNothing -- 032 + , ActNothing + , ActNothing + , ActNothing + , ActNothing + , ActNothing + , ActNothing + , ActNothing -- 039 -- 040 JMP - , Just ActInstructionReg2ProgrammCounter -- 040 - , Just ActResetUCounter -- 041 - , Nothing -- 042 - , Nothing - , Nothing - , Nothing - , Nothing - , Nothing - , Nothing - , Nothing -- 049 + , ActInstructionReg2ProgrammCounter -- 040 + , ActResetUCounter -- 041 + , ActNothing -- 042 + , ActNothing + , ActNothing + , ActNothing + , ActNothing + , ActNothing + , ActNothing + , ActNothing -- 049 ] @@ -194,6 +199,9 @@ type Msg | MsgReset | MsgAutoscrollUpdate | MsgManualStep UAction + | MsgRamEditAddress Int String + | MsgRamEditInstr Int String + | MsgCuEditAction Int String | MsgLocalSessionRecieve String @@ -223,6 +231,41 @@ update msg model = ( { model | pc = instruction model.pc} , Cmd.none ) + MsgRamEditAddress addr may_int -> + case String.toInt may_int of + Just int -> + let + (inst,_) = seperateInstructionsEntry ( valueAtInt addr model.pc.ram ) + new_val = inst * 100000 + int + old_pc = model.pc + new_pc = { old_pc | ram = (changeAtInt addr new_val old_pc.ram) } + in + ({ model | pc = new_pc } + , Cmd.none ) + _ -> (model, Cmd.none) + + MsgRamEditInstr addr may_int -> + case String.toInt may_int of + Just int -> + let + (_,address) = seperateInstructionsEntry ( valueAtInt addr model.pc.ram ) + new_val = int * 100000 + address + old_pc = model.pc + new_pc = { old_pc | ram = (changeAtInt addr new_val old_pc.ram) } + in + ({ model | pc = new_pc } + , Cmd.none ) + _ -> ( model, Cmd.none ) + + MsgCuEditAction addr may_action -> + case string2uAction may_action of + Just action -> + let + newCode = changeAtUCode addr action model.uCode + in + ({ model | uCode = newCode }, Cmd.none) + _ -> ( model, Cmd.none ) + MsgAutoscrollUpdate -> ( { model | autoscroll = not model.autoscroll } , Cmd.none @@ -250,12 +293,12 @@ uStepPC model = uCounter = model.pc.uCounter - may_instruction : Maybe (Maybe UAction) + may_instruction : Maybe UAction may_instruction = valueAt uCounter model.uCode in case may_instruction of - Just (Just action) -> + Just action -> let possible_instructions = List.filter (\s -> Tuple.first s == action) uCodeMaps @@ -284,6 +327,7 @@ uStepPC model = _ -> model + view : Model -> Html Msg view model = @@ -368,11 +412,30 @@ viewRamContent model = val = Tuple.second entry + + (instruction, address) = seperateInstructionsEntry val in Html.tr [ classList [ ( "current", id == model.pc.addressBus ) ] ] [ Html.td [ class "num" ] [ text (addLeadingZero id 3) ] - , Html.td [ class "num " ] [ viewInstrEntry val ] + , Html.td [ class "num " ] + [ Html.input + [ HAttr.type_ "number" + , HAttr.value (addLeadingZero instruction 3) + , onInput (MsgRamEditInstr id) + , class "ram-entry" + , class "instruction" + ] + [] + , Html.input + [ HAttr.type_ "number" + , HAttr.value (addLeadingZero address 5) + , onInput (MsgRamEditAddress id) + , class "ram-entry" + , class "address" + ] + [] + ] ] in Html.tbody [] (List.map ram2table indexedRam) @@ -438,50 +501,41 @@ viewCuUCodeContent model = indexedList = List.indexedMap Tuple.pair model.uCode - list2table : ( Int, Maybe UAction ) -> Html Msg - list2table may_t = + list2table : ( Int, UAction ) -> Html Msg + list2table t = let id = - Tuple.first may_t + Tuple.first t - may_code = - Tuple.second may_t + code = + Tuple.second t in - case may_code of - Just code -> - let - possibleDescriptions : List ( UAction, String ) - possibleDescriptions = - List.filter (\s -> Tuple.first s == code) uCodeDescriptions + Html.tr + [ classList [ ( "current", id == model.pc.uCounter ), ("empty", code == ActNothing) ] ] + [ Html.td [ class "num" ] [ text (addLeadingZero id 4) ] + , Html.td [] [ viewCuInstrSelect id code ] + ] - codeDescription = - case List.head possibleDescriptions of - Just ( _, description ) -> - description - - _ -> - "Idk what this is" - in - Html.tr - [ classList [ ( "current", id == model.pc.uCounter ) ] ] - [ Html.td [ class "num" ] [ text (addLeadingZero id 3) ] - , Html.td [] [ text codeDescription ] - ] - - Nothing -> - Html.tr [ class "empty" ] - [ Html.td [ class "num" ] [ text (addLeadingZero id 3) ] - , Html.td [] [ text "Empty" ] - ] in Html.tbody [] (List.map list2table indexedList) +viewCuInstrSelect : Int -> UAction -> Html Msg +viewCuInstrSelect id current = + let + info2option (action, info) = + Html.option [ HAttr.selected (action == current) ] [ text info ] + listOptions = List.map info2option uCodeDescriptions + in + Html.select + [ HEvent.on "change" ( JD.map (MsgCuEditAction id) selectCuValueDecoder) ] + listOptions + viewAlu : Model -> Html Msg viewAlu model = div [ class "section", class "alu" ] [ h1 [ class "header" ] [ text "ALU" ] - , p [] [ text ("Accumulator: " ++ String.fromInt model.pc.accumulator) ] + , p [] [ text ("Accumulator: " ++ (addLeadingZero model.pc.accumulator 8)) ] , div [ class "arrow", class "up"] [ div [ class "button" ] [ Html.a [ onClick (MsgManualStep ActDataBus2Accumulator)] [ text "DB -> ALU" ]] @@ -514,8 +568,7 @@ viewAddressBus model = viewInstrEntry : Int -> Html Msg viewInstrEntry i = let - instruction = i // 100000 - address = i - instruction*100000 + (instruction, address) = seperateInstructionsEntry i in text ( (addLeadingZero instruction 3) ++ " " ++ (addLeadingZero address 5) ) @@ -551,21 +604,28 @@ actResetUCounter pc = actInstructionReg2UCounter : PC -> PC actInstructionReg2UCounter pc = - -- Remove last 5 digits as they are address -- Multiply by ten, because every instruction is 10 uCodes long - { pc | uCounter = pc.instructionReg // 100000 * 10 } + let + (instruction, address) = seperateInstructionsEntry pc.instructionReg + in + { pc | uCounter = instruction * 10} actInstructionReg2AddressBus : PC -> PC actInstructionReg2AddressBus pc = - -- Only bring last 5 digits to AB, because the rest is opcode - { pc | addressBus = pc.instructionReg - pc.instructionReg // 100000 * 100000 } + let + (instruction, address) = seperateInstructionsEntry pc.instructionReg + in + { pc | addressBus = address } actInstructionReg2ProgrammCounter : PC -> PC actInstructionReg2ProgrammCounter pc = - -- Only bring last 5 digits to AB, because the rest is opcode - { pc | programmCounter = pc.instructionReg - pc.instructionReg // 100000 * 100000 } + let + (instruction, address) = seperateInstructionsEntry pc.instructionReg + in + + { pc | programmCounter = address } actProgrammCounterIncrement : PC -> PC @@ -602,7 +662,7 @@ actDataBus2Ram : PC -> PC actDataBus2Ram pc = let newRam = - changeAt pc.addressBus pc.dataBus pc.ram + changeAtInt pc.addressBus pc.dataBus pc.ram in { pc | ram = newRam } @@ -627,8 +687,17 @@ valueAt n l = List.head (List.drop n l) -changeAt : Int -> Int -> List Int -> List Int -changeAt pos newVal list = +changeAtInt : Int -> Int -> List Int -> List Int +changeAtInt pos newVal list = + changeAt pos newVal 0 list + + +changeAtUCode : Int -> UAction -> List UAction -> List UAction +changeAtUCode pos newVal list = + changeAt pos newVal ActNothing list + +changeAt : Int -> a -> a ->List a -> List a +changeAt pos newVal default list = let before = List.take pos list @@ -642,7 +711,7 @@ changeAt pos newVal list = if pos > len then let before2 = - List.append before (List.repeat (pos - len) 0) + List.append before (List.repeat (pos - len) default) in List.append before2 (newVal :: after) @@ -674,6 +743,38 @@ addLeadingZero number length = else num_str +seperateInstructionsEntry : Int -> (Int, Int) +seperateInstructionsEntry i = + let + instruction = i // 100000 + address = i - instruction*100000 + in + (instruction, address) + + +uAction2String : UAction -> String +uAction2String action = + let + filtered_list = List.filter (\s -> Tuple.first s == action) uCodeDescriptions + in + case List.head filtered_list of + Just (_,info) -> info + Nothing -> "IDK" + +string2uAction : String -> Maybe UAction +string2uAction msg = + let + filtered_list = List.filter (\s -> Tuple.second s == msg) uCodeDescriptions + in + case List.head filtered_list of + Just (action,_) -> Just action + _ -> Nothing + + +selectCuValueDecoder : JD.Decoder String +selectCuValueDecoder = + JD.field "target" ( JD.field "value" JD.string) + -- END HELPERS -- GENERAL