Archive for the ‘Jason’s News’ Category

A side order of Z80

Wednesday, November 18th, 2015

There hasn’t been much news here recently; MD201511 is still in what I rather euphemistically call the “design phase” – in other words, I’m still wandering lonely as a cloud through all of the prototype code on my hard disk whilst trying to settle on something to build into a proper release – and there’s another onefiler on the go which is under wraps for the moment. But there has been a little activity that wasn’t documented at my “side project”. HDM Clone is a copy of Happy DemoMaker’s Amstrad CPC one-parter HDM Demo 1 because the intention over there is to have a prod around old demos, loosely duplicate how they work and then release the source.

Essentially it’s just a raster bar routine, some colour splits to make the mode 1 graphics a bit busier, a couple of LDIR-powered scrolling messages and an AY conversion of the fabulous Amiga module Hymn To Yezz which was done by yours truly with Arkos Tracker. The scrolling routine is just a mode 1 reworking of the code written for Snoozing so the upper greetings scroller is too fast, but that’s in keeping with the original. I did at least manage to get it tested on a real CPC464 before release this time!

How MD201510 works

Wednesday, November 4th, 2015

The idea behind the UOCC was to find ways to use pseudo/illegal/undocumented/whatever opcodes in order to gain an advantage; these are commands that aren’t officially there but work because they accidentally perform the operation of two other commands at once. MD201510 relies on them for the main effect in the upper and lower borders and I’ll get to those in a moment, but the logo movement routine is also using a pseudo opcode, specifically LAX which simultaneously loads the A and X registers with the same value. In this particular case the loop starting at the label logo_copy_1a in the source code does the following…

lax logo_data_ln1,y
sta screen_ram+$000,y
lda logo_colour_dcd,x
sta $d800,y

…which basically reads from somewhere within a table called logo_data_ln1 (which is data for the first line of the Cosine logo, logo_data_ln2 is the second and so on – all of these reads are self modifying code so the logo can move) and stores the contents of A to the screen memory. It then uses that same value but in X as an offset to fetch a byte from the table logo_colour_dcd which gets pushed to the colour RAM. Each character in the set has a unique colour value in that table and changing one byte makes every instance of that character update when the screen is refreshed. Doing this in a loop using the regular commands would look something like…

lda logo_data_ln1,y
sta screen_ram+$000,y
lda logo_colour_dcd,x
sta $d800,y

…and for every character plotted the LAX shaves two cycles off by removing the TAX; that doesn’t sound much but it claws back over four hundred cycles when everything is added up and, to paraphrase a certain supermarket advertising campaign, every little helps. That said, this is jumping through hoops to make the pseudo opcode useful in this context and simply throwing some RAM at unrolling the entire loop will both solve the issue just as cleanly with regular commands and reduce the cycle count even further – that’s basically what Hammer Down is doing for it’s colour scrolling.

The main effect on the other hand is legitimately gaining an advantage but more cycle conscious too, producing a series of patterns across the upper and lower border areas by writing multiple values to the ghostbyte (a single byte that gets repeated throughout those spaces which is usually last byte of the current video bank) on each scanline. I’ve used this before in Spotified but that was a lower “resolution” because it’s using LDA #value / STA ghostbyte for each split, six cycles in total and one cycle is a character wide. MD201510‘s splits are only four cycles wide which has to be done by loading all three registers at the start of each scanline and then spending the visible area doing something like STA ghostbyte / STX ghostbyte / STY ghostbyte – there can be ten or eleven writes per line but, if the splits are to be the same width, the registers can’t be given new values mid line.

That’s where pseudo opcode SAX comes in because it takes the same four cycles as a regular STA or STX when writing to memory, but the value it pushes out is the contents of registers A and X with a logical AND applied. Set bits in the ghostbyte are always black (the colour is all provided by the background) and two mostly set bytes will AND together quite well in this situation. There was also meant to be some use of SBX in the routine which renders the moving “blob” texture but I’ve just noticed it was removed whilst trying to fix something else and not restored in the final source despite the comment still being there – whoops!

The competition was loads of fun distraction and I’m interested to see what everyone else comes up with to use some of the other pseudo opcodes.

Workprint – November 2015

Sunday, November 1st, 2015

So, hands up who thought I was going to miss the monthly demo deadline for October then…? Okay, I had my doubts as well but MD201510 – Spoopiness came out yesterday afternoon just in time for Halloween, which is good considering it’s appropriately themed and sports the music from Elvira – Mistress Of The Dark which was composed by Sean Connolly.

This demo is also an entry into the UOC coding challenge at the CSDb where the objective is to produce code that takes advantage of unintended opcodes – sometimes called illegal, pseudo or undocumented opcodes, your mileage will vary – so notes as to where the pseudo opcodes are used and what advantage is gained need to be included; in this case it’s relying on SAX (which ANDs the contents of the A and X registers together as the result is written to memory) to give four possible values per scanline to the ghostbyte splits in the border rather than the usual three and there’s some use of another command called LAX (which simultaneously loads the same value into the A and X registers) for the logo movement routine, saving a couple of cycles per character drawn. Also, it’s a Halloween demo which has ghostbyte splits, geddit? Oh, please yourselves… [Mutter, mutter]

The I’ve also opened a GitHub account and pushed everything bar the build tools required for MD201509 and MD201510 up for those who felt themselves masochistic brave enough for a nose around my source code; they’re probably not for beginners since there’s quite a bit of self modifying code and loop unrolling going on, but future instalments in the series will appear there as well.