diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..011aa0a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "trx2x"] + path = trx2x + url = https://github.com/atsidaev/trx2x.git diff --git a/rs232mnt/Makefile b/rs232mnt/Makefile index b63a3d2..15927ae 100644 --- a/rs232mnt/Makefile +++ b/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)) diff --git a/rs232mnt/disk.cpp b/rs232mnt/disk.cpp new file mode 100644 index 0000000..d162ea6 --- /dev/null +++ b/rs232mnt/disk.cpp @@ -0,0 +1,50 @@ +#include +#include + +#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(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; +} \ No newline at end of file diff --git a/rs232mnt/rs232mnt.cpp b/rs232mnt/rs232mnt.cpp index aa96eba..f6a9666 100644 --- a/rs232mnt/rs232mnt.cpp +++ b/rs232mnt/rs232mnt.cpp @@ -114,7 +114,6 @@ int _tmain(int argc, _TCHAR* argv[]) SECT sect; DWORD dwRead, dwWrite; - FILE *f; STATE state = ST_IDLE; printf("\n"); @@ -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); - } } } diff --git a/rs232mnt/stdafx.h b/rs232mnt/stdafx.h index 8702a22..7e85cca 100644 --- a/rs232mnt/stdafx.h +++ b/rs232mnt/stdafx.h @@ -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); diff --git a/trx2x b/trx2x new file mode 160000 index 0000000..fbe8676 --- /dev/null +++ b/trx2x @@ -0,0 +1 @@ +Subproject commit fbe8676bac99e04c2e8bae3c11c449ea40b0f3e7