256字节大赛__life
debug吧
全部回复
仅看楼主
level 7
life
2008年05月01日 13点05分 1
level 7
; Roto-life (rotozooming game of life, with blur -- in 256 bytes!); Game of life algorithms by INT-E; Decyphering and adaptation of game of life, and everything else by Bonzorg100h; The first two lines of the matrix are filled with crap because of the; algorithm, so we skip them when plotting the cellsNXequ512 / 8NYequ272EXTRAequ128 / 8 + NX * 8; So many bytes are not displayedCELLSequNX * NY; Also the origin of cells table; Constants for the rotozooming tabletableequ01000h; Pointer to base of tabletabentriesequ200h; Number of entries in the tabletabsizeequtabentries * 4; Size in bytes of tabletabmaskequtable | (tabsize - 1); Mask for addresses in the table; Macro for referencing FPU constantsworkequ200h; Base of work area%define var(x) word [byte si+x-work]; Setup video mode and palette -----------------------------------------fninitmoval,13hint10h; The palette is set to a blue...white gradient with this setup:; each bit represents whether the pixel was set 0..7 generations; ago: bit 7 is set if a pixel appeared in the most recent generation; and decreases the red and green components represents by 8,; while bit 0 is set if a pixel appeared 7 generations ago and; decreases the components by 1.; This allows one to plot a pixel with a simple BT+RCR pair; (BT on the game of life matrix, RCR on VRAM)movdx,03c8hxorax,axoutdx,alincdxsetpal:moval, 63jnssetpal2; SF has sign of AHmoval, 40; If cell alive, draw it more bluesetpal2:movcl, 8bit:rolah, 1; extract a bit into carryjncnodecsubal, cl; and accumulate the weightnodec:loopbitoutdx, al; Output red/greenoutdx, almoval, 255; Setting AL=255...outdx, al; ...is the same as 63 (full blue)...incax; ...but INC AX increments AH!jnzsetpal; Do next color; Compute sines and cosines ------------------------------------------movch, tabentries >> 8; 256 entries in the tablemovdi, table; Pointer to base of table%if tabentries == workmovsi, cx; Pointer to base of data%elsemovsi, work%endifcalctab:movword [si], cxfildword [si]; angfldpi; pi angfmulpst1; ang*pifidivvar(shift); ang*pi/128fsincos; sin cosfldst0; sin cos coscallcalc; sin coscallcalc; sinfstpst0loopcalctab; Main cycle ---------------------------------------------------------pushword 0a000hpopfsframe:pusha; Save CX=0, DI=anglemov
bp
, CELLS; number of bytes in the cells matrixmovdi, bp; di=cells matrixleasi, [bp+di]; si=workspace (at 2*CELLS)life:pushbp; save count of remaining bytesmovbp,NX * 2; start with the line belowmoval,byte [di+bp]; Copy screen to buffer formovbyte [si+bp],al; next lineline:; WARNING: black magic followsmovax,[si+bp-NX]; read 16 cells from bufferpushaxrorax,1; AX=89ABCDEF 01234567
2008年05月01日 13点05分 2
1