diff --git a/.envrc b/.envrc index 18ddd8b..e61840e 100644 --- a/.envrc +++ b/.envrc @@ -8,6 +8,8 @@ fi if [[ -x /opt/ccstudio/ccs/ccs_base/scripting/examples/loadti/loadti.sh ]]; then PATH="/opt/ccstudio/ccs/ccs_base/scripting/examples/loadti${PATH:+:}$PATH" fi +PATH="$PWD/scripts${PATH:+:}$PATH" + if command -v cl6x &>/dev/null; then export C6X_C_DIR C6X_C_DIR="$(dirname "$(dirname "$(realpath "$(command -v cl6x)")")")" diff --git a/README.md b/README.md index 191146d..45eabc5 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,8 @@ Default debugger is XDS100v3. See [targetConfigs](targetConfigs) to modify it. ```sh # load /the/path/of/352x288.yuv to DDR2 and run: -# build/x264.out 352x288.yuv 1 -scripts/burn.js /the/path/of/352x288.yuv -- 352x288.yuv 1 +# build/x264.out --input=352x288.yuv --frames=10 +scripts/burn.js /the/path/of/352x288.yuv -- build/x264.out --input=352x288.yuv --frames=10 ffplay build/out.264 ``` diff --git a/meson.build b/meson.build index 3edd478..dea69e2 100644 --- a/meson.build +++ b/meson.build @@ -100,9 +100,8 @@ if meson.is_cross_build() join_paths(meson.current_source_dir(), get_option('cmd_file')), language: ['c', 'linearasm'], ) -else - subdir('tests') endif +subdir('tests') deps = [] if cc.get_id() == 'c6000' diff --git a/meson/ti-c6000.txt b/meson/ti-c6000.txt index 54b0803..d63ab47 100644 --- a/meson/ti-c6000.txt +++ b/meson/ti-c6000.txt @@ -15,6 +15,7 @@ ar = 'ar6x' strip = 'strip6x' nm = 'nm6x' as = 'asm6x' +exe_wrapper = 'wrapper.sh' [properties] needs_exe_wrapper = true diff --git a/scripts/burn.js b/scripts/burn.js index 367dedd..a4d29a0 100755 --- a/scripts/burn.js +++ b/scripts/burn.js @@ -20,18 +20,21 @@ c64xp.expression.evaluate( 'GEL_LoadGel("/opt/ccstudio/ccs/ccs_base/emulation/boards/evmdm6467/gel/davincihd1080p_dsp.gel")' ); c64xp.target.connect(); -var bin = "build/x264.out"; + +if (arguments[0] && arguments[0] !== "--") { + var ddr2 = 0xa0000000; + arm926.memory.loadRaw(0, ddr2, arguments[0], 32, false); // DDR2 SDRAM + arm926.memory.verifyBinaryProgram(arguments[0], ddr2); +} + var args = []; for (i in arguments) if (arguments[i] === "--") { - args = [bin].concat(arguments.slice(Number(i) + 1)); + args = arguments.slice(Number(i) + 1); break; } -c64xp.memory.loadProgram(bin, args); -c64xp.memory.verifyProgram(bin); -if (arguments[0] && arguments[0] !== "--") { - var ddr2 = 0xa0000000; - arm926.memory.loadRaw(0, ddr2, arguments[0], 32, false); // DDR2 SDRAM - arm926.memory.verifyBinaryProgram(arguments[0], ddr2); +if (args.length) { + c64xp.memory.loadProgram(args[0], args); + c64xp.memory.verifyProgram(args[0]); + c64xp.clock.runBenchmark(); } -if (args.length) c64xp.clock.runBenchmark(); diff --git a/scripts/wrapper.sh b/scripts/wrapper.sh new file mode 100755 index 0000000..0b7d196 --- /dev/null +++ b/scripts/wrapper.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -e +cd "$(dirname "$(dirname "$(readlink -f "$0")")")" + +exec scripts/burn.js -- "$@" diff --git a/tests/check_getopt.c b/tests/check_getopt.c new file mode 100644 index 0000000..6f3623c --- /dev/null +++ b/tests/check_getopt.c @@ -0,0 +1,34 @@ +#include +#include + +#include "extras/getopt.h" + +static char shortopts[] = "0:1:2:"; +static struct option longopts[] = { + {"option0", required_argument, NULL, '0'}, + {"option1", required_argument, NULL, '1'}, + {"option2", required_argument, NULL, '2'}, + {NULL, 0, NULL, 0}}; + +int main(int argc, char *argv[]) { + int c; + char *results[3] = {}; + while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { + switch (c) { + case '0': + results[0] = optarg; + break; + case '1': + results[1] = optarg; + break; + case '2': + results[2] = optarg; + break; + default: + return -1; + } + } + for (c = 0; c < 3; ++c) + printf("%s\n", results[c]); + return EXIT_SUCCESS; +} diff --git a/tests/meson.build b/tests/meson.build index 679d7f6..3acdfc4 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,18 +1,27 @@ -checkmk = find_program('checkmk') -if checkmk.found() - check_downsample_c = custom_target( - 'check_downsample.c', - input: 'check_downsample.c.in', - output: 'check_downsample.c', - capture: true, - command: [checkmk, '@INPUT@'], - ) - check_dep = dependency('check', fallback: ['check', 'check_dep']) - check_downsample = executable( - 'check_downsample', - [check_downsample_c, '../downsample.c'], - include_directories: include_directories('..'), - dependencies: check_dep, - ) - test('check_downsample', check_downsample) +check_getopt = executable( + 'check_getopt', + ['check_getopt.c', '../extras/getopt.c'], + include_directories: include_directories('..'), +) +test('check_getopt', check_getopt, args: ['--option0=0', '--option1', '1', '-22']) + +if get_option('downsample').to_int() > 0 + checkmk = find_program('checkmk') + if checkmk.found() + check_downsample_c = custom_target( + 'check_downsample.c', + input: 'check_downsample.c.in', + output: 'check_downsample.c', + capture: true, + command: [checkmk, '@INPUT@'], + ) + check_dep = dependency('check', fallback: ['check', 'check_dep']) + check_downsample = executable( + 'check_downsample', + [check_downsample_c, '../downsample.c'], + include_directories: include_directories('..'), + dependencies: check_dep, + ) + test('check_downsample', check_downsample) + endif endif diff --git a/x264.c b/x264.c index d86b01c..8012849 100644 --- a/x264.c +++ b/x264.c @@ -8,6 +8,8 @@ #include "input.h" #include "output.h" +#include "extras/getopt.h" + /* In microseconds */ #define UPDATE_INTERVAL 1000000 @@ -85,17 +87,32 @@ int main(int argc, char **argv) { return ret; } +static char shortopts[] = "i:f:"; +static struct option longopts[] = { + {"input", required_argument, NULL, 'i'}, + {"frames", required_argument, NULL, 'f'}, + {NULL, 0, NULL, 0}}; + static int parse(int argc, char **argv, x264_param_t *param, cli_opt_t *opt) { char *input_filename = "352x288.yuv"; char *output_filename = "out.264"; video_info_t info = {0}; + int c; - if (argc > 1) - input_filename = argv[1]; - if (argc > 2) - info.num_frames = strtol(argv[2], NULL, 0); - info.num_frames = 1; opt->b_progress = 1; + info.num_frames = 1; + while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { + switch (c) { + case 'i': + input_filename = optarg; + break; + case 'f': + info.num_frames = strtol(optarg, NULL, 0); + break; + default: + return 1; + } + } x264_param_default(param); cli_log_level = param->i_log_level;