ca65 Questions

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
User avatar
Drew Sebastino
Formerly Espozo
Posts: 3496
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

ca65 Questions

Post by Drew Sebastino »

Well, I've been using ca65 for a while now after "The Incident" and I like it for the most part, but there are a couple of things I'm not sure how to do that I was able to do in WLA. See, in the game I'm making, I have an "object spawner" that looks for an empty object slot to put the specified number in. I then go through and check all the slots in the object table and jump to the code that corresponds to the number I stored earlier, if that makes sense. It works perfectly, but if I want to create a bullet, it looks like this:

Code: Select all

  lda #$0004
  sta NewObjectRequest
  jsr start_object_spawner
In the code, 4 represents a bullet, but when I start adding a ton of different objects, it is going to become difficult as to what number corresponds to what object. I know in WLA, you could say something like "bullet = 4" and whenever you mentioned "bullet" the assembler would now to substitute it with 4, so the code above would look like:

Code: Select all

  lda bullet
  sta NewObjectRequest
  jsr start_object_spawner
Is this possible to do in ca65?
KungFuFurby
Posts: 283
Joined: Wed Jul 09, 2008 8:46 pm

Re: ca65 Questions

Post by KungFuFurby »

Sure it is! Simply put in a line somewhere saying...

bullet = 4

That's how to define for at least the .asm file.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: ca65 Questions

Post by thefox »

Espozo wrote:

Code: Select all

  lda bullet
  sta NewObjectRequest
  jsr start_object_spawner
Is this possible to do in ca65?
Should be lda #bullet, but other than that the syntax for equates is exactly as you said.

You can also use .enum:

Code: Select all

.enum ObjectType
  cake
  waldo
  bullet
.endenum

lda #ObjectType::cake ; loads 0
lda #ObjectType::bullet ; loads 2
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
Drew Sebastino
Formerly Espozo
Posts: 3496
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: ca65 Questions

Post by Drew Sebastino »

KungFuFurby wrote:Sure it is! Simply put in a line somewhere saying...bullet = 4
Serious answers plea... Oh wait, never mind. :oops: I was confused because I didn't use a #, which thefox pointed out. You know, what is the game loading if you don't use a #? I tried it and it crashed because it must point to some place I don't want it to. I like that you can do something like that. It's so obvious that it's unobvious, unless there is some sort of "standard" for defining things.
KungFuFurby
Posts: 283
Joined: Wed Jul 09, 2008 8:46 pm

Re: ca65 Questions

Post by KungFuFurby »

The assembler loads a value from a memory location (which would be whatever is stored in $0004 plus the data bank register) instead of a constant without that # there.
User avatar
Drew Sebastino
Formerly Espozo
Posts: 3496
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: ca65 Questions

Post by Drew Sebastino »

Oh yeah, I have another question. Is it possible to say the address of a something like this (player1:) instead of something like this? (.proc player1) I had a jump table that wasn't working with the first method because it said player1 was undefined or something so I changed it and then it worked.
User avatar
rainwarrior
Posts: 8758
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: ca65 Questions

Post by rainwarrior »

.proc is a combination label and enclosing .scope for any labels inside the proc. If you don't need a scope, you don't need to use .proc, but it's a useful feature if used consistently. The main thing is you can have generic label names like loop: within a proc without worrying about a conflict with the same name in another proc.

.proc player1 should create a global label player1 that you can use elsewhere like in a jump table. Did you maybe forget an .endproc somewhere?

Also, something I find convenient when the setup for common subroutine calls tedious is to roll them up in a macro:

Code: Select all

.macro Spawn spawntype
    lda #spawntype
    sta NewObjectRequest
    jsr start_objects_spawner
.endmacro

; you can now do this with a 1 line statement
Spawn bullet
Post Reply