Add Leading 0 before addresses
This commit is contained in:
47
src/Main.elm
47
src/Main.elm
@ -10,6 +10,7 @@ import Html.Events exposing (onClick)
|
||||
import Html.Lazy exposing (lazy)
|
||||
import Tuple
|
||||
import Array exposing (get)
|
||||
import Html exposing (address)
|
||||
|
||||
|
||||
|
||||
@ -370,8 +371,8 @@ viewRamContent model =
|
||||
in
|
||||
Html.tr
|
||||
[ classList [ ( "current", id == model.pc.addressBus ) ] ]
|
||||
[ Html.td [ class "num" ] [ text (String.fromInt id) ]
|
||||
, Html.td [ class "num " ] [ text (String.fromInt val) ]
|
||||
[ Html.td [ class "num" ] [ text (addLeadingZero id 3) ]
|
||||
, Html.td [ class "num " ] [ viewInstrEntry val ]
|
||||
]
|
||||
in
|
||||
Html.tbody [] (List.map ram2table indexedRam)
|
||||
@ -465,13 +466,13 @@ viewCuUCodeContent model =
|
||||
in
|
||||
Html.tr
|
||||
[ classList [ ( "current", id == model.pc.uCounter ) ] ]
|
||||
[ Html.td [ class "num" ] [ text (String.fromInt id) ]
|
||||
[ Html.td [ class "num" ] [ text (addLeadingZero id 3) ]
|
||||
, Html.td [] [ text codeDescription ]
|
||||
]
|
||||
|
||||
Nothing ->
|
||||
Html.tr [ class "empty" ]
|
||||
[ Html.td [ class "num" ] [ text (String.fromInt id) ]
|
||||
[ Html.td [ class "num" ] [ text (addLeadingZero id 3) ]
|
||||
, Html.td [] [ text "Empty" ]
|
||||
]
|
||||
in
|
||||
@ -500,7 +501,7 @@ viewDataBus : Model -> Html Msg
|
||||
viewDataBus model =
|
||||
div [ class "databus" ]
|
||||
[ Html.span [ class "label" ] [ text "Databus" ]
|
||||
, Html.span [] [ text (String.fromInt model.pc.dataBus) ]
|
||||
, Html.span [] [ text (addLeadingZero model.pc.dataBus 8) ]
|
||||
]
|
||||
|
||||
|
||||
@ -508,10 +509,21 @@ viewAddressBus : Model -> Html Msg
|
||||
viewAddressBus model =
|
||||
div [ class "addressbus" ]
|
||||
[ Html.span [ class "label" ] [ text "Addressbus" ]
|
||||
, Html.span [] [ text (String.fromInt model.pc.addressBus) ]
|
||||
, Html.span [] [ text (addLeadingZero model.pc.addressBus 3) ]
|
||||
]
|
||||
|
||||
|
||||
viewInstrEntry : Int -> Html Msg
|
||||
viewInstrEntry i =
|
||||
let
|
||||
instruction = i // 100000
|
||||
address = i - instruction*100000
|
||||
in
|
||||
text ( (addLeadingZero instruction 3) ++ " " ++ (addLeadingZero address 5) )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- END VIEWERS
|
||||
-- ACTIONS
|
||||
@ -640,6 +652,29 @@ changeAt pos newVal list =
|
||||
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
|
||||
|
||||
-- END HELPERS
|
||||
-- GENERAL
|
||||
|
Reference in New Issue
Block a user