⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svga.asm

📁 VESA 图形编程的汇编子程序库
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;****************************************************************************
;*
;*                         SuperVGA Test Library
;*
;*                  Copyright (C) 1993 SciTech Software
;*                          All rights reserved.
;*
;* Filename:    $RCSfile: svga.asm $
;* Version:     $Revision: 1.2 $
;*
;* Language:    80386 Assembler
;* Environment: IBM PC (MS DOS)
;*
;* Description: Assembly language support routines for the SuperVGA test
;*              library.
;*
;* $Id: svga.asm 1.2 1993/10/22 08:58:40 kjb release $
;*
;****************************************************************************

        IDEAL
        JUMPS
        P386                    ; Use 386 instructions

        MODEL   large

CRTC            EQU 3D4h        ; Port of CRTC registers
VGABufferSeg    EQU 0A000h      ; Segment of VGA display memory

        DATASEG

        COMM    _maxx:WORD
        COMM    _maxy:WORD
        COMM    _maxcolor:DWORD
        COMM    _bytesperline:WORD
        COMM    _pagesize:DWORD
        COMM    _curBank:WORD
        COMM    _bankSwitch:DWORD
        COMM    _extendedflipping:WORD
        COMM    _bankAdjust:WORD
        COMM    _writeBank:DWORD; Relocated write bank routine
        COMM    _readBank:DWORD ; Relocated read bank routine
        COMM    _pageFlip:DWORD ; Relocated page flip routine

OriginOffset    dw  0           ; Starting offset within bank
BankOffset      dw  0           ; Starting bank in video memory

        CODESEG

MACRO   procstart name          ; Set up model independant proc
PROC    name
        PUBLIC name
ENDM

MACRO   procend name            ; End procedure macro
ENDP    name
ENDM

;----------------------------------------------------------------------------
; void putPixel16(int x,int y,long color)
;----------------------------------------------------------------------------
; Routine sets the value of a pixel in native VGA graphics modes.
;
; Entry:        x       -   X coordinate of pixel to draw
;               y       -   Y coordinate of pixel to draw
;               color   -   Color of pixel to draw
;
;----------------------------------------------------------------------------
procstart   __putPixel16

        ARG     x:WORD, y:WORD, color:DWORD

        push    bp                  ; Set up stack frame
        mov     bp,sp

; Compute the pixel's address in video buffer

        mov     ax,[y]
        mov     bx,[x]
        mul     [_bytesPerLine]     ; DX:AX := y * BytesPerLine

        mov     cl,bl               ; CL := low-order byte of x

        shr     bx,3                ; BX := x/8
        add     bx,ax
        adc     dx,0                ; DX:BX := y*BytesPerLine + x/8
        add     bx,[OriginOffset]   ; DX:BX := byte offset in video buffer
        adc     dx,[BankOffset]

        cmp     dl,[BYTE _curBank]
        je      @@NoChange

        mov     ax,dx
        call    setBank

@@NoChange:
        mov     ax,VGABufferSeg
        mov     es,ax               ; ES:BX := byte address of pixel

        mov     ah,1                ; AH := unshifted bit mask
        and     cl,7                ; CL := x & 7
        xor     cl,7                ; CL := # bits to shift left

; set Graphics Controller Bit Mask register

        shl     ah,cl               ; AH := bit mask in proper postion
        mov     dx,3CEh             ; GC address register port
        mov     al,8                ; AL := Bit Mask Register number
        out     dx,ax

; set Graphics Controller Mode register

        mov     ax,0205h            ; AL := Mode register number
                                    ; AH := Write mode 2 (bits 0,1)
                                    ;   Read mode 0 (bit 3)
        out     dx,ax

; set data rotate/Function Select register

        mov     ax,3                ; AL := Data Rotate/Func select reg #
        out     dx,ax

; set the pixel value

        mov     al,[es:bx]          ; latch one byte from each bit plane
        mov     al,[BYTE color]     ; AL := pixel value
        mov     [es:bx],al          ; update all bit planes

; restore default Graphics Controller registers

        mov     ax,0FF08h           ; default bit mask
        out     dx,ax

        mov     ax,0005             ; default mode register
        out     dx,ax

        mov     ax,0003             ; default function select
        out     dx,ax

        pop     bp
        ret

procend     __putPixel16

;----------------------------------------------------------------------------
; void putPixel256(int x,int y,long color)
;----------------------------------------------------------------------------
; Routine sets the value of a pixel in native VGA graphics modes.
;
; Entry:        x       -   X coordinate of pixel to draw
;               y       -   Y coordinate of pixel to draw
;               color   -   Color of pixel to draw
;
;----------------------------------------------------------------------------
procstart   __putPixel256

        ARG     x:WORD, y:WORD, color:DWORD

        push    bp                  ; Set up stack frame
        mov     bp,sp

        mov     ax,[y]
        mul     [_bytesperline]
        add     ax,[x]
        adc     dx,0                ; DX:AX := y * BytesPerLine + x
        add     ax,[OriginOffset]
        adc     dl,[BYTE BankOffset]; DL := bank number
        mov     bx,ax               ; BX := Offset in buffer
        cmp     dl,[BYTE _curBank]
        je      @@NoChange

        mov     ax,dx
        call    setBank

@@NoChange:
        mov     ax,VGABufferSeg
        mov     es,ax               ; ES:BX := byte address of pixel
        mov     al,[BYTE color]
        mov     [es:bx],al          ; Replace the pixel
        pop     bp
        ret

procend     __putPixel256

;----------------------------------------------------------------------------
; void putPixel32k(int x,int y,long color)
;----------------------------------------------------------------------------
; Routine sets the value of a pixel in native VGA graphics modes.
;
; Entry:        x       -   X coordinate of pixel to draw
;               y       -   Y coordinate of pixel to draw
;               color   -   Color of pixel to draw
;
;----------------------------------------------------------------------------
procstart   __putPixel32k

        ARG     x:WORD, y:WORD, color:DWORD

        push    bp                  ; Set up stack frame
        mov     bp,sp

        mov     ax,[y]
        mul     [_bytesperline]
        mov     bx,[x]
        shl     bx,1
        add     ax,bx
        adc     dx,0                ; DX:AX := y * BytesPerLine + x * 2
        add     ax,[OriginOffset]
        adc     dl,[BYTE BankOffset]; DL := bank number
        mov     bx,ax               ; BX := Offset in buffer
        cmp     dl,[BYTE _curBank]
        je      @@NoChange

        mov     al,dl
        call    setBank

@@NoChange:
        mov     ax,VGABufferSeg
        mov     es,ax               ; ES:BX := byte address of pixel
        mov     ax,[WORD color]
        mov     [es:bx],ax          ; Replace the pixel
        pop     bp
        ret

procend     __putPixel32k

;----------------------------------------------------------------------------
; void putPixel64k(int x,int y,long color)
;----------------------------------------------------------------------------
; Routine sets the value of a pixel in native VGA graphics modes.
;
; Entry:        x       -   X coordinate of pixel to draw
;               y       -   Y coordinate of pixel to draw
;               color   -   Color of pixel to draw
;
;----------------------------------------------------------------------------
procstart   __putPixel64k

        ARG     x:WORD, y:WORD, color:DWORD

        push    bp                  ; Set up stack frame
        mov     bp,sp

        mov     ax,[y]
        mul     [_bytesperline]
        mov     bx,[x]
        shl     bx,1
        add     ax,bx
        adc     dx,0                ; DX:AX := y * BytesPerLine + x * 2
        add     ax,[OriginOffset]
        adc     dl,[BYTE BankOffset]; DL := bank number
        mov     bx,ax               ; BX := Offset in buffer
        cmp     dl,[BYTE _curBank]
        je      @@NoChange

        mov     al,dl
        call    setBank

@@NoChange:
        mov     ax,VGABufferSeg
        mov     es,ax               ; ES:BX := byte address of pixel
        mov     ax,[WORD color]
        mov     [es:bx],ax          ; Replace the pixel
        pop     bp
        ret

procend     __putPixel64k

;----------------------------------------------------------------------------
; void putPixel16m(int x,int y,long color)
;----------------------------------------------------------------------------
; Routine sets the value of a pixel in native VGA graphics modes.
;
; Entry:        x       -   X coordinate of pixel to draw
;               y       -   Y coordinate of pixel to draw
;               color   -   Color of pixel to draw
;
;----------------------------------------------------------------------------
procstart   __putPixel16m

        ARG     x:WORD, y:WORD, color:DWORD

        push    bp                  ; Set up stack frame
        mov     bp,sp

        mov     ax,[y]
        mul     [_bytesperline]
        mov     bx,[x]
        add     ax,bx
        adc     dx,0
        shl     bx,1
        add     ax,bx
        adc     dx,0                ; DX:AX := y * BytesPerLine + x * 3
        add     ax,[OriginOffset]
        adc     dl,[BYTE BankOffset]; DL := bank number
        mov     bx,ax               ; BX := Offset in buffer
        cmp     dl,[BYTE _curBank]
        je      @@NoChange

        mov     al,dl
        call    setBank

@@NoChange:
        mov     ax,VGABufferSeg
        mov     es,ax               ; ES:BX := byte address of pixel
        mov     al,[BYTE color]
        mov     [es:bx],al          ; Replace the first byte
        cmp     bx,0FFFFh
        jne     @@NotSplit1

; Arrghh!! We have a case where a single pixel can be split across a
; bank boundary, if the bytes per line value is 1920. This can cause the
; machine to hang (and produce strange pixels).

        inc     dl
        mov     al,dl
        call    setBank         ; Change video banks

@@NotSplit1:
        mov     al,[BYTE color+1]
        mov     [es:bx+1],al        ; Replace the middle
        cmp     bx,0FFFEh
        jne     @@NotSplit2

        inc     dl
        mov     al,dl
        call    setBank     ; Change video banks

@@NotSplit2:
        mov     al,[BYTE color+2]
        mov     [es:bx+2],al        ; Replace the last byte
        pop     bp
        ret

procend     __putPixel16m

;----------------------------------------------------------------------------
; void clear16(void)
;----------------------------------------------------------------------------
; Routine to clear the screen. Works even if the display contains more than
; one bank, so will work for 1024x768 and 1280x1024 video modes.
;----------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -