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).
Yeah, let's paste the final version:
...
With this function on your main loop, you read keyboard .
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. :-)
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.
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 . 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
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
There is an example for sdcc at http://msx.atlantes.org/index_en.html maybe you can rewrite it to MSX-C?
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?
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 . 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.
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 . 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
P.D.: ignore BLOAD request, it's not a good solution since BASIC is slower than C
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.
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.
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 ^_^!
Solved, we must read it in rb mode:
fp=fopen("arthur4.pl5","rb");
Now it works, althought palette is not correct by the moment