Lua 5.3 didn't need an x86 emulator. But now, it has one regardless.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lunatic86.lua 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. local args = {...}
  2. local argp = {}
  3. local drive_map = {["a"]=0x00,["b"]=0x01,["c"]=0x80,["d"]=0x81,["e"]=0x82,["f"]=0x83}
  4. function has_module(m)
  5. res = pcall(function()
  6. require(m)
  7. end)
  8. if res then return true else return false end
  9. end
  10. local is_opencomputers = has_module("component")
  11. -- defaults
  12. argp["boot"] = "a"
  13. argp["mempack"] = 0
  14. argp["arch"] = "8086"
  15. if is_opencomputers then
  16. argp["mempack"] = 3
  17. if (1<<62) == 0 then argp["mempack"] = 2 end
  18. end
  19. for i=1,#args do
  20. local a = args[i]
  21. if a:sub(1,1) == "-" then
  22. local key = a:sub(2)
  23. local value = ((i + 1) <= #args) and args[i + 1] or "-"
  24. if value:sub(1,1) == "-" then
  25. argp[key] = true
  26. else
  27. i = i + 1
  28. argp[key] = value
  29. end
  30. end
  31. end
  32. if argp["h"] or argp["help"] then
  33. print("lunatic86 CPU emulator (0.1.1)")
  34. print("Usage: lunatic86 [args]")
  35. print(" -boot [drive] Boot from the given drive: a, b, c, d, e, f")
  36. print(" -[drive] [filename] Initialize a given drive letter from a specified file")
  37. print(" -mempack [0,1,2,3] Set the memory packing level. 0 is fastest; 3 requires")
  38. print(" 64-bit Lua and is about 10% slower; 2 requires only")
  39. print(" 32-bit Lua but is a few percent slower still.")
  40. print(" -arch [arch] Set the CPU architecture emulated. Supported:")
  41. print(" 8086 - 8086-compatible CPU")
  42. print(" 80186 - 80186-compatible CPU, work in progress!")
  43. os.exit()
  44. end
  45. if argp[argp["boot"]] == nil then
  46. print("Error: Did not find file for boot drive!")
  47. print("See 'lunatic86 -h' for usage.")
  48. os.exit()
  49. end
  50. reduced_memory_mode = math.floor(tonumber(argp["mempack"]))
  51. memory_preallocate = false
  52. cpu_arch = argp["arch"]
  53. if is_opencomputers then
  54. local shell = require("shell")
  55. local filesystem = require("filesystem")
  56. if filesystem.exists("emu_core.lua") then
  57. dofile("platform_oc.lua")
  58. else
  59. local cwd = shell.getWorkingDirectory()
  60. if filesystem.exists("/usr/lib/lunatic86/emu_core.lua") then
  61. shell.setWorkingDirectory("/usr/lib/lunatic86")
  62. elseif filesystem.exists("/lib/lunatic86/emu_core.lua") then
  63. shell.setWorkingDirectory("/lib/lunatic86")
  64. end
  65. dofile("platform_oc.lua")
  66. shell.setWorkingDirectory(cwd)
  67. end
  68. else
  69. dofile("platform_curses.lua")
  70. end
  71. for dk,did in pairs(drive_map) do
  72. if argp[dk] then
  73. disk_init(argp[dk],did)
  74. end
  75. end
  76. disk_boot(drive_map[argp["boot"]])
  77. xpcall(function()
  78. emu_execute()
  79. end, function(err)
  80. platform_error(err)
  81. end)
  82. platform_finish()