Ignore:
Timestamp:
Oct 8, 2010, 6:34:46 PM (9 years ago)
Author:
mulligan
Message:

Implemented latch access.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/ASMInterpret.ml

    r166 r168  
    1212
    1313type time = int;;
    14 type line = [ `P0 of byte
    15             | `P1 of byte
     14type line = [ `P1 of byte
     15            | `P3 of byte
    1616            | `SerialBuff of [ `Eight of byte | `Nine of BitVectors.bit * byte ]];;
    1717
     
    3434
    3535   (* sfr *)
    36    p0: byte;
    3736   sp: byte;
    3837   dpl: byte;
     
    4645   th1: byte;
    4746   p1: byte;
     47   p1_latch: byte;
    4848   scon: byte;
    4949   sbuf: byte;
    50    p2: byte;
    5150   ie: byte;
    5251   p3: byte;
     52   p3_latch: byte;
    5353   ip: byte;
    5454   psw: byte;
     
    7171(* Try to understand what DEC really does!!! *)
    7272(* Try to understand I/O *)
    73 let get_sfr status addr =
     73let get_sfr status addr from_latch =
    7474 match int_of_vect addr with
    7575  (* I/O and timer ports *)
    76     0x80 -> status.p0
    77   | 0x90 -> status.p1
    78   | 0xA0 -> status.p2
    79   | 0xB0 -> status.p3
     76    0x80 -> assert false (* P0 not modeled *)
     77  | 0x90 -> if from_latch then
     78              status.p1_latch
     79            else status.p1
     80  | 0xA0 -> assert false (* P2 not modeled *)
     81  | 0xB0 -> if from_latch then
     82              status.p3_latch
     83            else status.p3
    8084  | 0x99 -> status.sbuf
    8185  | 0x8A -> status.tl0
     
    111115 match int_of_vect addr with
    112116  (* I/O and timer ports *)
    113     0x80 -> { status with p0 = v }
    114   | 0x90 -> { status with p1 = v }
    115   | 0xA0 -> { status with p2 = v }
    116   | 0xB0 -> { status with p3 = v }
     117    0x80 -> assert false (* P0 not modeled *)
     118  | 0x90 -> { status with p1 = v; p1_latch = v }
     119  | 0xA0 -> assert false (* P2 not modeled *)
     120  | 0xB0 -> { status with p3 = v; p3_latch = v }
    117121  | 0x99 ->
    118122      if status.expected_out_time = `None then
     
    157161  pc = zero `Sixteen;
    158162
    159   p0 = zero `Eight;
    160163  sp = vect_of_int 7 `Eight;
    161164  dpl = zero `Eight;
     
    169172  th1 = zero `Eight;
    170173  p1 = zero `Eight;
     174  p1_latch = zero `Eight;
    171175  scon = zero `Eight;
    172176  sbuf = zero `Eight;
    173   p2 = zero `Eight;
    174177  ie = zero `Eight;
    175178  p3 = zero `Eight;
     179  p3_latch = zero `Eight;
    176180  ip = zero `Eight;
    177181  psw = zero `Eight;
     
    828832;;
    829833
    830 let get_arg_8 status =
     834let get_arg_8 status from_latch =
    831835 function
    832836    `DIRECT addr ->
     
    835839          (false,r1,r2,r3) ->
    836840            Byte7Map.find (mk_byte7 r1 r2 r3 n1) status.low_internal_ram
    837         | _ -> get_sfr status addr)
     841        | _ -> get_sfr status addr from_latch)
    838842  | `INDIRECT b ->
    839843       let (b1, b2) = from_byte (get_register status (false,false,b)) in
     
    868872let get_arg_16 _status = function `DATA16 w -> w
    869873
    870 let get_arg_1 status =
     874let get_arg_1 status from_latch =
    871875  function
    872876    `BIT addr
     
    883887            let div = addr / 8 in
    884888            let rem = addr mod 8 in
    885               get_bit (get_sfr status (vect_of_int ((div * 8) + 128) `Eight)) rem)
     889              get_bit (get_sfr status (vect_of_int ((div * 8) + 128) `Eight) from_latch) rem)
    886890    in (match x with `NBIT _ -> not res | _ -> res)
    887891  | `C -> get_cy_flag status
     
    902906            let rem = addr mod 8 in
    903907            let addr' = vect_of_int ((div * 8) + 128) `Eight in
    904             let sfr = get_sfr status addr' in
     908            let sfr = get_sfr status addr' true in (* are we reading from the latch here? *)
    905909            let sfr' = set_bit sfr rem v in
    906910              set_sfr status addr' sfr')
     
    994998     `ADD (`A,d1) ->
    995999        let v,c,ac,ov =
    996           add8_with_c (get_arg_8 status `A) (get_arg_8 status d1) false
     1000          add8_with_c (get_arg_8 status false `A) (get_arg_8 status false d1) false
    9971001        in
    9981002          set_flags (set_arg_8 status v `A) c (Some ac) ov
    9991003   | `ADDC (`A,d1) ->
    10001004        let v,c,ac,ov =
    1001           add8_with_c (get_arg_8 status `A) (get_arg_8 status d1) (get_cy_flag status)
     1005          add8_with_c (get_arg_8 status false `A) (get_arg_8 status false d1) (get_cy_flag status)
    10021006        in
    10031007          set_flags (set_arg_8 status v `A) c (Some ac) ov
    10041008   | `SUBB (`A,d1) ->
    10051009        let v,c,ac,ov =
    1006           subb8_with_c (get_arg_8 status `A) (get_arg_8 status d1) (get_cy_flag status)
     1010          subb8_with_c (get_arg_8 status false `A) (get_arg_8 status false d1) (get_cy_flag status)
    10071011        in
    10081012          set_flags (set_arg_8 status v `A) c (Some ac) ov
     
    10121016         { status with dpl = low_order_byte; dph = high_order_byte }
    10131017   | `INC ((`A | `REG _ | `DIRECT _ | `INDIRECT _) as d) ->
    1014        let b = get_arg_8 status d in
     1018       let b = get_arg_8 status true d in
    10151019       let cry, res = half_add b (vect_of_int 1 `Eight) in
    10161020         set_arg_8 status res d
    10171021   | `DEC d ->
    1018        let b = get_arg_8 status d in
     1022       let b = get_arg_8 status true d in
    10191023       let res,c,ac,ov = subb8_with_c b (vect_of_int 1 `Eight) false in
    10201024         set_arg_8 status res d
     
    10541058            status
    10551059   | `ANL (`U1(`A, ag)) ->
    1056         let and_val = get_arg_8 status `A -&- get_arg_8 status ag in
     1060        let and_val = get_arg_8 status true `A -&- get_arg_8 status true ag in
    10571061          set_arg_8 status and_val `A
    10581062   | `ANL (`U2((`DIRECT d), ag)) ->
    1059         let and_val = get_arg_8 status (`DIRECT d) -&- get_arg_8 status ag in
     1063        let and_val = get_arg_8 status true (`DIRECT d) -&- get_arg_8 status true ag in
    10601064          set_arg_8 status and_val (`DIRECT d)
    10611065   | `ANL (`U3 (`C, b)) ->
    1062         let and_val = get_cy_flag status && get_arg_1 status b in
     1066        let and_val = get_cy_flag status && get_arg_1 status true b in
    10631067          set_flags status and_val None (get_ov_flag status)
    10641068   | `ORL (`U1(`A, ag)) ->
    1065         let or_val = get_arg_8 status `A -|- get_arg_8 status ag in
     1069        let or_val = get_arg_8 status true `A -|- get_arg_8 status true ag in
    10661070          set_arg_8 status or_val `A
    10671071   | `ORL (`U2((`DIRECT d), ag)) ->
    1068         let or_val = get_arg_8 status (`DIRECT d) -|- get_arg_8 status ag in
     1072        let or_val = get_arg_8 status true (`DIRECT d) -|- get_arg_8 status true ag in
    10691073          set_arg_8 status or_val (`DIRECT d)
    10701074   | `ORL (`U3 (`C, b)) ->
    1071         let or_val = get_cy_flag status || get_arg_1 status b in
     1075        let or_val = get_cy_flag status || get_arg_1 status true b in
    10721076          set_flags status or_val None (get_ov_flag status)
    10731077   | `XRL (`U1(`A, ag)) ->
    1074         let xor_val = get_arg_8 status `A -^- get_arg_8 status ag in
     1078        let xor_val = get_arg_8 status true `A -^- get_arg_8 status true ag in
    10751079          set_arg_8 status xor_val `A
    10761080   | `XRL (`U2((`DIRECT d), ag)) ->
    1077         let xor_val = get_arg_8 status (`DIRECT d) -^- get_arg_8 status ag in
     1081        let xor_val = get_arg_8 status true (`DIRECT d) -^- get_arg_8 status true ag in
    10781082          set_arg_8 status xor_val (`DIRECT d)
    10791083   | `CLR `A -> set_arg_8 status (zero `Eight) `A
     
    10811085   | `CLR ((`BIT _) as a) -> set_arg_1 status false a
    10821086   | `CPL `A -> { status with acc = complement status.acc }
    1083    | `CPL `C -> set_arg_1 status (not $ get_arg_1 status `C) `C
    1084    | `CPL ((`BIT _) as b) -> set_arg_1 status (not $ get_arg_1 status b) b
     1087   | `CPL `C -> set_arg_1 status (not $ get_arg_1 status true `C) `C
     1088   | `CPL ((`BIT _) as b) -> set_arg_1 status (not $ get_arg_1 status true b) b
    10851089   | `RL `A -> { status with acc = rotate_left status.acc }
    10861090   | `RLC `A ->
     
    11001104        let (acc_nibble_upper, acc_nibble_lower) = from_byte status.acc in
    11011105          { status with acc = mk_byte acc_nibble_lower acc_nibble_upper }
    1102   | `MOV(`U1(b1, b2)) -> set_arg_8 status (get_arg_8 status b2) b1
    1103   | `MOV(`U2(b1, b2)) -> set_arg_8 status (get_arg_8 status b2) b1
    1104   | `MOV(`U3(b1, b2)) -> set_arg_8 status (get_arg_8 status b2) b1
     1106  | `MOV(`U1(b1, b2)) -> set_arg_8 status (get_arg_8 status false b2) b1
     1107  | `MOV(`U2(b1, b2)) -> set_arg_8 status (get_arg_8 status false b2) b1
     1108  | `MOV(`U3(b1, b2)) -> set_arg_8 status (get_arg_8 status false b2) b1
    11051109  | `MOV(`U4(b1,b2)) -> set_arg_16 status (get_arg_16 status b2) b1
    1106   | `MOV(`U5(b1,b2)) -> set_arg_1 status (get_arg_1 status b2) b1
    1107   | `MOV(`U6(b1,b2)) -> set_arg_1 status (get_arg_1 status b2) b1
     1110  | `MOV(`U5(b1,b2)) -> set_arg_1 status (get_arg_1 status false b2) b1
     1111  | `MOV(`U6(b1,b2)) -> set_arg_1 status (get_arg_1 status false b2) b1
    11081112  | `MOVC (`A, `A_DPTR) ->
    11091113     let big_acc = mk_word (zero `Eight) status.acc in
     
    11231127  (* data transfer *)
    11241128  (* DPM: MOVX currently only implements the *copying* of data! *)
    1125   | `MOVX (`U1 (a1, a2)) -> set_arg_8 status (get_arg_8 status a2) a1
    1126   | `MOVX (`U2 (a1, a2)) -> set_arg_8 status (get_arg_8 status a2) a1
     1129  | `MOVX (`U1 (a1, a2)) -> set_arg_8 status (get_arg_8 status false a2) a1
     1130  | `MOVX (`U2 (a1, a2)) -> set_arg_8 status (get_arg_8 status false a2) a1
    11271131  | `SETB b -> set_arg_1 status true b
    11281132  | `PUSH (`DIRECT b) ->
     
    11381142         status
    11391143  | `XCH(`A, arg) ->
    1140        let old_arg = get_arg_8 status arg in
     1144       let old_arg = get_arg_8 status false arg in
    11411145       let old_acc = status.acc in
    11421146       let status = set_arg_8 status old_acc arg in
    11431147         { status with acc = old_arg }
    11441148  | `XCHD(`A, i) ->
    1145        let acc_upper_nibble, acc_lower_nibble = from_byte $ get_arg_8 status `A in
    1146        let ind_upper_nibble, ind_lower_nibble = from_byte $ get_arg_8 status i in
     1149       let acc_upper_nibble, acc_lower_nibble = from_byte $ get_arg_8 status false `A in
     1150       let ind_upper_nibble, ind_lower_nibble = from_byte $ get_arg_8 status false i in
    11471151       let new_acc = mk_byte acc_upper_nibble ind_lower_nibble in
    11481152       let new_reg = mk_byte ind_upper_nibble acc_lower_nibble in
     
    11631167         status
    11641168  | `JB (b, (`REL rel)) ->
    1165        if get_arg_1 status b then
     1169       if get_arg_1 status false b then
    11661170         let cry, new_pc = half_add status.pc (sign_extension rel) in
    11671171           { status with pc = new_pc }
     
    11691173         status
    11701174  | `JNB (b, (`REL rel)) ->
    1171        if not $ get_arg_1 status b then
     1175       if not $ get_arg_1 status false b then
    11721176         let cry, new_pc = half_add status.pc (sign_extension rel) in
    11731177           { status with pc = new_pc }
     
    11761180  | `JBC (b, (`REL rel)) ->
    11771181       let status = set_arg_1 status false b in
    1178          if get_arg_1 status b then
     1182         if get_arg_1 status false b then
    11791183           let cry, new_pc = half_add status.pc (sign_extension rel) in
    11801184             { status with pc = new_pc }
     
    12521256         status
    12531257  | `CJNE ((`U1 (`A, ag)), `REL rel) ->
    1254        let new_carry = status.acc < get_arg_8 status ag in
    1255          if get_arg_8 status ag <> status.acc then
     1258       let new_carry = status.acc < get_arg_8 status false ag in
     1259         if get_arg_8 status false ag <> status.acc then
    12561260           let cry, new_pc = half_add status.pc (sign_extension rel) in
    12571261           let status = set_flags status new_carry None (get_ov_flag status) in
     
    12601264           set_flags status new_carry None (get_ov_flag status)
    12611265  | `CJNE ((`U2 (ag, `DATA d)), `REL rel) ->
    1262      let new_carry = get_arg_8 status ag < d in
    1263        if get_arg_8 status ag <> d then
     1266     let new_carry = get_arg_8 status false ag < d in
     1267       if get_arg_8 status false ag <> d then
    12641268         let cry, new_pc = half_add status.pc (sign_extension rel) in
    12651269         let status = { status with pc = new_pc } in
     
    12681272         set_flags status new_carry None (get_ov_flag status)
    12691273  | `DJNZ (ag, (`REL rel)) ->
    1270        let new_ag,_,_,_ = subb8_with_c (get_arg_8 status ag) (vect_of_int 1 `Eight) false in
     1274       let new_ag,_,_,_ = subb8_with_c (get_arg_8 status true ag) (vect_of_int 1 `Eight) false in
    12711275       let status = set_arg_8 status new_ag ag in
    12721276         if new_ag <> zero `Eight then
     
    14241428               let status =
    14251429                 match line with
    1426                    `P0 b -> assert false
    1427                  | `P1 b -> assert false
     1430                   `P1 b -> assert false
     1431                 | `P3 b -> assert false
    14281432                 | `SerialBuff (`Eight b) ->
    14291433                      let b7 = get_bit (status.scon) 7 in
Note: See TracChangeset for help on using the changeset viewer.