EXAMPLE CODE : Z80 Centipede routine

Do you live and breathe hexadecimal? Do you like speaking to hardware directly?

Moderator: Programming Moderators

kevman3d
Posts: 9
Joined: Mon Apr 02, 2018 6:35 am

EXAMPLE CODE : Z80 Centipede routine

Post by kevman3d » Wed Apr 04, 2018 8:24 am

Yello! :mrgreen:

For those who felt this post seems familiar in some way, then yes - I've already posted this onto the FB group as well, but I figured for those not frequenting FB I'd also post it here. Last evening I decided to 'take that plunge' and get back into some Z80 to see just how much I'd recall from 30+ years ago... Surprisingly once I got started, it all just made sense and next thing I know I'm tweaking code like a 16 year old. :lol:

Anyway...

Zipped and downloadable from the link below is an example for animating a Centipede (ie. the arcade game) from a project I'd hand-written back in 1986:

https://drive.google.com/file/d/1whNCcW ... sp=sharing

In here is a heavily commented .asm file that you can load up (initially typed it up in DesignDesign's ZEUS, but this one I actually loaded and assembled in ZXSpin). I saved out a snapshot (.sna) with example BASIC code that calls the routine to move and draw the centipede for those wanting to watch it work in your speccy emulator.

As well there is a PDF of my old 1986 scanned notebook that has a complete breakdown of my centipede 'plan' in case people want to take a stab at it (or just attempt to understand the pseudo code process behind it all).

Hope that it comes in educational or useful for anybody who was curious how to approach something like this. For me it was a nice nostalgic kick-in-the-brain, and strangely addictive past time that I now feel compelled to continue doing while I wait on the Next... :)

Enjoy!

User avatar
sol_hsa
Posts: 89
Joined: Fri Jun 02, 2017 10:10 am

Re: EXAMPLE CODE : Z80 Centipede routine

Post by sol_hsa » Wed Apr 04, 2018 10:42 am

Would it be possible to put this on GitHub or someplace similar (which would be viewable online) instead of a zip file on drive which may disappear at any point?

User avatar
SevenFFF
Posts: 211
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: EXAMPLE CODE : Z80 Centipede routine

Post by SevenFFF » Wed Apr 04, 2018 2:38 pm

+1 for github :) Apart from the persistance and versioning issues, I do most of my code reading and browsing on an ipad when not in front of a dev environment, and zip files make this hard work!

Did you know that Simon maintains a Zeus windows cross-assembler/IDE/Emulator? If you used the original ZEUS then this will blow your socks off. There is partial Next support too (Sprites, MMU paging, Parasys remote developing/debugging via the UART on the ESP8266 socket and an FTDI USB cable).

http://www.desdes.com/products/oldfiles/
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

kevman3d
Posts: 9
Joined: Mon Apr 02, 2018 6:35 am

Re: EXAMPLE CODE : Z80 Centipede routine

Post by kevman3d » Thu Apr 05, 2018 1:32 am

lol! Yup - I used the windows IDE version of ZEUS to type and debug it initially before I jumped over to ZXSpin. Its pretty nifty, and I like that I can also write out the tzx's and files from the assembler directly. Very cool! ;)

Interestingly ZEUS allowed me to use ld ix,de - and there were no reported errors. As far as standard Z80 goes, that's actually not a valid operation. For the ZXSpin assembler, I had to replace it with the valid "ld ixh,d" / "ld ixl,e" combination (which is how I found out my 'recollection' of Z80 wasn't quite as clear as I imagined it would be :lol: )

Does that mean ZEUS automatically converted that for me into the ixh/ixl opcodes, or is that some kind of NEXT related opcode update? Not that I really care, but it would be interesting to know just purely for curiosity's sake... :)

I do have a Github account from quite a while back. Will start looking at putting this stuff up there if I can remember (a) its URL and (b) what my login was for it. :roll:

User avatar
SevenFFF
Posts: 211
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: EXAMPLE CODE : Z80 Centipede routine

Post by SevenFFF » Thu Apr 05, 2018 1:42 am

It’s not Next-specific, Zeus makes a compound convenience instruction. If you right click >> Toggle Code you can see the assembled bytes - something like DD 62 DD 6B, which is ld ixh, d : ld ixl, e.

The compound instructions are in the docs somewhere, I forget which file.

All very cool, as you say!

Zeus has the Next-specific opcodes too. These ones, plus it might still have some of the earlier proposed ones that've now been dropped. I think it still has the A32 opcodes for instance. Conversely, a few of these are not yet working on the hardware:

Code: Select all

   swapnib           ED 23           8Ts   A bits 7-4 swap with A bits 3-0
   mul               ED 30           8Ts   multiply D*E = DE (no flags set)
   add  hl,a         ED 31           8Ts   Add A to HL (no flags set)
   add  de,a         ED 32           8Ts   Add A to DE (no flags set)
   add  bc,a         ED 33           8Ts   Add A to BC (no flags set)
   add  hl,$0000     ED 34 LO HI     16Ts  Add $0000 to HL (no flags set)
   add  de,$0000     ED 35 LO HI     16Ts  Add $0000 to DE (no flags set)
   add  bc,$0000     ED 36 LO HI     16Ts  Add $0000 to BC (no flags set)
   outinb            ED 90           16Ts  out (c),(hl), hl++
   ldix              ED A4           16Ts  As LDI,  but if byte==A does not copy
   ldirx             ED B4           21Ts  As LDIR, but if byte==A does not copy
   lddx              ED AC           16Ts  As LDD,  but if byte==A does not copy, and DE is incremented
   lddrx             ED BC           21Ts  As LDDR,  but if byte==A does not copy
   ldpirx            ED B7           16Ts  (de) = ( (hl&$fff8)+(E&7) ) when != A
   ldirscale         ED B6           21Ts  As LDIRX,  if(hl)!=A then (de)=(hl); HL_E'+=BC'; DE+=DE'; dec BC; Loop.
   mirror a          ED 24           8Ts   mirror the bits in A     
   mirror de         ED 26           8Ts   mirror the bits in DE     
   push $0000        ED 8A LO HI     19Ts  push 16bit immidiate value
   nextreg reg,val   ED 91 reg,val   16Ts  Set a NEXT register (like doing out($243b),reg then out($253b),val )
   nextreg reg,a     ED 92 reg       12Ts  Set a NEXT register using A (like doing out($243b),reg then out($253b),A )
   pixeldn           ED 93           8Ts   Move down a line on the ULA screen
   pixelad           ED 94           8Ts   using D,E (as Y,X) calculate the ULA screen address and store in HL
   setae             ED 95           8Ts   Using the lower 3 bits of E (X coordinate), set the correct bit value in A
   test $00          ED 27           11Ts  And A with $XX and set all flags. A is not affected.
   
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

kevman3d
Posts: 9
Joined: Mon Apr 02, 2018 6:35 am

Re: EXAMPLE CODE : Z80 Centipede routine

Post by kevman3d » Thu Apr 05, 2018 7:14 am

Awesome - thanks for the info. :)

And yup, I finally sorted my github password and have just thrown these examples up into a Z80 projects repository. You should be able to now see the files here as well...

https://github.com/kevman3d/

User avatar
sol_hsa
Posts: 89
Joined: Fri Jun 02, 2017 10:10 am

Re: EXAMPLE CODE : Z80 Centipede routine

Post by sol_hsa » Thu Apr 05, 2018 7:37 am

Thanks!

Here's direct link to the centipede source:

https://github.com/kevman3d/ZXSpeccy-z8 ... e_code.asm

kevman3d
Posts: 9
Joined: Mon Apr 02, 2018 6:35 am

Re: EXAMPLE CODE : Z80 Centipede routine

Post by kevman3d » Mon Apr 09, 2018 9:55 am

FYI - *almost* done. Bashed up a lot of examples of various items in Centipede (now called 'Centiblock' - Centipede with blocky (ie. colour attribs) graphics). Once I'm done with the scorpion, will clean it up/optimise, put it into a single piece of code and get a playable game assembled.

https://github.com/kevman3d/ZXSpeccy-z80-projects

Then I'll chuck some graphics in there... Its pretty ugly as blocks... But its visually functional for testing.

kevman3d
Posts: 9
Joined: Mon Apr 02, 2018 6:35 am

Re: EXAMPLE CODE : Z80 Centipede routine

Post by kevman3d » Tue Apr 10, 2018 8:46 am

Yus! Last example element - Scorpion motion and behaviour (not that its complex). Example coded and works... :)

Now comes the long part - mush all those examples together to form a single game program. Means cleaning up all that repetitive code everywhere that I hacked together to work. Plus will throw in some timing counters so I can create speed differences between elements in the game...

Its going to be probably quite a time-consuming job, but I'm pleased that I've written code that worked literally first time. A few small bugs, but not a single crash! Hoorah!

Roll on finished game. :mrgreen:

User avatar
SevenFFF
Posts: 211
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: EXAMPLE CODE : Z80 Centipede routine

Post by SevenFFF » Tue Apr 10, 2018 10:58 am

Good stuff. Yes it’s very satisfying writing asm that works first time :) Even more if you’ve been out of the game for 30+ years.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

Post Reply