Jump to content
Sign in to follow this  
slx

Action! - initializing an INT array with negative numbers

Recommended Posts

My son tried the following in Action! (version 3.7)

INT Array x=[-1 -2 -3 -4]

This results in an Error 9. The same happens when initializing a single INT to a negative value. Parentheses around the (-1) make no difference.

 

I didn't find anything in the the manual that would prohibit initializing to negative numbers.

 

Any ideas how to work around this or where/how to store values to initialize the array after it has been declared?

Edited by slx

Share this post


Link to post
Share on other sites

Would still be interesting why it doesn't work as documented.

Share this post


Link to post
Share on other sites

It doesn't work because the =[ ] data storing routine is looking for constants:

 

; GetConst(token)
; ---------------
gconst ldy #cnserr
cmp #$81
bcc adrerr
cmp #constt+strt
bcs adrerr
lda nxtadr
ldx nxtadr+1
rts

 

The A register is holding the token for the "-" minus symbol, not the value, and thus it fails the test. There's a few things that would have to be changed to allow for the presence of unary minus, like mnum would have to be updated to invoke part of the expression evaluator to process the constant. I expect he left it this way because it's so much simpler, and can be worked around. Don't forget, the cartridge is really tight for space.

  • Like 4

Share this post


Link to post
Share on other sites

It doesn't work because the =[ ] data storing routine is looking for constants:

 

 

Thanks for the detailed explanation. Sorry the thanks come late as I didn't check that subforum for some time.

 

I suppose it works like that because the compiler uses different code for initialization and "normal" assignments to a variable (because it's faster?) Would something else make it unwise to let the initialization routine to use the same logic as the variable assignment routine.

 

Negative numbers probably weren't that high on the list of priorities. The workaround is not extremely intuitive, though ;)

Share this post


Link to post
Share on other sites

I think it's more likely an unintended consequence of code sharing. The same code that processes code blocks [ ] where you can embed machine language does double duty as the array initializer. You wouldn't want minus signs in the code block, so it doesn't allow for that, and as a result it doesn't allow unary minus as an array initial value either. If he realized it, I'm sure he just wrote it off as a minor issue with a workaround.

 

The only token that it does recognize is $ which is then passed to mnum to extract the hex value.

 

Yes, assignment to a variable is done differently, and takes a lot of work internally and can generate a lot of code. He must have decided early on not to allow expressions in the initializer blocks or code blocks because it simply wasn't possible to fit the code in the cartridge.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...