Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
19 June, 2013, 08:55:10 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: 1 2 [3] 4 5   Go Down
  Print  
Author Topic: Prizm Useful Routines -- post here! -  (Read 4064 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Ashbad
Guest
« Reply #30 on: 12 September, 2011, 01:41:53 »
0

This routine will print masked Glyph numbers for you Smiley kinda application specific, but others could find use of it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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: 12 September, 2011, 01:44:17 by Ashbad » Logged
Eiyeron
LV7 Elite (Next: 700)
*******
Offline Offline

Gender: Male
Last Login: 07 January, 2013, 20:29:04
Date Registered: 09 August, 2011, 16:51:22
Location: Err 404.
Posts: 552


Total Post Ratings: +18

View Profile WWW
« Reply #31 on: 24 October, 2011, 22:42:52 »
0

Is any routine to draw some sprites with alpha based on a colour?
Logged




z80man
Casio Traitor
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 10 June, 2013, 08:37:04
Date Registered: 26 December, 2010, 10:02:50
Location: City 17
Posts: 966


Total Post Ratings: +83

View Profile
« Reply #32 on: 25 October, 2011, 06:10:01 »
0

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#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: 25 October, 2011, 22:56:21 by z80man » Logged


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)
calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: Today at 07:09:04
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2737


Total Post Ratings: +376

View Profile
« Reply #33 on: 25 October, 2011, 06:13:48 »
0

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: 25 October, 2011, 06:15:32 by calc84maniac » Logged

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
z80man
Casio Traitor
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 10 June, 2013, 08:37:04
Date Registered: 26 December, 2010, 10:02:50
Location: City 17
Posts: 966


Total Post Ratings: +83

View Profile
« Reply #34 on: 25 October, 2011, 06:17:41 »
0

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  Undecided

The error has been fixed in my above post
Logged


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)
Eiyeron
LV7 Elite (Next: 700)
*******
Offline Offline

Gender: Male
Last Login: 07 January, 2013, 20:29:04
Date Registered: 09 August, 2011, 16:51:22
Location: Err 404.
Posts: 552


Total Post Ratings: +18

View Profile WWW
« Reply #35 on: 25 October, 2011, 16:46:40 »
0

I should have clip' too, may you do it, please?
Logged




z80man
Casio Traitor
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 10 June, 2013, 08:37:04
Date Registered: 26 December, 2010, 10:02:50
Location: City 17
Posts: 966


Total Post Ratings: +83

View Profile
« Reply #36 on: 25 October, 2011, 22:53:17 »
0

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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: 25 October, 2011, 22:54:51 by z80man » Logged


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)
calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: Today at 07:09:04
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2737


Total Post Ratings: +376

View Profile
« Reply #37 on: 26 October, 2011, 02:39:34 »
0

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)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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: 26 October, 2011, 02:56:09 by calc84maniac » Logged

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
z80man
Casio Traitor
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 10 June, 2013, 08:37:04
Date Registered: 26 December, 2010, 10:02:50
Location: City 17
Posts: 966


Total Post Ratings: +83

View Profile
« Reply #38 on: 26 October, 2011, 04:46:02 »
0

I guess that what happens when you code with little sleep and don't have access to a test platform Tongue
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#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;
}
}
}
Logged


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)
calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: Today at 07:09:04
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2737


Total Post Ratings: +376

View Profile
« Reply #39 on: 26 October, 2011, 04:52:59 »
0

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: 26 October, 2011, 04:53:30 by calc84maniac » Logged

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
z80man
Casio Traitor
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 10 June, 2013, 08:37:04
Date Registered: 26 December, 2010, 10:02:50
Location: City 17
Posts: 966


Total Post Ratings: +83

View Profile
« Reply #40 on: 26 October, 2011, 05:29:40 »
0

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


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)
calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: Today at 07:09:04
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2737


Total Post Ratings: +376

View Profile
« Reply #41 on: 26 October, 2011, 05:30:46 »
0

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

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
z80man
Casio Traitor
LV8 Addict (Next: 1000)
********
Offline Offline

Gender: Male
Last Login: 10 June, 2013, 08:37:04
Date Registered: 26 December, 2010, 10:02:50
Location: City 17
Posts: 966


Total Post Ratings: +83

View Profile
« Reply #42 on: 26 October, 2011, 05:44:27 »
0

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 Sad
Maybe if I have some time later I'll have some alpha based sprite run around the screen and go through the edges.
Logged


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)
Eiyeron
LV7 Elite (Next: 700)
*******
Offline Offline

Gender: Male
Last Login: 07 January, 2013, 20:29:04
Date Registered: 09 August, 2011, 16:51:22
Location: Err 404.
Posts: 552


Total Post Ratings: +18

View Profile WWW
« Reply #43 on: 26 October, 2011, 09:58:53 »
0

Thanks, what version should I use? (any name given in the credits, too?)
Logged




calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: Today at 07:09:04
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2737


Total Post Ratings: +376

View Profile
« Reply #44 on: 26 October, 2011, 15:48:19 »
0

Here's a version of my code with fixed x_inc handling (his latest code doesn't work due to the typecasting)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#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;
}
}
}
Logged

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
Pages: 1 2 [3] 4 5   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.849 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.