DrawMisc.cpp 150 KB

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