Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2229 lines
89 KiB

  1. ;/*
  2. ; * Microsoft Confidential
  3. ; * Copyright (C) Microsoft Corporation 1988 - 1991
  4. ; * All Rights Reserved.
  5. ; */
  6. ;************************************************************
  7. ;**
  8. ;**
  9. ;** NAME: Support for HP PCL printers added to GRAPHICS.
  10. ;**
  11. ;** DESCRIPTION: I fixed a MS bug. MS did not initialize the variable
  12. ;** ROTATE_SW. Consequently, if you do a non-rotate after doing
  13. ;** a rotate, the picture would be printed incorrectly as a
  14. ;** rotated picture. Note this bug was in Q.01.01 and fixed for
  15. ;** Q.01.02.
  16. ;**
  17. ;** NOTES: The following bug was fixed for the pre-release version
  18. ;** Q.01.02.
  19. ;**
  20. ;** BUG (mda004)
  21. ;** ------------
  22. ;**
  23. ;** NAME: After GRAPHICS prints a rotated picture it will print pictures
  24. ;** which are not supposed to be rotated as rotated junk.
  25. ;**
  26. ;** FILES AFFECTED: GRCTRL.ASM
  27. ;**
  28. ;** CAUSE: MicroSoft was failing to initialize the variable ROTATE_SW to
  29. ;** OFF. Consequently, if you printed a picture whose corresponding
  30. ;** printbox did NOT specify a rotate after printing a picture whose
  31. ;** corresponding printbox did specify a rotate, the picture would
  32. ;** print as rotated junk.
  33. ;**
  34. ;** FIX: Initialize the variable ROTATE_SW to OFF right before going into
  35. ;** the print procedure Print_Color or Print_BW_APA.
  36. ;**
  37. ;** DOCUMENTATION NOTES: This version of GRCTRL.ASM differs from the previous
  38. ;** version only in terms of documentation.
  39. ;**
  40. ;**
  41. ;************************************************************
  42. PAGE ,132
  43. TITLE DOS GRAPHICS Command - Print screen Control module
  44. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  45. ;; DOS - GRAPHICS Command
  46. ;;
  47. ;;
  48. ;; File Name: GRCTRL.ASM
  49. ;; ----------
  50. ;;
  51. ;; Description:
  52. ;; ------------
  53. ;; This file contains the code for the Print Screen control module.
  54. ;;
  55. ;; Documentation Reference:
  56. ;; ------------------------
  57. ;; OASIS High Level Design
  58. ;; OASIS GRAPHICS I1 Overview
  59. ;;
  60. ;; Procedures Contained in This File:
  61. ;; ----------------------------------
  62. ;; PRT_SCR
  63. ;; DET_HW_CONFIG
  64. ;; DET_MODE_STATE
  65. ;; GET_MODE_ATTR
  66. ;; SET_UP_XLT_TAB
  67. ;; SET_CGA_XLT_TAB
  68. ;; CGA_COL2RGB
  69. ;; RGB2XLT_TAB
  70. ;; SET_EGA_XLT_TAB
  71. ;; EGA_COL2RGB
  72. ;; SET_MODE_F_XLT_TAB
  73. ;; SET_MODE_13H_XLT_TAB
  74. ;; SET_ROUNDUP_XLT_TAB
  75. ;; SET_BACKG_IN_XLT_TAB
  76. ;; RGB2BAND
  77. ;; RGB2INT
  78. ;;
  79. ;;
  80. ;; Include Files Required:
  81. ;; -----------------------
  82. ;; GRINST.EXT - Externals for GRINST.ASM
  83. ;;
  84. ;;
  85. ;; External Procedure References:
  86. ;; ------------------------------
  87. ;; FROM FILE GRINST.ASM:
  88. ;; GRAPHICS_INSTALL - Main module for installation.
  89. ;;
  90. ;; Linkage Instructions:
  91. ;; --------------------
  92. ;; Refer to GRAPHICS.ASM
  93. ;;
  94. ;; Change History:
  95. ;; ---------------
  96. ;; M001 NSM 1/30/91 New var to store the old int 10 handler
  97. ;;
  98. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  99. CODE SEGMENT PUBLIC 'CODE'
  100. ASSUME CS:CODE,DS:CODE
  101. .XLIST
  102. INCLUDE GRINT2FH.EXT
  103. INCLUDE GRBWPRT.EXT
  104. INCLUDE GRCOLPRT.EXT
  105. INCLUDE GRSHAR.STR
  106. INCLUDE GRPATTRN.STR
  107. INCLUDE GRPATTRN.EXT
  108. INCLUDE STRUC.INC
  109. .LIST
  110. PRT_SCR PROC NEAR
  111. JMP PRT_SCR_BEGIN
  112. PAGE
  113. ;===============================================================================
  114. ;
  115. ; GRAPHICS INTERRUPT DRIVER'S DATA:
  116. ;
  117. ;===============================================================================
  118. .xlist
  119. PUBLIC PRT_SCR,ERROR_CODE,XLT_TAB,MODE_TYPE
  120. PUBLIC CUR_MODE_PTR,CUR_MODE,NB_COLORS,SCREEN_HEIGHT,SCREEN_WIDTH
  121. PUBLIC CUR_PAGE,CUR_COLUMN,CUR_ROW,NB_SCAN_LINES,SCAN_LINE_MAX_LENGTH
  122. PUBLIC CUR_SCAN_LNE_LENGTH
  123. PUBLIC PRT_BUF,NB_BOXES_PER_PRT_BUF,CUR_BOX,BOX_H,BOX_W
  124. PUBLIC PRINT_SCREEN_ALLOWED,RGB
  125. PUBLIC BIOS_INT_5H
  126. PUBLIC OLD_INT_10H ; /* M001 */
  127. PUBLIC ROTATE_SW
  128. PUBLIC DET_HW_CONFIG
  129. PUBLIC NB_CHAR_COLUMNS
  130. PUBLIC RGB2INT
  131. PUBLIC RGB2BAND
  132. .list
  133. INCLUDE GRCTRL.STR
  134. ;-------------------------------------------------------------------------------
  135. ;
  136. ; ENTRY POINT TO BIOS HARDWARE INTERRUPT 5 HANDLER
  137. ;
  138. ;-------------------------------------------------------------------------------
  139. BIOS_INT_5H DW ? ; Pointer to BIOS int 5h
  140. DW ?
  141. ;/* M001 BEGIN */ --------------------------------------------------------------
  142. ;
  143. ; ENTRY POINT TO BIOS HARDWARE INTERRUPT 10 HANDLER
  144. ;
  145. ;-------------------------------------------------------------------------------
  146. OLD_INT_10H DW ? ; Pointer to BIOS int 10h
  147. DW ?
  148. ; /* M001 END */
  149. ;-------------------------------------------------------------------------------
  150. ;
  151. ; PRINT SCREEN ERROR CODE (Used at print screen time, see GRCTRL.STR for
  152. ; error codes allowed)
  153. ;
  154. ;-------------------------------------------------------------------------------
  155. ERROR_CODE DB 0 ; ERROR CODE 0 = NO ERROR
  156. ;-------------------------------------------------------------------------------
  157. ;
  158. ; SCREEN PIXEL: INTERNAL REPRESENTATION
  159. ;
  160. ;-------------------------------------------------------------------------------
  161. RGB PIXEL_STR < , , > ; PIXEL := RED, GREEN, BLUE Values
  162. ;-------------------------------------------------------------------------------
  163. ;
  164. ; COLOR TRANSLATION TABLE:
  165. ;
  166. ; This table is used to translate the color numbers returned by
  167. ; Interrupt 10H Read Dot and Read Character calls into print
  168. ; information. The table consists of 256 entries, one byte each,
  169. ; indexed by color number.
  170. ; In the case of black and white printing, the table
  171. ; entries are grey scale intensities from 0 to 63. In the case
  172. ; of color printing each table entry contains a "band mask" indicating
  173. ; which color print bands are required to generate the required color.
  174. ; The band masks are simply bit masks where each bit corresponds to one
  175. ; of the printer bands.
  176. ;
  177. ; The table is set up at the beginning of the print screen processing,
  178. ; before any data is read from the screen. From then on, translating
  179. ; from screen information into print information is done quickly by
  180. ; accessing this table. Not all 256 entries are initialized for each
  181. ; screen print. The number of entries used is equal to the number
  182. ; of colors available concurrently with the given display mode.
  183. ;-------------------------------------------------------------------------------
  184. XLT_TAB DB 256 DUP(32) ; COLOR TRANSLATION TABLE
  185. ; This table is used to translate the Color Dot
  186. ; or Byte Attribute to a Band Mask for color
  187. ; printing or to a Grey Intensity for Mono-
  188. ; chrome printing.
  189. ;-------------------------------------------------------------------------------
  190. ;
  191. ; CURRENT VIDEO MODE ATTRIBUTES
  192. ;
  193. ;-------------------------------------------------------------------------------
  194. MODE_TYPE DB ? ; Mode types (bit mask) APA or TXT
  195. CUR_MODE_PTR DW ? ; DISPLAYMODE INFO RECORD for the current
  196. ; mode (defined in the shared data area).
  197. CUR_MODE DB ? ; Current video mode number
  198. NB_COLORS DW ? ; Number of colors supported by this mode
  199. SCREEN_HEIGHT DW ? ; Number of rows on the screen (chars or pixels)
  200. SCREEN_WIDTH DW ? ; Number of columns on the screen (chars/pixels)
  201. ; (for text modes is equal to NB_CHAR_COLUMNS)
  202. NB_CHAR_COLUMNS DB ? ; Number of columns on the screen if in txt mode
  203. CUR_PAGE DB ? ; Active page number
  204. ROTATE_SW DB ? ; Switch: if "ON" then, must print sideways
  205. ;-------------------------------------------------------------------------------
  206. ;
  207. ; ACTIVE SCREEN ATTRIBUTES
  208. ;
  209. ;-------------------------------------------------------------------------------
  210. CUR_COLUMN DW ? ; Current pixel/char column number
  211. CUR_ROW DW ? ; Current pixel/char row number
  212. NB_SCAN_LINES DW ? ; Number of screen scan lines
  213. SCAN_LINE_MAX_LENGTH DW ? ; Maximum number of dots/chars per scan line
  214. CUR_SCAN_LNE_LENGTH DW ? ; Length in pels/chars of the current scan line
  215. ;-------------------------------------------------------------------------------
  216. ;
  217. ; PRINTER VARIABLES
  218. ;
  219. ;-------------------------------------------------------------------------------
  220. PRT_BUF DB ?,?,?,? ; PRINT BUFFER
  221. NB_BOXES_PER_PRT_BUF DB ? ; Number of boxes fitting in the print buffer
  222. CUR_BOX DB ?,?,?,? ; BOX = PRINTER REPRESENTATION OF 1 PIXEL
  223. BOX_H DB ? ; HEIGHT OF THE BOX
  224. BOX_W DB ? ; WIDTH OF THE BOX
  225. ;-------------------------------------------------------------------------------
  226. ;
  227. ; CONTROL VARIABLES:
  228. ;
  229. ; This data is used to communicate between the Installation Modules
  230. ; and the Resident Print Screen Modules.
  231. ;-------------------------------------------------------------------------------
  232. PRINT_SCREEN_ALLOWED DB YES; Used to avoid print screens
  233. ; while the GRAPHICS installation
  234. ; (or re-install) is in progress
  235. ; Set by GRAPHICS_INSTALL module.
  236. PAGE
  237. ;===============================================================================
  238. ;
  239. ; INTERRUPT 5 DRIVER'S CODE:
  240. ;
  241. ;-------------------------------------------------------------------------------
  242. ;===============================================================================
  243. ;
  244. ; PRT_SCR : PRINT THE ACTIVE SCREEN
  245. ;
  246. ;-------------------------------------------------------------------------------
  247. ;
  248. ; INPUT: SHARED_DATA_AREA_PTR = Offset of the data area used for
  249. ; passing data between the
  250. ; Installation process and the Print
  251. ; Screen process.
  252. ; PRINT_SCREEN_ALLOWED = Switch. Set to "No" if currently
  253. ; installing GRAPHICS.COM
  254. ;
  255. ; NOTE: These 2 variables are declared within
  256. ; PRT_SCR but initialized by the
  257. ; Installation process GRAPHICS_INIT
  258. ; OUTPUT: PRINTER
  259. ;
  260. ; CALLED BY: INTERRUPT 5
  261. ;
  262. ;
  263. ;-------------------------------------------------------------------------------
  264. ;
  265. ; DESCRIPTION:
  266. ;
  267. ; PRINT THE ACTIVE SCREEN for all TEXT and All Points Addressable (APA)
  268. ; display modes available with either a MONO, CGA, EGA, or VGA video
  269. ; adapter on a Black and White or Color printer.
  270. ;
  271. ; INITIALIZATION:
  272. ;
  273. ; Each pixel or character on the screen has a color attribute. These
  274. ; colors must be translated into different internal representations:
  275. ;
  276. ; For printing in colors, each color is translated to a BAND MASK.
  277. ; The Band Mask indicates how to obtain this color on the printer.
  278. ;
  279. ; For printing in Black and White, each color is translated to a
  280. ; GREY INTENSITY number between 0 (black) and 63 (white).
  281. ;
  282. ; The BAND MASK or the GREY INTENSITIES are found in the COLOR
  283. ; TRANSLATION TABLE. This table is initialized before calling any of
  284. ; the print screen modules.
  285. ;
  286. ; PRINT SCREEN TIME:
  287. ;
  288. ; When a pixel or character is read off the screen by one of the print
  289. ; screen modules, its color is used as an index into the translation
  290. ; table.
  291. ;
  292. ;
  293. ; LOGIC:
  294. ;
  295. ; IF SCREEN_PRINTS_ALLOWED=NO ; Block print screens until Installation
  296. ; THEN IRET ; Process (or re-install!) is finished.
  297. ; ELSE
  298. ;
  299. ; CALL DET_HW_CONFIG ; Determine hardware configuration
  300. ; CALL DET_MODE_STATE ; Determine video mode and active page
  301. ; CALL GET_MODE_ATTR ; Get video attributes (TXT or APA, etc)
  302. ;
  303. ; IF MODE_TYPE = TXT AND Number of colors = 0
  304. ; THEN Invoke BIOS INTERRUPT 5
  305. ; ELSE
  306. ; IF PRINTER_TYPE = BLACK_WHITE
  307. ; THEN
  308. ; IF MODE_TYPE = TXT
  309. ; THEN Invoke BIOS INTERRUPT 5
  310. ; ELSE ; Mode is APA
  311. ; CALL SET_UP_XLT_TAB ; Set up the color translation table
  312. ; CALL PRINT_BW_APA ; Print the active screen on a B&W printer
  313. ; ELSE ; Color printer attached
  314. ; CALL SET_UP_XLT_TAB ; Set up the color translation table
  315. ; CALL PRINT_COLOR ; Print the active screen on a Color prt.
  316. ; IRET
  317. ;
  318. PRT_SCR_BEGIN:
  319. PUSH AX ; Save Registers
  320. PUSH BX ;
  321. PUSH CX ;
  322. PUSH DX ;
  323. PUSH SI ;
  324. PUSH DI ;
  325. PUSH BP ;
  326. PUSH DS ;
  327. PUSH ES ;
  328. ;
  329. CLD ; Clear direction flag
  330. PUSH CS ; DS := CS
  331. POP DS
  332. ;-------------------------------------------------------------------------------
  333. ; Verify if we are allowed to print (not allowed if currently installing
  334. ; GRAPHICS or printing a screen):
  335. ;-------------------------------------------------------------------------------
  336. CMP PRINT_SCREEN_ALLOWED,NO ; IF not allowed to print
  337. JE PRT_SCR_RETURN ; THEN quit
  338. ; ELSE print the screen:
  339. ;-------------------------------------------------------------------------------
  340. ; INITIALIZATION:
  341. ;-------------------------------------------------------------------------------
  342. PRT_SCR_INIT: ; Disable print screen while
  343. MOV PRINT_SCREEN_ALLOWED,NO ; we are printing the current
  344. ; screen.
  345. MOV BP,SHARED_DATA_AREA_PTR ; BP := Offset Shared Data Area
  346. MOV ERROR_CODE,NO_ERROR ; No error so far.
  347. CALL DET_HW_CONFIG ; Determine the type of display adapter
  348. CALL DET_MODE_STATE ; Init CUR_PAGE, CUR_MODE
  349. CALL GET_MODE_ATTR ; Determine if APA or TXT, nb. of colors,
  350. ; and screen dimensions in pels or characters.
  351. ;
  352. ; Test the error code returned by GET_MODE_ATTR:
  353. ;
  354. TEST ERROR_CODE,MODE_NOT_SUPPORTED ;If mode not supported then,
  355. JNZ DO_BEEP ; let BIOS give it a try.
  356. ;------------------------------------------------------------------------------
  357. ; Check the printer type:
  358. ;------------------------------------------------------------------------------
  359. .IF <DS:[BP].PRINTER_TYPE EQ BLACK_WHITE> ; Is a black and white printer
  360. .THEN ; attached ?
  361. ;------------------------------------------------------------------------------
  362. ; A Black and White printer is attached
  363. ;------------------------------------------------------------------------------
  364. CMP MODE_TYPE,TXT ; Is the screen in text mode ?
  365. JNE INVOKE_PRINT_ROUTINE ; No, call GRAPHICS B&W routine
  366. JMP SHORT EXIT_TO_BIOS ; Yes, give control to BIOS INTERRUPT 5
  367. .ELSE
  368. ;------------------------------------------------------------------------------
  369. ; A Color printer is attached
  370. ;------------------------------------------------------------------------------
  371. CMP NB_COLORS,0 ; Is the screen in a Monochrome
  372. JNE INVOKE_PRINT_ROUTINE
  373. TEST MODE_TYPE,TXT ; text mode ?
  374. JNZ INVOKE_PRINT_ROUTINE
  375. JMP SHORT EXIT_TO_BIOS ; Yes, let BIOS INTERRUPT 5 handle it
  376. ; No, we handle it.
  377. .ENDIF ; ENDIF black and white or color printer
  378. ;-------------------------------------------------------------------------------
  379. ;
  380. ; Call the print routine (which is either PRINT_COLOR or PRINT_BW_APA)
  381. ;
  382. ;-------------------------------------------------------------------------------
  383. INVOKE_PRINT_ROUTINE:
  384. CALL SET_UP_XLT_TAB ; Set up the color translation table
  385. ; \/ ~~mda(004) ----------------------------------------------------------------
  386. ; The following fixes a MS bug. MS was failing to initialize
  387. ; the variable ROTATE_SW to off. Consequently, if you printed a
  388. ; picture whose corresponding printbox did NOT specify a rotate
  389. ; after printing a picture whose corresponding printbox did
  390. ; specify a rotate, the picture would print rotated.
  391. MOV ROTATE_SW,OFF ; Set printing to standard unless otherwise
  392. ; set to rotate via PRINT_OPTIONS.
  393. ; /\ ~~mda(004) ----------------------------------------------------------------
  394. CALL PRINT_MODULE_START ; Call the print modules that were
  395. ; made resident at Install time.
  396. MOV PRINT_SCREEN_ALLOWED,YES; Enable PrtScr for next calls
  397. ;-----------------------------------------------------------------------------
  398. ; Test the error code returned by either PRINT_COLOR or PRT_BW_APA
  399. ;-----------------------------------------------------------------------------
  400. TEST ERROR_CODE,UNABLE_TO_PRINT ; If unable to print the screen
  401. JNZ SHORT EXIT_TO_BIOS ; then, let BIOS give it a try
  402. PRT_SCR_RETURN:
  403. ; Restore registers
  404. POP ES ;
  405. POP DS ;
  406. POP BP ;
  407. POP DI ;
  408. POP SI ;
  409. POP DX ;
  410. POP CX ;
  411. POP BX ;
  412. POP AX ;
  413. ;
  414. IRET ; Return control to interrupted
  415. ; process
  416. ; give a beep for modes not supported by graphics
  417. DO_BEEP:
  418. mov ah,2 ; console output
  419. mov dx,7 ; ^G - beep for modes not supported
  420. int 21h
  421. EXIT_TO_BIOS:
  422. ; Restore registers
  423. POP ES ;
  424. POP DS ;
  425. POP BP ;
  426. POP DI ;
  427. POP SI ;
  428. POP DX ;
  429. POP CX ;
  430. POP BX ;
  431. POP AX ;
  432. CLI ; Disable interrupts
  433. MOV CS:PRINT_SCREEN_ALLOWED,YES ; Enable PrtScr for next calls
  434. JMP DWORD PTR CS:BIOS_INT_5H ; Exit to BIOS INTERRUPT 5
  435. PRT_SCR ENDP
  436. ;===============================================================================
  437. ;
  438. ; PRT_SCR MODULES:
  439. ;
  440. ;-------------------------------------------------------------------------------
  441. PAGE
  442. ;===============================================================================
  443. ;
  444. ; DET_HW_CONFIG : DETERMINE WHAT TYPE OF VIDEO HARDWARE IS PRESENT
  445. ;
  446. ;-------------------------------------------------------------------------------
  447. ;
  448. ; INPUT: BP = Offset of the shared data area
  449. ;
  450. ; OUTPUT: HARDWARE_CONFIG is updated in the shared data area
  451. ;
  452. ; CALLED BY: PRT_SCR
  453. ;
  454. ; EXTERNAL CALLS: BIOS INT 10H
  455. ;
  456. ;-------------------------------------------------------------------------------
  457. ;
  458. ; LOGIC:
  459. ; Issue BIOS INT10H Get Display Configuration Code (AX=1A00H)
  460. ; IF AL = 1AH THEN /* VGA (PS/2 OR BRECON-B) */
  461. ; /* BL = active DCC */
  462. ; /* BH = alternate DCC */
  463. ; /* Display Code: */
  464. ; /* 1 - Mono Adapter */
  465. ; /* 2 - CGA */
  466. ; /* 4 - EGA with Mono Display */
  467. ; /* 5 - EGA with Color Display */
  468. ; /* 7 - PS/2 Mod 50,60,80 OR BRECON-B with Mono Display */
  469. ; /* 8 - PS/2 Mod 50,60,80 OR BRECON-B with Color Display */
  470. ; /* B - PS/2 Mod 30 with Mono Display */
  471. ; /* C - PS/2 Mod 30 with Color Display */
  472. ; IF AL = 1AH THEN /* Call is supported */
  473. ; Set HARDWARE_CONFIG byte based on DCC returned in DL
  474. ; ELSE
  475. ; Issue INT 10H EGA Info (AH=12H BL=10H)
  476. ; IF BL <> 10H THEN /* EGA */
  477. ; Set EGA bit in HARDWARE_CONFIG
  478. ; ELSE /* CGA or */
  479. ; Issue INT 10H PC CONVERTIBLE Physical display description param.
  480. ; request. (AH=15H)
  481. ; IF ES:[DI] = 5140H
  482. ; THEN
  483. ; Set PC_CONVERTIBLE bit in HARDWARE_CONFIG
  484. ; ELSE
  485. ; Set OLD_ADAPTER bit in HARDWARE_CONFIG
  486. ; ENDIF
  487. ; ENDIF
  488. ; ENDIF
  489. ; RETURN
  490. ;
  491. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  492. DET_HW_CONFIG PROC NEAR
  493. ;-------------------------------------------------------------------------------
  494. ;
  495. ; Try to read display combination code (PS/2 call):
  496. ;
  497. ;-------------------------------------------------------------------------------
  498. MOV AX,READ_CONFIG_CALL
  499. INT 10H ; Call video BIOS
  500. .IF <AL EQ 1AH> ; If call is supported
  501. .THEN
  502. ;-------------------------------------------------------------------------------
  503. ;
  504. ; Call is supported, PS/2 BIOS is present (Model 39,50,60,80 or BRECON-B card),
  505. ; Determine what is the primary video adapter:
  506. ;
  507. ;-------------------------------------------------------------------------------
  508. .SELECT
  509. .WHEN <BL EQ 1> OR ; MONO or
  510. .WHEN <BL EQ 2> ; CGA
  511. MOV DS:[BP].HARDWARE_CONFIG,OLD_ADAPTER
  512. .WHEN <BL EQ 4> OR ; EGA with Mono or
  513. .WHEN <BL EQ 5> ; EGA with Color
  514. MOV DS:[BP].HARDWARE_CONFIG,EGA
  515. .WHEN <BL EQ 7> OR ; BRECON-B with Mono or
  516. .WHEN <BL EQ 8> ; BRECON-B with Color
  517. MOV DS:[BP].HARDWARE_CONFIG,ROUNDUP
  518. .WHEN <BL EQ 0Bh> OR ; PS/2 Model 30 with Mono or
  519. .WHEN <BL EQ 0Ch> ; PS/2 Model 30 with Color
  520. MOV DS:[BP].HARDWARE_CONFIG,PALACE
  521. .ENDSELECT
  522. ;-------------------------------------------------------------------------------
  523. ;
  524. ; PS/2 call is not supported, try the EGA info call:
  525. ;
  526. ;-------------------------------------------------------------------------------
  527. .ELSE
  528. MOV AH,ALT_SELECT_CALL ; Request Alternate select's
  529. MOV BL,EGA_INFO_CALL ; "return EGA information call"
  530. INT 10H ; Call video BIOS
  531. .IF <BL NE EGA_INFO_CALL> ; If a memory value is returned
  532. .THEN ; then, there is an EGA
  533. MOV DS:[BP].HARDWARE_CONFIG,EGA
  534. .ELSE ; else, call is not supported:
  535. ;-------------------------------------------------------------------------------
  536. ;
  537. ; EGA call is not supported, try the PC CONVERTIBLE display description call:
  538. ;
  539. ;-------------------------------------------------------------------------------
  540. MOV AH,DISP_DESC_CALL
  541. INT 10H ; Call BIOS, ES:DI :=Offset of parms
  542. .IF <ES:[DI] EQ 5140H> ; If LCD display type,
  543. .THEN ; set LCD bit in Shared Data area
  544. MOV DS:[BP].HARDWARE_CONFIG,PC_CONVERTIBLE
  545. .ELSE ; else, we have an old adapter.
  546. MOV DS:[BP].HARDWARE_CONFIG,OLD_ADAPTER ; (either MONO or CGA)
  547. .ENDIF ; Display type is LCD
  548. .ENDIF ; EGA BIOS is present
  549. .ENDIF ; PS/2 BIOS is present
  550. RET
  551. DET_HW_CONFIG ENDP
  552. PAGE
  553. ;=======================================================================
  554. ;
  555. ; DET_MODE_STATE : Determine the current video mode and the active page.
  556. ;
  557. ;-----------------------------------------------------------------------
  558. ;
  559. ; INPUT: HARDWARE_CONFIG = Type of video hardware attached
  560. ;
  561. ; OUTPUT: CUR_MODE = Video mode number (0-13H)
  562. ; CUR_PAGE = Video page number (0-8)
  563. ; NB_CHAR_COLUMNS = Number of columns if in a text mode.
  564. ;
  565. ;
  566. ; CALLED BY: PRT_SCR
  567. ;
  568. ;
  569. ;-------------------------------------------------------------------------------
  570. ;
  571. ; DESCRIPTION: Use the BIOS interface to
  572. ; obtain the current mode and active page.
  573. ;
  574. ; LOGIC:
  575. ;
  576. ; Call BIOS INTERRUPT 10H: "Return current video state" (AH = 0fh)
  577. ;
  578. DET_MODE_STATE PROC NEAR
  579. PUSH AX
  580. PUSH BX
  581. MOV AH,GET_STATE_CALL
  582. INT 10H ; CALL BIOS
  583. MOV CUR_MODE,AL
  584. MOV NB_CHAR_COLUMNS,AH
  585. MOV CUR_PAGE,BH
  586. POP BX
  587. POP AX
  588. RET
  589. DET_MODE_STATE ENDP
  590. PAGE
  591. ;=======================================================================
  592. ;
  593. ; GET_MODE_ATTR: Obtain attributes of current video mode.
  594. ;
  595. ;-----------------------------------------------------------------------
  596. ;
  597. ; INPUT: CUR_MODE = Current video mode (1 BYTE)
  598. ;
  599. ; OUTPUT: MODE_TYPE = Video mode type (TXT or APA)
  600. ; NB_COLORS = Maximum number of colors (0-256) (0=B&W)
  601. ; ERROR_CODE = Error code if error occurred.
  602. ; SCREEN_HEIGHT= Number of rows (in pixels if APA or char if TEXT)
  603. ; SCREEN_WIDTH = Number of columns (in pixels/char)
  604. ;
  605. ; CALLED BY: PRT_SCR
  606. ;
  607. ;
  608. ;-----------------------------------------------------------------------
  609. ;
  610. ; DESCRIPTION: Scan the 2 local video mode attribute tables until the
  611. ; current mode is located. Return the attributes.
  612. ; For APA modes SCREEN_HEIGHT and SCREEN_WIDTH are in pixels,
  613. ; for TEXT modes they are in characters.
  614. ;
  615. ;
  616. ; LOGIC:
  617. ;
  618. ; Scan the APA_ATTR_TABLE
  619. ; IF FOUND
  620. ; MODE_TYPE := APA
  621. ; NB_COLORS := mode.MAX_COLORS
  622. ; SCREEN_HEIGHT := mode.NB_L
  623. ; SCREEN_WIDTH := mode.NB_C
  624. ; ELSE
  625. ; Scan the TXT_ATTR_TABLE
  626. ; When FOUND
  627. ; MODE_TYPE := TXT
  628. ; NB_COLORS := mode.NUM_COLORS
  629. ; SCREEN_WIDTH := NB_CHAR_COLUMNS
  630. ; SCREEN_HEIGHT := Byte in ROM BIOS at 40:84
  631. ;
  632. ;-----------------------------------------------------------------------
  633. GET_MODE_ATTR PROC NEAR
  634. JMP SHORT GET_MODE_ATTR_BEGIN
  635. ;-----------------------------------------------------------------------
  636. ;
  637. ; LOCAL DATA
  638. ;
  639. ;-----------------------------------------------------------------------
  640. APA_ATTR STRUC ; ATTRIBUTES FOR APA MODES:
  641. APA_MODE DB ? ; Mode number
  642. NB_C DW ? ; Number of columns
  643. NB_L DW ? ; Number of lines
  644. MAX_COLORS DW ? ; Maximum number of colors available (0=B&W)
  645. APA_ATTR ENDS
  646. TXT_ATTR STRUC ; ATTRIBUTES FOR TXT MODES:
  647. TXT_MODE DB ? ; Mode number
  648. NUM_COLORS DB ? ; Number of colors
  649. TXT_ATTR ENDS
  650. ;-----------------------------------------------------------------------
  651. ;
  652. ; APA MODE ATTRIBUTES:
  653. ;
  654. ;-----------------------------------------------------------------------
  655. NB_APA_MODES DW 10
  656. APA_ATTR_TABLE LABEL WORD
  657. MODE04 APA_ATTR < 4,320,200, 4>
  658. MODE05 APA_ATTR < 5,320,200, 4>
  659. MODE06 APA_ATTR < 6,640,200, 2>
  660. MODE0D APA_ATTR <0DH,320,200, 16>
  661. MODE0E APA_ATTR <0EH,640,200, 16>
  662. MODE0F APA_ATTR <0FH,640,350, 4>
  663. MODE10H APA_ATTR <10H,640,350, 16>
  664. MODE11H APA_ATTR <11H,640,480, 2>
  665. MODE12H APA_ATTR <12H,640,480, 16>
  666. MODE13H APA_ATTR <13H,320,200,256>
  667. ;-----------------------------------------------------------------------
  668. ;
  669. ; TXT MODE ATTRIBUTES:
  670. ;
  671. ;-----------------------------------------------------------------------
  672. NB_TXT_MODES DW 5
  673. TXT_ATTR_TABLE LABEL WORD
  674. MODE00 TXT_ATTR < 0, 16>
  675. MODE01 TXT_ATTR < 1, 16>
  676. MODE02 TXT_ATTR < 2, 16>
  677. MODE03 TXT_ATTR < 3, 16>
  678. MODE07 TXT_ATTR < 7, 0>
  679. ;-----------------------------------------------------------------------
  680. ;
  681. ; BEGIN OF GET_MODE_ATTR
  682. ;
  683. ;-----------------------------------------------------------------------
  684. GET_MODE_ATTR_BEGIN:
  685. PUSH AX
  686. PUSH BX
  687. PUSH CX
  688. PUSH DX
  689. MOV DL,CUR_MODE ; DL = CURRENT MODE
  690. ;
  691. ; Scan the APA_ATTR_TABLE
  692. ;
  693. MOV CX,NB_APA_MODES ; CS <-- Number of APA modes
  694. MOV BX,OFFSET APA_ATTR_TABLE; BX <-- Offset of APA mode table
  695. SCAN_APA:
  696. CMP DL,[BX].APA_MODE ; IF mode found
  697. JE SHORT ITS_APA ; THEN get its attributes
  698. ADD BX,SIZE APA_ATTR
  699. LOOP SCAN_APA ; ELSE keep scanning
  700. JMP SHORT SCAN_TXT_INIT ; NOT in this table: scan txt modes
  701. ITS_APA:
  702. MOV MODE_TYPE,APA ; MODE = APA
  703. MOV AX,[BX].MAX_COLORS
  704. MOV NB_COLORS,AX ; Get number of colors
  705. MOV AX,[BX].NB_L
  706. MOV SCREEN_HEIGHT,AX ; Get number of lines
  707. MOV AX,[BX].NB_C
  708. MOV SCREEN_WIDTH,AX ; Get number of columns
  709. JMP SHORT GET_MODE_ATTR_END
  710. ;
  711. ; Scan the TXT_ATTR_TABLE
  712. ;
  713. SCAN_TXT_INIT:
  714. MOV CX,NB_TXT_MODES ; CX <-- Number of TXT modes
  715. MOV BX,OFFSET TXT_ATTR_TABLE; BX <-- Offset of TXT mode table
  716. SCAN_TXT:
  717. CMP DL,[BX].TXT_MODE ; IF mode found
  718. JE SHORT ITS_TXT ; THEN get its attributes
  719. ADD BX,SIZE TXT_ATTR
  720. LOOP SCAN_TXT ; ELSE keep scanning
  721. ITS_TXT:
  722. MOV MODE_TYPE,TXT ; MODE = TXT
  723. MOV AL,[BX].NUM_COLORS
  724. CBW
  725. MOV NB_COLORS,AX ; Get number of colors
  726. MOV AL,NB_CHAR_COLUMNS ; Get number of columns
  727. CBW
  728. MOV SCREEN_WIDTH,AX
  729. .IF <DS:[BP].HARDWARE_CONFIG EQ OLD_ADAPTER>; If an old adapter is there
  730. .THEN ; The number of lines is 25
  731. MOV SCREEN_HEIGHT,25
  732. .ELSE
  733. MOV AX,BIOS_SEG ; Get number of rows
  734. MOV ES,AX ; from BIOS Data Area
  735. MOV BX,NB_ROWS_OFFSET ; at 0040:0084
  736. MOV AL,ES:[BX]
  737. CBW
  738. INC AX
  739. MOV SCREEN_HEIGHT,AX
  740. .ENDIF
  741. JMP SHORT GET_MODE_ATTR_END
  742. ;
  743. ; The current mode was not found in any of the tables
  744. ;
  745. MOV ERROR_CODE,MODE_NOT_SUPPORTED
  746. GET_MODE_ATTR_END:
  747. POP AX
  748. POP BX
  749. POP CX
  750. POP DX
  751. RET
  752. GET_MODE_ATTR ENDP
  753. PAGE
  754. ;=======================================================================
  755. ;
  756. ; SET_UP_XLT_TABLE : SET UP A COLOR MAPPING FOR EACH COLOR AVAILABLE
  757. ; WITH THE CURRENT MODE
  758. ;
  759. ;-----------------------------------------------------------------------
  760. ;
  761. ; INPUT: CUR_MODE = Current video mode.
  762. ; HARDWARE_CONFIG = Type of display adapter.
  763. ; PRINTER_TYPE = Type of printer attached (Color or B&W)
  764. ; XLT_TAB = Color translation table.
  765. ; CUR_PAGE = Active page number
  766. ; BP = Offset of the shared data area
  767. ;
  768. ;
  769. ; OUTPUT: XLT_TAB IS UPDATED
  770. ;
  771. ; CALLED BY: PRT_SCR
  772. ;
  773. ;-----------------------------------------------------------------------
  774. ;
  775. ; DESCRIPTION: The table is updated to hold a mapping for each color
  776. ; available in the current video mode either TEXT or APA.
  777. ;
  778. ; For example, if the current mode supports 16 colors then the first
  779. ; sixteen bytes of the table will hold the corresponding Color printer
  780. ; or Black and White printer mappings for these colors.
  781. ;
  782. ;
  783. ; LOGIC:
  784. ;
  785. ; IF HARDWARE_CONFIG = CGA OR HARDWARE_CONFIG = PC_CONVERTIBLE
  786. ; THEN
  787. ; CALL SET_CGA_XLT_TAB
  788. ;
  789. ; ELSE IF HARDWARE_CONFIG = EGA
  790. ; THEN
  791. ; CALL SET_EGA_XLT_TAB
  792. ;
  793. ; ELSE IF CUR_MODE = 0FH
  794. ; THEN
  795. ; CALL SET_MODE_F_XLT_TAB
  796. ;
  797. ; ELSE IF CUR_MODE = 19
  798. ; THEN
  799. ; CALL SET_MODE_13H_XLT_TAB
  800. ;
  801. ; ELSE
  802. ; CALL SET_ROUNDUP_XLT_TAB
  803. ;
  804. ; CALL SET_BACKG_IN_XLT_TAB ; Update the background in the translation table
  805. ;
  806. SET_UP_XLT_TAB PROC NEAR
  807. ;-------------------------------------------------------------------------------
  808. ; For old display modes: set up translation table as for a Color Graphics Adapt.
  809. ; Either 4 or 16 colors are set up depending if the mode is an APA or text mode.
  810. ;
  811. ; NOTE: SET_UP_XLT_TAB cannot be invoked if the display adater is a Monochrome
  812. ; display adater. (When a Mono. adapter is attached, a jump is made to
  813. ; the ROM BIOS for printing the screen, and no translation table is set).
  814. ;-------------------------------------------------------------------------------
  815. .IF <BIT DS:[BP].HARDWARE_CONFIG NZ OLD_ADAPTER> OR ; IF it is a CGA
  816. .IF <BIT DS:[BP].HARDWARE_CONFIG NZ PC_CONVERTIBLE> ; or a PC convertible
  817. .THEN ; THEN set up CGA colors
  818. CALL SET_CGA_XLT_TAB ;
  819. .ELSEIF <BIT DS:[BP].HARDWARE_CONFIG NZ EGA> ; ELSEIF it is an EGA
  820. CALL SET_EGA_XLT_TAB ; set up EGA colors.
  821. .ELSEIF <CUR_MODE EQ 0FH> ; ELSEIF we are in mode 15
  822. CALL SET_MODE_F_XLT_TAB ; set up its 4 shades
  823. ;-------------------------------------------------------------------------------
  824. ; A PS/2 system is attached: (we either have a PALACE [Model 30] or a ROUNDUP)
  825. ;-------------------------------------------------------------------------------
  826. .ELSEIF <CUR_MODE EQ 13H> ; ELSEIF current mode is 13h
  827. CALL SET_MODE_13H_XLT_TAB ; set up 256 colors
  828. .ELSEIF <BIT DS:[BP].HARDWARE_CONFIG NZ PALACE> ; ELSEIF PS/2 Model 30(MCGA)
  829. CALL SET_CGA_XLT_TAB ; handle it like a CGA
  830. .ELSE ; ELSE we have a ROUNDUP
  831. ;-------------------------------------------------------------------------------
  832. ; A PS/2 model 50, 60 or 80 or an ADA 'B' card is attached (in 16 color mode):
  833. ;-------------------------------------------------------------------------------
  834. CALL SET_ROUNDUP_XLT_TAB ; set up 16 colors
  835. .ENDIF
  836. ;-------------------------------------------------------------------------------
  837. ; Finish setting up the translation table:
  838. ;-------------------------------------------------------------------------------
  839. CALL SET_BACKG_IN_XLT_TAB ; Update the background in the translation table
  840. ; according to the command line switch setting
  841. ; (i.e.,/R /B)
  842. RET
  843. SET_UP_XLT_TAB ENDP
  844. PAGE
  845. ;===============================================================================
  846. ;
  847. ; SET_BACKG_IN_XLT_TAB : ADJUST THE MAPPING FOR THE BACKGROUND COLOR IN THE
  848. ; XLT_TAB ACCORDING TO PRINTER TYPE AND /R /B.
  849. ;
  850. ;
  851. ;-------------------------------------------------------------------------------
  852. ;
  853. ; INPUT: BP = Offset of shared data area (SWITCHES)
  854. ; XLT_TAB = The color translation table.
  855. ;
  856. ; OUTPUT: XLT_TAB IS UPDATED
  857. ;
  858. ;-------------------------------------------------------------------------------
  859. ;
  860. ; DESCRIPTION: If there is a black and white printer and /R is NOT specified
  861. ; then the background color should not be printed and it is replaced in the
  862. ; translation table by the Intensity for white (will print nothing).
  863. ;
  864. ; If a color printer is attached and /B is not specified then the background
  865. ; color is replaced by the Print Band mask for white.
  866. ;
  867. ; LOGIC:
  868. ; IF (a black and white printer is attached) AND (/R is OFF)
  869. ; THEN
  870. ; MOV XLT_TAB, WHITE_INT ; Store white in translation table
  871. ; ELSE (a color printer is attached)
  872. ; IF (/B is ON)
  873. ; THEN
  874. ; RGB.R := MAX_INT
  875. ; RGB.G := MAX_INT
  876. ; RGB.B := MAX_INT
  877. ; CALL RGB2BAND ; Convert RGB for white to a Band Mask
  878. ; MOV XLT_TAB,AL ; Store the band mask in the xlt table
  879. ;
  880. ;
  881. ;-------------------------------------------------------------------------------
  882. SET_BACKG_IN_XLT_TAB PROC NEAR
  883. ;-------------------------------------------------------------------------------
  884. ;
  885. ; Test if a black and white printer is attached.
  886. ;
  887. ;-------------------------------------------------------------------------------
  888. .IF <BIT DS:[BP].PRINTER_TYPE NZ BLACK_WHITE> AND ; IF black and white
  889. .IF <BIT DS:[BP].SWITCHES Z REVERSE_SW> ; printer and not /R
  890. .THEN ; then, map background
  891. MOV XLT_TAB,WHITE_INT ; to white.
  892. ;-------------------------------------------------------------------------------
  893. ;
  894. ; A Color printer is attached:
  895. ;
  896. ;-------------------------------------------------------------------------------
  897. .ELSEIF <BIT DS:[BP].PRINTER_TYPE NZ COLOR> AND ; else, if color printer
  898. .IF <BIT DS:[BP].SWITCHES Z BACKGROUND_SW> ; and /B if OFF
  899. .THEN ;
  900. ; Store a null band mask
  901. MOV XLT_TAB,0 ; the translation table.
  902. .ENDIF
  903. RET
  904. SET_BACKG_IN_XLT_TAB ENDP
  905. PAGE
  906. ;=======================================================================
  907. ;
  908. ; SET_EGA_XLT_TAB : SET UP COLOR TRANSLATION TABLE FOR ENHANCED GRAPHIC
  909. ; ADAPTER
  910. ;
  911. ;-----------------------------------------------------------------------
  912. ;
  913. ; INPUT: XLT_TAB = Color translation table.
  914. ; PRINTER_TYPE = Type of printer attached (Color or B&W)
  915. ; SWITCHES = GRAPHICS command line parameters.
  916. ;
  917. ; OUTPUT: XLT_TAB IS UPDATED
  918. ;
  919. ; CALLED BY: SET_UP_XLT_TABLE
  920. ;
  921. ;-----------------------------------------------------------------------
  922. ;
  923. ; NOTES: With the EGA, "VIDEO BIOS READ DOT call" returns an index into
  924. ; the 16 EGA palette registers.
  925. ;
  926. ; These registers contain the actual colors stored as rgbRGB components
  927. ; (see EGA_COL2RGB for details) for mode hex 10. Under mode hex E these
  928. ; registers contain the actual colors as I0RGB components (see CGA_COL2RGB
  929. ; for details).
  930. ;
  931. ; These registers can be Revised by the user but, are 'WRITE ONLY'.
  932. ; However, it is possible to define a SAVE AREA where BIOS will maintain
  933. ; a copy of the palette registers.
  934. ;
  935. ; This area is called the "DYNAMIC SAVE AREA" and is defined via the
  936. ; BIOS EGA SAVE_PTR AREA. Whenever the palette registers are changed by
  937. ; the user, BIOS updates the EGA_SAVE_AREA.
  938. ;
  939. ; The 16 palette registers are the first 16 bytes of the DYNAMIC SAVE AREA.
  940. ;
  941. ; This program takes advantage of this feature and consults the EGA DYNAMIC
  942. ; SAVE AREA in order to obtain the colors used in the active screen.
  943. ;
  944. ;
  945. ; DESCRIPTION: Obtain each color available with an EGA by reading its
  946. ; palette register in the EGA_SAVE_AREA:
  947. ;
  948. ; Calculate the mapping for this color, either a BAND_MASK or a
  949. ; GREY INTENSITY and store it in the color translation table.
  950. ;
  951. ;
  952. ; LOGIC:
  953. ;
  954. ; Obtain the DYNAMIC EGA SAVE AREA offset from the BIOS SAVE_PTR_AREA.
  955. ;
  956. ; If current mode is either 4,5 or 6
  957. ; Then,
  958. ; CALL SET_CGA_XLT_TAB
  959. ; Get the background color by reading palette register number 0
  960. ; Else,
  961. ; For each register number (0 to 15):
  962. ; Get the register contents (rgbRGB values) from the EGA SAVE AREA
  963. ; CALL EGA_COL2RGB ; Obtain the Red, Green, Blue values
  964. ; CALL RGB2XLT_TAB ; Obtain a Band Mask or a Grey Intensity
  965. ; ; and store the result in the XLT_TAB
  966. ;
  967. SET_EGA_XLT_TAB PROC NEAR
  968. PUSH AX ; Save the registers used
  969. PUSH BX
  970. PUSH CX
  971. PUSH DX
  972. PUSH DI
  973. ;-------------------------------------------------------------------------------
  974. ;
  975. ; Obtain the pointer to the DYNAMIC SAVE AREA from the SAVE AREA POINTER TABLE:
  976. ;
  977. ;-------------------------------------------------------------------------------
  978. EGA_SAVE_PTR EQU 4A8H ; EGA BIOS pointer to table of
  979. ; pointer to save areas.
  980. XOR AX,AX ; ES segment := paragraph 0
  981. MOV ES,AX
  982. LES BX,ES:DWORD PTR EGA_SAVE_PTR ; ES:BX := Pointer to ptr table
  983. LES BX,ES:[BX]+4 ; ES:BX := Pointer to dynamic save area
  984. ; (NOTE: It is the second pointer in
  985. ; the table)
  986. ;-------------------------------------------------------------------------------
  987. ;
  988. ; Set up one entry in the translation table for each color available.
  989. ;
  990. ;-------------------------------------------------------------------------------
  991. .IF <CUR_MODE EQ 4> OR ; If the current mode is an old CGA
  992. .IF <CUR_MODE EQ 5> OR ; GRAPHICS mode:
  993. .IF <CUR_MODE EQ 6>
  994. .THEN
  995. ;-------------------------------------------------------------------------------
  996. ; Current mode is either mode 4, 5 or 6;
  997. ; Store each color of the old CGA All Points Addressable mode:
  998. ;-------------------------------------------------------------------------------
  999. CALL SET_CGA_XLT_TAB ; Set up colors in the translation
  1000. ; table, NOTE: The background color
  1001. ; will not be set properly since the
  1002. ; EGA BIOS does not update memory
  1003. ; location 40:66 with the value
  1004. ; of the background color as CGA
  1005. ; does.
  1006. ;------Adjust the background color in the translation table:
  1007. ;------The background color is obtained from the EGA DYNAMIC SAVE AREA
  1008. ;------ES:BX = Address of the EGA DYNAMIC SAVE AREA
  1009. ;------NOTE : For CGA compatible modes EGA BIOS stores the color in the
  1010. ;------DYNAMIC SAVE AREA as a I0RGB value.
  1011. XOR DI,DI ; DI:=register number = index in XLT_TAB
  1012. MOV AL,ES:[BX][DI] ; AL:=Palette register 0 = Back. color
  1013. MOV AH,AL ; Convert I0RGB to IRGB (CGA color)
  1014. AND AL,111B ; Isolate RGB bits
  1015. AND AH,10000B ; Isolate I bit
  1016. SHR AH,1 ; Move I bit from position 5 to 4
  1017. OR AL,AH ; Get IRGB byte.
  1018. CALL CGA_COL2RGB ; Convert IRGB to R,G,B values
  1019. CALL RGB2XLT_TAB ; Convert RGB to an entry in XLT_TAB
  1020. .ELSE ; ELSE, we have an EGA graphics mode:
  1021. ;-------------------------------------------------------------------------------
  1022. ; The current mode is a either a text mode or one of the EGA enhanced mode;
  1023. ; Store in the translation table each color available (these modes have 16 col.)
  1024. ;-------------------------------------------------------------------------------
  1025. MOV CX,16 ; CX := Number of palette registers
  1026. ; to read
  1027. XOR DI,DI ; DI := Palette register number
  1028. ; and index in the translation table
  1029. STORE_1_EGA_COLOR:
  1030. MOV AL,ES:[BX][DI] ; AL := Palette register
  1031. .IF <CUR_MODE EQ 14> OR ; If mode E (hex) OR mode D (hex)
  1032. .IF <CUR_MODE EQ 13> ; the colors are
  1033. .THEN ; stored as I0CGA colors
  1034. MOV AH,AL ; Convert I0RGB to IRGB (CGA color)
  1035. AND AL,111B ; Isolate RGB bits
  1036. AND AH,10000B ; Isolate I bit
  1037. SHR AH,1 ; Move I bit from position 5 to 4
  1038. OR AL,AH ; Get IRGB byte.
  1039. CALL CGA_COL2RGB ; Convert IRGB to R,G,B values
  1040. .ELSE ; Else, they are stored as (rgbRGB);
  1041. CALL EGA_COL2RGB ; Convert register to R,G,B values
  1042. .ENDIF
  1043. CALL RGB2XLT_TAB ; Convert RGB to an entry in XLT_TAB
  1044. INC DI ; Get next palette register number
  1045. LOOP STORE_1_EGA_COLOR
  1046. .ENDIF ; ENDIF 4 colors or 16 colors
  1047. POP DI ; Restore the registers
  1048. POP DX
  1049. POP CX
  1050. POP BX
  1051. POP AX
  1052. RET
  1053. SET_EGA_XLT_TAB ENDP
  1054. PAGE
  1055. ;=======================================================================
  1056. ;
  1057. ; SET_CGA_XLT_TAB : SET UP COLOR TRANSLATION TABLE FOR COLOR GRAPHIC
  1058. ; ADAPTER
  1059. ;
  1060. ;-----------------------------------------------------------------------
  1061. ;
  1062. ; INPUT: XLT_TAB = Color translation table.
  1063. ; PRINTER_TYPE = Type of printer attached (Color or B&W)
  1064. ; SWITCHES = GRAPHICS command line parameters.
  1065. ;
  1066. ; OUTPUT: XLT_TAB IS UPDATED
  1067. ;
  1068. ; CALLED BY: SET_UP_XLT_TABLE
  1069. ;
  1070. ;-----------------------------------------------------------------------
  1071. ;
  1072. ; NOTES: With the CGA, the "VIDEO BIOS READ DOT call" returns a number
  1073. ; from 0 to 3. A dot of value 0 is of the background color.
  1074. ;
  1075. ; The actual value of the background color is stored in BIOS VIDEO
  1076. ; DISPLAY DATA AREA as a PIIRGB value (see CGA_COL2RGB for details) and
  1077. ; can be any of 16 colors.
  1078. ;
  1079. ; A dot of value 1,2, or 3 represents any of 2 specific colors depending
  1080. ; on the current color palette.
  1081. ;
  1082. ; The palette number is obtained from the BIOS VIDEO DISPLAY DATA AREA
  1083. ; (It is the "P" bit or bit number 5)
  1084. ;
  1085. ; The dot values 1,2,3 expressed in binary actually represent the RG
  1086. ; (Red, Green) components of the color.
  1087. ;
  1088. ; The palette number represents the B (Blue) component therefore, when
  1089. ; the palette number is appended to the color number we obtain the RGB
  1090. ; components for that color.
  1091. ;
  1092. ; (E.G., COLOR = 010 ; COLOR # 2
  1093. ; PALETTE= 0 ; PALETTE # 0
  1094. ;
  1095. ; IRGB = 0100 ; Intensity = 0 Ŀ
  1096. ; ; Red = 1 ����> color = Red
  1097. ; ; Green = 0 �
  1098. ; ; Blue = 0 ��
  1099. ;
  1100. ;
  1101. ; DESCRIPTION:
  1102. ;
  1103. ; For each color available with a CGA:
  1104. ; Calculate the color mapping, either a BAND_MASK or a GREY
  1105. ; INTENSITY and store it in the color translation table.
  1106. ;
  1107. ; LOGIC:
  1108. ;
  1109. ; ; Obtain the background color from VIDEO BIOS DATA AREA
  1110. ; ; and the paletter number
  1111. ;
  1112. ; ; Store the Background color:
  1113. ; CALL CGA_COL2RGB ; Convert IRGB components to RGB values
  1114. ; CALL RGB2XLT_TAB ; Convert RGB to an entry in the translation
  1115. ; ; table
  1116. ; ; Store all other colors:
  1117. ; FOR IRG := 1 TO 3 ; Obtain the color number
  1118. ; Append palette number (B) to IRG
  1119. ; CALL CGA_COL2RGB ; Convert color to RGB values
  1120. ; CALL RGB2XLT_TAB ; Convert RGB to an entry in the translation
  1121. ; ; table
  1122. ;
  1123. SET_CGA_XLT_TAB PROC NEAR
  1124. PUSH AX
  1125. PUSH BX
  1126. PUSH CX
  1127. PUSH DI
  1128. PUSH ES
  1129. .IF <CUR_MODE EQ 4> OR
  1130. .IF <CUR_MODE EQ 5>
  1131. ;===============================================================================
  1132. ;
  1133. ; THE CURRENT MODE IS MODE 4 OR 5
  1134. ;
  1135. ;-------------------------------------------------------------------------------
  1136. .THEN
  1137. ;-------------------------------------------------------------------------------
  1138. ; Read the CRT palette from the BIOS ROM to obtain the background color and
  1139. ; the current palette number; store the palette number in BL
  1140. ;-------------------------------------------------------------------------------
  1141. ROM_BIOS_SEG EQU 40H ; CGA BIOS SEGMENT
  1142. CRT_PALETTE_OFF EQU 66H ; BIOS Current palette setting
  1143. P_BIT_MASK EQU 100000B ; bit 5 = Current palette
  1144. I_BIT_MASK EQU 1000B ; bit 4 = Intensity bit
  1145. R_BIT_MASK EQU 100B ; bit 2 = Red bit
  1146. G_BIT_MASK EQU 10B ; bit 1 = Green bit
  1147. B_BIT_MASK EQU 1B ; bit 0 = Blue bit
  1148. MOV AX,ROM_BIOS_SEG ; ES := ROM BIOS SEGMENT
  1149. PUSH AX
  1150. POP ES
  1151. MOV AL,ES:CRT_PALETTE_OFF; AL := CRT Palette (00PIIRGB)
  1152. MOV BL,P_BIT_MASK ; LOW NIBBLE = BACKGROUND COLOR
  1153. AND BL,AL ; BL := Palette number
  1154. MOV CL,5
  1155. SHR BL,CL
  1156. XOR DI,DI ; DI := Index in the XLT_TAB
  1157. ;-------------------------------------------------------------------------------
  1158. ; Store the background color, (obtained from low 4 bits of the byte at 40:66)
  1159. ;-------------------------------------------------------------------------------
  1160. CALL CGA_COL2RGB ; Convert color (in AL) to R, G, B values
  1161. CALL RGB2XLT_TAB ; Convert RGB to an entry in XLT_TAB
  1162. ;-------------------------------------------------------------------------------
  1163. ; Store the 3 foreground colors for mode 4 and 5
  1164. ;-------------------------------------------------------------------------------
  1165. MOV CX,3 ; For each color, but the background:
  1166. STORE_1_CGA_MODE4_COLOR:
  1167. INC DI ; Increment index in the translation table
  1168. MOV AX,DI ; AL := IRG
  1169. SHL AL,1
  1170. OR AL,BL ; AL := IRGB
  1171. CALL CGA_COL2RGB ; Convert color (in AL) to R, G, B values
  1172. CALL RGB2XLT_TAB ; Convert RGB to an entry in XLT_TAB
  1173. LOOP STORE_1_CGA_MODE4_COLOR
  1174. .ELSEIF <CUR_MODE EQ 6>
  1175. ;===============================================================================
  1176. ;
  1177. ; THE CURRENT MODE IS MODE 6
  1178. ;
  1179. ;-------------------------------------------------------------------------------
  1180. .THEN
  1181. ;-------------------------------------------------------------------------------
  1182. ; Store background color for mode 6 (mode 6 is a 2 colors, APA mode)
  1183. ; Background is stored as BLACK
  1184. ;-------------------------------------------------------------------------------
  1185. XOR DI,DI ; DI := Index of color in translation table
  1186. MOV RGB.R,BLACK_INT ; Foreground color is white
  1187. MOV RGB.G,BLACK_INT ; RGB := RGB of white
  1188. MOV RGB.B,BLACK_INT ;
  1189. CALL RGB2XLT_TAB ; Convert RGB to an entry in XLT_TAB
  1190. ;-------------------------------------------------------------------------------
  1191. ; Store foreground color for mode 6 (mode 6 is a 2 colors, APA mode)
  1192. ;-------------------------------------------------------------------------------
  1193. INC DI ; DI := Index of color in translation table
  1194. MOV RGB.R,WHITE_INT ; Background color is BLACK
  1195. MOV RGB.G,WHITE_INT ; RGB := RGB of BLACK
  1196. MOV RGB.B,WHITE_INT ;
  1197. CALL RGB2XLT_TAB ; Convert RGB to an entry in XLT_TAB
  1198. .ELSE
  1199. ;===============================================================================
  1200. ;
  1201. ; THE CURRENT MODE IS A TEXT MODE:
  1202. ;
  1203. ;-------------------------------------------------------------------------------
  1204. XOR DI,DI ; DI := Index in the translation table
  1205. MOV CX,16 ; For each of the 16 colors:
  1206. STORE_1_CGA_TEXT_COLOR:
  1207. MOV AX,DI ; AL := IRGB
  1208. CALL CGA_COL2RGB ; Convert color (in AL) to R, G, B values
  1209. CALL RGB2XLT_TAB ; Convert RGB to an entry in XLT_TAB
  1210. INC DI ; Increment index in the translation table
  1211. LOOP STORE_1_CGA_TEXT_COLOR
  1212. .ENDIF ;
  1213. POP ES
  1214. POP DI
  1215. POP CX
  1216. POP BX
  1217. POP AX
  1218. RET
  1219. SET_CGA_XLT_TAB ENDP
  1220. PAGE
  1221. ;===============================================================================
  1222. ;
  1223. ; RGB2XLT_TAB: CONVERT R,G,B VALUES TO EITHER A BAND MASK OR AN INTENSITY
  1224. ; STORE THE RESULT IN THE TRANSLATION TABLE
  1225. ;
  1226. ;-------------------------------------------------------------------------------
  1227. ;
  1228. ; INPUT: DI = Index in the translation table
  1229. ; RGB = Red Green Blue values of the color to be stored.
  1230. ;
  1231. ; OUTPUT: XLT_TAB is updated
  1232. ;
  1233. ;-------------------------------------------------------------------------------
  1234. ; DESCRIPTION: Convert the RGB values to either a Band mask or an intensity
  1235. ; depending on the printer type; store the result in the translation table.
  1236. ;
  1237. ; LOGIC:
  1238. ; IF PRINTER_TYPE = COLOR
  1239. ; THEN
  1240. ; CALL RGB2BAND ; Obtain a Band Mask
  1241. ; ELSE ; Printer is Monochrome
  1242. ; CALL RGB2INT ; Obtain a Grey Intensity
  1243. ; Store the result in the XLT_TAB
  1244. ;
  1245. RGB2XLT_TAB PROC NEAR
  1246. .IF <DS:[BP].PRINTER_TYPE EQ COLOR>; Color printer ?
  1247. .THEN
  1248. ;-------A color printer is attached:
  1249. CALL RGB2BAND ; Yes, convert RGB to color band (in AL)
  1250. .ELSE
  1251. ;-------A black and white printer is attached:
  1252. CALL RGB2INT ; No, RGB to an intensity in AL
  1253. .ENDIF
  1254. ;-------Store the result
  1255. MOV XLT_TAB[DI],AL
  1256. RET
  1257. RGB2XLT_TAB ENDP
  1258. PAGE
  1259. ;===============================================================================
  1260. ;
  1261. ; CGA_COL2RGB : CONVERT A COLOR FROM THE CGA TO RED GREEN BLUE VALUES
  1262. ;
  1263. ;-------------------------------------------------------------------------------
  1264. ;
  1265. ; INPUT: AL = 0000IRGB ONE BYTE WHERE BIT:
  1266. ;
  1267. ; I = Intensity bit
  1268. ; R = Red component
  1269. ; G = Green component
  1270. ; B = Blue component
  1271. ;
  1272. ;
  1273. ; OUTPUT: RGB.R = RED component (0-63)
  1274. ; RGB.G = GREEN component (0-63)
  1275. ; RGB.B = BLUE component (0-63)
  1276. ;
  1277. ; CALLED BY: SET_UP_CGA_XLT_TABLE
  1278. ;
  1279. ;-----------------------------------------------------------------------
  1280. ;
  1281. ; DESCRIPTION: If either the RED, GREEN, or BLUE bit is on (in an IRGB
  1282. ; byte) then, the corresponding color gun on the display is firing 2/3
  1283. ; of its capacity, giving a color intensity of "2/3".
  1284. ;
  1285. ; If the INTENSITY bit is on, then 1/3 is added to EACH color.
  1286. ;
  1287. ; (E.G., IRGB R G B
  1288. ; BLACK = 00000000 ( 0, 0, 0)
  1289. ; WHITE = 00001111 (3/3, 3/3, 3/3)
  1290. ; RED = 00000100 (2/3, 0, 0)
  1291. ; HIGH INT. RED = 00001100 (3/3, 1/3, 1/3)
  1292. ;
  1293. ; Since we want an intensity from 0 to 63,
  1294. ; "2/3" of RED means:
  1295. ; 2/3 * 63 = 42
  1296. ;
  1297. ;
  1298. ; LOGIC:
  1299. ; Get the intensity.
  1300. ; Get the red component
  1301. ; Get the green component
  1302. ; Get the blue component
  1303. ;
  1304. CGA_COL2RGB PROC NEAR
  1305. ;-----------------------------------------------------------------------
  1306. ;
  1307. ; Init the R,G,B values:
  1308. ;
  1309. ;-----------------------------------------------------------------------
  1310. MOV RGB.R,0
  1311. MOV RGB.G,0
  1312. MOV RGB.B,0
  1313. ;-----------------------------------------------------------------------
  1314. ;
  1315. ; Test the Intensity bit:
  1316. ;
  1317. ;-----------------------------------------------------------------------
  1318. .IF <BIT AL AND I_BIT_MASK> ; IF, I is on
  1319. .THEN
  1320. ADD RGB.R,ONE_THIRD ; Then, add one third to each
  1321. ADD RGB.G,ONE_THIRD ; color.
  1322. ADD RGB.B,ONE_THIRD
  1323. .ENDIF
  1324. ;-----------------------------------------------------------------------
  1325. ;
  1326. ; Test the RGB bits:
  1327. ;
  1328. ;-----------------------------------------------------------------------
  1329. .IF <BIT AL AND R_BIT_MASK> ; If, Red is on
  1330. .THEN
  1331. ADD RGB.R,TWO_THIRD ; then, add two third RED
  1332. .ENDIF
  1333. .IF <BIT AL AND G_BIT_MASK> ; If, Green is on
  1334. .THEN
  1335. ADD RGB.G,TWO_THIRD ; then, add two third GREEN
  1336. .ENDIF
  1337. .IF <BIT AL AND B_BIT_MASK> ; If, Blue is on
  1338. .THEN
  1339. ADD RGB.B,TWO_THIRD ; then, add two third BLUE
  1340. .ENDIF
  1341. RET
  1342. CGA_COL2RGB ENDP
  1343. PAGE
  1344. ;=======================================================================
  1345. ;
  1346. ; SET_MODE_F_XLT_TAB: SET UP COLOR TRANSLATION TABLE FOR MONOCHROME
  1347. ; MODE "F"
  1348. ;
  1349. ;-----------------------------------------------------------------------
  1350. ;
  1351. ; INPUT: XLT_TAB = Color translation table.
  1352. ; PRINTER_TYPE = Type of printer attached (Color or B&W)
  1353. ; SWITCHES = GRAPHICS command line parameters.
  1354. ;
  1355. ; OUTPUT: XLT_TAB IS UPDATED
  1356. ;
  1357. ; CALLED BY: SET_UP_XLT_TABLE
  1358. ;
  1359. ;-------------------------------------------------------------------------------
  1360. ;
  1361. ; NOTES: In mode F the "VIDEO BIOS READ DOT call" returns a byte where
  1362. ; bit 1 and 3 represent the value of plane 1 and 3.
  1363. ; The following colors are available using this mode:
  1364. ;
  1365. ; plane 2: plane 0: color:
  1366. ; 0 0 black
  1367. ; 0 1 white
  1368. ; 1 0 blinking white
  1369. ; 1 1 high-intensity white
  1370. ;
  1371. ;
  1372. ; DESCRIPTION: A local table holds the Red, Green, Blue values for each of
  1373. ; the 4 Mono colors available in Mode Fh.
  1374. ; Each color is stored as either a Grey intensity if printing in Monochrome
  1375. ; or as a Band Mask if printing in color.
  1376. ; Black is stored as black.
  1377. ; White is stored as a light gray
  1378. ; High-intensity white and blinking white are stored as white.
  1379. ;
  1380. ;
  1381. ; LOGIC:
  1382. ; FOR EACH "COLOR" AVAILABLE WITH MODE F
  1383. ; GET ITS R,G,B VALUES
  1384. ; CALL RGB2XLT_TAB ; Convert RGB to an entry in the translation
  1385. ; ; table
  1386. ;
  1387. SET_MODE_F_XLT_TAB PROC NEAR
  1388. PUSH AX
  1389. PUSH SI
  1390. PUSH DI
  1391. JMP SHORT SET_MODE_F_BEGIN
  1392. ;-------------------------------------------------------------------------------
  1393. ;
  1394. ; TABLE OF R,G,B VALUES WE ASSIGN TO THE 4 COLORS AVAILABLE IN MODE F:
  1395. ;
  1396. ;-------------------------------------------------------------------------------
  1397. MODE_F_RGB LABEL BYTE
  1398. DB BLACK_INT,BLACK_INT,BLACK_INT ; Black is mapped to black.
  1399. DB TWO_THIRD,TWO_THIRD,TWO_THIRD ; White --> light grey
  1400. DB WHITE_INT,WHITE_INT,WHITE_INT ; Blinking --> white
  1401. DB WHITE_INT,WHITE_INT,WHITE_INT ; High-int. White --> white
  1402. ;-------------------------------------------------------------------------------
  1403. ;
  1404. ; STORE THE COLORS AVAILABLE WITH MODE F
  1405. ;
  1406. ;-------------------------------------------------------------------------------
  1407. SET_MODE_F_BEGIN:
  1408. MOV SI,OFFSET MODE_F_RGB ; SI <-- Offset of RGB table
  1409. XOR DI,DI ; DI <-- Index into translation table
  1410. ;-------For each color available in mode F:
  1411. STORE_1_MODE_F_COLOR:
  1412. MOV AL,[SI] ; Get the Red component
  1413. MOV RGB.R,AL
  1414. MOV AL,[SI]+1 ; Get the Green component
  1415. MOV RGB.G,AL
  1416. MOV AL,[SI]+2 ; Get the Blue component
  1417. MOV RGB.B,AL
  1418. ;-------Convert pixel to either a Color band or an Intensity:
  1419. CALL RGB2XLT_TAB ; Convert and store in the xlt table
  1420. ADD SI,3 ; Get next R,G,B values
  1421. INC DI ; One more color has been stored
  1422. CMP DI,NB_COLORS ; All stored ?
  1423. JL STORE_1_MODE_F_COLOR
  1424. POP DI
  1425. POP SI
  1426. POP AX
  1427. RET
  1428. SET_MODE_F_XLT_TAB ENDP
  1429. PAGE
  1430. ;=======================================================================
  1431. ;
  1432. ; SET_MODE_13H_XLT_TAB: SET UP COLOR TRANSLATION TABLE FOR PALACE VIDEO
  1433. ; ADAPTER IN MODE 13H
  1434. ;
  1435. ;-----------------------------------------------------------------------
  1436. ;
  1437. ; INPUT: XLT_TAB = Color translation table.
  1438. ; PRINTER_TYPE = Type of printer attached (Color or B&W)
  1439. ; SWITCHES = GRAPHICS command line parameters.
  1440. ;
  1441. ; OUTPUT: XLT_TAB IS UPDATED
  1442. ;
  1443. ; CALLED BY: SET_UP_XLT_TABLE
  1444. ;
  1445. ;-----------------------------------------------------------------------
  1446. ;
  1447. ; NOTES: With the PALACE the "VIDEO BIOS READ DOT call" returns a direct
  1448. ; index to the 256 COLOR REGISTERS.
  1449. ;
  1450. ; These COLORS REGISTERS hold the R,G,B (Red, Green, Blue) values for
  1451. ; each of the 256 colors available at the same time on the screen.
  1452. ; Color register number 0 holds the background color.
  1453. ;
  1454. ; DESCRIPTION: Store a color mapping for each color register.
  1455. ; If the REVERSE_SW is off, exchange white and black.
  1456. ;
  1457. ; LOGIC:
  1458. ;
  1459. ; For each color (0 to 255)
  1460. ; Read the color register ; get the RGB values for this color num.
  1461. ; Store the result in the XLT_TAB
  1462. ;
  1463. SET_MODE_13H_XLT_TAB PROC NEAR
  1464. PUSH AX
  1465. PUSH BX
  1466. PUSH CX
  1467. PUSH DX
  1468. PUSH DI
  1469. MOV NB_COLORS_TO_READ,256 ; Read 256 color registers
  1470. ;-------------------------------------------------------------------------------
  1471. ;
  1472. ; Store in the translation table each color available for mode 13h:
  1473. ;
  1474. ;-------------------------------------------------------------------------------
  1475. XOR DI,DI ; DI := Palette register number
  1476. ; and index in the translation table
  1477. STORE_1_M13H_COLOR:
  1478. MOV BX,DI ; BX := Color register to be read
  1479. MOV AX,GET_C_REG_CALL ; AX := BIOS Get color register call
  1480. INT 10H ; Call BIOS
  1481. MOV RGB.R,DH ; Get Red value
  1482. MOV RGB.G,CH ; Get Green value
  1483. MOV RGB.B,CL ; Get Blue value
  1484. CALL RGB2XLT_TAB ; Convert RGB to an entry in XLT_TAB
  1485. INC DI ; Get next palette register number
  1486. CMP DI,NB_COLORS_TO_READ ; All colors stored ?
  1487. JL STORE_1_M13H_COLOR ; No, get next one
  1488. POP DI
  1489. POP DX
  1490. POP CX
  1491. POP BX
  1492. POP AX
  1493. RET
  1494. NB_COLORS_TO_READ DW ? ; Number of colors registers to read with a PS/2
  1495. SET_MODE_13H_XLT_TAB ENDP
  1496. PAGE
  1497. ;===============================================================================
  1498. ;
  1499. ; SET_ROUNDUP_XLT_TAB: SET UP COLOR TRANSLATION TABLE FOR ROUNDUP VIDEO
  1500. ; ADAPTER
  1501. ;
  1502. ;-------------------------------------------------------------------------------
  1503. ;
  1504. ; INPUT: XLT_TAB = Color translation table.
  1505. ; PRINTER_TYPE = Type of printer attached (Color or B&W)
  1506. ; SWITCHES = GRAPHICS command line parameters.
  1507. ;
  1508. ; OUTPUT: XLT_TAB IS UPDATED
  1509. ;
  1510. ; CALLED BY: SET_UP_XLT_TABLE
  1511. ;
  1512. ;-------------------------------------------------------------------------------
  1513. ;
  1514. ; NOTES: With the ROUNDUP the "VIDEO BIOS READ DOT call" returns an
  1515. ; index into the 16 PALETTE REGISTERS.
  1516. ;
  1517. ; Each palette register holds an index into the current "color page"
  1518. ; within the 256 COLOR REGISTERS.
  1519. ;
  1520. ; These "color pages" represent all the colors from WHICH TO CHOOSE the
  1521. ; screen colors for an active page; 16 colors can be displayed at the
  1522. ; same time on the screen.
  1523. ;
  1524. ; There are 2 paging modes: either 64 color pages or 16 color pages:
  1525. ;
  1526. ; In 64 color mode, there are 4 color pages available (the 256 palette
  1527. ; registers are partitioned in 4 blocks of 64 colors).
  1528. ;
  1529. ; The 16 screen colors for the active page are selected from these 64
  1530. ; color registers.
  1531. ;
  1532. ; This scheme allows for quickly changing the contents of the screen by
  1533. ; changing the active page.
  1534. ;
  1535. ; The COLOR REGISTERS contains the color information stored as RGB (Red,
  1536. ; Green, Blue) components. There is one byte for each of these 3
  1537. ; components. The value for each component ranges from 0 to 63 (where
  1538. ; 0 = color not present).
  1539. ;
  1540. ;
  1541. ; DESCRIPTION: Determine the paging mode and the active color page.
  1542. ; For each color available with the current mode, get the palette
  1543. ; register and then, read the corresponding color register in order to
  1544. ; obtain its RGB components.
  1545. ;
  1546. ; For mode 11h, 2 colors only are available. These colors are obtained from
  1547. ; palette register 0 (background) and 7 (foreground color). The contents
  1548. ; of these 2 palette registers is also used as an index within the color
  1549. ; registers.
  1550. ;
  1551. ; If printing is Monochrome, map the RGB to a Grey Intensity.
  1552. ; If printing is in colors, map the RGB to a Band Mask.
  1553. ; Store the result in the translation table
  1554. ;
  1555. ; LOGIC:
  1556. ;
  1557. ; Read color page state (BIOS INT 10H - AL = 1AH)
  1558. ;
  1559. ; If mode 4,5 or 6
  1560. ; Then
  1561. ; CALL SET_CGA_XLT_TAB
  1562. ; Adjust the background color.
  1563. ; else
  1564. ; If mode 11h
  1565. ; then
  1566. ; For PALETTE_INDEX := 0 to 15
  1567. ; IF PAGE_MODE = PAGE_64_REGISTERS
  1568. ; THEN
  1569. ; Read the palette register number "PALETTE_INDEX"
  1570. ; COLOR_INDEX := Palette register contents
  1571. ; COLOR_INDEX := (CUR_PAGE_NUM * 64) + COLOR_INDEX
  1572. ; Read color register number "COLOR_INDEX" ; Obtain R,G,B values.
  1573. ; CALL RGB2XLT_TAB ; Convert RGB to an entry in XLT_TAB
  1574. ;
  1575. ; ELSE IF PAGE_MODE = PAGE_16_REGISTERS
  1576. ; COLOR_INDEX := (CUR_PAGE_NUM * 16) + PALETTE_INDEX
  1577. ; Read color register number "COLOR_INDEX"
  1578. ; CALL RGB2XLT_TAB ; Convert RGB to an entry in XLT_TAB
  1579. ;
  1580. ;
  1581. SET_ROUNDUP_XLT_TAB PROC NEAR
  1582. PAGING_MODE_64 EQU 0
  1583. PUSH AX
  1584. PUSH BX
  1585. PUSH CX
  1586. PUSH DI
  1587. ;-------------------------------------------------------------------------------
  1588. ; Obtain the color page state
  1589. ;-------------------------------------------------------------------------------
  1590. MOV AX,PAGE_STATE_CALL ; Call BIOS
  1591. INT 10H ; BL := Paging mode
  1592. ; BH := Current page
  1593. ;-------------------------------------------------------------------------------
  1594. ; Check the video mode:
  1595. ;-------------------------------------------------------------------------------
  1596. .SELECT
  1597. .WHEN <CUR_MODE EQ 4> OR ; If the current mode is an old CGA
  1598. .WHEN <CUR_MODE EQ 5> OR ; mode:
  1599. .WHEN <CUR_MODE EQ 6> ;
  1600. ;-------------------------------------------------------------------------------
  1601. ;
  1602. ; Old CGA graphics mode (mode 4, 5 or 6)
  1603. ;
  1604. ;-------------------------------------------------------------------------------
  1605. ;-------------------------------------------------------------------------------
  1606. ; Store colors of the old CGA modes:
  1607. ;-------------------------------------------------------------------------------
  1608. CALL SET_CGA_XLT_TAB ; Set up colors in the translation
  1609. ; table, NOTE: The background color
  1610. ; will not be set properly since the
  1611. ; PS/2 BIOS does not update memory
  1612. ; location 40:66 with the value
  1613. ; of the background color as CGA
  1614. ; does for modes 4 and 5. However
  1615. ; 40:66 holds the current palette
  1616. ; selected.
  1617. ;-------------------------------------------------------------------------------
  1618. ; Adjust the background color for modes 4,5 or 6
  1619. ;-------------------------------------------------------------------------------
  1620. MOV PAL_REGISTER_NB,0 ; Read the palette register number 0
  1621. CALL GET_PALETTE_RGB ; this register points to the color
  1622. ; register that contains the RGB
  1623. ; values of the BACKGROUND color.
  1624. MOV DI,0 ; DI := Index in the translation table
  1625. CALL RGB2XLT_TAB ; Store mapping in the translation table
  1626. .WHEN <CUR_MODE EQ 11H>
  1627. ;-------------------------------------------------------------------------------
  1628. ;
  1629. ; Mode 11h (2 colors out of 256,000 colors)
  1630. ;
  1631. ;-------------------------------------------------------------------------------
  1632. ;-------------------------------------------------------------------------------
  1633. ; Get the background color:
  1634. ;-------------------------------------------------------------------------------
  1635. MOV PAL_REGISTER_NB,0 ; Read the palette register number 0
  1636. CALL GET_PALETTE_RGB ; Get the RGB values for this color
  1637. MOV DI,0 ; DI := Index in translation table
  1638. CALL RGB2XLT_TAB ; Store mapping in the translation table
  1639. ;-------------------------------------------------------------------------------
  1640. ; Get the foreground color:
  1641. ;-------------------------------------------------------------------------------
  1642. MOV PAL_REGISTER_NB,7 ; Read the palette register for the
  1643. ; FOREGROUND color (palette register 7)
  1644. CALL GET_PALETTE_RGB ; Get the RGB values for this color
  1645. MOV DI,1 ; DI := Index in translation table
  1646. CALL RGB2XLT_TAB ; Store mapping in the translation table
  1647. .OTHERWISE
  1648. ;-------------------------------------------------------------------------------
  1649. ;
  1650. ; The current mode is a 16 color mode
  1651. ;
  1652. ;-------------------------------------------------------------------------------
  1653. XOR DI,DI ; DI := Index in translation table
  1654. MOV CX,16 ; 16 colors to read and store
  1655. MOV PAL_REGISTER_NB,0 ; Palette register to read
  1656. STORE_1_PS2_COLOR:
  1657. CALL GET_PALETTE_RGB ; Get the RGB values for this color
  1658. ;
  1659. ;-------Convert the RGB values to band mask or intensity and store in XLT_TAB:
  1660. CALL RGB2XLT_TAB ; Store mapping in the translation table
  1661. INC DI ; Get next palette register number
  1662. INC PAL_REGISTER_NB ;
  1663. LOOP STORE_1_PS2_COLOR ; Read it.
  1664. .ENDSELECT
  1665. POP DI
  1666. POP CX
  1667. POP BX
  1668. POP AX
  1669. RET
  1670. PAL_REGISTER_NB DB ? ; Number of the palette register to read
  1671. SET_ROUNDUP_XLT_TAB ENDP
  1672. PAGE
  1673. ;===============================================================================
  1674. ;
  1675. ; GET_PALETTE_RGB: ON THE PS/2 MODEL 50, 60 AND 80, GET THE RGB VALUES FOR A
  1676. ; PALETTE REGISTER BY READING THE CORRESPONDING COLOR REGISTER
  1677. ;
  1678. ;-------------------------------------------------------------------------------
  1679. ;
  1680. ; INPUT: PAL_REGISTER_NB = Palette register number
  1681. ; BH = Current page number
  1682. ; BL = Current paging mode
  1683. ;
  1684. ; OUTPUT: RGB.R = The RGB values obtained from the color register
  1685. ; RGB.G corresponding to the palette register specified
  1686. ; RGB.B
  1687. ;
  1688. ; CALLED BY: SET_ROUNDUP_XLT_TAB
  1689. ;
  1690. ;-------------------------------------------------------------------------------
  1691. GET_PALETTE_RGB PROC
  1692. PUSH AX
  1693. PUSH BX
  1694. PUSH CX
  1695. PUSH DX
  1696. PUSH SI
  1697. MOV AL,BH ; SI := Current page number
  1698. CBW ;
  1699. MOV SI,AX ;
  1700. ;-------------------------------------------------------------------------------
  1701. ;
  1702. ; Calculte the absolute number of the first Color Register for the current page:
  1703. ; (calculated in SI)
  1704. ;
  1705. ;-------------------------------------------------------------------------------
  1706. .IF <BL EQ PAGING_MODE_64> ; If mode is 64 Color page
  1707. .THEN ; then
  1708. MOV CL,6 ; SI := Current page num * 64
  1709. SHL SI,CL ;
  1710. .ELSE ; else, Mode is 16 Color page
  1711. MOV CL,4 ; SI := Current page num * 16
  1712. SHL SI,CL ;
  1713. .ENDIF
  1714. ;
  1715. ;-------Read the PALETTE REGISTER
  1716. MOV BL,PAL_REGISTER_NB ; BL := Palette register to be read
  1717. MOV AX,GET_P_REG_CALL ; Read palette register call
  1718. INT 10H ; Call BIOS,
  1719. ; BH := Color register index
  1720. ; WITHIN the current page and is
  1721. ; either (0-15) or (0-63)
  1722. ; NOTE: SI = Absolute index (0-255) to
  1723. ; the first color register of the
  1724. ; current page and is a multiple of
  1725. ; either 16 or 64
  1726. MOV BL,BH ; BX := Index within current color page
  1727. XOR BH,BH ;
  1728. ;
  1729. ;-------Read the Color register:
  1730. OR BX,SI ; BX := Index of Color register to read
  1731. MOV AX,GET_C_REG_CALL ; Read the color register
  1732. INT 10H ; Call BIOS,
  1733. MOV RGB.R,DH ; DH := Red value read
  1734. MOV RGB.G,CH ; CH := Green value read
  1735. MOV RGB.B,CL ; CL := Blue value read
  1736. POP SI
  1737. POP DX
  1738. POP CX
  1739. POP BX
  1740. POP AX
  1741. RET
  1742. GET_PALETTE_RGB ENDP
  1743. PAGE
  1744. ;=======================================================================
  1745. ;
  1746. ; EGA_COL2RGB : CONVERT A COLOR FROM THE EGA TO RED GREEN BLUE VALUES
  1747. ;
  1748. ;-----------------------------------------------------------------------
  1749. ;
  1750. ; INPUT: AL = 00rgbRGB ONE BYTE WHERE BIT:
  1751. ;
  1752. ; r = 1/3 of Red component
  1753. ; g = 1/3 of Green component
  1754. ; b = 1/3 of Blue component
  1755. ; R = 2/3 of Red component
  1756. ; G = 2/3 of Green component
  1757. ; B = 3/3 of Blue component
  1758. ;
  1759. ;
  1760. ; OUTPUT: RGB.R = RED component (0-63)
  1761. ; RGB.G = GREEN component (0-63)
  1762. ; RGB.B = BLUE component (0-63)
  1763. ;
  1764. ; CALLED BY: SET_UP_EGA_XLT_TABLE
  1765. ;
  1766. ;-----------------------------------------------------------------------
  1767. ;
  1768. ; DESCRIPTION: Sums up the values for each color component.
  1769. ; "2/3 of RED" means that the red gun in the display attached to the EGA
  1770. ; is firing at 2/3 of full intensity.
  1771. ;
  1772. ; Since the color intensities range from 0 to 63, "1/3" means an
  1773. ; intensity of:
  1774. ; 1/3 * 63 = 21
  1775. ;
  1776. ; LOGIC:
  1777. ;
  1778. ; Get the red component
  1779. ; Get the green component
  1780. ; Get the blue component
  1781. ;
  1782. EGA_COL2RGB PROC NEAR
  1783. ;
  1784. ;-------Get the RED component (bit 5 and 2)
  1785. ;
  1786. ;-------Check bit 2
  1787. MOV RGB.R,0
  1788. TEST AL,100B ; "R" is on ?
  1789. JZ CHECK_BIT_5 ; No, check "r"
  1790. ADD RGB.R,TWO_THIRD ; Yes, add 2/3 RED
  1791. CHECK_BIT_5:
  1792. TEST AL,100000B ; "r" is on ?
  1793. JZ CHECK_BIT_1 ; No, check Green
  1794. ADD RGB.R,ONE_THIRD ; Yes, add 1/3 RED
  1795. ;
  1796. ;-------Get the GREEN component (bit 4 and 1)
  1797. ;
  1798. CHECK_BIT_1:
  1799. MOV RGB.G,0
  1800. TEST AL,10B ; "G" is on ?
  1801. JZ CHECK_BIT_4 ; No, check "g"
  1802. ADD RGB.G,TWO_THIRD ; Yes, add 2/3 GREEN
  1803. CHECK_BIT_4:
  1804. TEST AL,10000B ; "g" is on ?
  1805. JZ CHECK_BIT_0 ; No, check for Blue
  1806. ADD RGB.G,ONE_THIRD ; Yes, add 1/3 GREEN
  1807. ;
  1808. ;-------Get the BLUE component (bit 3 and 0)
  1809. ;
  1810. CHECK_BIT_0:
  1811. MOV RGB.B,0
  1812. TEST AL,1B ; "B" is on ?
  1813. JZ CHECK_BIT_3 ; No, check "b"
  1814. ADD RGB.B,TWO_THIRD ; Yes, add 2/3 BLUE
  1815. CHECK_BIT_3:
  1816. TEST AL,1000B ; "b" is on ?
  1817. JZ EGA_COL2RGB_RETURN ; No, return
  1818. ADD RGB.B,ONE_THIRD ; Yes, add 1/3 BLUE
  1819. EGA_COL2RGB_RETURN:
  1820. RET
  1821. EGA_COL2RGB ENDP
  1822. PAGE
  1823. ;===============================================================================
  1824. ;
  1825. ; RGB2INT : MAP RED GREEN BLUE VALUES TO AN INTENSITY.
  1826. ;
  1827. ;-------------------------------------------------------------------------------
  1828. ;
  1829. ; INPUT: RGB.R = A RED value (0-63)
  1830. ; RGB.G = A GREEN value (0-63)
  1831. ; RGB.B = A BLUE value (0-63)
  1832. ; DARKADJUST_VALUE= THE DARKNESS VALUE (In shared data area).
  1833. ; SWITCHES = Command line switches
  1834. ;
  1835. ; OUTPUT: AL = THE INTENSITY (0-63) NOTE: 0 = BLACK
  1836. ; 63 = BRIGHT WHITE
  1837. ;
  1838. ; WARNING: AH IS LOST
  1839. ;
  1840. ;-------------------------------------------------------------------------------
  1841. ;
  1842. ; DESCRIPTION: When the RGB values for a pixel are at their maximum
  1843. ; value, what we obtain is a bright white pixel on the screen; this is
  1844. ; the brightest color achievable and therefore, its intensity is 63.
  1845. ;
  1846. ; When no color gun is firing on the display: RGB values are 0,0,0 this
  1847. ; is no color at all and therefore maps to intensity 0.
  1848. ;
  1849. ; For intermediate colors, experimentation has shown that the eye will
  1850. ; see blue as darker than red and red as darker than green.
  1851. ;
  1852. ; On a grey rainbow from 0 - 10 where 0 is black and 10 is white:
  1853. ;
  1854. ; Blue corresponds to a grey of intensity 1
  1855. ; Red corresponds to a grey of intensity 3
  1856. ; Green corresponds to a grey of intensity 6
  1857. ;
  1858. ; Therefore, if we mix all 3 colors we obtain a grey of
  1859. ; intensity 1 + 3 + 6 = 10 (i.e.,white).
  1860. ;
  1861. ;
  1862. ; LOGIC:
  1863. ;
  1864. ; Calculate the intensity
  1865. ;
  1866. ; AL = (.6 * G) + (.3 * R) + (.1 * B)
  1867. ;
  1868. ; Adjust Darkness
  1869. ;
  1870. ; AL = AL + DARKADJUST_VALUE
  1871. ;
  1872. RGB2INT PROC NEAR
  1873. PUSH BX
  1874. PUSH CX
  1875. PUSH DX
  1876. XOR AX,AX ; AL := Current component intensity
  1877. XOR BX,BX ; BX is used for calculations
  1878. XOR DX,DX ; DL := Running sum for grey intensity
  1879. ;-------Process /R (Reverse black and white)
  1880. .IF <BIT DS:[BP].SWITCHES Z REVERSE_SW> ; IF reverse is OFF
  1881. .THEN ; THEN REVERSE BLACK AND WHITE:
  1882. ;-------Test if the color is BLACK
  1883. .IF <RGB.R EQ BLACK_INT> AND ; If black
  1884. .IF <RGB.G EQ BLACK_INT> AND ;
  1885. .IF <RGB.B EQ BLACK_INT> ;
  1886. .THEN ; then, replace it with white
  1887. MOV AL,WHITE_INT
  1888. JMP SHORT RGB2INT_END
  1889. .ELSEIF <RGB.R EQ WHITE_INT> AND ; else if, high-intensity white
  1890. .IF <RGB.G EQ WHITE_INT> AND ;
  1891. .IF <RGB.B EQ WHITE_INT> ;
  1892. .THEN ; then, replace it with black
  1893. MOV AL,BLACK_INT
  1894. JMP SHORT RGB2INT_END
  1895. .ELSEIF <RGB.R EQ TWO_THIRD> AND ; else if, white
  1896. .IF <RGB.G EQ TWO_THIRD> AND ;
  1897. .IF <RGB.B EQ TWO_THIRD> ;
  1898. .THEN ; then, replace it with black
  1899. MOV AL,BLACK_INT
  1900. JMP SHORT RGB2INT_END
  1901. .ENDIF
  1902. .ENDIF
  1903. ;-------Calculate Green component
  1904. MOV AL,RGB.G ; AL := Green component
  1905. MOV BH,6 ;
  1906. MUL BH ; AX := Green * 6
  1907. MOV BH,10 ;
  1908. DIV BH ; AL := (GREEN * 6) / 10
  1909. ADD DL,AL ; DL := Cumulative intensity
  1910. MOV CH,AH ; CH := Cumulative remainder
  1911. ;-------Calculate Red component
  1912. MOV AL,RGB.R ; AL := Red component
  1913. MOV BH,3 ;
  1914. MUL BH ; AX := Red * 3
  1915. MOV BH,10 ;
  1916. DIV BH ; AL := (RED * 3) / 10
  1917. ADD DL,AL ; DL := Cumulative intensity
  1918. ADD CH,AH ; CH := Cumulative remainder
  1919. ;-------Calculate Blue component
  1920. MOV AL,RGB.B ; AX := Blue component
  1921. XOR AH,AH ;
  1922. DIV BH ; AL := BLUE / 10
  1923. ADD DL,AL ; DL := Cumulative intensity
  1924. ADD CH,AH ; CH := Cumulative remainder
  1925. ;-------Adjust intensity with cumulative remainder
  1926. XOR AX,AX
  1927. MOV AL,CH ; AX := Cumulative remainder
  1928. MOV BH,10 ; BH := 10
  1929. DIV BH ; AL := Total remainder / 10
  1930. ADD DL,AL ; DL := Cumulative intensity
  1931. .IF <AH GT 4> ; If remainder > 4
  1932. .THEN ; Then, add 1
  1933. INC DL ; to the intensity
  1934. .ENDIF
  1935. ;-------Adjust darkness
  1936. ADD DL,DS:[BP].DARKADJUST_VALUE
  1937. ;-------Return result
  1938. MOV AL,DL ; AL := sum of R,G,B intensities
  1939. RGB2INT_END:
  1940. POP DX
  1941. POP CX
  1942. POP BX
  1943. RET
  1944. RGB2INT ENDP
  1945. PAGE
  1946. ;==============================================================================
  1947. ;
  1948. ; RGB2BAND: MAP RED GREEN BLUE VALUES TO A "SELECT COLOR BAND" MASK FOR
  1949. ; THE COLOR PRINTER.
  1950. ;
  1951. ;------------------------------------------------------------------------------
  1952. ;
  1953. ; INPUT: RGB.R = A RED value (0-63)
  1954. ; RGB.G = A GREEN value (0-63)
  1955. ; RGB.B = A BLUE value (0-63)
  1956. ; BP = Offset of the Shared Data Area.
  1957. ;
  1958. ; OUTPUT: AL = The Band Mask, one byte where:
  1959. ;
  1960. ; bit 0 = Color Band 1 is needed
  1961. ; bit 1 = Color Band 2 is needed
  1962. ; bit 2 = Color Band 3 is needed
  1963. ; bit 3 = Color Band 4 is needed
  1964. ;
  1965. ;
  1966. ; CALLED BY: SET_CGA_XLT_TAB
  1967. ; SET_EGA_XLT_TAB
  1968. ; SET_ROUNDUP_XLT_TAB
  1969. ; SET_MODE_13H_XLT_TAB
  1970. ; SET_MODE_F_XLT_TAB
  1971. ;
  1972. ;------------------------------------------------------------------------------
  1973. ;
  1974. ; NOTES: The RGB values in input describe a color from the screen.
  1975. ; Up to 256K different colors can be described with these RGB values.
  1976. ;
  1977. ; On the color printer, the print ribbon is composed of 4 color bands,
  1978. ; each of a different color. By overlapping these 4 bands when
  1979. ; printing, more colors can be obtained. However, the number of colors
  1980. ; that can be achieved by overlapping print bands is very limited (4 or
  1981. ; 8 colors).
  1982. ;
  1983. ; THIS MODULE SELECT THE PRINTER COLOR THAT IS THE CLOSEST TO THE
  1984. ; DESIRED SCREEN COLOR.
  1985. ;
  1986. ; The Band Mask specifies which color bands have to be overlapped to
  1987. ; obtain a color on the printer.
  1988. ;
  1989. ;
  1990. ; DESCRIPTION: Go through the list of printer colors in the SHARED DATA
  1991. ; AREA, for each of these colors, compare its RGB values with those in
  1992. ; input.
  1993. ; Get the BAND_MASK of the closest printer color.
  1994. ;
  1995. ; LOGIC:
  1996. ;
  1997. ; Locate the printer colors info structure in the shared data area:
  1998. ; COLORPRINT_PTR := BP + COLORPRINT_PTR
  1999. ;
  2000. ; Get the number of printer colors from the COLORPRINT info in the Shared
  2001. ; data area:
  2002. ; Number of colors := COLORPRINT_PTR.NUM_PRT_COLOR
  2003. ;
  2004. ; CURRENT_COLOR_PTR : First record in the COLORPRINT info structure
  2005. ; BEST_CHOICE := CURRENT_RECORD_PTR.BAND_MASK
  2006. ; MIN_DIFF := Maximum positive value
  2007. ;
  2008. ; FOR each printer color:
  2009. ; CUR_DIFF := 0
  2010. ; (* Calculate the geometric distance between the RGB values from the *)
  2011. ; (* input and those of the printer color. *)
  2012. ; Red difference := (R - CURRENT_COLOR_PTR.RED)
  2013. ; Red difference := Red difference * Red difference
  2014. ; CUR_DIFF := CUR_DIFF + Red difference
  2015. ;
  2016. ; Green difference := (G - CURRENT_COLOR_PTR.GREEN)
  2017. ; Green difference := Green difference * Green difference
  2018. ; CUR_DIFF := CUR_DIFF + Green difference
  2019. ;
  2020. ; Blue difference := (B - CURRENT_COLOR_PTR.BLUE)
  2021. ; Blue difference := Blue difference * Blue difference
  2022. ; CUR_DIFF := CUR_DIFF + Blue difference
  2023. ;
  2024. ; IF CUR_DIFF < MIN_DIFF
  2025. ; THEN BEGIN
  2026. ; MIN_DIFF := CUR_DIFF
  2027. ; BEST_CHOICE := printer color.BAND_MASK
  2028. ; END
  2029. ;
  2030. ; CURRENT_COLOR_PTR := Offset of next color
  2031. ; END (For each printer color)
  2032. ;
  2033. ; Return BEST_CHOICE
  2034. ;
  2035. ;
  2036. RGB2BAND PROC NEAR
  2037. PUSH AX
  2038. PUSH BX
  2039. PUSH CX
  2040. PUSH DX
  2041. ;-------Process /R (Reverse black and white)
  2042. .IF <BIT DS:[BP].SWITCHES Z REVERSE_SW> ; IF reverse is OFF
  2043. .THEN ; THEN REVERSE BLACK AND WHITE:
  2044. ;------------------------------------------------------------------------------
  2045. ;
  2046. ; REVERSE BLACK AND WHITE:
  2047. ;
  2048. ;------------------------------------------------------------------------------
  2049. ;-------Test if the color is BLACK
  2050. .IF <RGB.R EQ BLACK_INT> AND ; If black
  2051. .IF <RGB.G EQ BLACK_INT> AND ;
  2052. .IF <RGB.B EQ BLACK_INT> ;
  2053. .THEN ; then, replace it with the
  2054. MOV BEST_CHOICE,0 ; band mask for white
  2055. JMP RGB2BAND_END ; return this band mask
  2056. .ELSEIF <RGB.R EQ WHITE_INT> AND ; else if, high-intensity white
  2057. .IF <RGB.G EQ WHITE_INT> AND ;
  2058. .IF <RGB.B EQ WHITE_INT> ;
  2059. .THEN ; then, replace it with the
  2060. MOV RGB.R,BLACK_INT ; RGB values of black
  2061. MOV RGB.G,BLACK_INT
  2062. MOV RGB.B,BLACK_INT
  2063. .ELSEIF <RGB.R EQ TWO_THIRD> AND ; else if, white
  2064. .IF <RGB.G EQ TWO_THIRD> AND ;
  2065. .IF <RGB.B EQ TWO_THIRD> ;
  2066. .THEN ; then, replace it with the
  2067. MOV RGB.R,BLACK_INT ; RGB values of black
  2068. MOV RGB.G,BLACK_INT
  2069. MOV RGB.B,BLACK_INT
  2070. .ENDIF
  2071. .ENDIF
  2072. ;------------------------------------------------------------------------------
  2073. ;
  2074. ; CALCULATE THE GEOMETRIC DISTANCE BETWEEN THE COLORS OF THE PIXEL AND THOSE OF
  2075. ; THE PRINTER:
  2076. ;
  2077. ;------------------------------------------------------------------------------
  2078. MOV BX,DS:[BP].COLORPRINT_PTR ; BX := OFFSET of COLORPRINT
  2079. ADD BX,BP
  2080. MOV MIN_DIFF,7FFFh ; No match yet, minimum diff.
  2081. ; is maximum POSITIVE value.
  2082. XOR CX,CX
  2083. MOV CL,DS:[BP].NUM_PRT_COLOR ; CX := Number of print colors
  2084. INSPECT_1_PRINT_COLOR:
  2085. MOV CUR_DIFF,0 ; Current difference := 0
  2086. ;------------------------------------------------------------------------------
  2087. ; Calculate the Red difference:
  2088. ;------------------------------------------------------------------------------
  2089. MOV AL,RGB.R
  2090. SUB AL,[BX].RED
  2091. ;-------Elevate at the power of two
  2092. MOV DL,AL ; DX := Red difference
  2093. IMUL DL ; AX := Red diff. square
  2094. ADD CUR_DIFF,AX ; CURR_DIF + Red diff.
  2095. ;------------------------------------------------------------------------------
  2096. ; Calculate the Green difference:
  2097. ;------------------------------------------------------------------------------
  2098. MOV AL,RGB.G
  2099. SUB AL,[BX].GREEN
  2100. ;-------Elevate at the power of two
  2101. MOV DL,AL ; DX := Red difference
  2102. IMUL DL ; AX := Red diff. square
  2103. ADD CUR_DIFF,AX ; CURR_DIF + Green diff.
  2104. ;------------------------------------------------------------------------------
  2105. ; Calculate the Blue difference:
  2106. ;------------------------------------------------------------------------------
  2107. MOV AL,RGB.B
  2108. SUB AL,[BX].BLUE
  2109. ;-------Elevate at the power of two
  2110. MOV DL,AL ; DX := Red difference
  2111. IMUL DL ; AX := Red diff. square
  2112. ADD CUR_DIFF,AX ; CURR_DIF + Blue diff.
  2113. ;------------------------------------------------------------------------------
  2114. ; Check how close is this print color to the screen color:
  2115. ;------------------------------------------------------------------------------
  2116. MOV AX,CUR_DIFF ; If this color is better than what we
  2117. .IF <AX L MIN_DIFF> ; had before.
  2118. .THEN ;
  2119. MOV MIN_DIFF,AX ; then, new minimum distance;
  2120. MOV AL,[BX].SELECT_MASK ; get its band mask.
  2121. MOV BEST_CHOICE,AL ;
  2122. .ENDIF ;
  2123. ;------------------------------------------------------------------------------
  2124. ; Get offset of next COLORPRINT info record:
  2125. ;------------------------------------------------------------------------------
  2126. ADD BX,SIZE COLORPRINT_STR
  2127. LOOP INSPECT_1_PRINT_COLOR
  2128. ;------------------------------------------------------------------------------
  2129. ; BEST_CHOICE contains the print color with the closest RGB values
  2130. ;------------------------------------------------------------------------------
  2131. RGB2BAND_END:
  2132. POP DX
  2133. POP CX
  2134. POP BX
  2135. POP AX
  2136. MOV AL,BEST_CHOICE
  2137. RET
  2138. BEST_CHOICE DB ?
  2139. MIN_DIFF DW ?
  2140. CUR_DIFF DW ?
  2141. RGB2BAND ENDP
  2142. CODE ENDS
  2143. END
  2144.