Moving sprites

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Moving sprites

Post by MrPixel »

so, i'm watching the Master Class videos on youtube and was wondering, is there an ML or assembly routine that can move the sprites depending on what key is pressed. (i'm partial to arrow keys and WASD). the reason is because i want to make a simple demo of my Mom's candy company and show it to her. it's supposed to resemble chucky egg but play like Burgertime. (you fight chocolate chips and launch cookie dough to stun them and then eat them)

any ideas?

i'm using the Fuse emulator with the 48k option :)

thanks in advance you wonderful people
User avatar
PeterJ
Site Admin
Posts: 6858
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Moving sprites

Post by PeterJ »

I'm a long way from being an any sort of expert with Assembly Language but I learnt so much from [mention]Jonathan[/mention] Cauldwell's book:

https://spectrumcomputing.co.uk/index.p ... id=2001501

You need some experience of Assembly Language to get started. The MicroMart tutorial from [mention]Shaun_B[/mention] is a good starting point:

http://shaunbebbington.blogspot.co.uk/2 ... art-i.html
User avatar
R-Tape
Site Admin
Posts: 6353
Joined: Thu Nov 09, 2017 11:46 am

Re: Moving sprites

Post by R-Tape »

MrPixel wrote: Sat Mar 24, 2018 8:09 pm so, i'm watching the Master Class videos on youtube and was wondering, is there an ML or assembly routine that can move the sprites depending on what key is pressed. (i'm partial to arrow keys and WASD). the reason is because i want to make a simple demo of my Mom's candy company and show it to her. it's supposed to resemble chucky egg but play like Burgertime. (you fight chocolate chips and launch cookie dough to stun them and then eat them)

any ideas?

i'm using the Fuse emulator with the 48k option :)

thanks in advance you wonderful people
Hello MrPixel!

Don't know if it's less or more what you're after but I did this assembly sprite routine tutorial on the forum: viewtopic.php?f=6&t=256&hilit=sprite+tu ... t=20#p3000

And Jonathan's "How to write ZX Spectrum Games" is available here: https://spectrumcomputing.co.uk/index.p ... id=2001501, that has just about everything you could ever need to get started :-)

EDIT - similar post to Peter, I'll say "jinx no comebacks" first :-p
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Moving sprites

Post by Ast A. Moore »

MrPixel wrote: Sat Mar 24, 2018 8:09 pm is there an ML or assembly routine that can move the sprites depending on what key is pressed.
:D Yeah, it’s called Write Your First Sprite Moving and Keyboard Polling Routine.

It all depends on how well-versed you are with Z80 assembly in general and Spectrum’s video file structure in particular. The general idea is pretty straightforward: you store your sprite somewhere in RAM, you poll the keyboard, adjust the coordinates, translate the coordinates into a screen address, and start copying your sprite data onto the screen. Erase, poll, recalculate, redraw.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Moving sprites

Post by MrPixel »

tried assembly on ZXSpin and the assembler is a mess, barely running any code. will Zeus work? is there a Machine code routine i can call in Basic with USR?
User avatar
PeterJ
Site Admin
Posts: 6858
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Moving sprites

Post by PeterJ »

Have you tried the Arcade Game Designer for the Spectrum?

There are tutorials here:

http://www.thespectrumshow.co.uk/AGD.aspx
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Moving sprites

Post by Ast A. Moore »

I can’t vouch for ZXSpin or Zeus. I’m sure they’re as capable as any other assembler, at least for the task you’re set out to accomplish. But I’m sure Windows people will chime in with specific suggestions.

As for running a machine-code routine, the USR function is pretty much the only (simple) way of doing that, naturally. The most common way of using it is to stick it after the RANDOMIZE command with the address of your machine code as the argument like this:

Code: Select all

RANDOMIZE USR 40000
Most assemblers—especially those designed with the Spectrum in mind—can generate a tape file, which will contain a simple loader in BASIC, which will in turn load your assembled machine code and run it (just the way a typical Spectrum program works). Usually, you don’t need to worry about the BASIC (unless you really want to, of course), and can just focus on writing your assembly code.

Again, I don’t know how familiar you are with Z80 assembly, but the typical first program is just a single RET instruction. When called from BASIC, it will . . . well, return back to it. So if you see the OK message, you know you’re good. The opcode for the RET instruction is decimal 201. So, to test the waters, you can do the following right in Sinclair BASIC.

1. Use the POKE command to write the opcode for the RET instruction to a memory address
2. Execute that instruction.

Code: Select all

10 POKE 40000,201
20 RANDOMIZE USR 40000
Then enter RUN and you should be greeted with:

Code: Select all

0 OK, 20:1
which means “Statement 1 in line 20 returned with the message ‘OK.’”

A typical Spectrum program contains a BASIC loader, which may look like this:

Code: Select all

10 CLEAR 39999
20 LOAD ""CODE
30 RANDOMIZE USR 40000
Ignoring the CLEAR statement for the time being, this short BASIC program loads the next file (of the type CODE) at the address specified in its header and then passes the execution to memory address 40000.

Your assembler should be able to generate such a BASIC program and insert your assembled code into the tape file.

Once you figure out how to create a valid Spectrum tape file (and load it in Fuse), you can focus on the actual coding.

Do check out the guides the guys linked above. Don’t worry if it all doesn’t make sense to you immediately. And don’t hesitate to ask more questions. We might not always be able to walk in your shoes; a lot of these things are second nature to us. After all, we’d been doing them long before you were born. ;)

Hope this helps.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Moving sprites

Post by Nomad »

Like others have pointed out, you are looking at Pasmo or Zeus for cross development. There are some other choices but those seem to be the big two.

The Tutorials linked already are nice to look at, the important thing is to play with the examples and make your own little tech demos. Figure out how each bit works.

Zed Shaw said it best with
Learn to think like the computer hates you, because it does.
Lol defensive programming is the way to go. If you leave anything to chance it will come back to bite you. Either the computer will trip you up, the tools or the user will. I would see it as a kind of unholy alliance that is trying to ruin your day.

With the copy and paste stuff - that will make it more difficult to really understand what is going on. You need to write it out. That way you learn faster. Especially if you do it long hand. By using the Copy pasta you are short changing your learning potential.

If you are a windows guy I would say learn Zeus as early as you can. Linux guy - well you are in for a hard time. :lol: I use pasmo but its 'idosyncratic' is probably the most polite way to describe this old warhorse that on any other scene would have been sent to the metophorical glue factory/dog food cannery long ago.

Sometimes the books are a good place to start, but often times they are just as bad as the incomplete blog posts/youtube series you will find. There was no quality control back in the day. Plus you have an issue where the workflow for assembly coding was completely different.

If you are happy 'goin' oldschool' then fair enough but its going to frustrate you typing in hex codes :lol: Still for many people that was how they learned how get it done.

Spectrum books for the most part are a collection of highly specific use case examples/solutions often that do not generalize.
You want general solutions look at the Z80 books by Lance L and Zacks. But these are dry and extremely long reads. But if you are keen its worth a look (they are both on archive.org)

There is a 'third way' Check out the complete Machine Code tutor.

https://spectrumcomputing.co.uk/index.p ... 96&id=8031

I would look at this first, then come back at check out the more advanced tutorials. It is well worth your time to try it out. If you are more of a visual / learn by doing type of guy this will be a good one to try.
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Moving sprites

Post by Ralf »

Like others have pointed out, you are looking at Pasmo or Zeus for cross development. There are some other choices but those seem to be the big two.
You forgot about Sjasm. It's big too. And my personal choice for years ;)
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: Moving sprites

Post by AndyC »

One of the hardest things to get over when it comes to assembly on the Spectrum is realising that things like "sprites" aren't really things at all. That's why you'll struggle to find a "move a sprite" routine, everything is faking it and the best approach varies upon exactly what you're trying to accomplish.

Ultimately a sprite is just something drawn onto the screen, destroying whatever was there before. Moving it therefore is a case of restoring the background and then drawing it again in a slightly different position (possibly with a different animation frame) to give the impression that something has moved.

Now how you do that is a whole different issue. An easy way is to draw the sprite using XOR operations, taking advantage of the fact that doing the same thing again will restore the original image. It works well for plain backgrounds where sprites are unlikely to overlap, but soon gets very messy when things can overlap a lot. The other end of the stick is simply not to worry about it at all and simply redraw the entire playable area every time from scratch. It's a lot more work, but if you have scrolling backgrounds you may find you'd need to redraw most of the screen anyway and so a more simplistic approach like that can be just as effective. Various other intermediate approaches also exist, whether saving and restoring the background or redrawing it in any "dirty" areas. Each has it's own advantages and disadvantages that make them more suitable in certain circumstances.
User avatar
bobs
Microbot
Posts: 106
Joined: Thu Dec 28, 2017 8:26 am
Location: UK
Contact:

Re: Moving sprites

Post by bobs »

You can always see if there’s anything of use to you on my 8-bit coding blog:
https://bobs8bb.wordpress.com
Have covered sprites, keyboard routines, and much else besides
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Moving sprites

Post by MrPixel »

AndyC wrote: Sun Mar 25, 2018 12:50 pm One of the hardest things to get over when it comes to assembly on the Spectrum is realising that things like "sprites" aren't really things at all. That's why you'll struggle to find a "move a sprite" routine, everything is faking it and the best approach varies upon exactly what you're trying to accomplish.

Ultimately a sprite is just something drawn onto the screen, destroying whatever was there before. Moving it therefore is a case of restoring the background and then drawing it again in a slightly different position (possibly with a different animation frame) to give the impression that something has moved.

Now how you do that is a whole different issue. An easy way is to draw the sprite using XOR operations, taking advantage of the fact that doing the same thing again will restore the original image. It works well for plain backgrounds where sprites are unlikely to overlap, but soon gets very messy when things can overlap a lot. The other end of the stick is simply not to worry about it at all and simply redraw the entire playable area every time from scratch. It's a lot more work, but if you have scrolling backgrounds you may find you'd need to redraw most of the screen anyway and so a more simplistic approach like that can be just as effective. Various other intermediate approaches also exist, whether saving and restoring the background or redrawing it in any "dirty" areas. Each has it's own advantages and disadvantages that make them more suitable in certain circumstances.
how do i run an SCL. File? that's the only way ZX asm 3.0 will run :?
User avatar
PeterJ
Site Admin
Posts: 6858
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Moving sprites

Post by PeterJ »

SCL (* .scl) - a format for storing TR-DOS-files

I have not heard of ZX ASM 3 before but looking on Google it seems to be Russian and comes as a SCL or TRD TR-DOS image for Russian Clones.

You would be better off using Pasmo, ZX-Spin or similar. Have you looked at the material that other people have posted you links to?

Peter
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Moving sprites

Post by Ralf »

SCL (* .scl) - a format for storing TR-DOS-files
If you are new to Spectrum emulation, I would suggest using Spectaculator:

http://www.spectaculator.com/downloads/

Many people (including me ;) ) believe it's the most friendly of emulators. Speaking of .scl files you just click on it in Windows and it opens (assuming you created file associations during install)

Spectaculator is not free but you have 30 days of trial.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Moving sprites

Post by Nomad »

Ralf wrote: Sun Mar 25, 2018 11:17 am
Like others have pointed out, you are looking at Pasmo or Zeus for cross development. There are some other choices but those seem to be the big two.
You forgot about Sjasm. It's big too. And my personal choice for years ;)
Ah I didn't know about this.. nice
User avatar
Alessandro
Dynamite Dan
Posts: 1908
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: Moving sprites

Post by Alessandro »

Talking about learning Z80 Assembly on the Spectrum, I would heartily recommend anyone who wishes to undertake such an endeavor, besides the already given recommendations, Ian Sinclair's Introducing Spectrum Machine Code, together with Rodnay Zaks's Programming the Z80 and Lance A. Leventhal's Z80 Assembly Language Programming for a more comprehensive and in-depth approach. The last two books helped me so much from a first glance, that I ultimately found and bought a second-hand copy of Italian editions of both of them.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Moving sprites

Post by Nomad »

Zaks & Leventhal's books are good. But they take a lot of dedication to get the most from them.

I prefer the Leventhal books but they are both good. Dry but good. It would make a great youtube lecture series I figure probably 100-150 hours or so but it would be good.
User avatar
PeterJ
Site Admin
Posts: 6858
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Moving sprites

Post by PeterJ »

[mention]Alessandro[/mention],

The Introducing Spectrum Machine Code book is available here if anyone wants to download a copy.
User avatar
Alessandro
Dynamite Dan
Posts: 1908
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: Moving sprites

Post by Alessandro »

PeterJ wrote: Mon Apr 02, 2018 3:30 pm @Alessandro,

The Introducing Spectrum Machine Code book is available here if anyone wants to download a copy.
Thank you [mention]PeterJ[/mention], I downloaded the PDF scan from the WOS archive ages ago, and could not find a suitable link for the life of me!
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Choosing an Assembler

Post by MrPixel »

is there a good Z80 assembler (not zeus, i already went down that rabbit hole once) that i can use to start properly making games or, at least graphics :?:

***Title changed by Mod****
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Moving sprites

Post by Ast A. Moore »

There are plenty of Z80 assemblers to choose from. Some cater to the ZX Spectrum specifically. Some even let you assemble your source online. I think you need to focus on learning the Spectrum’s architecture and Z80 assembly language and worry about the tools later. In fact, you can use any number of assemblers written for the Spectrum itself (i.e. running on it natively).
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Wall_Axe
Manic Miner
Posts: 492
Joined: Mon Nov 13, 2017 11:13 pm

Re: Moving sprites

Post by Wall_Axe »

you are using windows?
on linux you can create a 'makefile' which really helps, to get makefiles running on windows is a hassle. I've never learnt how to do bat files on windows.

the makefile basically compiles your game and runs the emulator...only if it compiled successfully..which is very useful

That being said pasmo is a good compiler, it generates the .tap file for you, which is ready to be loaded into the emulator.

if your game isnt that complicated and doesnt need proper sprites you could go for boriel's basic, which also lets you use assembly routines mixed in with basic.

i usually make my own tools to get graphics into spectrum format (which i lost), zx paintbrush is spectrum oriented..but i dont know how to get the picture exported as bytes, which is what you need.
User avatar
PeterJ
Site Admin
Posts: 6858
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Moving sprites

Post by PeterJ »

Hi [mention]MrPixel[/mention] you will find a lot of appropriate answers and tutorials on the threads you started here:

viewtopic.php?f=6&t=554

And here:

viewtopic.php?f=6&t=559

Regarding graphics, ZX Paintbrush is recommended in the thread you started here:

viewtopic.php?f=7&t=657

I use a mix of Pasmo, and ZX-Spin running in a Windows XP Virtual Machine. As others have said Spin is very dated and not recommended by many, but it is a very good all in one solution for beginners IMHO.

You do need to do a lot of reading (as many others have said) before you starting typing at the keyboard though. If you really want to learn there is no magic wand or overnight solution. Once it starts to click, even at a simple level which is where I am at, the sense of achievement is amazing.
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Moving sprites

Post by Ralf »

is there a good Z80 assembler ... that i can use to start properly making games or, at least graphics
You don't make graphics with assembler, you make them with graphics editor ;) When they are ready you display them with assembler.

What you need is actually some tool to convert graphics into notation acceptable for assembler. I remember from your another post that you didn't want to use standard PC graphic editors but if you changed your mind then Sevenup is a tool for you.

You create some graphics, save them as standard picture (.png, .bmp, .gif etc) and import it to Sevenup. Then you configure your output, do export and get things like .BYTE 1,2,3 You paste it into your assembler code and can use it since that moment in your program.

As for the assembler if you don't want use Zeus then the most popular options are Pasmo and SjasmPlus.
Post Reply