Rev 9377 | Rev 9382 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9367 | Boppan | 1 | import os |
2 | import sys |
||
9368 | Boppan | 3 | import shlex |
9367 | Boppan | 4 | import shutil |
5 | import urllib.request |
||
6 | import subprocess |
||
7 | |||
9374 | Boppan | 8 | path_to_tools_workspace = os.path.dirname(os.path.abspath(__file__)) |
9 | path_to_tools = os.path.dirname(path_to_tools_workspace) |
||
9370 | Boppan | 10 | sys.path.append(path_to_tools) |
9367 | Boppan | 11 | |
9374 | Boppan | 12 | from workspace.build import build |
13 | |||
9370 | Boppan | 14 | from lib.makeflop import Floppy |
15 | from lib.platform import is_win32, path |
||
16 | from lib.logging import log |
||
17 | from lib.network import download |
||
9367 | Boppan | 18 | |
19 | # TODO: Move into _tools/lib |
||
20 | def run_qemu(start_dir = "workspace"): |
||
21 | qemu_command = f"qemu-system-i386" |
||
22 | flags = "" |
||
23 | flags += "-L . " # IDK why it does not work without this |
||
24 | flags += "-m 128 " |
||
25 | flags += f"-drive format=raw,file={start_dir}/kolibri.img,index=0,if=floppy -boot a " |
||
26 | flags += "-vga vmware " |
||
27 | flags += "-net nic,model=rtl8139 -net user " |
||
28 | flags += "-soundhw ac97 " |
||
29 | if is_win32(): |
||
30 | qemu_full_path = shutil.which(qemu_command) |
||
9381 | Boppan | 31 | qemu_directory = os.path.dirname(qemu_full_path) |
9367 | Boppan | 32 | flags += f"-L {qemu_directory} " |
33 | s = f"{qemu_command} {flags}" |
||
34 | qemu_stdout = open(f"{start_dir}/qemu_stdout.log", "w") |
||
35 | qemu_stderr = open(f"{start_dir}/qemu_stderr.log", "w") |
||
36 | if is_win32(): |
||
37 | return subprocess.Popen(s, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, shell = True, start_new_session = True) |
||
38 | else: |
||
39 | a = shlex.split(s) |
||
40 | return subprocess.Popen(a, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, start_new_session = True) |
||
41 | |||
42 | if __name__ == "__main__": |
||
9377 | Boppan | 43 | program_name = build() |
9367 | Boppan | 44 | |
45 | os.makedirs("workspace", exist_ok = True) |
||
46 | |||
9373 | Boppan | 47 | if not os.path.exists("workspace/kolibri.unmodified.img"): |
9367 | Boppan | 48 | img_url = "http://builds.kolibrios.org/eng/data/data/kolibri.img" |
9373 | Boppan | 49 | download(img_url, "workspace/kolibri.unmodified.img") |
9367 | Boppan | 50 | |
9373 | Boppan | 51 | # Create a copy of IMG |
52 | shutil.copyfile("workspace/kolibri.unmodified.img", "workspace/kolibri.img") |
||
53 | |||
9367 | Boppan | 54 | # Open the IMG |
55 | with open("workspace/kolibri.img", "rb") as img: |
||
56 | img_data = img.read() |
||
57 | img = Floppy(img_data) |
||
58 | |||
59 | # Remove unuseful folders |
||
60 | img.delete_path("GAMES") |
||
61 | img.delete_path("DEMOS") |
||
62 | img.delete_path("3D") |
||
63 | |||
9377 | Boppan | 64 | log("Moving program into kolibri image... ", end = "") |
65 | with open(program_name, "rb") as file: |
||
66 | file_data = file.read() |
||
67 | if not img.add_file_path(program_name.upper(), file_data): |
||
68 | print(f"Coudn't move {program_name} into IMG") |
||
9367 | Boppan | 69 | log("Done") |
70 | |||
9373 | Boppan | 71 | # TODO: Figure out which of compiled files is a program executable and only run it |
9377 | Boppan | 72 | log("Adding program to autorun.dat... ", end = "") |
73 | lines_to_add = bytes(f"\r\n/SYS/{program_name.upper()}\t\t""\t0\t# Your program", "ascii") |
||
9373 | Boppan | 74 | autorun_dat = img.extract_file_path("SETTINGS\AUTORUN.DAT") |
75 | place_for_new_lines = autorun_dat.index(b"\r\n/SYS/@TASKBAR")# b"\r\n### Hello, ASM World! ###") |
||
76 | autorun_dat = autorun_dat[:place_for_new_lines] + lines_to_add + autorun_dat[place_for_new_lines:] |
||
77 | img.delete_path("SETTINGS\AUTORUN.DAT") |
||
78 | img.add_file_path("SETTINGS\AUTORUN.DAT", autorun_dat) |
||
79 | log("Done") |
||
80 | |||
81 | img.save("workspace/kolibri.img") |
||
82 | |||
9367 | Boppan | 83 | run_qemu() |