Subversion Repositories Kolibri OS

Rev

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