home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / mslang / as / c-windo.asm < prev    next >
Assembly Source File  |  1984-10-17  |  5KB  |  191 lines

  1.     PAGE   60,132
  2. ;  WINDO.ASM   03/05/84
  3. ;  Subroutine called by a C-basic program to paint a window.
  4. ;
  5.     TITLE    WINDO
  6.     NAME    WINDO
  7. CGROUP    GROUP    CODESEG
  8. ;
  9. CODESEG SEGMENT PARA PUBLIC 'CODE'
  10.     ASSUME    CS:CGROUP,DS:CGROUP
  11.     PUBLIC    WINDO
  12. ;
  13. COLOR    EQU    0B800H        ;seg address of color adaptor memory
  14. MONO    EQU    0B000H        ;seg address of color adaptor memory
  15. CRTCA    EQU    3D4H        ;port address of 6845 crt controller addr reg
  16. CRTCD    EQU    3D5H        ;port address of 6845 crt controller data reg
  17. CRTSTAT EQU    03DAH        ;crt status port address
  18. VSYNC    EQU    08H        ;crt vertical retrace status bit map
  19. ;
  20. HBUF1    DW    1000H DUP(00H)    ;hold area for display buffer
  21. SCOL    DW    0        ;starting column position
  22. SROW    DW    0        ;starting row position
  23. COLS    DW    0        ;number of columns
  24. ROWS    DW    0        ;number of rows
  25. FOREGR    DW    0        ;foreground attribute
  26. BACKGR    DW    0        ;background attribute
  27. FUNCTN    DW    0        ;function 0=open,1=close
  28. PGNUM    DW    0        ;page number to display
  29. CCTR    DW    0        ;column counter
  30. RCTR    DW    0        ;row counter
  31. ;
  32. ; **************************** WINDOW ROUTINE ************************
  33. ;
  34. WINDO    PROC    NEAR
  35.     PUSH    BP        ;BP unknown (don't care)
  36.     MOV    BP,SP        ;set base for parm list
  37.     PUSH    DS        ;DS -> basic work area
  38.     PUSH    ES        ;ES -> basic work area
  39. ;
  40.     MOV    AX,SS:[BP+18]    ;get addr of parameter
  41. ;    MOV    AX,ES:[SI]    ;get value of parm
  42.     MOV    FUNCTN,AX
  43.     MOV    AX,SS:[BP+16]    ;get addr of parameter
  44. ;    MOV    AX,ES:[SI]    ;get value of parm
  45.     MOV    SCOL,AX
  46.     MOV    AX,SS:[BP+14]    ;get addr of parameter
  47. ;    MOV    AX,ES:[SI]    ;get value of parm
  48.     MOV    SROW,AX
  49.     MOV    AX,SS:[BP+12]    ;get addr of parameter
  50. ;    MOV    AX,ES:[SI]    ;get value of parm
  51.     MOV    COLS,AX
  52.     MOV    AX,SS:[BP+10]    ;get addr of parameter
  53. ;    MOV    AX,ES:[SI]    ;get value of parm
  54.     MOV    ROWS,AX
  55.     MOV    AX,SS:[BP+8]    ;get addr of parameter
  56. ;    MOV    AX,ES:[SI]    ;get value of parm
  57.     MOV    FOREGR,AX
  58.     MOV    AX,SS:[BP+6]    ;get addr of parameter
  59. ;    MOV    AX,ES:[SI]    ;get value of parm
  60.     MOV    BACKGR,AX
  61.     MOV    AX,SS:[BP+4]    ;get addr of parameter
  62. ;    MOV    AX,ES:[SI]    ;get value of parm
  63.     MOV    PGNUM,AX
  64. ;
  65. ;  determine if color or mono adaptor, and set ES to adaptor's address
  66.     PUSH    DS        ;save DS -> my data
  67.     MOV    AX,0        ;set up data seg register ..
  68.     MOV    DS,AX        ;..to gain access to DOS info
  69.     MOV    SI,410H     ;offset to color/mono byte
  70.     MOV    AL,[SI]     ;fetch byte
  71.     POP    DS        ;restore DS -> my data
  72.     AND    AL,48        ;mask
  73.     CMP    AL,48        ;48=mono, 32=color
  74.     JZ    SETMNO
  75.     MOV    AX,100H     ;move display page offset (divided by 10h)
  76.     MUL    PGNUM        ;compute total offset (num pages x offset)
  77.     ADD    AX,COLOR    ;add seg addr of page 0
  78.     JMP    SETES
  79. SETMNO: MOV    AX,MONO
  80. SETES:    MOV    ES,AX        ;now ES -> adaptor memory
  81. ;
  82. ;  initialize counters
  83.     MOV    CX,COLS
  84.     MOV    CCTR,CX     ;initialize column counter
  85.     MOV    CX,ROWS
  86.     MOV    RCTR,CX     ;initialize row counter
  87. ;
  88. ;  compute starting offset into display buffer
  89.     MOV    AX,SROW
  90.     DEC    AX        ;set row 1 to row 0
  91.     MOV    BX,160
  92.     MUL    BX        ;multiply by 160
  93.     ADD    AX,SCOL     ;add (scol * 2) to get relative offset
  94.     ADD    AX,SCOL
  95.     SUB    AX,2        ;point to attribute byte (adjust col 1 to 0)
  96.     MOV    DI,AX        ;AX has starting offset into buffer
  97.     MOV    SI,AX        ;SI and DI have same offsets to both buffers
  98. ;
  99. ;  determine function
  100.     CMP    FUNCTN,1
  101.     JZ    OPN
  102.     CALL    CLOSW
  103.     JMP    FINISH
  104. OPN:    CALL    OPENW
  105. FINISH: POP    ES
  106.     POP    DS
  107.     POP    BP
  108.     RET    16        ;return to basic
  109. WINDO    ENDP
  110. ;
  111. ;
  112. ;  open window - save original data and attributes
  113. ;
  114. OPENW    PROC    NEAR
  115. ;
  116. ;  convert attribute parameters (2 words) to attribute byte, store in BL
  117.     CMP    FOREGR,10H    ;check for blinking attr in foreground
  118.     JL    NOBLNK        ;skip conversion if no blink specified
  119.     SUB    FOREGR,10H    ;move the blink bit from foreground ...
  120.     ADD    BACKGR,10H    ;...to background
  121. NOBLNK: MOV    CL,4        ;count for SHL instruction
  122.     MOV    BX,BACKGR    ;background attr in low-nibble
  123.     SHL    BX,CL        ;background attr shifted left one nibble
  124.     ADD    BX,FOREGR    ;foreground attr in low-nibble
  125.     MOV    CL,8        ;count for SHL instruction
  126.     SHL    BX,CL        ;shift attr byte to high-byte
  127.     MOV    BL,' '          ;move space char to low-byte
  128. ;
  129.     MOV    DX,CRTSTAT
  130. ORETRC: IN    AL,DX
  131.     TEST    AL,VSYNC
  132.     JZ    ORETRC
  133. ;
  134.     MOV    AX,ES:[SI]
  135.     MOV    DS:[DI+OFFSET HBUF1],AX
  136.     MOV    ES:[DI],BX    ;move space + attribute byte to buffer
  137.     DEC    CCTR        ;count off number of columns
  138.     JZ    OCONT
  139.     ADD    DI,2        ;move destination of block one position
  140.     ADD    SI,2
  141.     JMP    ORETRC
  142. ;
  143. OCONT:    DEC    RCTR        ;count off number of rows
  144.     JZ    FINOPN
  145. ;
  146.     MOV    CX,COLS
  147.     MOV    CCTR,CX     ;reset column counter
  148.     MOV    AX,162
  149.     SUB    AX,COLS     ;move to next row in buffer
  150.     SUB    AX,COLS
  151.     ADD    DI,AX
  152.     ADD    SI,AX
  153.     JMP    ORETRC
  154. FINOPN: RET
  155. OPENW    ENDP
  156. ;
  157. ;
  158. ;  close window - restore original data and attributes
  159. ;
  160. CLOSW    PROC    NEAR
  161. ;
  162.     MOV    DX,CRTSTAT
  163. CRETRC: IN    AL,DX
  164.     TEST    AL,VSYNC
  165.     JZ    CRETRC
  166. ;
  167.     MOV    AX,DS:[SI+OFFSET HBUF1]
  168.     MOV    ES:[DI],AX
  169.     DEC    CCTR        ;count off number of columns
  170.     JZ    CCONT
  171.     ADD    DI,2        ;move destination of block one position
  172.     ADD    SI,2
  173.     JMP    CRETRC
  174. ;
  175. CCONT:    DEC    RCTR        ;count off number of rows
  176.     JZ    FINCLS
  177. ;
  178.     MOV    CX,COLS
  179.     MOV    CCTR,CX     ;reset column counter
  180.     MOV    AX,162
  181.     SUB    AX,COLS     ;move to next row in buffer
  182.     SUB    AX,COLS
  183.     ADD    DI,AX
  184.     ADD    SI,AX
  185.     JMP    CRETRC
  186. FINCLS: RET
  187. CLOSW    ENDP
  188. ;--------------------------------------------------------------------
  189. CODESEG ENDS
  190.     END
  191.