Assembly experiment: bouncing block

Page 1/7
| 2 | 3 | 4 | 5 | 6

By Pbk71

Expert (101)

Pbk71's picture

02-05-2021, 15:44

Hi all,

I've been working on little program written in assembly that displays a bouncing block on a MSX1 computer.
And here it is: https://msxpen.com/codes/-MZhICPdfzZSbUFti9cO

What I notice is that it runs very smooth on an American NTSC machine (60 Hz) but not on an European PAL machine (50 Hz). Seems that 10 Hz is a big difference for smoothness? Never realized that.

Login or register to post comments

By MsxKun

Paragon (1031)

MsxKun's picture

02-05-2021, 16:13

Pbk71 wrote:

What I notice is that it runs very smooth on an American NTSC machine (60 Hz) but not on an European PAL machine (50 Hz). Seems that 10 Hz is a big difference for smoothness? Never realized that.

It is!
That's why games at 25/30 are most of cases unnaceptable Tongue

By bore

Master (133)

bore's picture

02-05-2021, 16:25

50Hz should look smooth.

If it seems stuttery it is likely because you are using a display that is fixed to 60Hz with a 50Hz video signal.
Make sure you are connecting your MSX to a screen that is capable of both 50Hz and 60Hz to get a valid comparison.

By aoineko

Master (165)

aoineko's picture

02-05-2021, 16:39

In your case, it is more a speed difference than smoothness.
If you want to compare "smoothness" you should implement frequency detection and move 20% more when the VDP is at 50 Hz.
But with normal human eyes, it's hard to see any difference between 50 and 60 Hz.

By Grauw

Ascended (10068)

Grauw's picture

02-05-2021, 16:38

It is what Bore said. The issue is that you're looking at it on an emulator with a 60 Hz display.

By Daemos

Paragon (1952)

Daemos's picture

02-05-2021, 17:02

Quote:

That's why games at 25/30 are most of cases unnaceptable

25 bad. 30 just goes fine. You can take my word on that.

By Pbk71

Expert (101)

Pbk71's picture

02-05-2021, 21:30

Ok, thanks for the advice. I've only used WebMSX for this experiment and when I look at Quick Options there I see that the option for NTSC/PAL is set to AUTO. I will try some other emulators too te see the difference.
In the meanwhile I've added a multicolored sprite to it. It's a bouncing coin now although it bounces like a ball Tongue
https://msxpen.com/codes/-MZiXWv_XZVC5QrpSdYN

By ARTRAG

Enlighted (6550)

ARTRAG's picture

02-05-2021, 21:54

Your code looks a bit clumsy but works, nice effect.
A few general suggestions to improve your code:
- Try to remove the use of AND A / SBC HL,DE and use only ADD, resorting to the fact that speed can be negative.
- Use the sign of speed (its highest bit) as flag for the direction and remove dir
- Use RST DCOMPR to call DCOMPR
- Use the fact that the VDP vram pointer auto-increments each time you send a byte
e.g. this could replace your i/o write code

ld hl,SPRITEAT 
call SETWRT
ld c,98h
ld a,(y+1)		; y-coördinate = high byte of word y
out (c),a
ld a,(x)	    ; x-coördinate
out (c),a
ld a,(pattern)
out (c),a
ld a,(color)
out (c),a

By Pbk71

Expert (101)

Pbk71's picture

03-05-2021, 10:20

Quote:

Your code looks a bit clumsy but works, nice effect.
A few general suggestions to improve your code:

@ARTRAG: Thanks for your comment and suggestions. I really appreciate these suggestions and I will try to implement them in my experiment.

I'm quite new to Z80 assembly and programming a MSX with assembly so I will probably do many things in a not so convenient way. I'm using Google a lot to find all kind of code examples and use them in my own code. As I am used to programming in higher level languages it's a challenge for me to 'translate' high level programming routines to assembly. But I'm getting there and I was already very proud to get this running. Time for some optimization now Wink

By Pbk71

Expert (101)

Pbk71's picture

03-05-2021, 21:25

For my optimization I want to change the sign of my variable speed (dw).
So for two's complement I've got to xor it with 0xFFFF and then add 1.

To do this for a word in memory I've now written this code:

        ld de,(test)
        ld a, d
        xor 0xFF
        ld d,a
        ld a, e
        xor 0xFF
        ld e,a
        inc de 
        ld (test),de
test:   dW 0x1000

I've tested it and it seems to work. Is this the most fast way to do this?

By Daemos

Paragon (1952)

Daemos's picture

03-05-2021, 21:42

        ld a,(test+1)
   ;     ld a, d
    ;    xor 0xFF
       cpl
        ld d,a
        ld a, (test)
     ;   xor 0xFF
      cpl
        ld e,a
        inc de 
        ld (test),de
test:   dW 0x100

should shave of 4 Tstates if I calculated it right

Page 1/7
| 2 | 3 | 4 | 5 | 6