English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 25 April 2018, 00:58   #1
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,644
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


Can anybody kick this absolute moron in the right direction? I'm totally confused.
Amiga1992 is offline  
Old 25 April 2018, 01:30   #2
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,957
Quote:
Originally Posted by Akira View Post
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


Can anybody kick this absolute moron in the right direction? I'm totally confused.
Use
_custom EQU $DFF000
Don_Adan is offline  
Old 25 April 2018, 01:34   #3
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
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.
phx is offline  
Old 25 April 2018, 15:40   #4
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,644
Quote:
Originally Posted by Don_Adan View Post
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 View Post
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.
Amiga1992 is offline  
Old 25 April 2018, 21:44   #5
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,957
Quote:
Originally Posted by Akira View Post
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.
Don_Adan is offline  
Old 26 April 2018, 22:37   #6
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Akira View Post
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.
phx is offline  
Old 03 May 2018, 00:50   #7
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,644
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.
Amiga1992 is offline  
Old 07 May 2018, 11:54   #8
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,406
Quote:
Originally Posted by Akira View Post
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.
roondar is offline  
Old 07 May 2018, 16:12   #9
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,644
Quote:
Originally Posted by roondar View Post
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
Amiga1992 is offline  
Old 07 May 2018, 16:50   #10
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by Akira View Post
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.
mcgeezer is offline  
Old 07 May 2018, 17:10   #11
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,644
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
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?
Amiga1992 is offline  
Old 07 May 2018, 17:25   #12
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,322
Quote:
Originally Posted by Akira View Post
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 View Post
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.
meynaf is online now  
Old 07 May 2018, 17:49   #13
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,644
Quote:
Originally Posted by meynaf View Post
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!
I understand how this works now, and will try to do better!
Will report back with findings.
Amiga1992 is offline  
Old 07 May 2018, 18:40   #14
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by Akira View Post
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
No worries, just PM me and we can setup a time.
mcgeezer is offline  
Old 08 May 2018, 23:37   #15
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Akira View Post
I see, yes, I want to do things nicely, not "not really nice"-ly!
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.
phx is offline  
Old 09 May 2018, 00:27   #16
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,644
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.
Amiga1992 is offline  
Old 09 May 2018, 07:26   #17
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by phx View Post
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?
StingRay is offline  
Old 09 May 2018, 08:29   #18
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,322
Quote:
Originally Posted by phx View Post
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 ).


Quote:
Originally Posted by StingRay View Post
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
meynaf is online now  
Old 09 May 2018, 15:55   #19
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,644
Quote:
Originally Posted by StingRay View Post
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.
Amiga1992 is offline  
Old 09 May 2018, 18:48   #20
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
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.
mcgeezer is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
implement others 68000 machines ? turrican3 support.WinUAE 28 23 November 2017 00:54
Joystick reading code borchen Coders. Asm / Hardware 57 23 November 2014 14:08
Req: Tanks 'n' Stuff Src Code kevingpo request.Old Rare Games 1 07 July 2003 12:07
Should I implement PM download now ? RCK project.EAB 12 08 January 2002 01:21

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:59.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.28666 seconds with 13 queries