Ignore:
Timestamp:
Apr 12, 2019, 1:34:47 AM (6 years ago)
Author:
chronos
Message:
  • Added: Drawing to video memory.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/virtualcpu4/UFormMain.pas

    r174 r175  
    2121    ListViewRegisters: TListView;
    2222    Memo1: TMemo;
     23    PaintBox1: TPaintBox;
    2324    Timer1: TTimer;
     25    TimerDraw: TTimer;
    2426    procedure ButtonStartClick(Sender: TObject);
    2527    procedure ButtonStopClick(Sender: TObject);
     
    3032    procedure ListViewRegistersData(Sender: TObject; Item: TListItem);
    3133    procedure Memo1KeyPress(Sender: TObject; var Key: char);
     34    procedure PaintBox1Paint(Sender: TObject);
     35    procedure PaintBox1Resize(Sender: TObject);
    3236    procedure Timer1Timer(Sender: TObject);
     37    procedure TimerDrawTimer(Sender: TObject);
    3338  private
    3439    procedure ReloadMemoryDump;
     
    8590  I: Integer;
    8691begin
    87   if Item.Index < Length(Machine.Memory) div ItemsPerLine then begin
     92  if Item.Index < Machine.MemorySize div ItemsPerLine then begin
    8893    Line := '';
    8994    for I := 0 to ItemsPerLine - 1 do
    90       Line := Line + IntToHex(Machine.Memory[Item.Index * ItemsPerLine + I], 2) + ' ';
     95      Line := Line + IntToHex(PByte(Machine.Memory + Item.Index * ItemsPerLine + I)^, 2) + ' ';
    9196    Item.Caption := IntToHex(Item.Index * ItemsPerLine, 8);
    9297    Item.SubItems.Add(Line);
     
    118123end;
    119124
     125procedure TFormMain.PaintBox1Paint(Sender: TObject);
     126var
     127  X, Y: Integer;
     128  B: Byte;
     129  MemorySizeTmp: Integer;
     130  Addr: Integer;
     131begin
     132  MemorySizeTmp := Machine.MemorySize;
     133  with Machine, Screen do
     134  for Y := 0 to Size.Y - 1 do
     135  for X := 0 to Size.X - 1 do begin
     136    Addr := MemoryBase + Y * Size.X + X;
     137    if Addr < MemorySizeTmp then begin
     138      B := PByte(Memory + Addr)^;
     139      PaintBox1.Canvas.Pixels[X, Y] := B * $010101;
     140    end;
     141  end;
     142end;
     143
     144procedure TFormMain.PaintBox1Resize(Sender: TObject);
     145begin
     146  Machine.Screen.Size := Point(PaintBox1.Width, PaintBox1.Height);
     147end;
     148
    120149procedure TFormMain.Timer1Timer(Sender: TObject);
    121150begin
     
    129158end;
    130159
     160procedure TFormMain.TimerDrawTimer(Sender: TObject);
     161begin
     162  PaintBox1.Repaint;
     163end;
     164
    131165procedure TFormMain.ReloadMemoryDump;
    132166begin
    133   ListViewMemory.Items.Count := Length(Machine.Memory) div ItemsPerLine;
     167  ListViewMemory.Items.Count := Machine.MemorySize div ItemsPerLine;
    134168  ListViewMemory.Refresh;
    135169end;
     
    146180  R2: Byte;
    147181  R3: Byte;
     182  R4: Byte;
    148183  LabelStart: Integer;
    149184  LabelText: Integer;
    150185  LabelPrint: Integer;
     186  LabelClearScreen: Integer;
    151187begin
    152188  R1 := 1;
    153189  R2 := 2;
    154190  R3 := 3;
     191  R4 := 4;
    155192  with InstructionWriter do begin
     193    // Print Hello world text
    156194    LabelText := 200;
    157195    Loadi(R1, LabelText);
    158196    Loadi(R2, 12);
    159197  LabelPrint := IP;
    160     DataPrefix8; LoadMem(R3, R1);
     198      DataPrefix8; LoadMem(R3, R1);
    161199    DataPrefix8; Output(0, R3);
    162200    Increment(R1);
     
    165203    JumpNotZero(LabelPrint);
    166204
     205    // Draw to video memory
     206    Loadi(R1, Machine.Screen.MemoryBase);
     207    Loadi(R2, $10000);
     208    Loadi(R3, $7f);
     209  LabelClearScreen := IP;
     210    DataPrefix8; StoreMem(R1, R3);
     211    Increment(R1);
     212    Decrement(R2);
     213    Test(R2);
     214    JumpNotZero(LabelClearScreen);
     215
     216    // Read keyboard and print to console
    167217    Loadi(R1, 100);
    168218  LabelStart := IP;
    169219    Increment(R1);
    170     Loadi(R2, 100);
     220    Loadi(R2, $100);
    171221    DataPrefix8; StoreMem(R2, R1);
    172222    DataPrefix8; Input(R2, 0);
Note: See TracChangeset for help on using the changeset viewer.