Is there also an easy to use TP version of this replayer?
Cool, there are TP programmers in the forum . I should suggest open a similar thread for TP called "[Turbo Pascal] Q&A official thread" in order to centralize all questions about TP. Personally is a language that I like very much, I was hesitating between TP and MSX-C. Finally decided for MSX-C beacuse nowadays I see an interesting comunity behind it, but it should be great to see that there is also a TP comunity working
Hi again, I've continued with MSX-C and I've a problem reading text files. I've a text file like:
image001.sc5 000,000,100,500 Lorem ipsun
I'd like to read every line of the text file and store it in a string. However, it seems as like strings has some kind of thrash since they are not clear. Here goes the function:
char image[11]; char coords[14]; file=fopen("myfile.txt","r"); fread(image,sizeof(char),12,file); getc(file); /* to skip \n */ fread(coords,sizeof(char),15,file); getc(file);
When I prints both variables I get something like:
image001.sc5
000,000,100,050N1 <- ¿¿¿????
The second string has bad stuff. What could be happening? Thanks.
Ok, it's my fault, I almost forgot: in C the character '\0' indicates "end of string, so you need to do:
char image[12]; ...fread... image[12]='\0';
It works now.
Another question: how do I convert a readed string into NAT type. For example, I read something like:
0x0442
I'd like to convert it to NAT type in order to use it to set a colour of palette. How can I make de conversion?
Thanks.
NAT type? What’s that?
Palette colours are set in pairs of bytes 0xRB, 0x0G (R=red, B=blue, G=green, see Accessing the Palette Registers section). Read as a little endian word, this gives you the value 0x0GRB. So 0x0442 means G = 4, R = 4, B = 2.
Nat means unsigned, in c you can set 1 colour by setting it with a nat value (in the first 4 pages of this thread there is an example). It is grbdat as you say, but id like to convert from a readed string to nat, if possible.
I almost have it, but I have the last obstacle: I don't know how to read a binary file with hex values. The .pl5 file has values as following:
FE 80...
Suposse I simply want to read first byte: how in the hell it's supossed I can read it in hexadecimal format? I've tried fread, fscanf, int values, int pointers...but there is no luck.
Thanks.
Cool, there are TP programmers in the forum . I should suggest open a similar thread for TP called "[Turbo Pascal] Q&A official thread" in order to centralize all questions about TP. Personally is a language that I like very much, I was hesitating between TP and MSX-C. Finally decided for MSX-C beacuse nowadays I see an interesting comunity behind it, but it should be great to see that there is also a TP comunity working
Thanks, I will do
AxelStone: Maybe only block I/O is supported? At least this is the case in MSX-DOS. This means you have to read into a byte array or malloced buffer first, and then you can access the data in the buffer with pointers and casts.
The only thing I can think of is:
#include <stdio.h> int buf[1]; main(argc, argv) int argc; char *argv[]; { FILE *fp; fp = fopen(argv[1], "r"); while(fread(buf, sizeof(int), 1, fp)) { printf("%5x", buf[0]); } fclose(fp); }
it displays the file in hex codes, but only in pairs E4E4 etc..