Yoruk Posted June 8, 2021 Share Posted June 8, 2021 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 : 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... Quote Link to comment Share on other sites More sharing options...
gtoal Posted June 8, 2021 Share Posted June 8, 2021 Yes, life will be much simpler if you use signed chars for X and Y coordinates! Quote Link to comment Share on other sites More sharing options...
Yoruk Posted June 8, 2021 Author Share Posted June 8, 2021 I tried to use int8_t variables to store my positions. Seems to work fine now !! Now I can go deeper.... Thanks ! ? Quote Link to comment Share on other sites More sharing options...
Yoruk Posted June 10, 2021 Author Share Posted June 10, 2021 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 ? Quote Link to comment Share on other sites More sharing options...
Yoruk Posted July 9, 2021 Author Share Posted July 9, 2021 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 : But it doesn't works with numbers between -9 and 9 (with one digit). A kind of underscore is displayed instead : 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. Quote Link to comment Share on other sites More sharing options...
Malban Posted July 19, 2021 Share Posted July 19, 2021 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. Quote Link to comment Share on other sites More sharing options...
Yoruk Posted July 21, 2021 Author Share Posted July 21, 2021 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. So yes, maybe it's just a small issue in the ROM code... Quote Link to comment Share on other sites More sharing options...
Malban Posted July 21, 2021 Share Posted July 21, 2021 (edited) 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 July 21, 2021 by Malban Quote Link to comment Share on other sites More sharing options...
Yoruk Posted July 23, 2021 Author Share Posted July 23, 2021 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. ? Quote Link to comment Share on other sites More sharing options...
gtoal Posted July 26, 2021 Share Posted July 26, 2021 (edited) 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 July 26, 2021 by gtoal Quote Link to comment Share on other sites More sharing options...
Yoruk Posted July 27, 2021 Author Share Posted July 27, 2021 I'll try this "unsigned int8_t itoa" function, thanks !! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.