Christmas star Author: Mira Category: Christmas Challenge System: Atari Language: Assembler (mads) Len source code: 2958 bytes (with comments) Len exe file: 149 bytes Len code only: 82 bytes(net code size; subtract the bytes for header/start address; assembler: also subtract the BASIC stub) Instructions: Use Altirra, v 4.10 Menu: File -> Open Image -> *.obx Description: Antic chip (responsible for converting screen data in RAM into screen signal) in 8-bit Atari computers can be programmed in a way that each text screen line can star on an arbitrary address in RAM. The program for Antic is called a "display list". So, I created a display list for Antic to repeat the lines, according to the specified pattern. All the pattern consist of 4 distinct lines l1, l2, l3, and l4 only: l1: * * * l2: * * * * * * l3: * * * * * * l4: * * * * And I place them on the screen in this order: l1, l2, l3, l4, l3, l2, l1, l2, l3, l4, l3, l2, l1, l2, l3, l4, l3, l2, l1 Then my code needs to fill in only 4 lins the memory, which simplifies the rest of the program. The code itself is in 6502 assembly language, I used MADS cassembler to compile it to the executable image (object) file. Register X stores a screen code for asterisk ('*"). To correctly print a character on a specified position on the X-axis, I use this principle: 1. I use indirect addressing of the screen memory (I use a 16-bit pointer DISPPTR stored in zero page memory) with Y register: (DISPPTR), Y. 2. DISPPTR points to the first asterisk on the current line. a) that means, that when moving to the next line, I need to move it down (address += 40) and also left (address -= 1). Therefore, I add 39 to DISPPTR b) as those 4 lines occupy less than 1 page (256 bytes), I can update only lower byte of DISPPTR pointer 3. I use Y register as the relative offset from the first (leftmost) asterisk on the line. As I need to calculate correct Y only relative to DISPPTR, the pattern that I need to get simplifies to this: l1: * * * l2: * * * * * * l3: * * * * * * l4: * * * * An outer cycle uses YCOUNT variable (also in zero page memory) to correctly count 4 repettitions (for 4 lines to render). In the cycle, the first asterisk is printed and XCOUNT variable (also in zero page memory) is initialized - it specifies the number of X-axis pattern repetitions. The repetitions consist of updating value of Y register by subsequently adding 2 values, after each step an asterisk is prented on the screen. For line 1, these values are 0 (technically, it prints the asterist on the same position twice) and 6. For line 2, they are 2 and 4. For line 3, they are 4 and 2. And finally, for line4 they are 6 and 0. The second number is 6 minut the first number (as it is obvious from the pattern). Comments: It is a great challenge. I tried a couple of approaches. This one seemed to be teh "smartest", that's why I want to share it with others.