Subversion Repositories Kolibri OS

Rev

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