Subversion Repositories Kolibri OS

Rev

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