atarilux Posted June 12, 2022 Share Posted June 12, 2022 (edited) Hello, I have decided to start using CC65 so that atleast later on the basic game logic components can be easily ported to other platforms. However, I wondered if anyone can point me in the direction of examples of how to get the joystick working? I have been trying joystick.h and joy_read with little success. Edited June 12, 2022 by atarilux Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 12, 2022 Share Posted June 12, 2022 (edited) With the Atari, you don't need a joystick driver, the OS copies the joystick position into memory every vertical blank, all you need to do is read the memory location. something like this, prints joystick 0 position until you press a key:- #include <stdlib.h> #include <_atarios.h> #include <atari.h> #include <atarisyseq.h> #include <peekpoke.h> #define joy0 PEEK(STICK0) // define joystick 0 void main(void) { POKE(764,255); do{ printf("%u\n",joy0); // print the joystick position }while(PEEK(764)==255); } If you want faster access, you can read PORTA directly, the byte returned has STICK0 in the bottom 4 bits and STICK1 in the top 4 bits You can do exactly the same for the trigger #define trig0 PEEK(STRIG0) Edited June 12, 2022 by TGB1718 Quote Link to comment Share on other sites More sharing options...
danwinslow Posted June 12, 2022 Share Posted June 12, 2022 (edited) Absolutely correct, but he explicitly said he's developing for multiple platforms. That makes me think he is talking about the driver, which I don't know much about. @sanny probably does though. Atarilux - I am not sure if you can count on the joy driver being (a) sufficient, and (b) working for all platforms. Maybe you can...but if not and you are really intent on distributing for many systems, then implementing your own driver API with platform specific code underneath (such as shown above) would be a good idea. Edited June 12, 2022 by danwinslow Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 12, 2022 Share Posted June 12, 2022 @danwinslow I was thinking the same thing, maybe other systems need some sort of driver to read the joysticks. I don't think we can help on this forum due to the fact we don't need them. However if @atarilux needs code for many platforms, he can always use #ifdef etc. etc. to produce only the code for specific platforms at compile time Quote Link to comment Share on other sites More sharing options...
sanny Posted June 13, 2022 Share Posted June 13, 2022 see targettest/joy-text.c in the cc65 source code for an example how to use the driver Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 13, 2022 Share Posted June 13, 2022 As expected that code doesn't work on the 800/XE/XL range, but it does look like the 5200 could use it. Quote Link to comment Share on other sites More sharing options...
sanny Posted June 13, 2022 Share Posted June 13, 2022 Which code? Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 13, 2022 Share Posted June 13, 2022 2 hours ago, sanny said: see targettest/joy-text.c in the cc65 source code for an example how to use the driver That code Quote Link to comment Share on other sites More sharing options...
sanny Posted June 13, 2022 Share Posted June 13, 2022 Why do you think it doesn't work with the XL+ line? Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 14, 2022 Share Posted June 14, 2022 I compiled it and ran it just to see if it did work:- Error in joy_load_driver: 2 OS: 170, file not found D5:> It appears to only load the driver for certain system, Atari 800/XL/XE are not included, so this error is output. Quote Link to comment Share on other sites More sharing options...
sanny Posted June 14, 2022 Share Posted June 14, 2022 You didn't put the joystick driver itself onto the disk. `atrstd.joy` You need to compile and link the driver statically to your exe if you want to have a self-contained exe file: `cl65 -tatari -DJOYSTICK_DRIVER=atrstd_joy -o /tmp/joy-test.com joy-test.c` Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 14, 2022 Share Posted June 14, 2022 (edited) @sanny thanks for that, must have missed that Update: for anyone using this and uses normal joystick values, these don't work with this Centre = 0 Up = 1 DOWN = 2 LEFT = 4 RIGHT = 8 and diagonals = UP+LEFT,UP+RIGHT,DOWN+LEFT,GOWN+RIGHT TRIGGER BUTTON = 16 @atarilux, @sanny has solved your problem simple code to read a stick:- Res = joy_install (&JOYSTICK_DRIVER); // install driver . . . . j=joy_read(0); // or joy_read(1) Just compile as shown above. Edited June 14, 2022 by TGB1718 Quote Link to comment Share on other sites More sharing options...
atarilux Posted June 14, 2022 Author Share Posted June 14, 2022 (edited) Thanks to everyone for your help. I am happy for now just to write for the 8-bit line for now for certain things e.g. joysticks, graphics etc as and when required. I will try the joystick driver approach in the previous post and then take it from there. Once I get one platform working I will try it on others the question is whether to do C64 or 7800 afterwards. For now my build target is a 800xl, as that is the stock hardware I have here. One reason for not going down the pure assembler route is that I also want to get it working on my first computer which was a ZX Spectrum. But I will certainly look at doing some key parts in assmbler for each platform. Follow up to initial post: It works, so thanks! Edited June 14, 2022 by atarilux just added comment to initial post Quote Link to comment Share on other sites More sharing options...
atarilux Posted June 19, 2022 Author Share Posted June 19, 2022 (edited) Hello everyone, Thanks to all of you for your help so far. Please let me know if you know of a good working PMG example in CC65 (that also works on Altirra)? I have looked around online and sofar the one I have found does not run when compiled. So far CC65 has been an ok experience, I am also getting back into C again after many years. I had previously worked on learning Atari aspects in Fastbasic, but sadly it got too slow in the end. Although there is much left to do, so far this is not the case in CC65, not a surprise really now I am having to add things to slow aspects down. I am sure that will change with time.. Edited June 19, 2022 by atarilux Quote Link to comment Share on other sites More sharing options...
danwinslow Posted June 19, 2022 Share Posted June 19, 2022 If execution speed and size efficiency is an issue for you, be aware that you have to write the C code in a very specific way to get the best performance. Using 'regular' c coding style and function calls is absolutely going to work, but will be bloated and slow compared to how it performs when written 'correctly'. If this is the case, you can search for several very good threads here on optimizing CC65 C coding. Quote Link to comment Share on other sites More sharing options...
Harry Potter Posted June 19, 2022 Share Posted June 19, 2022 I am sorry fro SPAMming this forum again, but I really think I have something that may prove to be useful in this case. I have a collection of optimizations for cc64 code at c65 additions - Manage Files at SourceForge.net. Try them out. Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 19, 2022 Share Posted June 19, 2022 4 hours ago, atarilux said: Please let me know if you know of a good working PMG example in CC65 (that also works on Altirra)? I have looked around online and sofar the one I have found does not run when compiled. I have one program that uses PMG in cc65, but you might find it a bit on the "big" side for a starter, it's a sprite editor that uses PMG's. Also remember when using cc65 you can use Assembler (.s) files where needed if you want to speed things up i.e. VBI's, DLI's etc. Attached is the .xex, your welcome to the code if you want it, it may help. sprite.xex Quote Link to comment Share on other sites More sharing options...
atarilux Posted June 19, 2022 Author Share Posted June 19, 2022 (edited) 2 hours ago, TGB1718 said: I have one program that uses PMG in cc65, but you might find it a bit on the "big" side for a starter, it's a sprite editor that uses PMG's. Also remember when using cc65 you can use Assembler (.s) files where needed if you want to speed things up i.e. VBI's, DLI's etc. Attached is the .xex, your welcome to the code if you want it, it may help. sprite.xex 14.47 kB · 2 downloads Great thanks, I will take a look at it.. May get back to ask about code as well.. for now I will just explore. For now I am just experimenting with the basic game logic elements, so the graphics are very basic. I still need to get my head around VBI, DLI and if required sprite multiplexing. For now though, the performance improvement between FastBasic and CC65 is quite noticable. I had heard about the benefits of using Assembler for certain parts, but I will try to avoid premature optimisation for now. I guess Mapping on the Atari will need to become a closer friend for some future elements. Edited June 19, 2022 by atarilux Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 19, 2022 Share Posted June 19, 2022 Some others worth looking at De Re Atari, Technical Reference Notes and Hardware Manual although all written for the 400/800 most of the information is still relevant Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.