[MSX-C] Q&A official thread

Страница 3/55
1 | 2 | | 4 | 5 | 6 | 7 | 8

By anonymous

incognito ergo sum (109)

Аватар пользователя anonymous

28-08-2015, 03:12

Grauw wrote:

I don’t know if the K&R C supports the const keyword…? If so you could maybe define it as a const pointer variable (const TINY * NEWKEY = 0xFBE5).

MSX-C does support two -const types when running in default mode: intconst and charconst. They work as expected: the first one defines a 16-bit constant value, the second one an 8-bit value.

These types aren't available when MSX-C is running in PDP-11 mode (but you shouldn't be running it in this mode anyway).

By anonymous

incognito ergo sum (109)

Аватар пользователя anonymous

28-08-2015, 03:15

AxelStone wrote:

Yeah, let's paste the final version:

...

With this function on your main loop, you read keyboard Wink .

I'm happy to see how you guys are starting to do useful stuff in MSX-C. This is going to be helpful for everybody else who reads this thread in the future. :-)

By AxelStone

Prophet (2674)

Аватар пользователя AxelStone

28-08-2015, 09:37

JaviLM wrote:

MSX-C does support two -const types when running in default mode: intconst and charconst. They work as expected: the first one defines a 16-bit constant value, the second one an 8-bit value

Another discovery, thans for the info.

JaviLM wrote:

I'm happy to see how you guys are starting to do useful stuff in MSX-C. This is going to be helpful for everybody else who reads this thread in the future. :-)

This is the idea, try to collect as many info as possible Smile . When a lot of info is gathered, we could talk to admins in order to write it to Wiki. By the moment, let's go for next question Smile

Question: Is there any way in MSX-C to load images? I've read all functions included in glib.h that includes functions as cpym2v, cpyv2m, cpyv2v but I miss cpyd2v (disk to VRAM). On the other hand, I can see functions to handle palettes as setplt(pal, grbdat), but I don't understand them since I'm used to read a palette from .pl5 file in Basic. I suposse that in C the palette is defined in other way (perhaps an array with RGB values?)

Basically, what's the equivalent in C to this code in BASIC?

10 BLOAD "palette.pl5",S
20 COLOR=RESTORE
30 BLOAD "image.sc5",S

In 3 steps: Load palette, set that palette as active and load image in active screen.

Thanks Wink

By Sylvester

Champion (398)

Аватар пользователя Sylvester

28-08-2015, 10:20

There is an example for sdcc at http://msx.atlantes.org/index_en.html maybe you can rewrite it to MSX-C?

By AxelStone

Prophet (2674)

Аватар пользователя AxelStone

28-08-2015, 11:45

Sylvester wrote:

There is an example for sdcc at http://msx.atlantes.org/index_en.html maybe you can rewrite it to MSX-C?

Thanks for the url, let's see.

EDIT: ok, I've read it but It's not a good solution for MSX-C :( . That function is clearly oriented to cross compilers, since it uses standar IO functions. It reads the file in a 128bytes buffer and calculates position in VRAM to write buffer. This is highly inefficient.

In MSX-C I think that the right way is to use BLTVD Bios function using calbio from MSX-C. If someone can explain us how to load an image with BLTVD, I could translate it to MSX-C.

Another good aproach: calbas function of MSX-C, to invoke the Basic commands I've posted. Someone knows how to use calbas?

By Grauw

Ascended (8386)

Аватар пользователя Grauw

28-08-2015, 11:49

Any implementation will read data into a buffer first before writing it to the VRAM, so it’s a good approach. Although I would use a bigger buffer than 128 bytes Smile. So, I would use the C standard library functions to load part of the image into a buffer, then use ldirmv to copy the buffer to VRAM, and repeat until it’s fully loaded.

By AxelStone

Prophet (2674)

Аватар пользователя AxelStone

28-08-2015, 12:09

Grauw wrote:

Any implementation will read data into a buffer first before writing it to the VRAM, so it’s a good approach. Although I would use a bigger buffer than 128 bytes Smile. So, I would use the C standard library functions to load part of the image into a buffer, then use ldirmv to copy the buffer to VRAM, and repeat until it’s fully loaded.

You are right, I've read how BLOAD works and it uses a buffer too, it seems it's not possible to transfer directly from disk to VRAM (right, VDP can't access disk!). Your solution looks nice, with a buffer around 1Kb it could get a good performance. Let's try it.

Thanks Wink

P.D.: ignore BLOAD request, it's not a good solution since BASIC is slower than C Tongue

By anonymous

incognito ergo sum (109)

Аватар пользователя anonymous

28-08-2015, 12:10

AxelStone wrote:

Question: Is there any way in MSX-C to load images?

Not directly, but the method Laurens suggested should work just fine:

- Prepare buffer of size x
- Open file
- Read from file until you get x bytes or EOF
- Transfer contents of buffer to VRAM
- Repeat read until EOF

It's an interesting exercise. I'll see if I can work on it this weekend.

AxelStone wrote:

I've read all functions included in glib.h that includes functions as cpym2v, cpyv2m, cpyv2v but I miss cpyd2v (disk to VRAM). On the other hand, I can see functions to handle palettes as setplt(pal, grbdat), but I don't understand them since I'm used to read a palette from .pl5 file in Basic. I suposse that in C the palette is defined in other way (perhaps an array with RGB values?)

Yes, these functions in the MSX-C Library disk work with RGB values encoded as a 16-bit value. I'll translate that part later tonight or tomorrow.

By AxelStone

Prophet (2674)

Аватар пользователя AxelStone

28-08-2015, 13:12

Right, here goes my first try:

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

#define PAGE0 0x0000
#define PAGE1 0x4000
#define PAGE2 0x8000
#define PAGE3 0xC000
#define SCREEN5 (TINY)5
#define SCREEN0 (TINY)0

loadimg() {
	FILE *fp;
	char *buf;
	int size=128;
	int count=1;
	int i;
	int vrami=PAGE0;
	fp->bufsiz=128;
	fp=fopen("arthur4.pl5","r");
	for(i=0; i<213; i++) {
		fread(buf,size,count,fp);
		ldirvm(vrami,buf,size);
		vrami = vrami+128;
		printf("%c , %d\n",fp->ptr, fp->count);
	}
	fclose(fp); 
}

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

And I obtain this:

Something is wrong ^_^!

By AxelStone

Prophet (2674)

Аватар пользователя AxelStone

28-08-2015, 13:16

Solved, we must read it in rb mode:

fp=fopen("arthur4.pl5","rb");

Now it works, althought palette is not correct by the moment Wink

Страница 3/55
1 | 2 | | 4 | 5 | 6 | 7 | 8