Microsoft Small Basic

Program Listing: BHC136
''Virus Game Prototype Arena (CoreWar Emulator)
''By DaCodeDude
TextWindow.Title = "Virus Arena - Alpha 0.0.1"
TextWindow.WriteLine("Virus Arena - Alpha 0.0.1 (CoreWar Emulator)")
TextWindow.Pause()

''Not Implemented yet:
''Hard core players don't need this anyway :P :D
''Virus1 Only Memory
''virus1priv[1] = ""
''virus1priv[2] = ""
''virus1priv[3] = ""
''virus1priv[4] = ""

TextWindow.WriteLine("Virus loading:")
''Open Virus1
virus1file = "C:\Users\Valued Customer\Desktop\Projects\Small Basic\Virus Game\vir\virus1.txt" ''Replace with select file and load file for distribution ready version
virus1code = ""
filelength = 0
''Load each line of virus 1's code into temporary array
' The following line could be harmful and has been automatically commented.
' thisLine = File.ReadLine(virus1file, 1)
While (thisLine <> "EndVirus")
filelength = filelength + 1
virus1code[filelength] = thisLine
' The following line could be harmful and has been automatically commented.
' thisLine = File.ReadLine(virus1file, filelength + 1)
EndWhile
''Check virus 1 data [debug, 2 lines]
TextWindow.WriteLine("Virus 1: " + virus1code)
TextWindow.WriteLine("")
''Get virus 1's # of commmands
virus1length = Array.GetItemCount(virus1code)
''Verify # of commands in virus 1 [debug, 2 lines]
TextWindow.WriteLine(virus1length)
TextWindow.WriteLine("")

''Create memory areana
virus1startpoint = 1
''Verify startpoint for virus 1 [debug, 2 lines]
TextWindow.WriteLine("Virus 1 start point: " + virus1startpoint + ".")
TextWindow.WriteLine("")
''Load virus 1 commands into memory array from its array
tempnum = 0
While (tempnum <> virus1length)
tempnum = tempnum + 1
memory[tempnum] = virus1code[tempnum]
EndWhile
''Load rest of memory
While (tempnum <> 100)
tempnum = tempnum + 1
memory[tempnum] = "DAT 0, 0"
EndWhile
''Verify memory [debug, 2 lines]
TextWindow.WriteLine(memory)
TextWindow.WriteLine("")

''Begin the running of the Virtual Memory and Code Interpreter
percycle = 500 ''To be customizable as to run game at multiple speeds. i.e. for watching a virus for debugging/testing or running fast for quick tournement runs
maxnumcycles = 1000 ''Maximum number of cycles a round, also customizable
numcycles = 0
virus1exec = virus1startpoint ''virus1exec is the next execution point, here it initializes as the start point of virus 1
'' Remember virus1startpoint is also the virus's program execution start point
While (numcycles <> maxnumcycles)
virus1step = memory[virus1exec] ''Load virus 1 command from memory array
''Verify each command to run [debug 2 lines]
TextWindow.WriteLine(virus1step)
TextWindow.Pause()
ExecVirus1Command()
numcycles = numcycles + 1
virus1exec = virus1exec + 1 ''Move to ExecVirus1Command sub once more commands are implemented
EndWhile

Sub ExecVirus1Command
''Find command and execute instruction relating to the command. Command modifiers and other none math related commands not yet implemented.
code = Text.GetSubText(virus1step, 1, 3)
If (code = "DAT") Then ''Check for process destruction command
winlose = "Virus 1 died"
ElseIf (code = "NOP") Then ''Check for the do nothing command
''Does nothing except let let execution of virus continue to the next address
ElseIf (code = "ADD") Then ''Check for variable adding command
''temp code till GetABValues Sub is completed
GetABValues()
''Check A and B values [debug 3 lines]
TextWindow.WriteLine("AValue = " + AValue)
TextWindow.WriteLine("BValue = " + BValue)
TextWindow.WriteLine("")
ElseIf (code = "SUB") Then ''Check for variable subtracting command
''temp code till GetABValues Sub is completed
ElseIf (code = "MUL") Then ''Check for variable multiplying command
''temp code till GetABValues Sub is completed
ElseIf (code = "DIV") Then ''Check for variable dividing command
''temp code till GetABValues Sub is completed
Else ''Catchall for unkown data
TextWindow.WriteLine("Memory Array Error: Incompatible Data: '" + virus1step + "'")
TextWindow.WriteLine("Error Causes: (Incorrect virus code) Or (Program Error).")
EndIf
EndSub

Sub GetABValues
''Get the AValue and the BValue, Also check for Type modifiers (*, #, @, etc...) for each value
i = 0
varloc = 5
''AValue retrieve
While (i <> 1)
If (Text.GetSubText(virus1step, varloc, 1) = ",") Then
i = 1
Else
AValue = Text.Append(AValue, Text.GetSubText(virus1step, varloc, 1))
EndIf
varloc = varloc + 1
EndWhile

i = 0
varloc = varloc + 1
''BValue retrieve
While (i <> 1)
If (Text.GetSubText(virus1step, varloc, 1) = "") Then
i = 1
Else
BValue = Text.Append(BValue, Text.GetSubText(virus1step, varloc, 1))
EndIf
varloc = varloc + 1
EndWhile
EndSub