]> git.sur5r.net Git - cc65/blob - libsrc/common/getcpu.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / common / getcpu.s
1 ;
2 ; Ullrich von Bassewitz, 02.04.1999
3 ;
4 ; unsigned char getcpu (void);
5 ;
6
7         .export         _getcpu
8
9 ; ---------------------------------------------------------------------------
10 ; Subroutine to detect an 816. Returns
11 ;
12 ;   - carry clear and 0 in A for a NMOS 6502 CPU
13 ;   - carry set and 1 in A for some CMOS 6502 CPU
14 ;   - carry set and 2 in A for a 65816
15 ;
16 ; This function uses a $1A opcode which is a INA on the 816 and ignored
17 ; (interpreted as a NOP) on a NMOS 6502. There are several CMOS versions
18 ; of the 6502, but all of them interpret unknown opcodes as NOP so this is
19 ; just what we want.
20
21 .p816                           ; Enable 65816 instructions
22
23 _getcpu:
24         lda     #0
25         inc     a               ; .byte $1A
26         cmp     #1
27         bcc     @L9
28
29 ; This is at least a 65C02, check for a 65816
30
31         xba                     ; .byte $eb, put $01 in B accu
32         dec     a               ; .byte $3a, A=$00 if 65C02
33         xba                     ; .byte $eb, get $01 back if 65816
34         inc     a               ; .byte $1a, make $01/$02
35 @L9:    ldx     #0              ; Load high byte of word
36         rts
37