]> git.sur5r.net Git - cc65/blob - libsrc/common/getcpu.s
Removed bit opcode, not needed anymore.
[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 a 65c02
14 ;   - carry set and 2 in A for a 65816
15 ;   - carry set and 3 in A for a 4510
16 ;   - carry set and 4 in A for a 65sc02
17 ;   - carry set and 5 in A for a 65ce02
18 ;
19 ; This function uses a $1A opcode which is a INA on the 816 and ignored
20 ; (interpreted as a NOP) on a NMOS 6502. There are several CMOS versions
21 ; of the 6502, but all of them interpret unknown opcodes as NOP so this is
22 ; just what we want.
23
24 .p816                           ; Enable 65816 instructions
25
26 _getcpu:
27         lda     #0
28         inc     a               ; .byte $1A ; nop on nmos, inc on every cmos
29         cmp     #1
30         bcc     @L9
31
32 ; This is at least a 65C02, check for a 65ce02/4510
33
34         .byte   $42,$ea         ; neg on 65ce02/4510, nop #$ea on 65c02, wdm $ea on 65816
35         cmp     #1
36         beq     @L6
37
38 ; check for 4510
39
40         lda     #5              ; CPU_65CE02 constant
41         .byte   $5c             ; map on 4510, aug on 65ce02 (acts like 4 byte nop)
42         lda     #3              ; CPU_4510 constant
43         nop
44         bne     @L9
45
46 ; check for 65sc02
47
48 @L6:    ldy     $f7
49         ldx     #$00
50         stx     $f7
51         .byte   $f7,$f7         ; nop nop on 65sc02, smb7 $f7 on 65c02 and 65816
52         ldx     $f7
53         sty     $f7
54         cpx     #$00
55         bne     @L7
56         lda     #4              ; CPU_65SC02 constant
57         bne     @L9
58
59 ; check for 65816; after 4510, because $eb there is row (rotate word)
60
61 @L7:    xba                     ; .byte $eb, put $01 in B accu
62         dec     a               ; .byte $3a, A=$00 if 65C02
63         xba                     ; .byte $eb, get $01 back if 65816
64         inc     a               ; .byte $1a, make $01/$02
65 @L9:    ldx     #0              ; Load high byte of word
66         rts
67