]> git.sur5r.net Git - cc65/blob - libsrc/common/getcpu.s
added 4510 cpu detection to getcpu.s
[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 ;   - carry set and 3 in A for a 4510
16 ;
17 ; This function uses a $1A opcode which is a INA on the 816 and ignored
18 ; (interpreted as a NOP) on a NMOS 6502. There are several CMOS versions
19 ; of the 6502, but all of them interpret unknown opcodes as NOP so this is
20 ; just what we want.
21
22 .p816                           ; Enable 65816 instructions
23
24 _getcpu:
25         lda     #0
26         inc     a               ; .byte $1A ; nop on nmos, inc on every cmos
27         cmp     #1
28         bcc     @L9
29
30 ; This is at least a 65C02, check for a 4510
31
32         .byte   $42,$ea         ; neg on 4510, nop #$ea on 65c02, wdm $ea on 65816
33         cmp     #1
34         bne     @L8
35
36 ; check for 65816; after 4510, because $eb there is row (rotate word)
37
38         xba                     ; .byte $eb, put $01 in B accu
39         dec     a               ; .byte $3a, A=$00 if 65C02
40         xba                     ; .byte $eb, get $01 back if 65816
41         inc     a               ; .byte $1a, make $01/$02
42         .byte $2c               ; bit instruction to skip next command
43 @L8:    lda     #3              ; CPU_4510 constant
44 @L9:    ldx     #0              ; Load high byte of word
45         rts
46