Xmas2025 Author: Aitor Gómez García (spark2k06) Category: Christmas Challenge System: PCXT Language: Assembler, NASM 2.16.01 Len source code: 4670 bytes Len exe file: 82 bytes Len code only: 82 bytes Instructions: You can use PCEm as an emulator, or even simpler DosBox to run it comfortably. 1. Install DosBox from the official website: https://sourceforge.net/projects/dosbox/ 2. Save the demo to a folder (for example C:\Demo), run DosBox, mount the folder on a drive, like C: mount C C:\Demo 3. Go to the folder with the instructions C:\Demo, cd Demo, and run the demo with XMAS2025.COM Setting the Text Mode --------------------- The program switches the display to 40x25 color text mode using BIOS interrupt INT 10h with video mode 01h. This mode is compatible with PC/XT-era hardware and provides a text buffer of 40 columns by 25 rows, with each character cell occupying two bytes (character and attribute). The resulting memory layout uses a fixed stride of 80 bytes per screen row, which is later exploited for exact and efficient row positioning. Direct Video Memory Access -------------------------- Direct access to text video memory is established by loading segment register ES with value 0B800h, the standard CGA text mode framebuffer. All rendering is performed by writing directly to video memory using word-sized stores, allowing each character and its color attribute to be written in a single instruction. Snowflake Pattern Encoding -------------------------- The snowflake shape is defined by a small table of 10 words (16-bit masks). Each word represents one horizontal pattern row, where: - Each bit corresponds to one text column - A set bit produces a '*' character - A cleared bit produces a space character Each mask is expanded into 16 character cells by shifting the word bit by bit and testing the carry flag. Horizontal Extension -------------------- After generating the 16 columns defined by the bitmask, the program extends each row by copying three previously written character cells from the same scanline. This reuse of already rendered video memory allows the visual width of the snowflake arms to be increased without storing additional pattern data, reducing overall code and data size. Vertical Symmetry ----------------- The complete figure consists of 19 rows, generated from the 10 stored pattern rows. Vertical symmetry is achieved by: - Reading the pattern table forward for the upper half - Rewinding the pattern pointer after the central row - Reusing the same masks in reverse order for the lower half This produces a symmetrical figure while keeping the pattern data minimal. Row Alignment ------------- Each rendered row consists of 19 character cells, corresponding to 38 bytes written to video memory. After each row, the destination pointer is advanced by 42 bytes, resulting in a total movement of: 38 + 42 = 80 bytes This exactly matches the row stride of 40-column text mode, ensuring correct alignment for each subsequent row without additional calculations. Termination ----------- After rendering all rows, the program returns control to DOS via RET. The generated snowflake remains visible in video memory after execution. Comments: Develop & debug with NASM 2.16.01, DosBox and DEBUG.COM Go to my website for additional information about me and my personal projects https://www.aitorgomez.net