megadrive_test2

changeset 10:ca7108a82867

fixed gamepad input on real megadrive
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 24 Jun 2017 02:33:52 +0300
parents 6ecf2f3ff05a
children 302bcd73edc4
files src/debug.c src/debug.h src/io.c src/io.h src/main.c
diffstat 5 files changed, 49 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/src/debug.c	Sat Jun 24 00:33:10 2017 +0300
     1.2 +++ b/src/debug.c	Sat Jun 24 02:33:52 2017 +0300
     1.3 @@ -1,17 +1,29 @@
     1.4  #include "debug.h"
     1.5  #include "dbgfont.h"
     1.6 +#include "vdp.h"
     1.7  
     1.8 -static int init_done;
     1.9 +static uint16_t dbgpal[] = {
    1.10 +	VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(7, 0, 0),
    1.11 +	VDP_PACK_RGB(0, 7, 0), VDP_PACK_RGB(0, 0, 7),
    1.12 +	VDP_PACK_RGB(7, 7, 0), VDP_PACK_RGB(7, 0, 7),
    1.13 +	VDP_PACK_RGB(0, 7, 7), VDP_PACK_RGB(7, 7, 7),
    1.14 +	VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(3, 0, 0),
    1.15 +	VDP_PACK_RGB(0, 3, 0), VDP_PACK_RGB(0, 0, 3),
    1.16 +	VDP_PACK_RGB(3, 3, 0), VDP_PACK_RGB(3, 0, 3),
    1.17 +	VDP_PACK_RGB(0, 3, 3), VDP_PACK_RGB(3, 3, 3)
    1.18 +};
    1.19  
    1.20 -static void init_font(void)
    1.21 +void dbg_init(void)
    1.22  {
    1.23 +	int i;
    1.24  	/* TODO allocate tiles, prepare palette etc */
    1.25 +
    1.26 +	vdp_begin_palette(DBG_PALIDX, 0);
    1.27 +	for(i=0; i<16; i++) {
    1.28 +		VDP_PORT_DATA = dbgpal[i];
    1.29 +	}
    1.30  }
    1.31  
    1.32  void dbg_print(const char *s)
    1.33  {
    1.34 -	if(!init_done) {
    1.35 -		init_font();
    1.36 -		init_done = 1;
    1.37 -	}
    1.38  }
     2.1 --- a/src/debug.h	Sat Jun 24 00:33:10 2017 +0300
     2.2 +++ b/src/debug.h	Sat Jun 24 02:33:52 2017 +0300
     2.3 @@ -1,6 +1,9 @@
     2.4  #ifndef MD_DEBUG_H_
     2.5  #define MD_DEBUG_H_
     2.6  
     2.7 +#define DBG_PALIDX	3
     2.8 +
     2.9 +void dbg_init(void);
    2.10  void dbg_print(const char *s);
    2.11  
    2.12  #endif	/* MD_DEBUG_H_ */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/io.c	Sat Jun 24 02:33:52 2017 +0300
     3.3 @@ -0,0 +1,10 @@
     3.4 +#include "io.h"
     3.5 +
     3.6 +void io_init(void)
     3.7 +{
     3.8 +	io_setdir(0, 0x40);
     3.9 +	io_setdir(1, 0x40);
    3.10 +
    3.11 +	IO_REG_DATA(0) = 0;
    3.12 +	IO_REG_DATA(1) = 0;
    3.13 +}
     4.1 --- a/src/io.h	Sat Jun 24 00:33:10 2017 +0300
     4.2 +++ b/src/io.h	Sat Jun 24 02:33:52 2017 +0300
     4.3 @@ -43,6 +43,8 @@
     4.4  	IO_PAD_A		= 64,
     4.5  	IO_PAD_START	= 128
     4.6  };
     4.7 +#define IO_PAD_LOW_MASK		0x3f
     4.8 +#define IO_PAD_HIGH_MASK	(IO_PAD_A | IO_PAD_START)
     4.9  
    4.10  static inline void io_setdir(int port, uint8_t dir)
    4.11  {
    4.12 @@ -53,12 +55,18 @@
    4.13  {
    4.14  	uint16_t bnstate;
    4.15  
    4.16 -	io_setdir(port, 0x40);		/* pin 6 (multiplexer) output, 0-5 inputs */
    4.17 +	bnstate = ~(IO_REG_DATA(port) << 2) & IO_PAD_HIGH_MASK;
    4.18 +
    4.19  	IO_REG_DATA(port) = 0x40;	/* select mode 1 */
    4.20 -	bnstate = IO_REG_DATA(port);
    4.21 +	asm volatile("nop");
    4.22 +	asm volatile("nop");
    4.23 +	bnstate |= ~IO_REG_DATA(port) & IO_PAD_LOW_MASK;
    4.24 +
    4.25  	IO_REG_DATA(port) = 0;		/* select mode 0 */
    4.26 -	bnstate |= (IO_REG_DATA(port) << 2) & (IO_PAD_A | IO_PAD_START);
    4.27 -	return ~bnstate;
    4.28 +	return bnstate;
    4.29  }
    4.30  
    4.31 +void io_init(void);
    4.32 +/*uint16_t io_readpad(int port);*/
    4.33 +
    4.34  #endif	/* MEGADRIVE_IO_H_ */
     5.1 --- a/src/main.c	Sat Jun 24 00:33:10 2017 +0300
     5.2 +++ b/src/main.c	Sat Jun 24 02:33:52 2017 +0300
     5.3 @@ -3,6 +3,7 @@
     5.4  #include "io.h"
     5.5  #include "pad.h"
     5.6  #include "intr.h"
     5.7 +#include "debug.h"
     5.8  #include "tun_data.h"
     5.9  
    5.10  #define NAMETAB_A	6
    5.11 @@ -27,12 +28,16 @@
    5.12  	VDP_PACK_RGB(7, 0, 3)		/* 15: fixed */
    5.13  };
    5.14  
    5.15 +static uint16_t dbg;
    5.16 +
    5.17  
    5.18  int main(void)
    5.19  {
    5.20  	int i, j;
    5.21  
    5.22  	vdp_init();
    5.23 +	io_init();
    5.24 +	dbg_init();
    5.25  
    5.26  	if(IO_REG_VER & IO_VER_PAL) {
    5.27  		vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) | VDP_MODE2_V30CELL);
    5.28 @@ -65,6 +70,7 @@
    5.29  		if(pad_pressed(0, IO_PAD_C)) {
    5.30  			disable_intr();
    5.31  			vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) ^ VDP_MODE2_V30CELL);
    5.32 +			vdp_set_bgcolor(DBG_PALIDX, ++dbg & 1);
    5.33  			enable_intr();
    5.34  		}
    5.35