GetHardwareVer:		
	
	ld de,&0000
	
	push de
			call GetHardwareVer_CpcPlus_Init
			call PlusTest
	pop de
	jr nc,GetHardwareVer_NoPlus
	inc d
GetHardwareVer_NoPlus:		
	push de
		ld d,Bank4
		call BankTest
	pop de
	ret nc
	inc e
	push de
		ld d,Bank8
		call BankTestExt
	pop de
	ret nc
	inc e

	ret
	
;	D=CPCVer	(1=Plus)
;	E=Ram		(0=64k,1=128k,2=256k)
	
BankTest:
	ld a,Bank0
	call BankSwitch_SetCurrent

	ld a,&69
	ld (BankBase),a

	ld a,d
	call BankSwitch_SetCurrent
	
	ld a,(BankBase)
	;ld e,a
	cpl 
	ld (BankBase),a
	
	ld a,Bank0
	call BankSwitch_SetCurrent
	
	ld a,(BankBase)
	cp &69
	jr nz,BankFail
	
	;ld a,d
	;call BankSwitch_SetCurrent
	
;	ld a,e
	;ld (BankBase),a
	
	ld a,Bank0
	call BankSwitch_SetCurrent
	scf
	ret
BankFail:
	or a
	ret
BankTestExt:
	ld a,d
	and %11000111
	call BankSwitch_SetCurrent

	ld a,&69
	ld (BankBase),a

	ld a,d
	call BankSwitch_SetCurrent
	
	ld a,(BankBase)
	;ld e,a
	cpl 
	ld (BankBase),a
	
	ld a,d
	and %11000111
	call BankSwitch_SetCurrent
	
	ld a,(BankBase)
	cp &69
	jr nz,BankFail
	
	;ld a,d
	;call BankSwitch_SetCurrent
	
;	ld a,e
	;ld (BankBase),a
	
	ld a,Bank0
	call BankSwitch_SetCurrent
	scf
	ret	
PlusTest:
	ld a,Bank0
	call BankSwitch_SetCurrent
	
	
	ld a,&69
	ld (BankBase),a

	call CpcPlus_BankEnable
	
	ld a,(BankBase)
	;ld e,a
	cpl 
	ld (BankBase),a
	
	call CpcPlus_BankDisable
	
	ld a,(BankBase)
	cp &69
	jr nz,PlusFail
	
	;call CpcPlus_BankEnable
	
	;ld a,e
	;ld (BankBase),a
	
	call CpcPlus_BankDisable
	scf
	ret
PlusFail:
	or a
	ret
	
	
GetHardwareVer_CpcPlus_Init:
	di
	ld b,&bc
	ld hl,GetHardwareVer_PlusInitSequence
	ld e,17
PlusInitLoop:
	ld a,(hl)
	out (c),a
	inc hl
	dec e
	jr nz,PlusInitLoop
	ei
	ret


GetHardwareVer_PlusInitSequence:	;This is a special sequence to unock the CPC+ Asic... it's intentionally random!
	defb &ff,&00,&ff,&77,&b3,&51,&a8,&d4,&62,&39,&9c,&46,&2b,&15,&8a,&cd,&ee


