home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s4.arc / WRITECXY.MOD < prev    next >
Text File  |  1988-01-08  |  9KB  |  123 lines

  1. (*----------------------------------------------------------------------*)
  2. (*   WriteCXY --- Write character to screen  at specified row/column    *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE WriteCXY( C: CHAR; X: INTEGER; Y: INTEGER; Color: INTEGER );
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure:  WriteCXY                                             *)
  10. (*                                                                      *)
  11. (*     Purpose:    Writes a character at specified row and column       *)
  12. (*                 position on screen.                                  *)
  13. (*                                                                      *)
  14. (*     Calling Sequence:                                                *)
  15. (*                                                                      *)
  16. (*        WriteCXY( C: CHAR; X: INTEGER; Y: INTEGER; Color: INTEGER );  *)
  17. (*                                                                      *)
  18. (*           C      --- Character to be written                         *)
  19. (*           X      --- Column position to write character              *)
  20. (*           Y      --- Column position to write character              *)
  21. (*           Color  --- Color in which to write character               *)
  22. (*                                                                      *)
  23. (*----------------------------------------------------------------------*)
  24.  
  25. VAR
  26.    Save_WTS : BOOLEAN;
  27.  
  28. BEGIN (* WriteCXY *)
  29.                                    (* Use BIOS for DoubleDos *)
  30.    Save_WTS := Write_Screen_Memory;
  31.  
  32.    IF ( MultiTasker = DoubleDos ) OR
  33.       ( MultiTasker = TopView   ) THEN
  34.          Write_Screen_Memory := FALSE;
  35.  
  36. INLINE(
  37.   $1E                              {         PUSH  DS                             ;Save DS}
  38.                                    {;}
  39.                                    {;  Check if we're going to use BIOS}
  40.                                    {;}
  41.   /$F6/$06/>WRITE_SCREEN_MEMORY/$01{         TEST  BYTE [<Write_Screen_Memory],1  ;See if we're writing to screen memory}
  42.   /$74/$43                         {         JZ    BIOS                           ;No -- skip to BIOS code}
  43.                                    {;}
  44.                                    {;  Set up for direct screen write.}
  45.                                    {;  Get row position and column positions, and offset in screen buffer.}
  46.                                    {;}
  47.   /$C4/$3E/>DESQVIEW_SCREEN        {         LES   DI,[>DesqView_Screen]          ;Get base address of screen}
  48.   /$8B/$4E/<Y                      {         MOV   CX,[BP+<Y]                     ;CX = Row}
  49.   /$49                             {         DEC   CX                             ;Row to 0..Max_Screen_Line-1 range}
  50.   /$A1/>MAX_SCREEN_COL             {         MOV   AX,[>Max_Screen_Col]           ;Physical screen width}
  51.   /$F7/$E1                         {         MUL   CX                             ;Row * Max_Screen_Col}
  52.   /$8B/$5E/<X                      {         MOV   BX,[BP+<X]                     ;BX = Column}
  53.   /$4B                             {         DEC   BX                             ;Col to 0..Max_Screen_Col-1 range}
  54.   /$01/$D8                         {         ADD   AX,BX                          ;AX = (Row * Max_Screen_Col) + Col}
  55.   /$D1/$E0                         {         SHL   AX,1                           ;Account for attribute bytes}
  56.   /$89/$FB                         {         MOV   BX,DI                          ;Get base offset of screen}
  57.   /$01/$C3                         {         ADD   BX,AX                          ;Add computed offset}
  58.   /$89/$DF                         {         MOV   DI,BX                          ;Move result into DI}
  59.   /$8A/$5E/<C                      {         MOV   BL,[BP+<C]                     ;BL = character}
  60.   /$8A/$7E/<COLOR                  {         MOV   BH,[BP+<Color]                 ;BH = Attribute}
  61.   /$F6/$06/>WAIT_FOR_RETRACE/$01   {         TEST  BYTE [<Wait_For_Retrace],1     ;Check retrace wait flag}
  62.   /$74/$15                         {         JZ    Mono                           ; use "Mono" routine}
  63.                                    {;}
  64.                                    {;  Color routine (used only when Wait_For_Retrace is True) **}
  65.                                    {;}
  66.   /$BA/>CRT_STATUS                 {         MOV   DX,>CRT_Status                 ;Point DX to CGA status port}
  67.                                    {;}
  68.   /$EC                             {WaitNoH: IN    AL,DX                          ;Get 6845 status}
  69.   /$A8/$01                         {         TEST  AL,1                           ;Wait for horizontal}
  70.   /$75/$FB                         {         JNZ   WaitNoH                        ; retrace to finish}
  71.                                    {;}
  72.   /$FA                             {         CLI                                  ;Turn off interrupts}
  73.   /$EC                             {WaitH:   IN    AL,DX                          ;Get 6845 status again}
  74.   /$A8/$01                         {         TEST  AL,1                           ;Wait for horizontal retrace}
  75.   /$74/$FB                         {         JZ    WaitH                          ; to start}
  76.                                    {;}
  77.   /$89/$D8                         {Store:   MOV   AX,BX                          ;Restore attribute}
  78.   /$AB                             {         STOSW                                ; and then to screen}
  79.   /$FB                             {         STI                                  ;Allow interrupts}
  80.   /$E9/$25/$00                     {         JMP   Exit                           ;Done}
  81.                                    {;}
  82.                                    {;  Mono routine (used whenever Wait_For_Retrace is False) **}
  83.                                    {;}
  84.   /$89/$D8                         {Mono:    MOV   AX,BX                          ;Get character + attribute}
  85.   /$AB                             {         STOSW                                ;Move video word into place}
  86.   /$E9/$1F/$00                     {         JMP   Exit                           ;Done}
  87.                                    {;}
  88.                                    {;  Use BIOS to display string (if Write_Screen is False) **}
  89.                                    {;}
  90.   /$B4/$02                         {Bios:    MOV   AH,2                           ;BIOS positioning}
  91.   /$B7/$00                         {         MOV   BH,0                           ;Text page 0}
  92.   /$8A/$76/<Y                      {         MOV   DH,[BP+<Y]                     ;Y}
  93.   /$FE/$CE                         {         DEC   DH                             ;Y - 1}
  94.   /$8A/$56/<X                      {         MOV   DL,[BP+<X]                     ;X}
  95.   /$FE/$CA                         {         DEC   DL                             ;X - 1}
  96.   /$CD/$10                         {         INT   $10                            ;Call BIOS to position cursor}
  97.   /$B4/$09                         {         MOV   AH,9                           ;BIOS display character}
  98.   /$8A/$46/<C                      {         MOV   AL,[BP+<C]                     ;Character to display}
  99.   /$B7/$00                         {         MOV   BH,0                           ;Text page 0}
  100.   /$8A/$5E/<COLOR                  {         MOV   BL,[BP+<Color]                 ;Color}
  101.   /$B9/$01/$00                     {         MOV   CX,1                           ;One character}
  102.   /$CD/$10                         {         INT   $10                            ;Call BIOS to display character}
  103.                                    {;}
  104.   /$1F                             {Exit:    POP   DS                             ;Restore DS}
  105. );
  106.                                    (* Return BIOS write to previous state *)
  107.  
  108.    Write_Screen_Memory := Save_WTS;
  109.  
  110.    IF ( MultiTasker = TopView ) THEN
  111.       IF Write_Screen_Memory THEN
  112.          Sync_Screen( PRED( ( PRED( Y ) * Max_Screen_Col + X ) SHL 1 ) , 1 );
  113. {
  114.    IF Save_WTS THEN
  115.       IF ( MultiTasker = DoubleDos ) OR
  116.          ( MultiTasker = TopView   ) THEN
  117.          Write_Screen_Memory := Save_WTS;
  118. }
  119.                                    (* Synchronize screen for TopView *)
  120. {
  121. }
  122. END   (* WriteCXY *);
  123.