home *** CD-ROM | disk | FTP | other *** search
/ Shareware Supreme Volume 6 #1 / swsii.zip / swsii / 099 / TGE101.ZIP / 320X240.ASM < prev    next >
Assembly Source File  |  1993-02-04  |  15KB  |  885 lines

  1. ; 320x240x256 (requires register-compatible VGA+)
  2. ; loadable driver for The Graphics Engine
  3. ; Copyright (c) 1993 by Matthew Hildebrand
  4.  
  5. ; Turbo Assembler syntax
  6.  
  7. IDEAL
  8. P286
  9. MODEL LARGE
  10.  
  11.     CODESEG
  12.     ORG    0
  13.  
  14.     db    'GRAP'
  15.     dw    initGraphics        ; initGraphics
  16.     dw    ?
  17.     dw    deInitGraphics        ; deInitGraphics
  18.     dw    ?
  19.         dw    0            ; putImage
  20.         dw    ?
  21.         dw    0            ; putImageInv
  22.         dw    ?
  23.         dw    0            ; getImage
  24.         dw    ?
  25.         dw    putLine            ; putLine
  26.         dw    ?
  27.         dw    getLine            ; getLine
  28.         dw    ?
  29.         dw    0            ; imageSize
  30.         dw    ?
  31.     dw      putPixel        ; putPixel
  32.     dw    ?
  33.     dw    getPixel        ; getPixel
  34.     dw    ?
  35.     dw    0            ; line
  36.         dw    ?
  37.         dw    horizLine        ; horizLine
  38.     dw    ?
  39.     dw    0            ; drawRect
  40.     dw    ?
  41.         dw    0            ; filledRect
  42.     dw    ?
  43.     dw    setPaletteReg        ; setPaletteReg
  44.     dw    ?
  45.         dw    getPaletteReg        ; getPaletteReg
  46.     dw    ?
  47.     dw    setBlockPalette        ; setBlockPalette
  48.     dw    ?
  49.         dw    getBlockPalette        ; getBlockPalette
  50.         dw    ?
  51.         dw    clearGraphics        ; clearGraphics
  52.         dw    ?
  53.     dw    319
  54.     dw    239
  55.     dw    255
  56.  
  57. LABEL    output    DATAPTR
  58.     dw    0
  59.     dw    0A000h
  60.  
  61.     db    'The Graphics Engine -- Copyright (c) 1993 by Matthew Hildebrand'
  62.  
  63. inited        db    0
  64. colourPalette    db    768    DUP(?)
  65. lineOffs    dw    240    DUP(?)
  66.  
  67. ; Plane masks for horizLine
  68. leftEdgeMask    db    1111b, 1110b, 1100b, 1000b
  69. rightEdgeMask    db    0001b, 0011b, 0111b, 1111b
  70.  
  71.  
  72. SC_INDEX    EQU    3C4h    ; Sequence Controller Index
  73. GC_INDEX    EQU    3CEh    ; Graphics Controller Index register
  74. CRTC_INDEX    EQU    3D4h    ; CRT Controller Index
  75. MISC_OUTPUT    EQU    3C2h    ; Miscellaneous Output register
  76. SCREEN_SEG    EQU    0A000h  ; segment of display memory in mode X
  77. MAP_MASK    EQU     02h     ; index in SC of Map Mask register
  78. READ_MAP    EQU    4    ; Read Map register index in GC
  79. SCREEN_WIDTH    EQU    320      ; width of screen in bytes from one scan line
  80.                 ; to the next
  81. INPUT_STATUS_1  EQU     03DAh   ; Input Status 1 register
  82. START_ADDR_HIGH EQU    0Ch     ; start address high byte
  83. START_ADDR_LOW  EQU    0Dh     ; start address low byte
  84. WORD_OUTS_OK    EQU    1    ; Set to 0 for VGAs that can't handle
  85.                 ; word OUTs to indexed VGA registers
  86.  
  87.  
  88. MACRO    GETPALETTE
  89.   mov    ax,1017h
  90.   xor    bx,bx
  91.   mov    cx,256
  92.   mov    dx,cs
  93.   mov    es,dx
  94.   mov    dx,OFFSET colourPalette
  95.   int    10h
  96. ENDM
  97.  
  98. MACRO    SETPALETTE
  99.   mov    ax,1012h
  100.   xor    bx,bx
  101.   mov    cx,256
  102.   mov    dx,cs
  103.   mov    es,dx
  104.   mov    dx,OFFSET colourPalette
  105.   int    10h
  106. ENDM
  107.  
  108. MACRO    OUT_WORD
  109. if WORD_OUTS_OK
  110.   out    dx,ax
  111. else
  112.   out    dx,al
  113.   inc    dx
  114.   xchg    ah,al
  115.   out    dx,al
  116.   dec    dx
  117.   xchg    ah,al
  118. endif
  119. ENDM
  120.  
  121.  
  122.     PUBLIC    C    initGraphics
  123. PROC    C    initGraphics
  124.   push    si di
  125.  
  126.   mov   ax,0013h            ; set mode 13h
  127.   int   10h
  128.  
  129.   mov   dx,SC_INDEX
  130.   mov   ax,0604h
  131.   out   dx,ax               ; disable chain4 mode
  132.   mov   ax,0100h
  133.   out   dx,ax               ; synchronous reset while setting
  134.                       ; Misc Output for safety, even
  135.                     ; though clock unchanged
  136.  
  137.   mov   dx,MISC_OUTPUT
  138.   mov   al,0E3h
  139.   out   dx,al                ; select 25 MHz dot clock & 60 Hz
  140.                       ; scanning rate
  141.  
  142.   mov   dx,SC_INDEX
  143.   mov   ax,0300h
  144.   out   dx,ax                ; undo reset (restart sequencer)
  145.  
  146.   mov   dx,CRTC_INDEX             ; reprogram the CRT Controller
  147.   mov   al,11h              ; VSync End reg contains register
  148.   out   dx,al               ; write protect bit
  149.   inc   dx                  ; CRT Controller Data register
  150.   in    al,dx               ; get current VSync End register setting
  151.   and   al,7Fh              ; remove write protect on various
  152.   out   dx,al               ; CRTC registers
  153.   dec   dx                  ; CRT Controller Index
  154.  
  155.   mov    ax,00D06h            ; set CRT parameters
  156.   out    dx,ax
  157.   mov    ax,03E07h
  158.   out    dx,ax
  159.   mov    ax,04109h
  160.   out    dx,ax
  161.   mov    ax,0EA10h
  162.   out    dx,ax
  163.   mov    ax,0AC11h
  164.   out    dx,ax
  165.   mov    ax,0DF12h
  166.   out    dx,ax
  167.   mov    ax,00014h
  168.   out    dx,ax
  169.   mov    ax,0E715h
  170.   out    dx,ax
  171.   mov    ax,00616h
  172.   out    dx,ax
  173.   mov    ax,0E317h
  174.   out    dx,ax
  175.  
  176.   mov   dx,SC_INDEX
  177.   mov   ax,0F02h
  178.   out   dx,ax               ; enable writes to all four planes
  179.   mov   ax,SCREEN_SEG              ; now clear all display memory, 8
  180.   mov   es,ax                     ; pixels at a time
  181.   xor   di,di               ; point ES:DI to display memory
  182.   xor   ax,ax               ; clear to zero-value pixels
  183.   mov   cx,8000h             ; # of words in display memory
  184.   rep   stosw               ; clear all of display memory
  185.  
  186.   cmp    [inited],0            ; restore palette if necessary
  187.   je    @@notInited
  188.   SETPALETTE
  189.   pop    di si
  190.   mov    ax,1
  191.   retf
  192.  
  193.       @@notInited:
  194.   mov    [inited],1
  195.   mov    si,OFFSET lineOffs
  196.   mov    cx,240
  197.   xor    bx,bx
  198.  
  199.     @@LLoop:
  200.   mov    ax,SCREEN_WIDTH/4
  201.   mul    bx
  202.   mov    [cs:si],ax
  203.   add    si,2
  204.   inc    bx
  205.   loop    @@LLoop
  206.  
  207.   pop   di si
  208.   mov    ax,1
  209.   retf
  210. ENDP
  211.  
  212.     PUBLIC    C    deInitGraphics
  213. PROC    C    deInitGraphics
  214.   GETPALETTE
  215.   mov    ax,0003
  216.   int    10h
  217.   retf
  218. ENDP
  219.  
  220.     PUBLIC    C    putLine
  221. PROC    C    putLine
  222.     ARG    lineNum:WORD, xOff:WORD, lineLen:WORD, buf:DATAPTR
  223.         LOCAL    x2:WORD
  224.   push    ds si di
  225.  
  226.   mov    bx,[lineNum]            ; start address in ES:DI
  227.   shl    bx,1
  228.   mov    di,[lineOffs+bx]
  229.   mov    dx,[xOff]
  230.   shr    dx,2
  231.   add    di,dx
  232.   mov    ax,SCREEN_SEG
  233.   mov    es,ax
  234.   lds    si,[buf]            ; source in DS:SI
  235.   cld
  236.  
  237.   mov    bx,[xOff]
  238.   add    bx,[lineLen]            ; calculate x2
  239.   dec    bx
  240.   mov    [x2],bx
  241.  
  242.   mov    cx,[lineLen]            ; line is short
  243.   cmp    cx,4
  244. JUMPS
  245.   jle    @@ShortLine
  246. NOJUMPS
  247.  
  248.   mov    cx,[xOff]            ; calculate starting plane
  249.   mov    bx,cx
  250.   mov    ax,0102h
  251.   and    cl,3
  252.   shl    ah,cl
  253.   mov    dx,SC_INDEX
  254.   OUT_WORD
  255.   push    si
  256.   mov    bx,[x2]
  257.   mov    cx,[xOff]
  258.       @@Loop1:
  259.   cmp    cx,bx
  260.   jg    @@Loop1Done
  261.   lodsb
  262.   stosb
  263.   add    cx,4
  264.   add    si,3
  265.   jmp    short    @@Loop1
  266.  
  267.     @@Loop1Done:
  268.   pop    si
  269.   inc    si
  270.   push    si
  271.   mov    bx,[xOff]
  272.   inc    bx
  273.   mov    cx,bx
  274.   mov    ax,0102h
  275.   and    cl,3
  276.   shl    ah,cl
  277.   mov    dx,SC_INDEX
  278.   OUT_WORD
  279.   mov    cx,bx
  280.   mov    bx,[lineNum]            ; start address in ES:DI
  281.   shl    bx,1
  282.   mov    di,[lineOffs+bx]
  283.   shr    cx,2
  284.   add    di,cx
  285.   mov    bx,[x2]
  286.   mov    cx,[xOff]
  287.   inc    cx
  288.       @@Loop2:
  289.   cmp    cx,bx
  290.   jg    @@Loop2Done
  291.   lodsb
  292.   stosb
  293.   add    cx,4
  294.   add    si,3
  295.   jmp    short    @@Loop2
  296.  
  297.       @@Loop2Done:
  298.   pop    si
  299.   inc    si
  300.   push    si
  301.   mov    bx,[xOff]
  302.   add    bx,2
  303.   mov    cx,bx
  304.   mov    ax,0102h
  305.   and    cl,3
  306.   shl    ah,cl
  307.   mov    dx,SC_INDEX
  308.   OUT_WORD
  309.   mov    cx,bx
  310.   mov    bx,[lineNum]
  311.   shl    bx,1
  312.   mov    di,[lineOffs+bx]
  313.   shr    cx,2
  314.   add    di,cx
  315.   mov    bx,[x2]
  316.   mov    cx,[xOff]
  317.   add    cx,2
  318.       @@Loop3:
  319.   cmp    cx,bx
  320.   jg    @@Loop3Done
  321.   lodsb
  322.   stosb
  323.   add    cx,4
  324.   add    si,3
  325.   jmp    short    @@Loop3
  326.  
  327.       @@Loop3Done:
  328.   pop    si
  329.   inc    si
  330.   mov    bx,[xOff]
  331.   add    bx,3
  332.   mov    cx,bx
  333.   mov    ax,0102h
  334.   and    cl,3
  335.   shl    ah,cl
  336.   mov    dx,SC_INDEX
  337.   OUT_WORD
  338.   mov    cx,bx
  339.   mov    bx,[lineNum]
  340.   shl    bx,1
  341.   mov    di,[lineOffs+bx]
  342.   shr    cx,2
  343.   add    di,cx
  344.   mov    bx,[x2]
  345.   mov    cx,[xOff]
  346.   add    cx,3
  347.     @@Loop4:
  348.   cmp    cx,bx
  349.   jg    @@Exit
  350.   lodsb
  351.   stosb
  352.   add    cx,4
  353.   add    si,3
  354.   jmp    short    @@Loop4
  355.  
  356.       @@ShortLine:
  357.   mov    cx,[xOff]
  358.   mov    bx,cx
  359.   and    cl,3
  360.   mov    ax,0102h
  361.   shl    ah,cl
  362.   mov    dx,SC_INDEX
  363.   OUT_WORD
  364.   mov    cx,bx
  365.   shr    bx,2
  366.   mov    di,bx
  367.   mov    bx,[lineNum]
  368.   shl    bx,1
  369.   add    di,[lineOffs+bx]
  370.   movsb
  371.   cmp    cx,[x2]
  372.   jge    @@Exit
  373.   inc    [xOff]
  374.   jmp    short    @@ShortLine
  375.  
  376.       @@Exit:
  377.   pop   di si ds
  378.   leave
  379.   retf
  380. ENDP
  381.  
  382.     PUBLIC    C    getLine
  383. PROC    C    getLine
  384.     ARG    lineNum:WORD, xOff:WORD, lineLen:WORD, buf:DATAPTR
  385.         LOCAL    x2:WORD
  386.   push    ds si di
  387.  
  388.   mov    bx,[lineNum]            ; start address in ES:DI
  389.   shl    bx,1
  390.   mov    si,[lineOffs+bx]
  391.   mov    dx,[xOff]
  392.   shr    dx,2
  393.   add    si,dx
  394.   mov    ax,SCREEN_SEG
  395.   mov    ds,ax
  396.   les    di,[buf]            ; buffer addr in DS:SI
  397.   cld
  398.  
  399.   mov    bx,[xOff]
  400.   add    bx,[lineLen]            ; calculate x2
  401.   dec    bx
  402.   mov    [x2],bx
  403.  
  404.   mov    cx,[lineLen]            ; line is short
  405.   cmp    cx,4
  406. JUMPS
  407.   jle    @@ShortLine
  408. NOJUMPS
  409.  
  410.   mov    ax,[xOff]            ; calculate starting plane
  411.   mov    bx,ax
  412.   and    al,3
  413.   mov    ah,al
  414.   mov    al,READ_MAP
  415.   mov    dx,GC_INDEX
  416.   OUT_WORD
  417.   push    di
  418.   mov    bx,[x2]
  419.   mov    cx,[xOff]
  420.       @@Loop1:
  421.   cmp    cx,bx
  422.   jg    @@Loop1Done
  423.   lodsb
  424.   stosb
  425.   add    cx,4
  426.   add    di,3
  427.   jmp    short    @@Loop1
  428.  
  429.     @@Loop1Done:
  430.   pop    di
  431.   inc    di
  432.   push    di
  433.   mov    bx,[xOff]
  434.   inc    bx
  435.   mov    ax,bx
  436.   and    al,3
  437.   mov    ah,al
  438.   mov    al,READ_MAP
  439.   mov    dx,GC_INDEX
  440.   OUT_WORD
  441.   mov    cx,bx
  442.   mov    bx,[lineNum]            ; start address in ES:DI
  443.   shl    bx,1
  444.   mov    si,[lineOffs+bx]
  445.   shr    cx,2
  446.   add    si,cx
  447.   mov    bx,[x2]
  448.   mov    cx,[xOff]
  449.   inc    cx
  450.       @@Loop2:
  451.   cmp    cx,bx
  452.   jg    @@Loop2Done
  453.   lodsb
  454.   stosb
  455.   add    cx,4
  456.   add    di,3
  457.   jmp    short    @@Loop2
  458.  
  459.       @@Loop2Done:
  460.   pop    di
  461.   inc    di
  462.   push    di
  463.   mov    bx,[xOff]
  464.   add    bx,2
  465.   mov    ax,bx
  466.   and    al,3
  467.   mov    ah,al
  468.   mov    al,READ_MAP
  469.   mov    dx,GC_INDEX
  470.   OUT_WORD
  471.   mov    cx,bx
  472.   mov    bx,[lineNum]
  473.   shl    bx,1
  474.   mov    si,[lineOffs+bx]
  475.   shr    cx,2
  476.   add    si,cx
  477.   mov    bx,[x2]
  478.   mov    cx,[xOff]
  479.   add    cx,2
  480.       @@Loop3:
  481.   cmp    cx,bx
  482.   jg    @@Loop3Done
  483.   lodsb
  484.   stosb
  485.   add    cx,4
  486.   add    di,3
  487.   jmp    short    @@Loop3
  488.  
  489.       @@Loop3Done:
  490.   pop    di
  491.   inc    di
  492.   mov    bx,[xOff]
  493.   add    bx,3
  494.   mov    ax,bx
  495.   and    al,3
  496.   mov    ah,al
  497.   mov    al,READ_MAP
  498.   mov    dx,GC_INDEX
  499.   OUT_WORD
  500.   mov    cx,bx
  501.   mov    bx,[lineNum]
  502.   shl    bx,1
  503.   mov    si,[lineOffs+bx]
  504.   shr    cx,2
  505.   add    si,cx
  506.   mov    bx,[x2]
  507.   mov    cx,[xOff]
  508.   add    cx,3
  509.     @@Loop4:
  510.   cmp    cx,bx
  511.   jg    @@Exit
  512.   lodsb
  513.   stosb
  514.   add    cx,4
  515.   add    di,3
  516.   jmp    short    @@Loop4
  517.  
  518.       @@ShortLine:
  519.   mov    ax,[xOff]
  520.   mov    bx,ax
  521.   and    al,3
  522.   mov    ah,al
  523.   mov    al,READ_MAP
  524.   mov    dx,GC_INDEX
  525.   OUT_WORD
  526.   mov    cx,bx
  527.   shr    bx,2
  528.   mov    si,bx
  529.   mov    bx,[lineNum]
  530.   shl    bx,1
  531.   add    si,[lineOffs+bx]
  532.   movsb
  533.   cmp    cx,[x2]
  534.   jge    @@Exit
  535.   inc    [xOff]
  536.   jmp    short    @@ShortLine
  537.  
  538.       @@Exit:
  539.   pop   di si ds
  540.   leave
  541.   retf
  542. ENDP
  543.  
  544.     PUBLIC    C    putPixel
  545. PROC    C    putPixel
  546.     ARG    x:WORD, y:WORD, colour:BYTE
  547.   push    di
  548.  
  549.   mov    ax,SCREEN_SEG
  550.   mov    es,ax
  551.   mov    bx,[y]                ; point to start of desired row
  552.   shl    bx,1
  553.   mov    bx,[lineOffs+bx]
  554.   mov    dx,[x]
  555.   mov    cx,dx                ; store x coord
  556.   shr    dx,2
  557.   add    bx,dx
  558.   mov    di,bx                ; ES:DI points to pixel
  559.   and    cl,3                ; get the plane # of the pixel
  560.   mov    ax,102h
  561.   shl    ah,cl                ; set the bit corresponding to plane
  562.   mov    dx,SC_INDEX
  563.   OUT_WORD
  564.   mov    bl,[colour]
  565.   mov    [es:di],bl
  566.  
  567.   pop    di
  568.   leave
  569.   retf
  570. ENDP
  571.  
  572.     PUBLIC    C    getPixel
  573. PROC    C    getPixel
  574.     ARG    x:WORD, y:WORD
  575.   push    di
  576.  
  577.   mov    ax,SCREEN_SEG
  578.   mov    es,ax
  579.   mov    bx,[y]                ; point to start of desired row
  580.   shl    bx,1
  581.   mov    bx,[lineOffs+bx]
  582.   mov    dx,[x]
  583.   mov    cx,dx                ; store x coord
  584.   shr    dx,2
  585.   add    bx,dx
  586.   mov    di,bx                ; ES:DI points to pixel
  587.   and    cl,3                ; get the plane # of the pixel
  588.   mov    al,READ_MAP
  589.   mov    ah,cl
  590.   mov    dx,GC_INDEX            ; set the bit corresponding to plane
  591.   OUT_WORD
  592.   xor    ax,ax
  593.   mov    al,[es:di]
  594.  
  595.   pop    di
  596.   leave
  597.   retf
  598. ENDP
  599.  
  600.     PUBLIC    C    horizLine
  601. PROC    C    horizLine
  602.     ARG    y:WORD, x1:WORD, x2:WORD, colour:BYTE
  603.         LOCAL    adj1:WORD, adj2:WORD
  604.   push    si di
  605.   cld
  606.  
  607.   mov    ax,[x1]                ; set up adj1
  608.   and    ax,3
  609.   jz    @@adj1A
  610.   mov    bx,4
  611.   sub    bx,ax
  612.   mov    ax,[x1]
  613.   add    ax,bx
  614.   mov    [adj1],ax
  615.   jmp    short    @@adj1B
  616.       @@adj1A:
  617.   mov    ax,[x1]
  618.   mov    [adj1],ax
  619.       @@adj1B:
  620.  
  621.   mov    ax,[x2]                ; set up adj2
  622.   mov    [adj2],ax
  623.   and    ax,3
  624.   sub    [adj2],ax
  625.  
  626.   mov    ax,[x1]                ; ensure x1 <= x2
  627.   cmp    ax,[x2]
  628.   jbe    @@setup
  629.   mov    bx,[x2]
  630.   mov    [x1],bx
  631.   mov    [x2],ax
  632.  
  633.       @@setup:
  634.   mov    ax,SCREEN_SEG            ; set ES:DI to line start address
  635.   mov    es,ax
  636.   mov    bx,[y]
  637.   shl    bx,1
  638.   mov    di,[lineOffs+bx]
  639.   mov    bx,[x1]                ; current x counter
  640.   shr    bx,2
  641.   add    di,bx
  642.  
  643.   mov    cx,[adj2]            ; CX = # of 4-pixel sets starting
  644.   shr    cx,2                            ; on plane 0
  645.   mov    bx,[adj1]
  646.   shr    bx,2
  647.   sub    cx,bx
  648.  
  649.   cmp    cx,1
  650.   jl    @@shortLine
  651.  
  652.   ; Draw the left edge
  653.   mov    ax,[x1]                ; get plane number of pixel #1
  654.   and    ax,3
  655.   jz    @@planeZeroStart        ; starts at plane zero
  656.   mov    si,ax                ; set for pixels
  657.   mov    ah,[leftEdgeMask+si]
  658.   mov    al,MAP_MASK
  659.   mov    dx,SC_INDEX
  660.   OUT_WORD
  661.   mov    al,[colour]
  662.   stosb
  663.  
  664.   ; Draw the interior stretch
  665.       @@planeZeroStart:
  666.   mov    ax,0F02h            ; enable writes to all planes
  667.   mov    dx,SC_INDEX
  668.   OUT_WORD
  669.   mov    al,[colour]
  670.   mov    ah,al
  671.   shr    cx,1
  672.   jc    @@Odd
  673.   rep    stosw                ; even number of pixels
  674.   jmp    short    @@rightEdge
  675.       @@Odd:
  676.   rep    stosw                ; odd number of pixels
  677.   stosb
  678.  
  679.   ; Draw the right edge
  680.       @@rightEdge:
  681.   mov    ax,[x2]                ; get plane number of last pixel
  682.   and    ax,3
  683.   mov    si,ax                ; set for pixels
  684.   mov    ah,[rightEdgeMask+si]
  685.   mov    al,MAP_MASK
  686.   mov    dx,SC_INDEX
  687.   OUT_WORD
  688.   mov    al,[colour]
  689.   stosb
  690.  
  691.       @@Exit:
  692.   pop    di si                ; clean up and go home
  693.   leave
  694.   retf
  695.  
  696.     @@shortLine:            ; for very small lines
  697.   mov    al,[colour]
  698.   mov    cx,[x1]
  699.   mov    dx,[y]
  700.       @@Loop:
  701.   push    ax cx dx            ; slow loop until done
  702.   call    putPixel C, cx, dx, ax
  703.   pop    dx cx ax
  704.   inc    cx
  705.   cmp    cx,[x2]
  706.   jle    @@Loop
  707.  
  708.   pop     di si
  709.   leave
  710.   retf
  711. ENDP
  712.  
  713.     PUBLIC    C    setPaletteReg
  714. PROC    C    setPaletteReg
  715.     ARG    palNum:WORD,red:BYTE,green:BYTE,blue:BYTE
  716.   mov    bx,[palNum]
  717.  
  718.   mov    dx,3C8h                ; set for the right palette register
  719.   mov    ax,[palNum]
  720.   out    dx,al
  721.   inc    dx
  722.  
  723.   mov    al,[red]            ; red
  724.   shr    al,2
  725.   jnc    @@L1
  726.   cmp    al,63
  727.   je    @@L1
  728.   inc    al
  729.     @@L1:
  730.   out    dx,al
  731.  
  732.   mov    al,[green]            ; green
  733.   shr    al,2
  734.   jnc    @@L2
  735.   cmp    al,63
  736.   je    @@L2
  737.   inc    al
  738.     @@L2:
  739.   out    dx,al
  740.  
  741.   mov    al,[blue]            ; blue
  742.   shr    al,2
  743.   jnc    @@L3
  744.   cmp    al,63
  745.   je    @@L3
  746.   inc    al
  747.     @@L3:
  748.   out    dx,al
  749.  
  750.   leave
  751.   retf
  752. ENDP
  753.  
  754.     PUBLIC    C    getPaletteReg
  755. PROC    C    getPaletteReg
  756.     ARG    palNum:WORD,red:DATAPTR,green:DATAPTR,blue:DATAPTR
  757.   push    ds si
  758.  
  759.   mov    dx,3C7h                ; set for right palette register
  760.   mov    ax,[palNum]
  761.   out    dx,al
  762.   mov    dx,3C9h
  763.  
  764.   in    al,dx                ; red
  765.   lds    si,[red]
  766.   shl    al,2
  767.   mov    [ds:si],al
  768.   in    al,dx                ; green
  769.   lds    si,[green]
  770.   shl    al,2
  771.   mov    [ds:si],al
  772.   in    al,dx                ; blue
  773.   lds    si,[blue]
  774.   shl    al,2
  775.   mov    [ds:si],al
  776.  
  777.   pop    si ds
  778.   leave
  779.   retf
  780. ENDP
  781.  
  782.     PUBLIC    C    setBlockPalette
  783. PROC    C    setBlockPalette
  784.     ARG    firstReg:WORD,numRegs:WORD,paletteData:DATAPTR
  785.   push    ds si
  786.   lds    si,[paletteData]
  787.   mov    cx,[numRegs]
  788.   jcxz    @@LExit
  789.   cld
  790.  
  791.   mov    dx,3C8h                ; set for right first pal reg
  792.   mov    ax,[firstReg]
  793.   out    dx,al
  794.   inc    dx
  795.  
  796.     @@LLoop:
  797.   lodsb            ; red
  798.   shr    al,2
  799.   jnc    @@L1
  800.   cmp    al,63
  801.   je    @@L1
  802.   inc    al
  803.       @@L1:
  804.   out    dx,al
  805.  
  806.   lodsb            ; green
  807.   shr    al,2
  808.   jnc    @@L2
  809.   cmp    al,63
  810.   je    @@L2
  811.   inc    al
  812.       @@L2:
  813.   out    dx,al
  814.  
  815.   lodsb            ; blue
  816.   shr    al,2
  817.   jnc    @@L3
  818.   cmp    al,63
  819.   je    @@L3
  820.   inc    al
  821.       @@L3:
  822.   out    dx,al
  823.  
  824.   loop    @@LLoop
  825.  
  826.     @@LExit:
  827.   pop    si ds
  828.   leave
  829.   retf
  830. ENDP
  831.  
  832.     PUBLIC    C    getBlockPalette
  833. PROC    C    getBlockPalette
  834.     ARG    firstReg:WORD,numRegs:WORD,paletteData:DATAPTR
  835.   push    di
  836.   mov    cx,[numRegs]
  837.   jcxz    @@LExit
  838.   les    di,[paletteData]
  839.   cld
  840.  
  841.   mov    dx,3C7h                ; set for right first pal reg
  842.   mov    ax,[firstReg]
  843.   out    dx,al
  844.   mov    dx,3C9h
  845.  
  846.     @@L1:
  847.   in    al,dx
  848.   shl    al,2
  849.   stosb        ; red
  850.   in    al,dx
  851.   shl    al,2
  852.   stosb        ; green
  853.   in    al,dx
  854.   shl    al,2
  855.   stosb        ; blue
  856.   loop    @@L1
  857.  
  858.     @@LExit:
  859.   pop    di
  860.   leave
  861.   retf
  862. ENDP
  863.  
  864.     PUBLIC    C    clearGraphics
  865. PROC    C    clearGraphics
  866.     ARG    colour:BYTE
  867.   mov   dx,SC_INDEX
  868.   mov   ax,0F02h
  869.   out   dx,ax               ; enable writes to all four planes
  870.  
  871.   mov    ax,SCREEN_SEG
  872.   mov    es,ax
  873.   xor    di,di
  874.   cld
  875.   mov    cx,9600
  876.   mov    al,[colour]
  877.   mov    ah,al
  878.  
  879.   rep    stosw
  880.   leave
  881.   retf
  882. ENDP
  883.  
  884.     ENDS
  885. END