2012年7月5日星期四

sina.asm


;sina.asm
;正弦曲线的图像。
;虽然有很多人用很多办法实现了。
;但这是我自己亲自动手实现的。
;虽然有众多的不足与不满,但我可以改进。
;不足之处,敬请指导。
;QQ:112426112
;Email:leguanyuan at 126 dot com
;Homepage:http://correy.webs.com
;其实计算机计算的是不精确的,特别是fpu,还是用我们的笔算吧!
;画的图像更不用说了,能错一个像素,你能看到的。
;但它能为我们服务,快,能精确到一定的范围,听话,更好的机器还得自己设计。
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
includelib user32.lib
includelib kernel32.lib
include gdi32.inc
includelib gdi32.lib

.code
hInstance dd ?
hWinMain dd ?
stMsg MSG <>
szClassName db "correy",0
szCaptionMain db "made by correy",0
pwndclassex dd 48,3,offset liuchunli,0,0,0,0,0,6,0,offset szClassName,0

x DD ? 
y DD ?
n dw ?
n360 dw 360
client dd 768
harf_client dd 384
sina real4 0.0

liuchunli proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL hdc:HDC, ps:PAINTSTRUCT      
.IF uMsg==WM_PAINT  
  invoke BeginPaint,hWnd, ADDR ps
  mov hdc,eax 
  mov esi,0
  .WHILE si <= 768*2
    invoke SetPixel,hdc,esi,384,esi
    
    finit
    mov n,si
    fild n
    fimul client
    fidiv n360
    fist x;x=si*client/n360
    
    fldpi
    mov n,si
    fimul n
    fidiv n360
    fsin
    fst sina ;sina=sina(2*3.14159265*si/n360)
    
    fld sina
    fld1
    fsub st,st(1)
    fimul harf_client
    fist y;y=harf_client*(1-sina)
    
    invoke SetPixel,hdc,x,y,x
    inc si
  .ENDW 
invoke EndPaint,hWnd,ADDR ps
.ELSEIF uMsg==WM_DESTROY
  invoke PostQuitMessage,0
.ELSE
  invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
liuchunli endp

start:invoke GetModuleHandle,0
mov hInstance,eax
mov pwndclassex+20,eax
invoke LoadIcon,hInstance,1;其实这四行也可以去掉。
mov pwndclassex+24,eax
invoke LoadCursor,0,32512
mov pwndclassex+28,eax
invoke RegisterClassEx,addr pwndclassex
invoke CreateWindowEx,200h,offset szClassName,offset szCaptionMain,0ca0000h,80000000h,80000000h,768*2+99,399*2+20,0,0,hInstance,0;0cf0000h  0ca0000h
mov hWinMain,eax
invoke ShowWindow,hWinMain,1;不想显示这一两行也可以不要。
invoke UpdateWindow,hWinMain
again:invoke GetMessage,addr stMsg,0,0,0
  cmp eax,0
  je exit
  invoke TranslateMessage,addr stMsg;这一行也可以去掉,特别是不处理字符信息。
  invoke DispatchMessage,addr stMsg
jmp again
exit:invoke ExitProcess,0
end start
;made at 2010.04.20

没有评论:

发表评论