;**************************************************************************** ;*** Rotation stuff ;* ;* Brian Fisher ;* ;* modified March 5th, 1998 .286 Ideal Model Small Public getcos,getsin,rotatesprite,rotatereverse CodeSeg memoff dw 0 picseg dw 0 palseg dw 0 paloff dw 0 Planenum db 1 xplane db 1 evenflag db 1 color db 0 Xsize db 0 Ysize db 0 Xloc dw 0 Yloc dw 0 cos dw 0 sin dw 0 cos2 dw 0 sin2 dw 0 hxc dw 640 hyc dw 640 vxc dw 640 vyc dw 640 inits dw 640 initc dw 640 Trig dw 256,256,256,255,255,254,253,252,251,250,248,247,245,243,241,239,237,234,231,229,226,223,220,216,213,209,206,202,198,194,190,185,181,177,172,167,162,157,152,147,142,137,132,126,121,115,110,104,98,92,86,80,74,68,62,56,50,44,38,31,25,19,13,6,0 Proc SinVal ;give:bx=angle ret:ax=value cx,bx=destroyed mov cx,bx shr cx,6 mov ax,seg Trig mov ds,ax mov si,offset Trig and bx,63 test cx,1 jnz dirs neg bx add bx,64 dirs: shl bx,1 mov ax,[ds:si+bx] test cx,2 jnz notnegs neg ax notnegs: retn endp Sinval Proc GetSin ; anglenum push bp mov bp,sp push ds si mov bx,[ss:bp+06] call sinval pop si ds bp retf 2 endp GetSin Proc CosVal ; give:bx=angle ret:ax=value bx,cx=destroyed mov cx,bx shr cx,6 mov ax,seg Trig mov ds,ax mov si,offset Trig and bx,63 test cx,1 jz dirc neg bx add bx,64 dirc: shl bx,1 mov ax,[ds:si+bx] inc cx test cx,2 jz notnegc neg ax notnegc: retn endp cosval Proc GetCos ; anglenum push bp mov bp,sp push ds si mov bx,[ss:bp+06] call Cosval pop si ds bp retf 2 endp GetCos Proc rotatesprite ; Pic() Pal() poff Xloc Yloc Angle Page ; 18 16 14 12 10 8 6 push bp mov bp,sp push es ds si di cld mov al,1 mov [cs:evenflag],al mov bx,[ss:bp+16] mov di,[ds:bx+0ah] add di,[ss:bp+14] mov es,[ds:bx+02h] mov [cs:paloff],di mov [cs:palseg],es mov bx,[ss:bp+18] mov si,[ds:bx+0ah] mov ds,[ds:bx+02h] mov [cs:picseg],ds lodsw ;get the x and y dimensions of pic mov [cs:xsize],al mov [cs:ysize],ah push ds si mov bx,[ss:bp+08] call cosval ;get the cosine value (signed) mov [cs:cos],ax mov [cs:cos2],ax mov bx,[ss:bp+08] call sinval ;get the sine value (signed) mov [cs:sin],ax mov [cs:sin2],ax pop si ds call drawrotate pop di si ds es bp retf 14 endp rotatesprite Proc rotatereverse ; Pic() Pal() poff Xloc Yloc Angle Page ; 18 16 14 12 10 8 6 push bp mov bp,sp push es ds si di cld mov al,1 mov [cs:evenflag],al mov bx,[ss:bp+16] mov di,[ds:bx+0ah] add di,[ss:bp+14] mov es,[ds:bx+02h] mov [cs:paloff],di mov [cs:palseg],es mov bx,[ss:bp+18] mov si,[ds:bx+0ah] mov ds,[ds:bx+02h] mov [cs:picseg],ds lodsw ;get the x and y dimensions of pic mov [cs:xsize],al mov [cs:ysize],ah push ds si mov bx,[ss:bp+08] call cosval ;get the cosine value (signed) mov [cs:cos],ax neg ax mov [cs:cos2],ax mov bx,[ss:bp+08] call sinval ;get the sine value (signed) mov [cs:sin],ax neg ax mov [cs:sin2],ax pop si ds call drawrotate pop di si ds es bp retf 14 endp rotatereverse proc drawrotate mov cx,[ss:bp+12] ;x=center of rectangle xor ah,ah mov al,[cs:xsize] mov bx,[cs:cos2] shr ax,1 imul bx sar ax,8 sub cx,ax ;x=x-width*cos(theta) xor ah,ah mov al,[cs:ysize] shr ax,1 mov bx,[cs:sin] imul bx sar ax,8 add cx,ax ;x=x-height*sin(theta) mov [cs:xloc],cx ;x=upper left mov cx,[ss:bp+10] ;y=center xor ah,ah mov al,[cs:xsize] shr ax,1 mov bx,[cs:sin2] imul bx sar ax,8 sub cx,ax ;y=y-height*cos(theta) xor ah,ah mov al,[cs:ysize] shr ax,1 mov bx,[cs:cos] imul bx sar ax,8 sub cx,ax ;y=y-width*sin(theta) mov [cs:yloc],cx ;y=upper left mov ax,[cs:sin] shr ax,8 and ax,128 add ax,512 mov [cs:inits],ax mov [cs:hyc],ax mov [cs:vxc],ax mov ax,[cs:cos] shr ax,8 and ax,128 add ax,512 mov [cs:initc],ax mov [cs:hxc],ax mov [cs:vyc],ax ;initialize counters mov ax,[cs:yloc] ;figure out the starting vga offset mov bx,ax shl ax,6 shl bx,4 add ax,bx mov bx,[cs:xloc] shr bx,2 add bx,ax mov ax,[ss:bp+06] shl ax,14 add bx,ax mov [cs:memoff],bx mov cx,[cs:xloc] ;figure out the plane of the first pixel and cl,3 mov bx,1 shl bl,cl mov [cs:planenum],bl xor ch,ch mov ax,0a000h ;set up es mov es,ax xloop: mov di,[cs:memoff] ;reset di mov al,02h ;set the plane write enable mov dx,03c4h mov ah,[cs:planenum] mov [cs:xplane],ah out dx,ax xor dl,dl ;clear dl for the y-counter yloop: lodsb ;get the first pixel data cmp [cs:evenflag],1 ;get selected data using read flag jnz itszero shr al,4 sub si,1 itszero: xor [cs:evenflag],1 mov [cs:color],0 and ax,15 ;take 4-bits cmp ax,0 ;check for color 0 je nodraw mov ds,[cs:palseg] mov bx,[cs:paloff] add bx,ax mov al,[ds:bx] xor bh,bh mov [es:di],al mov [cs:color],al mov ds,[cs:picseg] nodraw: mov ax,[cs:vxc] add ax,[cs:sin] cmp ah,2 jz nohmove jb add2h call moveleft jmp didmove add2h: call moveright didmove: mov bl,[cs:color] cmp bl,0 jz nohmove mov [es:di],bl nohmove: mov ah,2 mov [cs:vxc],ax mov ax,[cs:vyc] add ax,[cs:cos] cmp ah,2 jz novmove ja add2v sub di,50h jmp novmove add2v: add di,50h novmove: mov ah,2 mov [cs:vyc],ax inc dl cmp dl,[cs:ysize] jnb noyloop jmp yloop noyloop: mov ax,[cs:inits] mov [cs:vxc],ax mov ax,[cs:initc] mov [cs:vyc],ax mov di,[cs:memoff] mov al,[cs:xplane] mov [cs:planenum],al mov ax,[cs:hxc] add ax,[cs:cos2] cmp ah,2 jz noxmove ja add2x call moveleft jmp noxmove add2x: call moveright noxmove: mov ah,2 mov [cs:hxc],ax mov ax,[cs:hyc] add ax,[cs:sin2] cmp ah,2 jz noymove ja add2y sub di,50h jmp noymove add2y: add di,50h noymove: mov ah,2 mov [cs:hyc],ax mov [cs:memoff],di inc ch cmp ch,[cs:xsize] jnb nope jmp xloop nope: retn endp drawrotate proc moveright push ax dx mov al,[cs:planenum] shl al,1 mov ah,al shr ah,4 add al,ah and al,15 mov [cs:planenum],al mov al,ah xor ah,ah add di,ax mov al,02h ;set the plane write enable mov dx,03c4h mov ah,[cs:planenum] out dx,ax pop dx ax retn endp moveright proc moveleft push ax dx mov al,[cs:planenum] mov ah,al shr ah,1 shl al,3 add al,ah and al,15 mov [cs:planenum],al xor ah,ah shr ax,3 sub di,ax mov al,02h ;set the plane write enable mov dx,03c4h mov ah,[cs:planenum] out dx,ax pop dx ax retn endp moveleft end