home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bgi256-3.zip / SHARD.INC < prev    next >
Text File  |  1992-12-27  |  10KB  |  378 lines

  1. ;SHARD.INC - Copyright 1991,1992 Knight Software
  2. ; History:
  3. ;  17 May 1991 - first release
  4. ;  14 Jul 1991 - Corrected default line draw from MoveByte to ForeByte
  5. ;  20 Aug 1992 - fixed scan line length init problem 
  6. ;  22 Nov 1992 - Adapted for protected mode operation
  7. ;
  8. ;**********************************************************************
  9. ;Misc init stuff this is common VGA initialization code
  10. ;It sets up various variables and tables in the system
  11. ;Assume:  DS = data segment
  12. ;Entry:   Nothing
  13. ;Return:  (Stuff is initialized)
  14. ;Destroys Nothing
  15.  
  16. MiscInit PROC NEAR
  17.     PUSH    ES
  18.     PUSH    SI
  19.     PUSH    DI
  20.     PUSH    DX
  21.     PUSH    CX
  22.     PUSH    BX
  23.     PUSH    AX
  24.     PUSHF
  25.  
  26.     MOV    BX,0FFH            ;Init bank select reg
  27.     MOV    DS:[PixelSegment],BX
  28.  
  29.     MOV    AL,0
  30.     MOV    DS:[ModeXflag],0    ;clr modex flag
  31.     MOV    AL,DS:[ModeSelect]
  32.     AND    AX,7
  33.     LEA    BX,StatusPtrTable    ;copy mode status table
  34.     ADD    BX,AX
  35.     ADD    BX,AX
  36.     MOV    SI,DS:[BX]
  37.     MOV    CX,StatBlockSize
  38.     LEA    DI,StatBlock
  39.     PUSH    DS
  40.     POP    ES
  41.     REP    MOVSB
  42.  
  43.     MOV    BX,DS:[ScanLineLength]
  44.     OR    BX,BX            ;if scan line length not
  45.     JNZ    @MiscInitB        ;initialized, fix it up
  46.     MOV    BX,DS:[StatBlock.BytesPerScanLine]
  47.     MOV    DS:[ScanLineLength],BX
  48. @MiscInitB:
  49.     LEA    BX,MoveByte
  50.     MOV    DS:[FillPixelProc],BX    ;preset proc ptrs
  51.     MOV    DS:[BitMapPixelProc],BX
  52.     LEA    BX,ForeByte
  53.     MOV    DS:[LinePixelProc],BX
  54.     MOV    DS:[TextPixelProc],BX
  55.     MOV    AL,0
  56.     MOV    DS:[FillPixelWritemode],AL    ;preset mode selects
  57.     MOV    DS:[BitMapPixelWritemode],AL
  58.     MOV    AL,8
  59.     MOV    DS:[LinePixelWritemode],AL
  60.     MOV    DS:[TextPixelWritemode],AL
  61.  
  62.     MOV    AL,DS:[StatBlock.ctblf]    ;init colors
  63.     MOV    DS:[DrawForeColor],AL
  64.     MOV    DS:[FillForeColor],AL
  65.     MOV    AL,0
  66.     MOV    DS:[DrawBackColor],AL
  67.     MOV    DS:[PixelBackColor],AL
  68.     MOV    DS:[FillBackColor],AL
  69.     MOV    DS:[TextBackColor],AL
  70.     MOV    DS:[BitMapBackColor],AL
  71.  
  72.     CALL    GetTextInfo    ;Load text info from BIOS
  73.  
  74.     MOV    AX,1012H
  75.     MOV    BX,0        ;Set default palette table
  76.     MOV    CX,256
  77.     LEA    DX,PaletteTable
  78.     PUSH    DS
  79.     POP    ES             ;point ES:DI at pal table
  80.     CALL    SetPal
  81.  
  82.     POPF
  83.     POP    AX
  84.     POP    BX
  85.     POP    CX
  86.     POP    DX
  87.     POP    DI
  88.     POP    SI
  89.     POP    ES
  90.     RET
  91. MiscInit ENDP
  92.  
  93. ;**********************************************************************
  94. ;Create mode string from mode name and card name
  95. ;Assume: DS    = data segment
  96. ;Entry:  CL    = Mode number for name
  97. ;Return: ES:BX = pointer to mode string
  98. ;        NC = valid mode; C= bad mode number
  99. GetModeName PROC NEAR
  100.     PUSH    SI
  101.     PUSH    DI
  102.     PUSH    CX
  103.     PUSH    DX
  104.     LEA    DI,ModeNameBuffer
  105.     INC    DI         ;Point DI to target buffer
  106.     MOV    CH,0
  107.     MOV    DX,0             ;init count to zero
  108.  
  109.     PUSH    DS    ;return a pointer to a pascal string ES:BX
  110.     POP    ES    ;of the mode name for the mode passed in CX
  111.     CMP    BYTE PTR DS:[ModeErrorFlag],0
  112.     JZ    @GetModeName1
  113.     PUSH    CX
  114.     LEA    SI,ModeNameBad
  115.     MOV    CL,DS:[SI]        ;get length
  116.     ADD    DL,CL
  117.     INC    SI
  118.     REP    MOVSB
  119.     POP    CX
  120.  
  121. @GetModeName1:
  122.     LEA    SI,ModeNameError    ;Beyond mode number allowed?
  123.     CMP    CX,DS:[NumberModes]
  124.     JNC    @GetModeName2
  125.     LEA    SI,ModeName
  126.     MOV    AL,ModeNameSize     ;get table entry size
  127.     MUL    CL
  128.     ADD    SI,AX            ;index into table for name
  129.  
  130. @GetModeName2:
  131.     MOV    CL,DS:[SI]        ;get mode name length
  132.     INC    SI
  133.     ADD    DL,CL            ;save count
  134.     REP    MOVSB            ;copy mode name to buffer
  135.  
  136.     MOV    SI,DS:[CardNamePtr] ;get card name buffer address
  137.     MOV    CL,CS:[SI]        ;get length of card name
  138.     INC    SI            ; (card name is in code segment)
  139.     ADD    DL,CL            ;add to overall name length
  140.     CMP    DL,ModeNameMax      ;make sure mode name doesn't
  141.     JC    @GetModeName3        ;overflow buffer
  142.     MOV    DL,ModeNameMax
  143. @GetModeName3:
  144.     MOV    AL,CS:[SI]
  145.     INC    SI
  146.     MOV    ES:[DI],AL        ;add card name to mode name
  147.     INC    DI
  148.     LOOP    @GetModeName3
  149.     MOV    BYTE PTR ES:[DI],0  ;tag with a null
  150.     LEA    BX,ModeNameBuffer   ;return pointer to name string 
  151.     MOV    ES:[BX],DL        ;set length
  152.  
  153.     POP    DX
  154.     POP    CX
  155.     POP    DI
  156.     POP    SI
  157.     RET
  158. GetModeName ENDP
  159.  
  160.  
  161. ;---------------------------------------------------------------
  162. ;Default dummy card name (code segment placement)
  163.  
  164. DummyCard    DB 12
  165.         DB 'Unknown card',0
  166.  
  167.  
  168. ;**********************************************************************
  169. ;Take the pixel position specified by PixelX, PixelY and the
  170. ;scan line length specified by BytesPerScanLine and compute
  171. ;the long address into the display. Selects proper segment bank
  172. ;on the display and stuffs bank select into PixelSegment and 
  173. ;the Display Offset address into PixelAddress. Returns how many 
  174. ;bytes are left in the display segment from the specified address
  175. ;in PixelSegmentLength.
  176. ;Assume:  DS       = data segment
  177. ;Entry:   [PixelX] = scan line offset (see description above)
  178. ;         [PixelY] = scan line number 
  179. ;Return:  [PixelAddress] = (see description abive)
  180. ;Destroy: None
  181.  
  182. GetPixelAddress PROC NEAR
  183.     PUSH    AX
  184.     PUSH    DX
  185.     PUSH    SI
  186.     MOV    AX,DS:[ScanLineLength]   ;bytes per scan line
  187.     MOV    DX,DS:[PixelY]           ;PixelY
  188.     MUL    DX                    ;dx:ax=beginning of scan line
  189.     MOV    SI,AX
  190.     ADD    SI,DS:[PixelX]           ;si=address
  191.     ADC    DX,0                  ;dx=bank
  192.     CMP    DS:[PixelSegment],DX     ;set the bank select
  193.     JE    @DoneBankSelect
  194.     MOV    DS:[PixelSegment],DX
  195.     CALL    DS:[BankSelectProc]   ;call approprate bank sel code
  196. @DoneBankSelect:
  197.     MOV    DS:[PixelAddress],SI     ;save the pixel address
  198.     NOT    SI
  199.     INC    SI
  200.     JNZ    @BankSelectOK
  201.     DEC    SI        ;limit length to 65535
  202. @BankSelectOK:
  203.     MOV    DS:[PixelSegmentLength],SI  ;save the segment length
  204.     POP    SI
  205.     POP    DX
  206.     POP    AX
  207.     RET
  208. GetPixelAddress ENDP
  209.  
  210.  
  211. ;**********************************************************************
  212. ;Standard VGA only has 320x200 which fully fits in 64K bank.
  213. ;Thus no selection needs to be done here.
  214. ;Assume:  DS = Nothing
  215. ;Entry:   N/A
  216. ;Return:  N/A
  217. ;Destroy: None
  218. VGABankSelect PROC NEAR
  219.     RET
  220. VGABankSelect ENDP
  221.  
  222.  
  223. ;----------------------------------------------------------------------
  224. ;Select standard VGA320x200 mode operation
  225. ;Assume:  DS = data segment
  226. ;Entry:   N/A
  227. ;Return:  Correct display mode selected
  228. ;Destroy: AX
  229.  
  230. VGA320x200Init PROC NEAR
  231.     MOV    AX,0013H    ;select standard mode
  232.     INT    10H        ;call BIOS to set the mode
  233.     RET
  234. VGA320x200Init ENDP
  235.  
  236.  
  237. ;----------------------------------------------------------------------
  238. ;Set EGA Pal color register in AL
  239. ;Assume:  DS = data segment
  240. ;Entry:   AL = color index
  241. ;         BL = color number
  242. ;Return:  palette is updated
  243. ;Destroy: AX,BX
  244.  
  245. SetEGAPal PROC NEAR
  246.     PUSH    AX
  247.     PUSH    BX
  248.     MOV    BH,BL    ;set color palette
  249.     MOV    BL,AL
  250.     MOV    AX,1000H
  251.     INT    10H
  252.     POP    BX
  253.     POP    AX
  254.     RET
  255. SetEGAPal ENDP
  256.  
  257.  
  258. ;----------------------------------------------------------------------
  259. ;Set full EGA color palette
  260. ;Note: although the manual says that the overscan register is not
  261. ;set with this function, in reality, it is passed in the array
  262. ;(it appears to be passed as a zero value). BI's SetAllPalette
  263. ;works like this too (ie it passed the overscan value at the end
  264. ;of the palette array). Thus there are actually 17 bytes passed.
  265. ;Note that while the Get Default Palette function (see Query Color)
  266. ;requires a length byte in the start of the array, this function is 
  267. ;intended to be feed to the BIOS directly, so there is no length
  268. ;byte. It is assumed that the array size is already known by the 
  269. ;mode you are currently in. I only support full EGA palette here.
  270. ;Assume:  DS    = data segment
  271. ;Entry:   ES:BX = points to palette table data
  272. ;Return:  palette is updated
  273. ;Destroy: AX,BX,DX
  274.  
  275. SetFullEGAPal PROC NEAR
  276.     PUSH    ES
  277.     PUSH    DI
  278.     PUSH    CX
  279.     PUSH    BX
  280.     PUSH    AX
  281.  
  282.     LEA    DI,TempWork    ;copy the palette stuff
  283.     MOV    CX,17        ;to local real mode memory
  284. @EGAPalCopy:
  285.     MOV    AL,ES:[BX]
  286.     MOV    DS:[DI],AL
  287.     INC    DI
  288.     INC    BX
  289.     LOOP    @EGAPalCopy
  290.  
  291.     PUSH    DS
  292.     POP    ES
  293.     LEA    DX,TempWork
  294.     MOV    AX,1002H
  295.     CALL    SetPal
  296.  
  297.     POP    AX
  298.     POP    BX
  299.     POP    CX
  300.     POP    DI
  301.     POP    ES
  302.     RET
  303. SetFullEGAPal ENDP
  304.  
  305.  
  306. ;----------------------------------------------------------------------
  307. ;Set VGA Pal color register in AX
  308. ;Assume:  DS = data segment
  309. ;Entry:   AX = color index
  310. ;         BX = red
  311. ;         CX = green
  312. ;      DX = blue
  313. ;Return:  palette is updated
  314. ;Destroy: AX,BX,CX,DX
  315.  
  316. SetVGAPal PROC NEAR
  317.     PUSH    AX
  318.     PUSH    BX
  319.     PUSH    CX
  320.     PUSH    DX
  321.     MOV    CH,CL    ;set an individual DAC color register
  322.     MOV    CL,DL    ;BX=red, CX=green, DX=blue, AX=index
  323.     MOV    DH,BL    ;top two bits of AX = 10
  324.     MOV    DL,0
  325.     MOV    BX,AX
  326.     AND    BX,00FFH
  327.     MOV    AX,1010H
  328.     INT    10H
  329.     POP    DX
  330.     POP    CX
  331.     POP    BX
  332.     POP    AX
  333.     RET
  334. SetVGAPal ENDP
  335.  
  336.  
  337. ;----------------------------------------------------------------------
  338. ;process Pal set int $10 call via DPMI protected mode operation
  339. ;Assume:  DS = data segment
  340. ;Entry:   AX = command
  341. ;         BX = pal start index
  342. ;         CX = items to change (count)
  343. ;Return:  palette is updated
  344. ;Destroy: All
  345.  
  346. SetPal    PROC NEAR
  347.     CMP    DS:[CurOpMode],0      ;if CurOpMode is zero
  348.     JNZ    @PalProt           ;just do a real INT 10 call 
  349.  
  350.     INT    10H
  351.     RET
  352.  
  353. @PalProt:
  354.     MOV word ptr DS:[SimInt.RealAX],AX ;pass command number 
  355.     MOV word ptr DS:[SimInt.RealBX],BX
  356.     MOV word ptr DS:[SimInt.RealCX],CX
  357.     MOV word ptr DS:[SimInt.RealDX],DX
  358.     MOV AX,DS:[RealModeDS]
  359.     MOV DS:[SimInt.RealES],AX       ;pass the real mode segment
  360.     MOV DS:[SimInt.RealDS],AX
  361.     MOV word ptr DS:[SimInt.RealSS],0  ;let DPMI make it's own stack
  362.     MOV word ptr DS:[SimInt.RealSP],0
  363.     MOV word ptr DS:[SimInt.RealXX],0
  364.     MOV word ptr DS:[SimInt.RealXX+2],0
  365.     MOV AX,DS
  366.     MOV ES,AX
  367.     LEA DI,SimInt    ;go simulate the interrupt call
  368.     MOV AX,0300H
  369.     MOV BL,10H
  370.     MOV BH,0
  371.     MOV CX,0
  372.     INT 31H
  373.     RET
  374. SetPal    ENDP
  375.  
  376.  
  377. ;----------------------------------------------------------------------
  378.