Conversion of RGBDS ASM to CIL/C#
Sample ASM Input:
assert_valid_rgb: MACRO
rept _NARG
assert 0 <= (\1) && (\1) <= 31, "RGB channel must be 0-31"
shift
endr
ENDM
RGB: MACRO
rept _NARG / 3
assert_valid_rgb \1, \2, \3
dw palred (\1) + palgreen (\2) + palblue (\3)
shift 3
endr
ENDM
palred EQUS "(1 << 0) *"
palgreen EQUS "(1 << 5) *"
palblue EQUS "(1 << 10) *"
;Graphics data header macro
;Format:
;1:bank number
;2:bank data offset
;3:start vram address
;4:type(0: uncompressed, 1: compressed w/ header, 2: compressed no header)
;5:length (not needed if type is 1)
gfxheader: MACRO
db \1
dw \2
dw \3
IF \4 == 1
db 0
ELSE
db (\5 & $FF)
ENDC
IF \4 == 1
db $80
ELIF \4 == 2
db $80 | (\5 >> 8)
ELSE
db (\5 >> 8)
ENDC
ENDM
Sample [WIP] C# Output:
namespace Macros
{
public class Gfx
{
public void Assert_Valid_Rgb(params object[] args)
{
for (var i = 0; i < args.Length; i++)
{
Debug.Assert(0 <= (args[0]) && (args[0]) <= 31, "RGB channel must be 0-31");
Shift();
}
}
public void RGB(params object[] args)
{
for (var i = 0; i < args.Length / 3; i++)
{
Assert_Valid_Rgb(args[0], args[1], args[2]);
Define(typeof(System.Int16), palred (args[0]) + palgreen (args[1]) + palblue (args[2]));
Shift();
}
}
const string palred = "(1 << 0) *";
const string palgreen = "(1 << 5) *";
const string palblue = "(1 << 10) *";
// Graphics data header macro
// Format:
// 1:bank number
// 2:bank data offset
// 3:start vram address
// 4:type(0: uncompressed, 1: compressed w/ header, 2: compressed no header)
// 5:length (not needed if type is 1)
public void Gfxheader(params object[] args)
{
Define(typeof(System.Byte), args[0]);
Define(typeof(System.Int16), args[1]);
Define(typeof(System.Int16), args[2]);
if (args[3] == 1)
{
Define(typeof(System.Byte), 0);
}
else
{
Define(typeof(System.Byte), (args[4] & 0xFF));
}
if (args[3] == 1)
{
Define(typeof(System.Byte), 0x80);
}
else if (args[3] == 2)
{
Define(typeof(System.Byte), 0x80 | (args[4] >> 8));
}
else
{
Define(typeof(System.Byte), (args[4] >> 8));
}
}
}
}