Jump to content
IGNORED

Question about SPRITE sintax


Recommended Posts

Sorry my english, guys.

 

Could someone explain me what it means "((X AND 3) * 8" in the sentence bellow?

 

SPRITE 0,X + MB_X_INTR + MB_X_VIS, 84+MB_Y_YSIZ2, MB_A_GRAM + X_YEL + ((X AND 3) * 8

 

 

"X" I think that is x-coord of MOB;

"3" I think that is the bitmaps group;

AND ??? ("AND" is, generally, a conditional, but in this situation I think that no)

" * 8" ???

 

 

Thanks!!!

 

 

Ismael

Link to comment
Share on other sites

There's 3 parameters and each one of them is 16 bit wide. Each bit except the last few are what affects the sprites.


sprite 2,Enx(0)-scrolloffset+$300+$400*EnS(0),$100*EnSy(0)+$80+Eny(0),$800+EnP(0)+EnC(0)

This example is what I set up the enemies in my ship shootem up game. If you're going to use scrolling in your game, then scrolloffset is necessory. Enx() is the sprite coordinates. $300 enables both the Interaction and visibility bits, which is bit 8 and 9. $400*EnS() enables or disable the double x size bit, which is bit 10. $100*EnSy enables or disables bit 8 and 9, which size the sprite y size by 2 times or 4 times. $80 turns bit 7 on, which enables the 16-line sprites. Eny() is the enemy y coordinates. And last parameter is what card and color is that object going to be. $800 turns bit 11 on, always use GRAM cards. EnP() is the card number. And lastly EnC() is the color. Enabling bit 12 will use the pastel colors, $1000 will turn that bit on.

You can see the information about sprites in the SPRITE section of the manual that came with IntyBASIC.

Link to comment
Share on other sites

It depends on the context. At first glance, it looks like "X" represents the X coordinate of the sprite.

 

MB_X_INTR = I imagine this refers to the "interaction bit" of a MOB's X register. This sets whether your sprite will generate collision events.

MB_X_VIS = Visibility bit in the X register. Sets whether the sprite is visible or not.

MB_Y_YSIZ2 = Zoom X2 bit in the Y register. Displays the MOB at twice it's size in the vertical axis.

MB_A_GRAM = GRAM bit in the A register. Specifies that the sprite graphics is a custom card taken from GRAM (as opposed to GROM).

X_YEL = Sets the color bits of the sprite to yellow.

 

The "SPRITE" statement is like this:

SPRITE [0-7], x, y, f
  x = x register value
  y = y register value
  f = a register value

Each register is 16-bits and follow this format:

X Register - Object position along the X axis:
  +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  | - : - : - : - : - | Z | V | I | X : X : X : X : X : X : X : X |
  +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
    F   E   D   C   B   A   9   8   7   6   5   4   3   2   1   0
                        \___,___/   \_____________,_____________/
                            |                     |
                            v                     v
                        Attributes             Position

    Attributes:                         Position:
    -----------------                   -----------------------------
    I - Interaction                     X - Position along the X axis
    V - Visible                             (0 to 255)
    Z - Zoom X x2

Y Register - Object position along the Y axis:
  +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  | - : - : - : - | V | H | Q | D | R | Y : Y : Y : Y : Y : Y : Y |
  +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
    F   E   D   C   B   A   9   8   7   6   5   4   3   2   1   0
                    \_______,_______/   \___________,___________/
                            |                       |
                            v                       v
                        Attributes               Position

    Attributes:                         Position:
    -------------------------------     -----------------------------
    R - Double vertical resolution      Y - Position along the Y axis
    D - Zoom Y x2                           (0 - 127)
    Q - Zoom Y x4
    H - Flip horizontally
    V - Flip vertically

A Register - Object color and other attributes:
  +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  | - : - | O | F | M | C : C : C : C : C : C : C : C | P : P : P |
  +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
    F   E   D   C   B   A   9   8   7   6   5   4   3   2   1   0
            \___,___/   \_____________,_____________/   \___,___/
                |                     |                     |
                v                     v                     v
            Attributes              Card                  Color

    Attributes:             Card:                   Color:
    --------------          ----------------        ------------------
    M - GRAM Flag           C - Card number         P - Primary color
    O - Priority                (0 to 255)          F - Pastel color

The statement you posted seems to compose a format attribute word specifying a GRAM card calculated from the "X" coordinate divided by 8 (i.e., aligned to the closest 8x8 background card), and setting it to yellow.

 

"X AND 3" is the same as X SHIFT RIGHT 3 bits (divide by 8 ) and then SHIFT LEFT 3 bits (multiply by 8 ). The last shift/multiply is because the "A" register has the card number aligned three bits from the right, starting on Bit #3 after the color.

 

 

 

 

EDIT: I've stricken the line above because it was incorrect. the "X AND 3" does a "modulo 4" on the X position to determine which of 4 animation frames to use for the sprite's graphic. I've explained it with more details below.

Edited by DZ-Jay
  • Like 3
Link to comment
Share on other sites

Guys, you are amazing!

 

I'm giving my first steps in Intellivision programming (I'm realizing a dream). I'm analysing the all BAS file programs released in this forum (some very well commented).

 

Thanks a lot!

 

Ismael

Curitiba - Brazil

  • Like 3
Link to comment
Share on other sites

Sorry my english, guys.

 

Could someone explain me what it means "((X AND 3) * 8" in the sentence bellow?

 

SPRITE 0,X + MB_X_INTR + MB_X_VIS, 84+MB_Y_YSIZ2, MB_A_GRAM + X_YEL + ((X AND 3) * 8

 

 

"X" I think that is x-coord of MOB;

"3" I think that is the bitmaps group;

AND ??? ("AND" is, generally, a conditional, but in this situation I think that no)

" * 8" ???

 

 

Thanks!!!

 

 

Ismael

 

Don't know that anyone's quite explained this:

 

AND is a bitwise operation often used to check specific bits. The basic rules are 0 AND 0 = 0, 0 AND 1 = 0, 1 AND 1 = 1. This operation is applied to every single bit in each operand. How it's being used here: X is an 8 bit variable. 3 is of course a constant, which in binary is 00000011. Essentially what this is doing is masking out (checking) the last 2 bits in X. Some examples:

 

X = 5 (00000101). X AND 3 = (1) 00000001.

 

X = 255 (11111111). X AND 3 = (3) 00000011.

 

And everything in between.

 

I'm not entirely sure the intention here (others seem to have a better idea but I see conflation between the X co-ord and the GRAM card #, which could be something clever being done) but the idea is that in this case, you're checking to see which of the last 2 bits are set to 1. It's a very useful trick. The net result is the shifts DZ described, but I've always found it easier to visualize it as bitmasking.

 

Incidentally, you can use OR to SET specific bits instead of CHECK bits. Another very handy trick.

 

Disclaimer - I'm writing this from a hotel room after too many hours on the highway, so I may be completely out to lunch here :)

  • Like 1
Link to comment
Share on other sites

 

Don't know that anyone's quite explained this:

 

AND is a bitwise operation often used to check specific bits. The basic rules are 0 AND 0 = 0, 0 AND 1 = 0, 1 AND 1 = 1. This operation is applied to every single bit in each operand. How it's being used here: X is an 8 bit variable. 3 is of course a constant, which in binary is 00000011. Essentially what this is doing is masking out (checking) the last 2 bits in X. Some examples:

 

X = 5 (00000101). X AND 3 = (1) 00000001.

 

X = 255 (11111111). X AND 3 = (3) 00000011.

 

And everything in between.

 

I'm not entirely sure the intention here (others seem to have a better idea but I see conflation between the X co-ord and the GRAM card #, which could be something clever being done) but the idea is that in this case, you're checking to see which of the last 2 bits are set to 1. It's a very useful trick. The net result is the shifts DZ described, but I've always found it easier to visualize it as bitmasking.

 

Incidentally, you can use OR to SET specific bits instead of CHECK bits. Another very handy trick.

 

Disclaimer - I'm writing this from a hotel room after too many hours on the highway, so I may be completely out to lunch here :)

This looks like it's from my "one_sprite.bas" sample program, that displays a robot running across the screen.

In this example, the robot has 4 frames of animation:

gramchars:

REM 0

	BITMAP "...####."
	BITMAP "...###.."
	BITMAP "...####."
	BITMAP "....#..."
	
	BITMAP "..######"
	BITMAP "..#.#..."
	BITMAP "....#..."
	BITMAP ".....#.."
	
REM 1

	BITMAP "...####."
	BITMAP "...###.."
	BITMAP "...####."
	BITMAP "....#..."
	
	BITMAP "..######"
	BITMAP "..#.#..."
	BITMAP "....##.."
	BITMAP "....#..."
	
REM 2

	BITMAP "...####."
	BITMAP "...###.."
	BITMAP "...####."
	BITMAP "....#..."
	
	BITMAP "..######"
	BITMAP "..#.#..."
	BITMAP "....#.#."
	BITMAP "...#...."
	
REM 3

	BITMAP "...####."
	BITMAP "...###.."
	BITMAP "...####."
	BITMAP "....#..."
	
	BITMAP "..######"
	BITMAP "..#.#..."
	BITMAP "...##..."
	BITMAP "......#."
	

These frames are loaded into GRAM cards 0-3. So the sprite command takes the x coordinate of the sprite and "ANDS" it with 3 to choose one of the 4 animation frames to display.

  • Like 3
Link to comment
Share on other sites

I believe I screwed up by reversing the mask in my head. It's not at all what I said, but reducing the position to one of four frames of animation, which is explained by Catsfolly. It is rather clear to me now, of course once I'm sitting at home.

 

That's what I get for trying to be helpful while reading on my stupid phone. Sorry. :)

 

To expand on the explanation: If there are four frames of animation and you need a different one as the sprite moves, then you need to know in which of the four "slots" the sprite is at any given time to figure out its animation frame.

 

For instance, you start at position 0 and frame 0, then move to position 1 and frame 1, and so on until position 3 and frame 3. After that it's position 4, and you start again at frame 0, then position 5 and frame 1 and so on an on:

X Pos   Frame
------|-------
   0  |   0   
   1  |   1
   2  |   2
   3  |   3
   4  |   0
   5  |   1
   6  |   2
   7  |   3
   8  |   0
   9  |   1
  10  |   2
  11  |   3
  12  |   0
  13  |   1
  14  |   2
  15  |   3
  

If you notice, it's the same as taking the position value and calculating modulo four:

xpos % 4 = frame

This is the same as a division by four and taking the residual, which is accomplished with an AND operation on the two least significant bits, which is binary 0011 or decimal 3.

xpos % 4 = xpos AND 3 = frame

That gives you the card number of the animation frame. The multiplication by 8 operation does what I had said before: it shifts the card number three bits to the left to fit in its corresponding field in the "A" register of the MOB.

 

-dZ.

  • Like 5
Link to comment
Share on other sites

Yes, DZ. In this situation there are a VARIABLE multiplied by a constant, I suspected that was it, but I'm not used to dealing with register and bits (I'm Delphi developer).

Intybasic is a great tool but you need knowledge in "low level language".

I'm studyng the BAS files downloaded (sprites, one_sprite, robot_blast_r, etc). I'm changing values, compiling, running in JZINTV emulator. I'm learning several things about how intellivision work.

Edited by Descolado
Link to comment
Share on other sites

Yes, DZ. In this situation there are a VARIABLE multiplied by a constant, I suspected that was it, but I'm not used to dealing with register and bits (I'm Delphi developer).

Intybasic is a great tool but you need knowledge in "low level language".

I'm studyng the BAS files downloaded (sprites, one_sprite, robot_blast_r, etc). I'm changing values, compiling, running in JZINTV emulator. I'm learning several things about how intellivision work.

 

I understand. Help is on the way, so hang in there. IntyBASIC is being improved with many features to make it easier to use and to abstract many of the low level details.

 

Keep in mind that one of the things that make IntyBASIC so powerful is that it is extremely close to the "metal." This allows you to make programs that are almost as fast and powerful as Assembly Language, but with a higher level syntax framework.

 

-dZ.

  • Like 2
Link to comment
Share on other sites

Keep in mind that one of the things that make IntyBASIC so powerful is that it is extremely close to the "metal." This allows you to make programs that are almost as fast and powerful as Assembly Language, but with a higher level syntax framework.

 

I can't second this enough. While there's always room for improvement, right now IntyBASIC is probably 70-90% (completely made up figure) as fast as pure Assembly. Which is damned fast for any HLL.

 

You'll never really be able to get completely away from understanding at least something about the hardware. And most of the questions people post here, to be quite honest, aren't something you can abstract away from. There's a lot of questions that are fundamentally "how does this math trick work" or "how do I create this data structure" - things that don't disappear no matter how high level you are. We can improve the syntax and add in optimization goodies, but there is a limit.

 

And I hope people realize just how fricking amazing IntyBASIC is already at shielding you from Assembly. I've coded in both, and never having to write a FOR loop or IF conditional in ASM is heaven. This isn't some half-assed BASIC that you still need to know a ton in order to use. Beyond hardware register knowledge, you literally can write the same code I was able to do when I was 8 years old, and end up with a fun and playable game. Not exactly advanced programming skills required.

  • Like 3
Link to comment
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...