Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ; CODE VIEWER - Compile with FASM for Menuet
  2.    
  3. ;B+ System header
  4. use32
  5. org 0x0
  6.  db 'MENUET00'
  7.  dd 38
  8.  dd START
  9.  dd I_END
  10.  dd 0x100000
  11.  dd 0x00000000
  12.  
  13. include 'lang.inc'
  14. include 'macros.inc'
  15. ;E:.
  16.    
  17. ;B+ Definitions
  18. type_begin equ 0
  19. type_end_normal equ 2
  20. type_not_end equ 4
  21. type_end_plus equ 6
  22. type_include equ 8
  23. type_file_end equ 11
  24. ; +1, if active jump
  25.    
  26. char_end equ 11
  27. new_line equ 10
  28.    
  29. win_width equ (496+6*6)
  30. win_field equ (4+10+6*6)
  31. win_toptext equ 38+4
  32. ;B+ Keys
  33. KEY_UP equ (130+48)
  34. KEY_DOWN equ (129+48)
  35. KEY_PGUP equ (136+48)
  36. KEY_PGDOWN equ (135+48)
  37. ;E:.
  38. start_data equ (I_END+10+27+16)
  39. ;E:.
  40.    
  41. ;B+ Execution
  42. START:
  43.   jmp  load_file1
  44. ;B+ Main cicle
  45. redr:
  46.   call draw_window
  47. still:
  48.   mov  eax,10
  49.   int  0x40
  50. still_:
  51.   cmp  eax,1
  52.   je   redr
  53.   cmp  eax,2
  54.   jne  no_key
  55.   mov  eax,2
  56.   int  0x40
  57.   jmp  key
  58. no_key:
  59.   cmp  eax,3
  60.   jne  still
  61.   mov  eax,17
  62.   int  0x40
  63.   cmp  ah,1
  64.   jne  .no_close
  65.   mov  eax,-1
  66.   int  0x40
  67. .no_close:
  68.   jmp  button
  69.   jmp  still
  70. ;E:.
  71. key:
  72. ;B+ Scroll text
  73.   mov  ebx,[top_pos]
  74.   mov  [activ_pos],ebx
  75.   mov  bx,[top_line]
  76.   mov  [activ_line],bx
  77.   mov  bx,[top_depth]
  78.   mov  [activ_depth],bx
  79.   mov  ebx,[top_file]
  80.   mov  [activ_file],ebx
  81.   cmp  ah,KEY_DOWN     ;key_up
  82.   jne  .no_down
  83.   call line_down
  84.   jmp  .save_shift
  85. .no_down:
  86.   cmp  ah,KEY_UP       ;key down
  87.   jne  .no_up
  88.   call line_up
  89.   jmp  .save_shift
  90. .no_up:
  91.   cmp  ah,KEY_PGUP     ;key page up
  92.   jne  .no_pgup
  93.   mov  edi,35
  94. .next_line:
  95.   call line_up
  96.   dec  edi
  97.   jnz  .next_line
  98.   jmp  .save_shift
  99. .no_pgup:
  100.   cmp  ah,KEY_PGDOWN   ;key page down
  101.   jne  .no_pgdown
  102.   mov  edi,35
  103. .next_line1:
  104.   call line_down
  105.   dec  edi
  106.   jnz  .next_line1
  107.   jmp  .save_shift
  108. .no_pgdown:
  109.   jmp  still
  110. .save_shift:
  111.   mov  ebx,[activ_pos]
  112.   mov  [top_pos],ebx
  113.   mov  bx,[activ_line]
  114.   mov  [top_line],bx
  115.   mov  bx,[activ_depth]
  116.   mov  [top_depth],bx
  117.   mov  ebx,[activ_file]
  118.   mov  [top_file],ebx
  119.   ; Show new text
  120.   mov  ebx,1
  121.   mov  eax,12
  122.   int  0x40
  123.   call show_text
  124.   mov  ebx,2
  125.   mov  eax,12
  126.   int  0x40
  127.   jmp  still
  128. ;E:.
  129. button:
  130. ;B+ Distribute button events
  131.   shr  eax,8
  132.   and  eax,0xff
  133.   cmp  eax,100
  134.   jge  down_buttons
  135. ;B+ Left buttons
  136. ;B+ Find line place
  137.   sub  eax,2
  138.   mov  ebx,[top_pos]
  139.   mov  [activ_pos],ebx
  140.   mov  bx,[top_depth]
  141.   mov  [activ_depth],bx
  142.   mov  ebx,[top_file]
  143.   mov  [activ_file],ebx
  144.   mov  bx,[top_line]
  145.   mov  [activ_line],bx
  146.   mov  ecx,eax
  147.   or   ecx,ecx
  148.   jz   .line_find
  149. .next_line:
  150.  push ecx
  151.   call line_down
  152.  pop  ecx
  153.   loop .next_line
  154. .line_find:
  155.   mov  ebx,[activ_pos]
  156. ;E:.
  157. ;B+ Switch, if special line
  158.   mov  cx,[ebx]
  159.   test cx,not 15
  160.   jnz  still
  161.   cmp  cx,type_begin
  162.   je   .is_begin_end
  163.   cmp  cx,type_begin+1
  164.   jne  .not_begin_end
  165. .is_begin_end:
  166.   xor  [ebx],word 1
  167.   mov  ebx,[ebx+4]
  168.   add  ebx,[activ_file]
  169.   xor  [ebx],word 1
  170.   jmp  .paint
  171. .not_begin_end:
  172.   cmp  cx,type_include
  173.   je   .open_file
  174.   ;close file
  175.   cmp  cx,type_include+1
  176.   jne  .not_include
  177.   xor  [ebx],word 1
  178.   jmp  .paint
  179. .open_file:
  180.   ;Open file
  181.   cmp  dword [ebx+4],-1
  182.   je   .load_file
  183.   xor  [ebx],word 1
  184.   jmp  .paint
  185. .paint1:
  186.  pop  ebx
  187.   jmp  .paint
  188. .load_file:
  189.  push ebx
  190. ;B+ Prepare file name
  191.   mov  ecx,26
  192.   mov  edi,incl_filename
  193.   mov  al,' '
  194.   cld
  195. rep  stosb
  196.   mov  cl,[skoba_txt]
  197.   mov  ch,[skoba_txt+1]
  198.   add  ebx,12
  199. .next_char:
  200.   cmp  [ebx],cl
  201.   je   .begin
  202.   cmp  byte [ebx],new_line
  203.   je   .paint1
  204.   inc  ebx
  205.   jmp  .next_char
  206. .begin:
  207.   inc  ebx
  208.   mov  esi,ebx
  209. .next_char1:
  210.   cmp  [ebx],ch
  211.   je   .end
  212.   cmp  byte [ebx],new_line
  213.   je   .paint1
  214.   inc  ebx
  215.   jmp  .next_char1
  216. .end:
  217.   sub  ebx,esi
  218.   mov  edi,incl_filename
  219.   mov  ecx,ebx
  220.  push ecx
  221. rep movsb
  222. ;  mov  al,0
  223. ;  stosb
  224.    
  225.   ;Save in memory
  226.   mov  ecx,[esp]
  227.   mov  esi,incl_filename
  228.   mov  edi,[end_of_file]
  229. rep movsb
  230.  pop  ecx
  231.   mov  [edi],ecx
  232.   add  ecx,2
  233.   add  [end_of_file],ecx
  234.    
  235.   mov  ebx,[esp]
  236. ;E:.
  237.   mov  edi,[top_free_file]
  238.   mov  [ebx+4],edi
  239.    
  240.   mov  [activ_pos],ebx
  241.   mov  eax,[activ_file]
  242.   sub  ebx,eax
  243.   mov  [incl_line],ebx
  244.  push eax
  245.   call line_down
  246.  pop  eax
  247.   mov  ebx,[activ_pos]
  248.   sub  ebx,eax
  249.   mov  [incl_next],ebx
  250.  pop  ebx
  251.   xor  [ebx],word 1
  252.  push  eax
  253.   mov  eax,[end_of_file]
  254.   add  eax,16
  255.   mov  [activ_file],eax
  256.   lea  edi,[file_array+4*edi]
  257.   mov  [edi],eax
  258.   mov  [activ_pos],eax
  259.    
  260.   mov  ebx,[incl_line]
  261.   mov  [eax-12],ebx
  262.   mov  bx,[activ_line]
  263.    dec  bx
  264.    mov  word [eax-6],bx
  265. ;B+ Save number for new file
  266.   mov  ebx,[esp]
  267.   cmp  ebx,[file_array]
  268.   jne  .no_root
  269.   mov  [eax-8],word 0
  270.   jmp  .parent_ok
  271. .no_root:
  272.   mov  ebx,[esp]
  273.   mov  bl,[ebx-2]
  274.   and  ebx,0xff
  275.   mov  [eax-8],bx
  276. .parent_ok:
  277.  push eax
  278. ;E:.
  279.   call add_file
  280.   mov  edi,[block_pointer]
  281.   mov  word [edi+4],char_end
  282.   add  [block_pointer],8
  283.  push edi
  284.   call fresh_file
  285.  pop  edi eax
  286.   mov  [block_pointer],edi
  287.    
  288. ;B+ Save newfile line count
  289.   mov  edi,[line_]
  290.   mov  word [eax-4],di
  291. ;E:.
  292.  pop  eax
  293.    
  294.   mov  [activ_file],eax
  295.   inc  [top_free_file]
  296.   jmp  .paint
  297. .not_include:
  298.    
  299. .paint:
  300.   mov  ebx,1
  301.   mov  eax,12
  302.   int  0x40
  303.   call show_text
  304.   mov  ebx,2
  305.   mov  eax,12
  306.   int  0x40
  307. ;E:.
  308.   jmp  still
  309. ;E:.
  310. down_buttons:
  311. ;B+ If down buttons
  312.   cmp  eax,101
  313.   je   load_file   ;Button 'Load'
  314.   sub  eax,100
  315.   mov  edx,[str_table+4*eax]
  316.   mov  [str_start],edx
  317. ;B+ Clear old info
  318.  push edx
  319.   ;clear text
  320.   mov  ecx,0xaa0000
  321.   call print_str
  322.  pop  edx
  323.   ;clear memory place
  324.   mov  ecx,[edx]
  325.   lea  edi,[edx+8]
  326.   mov  eax,'    '
  327.   cld
  328. rep stosb
  329. ;E:.
  330.   mov  ebx,[edx]
  331.   mov  [max_len],ebx
  332.   mov  ebx,[edx+4]
  333.   jmp  load_str
  334. save_str:
  335. ;B+ Save in base place
  336. ;B+ If file convert to upper case
  337.   mov  eax,it1
  338.   cmp  eax,[str_start]
  339.   jne  .no_file
  340.   mov  ecx,0xaa0000
  341.   mov  edx,str_
  342.   mov  esi,[it1]
  343.   mov  ebx,[it1+4]
  344.   mov  eax,4
  345.   int  0x40
  346.   mov  edx,edi
  347.   mov  eax,str_
  348.   dec  eax
  349.   inc  edx
  350. .next_char:
  351.   inc  eax
  352.   dec  edx
  353.   jz   .no_file
  354.   cmp  byte [eax],'a'
  355.   jl   .next_char
  356.   cmp  byte [eax],'z'
  357.   jg   .next_char
  358.   add  byte [eax],'A'-'a'
  359.   jmp  .next_char
  360. .no_file:
  361. ;E:.
  362.   mov  edx,[str_start]
  363.   add  edx,8
  364.   mov  ecx,edi
  365.   add  edi,edx
  366.   mov  byte [edi],char_end
  367.   mov  eax,it1
  368.   cmp  eax,[str_start]
  369.   jne  .no_null
  370.   mov  byte [edi],' ' ;0
  371. .no_null:
  372.   mov  esi,str_
  373.   mov  edi,edx
  374.   cld
  375. rep movsb
  376.   mov  ecx,0xffffff
  377.   jmp  print_str
  378. ;E:.
  379. ;E:.
  380. ;E:.
  381. ;B+ String tools
  382. ;B+ Data for load string
  383. curs db '_'
  384. str_: times 100 db ' '
  385.            db char_end
  386. max_len dd 10
  387. ;E:.
  388. load_str:
  389. ;B+ Load text field
  390.   xor  edi,edi
  391.   mov  ecx,0xffaaaa
  392.   mov  esi,1
  393. .next_char:
  394.   mov  edx,curs
  395.   mov  eax,4
  396.   int  0x40
  397. ;B+ Get key event
  398.   mov  eax,10
  399.   int  0x40
  400.  push eax
  401.   mov  ecx,0xaa0000
  402.   mov  eax,4
  403.   int  0x40
  404.  pop  eax
  405.   cmp  eax,2
  406.   je   .yes_key
  407.   call save_str
  408.   jmp  still_
  409. .yes_key:
  410.   mov  eax,2
  411.   int  0x40
  412. ;E:.
  413. ;B+ Test enter
  414.   cmp  ah,13
  415.   jne  .no_ok
  416.   call save_str
  417.   jmp  still
  418. .no_ok:
  419. ;E:.
  420. ;B+ Test backspace
  421.   cmp  ah,8
  422.   jne  .no_backsp
  423.   or   edi,edi
  424.   jz   .next_char
  425.   mov  byte [str_+edi],' '
  426.   mov  ecx,0xaa0000
  427.   mov  eax,4
  428.   int  0x40
  429.   dec  edi
  430.   sub  ebx,6*65536
  431.   lea  edx,[str_+edi]
  432.   int  0x40
  433.   mov  ecx,0xffaaaa
  434.   jmp  .next_char
  435.  .no_backsp:
  436. ;E:.
  437. ;B+ Prin 1 char
  438.   mov  [str_+edi],ah
  439.   mov  ecx,0xaa0000
  440.   mov  eax,4
  441.   int  0x40
  442.   mov  ecx,0xffaaaa
  443.   lea  edx,[str_+edi]
  444.   cmp  [max_len],edi
  445.   je   .next_char
  446.   int  0x40
  447.   add  ebx,6*65536
  448.   inc  edi
  449. ;E:.
  450.   jmp  .next_char
  451. ;E:.
  452. print_str:
  453. ;B+ Print select string
  454.   mov  ebx,[str_start]
  455.   lea  edx,[ebx+8]
  456.   mov  esi,[ebx]
  457.   mov  ebx,[ebx+4]
  458.   mov  eax,4
  459.   int  0x40
  460. ;B+ Test special strings
  461.  pusha
  462.   mov  eax,[str_start]
  463.   cmp  eax,it2
  464.   jge  .is_ok1
  465.  popa
  466.   ret
  467. .is_ok1:
  468.   cmp  eax,it3
  469.   jle  .is_ok
  470.  popa
  471.   ret
  472. .is_ok:
  473. ;E:.
  474.   add  eax,8
  475. .next_char:
  476.   mov  esi,1
  477.   cmp  byte [eax],' '
  478.   jne  .no_space
  479. ;B+ Draw special space
  480.  push eax
  481.   mov  edx,space
  482.   mov  eax,4
  483.   int  0x40
  484.  push  ebx
  485.   sub  ebx,1*65536
  486.   mov  edx,dot
  487.   int  0x40
  488.   add  ebx,3*65536
  489.   int  0x40
  490.  pop  ebx
  491.  pop  eax
  492. ;E:.
  493. .no_space:
  494.   add  ebx,6*65536
  495.   cmp  byte [eax],char_end
  496.   jne  .no_ret
  497.  popa
  498.   ret
  499. .no_ret:
  500.   inc  eax
  501.   jmp  .next_char
  502.    
  503. space db '_'
  504. dot db '.'
  505. ;E:.
  506. ;E:.
  507. ;B+ Add / remove files
  508. add_file:
  509. ;B+ Load and link file
  510.   mov  eax,[activ_file]
  511.  push  eax
  512.   mov  ebx,incl_filename
  513.   mov  ecx,0
  514.   mov  edx,-1
  515.   mov  esi,eax
  516.   mov  eax,6
  517.   int  0x40
  518.    
  519.   mov  ebx,[esp]
  520.   inc  eax
  521.   mov  [ebx-16],eax
  522.   dec  eax
  523.   add  ebx,eax
  524.   add  eax,16+15           +20 ;???
  525.   add  [end_of_file],eax
  526.   mov  byte [ebx],new_line
  527.   mov  word [ebx+1],char_end
  528.   mov  ax,[activ_line]
  529.   mov  word [ebx+3],ax
  530.   mov  eax,[incl_next]
  531.   mov  [ebx+5],eax
  532.   mov  dword [ebx+9],new_line
  533.   mov  byte [ebx+13],new_line
  534.  pop  ebx
  535.   mov  eax,[top_free_file]
  536.   mov  byte [ebx-2],al ; this file num
  537.   mov  byte [ebx-1],new_line
  538.   ret
  539. ;E:.
  540. ;B+ Include file data
  541. incl_filename db 'KERNEL.ASM'
  542. if_e:
  543. times (26+incl_filename-if_e) db ' '
  544. incl_line dd 0x0
  545. incl_next dd 0x0
  546. ;E:.
  547. ;E:.
  548. ;E:.
  549.    
  550. ;B+ Visualization tools
  551. draw_window:
  552. ;B+ Redraw window
  553.   mov  ebx,1
  554.   mov  eax,12
  555.   int  0x40
  556. ;B+ Draw window
  557.   mov  ebx,((640-win_width)/2)*65536+win_width
  558.   mov  ecx,10*65536+win_toptext+35*10+1+2*16
  559.   mov  edx,[color_depth]
  560.   or   edx,0x03000000
  561.   mov  esi,0x80aaaaff
  562.   mov  edi,0x00009000
  563.   mov  eax,0x0
  564.   int  0x40
  565. ;E:.
  566. ;B+ Draw caption
  567.   mov  ebx,8*65537
  568.   mov  ecx,0xffffff
  569.   mov  edx,caption
  570.   mov  esi,caption_end-caption
  571.   mov  eax,4
  572.   int  0x40
  573. ;E:.
  574. ;B+ Draw first line
  575.   mov  ebx,5*65536+win_width-9
  576.   mov  ecx,25*65536+win_toptext-22-4
  577.   mov  edx,0xaa0000
  578.   mov  eax,13
  579.   int  0x40
  580.   mov  ebx,21*65536+29
  581.   mov  ecx,0xffffff
  582.   mov  edx,line1up1
  583.   mov  esi,line1up1_end-line1up1
  584.   mov  eax,4
  585.   int  0x40
  586.   mov  ebx,(win_field+6)*65536+29
  587.   mov  edx,line1up2
  588.   mov  esi,line1up2_end-line1up2
  589.   int  0x40
  590. ;E:.
  591. ;B+ Main text zone
  592. ;B+ Fill text
  593.   ;Clear type lines
  594.   mov  edi,lines_view
  595.   mov  ecx,35
  596.   mov  eax,0
  597.   cld
  598. repe stosd
  599.   call show_text
  600. ;E:.
  601. ;B+ Define left buttons
  602. ;  mov  ebx,5*65536+9
  603. ;  mov  ecx,win_toptext*65536+9
  604. ;  mov  edx,0
  605. ;  mov  esi,0x9000a0
  606. ;  mov  eax,8
  607. ;  mov  edi,35
  608. ;.new_button:
  609. ;  int  0x40
  610. ;  add  ecx,10*65536
  611. ;  inc  edx
  612. ;  dec  edi
  613. ;  jnz  .new_button
  614. ;E:.
  615. ;B+ Vertical line
  616.   mov  ebx,(win_field-1)*65537
  617.   mov  ecx,24*65536+win_toptext+35*10
  618.   mov  edx,0xffffff
  619.   mov  eax,38
  620.   int  0x40
  621. ;E:.
  622. ;E:.
  623. ;B+ Down controle zone
  624.   mov  ebx,5*65536+win_width-9
  625.   mov  ecx,(35*10+win_toptext+1)*65536+28
  626.   mov  edx,0xaa0000
  627.   mov  eax,13
  628.   int  0x40
  629.    
  630.   mov  eax,line1down
  631.   mov  ebx,filetxt
  632.   mov  ecx,filetxt_end
  633.   call ins_button_prep
  634.   mov  edx,100
  635.   mov  eax,8
  636.   int  0x40
  637.   mov  eax,line1down
  638.   mov  ebx,loadtxt
  639.   mov  ecx,loadtxt_end
  640.   call ins_button_prep
  641.   inc  edx
  642.   mov  eax,8
  643.   int  0x40
  644.   mov  eax,line1down
  645.   mov  ebx,begintxt
  646.   mov  ecx,begintxt_end
  647.   call ins_button_prep
  648.   inc  edx
  649.   mov  eax,8
  650.   int  0x40
  651.   mov  eax,line1down
  652.   mov  ebx,endtxt
  653.   mov  ecx,endtxt_end
  654.   call ins_button_prep
  655.   inc  edx
  656.   mov  eax,8
  657.   int  0x40
  658.   mov  eax,line2down
  659.   mov  ebx,inctxt
  660.   mov  ecx,inctxt_end
  661.   call ins_button_prep
  662.   add  ecx,14*65536
  663.   inc  edx
  664.   mov  eax,8
  665.   int  0x40
  666.   mov  eax,line2down
  667.   mov  ebx,septxt
  668.   mov  ecx,septxt_end
  669.   call ins_button_prep
  670.   add  ecx,14*65536
  671.   inc  edx
  672.   mov  eax,8
  673.   int  0x40
  674.    
  675.   mov  ebx,22*65536+35*10+win_toptext+4
  676.   mov  ecx,0xffffff
  677.   mov  edx,line1down
  678.   mov  esi,line1down_end-line1down
  679.   mov  eax,4
  680.   int  0x40
  681.   add  ebx,14
  682.   mov  edx,line2down
  683.   mov  esi,line2down_end-line2down
  684.   int  0x40
  685. ;E:.
  686. ;B+ Down controle strings
  687.   mov  ecx,0xffffff
  688.   mov  eax,it1
  689.   mov  [str_start],eax
  690.   call print_str
  691.   mov  eax,it2
  692.   mov  [str_start],eax
  693.   call print_str
  694.   mov  eax,it3
  695.   mov  [str_start],eax
  696.   call print_str
  697.   mov  eax,it4
  698.   mov  [str_start],eax
  699.   call print_str
  700.   mov  eax,it5
  701.   mov  [str_start],eax
  702.   call print_str
  703. ;E:.
  704.   mov  ebx,2
  705.   mov  eax,12
  706.   int  0x40
  707.   ret
  708. ;E:.
  709. ins_button_prep:
  710. ;B+ Insert button
  711.  push edx
  712.  push eax
  713.   sub  ecx,ebx
  714.   mov  eax,6
  715.   mul  ecx
  716.   add  eax,6
  717.  push ax
  718.   mov  eax,[esp+2]
  719.   sub  ebx,eax
  720.   mov  eax,6
  721.   mul  ebx
  722.   add  eax,18
  723.   xchg eax,ebx
  724.   shl  ebx,16
  725.  pop  bx
  726.   mov  ecx,(35*10+win_toptext+1)*65536+13
  727.   mov  esi,0x00a050
  728.  pop  eax
  729.  pop  edx
  730.   ret
  731. ;E:.
  732. show_text:
  733. ;B+ Show text
  734. ;B+ Show file on top
  735.   mov  ebx,(win_field+45)*65536+win_width-(win_field+45+8)
  736.   mov  ecx,25*65536+win_toptext-22-4
  737.   mov  edx,0xaa0000
  738.   mov  eax,13
  739.   int  0x40
  740.    
  741.   mov  edx,[top_file]
  742.   xor  esi,esi
  743.   mov  si,[edx-18]
  744.   sub  edx,18
  745.   sub  edx,esi
  746.   mov  ebx,(win_field+45)*65536+29
  747.   mov  ecx,0xffaaaa
  748.   mov  eax,4
  749.   int  0x40
  750. ;E:.
  751.   mov  ax,[top_line]
  752.   mov  [activ_line],ax
  753.   mov  ebx,[top_pos]
  754.   mov  [activ_pos],ebx
  755.   mov  ax,[top_depth]
  756.   mov  [activ_depth],ax
  757.   mov  eax,[top_file]
  758.   mov  [activ_file],eax
  759.   mov  ecx,35
  760.   mov  [line_],0
  761. .next_line:
  762.   cmp  [activ_depth],0
  763.   jne  .next
  764.   cmp  byte [ebx],char_end
  765.   je   .end_of_file
  766. .next:
  767.  push ecx
  768.   call show_line
  769.   call line_down
  770.   inc  [line_]
  771.  pop  ecx
  772.   loop .next_line
  773.   ret
  774. .end_of_file:
  775.  push ecx
  776.   call clear_line
  777.    
  778.   inc  [activ_pos]
  779.   inc  [line_]
  780.  pop  ecx
  781.   loop .end_of_file
  782.   ret
  783. ;E:.
  784. ;B+ Button chars
  785. leftchars db '-','+',' ','H'
  786.           db '?', 0 ,'!','H'
  787.           db '&','x',' ', 0
  788. ;E:.
  789. show_line:
  790. ;B+ Show line
  791.   call clear_line
  792.   mov  ebx,ecx
  793.   shr  ebx,16
  794.   inc  ebx
  795.   or   ebx,(win_field+6)*65536
  796.  push ebx
  797.  push eax
  798. ;B+ Draw left button char
  799.   mov  eax,[activ_pos]
  800.   mov  ax,[eax]
  801.   test ax,not 15
  802.   jnz  .no_text
  803.   and  eax,0xff
  804.   lea  edx,[leftchars+eax]
  805.   and  ebx,0xffff
  806.   or   ebx,8*65536
  807.   mov  ecx,0xffffff
  808.   mov  esi,1
  809.   mov  eax,4
  810.   int  0x40
  811.   mov  ebx,[esp+4]
  812. .no_text:
  813. ;E:.
  814. ;B+ Draw line number
  815.   xor  ecx,ecx
  816.   mov  cx,[activ_line]
  817.   mov  edx,(10+4+4)*65536
  818.   mov  dx,bx
  819.   mov  ebx,5*65536
  820.   mov  esi,0xeeeeee
  821.   mov  eax,47
  822.   int  0x40
  823. ;E:.
  824. ;B+ Find line length
  825.   xor  esi,esi
  826.   mov  eax,[activ_pos]
  827.   cmp  byte [eax],new_line
  828.   je   .len_ok
  829.   test word [eax],not 15
  830.   jnz  .next_char
  831.   add  eax,12 ;sckip system zone
  832. .next_char:
  833.   cmp  byte [eax],new_line
  834.   je   .len_ok
  835.   inc  esi
  836.   inc  eax
  837.   jmp  .next_char
  838. .len_ok:
  839.   mov  eax,6
  840.   mul  esi
  841.   mov  ecx,eax
  842.   add  ecx,6
  843.  pop  eax
  844.   mov  [eax+2],cx
  845. ;E:.
  846.   mov  ecx,[textcolor]
  847.   mov  edx,[activ_pos]
  848.   xor  edi,edi
  849.   xor  ebx,ebx
  850.   mov  bx,word [edx]
  851.   cmp  bl,new_line
  852.   je   .normal_show_line
  853.   test bx,not 15
  854.   jnz  .normal_show_line
  855.   or   edi,ebx
  856.   mov  ecx,[color_type+4*ebx]
  857.   add  edx,12 ;sckip system zone
  858. .normal_show_line:
  859.  pop  ebx
  860.   mov  eax,4
  861.   int  0x40
  862.   test edi,4 ;bad type close block
  863.   jz   .nobad
  864.   add  ebx,65536
  865.   int  0x40
  866. .nobad:
  867.    ret
  868. ;E:.
  869. color_type:
  870. ;B+ Color data
  871.  dd 0x00dddd,0x00ee00 ;0/1 begin  00ee00
  872.  dd 0x00b5b5,0xffa000 ;2/3 end    00d000
  873.  dd 0xffffff,-1       ;4 text end
  874.  dd 0x00b5b5,0xffa000 ;6/7 auto end
  875.  dd 0x80ccff,0x80aaff ;8/9 include
  876.  dd -1      ,0xffa000 ;11 file end
  877. textcolor dd 0xffffff
  878. ;E:.
  879. clear_line:
  880. ;B+ Clear text in line
  881. ;B+ Find line position
  882.   mov  eax,[line_]
  883.   mov  ecx,10
  884.   mul  cx
  885.   mov  ecx,eax
  886.   add  ecx,win_toptext
  887. ;E:.
  888. ;B+ Draw/clear button
  889.  push ecx
  890.   shl  ecx,16
  891.   mov  cx,9
  892.   mov  ebx,5*65536+9
  893.   mov  edx,[line_]
  894.   add  edx,2
  895.   mov  esi,0x9000a0
  896.   mov  eax,8
  897.   int  0x40
  898.  pop  ecx
  899. ;E:.
  900. ;B+ Clear zone for line
  901.   shl  ecx,16
  902.   mov  cx,10
  903.   mov  ebx,(5+11)*65536+win_field-5-12
  904.   xor  edx,edx
  905.   mov  dx,[activ_depth]
  906.    mov  edx,[color_depth+4*edx]
  907.    mov  eax,13
  908.   int  0x40
  909. ;E:.
  910. ;B+ Clear main text zone
  911.   mov  ebx,(win_field)*65536+(win_width-win_field-8)
  912.   mov  eax,[line_]
  913.   lea  eax,[lines_view+4*eax]
  914.  push eax
  915.   mov  ax,[eax]
  916.   cmp  ax,[activ_depth]
  917.   jne  .draw_all_line
  918.   mov  eax,[esp]
  919.   cmp  bx,[eax+2]
  920.   jle  .draw_all_line
  921.   mov  bx,[eax+2]
  922. .draw_all_line:
  923.   mov  eax,13
  924.   int  0x40
  925. ;E:.
  926. ;B+ Update line type I
  927.   pop  eax
  928.   mov  bx,[activ_depth]
  929.   mov  [eax],bx
  930. ;E:.
  931.   ret
  932.    
  933. activ_depth dw 0x0
  934. color_depth dd 0x404040,0x606060,0x707070,0x7a7a7a
  935.             dd 0x878787,0x909090,0x9a9a9a,0xa5a5a5
  936.             dd 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
  937. lines_view: times 35 dd 0
  938. ;E:.
  939. line_up:
  940. ;B+ Line up
  941. ;B+ Test jumps I
  942.   mov  ebx,[activ_pos]
  943.   cmp  ebx,[activ_file]
  944.   jne  .yes_scroll
  945.   cmp  [activ_depth],0
  946.   jz   .top_of_file
  947.   dec  [activ_depth]
  948.   xor  eax,eax
  949.   mov  ax,[ebx-8]
  950.   mov  eax,[file_array+4*eax]
  951.   mov  [activ_file],eax
  952.   add  eax,[ebx-12]
  953.   mov  [activ_pos],eax
  954.   mov  ax,[ebx-6]
  955.   mov  [activ_line],ax
  956. .top_of_file:
  957.   ret
  958. ;E:.
  959. .yes_scroll:
  960.   sub  ebx,2
  961. .normal_line_up1:
  962.   cmp  byte [ebx],new_line
  963.   je   .line_ok
  964.   dec  ebx
  965.   jmp  .normal_line_up1
  966. .line_ok:
  967. ;B+ Test for special line
  968.   cmp  dword [ebx],new_line
  969.   jne  .line_ok1
  970.   sub  ebx,9
  971. ;E:.
  972. .line_ok1:
  973.   inc  ebx
  974.   test word [ebx],not 15
  975.   jnz  .normal_line_up
  976.   test word [ebx],1
  977.   jz   .normal_line_up
  978. ;B+ Test jumps II
  979.   cmp  word [ebx],type_end_normal+1
  980.   je   .to_begin
  981.   cmp  word [ebx],type_end_plus+1
  982.   je   .to_begin
  983.   cmp  word [ebx],type_include+1
  984.   je   .to_incl
  985.   jmp  .normal_line_up
  986. ;E:.
  987. .to_begin:
  988.   mov  eax,[ebx+4]
  989.   add  eax,[activ_file]
  990.   mov  [activ_pos],eax
  991.   mov  ax,[ebx+2]
  992.   inc  ax
  993.   sub  [activ_line],ax
  994.   ret
  995. .to_incl:
  996.   inc  [activ_depth]
  997.   mov  eax,[ebx+4]
  998.   mov  eax,[file_array+4*eax]
  999.   mov  [activ_file],eax
  1000.   mov  bx,[eax-4]
  1001.   mov  [activ_line],bx
  1002.   add  eax,[eax-16]
  1003.   mov  [activ_pos],eax
  1004.   ret
  1005. .normal_line_up:
  1006.   mov  [activ_pos],ebx
  1007.   dec  [activ_line]
  1008.   ret
  1009. ;E:.
  1010. line_down:
  1011. ;B+ Line down
  1012.   mov  ebx,[activ_pos]
  1013.   cmp  byte [ebx],char_end
  1014.   jne  .yes_scroll
  1015.   cmp  [activ_depth],0
  1016.   jne  .yes_scroll
  1017.   ret
  1018. .yes_scroll:
  1019.   cmp  byte [ebx],new_line
  1020.   je   .normal_line_down
  1021.   test word [ebx],not 15
  1022.   jnz  .normal_line_down
  1023.   test word [ebx],1
  1024.   jz   .not_activated
  1025. ;B+ Test jumps
  1026.   cmp  word [ebx],type_begin+1
  1027.   jne  .no_begin
  1028.   mov  eax,[ebx+4]
  1029.   add  eax,[activ_file]
  1030.   mov  [activ_pos],eax
  1031.   mov  ax,[ebx+2]
  1032.   add  [activ_line],ax
  1033.   call line_down
  1034.   ret
  1035. .no_begin:
  1036.   cmp  word [ebx],type_end_normal+1
  1037.   je   .not_activated
  1038.   cmp  word [ebx],type_end_plus+1
  1039.   je   .not_activated
  1040.   ;goto include
  1041.   cmp  word [ebx],type_include+1
  1042.   jne  .no_incl
  1043.   inc  [activ_depth]
  1044.   mov  eax,[ebx+4]
  1045.   mov  eax,[file_array+4*eax]
  1046.   mov  [activ_file],eax
  1047.   mov  [activ_pos],eax
  1048.   mov  [activ_line],1
  1049.   ret
  1050. .no_incl:
  1051.   ;return from include
  1052.   cmp  word [ebx],type_file_end
  1053.   jne  .no_end
  1054. ;CHECK FOR FIRST
  1055.   mov  ax,[ebx+2]
  1056.   mov  [activ_line],ax
  1057.   dec  [activ_depth]
  1058.   mov  ecx,[activ_file]
  1059.   xor  eax,eax
  1060.   mov  ax,[ecx-8]
  1061.   mov  eax,[file_array+4*eax]
  1062.   mov  [activ_file],eax
  1063.   add  eax,[ebx+4]
  1064.   mov  [activ_pos],eax
  1065.   mov  ebx,eax
  1066.   ret
  1067. .no_end:
  1068. ;E:.
  1069. .not_activated:
  1070.   add  ebx,12 ;sckip system zone
  1071. .normal_line_down:
  1072.   cmp  byte [ebx],new_line
  1073.   je   .line_ok
  1074.   cmp  byte [ebx],char_end
  1075.   inc  ebx
  1076.   jmp  .normal_line_down
  1077. .line_ok:
  1078.   inc  ebx
  1079.   mov  [activ_pos],ebx
  1080.   inc  [activ_line]
  1081.   ret
  1082. ;E:.
  1083. ;B+ File possition var.
  1084. line_      dd 0x0 ;Line on screen
  1085.    
  1086. top_pos    dd start_data
  1087. top_line   dw 1
  1088. top_depth  dw 0x0
  1089. activ_pos  dd start_data
  1090. activ_line dw 0x0 ;Abs line in file
  1091. ;E:.
  1092. ;E:.
  1093.    
  1094. ;B+ Load file tools
  1095. load_file:
  1096. ;B+ Main
  1097. ;B+ Init parameters
  1098.   mov  [top_pos],start_data
  1099.   mov  [activ_pos],start_data
  1100.   mov  [top_file],start_data
  1101.   mov  [activ_file],start_data
  1102.   mov  [file_array],start_data
  1103.   mov  [top_free_file],1
  1104.   mov  [end_of_file],start_data
  1105.   mov  [top_line],1
  1106.   mov  esi,file_txt
  1107.   mov  edi,incl_filename
  1108.   mov  ecx,25
  1109.   cld
  1110. rep movsb
  1111. ;E:.
  1112. load_file1:
  1113. ;B+ Load and fresh file
  1114.   mov  eax,[end_of_file]
  1115.  push eax
  1116.   call add_file
  1117.   mov  edi,[esp]
  1118.   mov  esi,incl_filename
  1119.   sub  edi,16+25+2
  1120.   mov  ecx,27
  1121.   cld
  1122. rep movsb
  1123.   pop  edi
  1124.   mov  word [edi-18],25
  1125.   mov  eax,[top_pos]
  1126.   mov  [activ_pos],eax
  1127.   call fresh_file
  1128.    
  1129.   call  draw_window
  1130.    
  1131.   jmp  still
  1132. ;E:.
  1133. ;E:.
  1134. fresh_file:
  1135. ;B+ Fresh file
  1136.   mov  [line_],0
  1137.   mov  [next_],next
  1138. .fresh_next:
  1139.   inc  [line_]
  1140.   ;Test open block
  1141.   mov  eax,[begin_txt]
  1142.   mov  ebx,[activ_pos]
  1143.   cmp  [ebx],eax
  1144.   je   block_begin
  1145.   ;Test close block
  1146.   mov  eax,[end_txt]
  1147.   cmp  [ebx],eax
  1148.   je   block_end
  1149. ;B+ Test include
  1150.   mov  esi,ebx
  1151.   mov  edi,include_txt
  1152.   mov  ecx,20
  1153.   cld
  1154. rep cmpsb
  1155.   cmp  byte [edi-1],char_end
  1156.   je  include_file
  1157. ;E:.
  1158. next:
  1159. ;B+ Go to next line
  1160.   mov  ebx,[activ_pos]
  1161. .next_char:
  1162.   cmp  byte [ebx],new_line
  1163.   je   yes_next
  1164.   cmp  byte [ebx],char_end
  1165.   je   file_end
  1166.   inc  ebx
  1167.   jmp  .next_char
  1168. yes_next:
  1169.   inc  ebx
  1170.   inc  [activ_line]
  1171.   mov  [activ_pos],ebx
  1172.   jmp  fresh_file.fresh_next
  1173. ;E:.
  1174. file_end:
  1175. ;B+ Auto set close block
  1176.   mov  [next_],.try_fill_next
  1177.   sub  ebx,5
  1178.   dec  [activ_line]
  1179.   mov  [activ_pos],ebx
  1180. .try_fill_next:
  1181.   add  [activ_pos],5
  1182.   inc  [activ_line]
  1183.   mov  ebx,[activ_pos]
  1184.   mov  eax,[end_txt]
  1185.   mov  ecx,[block_pointer]
  1186.   cmp  word [ecx-4],char_end
  1187.   je   .fill_ok
  1188.    inc  [line_]
  1189.    call ins_5_bytes
  1190.   mov  dword [ebx],eax
  1191.   mov  byte [ebx+4],new_line
  1192.   mov  byte [ebx+5],char_end
  1193.   mov  [activ_pos],ebx
  1194.   jmp  block_end
  1195. ;E:.
  1196. .fill_ok:
  1197.  ret
  1198. ;E:.
  1199. ;B+ Specify line markers
  1200. block_begin:
  1201. ;B+ Mark block begin
  1202. ;B+ Mark info in stack
  1203.   mov  eax,[activ_pos]
  1204.   mov  ebx,[block_pointer]
  1205.  push eax
  1206.   sub  eax,[activ_file]
  1207.   mov  [ebx],eax
  1208.  pop  eax
  1209.   mov  word [ebx+4],0
  1210.   mov  cx,[activ_line]
  1211.   mov  word [ebx+6],cx
  1212.   add  ebx,8
  1213.   mov  [block_pointer],ebx
  1214. ;E:.
  1215.   call ins_12_bytes
  1216.   ;line / possition not ready
  1217.   mov  word [eax],type_begin+1
  1218.   mov  dword [eax+8],new_line
  1219.   add  [activ_pos],12
  1220.   jmp  [next_]
  1221. ;E:.
  1222. block_end:
  1223. ;B+ Mark block end
  1224. ;B+ Mark end type I
  1225.   mov  eax,[activ_pos]
  1226.   call ins_12_bytes
  1227.   mov  ecx,[block_pointer]
  1228.   cmp  word [ecx-4],char_end
  1229.   je   .normal_line
  1230. ;E:.
  1231.   ;Pop stack
  1232.   sub  [block_pointer],8
  1233.   sub  ecx,8
  1234. ;B+ Form this (END) line/place to BEGIN
  1235.   mov  edx,[ecx]
  1236.   add  edx,[activ_file]
  1237.   mov  eax,[activ_pos]
  1238.   sub  eax,[activ_file]
  1239.   mov  [edx+4],eax
  1240.   mov  bx,[activ_line]
  1241.   sub  bx,[ecx+6]
  1242.   mov  [edx+2],bx
  1243. ;E:.
  1244. ;B+ From stack line/place to this (END)
  1245.   mov  eax,[activ_pos]
  1246.   mov  edx,[ecx]
  1247.   mov  [eax+4],edx
  1248.   mov  [eax+2],bx
  1249. ;E:.
  1250. ;B+ Mark end type II
  1251.   mov  word [eax],type_end_normal+1
  1252.   mov  ecx,[next_]
  1253.   cmp  ecx,next
  1254.   je   .yes_normal
  1255.   mov  word [eax],type_end_plus+1
  1256. .yes_normal:
  1257.   mov  dword [eax+8],new_line
  1258.   add  [activ_pos],12
  1259.   jmp  [next_]
  1260. .normal_line:
  1261.   mov  word [eax],type_not_end
  1262.   mov  dword [eax+8],new_line
  1263.   add  [activ_pos],12
  1264.   jmp  [next_]
  1265. ;E:.
  1266. ;E:.
  1267. include_file:
  1268. ;B+ Include and attach file
  1269.   mov  eax,[activ_pos]
  1270.  push eax
  1271.   call ins_12_bytes
  1272.  pop  eax
  1273.   mov  word [eax],type_include
  1274.   mov  word [eax+2],0
  1275.   mov  dword [eax+4],-1
  1276.   mov  dword [eax+8],new_line
  1277.   dec  [line_]
  1278.   jmp  [next_]
  1279. ;E:.
  1280.    
  1281. next_ dd next
  1282. ;E:.
  1283. ;B+ Additional tools
  1284. ins_12_bytes:
  1285.   mov  ecx,[end_of_file]
  1286.   add  [end_of_file],12
  1287.   mov  esi,ecx
  1288.   add  ecx,12
  1289.   mov  edi,ecx
  1290.   sub  ecx,11
  1291.   sub  ecx,eax
  1292.   std
  1293. rep movsb
  1294.   mov  ecx,[activ_file]
  1295.   add  dword [ecx-16],12
  1296.   ret
  1297.    
  1298. ins_5_bytes:
  1299.   mov  ecx,[end_of_file]
  1300.   add  [end_of_file],5
  1301.   mov  esi,ecx
  1302.   add  ecx,5
  1303.   mov  edi,ecx
  1304.   sub  ecx,4
  1305.   sub  ecx,ebx
  1306.   std
  1307. rep movsb
  1308.   mov  ecx,[activ_file]
  1309.   add  dword [ecx-16],5
  1310.   ret
  1311.    
  1312. ins_1_byte:
  1313.   mov  ecx,[end_of_file]
  1314.    inc  [end_of_file]
  1315.    mov  esi,ecx
  1316.   inc  ecx
  1317.   mov  edx,ecx
  1318.   sub  ecx,ebx
  1319.   std
  1320. rep movsb
  1321.   mov  ecx,[activ_file]
  1322.   inc  dword [ecx-16]
  1323.   ret
  1324. ;E:.
  1325. ;E:.
  1326.    
  1327. ;B+ Data section
  1328.    
  1329. ;B+ View data
  1330. caption db 'CODE VIEWER - ver. 0.2'
  1331. caption_end:
  1332.    
  1333. line1up1 db 'LINE'
  1334. line1up1_end:
  1335. line1up2 db 'FILE:'
  1336. line1up2_end:
  1337.    
  1338. line1down:
  1339. filetxt db 'FILE->'
  1340. filetxt_end:
  1341. times 28 db ' '
  1342. loadtxt db 'LOAD'
  1343. loadtxt_end:
  1344. db '  BLOCK: '
  1345. begintxt db 'BEGIN->'
  1346. begintxt_end:
  1347. times 10 db ' '
  1348. db '...'
  1349. times 10 db ' '
  1350. endtxt db '<-END'
  1351. endtxt_end:
  1352. line1down_end:
  1353.    
  1354. line2down:
  1355. inctxt db 'INCLUDE KEYWORD->'
  1356. inctxt_end:
  1357. times 46 db ' '
  1358. septxt db 'SEPARATORS->'
  1359. septxt_end:
  1360. line2down_end:
  1361. ;E:.
  1362. ;B+ Parameter strings
  1363. str_start dd it1
  1364. str_table dd it1,0,it2,it3,it4,it5
  1365. ;align
  1366. it1:
  1367.  dd 25
  1368.  dd (20+6*7)*65536+35*10+win_toptext+3
  1369. file_txt:
  1370.  db 'KERNEL.ASM               ',char_end
  1371. ;align 4
  1372. it2:
  1373.  dd 4
  1374.  dd (20+56*6)*65536+35*10+win_toptext+3
  1375. begin_txt:
  1376.  db ';B+ ',char_end
  1377. ;align 4
  1378. it3:
  1379.  dd 4
  1380.  dd (20+71*6)*65536+35*10+win_toptext+3
  1381. end_txt:
  1382.  db ';E:.',char_end
  1383. ;align 4
  1384. it4:
  1385.  dd 43
  1386.  dd (20+18*6)*65536+35*10+win_toptext+3+14
  1387. include_txt:
  1388.  db 'include ',char_end,'                                   '
  1389.  ;align 4
  1390. it5:
  1391.  dd 2
  1392.  dd (20+76*6)*65536+35*10+win_toptext+3+14
  1393. skoba_txt:
  1394.  db '""    ',char_end
  1395. ;E:.
  1396.    
  1397. block_pointer dd block_stack+8
  1398. block_stack dw 0,0,char_end,0
  1399.             times 10*2 dd 0x0
  1400.    
  1401. ; STACK BOX:
  1402. ; ÚÄÄÄÄÄÄÄÄÄÂÄÄÄÄÂÄÄÄÄÏ
  1403. ; Óabs placeÓ  0 ÓlineÓ
  1404. ; ÀÄÄÄÄÄÄÄÄÄÁÄÄÄÄÁÄÄÄÄÙ
  1405. ; or 0000 'char_end' 00 - bottom
  1406.    
  1407. top_file   dd start_data
  1408. activ_file dd start_data
  1409. top_free_file dd 1
  1410. file_array dd start_data
  1411.            times 50 dd 0x0
  1412.    
  1413. end_of_file dd start_data
  1414.    
  1415. ; TEXT MARKER:
  1416. ; ÚÄÄÄÄÂÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÏ
  1417. ; ÓtypeÓn.l.Ónew placeÓ    13   Ó
  1418. ; ÀÄÄÄÄÁÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÙ
  1419.    
  1420. ;E:.
  1421.    
  1422. ;B+ Program preview
  1423. ;ÚÄÄÄÄÄ
  1424. ;ÓCODE VIEWER - ver. 0.2    o _ x
  1425. ;ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  1426. ;Ó    Line | File:
  1427. ;Ó---------+---------------------
  1428. ;Ó[+]    |
  1429. ;Ó[-]    |
  1430. ;Ó[ ]    |
  1431. ;Ó[#]    |
  1432. ;ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  1433. ;Ó [FILE->]___________      [LOAD] BLOCK: [BEGIN->];B+ú   ...  ;E:.[<-END] Ó
  1434. ;Ó [INCLUDE KEYWORD->]include     [SEPARATORS->]""
  1435. ;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  1436. ;E:.
  1437.    
  1438. I_END:
  1439.  
  1440.