#include "../_sdk/io.h"
#include "../_sdk/str.h"
VAR BYTE psystrk[0x900];
#define BUFSECTORS 0x10
#define BUFSIZE (UINT)(BUFSECTORS*0x100)
VAR BYTE buf[BUFSIZE];
FUNC UINT copybody(UINT from, UINT to, BYTE count) // TODO ъюяшЁютрэшх эр Єю цх ьхёЄю эх фхырЄ№, эю фы ¤Єюую эрфю т√ўшёышЄ№ ёыхфє■∙шщ ёхъЄюЁ!
{
VAR UINT nextrdsector;
VAR UINT nextwrsector;
VAR BYTE wrsectors;
IF (from==to) {
nextwrsector = ((to&0xff00) >> 4) + (UINT)((BYTE)to&0x0f) + (UINT)count;
nextwrsector = ((nextwrsector << 4)&0xff00) + (UINT)((BYTE)nextwrsector&0x0f);
}ELSE {
nextrdsector = from;
nextwrsector = to;
WHILE (count > 0x00) {
IF (count >= BUFSECTORS) {
wrsectors = BUFSECTORS;
}ELSE {
wrsectors = count;
};
nextrdsector = readsectors((PBYTE)buf, nextrdsector, wrsectors);
nextwrsector = writesectors((PBYTE)buf, nextwrsector, wrsectors);
count = count - wrsectors;
};
};
RETURN nextwrsector;
}
PROC movedisk()
{
VAR UINT wasfreeplace; //
VAR UINT freeplace; //ъєфр яш°хь Єхыю Їрщыр
VAR PBYTE curfiledesc; //юЄъєфр ўшЄрхь фхёъЁшяЄюЁ
VAR PBYTE freefiledesc; //ъєфр яш°хь фхёъЁшяЄюЁ
VAR UINT nfreesectors;
VAR BYTE nfiles;
VAR BYTE count;
//ўшЄрхь ёшёЄхьэє■ фюЁюцъє
readsectors((PBYTE)psystrk, 0x0000, 0x09);
nfiles = 0x00; //psystrk[0x8e4];
nfreesectors = *(PUINT)(&psystrk[0x8e5]);
//эрўрыю ётюсюфэюую ьхёЄр = 0x0100
freeplace = 0x0100;
freefiledesc = (PBYTE)psystrk;
//Єхъє∙шщ Їрщыют√щ фхёъЁшяЄюЁ = &psystrk[0x0000]
curfiledesc = (PBYTE)psystrk;
loop:
//ш∙хь эхєфры╕ээ√щ Їрщы
IF (*(PBYTE)curfiledesc == 0x00) goto quit;
count = curfiledesc[0x0d]; //ЁрчьхЁ т ёхъЄюЁрї
IF (*(PBYTE)curfiledesc == 0x01) {
nfreesectors = nfreesectors + (UINT)count;
goto next;
};
//яхЁхсЁрё√трхь Єхыю Їрщыр т эрўрыю яєёЄюую ьхёЄр
wasfreeplace = freeplace;
freeplace = copybody(*(PUINT)(&curfiledesc[0x0e]), freeplace, count);
//ъюЁЁхъЄшЁєхь фшЁхъЄюЁш■
memcopy(curfiledesc, 14, freefiledesc);
POKE *(PUINT)(&freefiledesc[0x0e]) = wasfreeplace;
freefiledesc = &freefiledesc[16];
INC nfiles;
next:
//яхЁхїюфшь ъ ёыхфє■∙хьє фхъёЁшяЄюЁє
curfiledesc = &curfiledesc[16];
//яютЄюЁ хь фю 0
goto loop;
quit:
WHILE (freefiledesc[0] != 0x00) {
freefiledesc[0] = 0x00; //end of directory
freefiledesc = &freefiledesc[16];
};
//ъюЁЁхъЄшЁєхь ёшёЄхьэ√щ ёхъЄюЁ
POKE *(PUINT)(&psystrk[0x8e1]) = freeplace;
psystrk[0x8e4] = nfiles; //number of files
POKE *(PUINT)(&psystrk[0x8e5]) = nfreesectors;
psystrk[0x8f4] = 0x00; //number of erased files
//яш°хь ёшёЄхьэє■ фюЁюцъє
writesectors((PBYTE)psystrk, 0x0000, 0x09);
}