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

📄 mode716.mac

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 MAC
📖 第 1 页 / 共 3 页
字号:
;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com )
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;as published by the Free Software Foundation; either
;version 2 of the License, or (at your option) any later
;version.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


EXTSYM BGMS1,FillSubScr,CMainWinScr,CSubWinScr,scadtng
EXTSYM ngwinen, winbg1enval, BuildWindow, ngwintable, ngcwinptr, domosaicng16b
EXTSYM pesimpng,ScrDispl



%macro ProcessBuildWindow 1
    mov dword[ngwinen],0
    test byte[winbg1enval+ebx+%1*256],0Ah
    jz %%nowindowing
    push eax
    push ebx
    mov al,[winlogicaval+ebx*2]
    shr al,%1*2
    and al,03h
    mov [nglogicval],al
    mov eax,ebx
    add ebx,%1*256
    call BuildWindow
    cmp dword[ngwintable],0
    je %%zero
    dec dword[ngwintable]
    jmp %%notzero
%%zero
    dec dword[ngwintable+4]
%%notzero
    pop ebx
    pop eax
    mov dword[ngcwinptr],ngwintable
%%nowindowing
%endmacro

;Skip transparency if the bg is just a sub-screen or there are no sub-screens
;for that line:
%macro CheckTransparency 2
    cmp byte[curmosaicsz],1
    jne %%nosubmain
    test byte[BGMS1+ebx*2],%1
    jz %%nosubmain
    test byte[FillSubScr+ebx],1
    jnz near %2
%%nosubmain
%endmacro

%macro Mode7NoTranspPreStartUp 0
    mov esi,[cwinptr]
    mov [winptrref],esi
    mov esi,[curvidoffset]
    test byte[FillSubScr+ebx],1
    jz %%main
    test byte[BGMS1+ebx*2],01h
    jnz %%main
    add esi,75036*2
%%main
%endmacro

%macro Mode7NoTranspPreStartUp2 0
    mov esi,[cwinptr]
    mov [winptrref],esi
    mov esi,[curvidoffset]
%endmacro

%macro WinEnCheck 0
    mov esi,[CMainWinScr]
    test byte[FillSubScr+ebx],1
    jz %%main2
    test byte[BGMS1+ebx*2],01h
    jnz %%main2
    mov esi,[CSubWinScr]
%%main2
%endmacro

%macro WinEnCheckMS 0
    mov esi,winbg1enval
%endmacro

%macro Mode7Calculate16b 0
    ; mode 7, ax = curyposition, dx = curxposition (left side)
    ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen
    ; center map coordinates = (X0,Y0)
    ; 1.) cx=X0-bg1scrolx, cy =Y0-ax

    cmp byte[M7HROn],1
    je near .calculateb

    mov bx,[mode7X0]
    and bx,0001111111111111b    ; 13 -> 16 bit signed value
    test bx,0001000000000000b
    jz .nonega
    or bx,1110000000000000b    
    or word[mode7X0],1110000000000000b    
.nonega
    mov [mcxloc],bx
    mov bx,dx
    and bx,0001111111111111b    ; 13 -> 16 bit signed value
    test bx,0001000000000000b
    jz .nonegb
    or bx,1110000000000000b
.nonegb
    sub [mcxloc],bx
    mov bx,ax
    and bx,0001111111111111b    ; 13 -> 16 bit signed value
    test bx,0001000000000000b
    jz .nonegc
    or bx,1110000000000000b
.nonegc
    sub bx,[ScrDispl]
    mov [mcyloc],bx
    mov bx,[mode7Y0]
    and bx,0001111111111111b    ; 13 -> 16 bit signed value
    test bx,0001000000000000b
    jz .nonegd
    or bx,1110000000000000b
    or word[mode7Y0],1110000000000000b    
.nonegd
    sub word[mcyloc],bx

    ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D)

    movsx eax,word[mode7B]
    movsx ebx,word[mcyloc]
    imul eax,ebx
    mov [mmode7xpos],eax
    mov bx,word[mode7X0]
    add [mmode7xpos+1],bx

    movsx ebx,word[mcyloc]
    movsx eax,word[mode7D]
    imul eax,ebx
    mov [mmode7ypos],eax
    mov bx,word[mode7Y0]
    add [mmode7ypos+1],bx

    ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B)

    movsx ebx,word[mcxloc]
    movsx eax,word[mode7A]
    mov [mmode7xadder],eax
    imul eax,ebx
    neg eax
    add [mmode7xpos],eax

    movsx eax,word[mode7C]
    movsx ebx,word[mcxloc]
    neg eax
    mov [mmode7yadder],eax
    imul eax,ebx
    add [mmode7ypos],eax

    test byte[mode7set],1
    jz .nohflip
    mov eax,[mmode7xadder]
    shl eax,8
    add [mmode7xpos],eax
    neg dword[mmode7xadder]
    mov eax,[mmode7yadder]
    shl eax,8
    sub [mmode7ypos],eax
    neg dword[mmode7yadder]
.nohflip
    jmp .calculatea
.calculateb

    ; mode 7, ax = curyposition, dx = curxposition (left side)
    ; draw center map coordinates at (X0-bg1scrolx,Y0-bg1scroly) on screen
    ; center map coordinates = (X0,Y0)
    ; 1.) cx=X0-bg1scrolx, cy =Y0-ax

    mov bx,[mode7X0]
    and bx,0001111111111111b    ; 13 -> 16 bit signed value
    test bx,0001000000000000b
    jz .nonegacb
    or word[mode7X0],1110000000000000b    
    or bx,1110000000000000b    
.nonegacb
    mov [mcxloc],bx
    mov bx,dx
    and bx,0001111111111111b    ; 13 -> 16 bit signed value
    test bx,0001000000000000b
    jz .nonegbcb
    or bx,1110000000000000b
.nonegbcb
    sub [mcxloc],bx
    mov bx,ax
    and bx,0011111111111111b    ; 13 -> 16 bit signed value
    test bx,0010000000000000b
    jz .nonegccb
    or bx,1100000000000000b
.nonegccb
    mov [mcyloc],bx
    mov bx,[mode7Y0]
    and bx,0001111111111111b    ; 13 -> 16 bit signed value
    test bx,0001000000000000b
    jz .nonegdcb
    or word[mode7Y0],1110000000000000b    
    or bx,1110000000000000b
.nonegdcb
    add bx,bx
    sub word[mcyloc],bx

    ; 2.) Find position at scaled y, centered x at SCX=X0-(cy*C),SCY=Y0-(cy*D)

    movsx eax,word[mode7B]
    movsx ebx,word[mcyloc]
    imul eax,ebx
    sar eax,1
    mov [mmode7xpos],eax
    mov bx,word[mode7X0]
    add [mmode7xpos+1],bx

    movsx ebx,word[mcyloc]
    movsx eax,word[mode7D]
    imul eax,ebx
    sar eax,1
    mov [mmode7ypos],eax
    mov bx,word[mode7Y0]
    add [mmode7ypos+1],bx

    ; 3.) Find left scaled location : SCX=SCX-(cx*A),SCY=SCY-(cx*B)

    movsx ebx,word[mcxloc]
    movsx eax,word[mode7A]
    mov [mmode7xadder],eax
    imul eax,ebx
    neg eax
    add [mmode7xpos],eax

    movsx eax,word[mode7C]
    movsx ebx,word[mcxloc]
    neg eax
    mov [mmode7yadder],eax
    imul eax,ebx
    add [mmode7ypos],eax

    test byte[mode7set],1
    jz .nohflipcb
    mov eax,[mmode7xadder]
    shl eax,8
    add [mmode7xpos],eax
    neg dword[mmode7xadder]
    mov eax,[mmode7yadder]
    shl eax,8
    sub [mmode7ypos],eax
    neg dword[mmode7yadder]
.nohflipcb
.calculatea
%endmacro

Mode7Startup16b:
    Mode7Calculate16b
    ; esi = pointer to video buffer
    mov [pesimpng],esi
    cmp byte[curmosaicsz],1
    je .nomosaic
    mov esi,xtravbuf+32
    mov ecx,128
.clearnext
    mov dword[esi],0
    add esi,4
    dec ecx
    jnz .clearnext
    mov esi,xtravbuf+32
.nomosaic

    ; esi = pointer to video buffer
    ; edi = pointer to vram
    ; [.mode7xadder] = dword value to add to x value (decimal between 7 & 8bit)
    ; [.mode7yadder] = dword value to add to y value (decimal between 7 & 8bit)
    ; [.mode7xpos]   = dword value of x position, decimal between 7 & 8bit
    ; [.mode7xpos+1] = word value of x position
    ; [.mode7ypos]   = dword value of y position, decimal between 7 & 8bit
    ; [.mode7ypos+1] = word value of y position
    xor ebx,ebx
    xor edx,edx
    xor ecx,ecx
    mov dword[mmode7xadd2],800h
    mov byte[mmode7xinc],2
    mov byte[mmode7xincc],0
    test dword[mmode7xadder],80000000h
    jz .noneg
    mov dword[mmode7xadd2],-800h
    mov byte[mmode7xinc],-2
    mov byte[mmode7xincc],0FEh
.noneg
    mov dword[mmode7yadd2],800h
    mov byte[mmode7yinc],1
    test dword[mmode7yadder],80000000h
    jz .noneg2
    mov dword[mmode7yadd2],-800h
    mov byte[mmode7yinc],-1
.noneg2
    ret

%macro Mode7Startup 0
    call Mode7Startup16b

    cmp byte[ngwinen],1
    je near .drawmode7win

    mov edi,[vram]
    cmp dword[mmode7xadder],7F0h
    jg near .nextval3
    cmp dword[mmode7xadder],-7F0h
    jl near .nextval3
    cmp dword[mmode7yadder],7F0h
    jg near .nextval3
    cmp dword[mmode7yadder],-7F0h
    jl near .nextval3
%endmacro

%macro Mode7MidRoutines 0

.drawmode7win
.domosaicw
    mov ebx,[mmode7xrpos]
    mov [mode7xrpos],ebx
    mov ebx,[mmode7yrpos]
    mov [mode7yrpos],ebx
    mov ebx,[mmode7xadder]
    mov [mode7xadder],ebx
    mov ebx,[mmode7yadder]
    mov [mode7yadder],ebx
    mov ebx,[mmode7xpos]
    mov [mode7xpos],ebx
    mov ebx,[mmode7ypos]
    mov [mode7ypos],ebx
%endmacro


NEWSYM ProcessMode7ngwin16b
    mov ecx,[ngcwinptr]
    mov ecx,[ecx]
    or ecx,ecx
    jz near .winb
    cmp ecx,[ngwleft]
    jae .alldisplay
    sub [ngwleft],ecx
    mov dword[ngwleftb],ecx
    xor ecx,ecx
    mov eax,[mode7xrpos]
    ret
.alldisplay
    mov ecx,[ngwleft]
    mov dword[ngwleftb],ecx
    mov dword[ngwleft],0
    xor ecx,ecx
    mov eax,[mode7xrpos]
    ret
.winb
NEWSYM ProcessMode7ngwinB16b
    add dword[ngcwinptr],4
    mov ecx,[ngcwinptr]
    mov ecx,[ecx]
    cmp ecx,[ngwleft]
    jae near .finishmode7

;    mov ecx,[ngwleft]
;    mov dword[ngwleftb],ecx
;    mov dword[ngwleft],0
;    xor ecx,ecx
;    mov eax,[mode7xrpos]
;    ret

    sub [ngwleft],ecx
    or ecx,ecx
    jz .noclip
    mov [pixelsleft],ecx
.nextvalngw
    test byte[mode7xrpos+1],0F8h
    jnz near .rposoffx
.nextposx
    test byte[mode7yrpos+1],0F8h
    jnz near .rposoffy
.nextposy

    mov eax,[mode7xadder]
    add [mode7xrpos],eax
    mov eax,[mode7yadder]
    sub [mode7yrpos],eax
    add esi,2
    dec dword[pixelsleft]
    jnz near .nextvalngw
.noclip
    add dword[ngcwinptr],4
    jmp ProcessMode7ngwin16b
.finishmode7
    mov dword[ngwleft],0
    mov dword[ngwleftb],0
    ret

.rposoffx
    mov eax,[m7xaddof]
    sub [mode7xrpos],eax
    add bl,[m7xaddof2]
    test byte[mode7xrpos+1],0F8h
    jz .noaddstuff
    add bl,[mmode7xinc]
    mov eax,[mmode7xadd2]
    sub [mode7xrpos],eax
.noaddstuff
    xor ecx,ecx
    mov cl,[vrama+ebx]
    shl ecx,7
    lea edi,[ecx+vrama]
    jmp .nextposx
.rposoffy
    mov eax,[m7yaddof]
    add dword[mode7yrpos],eax
    sub bh,[m7yaddof2]
    test byte[mode7yrpos+1],0F8h
    jz .noaddstuff2
    sub bh,[mmode7yinc]
    mov eax,[mmode7yadd2]
    add dword[mode7yrpos],eax
.noaddstuff2
    and ebx,07FFFh
    xor ecx,ecx
    mov cl,[vrama+ebx]
    shl ecx,7
    lea edi,[ecx+vrama]
    jmp .nextposy

NEWSYM ProcessMode7ngwinC16b
    mov ecx,[ngcwinptr]
    mov ecx,[ecx]
    or ecx,ecx
    jz near .winb
    cmp ecx,[ngwleft]
    jae .alldisplay
    sub [ngwleft],ecx
    mov dword[ngwleftb],ecx
    xor ecx,ecx
    mov eax,[mode7xpos]
    ret
.alldisplay
    mov ecx,[ngwleft]
    mov dword[ngwleftb],ecx
    mov dword[ngwleft],0
    xor ecx,ecx
    mov eax,[mode7xpos]
    ret
.winb
NEWSYM ProcessMode7ngwinD16b
    add dword[ngcwinptr],4
    mov ecx,[ngcwinptr]
    mov ecx,[ecx]
    cmp ecx,[ngwleft]
    jae near .finishmode7
    sub [ngwleft],ecx
    or ecx,ecx
    jz .noclip
.nextvalngw
.nextvalr
;    cmp byte[switchtorep3],1
;    je .nextposy
;    test byte[mode7xpos+1],0F8h
;    jnz near .rposoffx
.nextposx
;    test byte[mode7ypos+1],0F8h
;    jnz near .rposoffy
.nextposy
    mov eax,[mode7xadder]
    add [mode7xpos],eax
    mov eax,[mode7yadder]
    sub [mode7ypos],eax
    add esi,2
    dec ecx
    jnz near .nextvalngw
.noclip
    add dword[ngcwinptr],4
    jmp ProcessMode7ngwin16b
.finishmode7
    mov dword[ngwleft],0
    mov dword[ngwleftb],0
    ret
.rposoffx
    mov al,[mmode7xinc]
    mov edi,[vram]
    add [mmode7ptr],al
    mov cl,byte[mmode7xincc]
    cmp byte[mmode7ptr],cl
    je .roffx
.roffxretb
    mov ebx,[mmode7ptr]
    xor ecx,ecx
    mov cl,[edi+ebx]
    mov eax,[mmode7xadd2]
    shl ecx,7
    sub [mode7xrpos],eax
    add edi,ecx
    jmp .nextvalr
.roffx
    mov byte[switchtorep3],1
    jmp .roffxretb
.rposoffy
    mov al,[mmode7yinc]
    mov edi,[vram]
    sub [mmode7ptr+1],al
    js .roffy
.roffyretb
    mov ebx,[mmode7ptr]
    xor ecx,ecx
    mov cl,[edi+ebx]
    mov eax,[mmode7yadd2]
    shl ecx,7
    add [mode7yrpos],eax
    add edi,ecx
    jmp .nextposx
.roffy
    mov byte[switchtorep3],1
    jmp .roffyretb

%macro ProcessBuildWindow16b 1
    mov dword[ngwinen],0
    test byte[esi+ebx+%1*256],0Ah
    jz %%nowindowing
    push eax
    push ebx
    mov al,[winlogicaval+ebx*2]
    shr al,%1*2
    and al,03h
    mov [nglogicval],al
    mov eax,ebx
    add ebx,%1*256
    call BuildWindow
    cmp dword[ngwintable],0
    je %%zero
    dec dword[ngwintable]
    jmp %%notzero
%%zero
    dec dword[ngwintable+4]
%%notzero
    pop ebx
    pop eax
    mov dword[ngcwinptr],ngwintable
%%nowindowing
%endmacro

%macro Mode7Process 3
    mov dword[mtemp],256
    test byte[mode7set],80h
    jnz near %%norep2

    mov eax,[mmode7xpos]
    and eax,7FFh
    mov [mmode7xrpos],eax
    mov eax,[mmode7ypos]
    and eax,7FFh
    mov [mmode7yrpos],eax

    ; get tile data offset into edi
    mov ebx,[mmode7ypos+1]
    mov eax,[mmode7xpos+1]
    shl ebx,5
    shr eax,3
    and ebx,07FF8h
    shl al,1
    mov bl,al
    mov edi,[vram]
    xor ch,ch
    mov [mmode7ptr],ebx
    mov cl,[edi+ebx]
    shl ecx,7
    add edi,ecx

    mov eax,[mmode7xrpos]
    mov ebx,[mmode7ptr]
    jmp %%nextval
    ALIGN16
%%nextval
    test ah,08h
    jnz near %%rposoffx
%%nextposx
    test byte[mmode7yrpos+1],08h
    jnz near %%rposoffy
%%nextposy
    mov ch,ah
    mov edx,[mmode7yadder]
    mov cl,byte[mmode7yrpos+1]
    sub dword[mmode7yrpos],edx
    xor edx,edx
    mov dl,[mode7tab+ecx]
    add eax,[mmode7xadder]
    mov dl,[edi+edx]
    %1
    dec dword[mtemp]
    jnz near %%nextval
    jmp %%finishmode7

%%rposoffx
    add bl,[mmode7xinc]
    xor ecx,ecx
    mov cl,[vrama+ebx]
    shl ecx,7
    sub eax,[mmode7xadd2]
    lea edi,[ecx+vrama]
    jmp %%nextposx

%%rposoffy
    sub bh,[mmode7yinc]
    and ebx,07FFFh
    xor ecx,ecx
    mov cl,[vrama+ebx]
    mov edx,[mmode7yadd2]
    shl ecx,7
    add dword[mmode7yrpos],edx
    lea edi,[ecx+vrama]
    jmp %%nextposy

%%finishmode7
    xor eax,eax
    mov dh,byte[curmosaicsz]
    cmp dh,1
    jne near %2
    ret

;**********************************************************
; Mode 7, no repetition mode

⌨️ 快捷键说明

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