Jump to content

Recommended Posts

Posted (edited)

Perhaps the problem is in using the value afterwards.  If you recall from my explanation before, the fixed-point is stored in reverse order, and the compiler does the magic of scaling by 256, and flipping the bytes for you, and adding the carry of the fractional part to the integer portion.  That way, you do not need to worry about how the fractional part is handled.

 

What that means is that, using this mechanism, the integer part will always be in the lower-byte.  You can then use an AND mask to extract it, like this:

intvar = (#h AND $00FF)

 

As discussed previously, you could wrap that in a macro for easier use:

DEF FN hLow = (#h AND $00FF)

intVar = hLow

Or, more generally (so that you can apply it to any fixed-point 16-bit variable):

DEF FN fixedLow(var) = (var AND $00FF)

intVar = fixedLow(#h)

 

Edited by DZ-Jay
  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)

I guess you can see by now that just asking a single, narrow question such as, "is there a way to DIM the two bytes of a 16 bit variable?" perhaps is not conducive to achieving your ultimate goal.  This is probably because encoded in your question are your personal assumptions about what you are trying to accomplish, but this is not necessarily clear and obvious to the rest of us.  I promise you that I am not being deliberately obtuse; I sincerely want to help you.

 

I will suggest that perhaps it would be best if you describe in more detail what you are trying to accomplish, and maybe show some of your code that is not working correctly.  Even pseudo-code of what you want to do can help us better understand your ultimate goal.  :)

 

     -dZ.

 

Edited by DZ-Jay
  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you! I really appreciate it! A little to late, but here's what I was trying to do, background collision check but using fixed point variables for the sprite

It took a while to get right but it works perfectly now thanks to all the help I get.

If you see anything I could improve please let me know.

Thank you!

 

    DIM #X0

    DIM #Y0

    #X0 =16.0

    #Y0 =16.0



    DIM overlap

    DIM #line



    CONST tileHeightMask = &00000111

    CONST tileHeight = 8

    CONST tileWidthMask = &00000111

    CONST tileWidth = 8

    CONST pfDiff = 8

    CONST spriteHeightMinusOne = 3

    CONST spriteWidthMinusOne = 7



    'top and bottom row and left and right column of sprite

    DEF FN top = ((#Y0 AND 255) - pfDiff) / 8

    DEF FN bottom = (((#Y0 AND 255) - pfDiff) + spriteHeightMinusOne) / 8

    DEF FN left = ((#X0 AND 255) - pfDiff) / 8

    DEF FN right = (((#X0 AND 255) - pfDiff) + spriteWidthMinusOne) / 8

InfiniteLoop:





    IF CONT1.UP = 0 THEN GOTO skipUp

    #Y0 = #Y0 -. 1.0

    overlap = tileHeight - (#Y0 AND tileHeightMask)



    #line = #backtab(right + top * 20)

    IF #line = GW THEN #Y0 = #Y0 +. overlap : GOTO skipUp



    #line = #backtab(left + top * 20)

    IF #line = GW THEN #Y0 = #Y0 +. overlap

skipUp:





    IF CONT1.DOWN = 0 THEN GOTO skipDown

    #Y0 = #Y0 +. 1.0

    overlap = (#Y0 AND tileHeightMask) - 4



    #line = #backtab(right + bottom * 20)

    IF #line = GW THEN #Y0 = #Y0 -. overlap : GOTO skipDown



    #line = #backtab(left + bottom * 20)

    IF #line = GW THEN #Y0 = #Y0 -. overlap

skipDown:





    IF CONT1.LEFT = 0 THEN GOTO skipLeft

    #X0 = #X0 -. 0.5

    overlap = tileWidth - (#X0 AND tileWidthMask)



    #line = #backtab(left + top * 20)

    IF #line = GW THEN #X0 = #X0 +. overlap : GOTO skipLeft



    #line = #backtab(left + bottom * 20)

    IF #line = GW THEN #X0 = #X0 +. overlap

skipLeft:





    IF CONT1.RIGHT = 0 THEN GOTO skipRight

    #X0 = #X0 +. 0.5

    overlap = #X0 AND tileWidthMask



    #line = #backtab(right + top * 20)

    IF #line = GW THEN #X0 = #X0 -. overlap : GOTO skipRight



    #line = #backtab(right + bottom * 20)

    IF #line = GW THEN #X0 = #X0 -. overlap

skipRight:






        SPRITE 0,   #X0 + HIT + VISIBLE,    #Y0,    SPR16 + sprite0FRAME*8 + SPR_YELLOW



        WAIT

    GOTO InfiniteLoop

 

 

 

 

 

Share this post


Link to post
Share on other sites
1 hour ago, Lillapojkenpåön said:

Thank you! I really appreciate it! A little to late, but here's what I was trying to do, background collision check but using fixed point variables for the sprite

It took a while to get right but it works perfectly now thanks to all the help I get.

If you see anything I could improve please let me know.

Thank you!

Great!  I'm glad you got it sorted out. 👍

 

I'll take a deeper look at your code later to see if I can make any recommendations, but at a glance I would say that the following construct:

   IF #line = GW THEN #Y0 = #Y0 +. overlap : GOTO skipUp

   #line = #backtab(left + top * 20)

   IF #line = GW THEN #Y0 = #Y0 +. overlap

skipUp:

 

Could be cleaner using an IF/ELSE/END IF construction, like this:

   IF #line = GW THEN
     #Y0 = #Y0 +. overlap
   ELSE
     #line = #backtab(left + top * 20)

     IF #line = GW THEN #Y0 = #Y0 +. overlap
   END IF

 

Notice that you are skipping the next two lines when the first IF condition is true, which means those statements will only execute if the expression is false.  That's the same as saying "IF <something> THEN <do this> ELSE <do that>"

 

     -dZ.

  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)

My brain has stopped working, I want to scroll horisontally, what would be the best way to read column 20 of the table, and also be able to make the level as big as possible?

Something like this, obviously super wrong since I'm not considering the length of the level, and I'm not trying to use an array, just control the offset

 

  dim #x

  #x=19

  RESTORE level1

  FOR y=0 TO 11

      READ #line(y*20+#x)  

      #BACKTAB(y*20)=#line

  NEXT

 

level1:

    DATA GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW

 

In bB I hade to do alot of manual inc and dec of the high byte of the pointer to do this, and made a program that output my level data column by column instead of row by row

 

Edited by Lillapojkenpåön

Share this post


Link to post
Share on other sites
Posted (edited)

#x=19

  FOR y=0 TO 11

      #BACKTAB(y*20)=level1(y*20+#x)

  NEXT

Edited by nanochess
  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Yes, it is a good example that DATA both can be READ value by value like in classic BASIC, and treated like a constant, indexed array like in e.g. C.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)
On 7/7/2021 at 8:08 PM, Lillapojkenpåön said:

My brain has stopped working, I want to scroll horisontally, what would be the best way to read column 20 of the table, and also be able to make the level as big as possible?

Something like this, obviously super wrong since I'm not considering the length of the level, and I'm not trying to use an array, just control the offset

 

  dim #x

  #x=19

  RESTORE level1

  FOR y=0 TO 11

      READ #line(y*20+#x)  

      #BACKTAB(y*20)=#line

  NEXT

 

level1:

    DATA GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW,GW,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,GW

    DATA GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW,GW

 

In bB I hade to do alot of manual inc and dec of the high byte of the pointer to do this, and made a program that output my level data column by column instead of row by row

 

 

Like @nanochess code suggests, and as mentioned by @carlsson, the access to "DATA" statements in IntyBASIC is treated slightly different from other flavors of BASIC.

 

The key difference is that you can define "blocks" of data by heading them with a label, as follows:

MyData:
   DATA $0000, $0000, $0000, $0000

OtherData:
   DATA $1111, $1111, $1111, $1111

 

This essentially makes such "DATA" blocks work like arrays, which in turn has important implications on how they are accessed.

 

You can still access the blocks in much the same way you do in other flavours of BASIC:  first, by setting the cursor to the beginning of a block using "RESTORE <label>"; second by reading each element into a variable using "READ <variable>".  The main difference is that there isn't really a "global" cursor, so you need to first initialize the cursor by pointing it to a specific block using "RESTORE."

 

(Note that an important consequence of this is that just calling READ without initializing the cursor will not actually read data from your first "DATA" statement as in other implementations of BASIC, so the label is sort of required.)

 

That's fine for sequential reading of data, which is very useful, and is optimized internally by the IntyBASIC runtime.

 

However, because IntyBASIC treats these data blocks as arrays, you can also randomly access them.  This is extremely powerful and allows you to avoid having to load data tables into memory for exactly this purpose.  In IntyBASIC, a data table stored as "DATA" is a look-up table, and you can access each element directly by its index in the table.

 

This is why code like the one offered by @nanochess, works:

    #BACKTAB(y*20)=level1(y*20+#x)

The data block following the label "level1" in your example, is treated as an array, and then specific elements are accessed directly without having to iterate through the entire thing.

 

I hope this provides some useful context to the solutions provided by the others. :)

 

    -dZ.

Edited by DZ-Jay
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
21 hours ago, nanochess said:

#x=19

  FOR y=0 TO 11

      #BACKTAB(y*20)=level1(y*20+#x)

  NEXT

Thanks!  #BACKTAB(y*20)=level1(y*DATACOLUMNS+#x)

It was 38 in my example.

 

 

 

 

 

 

 

  • 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.
Note: Your post will require moderator approval before it will be visible.

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...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...