Subversion Repositories Kolibri OS

Rev

Rev 617 | Rev 827 | 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:           4.0.5
  6. ; last update:       2007-09-18 (Sep 18, 2007)
  7. ; minimal kernel:    revision #270 (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,self_path
  36.  
  37. APP_VERSION equ '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. ASEPC = '-'  ; separator character (char)
  48. ATOPH = 19   ; menu bar height (pixels)
  49. SCRLW = 16   ; scrollbar widht/height (pixels)
  50. ATABW = 8    ; tab key indent width (chars)
  51. LINEH = 10   ; line height (pixels)
  52. PATHL = 256  ; maximum path length (chars) !!! don't change !!!
  53. AMINS = 8    ; minimal scroll thumb size (pixels)
  54. LCHGW = 3    ; changed/saved marker width (pixels)
  55.  
  56. STATH = 16   ; status bar height (pixels)
  57. TBARH = 18   ; tab bar height (pixels)
  58.  
  59. ;-----------------------------------------------------------------------------
  60. section @OPTIONS ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  61. ;-----------------------------------------------------------------------------
  62.  
  63. label color_tbl dword
  64.   .text:       RGB(  0,  0,  0)
  65.   .back:       RGB(255,255,255)
  66.   .text.sel:   RGB(255,255,255)
  67.   .back.sel:   RGB( 10, 36,106)
  68.   .symbol:     RGB( 48, 48,240)
  69.   .number:     RGB(  0,144,  0)
  70.   .string:     RGB(176,  0,  0)
  71.   .comment:    RGB(128,128,128)
  72.   .line.moded: RGB(255,238, 98)
  73.   .line.saved: RGB(108,226,108)
  74.  
  75. ins_mode db 1
  76. tab_pos  db 2
  77.  
  78. options  db OPTS_AUTOINDENT+OPTS_OPTIMSAVE+OPTS_SMARTTAB
  79.  
  80. mainwnd_pos:
  81.   .x dd 250
  82.   .y dd 75
  83.   .w dd 6*80+6+SCRLW+5  ;- 220
  84.   .h dd 402             ;- 220
  85.  
  86. ;-----------------------------------------------------------------------------
  87. section @CODE ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  88. ;-----------------------------------------------------------------------------
  89.  
  90. ;       fninit
  91.  
  92. ;       stdcall ini.get_int,finfo_ini,ini_sec_window,ini_window_left,50
  93. ;       mov     [mainwnd_pos.x],eax
  94. ;       stdcall ini.get_int,finfo_ini,ini_sec_window,ini_window_top,50
  95. ;       mov     [mainwnd_pos.y],eax
  96. ;       stdcall ini.get_int,finfo_ini,ini_sec_window,ini_window_right,350
  97. ;       sub     eax,[mainwnd_pos.x]
  98. ;       mov     [mainwnd_pos.w],eax
  99. ;       stdcall ini.get_int,finfo_ini,ini_sec_window,ini_window_bottom,450
  100. ;       sub     eax,[mainwnd_pos.y]
  101. ;       mov     [mainwnd_pos.h],eax
  102.  
  103.         cld
  104.         mov     edi,@UDATA
  105.         mov     ecx,@PARAMS-@UDATA
  106.         mov     al,0
  107.         rep     stosb
  108.  
  109.         mov     al,[tab_pos]
  110.         mov     [tab_bar.Style],al
  111.  
  112.         mcall   68,11
  113.         or      eax,eax
  114.         jz      key.alt_x.close
  115.  
  116.         stdcall dll.Load,@IMPORT
  117.         or      eax,eax
  118.         jnz     key.alt_x.close
  119.  
  120.         stdcall mem.Alloc,65536
  121.         mov     [temp_buf],eax
  122.  
  123.         inc     [do_not_draw]
  124.  
  125.         mov     dword[app_start],7
  126.  
  127.         mov     esi,s_example
  128.         mov     edi,tb_opensave.text
  129.         mov     ecx,s_example.size
  130.         mov     [tb_opensave.length],cl
  131.         rep     movsb
  132.  
  133.         mov     esi,s_still
  134.         mov     edi,s_search
  135.         mov     ecx,s_still.size
  136.         mov     [s_search.size],ecx
  137.         rep     movsb
  138.  
  139.         cmp     byte[@PARAMS],0
  140.         jz      no_params
  141.  
  142. ;// Willow's code to support DOCPAK [
  143.  
  144.         cmp     byte[@PARAMS],'*'
  145.         jne     .noipc
  146.  
  147. ;// diamond [ (convert size from decimal representation to dword)
  148. ;--     mov     edx,dword[@PARAMS+1]
  149.         mov     esi,@PARAMS+1
  150.         xor     edx,edx
  151.         xor     eax,eax
  152.     @@: lodsb
  153.         test    al,al
  154.         jz      @f
  155.         lea     edx,[edx*4+edx]
  156.         lea     edx,[edx*2+eax-'0']
  157.         jmp     @b
  158.     @@:
  159. ;// diamond ]
  160.  
  161.         add     edx,20
  162.  
  163.         stdcall mem.Alloc,edx
  164.         mov     ebp,eax
  165.         push    eax
  166.  
  167.         mov     dword[ebp+0],0
  168.         mov     dword[ebp+4],8
  169.         mcall   60,1,ebp
  170.         mcall   40,1000000b
  171.  
  172.         mcall   23,200
  173.  
  174.         cmp     eax,7
  175.         jne     key.alt_x.close
  176.         mov     byte[ebp],1
  177.  
  178.         mov     ecx,[ebp+12]
  179.         lea     esi,[ebp+16]
  180.         call    create_tab
  181.         call    load_from_memory
  182.  
  183.         pop     ebp
  184.         stdcall mem.Free,ebp
  185.  
  186.         jmp     @f
  187.   .noipc:
  188.  
  189. ;// Willow's code to support DOCPAK ]
  190.  
  191.         mov     esi,@PARAMS
  192.         mov     edi,tb_opensave.text
  193.         mov     ecx,PATHL
  194.         rep     movsb
  195.         mov     edi,tb_opensave.text
  196.         mov     ecx,PATHL
  197.         xor     al,al
  198.         repne   scasb
  199.         jne     key.alt_x.close
  200.         lea     eax,[edi-tb_opensave.text-1]
  201.         mov     [tb_opensave.length],al
  202.         call    load_file
  203.         jnc     @f
  204.  
  205.   no_params:
  206.         call    create_tab
  207.  
  208.     @@:
  209.         mov     [s_status],0
  210.         dec     [do_not_draw]
  211.         mcall   66,1,1
  212.         mcall   40,00100111b
  213. red:
  214.         call    drawwindow
  215.  
  216. ;-----------------------------------------------------------------------------
  217.  
  218. still:
  219.         call    draw_statusbar ; write current position & number of strings
  220.  
  221.   .skip_write:
  222.         mcall   10      ; wait here until event
  223.         cmp     [main_closed],0
  224.         jne     key.alt_x
  225.         dec     eax     ; redraw ?
  226.         jz      red
  227.         dec     eax     ; key ?
  228.         jz      key
  229.         dec     eax     ; button ?
  230.         jz      button
  231.         sub     eax,3   ; mouse ?
  232.         jz      mouse
  233.  
  234.         jmp     still.skip_write
  235.  
  236. ;-----------------------------------------------------------------------------
  237. proc get_event ctx ;//////////////////////////////////////////////////////////
  238. ;-----------------------------------------------------------------------------
  239.         mcall   10
  240.         dec     eax     ; redraw ?
  241.         jz      .redraw
  242.         dec     eax     ; key ?
  243.         jz      .key
  244.         dec     eax     ; button ?
  245.         jz      .button
  246.         sub     eax,2   ; background ?
  247.         jz      .background
  248.         dec     eax     ; mouse ?
  249.         jz      .mouse
  250.         dec     eax     ; ipc ?
  251.         jz      .ipc
  252.         dec     eax     ; network ?
  253.         jz      .network
  254.         dec     eax     ; debug ?
  255.         jz      .debug
  256.         sub     eax,7   ; irq ?
  257.         js      .nothing
  258.         cmp     eax,15
  259.         jg      .nothing
  260.         jmp     .irq
  261.  
  262.   .nothing:
  263.         mov     eax,EV_IDLE
  264.         ret
  265.  
  266.   .redraw:
  267.         mov     eax,EV_REDRAW
  268.         ret
  269.  
  270.   .key:
  271.         mov     eax,EV_KEY
  272.         ret
  273.  
  274.   .button:
  275.         mov     eax,EV_BUTTON
  276.         ret
  277.  
  278.   .background:
  279.         mov     eax,EV_BACKGROUND
  280.         ret
  281.  
  282.   .mouse:
  283.         mov     eax,EV_MOUSE
  284.         ret
  285.  
  286.   .ipc:
  287.         mov     eax,EV_IPC
  288.         ret
  289.  
  290.   .network:
  291.         mov     eax,EV_NETWORK
  292.         ret
  293.  
  294.   .debug:
  295.         mov     eax,EV_DEBUG
  296.         ret
  297. endp
  298.  
  299. ;-----------------------------------------------------------------------------
  300. proc start_fasm ;/////////////////////////////////////////////////////////////
  301. ;-----------------------------------------------------------------------------
  302. ; BL = run after compile
  303. ;-----------------------------------------------------------------------------
  304. ; FASM infile,outfile,/path/to/files[,run]
  305. ;-----------------------------------------------------------------------------
  306.         cmp     [cur_editor.AsmMode],0
  307.         jne     @f
  308.         ret
  309.     @@:
  310.         mov     eax,[tab_bar.Default.Ptr]
  311.         or      eax,eax
  312.         jnz     @f
  313.         mov     eax,[tab_bar.Current.Ptr]
  314.     @@: cmp     byte[eax+TABITEM.Editor.FilePath],'/'
  315.         je      @f
  316.         ret
  317.     @@:
  318.         mov     edi,fasm_parameters
  319.         push    eax
  320.  
  321.         cld
  322.  
  323.         lea     esi,[eax+TABITEM.Editor.FilePath]
  324.         add     esi,[eax+TABITEM.Editor.FileName]
  325.         push    esi esi
  326.     @@: lodsb
  327.         cmp     al,0
  328.         je      @f
  329.         stosb
  330.         cmp     al,'.'
  331.         jne     @b
  332.         mov     ecx,esi
  333.         jmp     @b
  334.     @@:
  335.         mov     al,','
  336.         stosb
  337.  
  338.         pop     esi
  339.         sub     ecx,esi
  340.         dec     ecx
  341.         jz      @f
  342.         rep     movsb
  343.     @@:
  344.         mov     al,','
  345.         stosb
  346.  
  347.         pop     ecx esi
  348.         add     esi,TABITEM.Editor.FilePath
  349.         sub     ecx,esi
  350.         rep     movsb
  351.  
  352.         cmp     bl,0 ; run outfile ?
  353.         je      @f
  354.         mov     dword[edi],',run'
  355.         add     edi,4
  356.     @@:
  357.         mov     al,0
  358.         stosb
  359.  
  360.         mov     [app_start.filename],app_fasm
  361.         mov     [app_start.params],fasm_parameters
  362. start_ret:
  363.         mcall   70,app_start
  364.         ret
  365. endp
  366.  
  367. ;-----------------------------------------------------------------------------
  368. proc open_debug_board ;///////////////////////////////////////////////////////
  369. ;-----------------------------------------------------------------------------
  370.         mov     [app_start.filename],app_board
  371.         mov     [app_start.params],0
  372.         jmp     start_ret
  373. endp
  374.  
  375. ;-----------------------------------------------------------------------------
  376. proc open_sysfuncs_txt ;//////////////////////////////////////////////////////
  377. ;-----------------------------------------------------------------------------
  378.         mov     [app_start.filename],app_docpak
  379.         mov     [app_start.params],sysfuncs_param
  380.         call    start_ret
  381.         cmp     eax,0xfffffff0
  382.         jb      @f
  383.         mov     [app_start.filename],app_tinypad
  384.         mov     [app_start.params],sysfuncs_filename
  385.         call    start_ret
  386.     @@: ret
  387. endp
  388.  
  389. set_opt:
  390.  
  391.   .dialog:
  392.         mov     [bot_mode],1
  393.         mov     [bot_dlg_height],128
  394.         mov     [bot_dlg_handler],optsdlg_handler
  395.         mov     [focused_tb],tb_color
  396.         mov     al,[tb_color.length]
  397.         mov     [tb_color.pos.x],al
  398.         mov     [tb_color.sel.x],0
  399.         mov     [tb_casesen],1
  400.         mov     [cur_part],0
  401.         m2m     [cur_color],dword[color_tbl.text]
  402.         mov     esi,color_tbl
  403.         mov     edi,cur_colors
  404.         mov     ecx,10
  405.         cld
  406.         rep     movsd
  407.         call    drawwindow
  408.         ret
  409.  
  410.   .line_numbers:
  411.         mov     al,OPTS_LINENUMS
  412.         jmp     .main
  413.   .optimal_fill:
  414.         mov     al,OPTS_OPTIMSAVE
  415.         jmp     .main
  416.   .auto_indents:
  417.         mov     al,OPTS_AUTOINDENT
  418.         jmp     .main
  419.   .auto_braces:
  420.         mov     al,OPTS_AUTOBRACES
  421.         jmp     .main
  422.   .secure_sel:
  423.         mov     al,OPTS_SECURESEL
  424.  
  425.   .main:
  426.         xor     [options],al
  427.         ret
  428.  
  429. ;-----------------------------------------------------------------------------
  430.  
  431. include 'data/tp-defines.inc'
  432.  
  433. include 'tp-draw.asm'
  434. include 'tp-key.asm'
  435. include 'tp-button.asm'
  436. include 'tp-mouse.asm'
  437. include 'tp-files.asm'
  438. include 'tp-common.asm'
  439. include 'tp-dialog.asm'
  440. include 'tp-popup.asm'
  441. include 'tp-tbox.asm'
  442. include 'tp-tabctl.asm'
  443. include 'tp-editor.asm'
  444. include 'tp-recode.asm'
  445.  
  446. include 'external/dll.inc'
  447.  
  448. ;-----------------------------------------------------------------------------
  449. section @DATA ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  450. ;-----------------------------------------------------------------------------
  451.  
  452. include 'data/tp-idata.inc'
  453.  
  454. ;-----------------------------------------------------------------------------
  455. section @IMPORT ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  456. ;-----------------------------------------------------------------------------
  457. ;align 16
  458. ;@IMPORT:
  459.  
  460. library \
  461.         libini,'libini.obj',\
  462.         libio,'libio.obj',\
  463.         libgfx,'libgfx.obj'
  464.  
  465. import  libini, \
  466.         ini.get_str,'ini.get_str',\
  467.         ini.set_str,'ini.set_str',\
  468.         ini.get_int,'ini.get_int',\
  469.         ini.set_int,'ini.set_int'
  470.  
  471. import  libio, \
  472.         file.find_first,'file.find_first',\
  473.         file.find_next ,'file.find_next',\
  474.         file.find_close,'file.find_close',\
  475.         file.size      ,'file.size',\
  476.         file.open      ,'file.open',\
  477.         file.read      ,'file.read',\
  478.         file.write     ,'file.write',\
  479.         file.seek      ,'file.seek',\
  480.         file.tell      ,'file.tell',\
  481.         file.eof?      ,'file.eof?',\
  482.         file.truncate  ,'file.truncate',\
  483.         file.close     ,'file.close'
  484.  
  485. import  libgfx, \
  486.         gfx.open        ,'gfx.open',\
  487.         gfx.close       ,'gfx.close',\
  488.         gfx.pen.color   ,'gfx.pen.color',\
  489.         gfx.brush.color ,'gfx.brush.color',\
  490.         gfx.pixel       ,'gfx.pixel',\
  491.         gfx.move.to     ,'gfx.move.to',\
  492.         gfx.line.to     ,'gfx.line.to',\
  493.         gfx.line        ,'gfx.line',\
  494.         gfx.polyline    ,'gfx.polyline',\
  495.         gfx.polyline.to ,'gfx.polyline.to',\
  496.         gfx.fillrect    ,'gfx.fillrect',\
  497.         gfx.fillrect.ex ,'gfx.fillrect.ex',\
  498.         gfx.framerect   ,'gfx.framerect',\
  499.         gfx.framerect.ex,'gfx.framerect.ex',\
  500.         gfx.rectangle   ,'gfx.rectangle',\
  501.         gfx.rectangle.ex,'gfx.rectangle.ex'
  502.  
  503. TINYPAD_END:     ; end of file
  504.  
  505. ;-----------------------------------------------------------------------------
  506. section @UDATA ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  507. ;-----------------------------------------------------------------------------
  508.  
  509. include 'data/tp-udata.inc'
  510.  
  511. ;-----------------------------------------------------------------------------
  512. section @PARAMS ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  513. ;-----------------------------------------------------------------------------
  514.  
  515. fasm_parameters:
  516.  
  517. p_info  process_information
  518. p_info2 process_information
  519. sc      system_colors
  520.  
  521. rb 1024*4
  522. MAIN_STACK:
  523. rb 1024*4
  524. POPUP_STACK:
  525.  
  526. STATIC_MEM_END:
  527.  
  528. diff10 'Main memory size',0,$
  529.