use pre-existing ZP storage. Make 32-bit pointer value loading more self-evident

This commit is contained in:
Paul Gardner-Stephen
2018-12-29 00:07:29 +10:30
committed by greg-king5
parent 19ca1f6b48
commit 837b9b3c2c

View File

@@ -3,7 +3,7 @@
; ;
; unsigned char getcpu (void); ; unsigned char getcpu (void);
; ;
.include "zeropage.inc"
.export _getcpu .export _getcpu
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
@@ -53,64 +53,41 @@ _getcpu:
; 45GS02 supports 32-bit ZP indirect, so use that to check CPU type ; 45GS02 supports 32-bit ZP indirect, so use that to check CPU type
; without requiring a functioning MEGA65 hypervisor. ; without requiring a functioning MEGA65 hypervisor.
; We setup a read of $200FF, then store a different value in $00FF ; We setup a read of $200xx, then store a different value in $xx
; and then re-read $200FF to see if it is unchanged. ; and then re-read $200xx to see if it is unchanged.
; Save the 32-bit ZP pointer and data byte ; Setup 32-bit pointer to $00020000+tmp1
ldx #4 lda #<$020000+tmp1
@L10: lda $fb,x sta regsave
sta @GetCPUTemp,x lda #>$020000+tmp1
dex sta regsave+1
bpl @L10 sta regsave+3 ; also write to upper byte of pointer to save an extra LDA #$00
lda #^$020000+tmp1
; Setup 32-bit pointer to $000200FF sta regsave+2
lda #$ff
sta $fb
lda #$00
sta $fc
sta $fe
lda #$02
sta $fd
; Prefixing LDA ($nn),Z with a NOP uses 32-bit ZP pointer on 45GS02, ; Prefixing LDA ($nn),Z with a NOP uses 32-bit ZP pointer on 45GS02,
; but normal 16-bit ZP pointer on 4510 ; but normal 16-bit ZP pointer on 4510
; (We assume Z=$00, which will be the normal case) ; (We assume Z=$00, which will be the normal case)
nop ; prefix to tell next instruction to be 32-bit ZP nop ; prefix to tell next instruction to be 32-bit ZP
.byte $b2,$fb ; LDA ($nn),Z .byte $b2,regsave ; LDA (regsave),Z
eor #$ff ; change the value eor #$ff ; change the value
sta $ff ; store in $FF sta tmp1 ; store in $xx
; now try again to load it: If the same, then 45GS02, as $200FF is unchanged ; now try again to load it: If the same, then 45GS02, as $200xx is unchanged
nop ; prefix to tell next instruction to be 32-bit ZP nop ; prefix to tell next instruction to be 32-bit ZP
.byte $b2,$fb ; LDA ($nn),Z .byte $b2,regsave ; LDA (regsave),Z
cmp $ff ; does the loaded value match what is in $FF? cmp tmp1 ; does the loaded value match what is in $FF?
beq @Is4510 ; matches, so must be a 4510 = C65 beq @Is4510 ; matches, so must be a 4510 = C65
bne @Is45GS02 ; $200FF and $FF have different values, so must be a MEGA65 45GS02 bne @Is45GS02 ; $200FF and $FF have different values, so must be a MEGA65 45GS02
@Is4510: @Is4510:
jsr @RestoreGetCPUTemp
lda #3 ; CPU_4510 constant lda #3 ; CPU_4510 constant
ldx #0 ; load high byte of word ldx #0 ; load high byte of word
rts rts
@Is45GS02: @Is45GS02:
jsr @RestoreGetCPUTemp
lda #8 ; CPU_45GS02 constant lda #8 ; CPU_45GS02 constant
ldx #0 ; load high byte of word ldx #0 ; load high byte of word
rts rts
@RestoreGetCPUTemp:
; Save the 32-bit ZP pointer and data byte
ldx #4
@L11: lda @GetCPUTemp,x
sta $fb,x
dex
bpl @L11
rts
; Temporary storage for the ZP locations we modify above
@GetCPUTemp: .byte 0,0,0,0,0
; 6502 type of cpu, check for a 2a03/2a07 ; 6502 type of cpu, check for a 2a03/2a07
@IsNMOS: @IsNMOS:
sed ; set decimal mode, no decimal mode on the 2a03/2a07 sed ; set decimal mode, no decimal mode on the 2a03/2a07