Skip to content

Commit

Permalink
cli: Fix stderr output
Browse files Browse the repository at this point in the history
  • Loading branch information
remko committed Aug 15, 2024
1 parent e25ba81 commit 08dd957
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ endif # $(OS)
.PHONY: all
all: uxn-wasm-cli

uxn-wasm-cli: cli_core.o cli.o wasm-rt-impl.o
uxn-wasm-cli: cli_core.o cli.o wasm-rt-impl.o wasm-rt-mem-impl.o
$(CC) $(CFLAGS) $(LINKFLAGS) -o $@ $^

cli_core.c cli_core.h: ../../build/uxn.wasm
Expand All @@ -70,6 +70,9 @@ cli_core.c cli_core.h: ../../build/uxn.wasm
wasm-rt-impl.o: $(WABT_DATA_DIR)/wasm2c/wasm-rt-impl.c
$(CC) -c $(CFLAGS) -o $@ $<

wasm-rt-mem-impl.o: $(WABT_DATA_DIR)/wasm2c/wasm-rt-mem-impl.c
$(CC) -c $(CFLAGS) -o $@ $<

../../build/uxn.wasm: ../../src/uxn.wat
$(MAKE) -C ../.. build/uxn.wasm

Expand All @@ -82,6 +85,9 @@ mandelbrot.rom: ../benchmarks/mandelbrot.tal
primes32.rom: ../benchmarks/primes32.tal
cd ../benchmarks && $(UXNASM) $(PWD)/$< $(PWD)/$@

fib.rom: ../benchmarks/fib.tal
$(UXNASM) $< $@

test: uxn-wasm-cli opctest.rom
./uxn-wasm-cli opctest.rom | tee opctest.log
@grep failed opctest.log; if [ $$? -eq 0 ]; then echo "Test failed"; exit -1; fi
Expand Down
5 changes: 4 additions & 1 deletion src/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void w2c_system_deo(struct w2c_system *sys, u32 port, u32 value) {
// Console
if (port == 0x18) {
fputc(value, stdout);
} else if (port == 0x18) {
} else if (port == 0x19) {
fputc(value, stderr);
}
}
Expand All @@ -27,6 +27,8 @@ int main(int argc, char **argv) {
printf("missing rom\n");
return 1;
}

// Open ROM
FILE *file = fopen(argv[1], "rb");
if (file == NULL) {
printf("error opening file\n");
Expand All @@ -36,6 +38,7 @@ int main(int argc, char **argv) {
long filesize = ftell(file);
fseek(file, 0, SEEK_SET);

// Initialize wasm2c
wasm_rt_init();
w2c_uxn uxn;
w2c_system sys;
Expand Down

0 comments on commit 08dd957

Please sign in to comment.