Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .macro push stackname, value, sp ; stackname, valuetoassign, stackpointer
- .ident( .sprintf("%s%04X",stackname,sp)) .set value
- sp .set sp + 1
- .endmacro
- .macro pop stackname, var, sp
- sp .set sp - 1
- var .set .ident( .sprintf("%s%04X",stackname,sp))
- .endmacro
- .macro if flagtest
- ; first time this macro is used:
- .ifndef _endif_flagtest_IF_label
- _endif_flagtest_IF_label .set -1 ; total number of IFs used, first time will be incremented = 0
- _endif_flagtest_SP .set 0 ; Stack Pointer
- _endif_flagtest_END_label .set 0
- .endif
- _endif_flagtest_IF_label .set _endif_flagtest_IF_label + 1
- push "IF_ENDIF_STACK",_endif_flagtest_IF_label, _endif_flagtest_SP
- ; Carry flag:
- ; carry set
- ; carry clear
- ; no carry
- ; not carry
- ; C set
- ; C clear
- ; less
- ; not less
- ; greater_equal
- ; not greater_equal
- ; carry clear
- .if (.xmatch(.left(1, {flagtest}) , less)) .or (.xmatch(.mid(1,1, {flagtest}) , less))
- .if (.xmatch(.left (1,{flagtest}), not))
- bcc .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) ; not less
- .else
- .if (.xmatch(.left(1, {flagtest}) , less))
- bcs .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label)) ; less
- .else
- .error "Unknown condition in IF (C flag - carry clear)"
- .fatal ""
- .endif
- .endif
- .else
- ; Carry set
- .if (.xmatch(.left(1, {flagtest}) , greater_equal)) .or (.xmatch(.mid(1,1, {flagtest}) , greater_equal)) .or (.xmatch(.left(1, {flagtest}) , carry)) .or (.xmatch(.mid(1,1, {flagtest}) , carry)) .or (.xmatch(.left(1, {flagtest}) , C))
- .if (.xmatch(.mid (1, 1,{flagtest}), clear)) .or (.xmatch(.left (1,{flagtest}), no)) .or (.xmatch(.left (1,{flagtest}), not))
- bcs .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .if (.xmatch(.mid (1, 1, {flagtest}), set)) .or (.xmatch(.left(1, {flagtest}) , greater_equal))
- bcc .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .error "Unknown condition in IF (C flag - carry set)"
- .endif
- .endif
- .else ; end "carry"
- ; Special case for greater than check ;
- .if (.xmatch(.left(1, {flagtest}) , greater)) .or (.xmatch(.mid(1,1, {flagtest}) , greater))
- .if (.xmatch(.left (1,{flagtest}), not)) ; Enter block on EQUAL or LESS - branch away on greater(BCS), stay if equal
- beq :+
- bcs .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- :
- .else
- .if (.xmatch(.left(1, {flagtest}) , greater)) ; enter block on greater - branch away on less or equal
- beq .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- bcc .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .error "Unknown condition in IF (C flag - greater)"
- .endif
- .endif
- .else ; end "greater"
- ; Zero flag: - set when equal
- ; zero
- ; zero clear
- ; zero set
- ; not zero
- ; equal
- ; not equal
- ; Z set
- ; Z clear
- ;
- .if (.xmatch(.mid(1,1, {flagtest}) , zero)) .or (.xmatch(.left(1, {flagtest}) , zero)) .or (.xmatch(.mid(1,1, {flagtest}) , equal)) .or (.xmatch(.left(1,{flagtest}) , equal)) .or (.xmatch(.left(1, {flagtest}) , Z))
- .if (.xmatch(.mid (1, 1, {flagtest}), clear)) .or (.xmatch(.left(1, {flagtest}), not))
- beq .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .if (.xmatch(.mid (1, 1,{flagtest}), set)) .or (.xmatch(.left(1,{flagtest}) , equal)) .or (.xmatch(.left(1, {flagtest}) , zero))
- bne .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .error "Unknown condition in IF (Z flag)"
- .fatal ""
- .endif
- .endif
- .else ; end "zero"
- ; Negative flag: set indicates negative
- ; plus
- ; not plus
- ; positive
- ; not positive
- ; minus
- ; negative
- ; not minus
- ; not negative
- ; N set
- ; N clear
- ; bit7 set
- ; bit7 clear
- .if (.xmatch(.mid(1,1, {flagtest}) , plus)) .or (.xmatch(.mid(1,1, {flagtest}) , positive)) .or (.xmatch(.left(1, {flagtest}) , plus)) .or (.xmatch(.left(1, {flagtest}) , positive))
- .if (.xmatch(.left(1, {flagtest}), not))
- bpl .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .if (.xmatch(.left(1, {flagtest}) , plus)) .or (.xmatch(.left(1, {flagtest}) , positive))
- bmi .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .error "Unknown condition in IF (N flag)"
- .fatal ""
- .endif
- .endif
- .else ; end "plus"
- .if (.xmatch(.left(1, {flagtest}) , minus)) .or (.xmatch(.left(1, {flagtest}) , negative)) .or (.xmatch(.mid(1,1, {flagtest}) , minus)) .or (.xmatch(.mid(1,1, {flagtest}) , negative)) .or (.xmatch(.left(1, {flagtest}) , N)) .or (.xmatch(.left(1, {flagtest}) , bit7))
- .if (.xmatch(.left(1, {flagtest}), not)) .or (.xmatch(.mid(1,1, {flagtest}), clear))
- bmi .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .if (.xmatch(.left(1, {flagtest}) , minus)) .or (.xmatch(.left(1, {flagtest}) , negative)) .or (.xmatch(.mid(1,1, {flagtest}), set))
- bpl .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .error "Unknown condition in IF (N flag)"
- .fatal
- .endif
- .endif
- .else ; end "minus"
- ; V:
- ; overflow
- ; overflow set
- ; overflow clear
- ; not overflow
- ; V set
- ; V clear
- ; bit6 clear
- ; bit6 set
- .if (.xmatch(.mid(1,1, {flagtest}) , overflow)) .or (.xmatch(.left(1, {flagtest}) , overflow)) .or (.xmatch(.left(1,{flagtest}) , V)) .or (.xmatch(.left(1, {flagtest}) , bit6))
- .if (.xmatch(.mid (1, 1, {flagtest}), clear)) .or (.xmatch(.left(1, {flagtest}), not))
- bvs .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .if (.xmatch(.mid (1, 1,{flagtest}), set)) .or (.xmatch(.left(1,{flagtest}) , overflow))
- bvc .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label))
- .else
- .error "Unknown condition in IF (V Flag)"
- .fatal
- .endif
- .endif
- .else ; end "zero"
- .if (.xmatch(.left(1,{flagtest}) , TRUE)) ; always true for ELSE macro
- ; do nothing (no branch)
- .else
- .error "Unrecognized IF test condition."
- .fatal ""
- .endif
- .endif
- .endif
- .endif
- .endif
- .endif
- .endif
- .endif
- .endmacro
- ; Create a label that will point to the next ENDIF and create an ENDIF/IF for the ELSE - the IF creates no code
- .macro else
- jmp .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_IF_label + 1)) ; one more than the last label, same lablel as the "if TRUE"
- endif
- if TRUE
- .endmacro
- ; Pop if address from the IF stack and make a label
- .macro endif
- .if (_endif_flagtest_SP - 1) < 0 ; if accessing the stack will result in a negative value, there are too many ENDIFs
- .error "ENDIF without IF"
- .fatal ""
- .endif
- pop "IF_ENDIF_STACK",_endif_flagtest_END_label, _endif_flagtest_SP
- .ident ( .sprintf ("%s%04X", "_END_IF_", _endif_flagtest_END_label)):
- .endmacro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement