mirror of
https://github.com/ctruLua/uCompat.git
synced 2025-10-27 16:49:31 +00:00
Fixed many things, Added overclock on new3DS (can be disabled), Rewrote the README
This commit is contained in:
parent
36c85bb540
commit
8ab6181928
8 changed files with 98 additions and 53 deletions
31
README.md
31
README.md
|
|
@ -1,7 +1,30 @@
|
||||||
# uCompat
|
# uCompat
|
||||||
µLua compatibility layer for ctrµLua.
|
µLua compatibility layer for ctrµLua.
|
||||||
|
|
||||||
Actually done:
|
### What is that ?
|
||||||
|
|
||||||
|
_uCompat_ is a ctrµLua "library" that allows you to launch and use µLua homebrews
|
||||||
|
on your 3DS.
|
||||||
|
|
||||||
|
### How does it work ?
|
||||||
|
|
||||||
|
This library recreate the µLua execution environment in ctrµLua using only pure
|
||||||
|
Lua. All the functions were recreated using the [official µLua documentation](https://sourceforge.net/p/microlua/wiki/API471/),
|
||||||
|
and the library is designed to run any µLua program from 3.0 to 4.7.2.
|
||||||
|
|
||||||
|
### How do I use it ?
|
||||||
|
|
||||||
|
Just download the latest version by clicking the "Download ZIP" button (somewhere
|
||||||
|
on the page) or with a `git clone`, and place the `uCompat` directory in your
|
||||||
|
ctrµLua `libs` folder (the __folder__, not the files in the folder).
|
||||||
|
Once it's done, put your µLua homebrews in a directory somewhere, it doesn't
|
||||||
|
mater where, just remember it.
|
||||||
|
Finally, open your homebrews' main files (`index.lua` on a lot of them) and add
|
||||||
|
the line `require("uCompat")` at the beggining of the file, before any other
|
||||||
|
line of code. Now, it should work.
|
||||||
|
|
||||||
|
### What's done ?
|
||||||
|
|
||||||
* Canvas
|
* Canvas
|
||||||
* Color
|
* Color
|
||||||
* Controls
|
* Controls
|
||||||
|
|
@ -22,3 +45,9 @@ Actually done:
|
||||||
* System
|
* System
|
||||||
* Timer
|
* Timer
|
||||||
* Wifi
|
* Wifi
|
||||||
|
|
||||||
|
### What's not ?
|
||||||
|
|
||||||
|
* Soundbanks decoding
|
||||||
|
* `screen.drawGradientRect()`: very ugly render ...
|
||||||
|
* 3DS <-> DS Nifi
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ local function attrTable()
|
||||||
[ATTR_COLOR3] = false,
|
[ATTR_COLOR3] = false,
|
||||||
[ATTR_COLOR4] = false,
|
[ATTR_COLOR4] = false,
|
||||||
[ATTR_TEXT] = false,
|
[ATTR_TEXT] = false,
|
||||||
[ATTR_VISIBLE] = false,
|
[ATTR_VISIBLE] = true,
|
||||||
[ATTR_FONT] = false,
|
[ATTR_FONT] = false,
|
||||||
[ATTR_IMAGE] = false
|
[ATTR_IMAGE] = false
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +186,9 @@ end
|
||||||
function Canvas.draw(scr, canvas, x, y)
|
function Canvas.draw(scr, canvas, x, y)
|
||||||
for i=1, #canvas do
|
for i=1, #canvas do
|
||||||
local o = canvas[i] -- gotta go fast
|
local o = canvas[i] -- gotta go fast
|
||||||
if o.type == TYPE_LINE then
|
if not o[ATTR_VISIBLE] then
|
||||||
|
-- Invisible
|
||||||
|
elseif o.type == TYPE_LINE then
|
||||||
screen.drawLine(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_X2]+x, o[ATTR_Y2]+y, o[ATTR_COLOR])
|
screen.drawLine(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_X2]+x, o[ATTR_Y2]+y, o[ATTR_COLOR])
|
||||||
elseif o.type == TYPE_POINT then
|
elseif o.type == TYPE_POINT then
|
||||||
screen.drawPoint(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_COLOR])
|
screen.drawPoint(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_COLOR])
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
local texture = require("ctr.gfx.texture")
|
local texture = require("ctr.gfx.texture")
|
||||||
local color = require("ctr.gfx.color")
|
local color = require("ctr.gfx.color")
|
||||||
|
require("uCompat.System")
|
||||||
|
|
||||||
-- Constants
|
-- Constants
|
||||||
|
|
||||||
|
|
@ -17,9 +18,14 @@ VRAM = texture.PLACE_VRAM -- has to be "PLACE_RAM" on hardware
|
||||||
Image = {}
|
Image = {}
|
||||||
|
|
||||||
function Image.load(path, dest)
|
function Image.load(path, dest)
|
||||||
local t = texture.load(path, dest)
|
local t = texture.load(System.fixPath(path), dest)
|
||||||
if not t then return nil end
|
if not t then return nil end
|
||||||
local w,h = t:getSize()
|
local w,h = t:getSize()
|
||||||
|
for x=0, w do
|
||||||
|
for y=0, h do
|
||||||
|
if t:getPixel(x,y) == 0xff00ffff then t:setPixel(x, y, 0) end
|
||||||
|
end
|
||||||
|
end
|
||||||
return { -- Image object
|
return { -- Image object
|
||||||
texture = t,
|
texture = t,
|
||||||
rotation = 0.0,
|
rotation = 0.0,
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,15 @@
|
||||||
|
|
||||||
-- Local
|
-- Local
|
||||||
|
|
||||||
map = require("ctr.gfx.map")
|
local map = require("ctr.gfx.map")
|
||||||
|
|
||||||
-- Interface
|
require("uCompat.System")
|
||||||
|
|
||||||
|
-- Module
|
||||||
Map = {}
|
Map = {}
|
||||||
|
|
||||||
function Map.mapToTable(filename, w, h)
|
function Map.mapToTable(filename, w, h)
|
||||||
local f = io.open(filename, "r")
|
local f = assert(io.open(filename, "r"))
|
||||||
local data = f:read("a")
|
local data = f:read("a")
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
|
|
@ -38,7 +40,7 @@ end
|
||||||
require("uCompat.screen")
|
require("uCompat.screen")
|
||||||
|
|
||||||
function Map.new(image, mapFile, width, height, tileWidth, tileHeight)
|
function Map.new(image, mapFile, width, height, tileWidth, tileHeight)
|
||||||
local tiles = mapToTable(mapFile, width, height)
|
local tiles = mapToTable(System.fixPath(mapFile), width, height)
|
||||||
local m = map.load(tiles, image.texture, tileWidth, tileHeight)
|
local m = map.load(tiles, image.texture, tileWidth, tileHeight)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -51,7 +53,8 @@ function Map.new(image, mapFile, width, height, tileWidth, tileHeight)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Map.destroy(m)
|
function Map.destroy(m)
|
||||||
m.map:unload()
|
-- This `if` should not exist.
|
||||||
|
if m then m.map:unload() end -- got some crashes here ... We should ban global values in Lua.
|
||||||
end
|
end
|
||||||
|
|
||||||
function Map.draw(scr, m, x, y, w, h)
|
function Map.draw(scr, m, x, y, w, h)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
-- Local
|
-- Local
|
||||||
|
|
||||||
map = require("ctr.gfx.map")
|
local map = require("ctr.gfx.map")
|
||||||
|
|
||||||
-- Module
|
-- Module
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ require("uCompat.Map")
|
||||||
ScrollMap = {}
|
ScrollMap = {}
|
||||||
|
|
||||||
function ScrollMap.new(image, mapFile, width, height, tileWidth, tileHeight)
|
function ScrollMap.new(image, mapFile, width, height, tileWidth, tileHeight)
|
||||||
local tiles = Map.mapToTable(mapFile, width, height)
|
local tiles = Map.mapToTable(System.fixPath(mapFile), width, height)
|
||||||
local m = map.load(tiles, image.texture, tileWidth, tileHeight)
|
local m = map.load(tiles, image.texture, tileWidth, tileHeight)
|
||||||
return {
|
return {
|
||||||
map = m,
|
map = m,
|
||||||
|
|
@ -26,7 +26,7 @@ function ScrollMap.new(image, mapFile, width, height, tileWidth, tileHeight)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ScrollMap.destroy(m)
|
function ScrollMap.destroy(m)
|
||||||
m.map:destroy()
|
m.map:unload()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ScrollMap.draw(scr, m)
|
function ScrollMap.draw(scr, m)
|
||||||
|
|
|
||||||
|
|
@ -9,42 +9,6 @@
|
||||||
local fs = require("ctr.fs")
|
local fs = require("ctr.fs")
|
||||||
local gfx = require("ctr.gfx")
|
local gfx = require("ctr.gfx")
|
||||||
|
|
||||||
-- µ -> ctrµ
|
|
||||||
local function fixPath(DSpath)
|
|
||||||
local path
|
|
||||||
if DSpath:sub(1, 5) == "fat:/" then -- fix root
|
|
||||||
path = ("sdmc:/"..DSpath:sub(6, -1))
|
|
||||||
elseif DSpath:sub(1, 1) == "/" then
|
|
||||||
path = ("sdmc:"..DSpath)
|
|
||||||
elseif DSpath:sub(1, 5) == "efs:/" then
|
|
||||||
path = ("romfs:/"..DSpath:sub(6,-1))
|
|
||||||
elseif DSpath:sub(1, 2) ~= "./" then
|
|
||||||
path = (fs.getDirectory()..DSpath)
|
|
||||||
else
|
|
||||||
path = DSpath
|
|
||||||
end
|
|
||||||
|
|
||||||
if path:sub(-1,-1) ~= "/" then
|
|
||||||
path = (path.."/")
|
|
||||||
end
|
|
||||||
|
|
||||||
return path
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ctrµ -> µ
|
|
||||||
local function unfixPath(path)
|
|
||||||
local DSpath
|
|
||||||
if path:sub(1, 6) == "sdmc:/" then
|
|
||||||
DSpath = ("fat:/"..path:sub(7, -1))
|
|
||||||
elseif path.sub(1, 1) == "/" then
|
|
||||||
DSpath = ("fat:"..path)
|
|
||||||
elseif path:sub(1, 7) == "romfs:/" then
|
|
||||||
DSpath = ("efs:/"..path:sub(8, -1))
|
|
||||||
end
|
|
||||||
|
|
||||||
return DSpath
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Constants
|
-- Constants
|
||||||
|
|
||||||
LED_ON = 0
|
LED_ON = 0
|
||||||
|
|
@ -58,11 +22,11 @@ System = {}
|
||||||
System.EFS = false
|
System.EFS = false
|
||||||
|
|
||||||
function System.currentDirectory()
|
function System.currentDirectory()
|
||||||
return unfixPath(fs.getDirectory())
|
return System.unfixPath(fs.getDirectory())
|
||||||
end
|
end
|
||||||
|
|
||||||
function System.changeDirectory(dir)
|
function System.changeDirectory(dir)
|
||||||
fs.setDirectory(fixPath(dir))
|
fs.setDirectory(System.fixPath(dir))
|
||||||
end
|
end
|
||||||
|
|
||||||
function System.remove(path)
|
function System.remove(path)
|
||||||
|
|
@ -79,7 +43,7 @@ end
|
||||||
|
|
||||||
function System.listDirectory(path)
|
function System.listDirectory(path)
|
||||||
|
|
||||||
local list = fs.list(fixPath(path))
|
local list = fs.list(System.fixPath(path))
|
||||||
local flist = {}
|
local flist = {}
|
||||||
for i=1, #list do
|
for i=1, #list do
|
||||||
flist[i] = {
|
flist[i] = {
|
||||||
|
|
@ -119,3 +83,37 @@ end
|
||||||
function System.sleep()
|
function System.sleep()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Small API
|
||||||
|
|
||||||
|
-- µ -> ctrµ
|
||||||
|
function System.fixPath(DSpath)
|
||||||
|
local path
|
||||||
|
if DSpath:sub(1, 5) == "fat:/" then -- fix root
|
||||||
|
path = ("sdmc:/"..DSpath:sub(6, -1))
|
||||||
|
elseif DSpath:sub(1, 1) == "/" then
|
||||||
|
path = ("sdmc:"..DSpath)
|
||||||
|
elseif DSpath:sub(1, 5) == "efs:/" then
|
||||||
|
path = ("romfs:/"..DSpath:sub(6,-1))
|
||||||
|
elseif DSpath:sub(1, 2) ~= "./" then
|
||||||
|
path = (fs.getDirectory()..DSpath)
|
||||||
|
else
|
||||||
|
path = DSpath
|
||||||
|
end
|
||||||
|
|
||||||
|
return path
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ctrµ -> µ
|
||||||
|
function System.unfixPath(path)
|
||||||
|
local DSpath
|
||||||
|
if path:sub(1, 6) == "sdmc:/" then
|
||||||
|
DSpath = ("fat:/"..path:sub(7, -1))
|
||||||
|
elseif path.sub(1, 1) == "/" then
|
||||||
|
DSpath = ("fat:"..path)
|
||||||
|
elseif path:sub(1, 7) == "romfs:/" then
|
||||||
|
DSpath = ("efs:/"..path:sub(8, -1))
|
||||||
|
end
|
||||||
|
|
||||||
|
return DSpath
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,14 @@
|
||||||
-- Just something needed
|
-- Just something needed
|
||||||
|
|
||||||
local ctr = require("ctr")
|
local ctr = require("ctr")
|
||||||
|
local ptm = require("ctr.ptm")
|
||||||
|
|
||||||
|
-- Setup the new3DS overclock, uncomment if you need more speed
|
||||||
|
ptm.init()
|
||||||
|
ptm.configureNew3DSCPU(true)
|
||||||
|
|
||||||
-- Constants
|
-- Constants
|
||||||
|
MICROLUA_VERSION = "Microlua 4.1" -- such old, very version
|
||||||
ULUA_VERSION = "Microlua 4.7.2"
|
ULUA_VERSION = "Microlua 4.7.2"
|
||||||
ULUA_DIR = ctr.root -- you can change it to anything
|
ULUA_DIR = ctr.root -- you can change it to anything
|
||||||
ULUA_SCRIPTS = (ULUA_DIR.."scripts/") -- Warning: you may need to create the folder
|
ULUA_SCRIPTS = (ULUA_DIR.."scripts/") -- Warning: you may need to create the folder
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ function stopDrawing()
|
||||||
if drawScreen == 0 then
|
if drawScreen == 0 then
|
||||||
fpscount = fpscount + 1
|
fpscount = fpscount + 1
|
||||||
end
|
end
|
||||||
if (ctr.time() - fpstime) > 1000 then
|
if (ctr.time() - fpstime) >= 1000 then
|
||||||
NB_FPS = fpscount
|
NB_FPS = fpscount
|
||||||
fpstime = ctr.time()
|
fpstime = ctr.time()
|
||||||
fpscount = 0
|
fpscount = 0
|
||||||
|
|
@ -205,6 +205,7 @@ function screen.init() -- unused
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.startDrawing2D() -- unused
|
function screen.startDrawing2D() -- unused
|
||||||
|
ctr.run()
|
||||||
--reset the video stacks
|
--reset the video stacks
|
||||||
videoStack[drawScreen] = {}
|
videoStack[drawScreen] = {}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue