Some byte shaving; lseek returns the offset.
This commit is contained in:
parent
01fdfef8c0
commit
2b013c34dc
|
@ -24,5 +24,5 @@ off_t lseek(int fd, off_t offset, int whence)
|
||||||
|
|
||||||
U16(fcbe->fcb.r) = offset>>7;
|
U16(fcbe->fcb.r) = offset>>7;
|
||||||
fcbe->offset = offset & 0x7f;
|
fcbe->offset = offset & 0x7f;
|
||||||
return 0;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ ssize_t read(int fd, void* buffer, size_t count)
|
||||||
struct FCBE* fcbe = &__fd[fd];
|
struct FCBE* fcbe = &__fd[fd];
|
||||||
uint8_t olduser;
|
uint8_t olduser;
|
||||||
ssize_t result;
|
ssize_t result;
|
||||||
|
uint8_t* src;
|
||||||
|
|
||||||
__init_file_descriptors();
|
__init_file_descriptors();
|
||||||
if (fcbe->fcb.dr == 0)
|
if (fcbe->fcb.dr == 0)
|
||||||
|
@ -36,8 +37,6 @@ ssize_t read(int fd, void* buffer, size_t count)
|
||||||
goto done;
|
goto done;
|
||||||
if (fcbe->offset || !SECTOR_ALIGNED(count))
|
if (fcbe->offset || !SECTOR_ALIGNED(count))
|
||||||
{
|
{
|
||||||
uint8_t delta;
|
|
||||||
|
|
||||||
/* We need to read bytes until we're at a sector boundary. */
|
/* We need to read bytes until we're at a sector boundary. */
|
||||||
|
|
||||||
cpm_set_dma(__transfer_buffer);
|
cpm_set_dma(__transfer_buffer);
|
||||||
|
@ -46,13 +45,13 @@ ssize_t read(int fd, void* buffer, size_t count)
|
||||||
|
|
||||||
/* Copy enough bytes to reach the end of the sector. */
|
/* Copy enough bytes to reach the end of the sector. */
|
||||||
|
|
||||||
delta = 128 - fcbe->offset;
|
src = __transfer_buffer + fcbe->offset;
|
||||||
if (delta > count)
|
while ((count != 0) && (fcbe->offset != 128))
|
||||||
delta = count;
|
{
|
||||||
memcpy(bbuffer, __transfer_buffer+fcbe->offset, delta);
|
*bbuffer++ = *src++;
|
||||||
fcbe->offset += delta;
|
fcbe->offset++;
|
||||||
count -= delta;
|
count--;
|
||||||
bbuffer += delta;
|
}
|
||||||
|
|
||||||
/* If we've read enough bytes, advance to the next sector. */
|
/* If we've read enough bytes, advance to the next sector. */
|
||||||
|
|
||||||
|
@ -89,7 +88,13 @@ ssize_t read(int fd, void* buffer, size_t count)
|
||||||
if (cpm_read_random_safe(&fcbe->fcb) != 0)
|
if (cpm_read_random_safe(&fcbe->fcb) != 0)
|
||||||
goto eio;
|
goto eio;
|
||||||
|
|
||||||
memcpy(bbuffer, __transfer_buffer, count);
|
src = __transfer_buffer;
|
||||||
|
while (count != 0)
|
||||||
|
{
|
||||||
|
*bbuffer++ = *src++;
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
|
||||||
fcbe->offset = count;
|
fcbe->offset = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,11 @@ void _sys_write_tty(char c)
|
||||||
|
|
||||||
ssize_t write(int fd, void* buffer, size_t count)
|
ssize_t write(int fd, void* buffer, size_t count)
|
||||||
{
|
{
|
||||||
uint8_t* bbuffer = buffer;
|
const uint8_t* bbuffer = buffer;
|
||||||
struct FCBE* fcbe = &__fd[fd];
|
struct FCBE* fcbe = &__fd[fd];
|
||||||
uint8_t olduser;
|
uint8_t olduser;
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
|
uint8_t* dest;
|
||||||
|
|
||||||
__init_file_descriptors();
|
__init_file_descriptors();
|
||||||
if (fcbe->fcb.dr == 0)
|
if (fcbe->fcb.dr == 0)
|
||||||
|
@ -40,8 +41,6 @@ ssize_t write(int fd, void* buffer, size_t count)
|
||||||
|
|
||||||
if (fcbe->offset || !SECTOR_ALIGNED(count))
|
if (fcbe->offset || !SECTOR_ALIGNED(count))
|
||||||
{
|
{
|
||||||
uint8_t delta;
|
|
||||||
|
|
||||||
/* We're not at a sector boundary, so we need to do a
|
/* We're not at a sector boundary, so we need to do a
|
||||||
* read/modify/write of the initial fragment. */
|
* read/modify/write of the initial fragment. */
|
||||||
|
|
||||||
|
@ -51,13 +50,13 @@ ssize_t write(int fd, void* buffer, size_t count)
|
||||||
|
|
||||||
/* Copy enough bytes to reach the end of the sector. */
|
/* Copy enough bytes to reach the end of the sector. */
|
||||||
|
|
||||||
delta = 128 - fcbe->offset;
|
dest = __transfer_buffer + fcbe->offset;
|
||||||
if (delta > count)
|
while ((count != 0) && (fcbe->offset != 128))
|
||||||
delta = count;
|
{
|
||||||
memcpy(__transfer_buffer+fcbe->offset, bbuffer, delta);
|
*dest++ = *bbuffer++;
|
||||||
fcbe->offset += delta;
|
fcbe->offset++;
|
||||||
count -= delta;
|
count--;
|
||||||
bbuffer += delta;
|
}
|
||||||
|
|
||||||
/* Write back. */
|
/* Write back. */
|
||||||
|
|
||||||
|
@ -94,7 +93,12 @@ ssize_t write(int fd, void* buffer, size_t count)
|
||||||
if (cpm_read_random_safe(&fcbe->fcb) != 0)
|
if (cpm_read_random_safe(&fcbe->fcb) != 0)
|
||||||
goto eio;
|
goto eio;
|
||||||
|
|
||||||
memcpy(__transfer_buffer, bbuffer, count);
|
dest = __transfer_buffer;
|
||||||
|
while (count != 0)
|
||||||
|
{
|
||||||
|
*dest++ = *bbuffer++;
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
|
||||||
if (cpm_write_random(&fcbe->fcb) != 0)
|
if (cpm_write_random(&fcbe->fcb) != 0)
|
||||||
goto eio;
|
goto eio;
|
||||||
|
|
Loading…
Reference in a new issue