Subversion Repositories Kolibri OS

Rev

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