Author Topic: Prizm Useful Routines -- post here!  (Read 28306 times)

0 Members and 1 Guest are viewing this topic.

Ashbad

  • Guest
Re: Prizm Useful Routines -- post here!
« Reply #30 on: September 11, 2011, 07:41:53 pm »
This routine will print masked Glyph numbers for you :) kinda application specific, but others could find use of it.

Code: [Select]
void drawprintnum(int x, int y, int num, int width, int height, void*glyph_nums) {
int digits[10] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
int pos_num = (num<0)?(-num):(num);
int num_digits = 0;
for(int i = 0; i < 10; i++) {
if(!pos_num) { break; }
digits[i] = pos_num%10;
pos_num = (pos_num - (pos_num%10)) / 10;
num_digits++;
}
if(num<0) {
CopySpriteMasked(glyph_nums + (width*height*2*10), x, y, width, height, 0xFFFF);
x += width+2;
} else if (num == 0) {
CopySpriteMasked(glyph_nums, x, y, width, height, 0xFFFF);
return;
}
for(int i = 0; i < num_digits; i++) {
CopySpriteMasked((digits[i]*(width*height*2))+glyph_nums, x, y, width, height, 0xFFFF);
x += width+2;
}
}
« Last Edit: September 11, 2011, 07:44:17 pm by Ashbad »

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Prizm Useful Routines -- post here!
« Reply #31 on: October 24, 2011, 04:42:52 pm »
Is any routine to draw some sprites with alpha based on a colour?

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: Prizm Useful Routines -- post here!
« Reply #32 on: October 25, 2011, 12:10:01 am »
I assume you mean that the alpha color is supplied at runtime and is only a single bit of alpha meaning that every pixel is either opaque or fully transparent. Here's what I got, it should do the trick. It's pretty simple and do note that it doesn't support clipping so if you need that ask and I'll write another routine.

Edit: fixed bug
Edit2: fixed another bug

Code: [Select]

#define WIDTH 384
#define HEIGHT 216

short * VRAM = (short*) GetVRAMAddress();

void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha)
{
     int y_index;
     int x_index;
     short * base = y * WIDTH + x + VRAM;
     for (y_index = height; y_index > 0; --y_index, base += WIDTH - width)
     {
          for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap)
          {
               if (*bitmap != alpha) *base = *bitmap;
          }
     }
}

« Last Edit: October 25, 2011, 04:56:21 pm by z80man »

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Prizm Useful Routines -- post here!
« Reply #33 on: October 25, 2011, 12:13:48 am »
I think if (*base != alpha) should be if (*bitmap != alpha) because you want that color in the bitmap to cause transparency, not that color in VRAM.

Edit: Also, base += WIDTH should be base += WIDTH - width because base was increased by the inner loop.
« Last Edit: October 25, 2011, 12:15:32 am by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: Prizm Useful Routines -- post here!
« Reply #34 on: October 25, 2011, 12:17:41 am »
I think if (*base != alpha) should be if (*bitmap != alpha) because you want that color in the bitmap to cause transparency, not that color in VRAM.

Edit: Also, base += WIDTH should be base += WIDTH - width because base was increased by the inner loop.
Good eye there. I was umm testing you for your ability to catch my on purpose mistakes  :/

The error has been fixed in my above post

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Prizm Useful Routines -- post here!
« Reply #35 on: October 25, 2011, 10:46:40 am »
I should have clip' too, may you do it, please?

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: Prizm Useful Routines -- post here!
« Reply #36 on: October 25, 2011, 04:53:17 pm »
I should have clip' too, may you do it, please?
Sure, I based this example off my previous routine but with some more work I can get a more optimized version out.
Code: [Select]
#define WIDTH 384
#define HEIGHT 216

short * VRAM = (short*) GetVRAMAddress();

void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha)
{
     int y_index;
     int x_index;
     short * base = y * WIDTH + x + VRAM;
     if (y < 0)
     {
          base += (y & 0x8fffffff) * WIDTH;
          bitmap += (y & 0x8fffffff) * WIDTH;
          height += y;
          y = 0;
     }
     if (height > HEIGHT) height = HEIGHT + y;
     for (y_index = height; y_index > 0; --y_index, base += WIDTH - width, bitmap += x_inc)
     {
          
          for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap)
          {
               if (*bitmap != alpha) *base = *bitmap;
          }
     }
}
« Last Edit: October 25, 2011, 04:54:51 pm by z80man »

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Prizm Useful Routines -- post here!
« Reply #37 on: October 25, 2011, 08:39:34 pm »
Okay, that routine is kind of messed up, so here is what I believe to be a fixed version (by the way, y & 0x8FFFFFFF is not even CLOSE to -y)

Code: [Select]
#define WIDTH 384
#define HEIGHT 216

short * VRAM = (short*) GetVRAMAddress();

void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha)
{
int x_inc = width;
if (y < 0)
{
bitmap -= y * x_inc;
height += y;
y = 0;
}
if (height > HEIGHT - y) height = HEIGHT - y;

if (x < 0)
{
bitmap -= x;
width += x;
x = 0;
}
if (width > WIDTH - x) width = WIDTH - x;

int y_index;
int x_index;
short * base = y * WIDTH + x + VRAM;
for (y_index = height; y_index > 0; --y_index, base += WIDTH - width, bitmap += x_inc)
{
for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap)
{
if (*bitmap != alpha) *base = *bitmap;
}
}
}

Edit: I just noticed the x_inc in your code that you never initialized, edited my code to include that.
« Last Edit: October 25, 2011, 08:56:09 pm by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: Prizm Useful Routines -- post here!
« Reply #38 on: October 25, 2011, 10:46:02 pm »
I guess that what happens when you code with little sleep and don't have access to a test platform :P
The x_inc I used (and must of accidentally deleted) is for how much the bitmap pointer needs to be incremented every time a new row is drawn. It is left at zero unless the bitmap overlaps either or both the left and right edges, Here is what I modified to hopefully work. Also one thing that I forgot to do is add some pointer type casts as even though I'm pretty sure  gcc will compile this, g++ could have some issues de to the stronger C++ rules about type casts.
Code: [Select]
#define WIDTH 384
#define HEIGHT 216

short * VRAM = (short*) GetVRAMAddress();

void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha)
{
int x_inc = 0;
if (y < 0)
{
bitmap -= (short*)(y * width);
height += y;
y = 0;
}
if (height > HEIGHT - y) height = HEIGHT - y;

if (x < 0)
{
                bitmap -= (short*)x;
width += x;
x = 0;
                x_inc += -x;
}
if (width > WIDTH - x)
        {
             width = WIDTH - x;
     x_inc += WIDTH - (width + x);
        }
int y_index;
int x_index;
short * base = (short*)(y * WIDTH) + x + VRAM;
for (y_index = height; y_index > 0; --y_index, base += (short*)WIDTH - width, bitmap += (short*)x_inc)
{
for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap)
{
if (*bitmap != alpha) *base = *bitmap;
}
}
}

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Prizm Useful Routines -- post here!
« Reply #39 on: October 25, 2011, 10:52:59 pm »
Eww bad bad typecasts. They won't work (ever try adding a short* to a short*?) and they're just not needed. Adding an int to a pointer is the preferred method for offsetting anyway.
« Last Edit: October 25, 2011, 10:53:30 pm by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: Prizm Useful Routines -- post here!
« Reply #40 on: October 25, 2011, 11:29:40 pm »
Eww bad bad typecasts. They won't work (ever try adding a short* to a short*?) and they're just not needed. Adding an int to a pointer is the preferred method for offsetting anyway.
It's been awhile since I did some heavy messing around with type casts. Looks like I forgot that adding an int to a pointer results in an implicit type cast. All of my programming class stuff (which is in java) makes pointers a lot harder when I come back to C especially because java is very strongly typed.

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Prizm Useful Routines -- post here!
« Reply #41 on: October 25, 2011, 11:30:46 pm »
Eww bad bad typecasts. They won't work (ever try adding a short* to a short*?) and they're just not needed. Adding an int to a pointer is the preferred method for offsetting anyway.
It's been awhile since I did some heavy messing around with type casts. Looks like I forgot that adding an int to a pointer results in an implicit type cast. All of my programming class stuff (which is in java) makes pointers a lot harder when I come back to C especially because java is very strongly typed.
Adding an int to a pointer results in a pointer. There's no implicit typecast at all, that's just how it's defined.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: Prizm Useful Routines -- post here!
« Reply #42 on: October 25, 2011, 11:44:27 pm »
Perhaps this should be tested but atm I don't have a program set up nor the time because I have plenty of homework to do :(
Maybe if I have some time later I'll have some alpha based sprite run around the screen and go through the edges.

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Prizm Useful Routines -- post here!
« Reply #43 on: October 26, 2011, 03:58:53 am »
Thanks, what version should I use? (any name given in the credits, too?)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Prizm Useful Routines -- post here!
« Reply #44 on: October 26, 2011, 09:48:19 am »
Here's a version of my code with fixed x_inc handling (his latest code doesn't work due to the typecasting)

Code: [Select]
#define WIDTH 384
#define HEIGHT 216

short * VRAM = (short*) GetVRAMAddress();

void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha)
{
int x_inc = width;
if (y < 0)
{
bitmap -= y * width;
height += y;
y = 0;
}
if (height > HEIGHT - y) height = HEIGHT - y;

if (x < 0)
{
bitmap -= x;
width += x;
x = 0;
}
if (width > WIDTH - x) width = WIDTH - x;

x_inc -= width;

int y_index;
int x_index;
short * base = y * WIDTH + x + VRAM;
for (y_index = height; y_index > 0; --y_index, base += WIDTH - width, bitmap += x_inc)
{
for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap)
{
if (*bitmap != alpha) *base = *bitmap;
}
}
}
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman