CX16 Programming and Coding in C Guide/Tutorial (2024)

Post Reply

  • Print view

14 posts

  • 1
  • 2
  • Next
mwiedmann
Posts: 69
Joined: Fri Jan 20, 2023 2:21 am
Location: New York City

CX16 Programming and Coding in C Guide/Tutorial

  • Quote

Postby mwiedmann »

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.

Top

Manannan
Posts: 64
Joined: Fri Oct 14, 2022 7:23 am

Re: CX16 Programming and Coding in C Guide/Tutorial

  • Quote

Postby Manannan »

This is a great idea.

I had a lot of trouble figuring things out when I started building my Sierra AGI interpreter.

Here is what I wish was documented when I started:
- File Seeking
- Executing C code from banks
- Integration between C and assembler
- Writing performant code in C. (I found that calling lots of C methods from my interpreter loop caused a significant performance penalty)
- When assembler should be used instead of C due to performance or other reasons

I asked some of these questions in forms post which have since become inaccessable for some reason. See here: https://www.commanderx16.com/forum/view ... hp?p=25434

I am not sure what is going on.

However if you don't already have examples. I can provide some if that would be helpful

Good job.

Top

mwiedmann
Posts: 69
Joined: Fri Jan 20, 2023 2:21 am
Location: New York City

Re: CX16 Programming and Coding in C Guide/Tutorial

  • Quote

Postby mwiedmann »

Those are all great topics. I think they would go well with some "Advanced Topics" chapters.

Right now its more geared towards someone who wants to make a game for the CX16 in C (because Assembly Language is a bit too much) and needs help with CX16 basics and some examples in C to show how. I'll keep working on it though and yes, if you want to connect on these more advanced topics, I'm in!

Top

Manannan
Posts: 64
Joined: Fri Oct 14, 2022 7:23 am

Re: CX16 Programming and Coding in C Guide/Tutorial

  • Quote

Postby Manannan »

Thanks. I will be in touch soon.

I hope there is something I can add from my experience.

Top

10?CHR$(147)
Posts: 3
Joined: Mon Jun 26, 2023 3:12 am

Re: CX16 Programming and Coding in C Guide/Tutorial

  • Quote

Postby 10?CHR$(147) »

Great tutorials, thanks for putting this together. I found the pages on setup and banked memory helpful.

I have a game that I have working on the C64 and the .prg is 37,210 bytes which is well under the 40Kb limit of the X16 even with the 1K loss to kernal functions and others. The C128 version is 37,221.

However, when I compile it get the following:
cl65 -t cx16 -g -Oirs src/*.c -o bin/main.cx16.prgld65: Error: /home/me/github/cc65/cfg/cx16.cfg:15: Size of memory area 'BSS' is negative: -140

Aside from breaking my .prg up into multiple files to load pieces into banked RAM, do I have other options for configuring CC65 to free up more space?

Top

mwiedmann
Posts: 69
Joined: Fri Jan 20, 2023 2:21 am
Location: New York City

Re: CX16 Programming and Coding in C Guide/Tutorial

  • Quote

Postby mwiedmann »

Good question. As far as compiler options, I'm not sure (I'm not an expert on that part). Your program will use more RAM than just its size (there is a stack and other things like any global data you have). I usually run into issues when I get over even 32k. You mentioned this, but look at Chapter 20 on Banked RAM. Its REALLY easy to put some of your code into Banked RAM.

Another thing to try is to load any data from a file at runtime rather than hardcoding in your code. For instance, if you have something like:

Code: Select all

unsigned char spriteData[] = { bunch of numbers };

You should load it into Banked RAM from a file at runtime. That will reduce code and data size.

Top

10?CHR$(147)
Posts: 3
Joined: Mon Jun 26, 2023 3:12 am

Re: CX16 Programming and Coding in C Guide/Tutorial

  • Quote

Postby 10?CHR$(147) »

Thanks I think I'll try and work my game down to under 32kb and move more of it into resource files.

Top

wizardmountain
Posts: 4
Joined: Tue May 02, 2023 2:03 pm

Re: CX16 Programming and Coding in C Guide/Tutorial

  • Quote

Postby wizardmountain »

Thank for this! I was trying my hand at ASM but getting frustrated. Bit of a steep learning curve. Hoping C will give me less trouble.

Top

mwiedmann
Posts: 69
Joined: Fri Jan 20, 2023 2:21 am
Location: New York City

Re: CX16 Programming and Coding in C Guide/Tutorial

  • Quote

Postby mwiedmann »

Quick update:
I've added some chapters around Scrolling, Files, and Banked RAM (thanks to Manannan for the section on how to run code from banked RAM). There is a Sound chapter but its just a reference to the ZSound library.

I'm basically done with this (for now). Please feel free to open PRs to fix things or add new chapters!

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
Chapter18-Scrolling
Chapter19-Files
Chapter20-Banked-RAM
Chapter21-Sound

Top

desertfish
Posts: 1055
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: CX16 Programming and Coding in C Guide/Tutorial

  • Quote

Postby desertfish »

Wow this must have been a lot of work!

Top

Post Reply

  • Print view

14 posts

  • 1
  • 2
  • Next

Return to “Programming”

Jump to

  • Forums
  • ↳ Official Announcements
  • ↳ X16 Bug Reporting
  • ↳ Introductions
  • ↳ Commander X16 Forums
  • ↳ CX16 General Chat
  • ↳ Programming
  • ↳ How-To
  • ↳ CX16 Hardware Support
  • ↳ X16 Software Support
  • ↳ X16 Feature Requests
  • ↳ Website Feedback And Support
  • ↳ Murray2 CX16 Discussion Archive
  • ↳ Works In-Progress Discussion
  • ↳ Libraries and Examples
  • ↳ Lounge
  • ↳ General Retro Chat
  • ↳ Creative Arts
  • ↳ Maker Projects
  • ↳ Memes
  • ↳ Modern Computing
  • ↳ Off Topic
  • ↳ Help Wanted
  • ↳ Trade, Buy, Sell
  • Downloads
  • ↳ Official Software
  • ↳ Games
  • Productivity Apps
  • ↳ Graphics Apps
  • ↳ Audio Apps
  • ↳ Development Tools
  • ↳ Libraries And Demo Code
  • ↳ Emulation, PC Connectivity, Networking
  • ↳ Misc Apps
  • ↳ Tutorials
  • ↳ Demoscene
  • ↳ WIP Demos
  • ↳ Archive
  • ↳ Program Requests, Suggestions, Ideas
  • ↳ Monarch Open ROM
  • ↳ Video/Podcast talk
CX16 Programming and Coding in C Guide/Tutorial (2024)
Top Articles
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 6116

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.