1
0
Fork 0
mirror of https://github.com/ctruLua/uCompat.git synced 2025-10-27 08:39:31 +00:00

Fixed many things, Added overclock on new3DS (can be disabled), Rewrote the README

This commit is contained in:
Firew0lf 2016-03-31 21:53:19 +02:00
parent 36c85bb540
commit 8ab6181928
8 changed files with 98 additions and 53 deletions

View file

@ -1,7 +1,30 @@
# uCompat
µ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
* Color
* Controls
@ -22,3 +45,9 @@ Actually done:
* System
* Timer
* Wifi
### What's not ?
* Soundbanks decoding
* `screen.drawGradientRect()`: very ugly render ...
* 3DS <-> DS Nifi

View file

@ -41,7 +41,7 @@ local function attrTable()
[ATTR_COLOR3] = false,
[ATTR_COLOR4] = false,
[ATTR_TEXT] = false,
[ATTR_VISIBLE] = false,
[ATTR_VISIBLE] = true,
[ATTR_FONT] = false,
[ATTR_IMAGE] = false
}
@ -186,7 +186,9 @@ end
function Canvas.draw(scr, canvas, x, y)
for i=1, #canvas do
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])
elseif o.type == TYPE_POINT then
screen.drawPoint(scr, o[ATTR_X1]+x, o[ATTR_Y1]+y, o[ATTR_COLOR])

View file

@ -6,6 +6,7 @@
local texture = require("ctr.gfx.texture")
local color = require("ctr.gfx.color")
require("uCompat.System")
-- Constants
@ -17,9 +18,14 @@ VRAM = texture.PLACE_VRAM -- has to be "PLACE_RAM" on hardware
Image = {}
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
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
texture = t,
rotation = 0.0,

View file

@ -4,13 +4,15 @@
-- Local
map = require("ctr.gfx.map")
local map = require("ctr.gfx.map")
-- Interface
require("uCompat.System")
-- Module
Map = {}
function Map.mapToTable(filename, w, h)
local f = io.open(filename, "r")
local f = assert(io.open(filename, "r"))
local data = f:read("a")
f:close()
@ -38,7 +40,7 @@ end
require("uCompat.screen")
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)
return {
@ -51,7 +53,8 @@ function Map.new(image, mapFile, width, height, tileWidth, tileHeight)
end
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
function Map.draw(scr, m, x, y, w, h)

View file

@ -4,7 +4,7 @@
-- Local
map = require("ctr.gfx.map")
local map = require("ctr.gfx.map")
-- Module
@ -14,7 +14,7 @@ require("uCompat.Map")
ScrollMap = {}
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)
return {
map = m,
@ -26,7 +26,7 @@ function ScrollMap.new(image, mapFile, width, height, tileWidth, tileHeight)
end
function ScrollMap.destroy(m)
m.map:destroy()
m.map:unload()
end
function ScrollMap.draw(scr, m)

View file

@ -9,42 +9,6 @@
local fs = require("ctr.fs")
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
LED_ON = 0
@ -58,11 +22,11 @@ System = {}
System.EFS = false
function System.currentDirectory()
return unfixPath(fs.getDirectory())
return System.unfixPath(fs.getDirectory())
end
function System.changeDirectory(dir)
fs.setDirectory(fixPath(dir))
fs.setDirectory(System.fixPath(dir))
end
function System.remove(path)
@ -79,7 +43,7 @@ end
function System.listDirectory(path)
local list = fs.list(fixPath(path))
local list = fs.list(System.fixPath(path))
local flist = {}
for i=1, #list do
flist[i] = {
@ -119,3 +83,37 @@ end
function System.sleep()
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

View file

@ -7,8 +7,14 @@
-- Just something needed
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
MICROLUA_VERSION = "Microlua 4.1" -- such old, very version
ULUA_VERSION = "Microlua 4.7.2"
ULUA_DIR = ctr.root -- you can change it to anything
ULUA_SCRIPTS = (ULUA_DIR.."scripts/") -- Warning: you may need to create the folder

View file

@ -72,7 +72,7 @@ function stopDrawing()
if drawScreen == 0 then
fpscount = fpscount + 1
end
if (ctr.time() - fpstime) > 1000 then
if (ctr.time() - fpstime) >= 1000 then
NB_FPS = fpscount
fpstime = ctr.time()
fpscount = 0
@ -205,6 +205,7 @@ function screen.init() -- unused
end
function screen.startDrawing2D() -- unused
ctr.run()
--reset the video stacks
videoStack[drawScreen] = {}