Conditionally print debug info

This commit is contained in:
Alex Kotov 2022-01-16 20:57:29 +05:00
parent aba85c2cd6
commit a1adba0733
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 31 additions and 24 deletions

View File

@ -51,6 +51,7 @@ struct Mbr {
__attribute__((packed));
static bool create_mbr_file(
bool print_debug,
const char *output_filename,
uint32_t disk_id,
const char *bootstrap_filename
@ -58,14 +59,18 @@ static bool create_mbr_file(
int main()
{
if (create_mbr_file("disk.img", 0xf01834d0, "src/x86_boot_sector.bin")) {
return 0;
} else {
return 1;
}
const bool result = create_mbr_file(
true,
"disk.img",
0xf01834d0,
"src/x86_boot_sector.bin"
);
return result ? 0 : 1;
}
bool create_mbr_file(
const bool print_debug,
const char *const output_filename,
const uint32_t disk_id,
const char *const bootstrap_filename
@ -102,6 +107,7 @@ bool create_mbr_file(
uint8_t *mbr_ptr = (uint8_t*)&mbr;
if (print_debug) {
for (size_t i = 0; i < 512 / 16; ++i) {
printf("%02x", mbr_ptr[i * 16]);
for (size_t j = 1; j < 16; ++j) {
@ -125,6 +131,7 @@ bool create_mbr_file(
fclose(fd);
}
}
return true;
}