+// SPDX-License-Identifier: MIT
+
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <endian.h>
-#include "../hunk-reloc.h"
-#include "piscsi.h"
+
+#include "config_file/config_file.h"
+#include "gpio/ps_protocol.h"
#include "piscsi-enums.h"
-#include "../../../config_file/config_file.h"
-#include "../../../gpio/ps_protocol.h"
+#include "piscsi.h"
+#include "platforms/amiga/hunk-reloc.h"
#define BE(val) be32toh(val)
#define BE16(val) be16toh(val)
-// Comment these lines to restore debug output:
+// Uncomment the line below to enable debug output
+//#define PISCSI_DEBUG
+
+#ifdef PISCSI_DEBUG
+#define DEBUG printf
+//#define DEBUG_TRIVIAL printf
+#define DEBUG_TRIVIAL(...)
+
+//extern void stop_cpu_emulation(uint8_t disasm_cur);
+#define stop_cpu_emulation(...)
+
+static const char *op_type_names[4] = {
+ "BYTE",
+ "WORD",
+ "LONGWORD",
+ "MEM",
+};
+#else
#define DEBUG(...)
-//#define DEBUG printf
#define DEBUG_TRIVIAL(...)
-//#define DEBUG_TRIVIAL printf
#define stop_cpu_emulation(...)
+#endif
#ifdef FAKESTORM
#define lseek64 lseek
#endif
extern struct emulator_config *cfg;
-extern void stop_cpu_emulation(uint8_t disasm_cur);
struct piscsi_dev devs[8];
struct piscsi_fs filesystems[NUM_FILESYSTEMS];
uint32_t rom_partition_dostype[128];
uint32_t rom_cur_partition = 0, rom_cur_fs = 0;
-
-
extern unsigned char ac_piscsi_rom[];
-static const char *op_type_names[4] = {
- "BYTE",
- "WORD",
- "LONGWORD",
- "MEM",
-};
-
//static const char *partition_marker = "PART";
struct hunk_info piscsi_hinfo;
devs[i].c = devs[i].h = devs[i].s = 0;
}
- FILE *in = fopen("./platforms/amiga/piscsi/piscsi.rom", "rb");
- if (in == NULL) {
- printf("[PISCSI] Could not open PISCSI Boot ROM file for reading!\n");
- // Zero out the boot ROM offset from the autoconfig ROM.
- ac_piscsi_rom[20] = 0;
- ac_piscsi_rom[21] = 0;
- ac_piscsi_rom[22] = 0;
- ac_piscsi_rom[23] = 0;
- return;
+ if (piscsi_rom_ptr == NULL) {
+ FILE *in = fopen("./platforms/amiga/piscsi/piscsi.rom", "rb");
+ if (in == NULL) {
+ printf("[PISCSI] Could not open PISCSI Boot ROM file for reading!\n");
+ // Zero out the boot ROM offset from the autoconfig ROM.
+ ac_piscsi_rom[20] = 0;
+ ac_piscsi_rom[21] = 0;
+ ac_piscsi_rom[22] = 0;
+ ac_piscsi_rom[23] = 0;
+ return;
+ }
+ fseek(in, 0, SEEK_END);
+ piscsi_rom_size = ftell(in);
+ fseek(in, 0, SEEK_SET);
+ piscsi_rom_ptr = malloc(piscsi_rom_size);
+ fread(piscsi_rom_ptr, piscsi_rom_size, 1, in);
+
+ fseek(in, PISCSI_DRIVER_OFFSET, SEEK_SET);
+ process_hunks(in, &piscsi_hinfo, piscsi_hreloc, PISCSI_DRIVER_OFFSET);
+
+ fclose(in);
+
+ printf("[PISCSI] Loaded Boot ROM.\n");
+ } else {
+ printf("[PISCSI] Boot ROM already loaded.\n");
}
- fseek(in, 0, SEEK_END);
- piscsi_rom_size = ftell(in);
- fseek(in, 0, SEEK_SET);
- piscsi_rom_ptr = malloc(piscsi_rom_size);
- fread(piscsi_rom_ptr, piscsi_rom_size, 1, in);
+ fflush(stdout);
+}
- fseek(in, PISCSI_DRIVER_OFFSET, SEEK_SET);
- process_hunks(in, &piscsi_hinfo, piscsi_hreloc, PISCSI_DRIVER_OFFSET);
+void piscsi_shutdown() {
+ printf("[PISCSI] Shutting down PiSCSI.\n");
+ for (int i = 0; i < 8; i++) {
+ if (devs[i].fd != -1) {
+ close(devs[i].fd);
+ devs[i].fd = -1;
+ devs[i].block_size = 0;
+ }
+ }
- fclose(in);
- printf("[PISCSI] Loaded Boot ROM.\n");
+ for (int i = 0; i < NUM_FILESYSTEMS; i++) {
+ if (filesystems[i].binary_data) {
+ free(filesystems[i].binary_data);
+ filesystems[i].binary_data = NULL;
+ }
+ if (filesystems[i].fhb) {
+ free(filesystems[i].fhb);
+ filesystems[i].fhb = NULL;
+ }
+ filesystems[i].h_info.current_hunk = 0;
+ filesystems[i].h_info.reloc_hunks = 0;
+ filesystems[i].FS_ID = 0;
+ filesystems[i].handler = 0;
+ }
}
void piscsi_find_partitions(struct piscsi_dev *d) {
return;
}
- char *block = malloc(512);
+ char *block = malloc(d->block_size);
- lseek(fd, BE(d->rdb->rdb_PartitionList) * 512, SEEK_SET);
+ lseek(fd, BE(d->rdb->rdb_PartitionList) * d->block_size, SEEK_SET);
next_partition:;
- read(fd, block, 512);
+ read(fd, block, d->block_size);
uint32_t first = be32toh(*((uint32_t *)&block[0]));
if (first != PART_IDENTIFIER) {
if (d->pb[cur_partition]->pb_Next != 0xFFFFFFFF) {
uint64_t next = be32toh(pb->pb_Next);
- block = malloc(512);
- lseek64(fd, next * 512, SEEK_SET);
+ block = malloc(d->block_size);
+ lseek64(fd, next * d->block_size, SEEK_SET);
cur_partition++;
DEBUG("[PISCSI] Next partition at block %d.\n", be32toh(pb->pb_Next));
goto next_partition;
int piscsi_parse_rdb(struct piscsi_dev *d) {
int fd = d->fd;
int i = 0;
- uint8_t *block = malloc(512);
+ uint8_t *block = malloc(PISCSI_MAX_BLOCK_SIZE);
lseek(fd, 0, SEEK_SET);
for (i = 0; i < RDB_BLOCK_LIMIT; i++) {
- read(fd, block, 512);
+ read(fd, block, PISCSI_MAX_BLOCK_SIZE);
uint32_t first = be32toh(*((uint32_t *)&block[0]));
if (first == RDB_IDENTIFIER)
goto rdb_found;
d->s = be32toh(rdb->rdb_Sectors);
d->num_partitions = 0;
DEBUG("[PISCSI] RDB - first partition at block %d.\n", be32toh(rdb->rdb_PartitionList));
+ d->block_size = be32toh(rdb->rdb_BlockBytes);
+ DEBUG("[PISCSI] Block size: %d. (%d)\n", be32toh(rdb->rdb_BlockBytes), d->block_size);
if (d->rdb)
free(d->rdb);
d->rdb = rdb;
void piscsi_find_filesystems(struct piscsi_dev *d) {
if (!d->num_partitions)
return;
-
+
uint8_t fs_found = 0;
-
- uint8_t *fhb_block = malloc(512);
+
+ uint8_t *fhb_block = malloc(d->block_size);
lseek64(d->fd, d->fshd_offs, SEEK_SET);
struct FileSysHeaderBlock *fhb = (struct FileSysHeaderBlock *)fhb_block;
- read(d->fd, fhb_block, 512);
-
+ read(d->fd, fhb_block, d->block_size);
+
while (BE(fhb->fhb_ID) == FS_IDENTIFIER) {
char *dosID = (char *)&fhb->fhb_DosType;
+#ifdef PISCSI_DEBUG
uint16_t *fsVer = (uint16_t *)&fhb->fhb_Version;
DEBUG("[FSHD] FSHD Block found.\n");
DEBUG("[FSHD] Prio: %d Startup: %d\n", BE(fhb->fhb_Priority), BE(fhb->fhb_Startup));
DEBUG("[FSHD] SegListBlocks: %d GlobalVec: %d\n", BE(fhb->fhb_Priority), BE(fhb->fhb_Startup));
DEBUG("[FSHD] FileSysName: %s\n", fhb->fhb_FileSysName + 1);
+#endif
for (int i = 0; i < NUM_FILESYSTEMS; i++) {
if (filesystems[i].FS_ID == fhb->fhb_DosType) {
DEBUG("[FSHD] File system %c%c%c/%d already loaded. Skipping.\n", dosID[0], dosID[1], dosID[2], dosID[3]);
if (BE(fhb->fhb_Next) == 0xFFFFFFFF)
goto fs_done;
-
+
goto skip_fs_load_lseg;
}
}
- if (load_lseg(d->fd, &filesystems[piscsi_num_fs].binary_data, &filesystems[piscsi_num_fs].h_info, filesystems[piscsi_num_fs].relocs) != -1) {
+ if (load_lseg(d->fd, &filesystems[piscsi_num_fs].binary_data, &filesystems[piscsi_num_fs].h_info, filesystems[piscsi_num_fs].relocs, d->block_size) != -1) {
filesystems[piscsi_num_fs].FS_ID = fhb->fhb_DosType;
filesystems[piscsi_num_fs].fhb = fhb;
printf("[FSHD] Loaded and set up file system %d: %c%c%c/%d\n", piscsi_num_fs + 1, dosID[0], dosID[1], dosID[2], dosID[3]);
skip_fs_load_lseg:;
fs_found++;
- lseek64(d->fd, BE(fhb->fhb_Next) * 512, SEEK_SET);
- fhb_block = malloc(512);
+ lseek64(d->fd, BE(fhb->fhb_Next) * d->block_size, SEEK_SET);
+ fhb_block = malloc(d->block_size);
fhb = (struct FileSysHeaderBlock *)fhb_block;
- read(d->fd, fhb_block, 512);
+ read(d->fd, fhb_block, d->block_size);
}
- if (!fs_found)
+ if (!fs_found) {
DEBUG("[!!!FSHD] No file systems found on hard drive!\n");
+ }
fs_done:;
if (fhb_block)
free(fhb_block);
}
+struct piscsi_dev *piscsi_get_dev(uint8_t index) {
+ return &devs[index];
+}
+
void piscsi_map_drive(char *filename, uint8_t index) {
if (index > 7) {
printf("[PISCSI] Drive index %d out of range.\nUnable to map file %s to drive.\n", index, filename);
d->h = 16;
d->s = 63;
d->c = (file_size / 512) / (d->s * d->h);
+ d->block_size = 512;
}
printf("[PISCSI] CHS: %d %d %d\n", d->c, d->h, d->s);
+ printf ("Finding partitions.\n");
piscsi_find_partitions(d);
+ printf ("Finding file systems.\n");
piscsi_find_filesystems(d);
+ printf ("Done.\n");
}
void piscsi_unmap_drive(uint8_t index) {
DEBUG("[PISCSI] Initializing devices.\n");
break;
case DBG_OPENDEV:
- if (piscsi_dbg[0] != 255)
+ if (piscsi_dbg[0] != 255) {
DEBUG("[PISCSI] Opening device %d (%d). Flags: %d (%.2X)\n", piscsi_dbg[0], piscsi_dbg[2], piscsi_dbg[1], piscsi_dbg[1]);
+ }
break;
case DBG_CLEANUP:
DEBUG("[PISCSI] Cleaning up.\n");
case DBG_SCSI_RDG:
DEBUG("[PISCSI] Get SCSI RDG MODE SENSE.\n");
break;
+ case DBG_SCSICMD_RW10:
+#ifdef PISCSI_DEBUG
+ r = get_mapped_item_by_address(cfg, piscsi_dbg[0]);
+ struct SCSICmd_RW10 *rwdat = NULL;
+ char data[10];
+ if (r != -1) {
+ uint32_t addr = piscsi_dbg[0] - cfg->map_offset[r];
+ rwdat = (struct SCSICmd_RW10 *)(&cfg->map_data[r][addr]);
+ }
+ else {
+ DEBUG_TRIVIAL("[RW10] scsiData: %.8X\n", piscsi_dbg[0]);
+ for (int i = 0; i < 10; i++) {
+ data[i] = read8(piscsi_dbg[0] + i);
+ }
+ rwdat = data;
+ }
+ if (rwdat) {
+ DEBUG_TRIVIAL("[RW10] CMD: %.2X\n", rwdat->opcode);
+ DEBUG_TRIVIAL("[RW10] RDP: %.2X\n", rwdat->rdprotect_flags);
+ DEBUG_TRIVIAL("[RW10] Block: %d (%d)\n", rwdat->block, BE(rwdat->block));
+ DEBUG_TRIVIAL("[RW10] Res_Group: %.2X\n", rwdat->res_groupnum);
+ DEBUG_TRIVIAL("[RW10] Len: %d (%d)\n", rwdat->len, BE16(rwdat->len));
+ }
+#endif
+ break;
case DBG_SCSI_DEBUG_MODESENSE_6:
DEBUG_TRIVIAL("[PISCSI] SCSI ModeSense debug. Data: %.8X\n", piscsi_dbg[0]);
r = get_mapped_item_by_address(cfg, piscsi_dbg[0]);
if (r != -1) {
+#ifdef PISCSI_DEBUG
uint32_t addr = piscsi_dbg[0] - cfg->map_offset[r];
struct SCSICmd_ModeSense6 *sense = (struct SCSICmd_ModeSense6 *)(&cfg->map_data[r][addr]);
DEBUG_TRIVIAL("[SenseData] CMD: %.2X\n", sense->opcode);
DEBUG_TRIVIAL("[SenseData] PageCodes: %.2X %.2X\n", (sense->pc_pagecode & 0x3F), sense->subpage_code);
DEBUG_TRIVIAL("[SenseData] AllocLen: %d\n", sense->alloc_len);
DEBUG_TRIVIAL("[SenseData] Control: %.2X (%d)\n", sense->control, sense->control);
+#endif
}
else {
DEBUG("[!!!PISCSI] ModeSense data not immediately available.\n");
void handle_piscsi_write(uint32_t addr, uint32_t val, uint8_t type) {
int32_t r;
+ uint8_t *map;
+#ifndef PISCSI_DEBUG
+ if (type) {}
+#endif
struct piscsi_dev *d = &devs[piscsi_cur_drive];
switch (cmd) {
case PISCSI_CMD_READ64:
case PISCSI_CMD_READ:
+ case PISCSI_CMD_READBYTES:
d = &devs[val];
if (d->fd == -1) {
DEBUG("[!!!PISCSI] BUG: Attempted read from unmapped drive %d.\n", val);
break;
}
- if (cmd == PISCSI_CMD_READ) {
+ if (cmd == PISCSI_CMD_READBYTES) {
+ DEBUG("[PISCSI-%d] %d byte READBYTES from block %d to address %.8X\n", val, piscsi_u32[1], piscsi_u32[0] / d->block_size, piscsi_u32[2]);
+ uint32_t src = piscsi_u32[0];
+ d->lba = (src / d->block_size);
+ lseek(d->fd, src, SEEK_SET);
+ }
+ else if (cmd == PISCSI_CMD_READ) {
DEBUG("[PISCSI-%d] %d byte READ from block %d to address %.8X\n", val, piscsi_u32[1], piscsi_u32[0], piscsi_u32[2]);
d->lba = piscsi_u32[0];
- lseek(d->fd, (piscsi_u32[0] * 512), SEEK_SET);
+ lseek(d->fd, (piscsi_u32[0] * d->block_size), SEEK_SET);
}
else {
uint64_t src = piscsi_u32[3];
src = (src << 32) | piscsi_u32[0];
- DEBUG("[PISCSI-%d] %d byte READ64 from block %lld to address %.8X\n", val, piscsi_u32[1], (src / 512), piscsi_u32[2]);
- d->lba = (src / 512);
+ DEBUG("[PISCSI-%d] %d byte READ64 from block %lld to address %.8X\n", val, piscsi_u32[1], (src / d->block_size), piscsi_u32[2]);
+ d->lba = (src / d->block_size);
lseek64(d->fd, src, SEEK_SET);
}
- r = get_mapped_item_by_address(cfg, piscsi_u32[2]);
- if (r != -1 && cfg->map_type[r] == MAPTYPE_RAM) {
+ map = get_mapped_data_pointer_by_address(cfg, piscsi_u32[2]);
+ if (map) {
DEBUG_TRIVIAL("[PISCSI-%d] \"DMA\" Read goes to mapped range %d.\n", val, r);
- read(d->fd, cfg->map_data[r] + piscsi_u32[2] - cfg->map_offset[r], piscsi_u32[1]);
+ read(d->fd, map, piscsi_u32[1]);
}
else {
DEBUG_TRIVIAL("[PISCSI-%d] No mapped range found for read.\n", val);
uint8_t c = 0;
for (uint32_t i = 0; i < piscsi_u32[1]; i++) {
read(d->fd, &c, 1);
- write8(piscsi_u32[2] + i, (uint32_t)c);
+ m68k_write_memory_8(piscsi_u32[2] + i, (uint32_t)c);
}
}
break;
case PISCSI_CMD_WRITE64:
case PISCSI_CMD_WRITE:
+ case PISCSI_CMD_WRITEBYTES:
d = &devs[val];
if (d->fd == -1) {
DEBUG ("[PISCSI] BUG: Attempted write to unmapped drive %d.\n", val);
break;
}
- if (cmd == PISCSI_CMD_WRITE) {
+ if (cmd == PISCSI_CMD_WRITEBYTES) {
+ DEBUG("[PISCSI-%d] %d byte WRITEBYTES to block %d from address %.8X\n", val, piscsi_u32[1], piscsi_u32[0] / d->block_size, piscsi_u32[2]);
+ uint32_t src = piscsi_u32[0];
+ d->lba = (src / d->block_size);
+ lseek(d->fd, src, SEEK_SET);
+ }
+ else if (cmd == PISCSI_CMD_WRITE) {
DEBUG("[PISCSI-%d] %d byte WRITE to block %d from address %.8X\n", val, piscsi_u32[1], piscsi_u32[0], piscsi_u32[2]);
d->lba = piscsi_u32[0];
- lseek(d->fd, (piscsi_u32[0] * 512), SEEK_SET);
+ lseek(d->fd, (piscsi_u32[0] * d->block_size), SEEK_SET);
}
else {
uint64_t src = piscsi_u32[3];
src = (src << 32) | piscsi_u32[0];
- DEBUG("[PISCSI-%d] %d byte WRITE64 to block %lld from address %.8X\n", val, piscsi_u32[1], (src / 512), piscsi_u32[2]);
- d->lba = (src / 512);
+ DEBUG("[PISCSI-%d] %d byte WRITE64 to block %lld from address %.8X\n", val, piscsi_u32[1], (src / d->block_size), piscsi_u32[2]);
+ d->lba = (src / d->block_size);
lseek64(d->fd, src, SEEK_SET);
}
- r = get_mapped_item_by_address(cfg, piscsi_u32[2]);
- if (r != -1) {
+ map = get_mapped_data_pointer_by_address(cfg, piscsi_u32[2]);
+ if (map) {
DEBUG_TRIVIAL("[PISCSI-%d] \"DMA\" Write comes from mapped range %d.\n", val, r);
- write(d->fd, cfg->map_data[r] + piscsi_u32[2] - cfg->map_offset[r], piscsi_u32[1]);
+ write(d->fd, map, piscsi_u32[1]);
}
else {
DEBUG_TRIVIAL("[PISCSI-%d] No mapped range found for write.\n", val);
uint8_t c = 0;
for (uint32_t i = 0; i < piscsi_u32[1]; i++) {
- c = read8(piscsi_u32[2] + i);
+ c = m68k_read_memory_8(piscsi_u32[2] + i);
write(d->fd, &c, 1);
}
}
break;
}
case PISCSI_CMD_DRVNUM:
- //printf("%d ", val);
- if (val % 10 != 0)
+ if (val % 10 != 0) {
piscsi_cur_drive = 255;
+ }
else
piscsi_cur_drive = val / 10;
- if (piscsi_cur_drive > NUM_UNITS)
+ if (piscsi_cur_drive > NUM_UNITS) {
piscsi_cur_drive = 255;
-
- if (piscsi_cur_drive != 255)
+ }
+ if (piscsi_cur_drive != 255) {
DEBUG("[PISCSI] (%s) Drive number set to %d (%d)\n", op_type_names[type], piscsi_cur_drive, val);
+ }
+ break;
+ case PISCSI_CMD_DRVNUMX:
+ piscsi_cur_drive = val;
+ DEBUG("[PISCSI] DRVNUMX: %d.\n", val);
break;
case PISCSI_CMD_DEBUGME:
piscsi_debugme(val);
break;
- case PISCSI_CMD_DRIVER: {
+ case PISCSI_CMD_DRIVER:
DEBUG("[PISCSI] Driver copy/patch called, destination address %.8X.\n", val);
- int r = get_mapped_item_by_address(cfg, val);
+ r = get_mapped_item_by_address(cfg, val);
if (r != -1) {
uint32_t addr = val - cfg->map_offset[r];
uint8_t *dst_data = cfg->map_data[r];
memcpy(dst_data + addr, piscsi_rom_ptr + PISCSI_DRIVER_OFFSET, 0x4000 - PISCSI_DRIVER_OFFSET);
piscsi_hinfo.base_offset = val;
-
+
reloc_hunks(piscsi_hreloc, dst_data + addr, &piscsi_hinfo);
#define PUTNODELONG(val) *(uint32_t *)&dst_data[p_offs] = htobe32(val); p_offs += 4;
skip_disk:;
}
}
-
+
break;
- }
case PISCSI_CMD_NEXTPART:
DEBUG("[PISCSI] Switch partition %d -> %d\n", rom_cur_partition, rom_cur_partition + 1);
rom_cur_partition++;
uint32_t addr = val - cfg->map_offset[r];
struct DeviceNode *node = (struct DeviceNode *)(cfg->map_data[r] + addr);
char *dosID = (char *)&rom_partition_dostype[rom_cur_partition];
+#ifdef PISCSI_DEBUG
+#endif
DEBUG("[PISCSI] Partition DOSType is %c%c%c/%d\n", dosID[0], dosID[1], dosID[2], dosID[3]);
for (i = 0; i < piscsi_num_fs; i++) {
if (rom_partition_dostype[rom_cur_partition] == filesystems[i].FS_ID) {
- node->dn_SegList = htobe32(filesystems[i].handler);
+ node->dn_SegList = htobe32((filesystems[i].handler >> 2));
+ node->dn_GlobalVec = 0xFFFFFFFF;
goto fs_found;
}
}
- DEBUG("[!!!PISCSI] Found no handler for file system!\n");
+ printf("[!!!PISCSI] Found no handler for file system %c%c%c/%d\n", dosID[0], dosID[1], dosID[2], dosID[3]);
fs_found:;
- DEBUG("[FS-HANDLER] Next: %d Type: %d\n", BE(node->dn_Next), BE(node->dn_Type));
+ DEBUG("[FS-HANDLER] Next: %d Type: %.8X\n", BE(node->dn_Next), BE(node->dn_Type));
DEBUG("[FS-HANDLER] Task: %d Lock: %d\n", BE(node->dn_Task), BE(node->dn_Lock));
DEBUG("[FS-HANDLER] Handler: %d Stacksize: %d\n", BE((uint32_t)node->dn_Handler), BE(node->dn_StackSize));
DEBUG("[FS-HANDLER] Priority: %d Startup: %d\n", BE((uint32_t)node->dn_Priority), BE(node->dn_Startup));
- DEBUG("[FS-HANDLER] SegList: %d GlobalVec: %d\n", BE((uint32_t)node->dn_SegList), BE(node->dn_GlobalVec));
+ DEBUG("[FS-HANDLER] SegList: %.8X GlobalVec: %d\n", BE((uint32_t)node->dn_SegList), BE(node->dn_GlobalVec));
DEBUG("[PISCSI] Handler for partition %.8X set to %.8X (%.8X).\n", BE((uint32_t)node->dn_Name), filesystems[i].FS_ID, filesystems[i].handler);
}
break;
}
return 0;
}
-
+
switch (addr & 0xFFFF) {
case PISCSI_CMD_ADDR1: case PISCSI_CMD_ADDR2: case PISCSI_CMD_ADDR3: case PISCSI_CMD_ADDR4: {
int i = ((addr & 0xFFFF) - PISCSI_CMD_ADDR1) / 4;
return devs[piscsi_cur_drive].s;
break;
case PISCSI_CMD_BLOCKS: {
- uint32_t blox = devs[piscsi_cur_drive].fs / 512;
- DEBUG("[PISCSI] %s Read from BLOCKS %d: %d\n", op_type_names[type], piscsi_cur_drive, (uint32_t)(devs[piscsi_cur_drive].fs / 512));
+ uint32_t blox = devs[piscsi_cur_drive].fs / devs[piscsi_cur_drive].block_size;
+ DEBUG("[PISCSI] %s Read from BLOCKS %d: %d\n", op_type_names[type], piscsi_cur_drive, (uint32_t)(devs[piscsi_cur_drive].fs / devs[piscsi_cur_drive].block_size));
DEBUG("fs: %lld (%d)\n", devs[piscsi_cur_drive].fs, blox);
return blox;
break;
case PISCSI_CMD_FSSIZE:
DEBUG("[PISCSI] Get alloc size of loaded file system: %d\n", filesystems[rom_cur_fs].h_info.alloc_size);
return filesystems[rom_cur_fs].h_info.alloc_size;
+ case PISCSI_CMD_BLOCKSIZE:
+ DEBUG("[PISCSI] Get block size of drive %d: %d\n", piscsi_cur_drive, devs[piscsi_cur_drive].block_size);
+ return devs[piscsi_cur_drive].block_size;
default:
DEBUG("[!!!PISCSI] WARN: Unhandled %s register read from %.8X\n", op_type_names[type], addr);
break;