Changeset 179 for branches/virtualcpu4


Ignore:
Timestamp:
Apr 12, 2019, 3:23:47 PM (6 years ago)
Author:
chronos
Message:
  • Added: Subroutine execution.
Location:
branches/virtualcpu4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/virtualcpu4/UFormMain.pas

    r178 r179  
    187187  R3: Byte;
    188188  R4: Byte;
    189   LabelStart: Integer;
    190189  LabelText: Integer;
     190  LabelText2: Integer;
    191191  LabelPrint: Integer;
    192192  LabelClearScreen: Integer;
     193  LabelPrintLoop: Integer;
     194  LabelConsole: Integer;
     195  LabelMain: Integer;
    193196begin
    194197  R1 := 1;
     
    198201  with InstructionWriter do begin
    199202    Init;
    200     // Print Hello world text
    201     LabelText := 200;
    202     Loadi(R1, LabelText);
    203     Loadi(R2, 12);
     203    LabelMain := $100;
     204    Jump(LabelMain);
     205
     206  LabelText := IP;
     207    WriteString('Hello World!');
     208
     209  LabelText2 := IP;
     210    WriteString('Good day!');
     211
    204212  LabelPrint := IP;
     213    Push(R3);
     214    Push(R2);
     215    Push(R1);
     216  LabelPrintLoop := IP;
    205217    DataPrefix8; LoadMem(R3, R1);
    206218    DataPrefix8; Output(0, R3);
     
    208220    Decrement(R2);
    209221    Test(R2);
    210     JumpNotZero(LabelPrint);
     222    AddrPrefix8; JumpNotZero(LabelPrintLoop);
     223    Pop(R1);
     224    Pop(R2);
     225    Pop(R3);
     226    Return;
     227
     228    IP := LabelMain;
     229
     230    // Print Hello world text
     231    Loadi(R1, LabelText);
     232    Loadi(R2, 12);
     233    Call(LabelPrint);
     234    Loadi(R1, LabelText2);
     235    Loadi(R2, 9);
     236    Call(LabelPrint);
    211237
    212238    // Draw to video memory
     
    231257    // Read keyboard and print to console
    232258    Loadi(R1, 100);
    233   LabelStart := IP;
     259  LabelConsole := IP;
    234260    Increment(R1);
    235261    Loadi(R2, $100);
     
    237263    DataPrefix8; Input(R2, 0);
    238264    DataPrefix8; Output(0, R2);
    239     Jump(LabelStart);
     265    Jump(LabelConsole);
     266
    240267    Halt;
    241   IP := LabelText;
    242     WriteString('Hello World!');
    243268  end;
    244269end;
  • branches/virtualcpu4/UInstructionWriter.pas

    r178 r179  
    4747    procedure Push(Reg: TRegIndex);
    4848    procedure Pop(Reg: TRegIndex);
     49    procedure Call(Addr: QWord);
     50    procedure Return;
    4951    procedure DataPrefix8;
    5052    procedure DataPrefix16;
     
    205207end;
    206208
     209procedure TInstructionWriter.Call(Addr: QWord);
     210begin
     211  PrefixBegin;
     212  Write8(Byte(opCall));
     213  WriteAddress(Addr);
     214  PrefixEnd;
     215end;
     216
     217procedure TInstructionWriter.Return;
     218begin
     219  PrefixBegin;
     220  Write8(Byte(opRet));
     221  PrefixEnd;
     222end;
     223
    207224procedure TInstructionWriter.DataPrefix8;
    208225begin
  • branches/virtualcpu4/UMachine.pas

    r177 r179  
    5454  Screen := TScreen.Create;
    5555  Screen.Size := Point(320, 240);
    56   Screen.MemoryBase := $100;
     56  Screen.MemoryBase := $200;
    5757  MemorySize := $1000000;
    5858  Cpu.Memory := Memory;
Note: See TracChangeset for help on using the changeset viewer.