diff src/main.c @ 28:c677507682e3

Untested controller implementation
author Michael Pavone <pavone@retrodev.com>
date Sun, 03 Apr 2016 00:33:54 -0700
parents 083347ccd508
children 78068060313a
line wrap: on
line diff
--- a/src/main.c	Fri Apr 01 21:51:46 2016 -0700
+++ b/src/main.c	Sun Apr 03 00:33:54 2016 -0700
@@ -6,6 +6,7 @@
 #include "vdp.h"
 #include "audio.h"
 #include "timer.h"
+#include "controller.h"
 #include "system.h"
 
 #define CYCLES_PER_FRAME (832*262)
@@ -17,8 +18,8 @@
 enum {
 	PORT_CONTROLLER_1,
 	PORT_CONTROLLER_2,
-	PORT_CONTROLLER_3,
-	PORT_CONTROLLER_4,
+	RESERVED_1,
+	RESERVED_2,
 	PORT_FREQUENCY_A,
 	PORT_FREQUENCY_B,
 	PORT_FREQUENCY_C,
@@ -34,10 +35,11 @@
 };
 
 typedef struct {
-	cpu   *proc;
-	audio *audio;
-	timer timer;
-	vdp   video;
+	cpu         *proc;
+	audio       *audio;
+	timer       timer;
+	controllers pads;
+	vdp         video;
 } console;
 
 void debug_port_write(cpu *context, uint8_t port, uint16_t value)
@@ -124,6 +126,14 @@
 	}
 }
 
+uint16_t controller_port_read(cpu *context, uint8_t port)
+{
+	//process events so controller state is as fresh as possible
+	system_poll_events();
+	console *system = context->system;
+	return controller_read(&system->pads, port - PORT_CONTROLLER_1);
+}
+
 uint32_t next_interrupt_cycle(cpu *context, uint8_t mask)
 {
 	console *system = context->system;
@@ -210,6 +220,8 @@
 	context.proc->system = &context;
 	vdp_init(&context.video, 2);
 	timer_init(&context.timer, 16);
+	context.proc->port_handlers[PORT_CONTROLLER_1].read = controller_port_read;
+	context.proc->port_handlers[PORT_CONTROLLER_2].read = controller_port_read;
 	context.proc->port_handlers[PORT_FREQUENCY_A].write = frequency_port_write;
 	context.proc->port_handlers[PORT_FREQUENCY_B].write = frequency_port_write;
 	context.proc->port_handlers[PORT_FREQUENCY_C].write = frequency_port_write;