Subversion Repositories Kolibri OS

Rev

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