Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                 ;;
  3. ;;  flat assembler source                          ;;
  4. ;;  Copyright (c) 1999-2004, 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)+6*2+2
  15. MAGIC2     = 14
  16. MAGIC3     = 1
  17. MAGIC4     = 7
  18. OUTPUTXY = (5+MAGIC4) shl 16 + MAGIC2*3+MAGIC3+MAGIC4+1+2
  19. MAX_PATH = 100
  20.  
  21. APP_MEMORY = 0x00800000
  22.  
  23. ;; Menuet header
  24.  
  25. use32
  26.  
  27.   org 0x0
  28.   db 'MENUET01'  ; 8 byte id
  29.   dd 0x01     ; header version
  30.   dd START     ; program start
  31.   dd program_end ; program image size
  32.   dd APP_MEMORY  ; required amount of memory
  33.   dd 0xDFFF0     ; stack
  34.   dd params,0x0  ; parameters,icon
  35.  
  36. include 'lang.inc'
  37. include 'fasm.inc'
  38. ;include 'debug2.inc'
  39.  
  40. center fix true
  41.  
  42. START:      ; Start of execution
  43.  
  44.    cmp       [params],0
  45.    jz       noparams
  46.  
  47.    mov       ecx,10
  48.    mov       al,' '
  49.    mov       edi,infile
  50.    push    ecx
  51.    cld
  52.    rep       stosd
  53.    mov       ecx,[esp]
  54.    mov       edi,outfile
  55.    rep       stosd
  56.    pop       ecx
  57.    mov       edi,path
  58.    rep       stosd
  59.  
  60.    mov       esi,params
  61. ;  DEBUGF  "params: %s\n",esi
  62.    mov       edi,infile
  63.    call    mov_param_str
  64. ;  mov     edi,infile
  65. ;  DEBUGF  " input: %s\n",edi
  66.    inc       esi
  67.    mov       edi,outfile
  68.    call    mov_param_str
  69. ;  mov     edi,outfile
  70. ;  DEBUGF  "output: %s\n",edi
  71.    inc       esi
  72.    mov       edi,path
  73.    call    mov_param_str
  74. ;  mov     edi,path
  75. ;  DEBUGF  "  path: %s\n",edi
  76.  
  77.    cmp       [esi], dword ',run'
  78.    jne       @f
  79.    mov       [_run_outfile],1
  80.   @@:
  81.  
  82.    mov       [_mode],CONSOLE_MODE
  83.    jmp       start
  84.  
  85.   noparams:
  86.  
  87.     call draw_window
  88.  
  89. still:
  90.  
  91.     mcall  10     ; Wait here for event
  92.  
  93.     dec    eax     ; Redraw request
  94.     jz       red
  95.     dec    eax     ; Key in buffer
  96.     jz       key
  97.     dec    eax     ; Button in buffer
  98.     jz       button
  99.  
  100.     jmp  still
  101.  
  102. red:    ; Redraw
  103.     call draw_window
  104.     jmp  still
  105.  
  106. key:    ; Key
  107.     mcall  2     ; Read it and ignore
  108.     jmp  still
  109.  
  110. button:    ; Button in Window
  111.  
  112.     mcall  17
  113.  
  114.     cmp  ah,2    ; Start compiling
  115.     je     start
  116.     cmp  ah,3    ; Start compiled file
  117.     jnz  norunout
  118.  
  119.     mov  edx,outfile
  120.     call make_fullpaths
  121.     mcall  58,file_info_start
  122. ;   xor   ecx,ecx
  123.     jmp  still
  124.    norunout:
  125.  
  126.     mov  ecx,[skinh]
  127.     add  ecx,MAGIC3+MAGIC2/2-3
  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.     dec  ah   ; Close application
  138.     jnz  still
  139.  
  140.     mcall -1
  141.  
  142. skinh dd ?
  143.  
  144. draw_window:
  145.  
  146.     pusha
  147.  
  148.     mcall  12,1 ; Start of draw
  149.  
  150.     get_sys_colors 1,0
  151.  
  152.     mcall 0,<50,280>,<50,250>,[sc.work]      ; Draw Window
  153.  
  154.     draw_caption header,header.size         ; Draw Window Label Text
  155.  
  156.     mov   ecx,[skinh-2]
  157.     mov   cx,word[skinh]
  158.     madd  ecx,MAGIC3,MAGIC3
  159.     mov   ebx,[pinfo.x_size]
  160.     madd  ebx,5,-5
  161.  
  162.     push  ecx
  163.     madd  ecx,MAGIC2*3+2,MAGIC2*3+2
  164.     mcall 38,,,[sc.work_graph]
  165.     pop   ecx
  166.  
  167.     sub   ebx,MAGIC1+3
  168.  
  169.     mcall
  170.     madd  ecx,MAGIC2,MAGIC2
  171.     mcall
  172.     madd  ecx,MAGIC2,MAGIC2
  173.     mcall
  174.     madd  ecx,MAGIC2,MAGIC2
  175.     mcall
  176.     push  ebx
  177.     mpack ebx,MAGIC1+5,MAGIC1+5
  178.     sub   cx,MAGIC2*3
  179.     mcall
  180.     mov   ebx,[esp-2]
  181.     pop   bx
  182.     mcall
  183.     add   esp,2
  184.  
  185.     mpack ebx,5,MAGIC1-1
  186.     mpack ecx,[skinh],MAGIC2-2
  187.     madd  ecx,MAGIC3+1,0
  188.     mcall 8,,,0x4000000B       ; Button: Enter Infile
  189.     madd  ecx,MAGIC2,0
  190.     mcall  ,,,0x4000000C       ; Button: Enter Outfile
  191.     madd  ecx,MAGIC2,0
  192.     mcall  ,,,0x4000000D       ; Button: Enter Path
  193.  
  194.     mpack ebx,[pinfo.x_size],MAGIC1
  195.     msub  ebx,MAGIC1+5+1,0
  196.     mpack ecx,[skinh],MAGIC2*3/2-1
  197.     madd  ecx,MAGIC3,0
  198.     mcall  ,,,0x00000002,[sc.work_button]
  199.     madd  ecx,MAGIC2*3/2+1,0
  200.     mcall  ,,,0x00000003
  201.  
  202.     mpack ebx,5+6,[skinh]    ; Draw Window Text
  203.     add   bx,MAGIC3+MAGIC2/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,MAGIC2
  211.     add  edx,text.line_size
  212.     cmp  byte[edx],'x'
  213.     jne  newline
  214.  
  215.     mov   ebx,[pinfo.x_size]
  216.     sub   ebx,MAGIC1+5+1-9
  217.     shl   ebx,16
  218.     mov   bx,word[skinh]
  219.     add   bx,MAGIC3+(MAGIC2*3/2-1)/2-3
  220.     mcall  ,,[sc.work_button_text],s_compile,7
  221.     add   ebx,MAGIC2*3/2+1
  222.     mcall ,,,s_run
  223.  
  224.     mpack ebx,MAGIC1+5+6,[skinh]
  225.     add   ebx,MAGIC3+MAGIC2/2-3+MAGIC2*0
  226.     mov   esi,[pinfo.x_size]
  227.     sub   esi,MAGIC1*2+5*2+6+3
  228.     mov   eax,esi
  229.     mov   cl,6
  230.     div   cl
  231.     cmp   al,MAX_PATH
  232.     jbe   @f
  233.     mov   al,MAX_PATH
  234. @@: movzx esi,al
  235.     mcall 4,,[sc.work_text],infile
  236.     add   ebx,MAGIC2
  237.     mcall ,,,outfile
  238.     add   ebx,MAGIC2
  239.     mcall ,,,path
  240.  
  241.     call  draw_messages
  242.  
  243.     mcall  12,2 ; End of Draw
  244.  
  245.     popa
  246.     ret
  247.  
  248. bottom_right dd ?
  249.  
  250. draw_messages:
  251.     mov    eax,13      ; clear work area
  252.     mpack  ebx,5+MAGIC4-2,[pinfo.x_size]
  253.     sub    ebx,5*2+MAGIC4*2-1-2*2
  254.     mpack  ecx,[skinh],[pinfo.y_size]
  255.     madd   ecx,MAGIC2*3+MAGIC3+MAGIC4+1,-(MAGIC2*3+MAGIC3+MAGIC4*2+5)+2
  256.     mov    word[bottom_right+2],bx
  257.     mov    word[bottom_right],cx
  258.     msub   [bottom_right],7,11
  259.     add    [bottom_right],OUTPUTXY
  260.     sub    ecx,[skinh]
  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,5+MAGIC4-3,5+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,5+MAGIC4-3,5+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+5+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+5+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. sz header,'FASM FOR MENUET'
  390.  
  391. text:
  392.   db ' INFILE:'
  393. .line_size = $-text
  394.   db 'OUTFILE:'
  395.   db '   PATH:'
  396.   db 'x'
  397.  
  398. s_compile db 'COMPILE'
  399. s_run      db '  RUN  '
  400.  
  401. infile    db 'EXAMPLE.ASM'
  402.   times MAX_PATH+$-infile  db 0
  403. outfile db 'EXAMPLE'
  404.   times MAX_PATH+$-outfile db 0
  405. path    db '/RD/1/'
  406.   times MAX_PATH+$-path    db 0
  407.  
  408. lf db 13,10,0
  409.  
  410. addr dd 0x0
  411. ya   dd 0x0
  412. zero db 0x0
  413.  
  414. mov_param_str:
  415.   @@:
  416.     mov    al,[esi]
  417.     cmp    al,','
  418.     je       @f
  419.     cmp    al,0
  420.     je       @f
  421.     mov    [edi],al
  422.     inc    esi
  423.     inc    edi
  424.     jmp    @b
  425.   @@:
  426.     mov    al,0
  427.     stosb
  428. ret
  429.  
  430. start:
  431.     cmp    [_mode],NORMAL_MODE
  432.     jne    @f
  433.     call   draw_messages
  434.     push   [skinh]
  435.     pop    [textxy]
  436.     add    [textxy],OUTPUTXY
  437. @@:
  438.     mov    esi,_logo
  439.     call   display_string
  440.  
  441.  ;
  442.  ;   Fasm native code
  443.  ;
  444.  
  445.     mov    [input_file],infile
  446.     mov    [output_file],outfile
  447.  
  448.     call   init_memory
  449.  
  450.     call   make_timestamp
  451.     mov    [start_time],eax
  452.  
  453.     call   preprocessor
  454.     call   parser
  455.     call   assembler
  456.     call   formatter
  457.  
  458.     call   display_user_messages
  459.     movzx  eax,[current_pass]
  460.     inc    eax
  461.     call   display_number
  462.     mov    esi,_passes_suffix
  463.     call   display_string
  464.     call   make_timestamp
  465.     sub    eax,[start_time]
  466.     xor    edx,edx
  467.     mov    ebx,100
  468.     div    ebx
  469.     or       eax,eax
  470.     jz       display_bytes_count
  471.     xor    edx,edx
  472.     mov    ebx,10
  473.     div    ebx
  474.     push   edx
  475.     call   display_number
  476.     mov    dl,'.'
  477.     call   display_character
  478.     pop    eax
  479.     call   display_number
  480.     mov    esi,_seconds_suffix
  481.     call   display_string
  482.   display_bytes_count:
  483.     mov    eax,[written_size]
  484.     call   display_number
  485.     mov    esi,_bytes_suffix
  486.     call   display_string
  487.     xor    al,al
  488.  
  489.     cmp    [_run_outfile],0
  490.     je       @f
  491.     mov    edx,outfile
  492.     call   make_fullpaths
  493.     mov    eax,58
  494.     mov    ebx,file_info_start
  495.     xor    ecx,ecx
  496.     int    0x40
  497. @@:
  498.     jmp    exit_program
  499.  
  500.  
  501. include 'system.inc'
  502.  
  503. include 'version.inc'
  504. include 'errors.inc'
  505. include 'expressi.inc'
  506. include 'preproce.inc'
  507. include 'parser.inc'
  508. include 'assemble.inc'
  509. include 'formats.inc'
  510. include 'x86_64.inc'
  511.  
  512. _logo db 'flat assembler  version ',VERSION_STRING,13,10,0
  513.  
  514. _passes_suffix db ' passes, ',0
  515. _seconds_suffix db ' seconds, ',0
  516. _bytes_suffix db ' bytes.',13,10,0
  517.  
  518. _include db 'INCLUDE',0
  519.  
  520. _counter db 4,'0000'
  521.  
  522. _mode          dd NORMAL_MODE
  523. _run_outfile  dd 0
  524.  
  525. sub_table:
  526. times $41 db $00
  527. times $1A db $20
  528. times $25 db $00
  529. times $10 db $20
  530. times $30 db $00
  531. times $10 db $50
  532. times $04 db $00,$01
  533. times $08 db $00
  534.  
  535. ;include_debug_strings
  536.  
  537. params db 0 ; 'TINYPAD.ASM,TINYPAD,/HD/1/TPAD4/',
  538. program_end:
  539. rb 1000h
  540.  
  541. align 4
  542.  
  543. include 'variable.inc'
  544.  
  545. program_base dd ?
  546. buffer_address dd ?
  547. memory_setting dd ?
  548. start_time dd ?
  549.  
  550. sc    system_colors
  551. pinfo process_information
  552.