return AT_NOT;
}
- p->opt = options & ~DRV_OPT_REATTATCH;
+ /* change options */
+ if ((p->opt ^ options) & DRV_OPT_RO) {
+ f_close(&p->fd);
+ res = f_open(&p->fd, p->img_name,
+ FA_READ | (options&DRV_OPT_RO ? 0 : FA_WRITE));
+ }
- /* TODO: change options */
+ p->opt = options & ~DRV_OPT_REATTATCH;
} else {
return AT_NOMEM;
res = f_open(&p->fd, p->img_name,
- FA_WRITE | FA_READ);
+ FA_READ | (options&DRV_OPT_RO ? 0 : FA_WRITE));
if (!res && f_size(&p->fd) < CONFIG_CPM_DISKSIZE) {
+#if 0
unsigned int bw;
-
debug_cpmsd(" expanding image file from %ld to %ld\n",
f_size(&p->fd), CONFIG_CPM_DISKSIZE);
p->flags |= DRV_FLG_DIRTY;
bg_setstat(handle_cpm_drv_to, 1);
}
+#else
+ debug_cpmsd(" wrong image file zize: %ld, should be %ld\n",
+ f_size(&p->fd), CONFIG_CPM_DISKSIZE);
+ res = 64;
+#endif
}
if (res) {
drv_detach(drv);
void do_msg_cpm_login(uint8_t subf, int len, uint8_t * msg)
{
uint8_t drv;
- struct cpm_drive_s *p;
+ struct cpm_drive_s *dp;
FRESULT res = 0;
(void)subf;
return msg_cpm_result(subf, 0x02, res);
}
- p = &drv_table[drv];
- p->flags &= ~DRV_FLG_OPEN;
- p->dph = ((uint32_t)msg[4] << 16) + ((uint16_t)msg[3] << 8) + msg[2];
+ dp = &drv_table[drv];
+ dp->flags &= ~DRV_FLG_OPEN;
+ dp->dph = ((uint32_t)msg[4] << 16) + ((uint16_t)msg[3] << 8) + msg[2];
- if (p->img_name == NULL) {
+ if (dp->img_name == NULL) {
/* no file attached */
debug_cpmsd("## failed: no file attached:\n");
return msg_cpm_result(subf, 0x03, res);
}
- p->flags |= DRV_FLG_OPEN;
+ dp->flags |= DRV_FLG_OPEN;
/* send result*/
msg_cpm_result(subf, 0x00, res);
void do_msg_cpm_rw(uint8_t subf, int len, uint8_t * msg)
{
uint8_t drv;
+ struct cpm_drive_s *dp;
uint32_t addr;
uint32_t pos;
uint8_t secs;
- bool dowrite = (subf == 2);
+ bool dowrite;
FRESULT res = 0;
uint8_t rc = 0;
bool buserr = 0;
return msg_cpm_result(subf, 0x02, res);
}
+ dp = &drv_table[drv];
+
+ if (dp->img_name == NULL) {
+ /* no media */
+ return msg_cpm_result(subf, 0x06, res);
+ }
+
+ if (subf == 2) {
+ dowrite = true;
+ if (dp->opt & DRV_OPT_RO) {
+ return msg_cpm_result(subf, 0x05, res);
+ }
+ } else {
+ dowrite = false;
+ }
+
secs = msg[CNT];
addr = ((uint32_t)msg[ADDR+2] << 16) + ((uint16_t)msg[ADDR+1] << 8) + msg[ADDR];
return msg_cpm_result(subf, 0x04, res);
}
- res = f_lseek(&drv_table[drv].fd, pos);
+ res = f_lseek(&dp->fd, pos);
while (!res && secs--) {
unsigned int brw;
z80_read_block(disk_buffer, addr, CONFIG_CPM_BLOCK_SIZE);
z80_bus_cmd(Release);
}
- res = f_write(&drv_table[drv].fd, disk_buffer, CONFIG_CPM_BLOCK_SIZE, &brw);
+ res = f_write(&dp->fd, disk_buffer, CONFIG_CPM_BLOCK_SIZE, &brw);
} else {
- res = f_read(&drv_table[drv].fd, disk_buffer, CONFIG_CPM_BLOCK_SIZE, &brw);
+ res = f_read(&dp->fd, disk_buffer, CONFIG_CPM_BLOCK_SIZE, &brw);
if (res == FR_OK) {
if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
buserr = 1;
}
if (dowrite && !res) {
- drv_table[drv].flags |= DRV_FLG_DIRTY;
+ dp->flags |= DRV_FLG_DIRTY;
bg_setstat(handle_cpm_drv_to, 1);
}