ID_VW_AC.ASM 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. ; Catacomb Armageddon Source Code
  2. ; Copyright (C) 1993-2014 Flat Rock Software
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License along
  15. ; with this program; if not, write to the Free Software Foundation, Inc.,
  16. ; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. ;=================================
  18. ;
  19. ; CGA view manager routines
  20. ;
  21. ;=================================
  22. ;============================================================================
  23. ;
  24. ; All of these routines draw into a floating virtual screen segment in main
  25. ; memory. bufferofs points to the origin of the drawing page in screenseg.
  26. ; The routines that write out words must take into account buffer wrapping
  27. ; and not write a word at 0xffff (which causes an exception on 386s).
  28. ;
  29. ; The direction flag should be clear
  30. ;
  31. ;============================================================================
  32. DATASEG
  33. plotpixels db 0c0h,030h,0ch,03h
  34. colorbyte db 000000b,01010101b,10101010b,11111111b
  35. colorword dw 0,5555h,0aaaah,0ffffh
  36. CODESEG
  37. ;============================================================================
  38. ;
  39. ; VW_Plot (int x,y,color)
  40. ;
  41. ;============================================================================
  42. PROC VW_Plot x:WORD, y:WORD, color:WORD
  43. PUBLIC VW_Plot
  44. USES SI,DI
  45. mov es,[screenseg]
  46. mov di,[bufferofs]
  47. mov bx,[y]
  48. shl bx,1
  49. add di,[ylookup+bx]
  50. mov bx,[x]
  51. mov ax,bx
  52. shr ax,1
  53. shr ax,1
  54. add di,ax ; di = byte on screen
  55. and bx,3
  56. mov ah,[plotpixels+bx]
  57. mov bx,[color]
  58. mov cl,[colorbyte+bx]
  59. and cl,ah
  60. not ah
  61. mov al,[es:di]
  62. and al,ah ; mask off other pixels
  63. or al,cl
  64. stosb
  65. ret
  66. ENDP
  67. ;============================================================================
  68. ;
  69. ; VW_Vlin (int yl,yh,x,color)
  70. ;
  71. ;============================================================================
  72. PROC VW_Vlin yl:WORD, yh:WORD, x:WORD, color:WORD
  73. PUBLIC VW_Vlin
  74. USES SI,DI
  75. mov es,[screenseg]
  76. mov di,[bufferofs]
  77. mov bx,[yl]
  78. shl bx,1
  79. add di,[ylookup+bx]
  80. mov bx,[x]
  81. mov ax,bx
  82. shr ax,1
  83. shr ax,1
  84. add di,ax ; di = byte on screen
  85. and bx,3
  86. mov ah,[plotpixels+bx]
  87. mov bx,[color]
  88. mov bl,[colorbyte+bx]
  89. and bl,ah
  90. not ah
  91. mov cx,[yh]
  92. sub cx,[yl]
  93. inc cx ;number of pixels to plot
  94. mov dx,[linewidth]
  95. @@plot:
  96. mov al,[es:di]
  97. and al,ah ; mask off other pixels
  98. or al,bl
  99. mov [es:di],al
  100. add di,dx
  101. loop @@plot
  102. ret
  103. ret
  104. ENDP
  105. ;============================================================================
  106. ;===================
  107. ;
  108. ; VW_DrawTile8
  109. ;
  110. ; xcoord in bytes (8 pixels), ycoord in pixels
  111. ; All Tile8s are in one grseg, so an offset is calculated inside it
  112. ;
  113. ; DONE
  114. ;
  115. ;===================
  116. PROC VW_DrawTile8 xcoord:WORD, ycoord:WORD, tile:WORD
  117. PUBLIC VW_DrawTile8
  118. USES SI,DI
  119. mov es,[screenseg]
  120. mov di,[bufferofs]
  121. add di,[xcoord]
  122. mov bx,[ycoord]
  123. shl bx,1
  124. add di,[ylookup+bx]
  125. mov bx,[linewidth]
  126. sub bx,2
  127. mov si,[tile]
  128. shl si,1
  129. shl si,1
  130. shl si,1
  131. shl si,1
  132. mov ds,[grsegs+STARTTILE8*2] ; segment for all tile8s
  133. ;
  134. ; start drawing
  135. ;
  136. REPT 7
  137. movsb ;no word moves because of segment wrapping
  138. movsb
  139. add di,bx
  140. ENDM
  141. movsb
  142. movsb
  143. mov ax,ss
  144. mov ds,ax ;restore turbo's data segment
  145. ret
  146. ENDP
  147. ;============================================================================
  148. ;
  149. ; VW_MaskBlock
  150. ;
  151. ; Draws a masked block shape to the screen. bufferofs is NOT accounted for.
  152. ; The mask comes first, then the data. Seperate unwound routines are used
  153. ; to speed drawing.
  154. ;
  155. ; Mask blocks will allways be an even width because of the way IGRAB works
  156. ;
  157. ; DONE
  158. ;
  159. ;============================================================================
  160. DATASEG
  161. UNWOUNDMASKS = 18
  162. maskroutines dw mask0,mask0,mask2E,mask2O,mask4E,mask4O
  163. dw mask6E,mask6O,mask8E,mask8O,mask10E,mask10O
  164. dw mask12E,mask12O,mask14E,mask14O,mask16E,mask16O
  165. dw mask18E,mask18O
  166. routinetouse dw ?
  167. CODESEG
  168. PROC VW_MaskBlock segm:WORD, ofs:WORD, dest:WORD, wide:WORD, height:WORD, planesize:WORD
  169. PUBLIC VW_MaskBlock
  170. USES SI,DI
  171. mov es,[screenseg]
  172. mov di,[wide]
  173. mov dx,[linewidth]
  174. sub dx,di ;dx = delta to start of next line
  175. mov bx,[planesize] ; si+bx = data location
  176. cmp di,UNWOUNDMASKS
  177. jbe @@unwoundroutine
  178. ;==============
  179. ;
  180. ; General purpose masked block drawing. This could be optimised into
  181. ; four routines to use words, but few play loop sprites should be this big!
  182. ;
  183. ;==============
  184. mov [ss:linedelta],dx
  185. mov ds,[segm]
  186. mov si,[ofs]
  187. mov di,[dest]
  188. mov dx,[height] ;scan lines to draw
  189. @@lineloopgen:
  190. mov cx,[wide]
  191. @@byteloop:
  192. mov al,[es:di]
  193. and al,[si]
  194. or al,[bx+si]
  195. inc si
  196. stosb
  197. loop @@byteloop
  198. add di,[ss:linedelta]
  199. dec dx
  200. jnz @@lineloopgen
  201. mask0:
  202. mov ax,ss
  203. mov ds,ax
  204. ret ;width of 0 = no drawing
  205. ;=================
  206. ;
  207. ; use the unwound routines
  208. ;
  209. ;=================
  210. @@unwoundroutine:
  211. shr di,1 ;we only have even width unwound routines
  212. mov cx,[dest]
  213. shr cx,1
  214. rcl di,1 ;shift a 1 in if destination is odd
  215. shl di,1
  216. mov ax,[maskroutines+di] ;call the right routine
  217. mov ds,[segm]
  218. mov si,[ofs]
  219. mov di,[dest]
  220. mov cx,[height] ;scan lines to draw
  221. jmp ax ;draw it
  222. ;=================
  223. ;
  224. ; Horizontally unwound routines to draw certain masked blocks faster
  225. ;
  226. ;=================
  227. MACRO MASKBYTE
  228. mov al,[es:di]
  229. and al,[si]
  230. or al,[bx+si]
  231. inc si
  232. stosb
  233. ENDM
  234. MACRO MASKWORD
  235. mov ax,[es:di]
  236. and ax,[si]
  237. or ax,[bx+si]
  238. inc si
  239. inc si
  240. stosw
  241. ENDM
  242. MACRO SPRITELOOP addr
  243. add di,dx
  244. loop addr
  245. mov ax,ss
  246. mov ds,ax
  247. ret
  248. ENDM
  249. EVEN
  250. mask2E:
  251. MASKWORD
  252. SPRITELOOP mask2E
  253. EVEN
  254. mask2O:
  255. MASKBYTE
  256. MASKBYTE
  257. SPRITELOOP mask2O
  258. EVEN
  259. mask4E:
  260. MASKWORD
  261. MASKWORD
  262. SPRITELOOP mask4E
  263. EVEN
  264. mask4O:
  265. MASKBYTE
  266. MASKWORD
  267. MASKBYTE
  268. SPRITELOOP mask4O
  269. EVEN
  270. mask6E:
  271. MASKWORD
  272. MASKWORD
  273. MASKWORD
  274. SPRITELOOP mask6E
  275. EVEN
  276. mask6O:
  277. MASKBYTE
  278. MASKWORD
  279. MASKWORD
  280. MASKBYTE
  281. SPRITELOOP mask6O
  282. EVEN
  283. mask8E:
  284. MASKWORD
  285. MASKWORD
  286. MASKWORD
  287. MASKWORD
  288. SPRITELOOP mask8E
  289. EVEN
  290. mask8O:
  291. MASKBYTE
  292. MASKWORD
  293. MASKWORD
  294. MASKWORD
  295. MASKBYTE
  296. SPRITELOOP mask8O
  297. EVEN
  298. mask10E:
  299. MASKWORD
  300. MASKWORD
  301. MASKWORD
  302. MASKWORD
  303. MASKWORD
  304. SPRITELOOP mask10E
  305. EVEN
  306. mask10O:
  307. MASKBYTE
  308. MASKWORD
  309. MASKWORD
  310. MASKWORD
  311. MASKWORD
  312. MASKBYTE
  313. SPRITELOOP mask10O
  314. EVEN
  315. mask12E:
  316. MASKWORD
  317. MASKWORD
  318. MASKWORD
  319. MASKWORD
  320. MASKWORD
  321. MASKWORD
  322. SPRITELOOP mask12E
  323. EVEN
  324. mask12O:
  325. MASKBYTE
  326. MASKWORD
  327. MASKWORD
  328. MASKWORD
  329. MASKWORD
  330. MASKWORD
  331. MASKBYTE
  332. SPRITELOOP mask12O
  333. EVEN
  334. mask14E:
  335. MASKWORD
  336. MASKWORD
  337. MASKWORD
  338. MASKWORD
  339. MASKWORD
  340. MASKWORD
  341. MASKWORD
  342. SPRITELOOP mask14E
  343. EVEN
  344. mask14O:
  345. MASKBYTE
  346. MASKWORD
  347. MASKWORD
  348. MASKWORD
  349. MASKWORD
  350. MASKWORD
  351. MASKWORD
  352. MASKBYTE
  353. SPRITELOOP mask14O
  354. EVEN
  355. mask16E:
  356. MASKWORD
  357. MASKWORD
  358. MASKWORD
  359. MASKWORD
  360. MASKWORD
  361. MASKWORD
  362. MASKWORD
  363. MASKWORD
  364. SPRITELOOP mask16E
  365. EVEN
  366. mask16O:
  367. MASKBYTE
  368. MASKWORD
  369. MASKWORD
  370. MASKWORD
  371. MASKWORD
  372. MASKWORD
  373. MASKWORD
  374. MASKWORD
  375. MASKBYTE
  376. SPRITELOOP mask16O
  377. EVEN
  378. mask18E:
  379. MASKWORD
  380. MASKWORD
  381. MASKWORD
  382. MASKWORD
  383. MASKWORD
  384. MASKWORD
  385. MASKWORD
  386. MASKWORD
  387. MASKWORD
  388. SPRITELOOP mask18E
  389. EVEN
  390. mask18O:
  391. MASKBYTE
  392. MASKWORD
  393. MASKWORD
  394. MASKWORD
  395. MASKWORD
  396. MASKWORD
  397. MASKWORD
  398. MASKWORD
  399. MASKWORD
  400. MASKBYTE
  401. SPRITELOOP mask18O
  402. ENDP
  403. ;============================================================================
  404. ;
  405. ; VW_ScreenToScreen
  406. ;
  407. ; Basic block copy routine. Copies one block of screen memory to another,
  408. ; bufferofs is NOT accounted for.
  409. ;
  410. ; DONE
  411. ;
  412. ;============================================================================
  413. PROC VW_ScreenToScreen source:WORD, dest:WORD, wide:WORD, height:WORD
  414. PUBLIC VW_ScreenToScreen
  415. USES SI,DI
  416. mov bx,[linewidth]
  417. sub bx,[wide]
  418. mov ax,[screenseg]
  419. mov es,ax
  420. mov ds,ax
  421. mov si,[source]
  422. mov di,[dest] ;start at same place in all planes
  423. mov dx,[height] ;scan lines to draw
  424. mov ax,[wide]
  425. ;
  426. ; if the width, source, and dest are all even, use word moves
  427. ; This is allways the case in the CGA refresh
  428. ;
  429. test ax,1
  430. jnz @@bytelineloop
  431. test si,1
  432. jnz @@bytelineloop
  433. test di,1
  434. jnz @@bytelineloop
  435. shr ax,1
  436. @@wordlineloop:
  437. mov cx,ax
  438. rep movsw
  439. add si,bx
  440. add di,bx
  441. dec dx
  442. jnz @@wordlineloop
  443. mov ax,ss
  444. mov ds,ax ;restore turbo's data segment
  445. ret
  446. @@bytelineloop:
  447. mov cx,ax
  448. rep movsb
  449. add si,bx
  450. add di,bx
  451. dec dx
  452. jnz @@bytelineloop
  453. mov ax,ss
  454. mov ds,ax ;restore turbo's data segment
  455. ret
  456. ENDP
  457. ;============================================================================
  458. ;
  459. ; VW_MemToScreen
  460. ;
  461. ; Basic block drawing routine. Takes a block shape at segment pointer source
  462. ; of width by height data, and draws it to dest in the virtual screen,
  463. ; based on linewidth. bufferofs is NOT accounted for.
  464. ; There are four drawing routines to provide the best optimized code while
  465. ; accounting for odd segment wrappings due to the floating screens.
  466. ;
  467. ; DONE
  468. ;
  469. ;============================================================================
  470. DATASEG
  471. memtoscreentable dw eventoeven,eventoodd,oddtoeven,oddtoodd
  472. CODESEG
  473. PROC VW_MemToScreen source:WORD, dest:WORD, wide:WORD, height:WORD
  474. PUBLIC VW_MemToScreen
  475. USES SI,DI
  476. mov es,[screenseg]
  477. mov bx,[linewidth]
  478. sub bx,[wide]
  479. mov ds,[source]
  480. xor si,si ;block is segment aligned
  481. xor di,di
  482. shr [wide],1 ;change wide to words, and see if carry is set
  483. rcl di,1 ;1 if wide is odd
  484. mov ax,[dest]
  485. shr ax,1
  486. rcl di,1 ;shift a 1 in if destination is odd
  487. shl di,1 ;to index into a word width table
  488. mov dx,[height] ;scan lines to draw
  489. mov ax,[wide]
  490. jmp [ss:memtoscreentable+di] ;call the right routine
  491. ;==============
  492. ;
  493. ; Copy an even width block to an even destination address
  494. ;
  495. ;==============
  496. eventoeven:
  497. mov di,[dest] ;start at same place in all planes
  498. EVEN
  499. @@lineloopEE:
  500. mov cx,ax
  501. rep movsw
  502. add di,bx
  503. dec dx
  504. jnz @@lineloopEE
  505. mov ax,ss
  506. mov ds,ax ;restore turbo's data segment
  507. ret
  508. ;==============
  509. ;
  510. ; Copy an odd width block to an even video address
  511. ;
  512. ;==============
  513. oddtoeven:
  514. mov di,[dest] ;start at same place in all planes
  515. EVEN
  516. @@lineloopOE:
  517. mov cx,ax
  518. rep movsw
  519. movsb ;copy the last byte
  520. add di,bx
  521. dec dx
  522. jnz @@lineloopOE
  523. mov ax,ss
  524. mov ds,ax ;restore turbo's data segment
  525. ret
  526. ;==============
  527. ;
  528. ; Copy an even width block to an odd video address
  529. ;
  530. ;==============
  531. eventoodd:
  532. mov di,[dest] ;start at same place in all planes
  533. dec ax ;one word has to be handled seperately
  534. EVEN
  535. @@lineloopEO:
  536. movsb
  537. mov cx,ax
  538. rep movsw
  539. movsb
  540. add di,bx
  541. dec dx
  542. jnz @@lineloopEO
  543. mov ax,ss
  544. mov ds,ax ;restore turbo's data segment
  545. ret
  546. ;==============
  547. ;
  548. ; Copy an odd width block to an odd video address
  549. ;
  550. ;==============
  551. oddtoodd:
  552. mov di,[dest] ;start at same place in all planes
  553. EVEN
  554. @@lineloopOO:
  555. movsb
  556. mov cx,ax
  557. rep movsw
  558. add di,bx
  559. dec dx
  560. jnz @@lineloopOO
  561. mov ax,ss
  562. mov ds,ax ;restore turbo's data segment
  563. ret
  564. ENDP
  565. ;===========================================================================
  566. ;
  567. ; VW_ScreenToMem
  568. ;
  569. ; Copies a block of video memory to main memory, in order from planes 0-3.
  570. ; This could be optimized along the lines of VW_MemToScreen to take advantage
  571. ; of word copies, but this is an infrequently called routine.
  572. ;
  573. ; DONE
  574. ;
  575. ;===========================================================================
  576. PROC VW_ScreenToMem source:WORD, dest:WORD, wide:WORD, height:WORD
  577. PUBLIC VW_ScreenToMem
  578. USES SI,DI
  579. mov es,[dest]
  580. mov bx,[linewidth]
  581. sub bx,[wide]
  582. mov ds,[screenseg]
  583. xor di,di
  584. mov si,[source]
  585. mov dx,[height] ;scan lines to draw
  586. @@lineloop:
  587. mov cx,[wide]
  588. rep movsb
  589. add si,bx
  590. dec dx
  591. jnz @@lineloop
  592. mov ax,ss
  593. mov ds,ax ;restore turbo's data segment
  594. ret
  595. ENDP
  596. ;===========================================================================
  597. ;
  598. ; MISC CGA ROUTINES
  599. ;
  600. ;===========================================================================
  601. ;==============
  602. ;
  603. ; VW_SetScreen
  604. ;
  605. ; DONE
  606. ;
  607. ;==============
  608. PROC VW_SetScreen crtc:WORD
  609. PUBLIC VW_SetScreen
  610. ;
  611. ; for some reason, my XT's EGA card doesn't like word outs to the CRTC
  612. ; index...
  613. ;
  614. cli
  615. mov cx,[crtc]
  616. mov dx,CRTC_INDEX
  617. mov al,0ch ;start address high register
  618. out dx,al
  619. inc dx
  620. mov al,ch
  621. out dx,al
  622. dec dx
  623. mov al,0dh ;start address low register
  624. out dx,al
  625. mov al,cl
  626. inc dx
  627. out dx,al
  628. sti
  629. ret
  630. ENDP
  631. if NUMFONT+NUMFONTM
  632. ;===========================================================================
  633. ;
  634. ; GENERAL FONT DRAWING ROUTINES
  635. ;
  636. ;===========================================================================
  637. DATASEG
  638. px dw ? ; proportional character drawing coordinates
  639. py dw ?
  640. pdrawmode db 11000b ; 8 = OR, 24 = XOR, put in GC_DATAROTATE
  641. fontcolor db 15 ;0-15 mapmask value
  642. PUBLIC px,py,pdrawmode,fontcolor
  643. ;
  644. ; offsets in font structure
  645. ;
  646. pcharheight = 0 ;lines high
  647. charloc = 2 ;pointers to every character
  648. charwidth = 514 ;every character's width in pixels
  649. propchar dw ? ; the character number to shift
  650. stringptr dw ?,?
  651. fontcolormask dw ? ; font color expands into this
  652. BUFFWIDTH = 100
  653. BUFFHEIGHT = 32 ; must be twice as high as font for masked fonts
  654. databuffer db BUFFWIDTH*BUFFHEIGHT dup (?)
  655. bufferwidth dw ? ; bytes with valid info / line
  656. bufferheight dw ? ; number of lines currently used
  657. bufferbyte dw ?
  658. bufferbit dw ?
  659. PUBLIC bufferwidth,bufferheight,bufferbyte,bufferbit
  660. screenspot dw ? ; where the buffer is going
  661. bufferextra dw ? ; add at end of a line copy
  662. screenextra dw ?
  663. CODESEG
  664. ;======================
  665. ;
  666. ; Macros to table shift a byte of font
  667. ;
  668. ;======================
  669. MACRO SHIFTNOXOR
  670. mov al,[es:bx] ; source
  671. xor ah,ah
  672. shl ax,1
  673. mov si,ax
  674. mov ax,[bp+si] ; table shift into two bytes
  675. or [di],al ; or with first byte
  676. inc di
  677. mov [di],ah ; replace next byte
  678. inc bx ; next source byte
  679. ENDM
  680. MACRO SHIFTWITHXOR
  681. mov al,[es:bx] ; source
  682. xor ah,ah
  683. shl ax,1
  684. mov si,ax
  685. mov ax,[bp+si] ; table shift into two bytes
  686. not ax
  687. and [di],al ; and with first byte
  688. inc di
  689. mov [di],ah ; replace next byte
  690. inc bx ; next source byte
  691. ENDM
  692. ;=======================
  693. ;
  694. ; VWL_XORBuffer
  695. ;
  696. ; Pass buffer start in SI (somewhere in databuffer)
  697. ; Draws the buffer to the screen buffer
  698. ;
  699. ;========================
  700. PROC VWL_XORBuffer NEAR
  701. USES BP
  702. mov bl,[fontcolor]
  703. xor bh,bh
  704. shl bx,1
  705. mov ax,[colorword+bx]
  706. mov [fontcolormask],ax
  707. mov es,[screenseg]
  708. mov di,[screenspot]
  709. mov bx,[bufferwidth] ;calculate offsets for end of each line
  710. mov [bufferwidth],bx
  711. or bx,bx
  712. jnz @@isthere
  713. ret ;nothing to draw
  714. @@isthere:
  715. test bx,1
  716. jnz @@odd
  717. jmp @@even
  718. ;
  719. ; clear the last byte so word draws can be used
  720. ;
  721. @@odd:
  722. mov al,0
  723. line = 0
  724. REPT BUFFHEIGHT
  725. mov [BYTE databuffer+BUFFWIDTH*line+bx],al
  726. line = line+1
  727. ENDM
  728. inc bx
  729. @@even:
  730. mov ax,[linewidth]
  731. sub ax,bx
  732. mov [screenextra],ax
  733. mov ax,BUFFWIDTH
  734. sub ax,bx
  735. mov [bufferextra],ax
  736. mov dx,bx
  737. shr dx,1 ;word to copy
  738. mov bx,[bufferheight] ;lines to copy
  739. mov bp,[fontcolormask]
  740. @@lineloop:
  741. mov cx,dx
  742. @@wordloop:
  743. lodsw ;get a word from the buffer
  744. and ax,bp
  745. xor [es:di],ax ;draw it
  746. add di,2
  747. loop @@wordloop
  748. add si,[bufferextra]
  749. add di,[screenextra]
  750. dec bx
  751. jnz @@lineloop
  752. ret
  753. ENDP
  754. DATASEG
  755. ;============================================================================
  756. ;
  757. ; NON MASKED FONT DRAWING ROUTINES
  758. ;
  759. ;============================================================================
  760. if numfont
  761. DATASEG
  762. shiftdrawtable dw 0,shift1wide,shift2wide,shift3wide,shift4wide
  763. dw shift5wide,shift6wide
  764. CODESEG
  765. ;==================
  766. ;
  767. ; ShiftPropChar
  768. ;
  769. ; Call with BX = character number (0-255)
  770. ; Draws one character to the buffer at bufferbyte/bufferbit, and adjusts
  771. ; them to the new position
  772. ;
  773. ;==================
  774. PROC ShiftPropChar NEAR
  775. mov es,[grsegs+STARTFONT*2] ;segment of font to use
  776. ;
  777. ; find character location, width, and height
  778. ;
  779. mov si,[es:charwidth+bx]
  780. and si,0ffh ;SI hold width in pixels
  781. shl bx,1
  782. mov bx,[es:charloc+bx] ;BX holds pointer to character data
  783. ;
  784. ; look up which shift table to use, based on bufferbit
  785. ;
  786. mov di,[bufferbit]
  787. shl di,1
  788. mov bp,[shifttabletable+di] ;BP holds pointer to shift table
  789. mov di,OFFSET databuffer
  790. add di,[bufferbyte] ;DI holds pointer to buffer
  791. mov cx,[bufferbit]
  792. add cx,si ;add twice because pixel == two bits
  793. add cx,si ;new bit position
  794. mov ax,cx
  795. and ax,7
  796. mov [bufferbit],ax ;new bit position
  797. mov ax,cx
  798. shr ax,1
  799. shr ax,1
  800. shr ax,1
  801. add [bufferbyte],ax ;new byte position
  802. add si,3
  803. shr si,1
  804. shr si,1 ;bytes the character is wide
  805. shl si,1 ;*2 to look up in shiftdrawtable
  806. mov cx,[es:pcharheight]
  807. mov dx,BUFFWIDTH
  808. jmp [ss:shiftdrawtable+si] ;procedure to draw this width
  809. ;
  810. ; one byte character
  811. ;
  812. shift1wide:
  813. dec dx
  814. EVEN
  815. @@loop1:
  816. SHIFTNOXOR
  817. add di,dx ; next line in buffer
  818. loop @@loop1
  819. ret
  820. ;
  821. ; two byte character
  822. ;
  823. shift2wide:
  824. dec dx
  825. dec dx
  826. EVEN
  827. @@loop2:
  828. SHIFTNOXOR
  829. SHIFTNOXOR
  830. add di,dx ; next line in buffer
  831. loop @@loop2
  832. ret
  833. ;
  834. ; three byte character
  835. ;
  836. shift3wide:
  837. sub dx,3
  838. EVEN
  839. @@loop3:
  840. SHIFTNOXOR
  841. SHIFTNOXOR
  842. SHIFTNOXOR
  843. add di,dx ; next line in buffer
  844. loop @@loop3
  845. ret
  846. ;
  847. ; four byte character
  848. ;
  849. shift4wide:
  850. sub dx,4
  851. EVEN
  852. @@loop4:
  853. SHIFTNOXOR
  854. SHIFTNOXOR
  855. SHIFTNOXOR
  856. SHIFTNOXOR
  857. add di,dx ; next line in buffer
  858. loop @@loop4
  859. ret
  860. ;
  861. ; five byte character
  862. ;
  863. shift5wide:
  864. sub dx,5
  865. EVEN
  866. @@loop5:
  867. SHIFTNOXOR
  868. SHIFTNOXOR
  869. SHIFTNOXOR
  870. SHIFTNOXOR
  871. SHIFTNOXOR
  872. add di,dx ; next line in buffer
  873. loop @@loop5
  874. ret
  875. ;
  876. ; six byte character
  877. ;
  878. shift6wide:
  879. sub dx,6
  880. EVEN
  881. @@loop6:
  882. SHIFTNOXOR
  883. SHIFTNOXOR
  884. SHIFTNOXOR
  885. SHIFTNOXOR
  886. SHIFTNOXOR
  887. SHIFTNOXOR
  888. add di,dx ; next line in buffer
  889. loop @@loop6
  890. ret
  891. ENDP
  892. ;============================================================================
  893. ;==================
  894. ;
  895. ; VW_DrawPropString
  896. ;
  897. ; Draws a C string of characters at px/py and advances px
  898. ;
  899. ;==================
  900. CODESEG
  901. PROC VW_DrawPropString string:DWORD
  902. PUBLIC VW_DrawPropString
  903. USES SI,DI
  904. ;
  905. ; proportional spaceing, which clears the buffer ahead of it, so only
  906. ; clear the first collumn
  907. ;
  908. mov al,0
  909. line = 0
  910. REPT BUFFHEIGHT
  911. mov [BYTE databuffer+BUFFWIDTH*line],al
  912. line = line+1
  913. ENDM
  914. ;
  915. ; shift the characters into the buffer
  916. ;
  917. @@shiftchars:
  918. mov ax,[px]
  919. and ax,3
  920. shl ax,1 ;one pixel == two bits
  921. mov [bufferbit],ax
  922. mov [bufferbyte],0
  923. mov ax,[WORD string]
  924. mov [stringptr],ax
  925. mov ax,[WORD string+2]
  926. mov [stringptr+2],ax
  927. @@shiftone:
  928. mov es,[stringptr+2]
  929. mov bx,[stringptr]
  930. inc [stringptr]
  931. mov bx,[es:bx]
  932. xor bh,bh
  933. or bl,bl
  934. jz @@allshifted
  935. call ShiftPropChar
  936. jmp @@shiftone
  937. @@allshifted:
  938. ;
  939. ; calculate position to draw buffer on screen
  940. ;
  941. mov bx,[py]
  942. shl bx,1
  943. mov di,[ylookup+bx]
  944. add di,[bufferofs]
  945. add di,[panadjust]
  946. mov ax,[px]
  947. shr ax,1
  948. shr ax,1 ;x location in bytes
  949. add di,ax
  950. mov [screenspot],di
  951. ;
  952. ; advance px
  953. ;
  954. mov ax,[bufferbyte]
  955. shl ax,1
  956. shl ax,1
  957. mov bx,[bufferbit]
  958. shr bx,1 ;two bits == one pixel
  959. or ax,bx
  960. add [px],ax
  961. ;
  962. ; draw it
  963. ;
  964. mov ax,[bufferbyte]
  965. test [bufferbit],7
  966. jz @@go
  967. inc ax ;so the partial byte also gets drawn
  968. @@go:
  969. mov [bufferwidth],ax
  970. mov es,[grsegs+STARTFONT*2]
  971. mov ax,[es:pcharheight]
  972. mov [bufferheight],ax
  973. mov si,OFFSET databuffer
  974. call VWL_XORBuffer
  975. ret
  976. ENDP
  977. endif ;numfont
  978. ;============================================================================
  979. ;
  980. ; MASKED FONT DRAWING ROUTINES
  981. ;
  982. ;============================================================================
  983. if numfontm
  984. DATASEG
  985. mshiftdrawtable dw 0,mshift1wide,mshift2wide,mshift3wide
  986. CODESEG
  987. ;==================
  988. ;
  989. ; ShiftMPropChar
  990. ;
  991. ; Call with BX = character number (0-255)
  992. ; Draws one character to the buffer at bufferbyte/bufferbit, and adjusts
  993. ; them to the new position
  994. ;
  995. ;==================
  996. PROC ShiftMPropChar NEAR
  997. mov es,[grsegs+STARTFONTM*2] ;segment of font to use
  998. ;
  999. ; find character location, width, and height
  1000. ;
  1001. mov si,[es:charwidth+bx]
  1002. and si,0ffh ;SI hold width in pixels
  1003. shl bx,1
  1004. mov bx,[es:charloc+bx] ;BX holds pointer to character data
  1005. ;
  1006. ; look up which shift table to use, based on bufferbit
  1007. ;
  1008. mov di,[bufferbit]
  1009. shl di,1
  1010. mov bp,[shifttabletable+di] ;BP holds pointer to shift table
  1011. mov di,OFFSET databuffer
  1012. add di,[bufferbyte] ;DI holds pointer to buffer
  1013. ;
  1014. ; advance position by character width
  1015. ;
  1016. mov cx,[bufferbit]
  1017. add cx,si ;new bit position
  1018. mov ax,cx
  1019. and ax,7
  1020. mov [bufferbit],ax ;new bit position
  1021. mov ax,cx
  1022. shr ax,1
  1023. shr ax,1
  1024. shr ax,1
  1025. add [bufferbyte],ax ;new byte position
  1026. add si,7
  1027. shr si,1
  1028. shr si,1
  1029. shr si,1 ;bytes the character is wide
  1030. shl si,1 ;*2 to look up in shiftdrawtable
  1031. mov cx,[es:pcharheight]
  1032. mov dx,BUFFWIDTH
  1033. jmp [ss:mshiftdrawtable+si] ;procedure to draw this width
  1034. ;
  1035. ; one byte character
  1036. ;
  1037. mshift1wide:
  1038. dec dx
  1039. EVEN
  1040. @@loop1m:
  1041. SHIFTWITHXOR
  1042. add di,dx ; next line in buffer
  1043. loop @@loop1m
  1044. mov cx,[es:pcharheight]
  1045. EVEN
  1046. @@loop1:
  1047. SHIFTNOXOR
  1048. add di,dx ; next line in buffer
  1049. loop @@loop1
  1050. ret
  1051. ;
  1052. ; two byte character
  1053. ;
  1054. mshift2wide:
  1055. dec dx
  1056. dec dx
  1057. EVEN
  1058. @@loop2m:
  1059. SHIFTWITHXOR
  1060. SHIFTWITHXOR
  1061. add di,dx ; next line in buffer
  1062. loop @@loop2m
  1063. mov cx,[es:pcharheight]
  1064. EVEN
  1065. @@loop2:
  1066. SHIFTNOXOR
  1067. SHIFTNOXOR
  1068. add di,dx ; next line in buffer
  1069. loop @@loop2
  1070. ret
  1071. ;
  1072. ; three byte character
  1073. ;
  1074. mshift3wide:
  1075. sub dx,3
  1076. EVEN
  1077. @@loop3m:
  1078. SHIFTWITHXOR
  1079. SHIFTWITHXOR
  1080. SHIFTWITHXOR
  1081. add di,dx ; next line in buffer
  1082. loop @@loop3m
  1083. mov cx,[es:pcharheight]
  1084. EVEN
  1085. @@loop3:
  1086. SHIFTNOXOR
  1087. SHIFTNOXOR
  1088. SHIFTNOXOR
  1089. add di,dx ; next line in buffer
  1090. loop @@loop3
  1091. ret
  1092. ENDP
  1093. ;============================================================================
  1094. ;==================
  1095. ;
  1096. ; VW_DrawMPropString
  1097. ;
  1098. ; Draws a C string of characters at px/py and advances px
  1099. ;
  1100. ;==================
  1101. PROC VW_DrawMPropString string:DWORD
  1102. PUBLIC VW_DrawMPropString
  1103. USES SI,DI
  1104. ;
  1105. ; clear out the first byte of the buffer, the rest will automatically be
  1106. ; cleared as characters are drawn into it
  1107. ;
  1108. mov es,[grsegs+STARTFONTM*2]
  1109. mov dx,[es:pcharheight]
  1110. mov di,OFFSET databuffer
  1111. mov ax,ds
  1112. mov es,ax
  1113. mov bx,BUFFWIDTH-1
  1114. mov cx,dx
  1115. mov al,0ffh
  1116. @@maskfill:
  1117. stosb ; fill the mask part with $ff
  1118. add di,bx
  1119. loop @@maskfill
  1120. mov cx,dx
  1121. xor al,al
  1122. @@datafill:
  1123. stosb ; fill the data part with $0
  1124. add di,bx
  1125. loop @@datafill
  1126. ;
  1127. ; shift the characters into the buffer
  1128. ;
  1129. mov ax,[px]
  1130. and ax,7
  1131. mov [bufferbit],ax
  1132. mov [bufferbyte],0
  1133. mov ax,[WORD string]
  1134. mov [stringptr],ax
  1135. mov ax,[WORD string+2]
  1136. mov [stringptr+2],ax
  1137. @@shiftone:
  1138. mov es,[stringptr+2]
  1139. mov bx,[stringptr]
  1140. inc [stringptr]
  1141. mov bx,[es:bx]
  1142. xor bh,bh
  1143. or bl,bl
  1144. jz @@allshifted
  1145. call ShiftMPropChar
  1146. jmp @@shiftone
  1147. @@allshifted:
  1148. ;
  1149. ; calculate position to draw buffer on screen
  1150. ;
  1151. mov bx,[py]
  1152. shl bx,1
  1153. mov di,[ylookup+bx]
  1154. add di,[bufferofs]
  1155. mov ax,[px]
  1156. shr ax,1
  1157. shr ax,1
  1158. shr ax,1 ;x location in bytes
  1159. add di,ax
  1160. mov [screenspot],di
  1161. ;
  1162. ; advance px
  1163. ;
  1164. mov ax,[bufferbyte]
  1165. shl ax,1
  1166. shl ax,1
  1167. shl ax,1
  1168. or ax,[bufferbit]
  1169. add [px],ax
  1170. ;
  1171. ; draw it
  1172. ;
  1173. mov ax,[bufferbyte]
  1174. test [bufferbit],7
  1175. jz @@go
  1176. inc ax ;so the partial byte also gets drawn
  1177. @@go:
  1178. mov [bufferwidth],ax
  1179. mov es,[grsegs+STARTFONTM*2]
  1180. mov ax,[es:pcharheight]
  1181. mov [bufferheight],ax
  1182. mov si,OFFSET databuffer
  1183. call BufferToScreen ; cut out mask
  1184. ; or in data
  1185. call BufferToScreen ; SI is still in the right position in buffer
  1186. ret
  1187. ENDP
  1188. endif ; if numfontm
  1189. endif ; if fonts