Is this a good way to organize public/private data in ca65?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
samophlange
Posts: 48
Joined: Sun Apr 08, 2018 11:45 pm
Location: Southern California

Is this a good way to organize public/private data in ca65?

Post by samophlange » Thu Jan 23, 2020 11:16 pm

I'm starting a new project, and I'd like to organize my code better than I did in my first project. Coming from a C/C++ background, my first instinct is to divide things in to "header" and "implementation" files. For example:

Code: Select all

; core_controllers.inc

BUTTON_A		= %10000000

.global buttons_down ; bit flags for current button states
.global update_controllers ; subroutine for updating button state

Code: Select all

; core_controllers.asm

.include "core_controllers.inc"

.segment "ZEROPAGE"
buttons_down: .res 1

.segment "CODE"

.proc update_controllers
    ; etc etc
    rts
.endproc
The idea is the code that wants to interact with the controllers just does an '.include "controllers.inc"' and has access to what it needs. I'm new to .import/.export/.global, so I'm don't know if this a good way to handle things or if I'm setting myself up for headaches.

User avatar
rainwarrior
Posts: 7732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Is this a good way to organize public/private data in ca65?

Post by rainwarrior » Fri Jan 24, 2020 1:48 am

Yes, that's pretty normal. A lot of the way ca65 works seems modelled on C practices like that.

Post Reply