flat assembler
Message board for the users of flat assembler.
Index
> Tutorials and Examples > graphics examples |
Author |
|
hopcode 22 Jan 2013, 17:34
description and idea sounds very good "tutorial teaching some aspect of assembly programming".
edfed wrote: other categories are to be opened about other domains of assembly programming... may i post video tutorials how i charm girls using assembly programming ? _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
22 Jan 2013, 17:34 |
|
HaHaAnonymous 22 Jan 2013, 18:15
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:55; edited 1 time in total |
|||
22 Jan 2013, 18:15 |
|
edfed 22 Jan 2013, 21:40
i think there can also be a post named flat assembler > category > [STICKY]category examples
and each example topic in each subforum will contain as first post, an introduction of the topic, and the menu to access individual examples in the current topic, or other places. the rest of the posts will be about examples, with at least an explanation of how it works, how it is implemented, and maybe, why the choices of particular instructions instead of others. and here, in this category > Examples and tutorials, there will be topics about subjects like applied mathematics, physics, structures, and all other subjects that can be aborded. test:
|
||||||||||||||||||||||||||||
22 Jan 2013, 21:40 |
|
uart777 23 Jan 2013, 14:59
Hey, hopcode Downloaded your X64LAB. Very professional, good file organization, unique design. How about some macro tutorials? You're more experienced with the macros than I am.
Please give me a moment to cleanup my library (remove/separate unfinished code)... |
|||
23 Jan 2013, 14:59 |
|
uart777 23 Jan 2013, 16:11
An example for testing. New graphics code (DRAW.INC, VGA.INC) uses StretchBlt to copy VGA. Tested on 4 PCs. Supports any resolution. Requires WinX and 32BPP (default is 16BPP in some netbooks). Includes 35 library files. Anyone can use them to create examples. Please tell me if this works on your PC. *Fingers crossed*.
PS: Just noticed the white line on right and bottom sides that wasn't visible on my HDTV. Easy fix, just increment start box X/Y. No time now. Must leave for 2-3 days to paint murals in a big church. It's an opportunity to have positive effects on 10,000s of people.
|
|||||||||||
23 Jan 2013, 16:11 |
|
uart777 23 Jan 2013, 16:15
Draw fade/gradient functions (DRAW.INC):
Code: ; draw gradual fade from color a to b. ; o/rient: 'h'=horizontal, 'v'=vertical function draw.fade, o, x, y, w, h, c1, c2 locals i, n, r, g, b, r2, g2, b2,\ nr, ng, nb, first, last ; orientation... .if [o]='h' let eax=[x], [first]=eax, ecx=[w] .else let eax=[y], [first]=eax, ecx=[h] .end let [n]=ecx, eax+ecx, [last]=eax ; extract r/g/b components let eax=&[r], ecx=&[g], edx=&[b] get.rgb [c1], eax, ecx, edx let eax=&[r2], ecx=&[g2], edx=&[b2] get.rgb [c2], eax, ecx, edx ; scale by 256 (2^ for accuracy then ; calculate deltas: c2-c1/n let [r]<<8, [g]<<8, [b]<<8, ecx=[n],\ eax=[r2], eax<<8, eax-[r], eax/ecx, [nr]=eax,\ eax=[g2], eax<<8, eax-[g], eax/ecx, [ng]=eax,\ eax=[b2], eax<<8, eax-[b], eax/ecx, [nb]=eax ; draw lines... .loop [i]=[first] to [last] let eax=[r], eax>>8,\ ecx=[g], ecx>>8, edx=[b], edx>>8 rgb eax, ecx, edx .if [o]='h' draw.line.v [i], [y], [h], eax .else draw.line.h [x], [i], [w], eax .end let eax=[nr], [r]+eax,\ ecx=[ng], [g]+ecx,\ edx=[nb], [b]+edx .endl endf ; draw at box function draw.fade.b, o, b, c1, c2 let eax=[b] draw.fade [o],\ [?box.x+eax], [?box.y+eax],\ [?box.w+eax], [?box.h+eax], [c1], [c2] endf ; draw with center fade: a to b then b to a function draw.fade.c, o, box, a, b locals p copy.box g.box, [box] .if [o]='h' let [g.box.w]>>1, [p]=!move.box.r .else let [g.box.h]>>1, [p]=!move.box.d .end draw.fade.b [o], g.box, [a], [b] calla [p], g.box draw.fade.b [o], g.box, [b], [a] endf ; draw reflective fade function draw.chrome, o, box, a, b locals l, p copy.box g.box, [box] .if [o]='h' let [g.box.w]>>1, [p]=!move.box.r .else let [g.box.h]>>1, [p]=!move.box.d .end draw.fade.b [o], g.box, [a], [b] calla [p], g.box get [l]=lightness [b], 32 draw.fade.b [o], g.box, [a], [l] draw.box.o [box], [l] endf macro draw.black.chrome box { draw.chrome 'v', box, BLACK, 202020h } macro draw.blue.chrome box { draw.chrome 'v', box, ROYAL.BLUE, BEACH.BLUE } macro draw.red.chrome box { draw.chrome 'v', box, 0FF03020h, FIRE.RED } macro draw.violet.chrome box { draw.chrome 'v', box, DARK.VIOLET, VIOLET } macro draw.alien.chrome box { draw.chrome 'v', box, 3D5310h, 0E4F737h } |
|||
23 Jan 2013, 16:15 |
|
KevinN 23 Jan 2013, 20:42
|
|||
23 Jan 2013, 20:42 |
|
sleepsleep 23 Jan 2013, 23:17
uart777 wrote: An example for testing. New graphics code (DRAW.INC, VGA.INC) uses StretchBlt to copy VGA. Tested on 4 PCs. Supports any resolution. Requires WinX and 32BPP (default is 16BPP in some netbooks). Includes 35 library files. Anyone can use them to create examples. Please tell me if this works on your PC. *Fingers crossed*. this is very cool! uart777, in fact, people could use this as some sort of framework for game / application programming! thumbs up! |
|||
23 Jan 2013, 23:17 |
|
hopcode 24 Jan 2013, 07:41
hallo people,
i agree with sleepsleep. output is cool. at a first glance the code seems to me very difficoult to understand. the reason being i am definitively towards hardware and almost direct-opcoding. but i didnt knew it before starting assembly some years ago! i.e. i am discovering/discovered this of mine natural attitude! anyway, i will read the code again on weekend, because i smell something capturing in the file GRADIENTS.ASM, maybe that trasgressive structure i have not much time to answer now because i am very busy. i think end of this week i will post some brief considerations about it and general thoughts i am collecting on macro languages. if think this from uart is indeed a macro-language. but if only fasm had a minimal I/O user subsystem, the same macro capability of it would allow a pure-macro-script to run on the preprocedural stage with/without compiling nothing eventually, but exiting when the macro terminates or after user input. then improving it in speed etc, it would allow implementing/running something like COBOL. AFAIK, for itself doable in some way using its macro capabs. see you later this week, Cheers, _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
24 Jan 2013, 07:41 |
|
tthsqe 25 Jan 2013, 03:02
i posted this in the windows section a while back. it is a nice template for plotting an implicit equation f(x,y)=0. It ts currently set up for the ellipse x^2+a y^2-1=0; for a different equation, one only needs to change "SquaredDistanceEstimate".
Code: format PE GUI 5.0 entry Start include 'win32axp.inc' DIB_RGB_COLORS = 0 section '.code' code readable executable align 16 SquaredDistanceEstimate: ; plotting F(x,y)=0 ; given x at xmm0 and y at xmm1 (double precision), this should return F(x,y)^2/(gradF(x,y).gradF(x,y)) in xmm0 (single precision) ; for F(x,y) = x^2+a y^2-1, this is (x^2+a y^2-1)^2/((2x)^2+(2a y)^2) mulsd xmm0,xmm0 mulsd xmm1,xmm1 mulsd xmm1,[a] movsd xmm2,xmm1 mulsd xmm2,[a] addsd xmm1,xmm0 addsd xmm2,xmm0 subsd xmm1,[.const_1] mulsd xmm1,xmm1 mulsd xmm2,[.const_4] cvtsd2ss xmm0,xmm1 cvtsd2ss xmm1,xmm2 rcpss xmm1,xmm1 mulss xmm0,xmm1 ret align 8 .const_1: dq 1.0 .const_4: dq 4.0 align 16 ConvertToGrey: ; given # at xmm0, convert to color in eax ; min(255,1.5*255/(1+#)) mov eax,3*128 mov ecx,255 cvtsi2ss xmm1,eax rcpss xmm0,xmm0 mulss xmm1,xmm0 cvtss2si eax,xmm1 cmp eax,ecx cmova eax,ecx mov ecx,0x00010101 imul ecx ret ; these are the size of the plotted region and the width of the line align 8 scale dq 2.0 width dq 1.0 DrawBitmap: push ebp mov ebp,esp sub esp,8*8 virtual at ebp-8*8 xmin dq ? xmax dq ? xstep dq ? ymin dq ? ymax dq ? ystep dq ? fac dd ? end virtual ; a = 2 + sin(t/500) invoke GetTickCount mov dword[esp-4],eax fild dword[esp-4] mov dword[esp-4],500 fild dword[esp-4] fdivp st1,st0 fsin fld1 fadd st1,st0 faddp st1,st0 fstp qword[a] ; find the window fild [Bitmap.x] fild [Bitmap.y] fdivp st1,st0 fsqrt fld [scale] fld st0 fmul st0,st2 fst [xmax] fchs fstp [xmin] fdivrp st1,st0 fst [ymax] fchs fstp [ymin] ; find the pixel fac fild [Bitmap.x] fild [Bitmap.y] fmulp st1,st0 fld [xmax] fld [xmin] fsubp st1,st0 fld [ymax] fld [ymin] fsubp st1,st0 fmulp st1,st0 fld [width] fmulp st1,st0 fdivp st1,st0 fstp [fac] ; find xstep and ystep fld [xmax] fld [xmin] fsubp st1,st0 fild [Bitmap.x] fdivp st1,st0 fstp [xstep] fld [ymax] fld [ymin] fsubp st1,st0 fild [Bitmap.y] fdivp st1,st0 fstp [ystep] ; fill the bitmap mov ebx,[ppvBits] mov esi,[Bitmap.y] .l1: mov edi,[Bitmap.x] .l2: movsd xmm0,[xmax] movsd xmm1,[ymax] cvtsi2sd xmm2,edi cvtsi2sd xmm3,esi mulsd xmm2,[xstep] mulsd xmm3,[ystep] subsd xmm0,xmm2 ; x subsd xmm1,xmm3 ; y call SquaredDistanceEstimate mulss xmm0,[fac] call ConvertToGrey mov [ebx],eax add ebx,4 sub edi,1 jnz .l2 sub esi,1 jnz .l1 mov esp,ebp pop ebp ret ;;;;;;;;;;;;;;;;;;;; this is all standard stuff to open the window ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Start: invoke GetModuleHandle,0 mov [wc.hInstance],eax mov [hInstance],eax invoke LoadIcon,0,IDI_APPLICATION mov [wc.hIcon],eax invoke LoadCursor,0,IDC_ARROW mov [wc.hCursor],eax invoke RegisterClass,wc test eax,eax jz Error invoke CreateWindowEx,0,MainWindowClass,MainWindowTitle,WS_VISIBLE+WS_OVERLAPPEDWINDOW,100,100,600,600,NULL,NULL,[wc.hInstance],NULL mov [hMainWindow],eax test eax,eax jz Error .MsgLoop: invoke PeekMessage,msg,NULL,0,0,PM_REMOVE cmp [msg.message],WM_QUIT je .EndLoop invoke TranslateMessage,msg invoke DispatchMessage,msg add byte[PaintTimer],8 jnz .MsgLoop call Paint invoke Sleep,20 jmp .MsgLoop .EndLoop: invoke ExitProcess,[msg.wParam] Error: invoke MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK invoke ExitProcess,0 proc WindowProc hwnd,wmsg,wparam,lparam push esi edi ebx cmp [wmsg],WM_CREATE je .wmcreate cmp [wmsg],WM_PAINT je .wmpaint cmp [wmsg],WM_SIZE je .wmsize cmp [wmsg],WM_DESTROY je .wm_destroy .defwndproc: invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam] jmp .return .wmcreate: .wmsize: invoke GetClientRect,[hwnd],rect mov eax,[rect.right] test eax,eax jz .returnz mov eax,[rect.right] mov ecx,[rect.bottom] mov [Bitmap.x],eax mov [Bitmap.y],ecx mov ecx,[hBitmap] test ecx,ecx jz .wmpaint_newbm jmp .wmpaint_redobm .wmpaint: invoke GetClientRect,[hMainWindow],rect mov eax,[rect.right] mov ecx,[hBitmap] test eax,eax jz .returnz test ecx,ecx jz .wmpaint_newbm .wmpaint_ok: call Paint jmp .returnz .wmpaint_redobm: invoke DeleteObject,[hBitmap] .wmpaint_newbm: mov [bmiheader.biSize],sizeof.BITMAPINFOHEADER mov eax,[Bitmap.x] mov [bmiheader.biWidth],eax mov eax,[Bitmap.y] neg eax mov [bmiheader.biHeight],eax mov [bmiheader.biPlanes],1 mov [bmiheader.biBitCount],32 mov [bmiheader.biCompression],BI_RGB mov eax,[Bitmap.x] imul eax,[Bitmap.y] lea eax,[4*eax+16] mov [bmiheader.biSizeImage],eax mov [bmiheader.biXPelsPerMeter],0 mov [bmiheader.biYPelsPerMeter],0 mov [bmiheader.biClrUsed],0 mov [bmiheader.biClrImportant],0 invoke CreateDIBSection,0,bmiheader,DIB_RGB_COLORS,ppvBits,0,0 mov [hBitmap],eax jmp .wmpaint_ok .wm_destroy: invoke PostQuitMessage,0 .returnz: xor eax,eax .return: pop ebx edi esi ret endp Paint: cmp [hBitmap],0 je .Done invoke InvalidateRect,[hMainWindow],rect,FALSE invoke BeginPaint,[hMainWindow],ps mov [hdc],eax invoke CreateCompatibleDC,eax test eax,eax jz Error mov [hMemDC],eax call DrawBitmap invoke SelectObject,[hMemDC],[hBitmap] invoke BitBlt,[hdc],0,0,[rect.right],[rect.bottom],[hMemDC],0,0,SRCCOPY invoke DeleteDC,[hMemDC] invoke EndPaint,[hMainWindow],ps .Done: ret section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ gdi32,'GDI32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' include 'api\gdi32.inc' section '.data' data readable writeable align 4 wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,MainWindowClass align 1 MainWindowTitle db 'plot', 0 MainWindowClass db 'plot32', 0 _error TCHAR 'Startup failed.',0 align 8 a dq 2.0 align 4 hMainWindow dd ? hStatusWindow dd ? hMainMenu dd ? hInstance dd ? ppvBits dd ? hMemDC dd ? hdc dd ? hBitmap dd ? Bitmap.x dd ? Bitmap.y dd ? TickCount dd ? bmiheader BITMAPINFOHEADER ps PAINTSTRUCT rc RECT rect RECT msg MSG align 1 PaintTimer db ? |
|||
25 Jan 2013, 03:02 |
|
avcaballero 27 Jan 2013, 12:07
[ Post removed by author. ]
_________________ Siempre aprendiendo |
|||||||||||
27 Jan 2013, 12:07 |
|
uart777 28 Jan 2013, 17:15
tthsqe: Thanks. You could combine my gradient algorithm with it. Do you have time to write a draw.ellipse(x,y,w,h,color) that draws to linear VGA and performs clipping? We need portable graphics as in my DRAW.INC. I have one written in C that uses a sin(acos(x)) table of fixed-point numbers but it only accepts radius (same W/H). Not a true ellipse.
avcaballero: Nice! No source code? |
|||
28 Jan 2013, 17:15 |
|
edfed 29 Jan 2013, 14:46
yep, without source code, a demo is useless here and cannot be named an example at all.
even if i have an idea of what is used to do that... exact source code would be better. avcaballero??? |
|||
29 Jan 2013, 14:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.