/*************************************************************** * - createTLocation * * Devolve um ponteiro para uma estrutura do tipo t_location * inicializada, alocada dinamicamente em memoria, que reflecte * as caracteristicas de um tetramino, recebido como argumento **************************************************************/ t_location* createTLocation(GameArea *gameArea, tetromino *t) { t_location *loc = malloc(sizeof(t_location)); int i; setTLocationHashPos(loc, getTHashPos(t)); setTLocationNumLines(loc, getLineSpan(t)); setTLocationLines(loc, malloc(getLineSpan(t)*sizeof(Line*))); for(i=0; i<getLineSpan(t); i++) { getTLocationLines(loc)[i] = getGameLine(gameArea, getPieceLine(t) - i); setLineT_location(getTLocationLines(loc)[i], loc); } return loc; }
bool Cartridge::readFromBuffer(const uint8_t *buffer, unsigned length) { if ((data = (uint8_t *)malloc(length)) == NULL) { return false; } memcpy(data, buffer, length); // Scan cartridge header if (memcmp("C64 CARTRIDGE ", data, 16) != 0) { fprintf(stderr, "Bad cartridge signature. Expected 'C64 CARTRIDGE ', got ...\n"); printReadable(&data[0], 16); return false; } // Cartridge header size uint32_t headerSize = HI_HI_LO_LO(data[0x10],data[0x11],data[0x12],data[0x13]); // Minimum header size is 0x40. Some cartridges show a value of 0x20 which is wrong. if (headerSize < 0x40) headerSize = 0x40; fprintf(stderr, "Cartridge: %s\n", getCartridgeName()); fprintf(stderr, " Header: %08X bytes long (normally 0x40)\n", headerSize); fprintf(stderr, " Type: %d\n", getCartridgeType()); fprintf(stderr, " Game: %d\n", getGameLine()); fprintf(stderr, " Exrom: %d\n", getExromLine()); // Load chip packets uint8_t *ptr = &data[headerSize]; for (numberOfChips = 0; ptr < data + length; numberOfChips++) { if (memcmp("CHIP", ptr, 4) != 0) { fprintf(stderr, "Unexpected data in cartridge, expected 'CHIP'\n"); printReadable(ptr, 4); return false; } // Remember start address of each chip section chips[numberOfChips] = ptr; ptr += 0x10; ptr += getChipSize(numberOfChips); } fprintf(stderr, "CRT container imported successfully (%d chips)\n", numberOfChips); return true; }