int32_t extractStartCluster(struct pcdir *dp) { uint32_t lo, hi; if (IsFAT32) { read_16_bits((uchar_t *)&(dp->un.pcd_scluster_hi), &hi); read_16_bits((uchar_t *)&(dp->pcd_scluster_lo), &lo); return ((int32_t)((hi << 16) | lo)); } else { read_16_bits((uchar_t *)&(dp->pcd_scluster_lo), &lo); return ((int32_t)lo); } }
void initialize_memory(chip_8_cpu cpu, FILE *program_file) { int new_16_bits; address destination = PROG_START; new_16_bits = read_16_bits(program_file); while (new_16_bits != EOF && destination < MEMORY_SIZE) { cpu->memory[destination] = (opcode)new_16_bits; destination++; new_16_bits = read_16_bits(program_file); } if (destination == MEMORY_SIZE) { fprintf(stderr, MEMORY_INIT_ERR "'Program size exceeds chip-8 memory capacity'\n"); shutdown_cpu(cpu, 1); } store_digit_sprites(cpu); }
// // ////////////////////////////////////////////////////////////////////////////// /// /// /// Read Start of Frame Marker /// /// @return => UINT16 EXTR::read_sof_marker : /// /// @note => ////////////////////////////////////////////////////////////////////////////// UINT8 EXTR::read_sof_marker() { UINT8 tmp, sof; UINT16 frame_header_length; UINT8 sample_precision; UINT16 number_of_lines, number_of_samples_per_line; space_uint2 i, number_of_image_components_in_frame; space_uint4 horizontal_sampling_factor, vertical_sampling_factor; //UINT16 quantization_table_destination_selector; UINT16 horizontal_mcus, vertical_mcus; // start_of_image must be detected only once if (m_jpeg_decoder_structure.sof_detected == 1) return ERROR_SOF_ALREADY_DETECTED; m_jpeg_decoder_structure.sof_detected = 1; sof = m_jpeg_decoder_structure.sof; computeFor(1); // frame_header_length = read_16_bits (); // sample precision must be baseline = 8 sample_precision = read_8_bits (); if (sample_precision != 8) { if ((sof == SOF0) || (sample_precision != 12)) return ERROR_INVALID_SAMPLE_PRECISION; return ERROR_TWELVE_BIT_SAMPLE_PRECISION_NOT_SUPPORTED; } // read # of lines in jpeg m_jpeg_decoder_structure.number_of_lines = number_of_lines = read_16_bits (); if (number_of_lines == 0) return ERROR_ZERO_NUMBER_OF_LINES_NOT_SUPPORTED; if (number_of_lines > MAXIMUM_NUMBER_OF_LINES) return ERROR_LARGE_NUMBER_OF_LINES_NOT_SUPPORTED; // read # of sample per lines in jpeg m_jpeg_decoder_structure.number_of_samples_per_line = number_of_samples_per_line = read_16_bits (); if (number_of_samples_per_line == 0) return ERROR_ZERO_SAMPLES_PER_LINE; if (number_of_samples_per_line > MAXIMUM_NUMBER_OF_SAMPLES_PER_LINE) return ERROR_LARGE_NUMBER_OF_SAMPLES_PER_LINE_NOT_SUPPORTED; // read # components per frame m_jpeg_decoder_structure.number_of_image_components_in_frame = number_of_image_components_in_frame = read_8_bits (); //if (number_of_image_components_in_frame != 1 && number_of_image_components_in_frame != 3) if (number_of_image_components_in_frame != 3) // luc: support only 4:2:0 return ERROR_INVALID_NUMBER_OF_IMAGE_COMPONENTS_IN_FRAME; if (frame_header_length != (number_of_image_components_in_frame * 3 + 8)) return ERROR_INVALID_FRAME_HEADER_LENGTH; computeFor(5); // for each component in frame for (i=0; i<number_of_image_components_in_frame; i++) { m_jpeg_decoder_structure.component_identifier [i] = read_8_bits (); tmp = read_8_bits (); // read horizontal & vertical sampling factor m_jpeg_decoder_structure.horizontal_sampling_factor [i] = horizontal_sampling_factor = tmp >> 4; if (horizontal_sampling_factor == 0 || horizontal_sampling_factor > 4) return ERROR_INVALID_HORIZONTAL_SAMPLING_FACTOR; m_jpeg_decoder_structure.vertical_sampling_factor [i] = vertical_sampling_factor = tmp & 0xf; if (vertical_sampling_factor == 0 || vertical_sampling_factor > 4) return ERROR_INVALID_VERTICAL_SAMPLING_FACTOR; // read quantization table selector //quantization_table_destination_selector = read_8_bits (); if (read_8_bits () > 3) return ERROR_INVALID_QUANTIZATION_TABLE_DESTINATION_SELECTOR; computeFor(3); } // compute the number of effective MCU H + V horizontal_mcus = (number_of_samples_per_line + 7) >> 3; vertical_mcus = (number_of_lines + 7) >> 3; computeFor(3); // // Fill structure for 4:2:0 image format. Others are rejected // if ((m_jpeg_decoder_structure . horizontal_sampling_factor [1] == 1) && (m_jpeg_decoder_structure . vertical_sampling_factor [1] == 1) && (m_jpeg_decoder_structure . horizontal_sampling_factor [2] == 1) && (m_jpeg_decoder_structure . vertical_sampling_factor [2] == 1)) { computeFor(1); if (m_jpeg_decoder_structure . horizontal_sampling_factor [0] == 2) { horizontal_mcus = (number_of_samples_per_line + 15) >> 4; computeFor(1); if (m_jpeg_decoder_structure . vertical_sampling_factor [0] == 2) { // 4:2:0 format m_jpeg_decoder_structure.mcu_size = 384; vertical_mcus = (number_of_lines + 15) >> 4; computeFor(3); }
UINT8 EXTR::read_soi_marker () { if (read_16_bits () != (0xFF00 | SOI)) return ERROR_SOI_NOT_DETECTED; return SUCCESS; }