Jump to content
Kiwi

Just need help with C programming.

Recommended Posts

I am a little nervous asking question, but I need to understand some functions that is confusing and why it isn't working. What I'm doing is I want to copy a character tile to a wild card tile. In my game, I want the "wallpaper" to change when you are in a different area like in the cave, you will see cave wall. I'm trying to understand some routines like get_vram(0x0480,[not exactly what to put here],1). How to get an array of 8 byte so I think get_vram suppose to fill 8 byte of data being copied from VRAM byte 0x0480-0x0488, which is where the brick texture is on the charset when loaded from memory. And load that data to 0x0408-0x040f, which should change the brick background painlessly.

 

Here's an illustration what I'm trying to do. I

post-24767-128262026736_thumb.png post-24767-128262027734_thumb.png

 

I don't understand how to do array completely. I don't know how to directly put data in a specific RAM area. Any help or example appreciated.

Share this post


Link to post
Share on other sites

I'm not up to date with what the kids are using for their devkits lately, so I don't know what library functions you have available to you.

 

You know your addresses, so it's pretty easy. To use psuedo-code, just create a buffer in CPU memory 8 bytes long. Read VRAM into the buffer, then write VRAM from it.

 

It is possible to do it without an intermediary buffer, but because you have to change the VDP address twice for every byte, it's (comparably) very slow. If 8 bytes RAM is critical to you, and speed isn't, then just do it one byte at a time.

 

Anyway, something like this:

 

unsigned char vram_buf[8];   /* defines an 8-byte buffer in VDP RAM */
get_vram(0x480, vram_buf, ;  /* assuming VRAM source is first parameter */
put_vram(0x408, vram_buf, ;  /* assuming VRAM dest is first parameter */

 

I made a lot of assumptions there, though. But I do have an actual example that I use in my code, though with all the extra defines it looks longer...

 

// used for patcpy
unsigned char tmpbuf[8];

// base address in VDP RAM of the pattern table
#define gPATTERN 0x1000

// copies a VDP character pattern 
void patcpy(int8 from, int8 to) {
cvu_vmemtomemcpy(tmpbuf, ((int)from<<3)+gPATTERN, ;
cvu_memtovmemcpy(((int)to<<3)+gPATTERN, tmpbuf, ;
}

 

I'm using the library from http://www.colecovision.eu/ColecoVision/development/libcv.shtml for that one (though I've been adapting everything to resemble TI Extended BASIC, so slowly been replacing the functions, for better or for worse ;) ). Still, the names should be straight forward enough to adapt to what you have.

 

I made the temporary buffer a global because I share it with several other functions, including my screen scroll. The #define sets the base address of the pattern table. I need this because, as you see, my patcpy function takes character numbers, rather than addresses. This does cost a little more CPU time - there's a shift and an addition in each function call, but it's straightforward to remember. And that's it.. the first line copies 8 VDP bytes into the tmpbuf, and the second line copies them back out to a new location.

 

hth

  • Like 1

Share this post


Link to post
Share on other sites

That works!!! Thanks!

 

I use both Coleco, and Getput. I have more direct control over the VRAM with Coleco since I am loading new tiles after the premade alphabit and doing some effect with it. I'm using the CV programming book made by Newcoleco 2005 as a guide.

 

I was SO close and it was working as it should when I had the right parameter and all that! It even made the train ride from Chicago a lot shorter as I struggled with this issue. Wow, don't you want to know what I did wrong the whole time? The source started at 488, not 480(which was an empty tile). Just now I said, why don't you try a different number and see if the next tile would show up. I just add 8 to 480, and the tile that I wanted showed up.

 

Again, thank you.

 

I really need to get some sleep LOL.

Share this post


Link to post
Share on other sites

I'm confused what I did wrong in this routine.

 

	
byte spelltext,e,f;

       [codes]

       f = 18;
       put_char(3,f,0x01);
e = 0;
while (e==0)
{
	if(joypad_1&(UP|DOWN))
		{
			print_at(3,f," ");
			if(joypad_1&DOWN)f--;
			if(joypad_1&UP)f++;
			put_char(3,f,0x01);
		}
	if(joypad_1&FIRE1)e++;
	delay(1);
}

if(f==18)
{
		ClearTextBox();
		print_at(3,16,"King:");
		print_at(3,18,"Thank you! you are so");
		print_at(3,19,"kind!");
}
if(f==19)
{
		ClearTextBox();
		print_at(3,16,"King:");
		print_at(3,18,"The dragon is... ");
		print_at(3,19,"um... I don't know.");
		print_at(3,20,"People in our town");
		print_at(3,21,"probably can help you.");


}
if(f==20)
{
		ClearTextBox();
		print_at(3,16,"King:");
		print_at(3,18,"How dare you reject my");
		print_at(3,19,"request!!! Thou art the");
		print_at(3,20,"hero!  Please help me");
		print_at(3,21,"get Plum back!PLEASE!!");
}
pause();

 

It seems that I coded it correctly and should work, but for some reason the while segment get skipped over to the next piece of code. It suppose to move the choice arrow up and down. When selected, e++ should increase the e to 1 and exit the loop. The variable f is suppose to be use for the if cases to branch to the text it require. The arrow limiter isn't added until I got that arrow to move. I looked in the cv programming book and couldn't understand why the code I have doesn't seem to work. Any help appreciated.

Share this post


Link to post
Share on other sites

Got it to work now. I imported the programming example from the cv programming book to my stratch programming program. The programming example I used is to move sprite around with the joypad(so I can see if this function working or not.) and changing sprite with keypad. In short, enabling nmi fixed the problem. So now I'm able to move that arrow. I'm still figuring out what NMI and when it should be enable, and when it should be disable. From I understand, it has to be disable when you have to update the VRAM, such as filling up color information, loading nametable, and other flashy stuff. Enabling it would keep the graphic from corrupting, and allow you to have a side routine like update sound, sprite etc. Kinda like how NES music would stop when it has to change screen.

Share this post


Link to post
Share on other sites

Just as a matter of style, it would be better to use the "break" statement rather than messing with the variable "e", and turn the while in to a while(1).

 

It would also probably be better to read the joypad once per loop (assuming "joypad_1" actually reads the I/O port) because it could change in the moment between different reads. Also, there seems too be no delay between up and down movements, so it would just zip to the beginning or end of your menu thingy.

Share this post


Link to post
Share on other sites

enable_nmi();
choice:
print_at(3,16,"Choose a choice below.");
print_at(3,18,"   Yes, I will help you.");
print_at(3,19,"   Where is the dragon? ");
print_at(3,20,"   No I cannot help you.");
f = 18;
e = 0;
put_char(3,f,0x01);
delay(2);
while (e==0)
       {
	if(joypad_1&(UP|DOWN))
                       {
			print_at(3,f," ");
			if(joypad_1&DOWN && f!=20)f++;
			if(joypad_1&UP && f!=18)f--;
			put_char(3,f,0x01);
		}
               if(joypad_1&FIRE1)e++; 
               delay(1);
       }

Works. There is a delay function in the loop, and delay(2) before it to prevent pushing the fire button accidentally before reading all the choices. Plus enable_nmi does slow the program when it is enable. I remove the delay function when there are only 2 choices. 3 or more will have delay() function in it. I will consider changing the while (e==0) to while(!(joypad_1&FIRE1)) to erase the e=0;, saving several bytes in my program. Also save my confusion for forgetting to set e to 0. I probably change the ifs into cases instead once I understand how it works, which I think it'll save bytes. Thanks for your advice Bruce.

Share this post


Link to post
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.

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