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 / STEXT.INC < prev    next >
Text File  |  1992-12-27  |  8KB  |  344 lines

  1. ;STEXT.INC - Copyright 1991,1992 Knight Software
  2. ;    History:
  3. ;       17 May 1991 - first release
  4. ;       08 Feb 1992 - fixed text position off by one
  5. ;       22 Nov 1992 - adapted for protected mode operation
  6. ;
  7. ;------------------------------------------------------
  8. ;Update internal text registers with system 8x8 font info
  9. ;Assume: DS = data segment
  10. ;Enter:  Nothing
  11. ;Return: Initializes text information 
  12. GetTextInfo PROC NEAR
  13.     PUSH    ES
  14.     PUSH    BP
  15.     PUSH    CX
  16.     PUSH    BX
  17.     PUSH    AX
  18.     MOV    DS:[FontSizeX],8
  19.     MOV    DS:[FontSizeY],8
  20.     MOV    DS:[CharSizeX],8
  21.     MOV    DS:[CharSizeY],8
  22.     MOV    DS:[FontMultX],1
  23.     MOV    DS:[FontMultY],1
  24.     POP    AX
  25.     POP    BX
  26.     POP    CX
  27.     POP    BP
  28.     POP    ES
  29.     RET
  30. GetTextInfo ENDP
  31.  
  32. ;-----------------------------------------------------------
  33. ;Read a character from font table
  34. ;Assume: DS = data segment
  35. ;Enter:  AL = Char to read
  36. ;Return: Character map is in TempChar
  37.  
  38. ReadChar PROC NEAR
  39.     PUSH    ES
  40.     PUSH    SI
  41.     PUSH    DI
  42.     PUSH    DX
  43.     PUSH    CX
  44.     PUSH    BX
  45.     PUSH    AX
  46.  
  47.     CALL    GetFontChar   ;point ES:SI at font bitmap for char
  48.     MOV    AX,ES:[SI]
  49.     MOV    BX,ES:[SI+2]  ;get character font from bios rom
  50.     MOV    CX,ES:[SI+4]
  51.     MOV    DX,ES:[SI+6]
  52.  
  53.     LEA    DI,TempChar    ;point to temp char array
  54.     CMP    DS:[FontDir],1
  55.     JZ    @Rotate1
  56.     CMP    DS:[FontDir],2
  57.     JZ    @Rotate2
  58.     CMP    DS:[FontDir],3
  59.     JZ    @Rotate3
  60.     MOV    DS:[DI],AX
  61.     MOV    DS:[DI+2],BX    ;copy character to temp vars 
  62.     MOV    DS:[DI+4],CX    ;as is since no rotate needed
  63.     MOV    DS:[DI+6],DX
  64.     JMP    @RotateDone
  65.  
  66. @Rotate1:
  67.     PUSH    BP    ;rotate the character to the
  68.     MOV    BP,8    ;right 90 degrees
  69. @Cloop1:
  70.     SHL    DH,1    ;if rotate required then rotate it
  71.     RCL    SI,1    ;as we stuff it to the local stack
  72.     SHL    DL,1
  73.     RCL    SI,1
  74.     SHL    CH,1
  75.     RCL    SI,1
  76.     SHL    CL,1
  77.     RCL    SI,1
  78.     SHL    BH,1
  79.     RCL    SI,1
  80.     SHL    BL,1
  81.     RCL    SI,1
  82.     SHL    AH,1
  83.     RCL    SI,1
  84.     SHL    AL,1
  85.     RCL    SI,1
  86.     MOV    DS:[DI],SI    ;copy char to temp vars
  87.     INC    DI
  88.     DEC    BP
  89.     JNZ    @Cloop1
  90.     POP    BP
  91.     JMP    @RotateDone
  92.  
  93. @Rotate2:
  94.     PUSH    BP    ;rotate the character to the 
  95.     MOV    BP,8    ;left 90 degrees
  96. @Cloop2:
  97.     SHR     AL,1    ;if rotate required then rotate it
  98.     RCL     SI,1    ;as we stuff it to the local stack
  99.     SHR     AH,1
  100.     RCL     SI,1
  101.     SHR     BL,1
  102.     RCL     SI,1
  103.     SHR     BH,1
  104.     RCL     SI,1
  105.     SHR     CL,1
  106.     RCL     SI,1    ;rotate in the other direction
  107.     SHR     CH,1    ;@@@ this probably does not work,  @@@
  108.     RCL     SI,1    ;@@@ I haven't checked it yet      @@@
  109.     SHR     DL,1
  110.     RCL     SI,1
  111.     SHR     DH,1
  112.     RCL     SI,1
  113.     MOV     DS:[DI],SI    ;copy char to local stack
  114.     INC     DI
  115.     DEC     BP
  116.     JNZ     @Cloop2
  117.     POP     BP
  118.     JMP    @RotateDone
  119.  
  120. @Rotate3:
  121.     XCHG    DH,AL    ;flip the character upside down
  122.     XCHG    DL,AH
  123.     XCHG    CH,BL
  124.     XCHG    CL,BH
  125.     MOV    DS:[DI],AX
  126.     MOV    DS:[DI+2],BX    ;copy character 
  127.     MOV    DS:[DI+4],CX    ;to local stack array
  128.     MOV    DS:[DI+6],DX
  129.     JMP    @RotateDone
  130.  
  131. @RotateDone:
  132.         POP    AX
  133.     POP    BX
  134.     POP    CX
  135.     POP    DX
  136.     POP    DI
  137.     POP    SI
  138.     POP    ES
  139.     RET
  140. ReadChar ENDP
  141.  
  142. ;----------------------------------------------------------
  143. ;Draw a character on the screen at given location
  144. ;Assume: DS = data segment
  145. ;Entry:  AL = Character to draw
  146. ;        BX = X location
  147. ;        DX = Y location
  148. ;Return: N/A
  149.  
  150. DrawChar PROC NEAR
  151.     PUSH    ES
  152.     PUSH    SI
  153.     PUSH    DI
  154.     PUSH    DX
  155.     PUSH    CX
  156.     PUSH    BX
  157.     PUSH    AX
  158.     MOV    DS:[PixelX1],BX    ;store temp x location
  159.     MOV    DS:[PixelY1],DX    ;store temp y location
  160.     CALL    ReadChar    ;Read the character map 
  161.     MOV    ES,DS:[VideoSegment] ;point ES at video segment
  162.     MOV    DH,0
  163.     LEA    SI,TempChar
  164. @CharLp:
  165.     MOV    DL,DS:[FontMultY]
  166. @YmultLp:
  167.     MOV    AX,DS:[PixelX1]
  168.     MOV    DS:[PixelX],AX
  169.     MOV    AL,DH
  170.     MUL    BYTE PTR DS:[FontMultY]
  171.     ADD    AL,DL
  172.     ADC    AH,0
  173.     DEC    AX
  174.     ADD    AX,DS:[PixelY1]
  175.     MOV    DS:[PixelY],AX
  176.     CALL    GetPixelAddress
  177.     MOV    DI,DS:[PixelAddress]
  178.     MOV    CH,DS:[CharSizeX]
  179.     MOV    BH,DS:[SI]
  180.     MOV    AL,DS:[DrawForeColor] ;text fore uses drawcolor
  181.     MOV    AH,DS:[TextBackColor] ;backcolor is its own color
  182. @PixLoop:
  183.     MOV    CL,DS:[FontMultX]
  184. @Nxtpix:
  185.     TEST    BH,80H
  186.     CALL    WORD PTR DS:[TextPixelProc]
  187.     INC    WORD PTR DS:[PixelX]
  188.     INC    DI
  189.     JNZ    @AdrOK
  190.     CALL    GetPixelAddress
  191.     MOV    DI,DS:[PixelAddress]
  192. @AdrOK:
  193.     DEC    CL
  194.     JNZ    @Nxtpix
  195.     SHL    BH,1
  196.     DEC    CH
  197.     JNZ    @PixLoop
  198.  
  199.     DEC    DL
  200.     JNZ    @YmultLp
  201.     INC    SI
  202.     INC    DH
  203.     CMP    DH,DS:[CharSizeY]
  204.     JNZ    @CharLp
  205.  
  206.     POP    AX
  207.     POP    BX
  208.     POP    CX
  209.     POP    DX
  210.     POP    DI
  211.     POP    SI
  212.     POP    ES
  213.     RET
  214. DrawChar ENDP
  215.  
  216. ;-----------------------------------------------------------
  217. ;Draw text on the screen
  218. ;Assume: DS = data segment
  219. ;Entry:  ES:BX = Pointer to string to draw
  220. ;           CX = String size in charcters
  221. ;Return: N/A 
  222.  
  223. DrawText PROC NEAR
  224.     PUSH    DI
  225.     PUSH    AX
  226.     PUSH    BX
  227.     PUSH    CX
  228.     PUSH    DX
  229.     MOV    DI,BX    
  230.     MOV    BX,DS:[CPX]    ;get current pointer
  231.     MOV    DX,DS:[CPY]
  232. @DrawTextLp:
  233.     MOV    AL,ES:[DI]  ;Get a char to draw
  234.     CALL    DrawChar    ;Draw the character
  235.     INC    DI        ;Point to next char in string
  236.  
  237.     MOV    AH,0           ;Preset AH to zero
  238.     CMP    DS:[FontDir],1 ;Adjust CP based on 
  239.     JZ    @DrawText1     ;Text Direction selected
  240.     CMP    DS:[FontDir],2
  241.     JZ    @DrawText2
  242.     CMP    DS:[FontDir],3
  243.     JZ    @DrawText3
  244.     JMP    @DrawText0
  245.  
  246. @DrawText0:
  247.     MOV    AL,DS:[FontSizeX] ;PixelX+FontSize - 0 degrees
  248.     ADD    BX,AX
  249.     JMP    @DrawTextDone
  250.  
  251. @DrawText1:
  252.     MOV    AL,DS:[FontSizeY] ;PixelY+FontSize - 90 degrees
  253.     ADD    DX,AX
  254.     JMP    @DrawTextDone
  255.  
  256. @DrawText2:
  257.     MOV    AL,DS:[FontSizeY] ;PixelY+FontSize - 180 degrees
  258.     ADD    DX,AX
  259.     JMP    @DrawTextDone
  260.  
  261. @DrawText3:
  262.     MOV    AL,DS:[FontSizeX] ;PixelX+FontSize - 270 degrees
  263.     ADD    BX,AX
  264.     JMP    @DrawTextDone
  265.  
  266. @DrawTextDone:
  267.         LOOP    @DrawTextLp ;loop til done
  268.     POP    DX
  269.     POP    CX
  270.     POP    BX
  271.     POP    AX
  272.     POP    DI
  273.     RET
  274. DrawText ENDP
  275.  
  276.  
  277.  
  278. ;-----------------------------------------------------------
  279. ;This will get the font char from the system font tables
  280. ;Warning: The font table resides in real mode memory, 
  281. ;*not* in protected mode memory, even if you are in protected 
  282. ;mode operation. To change the font table, you can load 
  283. ;a new font tsr at int $1f ahead of time. Alternately,
  284. ;if you are in real mode, you can just point the interrupt 
  285. ;at your own font table. If you are in protected mode, you
  286. ;must first allocate some real mode memory with GlobalDosAlloc
  287. ;then load the new font info to that area, finally, you must 
  288. ;call the DMPI service (0201H) to change the real mode int vector. 
  289. ;Assume: DS    = data segment
  290. ;Entry:  AL    = Character font to get
  291. ;Return: ES:SI = points to start of font bitmap 
  292.  
  293. GetFontChar Proc NEAR
  294.     XOR    AH,AH
  295.     MOV    SI,AX
  296.     SHL    SI,1
  297.     SHL    SI,1
  298.     SHL    SI,1
  299.     MOV    BX,word ptr DS:[ChrGen]
  300.     MOV    CX,word ptr DS:[ChrGen+2]   ;Get Table address
  301.     OR    CX,BX                ;from int 1f
  302.     JZ    @NoVect                ;if no vect found
  303.     MOV    ES,word ptr DS:[ChrGen+2]   ;use only system font
  304.     CMP    word ptr ES:[BX+1016],494DH ;check if this is
  305.     JNZ    @NotMyn                ;our font table
  306.     CMP    word ptr ES:[BX+1018],454BH
  307.     JZ    @GotMyn
  308. @NotMyn:
  309.     CMP    AL,80H             ;not our font, so use
  310.     JC    @GotLow             ;system font tables
  311. @GotMyn:
  312.     SUB    SI,0400H         ;it's our special font
  313.     ADD    SI,BX             ;table, so address it
  314.     RET                 ;as such
  315.  
  316. @NoVect:
  317.     CMP    AL,80H             ;if no ext font show 
  318.     JC    @GotLow             ;only a space char
  319.     MOV    BX,0100H         ;else map lower font
  320. @GotLow:
  321.     ADD    SI,0FA6EH         ;from bios font table
  322.     MOV    ES,DS:[SEGF000]
  323.     RET
  324. GetFontChar ENDP
  325.  
  326.  
  327. ;Note: Normally, the lower 128 chars are not redefinable.
  328. ;This can be a problem. The upper 128 chars are redefinable 
  329. ;by loading a new font table pointed at by int $1f. 
  330. ;This doesn't affect the lower 128 characters however. 
  331. ;Because of this, I adapted the font detection mechanism to 
  332. ;look for a special signature in the character position #255.
  333. ;if that character has the sequence $4D $69 $6B $65 in the 
  334. ;first four bytes, it is assumed that the lower 128 character
  335. ;fonts have been added to the end of the regular upper 128 
  336. ;character font table. I added it to the end so that it would 
  337. ;not confuse other software that is not aware of the extension.
  338. ;thus allowing it to use the upper font table even though the
  339. ;lower font table exists beyond the end of the upper font table.
  340. ;Huh? (You can unglaze your eyes now. <g>)
  341.  
  342. ;-----------------------------------------------------------
  343.  
  344.