Создать ответ 
 
Рейтинг темы:
  • Голосов: 0 - Средняя оценка: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Help with LUA scripting.
Автор Сообщение
MastaG Не на форуме
Пользователь
**

Сообщений: 87
Зарегистрирован: 13.04.2011
Рейтинг: 0
Сказал спасибо: 31
Поблагодарили 12 раз(а) в 12 сообщ.
Сообщение: #1
Help with LUA scripting.
Hi threre gang,

I'd like to offer my Dreamcast for helping out with some automated test cases.
For that I'd like DreamShell to download an iso file from a plain http server and run it at startup instead of showing the main menu.

So I'm trying to edit the DS/lua/startup.lua file:

Код:
-----------------------------------------
--                                     --
-- @name:     Startup script           --
-- @author:   SWAT                       --
-- @url:      http://www.dc-swat.ru    --
--                                     --
-----------------------------------------
--
-- Internal DreamShell lua functions:
--
--    OpenModule             Open module file and return ID
--    CloseModule            Close module by ID
--    GetModuleByName        Get module ID by module NAME
--
--    AddApp                 Add app by XML file, return app NAME
--    OpenApp                Open app by NAME (second argument for args)
--    CloseApp               Close app by NAME (second argument for change unload flag)
--
--    ShowConsole
--    HideConsole
--    SetDebugIO             Set the debug output (scif, dclsocket, fb, ds, sd). By default is ds.
--    Sleep                  Sleep in current thread (in ms)
--    MapleAttached          Check for attached maple device
--
--    Bit library:           bit.or, bit.and, bit.not, bit.xor
--    File system library:   lfs.chdir, lfs.currentdir, lfs.dir, lfs.mkdir, lfs.rmdir
--    
------------------------------------------

local DreamShell = {

    initialized = false,
    
    modules = {
        --"tolua",
        --"tolua_2plus",
        --"luaDS",            -- Depends: tolua
        --"luaKOS",           -- Depends: tolua
        --"luaSDL",           -- Depends: tolua
        --"luaGUI",           -- Depends: tolua
        --"luaMXML",          -- Depends: tolua
        --"luaSTD",           -- Depends: tolua
        --"sqlite3",
        --"luaSQL",           -- Depends: sqlite3
        "luaSocket",
        --"luaTask",
        --"bzip2",
        "minilzo",
        --"zip",              -- Depends: bzip2
        "http",
        --"httpd",
        --"telnetd",
        --"mongoose",
        --"ppp",
        --"mpg123",
        --"oggvorbis",
        --"adx",
        --"s3m",
        --"wav",
        --"xvid",
        --"SDL_mixer",        -- Depends: oggvorbis
        --"ffmpeg",           -- Depends: oggvorbis, mpg123, bzip2
        --"opengl",
        "isofs",            -- Depends: minilzo
        "isoldr"            -- Depends: isofs
        --"SDL_net",
        --"opkg",             -- Depends: minilzo
        --"aicaos",
        --"gumbo",
        --"ini",
        --"bflash",
        --"openssl",
        --"bitcoin",
        --"quirc",
        --"ftpd"
    },

    Initialize = function(self)

        os.execute("env USER Default");
        local path = os.getenv("PATH");

        print(os.getenv("HOST") .. " " .. os.getenv("VERSION") .. "\n");
        print(os.getenv("ARCH") .. ": " .. os.getenv("BOARD_ID") .. "\n");
        print("Date: " .. os.date() .. "\n");
        print("Base path: " .. path .. "\n");
        print("User: " .. os.getenv("USER") .. "\n");

        local emu = os.getenv("EMU");

        if emu ~= nil then
            print("Emulator: " .. emu .. "\n");
        end

        print("\n");

        if not MapleAttached("Keyboard") then
            table.insert(self.modules, "vkb");
        end

        table.foreach(self.modules, function(k, name)  
            print("DS_PROCESS: Loading module " .. name .. "...\n");
            if not OpenModule(path .. "/modules/" .. name .. ".klf") then
                print("DS_ERROR: Can't load module " .. path .. "/modules/" .. name .. ".klf\n");
            end
        end);

        self:InstallingApps(path .. "/apps");
        self.initialized = true;
        
        # Setup network
        os.execute("net --init");
        
        # disable FTP server for now
        --os.execute("ftpd -s -p 21 -d /");
        
        # try and download my file
        socket = require("socket")
        http = require("socket.http")
        ltn12 = require("ltn12")

        local file = ltn12.sink.file(io.open('/ide/GAMES/mygame/game.iso', 'w'))
        http.request {
                url = 'http://myserver/myfile.iso',
                sink = file,
        }
        
        # Run isoloader but I don't know how...
        OpenApp(os.getenv("APP"));
    end,

    InstallingApps = function(self, path)

        print("DS_PROCESS: Installing apps...\n");
        local name = nil;
        local list = {};

        for ent in lfs.dir(path) do
            if ent ~= nil and ent.name ~= ".." and ent.name ~= "." and ent.attr ~= 0 then
                table.insert(list, ent.name);
            end
        end

        table.sort(list, function(a, b) return a > b end);

        for index, directory in ipairs(list) do

            name = AddApp(path .. "/" .. directory .. "/app.xml");

            if not name then
                print("DS_ERROR: " .. directory .. "\n");
            else
                print("DS_OK: " .. name .. "\n");
            end
        end

        return true;
    end
};

if not DreamShell.initialized then
    DreamShell:Initialize();
end

As you can see I didn't got very far.

Any help would be greatly appreciated.
07.08.2024 12:31
Найти все сообщения Цитировать это сообщение
MastaG Не на форуме
Пользователь
**

Сообщений: 87
Зарегистрирован: 13.04.2011
Рейтинг: 0
Сказал спасибо: 31
Поблагодарили 12 раз(а) в 12 сообщ.
Сообщение: #2
RE: Help with LUA scripting.
I figured out the isoloader command:
Код:
isoldr -i -a -x 0x8c004000 -f /ide/GAMES/mygame/game.iso -o 1 -h 0

But it seems to hang on boot.
07.08.2024 13:09
Найти все сообщения Цитировать это сообщение
SWAT Не на форуме
Администратор
*******

Сообщений: 7217
Зарегистрирован: 04.01.2005
Рейтинг: 30
Сказал спасибо: 149
Поблагодарили 1209 раз(а) в 759 сообщ.
Сообщение: #3
RE: Help with LUA scripting.
Hang on network?
In general, there is some issues in KOS related to the simultaneous operation of AICA and BBA. In DS music plays at startup. Try to wait until it finishes playing or just turn it off by commenting this line: https://github.com/DC-SWAT/DreamShell/bl...?ts=4#L217
In it not help, seems issues in lua http, I never test it.
You can also try the http module, it adds a /http to the file system through which you can work with normal file operations, for example: /http/192.168.1.2/file.iso
But again, all the network stuff is not very stable yet, I haven’t got around to it.
And there are issues in the KOS itself, which are clearly visible in the FTP server, in one direction the data goes very poorly, in the other direction it goes well.

[Изображение: barbers.png]
(Последний раз сообщение было отредактировано 08.08.2024 в 06:01, отредактировал пользователь SWAT.)
08.08.2024 05:57
Вебсайт Найти все сообщения Цитировать это сообщение
MastaG Не на форуме
Пользователь
**

Сообщений: 87
Зарегистрирован: 13.04.2011
Рейтинг: 0
Сказал спасибо: 31
Поблагодарили 12 раз(а) в 12 сообщ.
Сообщение: #4
RE: Help with LUA scripting.
Then I need to build v4.0.0 from source, using the source code from: https://github.com/DC-SWAT/DreamShell/re....0.Release
For the toolchain which compiler version did you use?
config.mk.10.5.0.sample config.mk.12.3.0.sample config.mk.14.0.1-dev.sample config.mk.9.3.0-legacy.sample config.mk.stable.sample
config.mk.11.4.0.sample config.mk.13.2.1-dev.sample config.mk.4.7.4-legacy.sample config.mk.9.5.0-winxp.sample

EDIT the binary DS_CORE of the v4.0.0 final release says: sh-elf-gcc (GCC) 13.2.0
So I'm going to use: config.mk.13.2.1-dev.sample

EDIT2:
Just need to read the README.md of the source code release.
(Последний раз сообщение было отредактировано 08.08.2024 в 13:22, отредактировал пользователь MastaG.)
08.08.2024 11:59
Найти все сообщения Цитировать это сообщение
MastaG Не на форуме
Пользователь
**

Сообщений: 87
Зарегистрирован: 13.04.2011
Рейтинг: 0
Сказал спасибо: 31
Поблагодарили 12 раз(а) в 12 сообщ.
Сообщение: #5
RE: Help with LUA scripting.
@SWAT
Would you happen to know if the iso loader was still working with this commit (and KOS commit?): https://github.com/DC-SWAT/DreamShell/co...0067422670
I want to build the last commit where both the iso loader and bios was working.
I think this would be: https://github.com/DC-SWAT/DreamShell/co...7462df1e07

Because after this commit, you've updated ds/sdk/doc/KallistiOS.txt with a newer version and I think you said that it broke the bios and iso loader.

EDIT: Nope..
https://github.com/DC-SWAT/DreamShell/co...7462df1e07 Seems too far ahead.
Quake3 reboots itself.
(Последний раз сообщение было отредактировано 08.08.2024 в 14:59, отредактировал пользователь MastaG.)
08.08.2024 14:23
Найти все сообщения Цитировать это сообщение
SWAT Не на форуме
Администратор
*******

Сообщений: 7217
Зарегистрирован: 04.01.2005
Рейтинг: 30
Сказал спасибо: 149
Поблагодарили 1209 раз(а) в 759 сообщ.
Сообщение: #6
RE: Help with LUA scripting.
Updating the KOS only affects the core and bootloader. It does not affect the ISO loader.
The ISO Loader is a bit broken at the moment, as some development is going on.
If you want a working version, use the release version.
If you want to develop something, just run other games that work. Most games work.
What is your goal?

[Изображение: barbers.png]
(Последний раз сообщение было отредактировано 09.08.2024 в 06:14, отредактировал пользователь SWAT.)
09.08.2024 06:11
Вебсайт Найти все сообщения Цитировать это сообщение
MastaG Не на форуме
Пользователь
**

Сообщений: 87
Зарегистрирован: 13.04.2011
Рейтинг: 0
Сказал спасибо: 31
Поблагодарили 12 раз(а) в 12 сообщ.
Сообщение: #7
RE: Help with LUA scripting.
You're correct about the iso loader, in later versions it seems most games work fine.

Well my goal is to turn on the DC.
It should Download an iso file from a http server and then run the iso loader.

My first goal is to not have it show the DreamShell logo, but actually show what is going on by showing the conole.
I've edited main.c to read:
Код:
setenv("HOST", "DreamShell", 1);
        setenv("OS", getenv("HOST"), 1);
        setenv("USER", getenv("HOST"), 1);
        setenv("ARCH", hardware_sys_mode(&tmpi) == HW_TYPE_SET5 ? "Set5.xx" : "Dreamcast", 1);

        setenv("NET_IPV4", "0.0.0.0", 1);

        setenv("SDL_DEBUG", "0", 1);
        setenv("SDL_VIDEODRIVER", "dcvideo", 1);

        snd_stream_init();
        // Do not play startup audio
        // ds_sfx_play(DS_SFX_STARTUP);

        InitVideoHardware();
        // Do not show bootlogo
        // ShowLogo();

        vmu_draw_string(getenv("HOST"));
        dbglog(DBG_INFO, "Initializing DreamShell Core...\n");

        SetConsoleDebug(1);
        // Show the console
        ShowConsole();

        setenv("HOME", getenv("PATH"), 1);
        setenv("$PATH", getenv("PATH"), 1);
        setenv("LUA_PATH", getenv("PATH"), 1);
        setenv("LUA_CPATH", getenv("PATH"), 1);
        setenv("PWD", fs_getwd(), 1);
        setenv("APP", (settings->app[0] != 0 ? settings->app : "Main"), 1);

Without any edits to startup.lua.

But it hangs now..
09.08.2024 18:40
Найти все сообщения Цитировать это сообщение
MastaG Не на форуме
Пользователь
**

Сообщений: 87
Зарегистрирован: 13.04.2011
Рейтинг: 0
Сказал спасибо: 31
Поблагодарили 12 раз(а) в 12 сообщ.
Сообщение: #8
RE: Help with LUA scripting.
Okay so I got a bit further.
In src/main.c I've only commented out the startup sound.
It seems ShowLogo(); is required after InitVideoHardware();


Now in lua/startup.lua:

I've only added network init and trying to start gta3:
Код:
        self:InstallingApps(path .. "/apps");
        self.initialized = true;
        os.execute("net --init");
        isoldr -i -a -x 0x8c004000 -f /ide/GTA3/regta3dc.ds.iso -o 1 -h 0
        OpenApp(os.getenv("APP"));

Also the following modules are enabled: http, minilzo, isofs and isoldr.

But the isoldr command right before the OpenApp seems to hang the console.
09.08.2024 19:28
Найти все сообщения Цитировать это сообщение
MastaG Не на форуме
Пользователь
**

Сообщений: 87
Зарегистрирован: 13.04.2011
Рейтинг: 0
Сказал спасибо: 31
Поблагодарили 12 раз(а) в 12 сообщ.
Сообщение: #9
RE: Help with LUA scripting.
Okay, got the iso to auto start Big Grin
Код:
        self:InstallingApps(path .. "/apps");
        self.initialized = true;
        os.execute("net --init");
        OpenApp(os.getenv("APP"));
        os.execute("isoldr -i -a -x 0x8c000100 -f /ide/GTA3/regta3dc.ds.iso -o 1 -h 0");

Now I only need to copy the new iso from the http server before it executes the isoloader.
(Последний раз сообщение было отредактировано 09.08.2024 в 19:46, отредактировал пользователь MastaG.)
09.08.2024 19:44
Найти все сообщения Цитировать это сообщение
MastaG Не на форуме
Пользователь
**

Сообщений: 87
Зарегистрирован: 13.04.2011
Рейтинг: 0
Сказал спасибо: 31
Поблагодарили 12 раз(а) в 12 сообщ.
Сообщение: #10
RE: Help with LUA scripting.
I'm still awaiting my serial cable so I can actually see what is going on.
But according to "the inernet", it should be something like this:
Код:
...
        self:InstallingApps(path .. "/apps");
        self.initialized = true;
        
        -- Networking
        os.execute("net --init");
        
        -- Trying to download a file
        local ltn12 = require("ltn12");
        ltn12.pump.all(
            ltn12.source.file(assert(io.open("/http/xxx/regta3dc.ds.iso", "rb"))),
            ltn12.sink.file(assert(io.open("/ide/GTA3/regta3dc.ds.iso", "wb")))
        );
        
        OpenApp(os.getenv("APP"));
        -- Run GTA3
        os.execute("isoldr -i -a -x 0x8c000100 -f /ide/GTA3/regta3dc.ds.iso -o 1 -h 0");
        os.execute("console --show");
    end,
...

Unfortunately it seems to hang here.
Any ideas @SWAT ?
12.08.2024 11:56
Найти все сообщения Цитировать это сообщение
SWAT Не на форуме
Администратор
*******

Сообщений: 7217
Зарегистрирован: 04.01.2005
Рейтинг: 30
Сказал спасибо: 149
Поблагодарили 1209 раз(а) в 759 сообщ.
Сообщение: #11
RE: Help with LUA scripting.
Network issue, HTTP module issue, Lua issue Smile
I don't know and I haven't tested it like that.
Network capabilities in DS have still received little attention.
What I tested well is ping and ftp server module. They work, but ftp server shows that in KallistiOS there is a issue with the network in one direction, from PC to DC.
You can get data from the DC well, but you can only send a small amount to the DC in a reasonable amount of time. A large size will make it infinite.

[Изображение: barbers.png]
(Последний раз сообщение было отредактировано 13.08.2024 в 06:54, отредактировал пользователь SWAT.)
13.08.2024 06:51
Вебсайт Найти все сообщения Цитировать это сообщение
Создать ответ 


Переход:


Пользователи просматривают эту тему: 6 Гость(ей)