Subversion Repositories Kolibri OS

Rev

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