I cover the use of software interrupts for calling kernel services in my 65C816 interrupts article (
see here). The principles are mostly applicable to the 65C02.
Incidentally, the
INT XXh instruction in the x86, like the
TRAP $XX instruction in the MC68000, is a "vectored interrupt" that is vaguely analogous to the 65xx
BRK instruction followed by a defined signature byte. You could use a macro such as
INT x, where
x is the interrupt number, to simulate the x86 equivalent. The macro would expand to:
Code:
brk
.byte x
However, as Ed noted and is evident with Mike's code, fetching the signature byte is a somewhat convoluted process. It should be noted that UNIX, which uses software interrupts to call kernel APIs, doesn't use the interrupt number at all—for example, such a call on the 68000 is
TRAP $00. Instead, a general purpose register—usually
D0 on the 68000—is loaded with an API index number and then the software interrupt is executed. This is practical because any parameters required by the API are passed via a stack frame that is pushed prior to the actual API call.
With the 65C816, the
COP instruction can be used for the purpose. Here again, some gymnastics are needed to retrieve
COP's signature, an exercise that is further complicated by the bank-oriented nature of the '816 (I describe that in my 65C816 interrupts article). I recommend
COP $00 for calling kernel or BIOS functions, as it's easier to model the UNIX API method by using the 65C816's stack instructions, e.g.,
PEA and
PEI, to set up a stack frame.