/*-----------------------------------------------------------------------------------*/ int __fastcall__ c64_fs_read_raw(register struct c64_fs_file *f, char *buf, int len) { int i; unsigned char fptr, ftrack, fsect; /* Check if current block is already in buffer, and if not read it from disk. */ if(_c64_fs_filebuftrack != f->track || _c64_fs_filebufsect != f->sect) { _c64_fs_filebuftrack = f->track; _c64_fs_filebufsect = f->sect; c64_dio_read_block(_c64_fs_filebuftrack, _c64_fs_filebufsect, _c64_fs_filebuf); } if(_c64_fs_filebuf[0] == 0 && f->ptr == _c64_fs_filebuf[1]) { return 0; /* EOF */ } fptr = f->ptr; ftrack = f->track; fsect = f->sect; for(i = 0; i < len; ++i) { *buf = _c64_fs_filebuf[fptr]; ++fptr; if(_c64_fs_filebuf[0] == 0) { if(fptr == _c64_fs_filebuf[1]) { /* End of file reached, we return the amount of bytes read so far. */ return i + 1; } } else if(fptr == 0) { /* Read new block into buffer and set buffer state accordingly. */ _c64_fs_filebuftrack = ftrack = _c64_fs_filebuf[0]; _c64_fs_filebufsect = fsect = _c64_fs_filebuf[1]; fptr = 2; c64_dio_read_block(_c64_fs_filebuftrack, _c64_fs_filebufsect, _c64_fs_filebuf); } ++buf; } return i; }
/*-----------------------------------------------------------------------------------*/ int c64_fs_read_next(register struct c64_fs_file *f, int len) { int i; /* Check if current block is already in buffer, and if not read it from disk. */ if(_c64_fs_filebuftrack != f->track || _c64_fs_filebufsect != f->sect) { _c64_fs_filebuftrack = f->track; _c64_fs_filebufsect = f->sect; c64_dio_read_block(_c64_fs_filebuftrack, _c64_fs_filebufsect, _c64_fs_filebuf); } if(_c64_fs_filebuf[0] == 0 && f->ptr == _c64_fs_filebuf[1]) { return 0; /* EOF */ } for(i = 0; i < len; ++i) { ++f->ptr; if(_c64_fs_filebuf[0] == 0) { if(f->ptr == _c64_fs_filebuf[1]) { /* End of file reached, we return the amount of bytes read so far. */ return i + 1; } } else if(f->ptr == 0) { /* Read new block into buffer and set buffer state accordingly. */ _c64_fs_filebuftrack = f->track = _c64_fs_filebuf[0]; _c64_fs_filebufsect = f->sect = _c64_fs_filebuf[1]; f->ptr = 2; c64_dio_read_block(_c64_fs_filebuftrack, _c64_fs_filebufsect, _c64_fs_filebuf); } } return i; }
/*-----------------------------------------------------------------------------------*/ void _c64_fs_readdirbuf(unsigned char track, unsigned char sect) { if(_c64_fs_dirbuftrack == track && _c64_fs_dirbufsect == sect) { /* Buffer already contains requested block, return. */ return; } c64_dio_read_block(track, sect, _c64_fs_dirbuf); _c64_fs_dirbuftrack = track; _c64_fs_dirbufsect = sect; }
/*-----------------------------------------------------------------------------------*/ int __fastcall__ c64_fs_write(register struct c64_fs_file *f, char *buf, int len) { int i; if(len <= 0) { return 0; } /* Check if current block is already in buffer, and if not read it from disk. */ if(_c64_fs_filebuftrack != f->track || _c64_fs_filebufsect != f->sect) { _c64_fs_filebuftrack = f->track; _c64_fs_filebufsect = f->sect; c64_dio_read_block(_c64_fs_filebuftrack, _c64_fs_filebufsect, _c64_fs_filebuf); } i = 256 - f->ptr; if(len < i) { i = len; } memcpy(&_c64_fs_filebuf[f->ptr], buf, i); f->ptr += i; if(_c64_fs_filebuf[0] == 0 && f->ptr > _c64_fs_filebuf[1]) { _c64_fs_filebuf[1] = f->ptr; } c64_dio_write_block(_c64_fs_filebuftrack, _c64_fs_filebufsect, _c64_fs_filebuf); return i; }
/*-----------------------------------------------------------------------------------*/ #if !NOASM #pragma optimize(push, off) #endif /* !NOASM */ int __fastcall__ c64_fs_read(register struct c64_fs_file *f, char *buf, int len) { static int i; /* Check if current block is already in buffer, and if not read it from disk. */ #if NOASM if(f->track != _c64_fs_filebuftrack || _c64_fs_filebufsect != f->sect) { _c64_fs_filebuftrack = f->track; _c64_fs_filebufsect = f->sect; c64_dio_read_block(_c64_fs_filebuftrack, _c64_fs_filebufsect, _c64_fs_filebuf); } #else /* NOASM */ asm("ldy #%b", offsetof(struct c64_fs_file, track)); asm("lda (regbank+%b),y", 4); asm("cmp %v", _c64_fs_filebuftrack); asm("bne doblock"); asm("ldy #%b", offsetof(struct c64_fs_file, sect)); asm("lda (regbank+%b),y", 4); asm("cmp %v", _c64_fs_filebufsect); asm("bne doblock"); asm("jmp noblock"); asm("doblock:"); asm("ldy #%b", offsetof(struct c64_fs_file, track)); asm("lda (regbank+%b),y", 4); asm("sta %v", _c64_fs_filebuftrack); asm("sta %v", c64_dio_asm_track); asm("ldy #%b", offsetof(struct c64_fs_file, sect)); asm("lda (regbank+%b),y", 4); asm("sta %v", _c64_fs_filebufsect); asm("sta %v", c64_dio_asm_sector); asm("lda #<(%v)", _c64_fs_filebuf); asm("sta %v", c64_dio_asm_ptr); asm("lda #>(%v)", _c64_fs_filebuf); asm("sta %v+1", c64_dio_asm_ptr); asm("jsr %v", c64_dio_asm_read_block); asm("noblock:"); #endif /* NOASM */ if(_c64_fs_filebuf[0] == 0 && f->ptr == _c64_fs_filebuf[1]) { return 0; /* EOF */ } for(i = 0; i < len; ++i) { #if NOASM *buf = _c64_fs_filebuf[f->ptr]; ++f->ptr; #else /* NOASM */ asm("ldy #%o+1", buf); asm("jsr ldaxysp"); asm("sta ptr2"); asm("stx ptr2+1"); asm("ldy #%b", offsetof(struct c64_fs_file, ptr)); asm("lda (regbank+%b),y", 4); asm("tax"); asm("ldy #0"); asm("lda %v,x", _c64_fs_filebuf); asm("sta (ptr2),y"); asm("inx"); asm("txa"); asm("ldy #%b", offsetof(struct c64_fs_file, ptr)); asm("sta (regbank+%b),y", 4); #endif /* NOASM */ if(_c64_fs_filebuf[0] == 0) { if(f->ptr == _c64_fs_filebuf[1]) { /* End of file reached, we return the amount of bytes read so far. */ return i + 1; } } else if(f->ptr == 0) { /* Read new block into buffer and set buffer state accordingly. */ _c64_fs_filebuftrack = f->track = _c64_fs_filebuf[0]; _c64_fs_filebufsect = f->sect = _c64_fs_filebuf[1]; f->ptr = 2; c64_dio_read_block(_c64_fs_filebuftrack, _c64_fs_filebufsect, _c64_fs_filebuf); } ++buf; } return i; }
static void read_sector(void) { c64_dio_read_block(ds.track, ds.sect, uip_appdata); }