Subversion Repositories Kolibri OS

Rev

Rev 949 | 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.     push dword edit1
  269.     call [edit_box_draw]
  270.     push dword edit2
  271.     call [edit_box_draw]
  272.     push dword edit3
  273.     call [edit_box_draw]
  274.  
  275.     mcall  12,2 ; End of Draw
  276.  
  277.     popa
  278.     ret
  279.  
  280. bottom_right dd ?
  281.  
  282. draw_checkbox:
  283.         mcall   8,<5,10>,<14*3+5,10>,14,[sc.work_button]
  284.         cmp     [bGenerateDebugInfo], 0
  285.         jz      @f
  286.         mov     edx, [sc.work_button_text]
  287.         mcall   38,<7,13>,<14*3+7,14*3+13>
  288.         mcall   38,,<14*3+13,14*3+7>
  289. @@:
  290.         mov     ecx, [sc.work_text]
  291.         or      ecx, 0x80000000
  292.         mcall   4,<20,14*3+7>,,s_dbgdescr
  293.         ret
  294.  
  295. draw_messages:
  296.     mov    eax,13      ; clear work area
  297.     mpack  ebx,7-2,[pinfo.box.width]
  298.     sub    ebx,5*2+7*2-1-2*2
  299.     mpack  ecx,0,[pinfo.box.height]
  300.     madd   ecx, 14*3+16+1+7+1,-( 14*3+16+1+7*2+25)
  301.     mov    word[bottom_right+2],bx
  302.     mov    word[bottom_right],cx
  303.     msub   [bottom_right],7,11
  304.     add    [bottom_right],7 shl 16 + 53
  305.     mov    edx,[sc.work]
  306.     mcall
  307. _cy = 0
  308. _sy = 2
  309. _cx = 4
  310. _sx = 6
  311.     push   ebx ecx
  312.     mpack  ebx,4,5
  313.     add    bx,[esp+_cx]
  314.     mov    ecx,[esp+_sy-2]
  315.     mov    cx,[esp+_sy]
  316.     msub   ecx,1,1
  317.     mcall  38,,,[sc.work_graph]
  318.     mov    si,[esp+_cy]
  319.     add    cx,si
  320.     shl    esi,16
  321.     add    ecx,esi
  322.     madd   ecx,1,1
  323.     mcall
  324.     mpack  ebx,4,4
  325.     mov    esi,[esp+_sy-2]
  326.     mov    si,cx
  327.     mov    ecx,esi
  328.     mcall
  329.     mov    si,[esp+_cx]
  330.     add    bx,si
  331.     shl    esi,16
  332.     add    ebx,esi
  333.     madd   ebx,1,1
  334.     mcall
  335.     pop    ecx ebx
  336.     ret
  337.  
  338.  
  339. ; DATA
  340.  
  341. if lang eq ru
  342. text:
  343.   db ' ‚å” ©«:'
  344. .line_size = $-text
  345.   db '‚ë唠©«:'
  346.   db '   ãâì:'
  347.   db 'x'
  348.  
  349.   s_compile db 'Š®¬¯¨«.'
  350.   s_run     db ' ã᪠ '
  351.   s_debug   db 'Žâ« ¤ª '
  352.   s_dbgdescr      db      '‘®§¤ ¢ âì ®â« ¤®ç­ãî ¨­ä®à¬ æ¨î',0
  353.  
  354.   err_message_import db 'Žè¨¡ª  ¯à¨ ¨¬¯®à⥠box_lib.obj',0
  355.   err_message_found_lib db 'Žè¨¡ª  ¯à¨ ¯®¨áª¥ box_lib.obj',0 ;áâப , ª®â®à ï ¡ã¤¥â ¢ áä®à¬¨à®¢ ­­®¬ ®ª­¥, ¥á«¨ ¡¨¡«¨®â¥ª  ­¥ ¡ã¤¥â ­ ©¤¥­ 
  356.   head_f_i:
  357.   head_f_l db '‘¨á⥬­ ï ®è¨¡ª ',0 ;§ £®«®¢®ª ®ª­ , ¯à¨ ¢®§­¨ª­®¢¥­¨¨ ®è¨¡ª¨
  358.   system_path db '/sys/lib/'
  359.   library_name db 'box_lib.obj',0
  360. else
  361. text:
  362.   db ' INFILE:'
  363. .line_size = $-text
  364.   db 'OUTFILE:'
  365.   db '   PATH:'
  366.   db 'x'
  367.  
  368.   s_compile db 'COMPILE'
  369.   s_run     db '  RUN  '
  370.   s_debug   db ' DEBUG '
  371.   s_dbgdescr      db      'Generate debug information',0
  372.  
  373.   err_message_import db 'Error on load import library box_lib.obj',0
  374.   err_message_found_lib db 'Sorry I cannot found library box_lib.obj',0 ;áâப , ª®â®à ï ¡ã¤¥â ¢ áä®à¬¨à®¢ ­­®¬ ®ª­¥, ¥á«¨ ¡¨¡«¨®â¥ª  ­¥ ¡ã¤¥â ­ ©¤¥­ 
  375.   head_f_i:
  376.   head_f_l db 'System error',0 ;§ £®«®¢®ª ®ª­ , ¯à¨ ¢®§­¨ª­®¢¥­¨¨ ®è¨¡ª¨
  377.   system_path db '/sys/lib/'
  378.   library_name db 'box_lib.obj',0
  379. end if
  380.  
  381. myimport:
  382.   edit_box_draw  dd aEdit_box_draw
  383.   edit_box_key   dd aEdit_box_key
  384.   edit_box_mouse dd aEdit_box_mouse
  385.   ;version_ed     dd aVersion_ed
  386.  
  387.   ;check_box_draw  dd aCheck_box_draw
  388.   ;check_box_mouse dd aCheck_box_mouse
  389.   ;version_ch      dd aVersion_ch
  390.  
  391.   dd 0,0
  392.  
  393.   aEdit_box_draw  db 'edit_box',0
  394.   aEdit_box_key   db 'edit_box_key',0
  395.   aEdit_box_mouse db 'edit_box_mouse',0
  396.   ;aVersion_ed     db 'version_ed',0
  397.  
  398.   ;aCheck_box_draw  db 'check_box_draw',0
  399.   ;aCheck_box_mouse db 'check_box_mouse',0
  400.   ;aVersion_ch      db 'version_ch',0
  401.  
  402. edit1 edit_box 153, 56, 1, 0xe0ffff, 0xff, 0x80ff, 0, 0xa000, MAX_PATH+$, infile, mouse_dd, 0, 11,11
  403. edit2 edit_box 153, 56, 17, 0xe0ffff, 0xff, 0x80ff, 0, 0xa000, MAX_PATH+$, outfile, mouse_dd, 0, 7,7
  404. edit3 edit_box 153, 56, 33, 0xe0ffff, 0xff, 0x80ff, 0, 0xa000, MAX_PATH+$, path, mouse_dd, 0, 6,6
  405.  
  406. mouse_dd dd 0 ;íóæíî äëÿ Shift-à â editbox
  407.  
  408. infile    db 'example.asm'
  409.   times MAX_PATH+$-infile  db 0
  410. outfile db 'example'
  411.   times MAX_PATH+$-outfile db 0
  412. path    db '/rd/1/'
  413.   times MAX_PATH+$-path    db 0
  414.  
  415. lf db 13,10,0
  416.  
  417. addr dd 0x0
  418. ya   dd 0x0
  419. zero db 0x0
  420.  
  421. mov_param_str:
  422.   @@:
  423.     mov    al,[esi]
  424.     cmp    al,','
  425.     je       @f
  426.     cmp    al,0
  427.     je       @f
  428.     mov    [edi],al
  429.     inc    esi
  430.     inc    edi
  431.     jmp    @b
  432.   @@:
  433.     mov    al,0
  434.     stosb
  435. ret
  436.  
  437. start:
  438.     cmp    [_mode],NORMAL_MODE
  439.     jne    @f
  440.     call   draw_messages
  441.     mov    [textxy],7 shl 16 + 70
  442. @@:
  443.     mov    esi,_logo
  444.     call   display_string
  445.  
  446.  ;
  447.  ;   Fasm native code
  448.  ;
  449.  
  450.     mov    [input_file],infile
  451.     mov    [output_file],outfile
  452.  
  453.     call   init_memory
  454.  
  455.     call   make_timestamp
  456.     mov    [start_time],eax
  457.  
  458.     call   preprocessor
  459.     call   parser
  460.     call   assembler
  461.     cmp    [bGenerateDebugInfo], 0
  462.     jz     @f
  463.     call   symbol_dump
  464. @@:
  465.     call   formatter
  466.  
  467.     call   display_user_messages
  468.     movzx  eax,[current_pass]
  469.     inc    eax
  470.     call   display_number
  471.     mov    esi,_passes_suffix
  472.     call   display_string
  473.     call   make_timestamp
  474.     sub    eax,[start_time]
  475.     xor    edx,edx
  476.     mov    ebx,100
  477.     div    ebx
  478.     or       eax,eax
  479.     jz       display_bytes_count
  480.     xor    edx,edx
  481.     mov    ebx,10
  482.     div    ebx
  483.     push   edx
  484.     call   display_number
  485.     mov    dl,'.'
  486.     call   display_character
  487.     pop    eax
  488.     call   display_number
  489.     mov    esi,_seconds_suffix
  490.     call   display_string
  491.   display_bytes_count:
  492.     mov    eax,[written_size]
  493.     call   display_number
  494.     mov    esi,_bytes_suffix
  495.     call   display_string
  496.     xor    al,al
  497.  
  498.     cmp    [_run_outfile],0
  499.     je     @f
  500.     mov    edx,outfile
  501.     call   make_fullpaths
  502.     mov    eax,70
  503.     mov    ebx,file_info_start
  504.     xor    ecx,ecx
  505.     mcall
  506. @@:
  507.     jmp    exit_program
  508.  
  509.  
  510. include 'system.inc'
  511. include 'version.inc'
  512. include 'errors.inc'
  513. include 'expressi.inc'
  514. include 'preproce.inc'
  515. include 'parser.inc'
  516. include 'assemble.inc'
  517. include 'formats.inc'
  518. include 'x86_64.inc'
  519. include 'tables.inc'
  520. include 'symbdump.inc'
  521. include 'messages.inc'
  522.  
  523. title db appname,VERSION_STRING,0
  524.  
  525. _logo db 'flat assembler  version ',VERSION_STRING,13,10,0
  526.  
  527. _passes_suffix db ' passes, ',0
  528. _seconds_suffix db ' seconds, ',0
  529. _bytes_suffix db ' bytes.',13,10,0
  530.  
  531. _include db 'INCLUDE',0
  532.  
  533. _counter db 4,'0000'
  534.  
  535. _mode          dd NORMAL_MODE
  536. _run_outfile  dd 0
  537. bGenerateDebugInfo db 0
  538.  
  539. sub_table:
  540. times $41 db $00
  541. times $1A db $20
  542. times $25 db $00
  543. times $10 db $20
  544. times $30 db $00
  545. times $10 db $50
  546. times $04 db $00,$01
  547. times $08 db $00
  548.  
  549. ;include_debug_strings
  550.  
  551.   params db 0 ; 'TINYPAD.ASM,TINYPAD,/HD/1/TPAD4/',
  552.   cur_dir_path rb 4096
  553.   library_path rb 4096
  554.  
  555. program_end:
  556.  
  557. rb 1000h
  558. align 4
  559.  
  560. include 'variable.inc'
  561.  
  562. program_base dd ?
  563. buffer_address dd ?
  564. memory_setting dd ?
  565. start_time dd ?
  566. memblock        dd      ?
  567.  
  568. predefinitions rb 1000h
  569.  
  570. dbgfilename     rb      MAX_PATH+4
  571.  
  572. sc    system_colors
  573. max_handles = 8
  574. fileinfos rb (4+20+MAX_PATH)*max_handles
  575. fileinfos_end:
  576. pinfo process_information
  577.  
  578. align 1000h
  579. rb 1000h
  580. stacktop:
  581.