llcga.asm
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:21k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. TITLE LLCGA - CGA screen mode support
  2. ;***
  3. ;LLCGA - CGA screen mode support
  4. ;
  5. ; Copyright <C> 1986, Microsoft Corporation
  6. ;
  7. ;Purpose:
  8. ; Support for CGA graphics screen modes (BIOS 4,5,6).
  9. ; Note that this module module contains support
  10. ; code for all adapters capable of handling these
  11. ; screen modes and also attempts to compensate for
  12. ; the subtle differences in their treatment.
  13. ;
  14. ; This module sets hooks in the mode-independent
  15. ; modules to routines here for mode-dependent
  16. ; graphics support.  See the mode-independent
  17. ; modules for more precise descriptions of the
  18. ; purposes and interfaces of these routines.
  19. ;
  20. ; The following table summarizes the information for
  21. ; the modes and configurations covered:
  22. ;
  23. ;    C   | A      B
  24. ;    O   |  B T      I
  25. ;    L   |  I T  P      T
  26. ;    O      A M |  O R  A    C      S
  27. ;  S R      D O |  S I    C  G    H      / P
  28. ;  C B      A N | B    O  E    A   P  P L
  29. ;  R U C  R P I |  M U    L  X   Y  S    R   A  I A
  30. ;  E R O  O T T |  O T    O  R   R  I    B   G  X N
  31. ;  E S L  W E O |  D E    R  E   E  Z    O   E  E E
  32. ;  N T S  S R R |  E S    S  S   S  E    X   S  L S
  33. ; -- - -- -- - -- | -- --- ---- --- --- --- ---- --- - -
  34. ;  1 0 40 25 C x |  4  4  N/A 320 200  16 8x8   1  2 1
  35. ;  1 0 40 25 E x |  "   "  16  "   "   "  "   "  " "
  36. ;  1 1 40 25 C x |  5  "  N/A  "   "    "  "    "  " "
  37. ;  1 x 40 25 I x |  "   "   "   "   "    "  "    "  " "
  38. ;  1 1 40 25 E x |  "   "  16  "   "   "  "   "  " "
  39. ;  1 x 40 25 S x |  "   "   "   "   "    "  "    "  " "
  40. ;
  41. ;  2 x 80 25 C x |  6  2  N/A 640 200  16 8x8   1  1 1
  42. ;  2 x 80 25 I x |  "   "   "   "   "    "  "    "  " "
  43. ;  2 x 80 25 E x |  "   "  16  "   "   "  "   "  " "
  44. ;  2 x 80 25 S x |  "   "   "   "   "    "  "    "  " "
  45. ;
  46. ; Discussion of CGA odd/even line archtecture:
  47. ; CGA video memory is organized into two banks.  The first bank,
  48. ; starting at B800, contains all the even scan lines.  The second
  49. ; bank, starting at B800+8K, contains all the odd scan lines:
  50. ;
  51. ; Scan Offset
  52. ; Line from B800
  53. ; ---- ---------
  54. ; 0 0
  55. ; 1 8K
  56. ; 2 80
  57. ; 3 8K+80
  58. ; . .
  59. ; . .
  60. ; . .
  61. ;
  62. ; To move UP   from odd  scan line to even, add -8K    to current address
  63. ; To move UP   from even scan line to odd,  add +8K-80 to current address
  64. ; To move DOWN from odd  scan line to even, add -8K+80 to current address
  65. ; To move DOWN from even scan line to odd,  add +8K    to current address
  66. ;
  67. ;******************************************************************************
  68. INCLUDE switch.inc ;feature switches
  69. INCLUDE rmacros.inc
  70. USESEG _DATA
  71. USESEG _BSS
  72. USESEG GR_TEXT
  73. USESEG CN_TEXT
  74. USESEG XIB
  75. USESEG XI
  76. USESEG XIE
  77. INCLUDE seg.inc
  78. INCLUDE ibmunv.inc
  79. INCLUDE llgrp.inc ; Constant definitions
  80. INCLUDE idmac.inc
  81. INCLUDE grmac.inc ;ModeData macros
  82. INITIALIZER B$xINITCGA ;Put B$xINITCGA in initializer list
  83. sBegin _BSS
  84. ;
  85. ; ***************************************************************************
  86. ; Local variables
  87. ; ***************************************************************************
  88. ;
  89. staticB BackColor,,1 ;save background color for COLOR stmt
  90. ;__bBackColor is actually an attribute,
  91. ;and should stay 0 in graphics modes
  92. ;
  93. ; ***************************************************************************
  94. ; External function vectors
  95. ; ***************************************************************************
  96. ;
  97. externW b$PalPut
  98. ;
  99. ; ***************************************************************************
  100. ; External variables
  101. ; ***************************************************************************
  102. ;
  103. externW b$CurPages ; current active and visual page
  104. externB b$BiosMode
  105. externB b$Adapter
  106. externB b$Monitor
  107. externW b$ModeBurst
  108. externB b$ScreenMode
  109. externW b$VideoBase
  110. externB b$MaskC
  111. externB b$AttrC
  112. externW b$OffC
  113. externW b$SegC
  114. externB b$MaxAttr
  115. externB b$EgaPalSup
  116. externW B$VTOFST
  117. externW B$VBOFST
  118. externW B$VLOFST
  119. externW B$VROFST
  120. externW B$LEOFST
  121. externW B$REOFST
  122. externB b$NullColor
  123. externB b$BitsPerPixel
  124. externW b$BytesPerRow
  125. externW b$UpSub 
  126. externW b$DnSub 
  127. externW b$UpDnAdd
  128. externW b$ScreenTab
  129. sEnd _BSS
  130. assumes CS,GR_TEXT
  131. sBegin GR_TEXT
  132. externNP B$SCNIO  ;used in SCNIO macro
  133. externNP B$InitModeData
  134. externNP B$GetParm
  135. externNP B$EgaPalReset
  136. externNP B$EgaPalPut
  137. externNP B$EgaPalTrans
  138. externNP B$EgaPalSet
  139. externNP B$ErrorReturn
  140. externNP B$CgaSetAttr
  141. externNP B$CgaLeftC1
  142. externNP B$CgaLeftC2
  143. externNP B$CgaChkUpC
  144. externNP B$CgaUpC
  145. externNP B$CgaChkDownC
  146. externNP B$CgaDownC
  147. externNP B$CgaPaintBound
  148. externNP B$CgaReadC
  149. externNP B$CgaSetC
  150. externNP B$CgaSetPixC
  151. externNP B$CgaSetPixFirstC
  152. externNP B$CgaSetPixLastC
  153. externNP B$CgaPutAction
  154. externNP B$CgaNReadL
  155. externNP B$CgaNWriteL
  156. externNP B$CgaNSetC
  157. externNP B$CgaSetTile
  158. externNP B$CgaScanL
  159. externNP B$CgaScanR
  160. externNP B$CgaLineX
  161. externNP B$CgaLineY
  162. externNP B$CgaLineV
  163. ;===========================================================================
  164. mModeData Mode1Data
  165. ;
  166. ; SCREEN 1, BIOS modes 4 & 5
  167. ;
  168. ; Mode-dependent data follows to initialize the the "b$ModeData" table
  169. ; in LLCGRP.
  170. ;
  171. ;===========================================================================
  172. mScreenMode 1
  173. mBiosMode 4 ;BIOS mode and burst may be adjusted later
  174. mBurst 0
  175. mScrWidth 40
  176. mScrHeight 25
  177. mHorzRes 320
  178. mVertRes 200
  179. mVideoBase 0B800H
  180. mMaxAttr 3
  181. mMaxColor 15
  182. mPageSize 16     ;page size in K
  183. mCurrPSize <(16*1024) shr 4>   ;page size in paragraphs (1 plane)
  184. mMaxPage 0
  185. mNullColor 0
  186. mForeColor 3
  187. mBackColor 0
  188. mEgaWrMd 0
  189. mInitPalette Mode1Palette
  190. mInitVgaPal Mode1VgaPal
  191. mAlphaDim AlphaDim1
  192. mSetMode SetMode
  193. mSetPages B$CgaSetPages
  194. mPalReset B$EgaPalReset
  195. mPalPut  PalPut1
  196. mPalTrans B$EgaPalTrans
  197. mPalSet  B$EgaPalSet
  198. mSetColor SetColor1
  199. mForeMapped 3
  200. mBitsPerPixel 2
  201. mPlanes  1
  202. mMapXYC  MapXYC1
  203. mLeftC B$CgaLeftC2
  204. mChkUpC  B$CgaChkUpC
  205. mUpC B$CgaUpC
  206. mChkDownC B$CgaChkDownC
  207. mDownC B$CgaDownC
  208. mSetAttr SetAttr1
  209. mReadC B$CgaReadC
  210. mSetC B$CgaSetC
  211. mSetPixC B$CgaSetPixC
  212. mSetPixFirstC B$CgaSetPixFirstC
  213. mSetPixLastC B$CgaSetPixLastC
  214. mLineX B$CgaLineX
  215. mLineY B$CgaLineY
  216. mLineV B$CgaLineV
  217. mPutAction B$CgaPutAction
  218. mNReadL  B$CgaNReadL
  219. mNWriteL B$CgaNWriteL
  220. mNSetC B$CgaNSetC
  221. mPaintBound B$CgaPaintBound 
  222. mSetTile B$CgaSetTile
  223. mScanL B$CgaScanL
  224. mScanR B$CgaScanR
  225. mEnd GraphDataLen
  226. ;===========================================================================
  227. ;===========================================================================
  228. mModeData Mode2Data
  229. ;
  230. ; SCREEN 2, BIOS mode 6
  231. ;
  232. ; Mode-dependent data follows to initialize the the "b$ModeData" table
  233. ; in LLCGRP.
  234. ;
  235. ;===========================================================================
  236. mScreenMode 2
  237. mBiosMode 6
  238. mBurst 0
  239. mScrWidth 80
  240. mScrHeight 25
  241. mHorzRes 640
  242. mVertRes 200
  243. mVideoBase 0B800H
  244. mMaxAttr 1
  245. mMaxColor 15
  246. mPageSize 16     ;page size in K
  247. mCurrPSize <(16*1024) shr 4>   ;page size in paragraphs (1 plane)
  248. mMaxPage 0
  249. mNullColor 0
  250. mForeColor 1
  251. mBackColor 0
  252. mEgaWrMd 0
  253. mInitPalette b$Mode2Palette
  254. mInitVgaPal b$Mode2VgaPal
  255. mAlphaDim AlphaDim2
  256. mSetMode SetMode
  257. mSetPages B$CgaSetPages
  258. mPalReset B$EgaPalReset
  259. mPalPut  B$EgaPalPut
  260. mPalTrans B$EgaPalTrans
  261. mPalSet  B$EgaPalSet
  262. mSetColor B$ErrorReturn
  263. mForeMapped 1
  264. mBitsPerPixel 1
  265. mPlanes  1
  266. mMapXYC  MapXYC2
  267. mLeftC B$CgaLeftC1
  268. mChkUpC  B$CgaChkUpC
  269. mUpC B$CgaUpC
  270. mChkDownC B$CgaChkDownC
  271. mDownC B$CgaDownC
  272. mSetAttr B$CgaSetAttr
  273. mReadC B$CgaReadC
  274. mSetC B$CgaSetC
  275. mSetPixC B$CgaSetPixC
  276. mSetPixFirstC B$CgaSetPixFirstC
  277. mSetPixLastC B$CgaSetPixLastC
  278. mLineX B$CgaLineX
  279. mLineY B$CgaLineY
  280. mLineV B$CgaLineV
  281. mPutAction B$CgaPutAction
  282. mNReadL  B$CgaNReadL
  283. mNWriteL B$CgaNWriteL
  284. mNSetC B$CgaNSetC
  285. mPaintBound B$CgaPaintBound 
  286. mSetTile B$CgaSetTile
  287. mScanL B$CgaScanL
  288. mScanR B$CgaScanR
  289. mEnd GraphDataLen
  290. ;===========================================================================
  291. ;
  292. ; Mode1Palette - used to initialize the EGA palette for SCREEN 1
  293. ;  (BIOS mode 4 or 5).
  294. ;
  295. labelB Mode1Palette
  296. ; RGBrgb
  297. DB 000000B  ;black
  298. DB 111011B  ;bright cyan
  299. DB 111101B  ;bright magenta
  300. DB 111111B  ;bright white
  301. ;DB     12 DUP (0)
  302. ;
  303. ; Mode2Palette - used to initialize the EGA palette for SCREEN 2
  304. ;  (BIOS mode 6).
  305. ;
  306. PUBLIC b$Mode2Palette
  307. labelB b$Mode2Palette
  308. ; RGBrgb
  309. DB 000000B  ;black
  310. DB 111111B  ;bright white
  311. ;DB     14 DUP (0)
  312. labelNP <PUBLIC, B$CGAUSED>
  313. ;*** 
  314. ; B$Screen1
  315. ;
  316. ;Purpose:
  317. ; Establish all relevent mode dependent data values and function
  318. ; vectors for BASIC screen mode 1.
  319. ;Entry:
  320. ; AL = screen mode (1)
  321. ; AH = burst (0 or 1)
  322. ; CL = alpha columns
  323. ;Exit:
  324. ; PSW.C = set indicates error
  325. ;Uses:
  326. ; per conv.
  327. ;Exceptions:
  328. ;******************************************************************************
  329. cProc B$Screen1,<PUBLIC,NEAR>
  330. cBegin
  331. test b$Adapter,VGA + MCGA + EGA + CGA ;check for adapter support
  332. je ScrErr ;exit w/error if not supported
  333. test b$Monitor,AnalogColor + EnhColor + StdColor
  334. ;check for monitor support
  335. je ScrErr ;exit w/error if not supported
  336. mov al,ah ;new BIOS mode = 4 if no burst
  337. add al,4 ;  5 if burst
  338. mov bx,GR_TEXTOFFSET Mode1Data  ;mode-specific data
  339. mov cx,GraphDataLen 
  340. push ax
  341. call B$InitModeData ;initialize table data
  342. pop ax
  343. mov b$ModeBurst,ax ;save new mode and burst
  344. jmp short ScrCommon ;common exit
  345. ScrErr:
  346. stc
  347. ScrExit:
  348. JustReturn:
  349. cEnd
  350. ;*** 
  351. ; B$Screen2
  352. ;
  353. ;Purpose:
  354. ; Establish all relevent mode dependent data values and function
  355. ; vectors for BASIC screen mode 2.
  356. ;Entry:
  357. ; AL = screen mode (2)
  358. ; AH = burst (0 or 1)
  359. ; CL = alpha columns
  360. ;Exit:
  361. ; PSW.C = set indicates error
  362. ;Uses:
  363. ; per conv.
  364. ;Exceptions:
  365. ; can exit through B$Screen1's error exit.
  366. ;******************************************************************************
  367. cProc B$Screen2,<PUBLIC,NEAR>
  368. cBegin
  369. test b$Adapter,VGA + MCGA + EGA + CGA ;check for adapter support
  370. je ScrErr ;exit w/error if not supported
  371. test b$Monitor,AnalogColor + EnhColor + StdColor
  372. ;check for monitor support
  373. je ScrErr ;exit w/error if not supported
  374. mov bx,GR_TEXTOFFSET Mode2Data  ;mode-specific data
  375. mov cx,GraphDataLen 
  376. call B$InitModeData ;initialize table data
  377. ScrCommon:
  378. mov b$UpSub,8192
  379. mov b$DnSub,8192-80 
  380. mov b$UpDnAdd,8192-80+8192
  381. clc ;indicate no error
  382. cEnd
  383. ;***
  384. ; AlphaDim1
  385. ;
  386. ;Purpose:
  387. ; Validate the proposed text dimensions for Screen 1.
  388. ;   If 40x25 is requested, this mode satisfies the request
  389. ;   elseif 80x25 is requested, suggest screen mode 2
  390. ;   else suggest screen mode 0.
  391. ;Entry:
  392. ; BH = number of lines
  393. ; BL = number of columns
  394. ;Exit:
  395. ; AL = -1 if this mode satisfies the request, otherwise
  396. ; AL is suggested screen mode to invoke for desired dimensions
  397. ;Uses:
  398. ; per conv.
  399. ;Exceptions:
  400. ;******************************************************************************
  401. DbPub AlphaDim1
  402. cProc AlphaDim1,<NEAR>
  403. cBegin
  404. mov al,-1 ;flag request satisfied (maybe)
  405. cmp bx,40+25*256 ;40x25?
  406. je ADim1Exit ;exit if so, standard stuff
  407. xor al,al ;flag request for screen 0
  408. cmp bx,80+25*256 ;80x25?
  409. jne ADim1Exit ;if not, let text mode try
  410. mov al,2 ;otherwise use screen 2
  411. ADim1Exit:
  412. clc ;no error
  413. cEnd
  414. ;***
  415. ; AlphaDim2
  416. ;
  417. ;Purpose:
  418. ; Validate the proposed text dimensions for Screen 2.
  419. ;   If 80x25 is requested, this mode satisfies the request
  420. ;   elseif 40x25 is requested, suggest screen mode 1
  421. ;   else suggest screen mode 0.
  422. ;Entry:
  423. ; BH = number of lines
  424. ; BL = number of columns
  425. ;Exit:
  426. ; AL = -1 if this mode satisfies the request, otherwise
  427. ; AL is suggested screen mode to invoke for desired dimensions
  428. ;Uses:
  429. ; per conv.
  430. ;Exceptions:
  431. ;******************************************************************************
  432. DbPub AlphaDim2
  433. cProc AlphaDim2,<NEAR>
  434. cBegin
  435. mov al,-1 ;flag request satisfied (maybe)
  436. cmp bx,80+25*256 ;80x25?
  437. je ADim1Exit ;exit if so, standard stuff
  438. xor al,al ;flag request for screen 0
  439. cmp bx,40+25*256 ;40x25?
  440. jne ADim2Exit ;if not, let text mode try
  441. inc al ;otherwise use screen 1
  442. ADim2Exit:
  443. clc ;no error
  444. cEnd
  445. ;***
  446. ; SetMode
  447. ;
  448. ;Purpose:
  449. ; Set the screen mode according to the characteristics established
  450. ; by previous call to B$Screenx and b$AlphaDim.
  451. ;Entry:
  452. ;
  453. ;Exit:
  454. ;
  455. ;Uses:
  456. ; per conv.
  457. ;Exceptions:
  458. ;******************************************************************************
  459. DbPub SetMode
  460. cProc SetMode,<NEAR>
  461. cBegin
  462. mov al,b$BiosMode ;set BIOS mode
  463. SCNIOS vSetMode
  464. cmp b$ScreenMode,1 ;remainder for SCREEN 1 only
  465. jne SetModeExit ;exit if not
  466. test b$Adapter,EGA+VGA  ;EGA or VGA?
  467. jz SetModeExit ;go if not
  468. ;
  469. ; The following is provided only to overcome a bug in the EGA BIOS
  470. ; routines which support the graphics "compatibility mode" (BIOS 4)
  471. ; so that the two calls related to PALETTE (INT10 AH = 0BH and
  472. ; INT10H AH = 10H) work correctly.  If we use the first call once
  473. ; when user invokes SCREEN 1 to set the background color, then the
  474. ; BIOS will subsequently reference the correct (low-intensity)
  475. ; color values for the 4 palette attributes whenever the call using
  476. ; INT10H, AH = 0BH is used to toggle the palette, and whenever the
  477. ; call INT10H, AH = 10H is used to set an individual palette regis-
  478. ; ter.  In the absence of this initialization, the high-intensity
  479. ; color values for both palettes are referenced.
  480. ;
  481. xor bx,bx ;set background to 0
  482. SCNIOS vSetPalette ;INT10H, AH=0BH "set color palette"
  483. SetModeExit:
  484. cEnd
  485. ;***
  486. ; B$CgaSetPages
  487. ;
  488. ;Purpose:
  489. ; Set the current active and visual pages and calculate page size
  490. ; and video segment offset.
  491. ;Entry:
  492. ; AL = active page (will always be 0 for these modes)
  493. ; AH = visual page (will always be 0 for these modes)
  494. ;Exit:
  495. ; b$CurPages set to new active and visual pages
  496. ; b$SegC set to video segment
  497. ;Uses:
  498. ; per conv.
  499. ;Exceptions:
  500. ;******************************************************************************
  501. PUBLIC B$CgaSetPages
  502. cProc B$CgaSetPages,<NEAR>
  503. cBegin
  504. DbAssertRel AX,E,0,GR_TEXT,<Non-zero page requested in B$CgaSetPages (LLCGA)>
  505. mov [b$CurPages],ax ; save page numbers
  506. mov ax,[b$VideoBase] ;set video segment
  507. mov [b$SegC],ax
  508. cEnd
  509. ;***
  510. ; PalPut1
  511. ;
  512. ;Purpose:
  513. ; Change palette entry for Screen 1 with translation/verification.
  514. ; A color value of -1 indicates that the associated palette
  515. ; entry is not to be modified.
  516. ;Entry:
  517. ; [DX:AX] = color
  518. ; BL = attribute
  519. ;Exit:
  520. ; PSW.C reset indicates successful operation
  521. ; set indicates PALETTE function call error
  522. ;Uses:
  523. ; per conv.
  524. ;Exceptions:
  525. ;******************************************************************************
  526. DbPub PalPut1
  527. cProc PalPut1,<NEAR>
  528. cBegin
  529. cmp ax,-1 ;lo word of color == -1?
  530. jne PutPalA  ;go if not, can't ignore
  531. cmp dx,ax ;hi word too?
  532. je PutPalX  ;exit if color == -1
  533. PutPalA:
  534. push ax
  535. push dx
  536. push bx
  537. call B$EgaPalPut ;put palette value
  538. pop bx
  539. pop dx
  540. pop ax
  541. jc PutPalX  ;go if error
  542. or bl,bl ;is for background?
  543. jnz PutPalX  ;exit if not
  544. call B$EgaPalTrans ;translate color value again!!
  545. cmp b$EgaPalSup,0 ;have we an EGA palette?
  546. je PutPalX  ;exit if not
  547. mov bh,al ;overscan color
  548. mov al,1 ;subfunction "Set Overscan (Border) Register"
  549. SCNIO vSetEgaPalette ;set the border color identically
  550. PutPalX:
  551. cEnd
  552. ;***
  553. ; MapXYC1
  554. ;
  555. ;Purpose:
  556. ; May given X and Y coordinates to the graphics cursor for Screen 1.
  557. ;Entry:
  558. ; CX = X coordinate
  559. ; DX = Y coordinate
  560. ;Exit:
  561. ; b$OffC, b$MaskC updated
  562. ;Uses:
  563. ; per conv.
  564. ;Exceptions:
  565. ;******************************************************************************
  566. DbPub MapXYC1
  567. cProc MapXYC1,<NEAR>
  568. cBegin
  569. xor ax,ax
  570. shr dx,1 ;dx=row within odd or even half, carry=1 if odd
  571. rcr ax,1 ;ax=8K if dx was odd, 0 if was even
  572. shr ax,1 ;  computing offset to proper buffer half
  573. shr ax,1
  574. mov bx,dx ;multiply y by 80 to compute row displacement
  575. shl dx,1 ;dx=2*Y
  576. shl dx,1 ;dx=4*Y
  577. add dx,bx ;dx=5*Y
  578. shl dx,1 ;dx=10*Y
  579. shl dx,1 ;dx=20*Y
  580. shl dx,1 ;dx=40*Y
  581. shl dx,1 ;dx=80*Y
  582. add dx,ax ;odd rasters are displaced 8k
  583. mov ax,cx ;save x
  584. shr ax,1 ;div by PixelsPerByte (4)
  585. shr ax,1 ;  to get byte index
  586. add dx,ax ;add x byte offset to y row address
  587. mov b$OffC,dx ;save byte offset
  588. and cl,3 ;mask in x bit addr
  589. shl cl,1 ;  *2 for pixel addr in byte
  590. mov ch,11000000B ;leftmost pixel on in shift mask
  591. shr ch,cl ;move over to get mask
  592. mov b$MaskC,ch ;store cursor mask
  593. cEnd
  594. ;***
  595. ; MapXYC2
  596. ;
  597. ;Purpose:
  598. ; May given X and Y coordinates to the graphics cursor for Screen 2.
  599. ;Entry:
  600. ; CX = X coordinate
  601. ; DX = Y coordinate
  602. ;Exit:
  603. ; b$OffC, b$MaskC updated
  604. ;Uses:
  605. ; per conv.
  606. ;Exceptions:
  607. ;******************************************************************************
  608. DbPub MapXYC2
  609. cProc MapXYC2,<NEAR>
  610. cBegin
  611. xor ax,ax
  612. shr dx,1 ;dx=row within odd or even half, carry=1 if odd
  613. rcr ax,1 ;ax=8K if dx was odd, 0 if was even
  614. shr ax,1 ;  computing offset to proper buffer half
  615. shr ax,1
  616. mov bx,dx ;multiply y by 80 to compute row displacement
  617. shl dx,1 ;dx=2*Y
  618. shl dx,1 ;dx=4*Y
  619. add dx,bx ;dx=5*Y
  620. shl dx,1 ;dx=10*Y
  621. shl dx,1 ;dx=20*Y
  622. labelNP <PUBLIC,B$MapXYC2_4> ; common to MAPXYC4 routine (lloga.asm)
  623. shl dx,1 ;dx=40*Y
  624. shl dx,1 ;dx=80*Y
  625. add dx,ax ;odd rasters are displaced 8k
  626. mov ax,cx ;save x
  627. shr ax,1 ;div by PixelsPerByte (8)
  628. shr ax,1 ;  to get byte index
  629. shr ax,1
  630. add dx,ax ;add x byte offset to y row address
  631. mov b$OffC,dx ;save byte offset
  632. and cl,7 ;mask in x bit addr
  633. mov ch,10000000B ;leftmost pixel on in shift mask
  634. shr ch,cl ;move over to get mask
  635. mov b$MaskC,ch ;store cursor mask
  636. cEnd
  637. ;***
  638. ; SetAttr1
  639. ;
  640. ;Purpose:
  641. ; Replicate supplied attribute throughout the attribute byte for
  642. ; use by Screen 1 functions.  If supplied attribute is beyond
  643. ; legal range the maximum legal attribute is used.
  644. ;Entry:
  645. ; AL = attribute
  646. ;Exit:
  647. ; b$Attr updated
  648. ;Uses:
  649. ; per conv.
  650. ;Exceptions:
  651. ;******************************************************************************
  652. DbPub SetAttr1
  653. cProc SetAttr1,<NEAR>,<AX>
  654. cBegin
  655. cmp al,b$MaxAttr ;test against maximum attribute
  656. jbe SetAttr1Ok ;Brif legal
  657. mov al,b$MaxAttr ;limit to max
  658. SetAttr1Ok:
  659. MOV CL,2 ;2 bits per pixel
  660. MOV AH,AL ;attr mask in ??????xx
  661. SHL AH,CL
  662. OR AL,AH ;attr mask in ????xxxx
  663. SHL AH,CL
  664. OR AL,AH ;attr mask in ??xxxxxx
  665. SHL AH,CL
  666. OR AL,AH ;attr mask in xxxxxxxx
  667. MOV b$AttrC,al ;exit no error
  668. cEnd
  669. ;***
  670. ; SetColor1
  671. ;
  672. ;Purpose:
  673. ; Process the color statement for Screen 1.  Syntax for Screen 1
  674. ; color statement is as follows:
  675. ;
  676. ; COLOR [background],[fg palette],[fg override]
  677. ;
  678. ; where "background"  is a color number 0-255 which gets mapped to 0-15,
  679. ;       "fg palette"  is a number which selects CGA palette 0 if even,
  680. ;    or CGA palette 1 if odd,
  681. ;   and "fg override" (if present) replaces and functions identically
  682. ;     to "fg palette".
  683. ;
  684. ; Any omitted parameter(s) indicate no change for that parameter.
  685. ;Entry:
  686. ; parameter list
  687. ; WORD 1 = flag 0 if param not present
  688. ; WORD 2 = parameter if WORD 1 <> 0, else second param flag
  689. ; etc.
  690. ;Exit:
  691. ; PSW.C set if too many parameters, reset if Ok
  692. ; b$NullColor set to background attribute value (always 0 for screen 1)
  693. ;Uses:
  694. ; per conv.
  695. ;Exceptions:
  696. ;******************************************************************************
  697. DbPub SetColor1
  698. cProc SetColor1,<NEAR>
  699. cBegin
  700. cCall B$GetParm ;AL=background parameter
  701. push ax ;save background and flag
  702. cCall B$GetParm ;AL=1st palette parameter
  703. xchg ax,bx ;save 1st palette and flag
  704. cCall B$GetParm ;AL=2nd palette parameter
  705. jnz SetCol1  ;jump if param found
  706. ;  which overrides the 1st one
  707. xchg ax,bx ;restore 1st palette param
  708. or ah,ah ;is it defaulted too?
  709. jnz SetCol2  ;go if so
  710. SetCol1:
  711. ; If palette parameter, then user gets bogus palette reset to
  712. ; 0 or 1.
  713. push ax ;save palette select value
  714. test b$Adapter,EGA + VGA ;EGA or VGA?
  715. jnz IsEga ;go if so
  716. xor bx,bx ;set background subfunction (0)
  717. mov bl,BackColor ;get chosen background color
  718. SCNIOS vSetPalette ;set background
  719. IsEga:
  720. pop bx ;restore palette select value
  721. mov bh,1 ;subfunction - set bogus palette
  722. and bl,bh ;force palette number to 0 or 1
  723. SCNIOS vSetPalette
  724. SetCol2:
  725. pop bx ;the background parameter is on the stack
  726. or bh,bh ;was there background parameter?
  727. jnz SetColExit ;no, only palette
  728. and bl,0FH ;Allow 0-255, mask to 0-15.
  729. test bl,8 ;If Bgnd to be intensified
  730. jz SetCol3  ;Brif not
  731. or bl,10H ;Set Intensity Bit
  732. SetCol3:
  733. mov BackColor,bl ;save it
  734. test b$Adapter,EGA + VGA ; EGA card present? [10] or VGA?
  735. jz NoEga ; No, use CGA BIOS call to set background
  736. mov al,bl ;AL=color
  737. and al,0FH ;strip intensity (PalPut will translate)
  738. cbw ;AX=color
  739. cwd ;DX:AX=color
  740. mov bl,bh ;BL=attribute(0)
  741. call [b$PalPut] ;make the EGA do what WE want
  742. jmp short SetColExit 
  743. NoEga:
  744. SCNIOS vSetPalette ;set background color
  745. SetColExit:
  746. mov b$NullColor,0 ;use background for null color
  747. clc ;indicate no error
  748. jcxz SetColDun ;if we got all params, thats true
  749. stc ;otherwise set error
  750. SetColDun:
  751. cEnd
  752. ;***
  753. ; B$xINITCGA - initialize CGA modes
  754. ;
  755. ;Purpose:
  756. ; Added with revision [14].
  757. ; Put the addresses of CGA screen mode support routines into the
  758. ; dispatch table used by the screen statement.
  759. ;
  760. ;Entry:
  761. ; None
  762. ;Exit:
  763. ; ScreenTab updated
  764. ;Uses:
  765. ; None
  766. ;Exceptions:
  767. ;******************************************************************************
  768. cProc B$xINITCGA,<FAR,PUBLIC> 
  769. cBegin
  770. MOV WORD PTR [b$ScreenTab + (1*2) + 1],OFFSET B$Screen1
  771. MOV WORD PTR [b$ScreenTab + (2*2) + 1],OFFSET B$Screen2
  772. cEnd
  773. sEnd GR_TEXT
  774. END