12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733 |
- #include "dstd.h"
- #include "vfx.h"
- #include <stdio.h>
- extern char AlphaTable[256*256];
- typedef struct
- {
- DWORD bounds;
- DWORD origin;
- DWORD xmin;
- DWORD ymin;
- DWORD xmax;
- DWORD ymax;
- } SHAPEHEADER;
- //
- // Sprite format
- //
- //
- // Marker.
- // 0 End of line
- // 1 Skip next bytes
- // Bit 0 = 0 Repeat next byte [7654321] times
- // Bit 0 = 1 String packet [7654321] bytes
- //
- unsigned int lookaside;
- static unsigned int tempXmax,tempXmin;
- static unsigned int minX,minY,maxY,SkipLeft,NewWidth,StartofLine,StartofClip,EndofClip;
- static unsigned int lines,DestWidth,paneX0,paneX1,paneY0,paneY1;
- /*
- ;
- ; int cdecl VFX_shape_draw (PANE *panep, void *shape_table,
- ; long shape_number,int hotX, int hotY)
- ;
- ; This function clips and draws a shape to a pane.
- ;
- ; The panep parameter specifies the pane.
- ;
- ; The shape parameter specifies the shape, which must be in VFX Shape format.
- ;
- ; The hotX and hotY parameters specify the location where the shape is to be
- ; drawn. The shape's hot spot will end up at the specified location.
- ;
- */
- void AG_shape_draw (PANE *pane, void *shape_table,LONG shape_number, LONG hotX, LONG hotY)
- {
- _asm{
- mov esi,shape_table
- mov eax,shape_number
- mov ecx,[esi+eax*8+8]
- cmp word ptr [esi+ecx+SIZE SHAPEHEADER],3 ; (String packet, 0)
- jz AlphaDraw
- mov edi,pane
- nop
- ;
- ; Clip left and right of clipping window
- ;
- mov ecx,[edi+PANE.x0]
- mov edx,[edi+PANE.y0]
- mov ebx,ecx
- mov eax,edx
- sar ebx,31
- xor eax,-1
- sar eax,31 ; If less than 0, make 0
- xor ebx,-1
- and ecx,ebx
- and edx,eax
- mov paneX0,ecx
- mov paneY0,edx
- ;
- ; Clip top and bottom of clipping window
- ;
- mov ecx,[edi+PANE.x1]
- mov edx,[edi+PANE.y1]
- mov edi,[edi+PANE.window]
- mov esi,shape_table
- mov eax,[edi+WINDOW.x_max]
- xor ebx,ebx
- inc eax
- nop
- sub ecx,eax
- mov DestWidth,eax
- setge bl
- dec ebx ; if ecx is less than eax, load ecx with eax
- nop
- and ecx,ebx
- mov ebx,[edi+WINDOW.y_max]
- add ecx,eax
- inc ebx
- xor eax,eax
- sub edx,ebx
- setge al
- dec eax
- mov paneX1,ecx
-
- and edx,eax
- mov eax,shape_number
- add edx,ebx
- mov ebx,paneY0
- ;
- ; paneX0,Y0 to PaneX1,Y1 are 0,0 -> 639,479 or window size to render too
- ;
- mov ecx,[esi+eax*8+8] ; ESI now points to start of sprite data
- mov paneY1,edx
- lea esi,[esi+ecx+SIZE SHAPEHEADER]
- mov edx,hotY
- mov ecx,[esi+SHAPEHEADER.xmax-SIZE SHAPEHEADER]
- mov eax,[esi+SHAPEHEADER.xmin-SIZE SHAPEHEADER]
- mov tempXmax,ecx ; Store Xmax and Xmin
- mov tempXmin,eax
- mov ecx,[esi+SHAPEHEADER.ymax-SIZE SHAPEHEADER]
- mov eax,[esi+SHAPEHEADER.ymin-SIZE SHAPEHEADER]
- sub ecx,eax ; ecx = Height of sprite
- add eax,edx ; eax = top line
- inc ecx ; Add one line
- nop
- ;
- ; Now check for lines off the top of the clipping window
- ;
- cmp eax,ebx
- jl ClippedTop
- ;
- ; Now check for lines off the bottom of the clipping window
- ;
- rw5:
- lea ebx,[eax+ecx-1] ; ebx=Last Line
- nop
- sub ebx,paneY1 ; Check to see if off bottom
- ja ClippedBottom
- rw6:
- mov lines,ecx ; eax still equals top line
- ;
- ; Now check clipping in X
- ;
- mov ebx,tempXmax
- mov ecx,tempXmin
- mov edx,paneX0
- sub ebx,ecx ; ebx = Width of sprite
- add ecx,hotX ; ecx = offset to left edge
- cmp ecx,edx ; Is sprite off left edge of screen?
- jl ClippedLeft
- lea edx,[ebx+ecx]
- mov edi,[edi+WINDOW.buffer] ; edi points to top left of buffer
- sub edx,paneX1
- jnbe ClippedRight
- ;
- ; Work out screen position
- ;
- //NowDraw:
- imul DestWidth
- add eax,ecx
- xor ecx,ecx
- add edi,eax
- mov StartofLine,edi
- ;
- ;
- ; Main drawing loop
- ;
- ;
- lineLoop:
- mov al,[esi]
- inc esi
- shr al,1
- ja RunPacket
- jnz StringPacket
- jnc EndPacket
- //SkipPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- add edi,ecx
- jmp lineLoop
- RunPacket:
- mov cl,[esi]
- inc esi
- rp1:
- mov [edi],cl
- inc edi
- dec al
- jnz rp1
- jmp lineLoop
- StringPacket:
- //
- // 17 cycles / 8 bytes - 2.125 per byte
- //
- sub al,8
- jc sp2
- sp1:
- mov ecx,[esi]
- mov ebx,[esi+4]
- mov [edi],ecx
- mov [edi+4],ebx
- add esi,8
- add edi,8
- sub al,8
- jnc sp1
- sp2:
- add al,8
- jz lineLoop
- sp3:
- mov cl,[esi]
- inc esi
- mov [edi],cl
- inc edi
- dec al
- jnz sp3
- jmp lineLoop
- EndPacket:
- mov edx,DestWidth
- mov edi,StartofLine
- add edi,edx
- mov edx,lines
- dec edx
- mov StartofLine,edi
- mov lines,edx
- jnz lineLoop
- jmp Exit
- ;
- ;
- ; Lines are clipped off the bottom of the clip window
- ;
- ;
- ClippedBottom:
- sub ecx,ebx ; Remove lines that go off bottom
- jbe Exit
- jmp rw6
- ;
- ;
- ; Lines are off the top of the clip window
- ;
- ;
- ClippedTop:
- sub ebx,eax ; ebx=Lines to skip
- xor eax,eax
- sub ecx,ebx ; ecx=Lines in sprite
- jbe Exit ; Off top of screen
- rw8:
- mov al,[esi]
- add esi,2
- shr al,1
- ja rw8
- jnz rw8StringPacket ; Skip over lines in sprite data
- jc rw8
- dec esi
- dec ebx
- jnz rw8
- mov eax,paneY0 ; eax=top line
- jmp rw5
- rw8StringPacket:
- lea esi,[esi+eax-1]
- jmp rw8
- ;
- ;
- ; Sprite is clipped on either left or right
- ;
- ;
- ClippedLeft:
- sub edx,ecx
- mov edi,[edi+WINDOW.buffer] ; edi points to top left of buffer
- cmp ebx,edx
- jbe Exit ; Completly off left of screen?
- jmp ClippedX
- ClippedRight:
- cmp ecx,edx ; Completly off right of screen?
- jbe Exit
- ClippedX:
- imul DestWidth
- add edi,eax
- mov eax,paneX0
- mov edx,paneX1
- add eax,edi
- add edx,edi ; eax=Last pixel on right edge of clip window
- mov ebx,eax
- add edi,ecx
- xor ecx,ecx
- mov StartofLine,edi
- ;
- ; Clipped left and/or right drawing loop
- ;
- clineLoop:
- mov al,[esi]
- inc esi
- shr al,1
- ja cRunPacket
- jnz cStringPacket
- jnc cEndPacket
- //cSkipPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- add edi,ecx
- jmp clineLoop
- cRunPacket:
- mov cl,[esi]
- inc esi
- crp1:
- cmp edi,ebx
- jc crp2
- cmp edi,edx
- jnbe clineLoop
- mov [edi],cl
- crp2:
- inc edi
- dec al
- jnz crp1
- jmp clineLoop
- cStringPacket:
- mov cl,[esi]
- inc esi
- cmp edi,ebx
- jc crp3
- cmp edi,edx
- jnbe crp3a
- mov [edi],cl
- crp3:
- inc edi
- dec al
- jnz cStringPacket
- jmp clineLoop
- crp3a:
- and eax,255
- lea esi,[esi+eax-1]
- jmp clineLoop
- cEndPacket:
- mov eax,DestWidth
- mov edi,StartofLine
- add edx,eax
- add edi,eax
- add ebx,eax
- mov eax,lines
- mov StartofLine,edi
- dec eax
- mov lines,eax
- jnz clineLoop
- jmp Exit
- //
- //
- // Same routine as above, but using Alpha table
- //
- //
- AlphaDraw:
- mov edi,pane
- nop
- ;
- ; Clip left and right of clipping window
- ;
- mov ecx,[edi+PANE.x0]
- mov edx,[edi+PANE.y0]
- mov ebx,ecx
- mov eax,edx
- sar ebx,31
- xor eax,-1
- sar eax,31 ; If less than 0, make 0
- xor ebx,-1
- and ecx,ebx
- and edx,eax
- mov paneX0,ecx
- mov paneY0,edx
- ;
- ; Clip top and bottom of clipping window
- ;
- mov ecx,[edi+PANE.x1]
- mov edx,[edi+PANE.y1]
- mov edi,[edi+PANE.window]
- mov esi,shape_table
- mov eax,[edi+WINDOW.x_max]
- xor ebx,ebx
- inc eax
- nop
- sub ecx,eax
- mov DestWidth,eax
- setge bl
- dec ebx ; if ecx is less than eax, load ecx with eax
- nop
- and ecx,ebx
- mov ebx,[edi+WINDOW.y_max]
- add ecx,eax
- inc ebx
- xor eax,eax
- sub edx,ebx
- setge al
- dec eax
- mov paneX1,ecx
-
- and edx,eax
- mov eax,shape_number
- add edx,ebx
- mov ebx,paneY0
- ;
- ; paneX0,Y0 to PaneX1,Y1 are 0,0 -> 639,479 or window size to render too
- ;
- mov ecx,[esi+eax*8+8] ; ESI now points to start of sprite data
- mov paneY1,edx
- lea esi,[esi+ecx+SIZE SHAPEHEADER]
- mov edx,hotY
- mov ecx,[esi+SHAPEHEADER.xmax-SIZE SHAPEHEADER]
- mov eax,[esi+SHAPEHEADER.xmin-SIZE SHAPEHEADER]
- mov tempXmax,ecx ; Store Xmax and Xmin
- mov tempXmin,eax
- mov ecx,[esi+SHAPEHEADER.ymax-SIZE SHAPEHEADER]
- mov eax,[esi+SHAPEHEADER.ymin-SIZE SHAPEHEADER]
- sub ecx,eax ; ecx = Height of sprite
- add eax,edx ; eax = top line
- inc ecx ; Add one line
- nop
- ;
- ; Now check for lines off the top of the clipping window
- ;
- cmp eax,ebx
- jl aClippedTop
- ;
- ; Now check for lines off the bottom of the clipping window
- ;
- arw5:
- lea ebx,[eax+ecx] ; ebx=Last Line
- nop
- sub ebx,paneY1 ; Check to see if off bottom
- ja aClippedBottom
- arw6:
- mov lines,ecx ; eax still equals top line
- ;
- ; Now check clipping in X
- ;
- mov ebx,tempXmax
- mov ecx,tempXmin
- mov edx,paneX0
- sub ebx,ecx ; ebx = Width of sprite
- add ecx,hotX ; ecx = offset to left edge
- inc ecx
- nop
-
- cmp ecx,edx ; Is sprite off left edge of screen?
- jl aClippedLeft
- lea edx,[ebx+ecx]
- mov edi,[edi+WINDOW.buffer] ; edi points to top left of buffer
- sub edx,paneX1
- ja aClippedRight
- ;
- ; Work out screen position
- ;
- //aNowDraw:
- imul DestWidth
- add eax,ecx
- xor ecx,ecx
- add edi,eax
- mov StartofLine,edi
- ;
- ;
- ; Main drawing loop
- ;
- ;
- alineLoop:
- mov al,[esi]
- inc esi
- shr al,1
- ja aRunPacket
- jnz aStringPacket
- jnc aEndPacket
- //aSkipPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- add edi,ecx
- jmp alineLoop
- aRunPacket:
- mov ch,[esi]
- inc esi
- arp1:
- mov cl,[edi]
- inc edi
- mov cl,AlphaTable[ecx]
- dec al
- mov [edi-1],cl
- jnz arp1
- jmp alineLoop
- aStringPacket:
- mov ch,[esi]
- inc esi
- mov cl,[edi]
- inc edi
- mov cl,AlphaTable[ecx]
- dec al
- mov [edi-1],cl
- jnz aStringPacket
- jmp alineLoop
- aEndPacket:
- mov edx,DestWidth
- mov edi,StartofLine
- add edi,edx
- mov edx,lines
- dec edx
- mov StartofLine,edi
- mov lines,edx
- jnz alineLoop
- jmp Exit
- ;
- ;
- ; Lines are clipped off the bottom of the clip window
- ;
- ;
- aClippedBottom:
- sub ecx,ebx ; Remove lines that go off bottom
- jbe Exit
- jmp arw6
- ;
- ;
- ; Lines are off the top of the clip window
- ;
- ;
- aClippedTop:
- sub ebx,eax ; ebx=Lines to skip
- xor eax,eax
- sub ecx,ebx ; ecx=Lines in sprite
- jbe Exit ; Off top of screen
- arw8:
- mov al,[esi]
- add esi,2
- shr al,1
- ja arw8
- jnz arw8StringPacket ; Skip over lines in sprite data
- jc arw8
- dec esi
- dec ebx
- jnz arw8
- mov eax,paneY0 ; eax=top line
- jmp arw5
- arw8StringPacket:
- lea esi,[esi+eax-1]
- jmp arw8
- ;
- ;
- ; Sprite is clipped on either left or right
- ;
- ;
- aClippedLeft:
- sub edx,ecx
- mov edi,[edi+WINDOW.buffer] ; edi points to top left of buffer
- cmp ebx,edx
- jbe Exit ; Completly off left of screen?
- jmp aClippedX
- aClippedRight:
- cmp ecx,edx ; Completly off right of screen?
- jbe Exit
- aClippedX:
- imul DestWidth
- add edi,eax
- mov eax,paneX0
- mov edx,paneX1
- add eax,edi
- add edx,edi ; eax=Last pixel on right edge of clip window
- mov ebx,eax
- add edi,ecx
- mov StartofLine,edi
- xor ecx,ecx
- ;
- ; Clipped left and/or right drawing loop
- ;
- aclineLoop:
- mov al,[esi]
- inc esi
- shr al,1
- ja acRunPacket
- jnz acStringPacket
- jnc acEndPacket
- //acSkipPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- add edi,ecx
- jmp aclineLoop
- acRunPacket:
- mov ch,[esi]
- inc esi
- acrp1:
- cmp edi,ebx
- jc acrp2
- cmp edi,edx
- jnbe aclineLoop
- mov cl,[edi]
- mov cl,AlphaTable[ecx]
- mov [edi],cl
- acrp2:
- inc edi
- dec al
- jnz acrp1
- jmp aclineLoop
- acStringPacket:
- mov ch,[esi]
- inc esi
- cmp edi,ebx
- jc acrp3
- cmp edi,edx
- jnbe acrp3a
- mov cl,[edi]
- mov cl,AlphaTable[ecx]
- mov [edi],cl
- acrp3:
- inc edi
- dec al
- jnz acStringPacket
- jmp aclineLoop
- acrp3a:
- and eax,255
- lea esi,[esi+eax-1]
- jmp aclineLoop
- acEndPacket:
- mov eax,DestWidth
- mov edi,StartofLine
- add edx,eax
- add edi,eax
- add ebx,eax
- mov eax,lines
- mov StartofLine,edi
- dec eax
- mov lines,eax
- jnz aclineLoop
- Exit:
- }
- }
- /*
- ;----------------------------------------------------------------------------
- ;
- ; void cdecl VFX_shape_lookaside (unsigned char *table)
- ;
- ; Establishes a color translation lookaside table for use by future calls
- ; to VFX_shape_translate_draw().
- ;
- ; table points to a 256-byte table specifying remap values for each of
- ; the 256 possible palette indices. The table is copied to static local
- ; memory, and need not remain valid after the call.
- ;
- ;----------------------------------------------------------------------------
- */
- void AG_shape_lookaside( UBYTE *table )
- {
- _asm{
- mov eax,table
- mov lookaside,eax
- }
- }
- /*
- ;----------------------------------------------------------------------------
- ;
- ; int cdecl VFX_shape_translate_draw (PANE *panep, void *shape_table,
- ; long shape_number,int hotX, int hotY)
- ;
- ; This function clips and draws a shape to a pane. It is identical to
- ; VFX_shape_draw(), except that each pixel written is translated through a
- ; 256-byte table which was specified by a prior call to VFX_shape_lookaside().
- ;
- ; The panep parameter specifies the pane.
- ;
- ; The shape parameter specifies the shape, which must be in VFX Shape format.
- ;
- ; The hotX and hotY parameters specify the location where the shape is to be
- ; drawn. The shape's hot spot will end up at the specified location.
- ;
- ; For more information, see the "VFX Shape Format Description".
- ;
- ; Return values:
- ;
- ; 0: OK
- ; -1: Bad window
- ; -2: Bad pane
- ; -3: Shape off pane
- ; -4: Null shape
- ;
- ;----------------------------------------------------------------------------
- */
- void AG_shape_translate_draw (PANE *pane, void *shape_table,LONG shape_number, LONG hotX, LONG hotY)
- {
- _asm{
- mov esi,shape_table
- mov eax,shape_number
- mov ecx,[esi+eax*8+8]
- cmp word ptr [esi+ecx+SIZE SHAPEHEADER],3 ; (String packet, 0)
- jz AlphaDraw
- mov edi,pane
- nop
- ;
- ; Clip left and right of clipping window
- ;
- mov ecx,[edi+PANE.x0]
- mov edx,[edi+PANE.y0]
- mov ebx,ecx
- mov eax,edx
- sar ebx,31
- xor eax,-1
- sar eax,31 ; If less than 0, make 0
- xor ebx,-1
- and ecx,ebx
- and edx,eax
- mov paneX0,ecx
- mov paneY0,edx
- ;
- ; Clip top and bottom of clipping window
- ;
- mov ecx,[edi+PANE.x1]
- mov edx,[edi+PANE.y1]
- mov edi,[edi+PANE.window]
- mov esi,shape_table
- mov eax,[edi+WINDOW.x_max]
- xor ebx,ebx
- inc eax
- nop
- sub ecx,eax
- mov DestWidth,eax
- setge bl
- dec ebx ; if ecx is less than eax, load ecx with eax
- nop
- and ecx,ebx
- mov ebx,[edi+WINDOW.y_max]
- add ecx,eax
- inc ebx
- xor eax,eax
- sub edx,ebx
- setge al
- dec eax
- mov paneX1,ecx
-
- and edx,eax
- mov eax,shape_number
- add edx,ebx
- mov ebx,paneY0
- ;
- ; paneX0,Y0 to PaneX1,Y1 are 0,0 -> 639,479 or window size to render too
- ;
- mov ecx,[esi+eax*8+8] ; ESI now points to start of sprite data
- mov paneY1,edx
- lea esi,[esi+ecx+SIZE SHAPEHEADER]
- mov edx,hotY
- mov ecx,[esi+SHAPEHEADER.xmax-SIZE SHAPEHEADER]
- mov eax,[esi+SHAPEHEADER.xmin-SIZE SHAPEHEADER]
- mov tempXmax,ecx ; Store Xmax and Xmin
- mov tempXmin,eax
- mov ecx,[esi+SHAPEHEADER.ymax-SIZE SHAPEHEADER]
- mov eax,[esi+SHAPEHEADER.ymin-SIZE SHAPEHEADER]
- sub ecx,eax ; ecx = Height of sprite
- add eax,edx ; eax = top line
- inc ecx ; Add one line
- nop
- ;
- ; Now check for lines off the top of the clipping window
- ;
- cmp eax,ebx
- jl ClippedTop
- ;
- ; Now check for lines off the bottom of the clipping window
- ;
- rw5:
- lea ebx,[eax+ecx-1] ; ebx=Last Line
- nop
- sub ebx,paneY1 ; Check to see if off bottom
- ja ClippedBottom
- rw6:
- mov lines,ecx ; eax still equals top line
- ;
- ; Now check clipping in X
- ;
- mov ebx,tempXmax
- mov ecx,tempXmin
- mov edx,paneX0
- sub ebx,ecx ; ebx = Width of sprite
- add ecx,hotX ; ecx = offset to left edge
- cmp ecx,edx ; Is sprite off left edge of screen?
- jl ClippedLeft
- lea edx,[ebx+ecx-1]
- mov edi,[edi+WINDOW.buffer] ; edi points to top left of buffer
- sub edx,paneX1
- jnb ClippedRight
- ;
- ; Work out screen position
- ;
- //NowDraw:
- imul DestWidth
- add eax,ecx
- xor ecx,ecx
- add edi,eax
- mov StartofLine,edi
- push ebp
- mov ebp,lookaside
- xor ebx,ebx
- nop
- ;
- ; Main drawing loop
- ;
- ;
- lineLoop:
- mov al,[esi]
- inc esi
- shr al,1
- ja RunPacket
- jnz StringPacket
- jnc EndPacket
- //SkipPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- add edi,ecx
- jmp lineLoop
- RunPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- mov cl,[ecx+ebp]
- rp1:
- mov [edi],cl
- inc edi
- dec al
- jnz rp1
- jmp lineLoop
- StringPacket:
- //
- // 17 cycles / 8 bytes - 2.125 per byte
- //
- sub al,8
- jc sp2
- sp1:
- mov cl,[esi]
- mov bl,[esi+4]
- mov cl,[ecx+ebp]
- mov bl,[ebx+ebp]
- mov [edi],cl
- mov [edi+4],bl
- mov cl,[esi+1]
- mov bl,[esi+5]
- mov cl,[ecx+ebp]
- mov bl,[ebx+ebp]
- mov [edi+1],cl
- mov [edi+5],bl
- mov cl,[esi+2]
- mov bl,[esi+6]
- mov cl,[ecx+ebp]
- mov bl,[ebx+ebp]
- mov [edi+2],cl
- mov [edi+6],bl
- mov cl,[esi+3]
- mov bl,[esi+7]
- add esi,8
- add edi,8
- mov cl,[ecx+ebp]
- mov bl,[ebx+ebp]
- mov [edi+3-8],cl
- mov [edi+7-8],bl
- sub al,8
- jnc sp1
- sp2:
- add al,8
- jz lineLoop
- sp3:
- xor ecx,ecx
- mov cl,[esi]
- mov cl,[ecx+ebp]
- inc esi
- mov [edi],cl
- inc edi
- dec al
- jnz sp3
- jmp lineLoop
- EndPacket:
- mov edx,DestWidth
- mov edi,StartofLine
- add edi,edx
- mov edx,lines
- dec edx
- mov StartofLine,edi
- mov lines,edx
- jnz lineLoop
- pop ebp
- jmp Exit
- ;
- ;
- ; Lines are clipped off the bottom of the clip window
- ;
- ;
- ClippedBottom:
- sub ecx,ebx ; Remove lines that go off bottom
- jbe Exit
- jmp rw6
- ;
- ;
- ; Lines are off the top of the clip window
- ;
- ;
- ClippedTop:
- sub ebx,eax ; ebx=Lines to skip
- xor eax,eax
- sub ecx,ebx ; ecx=Lines in sprite
- jbe Exit ; Off top of screen
- rw8:
- mov al,[esi]
- add esi,2
- shr al,1
- ja rw8
- jnz rw8StringPacket ; Skip over lines in sprite data
- jc rw8
- dec esi
- dec ebx
- jnz rw8
- mov eax,paneY0 ; eax=top line
- jmp rw5
- rw8StringPacket:
- lea esi,[esi+eax-1]
- jmp rw8
- ;
- ;
- ; Sprite is clipped on either left or right
- ;
- ;
- ClippedLeft:
- sub edx,ecx
- mov edi,[edi+WINDOW.buffer] ; edi points to top left of buffer
- cmp ebx,edx
- jbe Exit ; Completly off left of screen?
- jmp ClippedX
- ClippedRight:
- cmp ecx,edx ; Completly off right of screen?
- jbe Exit
- ClippedX:
- imul DestWidth
- add edi,eax
- mov eax,paneX0
- mov edx,paneX1
- add eax,edi
- add edx,edi ; eax=Last pixel on right edge of clip window
- mov StartofClip,eax
- mov EndofClip,edx
- add edi,ecx
- xor ecx,ecx
- mov StartofLine,edi
- push ebp
- mov ebp,lookaside
- ;
- ; Clipped left and/or right drawing loop
- ;
- clineLoop:
- mov al,[esi]
- inc esi
- shr al,1
- ja cRunPacket
- jnz cStringPacket
- jnc cEndPacket
- //cSkipPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- add edi,ecx
- //DEBUG
- push edi
- shr edi,28
- cmp edi,8
- pop edi
- je clineLoop
- //END DEBUG
- jmp assertError //clineLoop
- cRunPacket:
- mov cl,[esi]
- inc esi
- crp1:
- cmp edi,StartofClip
- jc crp2
- cmp edi,EndofClip
- jnbe clineLoop
- mov cl,[ecx+ebp]
- mov [edi],cl
- crp2:
- inc edi
- dec al
- jnz crp1
- jmp clineLoop
- cStringPacket:
- mov cl,[esi]
- inc esi
- cmp edi,StartofClip
- jc crp3
- cmp edi,EndofClip
- jnbe crp3a
- mov cl,[ecx+ebp]
- mov [edi],cl
- crp3:
- inc edi
- dec al
- jnz cStringPacket
- jmp clineLoop
- crp3a:
- and eax,255
- lea esi,[esi+eax-1]
- jmp clineLoop
- cEndPacket:
- mov edx,DestWidth
- mov eax,EndofClip
- add eax,edx
- mov edi,StartofLine
- mov EndofClip,eax
- nop
- mov eax,StartofClip
- add edi,edx
- add eax,edx
- mov edx,lines
- mov StartofLine,edi
- dec edx
- mov StartofClip,eax
- mov lines,edx
- jnz clineLoop
- pop ebp
- jmp Exit
- //
- //
- // Same routine as above, but with Alpha Table effects
- //
- //
- AlphaDraw:
- mov edi,pane
- nop
- ;
- ; Clip left and right of clipping window
- ;
- mov ecx,[edi+PANE.x0]
- mov edx,[edi+PANE.y0]
- mov ebx,ecx
- mov eax,edx
- sar ebx,31
- xor eax,-1
- sar eax,31 ; If less than 0, make 0
- xor ebx,-1
- and ecx,ebx
- and edx,eax
- mov paneX0,ecx
- mov paneY0,edx
- ;
- ; Clip top and bottom of clipping window
- ;
- mov ecx,[edi+PANE.x1]
- mov edx,[edi+PANE.y1]
- mov edi,[edi+PANE.window]
- mov esi,shape_table
- mov eax,[edi+WINDOW.x_max]
- xor ebx,ebx
- inc eax
- nop
- sub ecx,eax
- mov DestWidth,eax
- setge bl
- dec ebx ; if ecx is less than eax, load ecx with eax
- nop
- and ecx,ebx
- mov ebx,[edi+WINDOW.y_max]
- add ecx,eax
- inc ebx
- xor eax,eax
- sub edx,ebx
- setge al
- dec eax
- mov paneX1,ecx
-
- and edx,eax
- mov eax,shape_number
- add edx,ebx
- mov ebx,paneY0
- ;
- ; paneX0,Y0 to PaneX1,Y1 are 0,0 -> 639,479 or window size to render too
- ;
- mov ecx,[esi+eax*8+8] ; ESI now points to start of sprite data
- mov paneY1,edx
- lea esi,[esi+ecx+SIZE SHAPEHEADER]
- mov edx,hotY
- mov ecx,[esi+SHAPEHEADER.xmax-SIZE SHAPEHEADER]
- mov eax,[esi+SHAPEHEADER.xmin-SIZE SHAPEHEADER]
- mov tempXmax,ecx ; Store Xmax and Xmin
- mov tempXmin,eax
- mov ecx,[esi+SHAPEHEADER.ymax-SIZE SHAPEHEADER]
- mov eax,[esi+SHAPEHEADER.ymin-SIZE SHAPEHEADER]
- sub ecx,eax ; ecx = Height of sprite
- add eax,edx ; eax = top line
- inc ecx ; Add one line
- nop
- ;
- ; Now check for lines off the top of the clipping window
- ;
- cmp eax,ebx
- jl aClippedTop
- ;
- ; Now check for lines off the bottom of the clipping window
- ;
- arw5:
- lea ebx,[eax+ecx-1] ; ebx=Last Line
- nop
- sub ebx,paneY1 ; Check to see if off bottom
- ja aClippedBottom
- //arw6:
- mov lines,ecx ; eax still equals top line
- ;
- ; Now check clipping in X
- ;
- mov ebx,tempXmax
- mov ecx,tempXmin
- mov edx,paneX0
- sub ebx,ecx ; ebx = Width of sprite
- add ecx,hotX ; ecx = offset to left edge
- cmp ecx,edx ; Is sprite off left edge of screen?
- jl aClippedLeft
- lea edx,[ebx+ecx-1]
- mov edi,[edi+WINDOW.buffer] ; edi points to top left of buffer
- sub edx,paneX1
- jnbe aClippedRight
- ;
- ; Work out screen position
- ;
- //aNowDraw:
- imul DestWidth
- add eax,ecx
- xor ecx,ecx
- add edi,eax
- mov StartofLine,edi
- push ebp
- mov ebp,lookaside
- xor ebx,ebx
- nop
- ;
- ; Main drawing loop
- ;
- ;
- alineLoop:
- mov al,[esi]
- inc esi
- shr al,1
- ja aRunPacket
- jnz aStringPacket
- jnc aEndPacket
- //aSkipPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- add edi,ecx
- jmp alineLoop
- aRunPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- mov ch,[ecx+ebp]
- arp1:
- mov cl,[edi]
- inc edi
- mov cl,AlphaTable[ecx]
- dec al
- mov [edi-1],cl
- jnz arp1
- jmp alineLoop
- aStringPacket:
- xor ecx,ecx
- mov cl,[esi]
- mov ch,[ecx+ebp]
- inc esi
- mov cl,[edi]
- inc edi
- mov cl,AlphaTable[ecx]
- dec al
- mov [edi-1],cl
- jnz aStringPacket
- jmp alineLoop
- aEndPacket:
- mov edx,DestWidth
- mov edi,StartofLine
- add edi,edx
- mov edx,lines
- dec edx
- mov StartofLine,edi
- mov lines,edx
- jnz alineLoop
- pop ebp
- jmp Exit
- ;
- ;
- ; Lines are clipped off the bottom of the clip window
- ;
- ;
- aClippedBottom:
- sub ecx,ebx ; Remove lines that go off bottom
- jbe Exit
- jmp rw6
- ;
- ;
- ; Lines are off the top of the clip window
- ;
- ;
- aClippedTop:
- sub ebx,eax ; ebx=Lines to skip
- xor eax,eax
- sub ecx,ebx ; ecx=Lines in sprite
- jbe Exit ; Off top of screen
- arw8:
- mov al,[esi]
- add esi,2
- shr al,1
- ja arw8
- jnz arw8StringPacket ; Skip over lines in sprite data
- jc arw8
- dec esi
- dec ebx
- jnz arw8
- mov eax,paneY0 ; eax=top line
- jmp arw5
- arw8StringPacket:
- lea esi,[esi+eax-1]
- jmp arw8
- ;
- ;
- ; Sprite is clipped on either left or right
- ;
- ;
- aClippedLeft:
- sub edx,ecx
- mov edi,[edi+WINDOW.buffer] ; edi points to top left of buffer
- cmp ebx,edx
- jbe Exit ; Completly off left of screen?
- jmp aClippedX
- aClippedRight:
- cmp ecx,edx ; Completly off right of screen?
- jbe Exit
- aClippedX:
- imul DestWidth
- add edi,eax
- mov eax,paneX0
- mov edx,paneX1
- add eax,edi
- add edx,edi ; eax=Last pixel on right edge of clip window
- mov StartofClip,eax
- mov EndofClip,edx
- add edi,ecx
- xor ecx,ecx
- mov StartofLine,edi
- push ebp
- mov ebp,lookaside
- ;
- ; Clipped left and/or right drawing loop
- ;
- aclineLoop:
- mov al,[esi]
- inc esi
- shr al,1
- ja acRunPacket
- jnz acStringPacket
- jnc acEndPacket
- //acSkipPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- add edi,ecx
- jmp aclineLoop
- acRunPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- mov ch,[ecx+ebp]
- acrp1:
- cmp edi,StartofClip
- jc acrp2
- cmp edi,EndofClip
- jnbe aclineLoop
- mov cl,[edi]
- mov cl,AlphaTable[ecx]
- mov [edi],cl
- acrp2:
- inc edi
- dec al
- jnz acrp1
- jmp aclineLoop
- acStringPacket:
- xor ecx,ecx
- mov cl,[esi]
- inc esi
- cmp edi,StartofClip
- jc acrp3
- cmp edi,EndofClip
- jnbe acrp3a
- mov ch,[ecx+ebp]
- mov cl,[edi]
- mov cl,AlphaTable[ecx]
- mov [edi],cl
- acrp3:
- inc edi
- dec al
- jnz acStringPacket
- jmp aclineLoop
- acrp3a:
- and eax,255
- lea esi,[esi+eax-1]
- jmp aclineLoop
- acEndPacket:
- mov edx,DestWidth
- mov eax,EndofClip
- add eax,edx
- mov edi,StartofLine
- mov EndofClip,eax
- nop
- mov eax,StartofClip
- add edi,edx
- add eax,edx
- mov edx,lines
- mov StartofLine,edi
- dec edx
- mov StartofClip,eax
- mov lines,edx
- jnz aclineLoop
- pop ebp
- jmp Exit
- assertError:
- pop ebp
-
- #ifdef CATCH_VFX_BUG
- mov saveEdi,edi
- }
- //void *shape_table,LONG shape_number, LONG hotX, LONG hotY
-
- char msg[1024];
-
- //-------------------------------------
- // Save off the shape data table start
- char *shapeTable = (char *)shape_table;
- char version[5];
- for (long i=0;i<4;i++)
- {
- version[i] = *shapeTable;
- shapeTable++;
- }
- version[4] = 0;
-
- long numShapes = (long)*shapeTable;
- shapeTable += 4;
- shapeTable += (shape_number * 8);
- long shapeNumOffset = (long) *shapeTable;
-
- sprintf(msg,"SP: %08x SF: %d X: %d Y:%d V: %s SN: %d SOf: %d",shape_table,shape_number,hotX,hotY,version,numShapes,shapeNumOffset);
- Fatal(saveEdi,msg);
- #else
- }
- #endif
- __asm
- {
- Exit:
- }
- }
|