This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

CA65 .global and .procs

CA65 .global and .procs
by on (#164352)
From what I have read in these forums and in the CA65 docs, I would think that this would work (a snippet of generated code):

Code:
; generated 2016-02-11T16:32:59-08:00

.PROC snake
   .global test
   init:
      jsr test::method

      rts

   update:
      
      rts

   destroy:
      
      rts
.ENDPROC

.PROC test
   method:
      rts
.ENDPROC


However, it does not and I get the following output:

Code:
 ca65 .\src\main.s -g -l .\bin\main.ls -o .\bin\main.o -D DEBUG=1

.\src/scenes/../../bin/gen/..\./objects/SNAKE.s(6): Error: No such scope: `test'
.\src/scenes/../../bin/gen/..\./objects/SNAKE.s(6): Error: Unexpected trailing garbage characters


Any suggestions? Does anything look wrong?
Re: CA65 .global and .procs
by on (#164358)
AFAIK, you can't reference scopes that haven't been defined yet.

EDIT: The only way I found to get around this is to use fake scoping, creating labels for anything I want to make visible AFTER the scope is closed, like this:

Code:
.proc test
  method:
.endproc

test_method = test::method

Then I can reference test_method anywhere, even before the "test" scope is created.

EDIT 2: BTW, .global has nothing to do with scopes, its purpose is to import end export symbols between sources that are assembled separately.
Re: CA65 .global and .procs
by on (#164366)
Thanks tokumaru! The workaround works great.