Implemented user alert for at the end of the program
This commit is contained in:
parent
227644ed91
commit
25c5df9e6d
@ -1 +1 @@
|
|||||||
{"model-version":"3","pc_model":{"pc":{"addressBus":0,"dataBus":0,"instructionReg":0,"programmCounter":0,"uCounter":0,"accumulator":0,"ram":[[100013,"Load ValB to Acc"],[300000,"Acc ++"],[200013,"Store Acc to ValB"],[100012,"Load ValA"],[400000,"Acc --"],[200012,"Store Acc to ValA"],[600008,"Jmp If eq 0"],[500000,"Jmp #000"],[0,"END OF PROGRAM"],[0,""],[0,""],[0,""],[7,"ValA"],[14,"ValB + Result"],[0,""],[0,""],[0,""]]},"uCodes":["pc2ab","ram2db","db2ir","pcInc","ir2uc","n","n","n","n","n","ir2ab","ram2db","db2acc","ucReset","n","n","n","n","n","n","acc2db","ir2ab","db2ram","ucReset","n","n","n","n","n","n","accInc","ucReset","n","n","n","n","n","n","n","n","accDec","ucReset","n","n","n","n","n","n","n","n","ir2pc","ucReset","n","n","n","n","n","n","n","n","ir2pciacceq0","ucReset","n","n","n","n","n","n","n","n"]},"autoscroll":true}
|
{"model-version":"3","pc_model":{"pc":{"addressBus":0,"dataBus":0,"instructionReg":0,"programmCounter":0,"uCounter":0,"accumulator":0,"ram":[[100013,"Load ValB to Acc"],[300000,"Acc ++"],[200013,"Store Acc to ValB"],[100012,"Load ValA"],[400000,"Acc --"],[200012,"Store Acc to ValA"],[700008,"Jmp If eq 0"],[600000,"Jmp #000"],[500000,"END OF PROGRAM"],[0,""],[0,""],[0,""],[4,"ValA"],[17,"ValB + Result"],[0,""],[0,""],[0,""]]},"uCodes":["pc2ab","ram2db","db2ir","pcInc","ir2uc","n","n","n","n","n","ir2ab","ram2db","db2acc","ucReset","n","n","n","n","n","n","acc2db","ir2ab","db2ram","ucReset","n","n","n","n","n","n","accInc","ucReset","n","n","n","n","n","n","n","n","accDec","ucReset","n","n","n","n","n","n","n","n","alert","ucReset","n","n","n","n","n","n","n","n","ir2pc","ucReset","n","n","n","n","n","n","n","n","ir2pciacceq0","ucReset","n","n","n","n","n","n","n","n"]},"autoscroll":true}
|
33
src/Main.elm
33
src/Main.elm
@ -51,6 +51,7 @@ type alias Model =
|
|||||||
, examplesListStatus : LoaderState
|
, examplesListStatus : LoaderState
|
||||||
, exampleLoaderStatus : LoaderState
|
, exampleLoaderStatus : LoaderState
|
||||||
, dragDrop : DragDrop
|
, dragDrop : DragDrop
|
||||||
|
, showAlert : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type alias Example =
|
type alias Example =
|
||||||
@ -89,6 +90,7 @@ type Msg
|
|||||||
| Msg_DrgDrp_Hover Bool
|
| Msg_DrgDrp_Hover Bool
|
||||||
| Msg_DrgDrp_GotFiles File (List File)
|
| Msg_DrgDrp_GotFiles File (List File)
|
||||||
| Msg_DrgDrp_DecodedFiles String
|
| Msg_DrgDrp_DecodedFiles String
|
||||||
|
| Msg_Alert_Hide
|
||||||
| Msg_Nothing
|
| Msg_Nothing
|
||||||
|
|
||||||
|
|
||||||
@ -117,6 +119,10 @@ update msg model =
|
|||||||
( new_model
|
( new_model
|
||||||
, cmd_up_lStorage_n_Scroller new_model
|
, cmd_up_lStorage_n_Scroller new_model
|
||||||
)
|
)
|
||||||
|
PUA_Alert ->
|
||||||
|
( { new_model | showAlert = True }
|
||||||
|
, cmd_up_lStorage new_model
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
Msg_Autoscroll_Toggle -> -- User toggled automatic scrolling checkbox
|
Msg_Autoscroll_Toggle -> -- User toggled automatic scrolling checkbox
|
||||||
@ -257,6 +263,10 @@ update msg model =
|
|||||||
, sendProcessing "Done"
|
, sendProcessing "Done"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Msg_Alert_Hide ->
|
||||||
|
( {model | showAlert = False}
|
||||||
|
, Cmd.none)
|
||||||
|
|
||||||
Msg_Nothing -> (model, Cmd.none)
|
Msg_Nothing -> (model, Cmd.none)
|
||||||
|
|
||||||
|
|
||||||
@ -328,7 +338,7 @@ modelDecoder =
|
|||||||
mainDecoder version =
|
mainDecoder version =
|
||||||
if (version == pcModelVersion) then
|
if (version == pcModelVersion) then
|
||||||
JD.map2
|
JD.map2
|
||||||
(\a b -> Model a b [] False Waiting Waiting initDragDrop )
|
(\a b -> Model a b [] False Waiting Waiting initDragDrop False )
|
||||||
( JD.field "pc_model" PC.Json.pcModelDecoder )
|
( JD.field "pc_model" PC.Json.pcModelDecoder )
|
||||||
( JD.field "autoscroll" JD.bool )
|
( JD.field "autoscroll" JD.bool )
|
||||||
else
|
else
|
||||||
@ -356,6 +366,7 @@ view model =
|
|||||||
div []
|
div []
|
||||||
[ lazy viewPC model
|
[ lazy viewPC model
|
||||||
, viewDragDrop model
|
, viewDragDrop model
|
||||||
|
, viewAlert model
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -478,6 +489,24 @@ viewDragDrop model =
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
viewAlert : Model -> Html Msg
|
||||||
|
viewAlert model =
|
||||||
|
div
|
||||||
|
[ classList
|
||||||
|
[("modal", True)
|
||||||
|
, ("hidden", not model.showAlert)]
|
||||||
|
]
|
||||||
|
[ div [] []
|
||||||
|
, div [ class "modal-card" ]
|
||||||
|
[ p []
|
||||||
|
[ text "End of Program reached" ]
|
||||||
|
, button
|
||||||
|
[ onClick Msg_Alert_Hide ]
|
||||||
|
[ text "Ok" ]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
dragDropAttributes : List (Attribute Msg)
|
dragDropAttributes : List (Attribute Msg)
|
||||||
dragDropAttributes =
|
dragDropAttributes =
|
||||||
[ hiJackOn "dragenter" <| JD.succeed <| Msg_DrgDrp_Hover True
|
[ hiJackOn "dragenter" <| JD.succeed <| Msg_DrgDrp_Hover True
|
||||||
@ -540,6 +569,7 @@ init mayLocalStorage =
|
|||||||
, examplesListStatus = Waiting
|
, examplesListStatus = Waiting
|
||||||
, exampleLoaderStatus = Waiting
|
, exampleLoaderStatus = Waiting
|
||||||
, dragDrop = initDragDrop
|
, dragDrop = initDragDrop
|
||||||
|
, showAlert = False
|
||||||
}
|
}
|
||||||
, Cmd.none )
|
, Cmd.none )
|
||||||
Nothing ->
|
Nothing ->
|
||||||
@ -550,6 +580,7 @@ init mayLocalStorage =
|
|||||||
, examplesListStatus = Waiting
|
, examplesListStatus = Waiting
|
||||||
, exampleLoaderStatus = Waiting
|
, exampleLoaderStatus = Waiting
|
||||||
, dragDrop = initDragDrop
|
, dragDrop = initDragDrop
|
||||||
|
, showAlert = False
|
||||||
}
|
}
|
||||||
, Cmd.none )
|
, Cmd.none )
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ type UAction
|
|||||||
| UA_Ram2DataBus
|
| UA_Ram2DataBus
|
||||||
| UA_ResetUCounter
|
| UA_ResetUCounter
|
||||||
| UA_ProgrammCounter2AddressBus
|
| UA_ProgrammCounter2AddressBus
|
||||||
|
| UA_AlertUser
|
||||||
| UA_Nothing
|
| UA_Nothing
|
||||||
|
|
||||||
|
|
||||||
@ -73,6 +74,7 @@ type PC_Msg
|
|||||||
-- to happen after a update
|
-- to happen after a update
|
||||||
type PC_AfterUpdateAction
|
type PC_AfterUpdateAction
|
||||||
= PUA_Nothing -- Do nothing
|
= PUA_Nothing -- Do nothing
|
||||||
|
| PUA_Alert -- Alert the user
|
||||||
| PUA_Storage -- Update localStorage
|
| PUA_Storage -- Update localStorage
|
||||||
| PUA_Scroller -- Scroll to value
|
| PUA_Scroller -- Scroll to value
|
||||||
| PUA_Storage_And_Scroller -- Update localStorage and scroll to values
|
| PUA_Storage_And_Scroller -- Update localStorage and scroll to values
|
@ -11,7 +11,8 @@ import PC.Helpers exposing (..)
|
|||||||
|
|
||||||
uCodes : List UCode
|
uCodes : List UCode
|
||||||
uCodes =
|
uCodes =
|
||||||
[ UCode UA_Accumulator2DataBus "acc2db" actAccumulator2DataBus "Acc -> DataBus"
|
[ UCode UA_Nothing "n" (\s -> s) "Empty"
|
||||||
|
, UCode UA_Accumulator2DataBus "acc2db" actAccumulator2DataBus "Acc -> DataBus"
|
||||||
, UCode UA_AccumulatorDecrement "accDec" actAccumulatorDecrement "Acc --"
|
, UCode UA_AccumulatorDecrement "accDec" actAccumulatorDecrement "Acc --"
|
||||||
, UCode UA_AccumulatorIncrement "accInc" actAccumulatorIncrement "Acc ++"
|
, UCode UA_AccumulatorIncrement "accInc" actAccumulatorIncrement "Acc ++"
|
||||||
, UCode UA_DataBus2Accumulator "db2acc" actDataBus2Accumulator "DataBus -> Acc"
|
, UCode UA_DataBus2Accumulator "db2acc" actDataBus2Accumulator "DataBus -> Acc"
|
||||||
@ -24,9 +25,9 @@ uCodes =
|
|||||||
, UCode UA_Ram2DataBus "ram2db" actRam2DataBus "Ram -> DataBus"
|
, UCode UA_Ram2DataBus "ram2db" actRam2DataBus "Ram -> DataBus"
|
||||||
, UCode UA_ResetUCounter "ucReset" actResetUCounter "µCounter = 0"
|
, UCode UA_ResetUCounter "ucReset" actResetUCounter "µCounter = 0"
|
||||||
, UCode UA_ProgrammCounter2AddressBus "pc2ab" actProgrammCounter2AddressBus "ProgCounter -> AddrBus"
|
, UCode UA_ProgrammCounter2AddressBus "pc2ab" actProgrammCounter2AddressBus "ProgCounter -> AddrBus"
|
||||||
, UCode UA_Nothing "n" (\s -> s) "Empty"
|
|
||||||
, UCode UA_InstructionReg2ProgrammCounterIfAccEq0
|
, UCode UA_InstructionReg2ProgrammCounterIfAccEq0
|
||||||
"ir2pciacceq0" actInstructionReg2ProgrammCounterIfAccEq0 "Acc == 0 => InstReg -> ProgCounter"
|
"ir2pciacceq0" actInstructionReg2ProgrammCounterIfAccEq0 "Acc == 0 => InstReg -> ProgCounter"
|
||||||
|
, UCode UA_AlertUser "alert" actDoAlert "Signal End of Programm"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -129,6 +130,9 @@ actDataBus2Ram pc =
|
|||||||
in
|
in
|
||||||
{ pc | ram = newRam }
|
{ pc | ram = newRam }
|
||||||
|
|
||||||
|
actDoAlert : PC -> PC
|
||||||
|
actDoAlert pc = pc -- This gets caputred by update anyway
|
||||||
|
|
||||||
|
|
||||||
-- #################################################################
|
-- #################################################################
|
||||||
-- Helpers
|
-- Helpers
|
||||||
|
@ -12,14 +12,21 @@ pc_update : PC_Msg -> PC_Model -> (PC_Model, PC_AfterUpdateAction)
|
|||||||
pc_update msg model =
|
pc_update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
PM_B_UCycleStep ->
|
PM_B_UCycleStep ->
|
||||||
( uStepPC model
|
let (new_model, reqAlert) = uStepPC model
|
||||||
, if model.pc.uCounter == 0 then PUA_Storage_And_Scroller
|
in
|
||||||
|
( new_model
|
||||||
|
, if reqAlert == True then PUA_Alert
|
||||||
|
else if model.pc.uCounter == 0 then PUA_Storage_And_Scroller
|
||||||
else PUA_Scroller
|
else PUA_Scroller
|
||||||
)
|
)
|
||||||
|
|
||||||
PM_B_InstructionStep ->
|
PM_B_InstructionStep ->
|
||||||
( executeInstruction model
|
let (new_model, reqAlert) = executeInstruction model
|
||||||
, PUA_Storage_And_Scroller )
|
in
|
||||||
|
( new_model
|
||||||
|
, if reqAlert then PUA_Alert
|
||||||
|
else PUA_Storage_And_Scroller
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
PM_B_Reset ->
|
PM_B_Reset ->
|
||||||
@ -177,7 +184,7 @@ getAction uAction =
|
|||||||
(\s -> s)
|
(\s -> s)
|
||||||
|
|
||||||
|
|
||||||
uStepPC : PC_Model -> PC_Model
|
uStepPC : PC_Model -> (PC_Model, Bool)
|
||||||
uStepPC model =
|
uStepPC model =
|
||||||
let
|
let
|
||||||
uCounter =
|
uCounter =
|
||||||
@ -198,45 +205,25 @@ uStepPC model =
|
|||||||
f = uCode.action
|
f = uCode.action
|
||||||
new_pc = f temp_pc
|
new_pc = f temp_pc
|
||||||
in
|
in
|
||||||
{ model | pc = new_pc }
|
if uCode.variant == UA_AlertUser then
|
||||||
|
(model, True)
|
||||||
|
else
|
||||||
--let
|
({ model | pc = new_pc }, False)
|
||||||
-- 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
|
(model, False)
|
||||||
|
|
||||||
|
|
||||||
executeInstruction : PC_Model -> PC_Model
|
executeInstruction : PC_Model -> (PC_Model, Bool)
|
||||||
executeInstruction model =
|
executeInstruction model =
|
||||||
let
|
let
|
||||||
new_model = uStepPC model
|
(new_model, reqAlert) = uStepPC model
|
||||||
in
|
in
|
||||||
if new_model.pc.uCounter == 0 then
|
if new_model.pc.uCounter == 0 then
|
||||||
uStepPC new_model
|
(new_model, reqAlert)
|
||||||
|
else
|
||||||
|
if reqAlert then
|
||||||
|
(new_model, True)
|
||||||
else
|
else
|
||||||
executeInstruction new_model
|
executeInstruction new_model
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user