Subversion Repositories Kolibri OS

Rev

Rev 539 | 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 APP_MEMORY  ; required amount of memory
  31.   dd 0xDFFF0     ; stack
  32.   dd params,0x0  ; 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. center fix true
  40.  
  41. START:      ; Start of execution
  42.         mov     edi, fileinfos
  43.         mov     ecx, (fileinfos_end-fileinfos)/4
  44.         or      eax, -1
  45.         rep     stosd
  46.  
  47.    cmp    [params],0
  48.    jz       red
  49.  
  50.    mov    ecx,10
  51.    mov    eax,'    '
  52.    mov    edi,infile
  53.    push   ecx
  54.    cld
  55.    rep    stosd
  56.    mov    ecx,[esp]
  57.    mov    edi,outfile
  58.    rep    stosd
  59.    pop    ecx
  60.    mov    edi,path
  61.    rep    stosd
  62.  
  63.    mov     esi,params
  64. ;  DEBUGF  "params: %s\n",esi
  65.    mov     edi,infile
  66.    call    mov_param_str
  67. ;  mov     edi,infile
  68. ;  DEBUGF  " input: %s\n",edi
  69.    inc     esi
  70.    mov     edi,outfile
  71.    call    mov_param_str
  72. ;  mov     edi,outfile
  73. ;  DEBUGF  "output: %s\n",edi
  74.    inc     esi
  75.    mov     edi,path
  76.    call    mov_param_str
  77. ;  mov     edi,path
  78. ;  DEBUGF  "  path: %s\n",edi
  79.  
  80.    cmp     [esi], dword ',run'
  81.    jne     @f
  82.    mov     [_run_outfile],1
  83.   @@:
  84.  
  85.    mov     [_mode],CONSOLE_MODE
  86.    jmp     start
  87.  
  88.  
  89. red:    ; Redraw
  90.     call draw_window
  91.  
  92. still:  
  93.     push 10          ; Wait here for event
  94.     pop eax
  95.     mcall
  96.     dec eax
  97.     je  red          ; Redraw request
  98.     dec eax
  99.     jne button       ; Button in buffer
  100.  
  101. key:                 ; Key
  102.     mov  al,2        ; Read it and ignore
  103.     mcall
  104.     jmp  still
  105.  
  106. button:    ; Button in Window
  107.  
  108.     mov  al,17
  109.     mcall
  110.  
  111.     cmp     ah,1
  112.     jne     noclose
  113.     or      eax,-1
  114.     mcall
  115.  
  116. noclose:    
  117.     cmp  ah,2         ; Start compiling
  118.     je   start
  119.     cmp  ah,3         ; Start compiled file
  120.     jnz  norunout
  121.  
  122.     mov  edx,outfile
  123.     call make_fullpaths
  124.     mcall  70,file_info_start
  125. ;   xor   ecx,ecx
  126.     jmp  still
  127.    norunout:
  128.     cmp  ah,4
  129.     jnz  norundebug
  130.  
  131.     mov  edx,outfile
  132.     call make_fullpaths
  133.     mcall 70,file_info_debug
  134.     jmp  still
  135.  
  136.    norundebug:
  137.     mov  ecx,5
  138.     mov  [ya],ecx
  139.  
  140.     cmp  ah,11     ; Infile
  141.     je   f1
  142.     cmp  ah,12     ; Outfile
  143.     je   f2
  144.     cmp  ah,13     ; Path
  145.     je   f3
  146.     cmp  ah,14
  147.     je   f4
  148.  
  149.     jmp  still
  150.  
  151. f4:
  152.         xor     [bGenerateDebugInfo], 1
  153.         mcall   8,,,0x8000000E
  154.         call    draw_checkbox
  155.         jmp     still
  156.  
  157. draw_window:
  158.  
  159.     pusha
  160.  
  161.     mcall  12,1 ; Start of draw
  162.  
  163.     get_sys_colors 1,0
  164.  
  165.     xor  eax,eax                    
  166.     mov  ebx,50*65536+280
  167.     mov  ecx,50*65536+260
  168.     mov  edx,[sc.work]
  169.     or   edx,0x33000000
  170.     mov  edi,title             ; Draw Window Label Text
  171.     mcall
  172.  
  173.     mcall 9,PROCESSINFO,-1         
  174.  
  175.     mpack ecx,1,1
  176.     mov   ebx,[pinfo.box.width]
  177.     sub   ebx,10
  178.  
  179.     push  ecx
  180.     madd  ecx, 14*3+16+2, 14*3+16+2
  181.     mcall 38,,,[sc.work_graph]
  182.     pop   ecx
  183.  
  184.     sub   ebx,MAGIC1+3
  185.     mcall
  186.     madd  ecx, 14, 14
  187.     mcall
  188.     madd  ecx, 14, 14
  189.     mcall
  190.     madd  ecx, 14, 14
  191.     mcall
  192.     push  ebx
  193.     mpack ebx,MAGIC1,MAGIC1
  194.     sub   ecx, 14*3
  195.     mcall
  196.     mov   ebx,[esp-2]
  197.     pop   bx
  198.     mcall
  199.     add   esp,2
  200.  
  201.     mpack ebx,0,MAGIC1-1
  202.     mpack ecx,1+1, 14-2
  203.     mcall 8,,,0x4000000B       ; Button: Enter Infile
  204.     madd  ecx, 14,0
  205.     mcall  ,,,0x4000000C       ; Button: Enter Outfile
  206.     madd  ecx, 14,0
  207.     mcall  ,,,0x4000000D       ; Button: Enter Path
  208.  
  209.     mpack ebx,[pinfo.box.width],MAGIC1
  210.     msub  ebx,MAGIC1+10+1,0
  211.     mpack ecx,0, (14*3+16)/3-1
  212.     madd  ecx,1,0
  213.     mcall  ,,,0x00000002,[sc.work_button]
  214.     madd  ecx, (14*3+16)/3+1,0
  215.     mcall  ,,,0x00000003
  216.     madd  ecx, (14*3+16)/3+1,0
  217.     mcall ,,,4
  218.  
  219.     mpack ebx,6,0    ; Draw Window Text
  220.     add  ebx,1+ 14/2-3
  221.     mov  ecx,[sc.work_text]
  222.     mov  edx,text
  223.     mov  esi,text.line_size
  224.     mov  eax,4
  225.    newline:
  226.     mcall
  227.     add  ebx, 14
  228.     add  edx,text.line_size
  229.     cmp  byte[edx],'x'
  230.     jne  newline
  231.  
  232.     mov   ebx,[pinfo.box.width]
  233.     sub   ebx,MAGIC1+10+1-9
  234.     shl   ebx,16
  235.     add   ebx,1+( (14*3+16)/3-1)/2-3
  236.     mcall  ,,[sc.work_button_text],s_compile,7
  237.     add   ebx,(14*3+16)/3+1
  238.     mcall ,,,s_run
  239.     add   ebx,(14*3+16)/3+1
  240.     mcall ,,,s_debug
  241.  
  242.     mpack ebx,MAGIC1+6,0
  243.     add   ebx,1+ 14/2-3+ 14*0
  244.     mov   esi,[pinfo.box.width]
  245.     sub   esi,MAGIC1*2+5*2+6+3
  246.     mov   eax,esi
  247.     mov   cl,6
  248.     div   cl
  249.     cmp   al,MAX_PATH
  250.     jbe   @f
  251.     mov   al,MAX_PATH
  252. @@: movzx esi,al
  253.     mcall 4,,[sc.work_text],infile
  254.     add   ebx,14
  255.     mcall ,,,outfile
  256.     add   ebx,14
  257.     mcall ,,,path
  258.  
  259.         call    draw_checkbox
  260.  
  261.     call  draw_messages
  262.  
  263.     mcall  12,2 ; End of Draw
  264.  
  265.     popa
  266.     ret
  267.  
  268. bottom_right dd ?
  269.  
  270. draw_checkbox:
  271.         mcall   8,<5,10>,<14*3+5,10>,14,[sc.work_button]
  272.         cmp     [bGenerateDebugInfo], 0
  273.         jz      @f
  274.         mov     edx, [sc.work_button_text]
  275.         mcall   38,<7,13>,<14*3+7,14*3+13>
  276.         mcall   38,,<14*3+13,14*3+7>
  277. @@:
  278.         mov     ecx, [sc.work_text]
  279.         or      ecx, 0x80000000
  280.         mcall   4,<20,14*3+7>,,s_dbgdescr
  281.         ret
  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. ; read string
  327.  
  328. f1: mov  [addr],infile
  329.     add  [ya], 14*0
  330.     jmp  rk
  331. f2: mov  [addr],outfile
  332.     add  [ya], 14*1
  333.     jmp  rk
  334. f3: mov  [addr],path
  335.     add  [ya], 14*2
  336. rk:
  337.  
  338.     mov  edi,[addr]
  339.     mov  al,0
  340.     mov  ecx,MAX_PATH
  341.     add  edi,ecx
  342.     dec  edi
  343.     std
  344.     repe scasb
  345.     sub  ecx,MAX_PATH
  346.     neg  ecx
  347.     mov  al,$1C ; ''
  348.     add  edi,2
  349.     push  edi
  350.     cld
  351.     rep  stosb
  352.     call print_text
  353.     pop edi
  354. f11:mcall  10
  355.     cmp    eax,2
  356.     jne read_done
  357.     mcall; 2
  358.     shr    eax,8
  359.     cmp    al,13
  360.     je    read_done
  361.     cmp    al,8
  362.     jne nobs
  363.     cmp    edi,[addr]
  364.     je    f11
  365.     sub    edi,1
  366.     mov    byte[edi],$1C ; '_'
  367.     call   print_text
  368.     jmp    f11
  369.    nobs:
  370.     movzx  ebx,al
  371.     sub    ebx,$20
  372.     jle    f11
  373.     sub    al,[sub_table+ebx]
  374.    keyok:
  375.     mov    ecx,[addr]
  376.     add    ecx,MAX_PATH
  377.     cmp    edi,ecx
  378.     jae    f11
  379.     mov    [edi],al
  380.  
  381.     call   print_text
  382.     inc    edi
  383.     jmp f11
  384.  
  385.   read_done:
  386.  
  387.     mov    ecx,[addr]
  388.     add    ecx,MAX_PATH
  389.     sub    ecx,edi
  390.     mov    al,0;' '
  391.     cld
  392.     rep    stosb
  393.     call   print_text
  394.  
  395.     jmp    still
  396.  
  397. print_text:
  398.  
  399.     mpack ebx,MAGIC1+6,[pinfo.box.width]
  400.     sub   ebx,MAGIC1*2+19
  401.     movzx esi,bx
  402.     mov   ecx,[ya-2]
  403.     mov   cx,8
  404.     mcall 13,,,[sc.work]
  405.  
  406.     mpack ebx,MAGIC1+6,[ya]
  407.     mov   eax,esi
  408.     mov   cl,6
  409.     div   cl
  410.     cmp   al,MAX_PATH
  411.     jbe   @f
  412.     mov   al,MAX_PATH
  413. @@: movzx esi,al
  414.     mcall 4,,[sc.work_text],[addr]
  415.  
  416.     ret
  417.  
  418.  
  419. ; DATA
  420.  
  421. text:
  422.   db ' INFILE:'
  423. .line_size = $-text
  424.   db 'OUTFILE:'
  425.   db '   PATH:'
  426.   db 'x'
  427.  
  428. s_compile db 'COMPILE'
  429. s_run     db '  RUN  '
  430. s_debug   db ' DEBUG '
  431.  
  432. s_dbgdescr      db      'Generate debug information',0
  433.  
  434. infile    db 'example.asm'
  435.   times MAX_PATH+$-infile  db 0
  436. outfile db 'example'
  437.   times MAX_PATH+$-outfile db 0
  438. path    db '/rd/1/'
  439.   times MAX_PATH+$-path    db 0
  440.  
  441. lf db 13,10,0
  442.  
  443. addr dd 0x0
  444. ya   dd 0x0
  445. zero db 0x0
  446.  
  447. mov_param_str:
  448.   @@:
  449.     mov    al,[esi]
  450.     cmp    al,','
  451.     je       @f
  452.     cmp    al,0
  453.     je       @f
  454.     mov    [edi],al
  455.     inc    esi
  456.     inc    edi
  457.     jmp    @b
  458.   @@:
  459.     mov    al,0
  460.     stosb
  461. ret
  462.  
  463. start:
  464.     cmp    [_mode],NORMAL_MODE
  465.     jne    @f
  466.     call   draw_messages
  467.     mov    [textxy],7 shl 16 + 70
  468. @@:
  469.     mov    esi,_logo
  470.     call   display_string
  471.  
  472.  ;
  473.  ;   Fasm native code
  474.  ;
  475.  
  476.     mov    [input_file],infile
  477.     mov    [output_file],outfile
  478.  
  479.     call   init_memory
  480.  
  481.     call   make_timestamp
  482.     mov    [start_time],eax
  483.  
  484.     call   preprocessor
  485.     call   parser
  486.     call   assembler
  487.     cmp    [bGenerateDebugInfo], 0
  488.     jz     @f
  489.     call   symbol_dump
  490. @@:
  491.     call   formatter
  492.  
  493.     call   display_user_messages
  494.     movzx  eax,[current_pass]
  495.     inc    eax
  496.     call   display_number
  497.     mov    esi,_passes_suffix
  498.     call   display_string
  499.     call   make_timestamp
  500.     sub    eax,[start_time]
  501.     xor    edx,edx
  502.     mov    ebx,100
  503.     div    ebx
  504.     or       eax,eax
  505.     jz       display_bytes_count
  506.     xor    edx,edx
  507.     mov    ebx,10
  508.     div    ebx
  509.     push   edx
  510.     call   display_number
  511.     mov    dl,'.'
  512.     call   display_character
  513.     pop    eax
  514.     call   display_number
  515.     mov    esi,_seconds_suffix
  516.     call   display_string
  517.   display_bytes_count:
  518.     mov    eax,[written_size]
  519.     call   display_number
  520.     mov    esi,_bytes_suffix
  521.     call   display_string
  522.     xor    al,al
  523.  
  524.     cmp    [_run_outfile],0
  525.     je     @f
  526.     mov    edx,outfile
  527.     call   make_fullpaths
  528.     mov    eax,70
  529.     mov    ebx,file_info_start
  530.     xor    ecx,ecx
  531.     mcall
  532. @@:
  533.     jmp    exit_program
  534.  
  535.  
  536. include 'system.inc'
  537. include 'version.inc'
  538. include 'errors.inc'
  539. include 'expressi.inc'
  540. include 'preproce.inc'
  541. include 'parser.inc'
  542. include 'assemble.inc'
  543. include 'formats.inc'
  544. include 'x86_64.inc'
  545. include 'tables.inc'
  546. include 'symbdump.inc'
  547.  
  548. title db appname,VERSION_STRING,0
  549.  
  550. _logo db 'flat assembler  version ',VERSION_STRING,13,10,0
  551.  
  552. _passes_suffix db ' passes, ',0
  553. _seconds_suffix db ' seconds, ',0
  554. _bytes_suffix db ' bytes.',13,10,0
  555.  
  556. _include db 'INCLUDE',0
  557.  
  558. _counter db 4,'0000'
  559.  
  560. _mode          dd NORMAL_MODE
  561. _run_outfile  dd 0
  562. bGenerateDebugInfo db 0
  563.  
  564. sub_table:
  565. times $41 db $00
  566. times $1A db $20
  567. times $25 db $00
  568. times $10 db $20
  569. times $30 db $00
  570. times $10 db $50
  571. times $04 db $00,$01
  572. times $08 db $00
  573.  
  574. ;include_debug_strings
  575.  
  576. params db 0 ; 'TINYPAD.ASM,TINYPAD,/HD/1/TPAD4/',
  577. program_end:
  578. rb 1000h
  579.  
  580. align 4
  581.  
  582. include 'variable.inc'
  583.  
  584. program_base dd ?
  585. buffer_address dd ?
  586. memory_setting dd ?
  587. start_time dd ?
  588.  
  589. dbgfilename     rb      MAX_PATH+4
  590.  
  591. sc    system_colors
  592. max_handles = 8
  593. fileinfos rb (4+20+MAX_PATH)*max_handles
  594. fileinfos_end:
  595. pinfo process_information
  596.