Advertisement
parabuhat

DimaBIOS

Apr 14th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.05 KB | None | 0 0
  1. if isColor == false then
  2.     term.clear()
  3.     term.setCursorPos(1,1)
  4.     print("BIOS can only run on advanced/color computers!")
  5. end
  6.  
  7.  
  8. function setVariables()
  9.     width, height = term.getSize()
  10.     version = "1.1"
  11.     stopProgramPending = false
  12. end
  13. function clearScreen()
  14.     term.clear()
  15.     term.setCursorPos(1,1)
  16. end
  17. function printM(text, heightMod)
  18.     if heightMod == nil then
  19.         heightMod = 0
  20.     end
  21.    
  22.     newLen = string.len(text) / 2
  23.     newWidth = width / 2
  24.     newWidth = newWidth - newLen
  25.     newWidth = math.floor(newWidth)
  26.     term.setCursorPos(newWidth, height / 2 + heightMod)
  27.     term.write(text)
  28.     term.setCursorPos(1,1)
  29. end
  30. setVariables()
  31.  
  32. clearScreen()
  33.  
  34. term.setTextColor(colors.red)
  35. printM("DimaBIOS", -1)
  36. term.setTextColor(colors.lime)
  37. printM("Please wait", 1)
  38. term.setTextColor(colors.white)
  39. printM("Booting from Hard Drive...", 2)
  40. term.setTextColor(colors.red)
  41. printM("Fatal: No bootable device. Reboot to FizzOS", 3)
  42.  
  43. sleep(math.random(1.0,2.0))
  44.  
  45. clearScreen()
  46.  
  47. --Set this variable to how many menu items there are in total:
  48. local menuItems = 6
  49.  
  50. --Default menu item:
  51. local selectedItem = 1
  52.  
  53. -- Main Operating System Loop!
  54. menuItemsBackup = menuItems - 1
  55. clearScreen()
  56. term.setTextColor(colors.lime)
  57. print("FizzOS "..version)
  58. term.setTextColor(colors.white)
  59.  
  60.  
  61.  
  62. function menuDraw()
  63.  
  64.     clearScreen()
  65.     term.setTextColor(colors.lime)
  66.     print("DimaBIOS "..version)
  67.     term.setTextColor(colors.white)
  68.    
  69.     term.setCursorPos(3,3)
  70.     term.write("Programs")
  71.     if selectedItem == 1 then
  72.         term.setCursorPos(2,3)
  73.         term.write(">")
  74.     else
  75.         term.setCursorPos(2,3)
  76.         term.write(" ")
  77.     end
  78.     yLevel = 4
  79.    
  80.     term.setCursorPos(3,yLevel)
  81.     term.write("Terminal")
  82.     if selectedItem == 2 then
  83.         term.setCursorPos(2,yLevel)
  84.         term.write(">")
  85.     else
  86.         term.setCursorPos(2,yLevel)
  87.         term.write(" ")
  88.     end
  89.     yLevel = yLevel + 1
  90.    
  91.     term.setCursorPos(3,yLevel)
  92.     term.write("Help")
  93.     if selectedItem == 3 then
  94.         term.setCursorPos(2,yLevel)
  95.         term.write(">")
  96.     else
  97.         term.setCursorPos(2,yLevel)
  98.         term.write(" ")
  99.     end
  100.     yLevel = yLevel + 1
  101.    
  102.     term.setCursorPos(3,yLevel)
  103.     term.write("MineOS")
  104.     if selectedItem == 4 then
  105.         term.setCursorPos(2,yLevel)
  106.         term.write(">")
  107.     else
  108.         term.setCursorPos(2,yLevel)
  109.         term.write(" ")
  110.     end
  111.     yLevel = yLevel + 1
  112.    
  113.     term.setCursorPos(3,yLevel)
  114.     term.write("Shutdown")
  115.     if selectedItem == 5 then
  116.         term.setCursorPos(2,yLevel)
  117.         term.write(">")
  118.     else
  119.         term.setCursorPos(2,yLevel)
  120.         term.write(" ")
  121.     end
  122.     yLevel = yLevel + 3
  123.    
  124.     --if peripheral.getType("right") == "drive" or peripheral.getType("left") == "drive" or peripheral.getType("back") == "drive" or peripheral.getType("front") == "drive" or peripheral.getType("bottom") == "drive" or peripheral.getType("top") == "drive" then
  125.     --    showDiskdrive = true
  126.     --    menuItems = menuItemsBackup + 1
  127.     --else
  128.     --    showDiskdrive = false
  129.     --    menuItems = menuItemsBackup
  130.     --end
  131.    
  132.     showDiskdrive = false
  133.    
  134.     local tSides = rs.getSides()
  135.         for n,sSide in ipairs( tSides ) do
  136.                 if peripheral.getType(sSide) == "drive" then
  137.             disk = peripheral.wrap(sSide)
  138.             if disk.hasData() then
  139.                 sDrive = sSide
  140.                 showDiskdrive = true
  141.                 break
  142.             end
  143.                 end
  144.         end
  145.    
  146.     showModem = false
  147.         for n,sSide in ipairs( tSides ) do
  148.                 if peripheral.getType(sSide) == "modem" then
  149.             sDrive = sSide
  150.             showModem = true
  151.             break
  152.                 end
  153.         end
  154.    
  155.     if showDiskdrive == false and showModem == true then
  156.         term.setCursorPos(1,height)
  157.         term.write("You must have a floppy connected to use networking!")
  158.         showModem = false
  159.         menuItems = menuItemsBackup
  160.     end
  161.    
  162.     if showDiskdrive then
  163.         term.setCursorPos(3,yLevel)
  164.         term.write("Diskdrive")
  165.         if selectedItem == 6 then
  166.             term.setCursorPos(2,yLevel)
  167.             term.write(">")
  168.         else
  169.             term.setCursorPos(2,yLevel)
  170.             term.write(" ")
  171.         end
  172.         yLevel = yLevel + 1
  173.     end
  174.    
  175.     if showModem then
  176.         term.setCursorPos(3,yLevel)
  177.         term.write("Network")
  178.         if selectedItem == 7 then
  179.             term.setCursorPos(2,yLevel)
  180.             term.write(">")
  181.         else
  182.             term.setCursorPos(2,yLevel)
  183.             term.write(" ")
  184.         end
  185.         yLevel = yLevel + 1
  186.     end
  187.    
  188.     if showModem and showDiskdrive then
  189.         menuItems = menuItemsBackup + 2
  190.     elseif showDiskdrive or showModem then
  191.         menuItems = menuItemsBackup + 1
  192.     end
  193.     if showDiskdrive == false and showModem == true then
  194.         term.setCursorPos(1,height)
  195.         term.write("You must have a floppy connected to use networking!")
  196.         showModem = false
  197.     end
  198.    
  199.     event, parm = os.pullEvent()
  200.     parm = tostring(parm)
  201.    
  202.     if event == "key" and parm == "200" and selectedItem > 1 then
  203.         selectedItem = selectedItem - 1
  204.     end
  205.    
  206.     if event == "key" and parm == "208" and selectedItem < menuItems then
  207.         selectedItem = selectedItem + 1
  208.     end
  209.    
  210.     if event == "key" and parm == "28" then
  211.         --- Old programs menu item.
  212.         --if selectedItem == 1 then
  213.         --   clearScreen()
  214.         --    local tPrograms = shell.programs( bAll )
  215.         --    clearScreen()
  216.         --    textutils.pagedTabulate( tPrograms )
  217.         --    term.setCursorPos(1,height)
  218.         --    term.write("Press any key to continue...")
  219.         --    os.pullEvent("char")
  220.         --    clearScreen()
  221.         --end
  222.        
  223.         -- New programs menu item
  224.         if selectedItem == 1 then
  225.             clearScreen()
  226.             local programList = shell.programs()
  227.             local selectedProgram = 1
  228.             local blocked = false
  229.            
  230.             function isBlocked(programName)
  231.                 local fBlocked = false
  232.                 if programName == "alias" then
  233.                     fBlocked = true
  234.                 end
  235.                 if programName == "cd" then
  236.                     fBlocked = true
  237.                 end
  238.                 if programName == "shell" then
  239.                     fBlocked = true
  240.                 end
  241.                 if programName == "lua" then
  242.                     fBlocked = true
  243.                 end
  244.                 if programName == "clear" then
  245.                     fBlocked = true
  246.                 end
  247.                 if programName == "FizzOS" then
  248.                     fBlocked = true
  249.                 end
  250.                 if programName == "startup" then
  251.                     fBlocked = true
  252.                 end
  253.                 return fBlocked
  254.             end
  255.            
  256.             while true do
  257.                 clearScreen()
  258.                 term.setTextColor(colors.lightBlue)
  259.                 print("Programs:")
  260.                 term.setTextColor(colors.red)
  261.                 term.setCursorPos(width - string.len("Press Backspace to go back!"), 1)
  262.                 term.write("Press Backspace to go back!")
  263.                 term.setCursorPos(3,3)
  264.                 term.setTextColor(colors.purple)
  265.                 if isBlocked(programList[selectedProgram]) == false then
  266.                     term.setTextColor(colors.magenta)
  267.                 else
  268.                     term.setTextColor(colors.red)
  269.                 end
  270.                 term.write(programList[selectedProgram])
  271.                
  272.                 term.setCursorPos(5,4)
  273.                 term.setTextColor(colors.pink)
  274.                 term.write("#"..selectedProgram)
  275.                
  276.                
  277.                 event, parm = os.pullEvent()
  278.                 parm = tostring(parm)
  279.                
  280.                 if event == "key" and parm == "205" then
  281.                     if selectedProgram < table.maxn(programList) then
  282.                         selectedProgram = selectedProgram + 1
  283.                     end
  284.                 end
  285.                
  286.                 if event == "key" and parm == "203" then
  287.                     if selectedProgram > 1 then
  288.                         selectedProgram = selectedProgram - 1
  289.                     end
  290.                 end
  291.                
  292.                 if event == "key" and parm == "14" then
  293.                     clearScreen()
  294.                     break
  295.                 end
  296.                
  297.                 if event == "key" and parm == "28" and not isBlocked(programList[selectedProgram]) then
  298.                     local tArgs = {}
  299.                     local curArg = "arg"
  300.                     while not curArg == "" do
  301.                         curArg = table.remove(tArgs,1)
  302.                     end
  303.                     clearScreen()
  304.                     term.setTextColor(colors.blue)
  305.                     print("Enter arguments:")
  306.                     local input = "arg"
  307.                     while true do
  308.                         if table.maxn(tArgs) == 10 then
  309.                             term.setTextColor(colors.red)
  310.                             print("Max arguments reached! Moving on...")
  311.                             sleep(2)
  312.                             break
  313.                         end
  314.                    
  315.                         term.setTextColor(colors.white)
  316.                         input = read()
  317.                         if input == "" then
  318.                             break
  319.                         else
  320.                             table.insert(tArgs, input)
  321.                             term.setTextColor(colors.lightBlue)
  322.                             print("Next argument (enter nothing to continue)")
  323.                         end
  324.                     end
  325.                     clearScreen()
  326.                    
  327.                     term.setTextColor(colors.white)
  328.                    
  329.                     shell.run(programList[selectedProgram], tArgs[1], tArgs[2], tArgs[3], tArgs[4], tArgs[5], tArgs[6], tArgs[7], tArgs[8], tArgs[9], tArgs[10])
  330.                     term.setTextColor(colors.white)
  331.                     term.setBackgroundColor(colors.black)
  332.                     term.setCursorPos(width - string.len("Program finished! Press any key to continue!"), height)
  333.                     term.write("Program finished! Press any key to continue!")
  334.                     os.pullEvent("char")
  335.                 end
  336.                
  337.                
  338.             end
  339.         end
  340.        
  341.         if selectedItem == 2 then
  342.             clearScreen()
  343.             term.setTextColor(colors.white)
  344.             shell.run("lua")
  345.         end
  346.         if selectedItem == 4 then
  347.             clearScreen()
  348.             term.setTextColor(colors.red)
  349.             printM("Logging off to MineOS...")
  350.             sleep(math.random(1.0,2.5))
  351.             clearScreen()
  352.             term.setTextColor(colors.white)
  353.             stopProgramPending = true
  354.         end
  355.         if selectedItem == 3 then
  356.             clearScreen()
  357.             term.setTextColor(colors.cyan)
  358.             print("FizzOS & ComputerCraft Help - Credits:")
  359.             term.setTextColor(colors.white)
  360.             term.setCursorPos(1,2)
  361.             print("FizzOS by mitchfizz05 (me).")
  362.             print("ComputerCraft by Daniel (dan200). His twitter: @DanTwoHundred")
  363.             print("Some assitance in ComputerCraft by Aaron (cloudy). His twitter: @CloudHunter")
  364.             print("The community on the forums and espernet for beta testing and support.")
  365.             print("Thanks to nitrogenfingers for the paint program.")
  366.             print("Thanks to deadlystrike for hosting www.computercraft.info")
  367.             print("Thanks to Eloraam for permission to interface with Redpower2")
  368.             print("Thanks to Mojang, the Forge team, the MCP team amd the LUA team.")
  369.             clearScreen()
  370.             term.setTextColor(colors.cyan)
  371.             print("FizzOS & ComputerCraft Help - ComputerCraft:")
  372.             term.setTextColor(colors.white)
  373.             term.setCursorPos(1,2)
  374.         end
  375.         if selectedItem == 5 then
  376.             clearScreen()
  377.             term.setTextColor(colors.red)
  378.             printM("Shutting down FizzOS...")
  379.             sleep(math.random(1.0,3.0))
  380.             clearScreen()
  381.             term.setTextColor(colors.white)
  382.             os.shutdown()
  383.         end
  384.        
  385.         if selectedItem == 6 then
  386.             clearScreen()
  387.             printM("Incomplete.")
  388.             printM("Press any key", 1)
  389.             os.pullEvent("char")
  390.         end
  391.        
  392.         if selectedItem == 7 then
  393.             local tSides = rs.getSides()
  394.             for n,sSide in ipairs( tSides ) do
  395.                 if peripheral.getType(sSide) == "modem" then
  396.                     sModem = sSide
  397.                     break
  398.                 end
  399.             end
  400.            
  401.             clearScreen()
  402.             rednet.open(sModem)
  403.             rednet.broadcast("FizzOS.PING")
  404.             term.setTextColor(colors.red)
  405.             printM("Sent a ping message.", -1)
  406.             term.setTextColor(colors.lightBlue)
  407.             printM("Press any key to continue!", 1)
  408.             term.setTextColor(colors.white)
  409.             sText = "More networking funtionality coming soon!"
  410.             term.setCursorPos(width - string.len(sText), height)
  411.             term.write(sText)
  412.             os.pullEvent("char")
  413.             rednet.close(sModem)
  414.         end
  415.        
  416.     end
  417.    
  418. end
  419.  
  420. function drawMenu_extras()
  421.     timeString = textutils.formatTime(os.time(), false)
  422.     oldX, oldY = term.getCursorPos()
  423.     term.setCursorPos(width - string.len(timeString), height)
  424.     term.write(timeString)
  425. end
  426.  
  427. while true do
  428.    
  429.     ------- Can't work out the parallel API properly. :( -------
  430.  
  431.     --parallel.waitForAll(menuDraw(), drawMenu_extras())
  432.     --if stopProgramPending == true then
  433.     --    break
  434.     --end
  435.    
  436.     menuDraw()
  437.     if stopProgramPending == true then
  438.         break
  439.     end
  440.    
  441.     --drawMenu_extras()
  442. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement