Caanoo / WIZ [Tutorial]Use The Snes9X For Dingux On Caanoo


Rikku2000

Member
Joined
Jul 2, 2010
Messages
348
[Tutorial]Use the SNES9X for DINGUX on CAANOO

/* ===================================(caanoo.h) */

- First we create a new file to add the CAANOO Key-mapping.
- Filename: "caanoo.h"

Code:
/*
	Caanoo Keys
*/

#define CAANOO_BUTTON_A             0
#define CAANOO_BUTTON_X             1
#define CAANOO_BUTTON_B             2
#define CAANOO_BUTTON_Y             3
#define CAANOO_BUTTON_L             4
#define CAANOO_BUTTON_R             5
#define CAANOO_BUTTON_START         6
#define CAANOO_BUTTON_SELECT        9
#define CAANOO_BUTTON_UP            11
#define CAANOO_BUTTON_DOWN          12
#define CAANOO_BUTTON_LEFT          13
#define CAANOO_BUTTON_RIGHT         14

/* =================================== */

/* ===================================(keydef.h) */

- Now we Change the keydef.h

Replace:
Code:
#define A_1 0
#define B_1 1
#define X_1 2
#define Y_1 3
#define L_1 4
#define R_1 5
#define A_2 6
#define B_2 7
#define X_2 8
#define Y_2 9
#define L_2 10
#define R_2 11
#define START_1 12
#define SELECT_1 13
#define START_2 14
#define SELECT_2 15
#define UP_1 16
#define DOWN_1 17
#define LEFT_1 18
#define RIGHT_1 19
#define UP_2 20
#define DOWN_2 21
#define LEFT_2 22
#define RIGHT_2 23
#define LU_2 24
#define LD_2 25
#define RU_2 26
#define RD_2 27

#define ACCEL 50
#define QUIT 51
#define HELP 52

#define SHIFTL 30
#define SHIFTR 31
#define CTRLL 32
#define CTRLR 33
with:
Code:
#define A_1 0
#define X_1 1
#define B_1 2
#define Y_1 3
#define L_1 4
#define R_1 5
#define START_1 6
#define SELECT_1 9
#define UP_1 11
#define DOWN_1 12
#define LEFT_1 13
#define RIGHT_1 14

#define ACCEL 50
#define QUIT 51
#define HELP 52

#define SHIFTL 30
#define SHIFTR 31
#define CTRLL 32
#define CTRLR 33

/* =================================== */

/* ===================================(unix.cpp) */

- Now we edit the Header Files.

Replace:
Code:
#include "dingoo.h"
with
Code:
#include "caanoo.h"

- Find the: "keyssnes" and we change the KEY SNES to Joystick SNES

Replace:
Code:
uint8 *keyssnes;
with
Code:
SDL_Joystick* keyssnes;

- Now go to S9xInitInputDevices and replace her this

Replace:
Code:
void S9xInitInputDevices () {
	memset(sfc_key, 0, 256);
	sfc_key[QUIT] = SDLK_a;

	sfc_key[A_1] = DINGOO_BUTTON_A;
	sfc_key[B_1] = DINGOO_BUTTON_B;
	sfc_key[X_1] = DINGOO_BUTTON_X;
	sfc_key[Y_1] = DINGOO_BUTTON_Y;
	sfc_key[L_1] = DINGOO_BUTTON_L;
	sfc_key[R_1] = DINGOO_BUTTON_R;
	sfc_key[START_1] = DINGOO_BUTTON_START;
	sfc_key[SELECT_1] = DINGOO_BUTTON_SELECT;
	sfc_key[LEFT_1] = DINGOO_BUTTON_LEFT;
	sfc_key[RIGHT_1] = DINGOO_BUTTON_RIGHT;
	sfc_key[UP_1] = DINGOO_BUTTON_UP;
	sfc_key[DOWN_1] = DINGOO_BUTTON_DOWN;

	sfc_key[LEFT_2] = SDLK_g;
	sfc_key[RIGHT_2] = SDLK_j;
	sfc_key[UP_2] = SDLK_u;
	sfc_key[DOWN_2] = SDLK_n;
	sfc_key[LU_2] = SDLK_y;
	sfc_key[LD_2] = SDLK_b;
	sfc_key[RU_2] = SDLK_i;
	sfc_key[RD_2] = SDLK_m;

	sfc_key[QUIT] = SDLK_d;
	sfc_key[ACCEL] = SDLK_u;

	int i = 0;
	char *envp, *j;
	envp = j = getenv ("S9XKEYS");
	if (envp) {
		do {
			if (j = strchr(envp, ','))
				*j = 0;
			if (i == 0) sfc_key[QUIT] = atoi(envp);
			else if (i == 1)  sfc_key[A_1] = atoi(envp);
			else if (i == 2)  sfc_key[B_1] = atoi(envp);
			else if (i == 3)  sfc_key[X_1] = atoi(envp);
			else if (i == 4)  sfc_key[Y_1] = atoi(envp);
			else if (i == 5)  sfc_key[L_1] = atoi(envp);
			else if (i == 6)  sfc_key[R_1] = atoi(envp);
			else if (i == 7)  sfc_key[START_1] = atoi(envp);
			else if (i == 8)  sfc_key[SELECT_1] = atoi(envp);
			else if (i == 9)  sfc_key[LEFT_2] = atoi(envp);
			else if (i == 10) sfc_key[RIGHT_2] = atoi(envp);
			else if (i == 11) sfc_key[UP_2] = atoi(envp);
			else if (i == 12) sfc_key[DOWN_2] = atoi(envp);
			else if (i == 13) sfc_key[LU_2] = atoi(envp);
			else if (i == 14) sfc_key[LD_2] = atoi(envp);
			else if (i == 15) sfc_key[RU_2] = atoi(envp);
			else if (i == 16) sfc_key[RD_2] = atoi(envp);
			envp = j + 1;
			++i;
		} while(j);
	}
}
with:
Code:
void S9xInitInputDevices () {
	memset(sfc_key, 0, 256);
	sfc_key[QUIT] = SDLK_a;
	sfc_key[A_1] = CAANOO_BUTTON_A;
	sfc_key[B_1] = CAANOO_BUTTON_B;
	sfc_key[X_1] = CAANOO_BUTTON_X;
	sfc_key[Y_1] = CAANOO_BUTTON_Y;
	sfc_key[L_1] = CAANOO_BUTTON_L;
	sfc_key[R_1] = CAANOO_BUTTON_R;
	sfc_key[START_1] = CAANOO_BUTTON_START;
	sfc_key[SELECT_1] = CAANOO_BUTTON_SELECT;
	sfc_key[LEFT_1] = CAANOO_BUTTON_LEFT;
	sfc_key[RIGHT_1] = CAANOO_BUTTON_RIGHT;
	sfc_key[UP_1] = CAANOO_BUTTON_UP;
	sfc_key[DOWN_1] = CAANOO_BUTTON_DOWN;

	sfc_key[QUIT] = SDLK_d;
	sfc_key[ACCEL] = SDLK_u;

	int i = 0;
	char *envp, *j;
	envp = j = getenv ("S9XKEYS");
	if (envp) {
		do {
			if (j = strchr(envp, ','))
				*j = 0;
			if (i == 0) sfc_key[QUIT] = atoi(envp);
			else if (i == 1)  sfc_key[A_1] = atoi(envp);
			else if (i == 2)  sfc_key[B_1] = atoi(envp);
			else if (i == 3)  sfc_key[X_1] = atoi(envp);
			else if (i == 4)  sfc_key[Y_1] = atoi(envp);
			else if (i == 5)  sfc_key[L_1] = atoi(envp);
			else if (i == 6)  sfc_key[R_1] = atoi(envp);
			else if (i == 7)  sfc_key[START_1] = atoi(envp);
			else if (i == 8)  sfc_key[SELECT_1] = atoi(envp);
			envp = j + 1;
			++i;
		} while(j);
	}
}

- Now

Find: void S9xProcessEvents (bool8_32 block)

Replace:
Code:
void S9xProcessEvents (bool8_32 block) {
	SDL_Event event;

	while(SDL_PollEvent(&event)) {
		switch(event.type) {
		case SDL_KEYDOWN:
			keyssnes = SDL_GetKeyState(NULL);

			if ((keyssnes[sfc_key[SELECT_1]] == SDL_PRESSED) && (keyssnes[sfc_key[START_1]] == SDL_PRESSED) && (keyssnes[sfc_key[B_1]] == SDL_PRESSED))
				S9xReset();
			else if ( (keyssnes[sfc_key[SELECT_1]] == SDL_PRESSED) &&(keyssnes[sfc_key[START_1]] == SDL_PRESSED) && (keyssnes[sfc_key[X_1]] == SDL_PRESSED) )
				S9xExit();
			else if ( (keyssnes[sfc_key[START_1]] == SDL_PRESSED) && (keyssnes[sfc_key[R_1]] == SDL_PRESSED) ) {
				char fname[256], ext[20];
				gp2x_sound_volume(0, 0);
				sprintf(ext, ".00%d", SaveSlotNum);
				strcpy(fname, S9xGetFilename (ext));
				S9xFreezeGame (fname);
				capt_screenshot();
				sprintf(ext, ".s0%d", SaveSlotNum);
				strcpy(fname, S9xGetFilename (ext));
				save_screenshot(fname);
				gp2x_sound_volume(vol, vol);
			} else if ( (keyssnes[sfc_key[START_1]] == SDL_PRESSED) && (keyssnes[sfc_key[L_1]] == SDL_PRESSED) ) {
				char fname[256], ext[8];
				gp2x_sound_volume(0, 0);
				sprintf(ext, ".00%d", SaveSlotNum);
				strcpy(fname, S9xGetFilename (ext));
				S9xLoadSnapshot (fname);
				gp2x_sound_volume(vol, vol);
			} else if ((keyssnes[sfc_key[SELECT_1]] == SDL_PRESSED)&&(keyssnes[sfc_key[B_1]] == SDL_PRESSED) ) {
				gp2x_sound_volume(0, 0);
				menu_loop();
				gp2x_sound_volume(vol, vol);
			}
			break;
		case SDL_KEYUP:
			keyssnes = SDL_GetKeyState(NULL);
		}
	}
}
with:
Code:
void S9xProcessEvents (bool8_32 block) {
	SDL_Event event;

	while(SDL_PollEvent(&event)) {
		switch (event.type) {
			keyssnes = SDL_JoystickOpen(0);

			case SDL_JOYBUTTONDOWN:
				switch(event.jbutton.button) {
					if (SDL_JoystickGetButton(keyssnes, 9) && SDL_JoystickGetButton(keyssnes, 6) && SDL_JoystickGetButton(keyssnes, 2))
						S9xReset();
					/* My Crap in here ... */
				}
			break;

			case SDL_JOYBUTTONUP:
				switch(event.jbutton.button) {
				}
			break;
		}
	}
}

Find: uint32 S9xReadJoypad (int which1)

Replace:
Code:
uint32 S9xReadJoypad (int which1) {
	uint32 val=0x80000000;

	if (keyssnes[sfc_key[L_1]] == SDL_PRESSED)		val |= SNES_TL_MASK;
	if (keyssnes[sfc_key[R_1]] == SDL_PRESSED)		val |= SNES_TR_MASK;
	if (keyssnes[sfc_key[X_1]] == SDL_PRESSED)		val |= SNES_X_MASK;
	if (keyssnes[sfc_key[Y_1]] == SDL_PRESSED)		val |= SNES_Y_MASK;
	if (keyssnes[sfc_key[B_1]] == SDL_PRESSED)		val |= SNES_B_MASK;
	if (keyssnes[sfc_key[A_1]] == SDL_PRESSED)		val |= SNES_A_MASK;
	if (keyssnes[sfc_key[START_1]] == SDL_PRESSED)	val |= SNES_START_MASK;
	if (keyssnes[sfc_key[SELECT_1]] == SDL_PRESSED)	val |= SNES_SELECT_MASK;
	if (keyssnes[sfc_key[UP_1]] == SDL_PRESSED)		val |= SNES_UP_MASK;
	if (keyssnes[sfc_key[DOWN_1]] == SDL_PRESSED)	val |= SNES_DOWN_MASK;
	if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED)	val |= SNES_LEFT_MASK;
	if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED)	val |= SNES_RIGHT_MASK;
	if (keyssnes[sfc_key[UP_2]] == SDL_PRESSED)		val |= SNES_UP_MASK;
	if (keyssnes[sfc_key[DOWN_2]] == SDL_PRESSED)	val |= SNES_DOWN_MASK;
	if (keyssnes[sfc_key[LEFT_2]] == SDL_PRESSED)	val |= SNES_LEFT_MASK;
	if (keyssnes[sfc_key[RIGHT_2]] == SDL_PRESSED)	val |= SNES_RIGHT_MASK;
	if (keyssnes[sfc_key[LU_2]] == SDL_PRESSED)	val |= SNES_LEFT_MASK | SNES_UP_MASK;
	if (keyssnes[sfc_key[LD_2]] == SDL_PRESSED)	val |= SNES_LEFT_MASK | SNES_DOWN_MASK;
	if (keyssnes[sfc_key[RU_2]] == SDL_PRESSED)	val |= SNES_RIGHT_MASK | SNES_UP_MASK;
	if (keyssnes[sfc_key[RD_2]] == SDL_PRESSED)	val |= SNES_RIGHT_MASK | SNES_DOWN_MASK;
	return(val);
}
with:
Code:
uint32 S9xReadJoypad (int which1) {
	uint32 val=0x80000000;

	if (SDL_JoystickGetButton(keyssnes, 4))				val |= SNES_TL_MASK;
	if (SDL_JoystickGetButton(keyssnes, 5))				val |= SNES_TR_MASK;
	if (SDL_JoystickGetButton(keyssnes, 1))				val |= SNES_X_MASK;
	if (SDL_JoystickGetButton(keyssnes, 3))				val |= SNES_Y_MASK;
	if (SDL_JoystickGetButton(keyssnes, 2))				val |= SNES_B_MASK;
	if (SDL_JoystickGetButton(keyssnes, 0))				val |= SNES_A_MASK;
	if (SDL_JoystickGetButton(keyssnes, 6))				val |= SNES_START_MASK;
	if (SDL_JoystickGetButton(keyssnes, 9))				val |= SNES_SELECT_MASK;
	if (SDL_JoystickGetAxis(keyssnes, 1) < -20000)		val |= SNES_UP_MASK;
	if (SDL_JoystickGetAxis(keyssnes, 1) > 20000)		val |= SNES_DOWN_MASK;
	if (SDL_JoystickGetAxis(keyssnes, 0) < -20000)		val |= SNES_LEFT_MASK;
	if (SDL_JoystickGetAxis(keyssnes, 0) > 20000)		val |= SNES_RIGHT_MASK;

	return(val);
}

/* =================================== */

/* ===================================(svga.cpp) */

- Now we edit the Header Files.

Replace:
Code:
#include "dingoo.h"
with
Code:
#include "caanoo.h"

- Find the: "keyssnes" and we change the KEY SNES to Joystick SNES

Replace:
Code:
extern uint8 *keyssnes;
with
Code:
extern SDL_Joystick* keyssnes;

Find: S9xInitDisplay

- In S9xInitDisplay find the SDL_INIT

Replace:
Code:
if (SDL_Init(SDL_INIT_VIDEO|(Settings.NextAPUEnabled ? SDL_INIT_AUDIO : 0)) < 0 ) {
with
Code:
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|(Settings.NextAPUEnabled ? SDL_INIT_AUDIO : 0)) < 0 ) {

- Now go some lines down

Replace:
Code:
keyssnes = SDL_GetKeyState(NULL);
with
Code:
keyssnes = SDL_JoystickOpen(0);

/* =================================== */

- So now we Have an simple SNES for CAANOO thats works fine

Download:
Binary
Source

Have FUN, Rikku2000
 
Hello,

Thanks for the tuto. Really good starting point to port snes9x.

But, which sources did you use?
I tried your method with both source packs I found for dingoo on openhandhelds, replacing compiler and libraries in the Makefile.
I tweaked it in many ways. I didn't manage to get it compiled.
Did I miss something?

Can you add an example of makefile you used to get a "simple SNES that works fine for CAANOO" or a link to the right sources to use?

The file that seems to trigger most compile errors is getset.h.
 
Great! Thanks for adding the sources, and the binary.

I will try it.

Thanks again for sharing your work.
 
thanks, I had a little play with donkey kong country and seems to run smooth but when I got to the bonus stage it freezed up on me.
Looking forward to the full port for the caanoo :)
 
I just tried the alpha, got Super Metroid to run. :)
But I noticed you made Caanoo A = SNES A, the controls need to be like this.

SNES A = B
SNES B = X
SNES X = Y
SNES Y = A

Screw the labels, the button positions are more important.
Luckily Super Metroid has configurable controls.

Edit: Start is also mapped to the wrong button, II is select but Home is Start, why?
It should be I for Start, II for select, and Home for the emulator menu.
 
Hi,

I have a problem with the binary files.
When i execute them from the caanoo, it display please press select + x.
then i can't continue, event if i press on all keys, is it a bug ?
 
tinos21 said:
Hi,

I have a problem with the binary files.
When i execute them from the caanoo, it display please press select + x.
then i can't continue, event if i press on all keys, is it a bug ?


me too!

EDIT: oh seems to work now lol! home button is start. can you access a menu or change games? i changed the game to mario all stars by renaming the one that came with the emu
 
Last edited by a moderator:
paul3100 said:
me too!

EDIT: oh seems to work now lol! home button is start. can you access a menu or change games? i changed the game to mario all stars by renaming the one that came with the emu

It's ok for me i changed the game (and gpe files), and after the game started.
 
Last edited by a moderator:
omg this is not for using this is just en tutorial the snes works but better wait for a better version...
 
i just download the snes binary. i created a .ini file. after that i load the snes emulator, and secret of mana load and no buttons are working.

where is the rom launcher ? why the buttons dont work ?


thanks for answer. i went here because i dont see the snes emu in the download section
 
renejr902 said:
i just download the snes binary. i created a .ini file. after that i load the snes emulator, and secret of mana load and no buttons are working.

where is the rom launcher ? why the buttons dont work ?


thanks for answer. i went here because i dont see the snes emu in the download section

I think this was ment more as a tutorial and not a full port !!! You can easily change things yourselve if they are not emulation specific...
 
Last edited by a moderator:
Back
Top