home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / VOGLE / DRIVERS / IBMPC / SIGMA_A.ASM < prev    next >
Assembly Source File  |  2000-02-11  |  8KB  |  482 lines

  1.     TITLE    SIG_LINE - Line drawing routine.
  2.     NAME    SIG_LINE
  3.     PAGE    55,132
  4.  
  5.  
  6.     COMMENT    $
  7.  
  8.     Name:        SIG_LINE
  9.  
  10.     Function:    Draw a line in 640x400 SIGMA graphics mode.
  11.  
  12.     Caller:        Microsoft C:
  13.  
  14.             void     sigline(x1, y1, x2, y2, n);
  15.                 int    x1, y1, x2, y2;    /* pixel co-ords */
  16.                 int    n;        /* pixel value */
  17.         $
  18.  
  19.  
  20.  
  21. SIGMA_DATA    SEGMENT    WORD    PUBLIC    'DATA'
  22.     color    dw    ?
  23.  
  24. row_table    label    word            ; define row table
  25.     line_num = 0
  26.     rept    100
  27.         dw    line_num * 80
  28.         dw    2000h + line_num * 80
  29.         dw    4000h + line_num * 80
  30.         dw    6000h + line_num * 80
  31.         line_num = line_num + 1        ; next row
  32.     endm
  33.  
  34.     negerr    dw    ?
  35.     poserr    dw    ?
  36. SIGMA_DATA    ENDS
  37.  
  38. extrn    __cur_color:word
  39. extrn    _chartab:word
  40. extrn    __fontsize:word
  41.  
  42. argbase    equ    2            ; 2 for large model, 0 for small
  43. ARGx1    equ    [bp + argbase + 4]
  44. ARGy1    equ    [bp + argbase + 6]
  45. ARGx2    equ    [bp + argbase + 8]
  46. ARGy2    equ    [bp + argbase + 10]
  47. ARGcol    equ    [bp + argbase + 12]
  48.  
  49. inc_di    equ    47h
  50. inc_cx    equ    41h
  51. dec_di    equ    4fh
  52. dec_cx    equ    49h
  53. do_nop    equ    90h
  54.  
  55. public    _sig_line
  56. public    _sigmachar
  57. public    _sigmaclear
  58. public    _sigma_set_colors
  59.  
  60. DGROUP    GROUP    SIGMA_DATA
  61.  
  62. SIGMA_TEXT    SEGMENT    byte public 'CODE'
  63.         ASSUME    cs:SIGMA_TEXT, ds:DGROUP
  64.  
  65.  
  66. _sig_line    proc    far
  67.     push    bp
  68.     mov    bp, sp
  69.     push    di
  70.     push    si
  71.     push    bx
  72.     push    cx
  73.     push    dx
  74.  
  75.     mov    ax, ARGcol
  76.     mov    color, ax
  77.     mov    ax, 0b800h            ; display mem segment
  78.     mov    es, ax                ; display mem segment
  79.     
  80.     mov    bx, inc_di * 256 + inc_cx    ; ystep + 1 in bh
  81.                         ; xstep + 1 in bl
  82. ; | x2 - x1 |
  83.     mov    cx, ARGx2            ; x2
  84.     sub    cx, ARGx1            ; x1
  85.     jge    pos_delta_x            ; jump if not negative
  86.     mov    bl, dec_cx            ; cx = delta_x
  87.     neg    cx
  88.  
  89. pos_delta_x:
  90. ; | y2 - y1 |
  91. ;    mov    bh, inc_di
  92.     mov    dx, ARGy2            ; y2
  93.     sub    dx, ARGy1            ; y1
  94.     jge    pos_delta_y
  95.     mov    bh, dec_di            ; ystep - 1
  96.     neg    dx                ; | y2 - y1 |
  97.  
  98. pos_delta_y:                    ; dx = delta_y
  99. ; self modifying code
  100.     mov    di, offset cs:positive
  101.     mov    word ptr cs:[di], bx        ; self mod
  102.  
  103. ; find long axis
  104.     cmp    cx, dx                ; delta_x, delta_y
  105.     jge    big_delta_x
  106.     mov    bl, do_nop            ; if vert, no inc/dec so nop
  107.     xchg    cx, dx                ; swap delta_x and delta_y
  108.     jmp    short got_long_axis
  109.  
  110. big_delta_x:
  111.     mov    bh, do_nop            ; if horiz, no inc/dec so nop
  112.  
  113. got_long_axis:
  114. ; self modifying code
  115.     mov    di, offset cs:negative        ; location to modify
  116.     mov    word ptr cs:[di], bx        ; make mod.
  117.     shl    dx, 1                ; (delta_y * 2)
  118.     mov    negerr, dx
  119.     sub    dx, cx                ; (delta_y * 2) - delta_x
  120.     mov    bx, dx                ; save initial value
  121.     sub    dx, cx                ; (delta_y * 2) - (delta_x * 2)
  122.     mov    poserr, dx
  123.     mov    dx, 02DEh            ; plane select port
  124.  
  125. ; adjust count
  126.     mov    si, cx                ; si = length of long axis
  127.     cmp    si, 0
  128.     jne    not_0
  129.     inc    si
  130. not_0:
  131.     mov    di, ARGy1            ; y
  132.     mov    cx, ARGx1            ; x
  133.     push    bp
  134.     mov    bp, negerr
  135.  
  136. main_loop:
  137.     push    di                ; save y
  138.     push    cx                ; save x
  139.     mov    ax, cx                ; x
  140.     shl    di, 1                ; word table index
  141.     mov    di, row_table[di]
  142.     shr    ax, 1
  143.     shr    ax, 1
  144.     shr    ax, 1
  145.     add    di, ax
  146.     and    cl, 7
  147.     mov    al, 10000000b            ; mask
  148.     ror    al ,cl
  149.     
  150.     mov    cl, al                ; bitORmask
  151.     mov    ch, al                
  152.     not    ch                ; bitANDmask
  153.  
  154.     xor    al, al
  155.     out    dx, al                ; plane 0
  156.     
  157.     mov    ah, byte ptr color
  158.     and    ah, 1
  159.     jz    np1a
  160.     or    es:[di], cl
  161.     jmp    short np1b
  162. np1a:
  163.     and    es:[di], ch
  164. np1b:
  165.     mov    al, 1
  166.     out    dx, al                ; plane 1
  167.     
  168.     mov    ah, byte ptr color
  169.     and    ah, 2
  170.     jz    np2a
  171.     or    es:[di], cl
  172.     jmp    short np2b
  173. np2a:
  174.     and    es:[di], ch
  175. np2b:
  176.     mov    al, 2
  177.     out    dx, al                ; plane 2
  178.     
  179.     mov    ah, byte ptr color
  180.     and    ah, 4
  181.     jz    np3a
  182.     or    es:[di], cl
  183.     jmp    short np3b
  184. np3a:
  185.     and    es:[di], ch
  186. np3b:
  187.     mov    al, 3
  188.     out    dx, al                ; plane 3
  189.     
  190.     mov    ah, byte ptr color
  191.     and    ah, 8
  192.     jz    np4a
  193.     or    es:[di], cl
  194.     jmp    short np4b
  195. np4a:
  196.     and    es:[di], ch
  197. np4b:
  198.  
  199.     pop    cx
  200.     pop    di
  201.  
  202.     cmp    bx, 0
  203.     jge    positive
  204.  
  205. negative:
  206.     inc    cx                ; update x
  207.                         ; inc cx / dec cx / nop
  208.                         ; update y
  209.     inc    di                ; inc di / dec di / nop
  210.     
  211.     add    bx, bp                ; negerr
  212.  
  213. dec_long_axis:
  214.     dec    si                ; dec count
  215.     jge    main_loop
  216.     jmp    short end_line            ; end of line
  217.  
  218. positive:
  219.     inc    cx                ; update x
  220.                         ; inc cx / dec cx
  221.     inc    di                ; update y
  222.                         ; inc di / dec di
  223.     add    bx, poserr            ; (dx)
  224.     dec    si                ; dec count
  225.     jz    short end_line
  226.     jmp    main_loop            ; not end of line
  227.  
  228. end_line:
  229.     pop    bp
  230.     pop    dx
  231.     pop    cx
  232.     pop    bx
  233.     pop    si
  234.     pop    di
  235.     mov    sp, bp
  236.     pop    bp
  237.     ret
  238. _sig_line    endp
  239.  
  240. ;
  241. ;            void
  242. ;            sigmachar(c, x, y, col)
  243. ;                int    c;        /* character code */
  244. ;                int    x, y;        /* upper left pixel */
  245. ;                int    col        /* colour    */
  246. ;
  247.  
  248. ARGC        equ    word ptr [bp + argbase + 4]    ; stack frame addressing
  249. ARGX        equ    word ptr [bp + argbase + 6]
  250. ARGY        equ    word ptr [bp + argbase + 8]
  251. ARGcol        equ             [bp + argbase + 10]
  252.  
  253. _sigmachar    proc    far
  254.  
  255.     push    bp        ; preserve caller registers
  256.     mov    bp,sp
  257.     push    di
  258.     push    si
  259.     push    ds
  260.  
  261.     mov    ax, ARGcol
  262.     mov     color, ax
  263.  
  264.     mov    ax, 0b800h            ; display mem segment
  265.     mov    es, ax                ; display mem segment
  266.  
  267. ; calculate first pixel address
  268.  
  269.     mov    di,ARGY        ; di = y
  270.     mov    cx,ARGX        ; aX = x
  271.     mov    ax, cx
  272.     sub    di,__fontsize    ; Make lower left the origin by
  273.     shl    di, 1        ; Index into row table
  274.     mov    di, row_table[di]
  275.     shr    ax, 1
  276.     shr    ax, 1
  277.     shr    ax, 1
  278.     add    di, ax
  279.     and    cl, 7
  280.  
  281. ; set up character definition table addressing
  282.  
  283.     mov    ch,byte ptr __fontsize
  284.     cmp    ch,16
  285.     je    big
  286.  
  287.     mov    ax,0f000h
  288.     mov    ds,ax
  289.     mov    ax,0fa6eh
  290.     mov    si,ax
  291.     
  292.     jmp    cont1
  293. big:
  294.     mov    ax, SEG _chartab
  295.     mov    ds, ax
  296.     mov    si, OFFSET _chartab
  297. cont1:
  298.     mov    ax,ARGC
  299.     mul    ch
  300.     add    si,ax
  301.         
  302. ; mask and set pixels in the video buffer
  303.  
  304.  
  305. L20:
  306.     xor    ax,ax
  307.     lodsb            ; AX = bit pattern for next pixel row
  308.  
  309.     ror    ax, cl        ; rotate pixels into position
  310.     mov    dx, ax        ; bitORmask
  311.     mov    bx, ax
  312.     not    bx        ; bitANDmask
  313.  
  314.     xor    al, al
  315.     push    dx
  316.     mov    dx, 02DEh
  317.     out    dx, al        ; plane 0
  318.     pop    dx
  319.     
  320.     mov    ah, byte ptr ARGcol
  321.     and    ah, 1
  322.     jz    np11a
  323.     or    es:[di], dx
  324.     jmp    short np11b
  325. np11a:
  326.     and    es:[di], bx
  327. np11b:
  328.     mov    al, 1
  329.     push    dx
  330.     mov    dx, 02DEh
  331.     out    dx, al        ; plane 1
  332.     pop    dx
  333.     
  334.     mov    ah, byte ptr ARGcol
  335.     and    ah, 2
  336.     jz    np22a
  337.     or    es:[di], dx
  338.     jmp    short np22b
  339. np22a:
  340.     and    es:[di], bx
  341. np22b:
  342.     mov    al, 2
  343.     push    dx
  344.     mov    dx, 02DEh
  345.     out    dx, al        ; plane 2
  346.     pop    dx
  347.     
  348.     mov    ah, byte ptr ARGcol
  349.     and    ah, 4
  350.     jz    np33a
  351.     or    es:[di], dx
  352.     jmp    short np33b
  353. np33a:
  354.     and    es:[di], bx
  355. np33b:
  356.     mov    al, 3
  357.     push    dx
  358.     mov    dx, 02DEh
  359.     out    dx, al        ; plane 3
  360.     pop    dx
  361.     
  362.     mov    ah, byte ptr ARGcol
  363.     and    ah, 8
  364.     jz    np44a
  365.     or    es:[di], dx
  366.     jmp    short np44b
  367. np44a:
  368.     and    es:[di], bx
  369. np44b:
  370.  
  371.     add    di, 2000h
  372.     jns    L22
  373.     add    di, 80-8000h
  374.  
  375. L22:    dec    ch
  376.     jnz    L20
  377. Lexit:
  378.     pop    ds        ; restore caller registers and return
  379.     pop    si
  380.     pop    di
  381.     mov    sp,bp
  382.     pop    bp
  383.     ret
  384.  
  385. _sigmachar    endp
  386.  
  387. _sigmaclear    proc    far
  388.     push    bp
  389.     mov    bp, sp
  390.     push    di
  391.     push    si
  392.     push    cx
  393.     push    dx
  394.  
  395.     mov    ax, 0b800h            ; display mem segment
  396.     mov    es, ax                ; display mem segment
  397.     xor    di, di
  398.         mov     cx, 04000h
  399.     mov    dx, 02DEh
  400.  
  401.     mov    al, 0                ; plane 0
  402.     out    dx, al
  403.     mov    ah, byte ptr __cur_color
  404.     and    ah, 1
  405.     jz    n1
  406.     mov    ax, 0FFFFh
  407.     jmp    short    n2
  408. n1:
  409.     xor    ax, ax
  410. n2:
  411.  
  412.         cld
  413.         rep    stosw                     
  414.     xor    di, di
  415.         mov     cx, 04000h
  416.  
  417.     mov    al, 1                ; plane 1
  418.     out    dx, al
  419.     mov    ah, byte ptr __cur_color
  420.     and    ah, 2
  421.     jz    n3
  422.     mov    ax, 0FFFFh
  423.     jmp    short    n4
  424. n3:
  425.     xor    ax, ax
  426. n4:
  427.         rep stosw                     
  428.     xor    di, di
  429.         mov     cx, 04000h
  430.  
  431.     mov    al, 2                ; plane 2
  432.     out    dx, al
  433.     mov    ah, byte ptr __cur_color
  434.     and    ah, 4
  435.     jz    n5
  436.     mov    ax, 0FFFFh
  437.     jmp    short    n6
  438. n5:
  439.     xor    ax, ax
  440. n6:
  441.         rep stosw                     
  442.     xor    di, di
  443.         mov     cx, 04000h
  444.  
  445.     mov    al, 3                ; plane 2
  446.     out    dx, al
  447.     mov    ah, byte ptr __cur_color
  448.     and    ah, 8
  449.     jz    n7
  450.     mov    ax, 0FFFFh
  451.     jmp    short    n8
  452. n7:
  453.     xor    ax, ax
  454. n8:
  455.         rep stosw                     
  456.  
  457.         pop di
  458.         pop si
  459.         pop cx
  460.         pop dx
  461.     mov sp, bp
  462.     pop bp
  463.         ret
  464. _sigmaclear endp
  465.  
  466. _sigma_set_colors    proc    far
  467.          push    bp
  468.          mov     bp, sp
  469.          les     dx,[bp+argbase+4]
  470.          mov    al,2
  471.          mov    ah,16;
  472.  
  473.          int     10H
  474.          pop     bp   
  475.          ret
  476. _sigma_set_colors    endp
  477.  
  478. SIGMA_TEXT    ends
  479.  
  480.         end
  481.  
  482.