3 * coded by Ketmar // Invisible Vector
4 * Understanding is not required. Only obedience.
6 * This program is free software. It comes without any warranty, to
7 * the extent permitted by applicable law. You can redistribute it
8 * and/or modify it under the terms of the Do What The Fuck You Want
9 * To Public License, Version 2, as published by Sam Hocevar. See
10 * http://sam.zoy.org/wtfpl/COPYING for more details.
13 #include "dskfs_all.h"
16 //==========================================================================
20 //==========================================================================
21 int dskLoadTRD (Floppy
*flp
, FILE *fl
) {
22 uint8_t trkBuf
[FLP_TRD_TRACK_SIZE
], b
;
23 if (fl
== NULL
) return FLPERR_SHIT
;
24 if (fseek(fl
, 0x8e7, SEEK_CUR
) != 0) {
25 libfdcMsg(LIBFDC_MSG_ERROR
, "cannot seek to TRD header");
28 if (fread(&b
, 1, 1, fl
) != 1) {
29 libfdcMsg(LIBFDC_MSG_ERROR
, "cannot read TRD header signature byte");
33 // TRD signature byte not found
34 libfdcMsg(LIBFDC_MSG_ERROR
, "TRD signature byte not found");
37 if (fseek(fl
, -0x8e8, SEEK_CUR
) != 0) {
38 libfdcMsg(LIBFDC_MSG_ERROR
, "cannot seek to TRD start");
41 if (flpFormatTRD(flp
) != FLPERR_OK
) {
42 libfdcMsg(LIBFDC_MSG_ERROR
, "cannot format emulated floppy");
45 //FIXME: TODO: single-sided, 43
46 for (int i
= 0; i
< FLP_MAX_TRACKS_80
; ++i
) {
47 size_t rd
= fread(trkBuf
, 1, FLP_TRD_TRACK_SIZE
, fl
);
57 if (rd
< FLP_TRD_TRACK_SIZE
) memset(trkBuf
+rd
, 0, FLP_TRD_TRACK_SIZE
-rd
);
58 if (flpFormatTRDTrack(flp
, i
, trkBuf
, sizeof(trkBuf
)) != FLPERR_OK
) return FLPERR_SHIT
;
59 if (rd
< FLP_TRD_TRACK_SIZE
) break; // no more bytes in file anyway
67 //==========================================================================
71 //==========================================================================
72 int dskSaveTRD (Floppy
*flp
, FILE *fl
) {
73 if (!flp
|| !flp
->insert
) return FLPERR_SHIT
;
74 if (fl
== NULL
) return FLPERR_SHIT
;
75 for (int trk
= 0; trk
< 80*2; ++trk
) {
76 for (int sec
= 1; sec
< 17; ++sec
) {
78 if (flpGetSectorData(flp
, trk
, sec
, sdata
, 256) != FLPERR_OK
) return FLPERR_SHIT
;
79 if (fwrite(sdata
, 256, 1, fl
) != 1) return FLPERR_SHIT
;