Subversion Repositories Kolibri OS

Rev

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