User Tools

Site Tools


base:detect_cpu_type

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

base:detect_cpu_type [2015-04-17 04:31] (current)
Line 1: Line 1:
 +<code>
 +; ---------------------------------------------------------------------------
 +; Subroutine to detect an 816. Returns
 +;
 +;   - carry clear and 0 in A for a NMOS 6502 CPU
 +;   - carry set and 1 in A for CMOS 6502 CPUs
 +;   - carry set and 2 in A for a 65816
 +;
 +; This function uses a $1A opcode which is a INA on the 816 and C02, and
 +; ignored (interpreted as a NOP) on a NMOS 6502. Detection of the 65816 is
 +; done by the xba instruction which is a NOP on the 65C02s.
 +
 +GetCPU: lda #0
 +      inc a       ; .byte $1a
 +      cmp #1
 +        bcc    @L9
 +
 +; This is at least a 65C02, check for a 65816
 +
 +      xba     ; .byte $eb, put $01 in B accu
 +      dec a      ; .byte $3a, A=$00 if 65C02
 +        xba                    ; .byte $eb, get $01 back if 65816
 +        inc    a              ; .byte $1a, make $01/$02
 +@L9: rts
 +</code>
 +
 +Ullrich von Bassewitz                                  uz@musoftware.de
  
base/detect_cpu_type.txt ยท Last modified: 2015-04-17 04:31 (external edit)