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}
|
35
src/Main.elm
35
src/Main.elm
@ -51,6 +51,7 @@ type alias Model =
|
||||
, examplesListStatus : LoaderState
|
||||
, exampleLoaderStatus : LoaderState
|
||||
, dragDrop : DragDrop
|
||||
, showAlert : Bool
|
||||
}
|
||||
|
||||
type alias Example =
|
||||
@ -89,6 +90,7 @@ type Msg
|
||||
| Msg_DrgDrp_Hover Bool
|
||||
| Msg_DrgDrp_GotFiles File (List File)
|
||||
| Msg_DrgDrp_DecodedFiles String
|
||||
| Msg_Alert_Hide
|
||||
| Msg_Nothing
|
||||
|
||||
|
||||
@ -117,6 +119,10 @@ update msg model =
|
||||
( 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
|
||||
@ -257,6 +263,10 @@ update msg model =
|
||||
, sendProcessing "Done"
|
||||
)
|
||||
|
||||
Msg_Alert_Hide ->
|
||||
( {model | showAlert = False}
|
||||
, Cmd.none)
|
||||
|
||||
Msg_Nothing -> (model, Cmd.none)
|
||||
|
||||
|
||||
@ -328,7 +338,7 @@ modelDecoder =
|
||||
mainDecoder version =
|
||||
if (version == pcModelVersion) then
|
||||
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 "autoscroll" JD.bool )
|
||||
else
|
||||
@ -355,7 +365,8 @@ view : Model -> Html Msg
|
||||
view model =
|
||||
div []
|
||||
[ 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 =
|
||||
[ hiJackOn "dragenter" <| JD.succeed <| Msg_DrgDrp_Hover True
|
||||
@ -540,6 +569,7 @@ init mayLocalStorage =
|
||||
, examplesListStatus = Waiting
|
||||
, exampleLoaderStatus = Waiting
|
||||
, dragDrop = initDragDrop
|
||||
, showAlert = False
|
||||
}
|
||||
, Cmd.none )
|
||||
Nothing ->
|
||||
@ -550,6 +580,7 @@ init mayLocalStorage =
|
||||
, examplesListStatus = Waiting
|
||||
, exampleLoaderStatus = Waiting
|
||||
, dragDrop = initDragDrop
|
||||
, showAlert = False
|
||||
}
|
||||
, Cmd.none )
|
||||
|
||||
|
@ -41,6 +41,7 @@ type UAction
|
||||
| UA_Ram2DataBus
|
||||
| UA_ResetUCounter
|
||||
| UA_ProgrammCounter2AddressBus
|
||||
| UA_AlertUser
|
||||
| UA_Nothing
|
||||
|
||||
|
||||
@ -73,6 +74,7 @@ type PC_Msg
|
||||
-- to happen after a update
|
||||
type PC_AfterUpdateAction
|
||||
= PUA_Nothing -- Do nothing
|
||||
| PUA_Alert -- Alert the user
|
||||
| PUA_Storage -- Update localStorage
|
||||
| PUA_Scroller -- Scroll to value
|
||||
| PUA_Storage_And_Scroller -- Update localStorage and scroll to values
|
@ -11,7 +11,8 @@ import PC.Helpers exposing (..)
|
||||
|
||||
uCodes : List UCode
|
||||
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_AccumulatorIncrement "accInc" actAccumulatorIncrement "Acc ++"
|
||||
, UCode UA_DataBus2Accumulator "db2acc" actDataBus2Accumulator "DataBus -> Acc"
|
||||
@ -24,9 +25,9 @@ uCodes =
|
||||
, 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"
|
||||
, UCode UA_AlertUser "alert" actDoAlert "Signal End of Programm"
|
||||
]
|
||||
|
||||
|
||||
@ -129,6 +130,9 @@ actDataBus2Ram pc =
|
||||
in
|
||||
{ pc | ram = newRam }
|
||||
|
||||
actDoAlert : PC -> PC
|
||||
actDoAlert pc = pc -- This gets caputred by update anyway
|
||||
|
||||
|
||||
-- #################################################################
|
||||
-- Helpers
|
||||
|
@ -11,15 +11,22 @@ 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_UCycleStep ->
|
||||
let (new_model, reqAlert) = uStepPC model
|
||||
in
|
||||
( new_model
|
||||
, if reqAlert == True then PUA_Alert
|
||||
else if model.pc.uCounter == 0 then PUA_Storage_And_Scroller
|
||||
else PUA_Scroller
|
||||
)
|
||||
|
||||
PM_B_InstructionStep ->
|
||||
( executeInstruction model
|
||||
, PUA_Storage_And_Scroller )
|
||||
PM_B_InstructionStep ->
|
||||
let (new_model, reqAlert) = executeInstruction model
|
||||
in
|
||||
( new_model
|
||||
, if reqAlert then PUA_Alert
|
||||
else PUA_Storage_And_Scroller
|
||||
)
|
||||
|
||||
|
||||
PM_B_Reset ->
|
||||
@ -177,7 +184,7 @@ getAction uAction =
|
||||
(\s -> s)
|
||||
|
||||
|
||||
uStepPC : PC_Model -> PC_Model
|
||||
uStepPC : PC_Model -> (PC_Model, Bool)
|
||||
uStepPC model =
|
||||
let
|
||||
uCounter =
|
||||
@ -198,47 +205,27 @@ uStepPC model =
|
||||
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 }
|
||||
if uCode.variant == UA_AlertUser then
|
||||
(model, True)
|
||||
else
|
||||
({ model | pc = new_pc }, False)
|
||||
|
||||
_ ->
|
||||
model
|
||||
(model, False)
|
||||
|
||||
|
||||
executeInstruction : PC_Model -> PC_Model
|
||||
executeInstruction : PC_Model -> (PC_Model, Bool)
|
||||
executeInstruction model =
|
||||
let
|
||||
new_model = uStepPC model
|
||||
(new_model, reqAlert) = uStepPC model
|
||||
in
|
||||
if new_model.pc.uCounter == 0 then
|
||||
uStepPC new_model
|
||||
(new_model, reqAlert)
|
||||
else
|
||||
executeInstruction new_model
|
||||
if reqAlert then
|
||||
(new_model, True)
|
||||
else
|
||||
executeInstruction new_model
|
||||
|
||||
|
||||
-- ###############################################################################
|
||||
|
Loading…
x
Reference in New Issue
Block a user