Andreas Gustafsson's Blog

Thursday, August 13, 2009

Z80 optimizing

It's funny how you can look at some code and think, yeah, that's as good as it gets, then suddenly you get a bright idea and realize that - no, it wasn't!
I am working on yet another little demo at the moment, on a system that uses the Z80 CPU (not saying any more than that at the moment! :))
For one of the effects, a single iteration of an unrolled loop looked like this:

exx ; 4
ld a,(bc) ; 7
inc bc ; 6
ld l,a ; 4
ld d,(hl) ; 7
ld a,(bc) ; 7
inc bc ; 6
ld l,a ; 4
ld a,(hl) ; 7
sla a ; 8
or d ; 4
exx ; 4
ld (de),a ; 7
inc de ; 6
---
81 T-STATES

That was my first, off-the-top-of-my-head implementation made a couple of days ago. I was convinced that it was possible to do much better, but I couldn't figure anything out.

Then yesterday I made some progress and came up with this, by swapping around some registers and realizing that in this case rlca worked just as well as sla a and saved 4 T-states:

exx ; 4
ld c,(hl) ; 7
inc hl ; 6
ld a,(bc) ; 7
ld d,a ; 4
ld c,(hl) ; 7
inc hl ; 6
ld a,(bc) ; 7
rlca ; 4
or d ; 4
exx ; 4
ld (de),a ; 7
inc de ; 6
---
73 T-STATES

I sat and stared at the solution for a quite long, and thought, yeah, that's optimized!
But today I discovered that by rearranging my data and using the nice ex de,hl instruction, there were cycles to be saved, and I ended up with this:

ld e,(hl) 7
inc hl ; 6
ld a,(de) ; 7
rlca ; 4
ld e,(hl) 7
inc hl ; 6
ex de,hl ; 4
or (hl) ; 7
ex de,hl ; 4
ld (bc),a ; 7
inc bc ; 6
---
65 T-STATES


So NOW it must be as optimized as possible, right? :)

Labels: ,

Thursday, January 01, 2009

2008 in retrospect

Yes, my blog has been woefully neglected the past year, so I better start this year a bit more productively with a look back at 2008.

Major things for me during 2008 was first of all that I added several nice items to my collection of old 80ies computers:

  • Commodore Plus/4

  • Commodore VIC-20

  • Philips NMS-8245 (MSX2)

  • Atari 130XE

  • Commodore 64 (old bread-bin model, I had a C64C before)


I also had a very productive year on the demoscene (after a bit slow start the first months), releasing more stuff than I have ever done any previous year:

  • 407566 - C64 onefile demo, released in April

  • Very Much Useless - Sega VMU demo, winner of mixed compo at LCP2008 in August

  • Pseudocode - C64 demo, 3rd in C64 compo at LCP2008 in August

  • 126b - VIC-20 intro, released in August

  • Ancient School - VIC-20 demo, winner of Sundown oldschool demo competition in September

  • Invasion of the big pixels - MSX1 demo, 2nd place at the Grep White demo competition in December


I'll be very pleased if I can keep the same tempo this year!

Labels:

Monday, August 06, 2007

BFP 2007

A week has passed since the Big Floppy People 2007 demo party, and I have forgotten to write about it!

It was a nice event, and I got to chat with some cool people like Archmage/Andromeda (who showed me stome stuff he was working on for the ASD-demo that won ASM07 this weekend), Zzap69 (a former Noice-member I never met before), Fix/TRSI (a fellow DTV owner who was kind enough to let us use his machine in the compo when mine didn't cooperate with the bigscreen projector) and many others. Best of all, I won the mixed demo competition with my DTV-demo, Uncharted Territory!

Labels: ,

Friday, July 27, 2007

Mad crunchtime!

I've been in completely insane coding crunch mode for almost two weeks now trying to finish my new DTV demo in time for Big Floppy People 2007

The amount of boring work that goes into linking everything together, making sure that parts cooperate nicely etc. is mind-boggling to say the least. I think I've spent about as many hours now just with putting the parts together as I have actually coding the ffects.

Well, now I'm ALMOST there, still some minor bugs, but I'm so damn tired of this that I think I will consider it ready now! :)
Anyway, here's a sneak preview of the intropicture from the demo:





Release should be now on saturday if everything works out!

Labels: ,

Monday, May 07, 2007

The C64DTV - a new "oldschool" demoscene platform?

The C64DTV and Hummer are cheap connect-to-TV-and-play toys. The cool thing is that the hardware implements a good approximation of the classic C64 and also extends it with new features like 256-color mode, 2Mb RAM and a blitter.
For democoders wanting to continue with oldschool productions but looking for new challenges, it is an interesting choice.
I have a background in C64 coding (haven't released anything since early nineties though) and I am excited by it!
Yesterday I released my first little DTV-demo "Hello DTV World".



The demo is very basic, the only DTV-specific things exploited is the 8bpp mode for the intro pic and the 256-color character mode used for the plasma,
but I still got a feel for the platform and what the possibilites are.
Compared to the C64 scene which is very mature and almost all technical tricks have been discovered, the DTV is still uncharted territory (however C64 legend Crossbow/Crest have been doing some DTV stuff, so perhaps he will shock the scene and release a demo exploiting every DTV-trick possible soon... :))

Anyway, I think that sceners that are looking for a new platform should give the DTV a thought.

Pros:
+ New platform (but with oldschool flavor!) with lots of technical tricks to be discovered.
+ Familiar coding environment for those with C64 experience.
+ Good development tools available.
+ Cheap.

Cons:
- Needs hardware modding.
- Production of new units has (to my knowledge) halted.
- Still depends on C64 peripherals (C64 diskdrivers are rather slow and low capacity, aswell as hard to aquire nowadays)
- No established scene yet.
- Uncompatible hardware versions (v1 NTSC lacks almost all the new features, v2 PAL has some blitter bug)

Labels: ,