256字节大赛__amiga
debug吧
全部回复
仅看楼主
level 7
amiga
2008年05月01日 13点05分 1
level 7
; Amiga, isn't it? -- by Bonz;; This is a bouncing sphere with an animated texture map, resembling the; original Amiga effect that stunned everybody at the time. Ahem, let's; put things straight, this is not a real sphere -- the formula is that; of the lens effect. Though I like the result, I wrote this just to do; a 256b intro in 16 color modes before anyone forgets how to program; them :-);; Everything is done in hardware: the animation is flicker-free thanks to; bitplane animation (you toggle which planes are visible with register; 12h@3c0h, and draw only on the opposite ones with register 2@3c4h), the; scrolling uses the start offset (0ch@3d4h and 0dh@3d4h) and pixel panning; (13h@3c0h) registers. I use Write Mode 2, which is set with register; 5@3ceh: the color comes from the written data, while the bitmask register; 8@3d4h decides which pixels are affected. Tnx to Boreal who taught me; the Color Plane Enable register and bitplane animation!;; The only program ever (I think) to use all of JPE, SALC and XADD (which; BTW makes it require a 486). Does exactly 12994 square roots per frame.org100hmoval, 12hmovdx, 1306h;9830h>>3 (9830h is close enough to VRAM)color:int10hmovbl, dl;color indexmovbh, 63;whitemovax, 1000h;set EGA palette functionshldx, 1;set color indices 0110 and 1100jnscolormovds, dx;point DS to (just before) VRAMpushbyte -100;create data area on the stack: originpushbyte -120pushbyte 2;and directionpushbyte -2movbl, 6;BX = mask for Color Plane Enable;xorcx, cx;don't care about a little flicker on the;xorsi, si;first frame (I got bored optimizing ;-)frame:movdx, 03DAh in al,dx;also clear flip floptestal,01h;test display disablejnzframemovdl, 0C0h;select Attribute Controllermoval, 33h;13h + Palette Address Source (PAS) bitoutdx, alxchgax, si;write the horizontal panningandal, 7outdx, almoval, 32h;12h + Palette Address Source (PAS) bitoutdx, alxchgax, bx;now write the maskoutdx, alxoral, 6^12;complemented maskmovbx, ax;put it back in BXmovdl, 0C4h;Sequencer Map Mask registermovah, almoval, 2;enable the invisible planes for writingoutdx, axmovdl, 0D4h;CRT controllermoval, 13movah, cloutdx, ax;start address lowdecaxmovah, choutdx, ax;start address highmovdl, 0CEh;Mode registermovax, 0205houtdx, ax;select "write mode 2"incdi;increment frame numberpushdi;and push it on the stackmovdi, 8+(0a0000h-98300h);set up top-left corner of the screenmovsi, -63;sphere Ymovax, 127;initial X^2 = 4096 - Y^2movdx, 125;initial delta between squaresline:pushax;update AX and compute square root in CXcallupdatepopcx;square root is leftmost x valuejcxzdone;end if no pixels to be drawnpushamovax, 4096;initial Z^2 = 8192 - x^2 - (4096-x^2)
2008年05月01日 13点05分 2
level 7
movdx, cx adddx, dx;draw from -CX to CX-1 (2*CX pixels)pushdx;save no. of pixels to drawdecdx;the first delta for Z values is 2*CX-1movbx, 8008h;prepare bitmask registerrolbh, cldeccxshrcx, 3;and compute offset into DI toosubdi, cxpopcx;no. of pixels to draw in CXpixel:pushax;update AX and compute square root in SIcallupdatepopsi;; STACK LAYOUT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ORIGIN X BP+28FFFC;; ORIGIN Y BP+26FFFA;; DX BP+24FFF8;; DY BP+22FFF6;; FRAME NUMBER BP+20FFF4;; AX BP+18;; CX BP+16;; DX BP+14;; BX BP+12;; SP BP+10;; BP BP+8;; SI BP+6;; DI BP+4;; (parameter) BP+2<--- these two could be overwritten;; (stack return) BP+0<--- by now (who cares)pushaxchgax, bx;Set bitmask registermovdx, 3cehoutdx, axmovax, [
bp
+16];sphere X is in old CXshlax, 6cwdidivsi;texture X = 64*X/Z in BXaddax, [bp+20];add frame numberxchgbx, ax;frame number in AXmovax, [bp+6];sphere Y is from old SIshlax, 6cwdidivsi;texture Y = 64*Y/Z in AXaddax, [bp+20];add frame numberxorax, bx;compute checker patternshral, 5;from (x^y) & 32salc;write with colors 4-15, but the Map Maskoral, 4;register changes them to 4-6 or 4-12!xchgal, [di];read to latch other bits, write new bitpopadecword [bp+16];modify sphere Xrorbh, 1;update bitmaskadcdi, byte 0;and pass to next byte if necessarylooppixelpopaadddi, byte 80;next screen lineincsi;update sphere Yjmpshort line;and go ondone:movcx, -348;maximum allowable Y valuebounce:xchgsi, ax;second time, save Y value in SImovax, [bp+8]cwd;if delta>0, limit coordinate to 0andcx, dx;else to the value in CXxadd[bp+12], ax;old Y in AX, new in [bp+12]cmpax, cx;limit reached?jneshort oknegword [bp+8];yes, invert movementok:movcx, -498;second time, do the Xdecbpdecbpjpebounce;loop twicepushax;push top X (for smooth scroll)imulcx, si, byte 80;top address in CXsarax, 3addcx, axpopsi;pop top X into SIpopdi;get back frame numbermovah, 1;key pressed?int16hjznear frame;if not, another framemovax, 3;else back to text modeint10hint20hupdate:addax, dx;compute next squaredecdx;decrement delta to next odd numberdecdxmovbp, spfildword [bp+2]fsqrtfistpword [bp+2]ret
2008年05月01日 13点05分 3
1