标题:精华区代码Revision-C版本[系列六-bottom half]
只看楼主
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
结帖率:100%
 问题点数:0 回复次数:0 
精华区代码Revision-C版本[系列六-bottom half]
程序代码:
;----------------------------------------------------------------------
;每局的开始预处理
gao_build    macro            ;static inlne gao_build();
   
    local    gao_build_repeat
;
    push    ax
    push    bx
    push    cx
    push    dx
;
    mov    [x],map_x
    mov    [y],map_y          ;g_xy.x = map_x; g_xy.y = map_y;
    inc    [x]
    inc    [y]                ;g_xy.x++; g_xy.y++;
    mov     al,18
    add    [x],al
    add    [y],al             ;g_xy.x += 18; g_xy.y += 18;
    mov    ax,map_size
    mov    bx,map_size
    mul    bx
    mov    cx,ax              ;uint16_t i = map_size*map_size;
    dec    cx                 ;i--;
;                             ;uint8_t *p_map;
gao_build_repeat:
    mov    ax,cx
    dec    ax                 ;i--;
    mov    bx,offset map      ;p_map = map;
    add    bx,ax              ;p_map += i;
    mov    [bx],0000h         ;*(uint16_t*)p_map = 0;
    loop    gao_build_repeat  ;while (i--);
;
    .if    [map_over]==1
        add     [person1],1   ;if(map_over == 1) person_t[0]++;
    .elseif    [map_over]==2
        add    [person2],1    ;else if (map_over == 2) person_t[1]++;
    .endif
;
    .if    [person_first]==2        ;if (person_first == 2) {
        mov    [person_first],1     ;person_first = 1;
        mov    [person],1           ;person = 1;
        mov    [map_over],6         ;map_over = 6;
    .else                           ;} else {
        mov    [person_first],2     ;person_first = 2;
        mov    [person],2           ;person = 2;
        mov    [map_over],7         ;map_over = 7;
    .endif                          ;}
;
    pop    dx
    pop    cx
    pop    bx
    pop    ax
endm

;----------------------------------------------------------------------
;将两个人的胜利局数都清零,并且做一些简单初始化
gao_init    macro                  ;static inline gao_init();

    push    ax
    push    bx
    push    cx
    push    dx
;
    mov    ax,@data           
    mov    ds,ax
    mov    [person1],0            ;person1 = 0;
    mov    [person2],0            ;person2 = 0;
    mov    [person_first],2       ;person_first = 2;
;
    pop    dx
    pop    cx
    pop    bx
    pop    ax
endm

;----------------------------------------------------------------------
;结束程序
gao_exit    macro

    push    ax
    push    bx
    push    cx
    push    dx
;
    gao_clear_screen    07h,0,0,49,79    ;clrscr(); /*Pseudo-code*/
    mov    ah,4ch
    int    21h                           ;exit(0);
;
    pop    dx
    pop    cx
    pop    bx
    pop    ax
endm

;----------------------------------------------------------------------
;输入函数
;辅助函数 1 , 坐标转换
gao_give_change    macro    state,x,y,xx,yy       
;static inline gao_give_change(uint16_t state, struct point xy, struct point x2y2);

    push    ax
    push    bx
    push    cx
    push    dx
;
    mov    al,x                ;struct point _xy; _xy.x = xy.x;
    sub    al,map_x            ;_xy.x -= map_x;
    mov    ah,0
    mov    bl,2
    div    bl                  ;_xy.x /= 2;
    mov    xx,al               ;x2y2.x = _xy.x;
    mov    ah,0
    mov    bl,map_size
    mul    bl
;
    mov    cx,ax               ;uint16_t state = _xy.x * map_size;
;
    mov    al,y               
    mov    ah,0                ;_xy.y = xy.y;
    sub    al,map_y
    mov    bl,2
    div    bl                  ;_xy.y /= 2;
    mov    yy,al               ;x2y2.y = _xy.y;
    mov    ah,0
    add    cx,ax               ;state += _xy.y;       
    mov    state,cx            ;state = state;
;
    pop    dx
    pop    cx
    pop    bx
    pop    ax
endm


;辅助函数 2 - 1 , 坐标转换
gao_judge_over_change macro    xx,x,y      
;static inline gao_judge_over_change(uint16_t xx, struct point xy);
   
    push    ax
    push    bx
    push    cx
    push    dx
;   
    mov    bl,map_size           
    mov    al,x                ;struct point _xy; _xy.x = xy.x;
    mov    ah,0
    mul    bl               
    mov    bl,y                ;_xy.y = xy.y;
    mov    bh,0
    add    ax,bx
    mov    xx,ax               ;xx = _xy.x * map_size + _xy.y;
;
    pop    dx
    pop    cx
    pop    bx
    pop    ax
endm


;辅助函数 2 - 2 , 计算连子数量
gao_judge_over_add macro    t,x,y,change_x,change_y,person   
           
;static inline gao_judge_over_add(uint8_t t, struct point xy, uint8_t change_x, uint8_t change_y, uint8_t person);
   
    local    gao_judge_over_add_end
;
    push    ax
    push    bx
    push    cx
    push    dx
;
    mov    dl,map_size
    dec    dl                    ;uint8_t size = map_size - 1;
;
    .while    [nothing1]==0      ;while (nothing1 == 0) {
       
        .if    x==0               
            .break    .if    change_x==0
        .endif                   ;if (xy.x == 0 && change_x == 0) break; 

        .if    y==0
            .break    .if    change_y==0
        .endif                   ;if (xy.y == 0 && change_y == 0) break;

        .if    x==dl
            .break    .if    change_x==1
        .endif                   ;if (xy.x == size && change_x == 1) break;

        .if    y==dl
            .break    .if    change_y==1
        .endif                   ;if (xy.y == size && change_y == 1) break;

        .if    change_x==1
            inc    x             ;if (change_x == 1) xy.x++;
        .elseif    change_x==0   
            dec    x             ;if (change_x == 0) xy.x--;
        .endif    

        .if    change_y==1
            inc    y             ;if (change_y == 1) xy.y++;
        .elseif    change_y==0   
            dec    y             ;if (change_y == 0) xy.y--;
        .endif    

        gao_judge_over_change    [chess_state],x,y
   
        mov    bx,offset map
        mov    ax,[chess_state]
        add    bx,ax               
        mov    bl,[bx]                ;uint8_t man = map[*(uint16_t*)chess_state];
   
        .break    .if    bl!=person   ;if (man != person) break;   
        inc    t                      ;t++;
    .endw                             ;}

gao_judge_over_add_end:
;
    pop    dx
    pop    cx
    pop    bx
    pop    ax
endm

;辅助函数 2 , 判断是否完满
gao_judge_over    macro    jud,x,y,person           
;static inline gao_judge_over(bool jud, struct point xy, uint8_t person); 

    local    gao_judge_over_end
;
    push    ax
    push    bx
    push    cx
    push    dx
;
    mov    [nothing1],0                ;nothing[0] = 0;
    mov    [nothing2],1                ;nothing[1] = 1;
    mov    [nothing3],2                ;nothing[2] = 2;
;
    mov    [chess_t],1                 ;chess_t = 1;
    mov    ah,x
    mov    al,y                        ;struct point _xy = xy;
    mov    [help_x],ah
    mov    [help_y],al                 ;help_x = _xy.x; help_y = _xy.y;
    gao_judge_over_add    [chess_t],[help_x],[help_y],[nothing3],[nothing1],person
    mov    [help_x],ah
    mov    [help_y],al                ;help_x = _xy.x; help_y = _xy.y;
    gao_judge_over_add    [chess_t],[help_x],[help_y],[nothing3],[nothing2],person
    .if    [chess_t]>=5               ;if (chess_t >= 5)
        mov    jud,2                  ;jud = (bool)2;
        jmp    gao_judge_over_end     ;goto gao_judge_over_end;
    .endif
;
    mov    [chess_t],1                ;chess_t = 1;
    mov    ah,x
    mov    al,y
    mov    [help_x],ah
    mov    [help_y],al                ;help_x = _xy.x; help_y = _xy.y;
    gao_judge_over_add    [chess_t],[help_x],[help_y],[nothing1],[nothing3],person
    mov    [help_x],ah
    mov    [help_y],al                ;help_x = _xy.x; help_y = _xy.y;
    gao_judge_over_add    [chess_t],[help_x],[help_y],[nothing2],[nothing3],person
    .if    [chess_t]>=5               ;if (chess_t >= 5)
        mov    jud,2                  ;jud = (bool)2;               
        jmp    gao_judge_over_end     ;goto gao_judge_over_end;
    .endif
;
    mov    [chess_t],1                ;ignore same c source code
    mov    ah,x
    mov    al,y
    mov    [help_x],ah
    mov    [help_y],al
    gao_judge_over_add    [chess_t],[help_x],[help_y],[nothing1],[nothing1],person
    mov    [help_x],ah
    mov    [help_y],al
    gao_judge_over_add    [chess_t],[help_x],[help_y],[nothing2],[nothing2],person
    .if    [chess_t]>=5
        mov    jud,2   
        jmp    gao_judge_over_end
    .endif
;
    mov    [chess_t],1
    mov    ah,x
    mov    al,y
    mov    [help_x],ah
    mov    [help_y],al
    gao_judge_over_add    [chess_t],[help_x],[help_y],[nothing1],[nothing2],person
    mov    [help_x],ah
    mov    [help_y],al
    gao_judge_over_add    [chess_t],[help_x],[help_y],[nothing2],[nothing1],person
    .if    [chess_t]>=5
        mov    jud,2   
        jmp    gao_judge_over_end
    .endif
;
gao_judge_over_end:   
;
    pop    dx
    pop    cx
    pop    bx
    pop    ax
endm

;辅助函数 3 , 判断复杂情况
gao_give_judge    macro    jud,x,y,person           
;static inline gao_give_judge(bool jud, struct point xy, uint8_t person);

    local    gao_give_judge_end
;
    push    ax
    push    bx
    push    cx
    push    dx
;
    mov        bx,offset map
    gao_give_change    [chess_state],x,y,[chess_x],[chess_y]
    mov        ax,[chess_state]
    add        bx,ax
    mov        al,[bx]              ;uint8_t man = map[*(uint16_t*)chess_state];
    .if    al!=0                    ;if (man)
        mov    jud,1                ;jud = true;
        jmp    gao_give_judge_end   ;goto gao_give_judge_end;
    .endif
;
    mov    al,[person]              ;man = person;
    mov    [bx],al                  ;map[*(uint16_t*)chess_state] = man;

    mov    jud,0                    ;jud = false;
    gao_judge_over    jud,[chess_x],[chess_y],[person]
    .if    jud!=0                   ;if (jud != false)
        mov    jud,2                ;jud = (bool)2;
        jmp    gao_give_judge_end   ;goto gao_give_judge_end;
    .endif
;
gao_give_judge_end:
;
    pop    dx
    pop    cx
    pop    bx
    pop    ax
endm

;辅助函数 4 , 判断能不能放子
gao_give    macro    jud,x,y,person           
;static inline gao_give(bool jud, struct point xy, uint8_t person);
    local    gao_give_end
;
    push    ax
    push    bx
    push    cx
    push    dx
;
    mov    jud,0                    ;jud = false;
    gao_judge    jud,x,y,map_x1,map_y1,map_x_end,map_y
;       
    .if    jud==1                   ;if (jud == true)
        mov    [map_over],4         ;map_over = 4;
        jmp    gao_give_end         ;goto gao_give_end;
    .endif
;
    mov    jud,0                    ;jud = false;
    gao_judge    [jud],x,y,map_x,map_y_end,map_x2,map_y2
;       
    .if    jud==1                   ;if (jud == true)
        mov    [map_over],4         ;map_over = 4;
        jmp    gao_give_end         ;goto gao_give_end;
    .endif
;
    mov    jud,0                    ;jud = false;
    gao_give_judge    jud,x,y,person
;
    .if    jud==1                   ;if (jud == true)
        mov    [map_over],4         ;map_over = 4;
        jmp    gao_give_end         ;goto gao_give_end;
    .elseif    jud==2               ;else if (jud == (bool)2)
        mov    bl,person
        mov    [map_over],bl        ;map_over = person;
        jmp    gao_give_end         ;goto gao_give_end;
    .else
        mov    [map_over],5         ;map_over = 5;
        .if    person==1            ;if (person == 1)
            mov    person,2         ;person = 2;
        .else                       ;else
            mov    person,1         ;person = 1;
        .endif
    .endif   
;
gao_give_end:
   
    pop    dx
    pop    cx
    pop    bx
    pop    ax
endm
    

;主输入函数

gao_scanf    macro    x,y         ;static inline gao_scanf(struct point xy);
   
    local    gao_scanf_end
;
    push    ax
    push    bx
    push    cx
    push    dx
;
    mov    dh,x
    mov    dl,y                   ;struct point _xy = xy;
    mov    ah,2
    mov    bh,0
    int    10h                    ;setcursor(_xy); /*Pseudo-code*/
;
    mov    ah,0h
    int    16h                    ;uint8_t scan_key = get_scan_code(); /*Pseudo-code*/
    mov    bl,2                   ;uint8_t step = 2;                   
;                                 ;switch (scan_key) {
    .if    ah==4bh               
        sub    y,bl               ;case SCAN_KEY_LEFT: xy.y -= step; break;
    .elseif ah==4dh
        add    y,bl               ;case SCAN_KEY_RIGHT: xy.y += step; break;
    .elseif    ah==48h
        sub    x,bl               ;case SCAN_KEY_UP: xy.x -= step; break;
    .elseif    ah==50h
        add    x,bl               ;case SCAN_KEY_DOWN: xy.x += step; break;
    .elseif    ah==01h            ;case SCAN_KEY_ESC: gao_exit(); break;
        gao_exit           
;                                  ;case SCAN_KEY_ENTER:
    .elseif    (ah==1ch)||(ah==39h);case SCAN_KEY_SPACE:
;
        gao_judge        [jud],x,y,person1_x1,person1_y1,person1_x2,person1_y2
            .if    [jud]==1        ;if (jud == true)
                mov    [map_over],2    ;map_over = 2;
            .endif
;
        gao_judge        [jud],x,y,person2_x1,person2_y1,person2_x2,person2_y2
            .if        [jud]==1    ;if (jud == true)
                mov    [map_over],1    ;map_over = 1;
            .endif
;
        gao_judge        [jud],x,y,answer_x1,answer_y1,answer_x2,answer_y2
            .if    [jud]==1        ;if (jud == true)
                mov    [map_over],3    ;map_over = 3;
            .endif
;
        gao_judge        [jud],x,y,end_x1,end_y1,end_x2,end_y2
            .if    [jud]==1        ;if (jud == 1)
                    gao_exit    ;gao_exit();
            .endif
;
        gao_judge        [jud],x,y,map_x1,map_y1,map_x2,map_y2
           
            .if    [jud]==1        ;if (jud == 1)               
                gao_give    [jud],x,y,[person]
            .endif
;
    .endif
                                  ;default:
                                  ;}
;
gao_scanf_end:
;
    mov    bl,2                   ;step = 2;

    .if    x<2
        add    x,bl               ;if (xy.x < 2) xy.x += step;
    .endif    

    .if    y<2
        add    y,bl               ;if (xy.y < 2) xy.y += step;
    .endif

    .if    x>47
        sub    x,bl               ;if (xy.x > 47) xy.x -= step;
    .endif

    .if    y>77
        sub    y,bl               ;if (xy.y > 47) xy.y -= step;
    .endif
;
    pop    dx
    pop    cx
    pop    bx
    pop    ax
endm

;----------------------------------------------------------------------
;主函数    

    .code
main    proc     far             void main();
   
    gao_init                    ;gao_init();
;
    mov    cx,0
        .while cx==0            ;while(1) {
       
        gao_build               ;gao_build();
        gao_print               ;gao_print();
;
        .while    [map_over]>3  ;while (map_over > 3) {   
            gao_scanf [x],[y]   ;gao_scanf(x, y);
            gao_print           ;gao_print();
        .endw                   ;}
    .endw                       ;}
;
    gao_exit                    ;gao_exit();
;
main    endp
        end     main    

;----------------------------------------------------------------------
系列六的bottom half
搜索更多相关主题的帖子: bottom local 
2011-11-30 15:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-356596-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029821 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved