# HG changeset patch # User John Tsiombikas # Date 1498260832 -10800 # Node ID ca7108a828675845ed1eb46158c84f66fe9556b4 # Parent 6ecf2f3ff05ad732c09d8995332d1e037d2d2b40 fixed gamepad input on real megadrive diff -r 6ecf2f3ff05a -r ca7108a82867 src/debug.c --- a/src/debug.c Sat Jun 24 00:33:10 2017 +0300 +++ b/src/debug.c Sat Jun 24 02:33:52 2017 +0300 @@ -1,17 +1,29 @@ #include "debug.h" #include "dbgfont.h" +#include "vdp.h" -static int init_done; +static uint16_t dbgpal[] = { + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(7, 0, 0), + VDP_PACK_RGB(0, 7, 0), VDP_PACK_RGB(0, 0, 7), + VDP_PACK_RGB(7, 7, 0), VDP_PACK_RGB(7, 0, 7), + VDP_PACK_RGB(0, 7, 7), VDP_PACK_RGB(7, 7, 7), + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(3, 0, 0), + VDP_PACK_RGB(0, 3, 0), VDP_PACK_RGB(0, 0, 3), + VDP_PACK_RGB(3, 3, 0), VDP_PACK_RGB(3, 0, 3), + VDP_PACK_RGB(0, 3, 3), VDP_PACK_RGB(3, 3, 3) +}; -static void init_font(void) +void dbg_init(void) { + int i; /* TODO allocate tiles, prepare palette etc */ + + vdp_begin_palette(DBG_PALIDX, 0); + for(i=0; i<16; i++) { + VDP_PORT_DATA = dbgpal[i]; + } } void dbg_print(const char *s) { - if(!init_done) { - init_font(); - init_done = 1; - } } diff -r 6ecf2f3ff05a -r ca7108a82867 src/debug.h --- a/src/debug.h Sat Jun 24 00:33:10 2017 +0300 +++ b/src/debug.h Sat Jun 24 02:33:52 2017 +0300 @@ -1,6 +1,9 @@ #ifndef MD_DEBUG_H_ #define MD_DEBUG_H_ +#define DBG_PALIDX 3 + +void dbg_init(void); void dbg_print(const char *s); #endif /* MD_DEBUG_H_ */ diff -r 6ecf2f3ff05a -r ca7108a82867 src/io.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/io.c Sat Jun 24 02:33:52 2017 +0300 @@ -0,0 +1,10 @@ +#include "io.h" + +void io_init(void) +{ + io_setdir(0, 0x40); + io_setdir(1, 0x40); + + IO_REG_DATA(0) = 0; + IO_REG_DATA(1) = 0; +} diff -r 6ecf2f3ff05a -r ca7108a82867 src/io.h --- a/src/io.h Sat Jun 24 00:33:10 2017 +0300 +++ b/src/io.h Sat Jun 24 02:33:52 2017 +0300 @@ -43,6 +43,8 @@ IO_PAD_A = 64, IO_PAD_START = 128 }; +#define IO_PAD_LOW_MASK 0x3f +#define IO_PAD_HIGH_MASK (IO_PAD_A | IO_PAD_START) static inline void io_setdir(int port, uint8_t dir) { @@ -53,12 +55,18 @@ { uint16_t bnstate; - io_setdir(port, 0x40); /* pin 6 (multiplexer) output, 0-5 inputs */ + bnstate = ~(IO_REG_DATA(port) << 2) & IO_PAD_HIGH_MASK; + IO_REG_DATA(port) = 0x40; /* select mode 1 */ - bnstate = IO_REG_DATA(port); + asm volatile("nop"); + asm volatile("nop"); + bnstate |= ~IO_REG_DATA(port) & IO_PAD_LOW_MASK; + IO_REG_DATA(port) = 0; /* select mode 0 */ - bnstate |= (IO_REG_DATA(port) << 2) & (IO_PAD_A | IO_PAD_START); - return ~bnstate; + return bnstate; } +void io_init(void); +/*uint16_t io_readpad(int port);*/ + #endif /* MEGADRIVE_IO_H_ */ diff -r 6ecf2f3ff05a -r ca7108a82867 src/main.c --- a/src/main.c Sat Jun 24 00:33:10 2017 +0300 +++ b/src/main.c Sat Jun 24 02:33:52 2017 +0300 @@ -3,6 +3,7 @@ #include "io.h" #include "pad.h" #include "intr.h" +#include "debug.h" #include "tun_data.h" #define NAMETAB_A 6 @@ -27,12 +28,16 @@ VDP_PACK_RGB(7, 0, 3) /* 15: fixed */ }; +static uint16_t dbg; + int main(void) { int i, j; vdp_init(); + io_init(); + dbg_init(); if(IO_REG_VER & IO_VER_PAL) { vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) | VDP_MODE2_V30CELL); @@ -65,6 +70,7 @@ if(pad_pressed(0, IO_PAD_C)) { disable_intr(); vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) ^ VDP_MODE2_V30CELL); + vdp_set_bgcolor(DBG_PALIDX, ++dbg & 1); enable_intr(); }