[MSX-C] Q&A official thread

Page 19/57
12 | 13 | 14 | 15 | 16 | 17 | 18 | | 20 | 21 | 22 | 23 | 24

By DarkSchneider

Paladin (942)

DarkSchneider's picture

14-09-2015, 08:41

Indeed is that:

Quote:

VOID setpg(dsppag, actpag)
Makes page 'dsppag' the VRAM page which is being displayed and page 'actpag' the VRAM page on which actions will be taken.

Works like in BASIC.

By AxelStone

Prophet (3094)

AxelStone's picture

14-09-2015, 08:56

I suspect perhaps that dspag will start at 0 and actpag will start at 8000. I've no choice to test it now, I'll try this evening and will comment results.

By Grauw

Ascended (10565)

Grauw's picture

14-09-2015, 09:06

Think it expects values 0 1 2 3 rather than 0 8000H etc.

By AxelStone

Prophet (3094)

AxelStone's picture

14-09-2015, 10:07

Grauw wrote:

Think it expects values 0 1 2 3 rather than 0 8000H etc.

Yeah, I mean that if you set disp page=0 and act page=1, their NAT address will be 0x0000 and 0x8000. However if you set for example act page=2, in 0x8000 will not be PAGE1 but PAGE2, and all operations as load image (see source attached) in address 0x8000 will occur in PAGE2.

I'll try as soon as I can and I'll comment results.

By anonymous

incognito ergo sum (116)

anonymous's picture

14-09-2015, 16:16

AxelStone wrote:

Question: Until now we have worked with lower 64Kb of VRAM (PAGE0 and PAGE1) but, what happens if we want to work with higher 64Kb of VRAM? I'm trying some operations and seems not to work. Let's recover the loading of image and add some copy:
[...]
That works, this is, load image in PAGE1, transfer to PAGE2 and copy from 2 to 0. But can I load directly in PAGE2? It seems that not, if I make the following change:

	int vrami=PAGE2;

Then image loads on PAGE0 (display screen), this is, starts as 0 address. Really it's reasonable since max value of integer is 65.535 (16bit) so its supossed that trying to acces next value will loop to 0. Is this correct?

Thanks.

I think you're right. I don't see any indication in the source code that these functions support 17-bit addresses to span the whole 128KB of VRAM. We could make a function to handle this and support the whole VRAM address space, but I think that the solution you're using is a good compromise: load to page 1 and then transfer to page 2 using cpyv2v().

By AxelStone

Prophet (3094)

AxelStone's picture

14-09-2015, 17:01

@Grauw you are right, the function setpg modify offset of ldirvm(), the active page determines the offset. Example:

setpg(...,(TINY)2));

With this sentence, PAGE2 of VRAM will start at address 0x0000 and PAGE3 at address 0x8000. By this way, you can put the pointer where needed and access to all pages using ldirvm(). As @DarkSchneider mentions, setpg() works exactly equals to Basic equivalent:

10 SET PAGE 0,2 <- Sets pointer to PAGE2 (this is, PAGE2=0x0000)
20 BLOAD"screen.sc5",S <- Loads the image to PAGE2

@JaviLM I think so, it's not a bad solution load to PAGE1 and make a cpyv2v to other pages, it takes too short time.

By Sylvester

Hero (552)

Sylvester's picture

14-09-2015, 21:20

Hi, can somebody explain why this wrap function doesn't work? It only prints garbage data. I think it's because I copy the data from str -> word -> out, because when i copy from str -> out it works. Maybe I need to reserve some memory with malloc?

#include < stdio.h >

VOID wrap(out, str, columns)
char *out;
char *str;
int columns;
{
    int len, n, w;
    int wordlen=0;
    int linepos=0;
    int outlen=0;
    char *word;
    len = strlen(str);

    for(n=0; n<=len; n++) {
        if(str[n] == ' ' || str[n] == '\n' || n == len ) {
            if(linepos > columns) {
                out[outlen++] = '\n';
                linepos = wordlen;
            }

            for(w=0; w < wordlen; w++) {
                out[outlen++] = word[w];
                word[w] = '\0';
            }

            if(n == len) {
                out[outlen] = '\0';
            } else if(str[n] == '\n') {
                out[outlen] = str[n];
                linepos=0;
            } else {
                out[outlen] = ' ';
                linepos++;
            }

            outlen++;
            wordlen=0;
        } else {
            word[wordlen++] = str[n];
            linepos++;
        }
    }
}

main()
{
  char *testStr;
  char *outStr;

  testStr = "Lorem ipsum color sit amet, consectetur adipiscing elit. Suspendisse blandit fermentum";
  wrap(outStr, testStr, 10);
  printf("Final wrapped string:\n\n%s\n", outStr);
}

By Manuel

Ascended (18747)

Manuel's picture

14-09-2015, 22:14

You didn't say what the size of the char-arrays should be... so you just declared a pointer and are writing 'randomly' in RAM Tongue
You don't need malloc.

Just try stuff like char word[200];

By Sylvester

Hero (552)

Sylvester's picture

14-09-2015, 22:35

dammit, your right, but I did use malloc to allocate enough memory:

char *word;
len = strlen(str);
word = malloc(len * sizeof(char));

And then it works, thanks for the tip!

By Manuel

Ascended (18747)

Manuel's picture

14-09-2015, 22:45

Be careful with malloc. You are then reserving memory on the heap instead of on the stack. For local variables, just use the stack method. If you really need the heap, then you also need to free the memory explicitly, or you will have lost it forever (well, during the run time of your program)...

Page 19/57
12 | 13 | 14 | 15 | 16 | 17 | 18 | | 20 | 21 | 22 | 23 | 24