Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Mobile OS --
- -- Koga --
- -- Episode 8 Youkoso -- (ignore this... it's an easter egg)
- local isMobile = (mobile ~= nil)
- local native = term.current()
- local resizing = true
- local MOS_dir = "/MOS"
- --[[
- Mobile (Normal) -> 44,55
- Mobile (Flipped) -> 86, 27
- --]]
- local function getSize() return term.getSize() end
- local w,h = getSize()
- if w < 30 and h < 30 then return error("Screen size too small: 30x30 minimum (yours:"..w.."x"..h..")") end
- local main = window.create(term.current(), 1,1,w,h) term.redirect(main)
- local app_screen = {
- display = window.create(term.current(), 5,5,w-6,(h/1.5)-6),
- mode = 3,
- defaults = {
- x=1, y=1,
- w=w, h=math.floor(h/1.5)-6,
- },
- extended = {
- x=1, y=1,
- w=w, h=h-4,
- }
- }
- local clr, cp, st, sb = term.clear, term.setCursorPos, term.setTextColor, term.setBackgroundColor
- local apps = {
- screen = 1,
- screen_length = 0,
- screen_height = 0,
- screen_length_limit = 10,
- screen_height_limit = 10,
- icons = {
- ["phone_logo"] = {{0,0,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768},{0,32768,1,1,1,256,256,256,256,256,256,256,256,256,256,128,128,128,32768},{32768,1,1,1,1,256,256,256,32768,32768,32768,32768,256,256,256,128,128,128,128,32768},{32768,1,1,1,1,256,256,256,256,256,256,256,256,256,256,128,128,128,128,32768},{32768,1,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32768,128,32768},{32768,1,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,32768},{32768,1,1,1,256,256,256,256,256,256,256,256,256,256,256,256,128,128,128,32768},{32768,1,1,1,256,256,256,256,32768,32768,32768,256,256,256,256,256,128,128,128,32768},{32768,1,1,1,256,256,256,256,32768,256,32768,256,256,256,256,256,128,128,128,32768},{32768,1,1,1,256,256,256,256,32768,32768,32768,256,256,256,256,256,128,128,128,32768},{0,32768,1,1,256,256,256,256,256,256,256,256,256,256,256,256,128,128,32768},{0,0,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768},{}},
- ["no_app_icon"] = {{0,0,256,256,256,256,256,256,256,256,256,256,256},{0,256,128,128,128,128,128,128,128,128,128,128,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{256,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,256},{0,256,128,128,128,128,128,128,128,128,128,128,128,256},{0,0,256,256,256,256,256,256,256,256,256,256,256},{}},
- ["arrow_up"] = {{0,0,0,128},{0,0,128,256,128},{0,128,256,256,256,128},{128,256,256,256,256,256,128},{}},
- ["arrow_down"] = {{128,256,256,256,128},{0,128,256,128},{0,0,128},{}},
- ["scroll_left"] = {{128},{256,128},{256,128},{256,128},{128},{}},
- ["scroll_right"] = {{0,128},{128,256},{128,256},{128,256},{0,128},{}},
- ["dpad_arrow_up"] = {{0,128,128},{128,256,256,128},{128,256,256,128},{}},
- ["dpad_arrow_down"] = {{128,256,256,128},{128,256,256,128},{0,128,128},{}},
- ["dpad_arrow_left"] = {{0,128,128},{128,256,256},{128,256,256},{0,128,128},{}},
- ["dpad_arrow_right"] = {{128,128},{256,256,128},{256,256,128},{128,128},{}},
- ["dpad_button_center"] = {{0,128,128},{128,256,256,128},{128,256,256,128},{0,128,128},{}},
- ["button_function"] = {{0,128,128,128},{128,256,256,256,128},{0,128,128,128},{}}, -- Enter / Ctrl
- ["button_power"] = {{16384},{16384,16384},{16384,16384,16384},{}},
- ["button_a"] = {{0,8192,8192,8192},{8192,32,32,32,8192},{8192,32,32,32,8192},{8192,32,32,32,8192},{0,8192,8192,8192},{}},
- ["button_b"] = {{0,1024,1024,1024},{1024,4,4,4,1024},{1024,4,4,4,1024},{1024,4,4,4,1024},{0,1024,1024,1024},{}},
- ["app_icon_missing"] = {{0,0,128,128,128,128,128,128,128,128,128,128,128},{0,128,128,256,256,256,256,256,256,256,256,256,128,128},{128,128,256,256,256,256,256,256,256,256,256,256,256,128,128},{128,256,256,256,256,256,256,256,256,256,256,256,256,256,128},{128,256,256,256,128,128,128,128,128,128,128,256,256,256,128},{128,256,256,128,16384,16384,128,128,128,16384,16384,128,256,256,128},{128,256,256,128,16384,128,16384,128,16384,128,16384,128,256,256,128},{128,256,256,128,16384,128,16384,128,16384,128,16384,128,256,256,128},{128,256,256,128,16384,128,128,16384,128,128,16384,128,256,256,128},{128,256,256,128,16384,128,128,128,128,128,16384,128,256,256,128},{128,256,256,256,128,128,128,128,128,128,128,256,256,256,128},{128,256,256,256,256,256,256,256,256,256,256,256,256,256,128},{128,128,256,256,256,256,256,256,256,256,256,256,256,128,128},{0,128,128,256,256,256,256,256,256,256,256,256,128,128},{0,0,128,128,128,128,128,128,128,128,128,128,128},{}},
- ["app_icon_invalid"] = {{0,0,128,128,128,128,128,128,128,128,128,128,128},{0,128,128,256,256,256,256,256,256,256,256,256,128,128},{128,128,256,256,256,256,256,256,256,256,256,256,256,128,128},{128,256,256,256,256,256,256,256,256,256,256,256,256,256,128},{128,256,256,256,128,128,128,128,128,128,128,256,256,256,128},{128,256,256,128,128,16384,16384,16384,16384,16384,128,128,256,256,128},{128,256,256,128,128,128,128,16384,128,128,128,128,256,256,128},{128,256,256,128,128,128,128,16384,128,128,128,128,256,256,128},{128,256,256,128,128,128,128,16384,128,128,128,128,256,256,128},{128,256,256,128,128,16384,16384,16384,16384,16384,128,128,256,256,128},{128,256,256,256,128,128,128,128,128,128,128,256,256,256,128},{128,256,256,256,256,256,256,256,256,256,256,256,256,256,128},{128,128,256,256,256,256,256,256,256,256,256,256,256,128,128},{0,128,128,256,256,256,256,256,256,256,256,256,128,128},{0,0,128,128,128,128,128,128,128,128,128,128,128},{}},
- ["app_icon_template"] = {{0,0,128,128,128,128,128,128,128,128,128,128,128,},{0,128,128,0,0,0,0,0,0,0,0,0,128,128,},{128,128,0,0,0,0,0,0,0,0,0,0,0,128,128,},{128,0,0,0,0,0,0,0,0,0,0,0,0,0,128,},{128,0,0,0,0,0,0,0,0,0,0,0,0,0,128,},{128,0,0,0,0,0,0,0,0,0,0,0,0,0,128,},{128,0,0,0,0,0,0,0,0,0,0,0,0,0,128,},{128,0,0,0,0,0,0,0,0,0,0,0,0,0,128,},{128,0,0,0,0,0,0,0,0,0,0,0,0,0,128,},{128,0,0,0,0,0,0,0,0,0,0,0,0,0,128,},{128,0,0,0,0,0,0,0,0,0,0,0,0,0,128,},{128,0,0,0,0,0,0,0,0,0,0,0,0,0,128,},{128,128,0,0,0,0,0,0,0,0,0,0,0,128,128,},{0,128,128,0,0,0,0,0,0,0,0,0,128,128,},{0,0,128,128,128,128,128,128,128,128,128,128,128,},{},},
- },
- size = {18,18}, real_app_size = {15,16},
- ["invalid_app"] = {
- name = "Invalid App",
- --icon = {{0,0,2,2,2,2,2,2,2,2,2,2,2},{0,2,16,16,16,16,16,16,16,16,16,16,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,1,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,1,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,1,32768,32768,1,1,1,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{0,2,16,16,16,16,16,16,16,16,16,16,16,2},{0,0,2,2,2,2,2,2,2,2,2,2,2},{}},
- --exe = "",
- extendable = false,
- extended = false,
- },
- ["shell"] = {
- name = "Shell",
- icon = {{0,0,2,2,2,2,2,2,2,2,2,2,2},{0,2,16,16,16,16,16,16,16,16,16,16,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,1,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,1,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,1,32768,32768,1,1,1,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{2,16,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,16,2},{0,2,16,16,16,16,16,16,16,16,16,16,16,2},{0,0,2,2,2,2,2,2,2,2,2,2,2},{}},
- exe = "rom/programs/shell.lua",
- extendable = true,
- extended = false,
- },
- ["lua"] = {
- name = "Lua",
- icon = {{0,0,128,128,128,128,128,128,128,128,128,128,128},{0,128,1,1,1,1,1,1,1,1,1,1,1,128},{128,1,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,1,128},{128,1,32768,1,32768,32768,32768,32768,32768,32768,32768,32768,32768,1,128},{128,1,32768,32768,1,32768,32768,32768,32768,32768,32768,32768,32768,1,128},{128,1,32768,1,32768,32768,1,1,1,32768,32768,32768,32768,1,128},{128,1,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,1,128},{128,1,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,1,128},{128,1,32768,128,32768,128,32768,128,32768,128,128,128,32768,1,128},{128,1,32768,128,32768,128,32768,128,32768,128,32768,128,32768,1,128},{128,1,32768,128,32768,128,32768,128,32768,128,128,128,32768,1,128},{128,1,32768,128,32768,128,128,128,32768,128,32768,128,32768,1,128},{128,1,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,1,128},{0,128,1,1,1,1,1,1,1,1,1,1,1,128},{0,0,128,128,128,128,128,128,128,128,128,128,128},{}},
- exe = "rom/programs/lua.lua",
- extendable = true,
- extended = false,
- },
- ["taskmngr"] = {
- name = "Task Manager",
- icon = {{0,0,128,128,128,128,128,128,128,128,128,128,128},{0,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128},{128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128},{128,32768,32768,16384,32768,32768,32768,32,32768,32768,32768,2048,32768,32768,128},{128,32768,32768,16384,32768,32768,256,256,256,32768,32768,2048,32768,32768,128},{128,32768,32768,16384,32768,32768,256,256,256,32768,32768,2048,32768,32768,128},{128,32768,32768,16384,32768,32768,32768,32,32768,32768,32768,2048,32768,32768,128},{128,32768,256,256,256,32768,32768,32,32768,32768,32768,2048,32768,32768,128},{128,32768,256,256,256,32768,32768,32,32768,32768,32768,2048,32768,32768,128},{128,32768,32768,16384,32768,32768,32768,32,32768,32768,256,256,256,32768,128},{128,32768,32768,16384,32768,32768,32768,32,32768,32768,256,256,256,32768,128},{128,32768,32768,16384,32768,32768,32768,32,32768,32768,32768,2048,32768,32768,128},{128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128},{0,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128},{0,0,128,128,128,128,128,128,128,128,128,128,128},{}},
- exe = "",
- extendable = true,
- extended = false,
- },
- ["updater"] = {
- name = "Updater",
- icon = {{0,0,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048},{0,2048,2048,256,256,256,256,256,256,256,256,256,2048,2048},{2048,2048,256,256,1,1,1,1,1,1,1,256,256,2048,2048},{2048,256,256,1,1,1,1,32,1,1,1,1,256,256,2048},{2048,256,1,1,1,1,32,32,32,1,1,1,1,256,2048},{2048,256,1,1,1,32,32,32,32,32,1,1,1,256,2048},{2048,256,1,1,32,32,32,32,32,32,32,1,1,256,2048},{2048,256,1,1,1,1,32,32,32,1,1,1,1,256,2048},{2048,256,1,1,1,1,32,32,32,1,1,1,1,256,2048},{2048,256,1,1,1,1,32,32,32,1,1,1,1,256,2048},{2048,256,1,1,1,1,32,32,32,1,1,1,1,256,2048},{2048,256,256,1,1,1,32,32,32,1,1,1,256,256,2048},{2048,2048,256,256,1,1,1,1,1,1,1,256,256,2048,2048},{0,2048,2048,256,256,256,256,256,256,256,256,256,2048,2048},{0,0,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048},{}},
- exe = "",
- extendable = false,
- extended = false,
- },
- ["power"] = {
- name = "Power",
- icon = {{0,0,0,128,128,128,128,128,128,128,128,128},{0,0,128,256,256,256,256,256,256,256,256,256,128},{0,128,256,16384,16384,16384,16384,16384,16384,16384,16384,16384,256,128},{128,256,16384,16384,16384,16384,16384,1,16384,16384,16384,16384,16384,256,128},{128,256,16384,16384,1,1,16384,1,16384,1,1,16384,16384,256,128},{128,256,16384,1,1,16384,16384,1,16384,16384,1,1,16384,256,128},{128,256,16384,1,16384,16384,16384,1,16384,16384,16384,1,16384,256,128},{128,256,16384,1,16384,16384,16384,16384,16384,16384,16384,1,16384,256,128},{128,256,16384,1,16384,16384,16384,16384,16384,16384,16384,1,16384,256,128},{128,256,16384,1,16384,16384,16384,16384,16384,16384,16384,1,16384,256,128},{128,256,16384,1,1,16384,16384,16384,16384,16384,1,1,16384,256,128},{128,256,16384,16384,1,1,1,1,1,1,1,16384,16384,256,128},{0,128,256,16384,16384,16384,16384,16384,16384,16384,16384,16384,256,128},{0,0,128,256,256,256,256,256,256,256,256,256,128},{0,0,0,128,128,128,128,128,128,128,128,128},{}},
- exe = "",
- extendable = false,
- extended = false,
- },
- ["reboot"] = {
- name = "Reboot",
- icon = {{0,0,0,128,128,128,128,128,128,128,128,128},{0,0,128,256,256,256,256,256,256,256,256,256,128},{0,128,256,8192,8192,8192,8192,8192,8192,8192,8192,8192,256,128},{128,256,8192,8192,8192,8192,8192,1,8192,8192,8192,8192,8192,256,128},{128,256,8192,8192,1,1,8192,1,8192,1,1,8192,8192,256,128},{128,256,8192,1,1,8192,8192,1,8192,8192,1,1,8192,256,128},{128,256,8192,1,8192,8192,8192,1,8192,8192,8192,1,8192,256,128},{128,256,8192,1,8192,8192,8192,8192,8192,8192,8192,1,8192,256,128},{128,256,8192,1,8192,8192,8192,8192,8192,8192,8192,1,8192,256,128},{128,256,8192,1,8192,8192,8192,8192,8192,8192,8192,1,8192,256,128},{128,256,8192,1,1,8192,8192,8192,8192,8192,1,1,8192,256,128},{128,256,8192,8192,1,1,1,1,1,1,1,8192,8192,256,128},{0,128,256,8192,8192,8192,8192,8192,8192,8192,8192,8192,256,128},{0,0,128,256,256,256,256,256,256,256,256,256,128},{0,0,0,128,128,128,128,128,128,128,128,128},{}},
- exe = "",
- extendable = false,
- extended = false,
- },
- ["worm"] = {
- name = "Worm",
- icon = {{0,0,128,128,128,128,128,128,128,128,128,128,128},{0,128,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,128},{128,128,32768,16384,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,128},{128,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,32768,128},{128,32768,32768,8192,32768,32768,32768,32768,32768,32768,32768,8192,32768,32768,128},{128,32768,32768,8192,32768,32768,32768,32768,32768,32768,32768,8192,32768,32768,128},{128,32768,32768,8192,32768,32768,32768,32768,32768,32768,32768,8192,32768,32768,128},{128,32768,32768,8192,32768,32768,32768,32768,32768,32768,32768,8192,32768,32768,128},{128,32768,32768,8192,32768,32768,8192,8192,8192,32768,32768,8192,32768,32768,128},{128,32768,32768,8192,32768,32768,8192,32768,8192,32768,32768,8192,32768,32768,128},{128,32768,32768,8192,32768,32768,8192,32768,8192,32768,32768,8192,32768,32768,128},{128,32768,32768,8192,8192,8192,8192,32768,8192,8192,8192,8192,32768,32768,128},{128,128,32768,32768,32768,32768,32768,32768,32768,16384,32768,32768,32768,128,128},{0,128,128,32768,32768,32768,32768,32768,32768,32768,32768,32768,128,128},{0,0,128,128,128,128,128,128,128,128,128,128,128},{}},
- exe = "rom/programs/fun/worm.lua",
- extendable = false,
- extended = false,
- },
- ["events"] = {
- name = "Events",
- icon = {{0,0,128,128,128,128,128,128,128,128,128,128,128},{0,128,128,256,256,256,256,256,256,256,256,256,128,128},{128,128,256,256,128,128,128,128,128,128,128,256,256,128,128},{128,256,256,1,1,1,1,1,1,1,1,1,256,256,128},{128,256,128,1,1,1,1,1,1,1,1,128,128,256,128},{128,256,128,1,128,128,128,128,128,128,128,128,128,256,128},{128,256,128,1,128,128,128,128,128,128,128,128,128,256,128},{128,256,128,1,1,1,1,1,128,128,128,128,128,256,128},{128,256,128,1,128,128,128,128,128,128,128,128,128,256,128},{128,256,128,1,128,128,128,128,128,128,128,128,128,256,128},{128,256,128,1,1,1,1,1,1,1,1,128,128,256,128},{128,256,256,1,1,1,1,1,1,1,1,1,256,256,128},{128,128,256,256,128,128,128,128,128,128,128,256,256,128,128},{0,128,128,256,256,256,256,256,256,256,256,256,128,128},{0,0,128,128,128,128,128,128,128,128,128,128,128},{}},
- exe = "",
- extendable = true,
- extended = false,
- },
- ["app_manager"] = {
- name = "App Manager",
- icon = {{0,0,128,128,128,128,128,128,128,128,128,128,128,},{0,128,128,256,256,256,256,256,256,256,256,256,128,128,},{128,128,1,1,1,256,1,1,1,256,1,1,1,128,128,},{128,256,1,1,1,256,1,1,1,256,1,1,1,256,128,},{128,256,1,1,1,256,1,1,1,256,1,1,1,256,128,},{128,256,256,256,256,256,256,256,256,256,256,256,256,256,128,},{128,256,1,1,1,256,1,1,1,256,1,1,1,256,128,},{128,256,1,1,1,256,1,1,1,256,1,1,1,256,128,},{128,256,1,1,1,256,1,1,1,256,1,1,1,256,128,},{128,256,256,256,256,256,256,256,256,256,256,256,256,256,128,},{128,256,1,1,1,256,1,1,1,256,1,1,1,256,128,},{128,256,1,1,1,256,1,1,1,256,1,1,1,256,128,},{128,128,1,1,1,256,1,1,1,256,1,1,1,128,128,},{0,128,128,256,256,256,256,256,256,256,256,256,128,128,},{0,0,128,128,128,128,128,128,128,128,128,128,128,},{},},
- exe = "",
- extendable = false,
- extended = false,
- },
- }
- local function grabFileData(f)
- if not fs.exists(f) then return error("'"..f.."' does not exists.") end
- local f_handle = fs.open(f, "r")
- if not f_handle then return error("Failed to open '"..f.."'.") end
- f = f_handle.readAll() f_handle.close()
- return f
- end
- local system = {}
- if fs.exists(MOS_dir.."/system.cfg") then
- system = textutils.unserialize(grabFileData(MOS_dir.."/system.cfg"))
- end
- if type(system) ~= "table" then system = {} end
- system = system or {}
- system.colors = system.colors or {["background"] = "cyan",["text"] = "white",}
- system.splash = system.splash or {
- text = "MOS",
- colors = {
- --["background"] = colors.cyan,
- ["text"] = "gray",
- },
- position = {1,1},
- }
- system.app_order = system.app_order or {"shell", "lua", "updater", "power", "reboot", "worm", "events", "app_manager"}
- if not fs.exists(MOS_dir.."/system.cfg") then
- local f = fs.open(MOS_dir.."/system.cfg", "w")
- f.write(textutils.serialize(system)) f.close()
- end
- local function validateIcon(icon)
- if not icon then return apps.icons["app_icon_missing"] end
- if type(icon) ~= "table" then return apps.icons["app_icon_invalid"] end
- local w = 0
- for i=1, #icon do
- if type(icon[i]) ~= "table" then return apps.icons["app_icon_invalid"] end
- w = math.max(#icon[i], w)
- end
- if w == apps.real_app_size[1] and #icon == apps.real_app_size[2] then return icon end
- return apps.icons["app_icon_invalid"]
- end
- local userapps_dir = MOS_dir.."/userapps"
- if not fs.exists(userapps_dir) then fs.makeDir(userapps_dir) end
- local f = fs.list(userapps_dir)
- for i=1, #f do
- if fs.isDir(userapps_dir.."/"..f[i]) then
- if fs.exists(userapps_dir.."/"..f[i].."/"..f[i]..".cfg") then
- tmp = textutils.unserialize(grabFileData(userapps_dir.."/"..f[i].."/"..f[i]..".cfg"))
- if type(tmp) == "table" then
- if tmp.load == nil then tmp.load = true end
- if tmp.name and tmp.load then
- tmp.icon = validateIcon(tmp.icon)
- apps[tmp.name:lower():gsub(" ", "_")] = tmp
- system.app_order[tmp.orderID or #system.app_order+1] = tmp.name:lower():gsub(" ", "_")
- end
- end
- end
- end
- end
- local function doStartupSplash()
- local ps = {(w/2-10)+2,(h/2-13)+4, (w/2-10)+17,(h/2-13)+19}
- st(colors.white) sb(colors.black) clr()
- paintutils.drawImage(apps.icons["phone_logo"], w/2-10, h/2-13) sleep(1)
- paintutils.drawFilledBox(ps[1],ps[2],ps[3],ps[4],colors.gray) sleep(.1)
- paintutils.drawFilledBox(ps[1],ps[2],ps[3],ps[4],colors.lightGray) sleep(.05)
- paintutils.drawFilledBox(ps[1],ps[2],ps[3],ps[4],colors.white) sleep(1)
- end doStartupSplash()
- local function doSplash() st(colors[system.splash.colors["text"] or system.colors["text"]]) sb(colors[system.splash.colors["background"] or system.colors["background"]]) cp(system.splash.position[1], system.splash.position[2]) write(system.splash.text) end
- --[[
- if w < apps.size[1]*2 or h < apps.size[2]*3 then
- error("Screen needs to be at least "..(apps.size[1]*2).."x"..(apps.size[2]*3))
- end
- --]]
- local function findFTE(t) local i=0 repeat i=i+1 until t[i] == nil return i end
- local function centerWrite(t) local x,y = term.getCursorPos() cp(w/2-string.len(t or "Invalid Centered Text: "..type(t))/2, y) write(t or "Invalid Centered Text: "..type(t)) end
- --==[[ Coroutine ]]==--
- local tasks, living = {}, 0
- local function addTask(...)
- local tFns = table.pack(...)
- local tCos = {}
- for i = 1, tFns.n, 1 do
- local fn = tFns[i]
- if type(fn) ~= "function" then
- error("bad argument #" .. i .. " (expected function, got " .. type(fn) .. ")", 3)
- end
- tCos[#tCos+1] = findFTE(tasks)
- tasks[findFTE(tasks)] = coroutine.create(fn)
- living = living + 1
- end
- return table.unpack(tCos)
- end
- local function removeTask(id)
- tasks[id] = nil
- living = living - 1
- end
- local function runTasks(_limit)
- local tFilters = {}
- local eventData = { n = 0 }
- while true do
- for n = 1, #tasks do
- local r = tasks[n]
- if r then
- if tFilters[r] == nil or tFilters[r] == eventData[1] or eventData[1] == "terminate" then
- local ok, param = coroutine.resume(r, table.unpack(eventData, 1, eventData.n))
- if not ok then
- return ok, param
- else
- tFilters[r] = param
- end
- if coroutine.status(r) == "dead" then
- table.remove(tasks, n)
- living = living - 1
- if living <= _limit then
- return n
- end
- end
- end
- end
- end
- for n = 1, #tasks do
- local r = tasks[n]
- if r and coroutine.status(r) == "dead" then
- tasks[n] = nil
- living = living - 1
- if living <= _limit then
- return n
- end
- end
- end
- eventData = table.pack(os.pullEventRaw())
- end
- end
- --[[
- local function waitForAny(...)
- local routines = create(...)
- return runUntilLimit(routines, #routines - 1)
- end
- local function waitForAll(...)
- local routines = create(...)
- return runUntilLimit(routines, 0)
- end
- --]]
- local function initTasks(...)
- addTask(...)
- return runTasks(1) -- 1 because RESIZE has os.pullEvent("term_resize") hanging it. so SCREEN ends the loop
- end
- --==[[ Coroutine ]]==--
- local function safeRedirect(m)
- m.restoreCursor()
- m.setCursorBlink(false)
- term.redirect(m)
- end
- local function waitForClick() print("Tap screen to go back...") os.pullEvent("mouse_click") end
- local function runNoProgram() print("This app does not have a program associated with it.") sleep(2) waitForClick() end
- local drawControllerUI
- local function runProgram(app)
- if app.extendable == nil then app.extendable = true end -- I know there is a better way of doing this but I just wanna keep it like this 4 now
- if app.extended == nil then app.extended = false end
- if app_screen.mode == 3 then if app.extended then app_screen.mode = 1 else app_screen.mode = 2 end end
- local function setAppScreenRes()
- if app_screen.mode == 1 then
- app_screen.display.reposition(app_screen.extended.x, app_screen.extended.y, app_screen.extended.w, app_screen.extended.h)
- else
- app_screen.display.reposition(app_screen.defaults.x, app_screen.defaults.y, app_screen.defaults.w, app_screen.defaults.h)
- end
- end
- local red_button_coords, arrow_coords, dpad_coords, inputs
- local function setValues()
- red_button_coords = {1,h-2,3,h}
- arrow_coords = {
- --{math.floor(w/2)-3, h-3, math.floor(w/2)+3, h}, -- EXTENDED
- --{math.floor(w/2)-3, app_screen.defaults.h+1, math.floor(w/2)+3, app_screen.defaults.h+4}
- {5, h-3, 4, 3}, -- EXTENDED
- {5, app_screen.defaults.h+1, 4, 3}
- }
- inputs = {
- {
- icon = apps.icons["button_function"], -- ENTER
- name = string.char(16),
- text_color = colors.white,
- background_color = colors.lightGray,
- text_offset_x = 2, text_offset_y = 1,
- x=w-5,y=app_screen.defaults.h+2,w=4,h=2,
- exe_a = function() os.queueEvent("key", 28, false) end,
- exe_b = function() os.queueEvent("key_up", 28) end
- },
- {
- icon = apps.icons["button_function"], -- CTRL
- name = string.char(17),
- text_color = colors.white,
- background_color = colors.lightGray,
- text_offset_x = 2, text_offset_y = 1,
- x=w-15,y=app_screen.defaults.h+2,w=4,h=2,
- exe_a = function() os.queueEvent("key", 29, false) end,
- exe_b = function() os.queueEvent("key_up", 29) end,
- },
- {
- icon = apps.icons["button_a"],
- name = "A",
- text_color = colors.white,
- background_color = colors.lime,
- text_offset_x = 2, text_offset_y = 2,
- x=3,y=h-11,w=4,h=4,
- exe_a = function() os.queueEvent("key", 30, false) os.queueEvent("char", "a") end,
- exe_b = function() os.queueEvent("key_up", 30) end
- },
- {
- icon = apps.icons["button_b"],
- name = "B",
- text_color = colors.white,
- background_color = colors.magenta,
- text_offset_x = 2, text_offset_y = 2,
- x=8,y=h-7,w=4,h=4,
- exe_a = function() os.queueEvent("key", 48, false) os.queueEvent("char", "b") end,
- exe_b = function() os.queueEvent("key_up", 48) end
- },
- }
- end setValues()
- local function drawController()
- local center = {w-9, h-8} setValues()
- paintutils.drawImage(apps.icons["dpad_button_center"], center[1], center[2])
- paintutils.drawImage(apps.icons["dpad_arrow_up"], center[1], center[2]-4)
- paintutils.drawImage(apps.icons["dpad_arrow_down"], center[1], center[2]+5)
- paintutils.drawImage(apps.icons["dpad_arrow_left"], center[1]-4, center[2])
- paintutils.drawImage(apps.icons["dpad_arrow_right"], center[1]+5, center[2])
- dpad_coords = {
- {center[1], center[2]-5, center[1]+3, center[2]-2, function() os.queueEvent("key", 200, false) end}, -- up
- {center[1], center[2]+5, center[1]+3, center[2]+8, function() os.queueEvent("key", 208, false) end}, -- down
- {center[1]-5, center[2], center[1]-2, center[2]+3, function() os.queueEvent("key", 203, false) end}, -- left
- {center[1]+5, center[2], center[1]+8, center[2]+3, function() os.queueEvent("key", 205, false) end}, -- right
- }
- for i=1, #inputs do
- paintutils.drawImage(inputs[i].icon, inputs[i].x, inputs[i].y)
- cp(inputs[i].x+inputs[i].text_offset_x, inputs[i].y+inputs[i].text_offset_y) st(inputs[i].text_color) sb(inputs[i].background_color) write(inputs[i].name)
- end
- end
- local function drawUI()
- main.setVisible(false) safeRedirect(main) setValues()
- paintutils.drawFilledBox(1,app_screen.defaults.h+1, w, h, colors[system.colors["background"] or colors.cyan])
- if app_screen.mode ~= 1 then drawController() end
- if app.extendable then
- arrow_coords = {
- --{math.floor(w/2)-3, h-3, math.floor(w/2)+3, h}, -- EXTENDED
- --{math.floor(w/2)-3, app_screen.defaults.h+1, math.floor(w/2)+3, app_screen.defaults.h+4}
- {5, h-3, 4, 3}, -- EXTENDED
- {5, app_screen.defaults.h+1, 4, 2}
- }
- paintutils.drawImage(apps.icons["arrow_down"], arrow_coords[app_screen.mode][1], arrow_coords[app_screen.mode][2])
- end
- paintutils.drawImage(apps.icons["button_power"], red_button_coords[1], red_button_coords[2])
- main.setVisible(true)
- end
- drawControllerUI = drawUI
- --[[ DEBUG --
- drawUI()
- for i=1, #inputs do
- paintutils.drawImage(inputs[i].icon, inputs[i].x, inputs[i].y)
- end
- for i=1, #inputs do
- paintutils.drawBox(inputs[i].x, inputs[i].y, inputs[i].x+inputs[i].w, inputs[i].y+inputs[i].h, colors.red)
- end
- paintutils.drawBox(arrow_coords[2][1], arrow_coords[2][2], arrow_coords[2][3]+arrow_coords[2][1], arrow_coords[2][4]+arrow_coords[2][2])
- sleep(2)
- -- DEBUG --]]
- local function a() -- Manage Controller / Resizing / Other
- drawUI()
- while true do
- local e = {os.pullEvent("mouse_click")}
- if e[3] >= red_button_coords[1] and e[3] <= red_button_coords[3] and e[4] >= red_button_coords[2] and e[4] <= red_button_coords[4] then
- break
- elseif e[3] >= arrow_coords[app_screen.mode][1] and e[3] <= arrow_coords[app_screen.mode][3]+arrow_coords[app_screen.mode][1] and e[4] >= arrow_coords[app_screen.mode][2] and e[4] <= arrow_coords[app_screen.mode][4]+arrow_coords[app_screen.mode][2] and app.extendable then
- if app_screen.mode == 1 then app_screen.mode = 2 else app_screen.mode = 1 end
- setAppScreenRes()
- drawUI()
- app_screen.display.redraw()
- safeRedirect(app_screen.display)
- else
- if app_screen.mode == 2 then
- for i=1, #dpad_coords do
- if e[3] >= dpad_coords[i][1] and e[3] <= dpad_coords[i][3] and e[4] >= dpad_coords[i][2] and e[4] <= dpad_coords[i][4] then
- dpad_coords[i][5]()
- end
- end
- for i=1, #inputs do
- if e[3] >= inputs[i].x and e[3] <= inputs[i].x+inputs[i].w and e[4] >= inputs[i].y and e[4] <= inputs[i].y+inputs[i].h then
- inputs[i].exe_a()
- os.pullEvent("mouse_up")
- inputs[i].exe_b()
- end
- end
- end
- end
- end
- end
- local function b() -- Manage Running Program
- sleep(.01)
- app_screen.display.setVisible(true)
- setAppScreenRes()
- safeRedirect(app_screen.display) st(colors.white) sb(colors.black) clr() cp(1,1)
- local r,e = false, "Failed to Run."
- if type(app.exe) == "function" then
- r,e = pcall(app.exe)
- elseif type(app.exe) == "string" then
- if not fs.exists(app.exe) then print("'"..app.exe.."' could not be located.") sleep(2) waitForClick() r = true else r,e = shell.run(app.exe) end
- else
- runNoProgram()
- r = true
- end
- if not r then
- printError(e) sleep(2) waitForClick()
- end
- app_screen.display.setVisible(false)
- end
- local ah,bh = addTask(a,b)
- while true do
- if tasks[ah] == nil or tasks[bh] == nil then break end sleep(.1)
- end
- if tasks[ah] then removeTask(ah) end
- if tasks[bh] then removeTask(bh) end
- app_screen.mode = 3
- end
- local function runAppManager()
- --[[
- local sel = 1
- local function drawUI()
- st(colors.white) sb(colors.black) clr()
- paintutils.drawLine(1,1,app_screen.defaults.w,1,colors.gray)
- paintutils.drawLine(1,app_screen.defaults.h,app_screen.defaults.w,app_screen.defaults.h,colors.gray)
- end
- while true do
- drawUI() sleep(5)
- end
- --]]
- print("Program is not setup.") sleep(2) waitForClick()
- end
- local function runUpdater()
- print("Updating...")
- local h = http.get("https://pastebin.com/raw/3XuFvnY3")
- if not h then
- printError("Failed to get update.") sleep(2) waitForClick()
- else
- local u = h.readAll() h.close()
- fs.delete("/startup.lua")
- local f = fs.open("startup.lua", "w")
- f.write(u) f.close()
- print("Updated! Rebooting...") sleep(1) os.reboot()
- end
- end
- local function runTaskMngr()
- print("Program is not setup.") sleep(2) waitForClick()
- end
- local run = true
- local function runExit()
- print("Exiting...") sleep(1) run = false
- end
- local function runReboot()
- print("Rebooting...") sleep(1) os.reboot()
- end
- local function runEvents()
- local last = {e={""}}
- while true do
- local e = {os.pullEvent()}
- if e[1] ~= last.e[1] then
- last = {e=e, c=1}
- for i=1, #e do
- write("["..i.."] "..tostring(e[i]).." ")
- end print("")
- else
- local x,y = term.getCursorPos()
- cp(1,y-1)
- for i=1, #last.e do
- write("["..i.."] "..tostring(last.e[i]).." ")
- end print(" ("..last.c..")")
- last.c = last.c + 1
- end
- end
- end
- apps["taskmngr"].exe = runTaskMngr
- apps["updater"].exe = runUpdater
- apps["power"].exe = runExit
- apps["reboot"].exe = runReboot
- apps["events"].exe = runEvents
- apps["app_manager"].exe = runAppManager
- local buttons
- local function SCREEN()
- --sleep(.1)
- local update = true
- while run do
- -- updates --
- if update then
- while resizing do sleep(.1) end sleep(.01)
- safeRedirect(main)
- update = false
- st(colors.white) sb(colors[system.colors["background"] or colors.cyan]) clr()
- local cnt = ((apps.screen_length*apps.screen_height)*(apps.screen-1))+1
- buttons = {}
- for i=1, apps.screen_height do
- for ii=1, apps.screen_length do
- local app_cal = {
- math.floor((w-(apps.screen_length*apps.size[1]))/2+2)+((ii-1)*apps.size[1]),
- math.floor((h-(apps.screen_height*apps.size[2]))/2+2)+((i-1)*apps.size[2]),
- }
- if apps[system.app_order[cnt]] then
- paintutils.drawImage(apps[system.app_order[cnt]].icon or apps.icons["app_icon_missing"], app_cal[1],app_cal[2])
- buttons[#buttons+1] = {app_cal[1], app_cal[2], app_cal[1]+apps.size[1]-3,app_cal[2]+apps.size[2]-3}
- --paintutils.drawPixel(buttons[#buttons][1]+8, buttons[#buttons][4], colors.red)
- sb(colors[system.colors["background"] or colors.cyan]) cp((buttons[#buttons][1]+8)-math.ceil(string.len(apps[system.app_order[cnt]].name)/2), buttons[#buttons][4]+1) write(apps[system.app_order[cnt]].name)
- elseif system.app_order[cnt] ~= nil then
- paintutils.drawImage(apps.icons["app_icon_invalid"], app_cal[1],app_cal[2])
- buttons[#buttons+1] = {app_cal[1], app_cal[2], app_cal[1]+apps.size[1]-3,app_cal[2]+apps.size[2]-3}
- --paintutils.drawPixel(buttons[#buttons][1]+8, buttons[#buttons][4], colors.red)
- sb(colors[system.colors["background"] or colors.cyan]) cp((buttons[#buttons][1]+8)-math.ceil(string.len(apps["invalid_app"].name)/2), buttons[#buttons][4]+1) write(apps["invalid_app"].name)
- else
- paintutils.drawImage(apps.icons["no_app_icon"], app_cal[1],app_cal[2])
- end
- cnt=cnt+1
- end
- end
- --[[ Debug --
- paintutils.drawLine(1,h/2,w,h/2, colors.gray)
- paintutils.drawLine(w/2,1,w/2,h, colors.gray)
- paintutils.drawPixel(w/2, h/2, colors.gray)
- paintutils.drawBox(w/2-1, h/2-1, w/2+1, h/2+1, colors.lightGray)
- -- Debug --]]
- paintutils.drawImage(apps.icons["scroll_left"], 1,h/2-2)
- paintutils.drawImage(apps.icons["scroll_right"], w-1,h/2-2)
- doSplash()
- end
- -- hitboxes --
- --
- for i=1, #buttons do
- --paintutils.drawBox(buttons[i][1], buttons[i][2], buttons[i][3], buttons[i][4], colors.red) sleep(.1)
- end
- --]]
- -- events --
- e = {os.pullEvent()}
- if e[1] == "term_resize" then
- update = true
- elseif e[1] == "mouse_click" then
- local e2 = {}
- while e2[1] ~= "mouse_up" do
- e2 = {os.pullEvent()}
- end
- if e2[3] >= e[3]-3 and e2[3] <= e[3]+3 then -- Clicked an app
- for i=1, #buttons do
- if e[3] >= buttons[i][1] and e[4] >= buttons[i][2] and e[3] <= buttons[i][3] and e[4] <= buttons[i][4] then
- runProgram(apps[system.app_order[((apps.screen_length*apps.screen_height)*(apps.screen-1))+i]] or apps["invalid_app"])
- update = true
- end
- end
- else
- if e2[3] >= e[3]+3 and apps.screen ~= 1 then -- Swipe Left
- apps.screen = apps.screen-1
- update = true
- elseif e2[3] <= e[3]-3 and apps.screen ~= math.ceil(#system.app_order/(apps.screen_length*apps.screen_height)) then -- Swipe Right
- apps.screen = apps.screen+1
- update = true
- end
- end
- end
- end
- end
- local function RESIZE()
- while run do
- resizing = true
- local c = term.current()
- term.redirect(term.native())
- if {getSize()} ~= {w,h} then
- w,h = getSize()
- apps.screen_length, apps.screen_height = math.min(math.floor(w/apps.size[1]), apps.screen_length_limit), math.min(math.floor(h/apps.size[1]), apps.screen_height_limit) -- 17 because of text and space under app
- apps.screen = math.min(apps.screen, math.ceil(#system.app_order/(apps.screen_length*apps.screen_height)))
- app_screen.defaults, app_screen.extended = {
- x=1, y=1,
- w=w, h=math.floor(h/1.5)-6,
- },{
- x=1, y=1,
- w=w, h=h-4,
- }
- if app_screen.mode ~= 3 then -- not in use
- if app_screen.mode == 1 then -- Extended
- app_screen.display.reposition(app_screen.extended.x, app_screen.extended.y, app_screen.extended.w, app_screen.extended.h)
- else -- Default or not in use
- app_screen.display.reposition(app_screen.defaults.x, app_screen.defaults.y, app_screen.defaults.w, app_screen.defaults.h)
- end
- end
- main.reposition(1,1,w,h) -- REDO CURSOR BLINK FOR SHELL
- main.redraw()
- if app_screen.mode ~= 3 then drawControllerUI() end
- app_screen.display.redraw()
- end
- term.redirect(c) resizing = false
- os.pullEvent("term_resize")
- end
- end
- local r,e = initTasks(SCREEN, RESIZE)
- main.setVisible(true)
- safeRedirect(main)
- if not r then
- sb(colors.cyan) st(colors.white) clr() cp(1,h/3) sleep(.5)
- centerWrite("Mobile OS has Crashed!") cp(1,h/3+2)
- centerWrite("=== Error Code ===") print("")
- st(colors.red) centerWrite(e) st(colors.white) sleep(2) cp(1,h-2)
- centerWrite("Tap the screen to continue...") os.pullEvent("mouse_click")
- end
- st(colors.white) sb(colors.black) clr() cp(1,1)
Advertisement
Add Comment
Please, Sign In to add comment