0 Members and 1 Guest are viewing this topic.
;Example usage:; varloc(tempswaparea);player_x = var(1);player_y = var(1);buffer_bullets = var(128);saveSP = var(2); varloc(textshadow,128);attack = var(1);deffence = var(1);overflowedvar = var(500) ;this will give a warning on assembling because overflowed the safe ram (on calculator causes RAM Clear, normally)#macro var(var.size) #define var.counter eval(var.counter+var.inc) #define var.inc eval(var.size) #ifdef var.end #if var.counter>var.end .error "Variable allocation overflow!" #endif #endif var.counter#endmacro#macro varloc(varloc.value,varloc.size) #define var.counter eval(varloc.value) #define var.inc 0 #ifdef varloc.size #define var.end eval(varloc.value+varloc.size-1) #endif#endmacro
;Example usage:; .echo convhex(%10000000);label:; .echo convhex(label)#macro zconvhex(hexn)#if hex_remain == 0 "$",return#else #define hex_digit eval(hexn & $0F) #define hex_remain eval(hexn/16) #ifndef return #define return "" #endif #if hex_digit == 0 #define hex_char "0" #endif #if hex_digit == 1 #define hex_char "1" #endif #if hex_digit == 2 #define hex_char "2" #endif #if hex_digit == 3 #define hex_char "3" #endif #if hex_digit == 4 #define hex_char "4" #endif #if hex_digit == 5 #define hex_char "5" #endif #if hex_digit == 6 #define hex_char "6" #endif #if hex_digit == 7 #define hex_char "7" #endif #if hex_digit == 8 #define hex_char "8" #endif #if hex_digit == 9 #define hex_char "9" #endif #if hex_digit == 10 #define hex_char "A" #endif #if hex_digit == 11 #define hex_char "B" #endif #if hex_digit == 12 #define hex_char "C" #endif #if hex_digit == 13 #define hex_char "D" #endif #if hex_digit == 14 #define hex_char "E" #endif #if hex_digit == 15 #define hex_char "F" #endif #define return eval(hex_char,return) zconvhex(eval(hex_remain))#endif#endmacro;wrap the main macro up with another macro to clear the global defines to work more times#macro convhex(zn) #define hex_remain -1 #define return "" zconvhex(zn)#endmacro
;breakpoints.inc;by Galandros#include "convhex.inc"#macro BREAKPOINT #ifndef BREAK_F .echo > breakpoints.txt "\nBreakpoints:\n" .echo >> breakpoints.txt convhex($),"\n" #define BREAK_F #else .echo >> breakpoints.txt convhex($),"\n" #endif#endmacro;Alternatives to break macro name#define breakpoint() BREAKPOINT#define .breakpoint BREAKPOINT
#macro relocate(location) #ifdef g_old_location .error "You cannot nest relocate blocks!" #else #define g_old_location eval($) #define g_new_location eval(location) .org location #endif#endmacro#macro endrelocate() #ifdef g_new_location .org $ - g_new_location + g_old_location #undefine g_new_location #undefine g_old_location #else .error "No relocate statements corresponds to this endrelocate!" #endif#endmacro
By labels I assume you mean a bit like the TI-BASIC ones, right?
#macro include_once(file) clr() wr("#ifndef ",file,"_INC") wr("#define ",file,"_INC") wr("#include ",file) wr("#endif") run() clr()#endmacro#define .include_once include_once(#macro align(boundary); Sets the current program counter value to the next multiple of boundary. .fill boundary-($%boundary)#endmacro#define .align align(#macro pad_str(str, size)_.db str#define str_len eval($- -_)#if str_len <= size .fill size-str_len,' ' .db 0 ; NULL terminator#else .error "String size is ",str_len-size," character(s) too long."#endif#endmacro#define .pad_str pad_str(#macro REPEAT(code,times)#if times==0#include temp.asm .echo > temp.asm ""#else .echo >> temp.asm code,"\n" REPEAT(code,eval(times-1))#endif#endmacro#define .repeat REPEAT(;l:; .repeat " ld a,1",8;m:; .echo m-l