;;; ============================================================ ;;; Generic Macros ;;; ============================================================ .define _is_immediate(arg) (.match (.mid (0, 1, {arg}), #)) .define _is_register(arg) (.match ({arg}, x) .or .match ({arg}, y)) .define _immediate_value(arg) (.right (.tcount ({arg})-1, {arg})) .macro _op_lo op, arg .if _is_immediate {arg} op #<_immediate_value {arg} .else op arg .endif .endmacro .macro _op_hi op, arg .if _is_immediate {arg} op #>_immediate_value {arg} .else op arg+1 .endif .endmacro ;;; ============================================================ ;;; Pad with zeros to the given address .macro PAD_TO addr .res addr - *, 0 .endmacro ;;; ============================================================ ;;; Common patterns .macro return arg lda arg rts .endmacro ;;; ============================================================ ;;; Calls with one parameter (address in A,X) .macro addr_call target, addr lda #addr jsr target .endmacro .macro addr_call_indirect target, addr lda addr ldx addr+1 jsr target .endmacro .macro addr_jump target, addr lda #addr jmp target .endmacro ;;; ============================================================ ;;; Calls with two paramters (call # in y, address in A,X) ;;; (various output orders to match original binary) .macro axy_call target, yparam, addr lda #addr ldy #yparam jsr target .endmacro .macro yax_call target, yparam, addr ldy #yparam lda #addr jsr target .endmacro .macro yxa_call target, yparam, addr ldy #yparam ldx #>addr lda #addr lda #