[MSX-C] Q&A official thread

Page 64/68
57 | 58 | 59 | 60 | 61 | 62 | 63 | | 65 | 66 | 67 | 68

Par DamnedAngel

Champion (266)

Portrait de DamnedAngel

02-02-2023, 23:43

rolandve wrote:

So how to use Jiffy. The system starts to behave erratic, like hang.

 unsigned oldJiffy;
oldJiffy = Jiffy;
if ( Jiffy > (oldJiffy +10 ) ) {
update();
oldJiffy = Jiffy;
}

What's around that code? Where's the game loop?
And remember that Jiffy will eventually overflow from 0xffff to 0x0000. That may break the Jiffy > (oldJiffy +10) comparison.

Par rolandve

Champion (358)

Portrait de rolandve

03-02-2023, 10:13

This happens in the game loop, which is about 300 lines. I intercept keystrokes (look at newkey) in it and jump to routines that handle these keystrokes. I know that Jiffy will reset, but when that happens "update" will not happen for a long time. Right below this code I placed a puts("skipped"); line. It prints 1 line and hangs. When I take this code out, this system keeps running.

Par DamnedAngel

Champion (266)

Portrait de DamnedAngel

03-02-2023, 12:04

1. How are Jiffy and oldJiffy declared?

2. Have you tried to step-by-step debug with OpenMSX Debugger?

3. Can you put

printf("Before If: Jiffy: %d; OldJiffy: %d", Jiffy, oldJiffy);

before the if and

printf("Before Update: Jiffy: %d; OldJiffy: %d", Jiffy, oldJiffy);

before update()?

Par rolandve

Champion (358)

Portrait de rolandve

06-02-2023, 23:00

Thanks for your reply. I worked around my issue.
I've got a new question mark.

VOID (*f_ptr) ( int*, int*);
f_ptr = move;

Does this compiler support this? If so how? The compiler doesn't know what to do with this expression and complains: ) missing, ; missing, syntax error....

Par aoineko

Paladin (1004)

Portrait de aoineko

06-02-2023, 23:42

You can try using a typedef;

void move(int* a, int* b) {}

typedef void (*f_type)(int*, int*);
f_type f_ptr = move;

Do you know the C standard version/name MSX-C is based on?

Par rolandve

Champion (358)

Portrait de rolandve

07-02-2023, 09:11

Yeah, it K&R C. That was years before ANSI. But Ascii didn't really mind K&R so they made their own version. Created some strange types: TINY (char), NAT (int), VOID (char) as an example of where they didn't really get it. They defined VOID as char so people could also use VOID in their compiler, because that was becoming popular.

There are many quirks in the compiler.

Par aoineko

Paladin (1004)

Portrait de aoineko

07-02-2023, 09:22

Isn't there a documentation that describes this C's syntax?

And why do you want to use this compiler instead of a modern one like SDCC or z88dk?
Do you program directly on MSX?

Par Sylvester

Hero (589)

Portrait de Sylvester

07-02-2023, 11:56

The C's syntax that MSX-C is using is described in The C Programming Language first edition as far as I know.

Par rolandve

Champion (358)

Portrait de rolandve

07-02-2023, 12:19

aoineko wrote:

Isn't there a documentation that describes this C's syntax?

And why do you want to use this compiler instead of a modern one like SDCC or z88dk?
Do you program directly on MSX?

I started my project in Ascii C. I write is Visual Studio Code, save on a (DirAs) floppy, compile on openMSX. I've got about 900 lines of Ascii C code to migrate to SDCC. I've got no idea, how much problems I wil have when I migrate to SDCC. I expect a lot of code rewrite.

In MSX c, you've got one MSX library that has all MSX specific functions (mlib). More modern frameworks like MSXgl offer more functionality to go, but also consist of more seperate header files and different function names.

One advantage of Ascii C is that all MSX functions are in mlib (the msx library) so I don't have to include different header files. I just declare the functions I need. But the limitations of the compiler are gradually pushing me towards SDCC.

Par rolandve

Champion (358)

Portrait de rolandve

07-02-2023, 13:58

Sylvester wrote:

The C's syntax that MSX-C is using is described in The C Programming Language first edition as far as I know.

Yes!

(*f_ptr) ();

(*f_ptr) ( x,y);

does the job.

Page 64/68
57 | 58 | 59 | 60 | 61 | 62 | 63 | | 65 | 66 | 67 | 68