Alchemy
Loading...
Searching...
No Matches

program_flash_sector.c

Go to the documentation of this file.
4
6
7/// Erases a standard sector and programs bytes until completion or an error.
8u16 ProgramFlashSector(u16 sector, u8 *source) {
9 u8 savedCode[64];
10 u16 result;
11 u8 *destination;
12
13 if ((u32)sector > 15)
14 return 0x80FF;
15
16 result = EraseFlashSector(sector);
17 if (result != 0)
18 return result;
19
21 REG_WAITCNT = (REG_WAITCNT & 0xFFFC) | gFlash->wait[0];
23 destination = (u8 *)((sector << gFlash->sector.shift) + 0x0E000000);
24
25 while (gFlashNumRemainingBytes != 0) {
26 result = ProgramFlashByte(source, destination);
27 if (result != 0)
28 break;
30 source++;
31 destination++;
32 }
33
34 REG_WAITCNT = (REG_WAITCNT & 0xFFFC) | 3;
35
36 return result;
37}
u16 gFlashNumRemainingBytes
void CopyFlashReadRoutineToRam(void *destination)
Copies the byte reader to RAM and installs its Thumb entry point.
Definition flash.c:161
Flash memory: erasing, programming and reading sectors.
The flash chips: sector size and count, and each chip type's routines.
const struct FlashType * gFlash
The hardware's I/O registers and their bits, as pret names them.
#define REG_WAITCNT
Definition io_reg.h:307
u16 ProgramFlashSector(u16 sector, u8 *source)
Erases a standard sector and programs bytes until completion or an error.
u16 EraseFlashSector(u16 sector)
Erases one of sixteen sectors, restoring the cartridge wait setting afterward.
Definition sst.c:39
u16 ProgramFlashByte(u8 *source, u8 *destination)
Issues a byte-program command and waits for its destination to match.
Definition sst.c:81
struct FlashSector sector
Definition flash_data.h:22
u16 wait[2]
Low two bits of REG_WAITCNT.
Definition flash_data.h:23
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11