MSX1 Partial Screen 1 Vertical Scroll

By chalky

Rookie (32)

chalky's picture

25-05-2011, 18:27

I have started learning a little assembler of the past few months so that I can enhance my BASIC programming. As an exercise, I am trying to recreate the sort of scroll employed in Konami's Road Fighter. The task is therefore to create a routine which scrolls the lefthand 22 characters of 24 lines of a 30 character width Screen 1.

Being a total ASM noob, I have managed to produce the following, which works:

 	.BASIC
	
	ROWLEN	EQU	22
	VRMADR	EQU	6144
	
	ORG	$D000			; Start Address

	JP	SCROLL			; &HD000
	
SCROLL:
	LD	HL,VRMADR+705		; Set VRAM address
	LD	[TARGET],HL
	LD	C,23			; Set Counter (screen rows)
LOOPS:
	PUSH	BC			; Preserve counter
	LD	HL,[TARGET]		; Calc Address
	LD	DE,BUFFER
	LD	BC,ROWLEN
	CALL	$0059
	LD	HL,[TARGET]		; Copy RAM block back to VRAM 1 row lower
	LD	DE,32
	ADD	HL,DE
	LD	DE,BUFFER
	EX	DE,HL
	LD	BC,ROWLEN
	CALL	$005C
	LD	HL,[TARGET]		; Move address up 1 row
	LD	DE,-32
	ADD	HL,DE
	LD	[TARGET],HL
	POP	BC			; Restore counter and check for end of loop
	DEC	C
	JR	NZ,LOOPS
	RET
	
BUFFER:
	DS	32			; Reserve [V]RAM Space
TARGET:
	DS	4			; Current MOVEBL Address

I call it from BASIC like this:

100 CLEAR200,&HD000
110 SCREEN1:WIDTH30:KEYOFF
115 CLS:LOCATE22,0:PRINT"HISCORE"
120 BLOAD"SCROLL.BIN":DEFUSR=&HD000
130 K=31
140 A=USR(0):LOCATE0,0:PRINTSTRING$(22,K):K=K+1:IFK=255THENK=31
150 GOTO140

Is there is a better/faster way of doing this?

Login or register to post comments

By hap

Paragon (1916)

hap's picture

25-05-2011, 19:21

Of course it can be faster, but the code is only good if you understand it yourself. Optimizations by an asm expert will only make you feel lost. So unless this is for a game you're making that needs this part to be optimized, just leave it be.

Keep on learning. Smile

By norakomi

Paladin (961)

norakomi's picture

25-05-2011, 20:07

cool idea you got there
what about using 8 vram pages,
in each consecutive page you use the same tiles, but scrolled down 1 pixel compared to the previous page.
and then simulate the scroll by swapping pages (and replace tiles that need to be replaced).

you would still have to read out the mapdata in ram and copy all the tiles each frame,
but hey that will really speed up your routine...

unless it's only a sc4 thing... I don't know sc2 specs that well.

oh yeah one more thing. the:

CALL $0059
CALL $005C

rewrite it into your own routine, it can always be optimised
e.g. setting vdp address and set write and using oti instead of otir.

By Creepy

Champion (274)

Creepy's picture

25-05-2011, 23:07

If you have the complete level data in memory (as is the case with Road Fighter), you wont need to read from VRAM anymore. You just write all the data to VRAM and once your screen is full, just repeat it but starting from one row lower in memory.

My MSX profile