Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                 ;;
  3. ;;  flat assembler source                          ;;
  4. ;;  Copyright (c) 1999-2006, Tomasz Grysztar       ;;
  5. ;;  All rights reserved.                           ;;
  6. ;;                                                 ;;
  7. ;;  Menuet port by VT                              ;;
  8. ;;                                                 ;;
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10.  
  11. NORMAL_MODE    = 8
  12. CONSOLE_MODE   = 32
  13.  
  14. MAGIC1         = 6*(text.line_size-1)+14
  15. MAX_PATH       = 100
  16.  
  17. APP_MEMORY     = 0x00800000
  18.  
  19. ;; Menuet header
  20.  
  21. appname equ "flat assembler "
  22.  
  23. use32
  24.  
  25.   org 0x0
  26.   db 'MENUET01'  ; 8 byte id
  27.   dd 0x01        ; header version
  28.   dd START       ; program start
  29.   dd program_end ; program image size
  30.   dd stacktop    ; required amount of memory
  31.   dd stacktop    ; stack
  32.   dd params,cur_dir_path  ; parameters,icon
  33.  
  34. include 'lang.inc'
  35. include '..\..\..\macros.inc'
  36. purge add,sub    ; macros.inc does incorrect substitution
  37. include 'fasm.inc'
  38.  
  39. include '..\..\..\develop\libraries\box_lib\trunk\editbox.mac'
  40. include '..\..\..\develop\libraries\box_lib\trunk\checkbox.mac'
  41. ;include '..\..\..\develop\libraries\box_lib\asm\trunk\editbox_ex.mac'
  42. include '..\..\..\develop\libraries\box_lib\load_lib.mac'
  43.   @use_library
  44.  
  45.  
  46.  
  47. center fix true
  48.  
  49. START:      ; Start of execution
  50. sys_load_library  library_name, cur_dir_path, library_path, system_path, \
  51.   err_message_found_lib, head_f_l, myimport, err_message_import, head_f_i
  52.  
  53.   cmp eax,-1
  54.   jne @f
  55.     mcall -1 ;exit if not open box_lib.obj
  56.   @@:
  57.   mcall 40,0x27 ;¬ áª  á¨á⥬­ëå ᮡë⨩
  58.  
  59.         mov     edi, fileinfos
  60.         mov     ecx, (fileinfos_end-fileinfos)/4
  61.         or      eax, -1
  62.         rep     stosd
  63.         push    68
  64.         pop     eax
  65.         push    11
  66.         pop     ebx
  67.         mcall
  68.  
  69.    cmp    [params],0
  70.    jz       red
  71.  
  72.    mov    ecx,10
  73.    mov    eax,'    '
  74.    mov    edi,infile
  75.    push   ecx
  76.    cld
  77.    rep    stosd
  78.    mov    ecx,[esp]
  79.    mov    edi,outfile
  80.    rep    stosd
  81.    pop    ecx
  82.    mov    edi,path
  83.    rep    stosd
  84.  
  85.    mov     esi,params
  86. ;  DEBUGF  "params: %s\n",esi
  87.    mov     edi,infile
  88.    call    mov_param_str
  89. ;  mov     edi,infile
  90. ;  DEBUGF  " input: %s\n",edi
  91.    inc     esi
  92.    mov     edi,outfile
  93.    call    mov_param_str
  94. ;  mov     edi,outfile
  95. ;  DEBUGF  "output: %s\n",edi
  96.    inc     esi
  97.    mov     edi,path
  98.    call    mov_param_str
  99. ;  mov     edi,path
  100. ;  DEBUGF  "  path: %s\n",edi
  101.  
  102.    cmp     [esi], dword ',run'
  103.    jne     @f
  104.    mov     [_run_outfile],1
  105.   @@:
  106.  
  107.    mov     [_mode],CONSOLE_MODE
  108.    jmp     start
  109.  
  110.  
  111. red:    ; Redraw
  112.     call draw_window
  113.  
  114. still: 
  115.     push 10          ; Wait here for event
  116.     pop eax
  117.     mcall
  118.     cmp al,6
  119.     jne @f
  120.       call mouse
  121.     @@:
  122.     dec eax
  123.     je  red          ; Redraw request
  124.     dec eax
  125.     jne button       ; Button in buffer
  126.  
  127. key:                 ; Key
  128.     mov  al,2        ; Read it and ignore
  129.     mcall
  130.  
  131.     push dword edit1
  132.     call [edit_box_key]
  133.     push dword edit2
  134.     call [edit_box_key]
  135.     push dword edit3
  136.     call [edit_box_key]
  137.  
  138.     jmp  still
  139.  
  140. button:    ; Button in Window
  141.  
  142.     mov  al,17
  143.     mcall
  144.  
  145.     cmp     ah,1
  146.     jne     noclose
  147.     or      eax,-1
  148.     mcall
  149.  
  150. noclose:    
  151.     cmp  ah,2         ; Start compiling
  152.     je   start
  153.     cmp  ah,3         ; Start compiled file
  154.     jnz  norunout
  155.  
  156.     mov  edx,outfile
  157.     call make_fullpaths
  158.     mcall  70,file_info_start
  159. ;   xor   ecx,ecx
  160.     jmp  still
  161.    norunout:
  162.     cmp  ah,4
  163.     jnz  norundebug
  164.  
  165.     mov  edx,outfile
  166.     call make_fullpaths
  167.     mcall 70,file_info_debug
  168.     jmp  still
  169.  
  170.    norundebug:
  171.  
  172.     jmp  still
  173.  
  174.  
  175. mouse:
  176.   push dword edit1
  177.   call [edit_box_mouse]
  178.   push dword edit2
  179.   call [edit_box_mouse]
  180.   push dword edit3
  181.   call [edit_box_mouse]
  182.   push dword ch1_dbg
  183.   call [check_box_mouse]
  184.   ret
  185.  
  186. draw_window:
  187.     pusha
  188.  
  189.     mcall  12,1 ; Start of draw
  190.  
  191.     get_sys_colors 1,0
  192.  
  193.     xor  eax,eax                     
  194.     mov  ebx,100*65536+280
  195.     mov  ecx,90*65536+260
  196.     mov  edx,[sc.work]
  197.     or   edx,0x33000000
  198.     mov  edi,title             ; Draw Window Label Text
  199.     mcall
  200.  
  201.     mcall 9,PROCESSINFO,-1         
  202.  
  203.     cmp dword[pinfo.box.width],230 ; ïðîâåðÿåì øèðèíó îêíà
  204.     jge @f
  205.       mov dword[pinfo.box.width],230 ; åñëè îêíî î÷åíü óçêîå, óâåëè÷èâàåì øèðèíó äëÿ èçáåæàíèÿ ãëþêîâ
  206.     @@:
  207.  
  208.     mpack ecx,1,1
  209.     mov   ebx,[pinfo.box.width]
  210.     sub   ebx,10
  211.  
  212.     mov eax,8
  213.     mov edx,0x4000000B
  214.     mpack ebx,[pinfo.box.width],MAGIC1
  215.     msub  ebx,MAGIC1+10+1,0
  216.     mpack ecx,0, (14*3+16)/3-1
  217.     madd  ecx,1,0
  218.     mcall  ,,,0x00000002,[sc.work_button]
  219.     madd  ecx, (14*3+16)/3+1,0
  220.     mcall  ,,,0x00000003
  221.     madd  ecx, (14*3+16)/3+1,0
  222.     mcall ,,,4
  223.  
  224.     mpack ebx,6,0    ; Draw Window Text
  225.     add  ebx,1+ 14/2-3
  226.     mov  ecx,[sc.work_text]
  227.     mov  edx,text
  228.     mov  esi,text.line_size
  229.     mov  eax,4
  230.    newline:
  231.     mcall
  232.     add  ebx, 16 ;14
  233.     add  edx,text.line_size
  234.     cmp  byte[edx],'x'
  235.     jne  newline
  236.  
  237.     mov   ebx,[pinfo.box.width]
  238.     sub   ebx,MAGIC1+10+1-9
  239.     shl   ebx,16
  240.     add   ebx,1+( (14*3+16)/3-1)/2-3
  241.     mcall  ,,[sc.work_button_text],s_compile,7
  242.     add   ebx,(14*3+16)/3+1
  243.     mcall ,,,s_run
  244.     add   ebx,(14*3+16)/3+1
  245.     mcall ,,,s_debug
  246.  
  247.     mpack ebx,MAGIC1+6,0
  248.     add   ebx,1+ 14/2-3+ 14*0
  249.     mov   esi,[pinfo.box.width]
  250.     sub   esi,MAGIC1*2+5*2+6+3
  251.     mov   eax,esi
  252.     mov   cl,6
  253.     div   cl
  254.     cmp   al,MAX_PATH
  255.     jbe   @f
  256.     mov   al,MAX_PATH
  257. @@: movzx esi,al
  258.  
  259.     call draw_messages
  260.  
  261.     mov eax,dword[pinfo.box.width]
  262.     sub eax,127
  263.     mov dword[edit1.width],eax ; óñòàíàâëèâàåì øèðèíó òåêñòîâûõ ïîëåé
  264.     mov dword[edit2.width],eax
  265.     mov dword[edit3.width],eax
  266.  
  267.     push dword edit1
  268.     call [edit_box_draw]
  269.     push dword edit2
  270.     call [edit_box_draw]
  271.     push dword edit3
  272.     call [edit_box_draw]
  273.     push dword ch1_dbg
  274.     call [check_box_draw]
  275.  
  276.     mcall  12,2 ; End of Draw
  277.  
  278.     popa
  279.     ret
  280.  
  281. bottom_right dd ?
  282.  
  283. draw_messages:
  284.     mov    eax,13      ; clear work area
  285.     mpack  ebx,7-2,[pinfo.box.width]
  286.     sub    ebx,5*2+7*2-1-2*2
  287.     mpack  ecx,0,[pinfo.box.height]
  288.     madd   ecx, 14*3+16+1+7+1,-( 14*3+16+1+7*2+25)
  289.     mov    word[bottom_right+2],bx
  290.     mov    word[bottom_right],cx
  291.     msub   [bottom_right],7,11
  292.     add    [bottom_right],7 shl 16 + 53
  293.     mov    edx,[sc.work]
  294.     mcall
  295. _cy = 0
  296. _sy = 2
  297. _cx = 4
  298. _sx = 6
  299.     push   ebx ecx
  300.     mpack  ebx,4,5
  301.     add    bx,[esp+_cx]
  302.     mov    ecx,[esp+_sy-2]
  303.     mov    cx,[esp+_sy]
  304.     msub   ecx,1,1
  305.     mcall  38,,,[sc.work_graph]
  306.     mov    si,[esp+_cy]
  307.     add    cx,si
  308.     shl    esi,16
  309.     add    ecx,esi
  310.     madd   ecx,1,1
  311.     mcall
  312.     mpack  ebx,4,4
  313.     mov    esi,[esp+_sy-2]
  314.     mov    si,cx
  315.     mov    ecx,esi
  316.     mcall
  317.     mov    si,[esp+_cx]
  318.     add    bx,si
  319.     shl    esi,16
  320.     add    ebx,esi
  321.     madd   ebx,1,1
  322.     mcall
  323.     pop    ecx ebx
  324.     ret
  325.  
  326.  
  327. ; DATA
  328.  
  329. if lang eq ru
  330. text:
  331.   db ' ‚å” ©«:'
  332. .line_size = $-text
  333.   db '‚ë唠©«:'
  334.   db '   ãâì:'
  335.   db 'x'
  336.  
  337.   s_compile db 'Š®¬¯¨«.'
  338.   s_run     db ' ã᪠ '
  339.   s_debug   db 'Žâ« ¤ª '
  340.   s_dbgdescr db '‘®§¤ ¢ âì ®â« ¤®ç­ãî ¨­ä®à¬ æ¨î',0
  341.   s_dbgdescr_end:
  342.  
  343.   err_message_import db 'Žè¨¡ª  ¯à¨ ¨¬¯®à⥠box_lib.obj',0
  344.   err_message_found_lib db 'Žè¨¡ª  ¯à¨ ¯®¨áª¥ box_lib.obj',0 ;áâப , ª®â®à ï ¡ã¤¥â ¢ áä®à¬¨à®¢ ­­®¬ ®ª­¥, ¥á«¨ ¡¨¡«¨®â¥ª  ­¥ ¡ã¤¥â ­ ©¤¥­ 
  345.   head_f_i:
  346.   head_f_l db '‘¨á⥬­ ï ®è¨¡ª ',0 ;§ £®«®¢®ª ®ª­ , ¯à¨ ¢®§­¨ª­®¢¥­¨¨ ®è¨¡ª¨
  347.   system_path db '/sys/lib/'
  348.   library_name db 'box_lib.obj',0
  349. else
  350. text:
  351.   db ' INFILE:'
  352. .line_size = $-text
  353.   db 'OUTFILE:'
  354.   db '   PATH:'
  355.   db 'x'
  356.  
  357.   s_compile db 'COMPILE'
  358.   s_run     db '  RUN  '
  359.   s_debug   db ' DEBUG '
  360.   s_dbgdescr db 'Generate debug information',0
  361.   s_dbgdescr_end:
  362.  
  363.   err_message_import db 'Error on load import library box_lib.obj',0
  364.   err_message_found_lib db 'Sorry I cannot found library box_lib.obj',0 ;áâப , ª®â®à ï ¡ã¤¥â ¢ áä®à¬¨à®¢ ­­®¬ ®ª­¥, ¥á«¨ ¡¨¡«¨®â¥ª  ­¥ ¡ã¤¥â ­ ©¤¥­ 
  365.   head_f_i:
  366.   head_f_l db 'System error',0 ;§ £®«®¢®ª ®ª­ , ¯à¨ ¢®§­¨ª­®¢¥­¨¨ ®è¨¡ª¨
  367.   system_path db '/sys/lib/'
  368.   library_name db 'box_lib.obj',0
  369. end if
  370.  
  371. myimport:
  372.   edit_box_draw  dd aEdit_box_draw
  373.   edit_box_key   dd aEdit_box_key
  374.   edit_box_mouse dd aEdit_box_mouse
  375.   ;version_ed     dd aVersion_ed
  376.  
  377.   check_box_draw  dd aCheck_box_draw
  378.   check_box_mouse dd aCheck_box_mouse
  379.   ;version_ch      dd aVersion_ch
  380.  
  381.   dd 0,0
  382.  
  383.   aEdit_box_draw  db 'edit_box',0
  384.   aEdit_box_key   db 'edit_box_key',0
  385.   aEdit_box_mouse db 'edit_box_mouse',0
  386.   ;aVersion_ed     db 'version_ed',0
  387.  
  388.   aCheck_box_draw  db 'check_box_draw',0
  389.   aCheck_box_mouse db 'check_box_mouse',0
  390.   ;aVersion_ch      db 'version_ch',0
  391.  
  392. edit1 edit_box 153, 56, 1, 0xffffff, 0xff, 0x80ff, 0, 0x8000, (outfile-infile-1), infile, mouse_dd, 0, 11,11
  393. edit2 edit_box 153, 56, 17, 0xffffff, 0xff, 0x80ff, 0, 0x8000,(path-outfile-1), outfile, mouse_dd, 0, 7,7
  394. edit3 edit_box 153, 56, 33, 0xffffff, 0xff, 0x80ff, 0, 0x8000,(path_end-path-1), path, mouse_dd, 0, 6,6
  395. ;ch1_dbg check_box 5, 49, 6, 12, 0xffffff, 0x80ff, 0, s_dbgdescr,(s_dbgdescr_end-s_dbgdescr)
  396. ch1_dbg:
  397.   .left:           dw  5
  398.   .top:            dw 49
  399.   .ch_text_margin: dd 6
  400.   .ch_size:        dd 12
  401.   .color:          dd 0xffffff
  402.   .border_color:   dd 0x80ff
  403.   .text_color:     dd 0
  404.   .text:           dd s_dbgdescr
  405.   .ch_text_length: dd (s_dbgdescr_end-s_dbgdescr)
  406.   .flags:          dd 0
  407.  
  408. mouse_dd dd 0 ;íóæíî äëÿ Shift-à â editbox
  409.  
  410. infile    db 'example.asm'
  411.   times MAX_PATH-$+infile  db 0
  412. outfile db 'example'
  413.   times MAX_PATH-$+outfile db 0
  414. path    db '/rd/1/'
  415.   times MAX_PATH-$+path    db 0
  416. path_end:
  417. lf db 13,10,0
  418.  
  419.  
  420. mov_param_str:
  421.   @@:
  422.     mov    al,[esi]
  423.     cmp    al,','
  424.     je       @f
  425.     cmp    al,0
  426.     je       @f
  427.     mov    [edi],al
  428.     inc    esi
  429.     inc    edi
  430.     jmp    @b
  431.   @@:
  432.     mov    al,0
  433.     stosb
  434. ret
  435.  
  436. start:
  437.     cmp    [_mode],NORMAL_MODE
  438.     jne    @f
  439.     call   draw_messages
  440.     mov    [textxy],7 shl 16 + 70
  441. @@:
  442.     mov    esi,_logo
  443.     call   display_string
  444.  
  445.  ;
  446.  ;   Fasm native code
  447.  ;
  448.  
  449.     mov    [input_file],infile
  450.     mov    [output_file],outfile
  451.  
  452.     call   init_memory
  453.  
  454.     call   make_timestamp
  455.     mov    [start_time],eax
  456.  
  457.     call   preprocessor
  458.     call   parser
  459.     call   assembler
  460.     bt     dword[ch1_dbg.flags],1 ;cmp [bGenerateDebugInfo], 0
  461.     jae    @f                     ;jz @f
  462.     call   symbol_dump
  463. @@:
  464.     call   formatter
  465.  
  466.     call   display_user_messages
  467.     movzx  eax,[current_pass]
  468.     inc    eax
  469.     call   display_number
  470.     mov    esi,_passes_suffix
  471.     call   display_string
  472.     call   make_timestamp
  473.     sub    eax,[start_time]
  474.     xor    edx,edx
  475.     mov    ebx,100
  476.     div    ebx
  477.     or       eax,eax
  478.     jz       display_bytes_count
  479.     xor    edx,edx
  480.     mov    ebx,10
  481.     div    ebx
  482.     push   edx
  483.     call   display_number
  484.     mov    dl,'.'
  485.     call   display_character
  486.     pop    eax
  487.     call   display_number
  488.     mov    esi,_seconds_suffix
  489.     call   display_string
  490.   display_bytes_count:
  491.     mov    eax,[written_size]
  492.     call   display_number
  493.     mov    esi,_bytes_suffix
  494.     call   display_string
  495.     xor    al,al
  496.  
  497.     cmp    [_run_outfile],0
  498.     je     @f
  499.     mov    edx,outfile
  500.     call   make_fullpaths
  501.     mov    eax,70
  502.     mov    ebx,file_info_start
  503.     xor    ecx,ecx
  504.     mcall
  505. @@:
  506.     jmp    exit_program
  507.  
  508.  
  509. include 'system.inc'
  510. include 'version.inc'
  511. include 'errors.inc'
  512. include 'expressi.inc'
  513. include 'preproce.inc'
  514. include 'parser.inc'
  515. include 'assemble.inc'
  516. include 'formats.inc'
  517. include 'x86_64.inc'
  518. include 'tables.inc'
  519. include 'symbdump.inc'
  520. include 'messages.inc'
  521.  
  522. title db appname,VERSION_STRING,0
  523.  
  524. _logo db 'flat assembler  version ',VERSION_STRING,13,10,0
  525.  
  526. _passes_suffix db ' passes, ',0
  527. _seconds_suffix db ' seconds, ',0
  528. _bytes_suffix db ' bytes.',13,10,0
  529.  
  530. _include db 'INCLUDE',0
  531.  
  532. _counter db 4,'0000'
  533.  
  534. _mode          dd NORMAL_MODE
  535. _run_outfile  dd 0
  536. ;bGenerateDebugInfo db 0
  537.  
  538. sub_table:
  539. times $41 db $00
  540. times $1A db $20
  541. times $25 db $00
  542. times $10 db $20
  543. times $30 db $00
  544. times $10 db $50
  545. times $04 db $00,$01
  546. times $08 db $00
  547.  
  548. ;include_debug_strings
  549.  
  550.   params db 0 ; 'TINYPAD.ASM,TINYPAD,/HD/1/TPAD4/',
  551.   cur_dir_path rb 4096
  552.   library_path rb 4096
  553.  
  554. program_end:
  555.  
  556. rb 1000h
  557. align 4
  558.  
  559. include 'variable.inc'
  560.  
  561. program_base dd ?
  562. buffer_address dd ?
  563. memory_setting dd ?
  564. start_time dd ?
  565. memblock        dd      ?
  566.  
  567. predefinitions rb 1000h
  568.  
  569. dbgfilename     rb      MAX_PATH+4
  570.  
  571. sc    system_colors
  572. max_handles = 8
  573. fileinfos rb (4+20+MAX_PATH)*max_handles
  574. fileinfos_end:
  575. pinfo process_information
  576.  
  577. align 1000h
  578. rb 1000h
  579. stacktop:
  580.