[MSX-C] Q&A official thread

ページ 9/68
2 | 3 | 4 | 5 | 6 | 7 | 8 | | 10 | 11 | 12 | 13 | 14

By DarkSchneider

Paragon (1030)

DarkSchneider さんの画像

04-09-2015, 08:44

Is that one this book, but in first edition?
http://www.iups.org/media/meeting_minutes/C.pdf
This one is updated to ANSI-C :(

By Sylvester

Hero (593)

Sylvester さんの画像

04-09-2015, 08:49

Yes, you need the first edition of it.

By anonymous

incognito ergo sum (116)

anonymous さんの画像

04-09-2015, 09:23

That's the second edition. Only the first edition (1978) covers K&R C (first edition on the left, Spanish version of the second edition on the right):

Anyway, you don't really need the book. It's difficult to find, and expensive.

If you already know modern C then you can work perfectly with that. You just need to be aware about a few small changes that happened to the language when it got standardized, and we're already talking about these things.

By Sylvester

Hero (593)

Sylvester さんの画像

04-09-2015, 09:55

Nice blog post about K&R C: https://spin0r.wordpress.com/2014/11/21/kr-c/

By AxelStone

Prophet (3199)

AxelStone さんの画像

04-09-2015, 11:25

Sylvester wrote:

Nice blog post about K&R C: https://spin0r.wordpress.com/2014/11/21/kr-c/

Thanks for the url. In any case as Javi says there are too few diferenced and they are being explained here, we hope to write all this in wiki. Is a good idea too take a look at .h files of msx-c in order to identify specific types.

By the way the blog is very complete explaining differences between ansii and k&r, nice ;)

By AxelStone

Prophet (3199)

AxelStone さんの画像

04-09-2015, 15:01

Time for next question Wink .

Question: How to make a HALT in MSX-C? When you work with graphic copys and image scrolls, you need to make a halt of the CPU in order to wait next cycle and draws exactly 60 times per second. Without it, the VDP draws as fast as it can and you obtain a really teering copy /scroll routines. For example:

vertscr() {
	TINY i;
	int h;
	for(i=0;i<212;i++){
		wrtvdp(VREG23,i);
	}
}

With this simple code in C, we can make vertical hardware scroll. However without HALT the scroll goes so fast! In TURBO BASIC we could do that simply with the following code:

10 SCREEN 5
20 FOR A=0 to 212
30 VDP(24)=A
40 '#I 118 // This line makes the interrupt
50 NEXT A
CALL RUN

Line 40 makes the interrupt, using the opcode of the ASM operation HALT. Since MSX-C integration with ASM needs to define the ASM functions (we can't make it inline as Javi has explained), how this could be done in C?

I've never wrote a line in Z80 ASM but, could this work?

public    halt@
halt@:   HALT
            ret
            end

Thanks.

By Grauw

Ascended (10819)

Grauw さんの画像

04-09-2015, 15:33

HALT waits for any interrupt, not just the 60Hz vertical blanking one that you’re interested in, so it’s not suitable for what you want to use it for. In stead, make a loop which reads the JIFFY value until it changes (don’t even need assembly for that).

By anonymous

incognito ergo sum (116)

anonymous さんの画像

04-09-2015, 15:34

AxelStone wrote:

Time for next question Wink .

Question: How to make a HALT in MSX-C? [...]

I've never wrote a line in Z80 ASM but, could this work?

public    halt@
halt@:   HALT
            ret
            end

It probably won't work as it is because the stack pointer will get corrupted.

When MSX-C calls your halt() routine it will put the return address as the first value in the stack. However, the HALT instruction never returns, and the RET after it will not get executed.

This may work if you let the program run exclusively from interrupt handling routines from this point, but I'm not comfortable with this solution.

To be on the safe side, you would have to remove the value in the stack before the HALT:

public	halt@

halt@:	pop	hl
	halt

	end

Note that there is no RET because it won't get executed anyway. When you do a HALT the CPU freezes at that point, and only wakes up to run the interrupt routines.

Anyway, give me some time to experiment with this. After I finish this next post of Relearning MSX I want to port to MSX-C the omnidirectional scroll routine that I wrote many years ago (http://lavandeira.net/misc/omni/). Don't bother trying to assemble that using M80/L80. The syntax is slightly different because back then I was using Egor Voznessenski's AS/LD package.

By Sylvester

Hero (593)

Sylvester さんの画像

04-09-2015, 16:00

I used the JIFFY for it in one of my projects like Grauw said:

#define JIFFY   (*(TINY *)0xfc9e)
main() {
  int timer = 0;

  timer = JIFFY;
  while (true)
  {
     /* Do stuff */

     /* Wait for interrupt */
      while (timer == JIFFY) {}
      timer = JIFFY;
  }
}

By AxelStone

Prophet (3199)

AxelStone さんの画像

04-09-2015, 15:58

Grauw wrote:

HALT waits for any interrupt, not just the 60Hz vertical blanking one that you’re interested in, so it’s not suitable for what you want to use it for. In stead, make a loop which reads the JIFFY value until it changes (don’t even need assembly for that).

It seems better solution that mine. I've read thay "JIFFY is same thing as TIME in BASIC". How can we do that in C? Cool . In Basic another trick I used was this:

870 '#I 118 // Halt
880 IF (VDP(-2)AND1)<>0 THEN 880 ELSE P=1-P // Wait for VDP to finish

This is easy to translate in C since we hace readVDP. Should this work?

JaviLM wrote:

Anyway, give me some time to experiment with this. After I finish this next post of Relearning MSX I want to port to MSX-C the omnidirectional scroll routine that I wrote many years ago (http://lavandeira.net/misc/omni/). Don't bother trying to assemble that using M80/L80. The syntax is slightly different because back then I was using Egor Voznessenski's AS/LD package.

It sounds great, let's wait for that ;) . As I said, I've no idea of MSX ASM.

P.D.: I didn't see your answer @Sylvester, thanks for it ;). I've tried an it works very fine.

ページ 9/68
2 | 3 | 4 | 5 | 6 | 7 | 8 | | 10 | 11 | 12 | 13 | 14