Skip to content

Commit 34286d7

Browse files
committed
Add IPL unit test & fixes
1 parent 8820455 commit 34286d7

File tree

3 files changed

+162
-6
lines changed

3 files changed

+162
-6
lines changed

ipl.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
static bool ipl_read_header(IPL *out, FILE *in, const char *filename) {
4343
bool ret = false;
44+
4445
if(fread(out->load_start_record, 1, 3, in) != 3) {
4546
ERROR_MSG("Failed to read IPLBLK from %s: %s", filename, strerror(errno));
4647
} else if(fread(&out->load_sector_count, 1, 1, in) != 1) {
@@ -107,21 +108,29 @@ void ipl_print(IPL *in) {
107108
} else {
108109
fprintf(stream, "IPLBLK: .db $%02x, $%02x, $%02x\n", in->load_start_record[0], in->load_start_record[1], in->load_start_record[2]);
109110
fprintf(stream, "IPLBKN: .db $%02x\n", in->load_sector_count);
110-
fprintf(stream, "IPLSTA: .dw $%02x%02x\n", in->load_store_address[0], in->load_store_address[1]);
111-
fprintf(stream, "IPLJMP: .dw $%02x%02x\n", in->load_exec_address[0], in->load_exec_address[1]);
111+
fprintf(stream, "IPLSTA: .dw $%02x%02x\n", in->load_store_address[1], in->load_store_address[0]);
112+
fprintf(stream, "IPLJMP: .dw $%02x%02x\n", in->load_exec_address[1], in->load_exec_address[0]);
112113
fprintf(stream, "IPLMPR: .db $%02x, $%02x, $%02x, $%02x, $%02x\n", in->mpr[0], in->mpr[1], in->mpr[2], in->mpr[3], in->mpr[4]);
113114
fprintf(stream, "OPENMODE: .db $%02x\n", in->opening_mode);
114115
fprintf(stream, "GRPBLK: .db $%02x, $%02x, $%02x\n", in->opening_gfx_record[0], in->opening_gfx_record[1], in->opening_gfx_record[2]);
115116
fprintf(stream, "GRPBLN: .db $%02x\n", in->opening_gfx_sector_count);
116-
fprintf(stream, "GRPADR: .dw $%02x%02x\n", in->opening_gfx_read_address[0], in->opening_gfx_read_address[1]);
117+
fprintf(stream, "GRPADR: .dw $%02x%02x\n", in->opening_gfx_read_address[1], in->opening_gfx_read_address[0]);
117118
fprintf(stream, "ADPBLK: .db $%02x, $%02x, $%02x\n", in->opening_adpcm_record[0], in->opening_adpcm_record[1], in->opening_adpcm_record[2]);
118119
fprintf(stream, "ADPBLN: .db %02x\n", in->opening_adpcm_sector_count);
119-
fprintf(stream, "ADPRATE: .db $%02x\b", in->opening_adpcm_sampling_rate);
120+
fprintf(stream, "ADPRATE: .db $%02x\n", in->opening_adpcm_sampling_rate);
120121
fprintf(stream, "RESERVED: .db $%02x, $%02x, $%02x, $%02x, $%02x, $%02x, $%02x\n",
121122
in->reserved[0], in->reserved[1], in->reserved[2], in->reserved[3],
122123
in->reserved[4], in->reserved[5], in->reserved[6]);
123-
fprintf(stream, "ID STR: .db \"%.24s\"\n", in->id);
124-
fprintf(stream, "LEGAL: .db \"%.50s\"\n", in->legal);
124+
fprintf(stream, "ID STR: .db \"%.24s\"", in->id);
125+
for(int i=23; (i>=0) && (in->id[i] == '\0'); i--) {
126+
fprintf(stream, ",0");
127+
}
128+
fputc('\n', stream);
129+
fprintf(stream, "LEGAL: .db \"%.50s\"", in->legal);
130+
for(int i=49; (i>=0) && (in->legal[i] == '\0'); i--) {
131+
fprintf(stream, ",0");
132+
}
133+
fputc('\n', stream);
125134
fprintf(stream,"PROGRAM NAME: .db \"%.16s\"\n", in->program_name);
126135
fprintf(stream,"EXTRA: .db \"%.6s\"\n", in->extra);
127136
fclose(stream);

test/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,13 @@ add_unit_test(
140140
LIBRARIES cwalk jansson
141141
INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}
142142
)
143+
144+
add_unit_test(
145+
NAME ipl
146+
SOURCES
147+
ipl.c
148+
${PROJECT_SOURCE_DIR}/message.c
149+
${PROJECT_SOURCE_DIR}/message/console.c
150+
LIBRARIES cwalk
151+
INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}
152+
)

test/ipl.c

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
¬°¤*,¸¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸
3+
¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯
4+
5+
__/¯\____ ___/\__ _/\__ _/\_ _/\__ _/\___ ___/\__ __/\_ _/\__
6+
\_ ____/_> ____ \_/ _ \_ \ < /_ \_/ _>> ____ \_ > \_/ _ \_
7+
_> ___/ ¯>__> <<__// __ _/ |> ></ _/> </ ¯ \\__> <<__// /\ // __ _/
8+
_> \7 <__/:. \__/:. \> \_/ L/ _____/. 7> .\_/:. \__/ <_/ </:. \> \_
9+
|:::::::::::::::::::::::/:::::::::::::>::::::::/::::::::::::::::::::::::/:::::|
10+
|¯¯\::::/\:/¯\::::/¯¯¯¯<::::/\::/¯¯\:/¯¯¯¯¯¯\::\::/¯¯\::::/¯¯\::::/¯¯¯¯<::::/¯|
11+
|__ |¯¯| T _ |¯¯¯| ___ |¯¯| |¯| _ T ______ |¯¯¯¯| _ |¯¯¯| _ |¯¯¯| ___ |¯¯| _|
12+
\|__|/\|/ \|___|/ \|__|/\|_|/ \|/ \| |/ \|___|/ \|___|/dNo\|__|/
13+
14+
¬°¤*,¸¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸
15+
¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯
16+
17+
This file is part of Etripator,
18+
copyright (c) 2009--2024 Vincent Cruz.
19+
20+
Etripator is free software: you can redistribute it and/or modify
21+
it under the terms of the GNU General Public License as published by
22+
the Free Software Foundation, either version 3 of the License, or
23+
(at your option) any later version.
24+
25+
Etripator is distributed in the hope that it will be useful,
26+
but WITHOUT ANY WARRANTY; without even the implied warranty of
27+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+
GNU General Public License for more details.
29+
30+
You should have received a copy of the GNU General Public License
31+
along with Etripator. If not, see <http://www.gnu.org/licenses/>.
32+
33+
¬°¤*,¸¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸
34+
¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯
35+
*/
36+
#include <munit.h>
37+
38+
#include "../ipl.c"
39+
40+
#include "message.h"
41+
#include "message/console.h"
42+
43+
static uint8_t g_hcd8004_ipl[] = {
44+
0x00, 0x00, 0x02, 0x04, 0x00, 0x40, 0x00, 0x40, 0x00, 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00,
45+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46+
0x50, 0x43, 0x20, 0x45, 0x6E, 0x67, 0x69, 0x6E, 0x65, 0x20, 0x43, 0x44, 0x2D, 0x52, 0x4F, 0x4D,
47+
0x20, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4D, 0x00, 0x43, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68,
48+
0x74, 0x20, 0x48, 0x55, 0x44, 0x53, 0x4F, 0x4E, 0x20, 0x53, 0x4F, 0x46, 0x54, 0x20, 0x2F, 0x20,
49+
0x4E, 0x45, 0x43, 0x20, 0x48, 0x6F, 0x6D, 0x65, 0x20, 0x45, 0x6C, 0x65, 0x63, 0x74, 0x72, 0x6F,
50+
0x6E, 0x69, 0x63, 0x73, 0x2C, 0x4C, 0x74, 0x64, 0x2E, 0x00, 0x53, 0x70, 0x61, 0x63, 0x65, 0x20,
51+
0x41, 0x64, 0x76, 0x65, 0x6E, 0x74, 0x75, 0x72, 0x65, 0x20, 0x43, 0x4F, 0x42, 0x52, 0x41, 0x20,
52+
};
53+
54+
void* setup(const MunitParameter params[] __attribute__((unused)), void* user_data __attribute__((unused))) {
55+
message_printer_init();
56+
console_message_printer_init();
57+
return NULL;
58+
}
59+
60+
void tear_down(void* fixture __attribute__((unused))) {
61+
message_printer_destroy();
62+
}
63+
64+
MunitResult ipl_read_test(const MunitParameter params[] __attribute__((unused)), void* fixture __attribute__((unused))) {
65+
IPL ipl = {0};
66+
const char *filename = "data/HCD8004.ipl";
67+
68+
FILE *in = fmemopen(g_hcd8004_ipl, sizeof(g_hcd8004_ipl), "r");
69+
70+
munit_assert_not_null(in);
71+
munit_assert_true(ipl_read_header(&ipl, in, filename));
72+
munit_assert_int(fclose(in), ==, 0);
73+
74+
munit_assert_uint8(ipl.load_start_record[0], ==, 0x00U);
75+
munit_assert_uint8(ipl.load_start_record[1], ==, 0x00U);
76+
munit_assert_uint8(ipl.load_start_record[2], ==, 0x02U);
77+
78+
munit_assert_uint8(ipl.load_sector_count, ==, 0x04U);
79+
80+
munit_assert_uint8(ipl.load_store_address[0], ==, 0x00U);
81+
munit_assert_uint8(ipl.load_store_address[1], ==, 0x40U);
82+
83+
munit_assert_uint8(ipl.load_exec_address[0], ==, 0x00U);
84+
munit_assert_uint8(ipl.load_exec_address[1], ==, 0x40U);
85+
86+
munit_assert_uint8(ipl.mpr[0], ==, 0x00U);
87+
munit_assert_uint8(ipl.mpr[1], ==, 0x01U);
88+
munit_assert_uint8(ipl.mpr[2], ==, 0x02U);
89+
munit_assert_uint8(ipl.mpr[3], ==, 0x03U);
90+
munit_assert_uint8(ipl.mpr[4], ==, 0x04U);
91+
92+
munit_assert_uint8(ipl.opening_mode, ==, 0x00U);
93+
94+
munit_assert_uint8(ipl.opening_gfx_record[0], ==, 0x00U);
95+
munit_assert_uint8(ipl.opening_gfx_record[1], ==, 0x00U);
96+
munit_assert_uint8(ipl.opening_gfx_record[2], ==, 0x00U);
97+
98+
munit_assert_uint8(ipl.opening_gfx_sector_count, ==, 0x00U);
99+
100+
munit_assert_uint8(ipl.opening_gfx_read_address[0], ==, 0x00U);
101+
munit_assert_uint8(ipl.opening_gfx_read_address[1], ==, 0x00U);
102+
103+
munit_assert_uint8(ipl.opening_adpcm_record[0], ==, 0x00U);
104+
munit_assert_uint8(ipl.opening_adpcm_record[1], ==, 0x00U);
105+
munit_assert_uint8(ipl.opening_adpcm_record[2], ==, 0x00U);
106+
107+
munit_assert_uint8(ipl.opening_adpcm_sector_count, ==, 0x00U);
108+
109+
munit_assert_uint8(ipl.opening_adpcm_sampling_rate, ==, 0x00U);
110+
111+
for(unsigned int i=0; i<7; i++) {
112+
munit_assert_uint8(ipl.reserved[i], ==, 0x00U);
113+
}
114+
115+
munit_assert_memory_equal(24U, ipl.id, "PC Engine CD-ROM SYSTEM");
116+
117+
munit_assert_memory_equal(50U, ipl.legal, "Copyright HUDSON SOFT / NEC Home Electronics,Ltd.");
118+
119+
munit_assert_memory_equal(16U, ipl.program_name, "Space Adventure ");
120+
121+
munit_assert_memory_equal(6U, ipl.extra, "COBRA ");
122+
123+
return MUNIT_OK;
124+
}
125+
126+
static MunitTest g_ipl_tests[] = {
127+
{ "/read", ipl_read_test, setup, tear_down, MUNIT_TEST_OPTION_NONE, NULL },
128+
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
129+
};
130+
131+
static const MunitSuite g_ipl_test_suite = {
132+
"Label test suite", g_ipl_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
133+
};
134+
135+
int main (int argc, char* const* argv) {
136+
return munit_suite_main(&g_ipl_test_suite, NULL, argc, argv);
137+
}

0 commit comments

Comments
 (0)