Writing my first (simple) game in assembly

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

Par Pbk71

Expert (101)

Portrait de Pbk71

27-05-2021, 21:38

Thanks Daemos and JohnHassink. It makes a difference that programming has always been a hobby of mine, then you already know the techniques. Translating them to assembly is the biggest challenge.

Par Pbk71

Expert (101)

Portrait de Pbk71

28-05-2021, 20:06

Hi,

I'm busy with expanding my "game engine". I use the name table for my obstacles which I update in a buffer in RAM and then it's written to VRAM in my timer routine.
There are 10 lines that I use and every line is 53 bytes long:

  • 1 "extra" byte for characters that move off screen on the left side.
  • 32 bytes of characters that are visible on screen
  • 22 bytes to put my obstacles that move from left to right on screen

Now I only need to write the 32 visible bytes to VRAM and I use the following code for this:

; --- WRITE OBSTACLE CHARACTERS TO VRAM ---
                ld HL,NMTBL+10*32   ; VRAM address to write characters
		call SETWRT		; enable VDP to write	

		ld de,21			; skip 21 bytes for every next buffer
		ld hl,bufferline1 	; start of buffer for patterns
               	ld c,0x98			; port to write to
                
                ld b,10			; write 10 buffers
writeallbuffers:
		push bc 			; store counter
                ld b,32			; write 32 bytes
ptrns_to_vram:
		 outi				; write byte to VRAM
                jp nz,ptrns_to_vram   
                
                pop bc 			; retrieve counter
                add hl,de 			; skip 21 bytes
                djnz writeallbuffers

It seems to work fine: https://msxpen.com/codes/-Mao3UXAtORBKJL1KKC8
This is btw a stripped down version, I have removed sprite collision and score. I will be using that in my real game.

I am just wondering if this is the fastest way to write my buffers to VRAM. Any comments are welcome.

Par Grauw

Ascended (10056)

Portrait de Grauw

28-05-2021, 21:56

Instead of storing the row counter in b, pushing and popping it, and then using djnz at the end, you can ld a,10 and loop with dec a / jp nz,writeallbuffers.

You may be able to optimise a bit more, also in the code that writes into the buffer, if you choose your numbers so that the buffer uses 64 bytes per line (a power of 2), and align the buffer to 256 bytes.

But other than that to be honest this seems a pretty good approach, unless you’re absolutely starved for cycles this seems already quite efficient and fast enough for most intents and purposes. The base cost per row is 928 cycles, and the current per-row cost is 57 which only adds 6%. The variant with the loop counter in a is 36 cycles (4%) so the effect of optimisation has limited effect relative to the base cost.

Par Pbk71

Expert (101)

Portrait de Pbk71

29-05-2021, 07:54

Grauw wrote:

Instead of storing the row counter in b, pushing and popping it, and then using djnz at the end, you can ld a,10 and loop with dec a / jp nz,writeallbuffers.

Thanks for the tips, I'll use the code to skip the push/pop the value of b and use register a instead.
The other tips are a bit too difficult for me at the moment, but I will study them. Probably will come back on them later Wink

Par Pbk71

Expert (101)

Portrait de Pbk71

29-05-2021, 08:06

I've been working on collision checking and on 2 different obstacle patterns that are sort of random chosen with register R.
All quick and dirty code that I need to clean up (lot of repetitions that can also be done in loop for example), but it works and it gives a bit of an impression of the game I am aiming at.

https://msxpen.com/codes/-MaqfBnAssxROmNvah5S

Par ray2day

Hero (664)

Portrait de ray2day

29-05-2021, 10:13

Nice progress! Difficult game to play.

(btw in one way or another MSXpen doesn't work anymore in my Firefox browser... in my Safari browser it works normal)

Par Pbk71

Expert (101)

Portrait de Pbk71

29-05-2021, 11:06

Thanks and yes, this is too difficult to start with. The game will slowly become more difficult in the real version.

Par thegeps

Paladin (860)

Portrait de thegeps

29-05-2021, 18:18

Yep, difficult but I've completed it at third attempt (after a while there are no more obstacles).
Cool achievememt, anyway

Par Pbk71

Expert (101)

Portrait de Pbk71

29-05-2021, 18:55

This demo is indeed a bit buggy and the obstacles stop after a while.

Par thegeps

Paladin (860)

Portrait de thegeps

29-05-2021, 21:36

Well, indeed its purpouse wasn't to be a complete game Wink but you are in the right way. Keep it up!

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