1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-06-15 05:29:28 +00:00

Add code to actually run the example.

This commit is contained in:
Radosław Kujawa 2018-04-06 14:25:26 +02:00
parent b44dcdc91a
commit 5173d10a69
2 changed files with 58 additions and 0 deletions

23
examples/Makefile Normal file
View File

@ -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)

35
examples/min3.c Normal file
View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdint.h>
#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);
}