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

📄 vesa2.asm

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 ASM
📖 第 1 页 / 共 2 页
字号:
        cmp al,0100b
        je .foundwin    ; Mode supported
        mov al,[fs:3]                   ; Get window B attributes
        and al,0100b
        cmp al,0100b
        jne .foundwin    ; Mode not supported
        mov byte[.whichwin],1
.foundwin

		; Success - a match has been found!!

	sub ebp,2
	mov ax,[ebp]
	mov [vesamode],ax		; Store vesa 2 mode number

;        call printhex
;        jmp DosExit

        mov ax,[fs:10h]
        mov byte[vesa2red10],0
        mov byte[vesa2_rposng],11
        mov byte[vesa2_gposng],6
        mov byte[vesa2_bposng],0
        mov dword[vesa2_clbitng],1111011111011110b
        mov dword[vesa2_clbitng2],11110111110111101111011111011110b
        mov dword[vesa2_clbitng2+4],11110111110111101111011111011110b
        mov dword[vesa2_clbitng3],0111101111101111b
	mov [bytesperscanline],ax	; Store bytes per scan line
        cmp byte[fs:20h],10
        jne near .nored10
        mov byte[fs:20h],11
        mov byte[vesa2red10],1
        mov byte[vesa2_rposng],10
        mov byte[vesa2_gposng],5
        mov dword[vesa2_clbitng],0111101111011110b
        mov dword[vesa2_clbitng2],01111011110111100111101111011110b
        mov dword[vesa2_clbitng2+4],01111011110111100111101111011110b
        mov dword[vesa2_clbitng3],0011110111101111b

        mov dword[UnusedBit],     10000000000000001000000000000000b
        mov dword[HalfTrans],     01111011110111100111101111011110b
        mov dword[UnusedBitXor],  01111111111111110111111111111111b
        mov dword[UnusedBit+4],   10000000000000001000000000000000b
        mov dword[HalfTrans+4],   01111011110111100111101111011110b
        mov dword[UnusedBitXor+4],01111111111111110111111111111111b
        mov dword[HalfTransB],    00000100001000010000010000100001b
        mov dword[HalfTransB+4],  00000100001000010000010000100001b
        mov dword[HalfTransC],    01111011110111100111101111011110b
        mov dword[HalfTransC+4],  01111011110111100111101111011110b
        mov dword[ngrposng],10
        mov dword[nggposng],5
        mov dword[ngbposng],0

.nored10
        ; fix up bit lengths
        mov al,16
        sub al,[fs:20h]
        mov ah,[fs:22h]
        sub ah,[fs:20h]
        mov bl,[fs:24h]
        sub bl,[fs:20h]
        mov bh,al
        cmp bh,ah
        jb .scheck1
        mov bh,ah
      .scheck1
        cmp bh,bl
        jb .scheck2
        mov bh,bl
      .scheck2
        mov byte[fs:19h],5

        mov al,16
        sub al,[fs:22h]
        mov ah,[fs:20h]
        sub ah,[fs:22h]
        mov bl,[fs:24h]
        sub bl,[fs:22h]
        mov bh,al
        cmp bh,ah
        jb .scheck1b
        mov bh,ah
      .scheck1b
        cmp bh,bl
        jb .scheck2b
        mov bh,bl
      .scheck2b
        mov [fs:21h],bh

        mov al,16
        sub al,[fs:24h]
        mov ah,[fs:20h]
        sub ah,[fs:24h]
        mov bl,[fs:22h]
        sub bl,[fs:24h]
        mov bh,al
        cmp bh,ah
        jb .scheck1c
        mov bh,ah
      .scheck1c
        cmp bh,bl
        jb .scheck2c
        mov bh,bl
      .scheck2c
        mov [fs:23h],bh

        mov word[vesa2_clbit],0

        cmp byte[fs:20h],10
        jne .nottopbit
        mov word[vesa2_usbit],8000h
.nottopbit

        ; Process Red Stuff
        mov al,[fs:20h]         ; bit sizes = [fs:19h,21h,23h]
        mov cl,al
        mov bx,1
        shl bx,cl
        cmp byte[fs:19h],6
        jne .no6bit
        mov [vesa2_usbit],bx
        inc al
.no6bit
        or [vesa2_clbit],bx
        mov [vesa2_rpos],al
        dec al
        mov cl,al
        mov bx,001Fh
        cmp cl,0FFh
        je .shrr
        shl bx,cl
        jmp .shlr
.shrr
        shr bx,1
.shlr
        mov word[vesa2_rfull],bx
        add al,5
        mov bx,1
        mov cl,al
        shl bx,cl
        mov word[vesa2_rtrcl],bx
        xor bx,0FFFFh
        mov word[vesa2_rtrcla],bx

;        mov ax,03h
;        int 10h
;        mov ax,[vesa2_rfull]
;        call printhex
;        jmp DosExit

        ; Process Green Stuff
        mov al,[fs:22h]
        mov cl,al
        mov bx,1
        shl bx,cl
        cmp byte[fs:21h],6
        jne .no6bitb
        mov [vesa2_usbit],bx
        inc al
.no6bitb
        or [vesa2_clbit],bx
        mov [vesa2_gpos],al
        dec al
        mov cl,al
        mov bx,001Fh
        cmp cl,0FFh
        je .shrg
        shl bx,cl
        jmp .shlg
.shrg
        shr bx,1
.shlg
        mov word[vesa2_gfull],bx
        add al,5
        mov bx,1
        mov cl,al
        shl bx,cl
        mov word[vesa2_gtrcl],bx
        xor bx,0FFFFh
        mov word[vesa2_gtrcla],bx

        ; Process Blue Stuff
        mov al,[fs:24h]
        mov cl,al
        mov bx,1
        shl bx,cl
        cmp byte[fs:23h],6
        jne .no6bitc
        mov [vesa2_usbit],bx
        inc al
.no6bitc
        or [vesa2_clbit],bx
        mov [vesa2_bpos],al
        dec al
        mov cl,al
        mov bx,001Fh
        cmp cl,0FFh
        je .shrb
        shl bx,cl
        jmp .shlb
.shrb
        shr bx,1
.shlb
        mov word[vesa2_bfull],bx
        add al,5
        mov bx,1
        mov cl,al
        shl bx,cl
        mov word[vesa2_btrcl],bx
        xor bx,0FFFFh
        mov word[vesa2_btrcla],bx

        xor word[vesa2_clbit],0FFFFh

;vesa2_rtrcl     dw 0            ; red transparency clear     (bit+4)
;vesa2_rtrcla    dw 0            ; red transparency (AND) clear (not(bit+4))
;vesa2_rfull     dw 0            ; red max (or (bit-1)*1Fh)

        call genfulladdtab

	test word[fs:0h],10000000b	; Check if linear available
	jnz .linearavailable
            mov edx,.nolframebuffer
            jmp VESA2EXITTODOS               ; None available
        .nolframebuffer db 'Linear Frame Buffer not Detected.',0

		;---------------------------------------------;
		 ; OK - now set the vesa 2 mode based on the ;
		 ; information gleaned...		     ;
		;---------------------------------------------;

	.linearavailable
	or word[vesamode],4000h		; Convert mode to its LFB
					; equivalent
	mov ebx,[fs:28h]		; Read in physical base ptr

	mov cx,bx
	shr ebx,16
	mov si,[noblocks]
	xor edi,edi			; Since noblocks = number of
					; 64k blocks, these lines leave
					; si:di holding byte size
	mov eax,800h
	int 31h
	jnc .mappedphysicalarea
            mov edx,.unablemap
            jmp VESA2EXITTODOS               ; Failure!!!
        .unablemap db 'Unable to map physical area.',0

	.mappedphysicalarea
	shl ebx,16
	mov bx,cx
	mov [LFBpointer],ebx
        mov eax,ebx
        sub eax,[ZSNESBase]
        mov [VESAAddr],eax

	xor eax,eax
	xor ebx,ebx
	xor ecx,ecx
	xor edx,edx
	mov ax,4f02h
	mov bx,[vesamode]
	int 10h				; Set the vesa mode
	cmp ax,004fh
	jz .modesetok
            mov edx,.unableset
            jmp VESA2EXITTODOS               ; Failure!!!
        .unableset db 'Unable to initialize video mode.',0

	.modesetok
;******************************* EXTRA BIT ****************************

;        cmp byte[.whichwin],1           ; Check if Write is at Window B
;        jne .nowinB
;
;        mov ax,4F05h
;        mov bx,1
;        mov dx,0
;        int 10h
;
;.nowinB

        ; Check logical scanline length
        mov eax,4f06h
        mov ebx,1
        int 10h
        cmp cx,[vesa2_x]
        je .correctwidth

	mov eax,4f06h			; VBE Set/Get logical scan line
					; length
	mov ebx,0			; Set scan line length in
					; pixels
        mov ecx, [vesa2_x]                ; Desired screen width
	int 10h
	cmp ax,04fh
	jz .correctwidth
            mov edx, .unablescan
	    jmp VESA2EXITTODOS		; Failure!!!
        .unablescan db 'Unable to set scan line length.',0

	.correctwidth

;*************************** END OF EXTRA BIT *************************

	xor eax,eax
	mov ecx,1
	int 31h				; Allocate a descriptor

	mov bx,ax			; Move our selector into bx

	mov ecx,[LFBpointer]
	mov dx,cx
	shr ecx,16
	mov eax,7
	int 31h				; Set our selector to LFB
	jnc .selectornowset
                mov edx,.unablelfb
                jmp VESA2EXITTODOS           ; Failure!!!
        .unablelfb db 'Unable to set selector to LFB.',0

	.selectornowset

	xor ecx,ecx
	mov cx,[noblocks]
	shl ecx,6			; Multiply by 64
	shl ecx,10			; And again by 1024
	sub ecx,1			; Necessary!!!
	mov dx,cx
	shr ecx,16			; CX:DX size of screen
	mov eax,8
	int 31h				; Set size of selector
	jnc .ok
                mov edx,.unablesets
                jmp VESA2EXITTODOS           ; Failure!!!
        .unablesets db 'Unable to set size of selector.',0

	.ok
	lar ecx,ebx
	shr ecx,8
	and cl,60h
	or cl,93h
	and ch,0c0h			; Keep granularity bit
	mov ax,9
	int 31h				; Set selector access rights
	jnc .accessrightsset
                mov edx,.unablesetar
                jmp VESA2EXITTODOS
        .unablesetar db 'Unable to set selector access rights.',0

	.accessrightsset
        mov [vesa2selec],bx

        cmp byte[vesa2red10],1
        je .red10
        mov eax,565
        jmp .red11
.red10
        mov eax,555
.red11
        push eax
        call Init_2xSaIMMX
        pop eax
        ret

NEWSYM LFBpointer
	dd 0
NEWSYM noblocks
	dw 0
NEWSYM bytesperscanline
	dw 0
NEWSYM vesamode
	dw 0
;----------------------------------------------------------------------
NEWSYM VESAmodelist
	times 512 dw 0
;----------------------------------------------------------------------
NEWSYM RMREGS
.edi	dd 0
.esi	dd 0
.ebp	dd 0
.esp	dd 0
.ebx	dd 0
.edx	dd 0
.ecx	dd 0
.eax	dd 0

.flags	dw 0
.es	dw 0
.ds	dw 0 
.fs	dw 0
.gs	dw 0
.ip	dw 0
.cs	dw 0
.sp	dw 0
.ss	dw 0
.spare	times 20 dd 0
;----------------------------------------------------------------------
NEWSYM Vesa2AsmEnd

⌨️ 快捷键说明

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