DCrespo3D/DavidPrograma (dapr) contest entry for VCCC2023 (bouncing ball algorithm). Author: David Crespo - Category: Christmas Challenge System: Sinclair ZX Spectrum 16K Language: Z80 Assembler, assembled using Z80ASM from Z88DK cross compiler/assembler Len source code: 1481 bytes for ASM source, including comments and formatting Len exe file: 120 bytes for TAP image file, loadable in (almost) any Spectrum emulator Len code only: 40 bytes for BIN code, which is loaded at addresses $6006 to $602E, both included Instructions: Open the .tap file with any Spectrum emulator. I personally use Fuse, File->Open, select .tap an ready to go! Description: The drawing is performed using a bouncing ball within a 18x21 rectangle, each time the ball/asterisk reaches a wall, it inverts its speed in the direction normal to the wall. Spectrum ROM routines are used (PRINT AT, using code 22, called with RST 16 opcode). 5 bytes (beginning from offset $1D) are used for avoiding writing to the first 3 lines, which would make an invalid figure. Direction inversion is performed by code self-modification at offsets $24 and $25, due to the fact that z80 opcodes for INC C/DEC C and INC D/DEC D are consecutive, so there is no need for variables to store x and y increments, just switch INC/DEC opcodes on the fly. For reaching the lowest byte count, the program does NOT clear the screen, and performs an infinite loop. It is sensitive to the low byte of the entry point address ($06), as it is used for: - the initial ball position (which must x == y and be 0 <= x < 20), so x0 = y0 = 6 - the actual character printed, which is determined by the L register, with HL pointing to INC/DEC opcodes at offset $24. $24 + $06 = $2A == ASCII for asterisk. I have sucessively lowered the byte count from 52 to 47, 45, 44 until the final 40 bytes. The (not included) unrolled loop version used 44 bytes, a simple 2-round DJNZ loop seems to do the trick of trimming 4 extra bytes. After that I have tried some approaches, but haven't been able to reduce it further. Maybe with a different algorithm... Comments: See .lis file (listing generated by assembler), with offsets and useful stuff. I have included the command used to generate the .lis, .bin and .tap files from the .asm source, in file compile_command.txt in case you have access to the z80asm assembler. Inspiration came from "The Office" episode where employees in the meeting room enjoy looking at the DVD logo bouncing on the TV screen, and they cheer when it reaches the corner. Thanks for organizing this challenge. It's fun, and good to keep the old skills alive!