add grrlib.
also restructure the code so the js file has an update and start function that gets called.
This commit is contained in:
parent
e5dfbf0e0c
commit
e9349f026a
10 changed files with 124 additions and 63 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "dependencies/GRRLIB/source"]
|
||||
path = dependencies/GRRLIB/source
|
||||
url = https://git.fries.gay/fries/GRRLIB
|
34
.vscode/launch.json
vendored
Normal file
34
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "(gdb) Launch",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/source/WiiDuktape.elf",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "/opt/devkitpro/devkitPPC/bin/powerpc-eabi-gdb",
|
||||
"miDebuggerServerAddress": "127.0.0.1:42069",
|
||||
"debugServerPath": "${workspaceFolder}/dolphin.sh",
|
||||
"debugServerArgs": "-e ${workspaceFolder}/build/source/WiiDuktape.elf --batch"
|
||||
},
|
||||
{
|
||||
"name": "(gdb) Attach",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/source/WiiDuktape.elf",
|
||||
"cwd": "${fileDirname}",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "/opt/devkitpro/devkitPPC/bin/powerpc-eabi-gdb",
|
||||
"miDebuggerServerAddress": "127.0.0.1:42069",
|
||||
},
|
||||
]
|
||||
}
|
|
@ -11,5 +11,5 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||
|
||||
project(WiiDuktape)
|
||||
|
||||
add_subdirectory(dependencies/duktape)
|
||||
add_subdirectory(dependencies)
|
||||
add_subdirectory(source)
|
||||
|
|
2
dependencies/CMakeLists.txt
vendored
Normal file
2
dependencies/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
add_subdirectory(duktape)
|
||||
add_subdirectory(GRRLIB)
|
42
dependencies/GRRLIB/CMakeLists.txt
vendored
Normal file
42
dependencies/GRRLIB/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
project(GRRLIB)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(PNG REQUIRED libpng)
|
||||
pkg_check_modules(FREETYPE REQUIRED freetype2)
|
||||
|
||||
|
||||
set(GRRLIB_DIR ./source/GRRLIB/GRRLIB)
|
||||
set(PNGU_DIR ./source/GRRLIB/lib/pngu)
|
||||
|
||||
set (pngu_sources
|
||||
${PNGU_DIR}/pngu.c
|
||||
)
|
||||
add_library(pngu ${pngu_sources})
|
||||
target_link_libraries(pngu PRIVATE ${PNG_LIBRARIES})
|
||||
target_include_directories(pngu PRIVATE ${PNG_INCLUDE_DIRS})
|
||||
target_include_directories(pngu PUBLIC ${PNGU_DIR})
|
||||
|
||||
set(grrlib_sources
|
||||
${GRRLIB_DIR}/GRRLIB_3D.c
|
||||
${GRRLIB_DIR}/GRRLIB_bmf.c
|
||||
${GRRLIB_DIR}/GRRLIB_bmfx.c
|
||||
${GRRLIB_DIR}/GRRLIB_core.c
|
||||
${GRRLIB_DIR}/GRRLIB_fbAdvanced.c
|
||||
${GRRLIB_DIR}/GRRLIB_fileIO.c
|
||||
${GRRLIB_DIR}/GRRLIB_gecko.c
|
||||
${GRRLIB_DIR}/GRRLIB_print.c
|
||||
${GRRLIB_DIR}/GRRLIB_render.c
|
||||
${GRRLIB_DIR}/GRRLIB_snapshot.c
|
||||
${GRRLIB_DIR}/GRRLIB_ttf.c
|
||||
)
|
||||
|
||||
add_library(GRRLIB ${grrlib_sources})
|
||||
target_link_libraries(GRRLIB PRIVATE pngu)
|
||||
target_link_libraries(GRRLIB PRIVATE ${FREETYPE_LIBRARIES})
|
||||
target_link_libraries(GRRLIB PRIVATE fat)
|
||||
target_include_directories(GRRLIB PRIVATE ${FREETYPE_INCLUDE_DIRS})
|
||||
|
||||
target_include_directories(GRRLIB PUBLIC ${GRRLIB_DIR})
|
||||
|
1
dependencies/GRRLIB/source
vendored
Submodule
1
dependencies/GRRLIB/source
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit d93847e6a3e350bd1157d61cc1315d8bbff76968
|
2
dolphin.sh
Executable file
2
dolphin.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
QT_QPA_PLATFORM=xcb /usr/bin/dolphin-emu $@
|
|
@ -7,4 +7,5 @@ add_custom_command(
|
|||
|
||||
add_executable(WiiDuktape main.c game.c)
|
||||
target_link_libraries(WiiDuktape duktape)
|
||||
target_link_libraries(WiiDuktape GRRLIB)
|
||||
ogc_create_dol(WiiDuktape)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
const PAD_BUTTON_START = 0x1000;
|
||||
const PAD_BUTTON_A = 0x0100;
|
||||
|
||||
while (wii.running) {
|
||||
wii.pad.scan_pads();
|
||||
function start() {
|
||||
}
|
||||
|
||||
function update() {
|
||||
const pressed = wii.pad.buttons_down();
|
||||
|
||||
if (pressed & PAD_BUTTON_START) {
|
||||
|
@ -15,5 +16,5 @@ while (wii.running) {
|
|||
wii.print("a pressed");
|
||||
}
|
||||
|
||||
wii.video.wait_vsync();
|
||||
wii.grrlib.fill_screen();
|
||||
}
|
||||
|
|
|
@ -1,32 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gccore.h>
|
||||
#include <ogcsys.h>
|
||||
#include <grrlib.h>
|
||||
#include <duktape.h>
|
||||
|
||||
static void *xfb = NULL;
|
||||
static GXRModeObj *rmode = NULL;
|
||||
extern const char* program;
|
||||
static bool running = true;
|
||||
|
||||
static duk_ret_t native_print(duk_context *ctx) {
|
||||
printf("%s\n", duk_to_string(ctx, 0));
|
||||
GRRLIB_GeckoPrintf("%s\n", duk_to_string(ctx, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static duk_ret_t native_exit(duk_context *ctx) {
|
||||
duk_push_global_object(ctx);
|
||||
duk_push_string(ctx, "wii");
|
||||
duk_get_prop(ctx, -2);
|
||||
duk_push_boolean(ctx, false);
|
||||
duk_put_prop_string(ctx, -2, "running");
|
||||
running = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void duk_fatal_error(void *udata, const char *msg) {
|
||||
printf("an error has occured: %s\n", msg);
|
||||
GRRLIB_GeckoPrintf("an error has occured: %s\n", msg);
|
||||
}
|
||||
|
||||
static duk_ret_t video_wait_vsync(duk_context *ctx) {
|
||||
VIDEO_WaitVSync();
|
||||
static duk_ret_t grrlib_fill_screen(duk_context *ctx) {
|
||||
GRRLIB_FillScreen(0xFFFFFFFF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -51,11 +44,11 @@ static void define_pad_object(duk_context *ctx) {
|
|||
duk_put_prop_string(ctx, pad_obj, "buttons_down");
|
||||
}
|
||||
|
||||
static void define_video_object(duk_context *ctx) {
|
||||
duk_idx_t video_obj = duk_push_object(ctx);
|
||||
static void define_grrlib_object(duk_context *ctx) {
|
||||
duk_idx_t grrlib_obj = duk_push_object(ctx);
|
||||
|
||||
duk_push_c_function(ctx, video_wait_vsync, 0);
|
||||
duk_put_prop_string(ctx, video_obj, "wait_vsync");
|
||||
duk_push_c_function(ctx, grrlib_fill_screen, 0);
|
||||
duk_put_prop_string(ctx, grrlib_obj, "fill_screen");
|
||||
}
|
||||
|
||||
static void define_wii_object(duk_context *ctx) {
|
||||
|
@ -70,63 +63,45 @@ static void define_wii_object(duk_context *ctx) {
|
|||
define_pad_object(ctx);
|
||||
duk_put_prop_string(ctx, wii_obj, "pad");
|
||||
|
||||
define_video_object(ctx);
|
||||
duk_put_prop_string(ctx, wii_obj, "video");
|
||||
define_grrlib_object(ctx);
|
||||
duk_put_prop_string(ctx, wii_obj, "grrlib");
|
||||
|
||||
duk_push_boolean(ctx, true);
|
||||
duk_put_prop_string(ctx, wii_obj, "running");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Initialise the video system
|
||||
VIDEO_Init();
|
||||
|
||||
// This function initialises the attached controllers
|
||||
GRRLIB_Init();
|
||||
PAD_Init();
|
||||
|
||||
// Obtain the preferred video mode from the system
|
||||
// This will correspond to the settings in the Wii menu
|
||||
rmode = VIDEO_GetPreferredMode(NULL);
|
||||
|
||||
// Allocate memory for the display in the uncached region
|
||||
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
|
||||
|
||||
// Initialise the console, required for printf
|
||||
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
|
||||
|
||||
// Set up the video registers with the chosen mode
|
||||
VIDEO_Configure(rmode);
|
||||
|
||||
// Tell the video hardware where our display memory is
|
||||
VIDEO_SetNextFramebuffer(xfb);
|
||||
|
||||
// Make the display visible
|
||||
VIDEO_SetBlack(false);
|
||||
|
||||
// Flush the video register changes to the hardware
|
||||
VIDEO_Flush();
|
||||
|
||||
// Wait for Video setup to complete
|
||||
VIDEO_WaitVSync();
|
||||
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
|
||||
|
||||
// The console understands VT terminal escape codes
|
||||
// This positions the cursor on row 2, column 0
|
||||
// we can use variables for this with format codes too
|
||||
// e.g. printf ("\x1b[%d;%dH", row, column );
|
||||
printf("\x1b[2;0H");
|
||||
|
||||
duk_context *ctx = duk_create_heap(NULL, NULL, NULL, NULL, duk_fatal_error);
|
||||
|
||||
define_wii_object(ctx);
|
||||
duk_put_global_string(ctx, "wii");
|
||||
|
||||
// evaluate functions from game.js
|
||||
duk_eval_string_noresult(ctx, program);
|
||||
|
||||
printf("destroying heap\n");
|
||||
// call start function
|
||||
duk_get_global_string(ctx, "start");
|
||||
duk_call(ctx, 0);
|
||||
duk_pop(ctx);
|
||||
|
||||
while (running) {
|
||||
PAD_ScanPads();
|
||||
|
||||
duk_get_global_string(ctx, "update");
|
||||
duk_call(ctx, 0);
|
||||
duk_pop(ctx);
|
||||
|
||||
GRRLIB_Render();
|
||||
}
|
||||
|
||||
// printf("destroying heap\n");
|
||||
duk_destroy_heap(ctx);
|
||||
|
||||
printf("exit time\n");
|
||||
// printf("exit time\n");
|
||||
GRRLIB_Exit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue