DrawMisc.cpp 150 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /*
  15. **
  16. **
  17. ** Misc asm functions from ww lib
  18. ** ST - 12/19/2018 1:20PM
  19. **
  20. **
  21. **
  22. **
  23. **
  24. **
  25. **
  26. **
  27. **
  28. **
  29. **
  30. */
  31. #include "gbuffer.h"
  32. #include "MISC.H"
  33. IconCacheClass::IconCacheClass (void)
  34. {
  35. IsCached =FALSE;
  36. SurfaceLost =FALSE;
  37. DrawFrequency =0;
  38. CacheSurface =NULL;
  39. IconSource =NULL;
  40. }
  41. IconCacheClass::~IconCacheClass (void)
  42. {
  43. }
  44. IconCacheClass CachedIcons[MAX_CACHED_ICONS];
  45. extern "C"{
  46. IconSetType IconSetList[MAX_ICON_SETS];
  47. short IconCacheLookup[MAX_LOOKUP_ENTRIES];
  48. }
  49. int CachedIconsDrawn=0; //Counter of number of cache hits
  50. int UnCachedIconsDrawn=0; //Counter of number of cache misses
  51. BOOL CacheMemoryExhausted; //Flag set if we have run out of video RAM
  52. void Invalidate_Cached_Icons (void) {}
  53. void Restore_Cached_Icons (void) {}
  54. void Register_Icon_Set (void *icon_data , BOOL pre_cache) {};
  55. //
  56. // Prototypes for assembly language procedures in STMPCACH.ASM
  57. //
  58. extern "C" void __cdecl Clear_Icon_Pointers (void) {};
  59. extern "C" void __cdecl Cache_Copy_Icon (void const *icon_ptr ,void * , int) {};
  60. extern "C" int __cdecl Is_Icon_Cached (void const *icon_data , int icon) {return -1;};
  61. extern "C" int __cdecl Get_Icon_Index (void *icon_ptr) {return 0;};
  62. extern "C" int __cdecl Get_Free_Index (void) {return 0;};
  63. extern "C" BOOL __cdecl Cache_New_Icon (int icon_index, void *icon_ptr) {return -1;};
  64. extern "C" int __cdecl Get_Free_Cache_Slot(void) {return -1;}
  65. void IconCacheClass::Draw_It (LPDIRECTDRAWSURFACE dest_surface , int x_pixel, int y_pixel, int window_left , int window_top , int window_width , int window_height) {}
  66. extern int CachedIconsDrawn;
  67. extern int UnCachedIconsDrawn;
  68. extern "C" void __cdecl Set_Font_Palette_Range(void const *palette, INT start_idx, INT end_idx)
  69. {
  70. }
  71. /*
  72. ;***************************************************************************
  73. ;* VVC::DRAW_LINE -- Scales a virtual viewport to another virtual viewport *
  74. ;* *
  75. ;* INPUT: WORD sx_pixel - the starting x pixel position *
  76. ;* WORD sy_pixel - the starting y pixel position *
  77. ;* WORD dx_pixel - the destination x pixel position *
  78. ;* WORD dy_pixel - the destination y pixel position *
  79. ;* WORD color - the color of the line to draw *
  80. ;* *
  81. ;* Bounds Checking: Compares sx_pixel, sy_pixel, dx_pixel and dy_pixel *
  82. ;* with the graphic viewport it has been assigned to. *
  83. ;* *
  84. ;* HISTORY: *
  85. ;* 06/16/1994 PWG : Created. *
  86. ;* 08/30/1994 IML : Fixed clipping bug. *
  87. ;*=========================================================================*
  88. PROC Buffer_Draw_Line C NEAR
  89. USES eax,ebx,ecx,edx,esi,edi
  90. */
  91. void __cdecl Buffer_Draw_Line(void *this_object, int sx, int sy, int dx, int dy, unsigned char color)
  92. {
  93. unsigned int clip_min_x;
  94. unsigned int clip_max_x;
  95. unsigned int clip_min_y;
  96. unsigned int clip_max_y;
  97. unsigned int clip_var;
  98. unsigned int accum;
  99. unsigned int bpr;
  100. static int _one_time_init = 0;
  101. //clip_tbl DD nada,a_up,a_dwn,nada
  102. // DD a_lft,a_lft,a_dwn,nada
  103. // DD a_rgt,a_up,a_rgt,nada
  104. // DD nada,nada,nada,nada
  105. static void *_clip_table [4*4] = {0};
  106. unsigned int int_color = color;
  107. unsigned int x1_pixel = (unsigned int) sx;
  108. unsigned int y1_pixel = (unsigned int) sy;
  109. unsigned int x2_pixel = (unsigned int) dx;
  110. unsigned int y2_pixel = (unsigned int) dy;
  111. __asm {
  112. mov eax,_one_time_init
  113. and eax,eax
  114. jnz init_done
  115. call do_init
  116. init_done:
  117. //;*==================================================================
  118. //;* Take care of find the clip minimum and maximums
  119. //;*==================================================================
  120. mov ebx,[this_object]
  121. xor eax,eax
  122. mov [clip_min_x],eax
  123. mov [clip_min_y],eax
  124. mov eax,[ebx]GraphicViewPortClass.Width
  125. mov [clip_max_x],eax
  126. add eax,[ebx]GraphicViewPortClass.XAdd
  127. add eax,[ebx]GraphicViewPortClass.Pitch
  128. mov [bpr],eax
  129. mov eax,[ebx]GraphicViewPortClass.Height
  130. mov [clip_max_y],eax
  131. //;*==================================================================
  132. //;* Adjust max pixels as they are tested inclusively.
  133. //;*==================================================================
  134. dec [clip_max_x]
  135. dec [clip_max_y]
  136. //;*==================================================================
  137. //;* Set the registers with the data for drawing the line
  138. //;*==================================================================
  139. mov eax,[x1_pixel] //; eax = start x pixel position
  140. mov ebx,[y1_pixel] //; ebx = start y pixel position
  141. mov ecx,[x2_pixel] //; ecx = dest x pixel position
  142. mov edx,[y2_pixel] //; edx = dest y pixel position
  143. //;*==================================================================
  144. //;* This is the section that "pushes" the line into bounds.
  145. //;* I have marked the section with PORTABLE start and end to signify
  146. //;* how much of this routine is 100% portable between graphics modes.
  147. //;* It was just as easy to have variables as it would be for constants
  148. //;* so the global vars ClipMaxX,ClipMinY,ClipMaxX,ClipMinY are used
  149. //;* to clip the line (default is the screen)
  150. //;* PORTABLE start
  151. //;*==================================================================
  152. cmp eax,[clip_min_x]
  153. jl short clip_it
  154. cmp eax,[clip_max_x]
  155. jg short clip_it
  156. cmp ebx,[clip_min_y]
  157. jl short clip_it
  158. cmp ebx,[clip_max_y]
  159. jg short clip_it
  160. cmp ecx,[clip_min_x]
  161. jl short clip_it
  162. cmp ecx,[clip_max_x]
  163. jg short clip_it
  164. cmp edx,[clip_min_y]
  165. jl short clip_it
  166. cmp edx,[clip_max_y]
  167. jle short on_screen
  168. //;*==================================================================
  169. //;* Takes care off clipping the line.
  170. //;*==================================================================
  171. clip_it:
  172. call set_bits
  173. xchg eax,ecx
  174. xchg ebx,edx
  175. mov edi,esi
  176. call set_bits
  177. mov [clip_var],edi
  178. or [clip_var],esi
  179. jz short on_screen
  180. test edi,esi
  181. jne short off_screen
  182. shl esi,2
  183. //call [clip_tbl+esi]
  184. call [_clip_table+esi]
  185. jc clip_it
  186. xchg eax,ecx
  187. xchg ebx,edx
  188. shl edi,2
  189. //call [clip_tbl+edi]
  190. call [_clip_table+edi]
  191. jmp clip_it
  192. on_screen:
  193. jmp draw_it
  194. off_screen:
  195. jmp and_out
  196. //;*==================================================================
  197. //;* Jump table for clipping conditions
  198. //;*==================================================================
  199. //clip_tbl DD nada,a_up,a_dwn,nada
  200. // DD a_lft,a_lft,a_dwn,nada
  201. // DD a_rgt,a_up,a_rgt,nada
  202. // DD nada,nada,nada,nada
  203. nada:
  204. clc
  205. ret
  206. a_up:
  207. mov esi,[clip_min_y]
  208. call clip_vert
  209. stc
  210. ret
  211. a_dwn:
  212. mov esi,[clip_max_y]
  213. neg esi
  214. neg ebx
  215. neg edx
  216. call clip_vert
  217. neg ebx
  218. neg edx
  219. stc
  220. ret
  221. //;*==================================================================
  222. //;* xa'=xa+[(miny-ya)(xb-xa)/(yb-ya)]
  223. //;*==================================================================
  224. clip_vert:
  225. push edx
  226. push eax
  227. mov [clip_var],edx //; clip_var = yb
  228. sub [clip_var],ebx //; clip_var = (yb-ya)
  229. neg eax //; eax=-xa
  230. add eax,ecx //; (ebx-xa)
  231. mov edx,esi //; edx=miny
  232. sub edx,ebx //; edx=(miny-ya)
  233. imul edx
  234. idiv [clip_var]
  235. pop edx
  236. add eax,edx
  237. pop edx
  238. mov ebx,esi
  239. ret
  240. a_lft:
  241. mov esi,[clip_min_x]
  242. call clip_horiz
  243. stc
  244. ret
  245. a_rgt:
  246. mov esi,[clip_max_x]
  247. neg eax
  248. neg ecx
  249. neg esi
  250. call clip_horiz
  251. neg eax
  252. neg ecx
  253. stc
  254. ret
  255. //;*==================================================================
  256. //;* ya'=ya+[(minx-xa)(yb-ya)/(xb-xa)]
  257. //;*==================================================================
  258. clip_horiz:
  259. push edx
  260. mov [clip_var],ecx //; clip_var = xb
  261. sub [clip_var],eax //; clip_var = (xb-xa)
  262. sub edx,ebx //; edx = (yb-ya)
  263. neg eax //; eax = -xa
  264. add eax,esi //; eax = (minx-xa)
  265. imul edx //; eax = (minx-xa)(yb-ya)
  266. idiv [clip_var] //; eax = (minx-xa)(yb-ya)/(xb-xa)
  267. add ebx,eax //; ebx = xa+[(minx-xa)(yb-ya)/(xb-xa)]
  268. pop edx
  269. mov eax,esi
  270. ret
  271. //;*==================================================================
  272. //;* Sets the condition bits
  273. //;*==================================================================
  274. set_bits:
  275. xor esi,esi
  276. cmp ebx,[clip_min_y] //; if y >= top its not up
  277. jge short a_not_up
  278. or esi,1
  279. a_not_up:
  280. cmp ebx,[clip_max_y] //; if y <= bottom its not down
  281. jle short a_not_down
  282. or esi,2
  283. a_not_down:
  284. cmp eax,[clip_min_x] //; if x >= left its not left
  285. jge short a_not_left
  286. or esi,4
  287. a_not_left:
  288. cmp eax,[clip_max_x] //; if x <= right its not right
  289. jle short a_not_right
  290. or esi,8
  291. a_not_right:
  292. ret
  293. //;*==================================================================
  294. //;* Draw the line to the screen.
  295. //;* PORTABLE end
  296. //;*==================================================================
  297. draw_it:
  298. sub edx,ebx //; see if line is being draw down
  299. jnz short not_hline //; if not then its not a hline
  300. jmp short hline //; do special case h line
  301. not_hline:
  302. jg short down //; if so there is no need to rev it
  303. neg edx //; negate for actual pixel length
  304. xchg eax,ecx //; swap x's to rev line draw
  305. sub ebx,edx //; get old edx
  306. down:
  307. push edx
  308. push eax
  309. mov eax,[bpr]
  310. mul ebx
  311. mov ebx,eax
  312. mov eax,[this_object]
  313. add ebx,[eax]GraphicViewPortClass.Offset
  314. pop eax
  315. pop edx
  316. mov esi,1 //; assume a right mover
  317. sub ecx,eax //; see if line is right
  318. jnz short not_vline //; see if its a vertical line
  319. jmp vline
  320. not_vline:
  321. jg short right //; if so, the difference = length
  322. //left:
  323. neg ecx //; else negate for actual pixel length
  324. neg esi //; negate counter to move left
  325. right:
  326. cmp ecx,edx //; is it a horiz or vert line
  327. jge short horiz //; if ecx > edx then |x|>|y| or horiz
  328. //vert:
  329. xchg ecx,edx //; make ecx greater and edx lesser
  330. mov edi,ecx //; set greater
  331. mov [accum],ecx //; set accumulator to 1/2 greater
  332. shr [accum],1
  333. //;*==================================================================
  334. //;* at this point ...
  335. //;* eax=xpos ; ebx=page line offset; ecx=counter; edx=lesser; edi=greater;
  336. //;* esi=adder; accum=accumulator
  337. //;* in a vertical loop the adder is conditional and the inc constant
  338. //;*==================================================================
  339. //vert_loop:
  340. add ebx,eax
  341. mov eax,[int_color]
  342. v_midloop:
  343. mov [ebx],al
  344. dec ecx
  345. jl and_out
  346. add ebx,[bpr]
  347. sub [accum],edx //; sub the lesser
  348. jge v_midloop //; any line could be new
  349. add [accum],edi //; add greater for new accum
  350. add ebx,esi //; next pixel over
  351. jmp v_midloop
  352. horiz:
  353. mov edi,ecx //; set greater
  354. mov [accum],ecx //; set accumulator to 1/2 greater
  355. shr [accum],1
  356. //;*==================================================================
  357. //;* at this point ...
  358. //;* eax=xpos ; ebx=page line offset; ecx=counter; edx=lesser; edi=greater;
  359. //;* esi=adder; accum=accumulator
  360. //;* in a vertical loop the adder is conditional and the inc constant
  361. //;*==================================================================
  362. //horiz_loop:
  363. add ebx,eax
  364. mov eax,[int_color]
  365. h_midloop:
  366. mov [ebx],al
  367. dec ecx //; dec counter
  368. jl and_out //; end of line
  369. add ebx,esi
  370. sub [accum],edx //; sub the lesser
  371. jge h_midloop
  372. add [accum],edi //; add greater for new accum
  373. add ebx,[bpr] //; goto next line
  374. jmp h_midloop
  375. //;*==================================================================
  376. //;* Special case routine for horizontal line draws
  377. //;*==================================================================
  378. hline:
  379. cmp eax,ecx //; make eax < ecx
  380. jl short hl_ac
  381. xchg eax,ecx
  382. hl_ac:
  383. sub ecx,eax //; get len
  384. inc ecx
  385. push edx
  386. push eax
  387. mov eax,[bpr]
  388. mul ebx
  389. mov ebx,eax
  390. mov eax,[this_object]
  391. add ebx,[eax]GraphicViewPortClass.Offset
  392. pop eax
  393. pop edx
  394. add ebx,eax
  395. mov edi,ebx
  396. cmp ecx,15
  397. jg big_line
  398. mov al,[color]
  399. rep stosb //; write as many words as possible
  400. jmp short and_out //; get outt
  401. big_line:
  402. mov al,[color]
  403. mov ah,al
  404. mov ebx,eax
  405. shl eax,16
  406. mov ax,bx
  407. test edi,3
  408. jz aligned
  409. mov [edi],al
  410. inc edi
  411. dec ecx
  412. test edi,3
  413. jz aligned
  414. mov [edi],al
  415. inc edi
  416. dec ecx
  417. test edi,3
  418. jz aligned
  419. mov [edi],al
  420. inc edi
  421. dec ecx
  422. aligned:
  423. mov ebx,ecx
  424. shr ecx,2
  425. rep stosd
  426. mov ecx,ebx
  427. and ecx,3
  428. rep stosb
  429. jmp and_out
  430. //;*==================================================================
  431. //;* a special case routine for vertical line draws
  432. //;*==================================================================
  433. vline:
  434. mov ecx,edx //; get length of line to draw
  435. inc ecx
  436. add ebx,eax
  437. mov eax,[int_color]
  438. vl_loop:
  439. mov [ebx],al //; store bit
  440. add ebx,[bpr]
  441. dec ecx
  442. jnz vl_loop
  443. jmp and_out
  444. do_init:
  445. mov edi, offset _clip_table
  446. lea esi, nada
  447. mov [edi], esi
  448. mov [edi+12], esi
  449. lea esi, a_up
  450. mov [edi+4], esi
  451. lea esi, a_dwn
  452. mov [edi+8], esi
  453. add edi, 16
  454. lea esi, a_lft
  455. mov [edi], esi
  456. mov [edi+4], esi
  457. lea esi, a_dwn
  458. mov [edi+8], esi
  459. lea esi, nada
  460. mov [edi+12], esi
  461. add edi, 16
  462. lea esi, a_rgt
  463. mov [edi], esi
  464. mov [edi+8], esi
  465. lea esi, a_up
  466. mov [edi+4], esi
  467. lea esi, nada
  468. mov [edi+12], esi
  469. add edi, 16
  470. lea esi, nada
  471. mov [edi], esi
  472. mov [edi+4], esi
  473. mov [edi+8], esi
  474. mov [edi+12], esi
  475. mov [_one_time_init], 1
  476. ret
  477. and_out:
  478. }
  479. }
  480. /*
  481. ;***************************************************************************
  482. ;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  483. ;***************************************************************************
  484. ;* *
  485. ;* Project Name : Westwood 32 bit Library *
  486. ;* *
  487. ;* File Name : DRAWLINE.ASM *
  488. ;* *
  489. ;* Programmer : Phil W. Gorrow *
  490. ;* *
  491. ;* Start Date : June 16, 1994 *
  492. ;* *
  493. ;* Last Update : August 30, 1994 [IML] *
  494. ;* *
  495. ;*-------------------------------------------------------------------------*
  496. ;* Functions: *
  497. ;* VVC::Scale -- Scales a virtual viewport to another virtual viewport *
  498. ;* Normal_Draw -- jump loc for drawing scaled line of normal pixel *
  499. ;* __DRAW_LINE -- Assembly routine to draw a line *
  500. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  501. IDEAL
  502. P386
  503. MODEL USE32 FLAT
  504. INCLUDE ".\drawbuff.inc"
  505. INCLUDE ".\gbuffer.inc"
  506. CODESEG
  507. */
  508. /*
  509. ;***************************************************************************
  510. ;* VVC::DRAW_LINE -- Scales a virtual viewport to another virtual viewport *
  511. ;* *
  512. ;* INPUT: WORD sx_pixel - the starting x pixel position *
  513. ;* WORD sy_pixel - the starting y pixel position *
  514. ;* WORD dx_pixel - the destination x pixel position *
  515. ;* WORD dy_pixel - the destination y pixel position *
  516. ;* WORD color - the color of the line to draw *
  517. ;* *
  518. ;* Bounds Checking: Compares sx_pixel, sy_pixel, dx_pixel and dy_pixel *
  519. ;* with the graphic viewport it has been assigned to. *
  520. ;* *
  521. ;* HISTORY: *
  522. ;* 06/16/1994 PWG : Created. *
  523. ;* 08/30/1994 IML : Fixed clipping bug. *
  524. ;*=========================================================================*
  525. PROC Buffer_Draw_Line C NEAR
  526. USES eax,ebx,ecx,edx,esi,edi
  527. ;*==================================================================
  528. ;* Define the arguements that the function takes.
  529. ;*==================================================================
  530. ARG this_object:DWORD ; associated graphic view port
  531. ARG x1_pixel:DWORD ; the start x pixel position
  532. ARG y1_pixel:DWORD ; the start y pixel position
  533. ARG x2_pixel:DWORD ; the dest x pixel position
  534. ARG y2_pixel:DWORD ; the dest y pixel position
  535. ARG color:DWORD ; the color we are drawing
  536. ;*==================================================================
  537. ;* Define the local variables that we will use on the stack
  538. ;*==================================================================
  539. LOCAL clip_min_x:DWORD
  540. LOCAL clip_max_x:DWORD
  541. LOCAL clip_min_y:DWORD
  542. LOCAL clip_max_y:DWORD
  543. LOCAL clip_var:DWORD
  544. LOCAL accum:DWORD
  545. LOCAL bpr:DWORD
  546. ;*==================================================================
  547. ;* Take care of find the clip minimum and maximums
  548. ;*==================================================================
  549. mov ebx,[this_object]
  550. xor eax,eax
  551. mov [clip_min_x],eax
  552. mov [clip_min_y],eax
  553. mov eax,[(GraphicViewPort ebx).GVPWidth]
  554. mov [clip_max_x],eax
  555. add eax,[(GraphicViewPort ebx).GVPXAdd]
  556. add eax,[(GraphicViewPort ebx).GVPPitch]
  557. mov [bpr],eax
  558. mov eax,[(GraphicViewPort ebx).GVPHeight]
  559. mov [clip_max_y],eax
  560. ;*==================================================================
  561. ;* Adjust max pixels as they are tested inclusively.
  562. ;*==================================================================
  563. dec [clip_max_x]
  564. dec [clip_max_y]
  565. ;*==================================================================
  566. ;* Set the registers with the data for drawing the line
  567. ;*==================================================================
  568. mov eax,[x1_pixel] ; eax = start x pixel position
  569. mov ebx,[y1_pixel] ; ebx = start y pixel position
  570. mov ecx,[x2_pixel] ; ecx = dest x pixel position
  571. mov edx,[y2_pixel] ; edx = dest y pixel position
  572. ;*==================================================================
  573. ;* This is the section that "pushes" the line into bounds.
  574. ;* I have marked the section with PORTABLE start and end to signify
  575. ;* how much of this routine is 100% portable between graphics modes.
  576. ;* It was just as easy to have variables as it would be for constants
  577. ;* so the global vars ClipMaxX,ClipMinY,ClipMaxX,ClipMinY are used
  578. ;* to clip the line (default is the screen)
  579. ;* PORTABLE start
  580. ;*==================================================================
  581. cmp eax,[clip_min_x]
  582. jl short ??clip_it
  583. cmp eax,[clip_max_x]
  584. jg short ??clip_it
  585. cmp ebx,[clip_min_y]
  586. jl short ??clip_it
  587. cmp ebx,[clip_max_y]
  588. jg short ??clip_it
  589. cmp ecx,[clip_min_x]
  590. jl short ??clip_it
  591. cmp ecx,[clip_max_x]
  592. jg short ??clip_it
  593. cmp edx,[clip_min_y]
  594. jl short ??clip_it
  595. cmp edx,[clip_max_y]
  596. jle short ??on_screen
  597. ;*==================================================================
  598. ;* Takes care off clipping the line.
  599. ;*==================================================================
  600. ??clip_it:
  601. call NEAR PTR ??set_bits
  602. xchg eax,ecx
  603. xchg ebx,edx
  604. mov edi,esi
  605. call NEAR PTR ??set_bits
  606. mov [clip_var],edi
  607. or [clip_var],esi
  608. jz short ??on_screen
  609. test edi,esi
  610. jne short ??off_screen
  611. shl esi,2
  612. call [DWORD PTR cs:??clip_tbl+esi]
  613. jc ??clip_it
  614. xchg eax,ecx
  615. xchg ebx,edx
  616. shl edi,2
  617. call [DWORD PTR cs:??clip_tbl+edi]
  618. jmp ??clip_it
  619. ??on_screen:
  620. jmp ??draw_it
  621. ??off_screen:
  622. jmp ??out
  623. ;*==================================================================
  624. ;* Jump table for clipping conditions
  625. ;*==================================================================
  626. ??clip_tbl DD ??nada,??a_up,??a_dwn,??nada
  627. DD ??a_lft,??a_lft,??a_dwn,??nada
  628. DD ??a_rgt,??a_up,??a_rgt,??nada
  629. DD ??nada,??nada,??nada,??nada
  630. ??nada:
  631. clc
  632. retn
  633. ??a_up:
  634. mov esi,[clip_min_y]
  635. call NEAR PTR ??clip_vert
  636. stc
  637. retn
  638. ??a_dwn:
  639. mov esi,[clip_max_y]
  640. neg esi
  641. neg ebx
  642. neg edx
  643. call NEAR PTR ??clip_vert
  644. neg ebx
  645. neg edx
  646. stc
  647. retn
  648. ;*==================================================================
  649. ;* xa'=xa+[(miny-ya)(xb-xa)/(yb-ya)]
  650. ;*==================================================================
  651. ??clip_vert:
  652. push edx
  653. push eax
  654. mov [clip_var],edx ; clip_var = yb
  655. sub [clip_var],ebx ; clip_var = (yb-ya)
  656. neg eax ; eax=-xa
  657. add eax,ecx ; (ebx-xa)
  658. mov edx,esi ; edx=miny
  659. sub edx,ebx ; edx=(miny-ya)
  660. imul edx
  661. idiv [clip_var]
  662. pop edx
  663. add eax,edx
  664. pop edx
  665. mov ebx,esi
  666. retn
  667. ??a_lft:
  668. mov esi,[clip_min_x]
  669. call NEAR PTR ??clip_horiz
  670. stc
  671. retn
  672. ??a_rgt:
  673. mov esi,[clip_max_x]
  674. neg eax
  675. neg ecx
  676. neg esi
  677. call NEAR PTR ??clip_horiz
  678. neg eax
  679. neg ecx
  680. stc
  681. retn
  682. ;*==================================================================
  683. ;* ya'=ya+[(minx-xa)(yb-ya)/(xb-xa)]
  684. ;*==================================================================
  685. ??clip_horiz:
  686. push edx
  687. mov [clip_var],ecx ; clip_var = xb
  688. sub [clip_var],eax ; clip_var = (xb-xa)
  689. sub edx,ebx ; edx = (yb-ya)
  690. neg eax ; eax = -xa
  691. add eax,esi ; eax = (minx-xa)
  692. imul edx ; eax = (minx-xa)(yb-ya)
  693. idiv [clip_var] ; eax = (minx-xa)(yb-ya)/(xb-xa)
  694. add ebx,eax ; ebx = xa+[(minx-xa)(yb-ya)/(xb-xa)]
  695. pop edx
  696. mov eax,esi
  697. retn
  698. ;*==================================================================
  699. ;* Sets the condition bits
  700. ;*==================================================================
  701. ??set_bits:
  702. xor esi,esi
  703. cmp ebx,[clip_min_y] ; if y >= top its not up
  704. jge short ??a_not_up
  705. or esi,1
  706. ??a_not_up:
  707. cmp ebx,[clip_max_y] ; if y <= bottom its not down
  708. jle short ??a_not_down
  709. or esi,2
  710. ??a_not_down:
  711. cmp eax,[clip_min_x] ; if x >= left its not left
  712. jge short ??a_not_left
  713. or esi,4
  714. ??a_not_left:
  715. cmp eax,[clip_max_x] ; if x <= right its not right
  716. jle short ??a_not_right
  717. or esi,8
  718. ??a_not_right:
  719. retn
  720. ;*==================================================================
  721. ;* Draw the line to the screen.
  722. ;* PORTABLE end
  723. ;*==================================================================
  724. ??draw_it:
  725. sub edx,ebx ; see if line is being draw down
  726. jnz short ??not_hline ; if not then its not a hline
  727. jmp short ??hline ; do special case h line
  728. ??not_hline:
  729. jg short ??down ; if so there is no need to rev it
  730. neg edx ; negate for actual pixel length
  731. xchg eax,ecx ; swap x's to rev line draw
  732. sub ebx,edx ; get old edx
  733. ??down:
  734. push edx
  735. push eax
  736. mov eax,[bpr]
  737. mul ebx
  738. mov ebx,eax
  739. mov eax,[this_object]
  740. add ebx,[(GraphicViewPort eax).GVPOffset]
  741. pop eax
  742. pop edx
  743. mov esi,1 ; assume a right mover
  744. sub ecx,eax ; see if line is right
  745. jnz short ??not_vline ; see if its a vertical line
  746. jmp ??vline
  747. ??not_vline:
  748. jg short ??right ; if so, the difference = length
  749. ??left:
  750. neg ecx ; else negate for actual pixel length
  751. neg esi ; negate counter to move left
  752. ??right:
  753. cmp ecx,edx ; is it a horiz or vert line
  754. jge short ??horiz ; if ecx > edx then |x|>|y| or horiz
  755. ??vert:
  756. xchg ecx,edx ; make ecx greater and edx lesser
  757. mov edi,ecx ; set greater
  758. mov [accum],ecx ; set accumulator to 1/2 greater
  759. shr [accum],1
  760. ;*==================================================================
  761. ;* at this point ...
  762. ;* eax=xpos ; ebx=page line offset; ecx=counter; edx=lesser; edi=greater;
  763. ;* esi=adder; accum=accumulator
  764. ;* in a vertical loop the adder is conditional and the inc constant
  765. ;*==================================================================
  766. ??vert_loop:
  767. add ebx,eax
  768. mov eax,[color]
  769. ??v_midloop:
  770. mov [ebx],al
  771. dec ecx
  772. jl ??out
  773. add ebx,[bpr]
  774. sub [accum],edx ; sub the lesser
  775. jge ??v_midloop ; any line could be new
  776. add [accum],edi ; add greater for new accum
  777. add ebx,esi ; next pixel over
  778. jmp ??v_midloop
  779. ??horiz:
  780. mov edi,ecx ; set greater
  781. mov [accum],ecx ; set accumulator to 1/2 greater
  782. shr [accum],1
  783. ;*==================================================================
  784. ;* at this point ...
  785. ;* eax=xpos ; ebx=page line offset; ecx=counter; edx=lesser; edi=greater;
  786. ;* esi=adder; accum=accumulator
  787. ;* in a vertical loop the adder is conditional and the inc constant
  788. ;*==================================================================
  789. ??horiz_loop:
  790. add ebx,eax
  791. mov eax,[color]
  792. ??h_midloop:
  793. mov [ebx],al
  794. dec ecx ; dec counter
  795. jl ??out ; end of line
  796. add ebx,esi
  797. sub [accum],edx ; sub the lesser
  798. jge ??h_midloop
  799. add [accum],edi ; add greater for new accum
  800. add ebx,[bpr] ; goto next line
  801. jmp ??h_midloop
  802. ;*==================================================================
  803. ;* Special case routine for horizontal line draws
  804. ;*==================================================================
  805. ??hline:
  806. cmp eax,ecx ; make eax < ecx
  807. jl short ??hl_ac
  808. xchg eax,ecx
  809. ??hl_ac:
  810. sub ecx,eax ; get len
  811. inc ecx
  812. push edx
  813. push eax
  814. mov eax,[bpr]
  815. mul ebx
  816. mov ebx,eax
  817. mov eax,[this_object]
  818. add ebx,[(GraphicViewPort eax).GVPOffset]
  819. pop eax
  820. pop edx
  821. add ebx,eax
  822. mov edi,ebx
  823. cmp ecx,15
  824. jg ??big_line
  825. mov al,[byte color]
  826. rep stosb ; write as many words as possible
  827. jmp short ??out ; get outt
  828. ??big_line:
  829. mov al,[byte color]
  830. mov ah,al
  831. mov ebx,eax
  832. shl eax,16
  833. mov ax,bx
  834. test edi,3
  835. jz ??aligned
  836. mov [edi],al
  837. inc edi
  838. dec ecx
  839. test edi,3
  840. jz ??aligned
  841. mov [edi],al
  842. inc edi
  843. dec ecx
  844. test edi,3
  845. jz ??aligned
  846. mov [edi],al
  847. inc edi
  848. dec ecx
  849. ??aligned:
  850. mov ebx,ecx
  851. shr ecx,2
  852. rep stosd
  853. mov ecx,ebx
  854. and ecx,3
  855. rep stosb
  856. jmp ??out
  857. ;*==================================================================
  858. ;* a special case routine for vertical line draws
  859. ;*==================================================================
  860. ??vline:
  861. mov ecx,edx ; get length of line to draw
  862. inc ecx
  863. add ebx,eax
  864. mov eax,[color]
  865. ??vl_loop:
  866. mov [ebx],al ; store bit
  867. add ebx,[bpr]
  868. dec ecx
  869. jnz ??vl_loop
  870. ??out:
  871. ret
  872. ENDP Buffer_Draw_Line
  873. */
  874. /*
  875. ;***************************************************************************
  876. ;* GVPC::FILL_RECT -- Fills a rectangular region of a graphic view port *
  877. ;* *
  878. ;* INPUT: WORD the left hand x pixel position of region *
  879. ;* WORD the upper x pixel position of region *
  880. ;* WORD the right hand x pixel position of region *
  881. ;* WORD the lower x pixel position of region *
  882. ;* UBYTE the color (optional) to clear the view port to *
  883. ;* *
  884. ;* OUTPUT: none *
  885. ;* *
  886. ;* NOTE: This function is optimized to handle viewport with no XAdd *
  887. ;* value. It also handles DWORD aligning the destination *
  888. ;* when speed can be gained by doing it. *
  889. ;* HISTORY: *
  890. ;* 06/07/1994 PWG : Created. *
  891. ;*=========================================================================*
  892. */
  893. /*
  894. ;******************************************************************************
  895. ; Much testing was done to determine that only when there are 14 or more bytes
  896. ; being copied does it speed the time it takes to do copies in this algorithm.
  897. ; For this reason and because 1 and 2 byte copies crash, is the special case
  898. ; used. SKB 4/21/94. Tested on 486 66mhz. Copied by PWG 6/7/04.
  899. */
  900. #define OPTIMAL_BYTE_COPY 14
  901. void __cdecl Buffer_Fill_Rect(void *thisptr, int sx, int sy, int dx, int dy, unsigned char color)
  902. {
  903. /*
  904. ;*===================================================================
  905. ;* define the arguements that our function takes.
  906. ;*===================================================================
  907. ARG this_object:DWORD ; this is a member function
  908. ARG x1_pixel:WORD
  909. ARG y1_pixel:WORD
  910. ARG x2_pixel:WORD
  911. ARG y2_pixel:WORD
  912. ARG color:BYTE ; what color should we clear to
  913. */
  914. void *this_object = thisptr;
  915. int x1_pixel = sx;
  916. int y1_pixel = sy;
  917. int x2_pixel = dx;
  918. int y2_pixel = dy;
  919. /*
  920. ;*===================================================================
  921. ; Define some locals so that we can handle things quickly
  922. ;*===================================================================
  923. LOCAL VPwidth:DWORD ; the width of the viewport
  924. LOCAL VPheight:DWORD ; the height of the viewport
  925. LOCAL VPxadd:DWORD ; the additional x offset of viewport
  926. LOCAL VPbpr:DWORD ; the number of bytes per row of viewport
  927. */
  928. int VPwidth;
  929. int VPheight;
  930. int VPxadd;
  931. int VPbpr;
  932. int local_ebp; // Can't use ebp
  933. __asm {
  934. ;*===================================================================
  935. ;* save off the viewport characteristics on the stack
  936. ;*===================================================================
  937. mov ebx,[this_object] ; get a pointer to viewport
  938. mov eax,[ebx]GraphicViewPortClass.Width ; get width from viewport
  939. mov ecx,[ebx]GraphicViewPortClass.Height ; get height from viewport
  940. mov edx,[ebx]GraphicViewPortClass.XAdd ; get xadd from viewport
  941. add edx,[ebx]GraphicViewPortClass.Pitch ; extra pitch of direct draw surface
  942. mov [VPwidth],eax ; store the width of locally
  943. mov [VPheight],ecx
  944. mov [VPxadd],edx
  945. add eax,edx
  946. mov [VPbpr],eax
  947. ;*===================================================================
  948. ;* move the important parameters into local registers
  949. ;*===================================================================
  950. mov eax,[x1_pixel]
  951. mov ebx,[y1_pixel]
  952. mov ecx,[x2_pixel]
  953. mov edx,[y2_pixel]
  954. ;*===================================================================
  955. ;* Convert the x2 and y2 pixel to a width and height
  956. ;*===================================================================
  957. cmp eax,ecx
  958. jl no_swap_x
  959. xchg eax,ecx
  960. no_swap_x:
  961. sub ecx,eax
  962. cmp ebx,edx
  963. jl no_swap_y
  964. xchg ebx,edx
  965. no_swap_y:
  966. sub edx,ebx
  967. inc ecx
  968. inc edx
  969. ;*===================================================================
  970. ;* Bounds check source X.
  971. ;*===================================================================
  972. cmp eax, [VPwidth] ; compare with the max
  973. jge done ; starts off screen, then later
  974. jb short sx_done ; if it's not negative, it's ok
  975. ;------ Clip source X to left edge of screen.
  976. add ecx, eax ; Reduce width (add in negative src X).
  977. xor eax, eax ; Clip to left of screen.
  978. sx_done:
  979. ;*===================================================================
  980. ;* Bounds check source Y.
  981. ;*===================================================================
  982. cmp ebx, [VPheight] ; compare with the max
  983. jge done ; starts off screen, then later
  984. jb short sy_done ; if it's not negative, it's ok
  985. ;------ Clip source Y to top edge of screen.
  986. add edx, ebx ; Reduce height (add in negative src Y).
  987. xor ebx, ebx ; Clip to top of screen.
  988. sy_done:
  989. ;*===================================================================
  990. ;* Bounds check width versus width of source and dest view ports
  991. ;*===================================================================
  992. push ebx ; save off ebx for later use
  993. mov ebx,[VPwidth] ; get the source width
  994. sub ebx, eax ; Maximum allowed pixel width (given coordinates).
  995. sub ebx, ecx ; Pixel width undershoot.
  996. jns short width_ok ; if not signed no adjustment necessary
  997. add ecx, ebx ; Reduce width to screen limits.
  998. width_ok:
  999. pop ebx ; restore ebx to old value
  1000. ;*===================================================================
  1001. ;* Bounds check height versus height of source view port
  1002. ;*===================================================================
  1003. push eax ; save of eax for later use
  1004. mov eax, [VPheight] ; get the source height
  1005. sub eax, ebx ; Maximum allowed pixel height (given coordinates).
  1006. sub eax, edx ; Pixel height undershoot.
  1007. jns short height_ok ; if not signed no adjustment necessary
  1008. add edx, eax ; Reduce height to screen limits.
  1009. height_ok:
  1010. pop eax ; restore eax to old value
  1011. ;*===================================================================
  1012. ;* Perform the last minute checks on the width and height
  1013. ;*===================================================================
  1014. or ecx,ecx
  1015. jz done
  1016. or edx,edx
  1017. jz done
  1018. cmp ecx,[VPwidth]
  1019. ja done
  1020. cmp edx,[VPheight]
  1021. ja done
  1022. ;*===================================================================
  1023. ;* Get the offset into the virtual viewport.
  1024. ;*===================================================================
  1025. xchg edi,eax ; save off the contents of eax
  1026. xchg esi,edx ; and edx for size test
  1027. mov eax,ebx ; move the y pixel into eax
  1028. mul [VPbpr] ; multiply by bytes per row
  1029. add edi,eax ; add the result into the x position
  1030. mov ebx,[this_object]
  1031. add edi,[ebx]GraphicViewPortClass.Offset
  1032. mov edx,esi ; restore edx back to real value
  1033. mov eax,ecx ; store total width in ecx
  1034. sub eax,[VPwidth] ; modify xadd value to include clipped
  1035. sub [VPxadd],eax ; width bytes (subtract a negative number)
  1036. ;*===================================================================
  1037. ; Convert the color byte to a DWORD for fast storing
  1038. ;*===================================================================
  1039. mov al,[color] ; get color to clear to
  1040. mov ah,al ; extend across WORD
  1041. mov ebx,eax ; extend across DWORD in
  1042. shl eax,16 ; several steps
  1043. mov ax,bx
  1044. ;*===================================================================
  1045. ; If there is no row offset then adjust the width to be the size of
  1046. ; the entire viewport and adjust the height to be 1
  1047. ;*===================================================================
  1048. mov esi,[VPxadd]
  1049. or esi,esi ; set the flags for esi
  1050. jnz row_by_row_aligned ; and act on them
  1051. xchg eax,ecx ; switch bit pattern and width
  1052. mul edx ; multiply by edx to get size
  1053. xchg eax,ecx ; switch size and bit pattern
  1054. mov edx,1 ; only 1 line off view port size to do
  1055. ;*===================================================================
  1056. ; Find out if we should bother to align the row.
  1057. ;*===================================================================
  1058. row_by_row_aligned:
  1059. mov [local_ebp],ecx ; width saved in ebp
  1060. cmp ecx,OPTIMAL_BYTE_COPY ; is it worth aligning them?
  1061. jl row_by_row ; if not then skip
  1062. ;*===================================================================
  1063. ; Figure out the alignment offset if there is any
  1064. ;*===================================================================
  1065. mov ebx,edi ; get output position
  1066. and ebx,3 ; is there a remainder?
  1067. jz aligned_loop ; if not we are aligned
  1068. xor ebx,3 ; find number of align bytes
  1069. inc ebx ; this number is off by one
  1070. sub [local_ebp],ebx ; subtract from width
  1071. ;*===================================================================
  1072. ; Now that we have the alignment offset copy each row
  1073. ;*===================================================================
  1074. aligned_loop:
  1075. mov ecx,ebx ; get number of bytes to align
  1076. rep stosb ; and move them over
  1077. mov ecx,[local_ebp] ; get number of aligned bytes
  1078. shr ecx,2 ; convert to DWORDS
  1079. rep stosd ; and move them over
  1080. mov ecx,[local_ebp] ; get number of aligned bytes
  1081. and ecx,3 ; find the remainder
  1082. rep stosb ; and move it over
  1083. add edi,esi ; fix the line offset
  1084. dec edx ; decrement the height
  1085. jnz aligned_loop ; if more to do than do it
  1086. jmp done ; we are all done
  1087. ;*===================================================================
  1088. ; If not enough bytes to bother aligning copy each line across a byte
  1089. ; at a time.
  1090. ;*===================================================================
  1091. row_by_row:
  1092. mov ecx,[local_ebp] ; get total width in bytes
  1093. rep stosb ; store the width
  1094. add edi,esi ; handle the xadd
  1095. dec edx ; decrement the height
  1096. jnz row_by_row ; if any left then next line
  1097. done:
  1098. }
  1099. }
  1100. /*
  1101. ;***************************************************************************
  1102. ;* VVPC::CLEAR -- Clears a virtual viewport instance *
  1103. ;* *
  1104. ;* INPUT: UBYTE the color (optional) to clear the view port to *
  1105. ;* *
  1106. ;* OUTPUT: none *
  1107. ;* *
  1108. ;* NOTE: This function is optimized to handle viewport with no XAdd *
  1109. ;* value. It also handles DWORD aligning the destination *
  1110. ;* when speed can be gained by doing it. *
  1111. ;* HISTORY: *
  1112. ;* 06/07/1994 PWG : Created. *
  1113. ;* 08/23/1994 SKB : Clear the direction flag to always go forward. *
  1114. ;*=========================================================================*
  1115. */
  1116. void __cdecl Buffer_Clear(void *this_object, unsigned char color)
  1117. {
  1118. unsigned int local_color = color;
  1119. __asm {
  1120. cld ; always go forward
  1121. mov ebx,[this_object] ; get a pointer to viewport
  1122. mov edi,[ebx]GraphicViewPortClass.Offset ; get the correct offset
  1123. mov edx,[ebx]GraphicViewPortClass.Height ; get height from viewport
  1124. mov esi,[ebx]GraphicViewPortClass.Width ; get width from viewport
  1125. //push [dword (GraphicViewPort ebx).GVPPitch] ; extra pitch of direct draw surface
  1126. push [ebx]GraphicViewPortClass.Pitch
  1127. mov ebx,[ebx]GraphicViewPortClass.XAdd ; esi = add for each line
  1128. add ebx,[esp] ; Yes, I know its nasty but
  1129. add esp,4 ; it works!
  1130. ;*===================================================================
  1131. ; Convert the color byte to a DWORD for fast storing
  1132. ;*===================================================================
  1133. mov al,[color] ; get color to clear to
  1134. mov ah,al ; extend across WORD
  1135. mov ecx,eax ; extend across DWORD in
  1136. shl eax,16 ; several steps
  1137. mov ax,cx
  1138. ;*===================================================================
  1139. ; Find out if we should bother to align the row.
  1140. ;*===================================================================
  1141. cmp esi , OPTIMAL_BYTE_COPY ; is it worth aligning them?
  1142. jl byte_by_byte ; if not then skip
  1143. ;*===================================================================
  1144. ; Figure out the alignment offset if there is any
  1145. ;*===================================================================
  1146. push ebx
  1147. dword_aligned_loop:
  1148. mov ecx , edi
  1149. mov ebx , esi
  1150. neg ecx
  1151. and ecx , 3
  1152. sub ebx , ecx
  1153. rep stosb
  1154. mov ecx , ebx
  1155. shr ecx , 2
  1156. rep stosd
  1157. mov ecx , ebx
  1158. and ecx , 3
  1159. rep stosb
  1160. add edi , [ esp ]
  1161. dec edx ; decrement the height
  1162. jnz dword_aligned_loop ; if more to do than do it
  1163. pop eax
  1164. jmp done
  1165. //ret
  1166. ;*===================================================================
  1167. ; If not enough bytes to bother aligning copy each line across a byte
  1168. ; at a time.
  1169. ;*===================================================================
  1170. byte_by_byte:
  1171. mov ecx,esi ; get total width in bytes
  1172. rep stosb ; store the width
  1173. add edi,ebx ; handle the xadd
  1174. dec edx ; decrement the height
  1175. jnz byte_by_byte ; if any left then next line
  1176. done:
  1177. }
  1178. }
  1179. BOOL __cdecl Linear_Blit_To_Linear( void *this_object, void * dest, int x_pixel, int y_pixel, int dest_x0, int dest_y0, int pixel_width, int pixel_height, BOOL trans)
  1180. {
  1181. /*
  1182. ;*===================================================================
  1183. ;* define the arguements that our function takes.
  1184. ;*===================================================================
  1185. ARG this_object :DWORD ; this is a member function
  1186. ARG dest :DWORD ; what are we blitting to
  1187. ARG x_pixel :DWORD ; x pixel position in source
  1188. ARG y_pixel :DWORD ; y pixel position in source
  1189. ARG dest_x0 :dword
  1190. ARG dest_y0 :dword
  1191. ARG pixel_width :DWORD ; width of rectangle to blit
  1192. ARG pixel_height:DWORD ; height of rectangle to blit
  1193. ARG trans :DWORD ; do we deal with transparents?
  1194. ;*===================================================================
  1195. ; Define some locals so that we can handle things quickly
  1196. ;*===================================================================
  1197. LOCAL x1_pixel :dword
  1198. LOCAL y1_pixel :dword
  1199. LOCAL dest_x1 : dword
  1200. LOCAL dest_y1 : dword
  1201. LOCAL scr_ajust_width:DWORD
  1202. LOCAL dest_ajust_width:DWORD
  1203. LOCAL source_area : dword
  1204. LOCAL dest_area : dword
  1205. */
  1206. int x1_pixel;
  1207. int y1_pixel;
  1208. int dest_x1;
  1209. int dest_y1;
  1210. int scr_adjust_width;
  1211. int dest_adjust_width;
  1212. int source_area;
  1213. int dest_area;
  1214. __asm {
  1215. ;This Clipping algorithm is a derivation of the very well known
  1216. ;Cohen-Sutherland Line-Clipping test. Due to its simplicity and efficiency
  1217. ;it is probably the most commontly implemented algorithm both in software
  1218. ;and hardware for clipping lines, rectangles, and convex polygons against
  1219. ;a rectagular clipping window. For reference see
  1220. ;"COMPUTER GRAPHICS principles and practice by Foley, Vandam, Feiner, Hughes
  1221. ; pages 113 to 177".
  1222. ; Briefly consist in computing the Sutherland code for both end point of
  1223. ; the rectangle to find out if the rectangle is:
  1224. ; - trivially accepted (no further clipping test, display rectangle)
  1225. ; - trivially rejected (return with no action)
  1226. ; - retangle must be iteratively clipped again edges of the clipping window
  1227. ; and the remaining retangle is display.
  1228. ; Clip Source Rectangle against source Window boundaries.
  1229. mov esi,[this_object] ; get ptr to src
  1230. xor ecx,ecx ; Set sutherland code to zero
  1231. xor edx,edx ; Set sutherland code to zero
  1232. ; compute the difference in the X axis and get the bit signs into ecx , edx
  1233. mov edi,[esi]GraphicViewPortClass.Width ; get width into register
  1234. mov ebx,[x_pixel] ; Get first end point x_pixel into register
  1235. mov eax,[x_pixel] ; Get second end point x_pixel into register
  1236. add ebx,[pixel_width] ; second point x1_pixel = x + width
  1237. shld ecx, eax,1 ; the sign bit of x_pixel is sutherland code0 bit4
  1238. mov [x1_pixel],ebx ; save second for future use
  1239. inc edi ; move the right edge by one unit
  1240. shld edx,ebx,1 ; the sign bit of x1_pixel is sutherland code0 bit4
  1241. sub eax,edi ; compute the difference x0_pixel - width
  1242. sub ebx,edi ; compute the difference x1_pixel - width
  1243. shld ecx,eax,1 ; the sign bit of the difference is sutherland code0 bit3
  1244. shld edx,ebx,1 ; the sign bit of the difference is sutherland code0 bit3
  1245. ; the following code is just a repeticion of the above code
  1246. ; in the Y axis.
  1247. mov edi,[esi]GraphicViewPortClass.Height ; get height into register
  1248. mov ebx,[y_pixel]
  1249. mov eax,[y_pixel]
  1250. add ebx,[pixel_height]
  1251. shld ecx,eax,1
  1252. mov [y1_pixel ],ebx
  1253. inc edi
  1254. shld edx,ebx,1
  1255. sub eax,edi
  1256. sub ebx,edi
  1257. shld ecx,eax,1
  1258. shld edx,ebx,1
  1259. ; Here we have the to Sutherland code into cl and dl
  1260. xor cl,5 ; bit 2 and 0 are complented, reverse then
  1261. xor dl,5 ; bit 2 and 0 are complented, reverse then
  1262. mov al,cl ; save code1 in case we have to clip iteratively
  1263. test dl,cl ; if any bit in code0 and its counter bit
  1264. jnz real_out ; in code1 is set then the rectangle in outside
  1265. or al,dl ; if all bit of code0 the counter bit in
  1266. jz clip_against_dest ; in code1 is set to zero, then all
  1267. ; end points of the rectangle are
  1268. ; inside the clipping window
  1269. ; if we are here the polygon have to be clip iteratively
  1270. test cl,1000b ; if bit 4 in code0 is set then
  1271. jz scr_left_ok ; x_pixel is smaller than zero
  1272. mov [x_pixel],0 ; set x_pixel to cero.
  1273. scr_left_ok:
  1274. test cl,0010b ; if bit 2 in code0 is set then
  1275. jz scr_bottom_ok ; y_pixel is smaller than zero
  1276. mov [ y_pixel ],0 ; set y_pixel to cero.
  1277. scr_bottom_ok:
  1278. test dl,0100b ; if bit 3 in code1 is set then
  1279. jz scr_right_ok ; x1_pixel is greater than the width
  1280. mov eax,[esi]GraphicViewPortClass.Width ; get width into register
  1281. mov [ x1_pixel ],eax ; set x1_pixel to width.
  1282. scr_right_ok:
  1283. test dl,0001b ; if bit 0 in code1 is set then
  1284. jz clip_against_dest ; y1_pixel is greater than the width
  1285. mov eax,[esi]GraphicViewPortClass.Height ; get height into register
  1286. mov [ y1_pixel ],eax ; set y1_pixel to height.
  1287. ; Clip Source Rectangle against destination Window boundaries.
  1288. clip_against_dest:
  1289. ; build the destination rectangle before clipping
  1290. ; dest_x1 = dest_x0 + ( x1_pixel - x_pixel )
  1291. ; dest_y1 = dest_y0 + ( y1_pixel - y_pixel )
  1292. mov eax,[dest_x0] ; get dest_x0 into eax
  1293. mov ebx,[dest_y0] ; get dest_y0 into ebx
  1294. sub eax,[x_pixel] ; subtract x_pixel from eax
  1295. sub ebx,[y_pixel] ; subtract y_pixel from ebx
  1296. add eax,[x1_pixel] ; add x1_pixel to eax
  1297. add ebx,[y1_pixel] ; add y1_pixel to ebx
  1298. mov [dest_x1],eax ; save eax into dest_x1
  1299. mov [dest_y1],ebx ; save eax into dest_y1
  1300. ; The followin code is a repeticion of the Sutherland clipping
  1301. ; descrived above.
  1302. mov esi,[dest] ; get ptr to src
  1303. xor ecx,ecx
  1304. xor edx,edx
  1305. mov edi,[esi]GraphicViewPortClass.Width ; get width into register
  1306. mov eax,[dest_x0]
  1307. mov ebx,[dest_x1]
  1308. shld ecx,eax,1
  1309. inc edi
  1310. shld edx,ebx,1
  1311. sub eax,edi
  1312. sub ebx,edi
  1313. shld ecx,eax,1
  1314. shld edx,ebx,1
  1315. mov edi,[esi]GraphicViewPortClass.Height ; get height into register
  1316. mov eax,[dest_y0]
  1317. mov ebx,[dest_y1]
  1318. shld ecx,eax,1
  1319. inc edi
  1320. shld edx,ebx,1
  1321. sub eax,edi
  1322. sub ebx,edi
  1323. shld ecx,eax,1
  1324. shld edx,ebx,1
  1325. xor cl,5
  1326. xor dl,5
  1327. mov al,cl
  1328. test dl,cl
  1329. jnz real_out
  1330. or al,dl
  1331. jz do_blit
  1332. test cl,1000b
  1333. jz dest_left_ok
  1334. mov eax,[ dest_x0 ]
  1335. mov [ dest_x0 ],0
  1336. sub [ x_pixel ],eax
  1337. dest_left_ok:
  1338. test cl,0010b
  1339. jz dest_bottom_ok
  1340. mov eax,[ dest_y0 ]
  1341. mov [ dest_y0 ],0
  1342. sub [ y_pixel ],eax
  1343. dest_bottom_ok:
  1344. test dl,0100b
  1345. jz dest_right_ok
  1346. mov ebx,[esi]GraphicViewPortClass.Width ; get width into register
  1347. mov eax,[ dest_x1 ]
  1348. mov [ dest_x1 ],ebx
  1349. sub eax,ebx
  1350. sub [ x1_pixel ],eax
  1351. dest_right_ok:
  1352. test dl,0001b
  1353. jz do_blit
  1354. mov ebx,[esi]GraphicViewPortClass.Height ; get width into register
  1355. mov eax,[ dest_y1 ]
  1356. mov [ dest_y1 ],ebx
  1357. sub eax,ebx
  1358. sub [ y1_pixel ],eax
  1359. ; Here is where we do the actual blit
  1360. do_blit:
  1361. cld
  1362. mov ebx,[this_object]
  1363. mov esi,[ebx]GraphicViewPortClass.Offset
  1364. mov eax,[ebx]GraphicViewPortClass.XAdd
  1365. add eax,[ebx]GraphicViewPortClass.Width
  1366. add eax,[ebx]GraphicViewPortClass.Pitch
  1367. mov ecx,eax
  1368. mul [y_pixel]
  1369. add esi,[x_pixel]
  1370. mov [source_area],ecx
  1371. add esi,eax
  1372. add ecx,[x_pixel ]
  1373. sub ecx,[x1_pixel ]
  1374. mov [scr_adjust_width ],ecx
  1375. mov ebx,[dest]
  1376. mov edi,[ebx]GraphicViewPortClass.Offset
  1377. mov eax,[ebx]GraphicViewPortClass.XAdd
  1378. add eax,[ebx]GraphicViewPortClass.Width
  1379. add eax,[ebx]GraphicViewPortClass.Pitch
  1380. mov ecx,eax
  1381. mul [ dest_y0 ]
  1382. add edi,[ dest_x0 ]
  1383. mov [ dest_area ],ecx
  1384. add edi,eax
  1385. mov eax,[ dest_x1 ]
  1386. sub eax,[ dest_x0 ]
  1387. jle real_out
  1388. sub ecx,eax
  1389. mov [ dest_adjust_width ],ecx
  1390. mov edx,[ dest_y1 ]
  1391. sub edx,[ dest_y0 ]
  1392. jle real_out
  1393. cmp esi,edi
  1394. jz real_out
  1395. jl backupward_blit
  1396. ; ********************************************************************
  1397. ; Forward bitblit
  1398. test [ trans ],1
  1399. jnz forward_Blit_trans
  1400. ; the inner loop is so efficient that
  1401. ; the optimal consept no longer apply because
  1402. ; the optimal byte have to by a number greather than 9 bytes
  1403. cmp eax,10
  1404. jl forward_loop_bytes
  1405. forward_loop_dword:
  1406. mov ecx,edi
  1407. mov ebx,eax
  1408. neg ecx
  1409. and ecx,3
  1410. sub ebx,ecx
  1411. rep movsb
  1412. mov ecx,ebx
  1413. shr ecx,2
  1414. rep movsd
  1415. mov ecx,ebx
  1416. and ecx,3
  1417. rep movsb
  1418. add esi,[ scr_adjust_width ]
  1419. add edi,[ dest_adjust_width ]
  1420. dec edx
  1421. jnz forward_loop_dword
  1422. jmp real_out //ret
  1423. forward_loop_bytes:
  1424. mov ecx,eax
  1425. rep movsb
  1426. add esi,[ scr_adjust_width ]
  1427. add edi,[ dest_adjust_width ]
  1428. dec edx
  1429. jnz forward_loop_bytes
  1430. jmp real_out
  1431. forward_Blit_trans:
  1432. mov ecx,eax
  1433. and ecx,01fh
  1434. lea ecx,[ ecx + ecx * 4 ]
  1435. neg ecx
  1436. shr eax,5
  1437. lea ecx,[ transp_reference + ecx * 2 ]
  1438. mov [ y1_pixel ],ecx
  1439. forward_loop_trans:
  1440. mov ecx,eax
  1441. jmp [ y1_pixel ]
  1442. forward_trans_line:
  1443. //REPT 32
  1444. //local transp_pixel
  1445. //No REPT in msvc inline assembly.
  1446. // Save ECX and use as counter instead. ST - 12/19/2018 5:41PM
  1447. push ecx
  1448. mov ecx, 32
  1449. rept_loop:
  1450. mov bl,[ esi ]
  1451. test bl,bl
  1452. jz transp_pixel
  1453. mov [ edi ],bl
  1454. transp_pixel:
  1455. inc esi
  1456. inc edi
  1457. dec ecx //ST - 12/19/2018 5:44PM
  1458. jnz rept_loop //ST - 12/19/2018 5:44PM
  1459. pop ecx //ST - 12/19/2018 5:44PM
  1460. //ENDM
  1461. transp_reference:
  1462. dec ecx
  1463. jge forward_trans_line
  1464. add esi,[ scr_adjust_width ]
  1465. add edi,[ dest_adjust_width ]
  1466. dec edx
  1467. jnz forward_loop_trans
  1468. jmp real_out //ret
  1469. ; ************************************************************************
  1470. ; backward bitblit
  1471. backupward_blit:
  1472. mov ebx,[ source_area ]
  1473. dec edx
  1474. add esi,eax
  1475. imul ebx,edx
  1476. std
  1477. lea esi,[ esi + ebx - 1 ]
  1478. mov ebx,[ dest_area ]
  1479. add edi,eax
  1480. imul ebx,edx
  1481. lea edi,[ edi + ebx - 1]
  1482. test [ trans ],1
  1483. jnz backward_Blit_trans
  1484. cmp eax,15
  1485. jl backward_loop_bytes
  1486. backward_loop_dword:
  1487. push edi
  1488. push esi
  1489. lea ecx,[edi+1]
  1490. mov ebx,eax
  1491. and ecx,3 ; Get non aligned bytes.
  1492. sub ebx,ecx ; remove that from the total size to be copied later.
  1493. rep movsb ; do the copy.
  1494. sub esi,3
  1495. mov ecx,ebx ; Get number of bytes left.
  1496. sub edi,3
  1497. shr ecx,2 ; Do 4 bytes at a time.
  1498. rep movsd ; do the dword copy.
  1499. mov ecx,ebx
  1500. add esi,3
  1501. add edi,3
  1502. and ecx,03h
  1503. rep movsb ; finnish the remaining bytes.
  1504. pop esi
  1505. pop edi
  1506. sub esi,[ source_area ]
  1507. sub edi,[ dest_area ]
  1508. dec edx
  1509. jge backward_loop_dword
  1510. cld
  1511. jmp real_out //ret
  1512. backward_loop_bytes:
  1513. push edi
  1514. mov ecx,eax ; remove that from the total size to be copied later.
  1515. push esi
  1516. rep movsb ; do the copy.
  1517. pop esi
  1518. pop edi
  1519. sub esi,[ source_area ]
  1520. sub edi,[ dest_area ]
  1521. dec edx
  1522. jge backward_loop_bytes
  1523. cld
  1524. jmp real_out //ret
  1525. backward_Blit_trans:
  1526. mov ecx,eax
  1527. and ecx,01fh
  1528. lea ecx,[ ecx + ecx * 4 ]
  1529. neg ecx
  1530. shr eax,5
  1531. lea ecx,[ back_transp_reference + ecx * 2 ]
  1532. mov [ y1_pixel ],ecx
  1533. backward_loop_trans:
  1534. mov ecx,eax
  1535. push edi
  1536. push esi
  1537. jmp [ y1_pixel ]
  1538. backward_trans_line:
  1539. //REPT 32
  1540. //local transp_pixel2
  1541. //No REPT in msvc inline assembly.
  1542. // Save ECX and use as counter instead. ST - 12/19/2018 5:41PM
  1543. push ecx
  1544. mov ecx, 32
  1545. rept_loop2:
  1546. mov bl,[ esi ]
  1547. test bl,bl
  1548. jz transp_pixel2
  1549. mov [ edi ],bl
  1550. transp_pixel2:
  1551. dec esi
  1552. dec edi
  1553. dec ecx //ST - 12/19/2018 5:44PM
  1554. jnz rept_loop2 //ST - 12/19/2018 5:44PM
  1555. pop ecx //ST - 12/19/2018 5:44PM
  1556. //ENDM
  1557. back_transp_reference:
  1558. dec ecx
  1559. jge backward_trans_line
  1560. pop esi
  1561. pop edi
  1562. sub esi,[ source_area ]
  1563. sub edi,[ dest_area ]
  1564. dec edx
  1565. jge backward_loop_trans
  1566. cld
  1567. //ret
  1568. real_out:
  1569. }
  1570. }
  1571. /*
  1572. ;***************************************************************************
  1573. ;* VVC::SCALE -- Scales a virtual viewport to another virtual viewport *
  1574. ;* *
  1575. ;* INPUT: *
  1576. ;* *
  1577. ;* OUTPUT: *
  1578. ;* *
  1579. ;* WARNINGS: *
  1580. ;* *
  1581. ;* HISTORY: *
  1582. ;* 06/16/1994 PWG : Created. *
  1583. ;*=========================================================================*
  1584. PROC Linear_Scale_To_Linear C NEAR
  1585. USES eax,ebx,ecx,edx,esi,edi
  1586. */
  1587. // Ran out of registers so had to use ebp. ST - 12/19/2018 6:22PM
  1588. #pragma warning (push)
  1589. #pragma warning (disable : 4731)
  1590. BOOL __cdecl Linear_Scale_To_Linear(void *this_object, void *dest, int src_x, int src_y, int dst_x, int dst_y, int src_width, int src_height, int dst_width, int dst_height, BOOL trans, char *remap)
  1591. {
  1592. /*
  1593. ;*===================================================================
  1594. ;* Define the arguements that our function takes.
  1595. ;*===================================================================
  1596. ARG this_object:DWORD ; pointer to source view port
  1597. ARG dest:DWORD ; pointer to destination view port
  1598. ARG src_x:DWORD ; source x offset into view port
  1599. ARG src_y:DWORD ; source y offset into view port
  1600. ARG dst_x:DWORD ; dest x offset into view port
  1601. ARG dst_y:DWORD ; dest y offset into view port
  1602. ARG src_width:DWORD ; width of source rectangle
  1603. ARG src_height:DWORD ; height of source rectangle
  1604. ARG dst_width:DWORD ; width of dest rectangle
  1605. ARG dst_height:DWORD ; width of dest height
  1606. ARG trans:DWORD ; is this transparent?
  1607. ARG remap:DWORD ; pointer to table to remap source
  1608. ;*===================================================================
  1609. ;* Define local variables to hold the viewport characteristics
  1610. ;*===================================================================
  1611. local src_x0 : dword
  1612. local src_y0 : dword
  1613. local src_x1 : dword
  1614. local src_y1 : dword
  1615. local dst_x0 : dword
  1616. local dst_y0 : dword
  1617. local dst_x1 : dword
  1618. local dst_y1 : dword
  1619. local src_win_width : dword
  1620. local dst_win_width : dword
  1621. local dy_intr : dword
  1622. local dy_frac : dword
  1623. local dy_acc : dword
  1624. local dx_frac : dword
  1625. local counter_x : dword
  1626. local counter_y : dword
  1627. local remap_counter :dword
  1628. local entry : dword
  1629. */
  1630. int src_x0;
  1631. int src_y0;
  1632. int src_x1;
  1633. int src_y1;
  1634. int dst_x0;
  1635. int dst_y0;
  1636. int dst_x1;
  1637. int dst_y1;
  1638. int src_win_width;
  1639. int dst_win_width;
  1640. int dy_intr;
  1641. int dy_frac;
  1642. int dy_acc;
  1643. int dx_frac;
  1644. int counter_x;
  1645. int counter_y;
  1646. int remap_counter;
  1647. int entry;
  1648. __asm {
  1649. ;*===================================================================
  1650. ;* Check for scale error when to or from size 0,0
  1651. ;*===================================================================
  1652. cmp [dst_width],0
  1653. je all_done
  1654. cmp [dst_height],0
  1655. je all_done
  1656. cmp [src_width],0
  1657. je all_done
  1658. cmp [src_height],0
  1659. je all_done
  1660. mov eax , [ src_x ]
  1661. mov ebx , [ src_y ]
  1662. mov [ src_x0 ] , eax
  1663. mov [ src_y0 ] , ebx
  1664. add eax , [ src_width ]
  1665. add ebx , [ src_height ]
  1666. mov [ src_x1 ] , eax
  1667. mov [ src_y1 ] , ebx
  1668. mov eax , [ dst_x ]
  1669. mov ebx , [ dst_y ]
  1670. mov [ dst_x0 ] , eax
  1671. mov [ dst_y0 ] , ebx
  1672. add eax , [ dst_width ]
  1673. add ebx , [ dst_height ]
  1674. mov [ dst_x1 ] , eax
  1675. mov [ dst_y1 ] , ebx
  1676. ; Clip Source Rectangle against source Window boundaries.
  1677. mov esi , [ this_object ] ; get ptr to src
  1678. xor ecx , ecx
  1679. xor edx , edx
  1680. mov edi , [esi]GraphicViewPortClass.Width ; get width into register
  1681. mov eax , [ src_x0 ]
  1682. mov ebx , [ src_x1 ]
  1683. shld ecx , eax , 1
  1684. inc edi
  1685. shld edx , ebx , 1
  1686. sub eax , edi
  1687. sub ebx , edi
  1688. shld ecx , eax , 1
  1689. shld edx , ebx , 1
  1690. mov edi,[esi]GraphicViewPortClass.Height ; get height into register
  1691. mov eax , [ src_y0 ]
  1692. mov ebx , [ src_y1 ]
  1693. shld ecx , eax , 1
  1694. inc edi
  1695. shld edx , ebx , 1
  1696. sub eax , edi
  1697. sub ebx , edi
  1698. shld ecx , eax , 1
  1699. shld edx , ebx , 1
  1700. xor cl , 5
  1701. xor dl , 5
  1702. mov al , cl
  1703. test dl , cl
  1704. jnz all_done
  1705. or al , dl
  1706. jz clip_against_dest
  1707. mov bl , dl
  1708. test cl , 1000b
  1709. jz src_left_ok
  1710. xor eax , eax
  1711. mov [ src_x0 ] , eax
  1712. sub eax , [ src_x ]
  1713. imul [ dst_width ]
  1714. idiv [ src_width ]
  1715. add eax , [ dst_x ]
  1716. mov [ dst_x0 ] , eax
  1717. src_left_ok:
  1718. test cl , 0010b
  1719. jz src_bottom_ok
  1720. xor eax , eax
  1721. mov [ src_y0 ] , eax
  1722. sub eax , [ src_y ]
  1723. imul [ dst_height ]
  1724. idiv [ src_height ]
  1725. add eax , [ dst_y ]
  1726. mov [ dst_y0 ] , eax
  1727. src_bottom_ok:
  1728. test bl , 0100b
  1729. jz src_right_ok
  1730. mov eax , [esi]GraphicViewPortClass.Width ; get width into register
  1731. mov [ src_x1 ] , eax
  1732. sub eax , [ src_x ]
  1733. imul [ dst_width ]
  1734. idiv [ src_width ]
  1735. add eax , [ dst_x ]
  1736. mov [ dst_x1 ] , eax
  1737. src_right_ok:
  1738. test bl , 0001b
  1739. jz clip_against_dest
  1740. mov eax , [esi]GraphicViewPortClass.Height ; get width into register
  1741. mov [ src_y1 ] , eax
  1742. sub eax , [ src_y ]
  1743. imul [ dst_height ]
  1744. idiv [ src_height ]
  1745. add eax , [ dst_y ]
  1746. mov [ dst_y1 ] , eax
  1747. ; Clip destination Rectangle against source Window boundaries.
  1748. clip_against_dest:
  1749. mov esi , [ dest ] ; get ptr to src
  1750. xor ecx , ecx
  1751. xor edx , edx
  1752. mov edi , [esi]GraphicViewPortClass.Width ; get width into register
  1753. mov eax , [ dst_x0 ]
  1754. mov ebx , [ dst_x1 ]
  1755. shld ecx , eax , 1
  1756. inc edi
  1757. shld edx , ebx , 1
  1758. sub eax , edi
  1759. sub ebx , edi
  1760. shld ecx , eax , 1
  1761. shld edx , ebx , 1
  1762. mov edi,[esi]GraphicViewPortClass.Height ; get height into register
  1763. mov eax , [ dst_y0 ]
  1764. mov ebx , [ dst_y1 ]
  1765. shld ecx , eax , 1
  1766. inc edi
  1767. shld edx , ebx , 1
  1768. sub eax , edi
  1769. sub ebx , edi
  1770. shld ecx , eax , 1
  1771. shld edx , ebx , 1
  1772. xor cl , 5
  1773. xor dl , 5
  1774. mov al , cl
  1775. test dl , cl
  1776. jnz all_done
  1777. or al , dl
  1778. jz do_scaling
  1779. mov bl , dl
  1780. test cl , 1000b
  1781. jz dst_left_ok
  1782. xor eax , eax
  1783. mov [ dst_x0 ] , eax
  1784. sub eax , [ dst_x ]
  1785. imul [ src_width ]
  1786. idiv [ dst_width ]
  1787. add eax , [ src_x ]
  1788. mov [ src_x0 ] , eax
  1789. dst_left_ok:
  1790. test cl , 0010b
  1791. jz dst_bottom_ok
  1792. xor eax , eax
  1793. mov [ dst_y0 ] , eax
  1794. sub eax , [ dst_y ]
  1795. imul [ src_height ]
  1796. idiv [ dst_height ]
  1797. add eax , [ src_y ]
  1798. mov [ src_y0 ] , eax
  1799. dst_bottom_ok:
  1800. test bl , 0100b
  1801. jz dst_right_ok
  1802. mov eax , [esi]GraphicViewPortClass.Width ; get width into register
  1803. mov [ dst_x1 ] , eax
  1804. sub eax , [ dst_x ]
  1805. imul [ src_width ]
  1806. idiv [ dst_width ]
  1807. add eax , [ src_x ]
  1808. mov [ src_x1 ] , eax
  1809. dst_right_ok:
  1810. test bl , 0001b
  1811. jz do_scaling
  1812. mov eax , [esi]GraphicViewPortClass.Height ; get width into register
  1813. mov [ dst_y1 ] , eax
  1814. sub eax , [ dst_y ]
  1815. imul [ src_height ]
  1816. idiv [ dst_height ]
  1817. add eax , [ src_y ]
  1818. mov [ src_y1 ] , eax
  1819. do_scaling:
  1820. cld
  1821. mov ebx , [ this_object ]
  1822. mov esi , [ebx]GraphicViewPortClass. Offset
  1823. mov eax , [ebx]GraphicViewPortClass. XAdd
  1824. add eax , [ebx]GraphicViewPortClass. Width
  1825. add eax , [ebx]GraphicViewPortClass. Pitch
  1826. mov [ src_win_width ] , eax
  1827. mul [ src_y0 ]
  1828. add esi , [ src_x0 ]
  1829. add esi , eax
  1830. mov ebx , [ dest ]
  1831. mov edi , [ebx]GraphicViewPortClass. Offset
  1832. mov eax , [ebx]GraphicViewPortClass. XAdd
  1833. add eax , [ebx]GraphicViewPortClass. Width
  1834. add eax , [ebx]GraphicViewPortClass. Pitch
  1835. mov [ dst_win_width ] , eax
  1836. mul [ dst_y0 ]
  1837. add edi , [ dst_x0 ]
  1838. add edi , eax
  1839. mov eax , [ src_height ]
  1840. xor edx , edx
  1841. mov ebx , [ dst_height ]
  1842. idiv [ dst_height ]
  1843. imul eax , [ src_win_width ]
  1844. neg ebx
  1845. mov [ dy_intr ] , eax
  1846. mov [ dy_frac ] , edx
  1847. mov [ dy_acc ] , ebx
  1848. mov eax , [ src_width ]
  1849. xor edx , edx
  1850. shl eax , 16
  1851. idiv [ dst_width ]
  1852. xor edx , edx
  1853. shld edx , eax , 16
  1854. shl eax , 16
  1855. mov ecx , [ dst_y1 ]
  1856. mov ebx , [ dst_x1 ]
  1857. sub ecx , [ dst_y0 ]
  1858. jle all_done
  1859. sub ebx , [ dst_x0 ]
  1860. jle all_done
  1861. mov [ counter_y ] , ecx
  1862. cmp [ trans ] , 0
  1863. jnz transparency
  1864. cmp [ remap ] , 0
  1865. jnz normal_remap
  1866. ; *************************************************************************
  1867. ; normal scale
  1868. mov ecx , ebx
  1869. and ecx , 01fh
  1870. lea ecx , [ ecx + ecx * 2 ]
  1871. shr ebx , 5
  1872. neg ecx
  1873. mov [ counter_x ] , ebx
  1874. lea ecx , [ ref_point + ecx + ecx * 2 ]
  1875. mov [ entry ] , ecx
  1876. outter_loop:
  1877. push esi
  1878. push edi
  1879. xor ecx , ecx
  1880. mov ebx , [ counter_x ]
  1881. jmp [ entry ]
  1882. inner_loop:
  1883. // REPT not supported for inline asm. ST - 12/19/2018 6:11PM
  1884. //REPT 32
  1885. push ebx //ST - 12/19/2018 6:11PM
  1886. mov ebx,32 //ST - 12/19/2018 6:11PM
  1887. rept_loop:
  1888. mov cl , [ esi ]
  1889. add ecx , eax
  1890. adc esi , edx
  1891. mov [ edi ] , cl
  1892. inc edi
  1893. dec ebx //ST - 12/19/2018 6:11PM
  1894. jnz rept_loop //ST - 12/19/2018 6:11PM
  1895. pop ebx //ST - 12/19/2018 6:11PM
  1896. //ENDM
  1897. ref_point:
  1898. dec ebx
  1899. jge inner_loop
  1900. pop edi
  1901. pop esi
  1902. add edi , [ dst_win_width ]
  1903. add esi , [ dy_intr ]
  1904. mov ebx , [ dy_acc ]
  1905. add ebx , [ dy_frac ]
  1906. jle skip_line
  1907. add esi , [ src_win_width ]
  1908. sub ebx , [ dst_height ]
  1909. skip_line:
  1910. dec [ counter_y ]
  1911. mov [ dy_acc ] , ebx
  1912. jnz outter_loop
  1913. jmp all_done //ret
  1914. ; *************************************************************************
  1915. ; normal scale with remap
  1916. normal_remap:
  1917. mov ecx , ebx
  1918. mov [ dx_frac ], eax
  1919. and ecx , 01fh
  1920. mov eax , [ remap ]
  1921. shr ebx , 5
  1922. imul ecx , - 13
  1923. mov [ counter_x ] , ebx
  1924. lea ecx , [ remapref_point + ecx ]
  1925. mov [ entry ] , ecx
  1926. remapoutter_loop:
  1927. mov ebx , [ counter_x ]
  1928. push esi
  1929. mov [ remap_counter ] , ebx
  1930. push edi
  1931. xor ecx , ecx
  1932. xor ebx , ebx
  1933. jmp [ entry ]
  1934. remapinner_loop:
  1935. // REPT not supported for inline asm. ST - 12/19/2018 6:11PM
  1936. //REPT 32
  1937. mov bl , [ esi ]
  1938. add ecx , [ dx_frac ]
  1939. adc esi , edx
  1940. mov cl , [ eax + ebx ]
  1941. mov [ edi ] , cl
  1942. inc edi
  1943. mov bl , [ esi ]
  1944. add ecx , [ dx_frac ]
  1945. adc esi , edx
  1946. mov cl , [ eax + ebx ]
  1947. mov [ edi ] , cl
  1948. inc edi
  1949. mov bl , [ esi ]
  1950. add ecx , [ dx_frac ]
  1951. adc esi , edx
  1952. mov cl , [ eax + ebx ]
  1953. mov [ edi ] , cl
  1954. inc edi
  1955. mov bl , [ esi ]
  1956. add ecx , [ dx_frac ]
  1957. adc esi , edx
  1958. mov cl , [ eax + ebx ]
  1959. mov [ edi ] , cl
  1960. inc edi
  1961. mov bl , [ esi ]
  1962. add ecx , [ dx_frac ]
  1963. adc esi , edx
  1964. mov cl , [ eax + ebx ]
  1965. mov [ edi ] , cl
  1966. inc edi
  1967. mov bl , [ esi ]
  1968. add ecx , [ dx_frac ]
  1969. adc esi , edx
  1970. mov cl , [ eax + ebx ]
  1971. mov [ edi ] , cl
  1972. inc edi
  1973. mov bl , [ esi ]
  1974. add ecx , [ dx_frac ]
  1975. adc esi , edx
  1976. mov cl , [ eax + ebx ]
  1977. mov [ edi ] , cl
  1978. inc edi
  1979. mov bl , [ esi ]
  1980. add ecx , [ dx_frac ]
  1981. adc esi , edx
  1982. mov cl , [ eax + ebx ]
  1983. mov [ edi ] , cl
  1984. inc edi
  1985. mov bl , [ esi ]
  1986. add ecx , [ dx_frac ]
  1987. adc esi , edx
  1988. mov cl , [ eax + ebx ]
  1989. mov [ edi ] , cl
  1990. inc edi
  1991. mov bl , [ esi ]
  1992. add ecx , [ dx_frac ]
  1993. adc esi , edx
  1994. mov cl , [ eax + ebx ]
  1995. mov [ edi ] , cl
  1996. inc edi
  1997. mov bl , [ esi ]
  1998. add ecx , [ dx_frac ]
  1999. adc esi , edx
  2000. mov cl , [ eax + ebx ]
  2001. mov [ edi ] , cl
  2002. inc edi
  2003. mov bl , [ esi ]
  2004. add ecx , [ dx_frac ]
  2005. adc esi , edx
  2006. mov cl , [ eax + ebx ]
  2007. mov [ edi ] , cl
  2008. inc edi
  2009. mov bl , [ esi ]
  2010. add ecx , [ dx_frac ]
  2011. adc esi , edx
  2012. mov cl , [ eax + ebx ]
  2013. mov [ edi ] , cl
  2014. inc edi
  2015. mov bl , [ esi ]
  2016. add ecx , [ dx_frac ]
  2017. adc esi , edx
  2018. mov cl , [ eax + ebx ]
  2019. mov [ edi ] , cl
  2020. inc edi
  2021. mov bl , [ esi ]
  2022. add ecx , [ dx_frac ]
  2023. adc esi , edx
  2024. mov cl , [ eax + ebx ]
  2025. mov [ edi ] , cl
  2026. inc edi
  2027. mov bl , [ esi ]
  2028. add ecx , [ dx_frac ]
  2029. adc esi , edx
  2030. mov cl , [ eax + ebx ]
  2031. mov [ edi ] , cl
  2032. inc edi
  2033. mov bl , [ esi ]
  2034. add ecx , [ dx_frac ]
  2035. adc esi , edx
  2036. mov cl , [ eax + ebx ]
  2037. mov [ edi ] , cl
  2038. inc edi
  2039. mov bl , [ esi ]
  2040. add ecx , [ dx_frac ]
  2041. adc esi , edx
  2042. mov cl , [ eax + ebx ]
  2043. mov [ edi ] , cl
  2044. inc edi
  2045. mov bl , [ esi ]
  2046. add ecx , [ dx_frac ]
  2047. adc esi , edx
  2048. mov cl , [ eax + ebx ]
  2049. mov [ edi ] , cl
  2050. inc edi
  2051. mov bl , [ esi ]
  2052. add ecx , [ dx_frac ]
  2053. adc esi , edx
  2054. mov cl , [ eax + ebx ]
  2055. mov [ edi ] , cl
  2056. inc edi
  2057. mov bl , [ esi ]
  2058. add ecx , [ dx_frac ]
  2059. adc esi , edx
  2060. mov cl , [ eax + ebx ]
  2061. mov [ edi ] , cl
  2062. inc edi
  2063. mov bl , [ esi ]
  2064. add ecx , [ dx_frac ]
  2065. adc esi , edx
  2066. mov cl , [ eax + ebx ]
  2067. mov [ edi ] , cl
  2068. inc edi
  2069. mov bl , [ esi ]
  2070. add ecx , [ dx_frac ]
  2071. adc esi , edx
  2072. mov cl , [ eax + ebx ]
  2073. mov [ edi ] , cl
  2074. inc edi
  2075. mov bl , [ esi ]
  2076. add ecx , [ dx_frac ]
  2077. adc esi , edx
  2078. mov cl , [ eax + ebx ]
  2079. mov [ edi ] , cl
  2080. inc edi
  2081. mov bl , [ esi ]
  2082. add ecx , [ dx_frac ]
  2083. adc esi , edx
  2084. mov cl , [ eax + ebx ]
  2085. mov [ edi ] , cl
  2086. inc edi
  2087. mov bl , [ esi ]
  2088. add ecx , [ dx_frac ]
  2089. adc esi , edx
  2090. mov cl , [ eax + ebx ]
  2091. mov [ edi ] , cl
  2092. inc edi
  2093. mov bl , [ esi ]
  2094. add ecx , [ dx_frac ]
  2095. adc esi , edx
  2096. mov cl , [ eax + ebx ]
  2097. mov [ edi ] , cl
  2098. inc edi
  2099. mov bl , [ esi ]
  2100. add ecx , [ dx_frac ]
  2101. adc esi , edx
  2102. mov cl , [ eax + ebx ]
  2103. mov [ edi ] , cl
  2104. inc edi
  2105. mov bl , [ esi ]
  2106. add ecx , [ dx_frac ]
  2107. adc esi , edx
  2108. mov cl , [ eax + ebx ]
  2109. mov [ edi ] , cl
  2110. inc edi
  2111. mov bl , [ esi ]
  2112. add ecx , [ dx_frac ]
  2113. adc esi , edx
  2114. mov cl , [ eax + ebx ]
  2115. mov [ edi ] , cl
  2116. inc edi
  2117. mov bl , [ esi ]
  2118. add ecx , [ dx_frac ]
  2119. adc esi , edx
  2120. mov cl , [ eax + ebx ]
  2121. mov [ edi ] , cl
  2122. inc edi
  2123. mov bl , [ esi ]
  2124. add ecx , [ dx_frac ]
  2125. adc esi , edx
  2126. mov cl , [ eax + ebx ]
  2127. mov [ edi ] , cl
  2128. inc edi
  2129. //ENDM
  2130. remapref_point:
  2131. dec [ remap_counter ]
  2132. jge remapinner_loop
  2133. pop edi
  2134. pop esi
  2135. add edi , [ dst_win_width ]
  2136. add esi , [ dy_intr ]
  2137. mov ebx , [ dy_acc ]
  2138. add ebx , [ dy_frac ]
  2139. jle remapskip_line
  2140. add esi , [ src_win_width ]
  2141. sub ebx , [ dst_height ]
  2142. remapskip_line:
  2143. dec [ counter_y ]
  2144. mov [ dy_acc ] , ebx
  2145. jnz remapoutter_loop
  2146. jmp all_done //ret
  2147. ;****************************************************************************
  2148. ; scale with trnsparency
  2149. transparency:
  2150. cmp [ remap ] , 0
  2151. jnz trans_remap
  2152. ; *************************************************************************
  2153. ; normal scale with transparency
  2154. mov ecx , ebx
  2155. and ecx , 01fh
  2156. imul ecx , -13
  2157. shr ebx , 5
  2158. mov [ counter_x ] , ebx
  2159. lea ecx , [ trans_ref_point + ecx ]
  2160. mov [ entry ] , ecx
  2161. trans_outter_loop:
  2162. xor ecx , ecx
  2163. push esi
  2164. push edi
  2165. mov ebx , [ counter_x ]
  2166. jmp [ entry ]
  2167. trans_inner_loop:
  2168. // REPT not supported for inline asm. ST - 12/19/2018 6:11PM
  2169. //REPT 32
  2170. push ebx //ST - 12/19/2018 6:11PM
  2171. mov ebx,32 //ST - 12/19/2018 6:11PM
  2172. rept_loop2:
  2173. mov cl , [ esi ]
  2174. test cl , cl
  2175. jz trans_pixel
  2176. mov [ edi ] , cl
  2177. trans_pixel:
  2178. add ecx , eax
  2179. adc esi , edx
  2180. inc edi
  2181. dec ebx //ST - 12/19/2018 6:11PM
  2182. jnz rept_loop2 //ST - 12/19/2018 6:11PM
  2183. pop ebx //ST - 12/19/2018 6:11PM
  2184. //ENDM
  2185. trans_ref_point:
  2186. dec ebx
  2187. jge trans_inner_loop
  2188. pop edi
  2189. pop esi
  2190. add edi , [ dst_win_width ]
  2191. add esi , [ dy_intr ]
  2192. mov ebx , [ dy_acc ]
  2193. add ebx , [ dy_frac ]
  2194. jle trans_skip_line
  2195. add esi , [ src_win_width ]
  2196. sub ebx , [ dst_height ]
  2197. trans_skip_line:
  2198. dec [ counter_y ]
  2199. mov [ dy_acc ] , ebx
  2200. jnz trans_outter_loop
  2201. jmp all_done //ret
  2202. ; *************************************************************************
  2203. ; normal scale with remap
  2204. trans_remap:
  2205. mov ecx , ebx
  2206. mov [ dx_frac ], eax
  2207. and ecx , 01fh
  2208. mov eax , [ remap ]
  2209. shr ebx , 5
  2210. imul ecx , - 17
  2211. mov [ counter_x ] , ebx
  2212. lea ecx , [ trans_remapref_point + ecx ]
  2213. mov [ entry ] , ecx
  2214. trans_remapoutter_loop:
  2215. mov ebx , [ counter_x ]
  2216. push esi
  2217. mov [ remap_counter ] , ebx
  2218. push edi
  2219. xor ecx , ecx
  2220. xor ebx , ebx
  2221. jmp [ entry ]
  2222. trans_remapinner_loop:
  2223. // REPT not supported for inline asm. ST - 12/19/2018 6:11PM
  2224. //REPT 32
  2225. // Run out of registers so use ebp
  2226. push ebp //ST - 12/19/2018 6:11PM
  2227. mov ebp,32 //ST - 12/19/2018 6:11PM
  2228. rept_loop3:
  2229. mov bl , [ esi ]
  2230. test bl , bl
  2231. jz trans_pixel2
  2232. mov cl , [ eax + ebx ]
  2233. mov [ edi ] , cl
  2234. trans_pixel2:
  2235. add ecx , [ dx_frac ]
  2236. adc esi , edx
  2237. inc edi
  2238. dec ebp //ST - 12/19/2018 6:11PM
  2239. jnz rept_loop3 //ST - 12/19/2018 6:11PM
  2240. pop ebp //ST - 12/19/2018 6:11PM
  2241. //ENDM
  2242. trans_remapref_point:
  2243. dec [ remap_counter ]
  2244. jge trans_remapinner_loop
  2245. pop edi
  2246. pop esi
  2247. add edi , [ dst_win_width ]
  2248. add esi , [ dy_intr ]
  2249. mov ebx , [ dy_acc ]
  2250. add ebx , [ dy_frac ]
  2251. jle trans_remapskip_line
  2252. add esi , [ src_win_width ]
  2253. sub ebx , [ dst_height ]
  2254. trans_remapskip_line:
  2255. dec [ counter_y ]
  2256. mov [ dy_acc ] , ebx
  2257. jnz trans_remapoutter_loop
  2258. //ret
  2259. all_done:
  2260. }
  2261. }
  2262. #pragma warning (pop)
  2263. unsigned int LastIconset = 0;
  2264. unsigned int StampPtr = 0; // DD 0 ; Pointer to icon data.
  2265. unsigned int IsTrans = 0; // DD 0 ; Pointer to transparent icon flag table.
  2266. unsigned int MapPtr = 0; // DD 0 ; Pointer to icon map.
  2267. unsigned int IconWidth = 0; // DD 0 ; Width of icon in pixels.
  2268. unsigned int IconHeight = 0; // DD 0 ; Height of icon in pixels.
  2269. unsigned int IconSize = 0; // DD 0 ; Number of bytes for each icon data.
  2270. unsigned int IconCount = 0; // DD 0 ; Number of icons in the set.
  2271. #if (0)
  2272. LastIconset DD 0 ; Pointer to last iconset initialized.
  2273. StampPtr DD 0 ; Pointer to icon data.
  2274. IsTrans DD 0 ; Pointer to transparent icon flag table.
  2275. MapPtr DD 0 ; Pointer to icon map.
  2276. IconWidth DD 0 ; Width of icon in pixels.
  2277. IconHeight DD 0 ; Height of icon in pixels.
  2278. IconSize DD 0 ; Number of bytes for each icon data.
  2279. IconCount DD 0 ; Number of icons in the set.
  2280. GLOBAL C Buffer_Draw_Stamp:near
  2281. GLOBAL C Buffer_Draw_Stamp_Clip:near
  2282. ; 256 color icon system.
  2283. #endif
  2284. /*
  2285. ;***********************************************************
  2286. ; INIT_STAMPS
  2287. ;
  2288. ; VOID cdecl Init_Stamps(VOID *icondata);
  2289. ;
  2290. ; This routine initializes the stamp data.
  2291. ; Bounds Checking: NONE
  2292. ;
  2293. ;*
  2294. */
  2295. extern "C" void __cdecl Init_Stamps(unsigned int icondata)
  2296. {
  2297. __asm {
  2298. pushad // ST - 12/20/2018 10:30AM
  2299. ; Verify legality of parameter.
  2300. cmp [icondata],0
  2301. je short fini
  2302. ; Don't initialize if already initialized to this set (speed reasons).
  2303. mov edi,[icondata]
  2304. cmp [LastIconset],edi
  2305. je short fini
  2306. mov [LastIconset],edi
  2307. ; Record number of icons in set.
  2308. movzx eax,[edi]IControl_Type.Count
  2309. mov [IconCount],eax
  2310. ; Record width of icon.
  2311. movzx eax,[edi]IControl_Type.Width
  2312. mov [IconWidth],eax
  2313. ; Record height of icon.
  2314. movzx ebx,[edi]IControl_Type.Height
  2315. mov [IconHeight],ebx
  2316. ; Record size of icon (in bytes).
  2317. mul ebx
  2318. mov [IconSize],eax
  2319. ; Record hard pointer to icon map data.
  2320. mov eax,[edi]IControl_Type.Map
  2321. add eax,edi
  2322. mov [MapPtr],eax
  2323. //nomap:
  2324. ; Record hard pointer to icon data.
  2325. mov eax,edi
  2326. add eax,[edi]IControl_Type.Icons
  2327. mov [StampPtr],eax
  2328. ; Record the transparent table.
  2329. mov eax,edi
  2330. add eax,[edi]IControl_Type.TransFlag
  2331. mov [IsTrans],eax
  2332. fini:
  2333. popad // ST - 12/20/2018 10:30AM
  2334. }
  2335. }
  2336. /*
  2337. ;***********************************************************
  2338. ;***********************************************************
  2339. ; DRAW_STAMP
  2340. ;
  2341. ; VOID cdecl Buffer_Draw_Stamp(VOID *icondata, WORD icon, WORD x_pixel, WORD y_pixel, VOID *remap);
  2342. ;
  2343. ; This routine renders the icon at the given coordinate.
  2344. ;
  2345. ; The remap table is a 256 byte simple pixel translation table to use when
  2346. ; drawing the icon. Transparency check is performed AFTER the remap so it is possible to
  2347. ; remap valid colors to be invisible (for special effect reasons).
  2348. ; This routine is fastest when no remap table is passed in.
  2349. ;*
  2350. */
  2351. void __cdecl Buffer_Draw_Stamp(void const *this_object, void const *icondata, int icon, int x_pixel, int y_pixel, void const *remap)
  2352. {
  2353. unsigned int modulo = 0;
  2354. unsigned int iwidth = 0;
  2355. unsigned char doremap = 0;
  2356. /*
  2357. PROC Buffer_Draw_Stamp C near
  2358. ARG this_object:DWORD ; this is a member function
  2359. ARG icondata:DWORD ; Pointer to icondata.
  2360. ARG icon:DWORD ; Icon number to draw.
  2361. ARG x_pixel:DWORD ; X coordinate of icon.
  2362. ARG y_pixel:DWORD ; Y coordinate of icon.
  2363. ARG remap:DWORD ; Remap table.
  2364. LOCAL modulo:DWORD ; Modulo to get to next row.
  2365. LOCAL iwidth:DWORD ; Icon width (here for speedy access).
  2366. LOCAL doremap:BYTE ; Should remapping occur?
  2367. */
  2368. __asm {
  2369. pushad
  2370. cmp [icondata],0
  2371. je proc_out
  2372. ; Initialize the stamp data if necessary.
  2373. mov eax,[icondata]
  2374. cmp [LastIconset],eax
  2375. je short noreset
  2376. push eax
  2377. call Init_Stamps
  2378. pop eax // Clean up stack. ST - 12/20/2018 10:42AM
  2379. noreset:
  2380. ; Determine if the icon number requested is actually in the set.
  2381. ; Perform the logical icon to actual icon number remap if necessary.
  2382. mov ebx,[icon]
  2383. cmp [MapPtr],0
  2384. je short notmap
  2385. mov edi,[MapPtr]
  2386. mov bl,[edi+ebx]
  2387. notmap:
  2388. cmp ebx,[IconCount]
  2389. jae proc_out
  2390. mov [icon],ebx ; Updated icon number.
  2391. ; If the remap table pointer passed in is NULL, then flag this condition
  2392. ; so that the faster (non-remapping) icon draw loop will be used.
  2393. cmp [remap],0
  2394. setne [doremap]
  2395. ; Get pointer to position to render icon. EDI = ptr to destination page.
  2396. mov ebx,[this_object]
  2397. mov edi,[ebx]GraphicViewPortClass.Offset
  2398. mov eax,[ebx]GraphicViewPortClass.Width
  2399. add eax,[ebx]GraphicViewPortClass.XAdd
  2400. add eax,[ebx]GraphicViewPortClass.Pitch
  2401. push eax ; save viewport full width for lower
  2402. mul [y_pixel]
  2403. add edi,eax
  2404. add edi,[x_pixel]
  2405. ; Determine row modulo for advancing to next line.
  2406. pop eax ; retrieve viewport width
  2407. sub eax,[IconWidth]
  2408. mov [modulo],eax
  2409. ; Setup some working variables.
  2410. mov ecx,[IconHeight] ; Row counter.
  2411. mov eax,[IconWidth]
  2412. mov [iwidth],eax ; Stack copy of byte width for easy BP access.
  2413. ; Fetch pointer to start of icon's data. ESI = ptr to icon data.
  2414. mov eax,[icon]
  2415. mul [IconSize]
  2416. mov esi,[StampPtr]
  2417. add esi,eax
  2418. ; Determine whether simple icon draw is sufficient or whether the
  2419. ; extra remapping icon draw is needed.
  2420. cmp [BYTE PTR doremap],0
  2421. je short istranscheck
  2422. ;************************************************************
  2423. ; Complex icon draw -- extended remap.
  2424. ; EBX = Palette pointer (ready for XLAT instruction).
  2425. ; EDI = Pointer to icon destination in page.
  2426. ; ESI = Pointer to icon data.
  2427. ; ECX = Number of pixel rows.
  2428. ;;; mov edx,[remap]
  2429. mov ebx,[remap]
  2430. xor eax,eax
  2431. xrowloop:
  2432. push ecx
  2433. mov ecx,[iwidth]
  2434. xcolumnloop:
  2435. lodsb
  2436. ;;; mov ebx,edx
  2437. ;;; add ebx,eax
  2438. ;;; mov al,[ebx] ; New real color to draw.
  2439. xlatb
  2440. or al,al
  2441. jz short xskip1 ; Transparency skip check.
  2442. mov [edi],al
  2443. xskip1:
  2444. inc edi
  2445. loop xcolumnloop
  2446. pop ecx
  2447. add edi,[modulo]
  2448. loop xrowloop
  2449. jmp short proc_out
  2450. ;************************************************************
  2451. ; Check to see if transparent or generic draw is necessary.
  2452. istranscheck:
  2453. mov ebx,[IsTrans]
  2454. add ebx,[icon]
  2455. cmp [BYTE PTR ebx],0
  2456. jne short rowloop
  2457. ;************************************************************
  2458. ; Fast non-transparent icon draw routine.
  2459. ; ES:DI = Pointer to icon destination in page.
  2460. ; DS:SI = Pointer to icon data.
  2461. ; CX = Number of pixel rows.
  2462. mov ebx,ecx
  2463. shr ebx,2
  2464. mov edx,[modulo]
  2465. mov eax,[iwidth]
  2466. shr eax,2
  2467. loop1:
  2468. mov ecx,eax
  2469. rep movsd
  2470. add edi,edx
  2471. mov ecx,eax
  2472. rep movsd
  2473. add edi,edx
  2474. mov ecx,eax
  2475. rep movsd
  2476. add edi,edx
  2477. mov ecx,eax
  2478. rep movsd
  2479. add edi,edx
  2480. dec ebx
  2481. jnz loop1
  2482. jmp short proc_out
  2483. ;************************************************************
  2484. ; Transparent icon draw routine -- no extended remap.
  2485. ; ES:DI = Pointer to icon destination in page.
  2486. ; DS:SI = Pointer to icon data.
  2487. ; CX = Number of pixel rows.
  2488. rowloop:
  2489. push ecx
  2490. mov ecx,[iwidth]
  2491. columnloop:
  2492. lodsb
  2493. or al,al
  2494. jz short skip1 ; Transparency check.
  2495. mov [edi],al
  2496. skip1:
  2497. inc edi
  2498. loop columnloop
  2499. pop ecx
  2500. add edi,[modulo]
  2501. loop rowloop
  2502. ; Cleanup and exit icon drawing routine.
  2503. proc_out:
  2504. popad
  2505. //ret
  2506. }
  2507. }
  2508. /*
  2509. ;***********************************************************
  2510. ; DRAW_STAMP_CLIP
  2511. ;
  2512. ; VOID cdecl MCGA_Draw_Stamp_Clip(VOID *icondata, WORD icon, WORD x_pixel, WORD y_pixel, VOID *remap, LONG min_x, LONG min_y, LONG max_x, LONG max_y);
  2513. ;
  2514. ; This routine renders the icon at the given coordinate.
  2515. ;
  2516. ; The remap table is a 256 byte simple pixel translation table to use when
  2517. ; drawing the icon. Transparency check is performed AFTER the remap so it is possible to
  2518. ; remap valid colors to be invisible (for special effect reasons).
  2519. ; This routine is fastest when no remap table is passed in.
  2520. ;*
  2521. */
  2522. void __cdecl Buffer_Draw_Stamp_Clip(void const *this_object, void const *icondata, int icon, int x_pixel, int y_pixel, void const *remap, int min_x, int min_y, int max_x, int max_y)
  2523. {
  2524. unsigned int modulo = 0;
  2525. unsigned int iwidth = 0;
  2526. unsigned int skip = 0;
  2527. unsigned char doremap = 0;
  2528. /*
  2529. ARG this_object:DWORD ; this is a member function
  2530. ARG icondata:DWORD ; Pointer to icondata.
  2531. ARG icon:DWORD ; Icon number to draw.
  2532. ARG x_pixel:DWORD ; X coordinate of icon.
  2533. ARG y_pixel:DWORD ; Y coordinate of icon.
  2534. ARG remap:DWORD ; Remap table.
  2535. ARG min_x:DWORD ; Clipping rectangle boundary
  2536. ARG min_y:DWORD ; Clipping rectangle boundary
  2537. ARG max_x:DWORD ; Clipping rectangle boundary
  2538. ARG max_y:DWORD ; Clipping rectangle boundary
  2539. LOCAL modulo:DWORD ; Modulo to get to next row.
  2540. LOCAL iwidth:DWORD ; Icon width (here for speedy access).
  2541. LOCAL skip:DWORD ; amount to skip per row of icon data
  2542. LOCAL doremap:BYTE ; Should remapping occur?
  2543. */
  2544. __asm {
  2545. pushad
  2546. cmp [icondata],0
  2547. je proc_out
  2548. ; Initialize the stamp data if necessary.
  2549. mov eax,[icondata]
  2550. cmp [LastIconset],eax
  2551. je short noreset2
  2552. push eax
  2553. call Init_Stamps
  2554. pop eax // Clean up stack. ST - 12/20/2018 10:42AM
  2555. noreset2:
  2556. ; Determine if the icon number requested is actually in the set.
  2557. ; Perform the logical icon to actual icon number remap if necessary.
  2558. mov ebx,[icon]
  2559. cmp [MapPtr],0
  2560. je short notmap2
  2561. mov edi,[MapPtr]
  2562. mov bl,[edi+ebx]
  2563. notmap2:
  2564. cmp ebx,[IconCount]
  2565. jae proc_out
  2566. mov [icon],ebx ; Updated icon number.
  2567. ; Setup some working variables.
  2568. mov ecx,[IconHeight] ; Row counter.
  2569. mov eax,[IconWidth]
  2570. mov [iwidth],eax ; Stack copy of byte width for easy BP access.
  2571. ; Fetch pointer to start of icon's data. ESI = ptr to icon data.
  2572. mov eax,[icon]
  2573. mul [IconSize]
  2574. mov esi,[StampPtr]
  2575. add esi,eax
  2576. ; Update the clipping window coordinates to be valid maxes instead of width & height
  2577. ; , and change the coordinates to be window-relative
  2578. mov ebx,[min_x]
  2579. add [max_x],ebx
  2580. add [x_pixel],ebx ; make it window-relative
  2581. mov ebx,[min_y]
  2582. add [max_y],ebx
  2583. add [y_pixel],ebx ; make it window-relative
  2584. ; See if the icon is within the clipping window
  2585. ; First, verify that the icon position is less than the maximums
  2586. mov ebx,[x_pixel]
  2587. cmp ebx,[max_x]
  2588. jge proc_out
  2589. mov ebx,[y_pixel]
  2590. cmp ebx,[max_y]
  2591. jge proc_out
  2592. ; Now verify that the icon position is >= the minimums
  2593. add ebx,[IconHeight]
  2594. cmp ebx,[min_y]
  2595. jle proc_out
  2596. mov ebx,[x_pixel]
  2597. add ebx,[IconWidth]
  2598. cmp ebx,[min_x]
  2599. jle proc_out
  2600. ; Now, clip the x, y, width, and height variables to be within the
  2601. ; clipping rectangle
  2602. mov ebx,[x_pixel]
  2603. cmp ebx,[min_x]
  2604. jge nominxclip
  2605. ; x < minx, so must clip
  2606. mov ebx,[min_x]
  2607. sub ebx,[x_pixel]
  2608. add esi,ebx ; source ptr += (minx - x)
  2609. sub [iwidth],ebx ; icon width -= (minx - x)
  2610. mov ebx,[min_x]
  2611. mov [x_pixel],ebx
  2612. nominxclip:
  2613. mov eax,[IconWidth]
  2614. sub eax,[iwidth]
  2615. mov [skip],eax
  2616. ; Check for x+width > max_x
  2617. mov eax,[x_pixel]
  2618. add eax,[iwidth]
  2619. cmp eax,[max_x]
  2620. jle nomaxxclip
  2621. ; x+width is greater than max_x, so must clip width down
  2622. mov eax,[iwidth] ; eax = old width
  2623. mov ebx,[max_x]
  2624. sub ebx,[x_pixel]
  2625. mov [iwidth],ebx ; iwidth = max_x - xpixel
  2626. sub eax,ebx
  2627. add [skip],eax ; skip += (old width - iwidth)
  2628. nomaxxclip:
  2629. ; check if y < miny
  2630. mov eax,[min_y]
  2631. cmp eax,[y_pixel] ; if(miny <= y_pixel), no clip needed
  2632. jle nominyclip
  2633. sub eax,[y_pixel]
  2634. sub ecx,eax ; height -= (miny - y)
  2635. mul [IconWidth]
  2636. add esi,eax ; icon source ptr += (width * (miny - y))
  2637. mov eax,[min_y]
  2638. mov [y_pixel],eax ; y = miny
  2639. nominyclip:
  2640. ; check if (y+height) > max y
  2641. mov eax,[y_pixel]
  2642. add eax,ecx
  2643. cmp eax,[max_y] ; if (y + height <= max_y), no clip needed
  2644. jle nomaxyclip
  2645. mov ecx,[max_y] ; height = max_y - y_pixel
  2646. sub ecx,[y_pixel]
  2647. nomaxyclip:
  2648. ; If the remap table pointer passed in is NULL, then flag this condition
  2649. ; so that the faster (non-remapping) icon draw loop will be used.
  2650. cmp [remap],0
  2651. setne [doremap]
  2652. ; Get pointer to position to render icon. EDI = ptr to destination page.
  2653. mov ebx,[this_object]
  2654. mov edi,[ebx]GraphicViewPortClass.Offset
  2655. mov eax,[ebx]GraphicViewPortClass.Width
  2656. add eax,[ebx]GraphicViewPortClass.XAdd
  2657. add eax,[ebx]GraphicViewPortClass.Pitch
  2658. push eax ; save viewport full width for lower
  2659. mul [y_pixel]
  2660. add edi,eax
  2661. add edi,[x_pixel]
  2662. ; Determine row modulo for advancing to next line.
  2663. pop eax ; retrieve viewport width
  2664. sub eax,[iwidth]
  2665. mov [modulo],eax
  2666. ; Determine whether simple icon draw is sufficient or whether the
  2667. ; extra remapping icon draw is needed.
  2668. cmp [BYTE PTR doremap],0
  2669. je short istranscheck2
  2670. ;************************************************************
  2671. ; Complex icon draw -- extended remap.
  2672. ; EBX = Palette pointer (ready for XLAT instruction).
  2673. ; EDI = Pointer to icon destination in page.
  2674. ; ESI = Pointer to icon data.
  2675. ; ECX = Number of pixel rows.
  2676. mov ebx,[remap]
  2677. xor eax,eax
  2678. xrowloopc:
  2679. push ecx
  2680. mov ecx,[iwidth]
  2681. xcolumnloopc:
  2682. lodsb
  2683. xlatb
  2684. or al,al
  2685. jz short xskip1c ; Transparency skip check.
  2686. mov [edi],al
  2687. xskip1c:
  2688. inc edi
  2689. loop xcolumnloopc
  2690. pop ecx
  2691. add edi,[modulo]
  2692. add esi,[skip]
  2693. loop xrowloopc
  2694. jmp short proc_out
  2695. ;************************************************************
  2696. ; Check to see if transparent or generic draw is necessary.
  2697. istranscheck2:
  2698. mov ebx,[IsTrans]
  2699. add ebx,[icon]
  2700. cmp [BYTE PTR ebx],0
  2701. jne short rowloopc
  2702. ;************************************************************
  2703. ; Fast non-transparent icon draw routine.
  2704. ; ES:DI = Pointer to icon destination in page.
  2705. ; DS:SI = Pointer to icon data.
  2706. ; CX = Number of pixel rows.
  2707. mov ebx,ecx
  2708. mov edx,[modulo]
  2709. mov eax,[iwidth]
  2710. ;
  2711. ; Optimise copy by dword aligning the destination
  2712. ;
  2713. loop1c:
  2714. push eax
  2715. //rept 3 // No rept in inline asm. ST - 12/20/2018 10:43AM
  2716. test edi,3
  2717. jz aligned
  2718. movsb
  2719. dec eax
  2720. jz finishedit
  2721. test edi,3
  2722. jz aligned
  2723. movsb
  2724. dec eax
  2725. jz finishedit
  2726. test edi,3
  2727. jz aligned
  2728. movsb
  2729. dec eax
  2730. jz finishedit
  2731. //endm
  2732. aligned:
  2733. mov ecx,eax
  2734. shr ecx,2
  2735. rep movsd
  2736. mov ecx,eax
  2737. and ecx,3
  2738. rep movsb
  2739. finishedit:
  2740. add edi,edx
  2741. add esi,[skip]
  2742. pop eax
  2743. dec ebx
  2744. jnz loop1c
  2745. jmp short proc_out
  2746. ;************************************************************
  2747. ; Transparent icon draw routine -- no extended remap.
  2748. ; ES:DI = Pointer to icon destination in page.
  2749. ; DS:SI = Pointer to icon data.
  2750. ; CX = Number of pixel rows.
  2751. rowloopc:
  2752. push ecx
  2753. mov ecx,[iwidth]
  2754. columnloopc:
  2755. lodsb
  2756. or al,al
  2757. jz short skip1c ; Transparency check.
  2758. mov [edi],al
  2759. skip1c:
  2760. inc edi
  2761. loop columnloopc
  2762. pop ecx
  2763. add edi,[modulo]
  2764. add esi,[skip]
  2765. loop rowloopc
  2766. ; Cleanup and exit icon drawing routine.
  2767. proc_out:
  2768. popad
  2769. //ret
  2770. }
  2771. }
  2772. VOID __cdecl Buffer_Draw_Line(void *thisptr, int sx, int sy, int dx, int dy, unsigned char color);
  2773. VOID __cdecl Buffer_Fill_Rect(void *thisptr, int sx, int sy, int dx, int dy, unsigned char color);
  2774. VOID __cdecl Buffer_Remap(void * thisptr, int sx, int sy, int width, int height, void *remap);
  2775. VOID __cdecl Buffer_Fill_Quad(void * thisptr, VOID *span_buff, int x0, int y0, int x1, int y1,
  2776. int x2, int y2, int x3, int y3, int color);
  2777. void __cdecl Buffer_Draw_Stamp(void const *thisptr, void const *icondata, int icon, int x_pixel, int y_pixel, void const *remap);
  2778. void __cdecl Buffer_Draw_Stamp_Clip(void const *thisptr, void const *icondata, int icon, int x_pixel, int y_pixel, void const *remap, int ,int,int,int);
  2779. void * __cdecl Get_Font_Palette_Ptr ( void );
  2780. /*
  2781. ;***************************************************************************
  2782. ;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  2783. ;***************************************************************************
  2784. ;* *
  2785. ;* Project Name : Westwood 32 bit Library *
  2786. ;* *
  2787. ;* File Name : REMAP.ASM *
  2788. ;* *
  2789. ;* Programmer : Phil W. Gorrow *
  2790. ;* *
  2791. ;* Start Date : July 1, 1994 *
  2792. ;* *
  2793. ;* Last Update : July 1, 1994 [PWG] *
  2794. ;* *
  2795. ;*-------------------------------------------------------------------------*
  2796. ;* Functions: *
  2797. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  2798. */
  2799. VOID __cdecl Buffer_Remap(void * this_object, int sx, int sy, int width, int height, void *remap)
  2800. {
  2801. /*
  2802. PROC Buffer_Remap C NEAR
  2803. USES eax,ebx,ecx,edx,esi,edi
  2804. ;*===================================================================
  2805. ;* Define the arguements that our function takes.
  2806. ;*===================================================================
  2807. ARG this_object:DWORD
  2808. ARG x0_pixel:DWORD
  2809. ARG y0_pixel:DWORD
  2810. ARG region_width:DWORD
  2811. ARG region_height:DWORD
  2812. ARG remap :DWORD
  2813. ;*===================================================================
  2814. ; Define some locals so that we can handle things quickly
  2815. ;*===================================================================
  2816. local x1_pixel : DWORD
  2817. local y1_pixel : DWORD
  2818. local win_width : dword
  2819. local counter_x : dword
  2820. */
  2821. unsigned int x0_pixel = (unsigned int) sx;
  2822. unsigned int y0_pixel = (unsigned int) sy;
  2823. unsigned int region_width = (unsigned int) width;
  2824. unsigned int region_height = (unsigned int) height;
  2825. unsigned int x1_pixel = 0;
  2826. unsigned int y1_pixel = 0;
  2827. unsigned int win_width = 0;
  2828. unsigned int counter_x = 0;
  2829. __asm {
  2830. cmp [ remap ] , 0
  2831. jz real_out
  2832. ; Clip Source Rectangle against source Window boundaries.
  2833. mov esi , [ this_object ] ; get ptr to src
  2834. xor ecx , ecx
  2835. xor edx , edx
  2836. mov edi , [esi]GraphicViewPortClass.Width ; get width into register
  2837. mov ebx , [ x0_pixel ]
  2838. mov eax , [ x0_pixel ]
  2839. add ebx , [ region_width ]
  2840. shld ecx , eax , 1
  2841. mov [ x1_pixel ] , ebx
  2842. inc edi
  2843. shld edx , ebx , 1
  2844. sub eax , edi
  2845. sub ebx , edi
  2846. shld ecx , eax , 1
  2847. shld edx , ebx , 1
  2848. mov edi,[esi]GraphicViewPortClass.Height ; get height into register
  2849. mov ebx , [ y0_pixel ]
  2850. mov eax , [ y0_pixel ]
  2851. add ebx , [ region_height ]
  2852. shld ecx , eax , 1
  2853. mov [ y1_pixel ] , ebx
  2854. inc edi
  2855. shld edx , ebx , 1
  2856. sub eax , edi
  2857. sub ebx , edi
  2858. shld ecx , eax , 1
  2859. shld edx , ebx , 1
  2860. xor cl , 5
  2861. xor dl , 5
  2862. mov al , cl
  2863. test dl , cl
  2864. jnz real_out
  2865. or al , dl
  2866. jz do_remap
  2867. test cl , 1000b
  2868. jz scr_left_ok
  2869. mov [ x0_pixel ] , 0
  2870. scr_left_ok:
  2871. test cl , 0010b
  2872. jz scr_bottom_ok
  2873. mov [ y0_pixel ] , 0
  2874. scr_bottom_ok:
  2875. test dl , 0100b
  2876. jz scr_right_ok
  2877. mov eax , [esi]GraphicViewPortClass.Width ; get width into register
  2878. mov [ x1_pixel ] , eax
  2879. scr_right_ok:
  2880. test dl , 0001b
  2881. jz do_remap
  2882. mov eax , [esi]GraphicViewPortClass.Height ; get width into register
  2883. mov [ y1_pixel ] , eax
  2884. do_remap:
  2885. cld
  2886. mov edi , [esi]GraphicViewPortClass.Offset
  2887. mov eax , [esi]GraphicViewPortClass.XAdd
  2888. mov ebx , [ x1_pixel ]
  2889. add eax , [esi]GraphicViewPortClass.Width
  2890. add eax , [esi]GraphicViewPortClass.Pitch
  2891. mov esi , eax
  2892. mul [ y0_pixel ]
  2893. add edi , [ x0_pixel ]
  2894. sub ebx , [ x0_pixel ]
  2895. jle real_out
  2896. add edi , eax
  2897. sub esi , ebx
  2898. mov ecx , [ y1_pixel ]
  2899. sub ecx , [ y0_pixel ]
  2900. jle real_out
  2901. mov eax , [ remap ]
  2902. mov [ counter_x ] , ebx
  2903. xor edx , edx
  2904. outer_loop:
  2905. mov ebx , [ counter_x ]
  2906. inner_loop:
  2907. mov dl , [ edi ]
  2908. mov dl , [ eax + edx ]
  2909. mov [ edi ] , dl
  2910. inc edi
  2911. dec ebx
  2912. jnz inner_loop
  2913. add edi , esi
  2914. dec ecx
  2915. jnz outer_loop
  2916. real_out:
  2917. // ret
  2918. }
  2919. }
  2920. /*
  2921. ; **************************************************************************
  2922. ; ** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S *
  2923. ; **************************************************************************
  2924. ; * *
  2925. ; * Project Name : WSA Support routines *
  2926. ; * *
  2927. ; * File Name : XORDELTA.ASM *
  2928. ; * *
  2929. ; * Programmer : Scott K. Bowen *
  2930. ; * *
  2931. ; * Last Update :May 23, 1994 [SKB] *
  2932. ; * *
  2933. ; *------------------------------------------------------------------------*
  2934. ; * Functions: *
  2935. ;* Apply_XOR_Delta -- Apply XOR delta data to a buffer. *
  2936. ;* Apply_XOR_Delta_To_Page_Or_Viewport -- Calls the copy or the XOR funti*
  2937. ;* Copy_Delta_buffer -- Copies XOR Delta Data to a section of a page. *
  2938. ;* XOR_Delta_Buffer -- Xor's the data in a XOR Delta format to a page. *
  2939. ; * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*
  2940. IDEAL
  2941. P386
  2942. MODEL USE32 FLAT
  2943. */
  2944. /*
  2945. LOCALS ??
  2946. ; These are used to call Apply_XOR_Delta_To_Page_Or_Viewport() to setup flags parameter. If
  2947. ; These change, make sure and change their values in wsa.cpp.
  2948. DO_XOR equ 0
  2949. DO_COPY equ 1
  2950. TO_VIEWPORT equ 0
  2951. TO_PAGE equ 2
  2952. ;
  2953. ; Routines defined in this module
  2954. ;
  2955. ;
  2956. ; UWORD Apply_XOR_Delta(UWORD page_seg, BYTE *delta_ptr);
  2957. ; PUBLIC Apply_XOR_Delta_To_Page_Or_Viewport(UWORD page_seg, BYTE *delta_ptr, WORD width, WORD copy)
  2958. ;
  2959. ; PROC C XOR_Delta_Buffer
  2960. ; PROC C Copy_Delta_Buffer
  2961. ;
  2962. GLOBAL C Apply_XOR_Delta:NEAR
  2963. GLOBAL C Apply_XOR_Delta_To_Page_Or_Viewport:NEAR
  2964. */
  2965. #define DO_XOR 0
  2966. #define DO_COPY 1
  2967. #define TO_VIEWPORT 0
  2968. #define TO_PAGE 2
  2969. void __cdecl XOR_Delta_Buffer(int nextrow);
  2970. void __cdecl Copy_Delta_Buffer(int nextrow);
  2971. /*
  2972. ;***************************************************************************
  2973. ;* APPLY_XOR_DELTA -- Apply XOR delta data to a linear buffer. *
  2974. ;* AN example of this in C is at the botton of the file commented out. *
  2975. ;* *
  2976. ;* INPUT: BYTE *target - destination buffer. *
  2977. ;* BYTE *delta - xor data to be delta uncompress. *
  2978. ;* *
  2979. ;* OUTPUT: *
  2980. ;* *
  2981. ;* WARNINGS: *
  2982. ;* *
  2983. ;* HISTORY: *
  2984. ;* 05/23/1994 SKB : Created. *
  2985. ;*=========================================================================*
  2986. */
  2987. unsigned int __cdecl Apply_XOR_Delta(char *target, char *delta)
  2988. {
  2989. /*
  2990. PROC Apply_XOR_Delta C near
  2991. USES ebx,ecx,edx,edi,esi
  2992. ARG target:DWORD ; pointers.
  2993. ARG delta:DWORD ; pointers.
  2994. */
  2995. __asm {
  2996. ; Optimized for 486/pentium by rearanging instructions.
  2997. mov edi,[target] ; get our pointers into offset registers.
  2998. mov esi,[delta]
  2999. cld ; make sure we go forward
  3000. xor ecx,ecx ; use cx for loop
  3001. top_loop:
  3002. xor eax,eax ; clear out eax.
  3003. mov al,[esi] ; get delta source byte
  3004. inc esi
  3005. test al,al ; check for a SHORTDUMP ; check al incase of sign value.
  3006. je short_run
  3007. js check_others
  3008. ;
  3009. ; SHORTDUMP
  3010. ;
  3011. mov ecx,eax ; stick count in cx
  3012. dump_loop:
  3013. mov al,[esi] ;get delta XOR byte
  3014. xor [edi],al ; xor that byte on the dest
  3015. inc esi
  3016. inc edi
  3017. dec ecx
  3018. jnz dump_loop
  3019. jmp top_loop
  3020. ;
  3021. ; SHORTRUN
  3022. ;
  3023. short_run:
  3024. mov cl,[esi] ; get count
  3025. inc esi ; inc delta source
  3026. do_run:
  3027. mov al,[esi] ; get XOR byte
  3028. inc esi
  3029. run_loop:
  3030. xor [edi],al ; xor that byte.
  3031. inc edi ; go to next dest pixel
  3032. dec ecx ; one less to go.
  3033. jnz run_loop
  3034. jmp top_loop
  3035. ;
  3036. ; By now, we know it must be a LONGDUMP, SHORTSKIP, LONGRUN, or LONGSKIP
  3037. ;
  3038. check_others:
  3039. sub eax,080h ; opcode -= 0x80
  3040. jnz do_skip ; if zero then get next word, otherwise use remainder.
  3041. mov ax,[esi]
  3042. lea esi,[esi+2] ; get word code in ax
  3043. test ax,ax ; set flags. (not 32bit register so neg flag works)
  3044. jle not_long_skip
  3045. ;
  3046. ; SHORTSKIP AND LONGSKIP
  3047. ;
  3048. do_skip:
  3049. add edi,eax ; do the skip.
  3050. jmp top_loop
  3051. not_long_skip:
  3052. jz stop ; long count of zero means stop
  3053. sub eax,08000h ; opcode -= 0x8000
  3054. test eax,04000h ; is it a LONGRUN (code & 0x4000)?
  3055. je long_dump
  3056. ;
  3057. ; LONGRUN
  3058. ;
  3059. sub eax,04000h ; opcode -= 0x4000
  3060. mov ecx,eax ; use cx as loop count
  3061. jmp do_run ; jump to run code.
  3062. ;
  3063. ; LONGDUMP
  3064. ;
  3065. long_dump:
  3066. mov ecx,eax ; use cx as loop count
  3067. jmp dump_loop ; go to the dump loop.
  3068. stop:
  3069. }
  3070. }
  3071. /*
  3072. ;----------------------------------------------------------------------------
  3073. ;***************************************************************************
  3074. ;* APPLY_XOR_DELTA_To_Page_Or_Viewport -- Calls the copy or the XOR funtion. *
  3075. ;* *
  3076. ;* *
  3077. ;* This funtion is call to either xor or copy XOR_Delta data onto a *
  3078. ;* page instead of a buffer. The routine will set up the registers *
  3079. ;* need for the actual routines that will perform the copy or xor. *
  3080. ;* *
  3081. ;* The registers are setup as follows : *
  3082. ;* es:edi - destination segment:offset onto page. *
  3083. ;* ds:esi - source buffer segment:offset of delta data. *
  3084. ;* dx,cx,ax - are all zeroed out before entry. *
  3085. ;* *
  3086. ;* INPUT: *
  3087. ;* *
  3088. ;* OUTPUT: *
  3089. ;* *
  3090. ;* WARNINGS: *
  3091. ;* *
  3092. ;* HISTORY: *
  3093. ;* 03/09/1992 SB : Created. *
  3094. ;*=========================================================================*
  3095. */
  3096. void __cdecl Apply_XOR_Delta_To_Page_Or_Viewport(void *target, void *delta, int width, int nextrow, int copy)
  3097. {
  3098. /*
  3099. USES ebx,ecx,edx,edi,esi
  3100. ARG target:DWORD ; pointer to the destination buffer.
  3101. ARG delta:DWORD ; pointer to the delta buffer.
  3102. ARG width:DWORD ; width of animation.
  3103. ARG nextrow:DWORD ; Page/Buffer width - anim width.
  3104. ARG copy:DWORD ; should it be copied or xor'd?
  3105. */
  3106. __asm {
  3107. mov edi,[target] ; Get the target pointer.
  3108. mov esi,[delta] ; Get the destination pointer.
  3109. xor eax,eax ; clear eax, later put them into ecx and edx.
  3110. cld ; make sure we go forward
  3111. mov ebx,[nextrow] ; get the amount to add to get to next row from end. push it later...
  3112. mov ecx,eax ; use cx for loop
  3113. mov edx,eax ; use dx to count the relative column.
  3114. push ebx ; push nextrow onto the stack for Copy/XOR_Delta_Buffer.
  3115. mov ebx,[width] ; bx will hold the max column for speed compares
  3116. ; At this point, all the registers have been set up. Now call the correct function
  3117. ; to either copy or xor the data.
  3118. cmp [copy],DO_XOR ; Do we want to copy or XOR
  3119. je xorfunct ; Jump to XOR if not copy
  3120. call Copy_Delta_Buffer ; Call the function to copy the delta buffer.
  3121. jmp didcopy ; jump past XOR
  3122. xorfunct:
  3123. call XOR_Delta_Buffer ; Call funtion to XOR the deltat buffer.
  3124. didcopy:
  3125. pop ebx ; remove the push done to pass a value.
  3126. }
  3127. }
  3128. /*
  3129. ;----------------------------------------------------------------------------
  3130. ;***************************************************************************
  3131. ;* XOR_DELTA_BUFFER -- Xor's the data in a XOR Delta format to a page. *
  3132. ;* This will only work right if the page has the previous data on it. *
  3133. ;* This function should only be called by XOR_Delta_Buffer_To_Page_Or_Viewport. *
  3134. ;* The registers must be setup as follows : *
  3135. ;* *
  3136. ;* INPUT: *
  3137. ;* es:edi - destination segment:offset onto page. *
  3138. ;* ds:esi - source buffer segment:offset of delta data. *
  3139. ;* edx,ecx,eax - are all zeroed out before entry. *
  3140. ;* *
  3141. ;* OUTPUT: *
  3142. ;* *
  3143. ;* WARNINGS: *
  3144. ;* *
  3145. ;* HISTORY: *
  3146. ;* 03/09/1992 SB : Created. *
  3147. ;*=========================================================================*
  3148. */
  3149. void __cdecl XOR_Delta_Buffer(int nextrow)
  3150. {
  3151. /*
  3152. ARG nextrow:DWORD
  3153. */
  3154. __asm {
  3155. top_loop:
  3156. xor eax,eax ; clear out eax.
  3157. mov al,[esi] ; get delta source byte
  3158. inc esi
  3159. test al,al ; check for a SHORTDUMP ; check al incase of sign value.
  3160. je short_run
  3161. js check_others
  3162. ;
  3163. ; SHORTDUMP
  3164. ;
  3165. mov ecx,eax ; stick count in cx
  3166. dump_loop:
  3167. mov al,[esi] ; get delta XOR byte
  3168. xor [edi],al ; xor that byte on the dest
  3169. inc esi
  3170. inc edx ; increment our count on current column
  3171. inc edi
  3172. cmp edx,ebx ; are we at the final column
  3173. jne end_col1 ; if not the jmp over the code
  3174. sub edi,edx ; get our column back to the beginning.
  3175. xor edx,edx ; zero out our column counter
  3176. add edi,[nextrow] ; jump to start of next row
  3177. end_col1:
  3178. dec ecx
  3179. jnz dump_loop
  3180. jmp top_loop
  3181. ;
  3182. ; SHORTRUN
  3183. ;
  3184. short_run:
  3185. mov cl,[esi] ; get count
  3186. inc esi ; inc delta source
  3187. do_run:
  3188. mov al,[esi] ; get XOR byte
  3189. inc esi
  3190. run_loop:
  3191. xor [edi],al ; xor that byte.
  3192. inc edx ; increment our count on current column
  3193. inc edi ; go to next dest pixel
  3194. cmp edx,ebx ; are we at the final column
  3195. jne end_col2 ; if not the jmp over the code
  3196. sub edi,ebx ; get our column back to the beginning.
  3197. xor edx,edx ; zero out our column counter
  3198. add edi,[nextrow] ; jump to start of next row
  3199. end_col2:
  3200. dec ecx
  3201. jnz run_loop
  3202. jmp top_loop
  3203. ;
  3204. ; By now, we know it must be a LONGDUMP, SHORTSKIP, LONGRUN, or LONGSKIP
  3205. ;
  3206. check_others:
  3207. sub eax,080h ; opcode -= 0x80
  3208. jnz do_skip ; if zero then get next word, otherwise use remainder.
  3209. mov ax,[esi] ; get word code in ax
  3210. lea esi,[esi+2]
  3211. test ax,ax ; set flags. (not 32bit register so neg flag works)
  3212. jle not_long_skip
  3213. ;
  3214. ; SHORTSKIP AND LONGSKIP
  3215. ;
  3216. do_skip:
  3217. sub edi,edx ; go back to beginning or row.
  3218. add edx,eax ; incriment our count on current row
  3219. recheck3:
  3220. cmp edx,ebx ; are we past the end of the row
  3221. jb end_col3 ; if not the jmp over the code
  3222. sub edx,ebx ; Subtract width from the col counter
  3223. add edi,[nextrow] ; jump to start of next row
  3224. jmp recheck3 ; jump up to see if we are at the right row
  3225. end_col3:
  3226. add edi,edx ; get to correct position in row.
  3227. jmp top_loop
  3228. not_long_skip:
  3229. jz stop ; long count of zero means stop
  3230. sub eax,08000h ; opcode -= 0x8000
  3231. test eax,04000h ; is it a LONGRUN (code & 0x4000)?
  3232. je long_dump
  3233. ;
  3234. ; LONGRUN
  3235. ;
  3236. sub eax,04000h ; opcode -= 0x4000
  3237. mov ecx,eax ; use cx as loop count
  3238. jmp do_run ; jump to run code.
  3239. ;
  3240. ; LONGDUMP
  3241. ;
  3242. long_dump:
  3243. mov ecx,eax ; use cx as loop count
  3244. jmp dump_loop ; go to the dump loop.
  3245. stop:
  3246. }
  3247. }
  3248. /*
  3249. ;----------------------------------------------------------------------------
  3250. ;***************************************************************************
  3251. ;* COPY_DELTA_BUFFER -- Copies XOR Delta Data to a section of a page. *
  3252. ;* This function should only be called by XOR_Delta_Buffer_To_Page_Or_Viewport. *
  3253. ;* The registers must be setup as follows : *
  3254. ;* *
  3255. ;* INPUT: *
  3256. ;* es:edi - destination segment:offset onto page. *
  3257. ;* ds:esi - source buffer segment:offset of delta data. *
  3258. ;* dx,cx,ax - are all zeroed out before entry. *
  3259. ;* *
  3260. ;* OUTPUT: *
  3261. ;* *
  3262. ;* WARNINGS: *
  3263. ;* *
  3264. ;* HISTORY: *
  3265. ;* 03/09/1992 SB : Created. *
  3266. ;*=========================================================================*
  3267. */
  3268. void __cdecl Copy_Delta_Buffer(int nextrow)
  3269. {
  3270. /*
  3271. ARG nextrow:DWORD
  3272. */
  3273. __asm {
  3274. top_loop:
  3275. xor eax,eax ; clear out eax.
  3276. mov al,[esi] ; get delta source byte
  3277. inc esi
  3278. test al,al ; check for a SHORTDUMP ; check al incase of sign value.
  3279. je short_run
  3280. js check_others
  3281. ;
  3282. ; SHORTDUMP
  3283. ;
  3284. mov ecx,eax ; stick count in cx
  3285. dump_loop:
  3286. mov al,[esi] ; get delta XOR byte
  3287. mov [edi],al ; store that byte on the dest
  3288. inc edx ; increment our count on current column
  3289. inc esi
  3290. inc edi
  3291. cmp edx,ebx ; are we at the final column
  3292. jne end_col1 ; if not the jmp over the code
  3293. sub edi,edx ; get our column back to the beginning.
  3294. xor edx,edx ; zero out our column counter
  3295. add edi,[nextrow] ; jump to start of next row
  3296. end_col1:
  3297. dec ecx
  3298. jnz dump_loop
  3299. jmp top_loop
  3300. ;
  3301. ; SHORTRUN
  3302. ;
  3303. short_run:
  3304. mov cl,[esi] ; get count
  3305. inc esi ; inc delta source
  3306. do_run:
  3307. mov al,[esi] ; get XOR byte
  3308. inc esi
  3309. run_loop:
  3310. mov [edi],al ; store the byte (instead of XOR against current color)
  3311. inc edx ; increment our count on current column
  3312. inc edi ; go to next dest pixel
  3313. cmp edx,ebx ; are we at the final column
  3314. jne end_col2 ; if not the jmp over the code
  3315. sub edi,ebx ; get our column back to the beginning.
  3316. xor edx,edx ; zero out our column counter
  3317. add edi,[nextrow] ; jump to start of next row
  3318. end_col2:
  3319. dec ecx
  3320. jnz run_loop
  3321. jmp top_loop
  3322. ;
  3323. ; By now, we know it must be a LONGDUMP, SHORTSKIP, LONGRUN, or LONGSKIP
  3324. ;
  3325. check_others:
  3326. sub eax,080h ; opcode -= 0x80
  3327. jnz do_skip ; if zero then get next word, otherwise use remainder.
  3328. mov ax,[esi] ; get word code in ax
  3329. lea esi,[esi+2]
  3330. test ax,ax ; set flags. (not 32bit register so neg flag works)
  3331. jle not_long_skip
  3332. ;
  3333. ; SHORTSKIP AND LONGSKIP
  3334. ;
  3335. do_skip:
  3336. sub edi,edx ; go back to beginning or row.
  3337. add edx,eax ; incriment our count on current row
  3338. recheck3:
  3339. cmp edx,ebx ; are we past the end of the row
  3340. jb end_col3 ; if not the jmp over the code
  3341. sub edx,ebx ; Subtract width from the col counter
  3342. add edi,[nextrow] ; jump to start of next row
  3343. jmp recheck3 ; jump up to see if we are at the right row
  3344. end_col3:
  3345. add edi,edx ; get to correct position in row.
  3346. jmp top_loop
  3347. not_long_skip:
  3348. jz stop ; long count of zero means stop
  3349. sub eax,08000h ; opcode -= 0x8000
  3350. test eax,04000h ; is it a LONGRUN (code & 0x4000)?
  3351. je long_dump
  3352. ;
  3353. ; LONGRUN
  3354. ;
  3355. sub eax,04000h ; opcode -= 0x4000
  3356. mov ecx,eax ; use cx as loop count
  3357. jmp do_run ; jump to run code.
  3358. ;
  3359. ; LONGDUMP
  3360. ;
  3361. long_dump:
  3362. mov ecx,eax ; use cx as loop count
  3363. jmp dump_loop ; go to the dump loop.
  3364. stop:
  3365. }
  3366. }
  3367. /*
  3368. ;----------------------------------------------------------------------------
  3369. */
  3370. /*
  3371. ;***************************************************************************
  3372. ;** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  3373. ;***************************************************************************
  3374. ;* *
  3375. ;* Project Name : Westwood Library *
  3376. ;* *
  3377. ;* File Name : FADING.ASM *
  3378. ;* *
  3379. ;* Programmer : Joe L. Bostic *
  3380. ;* *
  3381. ;* Start Date : August 20, 1993 *
  3382. ;* *
  3383. ;* Last Update : August 20, 1993 [JLB] *
  3384. ;* *
  3385. ;*-------------------------------------------------------------------------*
  3386. ;* Functions: *
  3387. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  3388. IDEAL
  3389. P386
  3390. MODEL USE32 FLAT
  3391. GLOBAL C Build_Fading_Table :NEAR
  3392. CODESEG
  3393. ;***********************************************************
  3394. ; BUILD_FADING_TABLE
  3395. ;
  3396. ; void *Build_Fading_Table(void *palette, void *dest, long int color, long int frac);
  3397. ;
  3398. ; This routine will create the fading effect table used to coerce colors
  3399. ; from toward a common value. This table is used when Fading_Effect is
  3400. ; active.
  3401. ;
  3402. ; Bounds Checking: None
  3403. ;*
  3404. */
  3405. void * __cdecl Build_Fading_Table(void const *palette, void const *dest, long int color, long int frac)
  3406. {
  3407. /*
  3408. PROC Build_Fading_Table C near
  3409. USES ebx, ecx, edi, esi
  3410. ARG palette:DWORD
  3411. ARG dest:DWORD
  3412. ARG color:DWORD
  3413. ARG frac:DWORD
  3414. LOCAL matchvalue:DWORD ; Last recorded match value.
  3415. LOCAL targetred:BYTE ; Target gun red.
  3416. LOCAL targetgreen:BYTE ; Target gun green.
  3417. LOCAL targetblue:BYTE ; Target gun blue.
  3418. LOCAL idealred:BYTE
  3419. LOCAL idealgreen:BYTE
  3420. LOCAL idealblue:BYTE
  3421. LOCAL matchcolor:BYTE ; Tentative match color.
  3422. */
  3423. int matchvalue = 0; //:DWORD ; Last recorded match value.
  3424. unsigned char targetred = 0; //BYTE ; Target gun red.
  3425. unsigned char targetgreen = 0; //BYTE ; Target gun green.
  3426. unsigned char targetblue = 0; //BYTE ; Target gun blue.
  3427. unsigned char idealred = 0; //BYTE
  3428. unsigned char idealgreen = 0; //BYTE
  3429. unsigned char idealblue = 0; //BYTE
  3430. unsigned char matchcolor = 0; //:BYTE ; Tentative match color.
  3431. __asm {
  3432. cld
  3433. ; If the source palette is NULL, then just return with current fading table pointer.
  3434. cmp [palette],0
  3435. je fini
  3436. cmp [dest],0
  3437. je fini
  3438. ; Fractions above 255 become 255.
  3439. mov eax,[frac]
  3440. cmp eax,0100h
  3441. jb short ok
  3442. mov [frac],0FFh
  3443. ok:
  3444. ; Record the target gun values.
  3445. mov esi,[palette]
  3446. mov ebx,[color]
  3447. add esi,ebx
  3448. add esi,ebx
  3449. add esi,ebx
  3450. lodsb
  3451. mov [targetred],al
  3452. lodsb
  3453. mov [targetgreen],al
  3454. lodsb
  3455. mov [targetblue],al
  3456. ; Main loop.
  3457. xor ebx,ebx ; Remap table index.
  3458. ; Transparent black never gets remapped.
  3459. mov edi,[dest]
  3460. mov [edi],bl
  3461. inc edi
  3462. ; EBX = source palette logical number (1..255).
  3463. ; EDI = running pointer into dest remap table.
  3464. mainloop:
  3465. inc ebx
  3466. mov esi,[palette]
  3467. add esi,ebx
  3468. add esi,ebx
  3469. add esi,ebx
  3470. mov edx,[frac]
  3471. shr edx,1
  3472. ; new = orig - ((orig-target) * fraction);
  3473. lodsb ; orig
  3474. mov dh,al ; preserve it for later.
  3475. sub al,[targetred] ; al = (orig-target)
  3476. imul dl ; ax = (orig-target)*fraction
  3477. shl ax,1
  3478. sub dh,ah ; dh = orig - ((orig-target) * fraction)
  3479. mov [idealred],dh ; preserve ideal color gun value.
  3480. lodsb ; orig
  3481. mov dh,al ; preserve it for later.
  3482. sub al,[targetgreen] ; al = (orig-target)
  3483. imul dl ; ax = (orig-target)*fraction
  3484. shl ax,1
  3485. sub dh,ah ; dh = orig - ((orig-target) * fraction)
  3486. mov [idealgreen],dh ; preserve ideal color gun value.
  3487. lodsb ; orig
  3488. mov dh,al ; preserve it for later.
  3489. sub al,[targetblue] ; al = (orig-target)
  3490. imul dl ; ax = (orig-target)*fraction
  3491. shl ax,1
  3492. sub dh,ah ; dh = orig - ((orig-target) * fraction)
  3493. mov [idealblue],dh ; preserve ideal color gun value.
  3494. ; Sweep through the entire existing palette to find the closest
  3495. ; matching color. Never matches with color 0.
  3496. mov eax,[color]
  3497. mov [matchcolor],al ; Default color (self).
  3498. mov [matchvalue],-1 ; Ridiculous match value init.
  3499. mov ecx,255
  3500. mov esi,[palette] ; Pointer to original palette.
  3501. add esi,3
  3502. ; BH = color index.
  3503. mov bh,1
  3504. innerloop:
  3505. ; Recursion through the fading table won't work if a color is allowed
  3506. ; to remap to itself. Prevent this from occuring.
  3507. add esi,3
  3508. cmp bh,bl
  3509. je short notclose
  3510. sub esi,3
  3511. xor edx,edx ; Comparison value starts null.
  3512. mov eax,edx
  3513. ; Build the comparison value based on the sum of the differences of the color
  3514. ; guns squared.
  3515. lodsb
  3516. sub al,[idealred]
  3517. mov ah,al
  3518. imul ah
  3519. add edx,eax
  3520. lodsb
  3521. sub al,[idealgreen]
  3522. mov ah,al
  3523. imul ah
  3524. add edx,eax
  3525. lodsb
  3526. sub al,[idealblue]
  3527. mov ah,al
  3528. imul ah
  3529. add edx,eax
  3530. jz short perfect ; If perfect match found then quit early.
  3531. cmp edx,[matchvalue]
  3532. ja short notclose
  3533. mov [matchvalue],edx ; Record new possible color.
  3534. mov [matchcolor],bh
  3535. notclose:
  3536. inc bh ; Checking color index.
  3537. loop innerloop
  3538. mov bh,[matchcolor]
  3539. perfect:
  3540. mov [matchcolor],bh
  3541. xor bh,bh ; Make BX valid main index again.
  3542. ; When the loop exits, we have found the closest match.
  3543. mov al,[matchcolor]
  3544. stosb
  3545. cmp ebx,255
  3546. jne mainloop
  3547. fini:
  3548. mov eax,[dest]
  3549. // ret
  3550. }
  3551. }
  3552. /*
  3553. ;***************************************************************************
  3554. ;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  3555. ;***************************************************************************
  3556. ;* *
  3557. ;* Project Name : Westwood Library *
  3558. ;* *
  3559. ;* File Name : PAL.ASM *
  3560. ;* *
  3561. ;* Programmer : Joe L. Bostic *
  3562. ;* *
  3563. ;* Start Date : May 30, 1992 *
  3564. ;* *
  3565. ;* Last Update : April 27, 1994 [BR] *
  3566. ;* *
  3567. ;*-------------------------------------------------------------------------*
  3568. ;* Functions: *
  3569. ;* Set_Palette_Range -- Sets changed values in the palette. *
  3570. ;* Bump_Color -- adjusts specified color in specified palette *
  3571. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  3572. ;********************** Model & Processor Directives ************************
  3573. IDEAL
  3574. P386
  3575. MODEL USE32 FLAT
  3576. ;include "keyboard.inc"
  3577. FALSE = 0
  3578. TRUE = 1
  3579. ;****************************** Declarations ********************************
  3580. GLOBAL C Set_Palette_Range:NEAR
  3581. GLOBAL C Bump_Color:NEAR
  3582. GLOBAL C CurrentPalette:BYTE:768
  3583. GLOBAL C PaletteTable:byte:1024
  3584. ;********************************** Data ************************************
  3585. LOCALS ??
  3586. DATASEG
  3587. CurrentPalette DB 768 DUP(255) ; copy of current values of DAC regs
  3588. PaletteTable DB 1024 DUP(0)
  3589. IFNDEF LIB_EXTERNS_RESOLVED
  3590. VertBlank DW 0 ; !!!! this should go away
  3591. ENDIF
  3592. ;********************************** Code ************************************
  3593. CODESEG
  3594. */
  3595. extern "C" unsigned char CurrentPalette[768] = {255}; // DB 768 DUP(255) ; copy of current values of DAC regs
  3596. extern "C" unsigned char PaletteTable[1024] = {0}; // DB 1024 DUP(0)
  3597. /*
  3598. ;***************************************************************************
  3599. ;* SET_PALETTE_RANGE -- Sets a palette range to the new pal *
  3600. ;* *
  3601. ;* INPUT: *
  3602. ;* *
  3603. ;* OUTPUT: *
  3604. ;* *
  3605. ;* PROTO: *
  3606. ;* *
  3607. ;* WARNINGS: This routine is optimized for changing a small number of *
  3608. ;* colors in the palette.
  3609. ;* *
  3610. ;* HISTORY: *
  3611. ;* 03/07/1995 PWG : Created. *
  3612. ;*=========================================================================*
  3613. */
  3614. void __cdecl Set_Palette_Range(void *palette)
  3615. {
  3616. memcpy(CurrentPalette, palette, 768);
  3617. Set_DD_Palette(palette);
  3618. /*
  3619. PROC Set_Palette_Range C NEAR
  3620. ARG palette:DWORD
  3621. GLOBAL Set_DD_Palette_:near
  3622. GLOBAL Wait_Vert_Blank_:near
  3623. pushad
  3624. mov esi,[palette]
  3625. mov ecx,768/4
  3626. mov edi,offset CurrentPalette
  3627. cld
  3628. rep movsd
  3629. ;call Wait_Vert_Blank_
  3630. mov eax,[palette]
  3631. push eax
  3632. call Set_DD_Palette_
  3633. pop eax
  3634. popad
  3635. ret
  3636. */
  3637. }
  3638. /*
  3639. ;***************************************************************************
  3640. ;* Bump_Color -- adjusts specified color in specified palette *
  3641. ;* *
  3642. ;* INPUT: *
  3643. ;* VOID *palette - palette to modify *
  3644. ;* WORD changable - color # to change *
  3645. ;* WORD target - color to bend toward *
  3646. ;* *
  3647. ;* OUTPUT: *
  3648. ;* *
  3649. ;* WARNINGS: *
  3650. ;* *
  3651. ;* HISTORY: *
  3652. ;* 04/27/1994 BR : Converted to 32-bit. *
  3653. ;*=========================================================================*
  3654. ; BOOL cdecl Bump_Color(VOID *palette, WORD changable, WORD target);
  3655. */
  3656. BOOL __cdecl Bump_Color(void *pal, int color, int desired)
  3657. {
  3658. /*
  3659. PROC Bump_Color C NEAR
  3660. USES ebx,ecx,edi,esi
  3661. ARG pal:DWORD, color:WORD, desired:WORD
  3662. LOCAL changed:WORD ; Has palette changed?
  3663. */
  3664. short short_color = (short) color;
  3665. short short_desired = (short) desired;
  3666. bool changed = false;
  3667. __asm {
  3668. mov edi,[pal] ; Original palette pointer.
  3669. mov esi,edi
  3670. mov eax,0
  3671. mov ax,[short_color]
  3672. add edi,eax
  3673. add edi,eax
  3674. add edi,eax ; Offset to changable color.
  3675. mov ax,[short_desired]
  3676. add esi,eax
  3677. add esi,eax
  3678. add esi,eax ; Offset to target color.
  3679. mov [changed],FALSE ; Presume no change.
  3680. mov ecx,3 ; Three color guns.
  3681. ; Check the color gun.
  3682. colorloop:
  3683. mov al,[BYTE PTR esi]
  3684. sub al,[BYTE PTR edi] ; Carry flag is set if subtraction needed.
  3685. jz short gotit
  3686. mov [changed],TRUE
  3687. inc [BYTE PTR edi] ; Presume addition.
  3688. jnc short gotit ; oops, subtraction needed so dec twice.
  3689. dec [BYTE PTR edi]
  3690. dec [BYTE PTR edi]
  3691. gotit:
  3692. inc edi
  3693. inc esi
  3694. loop colorloop
  3695. movzx eax,[changed]
  3696. }
  3697. }
  3698. /*
  3699. ;***************************************************************************
  3700. ;** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  3701. ;***************************************************************************
  3702. ;* *
  3703. ;* Project Name : GraphicViewPortClass *
  3704. ;* *
  3705. ;* File Name : PUTPIXEL.ASM *
  3706. ;* *
  3707. ;* Programmer : Phil Gorrow *
  3708. ;* *
  3709. ;* Start Date : June 7, 1994 *
  3710. ;* *
  3711. ;* Last Update : June 8, 1994 [PWG] *
  3712. ;* *
  3713. ;*-------------------------------------------------------------------------*
  3714. ;* Functions: *
  3715. ;* VVPC::Put_Pixel -- Puts a pixel on a virtual viewport *
  3716. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  3717. IDEAL
  3718. P386
  3719. MODEL USE32 FLAT
  3720. INCLUDE ".\drawbuff.inc"
  3721. INCLUDE ".\gbuffer.inc"
  3722. CODESEG
  3723. */
  3724. /*
  3725. ;***************************************************************************
  3726. ;* VVPC::PUT_PIXEL -- Puts a pixel on a virtual viewport *
  3727. ;* *
  3728. ;* INPUT: WORD the x position for the pixel relative to the upper *
  3729. ;* left corner of the viewport *
  3730. ;* WORD the y pos for the pixel relative to the upper left *
  3731. ;* corner of the viewport *
  3732. ;* UBYTE the color of the pixel to write *
  3733. ;* *
  3734. ;* OUTPUT: none *
  3735. ;* *
  3736. ;* WARNING: If pixel is to be placed outside of the viewport then *
  3737. ;* this routine will abort. *
  3738. ;* *
  3739. ;* HISTORY: *
  3740. ;* 06/08/1994 PWG : Created. *
  3741. ;*=========================================================================*
  3742. PROC Buffer_Put_Pixel C near
  3743. USES eax,ebx,ecx,edx,edi
  3744. */
  3745. void __cdecl Buffer_Put_Pixel(void * this_object, int x_pixel, int y_pixel, unsigned char color)
  3746. {
  3747. /*
  3748. ARG this_object:DWORD ; this is a member function
  3749. ARG x_pixel:DWORD ; x position of pixel to set
  3750. ARG y_pixel:DWORD ; y position of pixel to set
  3751. ARG color:BYTE ; what color should we clear to
  3752. */
  3753. __asm {
  3754. ;*===================================================================
  3755. ; Get the viewport information and put bytes per row in ecx
  3756. ;*===================================================================
  3757. mov ebx,[this_object] ; get a pointer to viewport
  3758. xor eax,eax
  3759. mov edi,[ebx]GraphicViewPortClass.Offset ; get the correct offset
  3760. mov ecx,[ebx]GraphicViewPortClass.Height ; edx = height of viewport
  3761. mov edx,[ebx]GraphicViewPortClass.Width ; ecx = width of viewport
  3762. ;*===================================================================
  3763. ; Verify that the X pixel offset if legal
  3764. ;*===================================================================
  3765. mov eax,[x_pixel] ; find the x position
  3766. cmp eax,edx ; is it out of bounds
  3767. jae short done ; if so then get out
  3768. add edi,eax ; otherwise add in offset
  3769. ;*===================================================================
  3770. ; Verify that the Y pixel offset if legal
  3771. ;*===================================================================
  3772. mov eax,[y_pixel] ; get the y position
  3773. cmp eax,ecx ; is it out of bounds
  3774. jae done ; if so then get out
  3775. add edx,[ebx]GraphicViewPortClass.XAdd ; otherwise find bytes per row
  3776. add edx,[ebx]GraphicViewPortClass.Pitch ; add in direct draw pitch
  3777. mul edx ; offset = bytes per row * y
  3778. add edi,eax ; add it into the offset
  3779. ;*===================================================================
  3780. ; Write the pixel to the screen
  3781. ;*===================================================================
  3782. mov al,[color] ; read in color value
  3783. mov [edi],al ; write it to the screen
  3784. done:
  3785. }
  3786. }
  3787. /*
  3788. ;***************************************************************************
  3789. ;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  3790. ;***************************************************************************
  3791. ;* *
  3792. ;* Project Name : Support Library *
  3793. ;* *
  3794. ;* File Name : cliprect.asm *
  3795. ;* *
  3796. ;* Programmer : Julio R Jerez *
  3797. ;* *
  3798. ;* Start Date : Mar, 2 1995 *
  3799. ;* *
  3800. ;* *
  3801. ;*-------------------------------------------------------------------------*
  3802. ;* Functions: *
  3803. ;* int Clip_Rect ( int * x , int * y , int * dw , int * dh , *
  3804. ;* int width , int height ) ; *
  3805. ;* int Confine_Rect ( int * x , int * y , int * dw , int * dh , *
  3806. ;* int width , int height ) ; *
  3807. ;* *
  3808. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  3809. IDEAL
  3810. P386
  3811. MODEL USE32 FLAT
  3812. GLOBAL C Clip_Rect :NEAR
  3813. GLOBAL C Confine_Rect :NEAR
  3814. CODESEG
  3815. ;***************************************************************************
  3816. ;* Clip_Rect -- clip a given rectangle against a given window *
  3817. ;* *
  3818. ;* INPUT: &x , &y , &w , &h -> Pointer to rectangle being clipped *
  3819. ;* width , height -> dimension of clipping window *
  3820. ;* *
  3821. ;* OUTPUT: a) Zero if the rectangle is totally contained by the *
  3822. ;* clipping window. *
  3823. ;* b) A negative value if the rectangle is totally outside the *
  3824. ;* the clipping window *
  3825. ;* c) A positive value if the rectangle was clipped against the *
  3826. ;* clipping window, also the values pointed by x, y, w, h will *
  3827. ;* be modified to new clipped values *
  3828. ;* *
  3829. ;* 05/03/1995 JRJ : added comment *
  3830. ;*=========================================================================*
  3831. ; int Clip_Rect (int* x, int* y, int* dw, int* dh, int width, int height); *
  3832. */
  3833. extern "C" int __cdecl Clip_Rect ( int * x , int * y , int * w , int * h , int width , int height )
  3834. {
  3835. /*
  3836. PROC Clip_Rect C near
  3837. uses ebx,ecx,edx,esi,edi
  3838. arg x:dword
  3839. arg y:dword
  3840. arg w:dword
  3841. arg h:dword
  3842. arg width:dword
  3843. arg height:dword
  3844. */
  3845. __asm {
  3846. ;This Clipping algorithm is a derivation of the very well known
  3847. ;Cohen-Sutherland Line-Clipping test. Due to its simplicity and efficiency
  3848. ;it is probably the most commontly implemented algorithm both in software
  3849. ;and hardware for clipping lines, rectangles, and convex polygons against
  3850. ;a rectagular clipping window. For reference see
  3851. ;"COMPUTER GRAPHICS principles and practice by Foley, Vandam, Feiner, Hughes
  3852. ; pages 113 to 177".
  3853. ; Briefly consist in computing the Sutherland code for both end point of
  3854. ; the rectangle to find out if the rectangle is:
  3855. ; - trivially accepted (no further clipping test, return the oroginal data)
  3856. ; - trivially rejected (return with no action, return error code)
  3857. ; - retangle must be iteratively clipped again edges of the clipping window
  3858. ; and return the clipped rectangle
  3859. ; get all four pointer into regisnters
  3860. mov esi,[x] ; esi = pointer to x
  3861. mov edi,[y] ; edi = pointer to x
  3862. mov eax,[w] ; eax = pointer to dw
  3863. mov ebx,[h] ; ebx = pointer to dh
  3864. ; load the actual data into reg
  3865. mov esi,[esi] ; esi = x0
  3866. mov edi,[edi] ; edi = y0
  3867. mov eax,[eax] ; eax = dw
  3868. mov ebx,[ebx] ; ebx = dh
  3869. ; create a wire frame of the type [x0,y0] , [x1,y1]
  3870. add eax,esi ; eax = x1 = x0 + dw
  3871. add ebx,edi ; ebx = y1 = y0 + dh
  3872. ; we start we suthenland code0 and code1 set to zero
  3873. xor ecx,ecx ; cl = sutherland boolean code0
  3874. xor edx,edx ; dl = sutherland boolean code0
  3875. ; now we start computing the to suthenland boolean code for x0 , x1
  3876. shld ecx,esi,1 ; bit3 of code0 = sign bit of (x0 - 0)
  3877. shld edx,eax,1 ; bit3 of code1 = sign bit of (x1 - 0)
  3878. sub esi,[width] ; get the difference (x0 - (width + 1))
  3879. sub eax,[width] ; get the difference (x1 - (width + 1))
  3880. dec esi
  3881. dec eax
  3882. shld ecx,esi,1 ; bit2 of code0 = sign bit of (x0 - (width + 1))
  3883. shld edx,eax,1 ; bit2 of code1 = sign bit of (x0 - (width + 1))
  3884. ; now we start computing the to suthenland boolean code for y0 , y1
  3885. shld ecx,edi,1 ; bit1 of code0 = sign bit of (y0 - 0)
  3886. shld edx,ebx,1 ; bit1 of code1 = sign bit of (y0 - 0)
  3887. sub edi,[height] ; get the difference (y0 - (height + 1))
  3888. sub ebx,[height] ; get the difference (y1 - (height + 1))
  3889. dec edi
  3890. dec ebx
  3891. shld ecx,edi,1 ; bit0 of code0 = sign bit of (y0 - (height + 1))
  3892. shld edx,ebx,1 ; bit0 of code1 = sign bit of (y1 - (height + 1))
  3893. ; Bit 2 and 0 of cl and bl are complemented
  3894. xor cl,5 ; reverse bit2 and bit0 in code0
  3895. xor dl,5 ; reverse bit2 and bit0 in code1
  3896. ; now perform the rejection test
  3897. mov eax,-1 ; set return code to false
  3898. mov bl,cl ; save code0 for future use
  3899. test dl,cl ; if any two pair of bit in code0 and code1 is set
  3900. jnz clip_out ; then rectangle is outside the window
  3901. ; now perform the aceptance test
  3902. xor eax,eax ; set return code to true
  3903. or bl,dl ; if all pair of bits in code0 and code1 are reset
  3904. jz clip_out ; then rectangle is insize the window. '
  3905. ; we need to clip the rectangle iteratively
  3906. mov eax,-1 ; set return code to false
  3907. test cl,1000b ; if bit3 of code0 is set then the rectangle
  3908. jz left_ok ; spill out the left edge of the window
  3909. mov edi,[x] ; edi = a pointer to x0
  3910. mov ebx,[w] ; ebx = a pointer to dw
  3911. mov esi,[edi] ; esi = x0
  3912. mov [dword ptr edi],0 ; set x0 to 0 "this the left edge value"
  3913. add [ebx],esi ; adjust dw by x0, since x0 must be negative
  3914. left_ok:
  3915. test cl,0010b ; if bit1 of code0 is set then the rectangle
  3916. jz bottom_ok ; spill out the bottom edge of the window
  3917. mov edi,[y] ; edi = a pointer to y0
  3918. mov ebx,[h] ; ebx = a pointer to dh
  3919. mov esi,[edi] ; esi = y0
  3920. mov [dword ptr edi],0 ; set y0 to 0 "this the bottom edge value"
  3921. add [ebx],esi ; adjust dh by y0, since y0 must be negative
  3922. bottom_ok:
  3923. test dl,0100b ; if bit2 of code1 is set then the rectangle
  3924. jz right_ok ; spill out the right edge of the window
  3925. mov edi,[w] ; edi = a pointer to dw
  3926. mov esi,[x] ; esi = a pointer to x
  3927. mov ebx,[width] ; ebx = the width of the window
  3928. sub ebx,[esi] ; the new dw is the difference (width-x0)
  3929. mov [edi],ebx ; adjust dw to (width - x0)
  3930. jle clip_out ; if (width-x0) = 0 then the clipped retangle
  3931. ; has no width we are done
  3932. right_ok:
  3933. test dl,0001b ; if bit0 of code1 is set then the rectangle
  3934. jz clip_ok ; spill out the top edge of the window
  3935. mov edi,[h] ; edi = a pointer to dh
  3936. mov esi,[y] ; esi = a pointer to y0
  3937. mov ebx,[height] ; ebx = the height of the window
  3938. sub ebx,[esi] ; the new dh is the difference (height-y0)
  3939. mov [edi],ebx ; adjust dh to (height-y0)
  3940. jle clip_out ; if (width-x0) = 0 then the clipped retangle
  3941. ; has no width we are done
  3942. clip_ok:
  3943. mov eax,1 ; signal the calling program that the rectangle was modify
  3944. clip_out:
  3945. //ret
  3946. }
  3947. //ENDP Clip_Rect
  3948. }
  3949. /*
  3950. ;***************************************************************************
  3951. ;* Confine_Rect -- clip a given rectangle against a given window *
  3952. ;* *
  3953. ;* INPUT: &x,&y,w,h -> Pointer to rectangle being clipped *
  3954. ;* width,height -> dimension of clipping window *
  3955. ;* *
  3956. ;* OUTPUT: a) Zero if the rectangle is totally contained by the *
  3957. ;* clipping window. *
  3958. ;* c) A positive value if the rectangle was shifted in position *
  3959. ;* to fix inside the clipping window, also the values pointed *
  3960. ;* by x, y, will adjusted to a new values *
  3961. ;* *
  3962. ;* NOTE: this function make not attempt to verify if the rectangle is *
  3963. ;* bigger than the clipping window and at the same time wrap around*
  3964. ;* it. If that is the case the result is meaningless *
  3965. ;*=========================================================================*
  3966. ; int Confine_Rect (int* x, int* y, int dw, int dh, int width, int height); *
  3967. */
  3968. extern "C" int __cdecl Confine_Rect ( int * x , int * y , int w , int h , int width , int height )
  3969. {
  3970. /*
  3971. PROC Confine_Rect C near
  3972. uses ebx, esi,edi
  3973. arg x:dword
  3974. arg y:dword
  3975. arg w:dword
  3976. arg h:dword
  3977. arg width :dword
  3978. arg height:dword
  3979. */
  3980. __asm {
  3981. xor eax,eax
  3982. mov ebx,[x]
  3983. mov edi,[w]
  3984. mov esi,[ebx]
  3985. add edi,[ebx]
  3986. sub edi,[width]
  3987. neg esi
  3988. dec edi
  3989. test esi,edi
  3990. jl x_axix_ok
  3991. mov eax,1
  3992. test esi,esi
  3993. jl shift_right
  3994. mov [dword ptr ebx],0
  3995. jmp x_axix_ok
  3996. shift_right:
  3997. inc edi
  3998. sub [ebx],edi
  3999. x_axix_ok:
  4000. mov ebx,[y]
  4001. mov edi,[h]
  4002. mov esi,[ebx]
  4003. add edi,[ebx]
  4004. sub edi,[height]
  4005. neg esi
  4006. dec edi
  4007. test esi,edi
  4008. jl confi_out
  4009. mov eax,1
  4010. test esi,esi
  4011. jl shift_top
  4012. mov [dword ptr ebx],0
  4013. //ret
  4014. jmp confi_out
  4015. shift_top:
  4016. inc edi
  4017. sub [ebx],edi
  4018. confi_out:
  4019. //ret
  4020. //ENDP Confine_Rect
  4021. }
  4022. }
  4023. /*
  4024. ; $Header: //depot/Projects/Mobius/QA/Project/Run/SOURCECODE/TIBERIANDAWN/WIN32LIB/DrawMisc.cpp#139 $
  4025. ;***************************************************************************
  4026. ;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  4027. ;***************************************************************************
  4028. ;* *
  4029. ;* Project Name : Library routine *
  4030. ;* *
  4031. ;* File Name : UNCOMP.ASM *
  4032. ;* *
  4033. ;* Programmer : Christopher Yates *
  4034. ;* *
  4035. ;* Last Update : 20 August, 1990 [CY] *
  4036. ;* *
  4037. ;*-------------------------------------------------------------------------*
  4038. ;* Functions: *
  4039. ;* *
  4040. ; ULONG LCW_Uncompress(BYTE *source, BYTE *dest, ULONG length); *
  4041. ;* *
  4042. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  4043. IDEAL
  4044. P386
  4045. MODEL USE32 FLAT
  4046. GLOBAL C LCW_Uncompress :NEAR
  4047. CODESEG
  4048. ; ----------------------------------------------------------------
  4049. ;
  4050. ; Here are prototypes for the routines defined within this module:
  4051. ;
  4052. ; ULONG LCW_Uncompress(BYTE *source, BYTE *dest, ULONG length);
  4053. ;
  4054. ; ----------------------------------------------------------------
  4055. */
  4056. extern "C" unsigned long __cdecl LCW_Uncompress(void *source, void *dest, unsigned long length_)
  4057. {
  4058. //PROC LCW_Uncompress C near
  4059. //
  4060. // USES ebx,ecx,edx,edi,esi
  4061. //
  4062. // ARG source:DWORD
  4063. // ARG dest:DWORD
  4064. // ARG length:DWORD
  4065. //;LOCALS
  4066. // LOCAL a1stdest:DWORD
  4067. // LOCAL maxlen:DWORD
  4068. // LOCAL lastbyte:DWORD
  4069. // LOCAL lastcom:DWORD
  4070. // LOCAL lastcom1:DWORD
  4071. unsigned long a1stdest;
  4072. unsigned long maxlen;
  4073. unsigned long lastbyte;
  4074. //unsigned long lastcom;
  4075. //unsigned long lastcom1;
  4076. __asm {
  4077. mov edi,[dest]
  4078. mov esi,[source]
  4079. mov edx,[length_]
  4080. ;
  4081. ;
  4082. ; uncompress data to the following codes in the format b = byte, w = word
  4083. ; n = byte code pulled from compressed data
  4084. ; Bit field of n command description
  4085. ; n=0xxxyyyy,yyyyyyyy short run back y bytes and run x+3
  4086. ; n=10xxxxxx,n1,n2,...,nx+1 med length copy the next x+1 bytes
  4087. ; n=11xxxxxx,w1 med run run x+3 bytes from offset w1
  4088. ; n=11111111,w1,w2 long copy copy w1 bytes from offset w2
  4089. ; n=11111110,w1,b1 long run run byte b1 for w1 bytes
  4090. ; n=10000000 end end of data reached
  4091. ;
  4092. mov [a1stdest],edi
  4093. add edx,edi
  4094. mov [lastbyte],edx
  4095. cld ; make sure all lod and sto are forward
  4096. mov ebx,esi ; save the source offset
  4097. loop_label:
  4098. mov eax,[lastbyte]
  4099. sub eax,edi ; get the remaining byte to uncomp
  4100. jz short out_label ; were done
  4101. mov [maxlen],eax ; save for string commands
  4102. mov esi,ebx ; mov in the source index
  4103. xor eax,eax
  4104. mov al,[esi]
  4105. inc esi
  4106. test al,al ; see if its a short run
  4107. js short notshort
  4108. mov ecx,eax ;put count nibble in cl
  4109. mov ah,al ; put rel offset high nibble in ah
  4110. and ah,0Fh ; only 4 bits count
  4111. shr cl,4 ; get run -3
  4112. add ecx,3 ; get actual run length
  4113. cmp ecx,[maxlen] ; is it too big to fit?
  4114. jbe short rsok ; if not, its ok
  4115. mov ecx,[maxlen] ; if so, max it out so it dosen't overrun
  4116. rsok:
  4117. mov al,[esi] ; get rel offset low byte
  4118. lea ebx,[esi+1] ; save the source offset
  4119. mov esi,edi ; get the current dest
  4120. sub esi,eax ; get relative offset
  4121. rep movsb
  4122. jmp loop_label
  4123. notshort:
  4124. test al,40h ; is it a length?
  4125. jne short notlength ; if not it could be med or long run
  4126. cmp al,80h ; is it the end?
  4127. je short out_label ; if so its over
  4128. mov cl,al ; put the byte in count register
  4129. and ecx,3Fh ; and off the extra bits
  4130. cmp ecx,[maxlen] ; is it too big to fit?
  4131. jbe short lenok ; if not, its ok
  4132. mov ecx,[maxlen] ; if so, max it out so it dosen't overrun
  4133. lenok:
  4134. rep movsb
  4135. mov ebx,esi ; save the source offset
  4136. jmp loop_label
  4137. out_label:
  4138. mov eax,edi
  4139. sub eax,[a1stdest]
  4140. jmp label_exit
  4141. notlength:
  4142. mov cl,al ; get the entire code
  4143. and ecx,3Fh ; and off all but the size -3
  4144. add ecx,3 ; add 3 for byte count
  4145. cmp al,0FEh
  4146. jne short notrunlength
  4147. xor ecx,ecx
  4148. mov cx,[esi]
  4149. xor eax,eax
  4150. mov al,[esi+2]
  4151. lea ebx,[esi+3] ;save the source offset
  4152. cmp ecx,[maxlen] ; is it too big to fit?
  4153. jbe short runlenok ; if not, its ok
  4154. mov ecx,[maxlen] ; if so, max it out so it dosen't overrun
  4155. runlenok:
  4156. test ecx,0ffe0h
  4157. jnz dont_use_stosb
  4158. rep stosb
  4159. jmp loop_label
  4160. dont_use_stosb:
  4161. mov ah,al
  4162. mov edx,eax
  4163. shl eax,16
  4164. or eax,edx
  4165. test edi,3
  4166. jz aligned
  4167. mov [edi],eax
  4168. mov edx,edi
  4169. and edi,0fffffffch
  4170. lea edi,[edi+4]
  4171. and edx,3
  4172. dec dl
  4173. xor dl,3
  4174. sub ecx,edx
  4175. aligned:
  4176. mov edx,ecx
  4177. shr ecx,2
  4178. rep stosd
  4179. and edx,3
  4180. jz loop_label
  4181. mov ecx,edx
  4182. rep stosb
  4183. jmp loop_label
  4184. notrunlength:
  4185. cmp al,0FFh ; is it a long run?
  4186. jne short notlong ; if not use the code as the size
  4187. xor ecx,ecx
  4188. xor eax,eax
  4189. mov cx,[esi] ; if so, get the size
  4190. lea esi,[esi+2]
  4191. notlong:
  4192. mov ax,[esi] ;get the real index
  4193. add eax,[a1stdest] ;add in the 1st index
  4194. lea ebx,[esi+2] ;save the source offset
  4195. cmp ecx,[maxlen] ;compare for overrun
  4196. mov esi,eax ;use eax as new source
  4197. jbe short runok ; if not, its ok
  4198. mov ecx,[maxlen] ; if so, max it out so it dosen't overrun
  4199. runok:
  4200. test ecx,0ffe0h
  4201. jnz dont_use_movsb
  4202. rep movsb
  4203. jmp loop_label
  4204. dont_use_movsb:
  4205. lea edx,[edi+0fffffffch]
  4206. cmp esi,edx
  4207. ja use_movsb
  4208. test edi,3
  4209. jz aligned2
  4210. mov eax,[esi]
  4211. mov [edi],eax
  4212. mov edx,edi
  4213. and edi,0fffffffch
  4214. lea edi,[edi+4]
  4215. and edx,3
  4216. dec dl
  4217. xor dl,3
  4218. sub ecx,edx
  4219. add esi,edx
  4220. aligned2:
  4221. mov edx,ecx
  4222. shr ecx,2
  4223. and edx,3
  4224. rep movsd
  4225. mov ecx,edx
  4226. use_movsb:
  4227. rep movsb
  4228. jmp loop_label
  4229. label_exit:
  4230. mov eax,edi
  4231. mov ebx,[dest]
  4232. sub eax,ebx
  4233. //ret
  4234. }
  4235. }
  4236. /*
  4237. ;***************************************************************************
  4238. ;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  4239. ;***************************************************************************
  4240. ;* *
  4241. ;* Project Name : Westwood 32 bit Library *
  4242. ;* *
  4243. ;* File Name : TOPAGE.ASM *
  4244. ;* *
  4245. ;* Programmer : Phil W. Gorrow *
  4246. ;* *
  4247. ;* Start Date : June 8, 1994 *
  4248. ;* *
  4249. ;* Last Update : June 15, 1994 [PWG] *
  4250. ;* *
  4251. ;*-------------------------------------------------------------------------*
  4252. ;* Functions: *
  4253. ;* Buffer_To_Page -- Copies a linear buffer to a virtual viewport *
  4254. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  4255. IDEAL
  4256. P386
  4257. MODEL USE32 FLAT
  4258. TRANSP equ 0
  4259. INCLUDE ".\drawbuff.inc"
  4260. INCLUDE ".\gbuffer.inc"
  4261. CODESEG
  4262. ;***************************************************************************
  4263. ;* VVC::TOPAGE -- Copies a linear buffer to a virtual viewport *
  4264. ;* *
  4265. ;* INPUT: WORD x_pixel - x pixel on viewport to copy from *
  4266. ;* WORD y_pixel - y pixel on viewport to copy from *
  4267. ;* WORD pixel_width - the width of copy region *
  4268. ;* WORD pixel_height - the height of copy region *
  4269. ;* BYTE * src - buffer to copy from *
  4270. ;* VVPC * dest - virtual viewport to copy to *
  4271. ;* *
  4272. ;* OUTPUT: none *
  4273. ;* *
  4274. ;* WARNINGS: Coordinates and dimensions will be adjusted if they exceed *
  4275. ;* the boundaries. In the event that no adjustment is *
  4276. ;* possible this routine will abort. If the size of the *
  4277. ;* region to copy exceeds the size passed in for the buffer *
  4278. ;* the routine will automatically abort. *
  4279. ;* *
  4280. ;* HISTORY: *
  4281. ;* 06/15/1994 PWG : Created. *
  4282. ;*=========================================================================*
  4283. */
  4284. extern "C" long __cdecl Buffer_To_Page(int x_pixel, int y_pixel, int pixel_width, int pixel_height, void *src, void *dest)
  4285. {
  4286. /*
  4287. PROC Buffer_To_Page C near
  4288. USES eax,ebx,ecx,edx,esi,edi
  4289. ;*===================================================================
  4290. ;* define the arguements that our function takes.
  4291. ;*===================================================================
  4292. ARG x_pixel :DWORD ; x pixel position in source
  4293. ARG y_pixel :DWORD ; y pixel position in source
  4294. ARG pixel_width :DWORD ; width of rectangle to blit
  4295. ARG pixel_height:DWORD ; height of rectangle to blit
  4296. ARG src :DWORD ; this is a member function
  4297. ARG dest :DWORD ; what are we blitting to
  4298. ; ARG trans :DWORD ; do we deal with transparents?
  4299. ;*===================================================================
  4300. ; Define some locals so that we can handle things quickly
  4301. ;*===================================================================
  4302. LOCAL x1_pixel :dword
  4303. LOCAL y1_pixel :dword
  4304. local scr_x : dword
  4305. local scr_y : dword
  4306. LOCAL dest_ajust_width:DWORD
  4307. LOCAL scr_ajust_width:DWORD
  4308. LOCAL dest_area : dword
  4309. */
  4310. unsigned long x1_pixel;
  4311. unsigned long y1_pixel;
  4312. unsigned long scr_x;
  4313. unsigned long scr_y;
  4314. unsigned long dest_ajust_width;
  4315. unsigned long scr_ajust_width;
  4316. //unsigned long dest_area;
  4317. __asm {
  4318. cmp [ src ] , 0
  4319. jz real_out
  4320. ; Clip dest Rectangle against source Window boundaries.
  4321. mov [ scr_x ] , 0
  4322. mov [ scr_y ] , 0
  4323. mov esi , [ dest ] ; get ptr to dest
  4324. xor ecx , ecx
  4325. xor edx , edx
  4326. mov edi , [esi]GraphicViewPortClass.Width ; get width into register
  4327. mov ebx , [ x_pixel ]
  4328. mov eax , [ x_pixel ]
  4329. add ebx , [ pixel_width ]
  4330. shld ecx , eax , 1
  4331. mov [ x1_pixel ] , ebx
  4332. inc edi
  4333. shld edx , ebx , 1
  4334. sub eax , edi
  4335. sub ebx , edi
  4336. shld ecx , eax , 1
  4337. shld edx , ebx , 1
  4338. mov edi, [esi]GraphicViewPortClass.Height ; get height into register
  4339. mov ebx , [ y_pixel ]
  4340. mov eax , [ y_pixel ]
  4341. add ebx , [ pixel_height ]
  4342. shld ecx , eax , 1
  4343. mov [ y1_pixel ] , ebx
  4344. inc edi
  4345. shld edx , ebx , 1
  4346. sub eax , edi
  4347. sub ebx , edi
  4348. shld ecx , eax , 1
  4349. shld edx , ebx , 1
  4350. xor cl , 5
  4351. xor dl , 5
  4352. mov al , cl
  4353. test dl , cl
  4354. jnz real_out
  4355. or al , dl
  4356. jz do_blit
  4357. test cl , 1000b
  4358. jz dest_left_ok
  4359. mov eax , [ x_pixel ]
  4360. neg eax
  4361. mov [ x_pixel ] , 0
  4362. mov [ scr_x ] , eax
  4363. dest_left_ok:
  4364. test cl , 0010b
  4365. jz dest_bottom_ok
  4366. mov eax , [ y_pixel ]
  4367. neg eax
  4368. mov [ y_pixel ] , 0
  4369. mov [ scr_y ] , eax
  4370. dest_bottom_ok:
  4371. test dl , 0100b
  4372. jz dest_right_ok
  4373. mov eax , [esi]GraphicViewPortClass.Width ; get width into register
  4374. mov [ x1_pixel ] , eax
  4375. dest_right_ok:
  4376. test dl , 0001b
  4377. jz do_blit
  4378. mov eax , [esi]GraphicViewPortClass.Height ; get width into register
  4379. mov [ y1_pixel ] , eax
  4380. do_blit:
  4381. cld
  4382. mov eax , [esi]GraphicViewPortClass.XAdd
  4383. add eax , [esi]GraphicViewPortClass.Width
  4384. add eax , [esi]GraphicViewPortClass.Pitch
  4385. mov edi , [esi]GraphicViewPortClass.Offset
  4386. mov ecx , eax
  4387. mul [ y_pixel ]
  4388. add edi , [ x_pixel ]
  4389. add edi , eax
  4390. add ecx , [ x_pixel ]
  4391. sub ecx , [ x1_pixel ]
  4392. mov [ dest_ajust_width ] , ecx
  4393. mov esi , [ src ]
  4394. mov eax , [ pixel_width ]
  4395. sub eax , [ x1_pixel ]
  4396. add eax , [ x_pixel ]
  4397. mov [ scr_ajust_width ] , eax
  4398. mov eax , [ scr_y ]
  4399. mul [ pixel_width ]
  4400. add eax , [ scr_x ]
  4401. add esi , eax
  4402. mov edx , [ y1_pixel ]
  4403. mov eax , [ x1_pixel ]
  4404. sub edx , [ y_pixel ]
  4405. jle real_out
  4406. sub eax , [ x_pixel ]
  4407. jle real_out
  4408. ; ********************************************************************
  4409. ; Forward bitblit only
  4410. //IF TRANSP
  4411. // test [ trans ] , 1
  4412. // jnz forward_Blit_trans
  4413. //ENDIF
  4414. ; the inner loop is so efficient that
  4415. ; the optimal consept no longer apply because
  4416. ; the optimal byte have to by a number greather than 9 bytes
  4417. cmp eax , 10
  4418. jl forward_loop_bytes
  4419. forward_loop_dword:
  4420. mov ecx , edi
  4421. mov ebx , eax
  4422. neg ecx
  4423. and ecx , 3
  4424. sub ebx , ecx
  4425. rep movsb
  4426. mov ecx , ebx
  4427. shr ecx , 2
  4428. rep movsd
  4429. mov ecx , ebx
  4430. and ecx , 3
  4431. rep movsb
  4432. add esi , [ scr_ajust_width ]
  4433. add edi , [ dest_ajust_width ]
  4434. dec edx
  4435. jnz forward_loop_dword
  4436. jmp real_out //ret
  4437. forward_loop_bytes:
  4438. mov ecx , eax
  4439. rep movsb
  4440. add esi , [ scr_ajust_width ]
  4441. add edi , [ dest_ajust_width ]
  4442. dec edx ; decrement the height
  4443. jnz forward_loop_bytes
  4444. // ret
  4445. //IF TRANSP
  4446. //
  4447. //
  4448. //forward_Blit_trans:
  4449. //
  4450. //
  4451. // mov ecx , eax
  4452. // and ecx , 01fh
  4453. // lea ecx , [ ecx + ecx * 4 ]
  4454. // neg ecx
  4455. // shr eax , 5
  4456. // lea ecx , [ transp_reference + ecx * 2 ]
  4457. // mov [ y1_pixel ] , ecx
  4458. //
  4459. //
  4460. //forward_loop_trans:
  4461. // mov ecx , eax
  4462. // jmp [ y1_pixel ]
  4463. //forward_trans_line:
  4464. // REPT 32
  4465. // local transp_pixel
  4466. // mov bl , [ esi ]
  4467. // inc esi
  4468. // test bl , bl
  4469. // jz transp_pixel
  4470. // mov [ edi ] , bl
  4471. // transp_pixel:
  4472. // inc edi
  4473. // ENDM
  4474. // transp_reference:
  4475. // dec ecx
  4476. // jge forward_trans_line
  4477. // add esi , [ scr_ajust_width ]
  4478. // add edi , [ dest_ajust_width ]
  4479. // dec edx
  4480. // jnz forward_loop_trans
  4481. // ret
  4482. //ENDIF
  4483. real_out:
  4484. //ret
  4485. }
  4486. }
  4487. //ENDP Buffer_To_Page
  4488. //END
  4489. /*
  4490. ;***************************************************************************
  4491. ;* VVPC::GET_PIXEL -- Gets a pixel from the current view port *
  4492. ;* *
  4493. ;* INPUT: WORD the x pixel on the screen. *
  4494. ;* WORD the y pixel on the screen. *
  4495. ;* *
  4496. ;* OUTPUT: UBYTE the pixel at the specified location *
  4497. ;* *
  4498. ;* WARNING: If pixel is to be placed outside of the viewport then *
  4499. ;* this routine will abort. *
  4500. ;* *
  4501. ;* HISTORY: *
  4502. ;* 06/07/1994 PWG : Created. *
  4503. ;*=========================================================================*
  4504. PROC Buffer_Get_Pixel C near
  4505. USES ebx,ecx,edx,edi
  4506. ARG this_object:DWORD ; this is a member function
  4507. ARG x_pixel:DWORD ; x position of pixel to set
  4508. ARG y_pixel:DWORD ; y position of pixel to set
  4509. */
  4510. extern "C" int __cdecl Buffer_Get_Pixel(void * this_object, int x_pixel, int y_pixel)
  4511. {
  4512. __asm {
  4513. ;*===================================================================
  4514. ; Get the viewport information and put bytes per row in ecx
  4515. ;*===================================================================
  4516. mov ebx,[this_object] ; get a pointer to viewport
  4517. xor eax,eax
  4518. mov edi,[ebx]GraphicViewPortClass.Offset ; get the correct offset
  4519. mov ecx,[ebx]GraphicViewPortClass.Height ; edx = height of viewport
  4520. mov edx,[ebx]GraphicViewPortClass.Width ; ecx = width of viewport
  4521. ;*===================================================================
  4522. ; Verify that the X pixel offset if legal
  4523. ;*===================================================================
  4524. mov eax,[x_pixel] ; find the x position
  4525. cmp eax,edx ; is it out of bounds
  4526. jae short exit_label ; if so then get out
  4527. add edi,eax ; otherwise add in offset
  4528. ;*===================================================================
  4529. ; Verify that the Y pixel offset if legal
  4530. ;*===================================================================
  4531. mov eax,[y_pixel] ; get the y position
  4532. cmp eax,ecx ; is it out of bounds
  4533. jae exit_label ; if so then get out
  4534. add edx,[ebx]GraphicViewPortClass.XAdd ; otherwise find bytes per row
  4535. add edx,[ebx]GraphicViewPortClass.Pitch ; otherwise find bytes per row
  4536. mul edx ; offset = bytes per row * y
  4537. add edi,eax ; add it into the offset
  4538. ;*===================================================================
  4539. ; Write the pixel to the screen
  4540. ;*===================================================================
  4541. xor eax,eax ; clear the word
  4542. mov al,[edi] ; read in the pixel
  4543. exit_label:
  4544. //ret
  4545. //ENDP Buffer_Get_Pixel
  4546. }
  4547. }