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

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