⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash.c

📁 支持nvram盘
💻 C
字号:
/* START LIBRARY DESCRIPTION ***************************************************
flash.lib 
	Copyright (c) 1999, Z-World.

DESCRIPTION: generic small sector flash routines for the Rabbit

END DESCRIPTION ***************************************************************/


// values that depend on the flash system's location	
#define	FS_BASEADDR		0x00040000ul
#define	FS_BASEXPC		0x32
#define	FS_BYTECMD1		FS_BASEXPC+5
#define	FS_BYTECMD2		FS_BASEXPC+2




	

	
/* START FUNCTION DESCRIPTION ********************************************
flash_sector2xwindow           <FLASH.LIB>

SYNTAX: void* flash_sector2xwindow(FlashDescriptor* fd, word sector);

KEYWORDS:		flash

DESCRIPTION: 	This function sets the MB1CR and XPC value so the requested
               sector falls within the XPC window. See flash_init description
               for restrictions.

PARAMETER1:    flash descriptor
PARAMETER2:    sector

RETURN VALUE:  logical offset of sector.
               
SEE ALSO:      flash_init, flash_gettype, flash_erasechip,
               flash_erasesector, flash_read, flash_readsector,
               flash_writesector

END DESCRIPTION **********************************************************/

/* START FUNCTION DESCRIPTION ********************************************
flash_erasechip                <FLASH.LIB>

SYNTAX: void flash_erasechip(FlashDescriptor* fd);

KEYWORDS:		flash

DESCRIPTION:   This function erases the chip that is referenced by fd.
               NOTE:  flash_init needs to be called on fd before using
               this function. See flash_init description for restrictions.

PARAMETER1:    flash descriptor of chip to erase

RETURN VALUE:  none
               
SEE ALSO:      flash_init, flash_gettype, flash_sector2xwindow,
               flash_erasesector, flash_read, flash_readsector,
               flash_writesector

END DESCRIPTION **********************************************************/






int flash_init(FlashDescriptor* fd, int mb1cr, int (*fptr)());

root int flash_gettype(FlashDescriptor* fd);

root void flash_erasechip(FlashDescriptor* fd);

root int __flash_erasesector(FlashDescriptor* fd, unsigned long which);

root int __flash_writesectorb(FlashDescriptor* fd, word sector,
	unsigned	long buffer, int length);

root int __flash_writesectors(FlashDescriptor* fd, word sector,
	unsigned long buffer, int length);

root void* flash_sector2xwindow(FlashDescriptor* fd, word sector);

/*** EndHeader */

#asm
;
;	int flash_getttype(FlashDescriptor* fd);
;	get the two byte identifier for the flash type
;

flash_gettype::
		;
		; change memory bank 3 for second flash
		;

		ld		a,(MB1CRShadow)				; save the third bank
		push	af
		
		ld		hl,(sp+4)						; load with the flash's bank
		ld		a,(hl)
ioi	ld		(MB1CR),a
		ld		(MB1CRShadow),a

		ld		a,xpc								; save the xpc
		push	af
		
		;
		; check flash type
		;
		
		;
		; enter product identification mode
		;
		
		ld		hl,0xe555
		ld		de,0xeaaa

		ld		a,FS_BYTECMD1							; 5555=aa
		ld		xpc,a
		ld		(hl),e
		
		ex		de,hl
		
		ld		a,FS_BYTECMD2							; 2AAA=55
		ld		xpc,a
		ld		(hl),e
		
		ex		de,hl

		ld		a,FS_BYTECMD1							; 5555=90
		ld		xpc,a
		ld		(hl),0x90
		
		ld		a,(hl)
fgt_loop:
		ld		b,(hl)
		xor	b
		and	0x40
		ld		b,a
		jr		nz,fgt_loop
		
		ld		a,FS_BASEXPC							; bc=flash type
		ld		xpc,a
		ld		bc,(0xe000)

		ld		a,FS_BYTECMD1							; 5555=aa
		ld		xpc,a
		ld		(hl),e
		
		ex		de,hl
		
		ld		a,FS_BYTECMD2							; 2AAA=55
		ld		xpc,a
		ld		(hl),e
		
		ex		de,hl

		ld		a,FS_BYTECMD1							; 5555=f0
		ld		xpc,a
		ld		(hl),0xf0
		
		ld		h,c
		ld		l,b
		
		pop	af									; restore the xpc
		ld		xpc,a
		
		pop	af									; restore the third bank
ioi	ld		(MB1CR),a
		ld		(MB1CRShadow),a
		ret
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -