From 4a24f72e3f9c1ced8b6b2919623c6f69ef639e2c Mon Sep 17 00:00:00 2001 From: Paul Molloy pinkASUS Date: Sun, 9 Jul 2017 18:51:37 -0500 Subject: [PATCH] Now able to make dictionary call from lua scripts. Currently have redefined table that needs to align with shared dictionary files. Next task is to parse shared dictionary files to create tables at runtime. --- host/scripts/inlretro.lua | 23 +++++++++++++++++++++-- host/source/dictionary.c | 27 +++++++++++++++------------ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/host/scripts/inlretro.lua b/host/scripts/inlretro.lua index 037beca..2e4cac9 100644 --- a/host/scripts/inlretro.lua +++ b/host/scripts/inlretro.lua @@ -1,10 +1,29 @@ -- main script that runs application logic and flow +-- Dictionary table definitions +dict = {} +dict["DICT_PINPORT"] = 1 +dict["DICT_IO"] = 2 +dict["DICT_NES"] = 3 +dict["DICT_SNES"] = 4 +dict["DICT_BUFFER"] = 5 +dict["DICT_USB"] = 6 +dict["DICT_OPER"] = 7 + +pinport = {} +pinport["LED_IP"] = 65 +pinport["LED_OP"] = 66 +pinport["LED_OFF"] = 67 +pinport["LED_ON"] = 68 + +USB_IN = 0x80 --device to host +USB_OUT = 0x00 --host to device + -- initial function called from C main function main () - print("print from main.\n") - print("dict_call ", dict_call( 1, 2, 3, 4), "\n") + -- print dictionary opcode addr miscdata endpt buffer length + print("dict_call ", dict_call( 1, dict["DICT_PINPORT"], pinport["LED_OFF"], 0, 0, USB_IN, nil, 1), "\n") end -- call functions desired to run when script is called diff --git a/host/source/dictionary.c b/host/source/dictionary.c index d9b9bac..53b2f32 100644 --- a/host/source/dictionary.c +++ b/host/source/dictionary.c @@ -8,24 +8,27 @@ void init_dictionary( USBtransfer *transfer ) { } int lua_dictionary_call (lua_State *L) { - //double d = lua_tonumber(L, 1); /* get argument */ - int arg1 = luaL_checknumber(L, 1); /* get argument */ - int arg2 = luaL_checknumber(L, 2); /* get argument */ - int arg3 = luaL_checknumber(L, 3); /* get argument */ - int arg4 = luaL_checknumber(L, 4); /* get argument */ - printf("arg1 %d, arg2 %d\n", arg1, arg2); - printf("arg3 %d, arg4 %d\n", arg3, arg4); + int arg1 = luaL_checknumber(L, 1); /* get print argument */ + int arg2 = luaL_checknumber(L, 2); /* get dictionary argument */ + int arg3 = luaL_checknumber(L, 3); /* get opcode argument */ + int arg4 = luaL_checknumber(L, 4); /* get addr argument */ + int arg5 = luaL_checknumber(L, 5); /* get miscdata argument */ + int arg6 = luaL_checknumber(L, 6); /* get endpoint argument */ + //int arg7 = luaL_checknumber(L, 7); /* get buffer argument */ + int arg8 = luaL_checknumber(L, 8); /* get length argument */ + int rv; //return value + + +// printf("arg1 %d, arg2 %d\n", arg1, arg2); +// printf("arg3 %d, arg4 %d\n", arg3, arg4); check( usb_xfr != NULL, "dictionary usb transfer pointer not initialized.\n") //dictionary_call_print_option( FALSE, transfer, dictionary, opcode, addr, miscdata, endpoint, buffer, length); - dictionary_call( usb_xfr, DICT_PINPORT, LED_OP, 0, 0, USB_IN, - NULL, 1); - dictionary_call( usb_xfr, DICT_PINPORT, LED_ON, 0, 0, USB_IN, - NULL, 1); + rv = dictionary_call_print_option( arg1, usb_xfr, arg2, arg3, arg4, arg5, arg6, NULL, arg8); - lua_pushnumber(L, (2*arg1)); /* push result */ + lua_pushnumber(L, rv); /* push result */ return 1; /* number of results */ error: