📄 ccall.asm
字号:
pre_ccall .macro NUM_PARAMS,arg1,arg2,arg3,arg4,arg5,arg6,arg7
AR_STACK .set ar1
.if NUM_PARAMS<1
.emsg "ERROR - ccall macro only supports 1 to 7 arguments"
.endif
.if NUM_PARAMS>7
.emsg "ERROR - ccall macro only supports 1 to 7 arguments"
.endif
; Replace ARG1, ARG2, etc with the names of the parameters you are passing.
; i.e. function(ARG1, ARG2, ARG3, ...)
AR_STACK .set ar1
.if NUM_PARAMS>0
:arg1: .set ar2
.endif
.if NUM_PARAMS>1
:arg2: .set ar3
.endif
.if NUM_PARAMS>2
:arg3: .set ar4
.endif
.if NUM_PARAMS>3
:arg4: .set ar5
.endif
.if NUM_PARAMS>4
:arg5: .set ar7
.endif
.if NUM_PARAMS>5
:arg6: .set ar6
.endif
.if NUM_PARAMS>6
:arg7: .set ar0
.endif
; Begin C Preprocessing
.if NUM_PARAMS==7
popd *+ ; pop return address, push on software stack
sar ar0,*+ ; save FP
sar ar6,* ; save ar6
sbrk #3
.elseif NUM_PARAMS==6
popd *+ ; pop return address, push on software stack
sar ar6,* ; save ar6
sbrk #2
.else
popd * ; pop return address, push on software stack
sbrk #1
.endif
; Local variables (and parameters) will be set up as follows:
;
; get arguments and place them properly - take the from the
; software stack and place them into their correct positions
.if NUM_PARAMS>0
lar arg1,*-
.endif
.if NUM_PARAMS>1
lar arg2,*-
.endif
.if NUM_PARAMS>2
lar arg3,*-
.endif
.if NUM_PARAMS>3
lar arg4,*-
.endif
.if NUM_PARAMS>4
lar arg5,*-
.endif
.if NUM_PARAMS>5
lar arg6,*-
.endif
.if NUM_PARAMS>6
lar arg7,*-
.endif
; Set ar1 = next empty point on stack (SP)
.if NUM_PARAMS==7
adrk #11
.elseif NUM_PARAMS==6
adrk #9
.else
adrk #NUM_PARAMS+2
.endif
; Modify any registers needed
; Note: Overflow mode is off in C.
; End C Preprocessing
.endm
post_ccall .macro NUM_PARAMS,OFFSET
; Begin C Post Processing
.if NUM_PARAMS<1
.emsg "ERROR - ccall macro only supports 1 to 7 arguments"
.endif
.if NUM_PARAMS>7
.emsg "ERROR - ccall macro only supports 1 to 7 arguments"
.endif
mar *,ar1
.if $iscons(OFFSET)
.if OFFSET!=-1
sbrk #1+OFFSET
.endif
.else
sbrk #1
.endif
.if NUM_PARAMS==7
lar ar6,*- ; save FP
lar ar0,*- ; save ar6
.endif
.if NUM_PARAMS==6
lar ar6,*- ; save ar6
.endif
pshd * ; pop return address, push on software stack
; End C Post Processing
; Restore any other registers modified
; Note: Overflow mode is off in C.
ret
.endm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -