Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. RAY_NUM equ   100000b
  2. RAY_ABS equ  1000000b
  3. RAY_REF equ 10000000b
  4. BBSIZE   equ 10
  5. ATOM_COUNT equ BBSIZE/2
  6.  
  7. CELL_EMPTY_CENTER equ 10100000b
  8. CELL_ABSORBED     equ 10000000b
  9. CELL_REFLECTED    equ 01000000b
  10. CELL_EMPTY_EDGE   equ 11000000b
  11. CELL_FULL_EDGE    equ 00100000b
  12. MASK_ATOM         equ 00000001b
  13. MASK_GUESS        equ 00000010b
  14. MASK_ALL          equ 11100000b
  15. MASK_DIR          equ 00000011b
  16.  
  17. BB_levelp:
  18.                 mcall 40,100111b
  19.     mov  byte[fx],BBSIZE
  20.     mov  byte[fy],BBSIZE
  21.                 and  [cur_step],0
  22.                 and  [pause_time],0
  23.     call get_xy_sf.count
  24.     call erase_field
  25.     mov  edi,field+1
  26.     mov  ecx,BBSIZE-2
  27.     mov  eax,CELL_EMPTY_EDGE+1
  28.     rep  stosb
  29.     mov  eax,CELL_EMPTY_CENTER
  30.     mov  ecx,BBSIZE-2
  31.   .lp:
  32.     push ecx
  33.     mov  word[edi],(CELL_EMPTY_EDGE+3) shl 8+CELL_EMPTY_EDGE
  34.     add  edi,2
  35.     mov  ecx,BBSIZE-2
  36.     rep  stosb
  37.     pop  ecx
  38.     loop .lp
  39.     mov  word[edi],(CELL_EMPTY_EDGE+3) shl 8+CELL_EMPTY_EDGE
  40.     add  edi,2
  41.     mov  eax,CELL_EMPTY_EDGE+2
  42.     mov  ecx,BBSIZE-2
  43.     rep  stosb
  44.  
  45.     mov  ecx,BBSIZE/2
  46.     mov  ebx,BBSIZE*BBSIZE
  47.   .again:
  48.     call get_rnd
  49.     xor  edx,edx
  50.     div  ebx
  51.     cmp  byte[field+edx],CELL_EMPTY_CENTER
  52.     jne  .again
  53.     or   byte[field+edx],MASK_ATOM
  54.     loop .again
  55.     mov  [win_flag],5
  56.     ret
  57.  
  58. BB_key:
  59.                 cmp  eax,-1
  60.                 je   BB_mouse
  61.                 cmp  eax,9
  62.                 jne  .ex
  63.                 xor  edx,edx
  64.                 xor  edi,edi
  65.                 mov  esi,field
  66.                 mov  ecx,BBSIZE*BBSIZE
  67.         .lp:
  68.                 lodsb
  69.                 mov  ebx,eax
  70.                 and  eax,MASK_ALL;+MASK_ATOM
  71.                 cmp  eax,CELL_EMPTY_CENTER
  72.                 jne  .nxt
  73.                 cmp  ebx,CELL_EMPTY_CENTER+MASK_ATOM+MASK_GUESS
  74.                 jne  .nomatch
  75.                 add  dx,0x101
  76.                 jmp  .nxt
  77.         .nomatch:
  78.                 test ebx,MASK_GUESS
  79.                 jz   .nxt
  80.                 inc  dh
  81.         .nxt:
  82.                 loop .lp
  83.                 cmp  dh,ATOM_COUNT
  84.                 je   .chk
  85.                 mov  [win_flag],9
  86.                 jmp  .ex
  87.         .chk:
  88.                 mov  [win_flag],10
  89.                 mov  ebx,(BBSIZE-2)*4
  90.                 mov  ecx,ATOM_COUNT
  91.                 sub  cl,dl
  92.                 imul  ecx,ATOM_COUNT
  93.                 sub  ebx,ecx
  94.                 sub  ebx,[pause_time]
  95.                 mov  [score],ebx
  96.         .ex:
  97.     ret
  98.  
  99. BB_drawm:
  100.                 mov  eax,47
  101.                 mov  esi,0x100000ff
  102.                 cmp  [win_flag],5
  103.                 jne  .no5
  104.     mcall ,0x10000,ATOM_COUNT,<XFOFS+MSGXO,42>
  105.         .no5:
  106.                 cmp  [win_flag],10
  107.                 jne  .no10
  108.     mcall ,0x20000,[score],<XFOFS+MSGXO+12*8,42>
  109.         .no10:
  110.                 cmp  [win_flag],9
  111.                 jne  .no9
  112.     mcall ,0x10000,ATOM_COUNT,<XFOFS+MSGXO+11*8,42>
  113.         .no9:
  114.     mov  ecx,[cell_count]
  115.   .lp:
  116.         push ecx
  117.         lea  eax,[ecx-1]
  118.         movzx ebx,byte[field+eax]
  119.         call get_xy
  120.         mov  eax,ebx
  121.         and  eax,MASK_ALL
  122.         cmp  eax,CELL_EMPTY_CENTER
  123.         jne  .nocenter
  124.         test ebx,MASK_ATOM
  125.         jz   .noatom
  126.         cmp  [win_flag],10
  127.         jne  .noatom
  128.         mov  edx,0xff0000
  129.         push ebx
  130.         mcall 13,[lx],[ly]
  131.         pop  ebx
  132.   .noatom:
  133.         test ebx,MASK_GUESS
  134.         jz   .nxtlp
  135.         add  [lx],2 shl 16-4
  136.         add  [ly],2 shl 16-4
  137.         mov  edx,0xffff00
  138.   .bar:
  139.         mcall 13,[lx],[ly]
  140.   .nxtlp:
  141.         pop  ecx
  142.         loop .lp
  143.   .ex2:
  144.     ret
  145.   .nocenter:
  146.         mov  edx,0xff
  147.         cmp  eax,CELL_ABSORBED
  148.         je   .bar
  149.         mov  edx,0x8000
  150.         cmp  eax,CELL_REFLECTED
  151.         je   .bar
  152.         cmp  eax,CELL_FULL_EDGE
  153.         jne  .nxtlp
  154.         and  ebx,11111b
  155.         mov  ecx,ebx
  156.         push word[ly+2]
  157.         pop  word[lx]
  158.         mov  eax,[Ces]
  159.         shr  eax,1
  160.         add  word[lx],ax
  161.         add  word[lx+2],ax
  162.         sub  [lx],8 shl 16+6
  163.         mcall 47,0x20000,,[lx],0x10000000
  164.         jmp  .nxtlp
  165.  
  166. corners db 0,BBSIZE-1,BBSIZE*BBSIZE-1,BBSIZE*(BBSIZE-1)
  167.  
  168. BB_mouse:
  169.                 cmp  [win_flag],1
  170.                 je   .ex
  171.     mov  [jump],still
  172.     mov  edx,eax
  173.                 call get_last_mclick
  174.                 mov  eax,ebx
  175.                 mov  edi,corners
  176.                 mov  ecx,4
  177.                 repne scasb
  178.                 je   .ex
  179.                 movzx ebx,byte[field+eax]
  180.                 mov  ecx,ebx
  181.                 and  ecx,MASK_ALL
  182.                 cmp  ecx,CELL_EMPTY_CENTER
  183.                 jne  .nocenter
  184.                 xor  byte[field+eax],MASK_GUESS
  185.     mov  [win_flag],11
  186.                 jmp  .red
  187.         .nocenter:
  188.                 cmp  ecx,CELL_EMPTY_EDGE
  189.                 jne  .ex
  190.  
  191.                 mov  [player],eax
  192.                 and  ebx,MASK_DIR
  193.         .step:
  194.                 mov  [finish],eax
  195.                 add  eax,[dirs+ebx*4] ; 1 step
  196.                 mov  [stepptr],eax
  197.                 movzx edx,byte[field+eax] ; cell ahead - edx
  198.                 and  edx,MASK_ALL+MASK_ATOM
  199.                 cmp  edx,CELL_EMPTY_CENTER+MASK_ATOM
  200.                 jne  .noabsorb
  201.                 mov  eax,[player]
  202.                 mov  byte[field+eax],CELL_ABSORBED
  203.                 inc  [pause_time]
  204.     mov  [win_flag],7
  205.                 jmp  .red
  206.         .noabsorb:
  207.                 lea  ecx,[ebx-2]
  208.                 and  ecx,MASK_DIR
  209.                 add  eax,[dirs+ecx*4]
  210.                 movzx edx,byte[field+eax] ; cell aside - edx
  211.                 xor  ecx,11b
  212.                 and  edx,MASK_ALL+MASK_ATOM
  213.                 cmp  edx,CELL_EMPTY_CENTER+MASK_ATOM
  214.                 jne  .noreflect1
  215.         .reflect:
  216.                 mov  eax,[finish]
  217.                 cmp  eax,[player]
  218.                 je   .endref
  219.                 mov  ebx,ecx ;new direction
  220.                 jmp  .nextstep
  221.         .noreflect1:
  222.                 mov  eax,[stepptr]
  223.                 add  eax,[dirs+ecx*4]
  224.                 movzx edx,byte[field+eax] ; cell aside - edx
  225.                 xor  ecx,11b
  226.                 and  edx,MASK_ALL+MASK_ATOM
  227.                 cmp  edx,CELL_EMPTY_CENTER+MASK_ATOM
  228.                 je   .reflect
  229.         .noreflect2:
  230.                 mov  eax,[stepptr]
  231.                 movzx edx,byte[field+eax]
  232.                 and  edx,MASK_ALL
  233.                 cmp  edx,CELL_EMPTY_CENTER
  234.                 je   .nextstep
  235.  
  236.                 cmp  eax,[player]
  237.                 je   .endref
  238.                 mov  ebx,[cur_step]
  239.                 add  ebx,CELL_FULL_EDGE
  240.                 mov  byte[field+eax],bl
  241.                 mov  eax,[player]
  242.                 mov  byte[field+eax],bl
  243.                 inc  [cur_step]
  244.     mov  [win_flag],6
  245.                 add  [pause_time],2
  246.                 jmp  .red
  247.         .endref:
  248.                 mov  eax,[player]
  249.                 mov  byte[field+eax],CELL_REFLECTED
  250.     mov  [win_flag],8
  251.                 inc  [pause_time]
  252.                 jmp  .red
  253.         .nextstep:
  254.                 jmp  .step
  255.  
  256.         .red:
  257.     mov  [jump],drw
  258.         .ex:
  259.                 ret
  260.  
  261. BB_level:
  262.         db 0
  263.  
  264. if lang eq ru
  265.         BB_help mstr \
  266.         '‚ è  楫ì á®á⮨⠢ ⮬, çâ®¡ë ®¡­ à㦨âì',\
  267.         '¯®«®¦¥­¨¥ ¯ï⨠ â®¬®¢ ¢ ç¥à­®¬ ï騪¥, ¯®áë« ï',\
  268.         '«ãç¨ á¢¥â  ¢ ª®à®¡ªã ¨ ­ ¡«î¤ ï, £¤¥ «ãç¨',\
  269.         '¯®ï¢«ïîâáï. €â®¬ ¨«¨ ¯®£«®â¨â «ãç, ¥á«¨ «ãç',\
  270.         '㯠¤¥â ­  ­¥£® ¢ 㯮à, ¨«¨ ®âª«®­¨â «ãç ­  90',\
  271.         '£à ¤ãᮢ, ¥á«¨ ®­ ¯à®©¤¥â ¯® ᬥ¦­®¬ã àï¤ã ¨«¨',\
  272.         'ª®«®­ª¥). Œ®£ã⠯ந§®©â¨ 2 ®âª«®­¥­¨ï, ¢ë­ã¦¤ ï',\
  273.         '«ãç ¢®§¢à â¨âìáï ¢® ¢å®¤­®© â®çª¥,- íâ® áç¨â ¥âáï',\
  274.         '®âà ¦¥­¨¥¬. …᫨ ¦¥« ¥â¥ ¯à®¢¥à¨âì á¥¡ï ¨ 㧭 âì',\
  275.         'áç¥â, ®â¬¥âì⥠5 ª«¥â®ª ¦¥«âë¬ æ¢¥â®¬ ¨ ­ ¦¬¨â¥',\
  276.         'TAB. ïâì áªàëâëå  â®¬®¢ ¡ã¤ãâ ¯®ª § ­ë ªà á­ë¬¨',\
  277.         'ª¢ ¤à â¨ª ¬¨.',\
  278.         ' ‹ãç ¯®£«®é¥­ - ᨭ¨© ª¢ ¤à â;',\
  279.         ' ‹ãç ®âà ¦¥­  - §¥«¥­ë© ª¢ ¤à â.',\
  280.         ' —¨á« ¬¨ ®â¬¥ç¥­ë â®çª¨ ¢å®¤  ¨ ¢ë室  «ã祩.','',\
  281.         'http://puzzleprograms.narod.ru'
  282. else
  283.         BB_help mstr \
  284.         'Your goal is to discover the whereabouts of five',\
  285.         'atoms in a black box by sending rays of light',\
  286.         'into the box and observing if and where the rays',\
  287.         'emerge. An atom will either absorb a ray if the',\
  288.         'ray hits it head on, or deflect a ray through 90',\
  289.         'if it comes close (passes through an adjacent row',\
  290.         'or column). Two deflections can occur at the same',\
  291.         'time forcing a ray to return and emerge at its',\
  292.         'entry point, this is referred to as reflection.','',\
  293.         'The challenge is to pin point the location of all',\
  294.         'atoms using the least number of rays. If you wish',\
  295.         'to commit your solution and to discover your',\
  296.         'score you must have exactly five guesses marked,',\
  297.         'then press TAB. The five hidden atoms will appear',\
  298.         'as red squares.','',\
  299.         'http://puzzleprograms.narod.ru'
  300. end if
  301.