// This method returns the the list of files we can use for the menu // It will filter by episode and sort the list by number of slot // It also takes care of the slotname resolution std::vector<std::string> CSaveGameController::getSlotList() { std::vector<std::string> filelist; std::string buf; //Get the list of ".ck?" files StateFileListFiller sfilelist; FindFiles(sfilelist, m_savedir, false, FM_REG); std::set<std::string>::iterator i; for( i=sfilelist.list.begin() ; i!=sfilelist.list.end() ; i++ ) { buf = i->substr(i->size()-1); // Check if the file fits to this episode if(atoi(buf) == m_Episode) { Uint32 pos = getSlotNumber(*i)-1; buf = getSlotName(*i); if(pos+1 > filelist.size()) filelist.resize(pos+1, ""); filelist.at(pos) = buf; } } return filelist; }
BOOST_FIXTURE_TEST_CASE(getSlotNumber, myFixture) { auto bank = fparamManagerInstance.getParamBank(); auto mapping = JPetGeomMapping(bank); JPetLayer layerOK(1, true, "Layer01", 42.5); JPetLayer layerWrong(2, true, "Layer02", 50); JPetBarrelSlot slotOK1(1, true, "C1_C2", 0, 1); slotOK1.setLayer(layerOK); JPetBarrelSlot slotOK2(2, true, "C3_C4", 90, 1); slotOK2.setLayer(layerOK); JPetBarrelSlot slotWrong(3, true, "C2AA", 5, 9); BOOST_REQUIRE_EQUAL(mapping.getSlotNumber(slotOK1), 1u); BOOST_REQUIRE_EQUAL(mapping.getSlotNumber(slotOK2), 2u); BOOST_REQUIRE_EQUAL(mapping.getSlotNumber(slotWrong), JPetGeomMapping::kBadSlotNumber); }
//compress a page, used for split page void Page::adjustPage( ){ int nextFree = 4; int slotSize = getSlotNumber(); int length, offset; int counter = getSlotNumber(); int location = 0; for ( int i = 0; i < slotSize; i ++ ) { length = getRecordLength( i ); //if the length is -1,it means that this data not in this page if ( length == -1 ) counter --; else{ bool flag = 0; //find a slot with record length of -1,if it succeed, then move the data into this slot for (int j = location; j < i; j ++ ) if ( getRecordLength( j ) == -1 ) { location = j; flag = 1; break; } if ( flag == 1 ){ offset = getRecordOffset( i ); memcpy( content + nextFree, content + offset, sizeof( char ) * length ); setRecordOffset( location, nextFree ); setRecordLength( location, length ); setRecordLength( i, -1 ); } nextFree += length; } } //update free offset and slot number setSlotNumber( counter ); setFreeOffset( nextFree ); }
//add a record, if success return 1, else 0 bool Page::addRecord(char* rec){ if ( canAddRecord(rec) ){ int temp = getSlotNumber(); int free_off = freeOffset(); int rec_length = strlen( rec ); //copy the record into the page and update related data memcpy( content + free_off, rec, sizeof( char ) * rec_length ); setRecordLength( temp, rec_length ); setRecordOffset( temp, free_off ); //update the free offset and number of the slot in the page setFreeOffset( free_off + rec_length ); slotNumberAdd(); return 1; } else return 0; }
//if can add record return 1,else 0 bool Page::canAddRecord( char *rec ){ if ( freeOffset() + strlen(rec) + 8 + 8 * getSlotNumber() + 8 < CAPACITY ) return 1; else return 0; }
void Page::slotNumberAdd ( ){ setSlotNumber( getSlotNumber() + 1 ); }
void IOPMaster(UNSIGNED argc, VOID *argv) { STATUS status; int ch = 0; int i; unsigned long pci_id; /* Access argc and argv just to avoid compilation warnings. */ status = (STATUS) argc + (STATUS) argv; printf("\n\r"); printf("Executing the System Code....\n\r"); /* Initilaize the Hardware */ #ifdef INCLUDE_ODYSSEY #if 0 if ((status = Init_Hardware()) != NU_SUCCESS) printf("Error in init %d\r\n", status); gt_init(); gt_initdma(0); gt_initdma(1); board_type = memmaps.aBoardType[getSlotNumber()]; init_buf(get_slotno()); #else init_galileo(); /* enable the Switches */ *((U8 *)(0xBC0F8000)) = 0; a_id = b_id = c_id = d_id = e_id = f_id = h_id = 0; /* Init the E bridge */ printf("Initializing the Bridge E...."); pci_id = get_pci_id(0, BRIDGE_21154_ID, 0); if ( pci_id ) { bridge_init(pci_id, PCI_G_NUM, PCI_E_NUM, PCI_E_SUB, 0xFFFFFFFF, 0); printf("OK\n\r"); e_id = pci_id; } else { printf("Fail\n\r"); goto done; } /* Init the F bridge */ printf("Initializing the Bridge F...."); pci_id = get_pci_id(0, BRIDGE_21154_ID, 1); if ( pci_id ) { bridge_init(pci_id, PCI_G_NUM, PCI_F_NUM, PCI_F_SUB, 0xFFFFFFFF, 0); printf("OK\n\r"); f_id = pci_id; } else { printf("Fail\n\r"); goto done; } /* Init the H bridge */ printf("Initializing the Bridge H...."); pci_id = get_pci_id(PCI_F_NUM, BRIDGE_21154_ID, 0); if ( pci_id ) { bridge_init(pci_id, PCI_F_NUM, PCI_H_NUM, PCI_H_SUB, 0xFFFFFFFF, 0); printf("OK\n\r"); h_id = pci_id; } else { printf("Fail\n\r"); goto done; } /* Init the C bridge */ printf("Initializing the Bridge C...."); pci_id = get_pci_id(PCI_F_NUM, BRIDGE_21154_ID, 1); if ( pci_id ) { bridge_init(pci_id, PCI_F_NUM, PCI_C_NUM, PCI_C_SUB, 0xFFFFFFFF, 0); printf("OK\n\r"); c_id = pci_id; } else { printf("Fail\n\r"); goto done; } /* Init the D bridge */ printf("Initializing the Bridge D...."); pci_id = get_pci_id(PCI_F_NUM, BRIDGE_21154_ID, 2); if ( pci_id ) { bridge_init(pci_id, PCI_F_NUM, PCI_D_NUM, PCI_D_SUB, 0xFFFFFFFF, 0); printf("OK\n\r"); d_id = pci_id; } else { printf("Fail\n\r"); goto done; } /* Init the A bridge */ printf("Initializing the Bridge A...."); pci_id = get_pci_id(PCI_H_NUM, BRIDGE_21154_ID, 0); if ( pci_id ) { bridge_init(pci_id, PCI_H_NUM, PCI_A_NUM, PCI_A_SUB, 0xFFFFFFFF, 0); printf("OK\n\r"); a_id = pci_id; } else { printf("Fail\n\r"); goto done; } /* Init the B bridge */ printf("Initializing the Bridge B...."); pci_id = get_pci_id(PCI_H_NUM, BRIDGE_21154_ID, 1); if ( pci_id ) { bridge_init(pci_id, PCI_H_NUM, PCI_B_NUM, PCI_B_SUB, 0xFFFFFFFF, 0); printf("OK\n\r"); b_id = pci_id; } else { printf("Fail\n\r"); goto done; } #endif #else init_galileo(); #endif INCLUDE_ODYSSEY done: /* Spawn the rest of the tasks and initialize */ Init_System(&System_Memory); /* Lower the Priority of this task */ NU_Change_Priority( (NU_TASK *)&IOPMaster_Task, 250 ); /* Now this task will be active with lowest priority and can be used to * any cleanup required */ for(;;){ NU_Sleep(500); Cleanup_System(); /* rlw: can we implement erc91 functionality here? */ } }