예제 #1
0
파일: main.cpp 프로젝트: Rohansi/LoonyOS
exp bool DirCreate(const char* dirName) {
    // Convert the filename into DOS8.3 format
    char* dosName = new char[12];
    ToDos83Name(dirName, dosName);

    DirectoryEntry* entry = MakeEntry(dosName, ATTRIB_DIRECTORY, 0, &directory);
    if (!entry) {
        LastError("DirCreate", "Failed to create a directory");
        delete[] dosName;
        return false;
    }

    // Write FAT entry
    FatEntry fatEntry;
    fatEntry.buffer = new char[bpb->bytesPerSector];
    fatEntry.cluster = GetClusterFromEntry(entry);
    fatEntry.sector = GetFATSector(fatEntry.cluster);

    UpdateFAT(&fatEntry, GetClusterFromEntry(entry));

    // Write entry to disk
    DirectoryWrite(&directory);
    //WriteSector(directoryBuffer + ((((char*)entry - directoryBuffer) / 512) * 512),directorySector + (((char*)entry - directoryBuffer) / 512));

    delete[] dosName;
    delete[] fatEntry.buffer;

    return true;
}
예제 #2
0
파일: adlib.cpp 프로젝트: Avin15/dospad
	void MakeTables( void ) {
		Bit8u index = 0;
		memset( ToReg, 0xff, sizeof ( ToReg ) );
		memset( ToRaw, 0xff, sizeof ( ToRaw ) );
		//Select the entries that are valid and the index is the mapping to the index entry
		MakeEntry( 0x01, index );					//0x01: Waveform select
		MakeEntry( 0x04, index );					//104: Four-Operator Enable
		MakeEntry( 0x05, index );					//105: OPL3 Mode Enable
		MakeEntry( 0x08, index );					//08: CSW / NOTE-SEL
		MakeEntry( 0xbd, index );					//BD: Tremolo Depth / Vibrato Depth / Percussion Mode / BD/SD/TT/CY/HH On
		//Add the 32 byte range that hold the 18 operators
		for ( int i = 0 ; i < 24; i++ ) {
			if ( (i & 7) < 6 ) {
				MakeEntry(0x20 + i, index );		//20-35: Tremolo / Vibrato / Sustain / KSR / Frequency Multiplication Facto
				MakeEntry(0x40 + i, index );		//40-55: Key Scale Level / Output Level 
				MakeEntry(0x60 + i, index );		//60-75: Attack Rate / Decay Rate 
				MakeEntry(0x80 + i, index );		//80-95: Sustain Level / Release Rate
				MakeEntry(0xe0 + i, index );		//E0-F5: Waveform Select
			}
		}
		//Add the 9 byte range that hold the 9 channels
		for ( int i = 0 ; i < 9; i++ ) {
			MakeEntry(0xa0 + i, index );			//A0-A8: Frequency Number
			MakeEntry(0xb0 + i, index );			//B0-B8: Key On / Block Number / F-Number(hi bits) 
			MakeEntry(0xc0 + i, index );			//C0-C8: FeedBack Modulation Factor / Synthesis Type
		}
		//Store the amount of bytes the table contains
		RawUsed = index;
//		assert( RawUsed <= 127 );
		delay256 = RawUsed;
		delayShift8 = RawUsed+1; 
	}
예제 #3
0
파일: main.cpp 프로젝트: borysn/AddressBook
void processInput(int option) {
	switch (option) {
	//setup an entry
	case 1:	
		printf_s("\n[Setting Up An Entry]...\n");
		entry = MakeEntry();
		break;
	//setup a search
	case 2:
		printf_s("\n[Setting Up A Search]...\n");
		key = MakeSearchKey();
		break;
	case 3:
	//que an entry
		printf_s("\n[Queing An Entry]...\n");
		//lets see if entry is empty first
		if (strcmp(entry.getFirstName(), "\0") == 0) {
			printf_s("\nERROR: NO ENTRY DEFINED!\n\n");
			break;
		}
		printf_s("\nChecking to see if entry exists using query...\n");
		printf_s("%s\n", entry.getEntryAsKey()); //works
		if (!ABman->entryExists(entry)) {
			printf("\n\n[Entry not found...]\n[Adding Entry...]\n\n");
			ABman->addNewEntry(entry); //works 
		} else {
			printf("\n\n[Entry already exists!]\n\n");
		}
		break;
	//que a search
	case 4:
		printf_s("\n[Queing A Search]...\n");
		//lets see if key is empty first
		if (strcmp(key.getFirstName(), "\0") == 0) {
			printf_s("\nERROR: NO SEARCH DEFINED!\n\n");
			break;
		}
		printf_s("\nChecking to see if entry exists using key...\n");
		printf_s("%s\n", key.getEntryAsKey()); //works
		if (!ABman->entryExists(key)) {
			printf("\n\n[Entry not found...]\n\n");
		} else {
			printf("\n\n[Entry found!]\n\n");
		}
		break;
	//edit an entry
	case 5:
		printf_s("\n[Editing an entry]\n\n");
		//lets see if key is empty first
		if (strcmp(key.getFirstName(), "\0") == 0) {
			printf_s("\nERROR: NO SEARCH DEFINED!\n\n");
			break; 
		}
		printf_s("\nChecking to see if entry exists using key...\n");
		printf_s("%s\n", key.getEntryAsKey()); //works
		if (!ABman->entryExists(key)) { 
			printf_s("\n\n[Entry not found. Cannot edit...]\n\n");
		} else { 
			printf_s("\n\n[Entry found! Beginning Editing Process]\n\n");
			printf_s("first create the new entry\n");
			entry = MakeEntry();
			ABman->editOldEntry(key, entry); 
			printf_s("\n\n[Finished with editing]\n\n");
		} 
		break;
	//Remove an entry
	case 6:
		printf_s("\n[Removing an entry]\n\n");		
		//lets see if key is empty first
		if (strcmp(key.getFirstName(), "\0") == 0) {
			printf_s("\nERROR: NO SEARCH DEFINED!\n\n");
			break;
		}
		printf_s("\nChecking to see if entry exists using key...\n");
		printf_s("%s\n", key.getEntryAsKey()); //works
		if (!ABman->entryExists(key)) {
			printf_s("\n\n[Entry not found. Cannot delete...]\n\n");
		} else { 
			//make sure i want to delete the entry
			printf_s("\n\n[Entry found!]\n");
			printf_s("Are you sure you want to delete this entry?(y/n)\n");
			printf_s("//:> "); 
			char *c = new char[2];
			scanf_s("%s", c); 
			switch (c[0]) {
			case 'y':
				printf("[Entry Deleted!]\n\n");
				ABman->removeEntry(key);
				break;
			case 'n':
				printf("[Entry not deleted!]\n\n");
				break;
			default:
				printf("[Entry not deleted!]\n\n");
				break;
			}
			delete c;
		}
		break;
	//Look at address book
	case 7:
		printf("\n\n[Retrieving Entries]\n\n"); 
		setupSearch(); 
		break;
	//Exit 
	case 8:
		printf("\n\n[Exiting the application]\n");
		break;
	//Just print menu
	default:
		printMenu();
		break;
	}
}
예제 #4
0
파일: main.cpp 프로젝트: Rohansi/LoonyOS
exp bool CopyIn(const char* source, const char* dest) {
    DirectoryEntry* entry = 0;
    char* buffer = new char[bpb->bytesPerSector];

    // Open file we're copying in
    std::ifstream inHandle(source, std::ios::in | std::ios::binary | std::ios::ate);
    if (!inHandle.is_open()) {
        LastError("CopyIn", "Failed to open source file");
        return false;
    }

    // Get size of source file
    size_t inLength = (size_t)inHandle.tellg();
    inHandle.seekg(std::ios::beg);

    // Convert the filename into DOS8.3 format
    char* dosName = new char[12];
    ToDos83Name(dest, dosName);

    // Check if entry exists, if so, overwrite it
    entry = FindEntry(dosName, &directory);
    if (entry) {
        // Delete file
        Delete(dest);

        // Undelete entry
        entry->name[0] = dosName[0];
    }

    // Create the directory entry
    if (!entry) {
        // Didn't delete file, make it
        entry = MakeEntry(dosName, ATTRIB_ARCHIVE, inLength, &directory);
        if (!entry) {
            LastError("CopyIn", "Failed to create directory entry");
            delete[] dosName;
            delete[] buffer;
            return false;
        }
    }
    else {
        // Deleted file, find it
        entry = FindEntry(dosName, &directory);
        if (!entry) {
            LastError("CopyIn", "Somehow a file that was just undeleted can't be found...");
            delete[] dosName;
            delete[] buffer;
            return false;
        }

        UpdateEntry(entry, 0, inLength);
    }

    // Write entry to disk
    DirectoryWrite(&directory);

    // Update FAT and then load each cluster and write it while updating the FAT
    FatEntry fatEntry;
    fatEntry.buffer = new char[bpb->bytesPerSector];
    fatEntry.cluster = GetClusterFromEntry(entry);
    fatEntry.sector = GetFATSector(fatEntry.cluster);
    ReadSector(fatEntry.buffer, fatEntry.sector);

    UpdateFAT(&fatEntry, FindFreeCluster());

    // Write to disk
    for (size_t i = 0; i < inLength; i += bpb->bytesPerSector) {
        memset(buffer, 0, bpb->bytesPerSector);
        if (!(i % bpb->bytesPerSector))
            inHandle.read(buffer, bpb->bytesPerSector);
        else
            inHandle.read(buffer, i % bpb->bytesPerSector);

        WriteCluster(&fatEntry, buffer);
    }

    delete[] dosName;
    delete[] buffer;
    delete[] fatEntry.buffer;

    inHandle.close();

    return true;
}