fr-0.1 code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 %line 1+1 fr0_1.asm | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 [bits 16] | |
| 8 [org 100 | |
| ; initial register contents assumed: | |
| ; ah = 0 | |
| ; bx = 0 | |
| ; si = 0x100 | |
| ; bp != 0 :) | |
| 9 | |
| 10 00000000 B013 start mov al, 0x13 ; these 2 bytes do double duty as frame counter later. | |
| 11 00000002 F5 cmc ; this one is a data byte, not actual code. | |
| 12 00000003 42 inc dx ; same here (first 4 bytes=tunnel UV scale factor) | |
| 13 00000004 CD10 int 0x10 ; set mode 013h (320x200, 256 colors) - gotta happen sometime :) | |
| 14 00000006 6800A0 push word 0xa000 ; es = 0xa000 (framebuffer segment) - no double dealing here. | |
| 15 00000009 07 pop es | |
| 16 | |
| 17 0000000A F7E3 pix mul bx ; bx=0, so this sets ax=dx=0 | |
| 18 0000000C 40 inc ax ; and now ax=1 (so these two lines set ax=1, dx=0 in 3 bytes) | |
| 19 0000000D 01F8 add ax, di ; pixel index + 1, also sets up carry... | |
| 20 0000000F 111C adc [si], bx ; ...because on carry, we increment the frame counter at 0x100. | |
| 21 00000011 F7740C div word [si+12] ; inc ax / add ax, ... doubles as constant 320 | |
| 22 ; now ax = y, dx = x for the next pixel. | |
| 23 00000014 D80C clp fmul dword [si] ; apply (float) UV scale to *previous* coord | |
| 24 00000016 DE04 fiadd word [si] ; add (short) frame counter from same location | |
| 25 00000018 DF1F fistp word [bx] ; convert to int and store to temp mem | |
| 26 0000001A 2D8200 sub ax, 130 ; x -= 130 | |
| 27 0000001D 8707 xchg ax, [bx] ; now ax=integer U/V, [bx] = new x/y coordinate | |
| 28 0000001F 31C1 xor cx, ax ; xor UV coord into cx (this generates a XOR texture pattern) | |
| 29 00000021 DF07 fild word [bx] ; load new x/y coord into FPU | |
| 30 00000023 D8C8 fmul st0 ; square | |
| 31 00000025 31EB xor bx, bp ; flip temp offset (alternates on x/y) - after second loop, back to 0! | |
| 32 00000027 92 xchg ax, dx ; swap x and y (this doesn't modify flags!) | |
| 33 00000028 D9C9 fxch st1 ; swap U and V on fpu stack | |
| 34 0000002A 75E6 jnz clp ; loops twice (X/Y) due to the xor bx, bp! | |
| 35 | |
| 36 0000002C DEC1 faddp st1, st0 ; x^2 + y^2 | |
| 37 0000002E D9FA fsqrt ; r | |
| 38 00000030 D83C fdivr dword [si] ; magic scale constant one more time | |
| 39 | |
| 40 00000032 DF07 fild word [bx] ; x | |
| 41 00000034 DF4600 fild word [bp] ; y | |
| 42 00000037 D9F3 fpatan ; atan2(x,y) | |
| 43 | |
| 44 00000039 D6 salc ; set al to carry; carry=0 here, ax = y (so ah=0 since y<200), so this clears ax! | |
| 45 0000003A 91 xchg ax, cx ; texture accum to ax, cx=0 | |
| 46 0000003B 0C87 or al, 0x87 ; the magic value to make the best out of our crappy palette. | |
| 47 0000003D AA stosb ; store to es:[di], increment di | |
| 48 0000003E EBC8 jmp short pix ; and loop - that's all, folks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment