Changeset 83


Ignore:
Timestamp:
Sep 16, 2010, 3:31:33 PM (9 years ago)
Author:
mulligan
Message:

Lots of work done on tidying up code.

Location:
Deliverables/D4.1
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/8051Series.ml

    r67 r83  
    1313  type word
    1414
     15  type sfr
     16
     17  type code_memory
     18  type low_internal_ram
     19  type high_internal_ram
     20  type external_ram
     21
    1522  type processor_status
    1623  type program_counter
     
    2128
    2229  val power_up: processor_status
    23   val next: program_counter -> processor_status ->
    2430end;;
     31
     32module 8051_Series (Bit: BIT)
     33                   (Nibble: NIBBLE
     34                      with type bit    = Bit.bit)
     35                   (Byte: BYTE
     36                      with type bit    = Bit.bit
     37                      and  type nibble = Nibble.nibble)
     38                   (Byte7: BYTE7
     39                      with type bit    = Bit.bit
     40                      and  type nibble = Nibble.nibble)
     41                   (Word: WORD
     42                      with type bit    = Bit.bit
     43                      and  type nibble = Nibble.nibble
     44                      and  type byte   = Byte.byte)
     45                   (SpecialFunctionRegister: SFR
     46                      with type bit    = Bit.bit
     47                      and  type byte   = Byte.byte): 8051_SERIES =
     48struct
     49  type bit = Bit.bit
     50  type nibble = Nibble.nibble
     51  type byte = Byte.byte
     52  type byte7 = Byte.byte7
     53  type word = Word.word
     54
     55  type sfr = SpecialFunctionRegister.sfr
     56
     57  type code_memory = word Map.Make (struct type t = byte7 let compare = Pervasives.compare end)
     58  type low_internal_ram = Map.Make (struct type t = byte7 let compare = Pervasives.compare end)
     59  type high_internal_ram = Map.Make (struct type t = byte7 let compare = Pervasives.compare end)
     60  type external_ram = Map.Make (struct type t = byte7 let compare = Pervasives.compare end)
     61
     62  type processor_status = {
     63    program_counter: word;
     64    sfr: sfr;
     65   
     66  }
     67end;;
  • Deliverables/D4.1/ASMInterpret.ml

    r81 r83  
    739739  else true
    740740;;
     741
     742let power_on =
     743  status
     744  {
     745    code_memory = WordMap.empty;
     746    external_memory = WordMap.empty;
     747    low_internal_ram = Byte7Map.empty;
     748    high_internal_ram = Byte7Map.empty;
     749
     750    pc =
     751  }
     752;;
     753 
    741754
    742755let execute1 status =
  • Deliverables/D4.1/Bit.ml

    r64 r83  
    2222  val (-^-): bit -> bit -> bit
    2323  val not: bit -> bit
     24
     25  val zero: bit
     26
     27  (* Half add: two input bits, returns addition of bit plus carry. *)
     28  val half_add: bit -> bit -> (bit * bit)
     29  (* Full add: two input bits, plus input carry bit, returns       *)
     30  (* addition of input bits plus carry.                            *)
     31  val full_add: (bit * bit) -> bit -> (bit * bit)
    2432end;;
    2533
     
    6775      true -> false
    6876    | false -> true
     77
     78  let zero = false
     79
     80  let half_add l r = (l -^- r, l -&- r)
     81  let full_add (l, c) r =
     82    ((l -^- r) -^- c, (l -&- r) -|- (c -&- (l -^- r)))
    6983end;;
  • Deliverables/D4.1/Byte.ml

    r67 r83  
    44(*              operations on them.                                          *)
    55(* CREATED:     10/09/2010, Dominic Mulligan                                 *)
    6 (* BUGS:                                                                     *)
     6(* BUGS:        `from_int' not yet implemented.                              *)
    77(*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*)
    88
     
    2020  val from_nibbles: nibble -> nibble -> byte
    2121  val from_nibble: nibble -> byte
    22 (*
    23   val from_int: int -> byte
    24 *)
     22  (* val from_int: int -> byte *)
     23
    2524  val to_bit: byte -> bit option
    2625  val to_nibble: byte -> nibble option
     
    4847  val zip_bit: (bit -> bit -> bit) -> byte -> byte -> byte
    4948  val to_string: byte -> string
     49
     50  val zero: byte
     51  val half_add: byte -> byte -> (byte * bit)
     52  val full_add: (byte * bit) -> byte -> (byte * bit)
    5053end
    5154
     
    7477                              (Bit.from_bool false) (Bit.from_bool false) in
    7578      (n1, n2)
     79  (* let from_int = assert false                                 DPM: finish! *)
    7680
    7781  let get_nibble_at index (n1, n2) =
     
    197201      (new_n1, new_n2)
    198202  let to_string = iter_nibble Nibble.to_string
     203
     204  let zero = (Nibble.zero, Nibble.zero)
     205  let half_add (l1, l2) (r1, r2) =
     206    let (a2, c2) = Nibble.half_add l2 r2 in
     207    let (a1, c1) = Nibble.full_add (l1, c2) r2 in
     208      ((a1, a2), c1)
     209  let full_add ((l1, l2), c) (r1, r2) =
     210    let (a2, c2) = Nibble.full_add (l2, c) r2 in
     211    let (a1, c1) = Nibble.full_add (l1, c2) r2 in
     212      ((a1, a2), c1)
    199213end;;
    200214
  • Deliverables/D4.1/Nibble.ml

    r66 r83  
    3939  val iter_bit: (bit -> string) -> nibble -> string
    4040  val zip_bit: (bit -> bit -> bit) -> nibble -> nibble -> nibble
     41
     42  val zero: nibble
     43 
     44  val half_add: nibble -> nibble -> (nibble * bit)
     45  val full_add: (nibble * bit) -> nibble -> (nibble * bit)
    4146end
    4247
     
    116121
    117122  let to_string = iter_bit Bit.to_string
    118 end
    119123
    120 module Nibble = NibbleFunctor(Bit)
     124  let zero = (Bit.zero, Bit.zero, Bit.zero, Bit.zero)
     125  let half_add (l1, l2, l3, l4) (r1, r2, r3, r4) =
     126    let (a4, c4) = Bit.half_add l4 r4 in
     127    let (a3, c3) = Bit.full_add (l3, c4) r3 in
     128    let (a2, c2) = Bit.full_add (l2, c3) r2 in
     129    let (a1, c1) = Bit.full_add (l1, c2) r1 in
     130      ((a1, a2, a3, a4), c1)
     131  let full_add ((l1, l2, l3, l4), c) (r1, r2, r3, r4) =
     132    let (a4, c4) = Bit.full_add (l4, c) r4 in
     133    let (a3, c3) = Bit.full_add (l3, c4) r3 in
     134    let (a2, c2) = Bit.full_add (l2, c3) r2 in
     135    let (a1, c1) = Bit.full_add (l1, c2) r1 in
     136      ((a1, a2, a3, a4), c1)
     137end;;
     138
     139module Nibble = NibbleFunctor(Bit);;
  • Deliverables/D4.1/Word.ml

    r67 r83  
    11(*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*)
    2 (* FILENAME:    Byte.ml                                                      *)
    3 (* DESCRIPTION: An ADT implementing standard 8 bit bytes, and common         *)
     2(* FILENAME:    Word.ml                                                      *)
     3(* DESCRIPTION: An ADT implementing standard 16 bit words, and common        *)
    44(*              operations on them.                                          *)
    55(* CREATED:     13/09/2010, Dominic Mulligan                                 *)
Note: See TracChangeset for help on using the changeset viewer.