Fusion-c copy to vram

By raymond

Champion (441)

raymond's picture

16-06-2020, 19:17

I am trying to copy a small graphic file (139 bytes) from disk to vram. In basic it would look like this:

copy "file.gfx" to (25,25)

I cannot find any method how to perform this same action in (fusion) C... Is this possible? If so, how?

Login or register to post comments

By ducasp

Champion (315)

ducasp's picture

16-06-2020, 22:11

I think WriteBlock in vdp_graph1.h is what you want, but you will need first to open the file and move to memory and then from memory to vdp, it doesn't have a direct function.

P.s.: not sure how copy works, if the file has a header like this:

https://www.msx.org/forum/development/msx-development/bsave-...

Remember to skip it as you don't want to copy the reader to VRAM ;)

By ericb59

Paladin (961)

ericb59's picture

17-06-2020, 09:51

Hello,
There is no pre-defined function to do that in Fusion-c. You must build your own routine.

-1- Define a Ram Buffer where to load Data
-2- Open the File to load
-3- Read the data, and send them to the Buffer
-4- Send the data from the buffer to the VRAM
-5- Close the file

Here an example for MSX2

#include "fusion-c/header/msx_fusion.h"
#include "fusion-c/header/vdp_graph2.h"
#include "fusion-c/header/io.h"
#include < string.h >

#define             _ScreenMode         (*(char *)0xFCAF) 

static FCB file; 

typedef struct {
      unsigned char LDbuffer[2560];  // 2560 Bytes Buffer. Adapt it for your own use.
} BufferType;

BufferType MyBuffer;

void FT_SetName( FCB *p_fcb, const char *p_name )  
{
  char i, j;
  memset( p_fcb, 0, sizeof(FCB) );
  for( i = 0; i < 11; i++ ) {
    p_fcb->name[i] = ' ';
  }
  for( i = 0; (i < 8) && (p_name[i] != 0) && (p_name[i] != '.'); i++ ) {
    p_fcb->name[i] =  p_name[i];
  }
  if( p_name[i] == '.' ) {
    i++;
    for( j = 0; (j < 3) && (p_name[i + j] != 0) && (p_name[i + j] != '.'); j++ ) {
      p_fcb->ext[j] =  p_name[i + j] ;
    }
  }
}

// --- Load Picture Data--------------------
// *file_name : File to load
// start_X : X coordonate where to start print the pixel on screen
// start_Y : Y coordonate where to start print the pixel on screen
// nx : Width in pixel of the image to laod
// ny : Heigh in pixel of the image to load
// op : Logical Operator to use to print image to screen
// Buffer : Buffer to use to load data
char FT_LoadPic(char *file_name, unsigned int start_X, unsigned int start_Y, unsigned int nx, unsigned int ny, char op, BufferType *Xbuffer)        // Charge les données d'un fichiers
    {
      
        ////////////////
        char pixels_byte[]={2,4,2,1,2,1,1,1};                          // Number of pixels color, coded in 1 byte 
        unsigned int nblineMax,rd,BytesPerLine,MaxToRead;
        char Nbloop,Nbreste,i,lastline;
        size_t BufferSize;
     

        BytesPerLine=nx / pixels_byte[_ScreenMode-5];
        BufferSize=sizeof(Xbuffer->LDbuffer);
        nblineMax=BufferSize / BytesPerLine;

        FT_SetName( &file, file_name );
        if(FcbOpen( &file ) != FCB_SUCCESS) 
        {
              Screen(0);Print("File Error");Exit(0);
        }
        MaxToRead=ny*BytesPerLine;
        Nbloop=MaxToRead/(nblineMax*BytesPerLine);
        Nbreste=MaxToRead%(nblineMax*BytesPerLine);
		
		//FcbRead( &file, Xbuffer->LDbuffer, 7);    // If File to load have an Header. Read the Header first to bypass these data.
        
           for (i = 0; i < Nbloop; ++i)
           {
                 rd=FcbRead( &file, Xbuffer->LDbuffer, nblineMax*BytesPerLine);                          // Read Read Data From Disc to RAM Buffer)                           
                 LMMC(Xbuffer->LDbuffer, start_X,start_Y, nx, nblineMax, op); 
                 start_Y=start_Y+nblineMax;                                                             // Next Y position where to put data in VRAM
                 MaxToRead-=rd;
            }
            if (MaxToRead>0)
            {
              rd=FcbRead( &file, Xbuffer->LDbuffer, MaxToRead);
               lastline=MaxToRead/BytesPerLine;    // Last lines calculation
              if (lastline<1)
              {
                lastline=1;
              }
              LMMC(Xbuffer->LDbuffer, start_X,start_Y, nx, lastline, op);
            }
        
        FcbClose(&file);
return(1);
}
void main() {
   	
 	Screen(8);
 	FT_LoadPic("test.pic",100,100,38,55,0,&MyBuffer); // Load Test.pic an image data of 38x55 pixel to print at coordonates100,100
 	WaitKey();
 	Screen(0);
 	Exit(0);

}


By raymond

Champion (441)

raymond's picture

19-06-2020, 07:47

Thanx, for the advice. I wil give it a try Big smile