home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-ASM_VI.ARJ / PROGASM.ZIP / PROG004.ASM < prev    next >
Assembly Source File  |  1988-05-15  |  6KB  |  146 lines

  1.  
  2. ;************************************************************************
  3. ;                                                                       *
  4. ; Select mode on EGA adapter by loading all control                     *
  5. ; registers.  Register are read from a table pointed to by              *
  6. ;                                                                       *
  7. ; Entry: [BP+4]-Pointer to the parameter table                          *
  8. ;               Parameter table should have the following format        *
  9. ;               1 byte  - 3BA for mono modes, 3DA for color modes       *
  10. ;               4 bytes - Sequencer values for register 1 - 4           *
  11. ;               25 bytes- CRT controller values                         *
  12. ;               9 bytes - Graphics controller values                    *
  13. ;               20 bytes- Attribute register values                     *
  14. ;                                                                       *
  15. ;************************************************************************
  16.  
  17.         PUBLIC  _Write_Register_Set
  18. _Write_Register_Set      PROC    NEAR
  19.         PUSH    BP                      ;Standard entry from C call
  20.         MOV     BP,SP
  21.         PUSH    SI
  22.         PUSH    DI
  23.  
  24.         ;--- Select both graphics controllers
  25.  
  26.         MOV     DX,3CCH                 ;Load address
  27.         MOV     AL,0                    ;Select controller 0
  28.         OUT     DX,AL
  29.         MOV     DX,3CAH                 ;Load address of second controller
  30.         MOV     AL,1                    ;Select controller 1
  31.         OUT     DX,AL
  32.  
  33.         ;--- Get address of CRT controller from the parameter table
  34.         ;    and turn the video off
  35.  
  36.         MOV     SI,[BP+4]               ;Fetch pointer to param table
  37.         MOV     DI,SI                   ;Keep pointer to first parameter
  38.         LODSB                           ;Fetch the crt controller address
  39.         MOV     DL,AL
  40.         MOV     DH,3
  41.         ADD     DX,6                    ;Turn video off
  42.         IN      AL,DX                   ;First reset data/index flip flop
  43.         MOV     DX,3C0H                 ;Address of attribute controller
  44.         XOR     AL,AL
  45.         OUT     DX,AL                   ;Write 0 to turn video off
  46.  
  47.         ;--- Load the Miscellaneous regiser
  48.  
  49.         MOV     DX,3C2H                 ;Fetch Misc register address
  50.         LODSB                           ;Fetch value from parameter table
  51.         OUT     DX,AL                   ;Load the Misc register
  52.  
  53.         ;--- Load the Sequencer registers
  54.  
  55.         MOV     DX,3C4H                 ;Halt the sequencer
  56.         XOR     AL,AL
  57.         OUT     DX,AL
  58.         INC     DX
  59.         MOV     AL,1
  60.         OUT     DX,AL
  61.         DEC     DX
  62.  
  63.         MOV     CX,4                    ;Number of registers to load
  64.         MOV     AH,1                    ;First register to load
  65.  
  66. LoopSeq:MOV     AL,AH                   ;Fetch index
  67.         OUT     DX,AL                   ;Select index
  68.         INC     DX                      ;Address of data register
  69.         LODSB                           ;Fetch value from paramter table
  70.         OUT     DX,AL                   ;Load data register
  71.         INC     AH                      ;Update register index
  72.         DEC     DX
  73.         LOOP    LoopSeq                 ;Check if more to do
  74.  
  75.         MOV     AL,0                    ;Restart the sequencer
  76.         OUT     DX,AL
  77.         INC     DX
  78.         MOV     AL,3
  79.         OUT     DX,AL
  80.  
  81.         ;--- Load the CRT controller registers
  82.  
  83.         MOV     DL,[DI]                 ;Fetch address of CRT controller
  84.         MOV     CX,25                   ;Number of registers to load
  85.         XOR     AH,AH                   ;Index of first register to load
  86.  
  87. LoopCRT:MOV     AL,AH                   ;Fetch index
  88.         OUT     DX,AL                   ;Select register
  89.         INC     DX                      ;Address of data register
  90.         LODSB                           ;Fetch data
  91.         OUT     DX,AL                   ;Load data register
  92.         DEC     DX                      ;Address of index
  93.         INC     AH                      ;Update index
  94.         LOOP    LoopCRT
  95.  
  96.         ;--- Load the Graphics controller registers
  97.  
  98.         MOV     DX,3CEH
  99.         MOV     CX,9
  100.         XOR     AH,AH
  101.  
  102. LoopGrf:MOV     AL,AH                   ;Fetch index
  103.         OUT     DX,AL                   ;Select index
  104.         INC     DX
  105.         LODSB                           ;Fetch value from parameter table
  106.         OUT     DX,AL                   ;Load value into data register
  107.         INC     AH
  108.         DEC     DX
  109.         LOOP    LoopGrf
  110.  
  111.         ;--- Load the palette registers in the Attribute controller
  112.  
  113.         MOV     DL,[DI]                 ;Reset data/index flip-flop
  114.         ADD     DL,6
  115.         IN      AL,DX
  116.  
  117.         MOV     DX,3C0H                 ;Address of index register
  118.         MOV     CX,16                   ;Number of registers to load
  119.         XOR     AH,AH                   ;First index
  120.  
  121. LoopVLT:MOV     AL,AH                   ;Fetch index
  122.         OUT     DX,AL                   ;Select next index
  123.         LODSB                           ;Fetch value from parameter table
  124.         OUT     DX,AL                   ;Load the next data register
  125.         INC     AH                      ;Update index
  126.         LOOP    LoopVLT
  127.  
  128.         ;--- Load Attribute registers beyond palette
  129.  
  130.         MOV     CX,4                    ;Number of register to load
  131.         MOV     AH,30H                  ;Starting index is 10H and 20h is
  132.                                         ;used to turn Attr. Ctrl on
  133. LoopAtt:MOV     AL,AH                   ;Fetch next index
  134.         OUT     DX,AL                   ;Select the index
  135.         LODSB                           ;Fetch value from parameter table
  136.         OUT     DX,AL                   ;Load register with the value
  137.         INC     AH                      ;Update index
  138.         LOOP    LoopAtt
  139.  
  140.         POP     DI                      ;Standard return to C
  141.         POP     SI
  142.         MOV     SP,BP
  143.         POP     BP
  144.         RET
  145. _Write_Register_Set  ENDP
  146.