Jump to content
IGNORED

Vectrex screen coordinates system


Yoruk

Recommended Posts

Hello there,

 

I was studying the incredible Vectrex, and to understand more how it works I started to code a small sample. Well for now it's just a moving "sprite", but maybe in the future it may become a small game. ?

 

I'm almost unfamiliar with assembly language (my small skills are only on the 6502) so I used the CMOC compiler to compile a source written in C. For now everything is fine. I found some samples, and with them I was able to start.

 

But now I have issues with the coordinates system. I understand that (0,0) is the screen center.

 

My sprite position, when I move it to (0,0) is perfectly aligned with the screen center :

 

image.thumb.png.d4d58b70f8ee0354c1c303b047823db9.png

 

My x/y variables are defined with uint8_t values.

 

When I move slightly to the left (x = x-1), as my x value can't be <0 it becomes like 250, and it works fine. (Looping between 0...255, normal).

 

So now I want to add a missile. When pushing a button a second "sprite" is added, moving on the +x axis, starting at the actual player position. The idea is to "cut" the missile once it is away from the screen.

 

So in my code I have something like this :

 

Quote

if ( ShootInProgress==1 &&  missileX >= 254 )                    
        ShootInProgress=0;

 

if ( ShootInProgress==1)

     drawMissile();

 

to "reset" the missile once it goes away from the screen. BUT 254 doesn't works as a limit, as x=254 means the middle of the screen.  The good "edge" value should be 128 is the missile is fired on the right part of the screen, 255 if left.

 

So I'm not sure how to deal with that. I can of course use an other variable or programming trick to solve this problem, but maybe it's not the good way to work.

 

Is there a good way to deal with coordinates ? Like using a signed variable ??? (something from -128 to +128) ???

 

Thanks for your feedback...

 

 

 

 

Link to comment
Share on other sites

Ok my knowledge on this is slowly increasing, but there is still some weird things that I need to understand, like the set_scale function that could be used to size objects.

 

It looks like that a scale value of 128 leave the object untouched, 64 divide the size by two, and so one.

 

But I don't see how to deal with multiples values, like putting two set_scales instructions together. It seems that everything is relative !

 

I didn't manage to find a programming manual or similar stuff on this (only for assembly...).

 

Is there resources for the Vectrex for C programming ?

Link to comment
Share on other sites

  • 5 weeks later...

Is there any C gurus here ? I have some issues with my custom "itoa" function that I use to convert a signed char (or unsigned) into a string :

 

/* reverse:  reverse string s in place */
void m_reverse(char s[])
{
    char i, j;
    char c;

    for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
        c = s[i];
        s[i] = s[j];
        s[j] = c;
    }
}

//* itoa:  convert n to characters in s */
void m_itoa(char n, char s[])
{
    char i, sign;

    if ((sign = n) < 0)  /* record sign */
        n = -n;          /* make n positive */
    i = 0;
    do {       /* generate digits in reverse order */
        s[i++] = n % 10 + '0';   /* get next digit */
    } while ((n /= 10) > 0);     /* delete it */
    if (sign < 0)
        s[i++] = '-';
    s[i] = '\0';
    m_reverse(s);
}

 

(I can't remember the source).

 

 

And, in my display loop :
 

  m_itoa(x, sX);   
  m_itoa(y, sY);   
        
print_str_c(127, 190, sX);  //y  x
print_str_c(127 , 0, sY);  //y  x

It does works fine with positives or negative numbers :

 

image.thumb.png.ef13db75acada3959281da5b4e57722f.png

 

 

But it doesn't works with numbers  between -9 and 9 (with one digit). A kind of underscore is displayed instead :

 

image.thumb.png.8a3c428af5063b60ca165fda10d73c34.png

 

I didn't manage to solve this. IS there something wrong with my itoa function ? Maybe a problem on the internal while loop... I'll check.

 

 

Link to comment
Share on other sites

  • 2 weeks later...

The functions look ok - though I didn't test them.

 

It might just be the printStr() functions of the vectrex BIOS.

For them to display correct results you need strings with AT LEAST THREE characters.

 

Try adding an additional function, which puts in leading spaces (or trailing) so the "numbers" are at least 3 characters long.

Link to comment
Share on other sites

Ok so this actually works :

 

//* itoa:  convert n to characters in s */

void m_itoa2(unsigned char n, char s[])

{

    unsigned char i, sign,f;


    if ((sign = n) < 0)  /* record sign */

        n = -n;          /* make n positive */


    f=n;


    i = 0;

    do {       /* generate digits in reverse order */

        s[i++] = n % 10 + '0';   /* get next digit */

    } while ((n /= 10) > 0);     /* delete it */

    

    if (f < 10)

        s[i++] = '0' + n ;

    

    

    if (sign < 0)

        s[i++] = '-';

    s[i] = '\0';

    m_reverse(s);

}

 

It adds a zero in numbers <10.

 

image.png.a530ad30e24f2870a271fb76cda23264.png

 

So yes, maybe it's just a small issue in the ROM code...

 

Link to comment
Share on other sites

I know you are using cmoc instead of gcc.

But I don't know if you know about Vide. (http://vide.malban.de/)

 

Even if you don't use Vide, the blog, the documentation (help and other docs provided with it) and the links I have collected provide much information about "everything vectrex".

If you have not looked at those yet - I'd recomend it.

(also many example "C" code)

 

Just a thought...

 

Also Roger Boesch has developed a "beginners" IDE for CMOC coding for the Vectrex, check out his Video: https://www.youtube.com/watch?v=I3f8qO8AU_k

 

 

Cheers

Malban

Edited by Malban
Link to comment
Share on other sites

My actual dev enviroment is very light, (Qt creator as IDE, a batch file to compile, and ParaJVE for execution). It works, but it's absolutely not easy to wok with.

 

I've downloaded Vide, I'll sure take a deep look at it. ?

Link to comment
Share on other sites

On 7/21/2021 at 12:50 AM, Yoruk said:

Ok so this actually works :

>  if ((sign = n) < 0) n = -n;


Any code with that logic in it will fail on the largest negative number. 

 

Integers go from -MAX-1 to MAX so negating the largest negative number results in MAX+1 which overflows MAX, but negating MAX merely results in -MAX which is not as negative as -MAX-1.

 

So, on a machine with a divide, it's marginally better to do:

 

if ((sign = m) > 0) n == -n

 

and divide or mod by -10 each step.  I.e. work with negative numbers until you come to outputting the digits.

 

However on the Vectrex I try to avoid divides - see for example  "unsigned int8_t itoa" in http://gtoal.com/vectrex/vecavern/v.c.html

although I must admit I've never done a benchmark to confirm that it is faster number to ascii conversion code. I should do that one day...

 

G

Edited by gtoal
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...