Page 1 of 1
CX16 Programming and Coding in C Guide/Tutorial
Posted: Thu May 25, 2023 2:51 pm
by mwiedmann
Cross post from the Programming section of the forums (I think belongs here too).
I've been working on a CX16 programming guide and C programming tutorial/guide. I'll be adding more but it's ready enough to share. Even if you don't want to code in C its a good general CX16 programming guide/tutorial. It has C code examples for everything discussed. It uses cc65 but I explain how to do everything "from scratch" before leveraging any libraries that cc65 has to offer so you _should_ be able to use another compiler. I learned a lot putting this together so hopefully someone will find this helpful.
https://github.com/mwiedmann/cx16CodingInC
Here are the current chapters just to give you an idea.
Chapter01-Installation
Chapter02-First-Program-Setup
Chapter03-Numbers
Chapter04-CX16-Overview
Chapter05-Video-Memory
Chapter06-Tiles
Chapter07-MapBase
Chapter08-Palette
Chapter09-Color-Depth-Modes
Chapter10-Tile-Sizes
Chapter11-Bitmap-Mode
Chapter12-Layers
Chapter13-GameLoop-Wait
Chapter14-Controls-and-Input
Chapter15-Sprites
Chapter16-Animations
Chapter17-Collisions
Coming soon - Files and some "Put it all together" game examples.
Re: CX16 Programming and Coding in C Guide/Tutorial
Posted: Thu May 25, 2023 3:58 pm
by StephenHorn
Only had a chance to take a quick glance at it, but this looks pretty good so far! This should be a huge help for C programmers wanting to get started with the X16!
Re: CX16 Programming and Coding in C Guide/Tutorial
Posted: Sun Dec 24, 2023 2:10 am
by Dr.J
Hey, just wanted to leave a note that I'm using this tutorial. I've worked through the first few chapters and this is enormously helpful so far. This is a very well-written tutorial and it is saving me many hours of having to figure these things out "the hard way." Thanks so much for taking the time to write this!
Dr.J
Re: CX16 Programming and Coding in C Guide/Tutorial
Posted: Tue Dec 26, 2023 1:53 am
by mwiedmann
Glad it is helping! I've learned a few things since I wrote this so I'll hopefully make a few updates soon. Everything in there is still good to go but some the joystick section needs an update and the (lack of) sound chapter needs a major update (plus a few other minor things). MooingLemur released the fantastic "ZSMKit" and I learned how to use it in C. This part is huge and makes it WAY easier to do music/sound now. Thanks again for checking this out though!
Re: CX16 Programming and Coding in C Guide/Tutorial
Posted: Fri Dec 29, 2023 5:39 pm
by Bill Leue
Very nice! I plan to learn 6502 assembler coding, but programming in C is a good first step, and I wrote a ton of C code during my long career as a programmer, so I expect, with the help of your tutorial, I will get this step done quickly.
-Bill
Re: CX16 Programming and Coding in C Guide/Tutorial
Posted: Tue Feb 06, 2024 8:19 am
by Ringoid
Thanks for providing this guide — I can confirm that the Linux steps you've given so far (in the first couple videos) work just fine on macOS, too. Same use of "make", same convenience putting cl65 in the PATH (I edited the one in my .zshrc, but people using the default Bash shell should put it in .bash_profile).
One question, though, and I don't know if you're covering it in a later video. How do we access Kernal routines from C? There doesn't seem to be a lot of documentation on how the cx16.h library works outside that big "vera" struct, but what if I want to use asm routines for speed in drawing character-cell graphics (like the old Below the Root game)?
Re: CX16 Programming and Coding in C Guide/Tutorial
Posted: Tue Feb 06, 2024 9:13 am
by ahenry3068
Ringoid wrote: ↑Tue Feb 06, 2024 8:19 am
Thanks for providing this guide — I can confirm that the Linux steps you've given so far (in the first couple videos) work just fine on macOS, too. Same use of "make", same convenience putting cl65 in the PATH (I edited the one in my .zshrc, but people using the default Bash shell should put it in .bash_profile).
One question, though, and I don't know if you're covering it in a later video. How do we access Kernal routines from C? There doesn't seem to be a lot of documentation on how the cx16.h library works outside that big "vera" struct, but what if I want to use asm routines for speed in drawing character-cell graphics (like the old Below the Root game)?
I've only played around with the C compiler a little but I believe there are two ways to do that. You can either use inline assembly (Not sure of the keyword, but I think there is one) or "link" in an external library written in assembly.
Re: CX16 Programming and Coding in C Guide/Tutorial
Posted: Tue Feb 06, 2024 9:36 am
by JimmyDansbo
You may find this useful for combining C and assembler:
https://techblog.dansbo.dk/?p=62
For short inline assembly, you use the __ASM__ keyword, see:
https://www.cc65.org/doc/cc65-9.html
Re: CX16 Programming and Coding in C Guide/Tutorial
Posted: Wed Sep 25, 2024 1:04 am
by jaydg
I'm a little more than halfway through and this has been an enormous help! Thank you for putting this together. If you turned this into a book I would buy it just to support your efforts. The writing is articulate, easy to read with small examples easily digested, but meaningful enough to show the power they represent. I am planning to use a hybrid C/asm approach and this documentation and samples have been a enormous springboard to get me up and running. Nice work!
Re: CX16 Programming and Coding in C Guide/Tutorial
Posted: Wed Sep 25, 2024 10:30 pm
by desertfish
I hadn't looked at this before but I browsed through it now. It's really some superb work ! I'm jealous!