mirror of
https://github.com/cc65/cc65.git
synced 2024-11-10 10:04:50 +00:00
Merge pull request #335 from IrgendwerA8/SMC_macro_fixes
SMC macro fixes for changed .paramcount and byte overflow behavior
This commit is contained in:
commit
e52feb2b91
@ -1,7 +1,7 @@
|
||||
; smc.mac
|
||||
; ca65 Macro-Pack for Self Modifying Code (SMC)
|
||||
;
|
||||
; (c) Christian Krüger, latest change: 09-Nov-2011
|
||||
; (c) Christian Krüger, latest change: 17-Jul-2016
|
||||
;
|
||||
; This software is provided 'as-is', without any expressed or implied
|
||||
; warranty. In no event will the authors be held liable for any damages
|
||||
@ -53,7 +53,7 @@ _SMCDesignator: statement
|
||||
.endmacro
|
||||
|
||||
.macro SMC_TransferOpcode label, opcode, register
|
||||
.if .paramcount = 2 .or .match ({register}, a)
|
||||
.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )
|
||||
lda #opcode
|
||||
sta _SMCDesignator
|
||||
.elseif .match ({register}, x)
|
||||
@ -62,44 +62,52 @@ _SMCDesignator: statement
|
||||
.elseif .match ({register}, y)
|
||||
ldy #opcode
|
||||
sty _SMCDesignator
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_TransferOpcode'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
.macro SMC_LoadOpcode label, register
|
||||
.if .paramcount = 1 .or .match ({register}, a)
|
||||
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
|
||||
lda _SMCDesignator
|
||||
.elseif .match ({register}, x)
|
||||
ldx _SMCDesignator
|
||||
.elseif .match ({register}, y)
|
||||
ldy _SMCDesignator
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_LoadOpcode'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
.macro SMC_StoreOpcode label, register
|
||||
.if .paramcount = 1 .or .match ({register}, a)
|
||||
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
|
||||
sta _SMCDesignator
|
||||
.elseif .match ({register}, x)
|
||||
stx _SMCDesignator
|
||||
.elseif .match ({register}, y)
|
||||
sty _SMCDesignator
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_StoreOpcode'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
.macro SMC_ChangeBranch label, destination, register
|
||||
.if .paramcount = 2 .or .match ({register}, a)
|
||||
lda #(destination - _SMCDesignator -2)
|
||||
.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )
|
||||
lda #(<(destination - _SMCDesignator -2))
|
||||
sta _SMCDesignator+1
|
||||
.elseif .match ({register}, x)
|
||||
ldx #(destination - _SMCDesignator - 2)
|
||||
ldx #(<(destination - _SMCDesignator - 2))
|
||||
stx _SMCDesignator+1
|
||||
.elseif .match ({register}, y)
|
||||
ldy #(destination - _SMCDesignator - 2)
|
||||
ldy #(<(destination - _SMCDesignator - 2))
|
||||
sty _SMCDesignator+1
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_ChangeBranch'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
.macro SMC_TransferValue label, value, register
|
||||
.if .paramcount = 2 .or .match ({register}, a)
|
||||
.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )
|
||||
lda value
|
||||
sta _SMCDesignator+1
|
||||
.elseif .match ({register}, x)
|
||||
@ -108,26 +116,32 @@ _SMCDesignator: statement
|
||||
.elseif .match ({register}, y)
|
||||
ldy value
|
||||
sty _SMCDesignator+1
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_TransferValue'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
.macro SMC_LoadValue label, register
|
||||
.if .paramcount = 1 .or .match ({register}, a)
|
||||
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
|
||||
lda _SMCDesignator+1
|
||||
.elseif .match ({register}, x)
|
||||
ldx _SMCDesignator+1
|
||||
.elseif .match ({register}, y)
|
||||
ldy _SMCDesignator+1
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_LoadValue'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
.macro SMC_StoreValue label, register
|
||||
.if .paramcount = 1 .or .match ({register}, a)
|
||||
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
|
||||
sta _SMCDesignator+1
|
||||
.elseif .match ({register}, x)
|
||||
stx _SMCDesignator+1
|
||||
.elseif .match ({register}, y)
|
||||
sty _SMCDesignator+1
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_StoreValue'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
@ -145,7 +159,7 @@ SMC_StoreValue label, register
|
||||
.endmacro
|
||||
|
||||
.macro SMC_TransferHighByte label, value, register
|
||||
.if .paramcount = 2 .or .match ({register}, a)
|
||||
.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )
|
||||
lda value
|
||||
sta _SMCDesignator+2
|
||||
.elseif .match ({register}, x)
|
||||
@ -154,31 +168,37 @@ SMC_StoreValue label, register
|
||||
.elseif .match ({register}, y)
|
||||
ldy value
|
||||
sty _SMCDesignator+2
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_TransferHighByte'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
.macro SMC_LoadHighByte label, register
|
||||
.if .paramcount = 1 .or .match ({register}, a)
|
||||
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
|
||||
lda _SMCDesignator+2
|
||||
.elseif .match ({register}, x)
|
||||
ldx _SMCDesignator+2
|
||||
.elseif .match ({register}, y)
|
||||
ldy _SMCDesignator+2
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_LoadHighByte'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
.macro SMC_StoreHighByte label, register
|
||||
.if .paramcount = 1 .or .match ({register}, a)
|
||||
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
|
||||
sta _SMCDesignator+2
|
||||
.elseif .match ({register}, x)
|
||||
stx _SMCDesignator+2
|
||||
.elseif .match ({register}, y)
|
||||
sty _SMCDesignator+2
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_StoreHighByte'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
.macro SMC_TransferAddressSingle label, address, register
|
||||
.if .paramcount = 2 .or .match ((register), a)
|
||||
.if .paramcount = 2 .or .match ((register), a) .or .match ({register}, )
|
||||
.if (.match (.left (1, {address}), #))
|
||||
; immediate mode
|
||||
lda #<(.right (.tcount ({address})-1, {address}))
|
||||
@ -220,6 +240,8 @@ SMC_StoreValue label, register
|
||||
ldy 1+(address)
|
||||
sty _SMCDesignator+2
|
||||
.endif
|
||||
.else
|
||||
.error "Invalid usage of macro 'SMC_TransferAddressSingle'"
|
||||
.endif
|
||||
.endmacro
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user