; smc.mac\r
; ca65 Macro-Pack for Self Modifying Code (SMC)\r
;\r
-; (c) Christian Krüger, latest change: 09-Nov-2011\r
+; (c) Christian Krüger, latest change: 17-Jul-2016\r
;\r
; This software is provided 'as-is', without any expressed or implied\r
; warranty. In no event will the authors be held liable for any damages\r
.endmacro\r
\r
.macro SMC_TransferOpcode label, opcode, register\r
-.if .paramcount = 2 .or .match ({register}, a)\r
+.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )\r
lda #opcode\r
sta _SMCDesignator\r
.elseif .match ({register}, x)\r
.elseif .match ({register}, y)\r
ldy #opcode\r
sty _SMCDesignator\r
+.else\r
+ .error "Invalid usage of macro 'SMC_TransferOpcode'"\r
.endif\r
.endmacro\r
\r
.macro SMC_LoadOpcode label, register\r
-.if .paramcount = 1 .or .match ({register}, a)\r
+.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )\r
lda _SMCDesignator\r
.elseif .match ({register}, x)\r
ldx _SMCDesignator\r
.elseif .match ({register}, y)\r
ldy _SMCDesignator\r
+.else\r
+ .error "Invalid usage of macro 'SMC_TransferOpcode'"\r
.endif\r
.endmacro\r
\r
.macro SMC_StoreOpcode label, register\r
-.if .paramcount = 1 .or .match ({register}, a)\r
+.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )\r
sta _SMCDesignator\r
.elseif .match ({register}, x)\r
stx _SMCDesignator\r
.elseif .match ({register}, y)\r
sty _SMCDesignator\r
+.else\r
+ .error "Invalid usage of macro 'SMC_StoreOpcode'"\r
.endif\r
.endmacro\r
\r
.macro SMC_ChangeBranch label, destination, register\r
-.if .paramcount = 2 .or .match ({register}, a)\r
- lda #(destination - _SMCDesignator -2)\r
+.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )\r
+ lda #(<(destination - _SMCDesignator -2))\r
sta _SMCDesignator+1\r
.elseif .match ({register}, x)\r
- ldx #(destination - _SMCDesignator - 2)\r
+ ldx #(<(destination - _SMCDesignator - 2))\r
stx _SMCDesignator+1\r
.elseif .match ({register}, y)\r
- ldy #(destination - _SMCDesignator - 2)\r
+ ldy #(<(destination - _SMCDesignator - 2))\r
sty _SMCDesignator+1\r
+.else\r
+ .error "Invalid usage of macro 'SMC_ChangeBranch'"\r
.endif\r
.endmacro\r
\r
.macro SMC_TransferValue label, value, register\r
-.if .paramcount = 2 .or .match ({register}, a)\r
+.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )\r
lda value\r
sta _SMCDesignator+1\r
.elseif .match ({register}, x)\r
.elseif .match ({register}, y)\r
ldy value\r
sty _SMCDesignator+1\r
+.else\r
+ .error "Invalid usage of macro 'SMC_TransferValue'"\r
.endif\r
.endmacro\r
\r
.macro SMC_LoadValue label, register\r
-.if .paramcount = 1 .or .match ({register}, a)\r
+.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )\r
lda _SMCDesignator+1\r
.elseif .match ({register}, x)\r
ldx _SMCDesignator+1\r
.elseif .match ({register}, y)\r
ldy _SMCDesignator+1\r
+.else\r
+ .error "Invalid usage of macro 'SMC_LoadValue'"\r
.endif\r
.endmacro\r
\r
.macro SMC_StoreValue label, register\r
-.if .paramcount = 1 .or .match ({register}, a)\r
+.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )\r
sta _SMCDesignator+1\r
.elseif .match ({register}, x)\r
stx _SMCDesignator+1\r
.elseif .match ({register}, y)\r
sty _SMCDesignator+1\r
+.else\r
+ .error "Invalid usage of macro 'SMC_StoreValue'"\r
.endif\r
.endmacro\r
\r
.endmacro\r
\r
.macro SMC_TransferHighByte label, value, register\r
-.if .paramcount = 2 .or .match ({register}, a)\r
+.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )\r
lda value\r
sta _SMCDesignator+2\r
.elseif .match ({register}, x)\r
.elseif .match ({register}, y)\r
ldy value\r
sty _SMCDesignator+2\r
+.else\r
+ .error "Invalid usage of macro 'SMC_TransferHighByte'"\r
.endif\r
.endmacro\r
\r
.macro SMC_LoadHighByte label, register\r
-.if .paramcount = 1 .or .match ({register}, a)\r
+.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )\r
lda _SMCDesignator+2\r
.elseif .match ({register}, x)\r
ldx _SMCDesignator+2\r
.elseif .match ({register}, y)\r
ldy _SMCDesignator+2\r
+.else\r
+ .error "Invalid usage of macro 'SMC_LoadHighByte'"\r
.endif\r
.endmacro\r
\r
.macro SMC_StoreHighByte label, register\r
-.if .paramcount = 1 .or .match ({register}, a)\r
+.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )\r
sta _SMCDesignator+2\r
.elseif .match ({register}, x)\r
stx _SMCDesignator+2\r
.elseif .match ({register}, y)\r
sty _SMCDesignator+2\r
+.else\r
+ .error "Invalid usage of macro 'SMC_StoreHighByte'"\r
.endif\r
.endmacro\r
\r
.macro SMC_TransferAddressSingle label, address, register\r
-.if .paramcount = 2 .or .match ((register), a)\r
+.if .paramcount = 2 .or .match ((register), a) .or .match ({register}, )\r
.if (.match (.left (1, {address}), #))\r
; immediate mode\r
lda #<(.right (.tcount ({address})-1, {address}))\r
ldy 1+(address)\r
sty _SMCDesignator+2\r
.endif\r
+.else\r
+ .error "Invalid usage of macro 'SMC_TransferAddressSingle'"\r
.endif\r
.endmacro\r
\r