From 5173d10a69e037e889bcfe2f92aaee2bcaad421b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Fri, 6 Apr 2018 14:25:26 +0200 Subject: [PATCH] Add code to actually run the example. --- examples/Makefile | 23 +++++++++++++++++++++++ examples/min3.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 examples/Makefile create mode 100644 examples/min3.c diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..08c8441 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,23 @@ +CFLAGS=-Wall -pedantic -I../src -g +LDFLAGS=-latf-c -lgc +RK6502LIB=../src/librk65c02.a +VASM=vasm6502_std +VASMFLAGS=-Fbin -c02 + +EXAMPLES=min3 +EXAMPLES_ROMS:=$(addsuffix .rom,$(basename $(wildcard *.s))) + +all : $(EXAMPLES) $(EXAMPLES_ROMS) + +min3 : min3.o $(RK6502LIB) + $(CC) -o $@ $(LDFLAGS) $< $(RK6502LIB) + +%.rom : %.s + $(VASM) $(VASMFLAGS) -o $@ $< + +%.o : %.c + $(CC) $(CFLAGS) -c $< +clean : + rm -f *.o + rm -f $(EXAMPLES) $(EXAMPLES_ROMS) + diff --git a/examples/min3.c b/examples/min3.c new file mode 100644 index 0000000..c36f8e7 --- /dev/null +++ b/examples/min3.c @@ -0,0 +1,35 @@ +#include +#include + +#include "rk65c02.h" +#include "bus.h" +#include "log.h" +#include "instruction.h" + +static const uint16_t load_addr = 0xC000; + +int main(void) +{ + uint8_t a, b, c; + uint8_t min; + bus_t bus; + rk65c02emu_t e; + + bus = bus_init_with_default_devs(); + e = rk65c02_init(&bus); + + bus_load_file(e.bus, load_addr, "min3.rom"); + + e.regs.SP = 0xFF; + e.regs.PC = load_addr; + a = 5; b = 9; c = 4; + + stack_push(&e, a); + stack_push(&e, b); + stack_push(&e, c); + + rk65c02_start(&e); + min = stack_pop(&e); + printf("Min is: %d\n", min); +} +