From 122def9f124f82ccb6af1b7269b040429e0e88b7 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Mon, 26 Feb 2018 19:19:13 -0800 Subject: [PATCH 1/4] Added proper 65sc02, 65ce02 and 4510 detection. --- include/6502.h | 2 ++ libsrc/common/getcpu.s | 34 ++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/6502.h b/include/6502.h index 31398e5c1..55083b036 100644 --- a/include/6502.h +++ b/include/6502.h @@ -51,6 +51,8 @@ typedef unsigned size_t; #define CPU_65C02 1 #define CPU_65816 2 #define CPU_4510 3 +#define CPU_65SC02 4 +#define CPU_65CE02 5 unsigned char getcpu (void); /* Detect the CPU the program is running on */ diff --git a/libsrc/common/getcpu.s b/libsrc/common/getcpu.s index 1e60a5d39..764e73a84 100644 --- a/libsrc/common/getcpu.s +++ b/libsrc/common/getcpu.s @@ -10,9 +10,11 @@ ; Subroutine to detect an 816. Returns ; ; - carry clear and 0 in A for a NMOS 6502 CPU -; - carry set and 1 in A for some CMOS 6502 CPU +; - carry set and 1 in A for a 65c02 ; - carry set and 2 in A for a 65816 ; - carry set and 3 in A for a 4510 +; - carry set and 4 in A for a 65sc02 +; - carry set and 5 in A for a 65ce02 ; ; This function uses a $1A opcode which is a INA on the 816 and ignored ; (interpreted as a NOP) on a NMOS 6502. There are several CMOS versions @@ -27,20 +29,40 @@ _getcpu: cmp #1 bcc @L9 -; This is at least a 65C02, check for a 4510 +; This is at least a 65C02, check for a 65ce02/4510 - .byte $42,$ea ; neg on 4510, nop #$ea on 65c02, wdm $ea on 65816 + .byte $42,$ea ; neg on 65ce02/4510, nop #$ea on 65c02, wdm $ea on 65816 cmp #1 - bne @L8 + beq @L6 + +; check for 4510 + + lda #5 ; CPU_65CE02 constant + .byte $5c ; map on 4510, aug on 65ce02 (acts like 4 byte nop) + lda #3 ; CPU_4510 constant + nop + bne @L9 + +; check for 65sc02 + +@L6: ldy $f7 + ldx #$00 + stx $f7 + .byte $f7,$f7 ; nop nop on 65sc02, smb7 $f7 on 65c02 and 65816 + ldx $f7 + sty $f7 + cpx #$00 + bne @L7 + lda #4 ; CPU_65SC02 constant + bne @L9 ; check for 65816; after 4510, because $eb there is row (rotate word) - xba ; .byte $eb, put $01 in B accu +@L7: 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 .byte $2c ; bit instruction to skip next command -@L8: lda #3 ; CPU_4510 constant @L9: ldx #0 ; Load high byte of word rts From e3779978b2a894eaa1ffa7682b8ccf20b9cf4ce5 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Mon, 26 Feb 2018 19:19:13 -0800 Subject: [PATCH 2/4] Added proper 65sc02, 65ce02 and 4510 detection. --- include/6502.h | 2 ++ libsrc/common/getcpu.s | 34 ++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/6502.h b/include/6502.h index 31398e5c1..55083b036 100644 --- a/include/6502.h +++ b/include/6502.h @@ -51,6 +51,8 @@ typedef unsigned size_t; #define CPU_65C02 1 #define CPU_65816 2 #define CPU_4510 3 +#define CPU_65SC02 4 +#define CPU_65CE02 5 unsigned char getcpu (void); /* Detect the CPU the program is running on */ diff --git a/libsrc/common/getcpu.s b/libsrc/common/getcpu.s index 1e60a5d39..764e73a84 100644 --- a/libsrc/common/getcpu.s +++ b/libsrc/common/getcpu.s @@ -10,9 +10,11 @@ ; Subroutine to detect an 816. Returns ; ; - carry clear and 0 in A for a NMOS 6502 CPU -; - carry set and 1 in A for some CMOS 6502 CPU +; - carry set and 1 in A for a 65c02 ; - carry set and 2 in A for a 65816 ; - carry set and 3 in A for a 4510 +; - carry set and 4 in A for a 65sc02 +; - carry set and 5 in A for a 65ce02 ; ; This function uses a $1A opcode which is a INA on the 816 and ignored ; (interpreted as a NOP) on a NMOS 6502. There are several CMOS versions @@ -27,20 +29,40 @@ _getcpu: cmp #1 bcc @L9 -; This is at least a 65C02, check for a 4510 +; This is at least a 65C02, check for a 65ce02/4510 - .byte $42,$ea ; neg on 4510, nop #$ea on 65c02, wdm $ea on 65816 + .byte $42,$ea ; neg on 65ce02/4510, nop #$ea on 65c02, wdm $ea on 65816 cmp #1 - bne @L8 + beq @L6 + +; check for 4510 + + lda #5 ; CPU_65CE02 constant + .byte $5c ; map on 4510, aug on 65ce02 (acts like 4 byte nop) + lda #3 ; CPU_4510 constant + nop + bne @L9 + +; check for 65sc02 + +@L6: ldy $f7 + ldx #$00 + stx $f7 + .byte $f7,$f7 ; nop nop on 65sc02, smb7 $f7 on 65c02 and 65816 + ldx $f7 + sty $f7 + cpx #$00 + bne @L7 + lda #4 ; CPU_65SC02 constant + bne @L9 ; check for 65816; after 4510, because $eb there is row (rotate word) - xba ; .byte $eb, put $01 in B accu +@L7: 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 .byte $2c ; bit instruction to skip next command -@L8: lda #3 ; CPU_4510 constant @L9: ldx #0 ; Load high byte of word rts From e79e779aba9aa463b7d4c5fa1f0beaf6016d5793 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Mon, 26 Feb 2018 19:30:25 -0800 Subject: [PATCH 3/4] Removed bit opcode, not needed anymore. --- libsrc/common/getcpu.s | 1 - 1 file changed, 1 deletion(-) diff --git a/libsrc/common/getcpu.s b/libsrc/common/getcpu.s index 764e73a84..f7ac3c170 100644 --- a/libsrc/common/getcpu.s +++ b/libsrc/common/getcpu.s @@ -62,7 +62,6 @@ _getcpu: dec a ; .byte $3a, A=$00 if 65C02 xba ; .byte $eb, get $01 back if 65816 inc a ; .byte $1a, make $01/$02 - .byte $2c ; bit instruction to skip next command @L9: ldx #0 ; Load high byte of word rts From 5d029af79ee46d4e57aa583c6d47cab333be5c02 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Tue, 27 Feb 2018 11:44:34 -0800 Subject: [PATCH 4/4] Fixed the 65816/65802 detection. --- libsrc/common/getcpu.s | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/libsrc/common/getcpu.s b/libsrc/common/getcpu.s index f7ac3c170..05a6d0143 100644 --- a/libsrc/common/getcpu.s +++ b/libsrc/common/getcpu.s @@ -35,7 +35,7 @@ _getcpu: cmp #1 beq @L6 -; check for 4510 +; This is at least a 65ce02, check for 4510 lda #5 ; CPU_65CE02 constant .byte $5c ; map on 4510, aug on 65ce02 (acts like 4 byte nop) @@ -43,25 +43,26 @@ _getcpu: nop bne @L9 +; Check for 65816/65802 +@L6: xba ; .byte $eb, put $01 in B accu (nop on 65c02/65sc02) + dec a ; .byte $3a, A=$00 + xba ; .byte $eb, A=$01 if 65816/65802 and A=$00 if 65c02/65sc02 + inc a ; .byte $1a, A=$02 if 65816/65802 and A=$01 if 65c02/65sc02 + cmp #2 + beq @L9 + ; check for 65sc02 -@L6: ldy $f7 - ldx #$00 + ldy $f7 + ldx #0 stx $f7 - .byte $f7,$f7 ; nop nop on 65sc02, smb7 $f7 on 65c02 and 65816 + .byte $f7,$f7 ; nop nop on 65sc02, smb7 $f7 on 65c02 ldx $f7 sty $f7 cpx #$00 - bne @L7 - lda #4 ; CPU_65SC02 constant bne @L9 + lda #4 ; CPU_65SC02 constant -; check for 65816; after 4510, because $eb there is row (rotate word) - -@L7: 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: ldx #0 ; Load high byte of word rts