Skip to content

Commit

Permalink
Added support of UDI, TRD, SCL, FDI, TD0, FDD formats via built-in trx2x
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Prilutskiy authored and Artem Prilutskiy committed Sep 17, 2020
1 parent aff155a commit 2162f10
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "trx2x"]
path = trx2x
url = https://github.com/atsidaev/trx2x.git
13 changes: 12 additions & 1 deletion rs232mnt/Makefile
@@ -1,10 +1,21 @@
TRX2X_FOLDER = ../trx2x

LIBRARIES := \
stdc++

DIRECTORIES := \
$(TRX2X_FOLDER)

OBJECTS = \
$(TRX2X_FOLDER)/DiskImage.o \
disk.o \
port.o \
fifo.o \
rs232mnt.o

FLAGS := \
-g -rdynamic -fno-omit-frame-pointer -O2 -MMD -fPIC
-g -rdynamic -fno-omit-frame-pointer -O2 -MMD -fPIC \
$(foreach directory, $(DIRECTORIES), -I$(directory))

LIBS := \
$(foreach library, $(LIBRARIES), -l$(library))
Expand Down
50 changes: 50 additions & 0 deletions rs232mnt/disk.cpp
@@ -0,0 +1,50 @@
#include <stdint.h>
#include <string.h>

#include "DiskImage.h"

bool LoadDiskImage(const char* path, uint8_t* buffer)
{
TDiskImage image;
VGFIND_SECTOR data;

int side;
int track;
int sector;

image.AddBOOT = false;
image.Open(const_cast<char*>(path), true);

if (image.DiskPresent)
{
for (track = 0; track <= image.MaxTrack; track ++)
{
for (side = 0; side <= image.MaxSide; side ++)
{
for (sector = 1; sector <= 16; sector ++)
{
if (image.FindSector(track, side, sector, &data))
{
if (!data.CRCOK ||
!data.vgfa.CRCOK ||
(data.SectorLength != 256))
{
// Unsupported data format or CRC
return false;
}

memcpy(buffer, data.SectorPointer, data.SectorLength);
buffer += data.SectorLength;

continue;
}

memset(buffer, '*', 256);
buffer += 256;
}
}
}
}

return image.DiskPresent;
}
9 changes: 1 addition & 8 deletions rs232mnt/rs232mnt.cpp
Expand Up @@ -114,7 +114,6 @@ int _tmain(int argc, _TCHAR* argv[])
SECT sect;

DWORD dwRead, dwWrite;
FILE *f;
STATE state = ST_IDLE;

printf("\n");
Expand All @@ -129,17 +128,11 @@ int _tmain(int argc, _TCHAR* argv[])
{
if (trd[i])
{
if (!(f = fopen(trd[i], "rb")))
if (!LoadDiskImage(trd[i], img[i]))
{
printf("Can't open: %s\n", trd[i]);
return 2;
}
else
{
printf("%s opened successfully\n", trd[i]);
fread(img[i], 1, TRD_SZ, f);
fclose(f);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions rs232mnt/stdafx.h
Expand Up @@ -25,3 +25,5 @@ extern "C"
void ReadFile(int handle, void* buffer, uint32_t size, uint32_t* count, void* unused);
void WriteFile(int handle, void* buffer, uint32_t size, uint32_t* count, void* unused);
}

bool LoadDiskImage(const char* path, uint8_t* buffer);
1 change: 1 addition & 0 deletions trx2x
Submodule trx2x added at fbe867

0 comments on commit 2162f10

Please sign in to comment.