bindings: Hack which allows returning multiple values
This really needs to be done better.
This commit is contained in:
parent
6a790fc1e4
commit
259f524fd1
|
@ -3,12 +3,25 @@
|
||||||
|
|
||||||
#include "call.h"
|
#include "call.h"
|
||||||
|
|
||||||
|
struct return2 { unsigned int return0; unsigned int return1; };
|
||||||
|
struct return3 { unsigned int return0; unsigned int return1; unsigned int return2; };
|
||||||
|
struct return4 { unsigned int return0; unsigned int return1; unsigned int return2; unsigned int return3; };
|
||||||
|
struct return5 { unsigned int return0; unsigned int return1; unsigned int return2; unsigned int return3; unsigned int return4; };
|
||||||
|
struct return6 { unsigned int return0; unsigned int return1; unsigned int return2; unsigned int return3; unsigned int return4; unsigned int return5; };
|
||||||
|
struct return7 { unsigned int return0; unsigned int return1; unsigned int return2; unsigned int return3; unsigned int return4; unsigned int return5; unsigned int return6; };
|
||||||
|
struct return8 { unsigned int return0; unsigned int return1; unsigned int return2; unsigned int return3; unsigned int return4; unsigned int return5; unsigned int return6; unsigned int return7; };
|
||||||
|
|
||||||
// fox32rom definitions
|
// fox32rom definitions
|
||||||
|
|
||||||
// system jump table
|
// system jump table
|
||||||
|
|
||||||
static inline void get_rom_version(void) {
|
static inline struct return3 get_rom_version(void) {
|
||||||
|
struct return3 result_0;
|
||||||
call(0xF0040000);
|
call(0xF0040000);
|
||||||
|
ret(0, result_0.return0);
|
||||||
|
ret(1, result_0.return1);
|
||||||
|
ret(2, result_0.return2);
|
||||||
|
return result_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void system_vsync_handler(void) {
|
static inline void system_vsync_handler(void) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ val IHalf = Type("short")
|
||||||
val Word = Type("unsigned int")
|
val Word = Type("unsigned int")
|
||||||
val IWord = Type("int")
|
val IWord = Type("int")
|
||||||
|
|
||||||
class Variable(val type: Type, val name: String)
|
class Variable(val type: Type, val name: String, val is_struct: Boolean)
|
||||||
|
|
||||||
class Function(val address: UInt, val name: String) {
|
class Function(val address: UInt, val name: String) {
|
||||||
class Register(val index: Int, val variable: Variable)
|
class Register(val index: Int, val variable: Variable)
|
||||||
|
@ -25,14 +25,17 @@ class Function(val address: UInt, val name: String) {
|
||||||
parameter(parameters.indexOfFirst { it == null }, type, name)
|
parameter(parameters.indexOfFirst { it == null }, type, name)
|
||||||
}
|
}
|
||||||
fun parameter(index: Int, type: Type, name: String) {
|
fun parameter(index: Int, type: Type, name: String) {
|
||||||
parameters[index] = Variable(type, name)
|
parameters[index] = Variable(type, name, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun returns(type: Type) {
|
fun returns(type: Type) {
|
||||||
returns(returns.indexOfFirst { it == null }, type)
|
returns(returns.indexOfFirst { it == null }, type)
|
||||||
}
|
}
|
||||||
fun returns(index: Int, type: Type) {
|
fun returns(index: Int, type: Type) {
|
||||||
returns[index] = Variable(type, "result_${index}")
|
returns[index] = Variable(type, "result_${index}", false)
|
||||||
|
}
|
||||||
|
fun returnstruct(index: Int, suffix: String, type: Type) {
|
||||||
|
returns[index] = Variable(type, "result_0.${suffix}", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
@ -65,12 +68,20 @@ class Function(val address: UInt, val name: String) {
|
||||||
text.append(") {\n")
|
text.append(") {\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
outputs.forEach {
|
for ((i, v) in outputs.withIndex()) {
|
||||||
text.append(" ")
|
if (!v.variable.is_struct) {
|
||||||
text.append(it.variable.type)
|
text.append(" ")
|
||||||
text.append(" ")
|
text.append(v.variable.type)
|
||||||
text.append(it.variable.name)
|
text.append(" ")
|
||||||
text.append(";\n")
|
text.append(v.variable.name.split(".")[0])
|
||||||
|
text.append(";\n")
|
||||||
|
} else if (i == 0) {
|
||||||
|
text.append(" ")
|
||||||
|
text.append(outputs.first().variable.type)
|
||||||
|
text.append(" ")
|
||||||
|
text.append(outputs.first().variable.name.split(".")[0])
|
||||||
|
text.append(";\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inputs.forEach {
|
inputs.forEach {
|
||||||
|
@ -99,7 +110,7 @@ class Function(val address: UInt, val name: String) {
|
||||||
if (returns != null) {
|
if (returns != null) {
|
||||||
text.append(" ")
|
text.append(" ")
|
||||||
text.append("return ")
|
text.append("return ")
|
||||||
text.append(returns.variable.name)
|
text.append(returns.variable.name.split(".")[0])
|
||||||
text.append(";\n")
|
text.append(";\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +127,14 @@ source.append("#pragma once\n")
|
||||||
source.append("\n")
|
source.append("\n")
|
||||||
source.append("#include \"call.h\"\n")
|
source.append("#include \"call.h\"\n")
|
||||||
source.append("\n")
|
source.append("\n")
|
||||||
|
source.append("struct return2 { unsigned int return0; unsigned int return1; };\n")
|
||||||
|
source.append("struct return3 { unsigned int return0; unsigned int return1; unsigned int return2; };\n")
|
||||||
|
source.append("struct return4 { unsigned int return0; unsigned int return1; unsigned int return2; unsigned int return3; };\n")
|
||||||
|
source.append("struct return5 { unsigned int return0; unsigned int return1; unsigned int return2; unsigned int return3; unsigned int return4; };\n")
|
||||||
|
source.append("struct return6 { unsigned int return0; unsigned int return1; unsigned int return2; unsigned int return3; unsigned int return4; unsigned int return5; };\n")
|
||||||
|
source.append("struct return7 { unsigned int return0; unsigned int return1; unsigned int return2; unsigned int return3; unsigned int return4; unsigned int return5; unsigned int return6; };\n")
|
||||||
|
source.append("struct return8 { unsigned int return0; unsigned int return1; unsigned int return2; unsigned int return3; unsigned int return4; unsigned int return5; unsigned int return6; unsigned int return7; };\n")
|
||||||
|
source.append("\n")
|
||||||
|
|
||||||
fun comment(text: String) {
|
fun comment(text: String) {
|
||||||
source.append("// ")
|
source.append("// ")
|
||||||
|
@ -147,6 +166,9 @@ comment("fox32rom definitions")
|
||||||
comment("system jump table")
|
comment("system jump table")
|
||||||
|
|
||||||
define(0xF0040000U, "get_rom_version") {
|
define(0xF0040000U, "get_rom_version") {
|
||||||
|
returnstruct(0, "return0", Type("struct return3"))
|
||||||
|
returnstruct(1, "return1", Type("struct return3"))
|
||||||
|
returnstruct(2, "return2", Type("struct return3"))
|
||||||
}
|
}
|
||||||
define(0xF0040004U, "system_vsync_handler") {
|
define(0xF0040004U, "system_vsync_handler") {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user