Search the web
Sign In
New User? Sign Up
gbadev
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Flash / EEprom reading / writing   Message List  
Reply | Forward Message #14591 of 15019 |
Re: [gbadev] Flash / EEprom reading / writing

Never mind on the flash part. I got that figured out. All of the following
code was written with the ham 2.71 dev kit. This code also needs the MBV2
debugging libraries.

--------------Flash.s-------------------------
.GLOBL check_flashrom
.GLOBL switchbank0
.GLOBL switchbank1
.GLOBL writeflash
.GLOBL eraseflash

.ARM
@.SECTION .iwram
.ALIGN
.TEXT

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@
@
@ Flash related functions.
@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@


@extern void check_flashrom(u16 *v1, u16 *v2);
check_flashrom:


STMFD sp!, {r2-r5}
ldr r5,=0xE005555
mov r2,#0xAA
strb r2,[r5] @ AA => 0800AAAA
mov r4,#0xE000000
ldr r3,=0xE002AAA
mov r2,#0x55
strb r2,[r3] @ 55 => 08005554
mov r2,#0x90
strb r2,[r5] @ 90 => 0800AAAA
ldrh r2,[r4] @ 08000000 => v1
strh r2,[r0]
ldrh r0,[r4,#0x1] @ 08000002 => v2
strh r0,[r1]
mov r0,#0xF0
strh r0,[r4] @ F0 => 08000000
LDMFD sp!, {r2-r5}
bx lr

@extern void switchbank0(void);
switchbank0:
STMFD sp!, {r2-r5}
ldr r5,=0xE005555
mov r2,#0xAA
strb r2,[r5] @ AA => 0800AAAA
mov r4,#0xE000000
ldr r3,=0xE002AAA
mov r2,#0x55
strb r2,[r3] @ 55 => 08005554
mov r2,#0xB0
strb r2,[r5] @ 90 => 0800AAAA
mov r2,#0x00
strb r2,[r4]
LDMFD sp!, {r2-r5}
bx lr

@extern void switchbank1(void);
switchbank1:
STMFD sp!, {r2-r5}
ldr r5,=0xE005555
mov r2,#0xAA
strb r2,[r5] @ AA => 0800AAAA
mov r4,#0xE000000
ldr r3,=0xE002AAA
mov r2,#0x55
strb r2,[r3] @ 55 => 08005554
mov r2,#0xB0
strb r2,[r5] @ 90 => 0800AAAA
mov r2,#0x01
strb r2,[r4]
LDMFD sp!, {r2-r5}
bx lr


@extern void writeflash(u16 address, u8 data);
writeflash:
STMFD sp!, {r2-r5}
ldr r5,=0xE005555
mov r2,#0xAA
strb r2,[r5] @ AA => 0800AAAA
mov r4,#0xE000000
add r0, r0, r4
ldr r3,=0xE002AAA
mov r2,#0x55
strb r2,[r3] @ 55 => 08005554
mov r2,#0xA0
strb r2,[r5] @ 90 => 0800AAAA
strb r1,[r0]
strb r1,[r0]
mov r2, #0xFF
strb r2,[r4]
LDMFD sp!, {r2-r5}
bx lr

@extern void eraseflash(void);
eraseflash:
STMFD sp!, {r0-r5}
ldr r3,=0xE005555
ldr r4,=0xE002AAA
ldr r5,=0xE000000
mov r2,#0xAA @ -> E005555
strb r2,[r3]
mov r2,#0x55 @ -> E002AAA
strb r2,[r4]
mov r2,#0x80 @ -> E005555
strb r2,[r3]
mov r2,#0xAA @ -> E005555
strb r2,[r3]
mov r2,#0x55 @ -> E002AAA
strb r2,[r4]
mov r2,#0x10 @ -> E005555
strb r2,[r3]
eraseloop:
ldrb r0,[r5]
ldrb r1,[r5]
cmp r0,r1
bne eraseloop
ldrb r0,[r5]
ldrb r1,[r5]
cmp r0,r1
bne eraseloop
LDMFD sp!, {r0-r5}
bx lr
--------------end of file----------------------

------------bios.s----------------------------
.GLOBL MidiKey2Freq
.GLOBL HardReset

.ARM
@.SECTION .iwram
.ALIGN
.TEXT

@extern u32 MidiKey2Freq(u32 wavedata, u8 cMK, u8 cFP);
MidiKey2Freq:

SWI 0x1F << 16
BX lr

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@
@ Undocumented function
@ Hard Reseet
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@

@extern void HardReset(void);
HardReset:

SWI 0x26 << 16
--------------end of file----------------------

-------------flash.c---------------------------
/*
* Created by using HAM 2.71
* Author: CaitSith2
*/

/***************************************************************************
******
* Includes

****************************************************************************
****/
#include "mygba.h"
#include "mbv2lib.c"

/***************************************************************************
*****
* Prototypes

****************************************************************************
***/

//bios.s prototypes
extern void HardReset(void);

//flash.s prototypes
extern void check_flashrom(u16 *v1, u16 *v2);
extern void switchbank0(void);
extern void switchbank1(void);
extern void writeflash(u16 address, u8 data);
extern void eraseflash(void);

//Internal prototypes
u8 readflash(u16 address);
int GetKey();


/***************************************************************************
******
* MULTIBOOT is interesting.
* If you write this on the top of your main file,
* the GBA ROM you build will automatically be capable of running both
* from FLA carts and, in addition directly over the MBV2 cable.
* If you do not need this, simply comment it out.

****************************************************************************
****/
MULTIBOOT

/***************************************************************************
******
* Program entry point

****************************************************************************
****/
int main(void)
{

unsigned char *a = ((unsigned char*)(0x08000000));

ham_Init();
ham_InitText(0);
ham_DrawText(2,10,"Waiting for Debug Console");
printf("Debug Console Found\n");
ham_DrawText(2,10," ");
ham_DrawText(2,11,"Do Not power off the GBA");
ham_DrawText(2,12,"Or unplug the MBV2 cable");


long i=0,j=0,k=0;
char filename[13];
char filespec[3] = { 'r', 'b', 0x00 };
int OptR=0;
int OptW=0;
int Size=0;

printf("Do What?\n");
printf("R - Read Save\n");
printf("W - Write Save\n");

i = GetKey();

if (i == 'R')
{
filespec[0] = 'w';
OptR=1;
}
if (i == 'W')
{
filespec[0] = 'r';
OptW=1;
}

if (OptR || OptW)
{
printf("What Size is the Flash?\n");
printf("1 - 64K\n");
printf("2 - 128K\n");
i = GetKey();

if (i == '2')
{
Size=1;
}
}

printf("Now Enter a Filename!\n");


while ((i=GetKey())!=0x0D)
{
filename[j] = i;
j++;
}

FILE *f;
f=fopen(filename,filespec);


if (OptW)
{

printf("Erasing Flash\n");
eraseflash();
// while((j=readflash(0))!=0xFF);
// while((j=readflash(0))!=0xFF);
// while((j=readflash(0))!=0xFF);
printf("Flash Erasing Complete\n");
for (k=0;k<=1;k++)
{
if (!Size)
{
k = 1;
}
for (i=0;i<=0xFFFF;i++)
{
if ((i % 0x0100) == 0)
{
ham_DrawText(1,10,"Flash Written to 0x%.5x",i+(k<<16));
}
j = dfgetc(f);
if(j!=0xFF)
{
writeflash(i,j);
}
}
if(Size)
{
switchbank1();
}
}
}

if (OptR)
{
if (Size)
{
switchbank0();
}
for (k=0;k<=1;k++)
{
if (!Size)
{
k=1;
}

for (i=0;i<=0xFFFF;i++)
{
if ((i % 0x0100) == 0)
{
ham_DrawText(1,10,"Flash Read from 0x%.5x",i+(k<<16));
}
j = readflash(i);
dfputc(j&0xFF,f);

}
if (Size)
{
switchbank1();
}
}
}
fclose(f);

printf("\n\nPress a key to continue\n");
GetKey();
while(1)
{
HardReset();
}
}

u8 readflash(u16 address)
{
unsigned char *a = ((unsigned char*)(0x0E000000 + address));
return *a;
}

int GetKey()
{
int i;
i = dgetch();
printf("%c",i);
return i;
}
--------------end of file----------------------

Now all I need, is the eeprom reading/writing code.






Tue Nov 4, 2003 9:27 pm

caitsith6502
Offline Offline
Send Email Send Email

Forward
Message #14591 of 15019 |
Expand Messages Author Sort by Date

Would anybody be able to show me some code (C++/assembler), for writing to flash (64K or 128K), or reading/writing eeprom?...
caitsith6502
Offline Send Email
Nov 4, 2003
3:21 pm

Never mind on the flash part. I got that figured out. All of the following code was written with the ham 2.71 dev kit. This code also needs the MBV2 ...
Damien Good
caitsith6502
Offline Send Email
Nov 5, 2003
3:39 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help