Jump to content
IGNORED

CC65 question


Recommended Posts

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 by atarilux
Link to comment
Share on other sites

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 by TGB1718
Link to comment
Share on other sites

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 by danwinslow
Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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`

 

Link to comment
Share on other sites

@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 by TGB1718
Link to comment
Share on other sites

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 by atarilux
just added comment to initial post
Link to comment
Share on other sites

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 by atarilux
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by atarilux
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...