Added whole Instruction step and a basic how to
This commit is contained in:
106
src/Main.elm
106
src/Main.elm
@ -74,6 +74,7 @@ type UAction
|
||||
| ActInstructionReg2ProgrammCounter
|
||||
| ActInstructionReg2UCounter
|
||||
| ActProgrammCounterIncrement
|
||||
| ActInstructionReg2ProgrammCounterIfAccEq0
|
||||
| ActRam2DataBus
|
||||
| ActResetUCounter
|
||||
| ActProgrammCounter2AddressBus
|
||||
@ -91,6 +92,7 @@ uCodeDescriptions =
|
||||
, ( ActInstructionReg2ProgrammCounter, "InstReg -> ProgCount" )
|
||||
, ( ActInstructionReg2UCounter, "InstReg -> µCounter" )
|
||||
, ( ActProgrammCounterIncrement, "ProgCounter ++" )
|
||||
, ( ActInstructionReg2ProgrammCounterIfAccEq0, "Acc == 0 => InstReg -> ProgCounter")
|
||||
, ( ActRam2DataBus, "Ram -> DataBus" )
|
||||
, ( ActResetUCounter, "µCounter = 0" )
|
||||
, ( ActProgrammCounter2AddressBus, "ProgCounter -> AddrBus" )
|
||||
@ -109,6 +111,7 @@ uCodeIds =
|
||||
, ( ActInstructionReg2ProgrammCounter, "ir2pc" )
|
||||
, ( ActInstructionReg2UCounter, "ir2uc" )
|
||||
, ( ActProgrammCounterIncrement, "pcInc" )
|
||||
, ( ActInstructionReg2ProgrammCounterIfAccEq0, "ir2pciacceq0")
|
||||
, ( ActRam2DataBus, "ram2db" )
|
||||
, ( ActResetUCounter, "ucReset" )
|
||||
, ( ActProgrammCounter2AddressBus, "pc2ab" )
|
||||
@ -127,6 +130,7 @@ uCodeMaps =
|
||||
, ( ActInstructionReg2ProgrammCounter, actInstructionReg2ProgrammCounter )
|
||||
, ( ActInstructionReg2UCounter, actInstructionReg2UCounter )
|
||||
, ( ActProgrammCounterIncrement, actProgrammCounterIncrement )
|
||||
, ( ActInstructionReg2ProgrammCounterIfAccEq0, actInstructionReg2ProgrammCounterIfAccEq0 )
|
||||
, ( ActRam2DataBus, actRam2DataBus )
|
||||
, ( ActResetUCounter, actResetUCounter )
|
||||
, ( ActProgrammCounter2AddressBus, actProgrammCounter2AddressBus )
|
||||
@ -236,7 +240,8 @@ type Msg
|
||||
| MsgRamAddBelow
|
||||
| MsgCuEditAction Int String
|
||||
| MsgCuAddBelow
|
||||
| MsgCuInstrRegEdit String
|
||||
| MsgCuInstrRegEditAddr String
|
||||
| MsgCuInstrRegEditInstr String
|
||||
| MsgCuUCounterEdit String
|
||||
| MsgCuProgCounterEdit String
|
||||
| MsgEditAddressBus String
|
||||
@ -265,16 +270,22 @@ update msg model =
|
||||
)
|
||||
|
||||
MsgInstructionStep ->
|
||||
( model, Cmd.none )
|
||||
( executeInstruction model
|
||||
, cmdSenduUpdate model )
|
||||
|
||||
|
||||
MsgReset ->
|
||||
updateModel { model | pc = { initialPC | ram = model.pc.ram } }
|
||||
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
|
||||
updateModel { model | pc = instruction model.pc}
|
||||
( new_model, cmdSenduUpdate new_model )
|
||||
|
||||
MsgRamEditAddress addr may_int ->
|
||||
case String.toInt may_int of
|
||||
@ -319,11 +330,22 @@ update msg model =
|
||||
MsgCuAddBelow ->
|
||||
updateModel {model | uCode = model.uCode ++ [ ActNothing ]}
|
||||
|
||||
MsgCuInstrRegEdit text ->
|
||||
MsgCuInstrRegEditAddr text ->
|
||||
case String.toInt text of
|
||||
Just int ->
|
||||
let old_pc = model.pc
|
||||
new_pc = { old_pc | instructionReg = int }
|
||||
(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 )
|
||||
@ -374,7 +396,14 @@ update msg model =
|
||||
_ -> ( model, Cmd.none )
|
||||
|
||||
MsgAutoscrollUpdate ->
|
||||
updateModel { model | autoscroll = not model.autoscroll }
|
||||
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 )
|
||||
@ -481,6 +510,16 @@ uStepPC model =
|
||||
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 =
|
||||
JE.object
|
||||
@ -595,7 +634,7 @@ viewPC model =
|
||||
div
|
||||
[ class "pc" ]
|
||||
[ div [ class "controls", class "grid-fullwidth" ]
|
||||
[ button [ onClick MsgUCycleStep ] [ text "µZyklus" ]
|
||||
[ button [ onClick MsgUCycleStep ] [ text "µCycle" ]
|
||||
, button [ onClick MsgInstructionStep ] [ text "Instruction" ]
|
||||
, button [ onClick MsgReset ] [ text "Reset PC" ]
|
||||
, div
|
||||
@ -616,7 +655,6 @@ viewPC model =
|
||||
[ HAttr.for "enableScrolling" ]
|
||||
[ text "Autoscroll" ]
|
||||
]
|
||||
, button [ onClick MsgLocalSessionExport ] [ text "Export" ]
|
||||
, button [ onClick MsgToggleLoadExample ] [ text "Load Example" ]
|
||||
]
|
||||
, div [ class "grid-fullwidth" ] [ lazy viewAddressBus model ]
|
||||
@ -715,6 +753,9 @@ viewRamContent model =
|
||||
|
||||
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" ]
|
||||
@ -730,6 +771,9 @@ viewCu model =
|
||||
, 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"
|
||||
@ -740,16 +784,30 @@ viewCu model =
|
||||
|
||||
, div [class "input-row"]
|
||||
[ Html.label [ HAttr.for "cu-instrReg" ] [ text "Instruction Register:" ]
|
||||
, Html.input
|
||||
[ HAttr.type_ "number"
|
||||
, HAttr.id "cu-instrReg"
|
||||
, value (addLeadingZero model.pc.instructionReg 8)
|
||||
, onInput MsgCuInstrRegEdit
|
||||
] []
|
||||
, 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"
|
||||
@ -775,8 +833,8 @@ viewCuUCode model =
|
||||
Html.table []
|
||||
[ Html.thead [ class "head" ]
|
||||
[ Html.tr []
|
||||
[ Html.th [ class "address" ] [ text "Addr" ]
|
||||
, Html.th [] [ text "Code" ]
|
||||
[ Html.th [ class "address" ] [ text "µCounter" ]
|
||||
, Html.th [] [ text "µCode" ]
|
||||
]
|
||||
]
|
||||
, lazy viewCuUCodeContent model
|
||||
@ -846,7 +904,10 @@ viewAlu model =
|
||||
, 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" ]
|
||||
@ -1003,6 +1064,15 @@ 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 =
|
||||
|
Reference in New Issue
Block a user