Posted: Sat Aug 25, 2012 6:57 pm
Yeah, if you were in assembly, you could write words or longs using movep.w or movep.l, which writes each byte of the word or long to every other byte location, but you cannot do that in C. You would need to do this to write a word:
The first line writes the MSB of the word, and the second writes the LSB of the word. You would have a similar issue reading the word from memory. If it were me, I'd make a set of assembly functions in a separate file to handle this... have an sram.s file with functions like this
Notes: to use them, you'd need to use the comment lines from the assembly for your protos in the C file, like this
and now you have C functions to call. Notice that the offset doesn't need to be doubled ahead of time - the function does that. So your code above would become
Code: Select all
*(vu8*)(0x200003) = 500 >> 8;
*(vu8*)(0x200005) = 500 & 255;
Code: Select all
| extern void sram_enable(void);
.global sram_enable
sram_enable:
move.b #1,0xA103F1
rts
| extern void sram_disable(void);
.global sram_disable
sram_enable:
move.b #0,0xA103F1
rts
| extern u8 sram_rd_byte(int offset);
.global sram_rd_byte
sram_rd_byte:
move.l 4(sp),d1
add.l d1,d1
lea 0x200001,a0
moveq #0,d0
move.b (a0,d1.l),d0
rts
| extern u16 sram_rd_word(int offset);
.global sram_rd_word
sram_rd_word:
move.l 4(sp),d1
add.l d1,d1
lea 0x200001,a0
lea (a0,d1.l),a0
moveq #0,d0
movep.w 0(a0),d0
rts
| extern u32 sram_rd_long(int offset);
.global sram_rd_long
sram_rd_long:
move.l 4(sp),d1
add.l d1,d1
lea 0x200001,a0
lea (a0,d1.l),a0
movep.l 0(a0),d0
rts
| extern void sram_wr_byte(int offset, u8 val);
.global sram_wr_byte
sram_wr_byte:
move.l 4(sp),d1
add.l d1,d1
move.l 8(sp),d0 /* values on stack are always long */
lea 0x200001,a0
move.b d0,(a0,d1.l)
rts
| extern void sram_wr_word(int offset, u16 val);
.global sram_wr_word
sram_wr_word:
move.l 4(sp),d1
add.l d1,d1
move.l 8(sp),d0 /* values on stack are always long */
lea 0x200001,a0
lea (a0,d1.l),a0
movep.w d0,0(a0)
rts
| extern void sram_wr_long(int offset, u32 val);
.global sram_wr_long
sram_wr_long:
move.l 4(sp),d1
add.l d1,d1
move.l 8(sp),d0 /* values on stack are always long */
lea 0x200001,a0
lea (a0,d1.l),a0
movep.l d0,0(a0)
rts
Code: Select all
extern void sram_enable(void);
extern void sram_disable(void);
extern u8 sram_rd_byte(int offset);
extern u16 sram_rd_word(int offset);
extern u32 sram_rd_long(int offset);
extern void sram_wr_byte(int offset, u8 val);
extern void sram_wr_word(int offset, u16 val);
extern void sram_wr_long(int offset, u32 val);
Code: Select all
sram_enable();
if (sram_rd_byte(0) != 250)
{
j=15;
VDP_drawText("First time running Dance Impact", 3, 3);
VDP_drawText("Reset memory", 3, 7);
for(i=0; i<5000; i++)
{
VDP_drawText(".", j, 7);
if (i==4990 && j<20) {j++; i=0;}
}
sram_wr_byte(0, 250); //indique qu'une sauvegarde existe
sram_wr_word(1, 500); //best score stage 1 réglé à 500
sram_wr_word(3, 500); //best score stage 2 réglé à 500
sram_wr_word(5, 500); //best score stage 3 réglé à 500
}
sram_disable();