[MSX-C] Q&A official thread

Page 30/57
23 | 24 | 25 | 26 | 27 | 28 | 29 | | 31 | 32 | 33 | 34 | 35

By AxelStone

Prophet (3120)

AxelStone's picture

25-02-2016, 20:38

Yes, I need to tell the start address since It will be used to store an external routine.

By Grauw

Ascended (10604)

Grauw's picture

25-02-2016, 20:55

If the external routine is written as relocatable code, without jp or call to internal code (use jr in stead) and with indirect addressing via bc/de/hl/ix/iy only, it doesn’t matter what address it’s stored at.

Or you could store the routine in the PSG queue, which is quite a sizable amount of available memory in page 3 which is unused as long as you don’t use the Basic/BIOS PSG MML commands.

Also maybe the linker has support for object files which say “I must be at this address”, I don’t know (probably not, but maybe).

By AxelStone

Prophet (3120)

AxelStone's picture

25-02-2016, 21:40

It's a premade routine (not mine), it needs to be stored in certain position, by this cause I need to reserve exactly that section of memory. I'll continue investigating, if I discover something I'll post here. Thanks for your ideas.

By the way, somebody has the original MSX-C manual in pdf, even in japanesse?

By Sylvester

Hero (563)

Sylvester's picture

25-02-2016, 23:24

for the japanese MSX-C manual check https://archive.org/details/fav-sndpl

By AxelStone

Prophet (3120)

AxelStone's picture

26-02-2016, 08:36

Sylvester wrote:

for the japanese MSX-C manual check https://archive.org/details/fav-sndpl

Got it, I'm trying to make some kind of automatic translation, but I think that with scaned PDF is not possible. Anyone knows a tool to make that?

Thanks.

By DarkSchneider

Paladin (944)

DarkSchneider's picture

26-02-2016, 09:56

I think the trick is in compiler options. Define the code and allocation spaces. Like when creating ROMs. If someone could translate them it would be really useful.

By AxelStone

Prophet (3120)

AxelStone's picture

28-02-2016, 13:11

Hi again this time I need some help with BLOAD function. This code doesn't works, I've tried it for example with a .PL5 file:

NAT bload(filename,modifier)
char *filename;
char modifier; 
{
	NAT addr[3];
	NAT *data;
	int count;
	FILE *fp=fopen(filename,"rb");
	if(fp==NULL) {
		printf("File read error!");
		return;
	}
	getc(fp); /* Skipping 1st byte */
	fread(addr,sizeof(NAT),3,fp);
	count = (addr[1]-addr[0])+1;
	fread(data,sizeof(NAT),count,fp);
	if(modifier=='S') {
                /* Working against VRAM */
		ldirvm(addr[0],data,sizeof(NAT)*count); 
	} else {
		/* Working against RAM */
	}
	fclose(fp);
	return addr[2];  
}

Simply replacing *data for data[16], works fine, palette is correctly stored. However I can't define static size array, since a generic BLOAD can receive a variable size array, so it should be a pointer.

What's wrong? Thanks.

By Grauw

Ascended (10604)

Grauw's picture

28-02-2016, 14:10

I mentioned before, you are reading into unallocated space, and corrupting memory.

It works with data[16] because that allocates space (on the stack). If you want to use data with a dynamic size, first allocate space with malloc (on the heap) and assign it to the data pointer. Only then can you read to it. An uninitialised pointer can contain any value and is making fread overwrite some random area of the memory.

But for a bload function you will actually still want to have a fixed-size array (e.g. 1K), and read/copy-to-vram in blocks, until the end of file is reached. Otherwise, the free memory requirement for reading a screen 5 image will be very high (27K), and a screen 7 image (53K) probably won’t even fit in the TPA.

By AxelStone

Prophet (3120)

AxelStone's picture

28-02-2016, 17:08

You are right, let's use a buffer. The idea is to replace all specific functions made until now (image, palette,...) for a generic bload, it's clearly a better solution.

By AxelStone

Prophet (3120)

AxelStone's picture

29-02-2016, 23:39

Hi again people, I've a doubt calling external functions. I've trying to use an external player wich has .BIN for use with basic, so I've trying to adapt to MSX-C. Here goes the original code in Basic:

100 CLEAR 100,&H9FFF:BLOAD"SAMPLE.BIN":BLOAD"BPLAY1.BIN"
110 DEFINT V
120 SCREEN 5
130 DEFUSR=&HC000:V=USR(&HA000):IF V<>-1 THEN SCREEN0:PRINT"ERROR":END
131 SETPAGE,1:BLOAD"SAMPLE1.SR5",S
132 SETPAGE,2:BLOAD"SAMPLE2.SR5",S
140 DEFUSR=&HC003:V$=USR("")
150 GOTO 150

It simply makes 2 BLOADs and then invoke functions in memory. Well, here is where I can't continue: In Line 130 is making a call to address &HC000 passing as parameter &HA000. Is there a equivalent to USR in MSX-C? The most similar in MSX-C should be this one:

call	int call(addr, a, hl, bc, de)	lib0.mac	stdio.h

However it's not clear how to pass that parameter. By the way if I try to compile a program using it I get error "Undeclared function", but it's supossed to be included in stdio.h.

Some idea? Thanks.

Page 30/57
23 | 24 | 25 | 26 | 27 | 28 | 29 | | 31 | 32 | 33 | 34 | 35