Cosmos/source2/Compiler/Cosmos.Compiler.DebugStub/Screen.cs
kudzu_cp 0583c7e7b6
2012-06-19 03:07:26 +00:00

111 lines
3.7 KiB
C#

using System;
using System.Linq;
using Cosmos.Assembler;
using Cosmos.Assembler.x86;
namespace Cosmos.Debug.DebugStub {
public class Screen : Cosmos.Assembler.Code {
public override void Assemble() {
new Comment("X#: Group DebugStub");
new Comment("X#: procedure Cls {");
new Label("DebugStub_Cls");
new Comment("VidBase");
new Comment("X#: ESI = $B8000");
new Mov{ DestinationReg = RegistersEnum.ESI, SourceValue = 0xB8000 };
new Comment("X#: BeginLoop:");
new Label("DebugStub_Cls_BeginLoop");
new Comment("Text");
new Comment("X#: AL = $00");
new Mov{ DestinationReg = RegistersEnum.AL, SourceValue = 0x00 };
new Comment("X#: ESI[0] = AL");
new Mov{ DestinationReg = RegistersEnum.ESI, DestinationIsIndirect = true, DestinationDisplacement = 0, SourceReg = RegistersEnum.AL };
new Comment("X#: ESI + 1");
new INC { DestinationReg = RegistersEnum.ESI };
new Comment("Colour");
new Comment("X#: AL = $0A");
new Mov{ DestinationReg = RegistersEnum.AL, SourceValue = 0x0A };
new Comment("X#: ESI[0] = AL");
new Mov{ DestinationReg = RegistersEnum.ESI, DestinationIsIndirect = true, DestinationDisplacement = 0, SourceReg = RegistersEnum.AL };
new Comment("X#: ESI + 1");
new INC { DestinationReg = RegistersEnum.ESI };
new Comment("End of Video Area");
new Comment("VidBase + 25 * 80 * 2 = B8FA0");
new Comment("X#: If (ESI < $B8FA0) goto BeginLoop");
new Compare { DestinationReg = RegistersEnum.ESI, SourceValue = 0xB8FA0 };
new ConditionalJump { Condition = ConditionalTestEnum.LessThan, DestinationLabel = "DebugStub_Cls_BeginLoop" };
new Comment("X#: }");
new Label("DebugStub_Cls_Exit");
new Return();
new Comment("X#: procedure DisplayWaitMsg {");
new Label("DebugStub_DisplayWaitMsg");
new Comment("http://wiki.osdev.org/Text_UI");
new Comment("Later can cycle for x changes of second register:");
new Comment("http://wiki.osdev.org/Time_And_Date");
new Comment("X#: ESI = @..DebugWaitMsg");
new Mov { DestinationReg = RegistersEnum.ESI , SourceRef = Cosmos.Assembler.ElementReference.New("DebugWaitMsg") };
new Comment("VidBase");
new Comment("X#: EDI = $B8000");
new Mov{ DestinationReg = RegistersEnum.EDI, SourceValue = 0xB8000 };
new Comment("10 lines down, 20 cols in (10 * 80 + 20) * 2)");
new Comment("X#: EDI + 1640");
new Add { DestinationReg = RegistersEnum.EDI, SourceValue = 1640 };
new Comment("Read and copy string till 0 terminator");
new Comment("X#: ReadChar:");
new Label("DebugStub_DisplayWaitMsg_ReadChar");
new Comment("X#: AL = ESI[0]");
new Mov{ DestinationReg = RegistersEnum.AL, SourceReg = RegistersEnum.ESI, SourceIsIndirect = true, SourceDisplacement = 0 };
new Comment("X#: if (AL = 0) goto AfterMsg");
new Compare { DestinationReg = RegistersEnum.AL, SourceValue = 0 };
new ConditionalJump { Condition = ConditionalTestEnum.Zero, DestinationLabel = "DebugStub_DisplayWaitMsg_AfterMsg" };
new Comment("X#: ESI + 1");
new INC { DestinationReg = RegistersEnum.ESI };
new Comment("X#: EDI[0] = AL");
new Mov{ DestinationReg = RegistersEnum.EDI, DestinationIsIndirect = true, DestinationDisplacement = 0, SourceReg = RegistersEnum.AL };
new Comment("X#: EDI + 2");
new Add { DestinationReg = RegistersEnum.EDI, SourceValue = 2 };
new Comment("X#: Goto ReadChar");
new Jump { DestinationLabel = "DebugStub_DisplayWaitMsg_ReadChar" };
new Comment("X#: AfterMsg:");
new Label("DebugStub_DisplayWaitMsg_AfterMsg");
new Comment("X#: }");
new Label("DebugStub_DisplayWaitMsg_Exit");
new Return();
}
}
}