Subversion Repositories Kolibri OS

Rev

Rev 720 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;   Port to KolibliOS
  3. ;   (jacekm.pl@gmail.com)
  4. ;
  5.  
  6. ;B+ System header
  7. use32
  8. org    0x0
  9.   db     'MENUET01'
  10.   dd     0x01
  11.   dd     START
  12.   dd     I_END
  13.   dd     0x500000
  14.   dd     0x7fff0
  15.   dd     0x0,0x0
  16. ;E:.
  17.  
  18. ;B+ Include C files
  19.   ; Compiler tools
  20.   include "INTRINS.ASM"
  21.  
  22.   ; C Library ("stdio.asm")
  23.   include "LIBSTD.ASM"
  24.  
  25.   ; MenuetOS implement
  26.   include "OSFUNC.ASM"
  27.  
  28. _fopen  equ _OS_fopen
  29. _fputc  equ _OS_fputc
  30. _fgetc  equ _OS_fgetc
  31. _fclose equ _OS_fclos
  32.  
  33.   ;Main program (compiled from C)
  34.   include "GETARG.ASM"
  35.   include "CC1.ASM"
  36.   include "CC2.ASM"
  37.   include "CC3.ASM"
  38.   include "CC4.ASM"
  39. ;E:.
  40.  
  41. START:
  42. ;B+ Main cycle
  43.   call draw_window
  44. still:
  45.   mov  eax,10
  46.   int  0x40
  47. still1:
  48.  
  49.   cmp  eax,1
  50.   je   red
  51.   cmp  eax,2
  52.   je   key
  53.   cmp  eax,3
  54.   je   button
  55.   jmp  still
  56.  
  57. red:
  58.   call draw_window
  59.   jmp  still
  60.  
  61. key:
  62.   mov  eax,2
  63.   int  0x40
  64.   jmp  still
  65.  
  66. button:
  67.   mov  eax,17
  68.   int  0x40
  69.  
  70.   cmp  ah,1
  71.   jne  .noclose
  72.   mov  eax,-1
  73.   int  0x40
  74. .noclose:
  75.  
  76.   cmp  ah,2
  77.   jne  .no_run
  78. ;  call begin_osfunc
  79. ;B+ Copy file path
  80.   mov  esi,inp_path
  81.   mov  edi,filepath
  82.   mov  ecx,[p_len]
  83.  push ecx
  84.   cld
  85. rep movsb
  86.  pop  ecx
  87.   add  ecx,filepath
  88.   mov  [p_filename],ecx
  89. ;E:.
  90. ;B+ Clear word area
  91.   mov  ebx,10 shl 16 + 280
  92.   mov  ecx,60 shl 16 + 250
  93.   mov  edx,0x303030
  94.   mov  eax,13
  95.   int  0x40
  96. ;E:.
  97. ;B+ Init parameters
  98.   mov  ecx,_input
  99.   sub  ecx,_nogo
  100.   mov  edi,_nogo
  101.   xor  eax,eax
  102.   cld
  103. rep stosb
  104.   mov  [_input],-1
  105.   mov  [_input2],-1
  106.   mov  [_usexpr],1
  107.   mov  [_ccode],1
  108.   mov  [_quote],34
  109.   mov  [test_outch.y_coord],60
  110. ;E:.
  111.   call init_osfunc
  112.  push dword 4
  113.  push args
  114. ;B+ Save exit ESP
  115.   mov  [exit_esp],esp
  116. ;E:.
  117.   call _main
  118.   add  esp,8
  119. ;  call end_osfunc
  120. .no_run:
  121.  
  122.   cmp  ah,3
  123.   jne  .no_path
  124.   mov  eax,inp_path
  125.   mov  bx,27
  126.   call read_string
  127.   mov  edx,[r_pos]
  128.   mov  [p_len],edx
  129.   ;
  130.   cmp  ah,10
  131.   je   still
  132.   jmp  still1
  133. .no_path:
  134.  
  135.   cmp  ah,4
  136.   jne  .no_file
  137.   mov  eax,inp_file
  138.   mov  bx,42
  139.   call read_string
  140.   mov  edx,[r_pos]
  141.   mov  [f_len],edx
  142.   ;
  143.   cmp  ah,10
  144.   je   still
  145.   jmp  still1
  146. .no_file:
  147.  
  148.   jmp  still
  149. ;E:.
  150.  
  151. read_string:
  152. ;B+ Read string
  153.   mov  [c_place],eax
  154.   mov  [r_pos],0
  155.   mov  [rel_x],60
  156.   mov  [rel_y],bx
  157.  
  158.   mov  ebx,60
  159.   shl  ebx,16
  160.   mov  bx,6*26+1
  161.   movzx ecx,[rel_y]
  162.   shl  ecx,16
  163.   mov  cx,10
  164.   mov  edx,0x000000
  165.   mov  eax,13
  166.   int  0x40
  167.  
  168.   add  ecx,11 shl 16
  169.   mov  cx,2
  170.   mov  edx,0x999999
  171.   int  0x40
  172.  
  173. .next:
  174.   mov  ebx,[rel_x]
  175.   shl  ebx,16
  176.   mov  bx,7
  177.   movzx ecx,[rel_y]
  178.   shl  ecx,16
  179.   mov  cx,10
  180.   mov  edx,0x000000
  181.   mov  eax,13
  182.   int  0x40
  183.  
  184.   mov  ebx,[c_place]
  185.   mov  byte [ebx],0
  186.  
  187.   mov  eax,10
  188.   int  0x40
  189.   cmp  eax,2
  190.   je   .key
  191.   jmp  .to_ret
  192. .key:
  193.  
  194.   mov  eax,2
  195.   int  0x40
  196.   cmp  ah,13
  197.   jne  .no_enter
  198.   jmp  .to_ret
  199. .no_enter:
  200.  
  201.   cmp  ah,8
  202.   jne  .no_back
  203.   cmp  [r_pos],0
  204.   je   .next
  205.   dec  [r_pos]
  206.   dec  [c_place]
  207.   sub  [rel_x],6
  208.   jmp  .next
  209. .no_back:
  210.  
  211.   cmp  [r_pos],25
  212.   je   .next
  213.  
  214.   cmp  ah,'a'
  215.   jb   .no_sm_l
  216.   cmp  ah,'z'
  217.   ja   .no_sm_l
  218.   add  ah,'A'-'a'
  219. .no_sm_l:
  220.  
  221.   mov  byte [ebx],ah
  222.   mov  [char],ah
  223.   inc  [c_place]
  224.   inc  [r_pos]
  225.  
  226.   mov  ebx,[rel_x]
  227.   inc  ebx
  228.   shl  ebx,16
  229.   mov  bx,[rel_y]
  230.   inc  bx
  231.   mov  ecx,0x00ffff
  232.   mov  edx,char
  233.   mov  esi,1
  234.   mov  eax,4
  235.   int  0x40
  236.  
  237.   add  [rel_x],6
  238.   jmp  .next
  239.  
  240. .to_ret:
  241.  push eax
  242.   mov  ebx,60
  243.   shl  ebx,16
  244.   mov  bx,6*26+1
  245.   movzx ecx,[rel_y]
  246.   add  ecx,11
  247.   shl  ecx,16
  248.   mov  cx,2
  249.   mov  edx,0x000000
  250.   mov  eax,13
  251.   int  0x40
  252.  pop  eax
  253.   ret
  254.  
  255. rel_x dd 60
  256. rel_y dw 0x0
  257. c_place dd 0x0
  258. r_pos dd 0x0
  259. char db '?'
  260. ;E:.
  261.  
  262. draw_window:
  263. ;B+ Draw window
  264.   mov  eax,12
  265.   mov  ebx,1
  266.   int  0x40
  267.  
  268.   mov  ebx,100*65536+300
  269.   mov  ecx,100*65536+320
  270.   mov  edx,0x035555DD
  271.   mov  esi,0x805080d0
  272.   mov  edi,0x005080d0
  273.   mov  eax,0
  274.   int  0x40
  275.  
  276.   mov  ebx,8*65536+8
  277.   mov  ecx,0x10ddeeff
  278.   mov  edx,caption
  279.   mov  esi,caption_end-caption
  280.   mov  eax,4
  281.   int  0x40
  282.  
  283.   ;mov  ebx,(300-19)*65536+12
  284.   ;mov  ecx,5*65536+12
  285.   ;mov  edx,1
  286.   ;mov  esi,0x6688dd
  287.   ;mov  eax,8
  288.   ;int  0x40
  289.  
  290. ;B+ Hot buttons
  291.   mov  ebx,220 shl 16 + 70
  292.   mov  ecx,25 shl 16 + 29
  293.   mov  edx,2 ; compile
  294.   mov  esi,0x6688dd
  295.   mov  eax,8
  296.   int  0x40
  297.  
  298.   mov  ebx,10 shl 16 + 47
  299.   mov  ecx,26 shl 16 + 12
  300.   mov  edx,3 ; path
  301.   mov  esi,0x6688dd
  302.   mov  eax,8
  303.   int  0x40
  304.  
  305.   mov  ebx,10 shl 16 + 47
  306.   mov  ecx,41 shl 16 + 12
  307.   mov  edx,4 ; file name
  308.   mov  esi,0x6688dd
  309.   mov  eax,8
  310.   int  0x40
  311. ;E:.
  312.  
  313. ;B+ Text in buttons
  314.   mov  ebx,231 shl 16 + 36
  315.   mov  ecx,0x10ffffff
  316.   mov  edx,txt_compile
  317.   mov  esi,txt_compile_end-txt_compile
  318.   mov  eax,4
  319.   int  0x40
  320.  
  321.   mov  ebx,14 shl 16 + 28
  322.   mov  ecx,0xffffff
  323.   mov  edx,txt_path
  324.   mov  esi,txt_path_end-txt_path
  325.   int  0x40
  326.  
  327.   mov  ebx,14 shl 16 + 43
  328.   mov  edx,txt_file
  329.   mov  esi,txt_file_end-txt_file
  330.   int  0x40
  331. ;E:.
  332.  
  333. ;B+ Draw path / file name
  334.   mov  ebx,61 shl 16 + 28
  335.   mov  ecx,0x00ffff
  336.   mov  edx,inp_path
  337.   mov  esi,[p_len]
  338.   mov  eax,4
  339.   int  0x40
  340.  
  341.   mov  ebx,61 shl 16 + 43
  342.   mov  ecx,0x00ffff
  343.   mov  edx,inp_file
  344.   mov  esi,[f_len]
  345.   mov  eax,4
  346.   int  0x40
  347. ;E:.
  348.  
  349.   mov  eax,12
  350.   mov  ebx,2
  351.   int  0x40
  352.  
  353.   ret
  354. ;E:.
  355.  
  356. ;B+ Data area
  357.  
  358. ;B+ Interface
  359. inp_path: times 100 db '/RD/1/',0
  360. p_len dd 6
  361. inp_file: times 100 db 'EXAMPLE',0
  362. f_len dd 7
  363.  
  364. txt_compile db 'Compile'
  365. txt_compile_end:
  366. txt_path    db 'Path ->'
  367. txt_path_end:
  368. txt_file    db 'File ->'
  369. txt_file_end:
  370. ;E:.
  371.  
  372. ;B+ Main arguments
  373. args dd arg_str0,inp_file,arg_str2,arg_str3,arg_str4
  374.  
  375. arg_str0 db 'CC',0
  376. arg_str1 db 'prog',0
  377. arg_str2 db '-m',0
  378. arg_str3 db '-a',0
  379. arg_str4 db '-p',0
  380. ;E:.
  381.  
  382. ;B+ System parameters
  383. exit_esp dd 0x0
  384. ;E:.
  385.  
  386. caption db  'Small C compiler for KolibriOS v 0.5.3'
  387. caption_end:
  388.  
  389. times 8-($ mod 8) db 0
  390. ;E:.
  391.  
  392. I_END:
  393.