A few days ago I issued a Z80 programming challenge for the ZX Spectrum:
Something simple for the first challenge. Write the shortest code to fill the screen with a chequerboard pattern of 1 pixel squares. No RAM/ROM other than the 6144 byte bitmap screen memory should be written to.
Target: under 25 bytes.
- Your program shouldn't rely on the initial contents of registers.
 - Programs must return. The 
RETinstruction is included in the size. - So everyone has a fair chance comment with the code size not code.
 - There are no prizes, just the chance to show off your coding skill.
 
Final Results
Congratulations to all who entered, especially Allan Høiberg and Introspec Zx who both discovered a 15-byte solution. The final results are as follows:
| Coder | Size | 
|---|---|
| Allan Høiberg | 15 | 
| Introspec Zx | 15 | 
| Jim Bagley | 16 | 
| Paul Rhodes | 16 | 
| Krystian Włosek | 16 | 
| Tim Webber | 16 | 
| Steve Wetherill | 16 | 
| John Young | 16 | 
| Simon Brattel | 16 | 
| John Metcalf | 16 | 
| Dariusz EM | 17 | 
| Chris Walsh | 23 | 
Winning Entries
Allan was the first to discover a 15-byte solution:
                LD BC,22272
                LD A,85
LoopB:          BIT 6,B
                RET Z
LoopC:          DEC C
                LD (BC),A
                JR NZ,LoopC
                CPL
                DJNZ loopB
Introspec found a 15-byte solution with only one loop:
                ld hl,16384+6143
filloop5:       ld a,h
                rra
                sbc a,a
                xor %01010101
                ld (hl),a
                dec hl
                bit 6,h
                jr nz,filloop5
                ret
My own attempts all fell short at 16 bytes:
                ld hl,22528-256
                ld bc,24*256+170
fill:           dec l
                ld (hl),c
                jr nz,fill
                rrc c
                dec h
                djnz fill
                ret
Entries are archived on John Young's website. Thanks to everyone who entered or otherwise supported the challenge. :-)

cp (hl) vs bit 6,h -byte
ReplyDelete