Subversion Repositories Kolibri OS

Rev

Rev 827 | Rev 1102 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;-----------------------------------------------------------------------------
  2. ; project name:      TINYPAD
  3. ; compiler:          flat assembler 1.67.21
  4. ; memory to compile: 3.0/9.0 MBytes (without/with size optimizations)
  5. ; version:           SVN (4.0.5)
  6. ; last update:       2008-07-18 (Jul 18, 2008)
  7. ; minimal kernel:    revision #823 (svn://kolibrios.org/kernel/trunk)
  8. ;-----------------------------------------------------------------------------
  9. ; originally by:     Ville Michael Turjanmaa >> villemt@aton.co.jyu.fi
  10. ; maintained by:     Mike Semenyako          >> mike.dld@gmail.com
  11. ;                    Ivan Poddubny           >> ivan-yar@bk.ru
  12. ;-----------------------------------------------------------------------------
  13. ; TODO (4.1.0):
  14. ;   - add vertical selection, undo, goto position, overwrite mode, smart tabulation
  15. ;   - improve window drawing with small dimensions
  16. ;   - save/load settings to/from ini file, not executable
  17. ;   - path autocompletion for open/save dialogs
  18. ;   - other bug-fixes and speed/size optimizations
  19. ;-----------------------------------------------------------------------------
  20. ; See history.txt for complete changelog
  21. ;-----------------------------------------------------------------------------
  22.  
  23. include 'lang.inc'
  24.  
  25. include '../../../macros.inc' ; useful stuff
  26. include '../../../struct.inc'
  27. include '../../../proc32.inc'
  28.  
  29. include 'external/libio.inc'
  30.  
  31. include 'tinypad.inc'
  32.  
  33. ;purge mov,add,sub            ;  SPEED
  34.  
  35. header '01',1,@CODE,TINYPAD_END,STATIC_MEM_END,MAIN_STACK,@PARAMS,ini_path
  36.  
  37. APP_VERSION equ 'SVN (4.0.5)'
  38.  
  39. TRUE = 1
  40. FALSE = 0
  41.  
  42. ;include 'debug.inc'
  43. ;define __DEBUG__ 1
  44. ;define __DEBUG_LEVEL__ 1
  45. ;include 'debug-fdo.inc'
  46.  
  47. ; compiled-in options
  48.  
  49. ASEPC = '-'  ; separator character (char)
  50. ATOPH = 19   ; menu bar height (pixels)
  51. SCRLW = 16   ; scrollbar widht/height (pixels)
  52. ATABW = 8    ; tab key indent width (chars)
  53. LINEH = 10   ; line height (pixels)
  54. PATHL = 256  ; maximum path length (chars) !!! don't change !!!
  55. AMINS = 8    ; minimal scroll thumb size (pixels)
  56. LCHGW = 3    ; changed/saved marker width (pixels)
  57.  
  58. STATH = 16   ; status bar height (pixels)
  59. TBARH = 18   ; tab bar height (pixels)
  60.  
  61. INI_SEC_PREFIX equ ''
  62.  
  63. ;-----------------------------------------------------------------------------
  64. section @CODE ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  65. ;-----------------------------------------------------------------------------
  66.  
  67.         cld
  68.         mov     edi,@UDATA
  69.         mov     ecx,@PARAMS-@UDATA
  70.         mov     al,0
  71.         rep     stosb
  72.  
  73.         mcall   68,11
  74.         or      eax,eax
  75.         jz      key.alt_x.close
  76.  
  77.         stdcall dll.Load,@IMPORT
  78.         or      eax,eax
  79.         jnz     key.alt_x.close
  80.  
  81.         mov     edi,ini_path
  82.         xor     al,al
  83.         mov     ecx,PATHL
  84.         repne   scasb
  85.         mov     dword[edi-1],'.ini'
  86.         mov     byte[edi+3],0
  87.  
  88.         stdcall load_settings
  89.  
  90.         stdcall mem.Alloc,65536
  91.         mov     [temp_buf],eax
  92.  
  93.         inc     [do_not_draw]
  94.  
  95.         mov     dword[app_start],7
  96.  
  97.         mov     esi,s_example
  98.         mov     edi,tb_opensave.text
  99.         mov     ecx,s_example.size
  100.         mov     [tb_opensave.length],cl
  101.         rep     movsb
  102.  
  103.         mov     esi,s_still
  104.         mov     edi,s_search
  105.         mov     ecx,s_still.size
  106.         mov     [s_search.size],ecx
  107.         rep     movsb
  108.  
  109.         cmp     byte[@PARAMS],0
  110.         jz      no_params
  111.  
  112. ;// Willow's code to support DOCPAK [
  113.  
  114.         cmp     byte[@PARAMS],'*'
  115.         jne     .noipc
  116.  
  117. ;// diamond [ (convert size from decimal representation to dword)
  118. ;--     mov     edx,dword[@PARAMS+1]
  119.         mov     esi,@PARAMS+1
  120.         xor     edx,edx
  121.         xor     eax,eax
  122.     @@: lodsb
  123.         test    al,al
  124.         jz      @f
  125.         lea     edx,[edx*4+edx]
  126.         lea     edx,[edx*2+eax-'0']
  127.         jmp     @b
  128.     @@:
  129. ;// diamond ]
  130.  
  131.         add     edx,20
  132.  
  133.         stdcall mem.Alloc,edx
  134.         mov     ebp,eax
  135.         push    eax
  136.  
  137.         mov     dword[ebp+0],0
  138.         mov     dword[ebp+4],8
  139.         mcall   60,1,ebp
  140.         mcall   40,1000000b
  141.  
  142.         mcall   23,200
  143.  
  144.         cmp     eax,7
  145.         jne     key.alt_x.close
  146.         mov     byte[ebp],1
  147.  
  148.         mov     ecx,[ebp+12]
  149.         lea     esi,[ebp+16]
  150.         call    create_tab
  151.         call    load_from_memory
  152.  
  153.         pop     ebp
  154.         stdcall mem.Free,ebp
  155.  
  156.         jmp     @f
  157.   .noipc:
  158.  
  159. ;// Willow's code to support DOCPAK ]
  160.  
  161.         mov     esi,@PARAMS
  162.         mov     edi,tb_opensave.text
  163.         mov     ecx,PATHL
  164.         rep     movsb
  165.         mov     edi,tb_opensave.text
  166.         mov     ecx,PATHL
  167.         xor     al,al
  168.         repne   scasb
  169.         jne     key.alt_x.close
  170.         lea     eax,[edi-tb_opensave.text-1]
  171.         mov     [tb_opensave.length],al
  172.         call    load_file
  173.         jnc     @f
  174.  
  175.   no_params:
  176.         call    create_tab
  177.  
  178.     @@:
  179.         mov     [s_status],0
  180.         dec     [do_not_draw]
  181.  
  182.         mov     al,[tabs_pos]
  183.         mov     [tab_bar.Style],al
  184.  
  185.         mcall   66,1,1
  186.         mcall   40,00100111b
  187. red:
  188.         call    drawwindow
  189.  
  190. ;-----------------------------------------------------------------------------
  191.  
  192. still:
  193.         call    draw_statusbar ; write current position & number of strings
  194.  
  195.   .skip_write:
  196.         mcall   10      ; wait here until event
  197.         cmp     [main_closed],0
  198.         jne     key.alt_x
  199.         dec     eax     ; redraw ?
  200.         jz      red
  201.         dec     eax     ; key ?
  202.         jz      key
  203.         dec     eax     ; button ?
  204.         jz      button
  205.         sub     eax,3   ; mouse ?
  206.         jz      mouse
  207.  
  208.         jmp     still.skip_write
  209.  
  210. ;-----------------------------------------------------------------------------
  211. proc get_event ctx ;//////////////////////////////////////////////////////////
  212. ;-----------------------------------------------------------------------------
  213.         mcall   10
  214.         dec     eax     ; redraw ?
  215.         jz      .redraw
  216.         dec     eax     ; key ?
  217.         jz      .key
  218.         dec     eax     ; button ?
  219.         jz      .button
  220.         sub     eax,2   ; background ?
  221.         jz      .background
  222.         dec     eax     ; mouse ?
  223.         jz      .mouse
  224.         dec     eax     ; ipc ?
  225.         jz      .ipc
  226.         dec     eax     ; network ?
  227.         jz      .network
  228.         dec     eax     ; debug ?
  229.         jz      .debug
  230.         sub     eax,7   ; irq ?
  231.         js      .nothing
  232.         cmp     eax,15
  233.         jg      .nothing
  234.         jmp     .irq
  235.  
  236.   .nothing:
  237.         mov     eax,EV_IDLE
  238.         ret
  239.  
  240.   .redraw:
  241.         mov     eax,EV_REDRAW
  242.         ret
  243.  
  244.   .key:
  245.         mov     eax,EV_KEY
  246.         ret
  247.  
  248.   .button:
  249.         mov     eax,EV_BUTTON
  250.         ret
  251.  
  252.   .background:
  253.         mov     eax,EV_BACKGROUND
  254.         ret
  255.  
  256.   .mouse:
  257.         mov     eax,EV_MOUSE
  258.         ret
  259.  
  260.   .ipc:
  261.         mov     eax,EV_IPC
  262.         ret
  263.  
  264.   .network:
  265.         mov     eax,EV_NETWORK
  266.         ret
  267.  
  268.   .debug:
  269.         mov     eax,EV_DEBUG
  270.         ret
  271. endp
  272.  
  273. ;-----------------------------------------------------------------------------
  274. proc load_settings ;//////////////////////////////////////////////////////////
  275. ;-----------------------------------------------------------------------------
  276.         pushad
  277.  
  278.         invoke  ini.get_int,ini_path,ini_sec_options,ini_options_tabs_pos,2
  279.         mov     [tabs_pos],al
  280.         invoke  ini.get_int,ini_path,ini_sec_options,ini_options_secure_sel,0
  281.         mov     [secure_sel],al
  282.         invoke  ini.get_int,ini_path,ini_sec_options,ini_options_auto_braces,0
  283.         mov     [auto_braces],al
  284.         invoke  ini.get_int,ini_path,ini_sec_options,ini_options_auto_indent,1
  285.         mov     [auto_indent],al
  286.         invoke  ini.get_int,ini_path,ini_sec_options,ini_options_smart_tab,1
  287.         mov     [smart_tab],al
  288.         invoke  ini.get_int,ini_path,ini_sec_options,ini_options_optim_save,1
  289.         mov     [optim_save],al
  290.         invoke  ini.get_int,ini_path,ini_sec_options,ini_options_line_nums,0
  291.         mov     [line_nums],al
  292.  
  293.         invoke  ini.get_color,ini_path,ini_sec_colors,ini_colors_text,0x00000000
  294.         mov     [color_tbl.text],eax
  295.         invoke  ini.get_color,ini_path,ini_sec_colors,ini_colors_back,0x00ffffff
  296.         mov     [color_tbl.back],eax
  297.         invoke  ini.get_color,ini_path,ini_sec_colors,ini_colors_text_sel,0x00ffffff
  298.         mov     [color_tbl.text.sel],eax
  299.         invoke  ini.get_color,ini_path,ini_sec_colors,ini_colors_back_sel,0x000a246a
  300.         mov     [color_tbl.back.sel],eax
  301.         invoke  ini.get_color,ini_path,ini_sec_colors,ini_colors_symbol,0x003030f0
  302.         mov     [color_tbl.symbol],eax
  303.         invoke  ini.get_color,ini_path,ini_sec_colors,ini_colors_number,0x00009000
  304.         mov     [color_tbl.number],eax
  305.         invoke  ini.get_color,ini_path,ini_sec_colors,ini_colors_string,0x00b00000
  306.         mov     [color_tbl.string],eax
  307.         invoke  ini.get_color,ini_path,ini_sec_colors,ini_colors_comment,0x00808080
  308.         mov     [color_tbl.comment],eax
  309.         invoke  ini.get_color,ini_path,ini_sec_colors,ini_colors_line_moded,0x00ffee62
  310.         mov     [color_tbl.line.moded],eax
  311.         invoke  ini.get_color,ini_path,ini_sec_colors,ini_colors_line_saved,0x006ce26c
  312.         mov     [color_tbl.line.saved],eax
  313.  
  314.         invoke  ini.get_int,ini_path,ini_sec_window,ini_window_left,250
  315.         mov     [mainwnd_pos.x],eax
  316.         invoke  ini.get_int,ini_path,ini_sec_window,ini_window_top,75
  317.         mov     [mainwnd_pos.y],eax
  318.         invoke  ini.get_int,ini_path,ini_sec_window,ini_window_width,6*80+6+SCRLW+5
  319.         mov     [mainwnd_pos.w],eax
  320.         invoke  ini.get_int,ini_path,ini_sec_window,ini_window_height,402
  321.         mov     [mainwnd_pos.h],eax
  322.  
  323.         popad
  324.         ret
  325. endp
  326.  
  327. ;-----------------------------------------------------------------------------
  328. proc save_settings ;//////////////////////////////////////////////////////////
  329. ;-----------------------------------------------------------------------------
  330.         pushad
  331.  
  332.         movzx   eax,[tabs_pos]
  333.         invoke  ini.set_int,ini_path,ini_sec_options,ini_options_tabs_pos,eax
  334.         movzx   eax,[secure_sel]
  335.         invoke  ini.set_int,ini_path,ini_sec_options,ini_options_secure_sel,eax
  336.         movzx   eax,[auto_braces]
  337.         invoke  ini.set_int,ini_path,ini_sec_options,ini_options_auto_braces,eax
  338.         movzx   eax,[auto_indent]
  339.         invoke  ini.set_int,ini_path,ini_sec_options,ini_options_auto_indent,eax
  340.         movzx   eax,[smart_tab]
  341.         invoke  ini.set_int,ini_path,ini_sec_options,ini_options_smart_tab,eax
  342.         movzx   eax,[optim_save]
  343.         invoke  ini.set_int,ini_path,ini_sec_options,ini_options_optim_save,eax
  344.         movzx   eax,[line_nums]
  345.         invoke  ini.set_int,ini_path,ini_sec_options,ini_options_line_nums,eax
  346.  
  347.         invoke  ini.set_color,ini_path,ini_sec_colors,ini_colors_text,[color_tbl.text]
  348.         invoke  ini.set_color,ini_path,ini_sec_colors,ini_colors_back,[color_tbl.back]
  349.         invoke  ini.set_color,ini_path,ini_sec_colors,ini_colors_text_sel,[color_tbl.text.sel]
  350.         invoke  ini.set_color,ini_path,ini_sec_colors,ini_colors_back_sel,[color_tbl.back.sel]
  351.         invoke  ini.set_color,ini_path,ini_sec_colors,ini_colors_symbol,[color_tbl.symbol]
  352.         invoke  ini.set_color,ini_path,ini_sec_colors,ini_colors_number,[color_tbl.number]
  353.         invoke  ini.set_color,ini_path,ini_sec_colors,ini_colors_string,[color_tbl.string]
  354.         invoke  ini.set_color,ini_path,ini_sec_colors,ini_colors_comment,[color_tbl.comment]
  355.         invoke  ini.set_color,ini_path,ini_sec_colors,ini_colors_line_moded,[color_tbl.line.moded]
  356.         invoke  ini.set_color,ini_path,ini_sec_colors,ini_colors_line_saved,[color_tbl.line.saved]
  357.  
  358.         invoke  ini.set_int,ini_path,ini_sec_window,ini_window_left,[mainwnd_pos.x]
  359.         invoke  ini.set_int,ini_path,ini_sec_window,ini_window_top,[mainwnd_pos.y]
  360.         invoke  ini.set_int,ini_path,ini_sec_window,ini_window_width,[mainwnd_pos.w]
  361.         invoke  ini.set_int,ini_path,ini_sec_window,ini_window_height,[mainwnd_pos.h]
  362.  
  363.         popad
  364.         ret
  365. endp
  366.  
  367. ;-----------------------------------------------------------------------------
  368. proc start_fasm ;/////////////////////////////////////////////////////////////
  369. ;-----------------------------------------------------------------------------
  370. ; BL = run after compile
  371. ;-----------------------------------------------------------------------------
  372. ; FASM infile,outfile,/path/to/files[,run]
  373. ;-----------------------------------------------------------------------------
  374.         cmp     [cur_editor.AsmMode],0
  375.         jne     @f
  376.         ret
  377.     @@:
  378.         mov     eax,[tab_bar.Default.Ptr]
  379.         or      eax,eax
  380.         jnz     @f
  381.         mov     eax,[tab_bar.Current.Ptr]
  382.     @@: cmp     byte[eax+TABITEM.Editor.FilePath],'/'
  383.         je      @f
  384.         ret
  385.     @@:
  386.         mov     edi,fasm_parameters
  387.         push    eax
  388.  
  389.         cld
  390.  
  391.         lea     esi,[eax+TABITEM.Editor.FilePath]
  392.         add     esi,[eax+TABITEM.Editor.FileName]
  393.         push    esi esi
  394.     @@: lodsb
  395.         cmp     al,0
  396.         je      @f
  397.         stosb
  398.         cmp     al,'.'
  399.         jne     @b
  400.         mov     ecx,esi
  401.         jmp     @b
  402.     @@:
  403.         mov     al,','
  404.         stosb
  405.  
  406.         pop     esi
  407.         sub     ecx,esi
  408.         dec     ecx
  409.         jz      @f
  410.         rep     movsb
  411.     @@:
  412.         mov     al,','
  413.         stosb
  414.  
  415.         pop     ecx esi
  416.         add     esi,TABITEM.Editor.FilePath
  417.         sub     ecx,esi
  418.         rep     movsb
  419.  
  420.         cmp     bl,0 ; run outfile ?
  421.         je      @f
  422.         mov     dword[edi],',run'
  423.         add     edi,4
  424.     @@:
  425.         mov     al,0
  426.         stosb
  427.  
  428.         mov     [app_start.filename],app_fasm
  429.         mov     [app_start.params],fasm_parameters
  430. start_ret:
  431.         mcall   70,app_start
  432.         ret
  433. endp
  434.  
  435. ;-----------------------------------------------------------------------------
  436. proc open_debug_board ;///////////////////////////////////////////////////////
  437. ;-----------------------------------------------------------------------------
  438.         mov     [app_start.filename],app_board
  439.         mov     [app_start.params],0
  440.         jmp     start_ret
  441. endp
  442.  
  443. ;-----------------------------------------------------------------------------
  444. proc open_sysfuncs_txt ;//////////////////////////////////////////////////////
  445. ;-----------------------------------------------------------------------------
  446.         mov     [app_start.filename],app_docpak
  447.         mov     [app_start.params],sysfuncs_param
  448.         call    start_ret
  449.         cmp     eax,0xfffffff0
  450.         jb      @f
  451.         mov     [app_start.filename],app_tinypad
  452.         mov     [app_start.params],sysfuncs_filename
  453.         call    start_ret
  454.     @@: ret
  455. endp
  456.  
  457. set_opt:
  458.  
  459.   .dialog:
  460.         mov     [bot_mode],1
  461.         mov     [bot_dlg_height],128
  462.         mov     [bot_dlg_handler],optsdlg_handler
  463.         mov     [focused_tb],tb_color
  464.         mov     al,[tb_color.length]
  465.         mov     [tb_color.pos.x],al
  466.         mov     [tb_color.sel.x],0
  467.         mov     [tb_casesen],1
  468.         mov     [cur_part],0
  469.         m2m     [cur_color],dword[color_tbl.text]
  470.         mov     esi,color_tbl
  471.         mov     edi,cur_colors
  472.         mov     ecx,10
  473.         cld
  474.         rep     movsd
  475.         call    drawwindow
  476.         ret
  477.  
  478.   .line_numbers:
  479.         xor     [line_nums],1
  480.         ret
  481.   .optimal_fill:
  482.         xor     [optim_save],1
  483.         ret
  484.   .auto_indents:
  485.         xor     [auto_indent],1
  486.         ret
  487.   .auto_braces:
  488.         xor     [auto_braces],1
  489.         ret
  490.   .secure_sel:
  491.         xor     [secure_sel],1
  492.         ret
  493.  
  494. ;-----------------------------------------------------------------------------
  495.  
  496. include 'data/tp-defines.inc'
  497.  
  498. include 'tp-draw.asm'
  499. include 'tp-key.asm'
  500. include 'tp-button.asm'
  501. include 'tp-mouse.asm'
  502. include 'tp-files.asm'
  503. include 'tp-common.asm'
  504. include 'tp-dialog.asm'
  505. include 'tp-popup.asm'
  506. include 'tp-tbox.asm'
  507. include 'tp-tabctl.asm'
  508. include 'tp-editor.asm'
  509. include 'tp-recode.asm'
  510.  
  511. include 'external/dll.inc'
  512.  
  513. ;-----------------------------------------------------------------------------
  514. section @DATA ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  515. ;-----------------------------------------------------------------------------
  516.  
  517. ;include_debug_strings
  518.  
  519. include 'data/tp-idata.inc'
  520.  
  521. ;-----------------------------------------------------------------------------
  522. section @IMPORT ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  523. ;-----------------------------------------------------------------------------
  524.  
  525. library \
  526.         libini,'libini.obj',\
  527.         libio,'libio.obj',\
  528.         libgfx,'libgfx.obj'
  529.  
  530. import  libini, \
  531.         ini.get_str  ,'ini.get_str',\
  532.         ini.set_str  ,'ini.set_str',\
  533.         ini.get_int  ,'ini.get_int',\
  534.         ini.set_int  ,'ini.set_int',\
  535.         ini.get_color,'ini.get_color',\
  536.         ini.set_color,'ini.set_color'
  537.  
  538. import  libio, \
  539.         file.find_first,'file.find_first',\
  540.         file.find_next ,'file.find_next',\
  541.         file.find_close,'file.find_close',\
  542.         file.size      ,'file.size',\
  543.         file.open      ,'file.open',\
  544.         file.read      ,'file.read',\
  545.         file.write     ,'file.write',\
  546.         file.seek      ,'file.seek',\
  547.         file.tell      ,'file.tell',\
  548.         file.eof?      ,'file.eof?',\
  549.         file.truncate  ,'file.truncate',\
  550.         file.close     ,'file.close'
  551.  
  552. import  libgfx, \
  553.         gfx.open        ,'gfx.open',\
  554.         gfx.close       ,'gfx.close',\
  555.         gfx.pen.color   ,'gfx.pen.color',\
  556.         gfx.brush.color ,'gfx.brush.color',\
  557.         gfx.pixel       ,'gfx.pixel',\
  558.         gfx.move.to     ,'gfx.move.to',\
  559.         gfx.line.to     ,'gfx.line.to',\
  560.         gfx.line        ,'gfx.line',\
  561.         gfx.polyline    ,'gfx.polyline',\
  562.         gfx.polyline.to ,'gfx.polyline.to',\
  563.         gfx.fillrect    ,'gfx.fillrect',\
  564.         gfx.fillrect.ex ,'gfx.fillrect.ex',\
  565.         gfx.framerect   ,'gfx.framerect',\
  566.         gfx.framerect.ex,'gfx.framerect.ex',\
  567.         gfx.rectangle   ,'gfx.rectangle',\
  568.         gfx.rectangle.ex,'gfx.rectangle.ex'
  569.  
  570. TINYPAD_END:     ; end of file
  571.  
  572. ;-----------------------------------------------------------------------------
  573. section @UDATA ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  574. ;-----------------------------------------------------------------------------
  575.  
  576. include 'data/tp-udata.inc'
  577.  
  578. ;-----------------------------------------------------------------------------
  579. section @PARAMS ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  580. ;-----------------------------------------------------------------------------
  581.  
  582. fasm_parameters:
  583.  
  584. p_info  process_information
  585. p_info2 process_information
  586. sc      system_colors
  587.  
  588. ini_path rb PATHL
  589.  
  590. rb 1024*4
  591. MAIN_STACK:
  592. rb 1024*4
  593. POPUP_STACK:
  594.  
  595. STATIC_MEM_END:
  596.  
  597. diff10 'Main memory size',0,$
  598.