[MSX-C] Q&A official thread

صفحة 4/68
1 | 2 | 3 | | 5 | 6 | 7 | 8 | 9

بواسطة AxelStone

Prophet (3199)

صورة AxelStone

28-08-2015, 14:16

Here goes the revised one, more clear and using #defines. It solves a bug too since SC5 images has a 7bytes header that we must skip:

#include<stdio.h>
#include<glib.h>

#define PAGE0 0x0000
#define PAGE1 0x8000
#define SCREEN5 (TINY)5
#define SCREEN0 (TINY)0
#define BUFSIZE 128
#define COUNT 1

loadimg() {
	FILE *fp;
	char buf[BUFSIZE];
	int i;
	int vrami=PAGE0;
	fp=fopen("arthur4.sc5","rb");
	if(fp==NULL) {
		printf("File read error!");
		return;
	}
	fread(buf,7,COUNT,fp);
	for(i=0; i<213; i++) {
		fread(buf,BUFSIZE,COUNT,fp);
		ldirvm(vrami,buf,BUFSIZE);
		vrami = vrami+BUFSIZE;
	}
	fclose(fp); 
}

main(){
	screen(SCREEN5);
	loadimg();
	getchar();
	screen(SCREEN0);
}

With this function, you can load an image in any VRAM page Wink . Feel free to play with buffer size to test performance. One important question: it still needs palette read.

Let's wait your translation JaviLM Wink

بواسطة ARTRAG

Enlighted (6935)

صورة ARTRAG

28-08-2015, 13:55

You must allocate buf before using it!

Edit
You did it correctly, I overlooked

بواسطة Sylvester

Hero (589)

صورة Sylvester

28-08-2015, 13:54

Nice! to make the function more reusable i would introduce some params (filename, page) but that's for the next version Smile
About the palette, according to https://github.com/sharksym/CPMEMU_HI-TECH_C/blob/master/BLG...
It's almost the same routine as for the image, it loads the file (see bl_grp_load_ge5_pat()) and then places it into the VRAM. Maybe it helps, else you have to wait for other solutions :)

بواسطة DarkSchneider

Paladin (1021)

صورة DarkSchneider

28-08-2015, 14:08

In SC5 pages are 32KB not 16KB. So pages are:
0 0x0
1 0x8000
2 0x10000
3 0x18000

بواسطة AxelStone

Prophet (3199)

صورة AxelStone

28-08-2015, 14:04

Sylvester wrote:

Nice! to make the function more reusable i would introduce some params (filename, page) but that's for the next version Smile
About the palette, according to https://github.com/sharksym/CPMEMU_HI-TECH_C/blob/master/BLG...
It's almost the same routine as for the image, it loads the file (see bl_grp_load_ge5_pat()) and then places it into the VRAM. Maybe it helps, else you have to wait for other solutions :)

Sure, the idea is to make the function reusable: filename, page, even screen. BUFSIZE should calculate dinamically depending on SCREEN mode (128bytes for SC5, 256bytes for SC7/SC8) and the header size I'm not sure if equals in all screens (7 bytes).

For palette, lets wait for JaviLM translation. MSX-C libraries has several palette functions, so I suposse this time it's a good idea to use them instead to make it yourself ;) .

When the final version of both functions were finished, we'll share the source code.

بواسطة ARTRAG

Enlighted (6935)

صورة ARTRAG

28-08-2015, 14:15

SCx image files are .bin renamed. They have 7 bytes of header in which you find vram addresses that can be used as start and stop addresses .

بواسطة AxelStone

Prophet (3199)

صورة AxelStone

28-08-2015, 14:16

DarkSchneider wrote:

In SC5 pages are 32KB not 16KB. So pages are:
0 0x0
1 0x8000
2 0x10000
3 0x18000

Correct, but a little annotation: we can't access adresses above 0xFFFF, so the only way to load images in pages 2-3 is play with setpg and setting them as active pages.

I've corrected the code, it's not needed to modify bufsize of *fp since the read pointers increases automatically depending the read bytes. This is, if you read 7 bytes, the pointer increases 7. If you read 128 bytes, the pointer increases 128 bytes.

بواسطة anonymous

incognito ergo sum (116)

صورة anonymous

28-08-2015, 15:34

AxelStone wrote:
DarkSchneider wrote:

In SC5 pages are 32KB not 16KB. So pages are:
0 0x0
1 0x8000
2 0x10000
3 0x18000

Correct, but a little annotation: we can't access adresses above 0xFFFF, so the only way to load images in pages 2-3 is play with setpg and setting them as active pages.

Actually, looking at the function declaration there's no indication that it shouldn't be able to access addresses above FFFFh. The declaration for ldirvm() is:

VOID ldirvm(dst, src, len)
NAT dst;
TINY *src;
NAT len;

If ldirvm() works internally with the 17th bit in the VRAM address then we should be able to set the destination VRAM address to FFFFh and the length also to FFFFh to access the VRAM addresses FFFFh to 1FFFEh.

However, this doesn't look like an elegant solution to me. Probably there's a note about this in the manual somewhere.

بواسطة anonymous

incognito ergo sum (116)

صورة anonymous

28-08-2015, 18:09

AxelStone wrote:

[...]
One important question: it still needs palette read.

Let's wait your translation JaviLM Wink

Ok, here's a quick translation of the MSX-C Library manual regarding the color handling functions. Looks pretty straighforward to me, and most likely the function you wanted is rstplt():

VOID color(fore, back, bord)
TINY fore, back, bord;

Changes the foreground, background and border colors of the screen. Doesn't return any value. If you use an invalid color (for example, color 250 under SCREEN 2) then the correct operation of this function is not guaranteed.

VOID iniplt()

Initializes the color palette (and the palette data stored in VRAM) to the default values.

VOID rstplt()

Restore the color palette stored in VRAM.

NAT getplt(pal)
TINY pal;

Returns the contents of the palette register especified by pal. See setplt() for the format of the value returned.

VOID setplt(pal, grbdat)
TINY pal;
NAT grbdat;

Set the palette register indicated by pal and saves it to the VRAM. grbdat is 2 bytes long, but only 12 bits are used, in groups of 4 bits. The meaning of these bits is as follows:

MSB |xxxx+0GGG|0RRR+0BBB| LSB

With GGG, RRR and BBB being the levels of green, red and blue, respectively.

بواسطة AxelStone

Prophet (3199)

صورة AxelStone

28-08-2015, 20:19

JaviLM wrote:

...

Nice, it's really straight forward to define a palette, now it works Big smile . Here goes the code:

#include<stdio.h>
#include<glib.h>

#define PAGE0 0x0000
#define PAGE1 0x8000
#define SCREEN5 (TINY)5
#define SCREEN0 (TINY)0
#define BUFSIZE 128
#define COUNT 1

NAT grbdat[16]={0x0442,0x0000,0x0400,0x0040,0x0200,0x0221,0x0231,0x0224,0x0346,0x0777,0x0436,0x0120,0x0555,0x0420,0x0250,0x0113};

loadimg() {
	FILE *fp;
	char buf[BUFSIZE];
	int i;
	int vrami=PAGE0;
	fp=fopen("arthur4.sc5","rb");
	if(fp==NULL) {
		printf("File read error!");
		return;
	}
	fread(buf,7,COUNT,fp);
	for(i=0; i<213; i++) {
		fread(buf,BUFSIZE,COUNT,fp);
		ldirvm(vrami,buf,BUFSIZE);
		vrami = vrami+BUFSIZE;
	}
	fclose(fp); 
}

loadplt() {
	TINY pal;
	iniplt();
	for(pal=0;pal<16;pal++) {
		setplt(pal,grbdat[pal]); 
	}
	rstplt();
}

main(){
	screen(SCREEN5);
	loadplt();
	loadimg();
	getchar();
	screen(SCREEN0);
}

Now we have functions to load image and a way to set its palette.
Thanks for the translation Big smile

صفحة 4/68
1 | 2 | 3 | | 5 | 6 | 7 | 8 | 9