implementing new function plz help

Strictly for discussing ZSNES development and for submitting code. You can also join us on IRC at irc.libera.chat in #zsnes.
Please, no requests here.

Moderator: ZSNES Mods

Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

implementing new function plz help

Post by Dolphin »

I wrote a function in C, and want to implement it into zsnes, I know where to put the function judging by the comments and variable names.

I don't know assambly(I lied I know a little bit ;)), anyway, How may I implement this function into the assembly file.

heres the form of my function
pointer, pointer, pointer, pointer, pointer, pointer, pointer, pointer, pointer, pointer, pointer, pointer

I could use one pointer but depending on the answer to this question:

are the variables that hold if a button is pressed or not consecutive in memory?
if yes I can make it one pointer yepi :)

There is 1 pointer declared in my C file that may be usefull for implementing into the GUI. I want to implement this function into cfgload.asm.

Any help is apreciated.

Thanks in advance!
Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

I implemented the function. Now I need to edit the makefile(s)

I have one C file and the rest of the code is directly implemented in the zsnes asm file(cfgload).

Now how may I edit the makefile(s) so I can test to see how well my implimentation works?

Thanks in advance!
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

Open the make file with DOS Edit, Notepad, or KEdit depending on your OS. Make sure you are also editing the makefile for your OS.

Next just add the name of your new file to the section on top for all object files to create, and the section on the bottom for which file to create the object file from.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
Malcster
Hazed
Posts: 72
Joined: Wed Jul 28, 2004 7:30 pm

Post by Malcster »

Dolphin: any update on this? Did the edit I did for you yesterday work?
Magus`
Cap'n Gin | Admin
Posts: 194
Joined: Tue Jul 27, 2004 10:59 pm
Location: Missouri

Re: implementing new function plz help

Post by Magus` »

Dolphin wrote:I wrote a function in C, and want to implement it into zsnes, I know where to put the function judging by the comments and variable names.

I don't know assambly(I lied I know a little bit ;)), anyway, How may I implement this function into the assembly file.

heres the form of my function
pointer, pointer, pointer, pointer, pointer, pointer, pointer, pointer, pointer, pointer, pointer, pointer

I could use one pointer but depending on the answer to this question:

are the variables that hold if a button is pressed or not consecutive in memory?
if yes I can make it one pointer yepi :)

There is 1 pointer declared in my C file that may be usefull for implementing into the GUI. I want to implement this function into cfgload.asm.

Any help is apreciated.

Thanks in advance!

Huh?
Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

Malcster wrote:Dolphin: any update on this? Did the edit I did for you yesterday work?
Yeah, Thanks very much Malcster for you help.

I fixed a bug in my snes_probe function wich trys litteraly all combinations to find a snes joystick in accessible parrallelports, It knows if anoth :). There is about 150 diferent combinations, and it takes around 12milliseconds to do this 5 times (5 joysticks).

The file cfgload.asm is not the right file I should be dealling with but its execute.asm. Which is better because I can now port my functions to windows98 much more easily(not NT, NT I'll have to build a driver and buy MS projects to do so.)

I just need to know where the information for the snes buttons are stored.
Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

Dolphin wrote:
Malcster wrote:Dolphin: any update on this? Did the edit I did for you yesterday work?
Yeah, Thanks very much Malcster for you help.

I fixed a bug in my snes_probe function wich trys litteraly all combinations to find a snes joystick in accessible parrallelports, It knows if another driver is using that port because it won't be accessible :). There is about 150 diferent combinations, and it takes around 12milliseconds to do this 5 times (5 joysticks).

The file cfgload.asm is not the right file I should be dealling with but its execute.asm. Which is better because I can now port my functions to windows98 much more easily(not NT, NT I'll have to build a driver and buy MS projects to do so.)

I just need to know where the information for the snes buttons are stored.
Edit: I ment to click edit but I clicked post reply accidently. I really should pay attention where I click ;)
Magus`
Cap'n Gin | Admin
Posts: 194
Joined: Tue Jul 27, 2004 10:59 pm
Location: Missouri

Post by Magus` »

I still don't understand what the hell you said in your first post.
Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

The first post doesn't matter anymore because I got it resolved. I just need to know which variable(s) in zsnes source code hold(s) information, if a button is pressed or not on the snes remote to be emulated.

e.g. lets say you on your keyboard you set 'A' to be emulated as 'B' on the snes joystick, I need to know what variable holds if 'B' is pressed or not. And aslo the other buttons on the joystick (if any). All information of the buttons can be stored in one WORD(16bit value), DWORD(32bit value) is recommended to be used for speed. It also could be stored in multiple bytes etc...
Radio

Post by Radio »

It was poorly worded but I could still understand it. Magus` is just in way over his head.
badinsults
"Your thread will be crushed."
Posts: 1236
Joined: Wed Jul 28, 2004 1:49 am
Location: Not in Winnipeg
Contact:

Post by badinsults »

Magus` isn't a developer. Neither am I. No wonder it doesn't mean anything to us.
<pagefault> i'd break up with my wife if she said FF8 was awesome
Malcster
Hazed
Posts: 72
Joined: Wed Jul 28, 2004 7:30 pm

Post by Malcster »

Dolphin wrote:Yeah, Thanks very much Malcster for you help.
No problem, glad to have helped.
Dolphin wrote:I just need to know where the information for the snes buttons are stored.
I'm afraid I can't help at all on that.. my assembly knowledge is nill. It might be a good idea, now that you have added a feature which works, to contact pagefault or Nach with the changes so he can possibly put them in CVS.
Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

I have succeeded yepi :).

Now zsnes has these new features:

Automatic detect of how a joystick is connected to parallel port (Not 100% successfull but works for most of the combinations)

Direct access to snes joystick on parallelport (Remains high refresh rate)

Featurns that I need someone to program:

A window to edit settings for my implimentation

Bugs:
None ;)

Before I give things I need to do:
Remove all my debuging code ;)
make my code look neat 8)

Finnal things I need to know
How to give the update. I used the source code not from WIP page so I don't know how it will be updated. and How should I send it, with instructiosn to copy and paste piece by piece(about 4 copy & pastes will do ;)) This is my first patch to zsnes :!:
neviksti
Lurker
Posts: 122
Joined: Thu Jul 29, 2004 6:15 am

Post by neviksti »

Dolphin wrote:Direct access to snes joystick on parallelport (Remains high refresh rate)
??
Sorry, but can you clarify.
Does this mean that if you have a snes port <-> parallel port connection that SNES programs see a "real" snes port ... ie we can use a multitap, or a snes mouse?
Can a SNES program now use the "manual read" method, or just the "auto joyread" method?
Dolphin wrote:Which is better because I can now port my functions to windows98 much more easily(not NT, NT I'll have to build a driver and buy MS projects to do so.)
You don't need anything from MS if you just want I/O port access (which is all you should need here). There are several free drivers that coders can use for this. I've never tried them since I use Win98 (or XP with port access enabled), so I'll just quote the ucon64 FAQ:

"You could use a driver like GiveIO, UserPort, io.dll or inpout32.dll. At http://www.devrs.com/gba/files/mbv2faqs.php#WinXP you can find links to GiveIO and UserPort. You can find io.dll in a file named io.zip at http://www.geekhideout.com/iodll.shtml and you can find inpout32.dll in a file named inpout32_source_and_bins.zip at http://www.logix4u.net. GiveIO is plainly horrible to configure. We recommend UserPort, io.dll and inpout32.dll. ... With GiveIO [port access] seems to go a bit faster than with UserPort, but UserPort is much easier to use."
Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

Sorry, but can you clarify.
Does this mean that if you have a snes port <-> parallel port connection that SNES programs see a "real" snes port ... ie we can use a multitap, or a snes mouse?
Can a SNES program now use the "manual read" method, or just the "auto joyread" method?
I don't think the mouse or other snes devices will work, I don't know how these devices work so I can't implement them.

There are many devices that allow you to connect your snes to parallel port. The most common is direct input, The least common and more expensive ones tend to allow more than 5 joysticks, but this way direct communication to snes joystick(s) from a running driver installed is not possible.

When I submit it, just try and see if it works for you.
Malcster
Hazed
Posts: 72
Joined: Wed Jul 28, 2004 7:30 pm

Post by Malcster »

Dolphin wrote: A window to edit settings for my implimentation
That could well be the tricky part, since it's all in assembly. Nach has coded some new windows in recently, but he's fairly busy right now.

Get in touch with pagefault about submitting the fix, and tell him the specifics of what files are changed etc.
neviksti
Lurker
Posts: 122
Joined: Thu Jul 29, 2004 6:15 am

Post by neviksti »

Dolphin wrote:I don't think the mouse or other snes devices will work, I don't know how these devices work so I can't implement them.
If you have "direct access" to the snes port ... then you don't need to understand the data the devices return, the snes program will handle that.

You didn't answer my question about "manual read" vs. "auto-joy read". ie. does reading/writing to $4016 and $4017 work correctly now? (Did it already and I wasn't aware of it?)
Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

neviksti wrote:
Dolphin wrote:I don't think the mouse or other snes devices will work, I don't know how these devices work so I can't implement them.
If you have "direct access" to the snes port ... then you don't need to understand the data the devices return, the snes program will handle that.
If the a snes program does that data flow then the snes program is communicating directly. If my implementation would talk to the snes program then zsnes does not have direct access, its using a third party program/dll. Direct access is communicateing directly with no third party dll's, programs or anything like that. Not many people do direct accessing because its very difficault, thats why there are drivers.
You didn't answer my question about "manual read" vs. "auto-joy read". ie. does reading/writing to $4016 and $4017 work correctly now? (Did it already and I wasn't aware of it?)
I don't understand what you mean by "manual read" vs. "auto-joy read".
neviksti
Lurker
Posts: 122
Joined: Thu Jul 29, 2004 6:15 am

Post by neviksti »

Dolphin wrote:If the a snes program does that data flow then the snes program is communicating directly. If my implementation would talk to the snes program then zsnes does not have direct access, its using a third party program/dll. Direct access is communicateing directly with no third party dll's, programs or anything like that. Not many people do direct accessing because its very difficault, thats why there are drivers.
Sorry, I'm not understanding. But I gather that you're saying "No, the access is not direct. The program just reads the data and returns the value which zsnes then uses." Is this correct?

So this was just a mis-type?
Dolphin wrote:Direct access to snes joystick on parallelport (Remains high refresh rate)
Dolphin wrote:I don't understand what you mean by "manual read" vs. "auto-joy read".
The SNES ports are designed to transfer data serially. This wastes CPU time to read and shift in every byte, so if the programmer wants, the SNES contains a peripheral that will read the first 16bits from the ports and save the results. This is "auto-joyread".

To access more than 16bits, or just to access the port manually, you can read/write to $4016 or $4017 to access the port.
Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

Sorry, I'm not understanding. But I gather that you're saying "No, the access is not direct. The program just reads the data and returns the value which zsnes then uses." Is this correct?
My implemintation does direct access when you said
If you have "direct access" to the snes port ... then you don't need to understand the data the devices return, the snes program will handle that.
You said that "the snes program will handle that" are you reffering to a third party program? thats what I thought.

The numbers 4016/4017, thats not the parallel port, the parallel port is located at 378h, 278h, 3BC windows gives them a name lpt1, lpt2, lpt3 respectfully.
To access more than 16bits, or just to access the port manually, you can read/write to $4016 or $4017 to access the port.
Thats what I do to access the ports manually, You cannot access more than 16bits, after accessing the 16bits if more bits are tryed to access then the controler requires a restart. The first time accessing the bits will recieve 0xFFFFFFFF if its something else then thats not a snes joystick.
The SNES ports are designed to transfer data serially. This wastes CPU time to read and shift in every byte, so if the programmer wants, the SNES contains a peripheral that will read the first 16bits from the ports and save the results. This is "auto-joyread".
So, a modern PC/laptop is much much more faster than a snes. Anyway I check it every 16milliseconds just like the actuall SNES.
neviksti
Lurker
Posts: 122
Joined: Thu Jul 29, 2004 6:15 am

Post by neviksti »

I'm sorry, we appear to be having communication problems. Since I keep failing, maybe someone can better explain what I mean by direct access.

The whole point of direct access is that the emulated SNES program sees what looks like the real SNES port. It can then read/write to it however it wants. This also means you don't need to worry what is connected to it (mouse, multitap, controller, whatever). Since the parallel port <-> snes port device should already allow control of the lines on the "snes port", direct access should not be hard to implement (once you know what parallel port pins connect to which snes port pin).
Dolphin wrote:The numbers 4016/4017, thats not the parallel port, the parallel port is located at 378h, 278h, 3BC windows gives them a name lpt1, lpt2, lpt3 respectfully.
No, the addresses $4016 / $4017 were referring to SNES addresses. These are what a SNES program can read/write to for manual communication on the SNES port.
Dolphin wrote:
To access more than 16bits, or just to access the port manually, you can read/write to $4016 or $4017 to access the port.
Thats what I do to access the ports manually, You cannot access more than 16bits, after accessing the 16bits if more bits are tryed to access then the controler requires a restart. The first time accessing the bits will recieve 0xFFFFFFFF if its something else then thats not a snes joystick.
You are talking about a specific device, not the port itself. You can read as many bits as you want from the port. Reading more than 16bits is often necessary. In particular, to use the mouse you will have to read more than 16bits. As well as with the multitap.
Dolphin wrote:
The SNES ports are designed to transfer data serially. This wastes CPU time to read and shift in every byte, so if the programmer wants, the SNES contains a peripheral that will read the first 16bits from the ports and save the results. This is "auto-joyread".
So, a modern PC/laptop is much much more faster than a snes. Anyway I check it every 16milliseconds just like the actuall SNES.
I'm sorry there is so much miscommunication. I'm obviously not explaining things well.

The CPU time I am referring to is CPU time on the SNES. The snes cpu was clocked fairly slowly, so reading in data serially did take a decent amount of time. This is why Nintendo included hardware in the console that would automatically read the first 16bits for the programmer if they enabled it. This method of reading data through the port I refer to as "auto-joyread".

However, that is not the only way to read data from the port. As mentioned above, a snes program can access the port manually by reading/writing to $4016 / $4017.

The fact that you read the data yourself and then supply it to zsnes every 16ms tells me that you are only supporting the "auto-joyread" method, and not the "manual read" method.

Does this make more sense now?

EDIT: Since ZSNES is supplied with the joypad data, it can use that to emulate both the auto-joyread and manual read methods for a joypad. But the snes program isn't actually given manual access to the port. If you have the real hardware, you shouldn't have to emulate it. I definitely feel direct access is the way to go here. (Especially since it automatically supports more devices then.)
Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

A few questions, what do you mean by "snes port", and "snes program".

I just took some wires and connected my joystick to where the printer usually goes(Parallel port).

If you want to, you may see my source code, many of your questions may be answered there. PM me and I'll send my source code.
Noxious Ninja
Dark Wind
Posts: 1271
Joined: Thu Jul 29, 2004 8:58 pm
Location: Texas
Contact:

Post by Noxious Ninja »

SNES Port - the gamepad connector.
SNES Program - an emulator.

Basicall, if your driver + connector gives direct access to the gamepad, zSNES can just treat it like a real port on the SNES.
[u][url=http://bash.org/?577451]#577451[/url][/u]
Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

Heres the code

Code: Select all

#include "snesf.h"
#ifdef __LINUX__
#include <sys/io.h>
#include <asm/current.h>
#include <time.h>

#define elapsed (clock())
#else
#define outb(a,b) _outp(b,a)
#define inb(a) _inp(a)
int ioperm(int p, int c, int i)
{
	outb(0, p);
	return 0;
}

#define elapsed GetTickCount()
#endif

#define uchar unsigned char



struct snes_remote snes_1;
struct snes_remote snes_2;
struct snes_remote snes_3;
struct snes_remote snes_4;
struct snes_remote snes_5;

int mjoys;
int using_snes_joys;
int timesp;
unsigned long lasttime_checked_snes;
unsigned long delay_between_snescheck;

int sincelast_snes_check()
{
	return (elapsed - lasttime_checked_snes);
}
int snprint()
{
	printf("************************************************\n %d\n************************************************", timesp);
	timesp++;
	return 0;
}
int printnumber(int a)
{
	printf("%d\n", a);
	return 0;
}
int GetSnesJoyCount()
{
	return using_snes_joys;
}
unsigned long GetSnesbtns(unsigned long sn)
{
	int ret;
	ret = 0;
	switch(sn)
	{
	case 1:
		ret = ReadSnes(snes_5.base, snes_5.info); break;
	case 2:
		ret = ReadSnes(snes_4.base, snes_4.info); break;
	case 3:
		ret = ReadSnes(snes_3.base, snes_3.info); break;
	case 4:
		ret =ReadSnes(snes_2.base, snes_2.info); break;
	case 5:
		ret =ReadSnes(snes_1.base, snes_1.info); break;
	}
	lasttime_checked_snes = elapsed;
return ret;

}

unsigned long Snes_joyflush(unsigned long base, unsigned long info)
{
	unsigned long ret;
	int i;
	int ib;
#define outd(a,b) outb(a, b)
#define ind(a) inb(a)

	//outd(POWER(info), base);
	ib = 0;
	ib = ind(base+1);


	//outd((RESET(info) | POWER(info)),base);
	ret = 0;
	for(i = 0; i < 16; i++)
	{
		outd( POWER(info) | CLOCK(info), base);
		if(ind(base+1) != ib)
		{
			ret |= 1 << i;
		}
		outd(POWER(info), base);
	}

#undef ind
#undef outd
	return ret;
}

unsigned long FlushSnesbtns(int sn)
{
	switch(sn)
	{
	case 1:
		return Snes_joyflush(snes_1.base, snes_1.info);
	case 2:
		return Snes_joyflush(snes_2.base, snes_2.info);
	case 3:
		return Snes_joyflush(snes_3.base, snes_3.info);
	case 4:
		return Snes_joyflush(snes_4.base, snes_4.info);
	case 5:
		return Snes_joyflush(snes_5.base, snes_5.info);
	}
	return 0;
}

unsigned long ReadSnes(unsigned long base, unsigned long info)
{
	unsigned long ret;
	int i;
	int ib;
#define outd(a,b) outb(a, b)
#define ind(a) inb(a)

	//outd(POWER(info), base);
	ib = 0;
	ib = ind(base+1);


	outd((RESET(info) | POWER(info)),base);
	ret = 0;
	for(i = 0; i < 16; i++)
	{
		outd( POWER(info) | CLOCK(info), base);
		if(ind(base+1) != ib)
		{
			ret |= 1 << i;
		}
		outd(POWER(info), base);
	}

#undef ind
#undef outd
	return ret;


}

int GetPermition(int port)
{
	return ioperm(port, 2, 1);
}
int Snes_checkconflict(struct snes_remote *a, struct snes_remote *b)
{
	if(a->base == b->base)
	{
		if( RESET(a->info) == RESET(b->info))
			return 1;
		if(CLOCK(a->info) == CLOCK(b->info))
			return 1;

		if(CLOCK(a->info) == RESET(b->info))
			return 1;
	}
	return 0;
}
int Snes_checkconflicts(struct snes_remote *sr)
{
	if(Snes_checkconflict(sr, &snes_1)==1)
		return 1;
	if(Snes_checkconflict(sr, &snes_1)==1)
		return 2;
	if(Snes_checkconflict(sr, &snes_1)==1)
		return 3;
	if(Snes_checkconflict(sr, &snes_1)==1)
		return 4;
	if(Snes_checkconflict(sr, &snes_1)==1)
		return 5;

	return 0;
}
int snes_find(struct snes_remote *sr, int accept)
{
	
	sr->info = MK_SNESINFO(1,1,1);
	outb(0, sr->base);
	while(1)
	{
		if(POWER(sr->info) == (1 << 7))
			break;


		while(1)
		{
clockcheck:
			if(CLOCK(sr->info) == (1 << 7))
				break;
			if(CLOCK(sr->info) == POWER(sr->info))
			{
				sr->info = MK_SNESINFO(POWER(sr->info), (CLOCK(sr->info) << 1), 1);
				goto clockcheck;
			}
			while(1)
			{
checkit:
				if(RESET(sr->info) == CLOCK(sr->info))
				{
					sr->info = MK_SNESINFO(POWER(sr->info), CLOCK(sr->info), (RESET(sr->info) << 1));
					if(RESET(sr->info) == (1<<7))
						break;
				}

				if(RESET(sr->info) == POWER(sr->info))
				{
					sr->info = MK_SNESINFO(POWER(sr->info), CLOCK(sr->info), (RESET(sr->info) << 1));
					if(RESET(sr->info) == (1<<7))
						break;
					goto checkit;
				}
				outb(0, sr->base);
				//outb(POWER(sr->info), sr->base);
				if(ReadSnes(sr->base, sr->info) == 0xFFFF)
				{
					if(Snes_joyflush(sr->base, sr->info) != 0xFFFF)
						goto searchnextone;

					outb(0, sr->base);


					//if(Snes_joyflush(sr->base, sr->info) != 0xFFFF)
					//	goto searchnextone;



					outb(0, sr->base);


					if(ReadSnes(sr->base, sr->info) == 0xFFFF)
					{
						if(ReadSnes(sr->base, sr->info) == 0)
						{
							if(Snes_checkconflicts(sr) == accept || Snes_checkconflicts(sr) == 0)
							{
								outb(0, sr->base);
								outb(POWER(sr->info), sr->base);
								return 1;
							}
						}
					}
				}
				searchnextone:
				if(RESET(sr->info) == (1<<7))
					break;

				sr->info = MK_SNESINFO(POWER(sr->info), CLOCK(sr->info), ( RESET(sr->info)<<1));

			}
			sr->info = MK_SNESINFO(POWER(sr->info), (CLOCK(sr->info) << 1), 1);

		}
		sr->info = MK_SNESINFO((POWER(sr->info) << 1), 1, 1);
	}
	memset(sr, 0, sizeof(struct snes_remote));
	return 0;

}

int snes_probe(int port, int *left)
{
#define outp(a) outb(a, port)

		//outp(0);
		if(*left == 0)goto endit;

		if(*left == 5)
		{
			snes_1.base = port;
			snes_1.info = 0;
			if(snes_find(&snes_1, 1) == 1)
			{
				*left -=1;
				using_snes_joys += 1;
			}
			else
				return 1;
		}

		if(*left == 4)
		{
			snes_2.base = port;
			snes_2.info = 0;
			if(snes_find(&snes_2, 2)==1)
			{
				*left -=1;
				using_snes_joys += 1;
			}
			else
				return 0;
		}

		if(*left == 3)
		{
			snes_3.base = port;
			snes_3.info = 0;
			if(snes_find(&snes_3, 3)==1)
			{
				*left -=1;
				using_snes_joys += 1;
			}
			else
				return 0;
		}

		if(*left == 2)
		{
			snes_4.base = port;
			snes_4.info = 0;
			if(snes_find(&snes_4, 4)==1)
			{
				*left -=1;
				using_snes_joys += 1;
			}
			else
				return 0;
		}

		if(*left == 1)
		{
			snes_5.base = port;
			snes_5.info = 0;
			if(snes_find(&snes_5, 5)==1)
			{
				*left -=1;
				using_snes_joys += 1;
			}
			else
				return 0;
		}
		return 0;
#undef outp
endit:
	return 1;

}
int snes_probe_all()
{
	int *left;
	left = &mjoys;
	if(GetPermition(0x378) == 0)
	{
		printf("Permition to 0x378 granted\n");
		outb(0, 0x378);
		snes_probe(0x378, left);

	}
	if(*left == 0)goto endit;
	if(GetPermition(0x278) == 0)
	{
		snes_probe(0x278, left);

	}

	if(*left == 0)goto endit;
	if(GetPermition(0x3BC)==0)
	{
		snes_probe(0x3BC, left);

	}
endit:
	printf("found %d Snes Joysticks\n", using_snes_joys);
	return *left;

}

int snes_joy_init(int joys)
{
	mjoys = joys;
	#define setnull(a) memset(&a, 0, sizeof(struct snes_remote))
	setnull(snes_1);
	setnull(snes_2);
	setnull(snes_3);
	setnull(snes_4);
	setnull(snes_5);
	lasttime_checked_snes = 0;
	using_snes_joys = 0;
	timesp = 0;
	delay_between_snescheck = 16;
	#undef setnull
	return 0;
}

int SetPortNULL(int port)
{
	if( (port & 1) ==1)
		outb(0, 0x378);

	if( (port & 2) ==2)
		outb(0, 0x278);

	if( (port & 4) ==4)
		outb(0, 0x3BC);

	return 0;
}


Dolphin
Rookie
Posts: 39
Joined: Thu Aug 26, 2004 8:55 pm

Post by Dolphin »

Now heres the code inside execute.asm for zsnes to use my functions

Code: Select all

extern GetSnesbtns
extern GetSnesJoyCount
extern printnumber
extern sincelast_snes_check
extern delay_between_snescheck
; I didn't include all to save space on posting
extern pl1Ak, pl1Bk, pl1Yk, pl1Xk, pl1Lk, pl1Rk, pl1selk, pl1startk, pl1upk
extern pl1leftk, pl1rightk, pl1downk
extern delay_between_snescheck
%define SNES_B		1
%define SNES_Y		2
%define SNES_SEL	4
%define SNES_START	8
%define SNES_UP		16
%define SNES_DOWN	32
%define SNES_LEFT	64
%define SNES_RIGHT	128
%define SNES_A		256
%define SNES_X		512
%define SNES_L		1024
%define SNES_R		2048
; 5-2 are the same as number 1 instead of pl1 its pl2 or 3 etc...
NEWSYM ADD_SNES_5

NEWSYM ADD_SNES_4

NEWSYM ADD_SNES_3

NEWSYM ADD_SNES_2

NEWSYM ADD_SNES_1

	push dword 1
	call GetSnesbtns
	pop ebx

	mov ecx, pressed

	mov ebx, ecx
	add ebx, [pl1Bk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1
;Y
	mov ebx, ecx
	add ebx, [pl1Yk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1

;next button
	mov ebx, ecx
	add ebx, [pl1selk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1

;start
	mov ebx, ecx
	add ebx, [pl1startk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1
;up
	mov ebx, ecx
	add ebx, [pl1upk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1
;down
	mov ebx, ecx
	add ebx, [pl1downk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl

	shr eax, 1
;left
	mov ebx, ecx
	add ebx, [pl1leftk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1
;right
	mov ebx, ecx
	add ebx, [pl1rightk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1
;a
	mov ebx, ecx
	add ebx, [pl1Ak]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1
;X
	mov ebx, ecx
	add ebx, [pl1Xk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1
;L
	mov ebx, ecx
	add ebx, [pl1Lk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1
;R
	mov ebx, ecx
	add ebx, [pl1Rk]

	mov edx, eax
	and edx, 1
	mov [ebx], dl
	shr eax, 1
	jmp SNES_M.End_snes_btns ; ****************
NEWSYM SNES_M
	push eax
	push ebx
	push ecx
	push edx
	call sincelast_snes_check

	cmp eax, [delay_between_snescheck]
	jl .End_snes_btns

	call GetSnesJoyCount

	cmp eax, 5
	je ADD_SNES_5
	cmp eax, 4
	je ADD_SNES_4
	cmp eax, 3
	je ADD_SNES_3
	cmp eax, 2
	je ADD_SNES_2
	cmp eax, 1
	je ADD_SNES_1

.End_snes_btns
	pop edx
	pop ecx
	pop ebx
	pop eax
	ret
Post Reply