//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Carpet_F.h" #include "DiskAccess.h" #include "Exception.h" #include "FileManager_F.h" #include "Main.h" #include "MainImage.h" #include "RWDisk.h" #include "StatusProgress.h" #include "undo.h" #include "UserColor_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPSpin" #pragma resource "*.dfm" //--------------------------------------------------------------------------- TCarpetForm *CarpetForm; #define IDS_FCAPTION StringTable[0] #define IDS_TEXTUREFILL StringTable[1] #define IDS_AREAFILL StringTable[2] #define IDS_REGAUGE StringTable[3] #define IDS_TABLEVIEW StringTable[4] #define IDS_NONE StringTable[5] //--------------------------------------------------------------------------- __fastcall TCarpetForm::TCarpetForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::sbFunctionClick(TObject *Sender) { View(); } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::sbFileClick(TObject *Sender) { TFileManagerForm *Form = NULL; if ((Form = new TFileManagerForm(this)) == NULL) goto fail; Form->Extension = 4; // Carpet ¸¦ fileManager¿¡°Ô ¾Ë¸². Form->FilterComboBox->Filter = "Texpro Carpet File (*.cpt)|*.cpt"; Form->OnRead = CPTOnRead; Form->OnFileName = CPTOnFileName; Form->OnSave = CPTOnSave; Form->ShowModal(); delete Form; return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::sbNewClick(TObject *Sender) { MainImageForm->ClearData(); stName->Caption = "NONE"; ScrollBar->Max = 0; ScrollBar->Position = 0; ScrollBar->Enabled = false; DrawImage(); ButtonStatus(); } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::sbDeleteClick(TObject *Sender) { if (currentIndex < MainImageForm->CarpetTexture->Count) { CTEXTURE *ct = (CTEXTURE *) MainImageForm->CarpetTexture->Items[currentIndex]; MainImageForm->CarpetTexture->Remove(ct); delete[] ct->map; delete ct; if (MainImageForm->CarpetTexture->Count == 0) { stName->Caption = "NONE"; ScrollBar->Max = 0; ScrollBar->Position = 0; ScrollBar->Enabled = false; } else { ScrollBar->Max--; ScrollBar->Position--; } if (currentIndex) currentIndex--; else currentIndex = 0; DrawImage(); ButtonStatus(); } } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::ScrollBarScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { currentIndex = ScrollPos; DrawImage(); } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::sbWindowRunClick(TObject *Sender) { if (MainImageForm->CarpetArea.IsArea) { MainImageForm->CarpetArea.Width = spEditW->Value; MainImageForm->CarpetArea.Height = spEditH->Value; } ButtonStatus(); ::RepaintImage(); } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::stWindowClick(TObject *Sender) { if (MainImageForm->CarpetArea.IsArea) { MainImageForm->CarpetArea.IsArea = false; stWindow->Caption = "OFF"; } else { MainImageForm->CarpetArea.IsArea = true; stWindow->Caption = "ON"; } } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::sbRegaugeRunClick(TObject *Sender) { int sy, x, y, w, h, nw, nh, tx, ty; Byte *IP, *DP; double row, col; TTexpiaBitmap *Bmp = MainImageForm->iMainImage->Bitmap; TPMemoryArea *TP = NULL; MainImageForm->UndoSave(UK_ALL, Rect(0, 0, Bmp->Width, Bmp->Height)); sy = Bmp->Height - MainImageForm->CarpetArea.Height; w = MainImageForm->CarpetArea.Width; h = MainImageForm->CarpetArea.Height; nw = spReEditW->Value; nh = spReEditH->Value; row = (double) nh / h; col = (double) nw / w; TP = new TPMemoryArea(nw, nh); if (!TP) goto fail; if (!Bmp->StartScanLine()) goto fail; TP->lock(); for (y = 0; y < nh; y++) { ty = sy + (int)(y / row); if (ty < 0 || ty >= Bmp->Height) continue; IP = Bmp->GetScanLine(ty); DP = TP->pointer(0, y); for (x = 0; x < nw; x++, DP++) { tx = (int)(x /col); if (tx < 0 || tx >= Bmp->Width) continue; *DP = IP[tx]; } } Bmp->StopScanLine(); Bmp->FillRect(Rect(0, sy, w, sy + h), PaletteForm->DIB256Palette->GetBGCOLORREF(Bmp->BitsPerPixel)); Bmp->LoadFromMemory(TP->pointer(0, 0), nw, Rect(0, Bmp->Height - nh, nw, Bmp->Height)); TP->unlock(); ::doDestroy(TP); MainImageForm->CarpetArea.Width = nw; MainImageForm->CarpetArea.Height = nh; ::RepaintImage(); return; fail : if (TP) delete TP; Bmp->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::spEditClick(TObject *Sender) { ((TPSpinEdit *) Sender)->SetFocus(); ((TPSpinEdit *) Sender)->SelectAll(); } //--------------------------------------------------------------------------- /// Private Method //--------------------------------------------------------------------------- void __fastcall TCarpetForm::ReadIni() { int count, i; AnsiString str, name; CTEXTURE *ct; TIniFile* Ini = NULL; Ini = new TIniFile(DirectoryItem+"\\Carpet.ini"); if (!Ini) goto fail; count = Ini->ReadInteger("Count", "cnt", 0); for (i = 0; i < count; i++) { str = Format("%d", OPENARRAY(TVarRec, (i))); name = Ini->ReadString(str, "name", ct->GetName()); ct = new CTEXTURE; if (!ct) goto fail; if (CarpetTableForm->CompareData(name, ct)) { MainImageForm->CarpetTexture->Add(ct); } else { delete ct; } } delete Ini; return; fail : if(Ini) delete Ini; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::WriteIni() { int count, i; AnsiString str; CTEXTURE *ct; TIniFile* Ini = new TIniFile(DirectoryItem+"\\Carpet.ini"); if (!Ini) goto fail; count = Ini->ReadInteger("Count", "cnt", 0); for (i = 0; iEraseSection(str); } Ini->WriteInteger("Count", "cnt", MainImageForm->CarpetTexture->Count); count = MainImageForm->CarpetTexture->Count; for (i = 0; i < count; i++) { ct = (CTEXTURE *) MainImageForm->CarpetTexture->Items[i]; str = Format("%d", OPENARRAY(TVarRec, (i))); Ini->WriteString(str, "name", ct->GetName()); } delete Ini; return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::DrawImage() { if (currentIndex < MainImageForm->CarpetTexture->Count) { CTEXTURE *ct = (CTEXTURE *) MainImageForm->CarpetTexture->Items[currentIndex]; ct->Draw(Bitmap); Image->Canvas->Draw(0, 0, Bitmap); stName->Caption = ct->GetName(); } else { Image->Canvas->Brush->Color = clWhite; Image->Canvas->FillRect(Rect(0, 0, Image->Width, Image->Height)); } } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::ButtonStatus() { if (MainImageForm->CarpetTexture->Count > 0) { sbTextureFill->Enabled = true; sbAreaFill->Enabled = true; } else { sbTextureFill->Enabled = false; sbAreaFill->Enabled = false; } if (MainImageForm->CarpetArea.IsArea) { sbTableView->Enabled = true; sbRegauge->Enabled = true; } else { sbTableView->Enabled = false; sbTextureFill->Enabled = false; sbAreaFill->Enabled = false; sbRegauge->Enabled = false; } } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::View() { if (sbWindow->Down) { WindowPanel->BringToFront(); if (MainImageForm->CarpetArea.IsArea) stWindow->Caption = "ON"; else stWindow->Caption = "OFF"; spEditW->Value = MainImageForm->CarpetArea.Width; spEditH->Value = MainImageForm->CarpetArea.Height; } else if (sbRegauge->Down) { RegaugePanel->BringToFront(); spReEditW->Value = MainImageForm->CarpetArea.Width; spReEditH->Value = MainImageForm->CarpetArea.Height; lbMax->Caption = "Max : " + Format(" %d x %d", OPENARRAY(TVarRec, ((int)spReEditW->Value, (int)spReEditH->Value))); } else { FillPanel->BringToFront(); DrawImage(); } CarpetTableForm->Visible = sbTableView->Down; if (MainImageForm->CarpetTexture->Count) ScrollBar->Max = MainImageForm->CarpetTexture->Count - 1; ScrollBar->Enabled = MainImageForm->CarpetTexture->Count ? true : false; } //--------------------------------------------------------------------------- bool __fastcall TCarpetForm::SearchSameThing(CTEXTURE *sct) { CTEXTURE *dct; AnsiString name = sct->GetName(); int i, cnt = MainImageForm->CarpetTexture->Count; for (i = 0; i < cnt; i++) { dct = (CTEXTURE *) MainImageForm->CarpetTexture->Items[i]; if (name == dct->GetName()) return true; } return false; } //--------------------------------------------------------------------------- bool __fastcall TCarpetForm::FillRead(Byte *p, int x) { return *(p+x) == FillColor; } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::FillSave(Byte *p, int x) { *(p+x) = 0xFF; } //--------------------------------------------------------------------------- Byte __fastcall TCarpetForm::ColorSearch(CTEXTURE *dct, int ex, int ey) { if (ex >= dct->lx) ex = ex % dct->lx; if (ey >= dct->ly) ey = ey % dct->ly; return *(dct->map + (ey * dct->lx + ex)); } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::TextureFill(int X, int Y) { TRect rect; CTEXTURE *dct; int sx, sy, ex, ey, x, y; Byte *IP; TCursor Cursor = Screen->Cursor; Screen->Cursor = crHourGlass; TTexpiaBitmap *Bmp = MainImageForm->iMainImage->Bitmap; Bmp->FloodFill(First, FillRead, FillSave, rect); dct = (CTEXTURE *) MainImageForm->CarpetTexture->Items[currentIndex]; if (rect.Left % 2) First.x = rect.Left + 1; else First.x = rect.Left; if (rect.Top % 2) First.y = rect.Top + 1; else First.y = rect.Top; if (rect.Left <= First.x) { sx = dct->lx + (rect.Left - First.x) % dct->lx; if (sx >= dct->lx) sx = 0; } else { sx = (rect.Left - First.x) % dct->lx; } if (rect.Top <= First.y) { sy = dct->ly + (rect.Top-First.y) % dct->ly; if (sy >= dct->ly) sy = 0; } else { sy = (rect.Top - First.y) % dct->ly; } ey = sy; if (!Bmp->StartScanLine()) goto fail; for (y = rect.Top; y < rect.Bottom; y++) { IP = Bmp->GetScanLine(y) + rect.Left; ex = sx; for (x = rect.Left; x < rect.Right; x++, IP++) { if (*IP == 0xFF) { *IP = ColorSearch(dct, ex, ey); } ex++; if (ex >= dct->lx) ex = 0; } ey++; if (ey >= dct->ly) ey = 0; Bmp->PutScanLine(y); } Bmp->StopScanLine(); Screen->Cursor = Cursor; return; fail : Bmp->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::AreaFill(int X, int Y) { CTEXTURE *dct; Byte *IP; short x, y, mx, my, sy, w, h; TCursor Cursor = Screen->Cursor; Screen->Cursor = crHourGlass; TTexpiaBitmap *Bmp = MainImageForm->iMainImage->Bitmap; dct = (CTEXTURE *) MainImageForm->CarpetTexture->Items[currentIndex]; sy = Bmp->Height - MainImageForm->CarpetArea.Height; w = MainImageForm->CarpetArea.Width; h = MainImageForm->CarpetArea.Height; if (!Bmp->StartScanLine()) goto fail; for (y = 0; y < h; y++) { IP = Bmp->GetScanLine(y + sy); my = y % dct->ly; for (x = 0; x < w; x++, IP++) { mx = x % dct->lx; if (*IP == FillColor) { *IP = *(dct->map + (my * dct->lx + mx)); } } Bmp->PutScanLine(y + sy); } Bmp->StopScanLine(); Screen->Cursor = Cursor; return; fail : Bmp->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- TPException __fastcall TCarpetForm::CPTOnRead(TFMReadParameter rp) { TCursor cur; TMainImageForm *Child = NULL; TPException ec = EC_NONE; cur = Screen->Cursor; Screen->Cursor = crHourGlass; if ((Child = new TMainImageForm(Application))==NULL) { ec = EC_FORM_NOT_CREATE; goto fail; } if ((ec = Child->InitFormFile(rp.DirName, rp.FileName, 7, rp.bpp)) != EC_NONE) goto fail; Screen->Cursor = cur; View(); return EC_NONE; fail: if (Child) delete Child; Screen->Cursor = cur; return ec; } //--------------------------------------------------------------------------- AnsiString __fastcall TCarpetForm::CPTOnFileName(AnsiString FileName, TGraphicFileFormat ExtIndex) { PChar s = AnsiStrScan(FileName.c_str(), '.'); if (s == NULL) { AnsiString fn = FileName + ".cpt"; return fn; } else { return FileName; } } //--------------------------------------------------------------------------- TPException __fastcall TCarpetForm::CPTOnSave(AnsiString DirName, AnsiString FileName, TGraphicFileFormat ExtIndex, TCompressMethod cm) { TPException ec; if ((ec = MainImageForm->SaveToCarpetFile(DirName, FileName, cm)) != EC_NONE) return ec; MainImageForm->DirName = DirName; MainImageForm->FileName = FileName; MainImageForm->SetCaption(); return EC_NONE; } //--------------------------------------------------------------------------- /// Public Method //--------------------------------------------------------------------------- void __fastcall TCarpetForm::InitForm() { ParentHeight = Parent->Height+20; ClientHeight = 260; Parent->Height = ParentHeight+ClientHeight; MainImageForm->iMainImage->Bitmap->GetColors(0, 256, rgb); CarpetTableForm = new TCarpetTableForm(MainForm); if (!CarpetTableForm) goto fail; CarpetTableForm->Parent = MainForm; CarpetTableForm->InitForm(rgb); CarpetTableForm->OnAccept = AcceptData; CarpetTableForm->Visible = false; Bitmap = new Graphics::TBitmap; if (!Bitmap) goto fail; Bitmap->PixelFormat = pf8bit; Bitmap->Width = Image->Width; Bitmap->Height = Image->Height; SetDIBColorTable(Bitmap->Canvas->Handle, 0, 256, rgb); spEditW->MaxValue = MainImageForm->iMainImage->Bitmap->Width; spEditH->MaxValue = MainImageForm->iMainImage->Bitmap->Height; spReEditW->MaxValue = MainImageForm->iMainImage->Bitmap->Width; spReEditH->MaxValue = MainImageForm->iMainImage->Bitmap->Height; ReadIni(); currentIndex = 0; DrawImage(); ButtonStatus(); View(); return; fail : if (CarpetTableForm) delete CarpetTableForm; if (Bitmap) delete Bitmap; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::ExitForm() { WriteIni(); MainImageForm->ClearData(); delete Bitmap; Bitmap = NULL; delete CarpetTableForm; CarpetTableForm = NULL; } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::AcceptData(CTEXTURE *sct) { CTEXTURE *dct = NULL; int size; if (SearchSameThing(sct)) return; dct = new CTEXTURE; if (!dct) goto fail; strcpy(dct->name, sct->name); dct->lx = sct->lx; dct->ly = sct->ly; size = dct->lx * dct->ly; dct->map = new Byte[size]; if (!dct->map) goto fail; memcpy(dct->map, sct->map, size * sizeof (Byte)); MainImageForm->CarpetTexture->Add(dct); currentIndex = MainImageForm->CarpetTexture->Count - 1; ScrollBar->Enabled = true; ScrollBar->Max = currentIndex; ScrollBar->Position = currentIndex; DrawImage(); ButtonStatus(); return; fail : if (dct) delete dct; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::iMainImageMouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width , MainImageForm->iMainImage->Bitmap->Height)); First = Point(X, Y); FillColor = MainImageForm->iMainImage->Bitmap->GetPixelColor(X, Y); if (sbTextureFill->Down) { TextureFill(X, Y); } else if (sbAreaFill->Down) { AreaFill(X, Y); } ::RepaintImage(); } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::ReDrawTexture() { RGBQUAD rgbquad[256]; MainImageForm->Palette->ToRGBQUAD(rgbquad, 256); // exitform½Ã repaintcolor ¿¡¼­ È£ÃâÇϱ⠶«½Ã if (CarpetTableForm && Bitmap) { CarpetTableForm->ReDrawGrid(rgbquad); SetDIBColorTable(Bitmap->Canvas->Handle, 0, 256, rgbquad); DrawImage(); } } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::FormCreate(TObject *Sender) { TIniFile *IniFile; //=================================================================== StringTable.Create(DirectoryBin+"\\Carpet", Language, "Carpet"); SetSmallFont(Font); SetSmallFont(stWindow->Font); SetSmallFont(lbMax->Font); Caption = IDS_FCAPTION; sbTextureFill->Caption = IDS_TEXTUREFILL; sbWindow->Caption = IDS_COMMON_WINDOW; sbAreaFill->Caption = IDS_AREAFILL; sbTableView->Caption = IDS_TABLEVIEW; sbRegauge->Caption = IDS_REGAUGE; sbFile->Caption = IDS_COMMON_FILE; stName->Caption = IDS_NONE; sbNew->Caption = IDS_COMMON_NEW; sbDelete->Caption = IDS_COMMON_DELETE; //=================================================================== } //--------------------------------------------------------------------------- #define TRACKS 80 #define HEADS 2 #define SECTORS 15 #define BYTES 512 #define NEEDLE 1356 //--------------------------------------------------------------------------- int __fastcall TCarpetForm::read_disk_buf(char *diskmap, TTexpiaBitmap *source) { BYTE c = 0, *map, *ip, comp[4] = { 0xC0, 0x30, 0x0C, 0x03 }; short i, j, pcl, clutch, lx, ly, total, pcl_cnt, clutch_cnt; total = 515; pcl_cnt = 170; clutch_cnt = 339; map = diskmap + (HEADS * SECTORS * BYTES); if (*map != 0x59 || *(map + 1) != 0x30) return -1; source->FillRect(Rect(0, 0, source->Width, source->Height), PaletteForm->DIB256Palette->GetBGCOLORREF(8)); map = diskmap + (HEADS * SECTORS * BYTES) + 14; lx = NEEDLE; ly = (*map << 8) | (*(map + 1)); if (lx > source->Width || ly > source->Height) return -1; MainImageForm->CarpetArea.Width = lx; MainImageForm->CarpetArea.Height = ly; map = diskmap + (HEADS * SECTORS * BYTES) + 0x100; source->StartScanLine(); for (i = 1; i <= ly; i++, map += total) { ip = source->GetScanLine(source->Height - i); for (j = 0; j < NEEDLE; j++) { if ((*(map + j / 8)) & (0x01 << (7 - j % 8))) pcl = 1; else pcl = 0; clutch = ((*(map + j / 4 + pcl_cnt)) & comp[j % 4]) >> ((3 - j % 4) * 2); if (pcl == 0) { switch (clutch) { case 0 : c = 1; break; case 1 : c = 3; break; case 2 : c = 2; break; case 3 : c = 7; break; } } else { switch (clutch) { case 0 : c = 4; break; case 1 : c = 6; break; case 2 : c = 5; break; } } ip[j] = c + 1; } source->PutScanLine(source->Height - i); } source->StopScanLine(); return 0; } //--------------------------------------------------------------------------- int __fastcall TCarpetForm::carpet_disk_read(int drive) { TCursor cursor; int track, head, sector; char *diskmap = NULL; TDiskAccess da('A' + drive); TPException ec = EC_NONE; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; diskmap = (BYTE *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1228800); sector = 0; StatusProgress->Maximum = TRACKS; for (track = 0; track < TRACKS; track++) { StatusProgress->Position = track; if (da.Read(sector, HEADS * SECTORS, diskmap + sector * BYTES) < 0) { ec = EC_FILE_NOT_READ; goto fail; } sector += HEADS * SECTORS; } StatusProgress->End(); if (read_disk_buf(diskmap, MainImageForm->iMainImage->Bitmap) < 0) { ec = EC_BIG_SIZE; goto fail; } HeapFree(GetProcessHeap(), 0, diskmap); Screen->Cursor = cursor; MainImageForm->iMainImage->Repaint(); return 0; fail: if (diskmap) HeapFree(GetProcessHeap(), 0, diskmap); Screen->Cursor = cursor; EXCEPTION_MESSAGE_OK(ec); return -1; } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::make_disk_buf(char *diskmap, TTexpiaBitmap *source) { short i, j, k, n, total, pcl_cnt, clutch_cnt; BYTE x, pcl=0, clutch=0; BYTE *map, *ip; BYTE buf[14] = { 0x59, 0x30, 0x00, 0x01, 0x00, 0x01, 0x05, 0x4c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01 }; BYTE comp[4] = { 0x3F, 0xCF, 0xF3, 0xFC }; memset(diskmap, 0xF6, TRACKS * HEADS * SECTORS * BYTES); map = diskmap + (HEADS * SECTORS * BYTES); memcpy(map, buf, 14); map[14] = MainImageForm->CarpetArea.Height / 256; map[15] = MainImageForm->CarpetArea.Height % 256; map += 0x100; pcl_cnt = 170; clutch_cnt = 339; total = pcl_cnt + clutch_cnt + 6; // 515 source->StartScanLine(); for (i = n = 1; i <= MainImageForm->CarpetArea.Height; i++, n++, map += total) { ip = source->GetScanLine(source->Height - i); memset(map, 0, pcl_cnt); memset(map + pcl_cnt, 0xFF, clutch_cnt); for (j = 0; j < NEEDLE; j++) { if (j < MainImageForm->CarpetArea.Width) { switch (*ip - 1) { case 1 : pcl = 0; clutch = 0; break; // H/L case 2 : pcl = 0; clutch = 2; break; // M/L case 3 : pcl = 0; clutch = 1; break; // L/L case 4 : pcl = 1; clutch = 0; break; // H/C case 5 : pcl = 1; clutch = 2; break; // M/C case 6 : pcl = 1; clutch = 1; break; // L/C default: pcl = 0; clutch = 3; break; // Á¶Á÷¾ø½¿ } *(map + j / 8) |= (pcl << (7 - j % 8)); *(map + j / 4 + pcl_cnt) &= comp[j % 4]; *(map + j / 4 + pcl_cnt) |= (clutch << ((3 - j % 4) * 2)); if (j < NEEDLE - 1) ip++; } else break; } for(k = 0; k < 3; k++) { *(map + (total - 6) + k * 2) = n / 256; *(map + (total - 5) + k * 2) = n % 256; } } source->StopScanLine(); } //--------------------------------------------------------------------------- int __fastcall TCarpetForm::carpet_disk_write(int drive) { TCursor cursor; int track, head, sector; char *diskmap = NULL; TDiskAccess da('A' + drive); cursor = Screen->Cursor; Screen->Cursor = crHourGlass; diskmap = (BYTE *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1228800); make_disk_buf(diskmap, MainImageForm->iMainImage->Bitmap); sector = 0; StatusProgress->Maximum = TRACKS; for (track = 0; track < TRACKS; track++) { StatusProgress->Position = track; if (da.Write(sector, HEADS * SECTORS, diskmap + sector * BYTES) < 0) goto fail; sector += HEADS * SECTORS; } StatusProgress->End(); HeapFree(GetProcessHeap(), 0, diskmap); Screen->Cursor = cursor; return 0; fail: if (diskmap) HeapFree(GetProcessHeap(), 0, diskmap); Screen->Cursor = cursor; EXCEPTION_MESSAGE_OK(EC_DISKETTE_NOT_WRITE); return -1; } //--------------------------------------------------------------------------- void __fastcall TCarpetForm::SpeedButton1Click(TObject *Sender) { TDiskForm *df; df = new TDiskForm(this); if (df->ShowModal() == mrOk) { if (df->Method) { // Write disk carpet_disk_write(df->cbDrive->ItemIndex); } else { // Read disk carpet_disk_read(df->cbDrive->ItemIndex); View(); } } delete df; } //---------------------------------------------------------------------------