Make Edits persist after reload

This commit is contained in:
Christian 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);
} );

View File

@ -11,10 +11,11 @@ import Html.Lazy exposing (lazy)
import Tuple
import Array exposing (get)
import Html exposing (address)
import Json.Encode as JE
import Json.Decode as JD
import Html.Events exposing (targetValue)
modelVersion = 1
-- Note that general Stuff is at the end of the document
-- PORTS
@ -23,10 +24,10 @@ import Html.Events exposing (targetValue)
port sendUUpdate : String -> Cmd msg
port sendRamUpdate : String -> Cmd msg
port localStorageSend : String -> Cmd msg
port recieveLocalSession : (String -> msg) -> Sub msg
port localStorageRecieve : (String -> msg) -> Sub msg
type alias PC =
@ -82,6 +83,23 @@ uCodeDescriptions =
, ( ActNothing, "Empty" )
]
uCodeIds : List ( UAction, String )
uCodeIds =
[ ( ActAccumulator2DataBus, "acc2db" )
, ( ActAccumulatorDecrement, "accDec" )
, ( ActAccumulatorIncrement, "accInc" )
, ( ActDataBus2Accumulator, "db2acc" )
, ( ActDataBus2InstructionReg, "db2ir" )
, ( ActDataBus2Ram, "db2ram" )
, ( ActInstructionReg2AddressBus, "ir2ab" )
, ( ActInstructionReg2ProgrammCounter, "ir2pc" )
, ( ActInstructionReg2UCounter, "ir2uc" )
, ( ActProgrammCounterIncrement, "pcInc" )
, ( ActRam2DataBus, "ram2db" )
, ( ActResetUCounter, "ucReset" )
, ( ActProgrammCounter2AddressBus, "pc2ab" )
, ( ActNothing, "n" )
]
uCodeMaps : List ( UAction, PC -> PC )
uCodeMaps =
@ -210,34 +228,34 @@ type Msg
| MsgEditAddressBus String
| MsgEditDataBus String
| MsgAluEdit String
| MsgLocalSessionExport
| MsgLocalSessionRecieve String
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
let
updateModel new_model =
( new_model, cmdUpdateLocalStorage new_model)
in
case msg of
MsgUCycleStep ->
( uStepPC model
, sendUUpdate "uCycle updated"
, cmdSenduUpdate model
)
MsgInstructionStep ->
( model, Cmd.none )
MsgReset ->
( { model | pc = { initialPC | ram = model.pc.ram } }
, Cmd.none
)
MsgLocalSessionRecieve message_in ->
( model, Cmd.none )
updateModel { model | pc = { initialPC | ram = model.pc.ram } }
MsgManualStep action ->
let
instruction = getAction action
in
( { model | pc = instruction model.pc}
, Cmd.none )
updateModel { model | pc = instruction model.pc}
MsgRamEditAddress addr may_int ->
case String.toInt may_int of
@ -248,8 +266,7 @@ update msg model =
old_pc = model.pc
new_pc = { old_pc | ram = (changeAtInt addr new_val old_pc.ram) }
in
({ model | pc = new_pc }
, Cmd.none )
updateModel { model | pc = new_pc }
_ -> (model, Cmd.none)
MsgRamEditInstr addr may_int ->
@ -261,8 +278,7 @@ update msg model =
old_pc = model.pc
new_pc = { old_pc | ram = (changeAtInt addr new_val old_pc.ram) }
in
({ model | pc = new_pc }
, Cmd.none )
updateModel { model | pc = new_pc }
_ -> ( model, Cmd.none )
MsgRamAddBelow ->
@ -270,8 +286,7 @@ update msg model =
old_pc = model.pc
new_pc = {old_pc | ram = old_pc.ram ++ [0]}
in
({model | pc = new_pc}, Cmd.none)
updateModel {model | pc = new_pc}
MsgCuEditAction addr may_action ->
case string2uAction may_action of
@ -279,13 +294,11 @@ update msg model =
let
newCode = changeAtUCode addr action model.uCode
in
({ model | uCode = newCode }, Cmd.none)
updateModel { model | uCode = newCode }
_ -> ( model, Cmd.none )
MsgCuAddBelow ->
( {model | uCode = model.uCode ++ [ ActNothing ]}
, Cmd.none
)
updateModel {model | uCode = model.uCode ++ [ ActNothing ]}
MsgCuInstrRegEdit text ->
case String.toInt text of
@ -293,7 +306,7 @@ update msg model =
let old_pc = model.pc
new_pc = { old_pc | instructionReg = int }
in
( { model | pc = new_pc }, Cmd.none )
updateModel { model | pc = new_pc }
_ -> ( model, Cmd.none )
MsgCuProgCounterEdit text ->
@ -302,7 +315,7 @@ update msg model =
let old_pc = model.pc
new_pc = { old_pc | programmCounter = int }
in
( { model | pc = new_pc }, Cmd.none )
updateModel { model | pc = new_pc }
_ -> ( model, Cmd.none )
MsgCuUCounterEdit text ->
@ -311,7 +324,7 @@ update msg model =
let old_pc = model.pc
new_pc = { old_pc | uCounter = int }
in
( { model | pc = new_pc }, sendUUpdate "uCycle updated" )
( { model | pc = new_pc }, cmdSenduUpdate model )
_ -> ( model, Cmd.none )
MsgEditAddressBus text ->
@ -320,7 +333,7 @@ update msg model =
let old_pc = model.pc
new_pc = { old_pc | addressBus = int }
in
( { model | pc = new_pc }, sendUUpdate "uCycle updated" )
( { model | pc = new_pc }, cmdSenduUpdate model )
_ -> ( model, Cmd.none )
MsgEditDataBus text ->
@ -329,7 +342,7 @@ update msg model =
let old_pc = model.pc
new_pc = { old_pc | dataBus = int }
in
( { model | pc = new_pc }, Cmd.none )
updateModel { model | pc = new_pc }
_ -> ( model, Cmd.none )
MsgAluEdit text ->
@ -338,13 +351,20 @@ update msg model =
let old_pc = model.pc
new_pc = { old_pc | accumulator = int }
in
( { model | pc = new_pc }, Cmd.none )
updateModel { model | pc = new_pc }
_ -> ( model, Cmd.none )
MsgAutoscrollUpdate ->
( { model | autoscroll = not model.autoscroll }
, Cmd.none
)
updateModel { model | autoscroll = not model.autoscroll }
MsgLocalSessionExport ->
( model, cmdUpdateLocalStorage model )
MsgLocalSessionRecieve message_in ->
case decodeModel message_in of
Just new_model ->
( new_model , Cmd.none )
_ -> ( model, Cmd.none )
@ -402,7 +422,74 @@ uStepPC model =
_ ->
model
encodeModel : Model -> String
encodeModel model =
JE.object
[ ( "model-version", JE.int modelVersion )
, ( "pc"
, JE.object
[ ("addressBus", JE.int model.pc.addressBus )
, ("dataBus", JE.int model.pc.dataBus )
, ("instructionReg", JE.int model.pc.instructionReg )
, ("programmCounter", JE.int model.pc.programmCounter )
, ("uCounter", JE.int model.pc.uCounter )
, ("accumulator", JE.int model.pc.accumulator )
, ("ram", JE.list JE.int model.pc.ram)
]
)
, ( "uCode", JE.list JE.string (List.map uAction2String model.uCode) )
, ( "autoscroll", JE.bool model.autoscroll )
]
|> JE.encode 0
decodeModel : String -> Maybe Model
decodeModel text =
let
error2maybe err =
case err of
Ok val -> Just val
_ -> Nothing
uCodeDecoder =
JD.map
(\s -> Maybe.withDefault ActNothing <| string2uAction s )
(JD.string)
in
text
|> JD.decodeString
( JD.map3
Model
( JD.field "pc"
( JD.map7
PC
(JD.field "ram" (JD.list JD.int))
(JD.field "dataBus" JD.int)
(JD.field "addressBus" JD.int)
(JD.field "instructionReg" JD.int)
(JD.field "programmCounter" JD.int)
(JD.field "uCounter" JD.int)
(JD.field "accumulator" JD.int)
)
)
( JD.field "uCode" (JD.list uCodeDecoder) )
( JD.field "autoscroll" JD.bool )
)
|> error2maybe
cmdUpdateLocalStorage : Model -> Cmd Msg
cmdUpdateLocalStorage model =
localStorageSend (encodeModel model)
cmdSenduUpdate : Model -> Cmd Msg
cmdSenduUpdate model =
Cmd.batch
[ cmdUpdateLocalStorage model
, sendUUpdate "update"
]
-- VIEWERS
view : Model -> Html Msg
view model =
@ -433,8 +520,9 @@ viewPC model =
[]
, Html.label
[ HAttr.for "enableScrolling" ]
[ text "Automatisch zum Eintrag Scrollen" ]
[ text "Autoscroll" ]
]
, button [ onClick MsgLocalSessionExport ] [ text "Export" ]
]
, div [ class "grid-fullwidth" ] [ lazy viewAddressBus model ]
, lazy viewRam model
@ -638,7 +726,10 @@ viewCuInstrSelect : Int -> UAction -> Html Msg
viewCuInstrSelect id current =
let
info2option (action, info) =
Html.option [ HAttr.selected (action == current) ] [ text info ]
Html.option
[ HAttr.selected (action == current)
, HAttr.value (uAction2String action) ]
[ text info ]
listOptions = List.map info2option uCodeDescriptions
in
Html.select
@ -891,7 +982,7 @@ seperateInstructionsEntry i =
uAction2String : UAction -> String
uAction2String action =
let
filtered_list = List.filter (\s -> Tuple.first s == action) uCodeDescriptions
filtered_list = List.filter (\s -> Tuple.first s == action) uCodeIds
in
case List.head filtered_list of
Just (_,info) -> info
@ -900,7 +991,7 @@ uAction2String action =
string2uAction : String -> Maybe UAction
string2uAction msg =
let
filtered_list = List.filter (\s -> Tuple.second s == msg) uCodeDescriptions
filtered_list = List.filter (\s -> Tuple.second s == msg) uCodeIds
in
case List.head filtered_list of
Just (action,_) -> Just action
@ -917,7 +1008,7 @@ selectCuValueDecoder =
subscriptions : Model -> Sub Msg
subscriptions model =
recieveLocalSession MsgLocalSessionRecieve
localStorageRecieve MsgLocalSessionRecieve
init : () -> ( Model, Cmd Msg )