English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. General (https://eab.abime.net/forumdisplay.php?f=37)
-   -   Trying to implement joystick code in my stuff (https://eab.abime.net/showthread.php?t=91999)

Amiga1992 25 April 2018 00:58

Trying to implement joystick code in my stuff
 
Hi guys,

I've been pulling my hairs out for a while trying to implement JOTD's CD32 pad reading code into my own code.
This seems like an absolute n00b mistake but I can't figure it out even after contacting JOTD and following his instructions (which I might have followed wrong, granted).

You can find the original code in JOTD's CD32Load archive:
http://jotd.pagesperso-orange.fr/amiga.html

The file I am trying to implement is called "ReadJoypad.s"
I am using Devpac 3.18

The error I get is the following:
Code:

Error: undefined symbol at line 70 in file READJOYPAD.S
  70 01.0000002E 41F900000007                        lea    _custom,a0
Error: undefined symbol at line 71 in file READJOYPAD.S
  71 01.00000034 43F900000005                        lea    _ciaa,a1

2 errors found

JOTD's first suggestion was to include cia.i and custom.i, but my program already inc'd them.
Second suggestion was that those symbols weren't in the includes, which they are not, which is weird, because these are the official includes as far as I understand. Anyway, he told me to include them manually:
Quote:

Originally Posted by JOTD
ciab => $bfe001
custom => $DFF000

lea $DFF000,a0
lea $BFE001,a1

So I went to cia.i and added
Code:

ciab EQU $BFE001
and in custom.i I added
Code:

custom EQU $DFF000
But this is still not working.
(note: i also tried ciaa EQU $BFE001, I noticed probaby JOTD made a mistake there. Still the same problem)

I also tried adding both on my code after the includes instead, and then it tells me:
Code:

Error: symbol defined twice at line 35 in file test.S
  35 01.0000010C                      custom EQU $DFF000

1 error found

:confused :confused :confused

Can anybody kick this absolute moron in the right direction? I'm totally confused.

Don_Adan 25 April 2018 01:30

Quote:

Originally Posted by Akira (Post 1236945)
Hi guys,

I've been pulling my hairs out for a while trying to implement JOTD's CD32 pad reading code into my own code.
This seems like an absolute n00b mistake but I can't figure it out even after contacting JOTD and following his instructions (which I might have followed wrong, granted).

You can find the original code in JOTD's CD32Load archive:
http://jotd.pagesperso-orange.fr/amiga.html

The file I am trying to implement is called "ReadJoypad.s"
I am using Devpac 3.18

The error I get is the following:
Code:

Error: undefined symbol at line 70 in file READJOYPAD.S
  70 01.0000002E 41F900000007                        lea    _custom,a0
Error: undefined symbol at line 71 in file READJOYPAD.S
  71 01.00000034 43F900000005                        lea    _ciaa,a1

2 errors found

JOTD's first suggestion was to include cia.i and custom.i, but my program already inc'd them.
Second suggestion was that those symbols weren't in the includes, which they are not, which is weird, because these are the official includes as far as I understand. Anyway, he told me to include them manually:


So I went to cia.i and added
Code:

ciab EQU $BFE001
and in custom.i I added
Code:

custom EQU $DFF000
But this is still not working.
(note: i also tried ciaa EQU $BFE001, I noticed probaby JOTD made a mistake there. Still the same problem)

I also tried adding both on my code after the includes instead, and then it tells me:
Code:

Error: symbol defined twice at line 35 in file test.S
  35 01.0000010C                      custom EQU $DFF000

1 error found

:confused :confused :confused

Can anybody kick this absolute moron in the right direction? I'm totally confused.

Use
_custom EQU $DFF000

phx 25 April 2018 01:34

The ReadJoypad.s from jst_6.0.zip on JOTD's home page seems different, as line 70 and 71 don't reference _custom and _ciaa. So I don't know what you assembled.

BTW, did you notice that the undefined symbols have a leading underscore? Your EQUs don't.

Another option is to link with amiga.lib, which should export these symbols as well.

Amiga1992 25 April 2018 15:40

Quote:

Originally Posted by Don_Adan (Post 1236946)
Use
_custom EQU $DFF000

Oh man I missed the underscore! I just copy pasted from JOTD's message.

Is the address for _ciaa ok or is it wrong? $BFE001 ?
Quote:

Originally Posted by phx (Post 1236947)
The ReadJoypad.s from jst_6.0.zip on JOTD's home page seems different, as line 70 and 71 don't reference _custom and _ciaa. So I don't know what you assembled.

I mentioned I assembled the code from the CD32Load archive.
I didn't know the JST one also had this code, I can try that instead! Thanks!

Quote:

BTW, did you notice that the undefined symbols have a leading underscore? Your EQUs don't.
No, I didn't, at all :/ That has to be it.

Quote:

Another option is to link with amiga.lib, which should export these symbols as well.
Where do I get that and what includes does it replace?

Thanks a lot! Sorry, I am a TOTAL NOOB.

Don_Adan 25 April 2018 21:44

Quote:

Originally Posted by Akira (Post 1237059)
Oh man I missed the underscore! I just copy pasted from JOTD's message.

Is the address for _ciaa ok or is it wrong? $BFE001 ?


I mentioned I assembled the code from the CD32Load archive.
I didn't know the JST one also had this code, I can try that instead! Thanks!


No, I didn't, at all :/ That has to be it.


Where do I get that and what includes does it replace?

Thanks a lot! Sorry, I am a TOTAL NOOB.

CIA-A is $bfe001.

phx 26 April 2018 22:37

Quote:

Originally Posted by Akira (Post 1237059)
Where do I get that and what includes does it replace?

amiga.lib is included in all official NDKs, and also comes with most compilers, sometimes with slightly modified versions. But amiga.lib should always define symbols like _ciaa, _custom, etc.

It's easier in assembler to include hardware/custom.i or cia.i before linking with amiga.lib, though.

Amiga1992 03 May 2018 00:50

OK I don't get this error anymore, but now when I include JOTD's code in my code, I can't launch the game.
All I get is being sent back to the prompt. No guru, no anything :/

I'm really way over my head here, unable to debug what is going on here. Any help appreciated.

roondar 07 May 2018 11:54

Quote:

Originally Posted by Akira (Post 1238463)
OK I don't get this error anymore, but now when I include JOTD's code in my code, I can't launch the game.
All I get is being sent back to the prompt. No guru, no anything :/

I'm really way over my head here, unable to debug what is going on here. Any help appreciated.

Without seeing your code the following is a guess, but...

Where in your do you include the ReadJoyPad.s?

If it is at the top of the file, the assembler will put the code in front of yours during assembly (include can be seen as the assembler just dumping the content of whatever file you include at the point where you write the include command).

In that case, the program will start executing whatever ReadJoyPad.s starts with and it's possible that the code at the start of ReadJoyPad.s just so happens to return without incident, which results in ending your program before it reaches your code.

If this is the actual problem and you wish to prevent it, you have to either use the include command later in your file or make your source consist of two separate files that you link together using a linker.

Amiga1992 07 May 2018 16:12

Quote:

Originally Posted by roondar (Post 1239334)
Without seeing your code the following is a guess, but...

Where in your do you include the ReadJoyPad.s?

You know this is exactly what I was thinking, that I was including it at the wrong time, and I think you are right! I DO have it at the top of the file, right after all the system includes.
Why does this have to be so weird? I guess I am too used to stuff like C :/
I actually have no idea where to put it, then, or how to fix this.

Actually what I realized is that I couldn't find anywhere in JOTD's CD32Load or JST code, any reference to where ReadJoypad.s is included. I Searched the source for "Readoypad.s"and NOTHING turned up. So maybe he "linked" it as you said? I have no idea what i am doing here, I just wanted to include the CD32 joypad reading code in my own game and I thought it'd be as easy as including it in the source :(

mcgeezer 07 May 2018 16:50

Quote:

Originally Posted by Akira (Post 1239378)
You know this is exactly what I was thinking, that I was including it at the wrong time, and I think you are right! I DO have it at the top of the file, right after all the system includes.
Why does this have to be so weird? I guess I am too used to stuff like C :/
I actually have no idea where to put it, then, or how to fix this.

Actually what I realized is that I couldn't find anywhere in JOTD's CD32Load or JST code, any reference to where ReadJoypad.s is included. I Searched the source for "Readoypad.s"and NOTHING turned up. So maybe he "linked" it as you said? I have no idea what i am doing here, I just wanted to include the CD32 joypad reading code in my own game and I thought it'd be as easy as including it in the source :(

Happy to run a team viewer session with you if u wantme to take a look.

Amiga1992 07 May 2018 17:10

mcgeezer I might take you up on this when I am ready to give up. I am pretty stubborn and determined to learn how to do this haha :D
I appreciate everyone's help really very much!

My first guess is that I will put this near where I want the actions to happen when keys/joystick stuff are pressed. Then see what happens.

Maybe ReadJoypad.s needs modifications to be included how I want to include it? Can anyone tell from the code posted above?

meynaf 07 May 2018 17:25

Quote:

Originally Posted by Akira (Post 1239388)
My first guess is that I will put this near where I want the actions to happen when keys/joystick stuff are pressed. Then see what happens.

That should work.


Quote:

Originally Posted by Akira (Post 1239388)
Maybe ReadJoypad.s needs modifications to be included how I want to include it? Can anyone tell from the code posted above?

If you really insist to include it at startup, then you can do the following :
Code:

jmp start
 include readjoypad.s
start:

Not really nice, though.

You have to understand that unlike C, the entry point in ASM is at the start of the program.
Therefore if you include something, any code in it will get executed before your program. System includes are harmless because they contain no code, just constant definitions.
But contrary to C or many other languages, in ASM you don't have to declare a routine before using it.
So you can include it anywhere it will not annoy. I recommend doing that right after your normal code.

Amiga1992 07 May 2018 17:49

Quote:

Originally Posted by meynaf (Post 1239393)
Not really nice, though.

You have to understand that unlike C, the entry point in ASM is at the start of the program.
Therefore if you include something, any code in it will get executed before your program. System includes are harmless because they contain no code, just constant definitions.
But contrary to C or many other languages, in ASM you don't have to declare a routine before using it.
So you can include it anywhere it will not annoy. I recommend doing that right after your normal code.

I see, yes, I want to do things nicely, not "not really nice"-ly! :D
I understand how this works now, and will try to do better!
Will report back with findings.

mcgeezer 07 May 2018 18:40

Quote:

Originally Posted by Akira (Post 1239388)
mcgeezer I might take you up on this when I am ready to give up. I am pretty stubborn and determined to learn how to do this haha :D

No worries, just PM me and we can setup a time.

phx 08 May 2018 23:37

Quote:

Originally Posted by Akira (Post 1239398)
I see, yes, I want to do things nicely, not "not really nice"-ly! :D

Including files which generate code or data is also not a nice practice, IMHO. Includes should only contain definitions (equates, macros). When you do that anyway, you have to be sure that there are no symbol conflicts with the included file.

The good way would be to assemble ReadJoypad.s into an object file, export the symbols you need, and use a linker to link it with your project into the final executable. It also makes building your project much faster, because you don't have to assemble it together with your code every time.

Amiga1992 09 May 2018 00:27

Is there any guide anywhere that explains how to make an OBJ and how to link together?

Also keep in mind I use Devpac, not a newfangled cross assembler.

StingRay 09 May 2018 07:26

Quote:

Originally Posted by phx (Post 1239646)
Including files which generate code or data is also not a nice practice, IMHO. Includes should only contain definitions (equates, macros).

Includes can and should contain any kind of code. For example, I include the complete system-kill/startup code at the top of my source which makes it much more readable as the startup code is neatly hidden and not interesting to look at anyway when coding effects. Same for various helper routines and other things. Why bloat the source with "standard" code when it can be easily included?

meynaf 09 May 2018 08:29

Quote:

Originally Posted by phx (Post 1239646)
The good way would be to assemble ReadJoypad.s into an object file, export the symbols you need, and use a linker to link it with your project into the final executable. It also makes building your project much faster, because you don't have to assemble it together with your code every time.

ReadJoypad.s is probably too small to count for anything in assembly time...
Using a linker has a small issue, it is that you'll generate slightly suboptimal code because some information (some of the offsets) will not be known at assembly time and therefore the assembler can't use its full peephole optimization power (not a big issue on Devpac, ok :p).


Quote:

Originally Posted by StingRay (Post 1239676)
Includes can and should contain any kind of code. For example, I include the complete system-kill/startup code at the top of my source which makes it much more readable as the startup code is neatly hidden and not interesting to look at anyway when coding effects. Same for various helper routines and other things. Why bloat the source with "standard" code when it can be easily included?

Yes it is a good practice to put reusable routines in includes.
I pushed that system up to the point there aren't any OS calls / hardware accesses directly in my code anymore :)

Amiga1992 09 May 2018 15:55

Quote:

Originally Posted by StingRay (Post 1239676)
I include the complete system-kill/startup code at the top of my source which makes it much more readable as the startup code is neatly hidden and not interesting to look at anyway when coding effects. Same for various helper routines and other things. Why bloat the source with "standard" code when it can be easily included?

See, this is where I come from, and why I wanted to include. This is a "helper" routine I have no interest in looking at. I know it works and all I need is to be able to interface with it.
If I had this my way, I'd do as meynaf described, and reserve my main chunk of code for just the logic of what I need to do with the specific program itself.

I don't like the "chuck all code in one file" approach that was common in demomaking in the 90s. This is tidier to me, but I need to know how to do it.

Then again, from what I described above, I feel like JOTD might have linked it anyway, because as I said there's no reference to any including of this file in any of the files in the source pack. :confused

mcgeezer 09 May 2018 18:48

I have a lot of includes in my game, without them the code would be unmanageable.

The way I do it now is split the code into secions i.e "input.asm" and any variables I put in an assoicated dat file like "input.dat".

I then group the includes together at the start of the code and put the dat's at the end, that way I can use an address register in the centre of the dat's to use relative addressing of variables in a 64K range. (thanks Galahad for the addressing tip)

Happy to give an example if you like.


All times are GMT +2. The time now is 00:57.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.05772 seconds with 11 queries