diff --git a/out/js/elm.js b/out/js/elm.js index 12c1bad..8736840 100644 --- a/out/js/elm.js +++ b/out/js/elm.js @@ -784,11 +784,11 @@ function _Debug_crash_UNUSED(identifier, fact1, fact2, fact3, fact4) function _Debug_regionToString(region) { - if (region.X.L === region.ab.L) + if (region.P.F === region.U.F) { - return 'on line ' + region.X.L; + return 'on line ' + region.P.F; } - return 'on lines ' + region.X.L + ' through ' + region.ab.L; + return 'on lines ' + region.P.F + ' through ' + region.U.F; } @@ -1857,9 +1857,9 @@ var _Platform_worker = F4(function(impl, flagDecoder, debugMetadata, args) return _Platform_initialize( flagDecoder, args, - impl.aR, + impl.aO, + impl.a6, impl.a2, - impl.a0, function() { return function() {} } ); }); @@ -2704,9 +2704,9 @@ var _VirtualDom_mapEventTuple = F2(function(func, tuple) var _VirtualDom_mapEventRecord = F2(function(func, record) { return { - x: func(record.x), - Y: record.Y, - V: record.V + o: func(record.o), + Q: record.Q, + N: record.N } }); @@ -2974,11 +2974,11 @@ function _VirtualDom_makeCallback(eventNode, initialHandler) // 3 = Custom var value = result.a; - var message = !tag ? value : tag < 3 ? value.a : value.x; - var stopPropagation = tag == 1 ? value.b : tag == 3 && value.Y; + var message = !tag ? value : tag < 3 ? value.a : value.o; + var stopPropagation = tag == 1 ? value.b : tag == 3 && value.Q; var currentEventNode = ( stopPropagation && event.stopPropagation(), - (tag == 2 ? value.b : tag == 3 && value.V) && event.preventDefault(), + (tag == 2 ? value.b : tag == 3 && value.N) && event.preventDefault(), eventNode ); var tagger; @@ -3928,11 +3928,11 @@ var _Browser_element = _Debugger_element || F4(function(impl, flagDecoder, debug return _Platform_initialize( flagDecoder, args, - impl.aR, + impl.aO, + impl.a6, impl.a2, - impl.a0, function(sendToApp, initialModel) { - var view = impl.a4; + var view = impl.a9; /**/ var domNode = args['node']; //*/ @@ -3964,12 +3964,12 @@ var _Browser_document = _Debugger_document || F4(function(impl, flagDecoder, deb return _Platform_initialize( flagDecoder, args, - impl.aR, + impl.aO, + impl.a6, impl.a2, - impl.a0, function(sendToApp, initialModel) { - var divertHrefToApp = impl.W && impl.W(sendToApp) - var view = impl.a4; + var divertHrefToApp = impl.O && impl.O(sendToApp) + var view = impl.a9; var title = _VirtualDom_doc.title; var bodyNode = _VirtualDom_doc.body; var currNode = _VirtualDom_virtualize(bodyNode); @@ -3977,12 +3977,12 @@ var _Browser_document = _Debugger_document || F4(function(impl, flagDecoder, deb { _VirtualDom_divertHrefToApp = divertHrefToApp; var doc = view(model); - var nextNode = _VirtualDom_node('body')(_List_Nil)(doc.aJ); + var nextNode = _VirtualDom_node('body')(_List_Nil)(doc.aE); var patches = _VirtualDom_diff(currNode, nextNode); bodyNode = _VirtualDom_applyPatches(bodyNode, currNode, patches, sendToApp); currNode = nextNode; _VirtualDom_divertHrefToApp = 0; - (title !== doc.aA) && (_VirtualDom_doc.title = title = doc.aA); + (title !== doc.as) && (_VirtualDom_doc.title = title = doc.as); }); } ); @@ -4038,12 +4038,12 @@ function _Browser_makeAnimator(model, draw) function _Browser_application(impl) { - var onUrlChange = impl.aU; - var onUrlRequest = impl.aV; + var onUrlChange = impl.aT; + var onUrlRequest = impl.aU; var key = function() { key.a(onUrlChange(_Browser_getUrl())); }; return _Browser_document({ - W: function(sendToApp) + O: function(sendToApp) { key.a = sendToApp; _Browser_window.addEventListener('popstate', key); @@ -4059,9 +4059,9 @@ function _Browser_application(impl) var next = $elm$url$Url$fromString(href).a; sendToApp(onUrlRequest( (next - && curr.aq === next.aq - && curr.ah === next.ah - && curr.an.a === next.an.a + && curr.ai === next.ai + && curr._ === next._ + && curr.af.a === next.af.a ) ? $elm$browser$Browser$Internal(next) : $elm$browser$Browser$External(href) @@ -4069,13 +4069,13 @@ function _Browser_application(impl) } }); }, - aR: function(flags) + aO: function(flags) { - return A3(impl.aR, flags, _Browser_getUrl(), key); + return A3(impl.aO, flags, _Browser_getUrl(), key); }, - a4: impl.a4, - a2: impl.a2, - a0: impl.a0 + a9: impl.a9, + a6: impl.a6, + a2: impl.a2 }); } @@ -4141,17 +4141,17 @@ var _Browser_decodeEvent = F2(function(decoder, event) function _Browser_visibilityInfo() { return (typeof _VirtualDom_doc.hidden !== 'undefined') - ? { aP: 'hidden', aK: 'visibilitychange' } + ? { aL: 'hidden', aF: 'visibilitychange' } : (typeof _VirtualDom_doc.mozHidden !== 'undefined') - ? { aP: 'mozHidden', aK: 'mozvisibilitychange' } + ? { aL: 'mozHidden', aF: 'mozvisibilitychange' } : (typeof _VirtualDom_doc.msHidden !== 'undefined') - ? { aP: 'msHidden', aK: 'msvisibilitychange' } + ? { aL: 'msHidden', aF: 'msvisibilitychange' } : (typeof _VirtualDom_doc.webkitHidden !== 'undefined') - ? { aP: 'webkitHidden', aK: 'webkitvisibilitychange' } - : { aP: 'hidden', aK: 'visibilitychange' }; + ? { aL: 'webkitHidden', aF: 'webkitvisibilitychange' } + : { aL: 'hidden', aF: 'visibilitychange' }; } @@ -4232,12 +4232,12 @@ var _Browser_call = F2(function(functionName, id) function _Browser_getViewport() { return { - aw: _Browser_getScene(), - aC: { - aE: _Browser_window.pageXOffset, - aF: _Browser_window.pageYOffset, - aD: _Browser_doc.documentElement.clientWidth, - ag: _Browser_doc.documentElement.clientHeight + ao: _Browser_getScene(), + au: { + aw: _Browser_window.pageXOffset, + ax: _Browser_window.pageYOffset, + av: _Browser_doc.documentElement.clientWidth, + Z: _Browser_doc.documentElement.clientHeight } }; } @@ -4247,8 +4247,8 @@ function _Browser_getScene() var body = _Browser_doc.body; var elem = _Browser_doc.documentElement; return { - aD: Math.max(body.scrollWidth, body.offsetWidth, elem.scrollWidth, elem.offsetWidth, elem.clientWidth), - ag: Math.max(body.scrollHeight, body.offsetHeight, elem.scrollHeight, elem.offsetHeight, elem.clientHeight) + av: Math.max(body.scrollWidth, body.offsetWidth, elem.scrollWidth, elem.offsetWidth, elem.clientWidth), + Z: Math.max(body.scrollHeight, body.offsetHeight, elem.scrollHeight, elem.offsetHeight, elem.clientHeight) }; } @@ -4271,15 +4271,15 @@ function _Browser_getViewportOf(id) return _Browser_withNode(id, function(node) { return { - aw: { - aD: node.scrollWidth, - ag: node.scrollHeight + ao: { + av: node.scrollWidth, + Z: node.scrollHeight }, - aC: { - aE: node.scrollLeft, - aF: node.scrollTop, - aD: node.clientWidth, - ag: node.clientHeight + au: { + aw: node.scrollLeft, + ax: node.scrollTop, + av: node.clientWidth, + Z: node.clientHeight } }; }); @@ -4309,18 +4309,18 @@ function _Browser_getElement(id) var x = _Browser_window.pageXOffset; var y = _Browser_window.pageYOffset; return { - aw: _Browser_getScene(), - aC: { - aE: x, - aF: y, - aD: _Browser_doc.documentElement.clientWidth, - ag: _Browser_doc.documentElement.clientHeight + ao: _Browser_getScene(), + au: { + aw: x, + ax: y, + av: _Browser_doc.documentElement.clientWidth, + Z: _Browser_doc.documentElement.clientHeight }, - aM: { - aE: x + rect.left, - aF: y + rect.top, - aD: rect.width, - ag: rect.height + aI: { + aw: x + rect.left, + ax: y + rect.top, + av: rect.width, + Z: rect.height } }; }); @@ -4358,6 +4358,43 @@ function _Browser_load(url) +var _Bitwise_and = F2(function(a, b) +{ + return a & b; +}); + +var _Bitwise_or = F2(function(a, b) +{ + return a | b; +}); + +var _Bitwise_xor = F2(function(a, b) +{ + return a ^ b; +}); + +function _Bitwise_complement(a) +{ + return ~a; +}; + +var _Bitwise_shiftLeftBy = F2(function(offset, a) +{ + return a << offset; +}); + +var _Bitwise_shiftRightBy = F2(function(offset, a) +{ + return a >> offset; +}); + +var _Bitwise_shiftRightZfBy = F2(function(offset, a) +{ + return a >>> offset; +}); + + + // SEND REQUEST var _Http_toTask = F3(function(router, toTask, request) @@ -4365,25 +4402,25 @@ var _Http_toTask = F3(function(router, toTask, request) return _Scheduler_binding(function(callback) { function done(response) { - callback(toTask(request.ad.a(response))); + callback(toTask(request.W.a(response))); } var xhr = new XMLHttpRequest(); xhr.addEventListener('error', function() { done($elm$http$Http$NetworkError_); }); xhr.addEventListener('timeout', function() { done($elm$http$Http$Timeout_); }); - xhr.addEventListener('load', function() { done(_Http_toResponse(request.ad.b, xhr)); }); - $elm$core$Maybe$isJust(request.aB) && _Http_track(router, xhr, request.aB.a); + xhr.addEventListener('load', function() { done(_Http_toResponse(request.W.b, xhr)); }); + $elm$core$Maybe$isJust(request.at) && _Http_track(router, xhr, request.at.a); try { - xhr.open(request.aS, request.S, true); + xhr.open(request.aR, request.K, true); } catch (e) { - return done($elm$http$Http$BadUrl_(request.S)); + return done($elm$http$Http$BadUrl_(request.K)); } _Http_configureRequest(xhr, request); - request.aJ.a && xhr.setRequestHeader('Content-Type', request.aJ.a); - xhr.send(request.aJ.b); + request.aE.a && xhr.setRequestHeader('Content-Type', request.aE.a); + xhr.send(request.aE.b); return function() { xhr.c = true; xhr.abort(); }; }); @@ -4394,13 +4431,13 @@ var _Http_toTask = F3(function(router, toTask, request) function _Http_configureRequest(xhr, request) { - for (var headers = request.af; headers.b; headers = headers.b) // WHILE_CONS + for (var headers = request.Y; headers.b; headers = headers.b) // WHILE_CONS { xhr.setRequestHeader(headers.a.a, headers.a.b); } - xhr.timeout = request.a1.a || 0; - xhr.responseType = request.ad.d; - xhr.withCredentials = request.aH; + xhr.timeout = request.a3.a || 0; + xhr.responseType = request.W.d; + xhr.withCredentials = request.aC; } @@ -4421,10 +4458,10 @@ function _Http_toResponse(toBody, xhr) function _Http_toMetadata(xhr) { return { - S: xhr.responseURL, - a_: xhr.status, - a$: xhr.statusText, - af: _Http_parseHeaders(xhr.getAllResponseHeaders()) + K: xhr.responseURL, + a0: xhr.status, + a1: xhr.statusText, + Y: _Http_parseHeaders(xhr.getAllResponseHeaders()) }; } @@ -4519,15 +4556,15 @@ function _Http_track(router, xhr, tracker) xhr.upload.addEventListener('progress', function(event) { if (xhr.c) { return; } _Scheduler_rawSpawn(A2($elm$core$Platform$sendToSelf, router, _Utils_Tuple2(tracker, $elm$http$Http$Sending({ - aZ: event.loaded, - ax: event.total + a$: event.loaded, + ap: event.total })))); }); xhr.addEventListener('progress', function(event) { if (xhr.c) { return; } _Scheduler_rawSpawn(A2($elm$core$Platform$sendToSelf, router, _Utils_Tuple2(tracker, $elm$http$Http$Receiving({ - aX: event.loaded, - ax: event.lengthComputable ? $elm$core$Maybe$Just(event.total) : $elm$core$Maybe$Nothing + aZ: event.loaded, + ap: event.lengthComputable ? $elm$core$Maybe$Just(event.total) : $elm$core$Maybe$Nothing })))); }); }var $elm$core$Basics$EQ = 1; @@ -4936,25 +4973,25 @@ var $elm$core$Array$treeFromBuilder = F2( }); var $elm$core$Array$builderToArray = F2( function (reverseNodeList, builder) { - if (!builder.b) { + if (!builder.a) { return A4( $elm$core$Array$Array_elm_builtin, - $elm$core$Elm$JsArray$length(builder.e), + $elm$core$Elm$JsArray$length(builder.c), $elm$core$Array$shiftStep, $elm$core$Elm$JsArray$empty, - builder.e); + builder.c); } else { - var treeLen = builder.b * $elm$core$Array$branchFactor; + var treeLen = builder.a * $elm$core$Array$branchFactor; var depth = $elm$core$Basics$floor( A2($elm$core$Basics$logBase, $elm$core$Array$branchFactor, treeLen - 1)); - var correctNodeList = reverseNodeList ? $elm$core$List$reverse(builder.f) : builder.f; - var tree = A2($elm$core$Array$treeFromBuilder, correctNodeList, builder.b); + var correctNodeList = reverseNodeList ? $elm$core$List$reverse(builder.d) : builder.d; + var tree = A2($elm$core$Array$treeFromBuilder, correctNodeList, builder.a); return A4( $elm$core$Array$Array_elm_builtin, - $elm$core$Elm$JsArray$length(builder.e) + treeLen, + $elm$core$Elm$JsArray$length(builder.c) + treeLen, A2($elm$core$Basics$max, 5, depth * $elm$core$Array$shiftStep), tree, - builder.e); + builder.c); } }); var $elm$core$Basics$idiv = _Basics_idiv; @@ -4967,7 +5004,7 @@ var $elm$core$Array$initializeHelp = F5( return A2( $elm$core$Array$builderToArray, false, - {f: nodeList, b: (len / $elm$core$Array$branchFactor) | 0, e: tail}); + {d: nodeList, a: (len / $elm$core$Array$branchFactor) | 0, c: tail}); } else { var leaf = $elm$core$Array$Leaf( A3($elm$core$Elm$JsArray$initialize, $elm$core$Array$branchFactor, fromIndex, fn)); @@ -5034,7 +5071,7 @@ var $elm$url$Url$Http = 0; var $elm$url$Url$Https = 1; var $elm$url$Url$Url = F6( function (protocol, host, port_, path, query, fragment) { - return {ae: fragment, ah: host, al: path, an: port_, aq: protocol, ar: query}; + return {X: fragment, _: host, ad: path, af: port_, ai: protocol, aj: query}; }); var $elm$core$String$contains = _String_contains; var $elm$core$String$length = _String_length; @@ -5313,260 +5350,217 @@ var $elm$core$Task$perform = F2( A2($elm$core$Task$map, toMessage, task)); }); var $elm$browser$Browser$element = _Browser_element; -var $author$project$Main$Model = F7( - function (pc, uCode, autoscroll, examples, exampleChooserOpen, examplesListStatus, exampleLoaderStatus) { - return {A: autoscroll, G: exampleChooserOpen, Q: exampleLoaderStatus, H: examples, R: examplesListStatus, a: pc, q: uCode}; - }); var $author$project$Main$Waiting = {$: 1}; -var $author$project$Main$PC = F7( - function (ram, dataBus, addressBus, instructionReg, programmCounter, uCounter, accumulator) { - return {m: accumulator, r: addressBus, s: dataBus, k: instructionReg, u: programmCounter, c: ram, l: uCounter}; +var $elm$core$Array$fromListHelp = F3( + function (list, nodeList, nodeListSize) { + fromListHelp: + while (true) { + var _v0 = A2($elm$core$Elm$JsArray$initializeFromList, $elm$core$Array$branchFactor, list); + var jsArray = _v0.a; + var remainingItems = _v0.b; + if (_Utils_cmp( + $elm$core$Elm$JsArray$length(jsArray), + $elm$core$Array$branchFactor) < 0) { + return A2( + $elm$core$Array$builderToArray, + true, + {d: nodeList, a: nodeListSize, c: jsArray}); + } else { + var $temp$list = remainingItems, + $temp$nodeList = A2( + $elm$core$List$cons, + $elm$core$Array$Leaf(jsArray), + nodeList), + $temp$nodeListSize = nodeListSize + 1; + list = $temp$list; + nodeList = $temp$nodeList; + nodeListSize = $temp$nodeListSize; + continue fromListHelp; + } + } }); -var $author$project$Main$initialRam = _List_fromArray( - [ - _Utils_Tuple2(100005, 'LoadA #005'), - _Utils_Tuple2(300000, 'IncA'), - _Utils_Tuple2(200005, 'StoreA #005'), - _Utils_Tuple2(400000, 'JMP #000'), - _Utils_Tuple2(0, ''), - _Utils_Tuple2(5, 'val'), - _Utils_Tuple2(0, ''), - _Utils_Tuple2(0, ''), - _Utils_Tuple2(0, ''), - _Utils_Tuple2(0, ''), - _Utils_Tuple2(0, '') - ]); -var $author$project$Main$initialPC = A7($author$project$Main$PC, $author$project$Main$initialRam, 0, 0, 0, 0, 0, 0); -var $author$project$Main$ActAccumulator2DataBus = 0; -var $author$project$Main$ActAccumulatorIncrement = 2; -var $author$project$Main$ActDataBus2Accumulator = 3; -var $author$project$Main$ActDataBus2InstructionReg = 4; -var $author$project$Main$ActDataBus2Ram = 5; -var $author$project$Main$ActInstructionReg2AddressBus = 6; -var $author$project$Main$ActInstructionReg2ProgrammCounter = 7; -var $author$project$Main$ActInstructionReg2UCounter = 8; -var $author$project$Main$ActNothing = 14; -var $author$project$Main$ActProgrammCounter2AddressBus = 13; -var $author$project$Main$ActProgrammCounterIncrement = 9; -var $author$project$Main$ActRam2DataBus = 11; -var $author$project$Main$ActResetUCounter = 12; -var $author$project$Main$initialUCodes = _List_fromArray( - [13, 11, 4, 9, 8, 14, 14, 14, 14, 14, 6, 11, 3, 12, 14, 14, 14, 14, 14, 14, 0, 6, 5, 12, 14, 14, 14, 14, 14, 14, 2, 12, 14, 14, 14, 14, 14, 14, 14, 14, 7, 12, 14, 14, 14, 14, 14, 14, 14, 14]); +var $elm$core$Array$fromList = function (list) { + if (!list.b) { + return $elm$core$Array$empty; + } else { + return A3($elm$core$Array$fromListHelp, list, _List_Nil, 0); + } +}; +var $author$project$PC$Defaults$initialRam = $elm$core$Array$fromList( + _List_fromArray( + [ + _Utils_Tuple2(100005, 'LoadA #005'), + _Utils_Tuple2(300000, 'IncA'), + _Utils_Tuple2(200005, 'StoreA #005'), + _Utils_Tuple2(400000, 'JMP #000'), + _Utils_Tuple2(0, ''), + _Utils_Tuple2(5, 'val'), + _Utils_Tuple2(0, ''), + _Utils_Tuple2(0, ''), + _Utils_Tuple2(0, ''), + _Utils_Tuple2(0, ''), + _Utils_Tuple2(0, '') + ])); +var $author$project$PC$Defaults$initialPC = {az: 0, aB: 0, aG: 0, aP: 0, aX: 0, aY: $author$project$PC$Defaults$initialRam, a5: 0}; +var $author$project$PC$Types$UA_Accumulator2DataBus = 0; +var $author$project$PC$Types$UA_AccumulatorIncrement = 2; +var $author$project$PC$Types$UA_DataBus2Accumulator = 3; +var $author$project$PC$Types$UA_DataBus2InstructionReg = 4; +var $author$project$PC$Types$UA_DataBus2Ram = 5; +var $author$project$PC$Types$UA_InstructionReg2AddressBus = 6; +var $author$project$PC$Types$UA_InstructionReg2ProgrammCounter = 7; +var $author$project$PC$Types$UA_InstructionReg2UCounter = 8; +var $author$project$PC$Types$UA_Nothing = 14; +var $author$project$PC$Types$UA_ProgrammCounter2AddressBus = 13; +var $author$project$PC$Types$UA_ProgrammCounterIncrement = 9; +var $author$project$PC$Types$UA_Ram2DataBus = 11; +var $author$project$PC$Types$UA_ResetUCounter = 12; +var $author$project$PC$Defaults$initialUCodes = $elm$core$Array$fromList( + _List_fromArray( + [13, 11, 4, 9, 8, 14, 14, 14, 14, 14, 6, 11, 3, 12, 14, 14, 14, 14, 14, 14, 0, 6, 5, 12, 14, 14, 14, 14, 14, 14, 2, 12, 14, 14, 14, 14, 14, 14, 14, 14, 7, 12, 14, 14, 14, 14, 14, 14, 14, 14])); +var $author$project$PC$Defaults$initalModel = {aW: $author$project$PC$Defaults$initialPC, a4: $author$project$PC$Defaults$initialUCodes}; +var $author$project$PC$PC$init = $author$project$PC$Defaults$initalModel; 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) { return _Utils_Tuple2( - A7($author$project$Main$Model, $author$project$Main$initialPC, $author$project$Main$initialUCodes, true, _List_Nil, false, $author$project$Main$Waiting, $author$project$Main$Waiting), + {s: true, y: false, C: $author$project$Main$Waiting, D: _List_Nil, E: $author$project$Main$Waiting, p: $author$project$PC$PC$init}, $elm$core$Platform$Cmd$none); }; -var $author$project$Main$MsgLocalSessionRecieve = function (a) { - return {$: 19, a: a}; -}; -var $elm$json$Json$Decode$string = _Json_decodeString; -var $author$project$Main$localStorageRecieve = _Platform_incomingPort('localStorageRecieve', $elm$json$Json$Decode$string); +var $elm$core$Platform$Sub$batch = _Platform_batch; +var $elm$core$Platform$Sub$none = $elm$core$Platform$Sub$batch(_List_Nil); var $author$project$Main$subscriptions = function (model) { - return $author$project$Main$localStorageRecieve($author$project$Main$MsgLocalSessionRecieve); + return $elm$core$Platform$Sub$none; }; var $author$project$Main$Failure = function (a) { return {$: 0, a: a}; }; +var $author$project$Main$Msg_DEsmpl_ExampleLoaded = function (a) { + return {$: 4, a: a}; +}; +var $author$project$Main$Msg_DEsmpl_ListLoaded = function (a) { + return {$: 5, a: a}; +}; var $author$project$Main$Success = {$: 2}; -var $elm$core$List$append = F2( - function (xs, ys) { - if (!ys.b) { - return xs; - } else { - return A3($elm$core$List$foldr, $elm$core$List$cons, ys, xs); - } - }); -var $elm$core$List$drop = F2( - function (n, list) { - drop: - while (true) { - if (n <= 0) { - return list; - } else { - if (!list.b) { - return list; +var $elm$json$Json$Encode$string = _Json_wrap; +var $author$project$Main$sendUUpdate = _Platform_outgoingPort('sendUUpdate', $elm$json$Json$Encode$string); +var $author$project$Main$cmd_scoller = function (model) { + return $author$project$Main$sendUUpdate('update'); +}; +var $elm$json$Json$Encode$bool = _Json_wrap; +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(0), + pairs)); +}; +var $elm$json$Json$Encode$int = _Json_wrap; +var $elm$core$Elm$JsArray$foldl = _JsArray_foldl; +var $elm$core$Array$foldl = F3( + function (func, baseCase, _v0) { + var tree = _v0.c; + var tail = _v0.d; + var helper = F2( + function (node, acc) { + if (!node.$) { + var subTree = node.a; + return A3($elm$core$Elm$JsArray$foldl, helper, acc, subTree); } else { - var x = list.a; - var xs = list.b; - var $temp$n = n - 1, - $temp$list = xs; - n = $temp$n; - list = $temp$list; - continue drop; + var values = node.a; + return A3($elm$core$Elm$JsArray$foldl, func, acc, values); } - } - } + }); + return A3( + $elm$core$Elm$JsArray$foldl, + func, + A3($elm$core$Elm$JsArray$foldl, helper, baseCase, tree), + tail); }); -var $elm$core$List$repeatHelp = F3( - function (result, n, value) { - repeatHelp: - while (true) { - if (n <= 0) { - return result; - } else { - var $temp$result = A2($elm$core$List$cons, value, result), - $temp$n = n - 1, - $temp$value = value; - result = $temp$result; - n = $temp$n; - value = $temp$value; - continue repeatHelp; - } - } +var $elm$json$Json$Encode$array = F2( + function (func, entries) { + return _Json_wrap( + A3( + $elm$core$Array$foldl, + _Json_addEntry(func), + _Json_emptyArray(0), + entries)); }); -var $elm$core$List$repeat = F2( - function (n, value) { - return A3($elm$core$List$repeatHelp, _List_Nil, n, value); +var $elm$json$Json$Encode$list = F2( + function (func, entries) { + return _Json_wrap( + A3( + $elm$core$List$foldl, + _Json_addEntry(func), + _Json_emptyArray(0), + entries)); }); -var $elm$core$List$takeReverse = F3( - function (n, list, kept) { - takeReverse: - while (true) { - if (n <= 0) { - return kept; - } else { - if (!list.b) { - return kept; - } else { - var x = list.a; - var xs = list.b; - var $temp$n = n - 1, - $temp$list = xs, - $temp$kept = A2($elm$core$List$cons, x, kept); - n = $temp$n; - list = $temp$list; - kept = $temp$kept; - continue takeReverse; - } - } - } +var $author$project$PC$Json$tuple2Encoder = F3( + function (encA, encB, _v0) { + var valA = _v0.a; + var valB = _v0.b; + return A2( + $elm$json$Json$Encode$list, + $elm$core$Basics$identity, + _List_fromArray( + [ + encA(valA), + encB(valB) + ])); }); -var $elm$core$List$takeTailRec = F2( - function (n, list) { - return $elm$core$List$reverse( - A3($elm$core$List$takeReverse, n, list, _List_Nil)); +var $author$project$PC$Json$ramEncoder = function (arr) { + return A2( + $elm$json$Json$Encode$array, + A2($author$project$PC$Json$tuple2Encoder, $elm$json$Json$Encode$int, $elm$json$Json$Encode$string), + arr); +}; +var $author$project$PC$Json$pcEncoder = function (pc) { + return $elm$json$Json$Encode$object( + _List_fromArray( + [ + _Utils_Tuple2( + 'addressBus', + $elm$json$Json$Encode$int(pc.aB)), + _Utils_Tuple2( + 'dataBus', + $elm$json$Json$Encode$int(pc.aG)), + _Utils_Tuple2( + 'instructionReg', + $elm$json$Json$Encode$int(pc.aP)), + _Utils_Tuple2( + 'programmCounter', + $elm$json$Json$Encode$int(pc.aX)), + _Utils_Tuple2( + 'uCounter', + $elm$json$Json$Encode$int(pc.a5)), + _Utils_Tuple2( + 'accumulator', + $elm$json$Json$Encode$int(pc.az)), + _Utils_Tuple2( + 'ram', + $author$project$PC$Json$ramEncoder(pc.aY)) + ])); +}; +var $author$project$PC$Types$UCode = F4( + function (variant, id, action, label) { + return {aA: action, aM: id, aQ: label, a7: variant}; }); -var $elm$core$List$takeFast = F3( - function (ctr, n, list) { - if (n <= 0) { - return _List_Nil; - } else { - var _v0 = _Utils_Tuple2(n, list); - _v0$1: - while (true) { - _v0$5: - while (true) { - if (!_v0.b.b) { - return list; - } else { - if (_v0.b.b.b) { - switch (_v0.a) { - case 1: - break _v0$1; - case 2: - var _v2 = _v0.b; - var x = _v2.a; - var _v3 = _v2.b; - var y = _v3.a; - return _List_fromArray( - [x, y]); - case 3: - if (_v0.b.b.b.b) { - var _v4 = _v0.b; - var x = _v4.a; - var _v5 = _v4.b; - var y = _v5.a; - var _v6 = _v5.b; - var z = _v6.a; - return _List_fromArray( - [x, y, z]); - } else { - break _v0$5; - } - default: - if (_v0.b.b.b.b && _v0.b.b.b.b.b) { - var _v7 = _v0.b; - var x = _v7.a; - var _v8 = _v7.b; - var y = _v8.a; - var _v9 = _v8.b; - var z = _v9.a; - var _v10 = _v9.b; - var w = _v10.a; - var tl = _v10.b; - return (ctr > 1000) ? A2( - $elm$core$List$cons, - x, - A2( - $elm$core$List$cons, - y, - A2( - $elm$core$List$cons, - z, - A2( - $elm$core$List$cons, - w, - A2($elm$core$List$takeTailRec, n - 4, tl))))) : A2( - $elm$core$List$cons, - x, - A2( - $elm$core$List$cons, - y, - A2( - $elm$core$List$cons, - z, - A2( - $elm$core$List$cons, - w, - A3($elm$core$List$takeFast, ctr + 1, n - 4, tl))))); - } else { - break _v0$5; - } - } - } else { - if (_v0.a === 1) { - break _v0$1; - } else { - break _v0$5; - } - } - } - } - return list; - } - var _v1 = _v0.b; - var x = _v1.a; - return _List_fromArray( - [x]); - } - }); -var $elm$core$List$take = F2( - function (n, list) { - return A3($elm$core$List$takeFast, 0, n, 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); - if (_Utils_cmp(pos, len) > 0) { - var before2 = A2( - $elm$core$List$append, - before, - A2($elm$core$List$repeat, pos - len, _default)); - return A2( - $elm$core$List$append, - before2, - A2($elm$core$List$cons, newVal, after)); - } else { - return A2( - $elm$core$List$append, - before, - A2($elm$core$List$cons, newVal, after)); - } +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) { @@ -5577,14 +5571,325 @@ var $elm$core$List$head = function (list) { return $elm$core$Maybe$Nothing; } }; -var $author$project$Main$valueAt = F2( - function (n, l) { - return $elm$core$List$head( - A2($elm$core$List$drop, n, l)); +var $author$project$PC$Types$UA_AccumulatorDecrement = 1; +var $author$project$PC$Types$UA_InstructionReg2ProgrammCounterIfAccEq0 = 10; +var $author$project$PC$UActions$actAccumulator2DataBus = function (pc) { + return _Utils_update( + pc, + {aG: pc.az}); +}; +var $author$project$PC$UActions$actAccumulatorDecrement = function (pc) { + return _Utils_update( + pc, + {az: pc.az - 1}); +}; +var $author$project$PC$UActions$actAccumulatorIncrement = function (pc) { + return _Utils_update( + pc, + {az: pc.az + 1}); +}; +var $author$project$PC$UActions$actDataBus2Accumulator = function (pc) { + return _Utils_update( + pc, + {az: pc.aG}); +}; +var $author$project$PC$UActions$actDataBus2InstructionReg = function (pc) { + return _Utils_update( + pc, + {aP: pc.aG}); +}; +var $elm$core$Elm$JsArray$appendN = _JsArray_appendN; +var $elm$core$Elm$JsArray$slice = _JsArray_slice; +var $elm$core$Array$appendHelpBuilder = F2( + function (tail, builder) { + var tailLen = $elm$core$Elm$JsArray$length(tail); + var notAppended = ($elm$core$Array$branchFactor - $elm$core$Elm$JsArray$length(builder.c)) - tailLen; + var appended = A3($elm$core$Elm$JsArray$appendN, $elm$core$Array$branchFactor, builder.c, tail); + return (notAppended < 0) ? { + d: A2( + $elm$core$List$cons, + $elm$core$Array$Leaf(appended), + builder.d), + a: builder.a + 1, + c: A3($elm$core$Elm$JsArray$slice, notAppended, tailLen, tail) + } : ((!notAppended) ? { + d: A2( + $elm$core$List$cons, + $elm$core$Array$Leaf(appended), + builder.d), + a: builder.a + 1, + c: $elm$core$Elm$JsArray$empty + } : {d: builder.d, a: builder.a, c: appended}); }); -var $author$project$Main$valueAtRam = F2( - function (n, l) { - var _v0 = A2($author$project$Main$valueAt, n, l); +var $elm$core$Bitwise$and = _Bitwise_and; +var $elm$core$Bitwise$shiftRightZfBy = _Bitwise_shiftRightZfBy; +var $elm$core$Array$bitMask = 4294967295 >>> (32 - $elm$core$Array$shiftStep); +var $elm$core$Basics$ge = _Utils_ge; +var $elm$core$Elm$JsArray$push = _JsArray_push; +var $elm$core$Elm$JsArray$singleton = _JsArray_singleton; +var $elm$core$Elm$JsArray$unsafeGet = _JsArray_unsafeGet; +var $elm$core$Elm$JsArray$unsafeSet = _JsArray_unsafeSet; +var $elm$core$Array$insertTailInTree = F4( + function (shift, index, tail, tree) { + var pos = $elm$core$Array$bitMask & (index >>> shift); + if (_Utils_cmp( + pos, + $elm$core$Elm$JsArray$length(tree)) > -1) { + if (shift === 5) { + return A2( + $elm$core$Elm$JsArray$push, + $elm$core$Array$Leaf(tail), + tree); + } else { + var newSub = $elm$core$Array$SubTree( + A4($elm$core$Array$insertTailInTree, shift - $elm$core$Array$shiftStep, index, tail, $elm$core$Elm$JsArray$empty)); + return A2($elm$core$Elm$JsArray$push, newSub, tree); + } + } else { + var value = A2($elm$core$Elm$JsArray$unsafeGet, pos, tree); + if (!value.$) { + var subTree = value.a; + var newSub = $elm$core$Array$SubTree( + A4($elm$core$Array$insertTailInTree, shift - $elm$core$Array$shiftStep, index, tail, subTree)); + return A3($elm$core$Elm$JsArray$unsafeSet, pos, newSub, tree); + } else { + var newSub = $elm$core$Array$SubTree( + A4( + $elm$core$Array$insertTailInTree, + shift - $elm$core$Array$shiftStep, + index, + tail, + $elm$core$Elm$JsArray$singleton(value))); + return A3($elm$core$Elm$JsArray$unsafeSet, pos, newSub, tree); + } + } + }); +var $elm$core$Bitwise$shiftLeftBy = _Bitwise_shiftLeftBy; +var $elm$core$Array$unsafeReplaceTail = F2( + function (newTail, _v0) { + var len = _v0.a; + var startShift = _v0.b; + var tree = _v0.c; + var tail = _v0.d; + var originalTailLen = $elm$core$Elm$JsArray$length(tail); + var newTailLen = $elm$core$Elm$JsArray$length(newTail); + var newArrayLen = len + (newTailLen - originalTailLen); + if (_Utils_eq(newTailLen, $elm$core$Array$branchFactor)) { + var overflow = _Utils_cmp(newArrayLen >>> $elm$core$Array$shiftStep, 1 << startShift) > 0; + if (overflow) { + var newShift = startShift + $elm$core$Array$shiftStep; + var newTree = A4( + $elm$core$Array$insertTailInTree, + newShift, + len, + newTail, + $elm$core$Elm$JsArray$singleton( + $elm$core$Array$SubTree(tree))); + return A4($elm$core$Array$Array_elm_builtin, newArrayLen, newShift, newTree, $elm$core$Elm$JsArray$empty); + } else { + return A4( + $elm$core$Array$Array_elm_builtin, + newArrayLen, + startShift, + A4($elm$core$Array$insertTailInTree, startShift, len, newTail, tree), + $elm$core$Elm$JsArray$empty); + } + } else { + return A4($elm$core$Array$Array_elm_builtin, newArrayLen, startShift, tree, newTail); + } + }); +var $elm$core$Array$appendHelpTree = F2( + function (toAppend, array) { + var len = array.a; + var tree = array.c; + var tail = array.d; + var itemsToAppend = $elm$core$Elm$JsArray$length(toAppend); + var notAppended = ($elm$core$Array$branchFactor - $elm$core$Elm$JsArray$length(tail)) - itemsToAppend; + var appended = A3($elm$core$Elm$JsArray$appendN, $elm$core$Array$branchFactor, tail, toAppend); + var newArray = A2($elm$core$Array$unsafeReplaceTail, appended, array); + if (notAppended < 0) { + var nextTail = A3($elm$core$Elm$JsArray$slice, notAppended, itemsToAppend, toAppend); + return A2($elm$core$Array$unsafeReplaceTail, nextTail, newArray); + } else { + return newArray; + } + }); +var $elm$core$Array$builderFromArray = function (_v0) { + var len = _v0.a; + var tree = _v0.c; + var tail = _v0.d; + var helper = F2( + function (node, acc) { + if (!node.$) { + var subTree = node.a; + return A3($elm$core$Elm$JsArray$foldl, helper, acc, subTree); + } else { + return A2($elm$core$List$cons, node, acc); + } + }); + return { + d: A3($elm$core$Elm$JsArray$foldl, helper, _List_Nil, tree), + a: (len / $elm$core$Array$branchFactor) | 0, + c: tail + }; +}; +var $elm$core$Array$append = F2( + function (a, _v0) { + var aTail = a.d; + var bLen = _v0.a; + var bTree = _v0.c; + var bTail = _v0.d; + if (_Utils_cmp(bLen, $elm$core$Array$branchFactor * 4) < 1) { + var foldHelper = F2( + function (node, array) { + if (!node.$) { + var tree = node.a; + return A3($elm$core$Elm$JsArray$foldl, foldHelper, array, tree); + } else { + var leaf = node.a; + return A2($elm$core$Array$appendHelpTree, leaf, array); + } + }); + return A2( + $elm$core$Array$appendHelpTree, + bTail, + A3($elm$core$Elm$JsArray$foldl, foldHelper, a, bTree)); + } else { + var foldHelper = F2( + function (node, builder) { + if (!node.$) { + var tree = node.a; + return A3($elm$core$Elm$JsArray$foldl, foldHelper, builder, tree); + } else { + var leaf = node.a; + return A2($elm$core$Array$appendHelpBuilder, leaf, builder); + } + }); + return A2( + $elm$core$Array$builderToArray, + true, + A2( + $elm$core$Array$appendHelpBuilder, + bTail, + A3( + $elm$core$Elm$JsArray$foldl, + foldHelper, + $elm$core$Array$builderFromArray(a), + bTree))); + } + }); +var $elm$core$Array$length = function (_v0) { + var len = _v0.a; + return len; +}; +var $elm$core$Array$repeat = F2( + function (n, e) { + return A2( + $elm$core$Array$initialize, + n, + function (_v0) { + return e; + }); + }); +var $elm$core$Array$setHelp = F4( + function (shift, index, value, tree) { + var pos = $elm$core$Array$bitMask & (index >>> shift); + var _v0 = A2($elm$core$Elm$JsArray$unsafeGet, pos, tree); + if (!_v0.$) { + var subTree = _v0.a; + var newSub = A4($elm$core$Array$setHelp, shift - $elm$core$Array$shiftStep, index, value, subTree); + return A3( + $elm$core$Elm$JsArray$unsafeSet, + pos, + $elm$core$Array$SubTree(newSub), + tree); + } else { + var values = _v0.a; + var newLeaf = A3($elm$core$Elm$JsArray$unsafeSet, $elm$core$Array$bitMask & index, value, values); + return A3( + $elm$core$Elm$JsArray$unsafeSet, + pos, + $elm$core$Array$Leaf(newLeaf), + tree); + } + }); +var $elm$core$Array$tailIndex = function (len) { + return (len >>> 5) << 5; +}; +var $elm$core$Array$set = F3( + function (index, value, array) { + var len = array.a; + var startShift = array.b; + var tree = array.c; + var tail = array.d; + return ((index < 0) || (_Utils_cmp(index, len) > -1)) ? array : ((_Utils_cmp( + index, + $elm$core$Array$tailIndex(len)) > -1) ? A4( + $elm$core$Array$Array_elm_builtin, + len, + startShift, + tree, + A3($elm$core$Elm$JsArray$unsafeSet, $elm$core$Array$bitMask & index, value, tail)) : A4( + $elm$core$Array$Array_elm_builtin, + len, + startShift, + A4($elm$core$Array$setHelp, startShift, index, value, tree), + tail)); + }); +var $author$project$PC$Helpers$overwriteAt_Arr = F4( + function (_default, pos, newVal, list) { + var len = $elm$core$Array$length(list); + return (!pos) ? A2( + $elm$core$Array$append, + $elm$core$Array$fromList( + _List_fromArray( + [newVal])), + list) : ((_Utils_cmp(pos, len) > 0) ? A2( + $elm$core$Array$append, + list, + A2( + $elm$core$Array$append, + A2($elm$core$Array$repeat, pos - len, _default), + $elm$core$Array$fromList( + _List_fromArray( + [newVal])))) : A3($elm$core$Array$set, pos, newVal, list)); + }); +var $elm$core$Array$getHelp = F3( + function (shift, index, tree) { + getHelp: + while (true) { + var pos = $elm$core$Array$bitMask & (index >>> shift); + var _v0 = A2($elm$core$Elm$JsArray$unsafeGet, pos, tree); + if (!_v0.$) { + var subTree = _v0.a; + var $temp$shift = shift - $elm$core$Array$shiftStep, + $temp$index = index, + $temp$tree = subTree; + shift = $temp$shift; + index = $temp$index; + tree = $temp$tree; + continue getHelp; + } else { + var values = _v0.a; + return A2($elm$core$Elm$JsArray$unsafeGet, $elm$core$Array$bitMask & index, values); + } + } + }); +var $elm$core$Array$get = F2( + function (index, _v0) { + var len = _v0.a; + var startShift = _v0.b; + var tree = _v0.c; + var tail = _v0.d; + return ((index < 0) || (_Utils_cmp(index, len) > -1)) ? $elm$core$Maybe$Nothing : ((_Utils_cmp( + index, + $elm$core$Array$tailIndex(len)) > -1) ? $elm$core$Maybe$Just( + A2($elm$core$Elm$JsArray$unsafeGet, $elm$core$Array$bitMask & index, tail)) : $elm$core$Maybe$Just( + A3($elm$core$Array$getHelp, startShift, index, tree))); + }); +var $author$project$PC$Helpers$valueAtRam = F2( + function (pos, arr) { + var _v0 = A2($elm$core$Array$get, pos, arr); if (!_v0.$) { var a = _v0.a; return a; @@ -5592,24 +5897,212 @@ var $author$project$Main$valueAtRam = F2( return _Utils_Tuple2(0, ''); } }); -var $author$project$Main$changeAtRam = F3( +var $author$project$PC$Helpers$changeAtRam = F3( function (pos, newVal, list) { - var _v0 = A2($author$project$Main$valueAtRam, pos, list); + var _v0 = A2($author$project$PC$Helpers$valueAtRam, pos, list); var comment = _v0.b; return A4( - $author$project$Main$changeAt, + $author$project$PC$Helpers$overwriteAt_Arr, + _Utils_Tuple2(0, ''), pos, _Utils_Tuple2(newVal, comment), - _Utils_Tuple2(0, ''), list); }); -var $author$project$Main$changeAtUCode = F3( - function (pos, newVal, list) { - return A4($author$project$Main$changeAt, pos, newVal, 14, list); - }); -var $author$project$Main$MsgLoadExampleArrived = function (a) { - return {$: 23, a: a}; +var $author$project$PC$UActions$actDataBus2Ram = function (pc) { + var newRam = A3($author$project$PC$Helpers$changeAtRam, pc.aB, pc.aG, pc.aY); + return _Utils_update( + pc, + {aY: newRam}); }; +var $author$project$PC$Helpers$seperateInstructionsEntry = function (i) { + var instruction = (i / 100000) | 0; + var address = i - (instruction * 100000); + return _Utils_Tuple2(instruction, address); +}; +var $author$project$PC$UActions$actInstructionReg2AddressBus = function (pc) { + var _v0 = $author$project$PC$Helpers$seperateInstructionsEntry(pc.aP); + var instruction = _v0.a; + var address = _v0.b; + return _Utils_update( + pc, + {aB: address}); +}; +var $author$project$PC$UActions$actInstructionReg2ProgrammCounter = function (pc) { + var _v0 = $author$project$PC$Helpers$seperateInstructionsEntry(pc.aP); + var instruction = _v0.a; + var address = _v0.b; + return _Utils_update( + pc, + {aX: address}); +}; +var $author$project$PC$UActions$actInstructionReg2ProgrammCounterIfAccEq0 = function (pc) { + if (!pc.az) { + var _v0 = $author$project$PC$Helpers$seperateInstructionsEntry(pc.aP); + var addr = _v0.b; + return _Utils_update( + pc, + {aX: addr}); + } else { + return pc; + } +}; +var $author$project$PC$UActions$actInstructionReg2UCounter = function (pc) { + var _v0 = $author$project$PC$Helpers$seperateInstructionsEntry(pc.aP); + var instruction = _v0.a; + var address = _v0.b; + return _Utils_update( + pc, + {a5: instruction * 10}); +}; +var $author$project$PC$UActions$actProgrammCounter2AddressBus = function (pc) { + return _Utils_update( + pc, + {aB: pc.aX}); +}; +var $author$project$PC$UActions$actProgrammCounterIncrement = function (pc) { + return _Utils_update( + pc, + {aX: pc.aX + 1}); +}; +var $author$project$PC$UActions$actRam2DataBus = function (pc) { + var ab = pc.aB; + var db = A2($author$project$PC$Helpers$valueAtRam, ab, pc.aY).a; + return _Utils_update( + pc, + {aG: db}); +}; +var $author$project$PC$UActions$actResetUCounter = function (pc) { + return _Utils_update( + pc, + {a5: 0}); +}; +var $author$project$PC$UActions$uCodes = _List_fromArray( + [ + A4($author$project$PC$Types$UCode, 0, 'acc2db', $author$project$PC$UActions$actAccumulator2DataBus, 'Acc -> DataBus'), + A4($author$project$PC$Types$UCode, 1, 'accDec', $author$project$PC$UActions$actAccumulatorDecrement, 'Acc --'), + A4($author$project$PC$Types$UCode, 2, 'accInc', $author$project$PC$UActions$actAccumulatorIncrement, 'Acc ++'), + A4($author$project$PC$Types$UCode, 3, 'db2acc', $author$project$PC$UActions$actDataBus2Accumulator, 'DataBus -> Acc'), + A4($author$project$PC$Types$UCode, 4, 'db2ir', $author$project$PC$UActions$actDataBus2InstructionReg, 'DataBus -> InstReg'), + A4($author$project$PC$Types$UCode, 5, 'db2ram', $author$project$PC$UActions$actDataBus2Ram, 'DataBus -> Ram'), + A4($author$project$PC$Types$UCode, 6, 'ir2ab', $author$project$PC$UActions$actInstructionReg2AddressBus, 'InstReg -> AddrBus'), + A4($author$project$PC$Types$UCode, 7, 'ir2pc', $author$project$PC$UActions$actInstructionReg2ProgrammCounter, 'InstReg -> ProgCount'), + A4($author$project$PC$Types$UCode, 8, 'ir2uc', $author$project$PC$UActions$actInstructionReg2UCounter, 'InstReg -> µCounter'), + A4($author$project$PC$Types$UCode, 9, 'pcInc', $author$project$PC$UActions$actProgrammCounterIncrement, 'ProgCounter ++'), + A4($author$project$PC$Types$UCode, 11, 'ram2db', $author$project$PC$UActions$actRam2DataBus, 'Ram -> DataBus'), + A4($author$project$PC$Types$UCode, 12, 'ucReset', $author$project$PC$UActions$actResetUCounter, 'µCounter = 0'), + A4($author$project$PC$Types$UCode, 13, 'pc2ab', $author$project$PC$UActions$actProgrammCounter2AddressBus, 'ProgCounter -> AddrBus'), + A4( + $author$project$PC$Types$UCode, + 14, + 'n', + function (s) { + return s; + }, + 'Empty'), + A4($author$project$PC$Types$UCode, 10, 'ir2pciacceq0', $author$project$PC$UActions$actInstructionReg2ProgrammCounterIfAccEq0, 'Acc == 0 => InstReg -> ProgCounter') + ]); +var $author$project$PC$UActions$uAction2UCode = function (variant) { + var filtered_list = A2( + $elm$core$List$filter, + function (u) { + return _Utils_eq(u.a7, variant); + }, + $author$project$PC$UActions$uCodes); + var _v0 = $elm$core$List$head(filtered_list); + if (!_v0.$) { + var uCode = _v0.a; + return uCode; + } else { + return A4( + $author$project$PC$Types$UCode, + 14, + 'n', + function (s) { + return s; + }, + 'Empty'); + } +}; +var $author$project$PC$Json$encodeSingleuCode = function (action) { + var uCode = $author$project$PC$UActions$uAction2UCode(action); + return $elm$json$Json$Encode$string(uCode.aM); +}; +var $author$project$PC$Json$uCodesEncoder = function (uActions) { + return A2($elm$json$Json$Encode$array, $author$project$PC$Json$encodeSingleuCode, uActions); +}; +var $author$project$PC$Json$pcModelEncoder = function (model) { + return $elm$json$Json$Encode$object( + _List_fromArray( + [ + _Utils_Tuple2( + 'pc', + $author$project$PC$Json$pcEncoder(model.aW)), + _Utils_Tuple2( + 'uCodes', + $author$project$PC$Json$uCodesEncoder(model.a4)) + ])); +}; +var $author$project$PC$Types$pcModelVersion = '3'; +var $author$project$Main$doEncodeModel = 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$string($author$project$PC$Types$pcModelVersion)), + _Utils_Tuple2( + 'pc_model', + $author$project$PC$Json$pcModelEncoder(model.p)), + _Utils_Tuple2( + 'autoscroll', + $elm$json$Json$Encode$bool(model.s)) + ]))); +}; +var $author$project$Main$localStorageSend = _Platform_outgoingPort('localStorageSend', $elm$json$Json$Encode$string); +var $author$project$Main$cmd_up_lStorage = function (model) { + return $author$project$Main$localStorageSend( + $author$project$Main$doEncodeModel(model)); +}; +var $author$project$Main$cmd_up_lStorage_n_Scroller = function (model) { + return $elm$core$Platform$Cmd$batch( + _List_fromArray( + [ + $author$project$Main$cmd_up_lStorage(model), + $author$project$Main$cmd_scoller(model) + ])); +}; +var $author$project$Main$Example = F4( + function (title, version, url, enabled) { + return {aJ: enabled, as: title, K: url, a8: version}; + }); +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$map4 = _Json_map4; +var $elm$json$Json$Decode$string = _Json_decodeString; +var $author$project$Main$exampleListDecoder = A2( + $elm$json$Json$Decode$field, + 'available', + $elm$json$Json$Decode$list( + A5( + $elm$json$Json$Decode$map4, + $author$project$Main$Example, + A2($elm$json$Json$Decode$field, 'title', $elm$json$Json$Decode$string), + A2($elm$json$Json$Decode$field, 'version', $elm$json$Json$Decode$string), + A2($elm$json$Json$Decode$field, 'url', $elm$json$Json$Decode$string), + A2( + $elm$json$Json$Decode$field, + 'enabled', + A2( + $elm$json$Json$Decode$map, + function (s) { + return s === 1; + }, + $elm$json$Json$Decode$int))))); +var $author$project$Main$examplesListUrl = 'examples-list.json'; var $elm$json$Json$Decode$decodeString = _Json_runOnString; var $elm$http$Http$BadStatus_ = F2( function (a, b) { @@ -6202,7 +6695,7 @@ var $elm$http$Http$resolve = F2( case 3: var metadata = response.a; return $elm$core$Result$Err( - $elm$http$Http$BadStatus(metadata.a_)); + $elm$http$Http$BadStatus(metadata.a0)); default: var body = response.b; return A2( @@ -6230,7 +6723,7 @@ var $elm$http$Http$Request = function (a) { }; var $elm$http$Http$State = F2( function (reqs, subs) { - return {at: reqs, ay: subs}; + return {al: reqs, aq: subs}; }); var $elm$http$Http$init = $elm$core$Task$succeed( A2($elm$http$Http$State, $elm$core$Dict$empty, _List_Nil)); @@ -6274,7 +6767,7 @@ var $elm$http$Http$updateReqs = F3( return A2( $elm$core$Task$andThen, function (pid) { - var _v4 = req.aB; + var _v4 = req.at; if (_v4.$ === 1) { return A3($elm$http$Http$updateReqs, router, otherCmds, reqs); } else { @@ -6304,7 +6797,7 @@ var $elm$http$Http$onEffects = F4( return $elm$core$Task$succeed( A2($elm$http$Http$State, reqs, subs)); }, - A3($elm$http$Http$updateReqs, router, cmds, state.at)); + A3($elm$http$Http$updateReqs, router, cmds, state.al)); }); var $elm$core$List$maybeCons = F3( function (f, mx, xs) { @@ -6347,7 +6840,7 @@ var $elm$http$Http$onSelfMsg = F3( A2( $elm$core$List$filterMap, A3($elm$http$Http$maybeSend, router, tracker, progress), - state.ay))); + state.aq))); }); var $elm$http$Http$Cancel = function (a) { return {$: 0, a: a}; @@ -6361,14 +6854,14 @@ var $elm$http$Http$cmdMap = F2( var r = cmd.a; return $elm$http$Http$Request( { - aH: r.aH, - aJ: r.aJ, - ad: A2(_Http_mapExpect, func, r.ad), - af: r.af, - aS: r.aS, - a1: r.a1, - aB: r.aB, - S: r.S + aC: r.aC, + aE: r.aE, + W: A2(_Http_mapExpect, func, r.W), + Y: r.Y, + aR: r.aR, + a3: r.a3, + at: r.at, + K: r.K }); } }); @@ -6391,70 +6884,67 @@ var $elm$http$Http$subscription = _Platform_leaf('Http'); var $elm$http$Http$request = function (r) { return $elm$http$Http$command( $elm$http$Http$Request( - {aH: false, aJ: r.aJ, ad: r.ad, af: r.af, aS: r.aS, a1: r.a1, aB: r.aB, S: r.S})); + {aC: false, aE: r.aE, W: r.W, Y: r.Y, aR: r.aR, a3: r.a3, at: r.at, K: r.K})); }; var $elm$http$Http$get = function (r) { return $elm$http$Http$request( - {aJ: $elm$http$Http$emptyBody, ad: r.ad, af: _List_Nil, aS: 'GET', a1: $elm$core$Maybe$Nothing, aB: $elm$core$Maybe$Nothing, S: r.S}); + {aE: $elm$http$Http$emptyBody, W: r.W, Y: _List_Nil, aR: 'GET', a3: $elm$core$Maybe$Nothing, at: $elm$core$Maybe$Nothing, K: r.K}); }; +var $author$project$Main$Model = F6( + function (pc_model, autoscroll, examples, exampleChooserOpen, examplesListStatus, exampleLoaderStatus) { + return {s: autoscroll, y: exampleChooserOpen, C: exampleLoaderStatus, D: examples, E: examplesListStatus, p: pc_model}; + }); +var $elm$json$Json$Decode$andThen = _Json_andThen; var $elm$json$Json$Decode$bool = _Json_decodeBool; -var $elm$json$Json$Decode$field = _Json_decodeField; -var $elm$json$Json$Decode$index = _Json_decodeIndex; -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$fail = _Json_fail; +var $author$project$PC$Types$PC_Model = F2( + function (pc, uCodes) { + return {aW: pc, a4: uCodes}; + }); +var $author$project$PC$Types$PC = F7( + function (ram, dataBus, addressBus, instructionReg, programmCounter, uCounter, accumulator) { + return {az: accumulator, aB: addressBus, aG: dataBus, aP: instructionReg, aX: programmCounter, aY: ram, a5: uCounter}; + }); +var $elm$json$Json$Decode$array = _Json_decodeArray; var $elm$json$Json$Decode$map7 = _Json_map7; +var $elm$json$Json$Decode$index = _Json_decodeIndex; var $elm$core$Tuple$pair = F2( function (a, b) { return _Utils_Tuple2(a, b); }); -var $elm$core$List$filter = F2( - function (isGood, list) { +var $author$project$PC$Json$tuple2Decoder = F2( + function (enc1, enc2) { return A3( - $elm$core$List$foldr, - F2( - function (x, xs) { - return isGood(x) ? A2($elm$core$List$cons, x, xs) : xs; - }), - _List_Nil, - list); + $elm$json$Json$Decode$map2, + $elm$core$Tuple$pair, + A2($elm$json$Json$Decode$index, 0, enc1), + A2($elm$json$Json$Decode$index, 1, enc2)); }); -var $elm$core$Tuple$second = function (_v0) { - var y = _v0.b; - return y; -}; -var $author$project$Main$ActAccumulatorDecrement = 1; -var $author$project$Main$ActInstructionReg2ProgrammCounterIfAccEq0 = 10; -var $author$project$Main$uCodeIds = _List_fromArray( - [ - _Utils_Tuple2(0, 'acc2db'), - _Utils_Tuple2(1, 'accDec'), - _Utils_Tuple2(2, 'accInc'), - _Utils_Tuple2(3, 'db2acc'), - _Utils_Tuple2(4, 'db2ir'), - _Utils_Tuple2(5, 'db2ram'), - _Utils_Tuple2(6, 'ir2ab'), - _Utils_Tuple2(7, 'ir2pc'), - _Utils_Tuple2(8, 'ir2uc'), - _Utils_Tuple2(9, 'pcInc'), - _Utils_Tuple2(10, 'ir2pciacceq0'), - _Utils_Tuple2(11, 'ram2db'), - _Utils_Tuple2(12, 'ucReset'), - _Utils_Tuple2(13, 'pc2ab'), - _Utils_Tuple2(14, 'n') - ]); -var $author$project$Main$string2uAction = function (msg) { +var $author$project$PC$Json$pcDecoder = A8( + $elm$json$Json$Decode$map7, + $author$project$PC$Types$PC, + A2( + $elm$json$Json$Decode$field, + 'ram', + $elm$json$Json$Decode$array( + A2($author$project$PC$Json$tuple2Decoder, $elm$json$Json$Decode$int, $elm$json$Json$Decode$string))), + 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)); +var $author$project$PC$UActions$string2uAction = function (str) { var filtered_list = A2( $elm$core$List$filter, - function (s) { - return _Utils_eq(s.b, msg); + function (u) { + return _Utils_eq(u.aM, str); }, - $author$project$Main$uCodeIds); + $author$project$PC$UActions$uCodes); var _v0 = $elm$core$List$head(filtered_list); if (!_v0.$) { - var _v1 = _v0.a; - var action = _v1.a; - return $elm$core$Maybe$Just(action); + var uCode = _v0.a; + return $elm$core$Maybe$Just(uCode.a7); } else { return $elm$core$Maybe$Nothing; } @@ -6468,415 +6958,37 @@ var $elm$core$Maybe$withDefault = F2( return _default; } }); -var $author$project$Main$modelDecoder = function () { - var tuple2Decoder = F2( - function (enc1, enc2) { - return A3( - $elm$json$Json$Decode$map2, - $elm$core$Tuple$pair, - A2($elm$json$Json$Decode$index, 0, enc1), - A2($elm$json$Json$Decode$index, 1, enc2)); - }); - return A4( - $elm$json$Json$Decode$map3, - F3( - function (a, b, c) { - return A7($author$project$Main$Model, a, b, c, _List_Nil, false, $author$project$Main$Waiting, $author$project$Main$Waiting); - }), - 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( - A2(tuple2Decoder, $elm$json$Json$Decode$int, $elm$json$Json$Decode$string))), - 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( - A2( - $elm$json$Json$Decode$map, - function (s) { - return A2( - $elm$core$Maybe$withDefault, - 14, - $author$project$Main$string2uAction(s)); - }, - $elm$json$Json$Decode$string))), - A2($elm$json$Json$Decode$field, 'autoscroll', $elm$json$Json$Decode$bool)); -}(); -var $author$project$Main$cmdLoadExampleSing = F2( - function (model, example) { - return $elm$http$Http$get( - { - ad: A2($elm$http$Http$expectJson, $author$project$Main$MsgLoadExampleArrived, $author$project$Main$modelDecoder), - S: example.S - }); - }); -var $author$project$Main$MsgExamplesArrived = function (a) { - return {$: 24, a: a}; -}; -var $author$project$Main$Example = F4( - function (title, version, url, enabled) { - return {aN: enabled, aA: title, S: url, a3: version}; - }); -var $elm$json$Json$Decode$map4 = _Json_map4; -var $author$project$Main$exampleListDecoder = A2( - $elm$json$Json$Decode$field, - 'available', - $elm$json$Json$Decode$list( - A5( - $elm$json$Json$Decode$map4, - $author$project$Main$Example, - A2($elm$json$Json$Decode$field, 'title', $elm$json$Json$Decode$string), - A2($elm$json$Json$Decode$field, 'version', $elm$json$Json$Decode$string), - A2($elm$json$Json$Decode$field, 'url', $elm$json$Json$Decode$string), - A2( - $elm$json$Json$Decode$field, - 'enabled', - A2( - $elm$json$Json$Decode$map, - function (s) { - return s === 1; - }, - $elm$json$Json$Decode$int))))); -var $author$project$Main$examplesListUrl = 'examples-list.json'; -var $author$project$Main$cmdLoadExamples = function (model) { - return $elm$http$Http$get( - { - ad: A2($elm$http$Http$expectJson, $author$project$Main$MsgExamplesArrived, $author$project$Main$exampleListDecoder), - S: $author$project$Main$examplesListUrl - }); -}; -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(0), - entries)); - }); -var $author$project$Main$modelVersion = 2; -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(0), - pairs)); -}; -var $elm$json$Json$Encode$string = _Json_wrap; -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.$) { - var _v1 = _v0.a; - var info = _v1.b; - return info; - } else { - return 'IDK'; - } -}; -var $author$project$Main$encodeModel = function (model) { - var tuple2Encoder = F3( - function (enc1, enc2, _v0) { - var val1 = _v0.a; - var val2 = _v0.b; - return A2( - $elm$json$Json$Encode$list, - $elm$core$Basics$identity, - _List_fromArray( - [ - enc1(val1), - enc2(val2) - ])); - }); +var $author$project$PC$Json$uActionDecoder = function (str) { 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.a.r)), - _Utils_Tuple2( - 'dataBus', - $elm$json$Json$Encode$int(model.a.s)), - _Utils_Tuple2( - 'instructionReg', - $elm$json$Json$Encode$int(model.a.k)), - _Utils_Tuple2( - 'programmCounter', - $elm$json$Json$Encode$int(model.a.u)), - _Utils_Tuple2( - 'uCounter', - $elm$json$Json$Encode$int(model.a.l)), - _Utils_Tuple2( - 'accumulator', - $elm$json$Json$Encode$int(model.a.m)), - _Utils_Tuple2( - 'ram', - A2( - $elm$json$Json$Encode$list, - A2(tuple2Encoder, $elm$json$Json$Encode$int, $elm$json$Json$Encode$string), - model.a.c)) - ]))), - _Utils_Tuple2( - 'uCode', - A2( - $elm$json$Json$Encode$list, - $elm$json$Json$Encode$string, - A2($elm$core$List$map, $author$project$Main$uAction2String, model.q))), - _Utils_Tuple2( - 'autoscroll', - $elm$json$Json$Encode$bool(model.A)) - ]))); -}; -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 $author$project$Main$decodeModel = F2( - function (model, text) { - var error2maybe = function (err) { - if (!err.$) { - var val = err.a; - return $elm$core$Maybe$Just(val); - } else { - return $elm$core$Maybe$Nothing; - } - }; - return error2maybe( - A2($elm$json$Json$Decode$decodeString, $author$project$Main$modelDecoder, text)); - }); -var $author$project$Main$actAccumulator2DataBus = function (pc) { - return _Utils_update( - pc, - {s: pc.m}); -}; -var $author$project$Main$actAccumulatorDecrement = function (pc) { - return _Utils_update( - pc, - {m: pc.m - 1}); -}; -var $author$project$Main$actAccumulatorIncrement = function (pc) { - return _Utils_update( - pc, - {m: pc.m + 1}); -}; -var $author$project$Main$actDataBus2Accumulator = function (pc) { - return _Utils_update( - pc, - {m: pc.s}); -}; -var $author$project$Main$actDataBus2InstructionReg = function (pc) { - return _Utils_update( - pc, - {k: pc.s}); -}; -var $author$project$Main$actDataBus2Ram = function (pc) { - var newRam = A3($author$project$Main$changeAtRam, pc.r, pc.s, pc.c); - return _Utils_update( - pc, - {c: 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.k); - var instruction = _v0.a; - var address = _v0.b; - return _Utils_update( - pc, - {r: address}); -}; -var $author$project$Main$actInstructionReg2ProgrammCounter = function (pc) { - var _v0 = $author$project$Main$seperateInstructionsEntry(pc.k); - var instruction = _v0.a; - var address = _v0.b; - return _Utils_update( - pc, - {u: address}); -}; -var $author$project$Main$actInstructionReg2ProgrammCounterIfAccEq0 = function (pc) { - if (!pc.m) { - var _v0 = $author$project$Main$seperateInstructionsEntry(pc.k); - var addr = _v0.b; - return _Utils_update( - pc, - {u: addr}); - } else { - return pc; - } -}; -var $author$project$Main$actInstructionReg2UCounter = function (pc) { - var _v0 = $author$project$Main$seperateInstructionsEntry(pc.k); - var instruction = _v0.a; - var address = _v0.b; - return _Utils_update( - pc, - {l: instruction * 10}); -}; -var $author$project$Main$actProgrammCounter2AddressBus = function (pc) { - return _Utils_update( - pc, - {r: pc.u}); -}; -var $author$project$Main$actProgrammCounterIncrement = function (pc) { - return _Utils_update( - pc, - {u: pc.u + 1}); -}; -var $author$project$Main$actRam2DataBus = function (pc) { - var ab = pc.r; - var db = A2($author$project$Main$valueAtRam, ab, pc.c).a; - return _Utils_update( - pc, - {s: db}); -}; -var $author$project$Main$actResetUCounter = function (pc) { - return _Utils_update( - pc, - {l: 0}); -}; -var $author$project$Main$uCodeMaps = _List_fromArray( - [ - _Utils_Tuple2(0, $author$project$Main$actAccumulator2DataBus), - _Utils_Tuple2(1, $author$project$Main$actAccumulatorDecrement), - _Utils_Tuple2(2, $author$project$Main$actAccumulatorIncrement), - _Utils_Tuple2(3, $author$project$Main$actDataBus2Accumulator), - _Utils_Tuple2(4, $author$project$Main$actDataBus2InstructionReg), - _Utils_Tuple2(5, $author$project$Main$actDataBus2Ram), - _Utils_Tuple2(6, $author$project$Main$actInstructionReg2AddressBus), - _Utils_Tuple2(7, $author$project$Main$actInstructionReg2ProgrammCounter), - _Utils_Tuple2(8, $author$project$Main$actInstructionReg2UCounter), - _Utils_Tuple2(9, $author$project$Main$actProgrammCounterIncrement), - _Utils_Tuple2(10, $author$project$Main$actInstructionReg2ProgrammCounterIfAccEq0), - _Utils_Tuple2(11, $author$project$Main$actRam2DataBus), - _Utils_Tuple2(12, $author$project$Main$actResetUCounter), - _Utils_Tuple2(13, $author$project$Main$actProgrammCounter2AddressBus), - _Utils_Tuple2( + $elm$core$Maybe$withDefault, 14, - function (s) { - return s; - }) - ]); -var $author$project$Main$uStepPC = function (model) { - var uCounter = model.a.l; - var may_instruction = A2($author$project$Main$valueAt, uCounter, model.q); - if (!may_instruction.$) { - var action = may_instruction.a; - var possible_instructions = A2( - $elm$core$List$filter, - function (s) { - return _Utils_eq(s.a, action); - }, - $author$project$Main$uCodeMaps); - var _v1 = $elm$core$List$head(possible_instructions); - if (!_v1.$) { - var _v2 = _v1.a; - var name = _v2.a; - var instruction = _v2.b; - var old_pc = model.a; - var new_pc = _Utils_update( - old_pc, - {l: old_pc.l + 1}); - return _Utils_update( - model, - { - a: instruction(new_pc) - }); - } else { - var old_pc = model.a; - var new_pc = _Utils_update( - old_pc, - {l: 0}); - return _Utils_update( - model, - {a: new_pc}); - } - } else { - return model; - } + $author$project$PC$UActions$string2uAction(str)); }; -var $author$project$Main$executeInstruction = function (model) { - executeInstruction: - while (true) { - var new_model = $author$project$Main$uStepPC(model); - if (!new_model.a.l) { - return $author$project$Main$uStepPC(new_model); - } else { - var $temp$model = new_model; - model = $temp$model; - continue executeInstruction; - } - } -}; -var $author$project$Main$getAction = function (uAction) { - var possible_instructions = A2( - $elm$core$List$filter, - function (s) { - return _Utils_eq(s.a, uAction); - }, - $author$project$Main$uCodeMaps); - var _v0 = $elm$core$List$head(possible_instructions); - if (!_v0.$) { - var _v1 = _v0.a; - var name = _v1.a; - var instruction = _v1.b; - return instruction; - } else { - return function (s) { - return s; - }; - } -}; -var $author$project$Main$httpError2String = function (err) { +var $author$project$PC$Json$uCodeDecoder = $elm$json$Json$Decode$array( + A2($elm$json$Json$Decode$map, $author$project$PC$Json$uActionDecoder, $elm$json$Json$Decode$string)); +var $author$project$PC$Json$pcModelDecoder = A3( + $elm$json$Json$Decode$map2, + $author$project$PC$Types$PC_Model, + A2($elm$json$Json$Decode$field, 'pc', $author$project$PC$Json$pcDecoder), + A2($elm$json$Json$Decode$field, 'uCodes', $author$project$PC$Json$uCodeDecoder)); +var $author$project$Main$modelDecoder = function () { + var mainDecoder = function (version) { + return _Utils_eq(version, $author$project$PC$Types$pcModelVersion) ? A3( + $elm$json$Json$Decode$map2, + F2( + function (a, b) { + return A6($author$project$Main$Model, a, b, _List_Nil, false, $author$project$Main$Waiting, $author$project$Main$Waiting); + }), + A2($elm$json$Json$Decode$field, 'pc_model', $author$project$PC$Json$pcModelDecoder), + A2($elm$json$Json$Decode$field, 'autoscroll', $elm$json$Json$Decode$bool)) : $elm$json$Json$Decode$fail('Outdated version: \'' + (version + '\'')); + }; + return A2( + $elm$json$Json$Decode$andThen, + mainDecoder, + A2($elm$json$Json$Decode$field, 'model-version', $elm$json$Json$Decode$string)); +}(); +var $elm$core$Basics$not = _Basics_not; +var $author$project$PC$Helpers$printHttpError = function (err) { switch (err.$) { case 0: var str = err.a; @@ -6893,339 +7005,440 @@ var $author$project$Main$httpError2String = function (err) { return 'Bad Body: ' + str; } }; -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)); +var $author$project$PC$Types$PUA_Nothing = 0; +var $author$project$PC$Types$PUA_Scroller = 2; +var $author$project$PC$Types$PUA_Storage = 1; +var $author$project$PC$Types$PUA_Storage_And_Scroller = 3; +var $author$project$PC$Update$uStepPC = function (model) { + var uCounter = model.aW.a5; + var may_code = A2($elm$core$Array$get, uCounter, model.a4); + if (!may_code.$) { + var code = may_code.a; + var uCode = $author$project$PC$UActions$uAction2UCode(code); + var old_pc = model.aW; + var temp_pc = _Utils_update( + old_pc, + {a5: uCounter + 1}); + var f = uCode.aA; + var new_pc = f(temp_pc); + return _Utils_update( + model, + {aW: new_pc}); + } else { + return model; + } +}; +var $author$project$PC$Update$executeInstruction = function (model) { + executeInstruction: + while (true) { + var new_model = $author$project$PC$Update$uStepPC(model); + if (!new_model.aW.a5) { + return $author$project$PC$Update$uStepPC(new_model); + } else { + var $temp$model = new_model; + model = $temp$model; + continue executeInstruction; + } + } +}; +var $author$project$PC$Update$getAction = function (uAction) { + var possible_instructions = A2( + $elm$core$List$filter, + function (u) { + return _Utils_eq(u.a7, uAction); + }, + $author$project$PC$UActions$uCodes); + var _v0 = $elm$core$List$head(possible_instructions); + if (!_v0.$) { + var uCode = _v0.a; + return uCode.aA; + } else { + return function (s) { + return s; }; + } +}; +var $author$project$PC$Update$pc_update = F2( + function (msg, model) { switch (msg.$) { case 0: return _Utils_Tuple2( - $author$project$Main$uStepPC(model), - $author$project$Main$cmdSenduUpdate(model)); + $author$project$PC$Update$uStepPC(model), + (!model.aW.a5) ? 3 : 2); case 1: return _Utils_Tuple2( - $author$project$Main$executeInstruction(model), - $author$project$Main$cmdSenduUpdate(model)); + $author$project$PC$Update$executeInstruction(model), + 3); case 2: - var new_model = _Utils_update( - model, + return _Utils_Tuple2( + _Utils_update( + model, + { + aW: _Utils_update( + $author$project$PC$Defaults$initialPC, + {aY: model.aW.aY}) + }), + 3); + case 3: + var old_pc = model.aW; + var new_pc = _Utils_update( + old_pc, { - a: _Utils_update( - $author$project$Main$initialPC, - {c: model.a.c}) + aY: A2( + $elm$core$Array$append, + old_pc.aY, + $elm$core$Array$fromList( + _List_fromArray( + [ + _Utils_Tuple2(0, '') + ]))) }); return _Utils_Tuple2( - new_model, - $author$project$Main$cmdSenduUpdate(new_model)); + _Utils_update( + model, + {aW: new_pc}), + 1); case 4: - var action = msg.a; - var instruction = $author$project$Main$getAction(action); - var new_model = _Utils_update( - model, - { - a: instruction(model.a) - }); return _Utils_Tuple2( - new_model, - $author$project$Main$cmdSenduUpdate(new_model)); - case 5: + _Utils_update( + model, + { + a4: A2( + $elm$core$Array$append, + model.a4, + A2($elm$core$Array$repeat, 10, 14)) + }), + 1); + case 6: var addr = msg.a; var may_int = msg.b; var _v1 = $elm$core$String$toInt(may_int); if (!_v1.$) { var _int = _v1.a; - var old_pc = model.a; - var _v2 = $author$project$Main$seperateInstructionsEntry( - A2($author$project$Main$valueAtRam, addr, model.a.c).a); + var old_pc = model.aW; + var _v2 = $author$project$PC$Helpers$seperateInstructionsEntry( + A2($author$project$PC$Helpers$valueAtRam, addr, model.aW.aY).a); var inst = _v2.a; var new_val = (inst * 100000) + _int; var new_pc = _Utils_update( old_pc, { - c: A3($author$project$Main$changeAtRam, addr, new_val, old_pc.c) + aY: A3($author$project$PC$Helpers$changeAtRam, addr, new_val, old_pc.aY) }); - return updateModel( + return _Utils_Tuple2( _Utils_update( model, - {a: new_pc})); + {aW: new_pc}), + 1); } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + return _Utils_Tuple2(model, 0); } - case 6: + case 5: var addr = msg.a; var may_int = msg.b; var _v3 = $elm$core$String$toInt(may_int); if (!_v3.$) { var _int = _v3.a; - var old_pc = model.a; - var _v4 = $author$project$Main$seperateInstructionsEntry( - A2($author$project$Main$valueAtRam, addr, model.a.c).a); + var old_pc = model.aW; + var _v4 = $author$project$PC$Helpers$seperateInstructionsEntry( + A2($author$project$PC$Helpers$valueAtRam, addr, model.aW.aY).a); var address = _v4.b; var new_val = (_int * 100000) + address; var new_pc = _Utils_update( old_pc, { - c: A3($author$project$Main$changeAtRam, addr, new_val, old_pc.c) + aY: A3($author$project$PC$Helpers$changeAtRam, addr, new_val, old_pc.aY) }); - return updateModel( + return _Utils_Tuple2( _Utils_update( model, - {a: new_pc})); + {aW: new_pc}), + 1); } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + return _Utils_Tuple2(model, 0); } case 7: - var old_pc = model.a; - var new_pc = _Utils_update( - old_pc, - { - c: _Utils_ap( - old_pc.c, - _List_fromArray( - [ - _Utils_Tuple2(0, '') - ])) - }); - return updateModel( - _Utils_update( - model, - {a: new_pc})); - case 8: var addr = msg.a; var str = msg.b; - var old_pc = model.a; - var _v5 = A2($author$project$Main$valueAtRam, addr, model.a.c); + var old_pc = model.aW; + var _v5 = A2($author$project$PC$Helpers$valueAtRam, addr, model.aW.aY); var val = _v5.a; var new_pc = _Utils_update( old_pc, { - c: A4( - $author$project$Main$changeAt, + aY: A4( + $author$project$PC$Helpers$overwriteAt_Arr, + _Utils_Tuple2(0, ''), addr, _Utils_Tuple2(val, str), - _Utils_Tuple2(0, ''), - old_pc.c) + old_pc.aY) }); - return updateModel( + return _Utils_Tuple2( _Utils_update( model, - {a: new_pc})); - case 9: + {aW: new_pc}), + 1); + case 8: var addr = msg.a; var may_action = msg.b; - var _v6 = $author$project$Main$string2uAction(may_action); + var _v6 = $author$project$PC$UActions$string2uAction(may_action); if (!_v6.$) { var action = _v6.a; - var newCode = A3($author$project$Main$changeAtUCode, addr, action, model.q); - return updateModel( + var newCode = A3($elm$core$Array$set, addr, action, model.a4); + return _Utils_Tuple2( _Utils_update( model, - {q: newCode})); + {a4: newCode}), + 1); } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + return _Utils_Tuple2(model, 0); } - case 10: - return updateModel( - _Utils_update( - model, - { - q: _Utils_ap( - model.q, - A2($elm$core$List$repeat, 10, 14)) - })); - case 11: + case 9: var text = msg.a; var _v7 = $elm$core$String$toInt(text); if (!_v7.$) { var _int = _v7.a; - var old_pc = model.a; - var _v8 = $author$project$Main$seperateInstructionsEntry(old_pc.k); + var old_pc = model.aW; + var _v8 = $author$project$PC$Helpers$seperateInstructionsEntry(old_pc.aP); var instr = _v8.a; var new_pc = _Utils_update( old_pc, - {k: (instr * 100000) + _int}); - return updateModel( + {aP: (instr * 100000) + _int}); + return _Utils_Tuple2( _Utils_update( model, - {a: new_pc})); + {aW: new_pc}), + 1); } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + return _Utils_Tuple2(model, 0); } - case 12: + case 10: var text = msg.a; var _v9 = $elm$core$String$toInt(text); if (!_v9.$) { var _int = _v9.a; - var old_pc = model.a; - var _v10 = $author$project$Main$seperateInstructionsEntry(old_pc.k); + var old_pc = model.aW; + var _v10 = $author$project$PC$Helpers$seperateInstructionsEntry(old_pc.aP); var addr = _v10.b; var new_pc = _Utils_update( old_pc, - {k: (_int * 100000) + addr}); - return updateModel( + {aP: (_int * 100000) + addr}); + return _Utils_Tuple2( _Utils_update( model, - {a: new_pc})); + {aW: new_pc}), + 1); } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + return _Utils_Tuple2(model, 0); } - case 14: + case 11: var text = msg.a; var _v11 = $elm$core$String$toInt(text); if (!_v11.$) { var _int = _v11.a; - var old_pc = model.a; + var old_pc = model.aW; var new_pc = _Utils_update( old_pc, - {u: _int}); - return updateModel( + {aX: _int}); + return _Utils_Tuple2( _Utils_update( model, - {a: new_pc})); + {aW: new_pc}), + 1); } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + return _Utils_Tuple2(model, 0); } - case 13: + case 12: var text = msg.a; var _v12 = $elm$core$String$toInt(text); if (!_v12.$) { var _int = _v12.a; - var old_pc = model.a; + var old_pc = model.aW; var new_pc = _Utils_update( old_pc, - {l: _int}); + {a5: _int}); return _Utils_Tuple2( _Utils_update( model, - {a: new_pc}), - $author$project$Main$cmdSenduUpdate(model)); + {aW: new_pc}), + 3); } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + return _Utils_Tuple2(model, 0); } - case 15: + case 13: var text = msg.a; var _v13 = $elm$core$String$toInt(text); if (!_v13.$) { var _int = _v13.a; - var old_pc = model.a; + var old_pc = model.aW; var new_pc = _Utils_update( old_pc, - {r: _int}); + {aB: _int}); return _Utils_Tuple2( _Utils_update( model, - {a: new_pc}), - $author$project$Main$cmdSenduUpdate(model)); + {aW: new_pc}), + 3); } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + return _Utils_Tuple2(model, 0); } - case 16: + case 14: var text = msg.a; var _v14 = $elm$core$String$toInt(text); if (!_v14.$) { var _int = _v14.a; - var old_pc = model.a; + var old_pc = model.aW; var new_pc = _Utils_update( old_pc, - {s: _int}); - return updateModel( + {aG: _int}); + return _Utils_Tuple2( _Utils_update( model, - {a: new_pc})); + {aW: new_pc}), + 1); } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + return _Utils_Tuple2(model, 0); } - case 17: + case 15: var text = msg.a; var _v15 = $elm$core$String$toInt(text); if (!_v15.$) { var _int = _v15.a; - var old_pc = model.a; + var old_pc = model.aW; var new_pc = _Utils_update( old_pc, - {m: _int}); - return updateModel( + {az: _int}); + return _Utils_Tuple2( _Utils_update( model, - {a: new_pc})); + {aW: new_pc}), + 1); } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); + return _Utils_Tuple2(model, 0); + } + default: + var action = msg.a; + var instruction = $author$project$PC$Update$getAction(action); + var new_model = _Utils_update( + model, + { + aW: instruction(model.aW) + }); + return _Utils_Tuple2(new_model, 3); + } + }); +var $author$project$PC$PC$update = $author$project$PC$Update$pc_update; +var $elm$core$List$drop = F2( + function (n, list) { + drop: + while (true) { + if (n <= 0) { + return list; + } else { + if (!list.b) { + return list; + } else { + var x = list.a; + var xs = list.b; + var $temp$n = n - 1, + $temp$list = xs; + n = $temp$n; + list = $temp$list; + continue drop; + } + } + } + }); +var $author$project$PC$Helpers$valueAt = F2( + function (pos, list) { + return $elm$core$List$head( + A2($elm$core$List$drop, pos, list)); + }); +var $author$project$Main$update = F2( + function (msg, model) { + switch (msg.$) { + case 0: + var pc_msg = msg.a; + var _v1 = A2($author$project$PC$PC$update, pc_msg, model.p); + var new_pc = _v1.a; + var pua = _v1.b; + var new_model = _Utils_update( + model, + {p: new_pc}); + switch (pua) { + case 0: + return _Utils_Tuple2(new_model, $elm$core$Platform$Cmd$none); + case 1: + return _Utils_Tuple2( + new_model, + $author$project$Main$cmd_up_lStorage(new_model)); + case 2: + return _Utils_Tuple2( + new_model, + $author$project$Main$cmd_scoller(new_model)); + default: + return _Utils_Tuple2( + new_model, + $author$project$Main$cmd_up_lStorage_n_Scroller(new_model)); + } + case 1: + var new_model = _Utils_update( + model, + {s: !model.s}); + return _Utils_Tuple2( + new_model, + $author$project$Main$cmd_up_lStorage_n_Scroller(new_model)); + case 2: + if (msg.a) { + return _Utils_Tuple2( + _Utils_update( + model, + {y: true}), + $elm$http$Http$get( + { + W: A2($elm$http$Http$expectJson, $author$project$Main$Msg_DEsmpl_ListLoaded, $author$project$Main$exampleListDecoder), + K: $author$project$Main$examplesListUrl + })); + } else { + return _Utils_Tuple2( + _Utils_update( + model, + {y: false}), + $elm$core$Platform$Cmd$none); } case 3: - if (model.A) { - return updateModel( - _Utils_update( - model, - {A: false})); - } else { - var new_model = _Utils_update( - model, - {A: true}); - return _Utils_Tuple2( - new_model, - $author$project$Main$cmdSenduUpdate(new_model)); - } - case 18: - return _Utils_Tuple2( - model, - $author$project$Main$cmdUpdateLocalStorage(model)); - case 19: - var message_in = msg.a; - var _v16 = A2($author$project$Main$decodeModel, model, message_in); - if (!_v16.$) { - var new_model = _v16.a; - return _Utils_Tuple2( - _Utils_update( - new_model, - {H: model.H}), - $elm$core$Platform$Cmd$none); - } else { - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); - } - case 20: - return model.G ? _Utils_Tuple2( - _Utils_update( - model, - {G: false}), - $elm$core$Platform$Cmd$none) : _Utils_Tuple2( - _Utils_update( - model, - {G: true}), - $author$project$Main$cmdLoadExamples(model)); - case 21: - return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); - case 22: var i = msg.a; - var _v17 = A2($author$project$Main$valueAt, i, model.H); - if (!_v17.$) { - var example = _v17.a; + var _v3 = A2($author$project$PC$Helpers$valueAt, i, model.D); + if (!_v3.$) { + var example = _v3.a; return _Utils_Tuple2( - _Utils_update( - model, - {G: false}), - A2($author$project$Main$cmdLoadExampleSing, model, example)); + model, + $elm$http$Http$get( + { + W: A2($elm$http$Http$expectJson, $author$project$Main$Msg_DEsmpl_ExampleLoaded, $author$project$Main$modelDecoder), + K: example.K + })); } else { return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none); } - case 23: + case 4: var result = msg.a; if (!result.$) { - var new_model = result.a; - return updateModel( - _Utils_update( - model, - {Q: $author$project$Main$Success, a: new_model.a, q: new_model.q})); + var example_model = result.a; + var new_model = _Utils_update( + model, + {y: false, C: $author$project$Main$Success, p: example_model.p}); + return _Utils_Tuple2( + new_model, + $author$project$Main$cmd_up_lStorage_n_Scroller(new_model)); } else { var err = result.a; return _Utils_Tuple2( _Utils_update( model, { - Q: $author$project$Main$Failure( - $author$project$Main$httpError2String(err)) + C: $author$project$Main$Failure( + $author$project$PC$Helpers$printHttpError(err)) }), $elm$core$Platform$Cmd$none); } @@ -7236,7 +7449,7 @@ var $author$project$Main$update = F2( return _Utils_Tuple2( _Utils_update( model, - {H: exampleList, R: $author$project$Main$Success}), + {D: exampleList, E: $author$project$Main$Success}), $elm$core$Platform$Cmd$none); } else { var err = result.a; @@ -7244,8 +7457,8 @@ var $author$project$Main$update = F2( _Utils_update( model, { - R: $author$project$Main$Failure( - $author$project$Main$httpError2String(err)) + E: $author$project$Main$Failure( + $author$project$PC$Helpers$printHttpError(err)) }), $elm$core$Platform$Cmd$none); } @@ -7253,11 +7466,16 @@ var $author$project$Main$update = F2( }); var $elm$virtual_dom$VirtualDom$lazy = _VirtualDom_lazy; var $elm$html$Html$Lazy$lazy = $elm$virtual_dom$VirtualDom$lazy; -var $author$project$Main$MsgAutoscrollUpdate = {$: 3}; -var $author$project$Main$MsgInstructionStep = {$: 1}; -var $author$project$Main$MsgReset = {$: 2}; -var $author$project$Main$MsgToggleLoadExample = {$: 20}; -var $author$project$Main$MsgUCycleStep = {$: 0}; +var $author$project$Main$Msg_Autoscroll_Toggle = {$: 1}; +var $author$project$Main$Msg_DEsmpl_Open = function (a) { + return {$: 2, a: a}; +}; +var $author$project$Main$Msg_PC = function (a) { + return {$: 0, a: a}; +}; +var $author$project$PC$Types$PM_B_InstructionStep = {$: 1}; +var $author$project$PC$Types$PM_B_Reset = {$: 2}; +var $author$project$PC$Types$PM_B_UCycleStep = {$: 0}; var $elm$html$Html$button = _VirtualDom_node('button'); var $elm$html$Html$Attributes$boolProperty = F2( function (key, bool) { @@ -7275,6 +7493,10 @@ 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( @@ -7290,6 +7512,8 @@ var $elm$html$Html$Attributes$for = $elm$html$Html$Attributes$stringProperty('ht var $elm$html$Html$Attributes$id = $elm$html$Html$Attributes$stringProperty('id'); var $elm$html$Html$input = _VirtualDom_node('input'); var $elm$html$Html$label = _VirtualDom_node('label'); +var $elm$virtual_dom$VirtualDom$map = _VirtualDom_map; +var $elm$html$Html$map = $elm$virtual_dom$VirtualDom$map; var $elm$virtual_dom$VirtualDom$Normal = function (a) { return {$: 0, a: a}; }; @@ -7310,38 +7534,41 @@ var $elm$html$Html$Events$onClick = function (msg) { var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text; var $elm$html$Html$text = $elm$virtual_dom$VirtualDom$text; var $elm$html$Html$Attributes$type_ = $elm$html$Html$Attributes$stringProperty('type'); -var $author$project$Main$MsgEditAddressBus = function (a) { - return {$: 15, a: a}; +var $author$project$PC$Types$PM_F_EditAddressBus = function (a) { + return {$: 13, a: a}; }; var $elm$core$String$fromList = _String_fromList; -var $author$project$Main$addLeadingZero = F2( +var $elm$core$List$repeatHelp = F3( + function (result, n, value) { + repeatHelp: + while (true) { + if (n <= 0) { + return result; + } else { + var $temp$result = A2($elm$core$List$cons, value, result), + $temp$n = n - 1, + $temp$value = value; + result = $temp$result; + n = $temp$n; + value = $temp$value; + continue repeatHelp; + } + } + }); +var $elm$core$List$repeat = F2( + function (n, value) { + return A3($elm$core$List$repeatHelp, _List_Nil, n, value); + }); +var $author$project$PC$Helpers$addLeadingZero = F2( function (number, length) { var num_str = $elm$core$String$fromInt(number); - return (number < 10) ? _Utils_ap( + return _Utils_ap( $elm$core$String$fromList( - A2($elm$core$List$repeat, length - 1, '0')), - num_str) : ((number < 100) ? _Utils_ap( - $elm$core$String$fromList( - A2($elm$core$List$repeat, length - 2, '0')), - num_str) : ((number < 1000) ? _Utils_ap( - $elm$core$String$fromList( - A2($elm$core$List$repeat, length - 3, '0')), - num_str) : ((number < 10000) ? _Utils_ap( - $elm$core$String$fromList( - A2($elm$core$List$repeat, length - 4, '0')), - num_str) : ((number < 100000) ? _Utils_ap( - $elm$core$String$fromList( - A2($elm$core$List$repeat, length - 5, '0')), - num_str) : ((number < 1000000) ? _Utils_ap( - $elm$core$String$fromList( - A2($elm$core$List$repeat, length - 6, '0')), - num_str) : ((number < 10000000) ? _Utils_ap( - $elm$core$String$fromList( - A2($elm$core$List$repeat, length - 7, '0')), - num_str) : ((number < 100000000) ? _Utils_ap( - $elm$core$String$fromList( - A2($elm$core$List$repeat, length - 8, '0')), - num_str) : num_str))))))); + A2( + $elm$core$List$repeat, + length - $elm$core$String$length(num_str), + '0')), + num_str); }); var $elm$html$Html$Events$alwaysStop = function (x) { return _Utils_Tuple2(x, true); @@ -7376,7 +7603,7 @@ var $elm$html$Html$Events$onInput = function (tagger) { }; var $elm$html$Html$span = _VirtualDom_node('span'); var $elm$html$Html$Attributes$value = $elm$html$Html$Attributes$stringProperty('value'); -var $author$project$Main$viewAddressBus = function (model) { +var $author$project$PC$View$viewAddressBus = function (model) { return A2( $elm$html$Html$div, _List_fromArray( @@ -7406,23 +7633,67 @@ var $author$project$Main$viewAddressBus = function (model) { [ $elm$html$Html$Attributes$type_('number'), $elm$html$Html$Attributes$value( - A2($author$project$Main$addLeadingZero, model.a.r, 3)), - $elm$html$Html$Events$onInput($author$project$Main$MsgEditAddressBus) + A2($author$project$PC$Helpers$addLeadingZero, model.aW.aB, 3)), + $elm$html$Html$Events$onInput($author$project$PC$Types$PM_F_EditAddressBus) ]), _List_Nil) ])) ])); }; -var $author$project$Main$MsgAluEdit = function (a) { - return {$: 17, a: a}; +var $author$project$PC$View$Bottom = 1; +var $author$project$PC$View$Down = 1; +var $author$project$PC$Types$PM_F_AluEdit = function (a) { + return {$: 15, a: a}; }; -var $author$project$Main$MsgManualStep = function (a) { - return {$: 4, a: a}; +var $author$project$PC$Types$PM_ManualStep = function (a) { + return {$: 16, a: a}; }; +var $author$project$PC$View$Up = 0; +var $author$project$PC$View$Top = 0; var $elm$html$Html$a = _VirtualDom_node('a'); +var $author$project$PC$View$drawArrow = F4( + function (pos, dir, act, str) { + return A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$classList( + _List_fromArray( + [ + _Utils_Tuple2('arrow', true), + _Utils_Tuple2('top', !pos), + _Utils_Tuple2('up', !dir), + _Utils_Tuple2('down', dir === 1) + ])) + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('button') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$a, + _List_fromArray( + [ + $elm$html$Html$Events$onClick( + $author$project$PC$Types$PM_ManualStep(act)) + ]), + _List_fromArray( + [ + $elm$html$Html$text(str) + ])) + ])), + A2($elm$html$Html$div, _List_Nil, _List_Nil) + ])); + }); var $elm$html$Html$h1 = _VirtualDom_node('h1'); var $elm$html$Html$p = _VirtualDom_node('p'); -var $author$project$Main$viewAlu = function (model) { +var $author$project$PC$View$viewAlu = function (model) { return A2( $elm$html$Html$div, _List_fromArray( @@ -7464,8 +7735,8 @@ var $author$project$Main$viewAlu = function (model) { $elm$html$Html$Attributes$type_('number'), $elm$html$Html$Attributes$id('alu-accumulator'), $elm$html$Html$Attributes$value( - A2($author$project$Main$addLeadingZero, model.a.m, 8)), - $elm$html$Html$Events$onInput($author$project$Main$MsgAluEdit) + A2($author$project$PC$Helpers$addLeadingZero, model.aW.az, 8)), + $elm$html$Html$Events$onInput($author$project$PC$Types$PM_F_AluEdit) ]), _List_Nil) ])), @@ -7479,7 +7750,7 @@ var $author$project$Main$viewAlu = function (model) { _List_fromArray( [ $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(2)) + $author$project$PC$Types$PM_ManualStep(2)) ]), _List_fromArray( [ @@ -7490,145 +7761,101 @@ var $author$project$Main$viewAlu = function (model) { _List_fromArray( [ $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(1)) + $author$project$PC$Types$PM_ManualStep(1)) ]), _List_fromArray( [ $elm$html$Html$text('Acc --') ])) ])), - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('arrow'), - $elm$html$Html$Attributes$class('up') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('button') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$a, - _List_fromArray( - [ - $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(3)) - ]), - _List_fromArray( - [ - $elm$html$Html$text('DB -> ALU') - ])) - ])), - A2($elm$html$Html$div, _List_Nil, _List_Nil) - ])), - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('arrow'), - $elm$html$Html$Attributes$class('down') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('button') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$a, - _List_fromArray( - [ - $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(0)) - ]), - _List_fromArray( - [ - $elm$html$Html$text('ALU -> DB') - ])) - ])), - A2($elm$html$Html$div, _List_Nil, _List_Nil) - ])) + A4($author$project$PC$View$drawArrow, 1, 0, 3, 'DB -> ALU'), + A4($author$project$PC$View$drawArrow, 1, 1, 0, 'ALU -> DB') ])); }; -var $author$project$Main$MsgCuInstrRegEditAddr = function (a) { +var $author$project$PC$Types$PM_F_CuInstrRegEditAddr = function (a) { + return {$: 9, a: a}; +}; +var $author$project$PC$Types$PM_F_CuInstrRegEditInstr = function (a) { + return {$: 10, a: a}; +}; +var $author$project$PC$Types$PM_F_CuProgCounterEdit = function (a) { return {$: 11, a: a}; }; -var $author$project$Main$MsgCuInstrRegEditInstr = function (a) { +var $author$project$PC$Types$PM_F_CuUCounterEdit = function (a) { return {$: 12, a: a}; }; -var $author$project$Main$MsgCuProgCounterEdit = function (a) { - return {$: 14, a: a}; -}; -var $author$project$Main$MsgCuUCounterEdit = function (a) { - return {$: 13, a: a}; -}; var $elm$html$Html$table = _VirtualDom_node('table'); var $elm$html$Html$th = _VirtualDom_node('th'); var $elm$html$Html$thead = _VirtualDom_node('thead'); var $elm$html$Html$tr = _VirtualDom_node('tr'); -var $author$project$Main$MsgCuAddBelow = {$: 10}; +var $author$project$PC$Types$PM_B_CuAddBelow = {$: 4}; +var $elm$core$Elm$JsArray$indexedMap = _JsArray_indexedMap; +var $elm$core$Array$indexedMap = F2( + function (func, _v0) { + var len = _v0.a; + var tree = _v0.c; + var tail = _v0.d; + var initialBuilder = { + d: _List_Nil, + a: 0, + c: A3( + $elm$core$Elm$JsArray$indexedMap, + func, + $elm$core$Array$tailIndex(len), + tail) + }; + var helper = F2( + function (node, builder) { + if (!node.$) { + var subTree = node.a; + return A3($elm$core$Elm$JsArray$foldl, helper, builder, subTree); + } else { + var leaf = node.a; + var offset = builder.a * $elm$core$Array$branchFactor; + var mappedLeaf = $elm$core$Array$Leaf( + A3($elm$core$Elm$JsArray$indexedMap, func, offset, leaf)); + return { + d: A2($elm$core$List$cons, mappedLeaf, builder.d), + a: builder.a + 1, + c: builder.c + }; + } + }); + return A2( + $elm$core$Array$builderToArray, + true, + A3($elm$core$Elm$JsArray$foldl, helper, initialBuilder, tree)); + }); var $elm$html$Html$tbody = _VirtualDom_node('tbody'); var $elm$html$Html$td = _VirtualDom_node('td'); -var $author$project$Main$MsgCuEditAction = F2( +var $author$project$PC$Types$PM_F_CuEditAction = F2( function (a, b) { - return {$: 9, a: a, b: b}; + return {$: 8, a: a, b: b}; }); var $elm$html$Html$option = _VirtualDom_node('option'); var $elm$html$Html$select = _VirtualDom_node('select'); -var $author$project$Main$selectCuValueDecoder = A2( +var $author$project$PC$View$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$uCodeDescriptions = _List_fromArray( - [ - _Utils_Tuple2(0, 'Acc -> DataBus'), - _Utils_Tuple2(1, 'Acc --'), - _Utils_Tuple2(2, 'Acc ++'), - _Utils_Tuple2(3, 'DataBus -> Acc'), - _Utils_Tuple2(4, 'DataBus -> InstReg'), - _Utils_Tuple2(5, 'DataBus -> Ram'), - _Utils_Tuple2(6, 'InstReg -> AddrBus'), - _Utils_Tuple2(7, 'InstReg -> ProgCount'), - _Utils_Tuple2(8, 'InstReg -> µCounter'), - _Utils_Tuple2(9, 'ProgCounter ++'), - _Utils_Tuple2(10, 'Acc == 0 => InstReg -> ProgCounter'), - _Utils_Tuple2(11, 'Ram -> DataBus'), - _Utils_Tuple2(12, 'µCounter = 0'), - _Utils_Tuple2(13, 'ProgCounter -> AddrBus'), - _Utils_Tuple2(14, 'Empty') - ]); -var $author$project$Main$viewCuInstrSelect = F2( +var $author$project$PC$View$viewCuInstrSelect = F2( function (id, current) { - var info2option = function (_v0) { - var action = _v0.a; - var info = _v0.b; + var info2option = function (uCode) { return A2( $elm$html$Html$option, _List_fromArray( [ $elm$html$Html$Attributes$selected( - _Utils_eq(action, current)), - $elm$html$Html$Attributes$value( - $author$project$Main$uAction2String(action)) + _Utils_eq(uCode.a7, current)), + $elm$html$Html$Attributes$value(uCode.aM) ]), _List_fromArray( [ - $elm$html$Html$text(info) + $elm$html$Html$text(uCode.aQ) ])); }; - var listOptions = A2($elm$core$List$map, info2option, $author$project$Main$uCodeDescriptions); + var listOptions = A2($elm$core$List$map, info2option, $author$project$PC$UActions$uCodes); return A2( $elm$html$Html$select, _List_fromArray( @@ -7638,56 +7865,55 @@ var $author$project$Main$viewCuInstrSelect = F2( 'change', A2( $elm$json$Json$Decode$map, - $author$project$Main$MsgCuEditAction(id), - $author$project$Main$selectCuValueDecoder)) + $author$project$PC$Types$PM_F_CuEditAction(id), + $author$project$PC$View$selectCuValueDecoder)) ]), listOptions); }); -var $author$project$Main$viewCuUCodeContent = function (model) { - 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.a.l)), - _Utils_Tuple2('empty', code === 14) - ])) - ]), - _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.q); +var $author$project$PC$View$viewCuUCodeContent = function (model) { + var list2table = F2( + function (id, code) { + return A2( + $elm$html$Html$tr, + _List_fromArray( + [ + $elm$html$Html$Attributes$classList( + _List_fromArray( + [ + _Utils_Tuple2( + 'current', + _Utils_eq(id, model.aW.a5)), + _Utils_Tuple2('empty', code === 14) + ])) + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$td, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('num') + ]), + _List_fromArray( + [ + $elm$html$Html$text( + A2($author$project$PC$Helpers$addLeadingZero, id, 4)) + ])), + A2( + $elm$html$Html$td, + _List_Nil, + _List_fromArray( + [ + A2($author$project$PC$View$viewCuInstrSelect, id, code) + ])) + ])); + }); return A2( $elm$html$Html$tbody, _List_Nil, _Utils_ap( - A2($elm$core$List$map, list2table, indexedList), + $elm$core$Array$toList( + A2($elm$core$Array$indexedMap, list2table, model.a4)), _List_fromArray( [ A2( @@ -7705,7 +7931,7 @@ var $author$project$Main$viewCuUCodeContent = function (model) { $elm$html$Html$button, _List_fromArray( [ - $elm$html$Html$Events$onClick($author$project$Main$MsgCuAddBelow) + $elm$html$Html$Events$onClick($author$project$PC$Types$PM_B_CuAddBelow) ]), _List_fromArray( [ @@ -7715,7 +7941,7 @@ var $author$project$Main$viewCuUCodeContent = function (model) { ])) ]))); }; -var $author$project$Main$viewCuUCode = function (model) { +var $author$project$PC$View$viewCuUCode = function (model) { return A2( $elm$html$Html$table, _List_Nil, @@ -7753,11 +7979,11 @@ var $author$project$Main$viewCuUCode = function (model) { ])) ])) ])), - A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewCuUCodeContent, model) + A2($elm$html$Html$Lazy$lazy, $author$project$PC$View$viewCuUCodeContent, model) ])); }; -var $author$project$Main$viewCu = function (model) { - var _v0 = $author$project$Main$seperateInstructionsEntry(model.a.k); +var $author$project$PC$View$viewCu = function (model) { + var _v0 = $author$project$PC$Helpers$seperateInstructionsEntry(model.aW.aP); var instrRegInst = _v0.a; var instrRegAddr = _v0.b; return A2( @@ -7769,71 +7995,8 @@ var $author$project$Main$viewCu = function (model) { ]), _List_fromArray( [ - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('arrow'), - $elm$html$Html$Attributes$class('up'), - $elm$html$Html$Attributes$class('top') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('button') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$a, - _List_fromArray( - [ - $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(6)) - ]), - _List_fromArray( - [ - $elm$html$Html$text('InstR -> AddrB') - ])) - ])), - A2($elm$html$Html$div, _List_Nil, _List_Nil) - ])), - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('arrow'), - $elm$html$Html$Attributes$class('up'), - $elm$html$Html$Attributes$class('top'), - $elm$html$Html$Attributes$class('arrow2') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('button') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$a, - _List_fromArray( - [ - $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(13)) - ]), - _List_fromArray( - [ - $elm$html$Html$text('ProgCounter -> AddrB') - ])) - ])), - A2($elm$html$Html$div, _List_Nil, _List_Nil) - ])), + A4($author$project$PC$View$drawArrow, 0, 0, 6, 'InstR -> AddrB'), + A4($author$project$PC$View$drawArrow, 0, 0, 13, 'ProgCounter -> AddrB'), A2( $elm$html$Html$h1, _List_fromArray( @@ -7872,7 +8035,7 @@ var $author$project$Main$viewCu = function (model) { _List_fromArray( [ $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(7)) + $author$project$PC$Types$PM_ManualStep(7)) ]), _List_fromArray( [ @@ -7885,8 +8048,8 @@ var $author$project$Main$viewCu = function (model) { $elm$html$Html$Attributes$type_('number'), $elm$html$Html$Attributes$id('cu-progcounter'), $elm$html$Html$Attributes$value( - A2($author$project$Main$addLeadingZero, model.a.u, 3)), - $elm$html$Html$Events$onInput($author$project$Main$MsgCuProgCounterEdit) + A2($author$project$PC$Helpers$addLeadingZero, model.aW.aX, 3)), + $elm$html$Html$Events$onInput($author$project$PC$Types$PM_F_CuProgCounterEdit) ]), _List_Nil) ])), @@ -7921,8 +8084,8 @@ var $author$project$Main$viewCu = function (model) { $elm$html$Html$Attributes$id('cu-instrReg'), $elm$html$Html$Attributes$class('instruction'), $elm$html$Html$Attributes$value( - A2($author$project$Main$addLeadingZero, instrRegInst, 3)), - $elm$html$Html$Events$onInput($author$project$Main$MsgCuInstrRegEditInstr) + A2($author$project$PC$Helpers$addLeadingZero, instrRegInst, 3)), + $elm$html$Html$Events$onInput($author$project$PC$Types$PM_F_CuInstrRegEditInstr) ]), _List_Nil), A2( @@ -7933,8 +8096,8 @@ var $author$project$Main$viewCu = function (model) { $elm$html$Html$Attributes$id('cu-instrReg'), $elm$html$Html$Attributes$class('address'), $elm$html$Html$Attributes$value( - A2($author$project$Main$addLeadingZero, instrRegAddr, 5)), - $elm$html$Html$Events$onInput($author$project$Main$MsgCuInstrRegEditAddr) + A2($author$project$PC$Helpers$addLeadingZero, instrRegAddr, 5)), + $elm$html$Html$Events$onInput($author$project$PC$Types$PM_F_CuInstrRegEditAddr) ]), _List_Nil) ])) @@ -7962,7 +8125,7 @@ var $author$project$Main$viewCu = function (model) { _List_fromArray( [ $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(8)) + $author$project$PC$Types$PM_ManualStep(8)) ]), _List_fromArray( [ @@ -7975,8 +8138,8 @@ var $author$project$Main$viewCu = function (model) { $elm$html$Html$Attributes$type_('number'), $elm$html$Html$Attributes$id('cu-uCounter'), $elm$html$Html$Attributes$value( - A2($author$project$Main$addLeadingZero, model.a.l, 4)), - $elm$html$Html$Events$onInput($author$project$Main$MsgCuUCounterEdit) + A2($author$project$PC$Helpers$addLeadingZero, model.aW.a5, 4)), + $elm$html$Html$Events$onInput($author$project$PC$Types$PM_F_CuUCounterEdit) ]), _List_Nil) ])) @@ -7989,45 +8152,15 @@ var $author$project$Main$viewCu = function (model) { ]), _List_fromArray( [ - $author$project$Main$viewCuUCode(model) + $author$project$PC$View$viewCuUCode(model) ])), - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('arrow'), - $elm$html$Html$Attributes$class('up') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('button') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$a, - _List_fromArray( - [ - $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(4)) - ]), - _List_fromArray( - [ - $elm$html$Html$text('DB -> InstR') - ])) - ])), - A2($elm$html$Html$div, _List_Nil, _List_Nil) - ])) + A4($author$project$PC$View$drawArrow, 1, 0, 4, 'DB -> InstR') ])); }; -var $author$project$Main$MsgEditDataBus = function (a) { - return {$: 16, a: a}; +var $author$project$PC$Types$PM_F_EditDataBus = function (a) { + return {$: 14, a: a}; }; -var $author$project$Main$viewDataBus = function (model) { +var $author$project$PC$View$viewDataBus = function (model) { return A2( $elm$html$Html$div, _List_fromArray( @@ -8057,275 +8190,122 @@ var $author$project$Main$viewDataBus = function (model) { [ $elm$html$Html$Attributes$type_('number'), $elm$html$Html$Attributes$value( - A2($author$project$Main$addLeadingZero, model.a.s, 8)), - $elm$html$Html$Events$onInput($author$project$Main$MsgEditDataBus) + A2($author$project$PC$Helpers$addLeadingZero, model.aW.aG, 8)), + $elm$html$Html$Events$onInput($author$project$PC$Types$PM_F_EditDataBus) ]), _List_Nil) ])) ])); }; -var $elm$core$Basics$not = _Basics_not; -var $author$project$Main$MsgLoadExample = function (a) { - return {$: 22, a: a}; -}; -var $author$project$Main$viewExamplesEntrys = function (model) { - var entry2html = function (_v1) { - var id = _v1.a; - var example = _v1.b; - return A2( - $elm$html$Html$tr, - _List_Nil, - _List_fromArray( - [ - A2( - $elm$html$Html$td, - _List_Nil, - _List_fromArray( - [ - $elm$html$Html$text('Example: ' + example.aA) - ])), - A2( - $elm$html$Html$td, - _List_Nil, - _List_fromArray( - [ - A2( - $elm$html$Html$button, - _List_fromArray( - [ - $elm$html$Html$Events$onClick( - $author$project$Main$MsgLoadExample(id)) - ]), - _List_fromArray( - [ - $elm$html$Html$text('Laden') - ])) - ])) - ])); - }; - var _v0 = model.R; - switch (_v0.$) { - case 0: - var msg = _v0.a; - return A2( - $elm$html$Html$div, - _List_Nil, - _List_fromArray( - [ - $elm$html$Html$text('That didn\'t work: ' + msg) - ])); - case 1: - return A2( - $elm$html$Html$div, - _List_Nil, - _List_fromArray( - [ - $elm$html$Html$text('Loading...') - ])); - default: - return A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('scroller') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$table, - _List_Nil, - A2( - $elm$core$List$map, - entry2html, - A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, model.H))) - ])); - } -}; -var $author$project$Main$viewExamples = function (model) { - return A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$classList( - _List_fromArray( - [ - _Utils_Tuple2('modal', true), - _Utils_Tuple2('hidden', !model.G) - ])) - ]), - _List_fromArray( - [ - A2($elm$html$Html$div, _List_Nil, _List_Nil), - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('modal-card') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$a, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('modal-close'), - $elm$html$Html$Events$onClick($author$project$Main$MsgToggleLoadExample) - ]), - _List_Nil), - A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewExamplesEntrys, model) - ])) - ])); -}; -var $author$project$Main$viewExamplesLoaderError = function (model) { - var _v0 = model.Q; - if (!_v0.$) { - var msg = _v0.a; - return A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('modal') - ]), - _List_fromArray( - [ - A2($elm$html$Html$div, _List_Nil, _List_Nil), - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('modal-card') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$p, - _List_Nil, - _List_fromArray( - [ - $elm$html$Html$text('Something didn\'t work. Please refresh the page') - ])), - A2( - $elm$html$Html$p, - _List_Nil, - _List_fromArray( - [ - $elm$html$Html$text(msg) - ])) - ])) - ])); - } else { - return $elm$html$Html$text(''); - } -}; -var $author$project$Main$MsgRamAddBelow = {$: 7}; -var $author$project$Main$MsgRamEditAddress = F2( - function (a, b) { - return {$: 5, a: a, b: b}; - }); -var $author$project$Main$MsgRamEditComment = F2( - function (a, b) { - return {$: 8, a: a, b: b}; - }); -var $author$project$Main$MsgRamEditInstr = F2( +var $author$project$PC$Types$PM_B_RamAddBelow = {$: 3}; +var $author$project$PC$Types$PM_F_RamEditAddress = F2( function (a, b) { return {$: 6, a: a, b: b}; }); -var $author$project$Main$viewRamContent = function (model) { - var ram2table = function (entry) { - var id = entry.a; - var _v0 = entry.b; - var val = _v0.a; - var comment = _v0.b; - var _v1 = $author$project$Main$seperateInstructionsEntry(val); - var instruction = _v1.a; - var address = _v1.b; - return A2( - $elm$html$Html$tr, - _List_fromArray( - [ - $elm$html$Html$Attributes$classList( - _List_fromArray( - [ - _Utils_Tuple2( - 'current', - _Utils_eq(id, model.a.r)) - ])) - ]), - _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_fromArray( - [ - $elm$html$Html$Attributes$class('num ') - ]), - _List_fromArray( - [ - 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) - ])), - A2( - $elm$html$Html$td, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('comment') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$input, - _List_fromArray( - [ - $elm$html$Html$Attributes$type_('text'), - $elm$html$Html$Attributes$value(comment), - $elm$html$Html$Events$onInput( - $author$project$Main$MsgRamEditComment(id)) - ]), - _List_Nil) - ])) - ])); - }; - var indexedRam = A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, model.a.c); +var $author$project$PC$Types$PM_F_RamEditComment = F2( + function (a, b) { + return {$: 7, a: a, b: b}; + }); +var $author$project$PC$Types$PM_F_RamEditInstr = F2( + function (a, b) { + return {$: 5, a: a, b: b}; + }); +var $author$project$PC$View$viewRamContent = function (model) { + var ram2table = F2( + function (id, entry) { + var _v0 = entry; + var val = _v0.a; + var comment = _v0.b; + var _v1 = $author$project$PC$Helpers$seperateInstructionsEntry(val); + var instruction = _v1.a; + var address = _v1.b; + return A2( + $elm$html$Html$tr, + _List_fromArray( + [ + $elm$html$Html$Attributes$classList( + _List_fromArray( + [ + _Utils_Tuple2( + 'current', + _Utils_eq(id, model.aW.aB)) + ])) + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$td, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('num') + ]), + _List_fromArray( + [ + $elm$html$Html$text( + A2($author$project$PC$Helpers$addLeadingZero, id, 3)) + ])), + A2( + $elm$html$Html$td, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('num ') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$input, + _List_fromArray( + [ + $elm$html$Html$Attributes$type_('number'), + $elm$html$Html$Attributes$value( + A2($author$project$PC$Helpers$addLeadingZero, instruction, 3)), + $elm$html$Html$Events$onInput( + $author$project$PC$Types$PM_F_RamEditInstr(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$PC$Helpers$addLeadingZero, address, 5)), + $elm$html$Html$Events$onInput( + $author$project$PC$Types$PM_F_RamEditAddress(id)), + $elm$html$Html$Attributes$class('ram-entry'), + $elm$html$Html$Attributes$class('address') + ]), + _List_Nil) + ])), + A2( + $elm$html$Html$td, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('comment') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$input, + _List_fromArray( + [ + $elm$html$Html$Attributes$type_('text'), + $elm$html$Html$Attributes$value(comment), + $elm$html$Html$Events$onInput( + $author$project$PC$Types$PM_F_RamEditComment(id)) + ]), + _List_Nil) + ])) + ])); + }); return A2( $elm$html$Html$tbody, _List_Nil, _Utils_ap( - A2($elm$core$List$map, ram2table, indexedRam), + $elm$core$Array$toList( + A2($elm$core$Array$indexedMap, ram2table, model.aW.aY)), _List_fromArray( [ A2( @@ -8343,7 +8323,7 @@ var $author$project$Main$viewRamContent = function (model) { $elm$html$Html$button, _List_fromArray( [ - $elm$html$Html$Events$onClick($author$project$Main$MsgRamAddBelow) + $elm$html$Html$Events$onClick($author$project$PC$Types$PM_B_RamAddBelow) ]), _List_fromArray( [ @@ -8354,7 +8334,7 @@ var $author$project$Main$viewRamContent = function (model) { ])) ]))); }; -var $author$project$Main$viewRam = function (model) { +var $author$project$PC$View$viewRam = function (model) { return A2( $elm$html$Html$div, _List_fromArray( @@ -8442,73 +8422,200 @@ var $author$project$Main$viewRam = function (model) { ])) ])) ])), - A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewRamContent, model) + A2($elm$html$Html$Lazy$lazy, $author$project$PC$View$viewRamContent, model) ])) ])), + A4($author$project$PC$View$drawArrow, 1, 1, 11, 'Ram -> DataBus'), + A4($author$project$PC$View$drawArrow, 1, 0, 5, 'DataBus -> Ram') + ])); +}; +var $author$project$PC$View$pc_view = function (model) { + return A2( + $elm$html$Html$div, + _List_Nil, + _List_fromArray( + [ A2( $elm$html$Html$div, _List_fromArray( [ - $elm$html$Html$Attributes$class('arrow'), - $elm$html$Html$Attributes$class('down') + $elm$html$Html$Attributes$class('grid-fullwidth'), + $elm$html$Html$Attributes$class('grid-addressbus') ]), _List_fromArray( [ - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('button') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$a, - _List_fromArray( - [ - $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(11)) - ]), - _List_fromArray( - [ - $elm$html$Html$text('Ram -> DataBus') - ])) - ])), - A2($elm$html$Html$div, _List_Nil, _List_Nil) + A2($elm$html$Html$Lazy$lazy, $author$project$PC$View$viewAddressBus, model) ])), + A2($elm$html$Html$Lazy$lazy, $author$project$PC$View$viewRam, model), + A2($elm$html$Html$Lazy$lazy, $author$project$PC$View$viewCu, model), + A2($elm$html$Html$Lazy$lazy, $author$project$PC$View$viewAlu, model), A2( $elm$html$Html$div, _List_fromArray( [ - $elm$html$Html$Attributes$class('arrow'), - $elm$html$Html$Attributes$class('up') + $elm$html$Html$Attributes$class('grid-fullwidth'), + $elm$html$Html$Attributes$class('grid-databus') ]), _List_fromArray( [ - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('button') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$a, - _List_fromArray( - [ - $elm$html$Html$Events$onClick( - $author$project$Main$MsgManualStep(5)) - ]), - _List_fromArray( - [ - $elm$html$Html$text('DataBus -> Ram') - ])) - ])), - A2($elm$html$Html$div, _List_Nil, _List_Nil) + A2($elm$html$Html$Lazy$lazy, $author$project$PC$View$viewDataBus, model) ])) ])); }; +var $author$project$PC$PC$view = $author$project$PC$View$pc_view; +var $author$project$Main$Msg_DEsmpl_EClick = function (a) { + return {$: 3, a: a}; +}; +var $author$project$Main$viewExamplesEntrys = function (model) { + var entry2html = function (_v1) { + var id = _v1.a; + var example = _v1.b; + return A2( + $elm$html$Html$tr, + _List_Nil, + _List_fromArray( + [ + A2( + $elm$html$Html$td, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text('Example: ' + example.as) + ])), + A2( + $elm$html$Html$td, + _List_Nil, + _List_fromArray( + [ + A2( + $elm$html$Html$button, + _List_fromArray( + [ + $elm$html$Html$Events$onClick( + $author$project$Main$Msg_DEsmpl_EClick(id)) + ]), + _List_fromArray( + [ + $elm$html$Html$text('Laden') + ])) + ])) + ])); + }; + var _v0 = model.E; + switch (_v0.$) { + case 0: + var msg = _v0.a; + return A2( + $elm$html$Html$div, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text('That didn\'t work: ' + msg) + ])); + case 1: + return A2( + $elm$html$Html$div, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text('Loading...') + ])); + default: + return A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('scroller') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$table, + _List_Nil, + A2( + $elm$core$List$map, + entry2html, + A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, model.D))) + ])); + } +}; +var $author$project$Main$viewExamples = function (model) { + return A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$classList( + _List_fromArray( + [ + _Utils_Tuple2('modal', true), + _Utils_Tuple2('hidden', !model.y) + ])) + ]), + _List_fromArray( + [ + A2($elm$html$Html$div, _List_Nil, _List_Nil), + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('modal-card') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$a, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('modal-close'), + $elm$html$Html$Events$onClick( + $author$project$Main$Msg_DEsmpl_Open(false)) + ]), + _List_Nil), + A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewExamplesEntrys, model) + ])) + ])); +}; +var $author$project$Main$viewExamplesLoaderError = function (model) { + var _v0 = model.C; + if (!_v0.$) { + var msg = _v0.a; + return A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('modal') + ]), + _List_fromArray( + [ + A2($elm$html$Html$div, _List_Nil, _List_Nil), + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('modal-card') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$p, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text('Something didn\'t work. Please refresh the page') + ])), + A2( + $elm$html$Html$p, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text(msg) + ])) + ])) + ])); + } else { + return $elm$html$Html$text(''); + } +}; var $author$project$Main$viewPC = function (model) { return A2( $elm$html$Html$div, @@ -8531,7 +8638,8 @@ var $author$project$Main$viewPC = function (model) { $elm$html$Html$button, _List_fromArray( [ - $elm$html$Html$Events$onClick($author$project$Main$MsgUCycleStep) + $elm$html$Html$Events$onClick( + $author$project$Main$Msg_PC($author$project$PC$Types$PM_B_UCycleStep)) ]), _List_fromArray( [ @@ -8541,7 +8649,8 @@ var $author$project$Main$viewPC = function (model) { $elm$html$Html$button, _List_fromArray( [ - $elm$html$Html$Events$onClick($author$project$Main$MsgInstructionStep) + $elm$html$Html$Events$onClick( + $author$project$Main$Msg_PC($author$project$PC$Types$PM_B_InstructionStep)) ]), _List_fromArray( [ @@ -8551,7 +8660,8 @@ var $author$project$Main$viewPC = function (model) { $elm$html$Html$button, _List_fromArray( [ - $elm$html$Html$Events$onClick($author$project$Main$MsgReset) + $elm$html$Html$Events$onClick( + $author$project$Main$Msg_PC($author$project$PC$Types$PM_B_Reset)) ]), _List_fromArray( [ @@ -8566,9 +8676,9 @@ var $author$project$Main$viewPC = function (model) { [ _Utils_Tuple2('checker', true), _Utils_Tuple2('button', true), - _Utils_Tuple2('checked', model.A) + _Utils_Tuple2('checked', model.s) ])), - $elm$html$Html$Events$onClick($author$project$Main$MsgAutoscrollUpdate) + $elm$html$Html$Events$onClick($author$project$Main$Msg_Autoscroll_Toggle) ]), _List_fromArray( [ @@ -8578,8 +8688,8 @@ var $author$project$Main$viewPC = function (model) { [ $elm$html$Html$Attributes$type_('checkbox'), $elm$html$Html$Attributes$id('enableScrolling'), - $elm$html$Html$Attributes$checked(model.A), - $elm$html$Html$Events$onClick($author$project$Main$MsgAutoscrollUpdate) + $elm$html$Html$Attributes$checked(model.s), + $elm$html$Html$Events$onClick($author$project$Main$Msg_Autoscroll_Toggle) ]), _List_Nil), A2( @@ -8597,7 +8707,8 @@ var $author$project$Main$viewPC = function (model) { $elm$html$Html$button, _List_fromArray( [ - $elm$html$Html$Events$onClick($author$project$Main$MsgToggleLoadExample) + $elm$html$Html$Events$onClick( + $author$project$Main$Msg_DEsmpl_Open(true)) ]), _List_fromArray( [ @@ -8608,26 +8719,14 @@ var $author$project$Main$viewPC = function (model) { $elm$html$Html$div, _List_fromArray( [ - $elm$html$Html$Attributes$class('grid-fullwidth'), - $elm$html$Html$Attributes$class('grid-addressbus') + $elm$html$Html$Attributes$class('pc-main') ]), _List_fromArray( [ - A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewAddressBus, model) - ])), - A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewRam, model), - A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewCu, model), - A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewAlu, model), - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('grid-fullwidth'), - $elm$html$Html$Attributes$class('grid-databus') - ]), - _List_fromArray( - [ - A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewDataBus, model) + A2( + $elm$html$Html$map, + $author$project$Main$Msg_PC, + $author$project$PC$PC$view(model.p)) ])), A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewExamples, model), A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewExamplesLoaderError, model) @@ -8637,6 +8736,6 @@ var $author$project$Main$view = function (model) { return A2($elm$html$Html$Lazy$lazy, $author$project$Main$viewPC, model); }; var $author$project$Main$main = $elm$browser$Browser$element( - {aR: $author$project$Main$init, a0: $author$project$Main$subscriptions, a2: $author$project$Main$update, a4: $author$project$Main$view}); + {aO: $author$project$Main$init, a2: $author$project$Main$subscriptions, a6: $author$project$Main$update, a9: $author$project$Main$view}); _Platform_export({'Main':{'init':$author$project$Main$main( $elm$json$Json$Decode$succeed(0))(0)}});}(this)); \ No newline at end of file diff --git a/src/Main.elm b/src/Main.elm index ac36f08..1bfd927 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -4,48 +4,39 @@ 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 as HEvent exposing (onClick, onInput) -import Html.Lazy exposing (lazy) +import Html exposing (Html, button, div, h1, p, text) +import Html.Attributes as HAttr exposing (class, classList, value) +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.Encode as JE -import Json.Decode as JD -import Html.Events exposing (targetValue) +import Array exposing (get) +--import Html exposing (address) +import Json.Encode as JE +import Json.Decode as JD +--import Html.Events exposing (targetValue) import Http -modelVersion = 2 -examplesListUrl = "examples-list.json" +import PC.Types exposing (..) +import PC.PC as PC +import PC.Json +import PC.Helpers exposing (..) -- Note that general Stuff is at the end of the document + +examplesListUrl = "examples-list.json" + +-- #################################################### -- PORTS - - +-- #################################################### port sendUUpdate : String -> Cmd msg - - port localStorageSend : String -> Cmd msg -port localStorageRecieve : (String -> msg) -> Sub msg - - -type alias PC = - { ram : List (Int, String) - , dataBus : Int - , addressBus : Int - , instructionReg : Int - , programmCounter : Int - , uCounter : Int - , accumulator : Int - } - +-- ##################################################################### +-- ##################################################################### type alias Model = - { pc : PC - , uCode : List UAction + { pc_model : PC_Model , autoscroll : Bool , examples : List Example , exampleChooserOpen : Bool @@ -62,509 +53,129 @@ type alias Example = type LoaderState = Failure String | Waiting | Success +-- ##################################################################### +-- Update +-- ##################################################################### -type UAction - = ActAccumulator2DataBus - | ActAccumulatorDecrement - | ActAccumulatorIncrement - | ActDataBus2Accumulator - | ActDataBus2InstructionReg - | ActDataBus2Ram - | ActInstructionReg2AddressBus - | ActInstructionReg2ProgrammCounter - | ActInstructionReg2UCounter - | ActProgrammCounterIncrement - | ActInstructionReg2ProgrammCounterIfAccEq0 - | ActRam2DataBus - | ActResetUCounter - | ActProgrammCounter2AddressBus - | ActNothing - -uCodeDescriptions : List ( UAction, String ) -uCodeDescriptions = - [ ( ActAccumulator2DataBus, "Acc -> DataBus" ) - , ( ActAccumulatorDecrement, "Acc --" ) - , ( ActAccumulatorIncrement, "Acc ++" ) - , ( ActDataBus2Accumulator, "DataBus -> Acc" ) - , ( ActDataBus2InstructionReg, "DataBus -> InstReg" ) - , ( ActDataBus2Ram, "DataBus -> Ram" ) - , ( ActInstructionReg2AddressBus, "InstReg -> AddrBus" ) - , ( ActInstructionReg2ProgrammCounter, "InstReg -> ProgCount" ) - , ( ActInstructionReg2UCounter, "InstReg -> µCounter" ) - , ( ActProgrammCounterIncrement, "ProgCounter ++" ) - , ( ActInstructionReg2ProgrammCounterIfAccEq0, "Acc == 0 => InstReg -> ProgCounter") - , ( ActRam2DataBus, "Ram -> DataBus" ) - , ( ActResetUCounter, "µCounter = 0" ) - , ( ActProgrammCounter2AddressBus, "ProgCounter -> AddrBus" ) - , ( 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" ) - , ( ActInstructionReg2ProgrammCounterIfAccEq0, "ir2pciacceq0") - , ( ActRam2DataBus, "ram2db" ) - , ( ActResetUCounter, "ucReset" ) - , ( ActProgrammCounter2AddressBus, "pc2ab" ) - , ( ActNothing, "n" ) - ] - -uCodeMaps : List ( UAction, PC -> PC ) -uCodeMaps = - [ ( ActAccumulator2DataBus, actAccumulator2DataBus ) - , ( ActAccumulatorDecrement, actAccumulatorDecrement ) - , ( ActAccumulatorIncrement, actAccumulatorIncrement ) - , ( ActDataBus2Accumulator, actDataBus2Accumulator ) - , ( ActDataBus2InstructionReg, actDataBus2InstructionReg ) - , ( ActDataBus2Ram, actDataBus2Ram ) - , ( ActInstructionReg2AddressBus, actInstructionReg2AddressBus ) - , ( ActInstructionReg2ProgrammCounter, actInstructionReg2ProgrammCounter ) - , ( ActInstructionReg2UCounter, actInstructionReg2UCounter ) - , ( ActProgrammCounterIncrement, actProgrammCounterIncrement ) - , ( ActInstructionReg2ProgrammCounterIfAccEq0, actInstructionReg2ProgrammCounterIfAccEq0 ) - , ( ActRam2DataBus, actRam2DataBus ) - , ( ActResetUCounter, actResetUCounter ) - , ( ActProgrammCounter2AddressBus, actProgrammCounter2AddressBus ) - , ( ActNothing, (\s -> s)) - ] - - -initialRam : List (Int, String) -initialRam = - [ (100005, "LoadA #005") -- 000 -- LoadA #005 - , (300000, "IncA") -- 001 -- IncA - , (200005, "StoreA #005") -- 002 -- StoreA #005 - , (400000, "JMP #000") -- 003 -- JMP #000 - , (0,"") -- 004 - , (5,"val") -- 005 - , (0, "") -- 006 - , (0, "") -- 007 - , (0, "") -- 008 - , (0, "") -- 009 - , (0, "") -- 010 - ] - - -initialPC : PC -initialPC = - PC - initialRam - 0 - 0 - 0 - 0 - 0 - 0 - - -initialUCodes : List UAction -initialUCodes = - [ ActProgrammCounter2AddressBus -- 000 - , ActRam2DataBus -- 001 - , ActDataBus2InstructionReg -- 002 - , ActProgrammCounterIncrement -- 003 - , ActInstructionReg2UCounter -- 004 - , ActNothing -- 005 - , ActNothing - , ActNothing - , ActNothing - , ActNothing -- 009 - - -- 010 LOADA - , ActInstructionReg2AddressBus -- 010 - , ActRam2DataBus -- 011 - , ActDataBus2Accumulator -- 012 - , ActResetUCounter -- 013 - , ActNothing -- 014 - , ActNothing - , ActNothing - , ActNothing - , ActNothing - , ActNothing -- 019 - - -- 020 STOA - , ActAccumulator2DataBus -- 020 - , ActInstructionReg2AddressBus -- 021 - , ActDataBus2Ram -- 022 - , ActResetUCounter -- 023 - , ActNothing --024 - , ActNothing - , ActNothing - , ActNothing - , ActNothing - , ActNothing -- 029 - - -- 030 INCA - , ActAccumulatorIncrement -- 030 - , ActResetUCounter -- 031 - , ActNothing -- 032 - , ActNothing - , ActNothing - , ActNothing - , ActNothing - , ActNothing - , ActNothing - , ActNothing -- 039 - - -- 040 JMP - , ActInstructionReg2ProgrammCounter -- 040 - , ActResetUCounter -- 041 - , ActNothing -- 042 - , ActNothing - , ActNothing - , ActNothing - , ActNothing - , ActNothing - , ActNothing - , ActNothing -- 049 - ] - - +-- DEsmpl = Dialog Examples type Msg - = MsgUCycleStep - | MsgInstructionStep - | MsgReset - | MsgAutoscrollUpdate - | MsgManualStep UAction - | MsgRamEditAddress Int String - | MsgRamEditInstr Int String - | MsgRamAddBelow - | MsgRamEditComment Int String - | MsgCuEditAction Int String - | MsgCuAddBelow - | MsgCuInstrRegEditAddr String - | MsgCuInstrRegEditInstr String - | MsgCuUCounterEdit String - | MsgCuProgCounterEdit String - | MsgEditAddressBus String - | MsgEditDataBus String - | MsgAluEdit String - | MsgLocalSessionExport - | MsgLocalSessionRecieve String - | MsgToggleLoadExample - | MsgLoadExamplesList - | MsgLoadExample Int - | MsgLoadExampleArrived (Result Http.Error Model) - | MsgExamplesArrived (Result Http.Error (List Example)) + = Msg_PC PC_Msg + | Msg_Autoscroll_Toggle + | Msg_DEsmpl_Open Bool + | Msg_DEsmpl_EClick Int + | Msg_DEsmpl_ExampleLoaded (Result Http.Error Model) + | Msg_DEsmpl_ListLoaded (Result Http.Error (List Example)) 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 - , cmdSenduUpdate model + Msg_PC pc_msg -> -- PC is updated + let + (new_pc, pua) = PC.update pc_msg model.pc_model + new_model = {model | pc_model = new_pc} + in + case pua of + PUA_Nothing -> + ( new_model + , Cmd.none) + PUA_Storage -> + ( new_model + , cmd_up_lStorage new_model) + PUA_Scroller -> + ( new_model + , cmd_scoller new_model ) + PUA_Storage_And_Scroller -> + ( new_model + , cmd_up_lStorage_n_Scroller new_model + ) + + + Msg_Autoscroll_Toggle -> -- User toggled automatic scrolling checkbox + let + new_model = { model | autoscroll = not model.autoscroll } + in + ( new_model, cmd_up_lStorage_n_Scroller new_model ) + + + Msg_DEsmpl_Open True -> -- When the user clicks on "open examples" + ( { model | exampleChooserOpen = True } + , Http.get + { url = examplesListUrl + , expect = Http.expectJson Msg_DEsmpl_ListLoaded exampleListDecoder + } ) - MsgInstructionStep -> - ( executeInstruction model - , cmdSenduUpdate model ) - - - MsgReset -> - let - new_model = { model | pc = { initialPC | ram = model.pc.ram } } - in - ( new_model, cmdSenduUpdate new_model ) - - MsgManualStep action -> - let - instruction = getAction action - new_model = { model | pc = instruction model.pc } - in - ( new_model, cmdSenduUpdate new_model ) - - MsgRamEditAddress addr may_int -> - case String.toInt may_int of - Just int -> - let - (inst,_) = seperateInstructionsEntry ( Tuple.first <| valueAtRam addr model.pc.ram ) - new_val = inst * 100000 + int - old_pc = model.pc - new_pc = { old_pc | ram = (changeAtRam addr new_val old_pc.ram) } - in - updateModel { model | pc = new_pc } - _ -> (model, Cmd.none) - - MsgRamEditInstr addr may_int -> - case String.toInt may_int of - Just int -> - let - (_,address) = seperateInstructionsEntry ( Tuple.first <| valueAtRam addr model.pc.ram ) - new_val = int * 100000 + address - old_pc = model.pc - new_pc = { old_pc | ram = (changeAtRam addr new_val old_pc.ram) } - in - updateModel { model | pc = new_pc } - _ -> ( model, Cmd.none ) - - MsgRamAddBelow -> - let - old_pc = model.pc - new_pc = {old_pc | ram = old_pc.ram ++ [(0, "")]} - in - updateModel {model | pc = new_pc} - - MsgRamEditComment addr str -> - let - (val, _) = valueAtRam addr model.pc.ram - old_pc = model.pc - new_pc = { old_pc | ram = changeAt addr (val, str) (0,"") old_pc.ram } - in - updateModel { model | pc = new_pc } - - MsgCuEditAction addr may_action -> - case string2uAction may_action of - Just action -> - let - newCode = changeAtUCode addr action model.uCode - in - updateModel { model | uCode = newCode } - _ -> ( model, Cmd.none ) - - MsgCuAddBelow -> - updateModel {model | uCode = model.uCode ++ List.repeat 10 ActNothing} - - MsgCuInstrRegEditAddr text -> - case String.toInt text of - Just int -> - let old_pc = model.pc - (instr,_) = seperateInstructionsEntry old_pc.instructionReg - new_pc = { old_pc | instructionReg = instr * 100000 + int } - in - updateModel { model | pc = new_pc } - _ -> ( model, Cmd.none ) - - MsgCuInstrRegEditInstr text -> - case String.toInt text of - Just int -> - let old_pc = model.pc - (_,addr) = seperateInstructionsEntry old_pc.instructionReg - new_pc = { old_pc | instructionReg = int * 100000 + addr } - in - updateModel { model | pc = new_pc } - _ -> ( model, Cmd.none ) - - MsgCuProgCounterEdit text -> - case String.toInt text of - Just int -> - let old_pc = model.pc - new_pc = { old_pc | programmCounter = int } - in - updateModel { model | pc = new_pc } - _ -> ( model, Cmd.none ) - - MsgCuUCounterEdit text -> - case String.toInt text of - Just int -> - let old_pc = model.pc - new_pc = { old_pc | uCounter = int } - in - ( { model | pc = new_pc }, cmdSenduUpdate model ) - _ -> ( model, Cmd.none ) - - MsgEditAddressBus text -> - case String.toInt text of - Just int -> - let old_pc = model.pc - new_pc = { old_pc | addressBus = int } - in - ( { model | pc = new_pc }, cmdSenduUpdate model ) - _ -> ( model, Cmd.none ) - - MsgEditDataBus text -> - case String.toInt text of - Just int -> - let old_pc = model.pc - new_pc = { old_pc | dataBus = int } - in - updateModel { model | pc = new_pc } - _ -> ( model, Cmd.none ) - - MsgAluEdit text -> - case String.toInt text of - Just int -> - let old_pc = model.pc - new_pc = { old_pc | accumulator = int } - in - updateModel { model | pc = new_pc } - _ -> ( model, Cmd.none ) - - MsgAutoscrollUpdate -> - if model.autoscroll then - updateModel { model | autoscroll = False } - else - let - new_model = { model | autoscroll = True } - in - ( new_model - , cmdSenduUpdate new_model ) - - MsgLocalSessionExport -> - ( model, cmdUpdateLocalStorage model ) - - MsgLocalSessionRecieve message_in -> - case decodeModel model message_in of - Just new_model -> - ( { new_model | examples = model.examples } , Cmd.none ) - _ -> ( model, Cmd.none ) - - MsgToggleLoadExample -> - if model.exampleChooserOpen then - ( { model | exampleChooserOpen = False } - , Cmd.none ) - else - ( { model | exampleChooserOpen = True } - , cmdLoadExamples model) - - - MsgLoadExamplesList -> - ( model, Cmd.none ) - - MsgLoadExample i -> + Msg_DEsmpl_Open False -> -- User closes Dialog + ( { model | exampleChooserOpen = False }, Cmd.none ) + + Msg_DEsmpl_EClick i -> -- User chose example. Load it. case valueAt i model.examples of Just example -> - ({ model | exampleChooserOpen = False } - , cmdLoadExampleSing model example ) + ( model + , Http.get + { url = example.url + , expect = Http.expectJson Msg_DEsmpl_ExampleLoaded modelDecoder + } + ) + Nothing -> ( model, Cmd.none ) - MsgLoadExampleArrived result -> + Msg_DEsmpl_ExampleLoaded result -> -- When a single example is loaded case result of - Ok new_model -> - updateModel { model | pc = new_model.pc - , uCode = new_model.uCode - , exampleLoaderStatus = Success } + Ok example_model -> + let + new_model = + { model + | pc_model = example_model.pc_model + , exampleLoaderStatus = Success + , exampleChooserOpen = False + } + in + ( new_model, cmd_up_lStorage_n_Scroller new_model ) Err err -> - ( { model | exampleLoaderStatus = Failure <| httpError2String err } + ( { model | exampleLoaderStatus = Failure <| printHttpError err } , Cmd.none ) - MsgExamplesArrived result -> + Msg_DEsmpl_ListLoaded result -> case result of Ok exampleList -> ( { model | examples = exampleList, examplesListStatus = Success } , Cmd.none ) Err err -> - ( { model | examplesListStatus = Failure <| httpError2String err } + ( { model | examplesListStatus = Failure <| printHttpError err } , Cmd.none ) - --- Practically a part of uStepPC but sepeated for manual mode -getAction : UAction -> (PC -> PC) -getAction uAction = - let - possible_instructions = - List.filter (\s -> Tuple.first s == uAction) uCodeMaps - in - case List.head possible_instructions of - Just ( name, instruction ) -> - instruction - _ -> - (\s -> s) -uStepPC : Model -> Model -uStepPC model = - let - uCounter = - model.pc.uCounter +-- ############################################################################### - may_instruction : Maybe UAction - may_instruction = - valueAt uCounter model.uCode - in - case may_instruction of - Just action -> - let - possible_instructions = - List.filter (\s -> Tuple.first s == action) uCodeMaps - in - case List.head possible_instructions of - Just ( name, instruction ) -> - let - old_pc = - model.pc +cmd_up_lStorage : Model -> Cmd Msg +cmd_up_lStorage model = + localStorageSend (doEncodeModel model) - new_pc = - { old_pc | uCounter = old_pc.uCounter + 1 } - in - { model | pc = instruction new_pc } +cmd_scoller : Model -> Cmd Msg +cmd_scoller model = + sendUUpdate "update" - _ -> - let - old_pc = - model.pc +cmd_up_lStorage_n_Scroller : Model -> Cmd Msg +cmd_up_lStorage_n_Scroller model = + Cmd.batch + [ cmd_up_lStorage model + , cmd_scoller model + ] - new_pc = - { old_pc | uCounter = 0 } - in - { model | pc = new_pc } - - _ -> - model +-- ############################################################################### +-- ############################################################################### -executeInstruction : Model -> Model -executeInstruction model = - let - new_model = uStepPC model - in - if new_model.pc.uCounter == 0 then - uStepPC new_model - else - executeInstruction new_model -encodeModel : Model -> String -encodeModel model = - let - tuple2Encoder : (a -> JE.Value) -> (b -> JE.Value) -> (a, b) -> JE.Value - tuple2Encoder enc1 enc2 (val1, val2) = - JE.list identity [ enc1 val1, enc2 val2 ] - in - 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 (tuple2Encoder JE.int JE.string) model.pc.ram ) - ] - ) - , ( "uCode", JE.list JE.string (List.map uAction2String model.uCode) ) - , ( "autoscroll", JE.bool model.autoscroll ) - ] - |> JE.encode 0 - -decodeModel : Model -> String -> Maybe Model -decodeModel model text = - let - error2maybe err = - case err of - Ok val -> Just val - _ -> Nothing - in - text - |> JD.decodeString modelDecoder - |> error2maybe +-- ############################################################################### +-- Encoders and Decoders +-- ############################################################################### + exampleListDecoder : JD.Decoder (List Example) exampleListDecoder = @@ -572,78 +183,61 @@ exampleListDecoder = <| JD.list <| JD.map4 Example - ( JD.field "title" JD.string ) - ( JD.field "version" JD.string ) - ( JD.field "url" JD.string ) + ( JD.field "title" JD.string ) + ( JD.field "version" JD.string ) + ( JD.field "url" JD.string ) ( JD.field "enabled" (JD.map (\s -> s == 1) JD.int) ) -modelDecoder : JD.Decoder Model -modelDecoder = - let - tuple2Decoder : JD.Decoder a -> JD.Decoder b -> JD.Decoder (a,b) - tuple2Decoder enc1 enc2 = - JD.map2 Tuple.pair - (JD.index 0 enc1) - (JD.index 1 enc2) - in - JD.map3 - (\a b c -> Model a b c [] False Waiting Waiting) - ( JD.field "pc" - ( JD.map7 - PC - (JD.field "ram" <| JD.list <| tuple2Decoder JD.int JD.string) - (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 - <| JD.map (\s -> Maybe.withDefault ActNothing <| string2uAction s ) - <| JD.string - ) - ( JD.field "autoscroll" JD.bool ) - -cmdUpdateLocalStorage : Model -> Cmd Msg -cmdUpdateLocalStorage model = - localStorageSend (encodeModel model) - -cmdSenduUpdate : Model -> Cmd Msg -cmdSenduUpdate model = - Cmd.batch - [ cmdUpdateLocalStorage model - , sendUUpdate "update" +doEncodeModel : Model -> String +doEncodeModel model = + JE.object + [ ( "model-version" , JE.string pcModelVersion ) + , ( "pc_model" , PC.Json.pcModelEncoder model.pc_model ) + , ( "autoscroll" , JE.bool model.autoscroll ) ] + |> JE.encode 0 + +doDecodeModel : String -> Maybe Model +doDecodeModel jText = + let + error2maybe err = + case err of + Ok val -> Just val + _ -> Nothing + in + jText + |> JD.decodeString modelDecoder + |> error2maybe -cmdLoadExamples : Model -> Cmd Msg -cmdLoadExamples model = - Http.get - { url = examplesListUrl - , expect = Http.expectJson MsgExamplesArrived exampleListDecoder - } +modelDecoder : JD.Decoder Model +modelDecoder = + let + mainDecoder : String -> JD.Decoder Model + mainDecoder version = + if (version == pcModelVersion) then + JD.map2 + (\a b -> Model a b [] False Waiting Waiting ) + ( JD.field "pc_model" PC.Json.pcModelDecoder ) + ( JD.field "autoscroll" JD.bool ) + else + JD.fail <| "Outdated version: '" ++ version ++ "'" + in + JD.field "model-version" JD.string + |> JD.andThen mainDecoder + -cmdLoadExampleSing : Model -> Example -> Cmd Msg -cmdLoadExampleSing model example = - Http.get - { url = example.url - , expect = Http.expectJson MsgLoadExampleArrived modelDecoder - } -httpError2String : Http.Error -> String -httpError2String err = - case err of - Http.BadUrl str -> "Bad Url: " ++ str - Http.Timeout -> "Timeout" - Http.NetworkError -> "Network Error" - Http.BadStatus num -> "Bad Status: " ++ String.fromInt num - Http.BadBody str -> "Bad Body: " ++ str +-- ##################################################################### +-- ##################################################################### + + + +-- ##################################################################### -- VIEWERS +-- ##################################################################### view : Model -> Html Msg view model = @@ -655,337 +249,39 @@ viewPC model = div [ class "pc" ] [ div [ class "controls", class "grid-fullwidth" ] - [ button [ onClick MsgUCycleStep ] [ text "µCycle" ] - , button [ onClick MsgInstructionStep ] [ text "Instruction" ] - , button [ onClick MsgReset ] [ text "Reset PC" ] + [ button [ onClick <| Msg_PC PM_B_UCycleStep ] [ text "µCycle" ] + , button [ onClick <| Msg_PC PM_B_InstructionStep ] [ text "Instruction" ] + , button [ onClick <| Msg_PC PM_B_Reset ] [ text "Reset PC" ] , div [ classList [ ("checker", True) , ("button", True) , ("checked", model.autoscroll) ] - , onClick MsgAutoscrollUpdate + , onClick Msg_Autoscroll_Toggle ] [ Html.input [ HAttr.type_ "checkbox" , HAttr.id "enableScrolling" , HAttr.checked model.autoscroll - , onClick MsgAutoscrollUpdate + , onClick Msg_Autoscroll_Toggle ] [] , Html.label [ HAttr.for "enableScrolling" ] [ text "Autoscroll" ] ] - , button [ onClick MsgToggleLoadExample ] [ text "Load Example" ] + , button [ onClick <| Msg_DEsmpl_Open True ] [ text "Load Example" ] ] - , div [ class "grid-fullwidth", class "grid-addressbus" ] [ lazy viewAddressBus model ] - , lazy viewRam model - , lazy viewCu model - , lazy viewAlu model - , div [ class "grid-fullwidth", class "grid-databus" ] [ lazy viewDataBus model ] + , div [class "pc-main"] [ Html.map Msg_PC <| PC.view model.pc_model ] , lazy viewExamples model , lazy viewExamplesLoaderError model ] -viewRam : Model -> Html Msg -viewRam model = - div [ class "section", class "ram" ] - [ h1 [ class "header" ] [ text "RAM" ] - , div [ class "arrow", class "down", class "top"] [ div [] [] , div [] [] ] - , div [ class "scroller" ] - [ Html.table [ class "" ] - [ Html.thead [ class "head" ] - [ Html.tr [] - [ Html.th [ class "address" ] [ text "Addr" ] - , Html.th [] [ text "Value" ] - , Html.th [] [ text "Comment" ] - ] - ] - , lazy viewRamContent model - ] - ] - , div [ class "arrow", class "down"] - [ div [ class "button" ] - [ Html.a [ onClick (MsgManualStep ActRam2DataBus) ] [ text "Ram -> DataBus" ]] - , div [] [] - ] - , div [ class "arrow", class "up"] - [ div [ class "button" ] - [ Html.a [ onClick (MsgManualStep ActDataBus2Ram) ] [ text "DataBus -> Ram" ]] - , div [] [] - ] - ] -viewRamContent : Model -> Html Msg -viewRamContent model = - let - indexedRam = - List.indexedMap Tuple.pair model.pc.ram - - ram2table : ( Int, (Int, String) ) -> Html Msg - ram2table entry = - let - id = - Tuple.first entry - - (val,comment) = - 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 " ] - [ 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" - ] - [] - ] - , Html.td[ class "comment" ] - [ Html.input - [ HAttr.type_ "text" - , HAttr.value comment - , onInput <| MsgRamEditComment id ] - [] - ] - ] - in - Html.tbody [] - ((List.map ram2table indexedRam) - ++ - [ Html.tr [] - [ Html.td [] [] - , Html.td [] - [ button - [ onClick MsgRamAddBelow ] - [ text "Add Entry"] - ] - , Html.td [][] - ] - ] - ) -viewCu : Model -> Html Msg -viewCu model = - let - ( instrRegInst, instrRegAddr ) = seperateInstructionsEntry model.pc.instructionReg - in - div [ class "section", class "cu" ] - [ div [ class "arrow", class "up", class "top"] - [ div [ class "button" ] - [ Html.a [ onClick (MsgManualStep ActInstructionReg2AddressBus)] [ text "InstR -> AddrB" ]] - , div [] [] - ] - , div [ class "arrow", class "up", class "top", class "arrow2"] - [ div [ class "button" ] - [ Html.a [ onClick (MsgManualStep ActProgrammCounter2AddressBus)] [ text "ProgCounter -> AddrB" ]] - , div [] [] - ] - , h1 [ class "header" ] [ text "Control Unit" ] - , p [] - [ div [class "input-row"] - [ Html.label [ HAttr.for "cu-progcounter" ] [ text "Programm Counter:" ] - , button - [ onClick <| MsgManualStep ActInstructionReg2ProgrammCounter ] - [ text "InstRA -> " ] - , Html.input - [ HAttr.type_ "number" - , HAttr.id "cu-progcounter" - , value (addLeadingZero model.pc.programmCounter 3) - , onInput MsgCuProgCounterEdit - ] [] - ] - - , div [class "input-row"] - [ Html.label [ HAttr.for "cu-instrReg" ] [ text "Instruction Register:" ] - , div [] - [ Html.input - [ HAttr.type_ "number" - , HAttr.id "cu-instrReg" - , class "instruction" - , value (addLeadingZero instrRegInst 3) - , onInput MsgCuInstrRegEditInstr - ] [] - , Html.input - [ HAttr.type_ "number" - , HAttr.id "cu-instrReg" - , class "address" - , value (addLeadingZero instrRegAddr 5) - , onInput MsgCuInstrRegEditAddr - ] [] - ] - ] - - , div [class "input-row"] - [ Html.label [ HAttr.for "cu-uCounter" ] [ text "µCode Counter:" ] - , button - [ onClick <| MsgManualStep ActInstructionReg2UCounter - ] - [ text "IntrRI ->" ] - , Html.input - [ HAttr.type_ "number" - , HAttr.id "cu-uCounter" - , value (addLeadingZero model.pc.uCounter 4) - , onInput MsgCuUCounterEdit - ] [] - ] - - ] - , div [ class "scroller" ] - [ viewCuUCode model - ] - , div [ class "arrow", class "up"] - [ div [ class "button" ] - [ Html.a [ onClick (MsgManualStep ActDataBus2InstructionReg) ] [ text "DB -> InstR" ]] - , div [] [] - ] - ] - - -viewCuUCode : Model -> Html Msg -viewCuUCode model = - Html.table [] - [ Html.thead [ class "head" ] - [ Html.tr [] - [ Html.th [ class "address" ] [ text "µCounter" ] - , Html.th [] [ text "µCode" ] - ] - ] - , lazy viewCuUCodeContent model - ] - - -viewCuUCodeContent : Model -> Html Msg -viewCuUCodeContent model = - let - indexedList = - List.indexedMap Tuple.pair model.uCode - - list2table : ( Int, UAction ) -> Html Msg - list2table t = - let - id = - Tuple.first t - - code = - Tuple.second t - in - Html.tr - [ classList [ ( "current", id == model.pc.uCounter ), ("empty", code == ActNothing) ] ] - [ Html.td [ class "num" ] [ text (addLeadingZero id 4) ] - , Html.td [] [ viewCuInstrSelect id code ] - ] - - in - Html.tbody [] - ((List.map list2table indexedList) - ++ - [ Html.tr [] - [ Html.td [] [] - , Html.td [] - [ button - [ onClick MsgCuAddBelow ] - [ text "Add Entry"] - ] - ] - ] - ) - -viewCuInstrSelect : Int -> UAction -> Html Msg -viewCuInstrSelect id current = - let - info2option (action, info) = - Html.option - [ HAttr.selected (action == current) - , HAttr.value (uAction2String action) ] - [ 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 [] - [ Html.label [ HAttr.for "alu-accumulator" ] [ text "Accumulator:" ] - , Html.input - [ HAttr.type_ "number" - , HAttr.id "alu-accumulator" - , value (addLeadingZero model.pc.accumulator 8) - , onInput MsgAluEdit - ] [] - ] - , p [] - [ button [ onClick <| MsgManualStep ActAccumulatorIncrement ] [ text "Acc ++" ] - , button [ onClick <| MsgManualStep ActAccumulatorDecrement ] [ text "Acc --" ] - ] - , div [ class "arrow", class "up"] - [ div [ class "button" ] - [ Html.a [ onClick (MsgManualStep ActDataBus2Accumulator)] [ text "DB -> ALU" ]] - , div [] [] - ] - , div [ class "arrow", class "down"] - [ div [ class "button" ] - [ Html.a [ onClick (MsgManualStep ActAccumulator2DataBus)] [ text "ALU -> DB" ]] - , div [] [] - ] - ] - - -viewDataBus : Model -> Html Msg -viewDataBus model = - div [ class "databus" ] - [ Html.span [ class "label" ] [ text "Databus" ] - , Html.span [] - [ Html.input - [ HAttr.type_ "number" - , value (addLeadingZero model.pc.dataBus 8) - , onInput MsgEditDataBus - ] [] - ] - ] - - -viewAddressBus : Model -> Html Msg -viewAddressBus model = - div [ class "addressbus" ] - [ Html.span [ class "label" ] [ text "Addressbus" ] - , Html.span [] - [ Html.input - [ HAttr.type_ "number" - , value (addLeadingZero model.pc.addressBus 3) - , onInput MsgEditAddressBus - ] [] - ] - ] - - -viewInstrEntry : Int -> Html Msg -viewInstrEntry i = - let - (instruction, address) = seperateInstructionsEntry i - in - text ( (addLeadingZero instruction 3) ++ " " ++ (addLeadingZero address 5) ) viewExamples : Model -> Html Msg @@ -993,7 +289,7 @@ viewExamples model = div [ classList [("modal", True), ("hidden", (not model.exampleChooserOpen))] ] [ div [] [] , div [ class "modal-card" ] - [ Html.a [ class "modal-close", onClick MsgToggleLoadExample ] [] + [ Html.a [ class "modal-close", onClick <| Msg_DEsmpl_Open False ] [] , lazy viewExamplesEntrys model ] ] @@ -1004,7 +300,7 @@ viewExamplesEntrys model = entry2html (id, example) = Html.tr [] [ Html.td [] [ text <| "Example: " ++ example.title ] - , Html.td [] [ button [ onClick <| MsgLoadExample id ] [ text "Laden" ] ] + , Html.td [] [ button [ onClick <| Msg_DEsmpl_EClick id ] [ text "Laden" ] ] ] in case model.examplesListStatus of @@ -1033,229 +329,55 @@ viewExamplesLoaderError model = ] _ -> text "" + -- END VIEWERS --- ACTIONS +-- ##################################################################### +-- ##################################################################### -actRam2DataBus : PC -> PC -actRam2DataBus pc = - let - ab = - pc.addressBus - - db = - Tuple.first <| valueAtRam ab pc.ram - in - { pc | dataBus = db } - - -actDataBus2InstructionReg : PC -> PC -actDataBus2InstructionReg pc = - { pc | instructionReg = pc.dataBus } - - -actResetUCounter : PC -> PC -actResetUCounter pc = - { pc | uCounter = 0 } - - -actInstructionReg2UCounter : PC -> PC -actInstructionReg2UCounter pc = - -- Multiply by ten, because every instruction is 10 uCodes long - let - (instruction, address) = seperateInstructionsEntry pc.instructionReg - in - { pc | uCounter = instruction * 10} - - -actInstructionReg2AddressBus : PC -> PC -actInstructionReg2AddressBus pc = - let - (instruction, address) = seperateInstructionsEntry pc.instructionReg - in - { pc | addressBus = address } - - -actInstructionReg2ProgrammCounter : PC -> PC -actInstructionReg2ProgrammCounter pc = - let - (instruction, address) = seperateInstructionsEntry pc.instructionReg - in - - { pc | programmCounter = address } - - -actProgrammCounterIncrement : PC -> PC -actProgrammCounterIncrement pc = - { pc | programmCounter = pc.programmCounter + 1 } - - -actProgrammCounter2AddressBus : PC -> PC -actProgrammCounter2AddressBus pc = - { pc | addressBus = pc.programmCounter } - -actInstructionReg2ProgrammCounterIfAccEq0 : PC -> PC -actInstructionReg2ProgrammCounterIfAccEq0 pc = - if pc.accumulator == 0 then - let - (_,addr) = seperateInstructionsEntry pc.instructionReg - in - { pc | programmCounter = addr } - else - pc - -actDataBus2Accumulator : PC -> PC -actDataBus2Accumulator pc = - { pc | accumulator = pc.dataBus } - - -actAccumulator2DataBus : PC -> PC -actAccumulator2DataBus pc = - { pc | dataBus = pc.accumulator } - - -actAccumulatorIncrement : PC -> PC -actAccumulatorIncrement pc = - { pc | accumulator = pc.accumulator + 1 } - - -actAccumulatorDecrement : PC -> PC -actAccumulatorDecrement pc = - { pc | accumulator = pc.accumulator - 1 } - - -actDataBus2Ram : PC -> PC -actDataBus2Ram pc = - let - newRam = - changeAtRam pc.addressBus pc.dataBus pc.ram - in - { pc | ram = newRam } - - - --- END ACTIONS +-- ##################################################################### -- HELPERS +-- ##################################################################### + + +--changeAtUCode : Int -> UAction -> List UAction -> List UAction +--changeAtUCode pos newVal list = +-- changeAt pos newVal ActNothing list -valueAtRam : Int -> List (Int, String) -> (Int, String) -valueAtRam n l = - case valueAt n l of - Just a -> - a - - Nothing -> - (0, "") - - -valueAt : Int -> List a -> Maybe a -valueAt n l = - List.head (List.drop n l) - - -changeAtRam : Int -> Int -> List (Int, String) -> List (Int,String) -changeAtRam pos newVal list = - let - (_,comment) = valueAtRam pos list - in - changeAt pos (newVal, comment) (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 - - after = - List.drop (pos + 1) list - - len = - List.length list - in - if pos > len then - let - before2 = - List.append before (List.repeat (pos - len) default) - in - List.append before2 (newVal :: after) - - else - List.append before (newVal :: after) - - -addLeadingZero : Int -> Int -> String -addLeadingZero number length = - let - num_str = String.fromInt number - in - if number < 10 then - (String.fromList (List.repeat (length - 1) '0') ) ++ num_str - else if number < 100 then - (String.fromList (List.repeat (length - 2) '0') ) ++ num_str - else if number < 1000 then - (String.fromList (List.repeat (length - 3) '0') ) ++ num_str - else if number < 10000 then - (String.fromList (List.repeat (length - 4) '0') ) ++ num_str - else if number < 100000 then - (String.fromList (List.repeat (length - 5) '0') ) ++ num_str - else if number < 1000000 then - (String.fromList (List.repeat (length - 6) '0') ) ++ num_str - else if number < 10000000 then - (String.fromList (List.repeat (length - 7) '0') ) ++ num_str - else if number < 100000000 then - (String.fromList (List.repeat (length - 8) '0') ) ++ num_str - 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) uCodeIds - 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) uCodeIds - 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 +-- ##################################################################### subscriptions : Model -> Sub Msg subscriptions model = - localStorageRecieve MsgLocalSessionRecieve + Sub.none + --localStorageRecieve Msg_LocalStorageLoaded + +-- TODO: Make it load localStorage when starting init : () -> ( Model, Cmd Msg ) init flags = - ( Model initialPC initialUCodes True [] False Waiting Waiting, Cmd.none ) + ({ pc_model = PC.init + , autoscroll = True + , examples = [] + , exampleChooserOpen = False + , examplesListStatus = Waiting + , exampleLoaderStatus = Waiting + } + , Cmd.none ) + + --( Model initialPC initialUCodes True [] False Waiting Waiting, Cmd.none ) + main : Program () Model Msg @@ -1266,3 +388,9 @@ main = , update = update , subscriptions = subscriptions } + + +-- ##################################################################### +-- ##################################################################### + +-- Done. \ No newline at end of file diff --git a/src/PC/Defaults.elm b/src/PC/Defaults.elm new file mode 100644 index 0000000..0454a16 --- /dev/null +++ b/src/PC/Defaults.elm @@ -0,0 +1,107 @@ +module PC.Defaults exposing (..) + +import Array exposing (Array) + +import PC.Types exposing (..) +import PC.UActions exposing (..) + + +initalModel : PC_Model +initalModel = + { pc = initialPC + , uCodes = initialUCodes + } + +initialPC : PC +initialPC = + { ram = initialRam + , dataBus = 0 + , addressBus = 0 + , instructionReg = 0 + , programmCounter = 0 + , uCounter = 0 + , accumulator = 0 + } + + +initialRam : Array (Int, String) +initialRam = Array.fromList + [ (100005, "LoadA #005") -- 000 -- LoadA #005 + , (300000, "IncA") -- 001 -- IncA + , (200005, "StoreA #005") -- 002 -- StoreA #005 + , (400000, "JMP #000") -- 003 -- JMP #000 + , (0,"") -- 004 + , (5,"val") -- 005 + , (0, "") -- 006 + , (0, "") -- 007 + , (0, "") -- 008 + , (0, "") -- 009 + , (0, "") -- 010 + ] + + + +initialUCodes : Array UAction +initialUCodes = Array.fromList + [ UA_ProgrammCounter2AddressBus -- 000 + , UA_Ram2DataBus -- 001 + , UA_DataBus2InstructionReg -- 002 + , UA_ProgrammCounterIncrement -- 003 + , UA_InstructionReg2UCounter -- 004 + , UA_Nothing -- 005 + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing -- 009 + + -- 010 LOADA + , UA_InstructionReg2AddressBus -- 010 + , UA_Ram2DataBus -- 011 + , UA_DataBus2Accumulator -- 012 + , UA_ResetUCounter -- 013 + , UA_Nothing -- 014 + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing -- 019 + + -- 020 STOA + , UA_Accumulator2DataBus -- 020 + , UA_InstructionReg2AddressBus -- 021 + , UA_DataBus2Ram -- 022 + , UA_ResetUCounter -- 023 + , UA_Nothing --024 + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing -- 029 + + -- 030 INCA + , UA_AccumulatorIncrement -- 030 + , UA_ResetUCounter -- 031 + , UA_Nothing -- 032 + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing -- 039 + + -- 040 JMP + , UA_InstructionReg2ProgrammCounter -- 040 + , UA_ResetUCounter -- 041 + , UA_Nothing -- 042 + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing + , UA_Nothing -- 049 + ] + + + diff --git a/src/PC/Helpers.elm b/src/PC/Helpers.elm new file mode 100644 index 0000000..c8b01ee --- /dev/null +++ b/src/PC/Helpers.elm @@ -0,0 +1,96 @@ +module PC.Helpers exposing (..) + +import Array exposing (Array) +import Http exposing (..) + +-- Convert a number from 42 to 0042 +-- number : (Prefered positive) whole number +-- length : positive whole number +-- Please note that only 0 are added. The number will not be shortend! +addLeadingZero : Int -> Int -> String +addLeadingZero number length = + let + num_str = String.fromInt number + in + (String.fromList <| List.repeat (length - String.length num_str) '0' + ) + ++ num_str + + +-- Get the value at a given position in a List. +-- For performance reasons it might be better +-- to use an Array instead. +valueAt : Int -> List a -> Maybe a +valueAt pos list = List.head <| List.drop pos list + + +-- Change the value at a given position in a List. +-- If your pos is greater than the length of +-- the list, then the rest is filled with the +-- default element. +overwriteAt : a -> Int -> a ->List a -> List a +overwriteAt default pos newVal list = + let + len = List.length list + in + if pos == 0 then + newVal :: list + else if pos > len then + list ++ + (List.repeat (pos-len) default) ++ + [newVal] + else + let + before = List.take pos list + after = List.drop (pos+1) list + in + before ++ [newVal] ++ after + +overwriteAt_Arr : a -> Int -> a -> Array a -> Array a +overwriteAt_Arr default pos newVal list = + let + len = Array.length list + in + if pos == 0 then + Array.append (Array.fromList [newVal]) list + else if pos > len then + Array.append list + <| Array.append (Array.repeat (pos-len) default) + <| Array.fromList [newVal] + else + Array.set pos newVal list + + +-- Prints Http Errors into something readable +printHttpError : Http.Error -> String +printHttpError err = + case err of + Http.BadUrl str -> "Bad Url: " ++ str + Http.Timeout -> "Timeout" + Http.NetworkError -> "Network Error" + Http.BadStatus num -> "Bad Status: " ++ String.fromInt num + Http.BadBody str -> "Bad Body: " ++ str + + +seperateInstructionsEntry : Int -> (Int, Int) +seperateInstructionsEntry i = + let + instruction = i // 100000 + address = i - instruction*100000 + in + (instruction, address) + + +valueAtRam : Int -> Array (Int, String) -> (Int, String) +valueAtRam pos arr = + case Array.get pos arr of + Just a -> a + Nothing -> (0, "") + + +changeAtRam : Int -> Int -> Array (Int, String) -> Array (Int,String) +changeAtRam pos newVal list = + let + (_,comment) = valueAtRam pos list + in + overwriteAt_Arr (0, "") pos (newVal, comment) list diff --git a/src/PC/JSON.elm b/src/PC/JSON.elm new file mode 100644 index 0000000..c7a2d9e --- /dev/null +++ b/src/PC/JSON.elm @@ -0,0 +1,112 @@ +module PC.Json exposing ( pcModelDecoder + , pcModelEncoder + , tuple2Decoder + , tuple2Encoder + ) + +import PC.Types exposing (..) +import Maybe +import Array exposing (Array) + +import Json.Encode as JE exposing (Value) +import Json.Decode as JD exposing (Decoder) + +import PC.Types exposing (..) +import PC.UActions exposing (..) + + +-- ########################################################## +-- Decoders +-- ########################################################## + +pcModelDecoder : Decoder PC_Model +pcModelDecoder = + JD.map2 + PC_Model + (JD.field "pc" pcDecoder) + (JD.field "uCodes" uCodeDecoder) + + +pcDecoder : Decoder PC +pcDecoder = + JD.map7 + PC + (JD.field "ram" <| JD.array <| tuple2Decoder JD.int JD.string) + (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) + +uCodeDecoder : Decoder (Array UAction) +uCodeDecoder = + JD.array <| JD.map uActionDecoder JD.string + +uActionDecoder : String -> UAction +uActionDecoder str = + Maybe.withDefault UA_Nothing <| string2uAction str + + + +tuple2Decoder : Decoder a -> Decoder b -> Decoder (a,b) +tuple2Decoder enc1 enc2 = + JD.map2 Tuple.pair + (JD.index 0 enc1) + (JD.index 1 enc2) + +-- ########################################################## +-- ########################################################## + + + + + +-- ########################################################## +-- Encoders +-- ########################################################## + +pcModelEncoder : PC_Model -> Value +pcModelEncoder model = + JE.object + [ ( "pc" , pcEncoder model.pc ) + , ( "uCodes" , uCodesEncoder model.uCodes ) + ] + +pcEncoder : PC -> Value +pcEncoder pc = + JE.object + [ ( "addressBus" , JE.int pc.addressBus ) + , ( "dataBus" , JE.int pc.dataBus ) + , ( "instructionReg" , JE.int pc.instructionReg ) + , ( "programmCounter" , JE.int pc.programmCounter ) + , ( "uCounter" , JE.int pc.uCounter ) + , ( "accumulator" , JE.int pc.accumulator ) + , ( "ram" , ramEncoder pc.ram ) + ] + +ramEncoder : Array (Int, String) -> Value +ramEncoder arr = + JE.array + (tuple2Encoder JE.int JE.string) + arr + +uCodesEncoder : Array UAction -> Value +uCodesEncoder uActions = + JE.array encodeSingleuCode uActions + +encodeSingleuCode : UAction -> Value +encodeSingleuCode action = + let + uCode = uAction2UCode action + in + JE.string uCode.id + + +tuple2Encoder : (a -> Value) -> (b -> Value) -> (a,b) -> Value +tuple2Encoder encA encB (valA, valB) = + JE.list identity [ encA valA, encB valB ] + +-- ########################################################## +-- ########################################################## +-- Done. \ No newline at end of file diff --git a/src/PC/PC.elm b/src/PC/PC.elm new file mode 100644 index 0000000..805aeaf --- /dev/null +++ b/src/PC/PC.elm @@ -0,0 +1,28 @@ +module PC.PC exposing (..) + +import Html exposing (Html) +--import Json.Encode as JE +import Json.Decode as JD + +import PC.Types exposing (..) +import PC.Defaults exposing (..) +import PC.Helpers exposing (..) +import PC.Update exposing (..) +import PC.View exposing (..) + + + +update : PC_Msg -> PC_Model -> (PC_Model, PC_AfterUpdateAction) +update = pc_update + + +view : PC_Model -> Html PC_Msg +view = pc_view + +init : PC_Model +init = initalModel + + + + + diff --git a/src/PC/Types.elm b/src/PC/Types.elm new file mode 100644 index 0000000..d2689d7 --- /dev/null +++ b/src/PC/Types.elm @@ -0,0 +1,78 @@ +module PC.Types exposing (..) + +import Array exposing (Array) + +pcModelVersion = "3" + +type alias PC_Model = + { pc : PC + , uCodes : Array UAction + } + +type alias PC = + { ram : Array (Int, String) + , dataBus : Int + , addressBus : Int + , instructionReg : Int + , programmCounter : Int + , uCounter : Int + , accumulator : Int + } + +type alias UCode = + { variant : UAction + , id : String + , action : PC -> PC + , label : String + } + +type UAction + = UA_Accumulator2DataBus + | UA_AccumulatorDecrement + | UA_AccumulatorIncrement + | UA_DataBus2Accumulator + | UA_DataBus2InstructionReg + | UA_DataBus2Ram + | UA_InstructionReg2AddressBus + | UA_InstructionReg2ProgrammCounter + | UA_InstructionReg2UCounter + | UA_ProgrammCounterIncrement + | UA_InstructionReg2ProgrammCounterIfAccEq0 + | UA_Ram2DataBus + | UA_ResetUCounter + | UA_ProgrammCounter2AddressBus + | UA_Nothing + + +-- To make it easier to understand everything has name convention +-- PM_ -> PC_Msg in general +-- PM_B_ -> for a Button +-- PM_C_ -> for a Checkbox +-- PM_F_ -> for a TextField +type PC_Msg + = PM_B_UCycleStep + | PM_B_InstructionStep + | PM_B_Reset + | PM_B_RamAddBelow + | PM_B_CuAddBelow + | PM_F_RamEditInstr Int String + | PM_F_RamEditAddress Int String + | PM_F_RamEditComment Int String + | PM_F_CuEditAction Int String + | PM_F_CuInstrRegEditAddr String + | PM_F_CuInstrRegEditInstr String + | PM_F_CuProgCounterEdit String + | PM_F_CuUCounterEdit String + | PM_F_EditAddressBus String + | PM_F_EditDataBus String + | PM_F_AluEdit String + | PM_ManualStep UAction + + +-- Tells main what is supposed +-- to happen after a update +type PC_AfterUpdateAction + = PUA_Nothing -- Do nothing + | PUA_Storage -- Update localStorage + | PUA_Scroller -- Scroll to value + | PUA_Storage_And_Scroller -- Update localStorage and scroll to values \ No newline at end of file diff --git a/src/PC/UActions.elm b/src/PC/UActions.elm new file mode 100644 index 0000000..e32b7ad --- /dev/null +++ b/src/PC/UActions.elm @@ -0,0 +1,163 @@ +module PC.UActions exposing ( uCodes + , uAction2Label + , string2uAction + , uAction2UCode ) + +import Array exposing (Array) +import Tuple + +import PC.Types exposing (..) +import PC.Helpers exposing (..) + +uCodes : List UCode +uCodes = + [ UCode UA_Accumulator2DataBus "acc2db" actAccumulator2DataBus "Acc -> DataBus" + , UCode UA_AccumulatorDecrement "accDec" actAccumulatorDecrement "Acc --" + , UCode UA_AccumulatorIncrement "accInc" actAccumulatorIncrement "Acc ++" + , UCode UA_DataBus2Accumulator "db2acc" actDataBus2Accumulator "DataBus -> Acc" + , UCode UA_DataBus2InstructionReg "db2ir" actDataBus2InstructionReg "DataBus -> InstReg" + , UCode UA_DataBus2Ram "db2ram" actDataBus2Ram "DataBus -> Ram" + , UCode UA_InstructionReg2AddressBus "ir2ab" actInstructionReg2AddressBus "InstReg -> AddrBus" + , UCode UA_InstructionReg2ProgrammCounter "ir2pc" actInstructionReg2ProgrammCounter "InstReg -> ProgCount" + , UCode UA_InstructionReg2UCounter "ir2uc" actInstructionReg2UCounter "InstReg -> µCounter" + , UCode UA_ProgrammCounterIncrement "pcInc" actProgrammCounterIncrement "ProgCounter ++" + , UCode UA_Ram2DataBus "ram2db" actRam2DataBus "Ram -> DataBus" + , UCode UA_ResetUCounter "ucReset" actResetUCounter "µCounter = 0" + , UCode UA_ProgrammCounter2AddressBus "pc2ab" actProgrammCounter2AddressBus "ProgCounter -> AddrBus" + , UCode UA_Nothing "n" (\s -> s) "Empty" + , UCode UA_InstructionReg2ProgrammCounterIfAccEq0 + "ir2pciacceq0" actInstructionReg2ProgrammCounterIfAccEq0 "Acc == 0 => InstReg -> ProgCounter" + ] + + +-- ####################################################################################### +-- ACTIONS +-- ####################################################################################### + +actRam2DataBus : PC -> PC +actRam2DataBus pc = + let + ab = + pc.addressBus + + db = + Tuple.first <| valueAtRam ab pc.ram + in + { pc | dataBus = db } + + +actDataBus2InstructionReg : PC -> PC +actDataBus2InstructionReg pc = + { pc | instructionReg = pc.dataBus } + + +actResetUCounter : PC -> PC +actResetUCounter pc = + { pc | uCounter = 0 } + + +actInstructionReg2UCounter : PC -> PC +actInstructionReg2UCounter pc = + -- Multiply by ten, because every instruction is 10 uCodes long + let + (instruction, address) = seperateInstructionsEntry pc.instructionReg + in + { pc | uCounter = instruction * 10} + + +actInstructionReg2AddressBus : PC -> PC +actInstructionReg2AddressBus pc = + let + (instruction, address) = seperateInstructionsEntry pc.instructionReg + in + { pc | addressBus = address } + + +actInstructionReg2ProgrammCounter : PC -> PC +actInstructionReg2ProgrammCounter pc = + let + (instruction, address) = seperateInstructionsEntry pc.instructionReg + in + + { pc | programmCounter = address } + + +actProgrammCounterIncrement : PC -> PC +actProgrammCounterIncrement pc = + { pc | programmCounter = pc.programmCounter + 1 } + + +actProgrammCounter2AddressBus : PC -> PC +actProgrammCounter2AddressBus pc = + { pc | addressBus = pc.programmCounter } + +actInstructionReg2ProgrammCounterIfAccEq0 : PC -> PC +actInstructionReg2ProgrammCounterIfAccEq0 pc = + if pc.accumulator == 0 then + let + (_,addr) = seperateInstructionsEntry pc.instructionReg + in + { pc | programmCounter = addr } + else + pc + +actDataBus2Accumulator : PC -> PC +actDataBus2Accumulator pc = + { pc | accumulator = pc.dataBus } + + +actAccumulator2DataBus : PC -> PC +actAccumulator2DataBus pc = + { pc | dataBus = pc.accumulator } + + +actAccumulatorIncrement : PC -> PC +actAccumulatorIncrement pc = + { pc | accumulator = pc.accumulator + 1 } + + +actAccumulatorDecrement : PC -> PC +actAccumulatorDecrement pc = + { pc | accumulator = pc.accumulator - 1 } + + +actDataBus2Ram : PC -> PC +actDataBus2Ram pc = + let + newRam = + changeAtRam pc.addressBus pc.dataBus pc.ram + in + { pc | ram = newRam } + + +-- ################################################################# +-- Helpers +-- ################################################################# + +uAction2Label : UAction -> String +uAction2Label variant = + let + filtered_list = List.filter (\u -> u.variant == variant ) uCodes + in + case List.head filtered_list of + Just uCode -> uCode.label + Nothing -> "IDK" + +uAction2UCode : UAction -> UCode +uAction2UCode variant = + let + filtered_list = List.filter (\u -> u.variant == variant ) uCodes + in + case List.head filtered_list of + Just uCode -> uCode + Nothing -> UCode UA_Nothing "n" (\s -> s) "Empty" + +string2uAction : String -> Maybe UAction +string2uAction str = + let + filtered_list = List.filter (\u -> u.id == str) uCodes + in + case List.head filtered_list of + Just uCode -> Just uCode.variant + _ -> Nothing + diff --git a/src/PC/Update.elm b/src/PC/Update.elm new file mode 100644 index 0000000..283e4ad --- /dev/null +++ b/src/PC/Update.elm @@ -0,0 +1,246 @@ +module PC.Update exposing (pc_update) + +import Array exposing (Array) + +import PC.Types exposing (..) +import PC.UActions exposing (..) +import PC.Defaults exposing (..) +import PC.Helpers exposing (..) + + +pc_update : PC_Msg -> PC_Model -> (PC_Model, PC_AfterUpdateAction) +pc_update msg model = + case msg of + PM_B_UCycleStep -> + ( uStepPC model + , if model.pc.uCounter == 0 then PUA_Storage_And_Scroller + else PUA_Scroller + ) + + PM_B_InstructionStep -> + ( executeInstruction model + , PUA_Storage_And_Scroller ) + + + PM_B_Reset -> + ( { model | pc = { initialPC | ram = model.pc.ram } } + , PUA_Storage_And_Scroller ) + + PM_B_RamAddBelow -> + let + old_pc = model.pc + new_pc = {old_pc | ram = Array.append old_pc.ram <| Array.fromList [(0, "")]} + in + ({model | pc = new_pc} + , PUA_Storage) + + PM_B_CuAddBelow -> + ({model | uCodes = Array.append model.uCodes <| Array.repeat 10 UA_Nothing} + , PUA_Storage) + + PM_F_RamEditAddress addr may_int -> + case String.toInt may_int of + Just int -> + let + (inst,_) = seperateInstructionsEntry ( Tuple.first <| valueAtRam addr model.pc.ram ) + new_val = inst * 100000 + int + old_pc = model.pc + new_pc = { old_pc | ram = (changeAtRam addr new_val old_pc.ram) } + in + ({ model | pc = new_pc }, PUA_Storage) + _ -> (model, PUA_Nothing) + + PM_F_RamEditInstr addr may_int -> + case String.toInt may_int of + Just int -> + let + (_,address) = seperateInstructionsEntry ( Tuple.first <| valueAtRam addr model.pc.ram ) + new_val = int * 100000 + address + old_pc = model.pc + new_pc = { old_pc | ram = (changeAtRam addr new_val old_pc.ram) } + in + ({ model | pc = new_pc }, PUA_Storage) + _ -> ( model, PUA_Nothing ) + + + PM_F_RamEditComment addr str -> + let + (val, _) = valueAtRam addr model.pc.ram + old_pc = model.pc + new_pc = { old_pc | ram = overwriteAt_Arr (0,"") addr (val, str) old_pc.ram } + in + ({ model | pc = new_pc }, PUA_Storage) + + PM_F_CuEditAction addr may_action -> + case string2uAction may_action of + Just action -> + let + newCode = Array.set addr action model.uCodes + in + ({ model | uCodes = newCode }, PUA_Storage) + _ -> ( model, PUA_Nothing ) + + + PM_F_CuInstrRegEditAddr text -> + case String.toInt text of + Just int -> + let old_pc = model.pc + (instr,_) = seperateInstructionsEntry old_pc.instructionReg + new_pc = { old_pc | instructionReg = instr * 100000 + int } + in + ({ model | pc = new_pc }, PUA_Storage) + _ -> ( model, PUA_Nothing ) + + PM_F_CuInstrRegEditInstr text -> + case String.toInt text of + Just int -> + let old_pc = model.pc + (_,addr) = seperateInstructionsEntry old_pc.instructionReg + new_pc = { old_pc | instructionReg = int * 100000 + addr } + in + ({ model | pc = new_pc }, PUA_Storage) + _ -> ( model, PUA_Nothing ) + + PM_F_CuProgCounterEdit text -> + case String.toInt text of + Just int -> + let old_pc = model.pc + new_pc = { old_pc | programmCounter = int } + in + ({ model | pc = new_pc }, PUA_Storage) + _ -> ( model, PUA_Nothing ) + + PM_F_CuUCounterEdit text -> + case String.toInt text of + Just int -> + let old_pc = model.pc + new_pc = { old_pc | uCounter = int } + in + ( { model | pc = new_pc }, PUA_Storage_And_Scroller ) + _ -> ( model, PUA_Nothing ) + + PM_F_EditAddressBus text -> + case String.toInt text of + Just int -> + let old_pc = model.pc + new_pc = { old_pc | addressBus = int } + in + ( { model | pc = new_pc }, PUA_Storage_And_Scroller ) + _ -> ( model, PUA_Nothing ) + + PM_F_EditDataBus text -> + case String.toInt text of + Just int -> + let old_pc = model.pc + new_pc = { old_pc | dataBus = int } + in + ({ model | pc = new_pc }, PUA_Storage) + _ -> ( model, PUA_Nothing ) + + PM_F_AluEdit text -> + case String.toInt text of + Just int -> + let old_pc = model.pc + new_pc = { old_pc | accumulator = int } + in + ({ model | pc = new_pc }, PUA_Storage) + _ -> ( model, PUA_Nothing ) + + + PM_ManualStep action -> + let + instruction = getAction action + new_model = { model | pc = instruction model.pc } + in + ( new_model, PUA_Storage_And_Scroller ) + +-- ############################################################################### +-- ############################################################################### + + + +-- ############################################################################### +-- Update Helpers +-- ############################################################################### + +-- Practically a part of uStepPC but sepeated for manual mode +getAction : UAction -> (PC -> PC) +getAction uAction = + let + possible_instructions = + List.filter (\u -> u.variant == uAction) uCodes + in + case List.head possible_instructions of + Just uCode -> + uCode.action + _ -> + (\s -> s) + + +uStepPC : PC_Model -> PC_Model +uStepPC model = + let + uCounter = + model.pc.uCounter + + may_code : Maybe UAction + may_code = Array.get uCounter model.uCodes + --valueAt uCounter model.uCodes + in + case may_code of + Just code -> + let + -- code :: UAction + old_pc = model.pc + temp_pc = { old_pc | uCounter = uCounter + 1 } + + uCode = uAction2UCode code + f = uCode.action + new_pc = f temp_pc + in + { model | pc = new_pc } + + + --let + -- possible_instructions = + -- List.filter (\s -> Tuple.first s == action) uCodeMaps + --in + --case List.head possible_instructions of + -- Just ( name, instruction ) -> + -- let + -- old_pc = + -- model.pc + + -- new_pc = + -- { old_pc | uCounter = old_pc.uCounter + 1 } + -- in + -- { model | pc = instruction new_pc } + + -- _ -> + -- let + -- old_pc = + -- model.pc + + -- new_pc = + -- { old_pc | uCounter = 0 } + -- in + -- { model | pc = new_pc } + + _ -> + model + + +executeInstruction : PC_Model -> PC_Model +executeInstruction model = + let + new_model = uStepPC model + in + if new_model.pc.uCounter == 0 then + uStepPC new_model + else + executeInstruction new_model + + +-- ############################################################################### +-- ############################################################################### +-- Done. diff --git a/src/PC/View.elm b/src/PC/View.elm new file mode 100644 index 0000000..bb39a9e --- /dev/null +++ b/src/PC/View.elm @@ -0,0 +1,381 @@ +module PC.View exposing (pc_view) + +import Html exposing (Html, button, div, h1, p, text) +import Html.Attributes as HAttr exposing (class, classList, value) +import Html.Events as HEvent exposing (onClick, onInput) +import Html.Lazy exposing (lazy) +import Array exposing (Array) +import Json.Decode as JD + +import PC.Types exposing (..) +import PC.UActions exposing (..) +import PC.Helpers exposing (..) + +pc_view : PC_Model -> Html PC_Msg +pc_view model = div [] + [ div + [ class "grid-fullwidth", class "grid-addressbus" ] + [ lazy viewAddressBus model ] + , lazy viewRam model + , lazy viewCu model + , lazy viewAlu model + , div + [ class "grid-fullwidth", class "grid-databus" ] + [ lazy viewDataBus model ] + ] + +-- ##################################################################### +-- ##################################################################### + + + +-- ##################################################################### +-- RAM +-- ##################################################################### + +viewRam : PC_Model -> Html PC_Msg +viewRam model = + div [ class "section", class "ram" ] + [ h1 [ class "header" ] [ text "RAM" ] + , div [ class "arrow", class "down", class "top"] [ div [] [] , div [] [] ] + , div [ class "scroller" ] + [ Html.table [ class "" ] + [ Html.thead [ class "head" ] + [ Html.tr [] + [ Html.th [ class "address" ] [ text "Addr" ] + , Html.th [] [ text "Value" ] + , Html.th [] [ text "Comment" ] + ] + ] + , lazy viewRamContent model + ] + ] + , drawArrow Bottom Down UA_Ram2DataBus "Ram -> DataBus" + , drawArrow Bottom Up UA_DataBus2Ram "DataBus -> Ram" + ] + + +viewRamContent : PC_Model -> Html PC_Msg +viewRamContent model = + let + --indexedRam = + -- List.indexedMap Tuple.pair <| Array.toList model.pc.ram + + ram2table : Int -> (Int, String) -> Html PC_Msg + ram2table id entry = + let + (val,comment) = 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 " ] + [ Html.input + [ HAttr.type_ "number" + , HAttr.value <| addLeadingZero instruction 3 + , onInput <| PM_F_RamEditInstr id + , class "ram-entry" + , class "instruction" + ] + [] + , Html.input + [ HAttr.type_ "number" + , HAttr.value <| addLeadingZero address 5 + , onInput <| PM_F_RamEditAddress id + , class "ram-entry" + , class "address" + ] + [] + ] + , Html.td[ class "comment" ] + [ Html.input + [ HAttr.type_ "text" + , HAttr.value comment + , onInput <| PM_F_RamEditComment id ] + [] + ] + ] + in + Html.tbody [] + ((Array.toList <| Array.indexedMap ram2table model.pc.ram) + ++ + [ Html.tr [] + [ Html.td [] [] + , Html.td [] + [ button + [ onClick PM_B_RamAddBelow ] + [ text "Add Entry"] + ] + , Html.td [][] + ] + ] + ) + +-- ##################################################################### +-- ##################################################################### + + + + +-- ##################################################################### +-- Control Unit +-- ##################################################################### + +viewCu : PC_Model -> Html PC_Msg +viewCu model = + let + ( instrRegInst, instrRegAddr ) = seperateInstructionsEntry model.pc.instructionReg + in + div [ class "section", class "cu" ] + [ drawArrow Top Up UA_InstructionReg2AddressBus "InstR -> AddrB" + , drawArrow Top Up UA_ProgrammCounter2AddressBus "ProgCounter -> AddrB" + --, div [ class "arrow", class "up", class "top"] + -- [ div [ class "button" ] + -- [ Html.a [ onClick (PM_ManualStep ActInstructionReg2AddressBus)] [ text "InstR -> AddrB" ]] + -- , div [] [] + -- ] + --, div [ class "arrow", class "up", class "top", class "arrow2"] + -- [ div [ class "button" ] + -- [ Html.a [ onClick (PM_ManualStep ActProgrammCounter2AddressBus)] [ text "ProgCounter -> AddrB" ]] + -- , div [] [] + -- ] + + + , h1 [ class "header" ] [ text "Control Unit" ] + , p [] + [ div [class "input-row"] + [ Html.label [ HAttr.for "cu-progcounter" ] [ text "Programm Counter:" ] + , button + [ onClick <| PM_ManualStep UA_InstructionReg2ProgrammCounter ] + [ text "InstRA -> " ] + , Html.input + [ HAttr.type_ "number" + , HAttr.id "cu-progcounter" + , value (addLeadingZero model.pc.programmCounter 3) + , onInput PM_F_CuProgCounterEdit + ] [] + ] + + , div [class "input-row"] + [ Html.label [ HAttr.for "cu-instrReg" ] [ text "Instruction Register:" ] + , div [] + [ Html.input + [ HAttr.type_ "number" + , HAttr.id "cu-instrReg" + , class "instruction" + , value (addLeadingZero instrRegInst 3) + , onInput PM_F_CuInstrRegEditInstr + ] [] + , Html.input + [ HAttr.type_ "number" + , HAttr.id "cu-instrReg" + , class "address" + , value (addLeadingZero instrRegAddr 5) + , onInput PM_F_CuInstrRegEditAddr + ] [] + ] + ] + + , div [class "input-row"] + [ Html.label [ HAttr.for "cu-uCounter" ] [ text "µCode Counter:" ] + , button + [ onClick <| PM_ManualStep UA_InstructionReg2UCounter + ] + [ text "IntrRI ->" ] + , Html.input + [ HAttr.type_ "number" + , HAttr.id "cu-uCounter" + , value (addLeadingZero model.pc.uCounter 4) + , onInput PM_F_CuUCounterEdit + ] [] + ] + + ] + , div [ class "scroller" ] + [ viewCuUCode model + ] + --, div [ class "arrow", class "up"] + -- [ div [ class "button" ] + -- [ Html.a [ onClick (MsgManualStep ActDataBus2InstructionReg) ] [ text "DB -> InstR" ]] + -- , div [] [] + -- ] + , drawArrow Bottom Up UA_DataBus2InstructionReg "DB -> InstR" + ] + + +viewCuUCode : PC_Model -> Html PC_Msg +viewCuUCode model = + Html.table [] + [ Html.thead [ class "head" ] + [ Html.tr [] + [ Html.th [ class "address" ] [ text "µCounter" ] + , Html.th [] [ text "µCode" ] + ] + ] + , lazy viewCuUCodeContent model + ] + + +viewCuUCodeContent : PC_Model -> Html PC_Msg +viewCuUCodeContent model = + let + list2table : Int -> UAction -> Html PC_Msg + list2table id code = + Html.tr + [ classList [ ( "current", id == model.pc.uCounter ), ("empty", code == UA_Nothing) ] ] + [ Html.td [ class "num" ] [ text (addLeadingZero id 4) ] + , Html.td [] [ viewCuInstrSelect id code ] + ] + + in + Html.tbody [] + ((Array.toList <| Array.indexedMap list2table model.uCodes) + ++ + [ Html.tr [] + [ Html.td [] [] + , Html.td [] + [ button + [ onClick PM_B_CuAddBelow ] + [ text "Add Entry"] + ] + ] + ] + ) + +viewCuInstrSelect : Int -> UAction -> Html PC_Msg +viewCuInstrSelect id current = + let + info2option uCode = + Html.option + [ HAttr.selected (uCode.variant == current) + , HAttr.value uCode.id ] + [ text uCode.label ] + listOptions = List.map info2option uCodes + in + Html.select + [ HEvent.on "change" ( JD.map (PM_F_CuEditAction id) selectCuValueDecoder) ] + listOptions + +viewInstrEntry : Int -> Html PC_Msg +viewInstrEntry i = + let + (instruction, address) = seperateInstructionsEntry i + in + text ( (addLeadingZero instruction 3) ++ " " ++ (addLeadingZero address 5) ) + +-- ##################################################################### +-- ##################################################################### + + + + +-- ##################################################################### +-- ALU +-- ##################################################################### + + +viewAlu : PC_Model -> Html PC_Msg +viewAlu model = + div [ class "section", class "alu" ] + [ h1 [ class "header" ] [ text "ALU" ] + , p [] + [ Html.label [ HAttr.for "alu-accumulator" ] [ text "Accumulator:" ] + , Html.input + [ HAttr.type_ "number" + , HAttr.id "alu-accumulator" + , value (addLeadingZero model.pc.accumulator 8) + , onInput PM_F_AluEdit + ] [] + ] + , p [] + [ button [ onClick <| PM_ManualStep UA_AccumulatorIncrement ] [ text "Acc ++" ] + , button [ onClick <| PM_ManualStep UA_AccumulatorDecrement ] [ text "Acc --" ] + ] + , drawArrow Bottom Up UA_DataBus2Accumulator "DB -> ALU" + , drawArrow Bottom Down UA_Accumulator2DataBus "ALU -> DB" + --, div [ class "arrow", class "up"] + -- [ div [ class "button" ] + -- [ Html.a [ onClick (MsgManualStep ActDataBus2Accumulator)] [ text "DB -> ALU" ]] + -- , div [] [] + -- ] + --, div [ class "arrow", class "down"] + -- [ div [ class "button" ] + -- [ Html.a [ onClick (MsgManualStep ActAccumulator2DataBus)] [ text "ALU -> DB" ]] + -- , div [] [] + -- ] + ] + +-- ##################################################################### +-- Busses +-- ##################################################################### + +viewDataBus : PC_Model -> Html PC_Msg +viewDataBus model = + div [ class "databus" ] + [ Html.span [ class "label" ] [ text "Databus" ] + , Html.span [] + [ Html.input + [ HAttr.type_ "number" + , value (addLeadingZero model.pc.dataBus 8) + , onInput PM_F_EditDataBus + ] [] + ] + ] + + +viewAddressBus : PC_Model -> Html PC_Msg +viewAddressBus model = + div [ class "addressbus" ] + [ Html.span [ class "label" ] [ text "Addressbus" ] + , Html.span [] + [ Html.input + [ HAttr.type_ "number" + , value (addLeadingZero model.pc.addressBus 3) + , onInput PM_F_EditAddressBus + ] [] + ] + ] + + +-- ##################################################################### +-- ##################################################################### + + + +-- ##################################################################### +-- Helpers +-- ##################################################################### + +type Arrow_Pos = Top | Bottom +type Arrow_Dir = Up | Down + +drawArrow : Arrow_Pos -> Arrow_Dir -> UAction -> String -> Html PC_Msg +drawArrow pos dir act str = + div + [ HAttr.classList + [ ("arrow", True) + , ("top", pos == Top) + , ("up", dir == Up) + , ("down", dir == Down)] + ] + [ div [ class "button" ] + [ Html.a + [ onClick (PM_ManualStep act) ] + [ text str ] + ] + , div [] [] + ] + + +selectCuValueDecoder : JD.Decoder String +selectCuValueDecoder = + JD.field "target" ( JD.field "value" JD.string) + + +-- ##################################################################### +-- ##################################################################### +-- Done. + +