Jump to content

Photo

Action! - initializing an INT array with negative numbers

Action!

5 replies to this topic

#1 slx OFFLINE  

slx

    Stargunner

  • 1,560 posts
  • Location:Vienna, Austria

Posted Sun Aug 5, 2018 12:14 PM

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, Mon Aug 6, 2018 2:26 AM.


#2 joyfulcoder OFFLINE  

joyfulcoder

    Star Raider

  • 96 posts
  • Location:Western Mass

Posted Mon Aug 6, 2018 7:53 PM

a work around:

INT Array x=[65535 65534 65533 65532]


#3 slx OFFLINE  

slx

    Stargunner

  • Topic Starter
  • 1,560 posts
  • Location:Vienna, Austria

Posted Fri Aug 10, 2018 6:25 AM

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



#4 Alfred OFFLINE  

Alfred

    Moonsweeper

  • 333 posts
  • Location:Elmwood, Ontario

Posted Fri Aug 10, 2018 6:56 PM

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.



#5 slx OFFLINE  

slx

    Stargunner

  • Topic Starter
  • 1,560 posts
  • Location:Vienna, Austria

Posted Sun Aug 26, 2018 2:53 AM

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 ;) 



#6 Alfred OFFLINE  

Alfred

    Moonsweeper

  • 333 posts
  • Location:Elmwood, Ontario

Posted Sun Aug 26, 2018 7:22 AM

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.


  • slx likes this





Also tagged with one or more of these keywords: Action!

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users