home *** CD-ROM | disk | FTP | other *** search
/ Aztec Shareware Collection / ARCADE_1.ISO / snarf / mandir.asm < prev    next >
Assembly Source File  |  1988-01-16  |  6KB  |  466 lines

  1. page 60,132
  2. title TFMISC --- MISCELLANEOUS ASSEMBLY ROUTINES FOR TIGER FOX
  3. ;
  4. debug    equ    0
  5. ;
  6. _text    segment    byte public 'code'
  7. _text    ends
  8. _data    segment    word public 'data'
  9. _data    ends
  10. const    segment    word public 'const'
  11. const    ends
  12. _bss    segment    word public 'bss'
  13. _bss    ends
  14. ;
  15.         extrn    _flabel:near
  16. ;
  17.         public    _set_bug_loc
  18.         public    _bug_dir
  19.         public    _man_dirs
  20.         public    _man_dist
  21. ;
  22. dgroup    group    const, _bss, _data
  23.     assume    cs:_text, ds:dgroup, ss:dgroup, es:dgroup
  24. ;
  25. _data    segment    word public 'data'
  26. ;
  27. wmaze        db    820 dup (?)
  28. stack1        db    400 dup (0)
  29. stack2        db    400 dup (0)
  30. mandist        dw    ?
  31. mandir        db    ?
  32. stk2ptr        dw    ?
  33. stk1ptr        dw    ?
  34. buglocs        dw    20 dup (-2)
  35. bugdirs        dw    20 dup (?)
  36. ;
  37. _data    ends
  38. ;
  39. ;
  40. ;
  41. _text    segment
  42. ;
  43. ;
  44. ; man_dirs(&field, man-field-index);
  45. ;
  46. _man_dirs:
  47.     push    bp
  48.     mov    bp,sp
  49.     push    si
  50.     push    di
  51.     call    mansub2
  52.     pop    di
  53.     pop    si
  54.     pop    bp
  55.     ret
  56. ;
  57. ; man_dist(&field, loc x, loc y, man x, man y);
  58. ;
  59. _man_dist:
  60.     push    bp
  61.     mov    bp,sp
  62.     push    si
  63.     push    di
  64.     call    mansub1
  65.     mov    ax,mandist
  66.     pop    di
  67.     pop    si
  68.     pop    bp
  69.     ret
  70. ;
  71. ; bug_dir(n);
  72. ;
  73. _bug_dir:
  74.     push    bp
  75.     mov    bp,sp
  76.     mov    bx,[bp+4]
  77.     shl    bx,1
  78.     mov    ax,[bx+bugdirs]
  79.     pop    bp
  80.     ret
  81. ;
  82. ; set_bug_loc(n, bug-field-index);
  83. ;
  84. _set_bug_loc:
  85.     push    bp
  86.     mov    bp,sp
  87.     lea    ax,wmaze
  88.     mov    ax,[bp+6]
  89.     mov    bx,[bp+4]
  90.     shl    bx,1
  91.     mov    [bx+buglocs],ax
  92.     pop    bp
  93.     ret
  94. ;
  95. ;
  96. mansub1:
  97.     cld
  98.     mov    mandist,1
  99.     mov    mandir,-1
  100.     mov    si,[bp+4]        ; get maze address
  101.     lea    di,wmaze
  102.     mov    cx,410
  103.     rep    movsw
  104.  
  105.     mov    ax,[bp+12]        ; get man y
  106.     mov    bl,41
  107.     mul    bl
  108.     add    ax,[bp+10]
  109.     lea    si,wmaze
  110.     add    si,ax
  111.     mov    byte ptr [si],30h    ; place man flag
  112.  
  113.     mov    ax,[bp+8]        ; get ptr to bug location
  114.     mov    bl,41
  115.     mul    bl
  116.     add    ax,[bp+6]
  117.     lea    si,wmaze
  118.     add    si,ax            ; si = search start point
  119.  
  120.     mov    byte ptr [si],1        ; put brick at bug's start point
  121.  
  122.     lea    ax,stack1        ; init stacks
  123.     mov    stk1ptr,ax
  124.     lea    ax,stack2
  125.     mov    stk2ptr,ax
  126.  
  127.     mov    dh,0            ; seed stack1 with first 4 dirs
  128.     mov    di,si
  129.     inc    di
  130.     call    chkmovi
  131.  
  132.     mov    dh,1
  133.     mov    di,si
  134.     sub    di,41
  135.     call    chkmovi
  136.  
  137.     mov    dh,2
  138.     mov    di,si
  139.     dec    di
  140.     call    chkmovi
  141.  
  142.     mov    dh,3
  143.     mov    di,si
  144.     add    di,41
  145.     call    chkmovi
  146. whilp10:
  147.     lea    si,stack1        ; ripple search out from there
  148.     cmp    si,stk1ptr
  149.     mov    si,stk1ptr
  150.     jz    whilp20
  151.     dec    si
  152.     mov    dh,[si]
  153.     dec    si
  154.     dec    si
  155.     mov    stk1ptr,si
  156.     mov    di,[si]
  157.  
  158.     push    di
  159.     inc    di
  160.     call    chkmov
  161.     pop    di
  162.  
  163.     push    di
  164.     sub    di,41
  165.     call    chkmov
  166.     pop    di
  167.  
  168.     push    di
  169.     dec    di
  170.     call    chkmov
  171.     pop    di
  172.  
  173.     add    di,41
  174.     call    chkmov
  175.     cmp    mandir,-1
  176.     jz    whilp10
  177. exitmandir:
  178.     ret
  179. whilp20:
  180.     inc    mandist
  181.     lea    si,stack2
  182.     lea    di,stack1
  183.     mov    cx,stk2ptr
  184.     sub    cx,si
  185.     jz    exitmandir
  186.     mov    stk2ptr,si
  187.     rep    movsb
  188.     mov    stk1ptr,di
  189.     jmp    whilp10
  190. ;
  191. ; di=maze ptr    dh=original direction
  192. ;
  193. chkmov:
  194.     cmp    byte ptr [di],0        ; empty?
  195.     jz    cmiyes            ; jif yes
  196.     cmp    byte ptr [di],30h    ; man?
  197.     jnz    cmino            ; jif no
  198.     mov    mandir,dh
  199. cmiyes:
  200.     mov    byte ptr [di],1        ; mark as been there
  201.     mov    ax,di
  202.     mov    di,stk2ptr
  203.     stosw
  204.     mov    al,dh
  205.     stosb
  206.     mov    stk2ptr,di
  207. cmino:
  208.     ret
  209. ;
  210. ;
  211. ;
  212. chkmovi:
  213.     call    chkmov
  214.     lea    di,stack2
  215.     cmp    di,stk2ptr
  216.     jz    cmino
  217.     mov    stk2ptr,di
  218.     mov    ax,[di]
  219.     mov    bx,stk1ptr
  220.     mov    [bx],ax
  221.     inc    bx
  222.     inc    bx
  223.     mov    al,[di+2]
  224.     mov    [bx],al
  225.     inc    bx
  226.     mov    stk1ptr,bx
  227.     ret
  228. ;
  229. ;
  230. ;
  231. ;
  232. ;
  233. mansub2:
  234.     cld
  235.     mov    si,[bp+4]        ; get maze address
  236.     lea    di,wmaze
  237.     mov    cx,410
  238.     rep    movsw
  239.  
  240.     lea    di,bugdirs        ; clear bugdirs table
  241.     mov    cx,20
  242.     mov    ax,-1
  243.     rep    stosw
  244.  
  245.     lea    si,buglocs
  246.     lea    bx,wmaze
  247.     mov    al,50h            ; bug flag
  248. ms21:
  249.     mov    di,[si]            ; get ptr to bug location
  250.     inc    si
  251.     inc    si
  252.     cmp    di,-2            ; end of list?
  253.     jz    ms22            ; jif yes
  254.     or    di,di            ; bug exist?
  255.     jz    ms26
  256.     add    di,bx
  257.     mov    [di],al            ; set bug location in maze
  258. ms26:
  259.     inc    al            ; bump flag to next bug number
  260.     jmp    ms21
  261. ms22:
  262.     lea    si,wmaze
  263.     add    si,[bp+6]            ; si = search start point
  264.     mov    byte ptr [si],1        ; put brick at man's start point
  265.  
  266.     lea    ax,stack1        ; init stacks
  267.     mov    stk1ptr,ax
  268.     lea    ax,stack2
  269.     mov    stk2ptr,ax
  270.  
  271.     mov    dx,2            ; seed stack1 with first 4 dirs
  272.     mov    di,si
  273.     inc    di
  274.     call    chkmovi2
  275.  
  276.     mov    dx,3
  277.     mov    di,si
  278.     sub    di,41
  279.     call    chkmovi2
  280.  
  281.     mov    dx,0
  282.     mov    di,si
  283.     dec    di
  284.     call    chkmovi2
  285.  
  286.     mov    dx,1
  287.     mov    di,si
  288.     add    di,41
  289.     call    chkmovi2
  290. ms23:
  291.     lea    si,stack1        ; ripple search out from there
  292.     cmp    si,stk1ptr
  293.     mov    si,stk1ptr
  294.     jnz    ms24
  295.  
  296.     lea    si,stack2
  297.     lea    di,stack1
  298.     mov    cx,stk2ptr
  299.     sub    cx,si
  300.     jz    ms25
  301.     mov    stk2ptr,si
  302.     rep    movsb
  303.     mov    stk1ptr,di
  304.     jmp    ms23
  305. ms24:
  306.     dec    si
  307.     dec    si
  308.     mov    stk1ptr,si
  309.     mov    di,[si]
  310.  
  311.     push    di
  312.     inc    di
  313.     mov    dx,2
  314.     call    chkmov2
  315.     pop    di
  316.  
  317.     push    di
  318.     sub    di,41
  319.     mov    dx,3
  320.     call    chkmov2
  321.     pop    di
  322.  
  323.     push    di
  324.     dec    di
  325.     mov    dx,0
  326.     call    chkmov2
  327.     pop    di
  328.  
  329.     add    di,41
  330.     mov    dx,1
  331.     call    chkmov2
  332.     jmp    ms23
  333. ms25:
  334.     ret
  335. ;
  336. ; di=maze ptr    dh=original direction
  337. ;
  338. chkmov2:
  339.     cmp    byte ptr [di],0        ; empty?
  340.     jz    cmiyes2            ; jif yes
  341.     mov    al,[di]            ; get byte
  342.     and    al,0f0h
  343.     cmp    al,50h            ; bug?
  344.     jnz    cmino2            ; jif no
  345.     mov    bl,[di]
  346.     and    bl,0fh
  347.     xor    bh,bh
  348.     shl    bx,1
  349.     mov    [bx+bugdirs],dx
  350. cmiyes2:
  351.     mov    byte ptr [di],1        ; mark as been there
  352.     mov    ax,di
  353.     mov    di,stk2ptr
  354.     stosw
  355.     mov    stk2ptr,di
  356. cmino2:
  357.     ret
  358. ;
  359. ;
  360. ;
  361. chkmovi2:
  362.     call    chkmov2
  363.     lea    di,stack2
  364.     cmp    di,stk2ptr
  365.     jz    cmino2
  366.     mov    stk2ptr,di
  367.     mov    ax,[di]
  368.     mov    di,stk1ptr
  369.     stosw
  370.     mov    stk1ptr,di
  371.     ret
  372. ;
  373. if debug
  374. ;
  375. ;
  376. showhere:
  377.     push    bp
  378.     push    si
  379.     push    di
  380.     mov    bp,sp
  381.     lea    di,wmaze
  382.     cld
  383.     add    al,'0'
  384.     stosb
  385.     xor    ax,ax
  386.     stosb
  387.     push    ax
  388.     push    ax
  389.     mov    ax,15
  390.     push    ax
  391.     lea    di,wmaze
  392.     push    di
  393.     mov    ax,8
  394.     push    ax
  395.     mov    ax,30
  396.     push    ax
  397.     call    _flabel
  398.     mov    sp,bp
  399.     pop    di
  400.     pop    si
  401.     pop    bp
  402.     ret
  403. ;
  404. ;
  405. show_hex:
  406.     push    ax
  407.     push    bp
  408.     push    si
  409.     push    di
  410.     mov    bp,sp
  411.     lea    di,wmaze
  412.     cld
  413.     push    ax
  414.     mov    al,ah
  415.     call    show_al
  416.     pop    ax
  417.     call    show_al
  418.     xor    ax,ax
  419.     stosb
  420.     push    ax
  421.     push    ax
  422.     mov    ax,15
  423.     push    ax
  424.     lea    di,wmaze
  425.     push    di
  426.     mov    ax,8
  427.     push    ax
  428.     mov    ax,50
  429.     push    ax
  430.     call    _flabel
  431.     mov    sp,bp
  432.     pop    di
  433.     pop    si
  434.     pop    bp
  435.     pop    ax
  436.     ret
  437.  
  438. show_al:
  439.     shl    ax,1
  440.     shl    ax,1
  441.     shl    ax,1
  442.     shl    ax,1
  443.     shr    al,1
  444.     shr    al,1
  445.     shr    al,1
  446.     shr    al,1
  447.     and    ax,0f0fh
  448.     add    ax,3030h
  449.     cmp    al,'9'
  450.     jbe    alok
  451.     add    al,7
  452. alok:
  453.     cmp    ah,'9'
  454.     jbe    ahok
  455.     add    ah,7
  456. ahok:
  457.     xchg    al,ah
  458.     stosw
  459.     ret
  460. ;
  461. endif
  462. ;
  463. _text    ends
  464. ;
  465.     end
  466.