Newbie wanting help

General Programming help in C, C++ or ASM, Compiling / Debugging, and R3000A Central Processing Unit (CPU) information
Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Newbie wanting help

Post by Chris » December 20th, 2014, 1:54 pm

OK, so I've been making my game, slowly, and it works OK, but I do have a few questions.
#1. How would I make it so I can have more than one place to draw graphics from? I'm using TIM tool and am having success in adding new images to it, but I figure sometime soon, the CLUT will be all filled up. Is there a way to switch or add a CLUT so I can have more images? How would I do so in the code?
#2. How do I display text? Any font will do. I tried printf and no text showed up.
If you want to look at my code, you can find it here:
http://www.atari2600land.com/jackandthebeanstalk/

User avatar
Shendo
C Programming Expert
C Programming Expert
Posts: 238
Joined: March 21st, 2012, 4:34 am
I am a: Programmer
Motto: Never settle
PlayStation Model: SCPH-9002
Location: Croatia, EU

Re: Newbie wanting help

Post by Shendo » December 25th, 2014, 11:14 pm

You can place CLUT anywhere in the VRAM. I'm not sure I understand when you say that it will all be filled up...

As for displaying text you can use FntPrint() function. printf is for debug only and is usually used on serial port..
However I encurage you to write your own text displaying routine because FntPrint is pretty limited.
My PS1 consoles: 2 x SCPH-1002, SCPH-5552, SCPH-7002, 4x SCPH-9002, 2 x SCPH-102.
Dev console: SCPH-9002, MM3 - 7 wire modchip, PAL color mod, CH340 serial cable addon.

Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Re: Newbie wanting help

Post by Chris » December 26th, 2014, 8:00 pm

OK, so suppose I have an image starting at 0,0. So how would I make it read a different image at 0,0? Or would you just have different CLUTs? I will try FntPrint() first and see how that works.

User avatar
Shendo
C Programming Expert
C Programming Expert
Posts: 238
Joined: March 21st, 2012, 4:34 am
I am a: Programmer
Motto: Never settle
PlayStation Model: SCPH-9002
Location: Croatia, EU

Re: Newbie wanting help

Post by Shendo » December 27th, 2014, 11:16 am

First I would suggest to just go with 16 bit images to avoid using CLUTs.
Once you manage that then start using palletized images.

You should upload image to VRAM outside of your display buffer (usually 320,0 should suffice) and then make a sprite out of it. After that set up a game loop and draw that sprite each frame.
My PS1 consoles: 2 x SCPH-1002, SCPH-5552, SCPH-7002, 4x SCPH-9002, 2 x SCPH-102.
Dev console: SCPH-9002, MM3 - 7 wire modchip, PAL color mod, CH340 serial cable addon.

Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Re: Newbie wanting help

Post by Chris » December 27th, 2014, 5:35 pm

OK, so when I go into TimTool to make a new image, I select 16 bit colors. So does that mean I haven't been using CLUTs at all and so I could put the sprite at any position?

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2233
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: Newbie wanting help

Post by Shadow » December 27th, 2014, 5:39 pm

16-bit TIM's don't use CLUT's. You don't need to worry about it if they are 16-bits (just like Shendo said).
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Re: Newbie wanting help

Post by Chris » January 7th, 2015, 3:28 pm

I have a tree sprite. I want multiple copies of the tree sprite scattered various places, like a pattern. How would I do this? The pattern of the trees would change once you clear the screen.

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2233
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: Newbie wanting help

Post by Shadow » January 7th, 2015, 3:56 pm

If you want them in a pattern, then you should use a predefined array for the TIM's X and Y position on the screen.

I'm confused by your second line " The pattern of the trees would change once you clear the screen.". It contradicts your first argument stating it's not random. If it's not random, then an array will work. Otherwise, you will need to use the random function within Psy-Q. Additional logic will be required to ensure that you do not get trees overlapping and being placed too close to one another.

Code: Select all

int Random(int max) { return (rand()%max); }
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Re: Newbie wanting help

Post by Chris » January 7th, 2015, 4:06 pm

Well, I would want the trees in specific various places, not randomly, like to create a maze of trees that the player must navigate through.

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2233
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: Newbie wanting help

Post by Shadow » January 7th, 2015, 4:54 pm

Ah, well a hardcoded array will suffice nicely then :)
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Re: Newbie wanting help

Post by Chris » January 8th, 2015, 1:08 pm

But before I attempt to do that, a new problem popped up. It seems that moving Jack left or up glitches up all the sprites until he gets to near the top. I don't know what's causing this.
Attachments
ihatethisstupidthing.png
(22.34 KiB) Downloaded 118 times

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2233
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: Newbie wanting help

Post by Shadow » January 8th, 2015, 6:05 pm

Looks like you're overwriting something.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

User avatar
nocash
PSX Aficionado
PSX Aficionado
Posts: 306
Joined: November 12th, 2012, 2:36 pm
Contact:

Re: Newbie wanting help

Post by nocash » January 8th, 2015, 10:17 pm

Or you got something wrong when you tried to scroll-down the screen when moving-up?

Using a VRAM Viewer that can display the whole 1024x512 pixel video memory (=not just the display area) might help you to figure out what's going on.

Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Re: Newbie wanting help

Post by Chris » January 9th, 2015, 6:50 am

I fixed that problem I was having. Seems like I was calling something when I wasn't supposed to be.
About arrays, then, I have been using the sample code for displaying a picture. Would I be able to shorten the code a lot when I put it in one? Here's the code I am using to display one tree:

Code: Select all

 RECT            rect;                                    // RECT structure
 GsIMAGE         tim_data;                                // holds tim graphic info
   
   // put data from the raw binary header file into rect         
   GsGetTimInfo((u_long *)(treetoruninto+4),&tim_data);

   // load the image into the frame buffer
   rect.x = tim_data.px;                                    // tim start X coord
   rect.y = tim_data.py;                                    // tim start Y coord
   rect.w = tim_data.pw;                                    // data width
   rect.h = tim_data.ph;                                    // data height
   // load the tim data into the frame buffer
   LoadImage(&rect, tim_data.pixel);       

   // load the CLUT into the frame buffer
   rect.x = tim_data.cx;                                    // x pos in frame buffer
   rect.y = tim_data.cy;                                    // y pos in frame buffer
   rect.w = tim_data.cw;                                    // width of CLUT
   rect.h = tim_data.ch;                                    // height of CLUT
   // load data into frame buffer (DMA from DRAM to VRAM)
   LoadImage(&rect, tim_data.clut);



   // initialise sprite
   treea.attribute=0x2000000;                           	// 16 bit CLUT, all options off (0x1 = 8-bit, 0x2 = 16-bit)
   treea.x = treeax;                                        // draw at x coord 0
   treea.y = treeay;                                        // draw at y coord 0
   treea.w = 15;                                        	// width of sprite
   treea.h = 42;                               		    	// height of sprite
   // texture mode (0 4-bit, 1 8-bit, 2 16-bit), semi-transparency rate, texture x, texture y in the framebuffer
   treea.tpage=GetTPage(2, 1, 896, 0);
   treea.r = 128;                                       	// RGB Data
   treea.g = 128;
   treea.b = 128;
   treea.u=0;                                           	// position within timfile for sprite
   treea.v=0;                                           
   treea.cx = tim_data.cx;                             	 	// CLUT location x coord
   treea.cy = tim_data.cy;                              	// CLUT location y coord
   treea.r=treea.g=treea.b=128;                   			// normal luminosity
   treea.mx = 0;                                        	// rotation x coord
   treea.my = 0;                                        	// rotation y coord
   treea.scalex = ONE;                                  	// scale x coord (ONE = 100%)
   treea.scaley = ONE;                                  	// scale y coord (ONE = 100%)
   treea.rotate = 0;                                    	// degrees to rotate

Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Re: Newbie wanting help

Post by Chris » January 18th, 2015, 4:37 pm

I learned about arrays, I think I learned how to understand them, but what I don't understand is how to make multiple copies(in this case, trees), out of the same image. As a test, I did an array from 0-4 and I only got one tree to display at the last array point. What do I do?

int treesxscreen1 [5] = { 30, 70, 140, 170, 230 };

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2233
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: Newbie wanting help

Post by Shadow » January 18th, 2015, 5:10 pm

You need to tell the function to use treesxscreen1 but increment through the array of 1 to 5.
At the moment, you have, but it's using the last integer in the array (230) which would be 5.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Re: Newbie wanting help

Post by Chris » January 18th, 2015, 5:19 pm

Well, even if I do this, it still displays one tree:

Code: Select all

    treea.x = treesxscreen1[0];                                   // draw at x coord 0
    treea.y = treesxscreen1[0];                                   // draw at y coord 0
    treea.x = treesxscreen1[1];                                   // draw at x coord 0
    treea.y = treesxscreen1[1];  
    treea.x = treesxscreen1[2];                                   // draw at x coord 0
    treea.y = treesxscreen1[2];                                   // draw at y coord 0
    treea.x = treesxscreen1[3];                                   // draw at x coord 0
    treea.y = treesxscreen1[3];  
    treea.x = treesxscreen1[4];                                   // draw at x coord 0
    treea.y = treesxscreen1[4];                                   // draw at y coord 0

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2233
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: Newbie wanting help

Post by Shadow » January 18th, 2015, 5:47 pm

Of course it will :P
It's setting them, yes, but it's doing them in order so the variable is being overwritten.
So, the last one will be the one set (treea.x = treesxscreen1[4]; treea.y = treesxscreen1[4];)

You need to do looping/routine logic. Something like this (note, this is just a crude example!):

Code: Select all

for(;;)
{
     // if the tree is off the screen, update the position
     if (treea.x < 0) { treea.x = treesxscreen1[0]; treea.y = treesxscreen1[0]; }
     if (treea.x == 100) { treea.x = treesxscreen1[1]; treea.y = treesxscreen1[1]; }
     // and so on...
}
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Re: Newbie wanting help

Post by Chris » January 18th, 2015, 6:02 pm

If I try to do any for statement beginning with for(;;) the game freezes.

Chris
Active PSXDEV User
Active PSXDEV User
Posts: 47
Joined: July 3rd, 2013, 4:38 am
Location: USA
Contact:

Re: Newbie wanting help

Post by Chris » January 18th, 2015, 6:13 pm

OK, I understand why now.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest