Make Edits persist after reload

This commit is contained in:
2020-12-26 15:07:14 +01:00
parent de10d8968b
commit 1701a5ea08
4 changed files with 435 additions and 129 deletions

View File

@ -127,6 +127,8 @@ button {
flex-direction: column;
position: relative;
/*top: 0;
left: 0;*/
}
.pc .section h1.header {
@ -146,7 +148,7 @@ button {
overflow-x: auto;
overflow-y: scroll;
position: relative;
/*position: relative;*/
/* max-height: 60%; */
padding: 0;
@ -246,12 +248,12 @@ th.address {
.pc .controls .checker {
display: inline-flex;
align-items: center;
padding-left: 3.5em;
padding-left: 3em;
}
.pc .controls .checker label {
display: inline;
font-size: 0.8em;
/*font-size: 0.8em;*/
white-space: initial;
white-space: break-spaces;
text-transform: none;
@ -385,7 +387,7 @@ th.address {
.pc .databus,
.pc .addressbus{
position: relative;
/*position: relative;*/
text-align: left;
margin: 0;

View File

@ -5181,9 +5181,9 @@ var $author$project$Main$MsgLocalSessionRecieve = function (a) {
return {$: 'MsgLocalSessionRecieve', a: a};
};
var $elm$json$Json$Decode$string = _Json_decodeString;
var $author$project$Main$recieveLocalSession = _Platform_incomingPort('recieveLocalSession', $elm$json$Json$Decode$string);
var $author$project$Main$localStorageRecieve = _Platform_incomingPort('localStorageRecieve', $elm$json$Json$Decode$string);
var $author$project$Main$subscriptions = function (model) {
return $author$project$Main$recieveLocalSession($author$project$Main$MsgLocalSessionRecieve);
return $author$project$Main$localStorageRecieve($author$project$Main$MsgLocalSessionRecieve);
};
var $elm$core$List$append = F2(
function (xs, ys) {
@ -5390,6 +5390,32 @@ 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$json$Json$Encode$bool = _Json_wrap;
var $elm$json$Json$Encode$int = _Json_wrap;
var $elm$json$Json$Encode$list = F2(
function (func, entries) {
return _Json_wrap(
A3(
$elm$core$List$foldl,
_Json_addEntry(func),
_Json_emptyArray(_Utils_Tuple0),
entries));
});
var $author$project$Main$modelVersion = 1;
var $elm$json$Json$Encode$object = function (pairs) {
return _Json_wrap(
A3(
$elm$core$List$foldl,
F2(
function (_v0, obj) {
var k = _v0.a;
var v = _v0.b;
return A3(_Json_addField, k, v, obj);
}),
_Json_emptyObject(_Utils_Tuple0),
pairs));
};
var $elm$json$Json$Encode$string = _Json_wrap;
var $elm$core$List$filter = F2(
function (isGood, list) {
return A3(
@ -5411,6 +5437,184 @@ var $elm$core$List$head = function (list) {
}
};
var $author$project$Main$ActAccumulatorDecrement = {$: 'ActAccumulatorDecrement'};
var $author$project$Main$uCodeIds = _List_fromArray(
[
_Utils_Tuple2($author$project$Main$ActAccumulator2DataBus, 'acc2db'),
_Utils_Tuple2($author$project$Main$ActAccumulatorDecrement, 'accDec'),
_Utils_Tuple2($author$project$Main$ActAccumulatorIncrement, 'accInc'),
_Utils_Tuple2($author$project$Main$ActDataBus2Accumulator, 'db2acc'),
_Utils_Tuple2($author$project$Main$ActDataBus2InstructionReg, 'db2ir'),
_Utils_Tuple2($author$project$Main$ActDataBus2Ram, 'db2ram'),
_Utils_Tuple2($author$project$Main$ActInstructionReg2AddressBus, 'ir2ab'),
_Utils_Tuple2($author$project$Main$ActInstructionReg2ProgrammCounter, 'ir2pc'),
_Utils_Tuple2($author$project$Main$ActInstructionReg2UCounter, 'ir2uc'),
_Utils_Tuple2($author$project$Main$ActProgrammCounterIncrement, 'pcInc'),
_Utils_Tuple2($author$project$Main$ActRam2DataBus, 'ram2db'),
_Utils_Tuple2($author$project$Main$ActResetUCounter, 'ucReset'),
_Utils_Tuple2($author$project$Main$ActProgrammCounter2AddressBus, 'pc2ab'),
_Utils_Tuple2($author$project$Main$ActNothing, 'n')
]);
var $author$project$Main$uAction2String = function (action) {
var filtered_list = A2(
$elm$core$List$filter,
function (s) {
return _Utils_eq(s.a, action);
},
$author$project$Main$uCodeIds);
var _v0 = $elm$core$List$head(filtered_list);
if (_v0.$ === 'Just') {
var _v1 = _v0.a;
var info = _v1.b;
return info;
} else {
return 'IDK';
}
};
var $author$project$Main$encodeModel = function (model) {
return A2(
$elm$json$Json$Encode$encode,
0,
$elm$json$Json$Encode$object(
_List_fromArray(
[
_Utils_Tuple2(
'model-version',
$elm$json$Json$Encode$int($author$project$Main$modelVersion)),
_Utils_Tuple2(
'pc',
$elm$json$Json$Encode$object(
_List_fromArray(
[
_Utils_Tuple2(
'addressBus',
$elm$json$Json$Encode$int(model.pc.addressBus)),
_Utils_Tuple2(
'dataBus',
$elm$json$Json$Encode$int(model.pc.dataBus)),
_Utils_Tuple2(
'instructionReg',
$elm$json$Json$Encode$int(model.pc.instructionReg)),
_Utils_Tuple2(
'programmCounter',
$elm$json$Json$Encode$int(model.pc.programmCounter)),
_Utils_Tuple2(
'uCounter',
$elm$json$Json$Encode$int(model.pc.uCounter)),
_Utils_Tuple2(
'accumulator',
$elm$json$Json$Encode$int(model.pc.accumulator)),
_Utils_Tuple2(
'ram',
A2($elm$json$Json$Encode$list, $elm$json$Json$Encode$int, model.pc.ram))
]))),
_Utils_Tuple2(
'uCode',
A2(
$elm$json$Json$Encode$list,
$elm$json$Json$Encode$string,
A2($elm$core$List$map, $author$project$Main$uAction2String, model.uCode))),
_Utils_Tuple2(
'autoscroll',
$elm$json$Json$Encode$bool(model.autoscroll))
])));
};
var $author$project$Main$localStorageSend = _Platform_outgoingPort('localStorageSend', $elm$json$Json$Encode$string);
var $author$project$Main$cmdUpdateLocalStorage = function (model) {
return $author$project$Main$localStorageSend(
$author$project$Main$encodeModel(model));
};
var $author$project$Main$sendUUpdate = _Platform_outgoingPort('sendUUpdate', $elm$json$Json$Encode$string);
var $author$project$Main$cmdSenduUpdate = function (model) {
return $elm$core$Platform$Cmd$batch(
_List_fromArray(
[
$author$project$Main$cmdUpdateLocalStorage(model),
$author$project$Main$sendUUpdate('update')
]));
};
var $elm$json$Json$Decode$bool = _Json_decodeBool;
var $elm$json$Json$Decode$decodeString = _Json_runOnString;
var $elm$json$Json$Decode$field = _Json_decodeField;
var $elm$json$Json$Decode$int = _Json_decodeInt;
var $elm$json$Json$Decode$list = _Json_decodeList;
var $elm$json$Json$Decode$map3 = _Json_map3;
var $elm$json$Json$Decode$map7 = _Json_map7;
var $elm$core$Tuple$second = function (_v0) {
var y = _v0.b;
return y;
};
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$uCodeIds);
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 $elm$core$Maybe$withDefault = F2(
function (_default, maybe) {
if (maybe.$ === 'Just') {
var value = maybe.a;
return value;
} else {
return _default;
}
});
var $author$project$Main$decodeModel = function (text) {
var uCodeDecoder = A2(
$elm$json$Json$Decode$map,
function (s) {
return A2(
$elm$core$Maybe$withDefault,
$author$project$Main$ActNothing,
$author$project$Main$string2uAction(s));
},
$elm$json$Json$Decode$string);
var error2maybe = function (err) {
if (err.$ === 'Ok') {
var val = err.a;
return $elm$core$Maybe$Just(val);
} else {
return $elm$core$Maybe$Nothing;
}
};
return error2maybe(
A2(
$elm$json$Json$Decode$decodeString,
A4(
$elm$json$Json$Decode$map3,
$author$project$Main$Model,
A2(
$elm$json$Json$Decode$field,
'pc',
A8(
$elm$json$Json$Decode$map7,
$author$project$Main$PC,
A2(
$elm$json$Json$Decode$field,
'ram',
$elm$json$Json$Decode$list($elm$json$Json$Decode$int)),
A2($elm$json$Json$Decode$field, 'dataBus', $elm$json$Json$Decode$int),
A2($elm$json$Json$Decode$field, 'addressBus', $elm$json$Json$Decode$int),
A2($elm$json$Json$Decode$field, 'instructionReg', $elm$json$Json$Decode$int),
A2($elm$json$Json$Decode$field, 'programmCounter', $elm$json$Json$Decode$int),
A2($elm$json$Json$Decode$field, 'uCounter', $elm$json$Json$Decode$int),
A2($elm$json$Json$Decode$field, 'accumulator', $elm$json$Json$Decode$int))),
A2(
$elm$json$Json$Decode$field,
'uCode',
$elm$json$Json$Decode$list(uCodeDecoder)),
A2($elm$json$Json$Decode$field, 'autoscroll', $elm$json$Json$Decode$bool)),
text));
};
var $author$project$Main$actAccumulator2DataBus = function (pc) {
return _Utils_update(
pc,
@ -5549,45 +5753,6 @@ 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);
@ -5628,36 +5793,36 @@ var $author$project$Main$uStepPC = function (model) {
};
var $author$project$Main$update = F2(
function (msg, model) {
var updateModel = function (new_model) {
return _Utils_Tuple2(
new_model,
$author$project$Main$cmdUpdateLocalStorage(new_model));
};
switch (msg.$) {
case 'MsgUCycleStep':
return _Utils_Tuple2(
$author$project$Main$uStepPC(model),
$author$project$Main$sendUUpdate('uCycle updated'));
$author$project$Main$cmdSenduUpdate(model));
case 'MsgInstructionStep':
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
case 'MsgReset':
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{
pc: _Utils_update(
$author$project$Main$initialPC,
{ram: model.pc.ram})
}),
$elm$core$Platform$Cmd$none);
case 'MsgLocalSessionRecieve':
var message_in = msg.a;
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}));
case 'MsgManualStep':
var action = msg.a;
var instruction = $author$project$Main$getAction(action);
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{
pc: instruction(model.pc)
}),
$elm$core$Platform$Cmd$none);
}));
case 'MsgRamEditAddress':
var addr = msg.a;
var may_int = msg.b;
@ -5674,11 +5839,10 @@ var $author$project$Main$update = F2(
{
ram: A3($author$project$Main$changeAtInt, addr, new_val, old_pc.ram)
});
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{pc: new_pc}),
$elm$core$Platform$Cmd$none);
{pc: new_pc}));
} else {
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
@ -5698,11 +5862,10 @@ var $author$project$Main$update = F2(
{
ram: A3($author$project$Main$changeAtInt, addr, new_val, old_pc.ram)
});
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{pc: new_pc}),
$elm$core$Platform$Cmd$none);
{pc: new_pc}));
} else {
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
@ -5716,11 +5879,10 @@ var $author$project$Main$update = F2(
_List_fromArray(
[0]))
});
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{pc: new_pc}),
$elm$core$Platform$Cmd$none);
{pc: new_pc}));
case 'MsgCuEditAction':
var addr = msg.a;
var may_action = msg.b;
@ -5728,16 +5890,15 @@ var $author$project$Main$update = F2(
if (_v5.$ === 'Just') {
var action = _v5.a;
var newCode = A3($author$project$Main$changeAtUCode, addr, action, model.uCode);
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{uCode: newCode}),
$elm$core$Platform$Cmd$none);
{uCode: newCode}));
} else {
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
case 'MsgCuAddBelow':
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{
@ -5745,8 +5906,7 @@ var $author$project$Main$update = F2(
model.uCode,
_List_fromArray(
[$author$project$Main$ActNothing]))
}),
$elm$core$Platform$Cmd$none);
}));
case 'MsgCuInstrRegEdit':
var text = msg.a;
var _v6 = $elm$core$String$toInt(text);
@ -5756,11 +5916,10 @@ var $author$project$Main$update = F2(
var new_pc = _Utils_update(
old_pc,
{instructionReg: _int});
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{pc: new_pc}),
$elm$core$Platform$Cmd$none);
{pc: new_pc}));
} else {
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
@ -5773,11 +5932,10 @@ var $author$project$Main$update = F2(
var new_pc = _Utils_update(
old_pc,
{programmCounter: _int});
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{pc: new_pc}),
$elm$core$Platform$Cmd$none);
{pc: new_pc}));
} else {
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
@ -5794,7 +5952,7 @@ var $author$project$Main$update = F2(
_Utils_update(
model,
{pc: new_pc}),
$author$project$Main$sendUUpdate('uCycle updated'));
$author$project$Main$cmdSenduUpdate(model));
} else {
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
@ -5811,7 +5969,7 @@ var $author$project$Main$update = F2(
_Utils_update(
model,
{pc: new_pc}),
$author$project$Main$sendUUpdate('uCycle updated'));
$author$project$Main$cmdSenduUpdate(model));
} else {
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
@ -5824,11 +5982,10 @@ var $author$project$Main$update = F2(
var new_pc = _Utils_update(
old_pc,
{dataBus: _int});
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{pc: new_pc}),
$elm$core$Platform$Cmd$none);
{pc: new_pc}));
} else {
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
@ -5841,30 +5998,41 @@ var $author$project$Main$update = F2(
var new_pc = _Utils_update(
old_pc,
{accumulator: _int});
return _Utils_Tuple2(
return updateModel(
_Utils_update(
model,
{pc: new_pc}),
$elm$core$Platform$Cmd$none);
{pc: new_pc}));
} else {
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
default:
return _Utils_Tuple2(
case 'MsgAutoscrollUpdate':
return updateModel(
_Utils_update(
model,
{autoscroll: !model.autoscroll}),
$elm$core$Platform$Cmd$none);
{autoscroll: !model.autoscroll}));
case 'MsgLocalSessionExport':
return _Utils_Tuple2(
model,
$author$project$Main$cmdUpdateLocalStorage(model));
default:
var message_in = msg.a;
var _v12 = $author$project$Main$decodeModel(message_in);
if (_v12.$ === 'Just') {
var new_model = _v12.a;
return _Utils_Tuple2(new_model, $elm$core$Platform$Cmd$none);
} else {
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
}
});
var $elm$virtual_dom$VirtualDom$lazy = _VirtualDom_lazy;
var $elm$html$Html$Lazy$lazy = $elm$virtual_dom$VirtualDom$lazy;
var $author$project$Main$MsgAutoscrollUpdate = {$: 'MsgAutoscrollUpdate'};
var $author$project$Main$MsgInstructionStep = {$: 'MsgInstructionStep'};
var $author$project$Main$MsgLocalSessionExport = {$: 'MsgLocalSessionExport'};
var $author$project$Main$MsgReset = {$: 'MsgReset'};
var $author$project$Main$MsgUCycleStep = {$: 'MsgUCycleStep'};
var $elm$html$Html$button = _VirtualDom_node('button');
var $elm$json$Json$Encode$bool = _Json_wrap;
var $elm$html$Html$Attributes$boolProperty = F2(
function (key, bool) {
return A2(
@ -5986,7 +6154,6 @@ var $elm$html$Html$Events$stopPropagationOn = F2(
event,
$elm$virtual_dom$VirtualDom$MayStopPropagation(decoder));
});
var $elm$json$Json$Decode$field = _Json_decodeField;
var $elm$json$Json$Decode$at = F2(
function (fields, decoder) {
return A3($elm$core$List$foldr, $elm$json$Json$Decode$field, decoder, fields);
@ -6195,6 +6362,23 @@ var $author$project$Main$selectCuValueDecoder = A2(
'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$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$viewCuInstrSelect = F2(
function (id, current) {
var info2option = function (_v0) {
@ -6205,7 +6389,9 @@ var $author$project$Main$viewCuInstrSelect = F2(
_List_fromArray(
[
$elm$html$Html$Attributes$selected(
_Utils_eq(action, current))
_Utils_eq(action, current)),
$elm$html$Html$Attributes$value(
$author$project$Main$uAction2String(action))
]),
_List_fromArray(
[
@ -6946,8 +7132,18 @@ var $author$project$Main$viewPC = function (model) {
]),
_List_fromArray(
[
$elm$html$Html$text('Automatisch zum Eintrag Scrollen')
$elm$html$Html$text('Autoscroll')
]))
])),
A2(
$elm$html$Html$button,
_List_fromArray(
[
$elm$html$Html$Events$onClick($author$project$Main$MsgLocalSessionExport)
]),
_List_fromArray(
[
$elm$html$Html$text('Export')
]))
])),
A2(

View File

@ -44,6 +44,17 @@ function shrinkTableHead(scroll){
}
function loadStorage() {
let content = localStorage.getItem("pc_data");
if( typeof content == "string" ){
app.ports.localStorageRecieve.send( content );
}
}
// Load last state of pc
loadStorage();
// EVENT LISTENERS
pc_ram_scroller.addEventListener("scroll", shrinkTableHead);
@ -57,3 +68,9 @@ app.ports.sendUUpdate.subscribe( (message) => {
// Make sure that even when the calculation takes longer it will scroll correctly
setTimeout( scrollToCurrent, 100 );
} );
// Recieve LocalSession Updates via Ports
app.ports.localStorageSend.subscribe( (message) => {
console.log("localSessionSend: ", message);
localStorage.setItem("pc_data", message);
} );