Subversion Repositories Kolibri OS

Rev

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