mirror of
https://github.com/marqs85/ossc.git
synced 2025-01-06 00:30:04 +00:00
Shrink write_userdata() by 20 bytes
This commit is contained in:
parent
571b588da7
commit
d638b6a650
@ -39,6 +39,7 @@ int write_userdata(alt_u8 entry)
|
|||||||
alt_u16 vm_to_write;
|
alt_u16 vm_to_write;
|
||||||
alt_u16 pageoffset, srcoffset;
|
alt_u16 pageoffset, srcoffset;
|
||||||
alt_u8 pageno;
|
alt_u8 pageno;
|
||||||
|
alt_u32 bytes_to_w;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (entry > MAX_USERDATA_ENTRY) {
|
if (entry > MAX_USERDATA_ENTRY) {
|
||||||
@ -68,31 +69,29 @@ int write_userdata(alt_u8 entry)
|
|||||||
((ude_profile*)databuf)->avc_data_len = sizeof(avconfig_t);
|
((ude_profile*)databuf)->avc_data_len = sizeof(avconfig_t);
|
||||||
((ude_profile*)databuf)->vm_data_len = vm_to_write;
|
((ude_profile*)databuf)->vm_data_len = vm_to_write;
|
||||||
|
|
||||||
pageno = 0;
|
|
||||||
pageoffset = offsetof(ude_profile, avc);
|
pageoffset = offsetof(ude_profile, avc);
|
||||||
|
|
||||||
// assume that sizeof(avconfig_t) << PAGESIZE
|
// assume that sizeof(avconfig_t) << PAGESIZE
|
||||||
memcpy(databuf+pageoffset, &tc, sizeof(avconfig_t));
|
memcpy(databuf+pageoffset, &tc, sizeof(avconfig_t));
|
||||||
pageoffset += sizeof(avconfig_t);
|
pageoffset += sizeof(avconfig_t);
|
||||||
|
|
||||||
srcoffset = 0;
|
// write a full page first
|
||||||
while (vm_to_write > 0) {
|
memcpy(databuf+pageoffset, (char*)video_modes, PAGESIZE-pageoffset);
|
||||||
if (vm_to_write >= PAGESIZE-pageoffset) {
|
srcoffset = PAGESIZE-pageoffset;
|
||||||
memcpy(databuf+pageoffset, (char*)video_modes+srcoffset, PAGESIZE-pageoffset);
|
|
||||||
srcoffset += PAGESIZE-pageoffset;
|
|
||||||
pageoffset = 0;
|
|
||||||
vm_to_write -= PAGESIZE-pageoffset;
|
vm_to_write -= PAGESIZE-pageoffset;
|
||||||
// check
|
write_flash_page(databuf, PAGESIZE, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE));
|
||||||
write_flash_page(databuf, PAGESIZE, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE) + pageno);
|
|
||||||
pageno++;
|
// then write the rest
|
||||||
} else {
|
pageno = 1;
|
||||||
memcpy(databuf+pageoffset, (char*)video_modes+srcoffset, vm_to_write);
|
while (vm_to_write > 0) {
|
||||||
pageoffset += vm_to_write;
|
bytes_to_w = (vm_to_write > PAGESIZE) ? PAGESIZE : vm_to_write;
|
||||||
vm_to_write = 0;
|
memcpy(databuf, (char*)video_modes+srcoffset, bytes_to_w);
|
||||||
// check
|
write_flash_page(databuf, bytes_to_w, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE) + pageno);
|
||||||
write_flash_page(databuf, PAGESIZE, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE) + pageno);
|
srcoffset += bytes_to_w;
|
||||||
}
|
vm_to_write -= bytes_to_w;
|
||||||
|
++pageno;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Profile %u data written (%u bytes)\n", entry, sizeof(avconfig_t)+VIDEO_MODES_SIZE);
|
printf("Profile %u data written (%u bytes)\n", entry, sizeof(avconfig_t)+VIDEO_MODES_SIZE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user