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

📄 xpbitmap.asm

📁 视频游戏开发C语言源程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
        mov   al,ah
        out   dx,al
@@RowLoop:
	mov   cl,bh
	shr   cl,1
	rep   movsw                       ; Copy a complete row for curr plane
	adc   cl,0
	rep   movsb
	add   di,[LineInc]                ; Move to next row
        dec   bl                          ; decrement row counter
        jnz   @@RowLoop                   ; Jump if more rows left
        pop   di                          ; Restore bitmaps start dest byte
        rol   ah,1                        ; Shift mask for next plane
	adc   di,0                        ; If wrapped increment dest address
	dec   [Plane]                     ; Decrement plane counter
        jnz   @@PlaneLoop                 ; Jump if more planes left

        pop   ds                          ; restore data segment
        pop   di                          ; restore registers
        pop   si
        mov   sp,bp                       ; dealloc local variables
        pop   bp
        ret
_x_put_pbm  endp

;----------------------------------------------------------------------
; x_flip_pbm - Write a planar bitmap from system ram to video ram
; If "Orientation" is set then the bitmap is flipped from left to right as
; it is drawn

;
; Source Bitmap structure:
;
;  Width:byte, Height:byte, Bitmap data (plane 0)...Bitmap data (plane 1)..,
;  Bitmap data (plane 2)..,Bitmap data (plane 3)..
;
;  note width is in bytes ie lots of 4 pixels
;
;  x_flip_pbm(X,Y,ScrnOffs,char far * Bitmap, WORD orientation)
;
;
; LIMITATIONS: No clipping is supported
;              Only supports bitmaps with widths which are a multiple of
;              4 pixels
;
; NOTES: The flipped put function is slower than the standard put function
;
; Written by Themie Gouthas
;----------------------------------------------------------------------
_x_flip_pbm  proc
        ARG X:word,Y:word,ScrnOffs:word,Bitmap:dword,Orientation:word
	LOCAL Plane:byte,BMHeight:byte,LineInc:word=LocalStk
	push  bp
        mov   bp,sp
	sub   sp,LocalStk                 ; Create space for local variables
        push  si
        push  di
	push  ds
	cld
        mov   ax,SCREEN_SEG
        mov   es,ax
        mov   ax,[Y]                      ; Calculate dest screen row
	mov   bx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
	mul   bx                          ;  width then adding screen offset
        mov   di,[ScrnOffs]               ;  store result in DI
        add   di,ax
        mov   cx,[X]                      ; Load X coord into CX and make a
	mov   dx,cx                       ;  copy in DX
	shr   dx,2                        ; Find starting byte in dest row
	add   di,dx                       ;  add to DI giving screen offset of
                                          ;  first pixel's byte
        lds   si,[Bitmap]                 ; DS:SI -> Bitmap data
        lodsw                             ; Al = B.M. width (bytes) AH = B.M.
                                          ;  height
        cmp   Orientation,0
        jz    UnFlipped

	mov   [BMHeight],ah               ; Save source bitmap dimensions
        xor   ah,ah                       ; LineInc = bytes to the begin.
	add   bx,ax                       ;  of bitmaps next row on screen
	mov   [LineInc],bx
	mov   bh,al                       ; Use bh as column loop count
        and   cx,0003h                    ; mask X coord giving plane of 1st
					  ; bitmap pixel(zero CH coincidentally)
	mov   ah,11h                      ; Init. mask for VGA plane selection
        shl   ah,cl                       ; Shift for starting pixel plane
        mov   dx,SC_INDEX                 ; Prepare VGA for cpu to video writes
        mov   al,MAP_MASK
        out   dx,al
        inc   dx
	mov   [Plane],4                   ; Set plane counter to 4
@@PlaneLoop:
        push  di                          ; Save bitmap's start dest. offset
        mov   bl,[BMHeight]               ; Reset row counter (BL)
        mov   al,ah
        out   dx,al                       ; set vga write plane
@@RowLoop:
	mov   cl,bh                       ; Reset Column counter cl
@@ColLoop:
        lodsb
        mov   es:[di],al
        dec   di
        sub   di,2
	loop  @@ColLoop                   ; loop if more columns left
@@DoneCol:
	add   di,[LineInc]                ; Move to next row
        dec   bl                          ; decrement row counter
        jnz   @@RowLoop                   ; Jump if more rows left
        pop   di                          ; Restore bitmaps start dest byte
        ror   ah,1                        ; Shift mask for next plane
	sbb   di,0                        ; If wrapped increment dest address
	dec   [Plane]                     ; Decrement plane counter
        jnz   @@PlaneLoop                 ; Jump if more planes left

        pop   ds                          ; restore data segment
        pop   di                          ; restore registers
        pop   si
        mov   sp,bp                       ; dealloc local variables
        pop   bp
        ret
_x_flip_pbm  endp


;----------------------------------------------------------------------
; x_get_pbm - Read a planar bitmap to system ram from video ram
;
; Source Bitmap structure:
;
;  Width:byte, Height:byte, Bitmap data (plane 0)...Bitmap data (plane 1)..,
;  Bitmap data (plane 2)..,Bitmap data (plane 3)..
;
;  note width is in bytes ie lots of 4 pixels
;
;  x_get_pbm(X,Y,BMwidth,BMheight,ScrnOffs,char far * Bitmap)
;
;
; LIMITATIONS: No clipping is supported
;              Only supports bitmaps with widths which are a multiple of
;              4 pixels
; FEATURES   : Automatically selects REP MOVSB or REP MOVSW  depending on
;              source bitmap width, by modifying opcode ;-).
;
; Written by Themie Gouthas
;----------------------------------------------------------------------
_x_get_pbm  proc
	ARG X:word,Y:word,SrcWidth:byte,SrcHeight:byte,ScrnOffs:word,Bitmap:dword
	LOCAL Plane:byte,LineInc:word=LocalStk
	push  bp
        mov   bp,sp
	sub   sp,LocalStk                 ; Create space for local variables
        push  si
        push  di
        push  ds
	cld

	mov   ax,[Y]                      ; Calculate screen row
	mov   bx,[_ScrnLogicalByteWidth]  ;  by mult. Y coord by Screen
	mul   bx                          ;  width then adding screen offset
	mov   si,[ScrnOffs]               ;  store result in SI
	add   si,ax
        mov   cx,[X]                      ; Load X coord into CX and make a
	mov   dx,cx                       ;  copy in DX
	shr   dx,2                        ; Find starting byte in screen row
	add   si,dx                       ;  add to SI giving screen offset of
					  ;  first pixel's byte
	mov   ax,SCREEN_SEG
	mov   ds,ax
	les   di,[Bitmap]                 ; ES:DI -> Bitmap data
	mov   al,[SrcWidth]
	mov   ah,[SrcHeight]
	stosw                             ; Al = B.M. width (bytes) AH = B.M.
                                          ;  height
        xor   ah,ah                       ; LineInc = bytes to the begin.
	sub   bx,ax                       ;  of bitmaps next row on screen
	mov   [LineInc],bx
	mov   bh,al
					  ; Self Modifying, Shame, shame shame..
        and   cx,0003h                    ; mask X coord giving plane of 1st
                                          ; bitmap pixel(zero CH coincidentally)
	mov   ah,11h                      ; Init. mask for VGA plane selection
	shl   ah,cl                       ; Shift for starting pixel plane
	mov   dx,GC_INDEX                 ; Prepare VGA for cpu to video reads
	mov   al,READ_MAP
        out   dx,al
        inc   dx
	mov   [Plane],4                   ; Set plane counter (BH) to 4
	mov   al,cl
@@PlaneLoop:
	push  si
	mov   bl,[SrcHeight]
        out   dx,al
@@RowLoop:
	mov   cl,bh
	shr   cl,1
	rep   movsw                       ; Copy a complete row for curr plane
	adc   cl,0
	rep   movsb
	add   si,[LineInc]                ; Move to next row
        dec   bl                          ; decrement row counter
        jnz   @@RowLoop                   ; Jump if more rows left
	pop   si                          ; Restore bitmaps start dest byte

	inc   al                          ; Select next plane to read from
	and   al,3                        ;

	rol   ah,1                        ; Shift mask for next plane
	adc   si,0                        ; If wrapped increment dest address
	dec   [Plane]                     ; Decrement plane counter
	jnz   @@PlaneLoop                 ; Jump if more planes left

        pop   ds                          ; restore data segment
        pop   di                          ; restore registers
        pop   si
        mov   sp,bp                       ; dealloc local variables
        pop   bp
        ret
_x_get_pbm  endp




	end



        ARG X:word,Y:word,ScrnOffs:word,Bitmap:dword,Orientation:word
	LOCAL Plane:byte,BMHeight:byte,LineInc:word,Columns:byte=LocalStk
	push  bp
        mov   bp,sp
	sub   sp,LocalStk                 ; Create space for local variables
        push  si
        push  di
	push  ds
	cld
        mov   ax,SCREEN_SEG
        mov   es,ax
        mov   ax,[Y]                      ; Calculate dest screen row
	mov   bx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
	mul   bx                          ;  width then adding screen offset
        mov   di,[ScrnOffs]               ;  store result in DI
        add   di,ax
        mov   cx,[X]                      ; Load X coord into CX and make a
	mov   dx,cx                       ;  copy in DX
	shr   dx,2                        ; Find starting byte in dest row
	add   di,dx                       ;  add to DI giving screen offset of
                                          ;  first pixel's byte
        lds   si,[Bitmap]                 ; DS:SI -> Bitmap data
        lodsw                             ; Al = B.M. width (bytes) AH = B.M.
                                          ;  height
        cmp   Orientation,0
        jz    UnFlipped

	mov   [BMHeight],ah               ; Save source bitmap dimensions
        xor   ah,ah                       ; LineInc = bytes to the begin.
	add   bx,ax                       ;  of bitmaps next row on screen
	mov   [LineInc],bx
	mov   [Columns],al                ; Use bh as column loop count
        and   cx,0003h                    ; mask X coord giving plane of 1st
					  ; bitmap pixel(zero CH coincidentally)
	mov   ah,11h                      ; Init. mask for VGA plane selection
        shl   ah,cl                       ; Shift for starting pixel plane
        mov   bh,ah
        mov   dx,SC_INDEX                 ; Prepare VGA for cpu to video writes
        mov   al,MAP_MASK
        out   dx,al
        inc   dx
	mov   [Plane],4                   ; Set plane counter to 4
@@PlaneLoop:
        push  di                          ; Save bitmap's start dest. offset
        mov   bl,[BMHeight]               ; Reset row counter (BL)
        mov   al,bh
        out   dx,al                       ; set vga write plane
@@RowLoop:
	mov   cl,[Columns]                ; Reset Column counter cl
        shr   cx,1
        jnc   @@ColLoop
        lodsb
        mov   es:[di],al
	dec   di
@@ColLoop:
	lodsw                             ; Get next source bitmap byte
        xchg  al,ah
	mov   es:[di],ax
	sub   di,2
	loop  @@ColLoop                   ; loop if more columns left

	add   di,[LineInc]                ; Move to next row
        dec   bl                          ; decrement row counter
        jnz   @@RowLoop                   ; Jump if more rows left
        pop   di                          ; Restore bitmaps start dest byte
        ror   bh,1                        ; Shift mask for next plane
	sbb   di,0                        ; If wrapped increment dest address
	dec   [Plane]                     ; Decrement plane counter
        jnz   @@PlaneLoop                 ; Jump if more planes left

        pop   ds                          ; restore data segment
        pop   di                          ; restore registers
        pop   si
        mov   sp,bp                       ; dealloc local variables
        pop   bp
        ret

⌨️ 快捷键说明

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