/* 3D scroll rutine */
/* mapv.c           */
/*    -> fz3.exp    */


asm("
.text
 
.align 4 
.globl _map3d 
_map3d:
    pushl %ebp 
    movl %esp,(map3d_esp) 
    subl $24,%esp 
      
    /**/
    movl %edi,(map3d_edi) 
    movl %esi,(map3d_esi) 
    movl %ebx,(map3d_ebx) 
    movw %gs,%bx 
    movw %bx,(map3d_gs) 
    /**/
      
    /* vram */
    pushl $0x104 
    popl %gs 
    /* write adds */
    movl 32(%esp),%edi 
");
#ifdef LARGE_SCREEN
asm("
    imull $112,44(%esp),%edx
");
#else
asm("
    imull $56,44(%esp),%edx 
");
#endif
asm("
    movl %edx,8(%esp) 
    movl $0,4(%esp) 
");
#ifdef LARGE_SCREEN
asm("
    movl $112,12(%esp)       /* SY */
");
#else
asm("      
    movl $56,12(%esp)       /* SY */
");
#endif
asm("
    /* roop 1 */
    mp1:
        movl 8(%esp),%eax 
        sall $4,%eax 
        movl _table+8(%eax),%edx 
        movl %edx,20(%esp) 
        movl _table+12(%eax),%edx 
        sall $10,%edx 
        movl %edx,16(%esp) 
        movl 36(%esp),%esi 
        /**/
        addl _table(%eax),%esi 
        /**/
        movl 40(%esp),%edx 
        addl _table+4(%eax),%edx 
        movl %edx,%ecx 
        sall $10,%ecx 
        subl 20(%esp),%esi 
        subl 16(%esp),%ecx 
        incl 8(%esp) 
          
        /* vram adds align 512 */
        andl $0xfffffe00,%edi 
");
#ifdef SPEED_SLOW
asm("
        addl $0x208,%edi            /* LSHIFT */
        movl $16,(map3d_roop_count) /* SX / 4 */
");
#else
asm("
        addl $0x210,%edi            /* LSHIFT */
        movl $32,(map3d_roop_count) /* SX / 4 */
");
#endif
asm("
        movl 20(%esp),%ebp 
        movl 16(%esp),%ebx 

        mp2:
            movl %esi,%eax 
            andl $1047552,%eax 
            movl %ecx,%edx 
            andl $267386880,%edx 
            orl %edx,%eax 
            sarl $10,%eax 
            movw _gr1(,%eax,2),%dx 
            movw %dx,%gs:(,%edi,2) 
            addl %ebp,%esi
            addl %ebx,%ecx
              
            movl %esi,%eax 
            andl $1047552,%eax 
            movl %ecx,%edx 
            andl $267386880,%edx 
            orl %edx,%eax 
            sarl $10,%eax 
            movw _gr1(,%eax,2),%dx 
            movw %dx,%gs:2(,%edi,2) 
            addl %ebp,%esi
            addl %ebx,%ecx
              
            movl %esi,%eax 
            andl $1047552,%eax 
            movl %ecx,%edx 
            andl $267386880,%edx 
            orl %edx,%eax 
            sarl $10,%eax 
            movw _gr1(,%eax,2),%dx 
            movw %dx,%gs:4(,%edi,2) 
            addl %ebp,%esi
            addl %ebx,%ecx
              
            movl %esi,%eax 
            andl $1047552,%eax 
            movl %ecx,%edx 
            andl $267386880,%edx 
            orl %edx,%eax 
            sarl $10,%eax 
            movw _gr1(,%eax,2),%dx 
            movw %dx,%gs:6(,%edi,2) 
            addl %ebx,%ecx 
            addl %ebp,%esi 

            addl $4,%edi
            decl (map3d_roop_count) 
            jnz mp2 
         
        decl 12(%esp)
        jnz mp1 
     
    movl 4(%esp),%eax 
    /**/
    movw (map3d_gs),%bx 
    movw %bx,%gs 
    movl (map3d_ebx),%ebx 
    movl (map3d_esi),%esi 
    movl (map3d_edi),%edi 
    /**/
    movl (map3d_esp),%esp 
    popl %ebp 
    ret


/* 各レジスタを退避させる場所 */
/* push / pop の代わり        */

.align 4 
.lcomm map3d_edi,4 
.lcomm map3d_esi,4 
.lcomm map3d_ebx,4 

.lcomm map3d_esp,4 
.lcomm map3d_gs,2 

/* 変数格納域 */

.align 4  
.lcomm map3d_roop_count,4 

");
