home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume8 / gnuplot1.10A / part03 / pcgraph.asm < prev   
Encoding:
Assembly Source File  |  1989-09-09  |  3.1 KB  |  185 lines

  1. TITLE    PC graphics module
  2. ;    Colin Kelley
  3. ;    December 22, 1986
  4. ;    modified January 1987 to use LINEPROC.MAC
  5.  
  6. include header.mac
  7.  
  8. if1
  9. include lineproc.mac
  10. endif
  11.  
  12.  
  13. _text    segment
  14.  
  15.     public _PC_line, _PC_color, _PC_mask, _PC_curloc, _PC_puts, _Vmode
  16.     public _save_stack, _ss_interrupt
  17.     extrn _interrupt:near
  18.  
  19. pcpixel proc near
  20.     ror word ptr linemask,1
  21.     jc cont
  22.     ret
  23. cont:
  24.     push ax
  25.     push bx
  26.     push cx
  27.     push dx
  28.     push bp
  29.     mov cx,ax        ; x
  30.     mov dx,bx        ; y
  31.     mov ah,0ch        ; ah = write pixel
  32.     mov al,byte ptr color
  33.  
  34.     mov bh, 0        ; page 0
  35.     int 10h
  36.     pop bp
  37.     pop dx
  38.     pop cx
  39.     pop bx
  40.     pop ax
  41.     ret
  42. pcpixel endp
  43.  
  44. lineproc _PC_line, pcpixel
  45.  
  46. _PC_color proc near
  47.     push bp
  48.     mov bp,sp
  49.     mov al,[bp+X]            ; color
  50.     mov byte ptr color,al
  51.     pop bp
  52.     ret
  53. _PC_color endp
  54.  
  55. _PC_mask proc near
  56.     push bp
  57.     mov bp,sp
  58.     mov ax,[bp+X]            ; mask
  59.     mov word ptr linemask,ax
  60.     pop bp
  61.     ret
  62. _PC_mask endp
  63.  
  64. _Vmode    proc near
  65.     push bp
  66.     mov bp,sp
  67.     push si
  68.     push di
  69.     mov ax,[bp+X]
  70.     int 10h
  71.     pop di
  72.     pop si
  73.     pop bp
  74.     ret
  75. _Vmode    endp
  76.  
  77. _PC_curloc proc near
  78.     push bp
  79.     mov bp,sp
  80.     mov dh, byte ptr [bp+X] ; row number
  81.     mov dl, byte ptr [bp+X+2] ; col number
  82.     mov bh, 0
  83.     mov ah, 2
  84.     int 10h
  85.     pop bp
  86.     ret
  87. _PC_curloc endp
  88.  
  89. ;
  90. ; thanks to watale!broehl for finding a bug here--I wasn't pushing BP
  91. ;   and reloading AH before INT 10H, which is necessary on genuine IBM
  92. ;   boards...
  93. ;
  94. _PC_puts proc near
  95.     push bp
  96.     mov bp,sp
  97.     push si
  98.     mov bl,byte ptr color
  99.     mov si,[bp+X]        ; offset
  100.  
  101. ifdef LARGE_DATA
  102.     mov es,[bp+X+2]        ; segment if large or compact data model
  103. endif
  104.  
  105. puts2:
  106.  
  107. ifdef LARGE_DATA
  108.     mov al,es:[si]
  109. else
  110.     mov al,[si]
  111. endif
  112.     or al,al
  113.     jz puts3
  114.     mov ah,0eh        ; write TTY char
  115.     int 10h
  116.     inc si
  117.     jmp short puts2
  118. puts3:    pop si
  119.     pop bp
  120.     ret
  121. _PC_puts endp
  122.  
  123.  
  124. ; int kbhit();
  125. ;   for those without MSC 4.0
  126. ; Use BIOS interrupt 16h to determine if a key is waiting in the buffer.
  127. ; Return nonzero if so.
  128. ;
  129.  
  130. beginproc _kbhit
  131.     mov ah, 1        ; function code 1 is keyboard test
  132.     int 16h            ; keyboard functions
  133.     jnz kbfin        ; Exit if char available
  134.     xor ax, ax        ; No char:  return zero.
  135. kbfin:    ret
  136. _kbhit    endp
  137.  
  138.  
  139. ; _save_stack and _ss_interrupt are needed due to a bug in the MSC 4.0
  140. ; code when run under MS-DOS 3.x.  Starting with 3.0, MS-DOS automatically
  141. ; switches to an internal stack during system calls.  This leaves SS:SP
  142. ; pointing at MS-DOS's stack when the ^C interrupt (INT 23H) is triggered.
  143. ; MSC should restore its own stack before calling the user signal() routine,
  144. ; but it doesn't.
  145. ;
  146. ; Presumably this code will be unnecessary in later releases of the compiler.
  147. ;
  148.  
  149. ; _save_stack saves the current SS:SP to be loaded later by _ss_interrupt.
  150. ;
  151.  
  152. beginproc _save_stack
  153.     mov ax,ss
  154.     mov cs:save_ss,ax
  155.     mov ax,sp
  156.     mov cs:save_sp,ax
  157.     ret
  158. _save_stack endp
  159.  
  160.  
  161. ; _ss_interrupt is called on ^C (INT 23H).  It restores SS:SP as saved in
  162. ; _save_stack and then jumps to the C routine interrupt().
  163. ;
  164. beginproc _ss_interrupt
  165.     cli            ; no interrupts while the stack is changed!
  166.     mov ax,-1        ; self-modifying code again
  167. save_ss    equ this word - 2
  168.     mov ss,ax
  169.     mov sp,-1        ; here too
  170. save_sp equ this word - 2
  171.     sti
  172.     jmp _interrupt        ; now it's safe to call the real routine
  173. _ss_interrupt endp
  174.  
  175.  
  176. _text    ends
  177.  
  178.  
  179. const    segment
  180. linemask dw -1
  181. color    db 1
  182. const    ends
  183.  
  184.     end
  185.