Subversion Repositories Kolibri OS

Rev

Rev 6573 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;             program to generate files            ;
  2. ;              path to folder in edit1             ;
  3. ;              count of files in edit2             ;
  4. ; to compile: nasm -f bin GenFiles.asm -o GenFiles ;
  5. ORG 0
  6. BITS 32
  7. ; ------------------------------------- ;
  8. STACK_SIZE             equ 256
  9. ; ------------------------------------- ;
  10. EM_REDRAW              equ 0b1
  11. EM_KEY                 equ 0b10
  12. EM_BUTTON              equ 0b100
  13. EM_MOUSE               equ 0b100000
  14. ; ------------------------------------- ;
  15. BUTTON_START           equ 2
  16. ; ------------------------------------- ;
  17. ED_DISABLED            equ 0b100000000000
  18. ; ------------------------------------- ;
  19. EDIT1_MAX_LENGTH       equ 1024
  20. EDIT2_MAX_LENGTH       equ 10
  21. FILE_NAME_LENGTH       equ 256
  22. ; ------------------------------------- ;
  23. text_buffer1           equ END + STACK_SIZE
  24. text_buffer2           equ END + STACK_SIZE + (EDIT1_MAX_LENGTH + 2)
  25. file_name              equ END + STACK_SIZE + (EDIT1_MAX_LENGTH + 2) + (EDIT2_MAX_LENGTH + 2)
  26. ; ------------------------------------- ;
  27. MENUET01                db 'MENUET01'
  28. version                 dd 1
  29. program.start           dd START
  30. program.end             dd END
  31. program.memory          dd END + STACK_SIZE + (EDIT1_MAX_LENGTH + 2) + (EDIT2_MAX_LENGTH + 2) + FILE_NAME_LENGTH
  32. program.stack           dd END + STACK_SIZE
  33. program.params          dd 0
  34. program.path            dd 0
  35. ; ------------------------------------- ;
  36. align 4
  37. Events:
  38. .0:                     dd  On_Idle
  39. .1:                     dd  On_Redraw
  40. .2:                     dd  On_Key
  41. .3:                     dd  On_Button
  42. .4:                     dd  0
  43. .5:                     dd  0
  44. .6:                     dd  On_Mouse
  45. ; ------------------------------------- ;
  46. ButtonEvents:
  47. .0:                     dd  0
  48. .1:                     dd  On_ButtonClose
  49. .2:                     dd  On_ButtonStart
  50. ; ------------------------------------- ;
  51. count                   dd  0
  52. ; ------------------------------------- ;
  53. pb:
  54. .value                  dd 0
  55. .left                   dd 8
  56. .top                    dd 38
  57. .width                  dd 269
  58. .height                 dd 15
  59. .style                  dd 0
  60. .min                    dd 0
  61. .max                    dd 0
  62. .back_color             dd 0x00C8D0D4
  63. .progress_color         dd 0x8072B7EB
  64. .frame_color            dd 0x00406175
  65. ; ------------------------------------- ;
  66. edit1:
  67. .width                  dd 100
  68. .left                   dd 48
  69. .top                    dd 8
  70. .color                  dd 0X00FFFFFF
  71. .shift_color            dd 0x94AECE
  72. .focus_border_color     dd 0
  73. .blur_border_color      dd 0
  74. .text_color             dd 0x10000000
  75. .max                    dd EDIT1_MAX_LENGTH
  76. .text                   dd text_buffer1
  77. .mouse_variable         dd 0
  78. .flags                  dd 10b ; active
  79. .size                   dd 0
  80. .pos                    dd 0
  81. .offset                 dd 0
  82. .cl_curs_x              dd 0
  83. .cl_curs_y              dd 0
  84. .shift                  dd 0
  85. .shift_old              dd 0
  86. ; ------------------------------------- ;
  87. edit2:
  88. .width                  dd 60
  89. .left                   dd 216
  90. .top                    dd 8
  91. .color                  dd 0X00FFFFFF
  92. .shift_color            dd 0x94AECE
  93. .focus_border_color     dd 0
  94. .blur_border_color      dd 0
  95. .text_color             dd 0x10000000
  96. .max                    dd EDIT2_MAX_LENGTH
  97. .text                   dd text_buffer2
  98. .mouse_variable         dd 0
  99. .flags                  dd 1000000000000000b ; only numbers
  100. .size                   dd 0
  101. .pos                    dd 0
  102. .offset                 dd 0
  103. .cl_curs_x              dd 0
  104. .cl_curs_y              dd 0
  105. .shift                  dd 0
  106. .shift_old              dd 0
  107. ; ------------------------------------- ;
  108. progressbar_progress    dd 0
  109. progressbar_draw        dd 0
  110. ; ------------------------------------- ;
  111. edit_box_draw           dd 0
  112. edit_box_key            dd 0
  113. edit_box_mouse          dd 0
  114. edit_box_set_text       dd 0
  115. ; ------------------------------------- ;
  116. status_string           dd sz_empty
  117. ; ------------------------------------- ;
  118. box_lib                 dd 0
  119. ; ------------------------------------- ;
  120. sz_box_lib              db "/sys/lib/box_lib.obj",0
  121. ; ------------------------------------- ;
  122. sz_progressbar_draw     db 'progressbar_draw', 0
  123. sz_progressbar_progress db 'progressbar_progress', 0
  124. ; ------------------------------------- ;
  125. sz_edit_box             db "edit_box",0
  126. sz_edit_box_key         db "edit_box_key",0
  127. sz_edit_box_mouse       db "edit_box_mouse",0
  128. sz_edit_box_set_text    db "edit_box_set_text",0
  129. ; ------------------------------------- ;
  130. sz_path                 db "Path:",0
  131. sz_count                db "Count:",0
  132. sz_start                db "Start",0
  133. sz_caption              db "Generate files",0
  134. ; ------------------------------------- ;
  135. sz_empty                db "",0
  136. sz_doing                db "doing",0
  137. sz_done                 db "done ",0
  138. sz_error                db "error",0
  139. ; ------------------------------------- ;
  140. digits                  db "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  141. ; ------------------------------------- ;
  142. START:
  143. ; LoadLibrary:
  144.         mov    eax, 68
  145.         mov    ebx, 19
  146.         mov    ecx, sz_box_lib
  147.         int    64
  148.         mov    [box_lib], eax
  149.  
  150.         push   dword[box_lib]
  151.         push   sz_edit_box
  152.         call   GetProcAddress
  153.         mov    [edit_box_draw], eax
  154.  
  155.         push   dword[box_lib]
  156.         push   sz_edit_box_key
  157.         call   GetProcAddress
  158.         mov    [edit_box_key], eax
  159.  
  160.         push   dword[box_lib]
  161.         push   sz_edit_box_mouse
  162.         call   GetProcAddress
  163.         mov    [edit_box_mouse], eax
  164.  
  165.         push   dword[box_lib]
  166.         push   sz_edit_box_set_text
  167.         call   GetProcAddress
  168.         mov    [edit_box_set_text], eax
  169.  
  170.         push   dword[box_lib]
  171.         push   sz_progressbar_draw
  172.         call   GetProcAddress
  173.         mov    [progressbar_draw], eax
  174.  
  175.         push   dword[box_lib]
  176.         push   sz_progressbar_progress
  177.         call   GetProcAddress
  178.         mov    [progressbar_progress], eax
  179. ; ------------------------------------- ;
  180. ; SetEventMask
  181.         mov    eax, 40
  182.         mov    ebx, EM_REDRAW | EM_KEY | EM_BUTTON | EM_MOUSE
  183.         int    64
  184. ; ------------------------------------- ;
  185. align 4
  186. WaitEvent:
  187.         mov    eax, 10
  188.         int    64
  189.         call   [eax * 4 + Events]
  190.         jmp    WaitEvent
  191. ; ------------------------------------- ;
  192. %macro CreateNextFile 0
  193. ; Base36(count)
  194.         mov    eax, [count]
  195.         mov    ecx, 36        ; because our base is 36
  196.         mov    esi, file_name
  197.         mov    edi, esi
  198.         add    esi, 7         ; base36(0xFFFFFFFF) = 1Z141Z3 : 7 simbols
  199.         mov    [esi], byte 0
  200. %%next:
  201.         xor    edx, edx
  202.         div    ecx
  203.         dec    esi
  204.         mov    dl, [edx + digits]
  205.         mov    [esi], dl
  206.         test   eax, eax
  207.         jnz    %%next
  208.         mov    eax, esi
  209.         sub    eax, edi
  210.         mov    ecx, 7 + 1
  211.         sub    ecx, eax
  212.         rep    movsb
  213. ; ------------------------------------- ;
  214.         push   dword file_name
  215.         dec    esp
  216.         mov    [esp], byte 0
  217.         push   dword 0
  218.         push   dword 0
  219.         push   dword 0
  220.         push   dword 0
  221.         push   dword 2  ; SubFunction #2 Create/Rewrite file
  222.         mov    ebx, esp
  223.         mov    eax, 70  ; Function #70
  224.         int    64
  225.         add    esp, 25  ; restore stack
  226. %endmacro
  227. ; ------------------------------------- ;
  228. align 4
  229. DoAction:
  230. ; convert text in edit2 to number
  231.         mov    edx, [edit2.text]
  232.         xor    eax, eax
  233.         xor    ecx, ecx
  234. .convert:
  235.         mov    al, [edx]
  236.         test   al, al
  237.         jz     .converted
  238.         lea    ecx, [ecx + ecx * 4]
  239.         lea    ecx, [eax + ecx * 2 - 48]
  240.         inc    edx
  241.         jmp    .convert
  242. .converted:
  243.         mov    [count], ecx
  244. ; ------------------------------------- ;
  245.         mov    [pb.max], ecx
  246.         mov    [pb.value], dword 0
  247. ; draw progressbar
  248.         push   pb
  249.         call   [progressbar_draw]
  250. ; ------------------------------------- ;
  251.         cmp    [count], dword 0
  252.         jz     .done
  253. ; SetCurrentDirectory
  254.         mov    eax, 30
  255.         mov    ebx, 1
  256.         mov    ecx, [edit1.text]
  257.         int    64
  258. ;
  259.         mov    [status_string], dword sz_doing
  260.         call   DrawStatus
  261. .do:
  262.         CreateNextFile
  263.         test   eax, eax
  264.         jnz    .error
  265. ; increase progress
  266.         push   pb
  267.         call   [progressbar_progress]
  268. ; CheckEvent
  269.         mov    eax, 11
  270.         int    64
  271.         call   [eax * 4 + Events]
  272.         dec    dword [count]
  273.         jnz   .do
  274. .done:
  275.         mov    [status_string], dword sz_done
  276.         call   DrawStatus
  277.                                                                 ret
  278. .error:
  279.         mov    [status_string], dword sz_error
  280.         call   DrawStatus
  281.                                                                 ret
  282. ; ------------------------------------- ;
  283. DrawStatus:
  284.         mov    eax, 4
  285.         mov    ecx, 0xD0000000
  286.         mov    ebx, (297 << 16) | 38
  287.         mov    edx, [status_string]
  288.         mov    edi, 0x00FFFFFF
  289.         int    64
  290.         ret
  291. ; ------------------------------------- ;
  292. align 4
  293. On_Idle:
  294.         ret
  295. ; ------------------------------------- ;
  296. align 4
  297. On_Redraw:
  298. ; RedrawStart
  299.         mov    eax, 12
  300.         mov    ebx, 1
  301.         int    64
  302. ; DrawWindow
  303.         xor    eax, eax
  304.         mov    ebx, (50 << 16) | 360
  305.         mov    ecx, (50 << 16) | 88
  306.         mov    edx, 0x34FFFFFF
  307.         mov    edi, sz_caption
  308.         xor    esi, esi
  309.         int    64
  310. ; draw progressbar
  311.         push   pb
  312.         call   [progressbar_draw]
  313. ; draw edit1
  314.         push   edit1
  315.         call   [edit_box_draw]
  316. ; draw edit2
  317.         push   edit2
  318.         call   [edit_box_draw]
  319. ; DrawButton
  320.         mov    eax, 8
  321.         mov    ecx, (8   << 16) | 26
  322.         mov    ebx, (288 << 16) | 53
  323.         mov    edx, BUTTON_START
  324.         mov    esi, 0x00DDDDDD
  325.         int    64
  326. ; DrawTexts
  327.         mov    eax, 4
  328.         mov    ecx, 0x90000000
  329. ;   Path:
  330.         mov    ebx, (8   << 16) | 11
  331.         mov    edx, sz_path
  332.         int    64
  333. ;   Count:
  334.         mov    ebx, (168 << 16) | 11
  335.         mov    edx, sz_count
  336.         int    64
  337. ;   Start:
  338.         mov    ebx, (297 << 16) | 15
  339.         mov    edx, sz_start
  340.         int    64
  341. ; draw status
  342.         call   DrawStatus
  343. ; RedrawFinish
  344.         mov    eax, 12
  345.         mov    ebx, 2
  346.         int    64
  347.         ret
  348. ; ------------------------------------- ;
  349. align 4
  350. On_Key:
  351. ; GetKeyCode
  352.         mov    eax, 2
  353.         int    64
  354. ; notify edit1 about key event
  355.         push   edit1
  356.         call   [edit_box_key]
  357. ; notify edit2 about key event
  358.         push   edit2
  359.         call   [edit_box_key]
  360.         ret
  361. ; ------------------------------------- ;
  362. align 4
  363. On_Button:
  364. ; GetButtonNumber
  365.         mov    eax, 17
  366.         int    64
  367.         movzx  eax, ah
  368.         call   [eax * 4 + ButtonEvents]
  369.         ret
  370. ; ------------------------------------- ;
  371. align 4
  372. On_ButtonClose:
  373. ; Terminate
  374.         or     eax, -1
  375.         int    64
  376.         ; ret is not needed here because we are not back after terminate
  377. ; ------------------------------------- ;
  378. align 4
  379. On_ButtonStart:
  380.         mov    [ButtonEvents.2], dword On_Idle        ; disable ButtonStart | because
  381.         or     [edit1.flags], dword ED_DISABLED       ; disable edit1       |   we will
  382.         or     [edit2.flags], dword ED_DISABLED       ; disable edit2       |     in Action
  383. ; redraw edit1 after change flag
  384.         push   edit1
  385.         call   [edit_box_draw]
  386. ; redraw edit2 after change flag
  387.         push   edit2
  388.         call   [edit_box_draw]
  389.         call   DoAction
  390.         mov    [ButtonEvents.2], dword On_ButtonStart ; enable ButtonStart
  391.         and    [edit1.flags], dword ~ED_DISABLED      ; enable edit1
  392.         and    [edit2.flags], dword ~ED_DISABLED      ; enable edit2
  393. ; redraw edit1 after change flag
  394.         push   edit1
  395.         call   [edit_box_draw]
  396. ; redraw edit2 after change flag
  397.         push   edit2
  398.         call   [edit_box_draw]
  399.         ret
  400. ; ------------------------------------- ;
  401. align 4
  402. On_Mouse:
  403. ; notify edit1 about mouse event
  404.         push   edit1
  405.         call   [edit_box_mouse]
  406. ; notify edit2 about mouse event
  407.         push   edit2
  408.         call   [edit_box_mouse]
  409.         ret
  410. ; ------------------------------------- ;
  411. align 4
  412. GetProcAddress:
  413.         mov    edx, [esp + 8]
  414.         xor    eax, eax
  415.         test   edx, edx
  416.         jz     .end
  417. .next:
  418.         xor    eax, eax
  419.         cmp    [edx], dword 0
  420.         jz     .end
  421.         mov    esi, [edx]
  422.         mov    edi, [esp + 4]
  423. .next_:
  424.         lodsb
  425.         scasb
  426.         jne    .fail
  427.         test   al, al
  428.         jnz    .next_
  429.         jmp    .ok
  430. .fail:
  431.         add    edx, 8
  432.         jmp    .next
  433. .ok:
  434.         mov    eax, [edx + 4]
  435. .end:
  436.         ret    8
  437. ; ------------------------------------- ;
  438. align 4
  439. END: