# This script can be used to generate a VMWare Virtual Machine Image

# Path: In this example, the destination path for the object files and all files generated (ZIP, IMG) is ../Test/.
# This folder must exist. You can change it by search all occurences of "../Test/" and replace them by your preferred path..

# Step 1: Compile modules and generate ZIP packages

Release.Build --path="../Test/" --build --zip A2 ~

# Step 2: Generate disk image & A2VM.zip file

SystemTools.DoCommands

	SystemTools.Show Generating A2 disk image... ~ SystemTools.Ln ~
	SystemTools.Timer start ~

	VirtualDisks.Create ../Test/A2HDD.img 204624 512~
	VirtualDisks.Install VDISK0 ../Test/A2HDD.img ~

	Linker.Link \P../Test/ \.Obx ../Test/IDE.Bin 0100000H 1000H Kernel Traps
		ATADisks DiskVolumes DiskFS Loader BootConsole ~

	Partitions.WriteMBR VDISK0#0 OBEMBR.Bin ~
	Partitions.InstallBootManager VDISK0#0 ~
	Partitions.Create VDISK0#1 76 9999 ~
	Partitions.Format VDISK0#1 AosFS 1024 ../Test/IDE.Bin ~

	FSTools.Mount VDISK AosFS VDISK0#1 ~

	ZipTool.ExtractAll --prefix=VDISK: --sourcePath=../Test/ --overwrite --silent
		Kernel.zip System.zip Drivers.zip ApplicationsMini.zip Applications.zip
		Compiler.zip GuiApplicationsMini.zip GuiApplications.zip Fun.zip Contributions.zip Build.zip EFI.zip

		KernelSrc.zip SystemSrc.zip DriversSrc.zip ApplicationsMiniSrc.zip ApplicationsSrc.zip
		CompilerSrc.zip GuiApplicationsMiniSrc.zip GuiApplicationsSrc.zip FunSrc.zip ContributionsSrc.zip BuildSrc.zip EFISrc.zip

		ScreenFonts.zip CjkFonts.zip TrueTypeFonts.zip
	~

	FSTools.Watch VDISK ~
	FSTools.Unmount VDISK ~

	Partitions.SetConfig VDISK0#1
		BootVol1="AOS AosFS IDE0#1"
		AosFS="DiskVolumes.New DiskFS.NewFS"
		Boot="DisplayLinear.Install"
		Boot1="Keyboard.Install;MousePS2.Install"
		Boot2="WindowManager.Install"
		Boot3="AM79C970.Install;InitNetwork.Init"
		Boot4="Autostart.Run"
		Boot5="VMWareTools.Install"
		TraceMode="4"
		TracePort="1"
		TraceBPS="115200"
		Init="117"
		CacheSize="1000"
	~

	VirtualDisks.Uninstall VDISK0 ~

	FSTools.CreateFile -c -r ../Test/a2.vmx
		config.version = "8"
		virtualHW.version = "6"
		scsi0.present = "TRUE"
		memsize = "256"
		ide0:0.present = "TRUE"
		ide0:0.fileName = "a2.vmdk"
		ide1:0.present = "TRUE"
		ide1:0.fileName = "auto detect"
		ide1:0.deviceType = "cdrom-raw"
		ide1:0.autodetect = "TRUE"
		ethernet0.present = "TRUE"
		ethernet0.wakeOnPcktRcv = "FALSE"
		svga.autodetect = "TRUE"
		pciBridge0.present = "TRUE"
		mks.keyboardFilter = "allow"
		displayName = "A2"
		guestOS = "win95"
		nvram = "Windows 95.nvram"
		deploymentPlatform = "windows"
		virtualHW.productCompatibility = "hosted"
		tools.upgrade.policy = "useGlobal"

		extendedConfigFile = "Windows 95.vmxf"

		ethernet0.addressType = "generated"
		uuid.location = "56 4d 08 e1 a6 3b 8b a6-a7 94 60 15 67 22 e5 cb"
		uuid.bios = "56 4d 08 e1 a6 3b 8b a6-a7 94 60 15 67 22 e5 cb"
		ide0:0.redo = ""
		pciBridge0.pciSlotNumber = "17"
		scsi0.pciSlotNumber = "16"
		ethernet0.pciSlotNumber = "32"
		sound.pciSlotNumber = "-1"
		ethernet0.generatedAddress = "00:0c:29:22:e5:cb"
		ethernet0.generatedAddressOffset = "0"

		sound.present = "FALSE"

		floppy0.present = "FALSE"
		floppy0.autodetect = "FALSE"

		serial0.present = "TRUE"
		serial0.fileType = "file"
		serial0.fileName = "a2serialport.txt"
	~

	FSTools.CreateFile -c -r ../Test/A2.vmdk
		# Disk DescriptorFile
		version=1
		CID=c201f407
		parentCID=ffffffff
		createType="monolithicFlat"

		# Extent description
		RW 204624 FLAT "A2HDD.img" 0

		# The Disk Data Base
		#DDB
		ddb.virtualHWVersion = "6"
		ddb.geometry.cylinders = "203"
		ddb.geometry.heads = "16"
		ddb.geometry.sectors = "63"
		ddb.adapterType = "ide"
	~
	FSTools.CreateFile -c -r ../Test/bochsrc.bxrc
		# configuration file generated by Bochs
		plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, gameport=1, pci_ide=1, acpi=1, ioapic=1
		config_interface: win32config
		display_library: win32
		memory: host=32, guest=32
		romimage: file="C:\Program Files (x86)\Bochs-2.4.6/BIOS-bochs-latest"
		vgaromimage: file="C:\Program Files (x86)\Bochs-2.4.6/VGABIOS-lgpl-latest"
		boot: disk
		floppy_bootsig_check: disabled=0
		# no floppya
		# no floppyb
		ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
		ata0-master: type=disk, mode=flat, translation=auto, path="E:\felix.svn\Test\A2HDD.img", cylinders=203, heads=16, spt=63, biosdetect=auto, model="Generic 1234"
		ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
		ata2: enabled=0
		ata3: enabled=0
		parport1: enabled=1, file=""
		parport2: enabled=0
		com1: enabled=1, mode=null, dev=""
		com2: enabled=0
		com3: enabled=0
		com4: enabled=0
		usb_uhci: enabled=0
		usb_ohci: enabled=0
		i440fxsupport: enabled=1
		vga_update_interval: 50000
		vga: extension=vbe
		cpu: count=1, ips=4000000, reset_on_triple_fault=1, ignore_bad_msrs=1
		cpuid: cpuid_limit_winnt=0, mmx=1, sse=sse2, xapic=1, sep=1, aes=0, xsave=0, movbe=0, 1g_pages=0, pcid=0 fsgsbase=0
		cpuid: stepping=3, vendor_string="GenuineIntel", brand_string="              Intel(R) Pentium(R) 4 CPU        "
		print_timestamps: enabled=0
		port_e9_hack: enabled=0
		text_snapshot_check: enabled=0
		private_colormap: enabled=0
		clock: sync=none, time0=local
		# no cmosimage
		ne2k: enabled=0
		pnic: enabled=0
		sb16: enabled=0
		# no loader
		log: -
		logprefix: %t%e%d
		panic: action=ask
		error: action=report
		info: action=report
		debug: action=ignore
		pass: action=fatal
		keyboard_type: mf
		keyboard_serial_delay: 250
		keyboard_paste_delay: 100000
		keyboard_mapping: enabled=0, map=
		user_shortcut: keys=none
		mouse: enabled=0, type=ps2, toggle=ctrl+mbutton
	~
	
	FSTools.CreateFile -c -r ../Test/A2qemu.bat
		qemu -hda A2HDD.img -serial file:a2serialport.txt
	~

	FSTools.DeleteFiles ../Test/A2VM.zip ~

	ZipTool.Add --nopath ../Test/A2VM.zip
		../Test/A2.vmx ../Test/A2.vmdk ../Test/A2HDD.img ../Test/A2qemu.bat ../Test/bochsr.bxrc
	~

	SystemTools.Ln ~
	SystemTools.Show Generated A2 HDD image ../Test/A2VM.zip ~ SystemTools.Ln ~

	SystemTools.Show HDD image build time:  ~ SystemTools.Timer elapsed ~
	SystemTools.Ln ~
~

# Step 3 (optional): Generate FAT32 formatted disk image

SystemTools.DoCommands

	SystemTools.Show Generating FAT32 disk image... ~ SystemTools.Ln ~
	SystemTools.Timer start ~

	VirtualDisks.Create ../Test/FATHDD.img 200000 512~
	VirtualDisks.Install VDISK1 ../Test/FATHDD.img ~

	Partitions.WriteMBR VDISK1#0 OBEMBR.Bin ~
	Partitions.Create VDISK1#1 12 9999 ~
	Partitions.Format VDISK1#1 FatFS ~

	VirtualDisks.Uninstall VDISK1 ~


	FSTools.CreateFile -c -r ../Test/fat.vmdk
		# Disk DescriptorFile
		version=1
		CID=c201f407
		parentCID=ffffffff
		createType="monolithicFlat"

		# Extent description
		RW 200000 FLAT "FATHDD.img" 0

		# The Disk Data Base
		#DDB
		ddb.virtualHWVersion = "6"
		ddb.geometry.cylinders = "208"
		ddb.geometry.heads = "16"
		ddb.geometry.sectors = "63"
		ddb.adapterType = "ide"
	~

	FSTools.CreateFile -c -r ../Test/a2.vmx
		config.version = "8"
		virtualHW.version = "6"
		scsi0.present = "TRUE"
		memsize = "256"
		ide0:0.present = "TRUE"
		ide0:0.fileName = "a2.vmdk"
		ide0:1.present = "TRUE"
		ide0:1.fileName = "fat.vmdk"
		ide1:0.present = "TRUE"
		ide1:0.fileName = "auto detect"
		ide1:0.deviceType = "cdrom-raw"
		ide1:0.autodetect = "TRUE"
		ethernet0.present = "TRUE"
		ethernet0.wakeOnPcktRcv = "FALSE"
		svga.autodetect = "TRUE"
		pciBridge0.present = "TRUE"
		mks.keyboardFilter = "allow"
		displayName = "A2"
		guestOS = "win95"
		nvram = "Windows 95.nvram"
		deploymentPlatform = "windows"
		virtualHW.productCompatibility = "hosted"
		tools.upgrade.policy = "useGlobal"

		extendedConfigFile = "Windows 95.vmxf"

		ethernet0.addressType = "generated"
		uuid.location = "56 4d 08 e1 a6 3b 8b a6-a7 94 60 15 67 22 e5 cb"
		uuid.bios = "56 4d 08 e1 a6 3b 8b a6-a7 94 60 15 67 22 e5 cb"
		ide0:0.redo = ""
		pciBridge0.pciSlotNumber = "17"
		scsi0.pciSlotNumber = "16"
		ethernet0.pciSlotNumber = "32"
		sound.pciSlotNumber = "-1"
		ethernet0.generatedAddress = "00:0c:29:22:e5:cb"
		ethernet0.generatedAddressOffset = "0"

		sound.present = "FALSE"

		floppy0.present = "FALSE"
		floppy0.autodetect = "FALSE"

		serial0.present = "TRUE"
		serial0.fileType = "file"
		serial0.fileName = "a2serialport.txt"
	~

	ZipTool.Delete ../Test/A2VM.zip A2.vmx ~

	ZipTool.Add --nopath ../Test/A2VM.zip
		../Test/A2.vmx
	~

	SystemTools.Ln ~
	SystemTools.Show Generated A2 HDD image ../Test/A2VM.zip ~ SystemTools.Ln ~

	SystemTools.Show HDD image build time:  ~ SystemTools.Timer elapsed ~
	SystemTools.Ln ~
~~~