65c02, 6502, 65816 ??? CPU sells but who`s buying...


How to detect on which CPU the assembler code is running

(This information is from Draco, the author of SYSINFO 2.0)

You can test on plain 6502-Code if there is a 65c816 CPU, the 16-Bit processor avaible in some XLs as a turbo-board, avaible. Draco told me how to do this:

First we make sure, whether we are running on NMOS-CPU (6502) or CMOS (65c02,65c816). I will just show the "official" way which doesn`t uses "illegal opcodes":

test_nmos: lda #$99
           adc #$01
           beq cmos
; if the program is here we have a 6502-cpu
cmos       ...
; if here, we have a cmos-type (65c02,65c816)
           jmp test_65816

This test uses the decimal mode and the decimal addition. On NMOS-CPUs the addition does not affect the Z-flag.

But now we have to make sure if we are running on a 16-bit-CPU. This could be important if we include in our program/demo 16-bit Code or on the other side if we can use "illegal opcodes".

The 16-bit test uses the REP #$xx command which does nothing on 65c02! (but on 65c816 !!!):

test_65816: rep #$02  ; resets the Z-flag on 65c816 (use MAE-Assembler !!!)
            bne c816
            ...       ; here is stored the 65c02-Code
c816        ...       ; here could be the additional 16-bit code

Special thanx to Draco!!! I will use in my next demos/intros 16-Bit code even if its just 16-bit additions which make life easier. ;)

back to main-index

Last changes: 19 Jun 1997


Feel free to contact me for any legal reason!

email_icon HeAvEn, Member of TaquarT