Problem on scroll routine

Page 1/2
| 2

Par smx

Expert (72)

Portrait de smx

14-04-2018, 09:13

Hi,
I'm working on scroll routine.
I've all my tiles preshifted in vram and update only position tiles.
Basically there's a loop (inc HL from 0 to 1023) that call my scroll routine. Every value of HL is 1 pixel scroll.
When I call my routine from basic, with basic loop, scroll is good.
When I call my routine with asm loop my scroll is wrong.

I've think about vdp latency without success.

ld DE,$0400
LD HL,$0000
LoopHL:
push DE
PUSH HL
Call Scroll
POP HL
POP DE
INC HL
dec de
ld a,d
or e
jp nz,LoopHL

...
...
Scroll:
...
Code of scroll routine
...
ld BC,$40 ;= 64 Bytes = 2 rows
ld HL,$8800
ld DE,$19A0 ;= 6144 + 13 * 32
Call $005C
ret

!login ou Inscrivez-vous pour poster

Par smx

Expert (72)

Portrait de smx

14-04-2018, 09:17

This is my scroll code:

Scroll:
ld a,l
ld d,a

SRL H ;SHIFT 16 bit RIGHT 3
RR L
SRL H
RR L
SRL H
RR L

;****************************************************************************

ld a,d
and $07 ;
ld d,a
add a,a ; 14
add a,a ; 28
add a,a ;56
add a,a ;112 ;multiply by 16
sub d ;

;*********************************************************
;l=value, a=displacement

ld c,a ;displacement
ld B,$20
ld DE,$8800
LoopScroll:
push BC
push HL

ld a,l
And $7F ;01111111 ; module 128 of a

ld HL,POSSKY
add a,l ;add HL,a
ld l,a
adc a,h
sub l
ld h,a

;Copio in Buffer
ld a,(HL)

cp $00
jr z,Salta

add a,c ;sum displacement

Salta: LD (DE),a

pop HL
pop BC
INC HL
INC DE
DJNZ LoopScroll

Par Sandy Brand

Champion (295)

Portrait de Sandy Brand

14-04-2018, 12:26

Without having the full context of what you are trying to do and what is actually going 'wrong' (Is the code not running, are there visual artifacts on screen? Etc.), it is a bit hard to understand where the problem might be. Also, what do you mean by 'calling from Basic' and 'calling from Assembly'?

Just some initial ideas:
- If you run your code from MSX-DOS then you need do some some additional magic to call into the BIOS (for example: LDIRVM ($005C) cannot be called directly from MSX-DOS).
- If you call your routines from Basic, make sure they are located in memory that is 'safe' (as in: not accidentally modified by BASIC). A common trick is to store code in the PSG PLAY command buffers, see: VOICAQ ($F975), VOICBQ ($F9F5) and VOICCQ ($FA75).
- It looks like some of the parameters that you feed in into the LDIRVM Bios call ($005C) are wrong? (if you specify DE = $19A0 then this is basically copying random BIOS data into VRAM, if you were to be running this code from BASIC).
- Your code has some inconsistencies in how you pass in data through the registers? You pass in DE = $0400, but the second command in the Scroll function just overwrites register D?: LD D,A

Oh and a small tip: AND A is slightly faster than CP 0. Smile

Par smx

Expert (72)

Portrait de smx

14-04-2018, 14:43

The problem is not the controlled loop, I've tested different asm loops
My scroll routine is controlled by a loop like this:

ld b,$7F
ld l,$00
LooppA:
push BC
ld a,$00
ld b,$08
LooppB:
push BC
push AF
push HL
Call Scroll ; a and l are my values
pop HL
pop AF
pop BC
ADD a,$0F
DJNZ LooppB
pop BC
inc l
DJNZ LooppA
ret

My tiles are preshifted, so we have a set for 0, a set for 1 etc until a set for 8 (to indicate which set for every step show on the screen).
All is in VRAM, so for 1 pixel scroll it's needed to change only tile position.

Tile position are stored from $8800 to $8840 = $40 bytes (2 rows on the screen)

My scroll routine accept HL as input, HL is a 16 bit value from 0 to 1023.
To test it I've write a simple basic loop FOR NEXT that write a value (from 0 to 1023) in 2 ram locations.
The scroll routine is then modified to read the 2 ram location values in HL and in this manner go well.

In debug I see HL that increase from 0 to 1023.
When insert an asm loop (also a simple 8 bit loop from 0 to $FF), i see always my HL to increase from 0 to the end but scroll routine go wrong and jump 8 pixel instead 1 pixel.
So I've think about vdp latency, then i've inserted some loops to speed down the code without success.

Thanks

Par Sandy Brand

Champion (295)

Portrait de Sandy Brand

14-04-2018, 15:01

In the comment at CALL SCROLL it says ; and l are my values.
But a the start of Scroll it says:

Scroll:
ld a,l
ld d,a

So register A is immediately overwritten?

Also, it seems that you are assuming that AND $07 is somehow equal to modulo 7? It is not, it is equal to modulo 8.

ld a,d
and $07	;
ld d,a
add a,a ; 14
add a,a ; 28
add a,a ;56
add a,a ;112	;multiply by 16
sub d	;


Edit: I see now, it is multiplying by 15 (your comments confused me).

Par smx

Expert (72)

Portrait de smx

14-04-2018, 14:57

I've attach my code in dsk format ScrollTest.dsk.

Simply autoexec.bas start with basic routine and go well
WRONG.BAS is a basic routine that start routine with asm loop and go wrong.

Par Grauw

Ascended (10706)

Portrait de Grauw

14-04-2018, 15:00

About VDP delays, you do not need to take them into account when using the BIOS routines.

When performing direct VDP access:

  • There is no delay requirement on register write.
  • There is a delay requirement on each VRAM write via port 98H (which LDIRVM does), depending on the screen mode and whether sprites are enabled the number of access slots is reduced, and writes need to be up to 29 cycles apart.
  • There is a delay requirement on executing VDP commands with the V9938 hardware blitter, you need to poll the CE status bit to wait for command completion before issuing the next.

Par smx

Expert (72)

Portrait de smx

14-04-2018, 20:18

I'm sorry. I've tested with Meisei and slowdown emulation at the minimum speed.
So I can verify it's all ok, fine scroll also in assembler. My scroll is too fast, and this is a good news.

Thanks

Par Manuel

Ascended (19298)

Portrait de Manuel

14-04-2018, 21:57

Cool, why meisei?

Par smx

Expert (72)

Portrait de smx

15-04-2018, 09:34

I don't know.
I set Bluemsx with the slow emulation to see my scroll routine, but it's too fast.
Then I test with Meise with the minimum speed and by pressing F10 I can verify it's all ok

Par Manuel

Ascended (19298)

Portrait de Manuel

15-04-2018, 10:56

What speed do you need then?

Also, what functionality is behind F10?

Page 1/2
| 2