Changeset 2


Ignore:
Timestamp:
Nov 6, 2009, 10:24:38 AM (14 years ago)
Author:
george
Message:
  • Přidáno: Třída pro obsluhu čísel s dynamickou velikostí.
  • Přidáno: Struktury pro vytváření specifikace assembleru a strojových kódů.
Location:
branches/Z80
Files:
7 added
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • branches/Z80

    • Property svn:ignore set to
      backup
      Compiler.exe
      lib
  • branches/Z80/Compiler.dpr

    r1 r2  
    66{R-}
    77{  $M 16384,0,655360   }
    8 
    9 uses
    10   UZ80Compiler in 'UZ80Compiler.pas';
    118
    129CONST
     
    455452         done := FALSE;
    456453         WHILE (Length(line)>0) AND NOT done DO BEGIN
    457             word := word + Upcase(line[1]);
     454      word := word + Upcase(line[1]);
    458455            Delete(line,1,1);
    459             IF Length(line)>0 THEN
     456      IF Length(line)>0 THEN
    460457               done := Pos(Upcase(line[1]),AlphaNumeric)=0;
    461458         END;
  • branches/Z80/UZ80Compiler.pas

    r1 r2  
    11unit UZ80Compiler;
     2
     3{$mode Delphi}{$H+}
    24
    35interface
    46
     7uses
     8  Classes, SysUtils, UDynamicNumber;
     9
     10type
     11  TMaskedValue = class
     12  private
     13    function GetSize: Integer;
     14    procedure SetSize(const AValue: Integer);
     15  public
     16    Value: TDynamicNumber;
     17    Mask: TDynamicNumber;
     18    property Size: Integer read GetSize write SetSize;
     19  end;
     20
     21  TStringEnumeration = class
     22    Values: TStringList;
     23    constructor Create;
     24    destructor Destroy; override;
     25  end;
     26
     27  TOperandType = (otEnumeration, otConstant);
     28
     29  TOperand = class
     30    OperandType: TOperandType;
     31    MaskedValue: TMaskedValue;
     32    Enumeration: TStringEnumeration;
     33    constructor Create;
     34    destructor Destroy; override;
     35  end;
     36
     37  TOpcode = class
     38    Name: string;
     39    Cycles: Integer;
     40    Operands: TList;
     41    MaskedValue: TMaskedValue;
     42    constructor Create;
     43    destructor Destroy; override;
     44  end;
     45
     46  TZ80Compiler = class
     47  private
     48    OperandEnumerations: TList;
     49    Opcodes: TList;
     50    MachineCode: TMemoryStream;
     51    procedure InitOpcodes;
     52  public
     53    procedure Load(StringList: TStringList);
     54    constructor Create;
     55    destructor Destroy; override;
     56  end;
     57
    558implementation
    659
     60{ TZ80Compiler }
     61
     62procedure TZ80Compiler.InitOpcodes;
     63var
     64  SigleRegistersEnum: TStringEnumeration;
     65begin
     66  SigleRegistersEnum := TStringEnumeration.Create;
     67  with SigleRegistersEnum do begin
     68    Values.Add('B');
     69    Values.Add('C');
     70    Values.Add('D');
     71    Values.Add('E');
     72    Values.Add('H');
     73    Values.Add('L');
     74    Values.Add('(HL)');
     75    Values.Add('A');
     76  end;
     77  OperandEnumerations.Add(SigleRegistersEnum);
     78
     79  with TOpcode(Opcodes[Opcodes.Add(TOpcode.Create)]) do begin
     80    Name := 'NOP';
     81    with MaskedValue do begin
     82      Value.Assign(0);
     83      Mask.Assign($ff);
     84    end;
     85  end;
     86  with TOpcode(Opcodes[Opcodes.Add(TOpcode.Create)]) do begin
     87    Name := 'INC';
     88    with MaskedValue do begin
     89      Value.Assign($04);
     90      Mask.Assign($c7);
     91    end;
     92    with TOperand(Operands[Operands.Add(TOperand.Create)]) do begin
     93      OperandType := otEnumeration;
     94      Enumeration := SigleRegistersEnum;
     95      with MaskedValue do begin
     96        Value.Assign($00);
     97        Mask.Assign($38);
     98      end;
     99    end;
     100  end;
     101end;
     102
     103procedure TZ80Compiler.Load(StringList: TStringList);
     104var
     105  I: Integer;
     106begin
     107  for I := 0 to StringList.Count - 1 do begin
     108
     109  end;
     110end;
     111
     112constructor TZ80Compiler.Create;
     113begin
     114  MachineCode := TMemoryStream.Create;
     115  Opcodes := TList.Create;
     116  OperandEnumerations := TList.Create;
     117  InitOpcodes;
     118end;
     119
     120destructor TZ80Compiler.Destroy;
     121var
     122  I: Integer;
     123begin
     124  for I := 0 to Opcodes.Count - 1 do
     125    TOpcode(Opcodes[I]).Destroy;
     126  Opcodes.Destroy;
     127  for I := 0 to OperandEnumerations.Count - 1 do
     128    TStringEnumeration(OperandEnumerations[I]).Destroy;
     129  OperandEnumerations.Destroy;
     130  MachineCode.Destroy;
     131  inherited Destroy;
     132end;
     133
     134{ TMaskedValue }
     135
     136function TMaskedValue.GetSize: Integer;
     137begin
     138  Result := Value.Size;
     139end;
     140
     141procedure TMaskedValue.SetSize(const AValue: Integer);
     142begin
     143  Value.Size := AValue;
     144  Mask.Size := AValue;
     145end;
     146
     147{ TOpcode }
     148
     149constructor TOpcode.Create;
     150begin
     151  MaskedValue := TMaskedValue.Create;
     152end;
     153
     154destructor TOpcode.Destroy;
     155var
     156  I: Integer;
     157begin
     158  for I := 0 to Operands.Count - 1 do
     159    TOperand(Operands[I]).Destroy;
     160  Operands.Destroy;
     161  MaskedValue.Destroy;
     162  inherited Destroy;
     163end;
     164
     165{ TOperand }
     166
     167constructor TOperand.Create;
     168begin
     169  MaskedValue := TMaskedValue.Create;
     170  Enumeration := nil;
     171end;
     172
     173destructor TOperand.Destroy;
     174begin
     175  MaskedValue.Destroy;
     176  inherited Destroy;
     177end;
     178
     179{ TStringEnumeration }
     180
     181constructor TStringEnumeration.Create;
     182begin
     183  Values := TStringList.Create;
     184end;
     185
     186destructor TStringEnumeration.Destroy;
     187begin
     188  Values.Destroy;
     189  inherited Destroy;
     190end;
     191
    7192end.
Note: See TracChangeset for help on using the changeset viewer.