1
0
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:
Oliver Schmidt 2016-08-16 09:23:28 +02:00 committed by GitHub
commit e52feb2b91

View File

@ -1,7 +1,7 @@
; smc.mac ; smc.mac
; ca65 Macro-Pack for Self Modifying Code (SMC) ; 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 ; This software is provided 'as-is', without any expressed or implied
; warranty. In no event will the authors be held liable for any damages ; warranty. In no event will the authors be held liable for any damages
@ -53,7 +53,7 @@ _SMCDesignator: statement
.endmacro .endmacro
.macro SMC_TransferOpcode label, opcode, register .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 lda #opcode
sta _SMCDesignator sta _SMCDesignator
.elseif .match ({register}, x) .elseif .match ({register}, x)
@ -62,44 +62,52 @@ _SMCDesignator: statement
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy #opcode ldy #opcode
sty _SMCDesignator sty _SMCDesignator
.else
.error "Invalid usage of macro 'SMC_TransferOpcode'"
.endif .endif
.endmacro .endmacro
.macro SMC_LoadOpcode label, register .macro SMC_LoadOpcode label, register
.if .paramcount = 1 .or .match ({register}, a) .if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
lda _SMCDesignator lda _SMCDesignator
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx _SMCDesignator ldx _SMCDesignator
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy _SMCDesignator ldy _SMCDesignator
.else
.error "Invalid usage of macro 'SMC_LoadOpcode'"
.endif .endif
.endmacro .endmacro
.macro SMC_StoreOpcode label, register .macro SMC_StoreOpcode label, register
.if .paramcount = 1 .or .match ({register}, a) .if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
sta _SMCDesignator sta _SMCDesignator
.elseif .match ({register}, x) .elseif .match ({register}, x)
stx _SMCDesignator stx _SMCDesignator
.elseif .match ({register}, y) .elseif .match ({register}, y)
sty _SMCDesignator sty _SMCDesignator
.else
.error "Invalid usage of macro 'SMC_StoreOpcode'"
.endif .endif
.endmacro .endmacro
.macro SMC_ChangeBranch label, destination, register .macro SMC_ChangeBranch label, destination, register
.if .paramcount = 2 .or .match ({register}, a) .if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )
lda #(destination - _SMCDesignator -2) lda #(<(destination - _SMCDesignator -2))
sta _SMCDesignator+1 sta _SMCDesignator+1
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx #(destination - _SMCDesignator - 2) ldx #(<(destination - _SMCDesignator - 2))
stx _SMCDesignator+1 stx _SMCDesignator+1
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy #(destination - _SMCDesignator - 2) ldy #(<(destination - _SMCDesignator - 2))
sty _SMCDesignator+1 sty _SMCDesignator+1
.else
.error "Invalid usage of macro 'SMC_ChangeBranch'"
.endif .endif
.endmacro .endmacro
.macro SMC_TransferValue label, value, register .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 lda value
sta _SMCDesignator+1 sta _SMCDesignator+1
.elseif .match ({register}, x) .elseif .match ({register}, x)
@ -108,26 +116,32 @@ _SMCDesignator: statement
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy value ldy value
sty _SMCDesignator+1 sty _SMCDesignator+1
.else
.error "Invalid usage of macro 'SMC_TransferValue'"
.endif .endif
.endmacro .endmacro
.macro SMC_LoadValue label, register .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 lda _SMCDesignator+1
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx _SMCDesignator+1 ldx _SMCDesignator+1
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy _SMCDesignator+1 ldy _SMCDesignator+1
.else
.error "Invalid usage of macro 'SMC_LoadValue'"
.endif .endif
.endmacro .endmacro
.macro SMC_StoreValue label, register .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 sta _SMCDesignator+1
.elseif .match ({register}, x) .elseif .match ({register}, x)
stx _SMCDesignator+1 stx _SMCDesignator+1
.elseif .match ({register}, y) .elseif .match ({register}, y)
sty _SMCDesignator+1 sty _SMCDesignator+1
.else
.error "Invalid usage of macro 'SMC_StoreValue'"
.endif .endif
.endmacro .endmacro
@ -145,7 +159,7 @@ SMC_StoreValue label, register
.endmacro .endmacro
.macro SMC_TransferHighByte label, value, register .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 lda value
sta _SMCDesignator+2 sta _SMCDesignator+2
.elseif .match ({register}, x) .elseif .match ({register}, x)
@ -154,31 +168,37 @@ SMC_StoreValue label, register
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy value ldy value
sty _SMCDesignator+2 sty _SMCDesignator+2
.else
.error "Invalid usage of macro 'SMC_TransferHighByte'"
.endif .endif
.endmacro .endmacro
.macro SMC_LoadHighByte label, register .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 lda _SMCDesignator+2
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx _SMCDesignator+2 ldx _SMCDesignator+2
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy _SMCDesignator+2 ldy _SMCDesignator+2
.else
.error "Invalid usage of macro 'SMC_LoadHighByte'"
.endif .endif
.endmacro .endmacro
.macro SMC_StoreHighByte label, register .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 sta _SMCDesignator+2
.elseif .match ({register}, x) .elseif .match ({register}, x)
stx _SMCDesignator+2 stx _SMCDesignator+2
.elseif .match ({register}, y) .elseif .match ({register}, y)
sty _SMCDesignator+2 sty _SMCDesignator+2
.else
.error "Invalid usage of macro 'SMC_StoreHighByte'"
.endif .endif
.endmacro .endmacro
.macro SMC_TransferAddressSingle label, address, register .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}), #)) .if (.match (.left (1, {address}), #))
; immediate mode ; immediate mode
lda #<(.right (.tcount ({address})-1, {address})) lda #<(.right (.tcount ({address})-1, {address}))
@ -220,6 +240,8 @@ SMC_StoreValue label, register
ldy 1+(address) ldy 1+(address)
sty _SMCDesignator+2 sty _SMCDesignator+2
.endif .endif
.else
.error "Invalid usage of macro 'SMC_TransferAddressSingle'"
.endif .endif
.endmacro .endmacro