Subversion Repositories Kolibri OS

Rev

Rev 1013 | Rev 4095 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
;
2
;   LAUNCHER - АВТОЗАПУСК ПРОГРАММ
3
;     Код программы совсем не оптимизирован, но очень прост для понимания.
4
;     Этот лаунчер грузит информацию о программах для запуска из файла
5
;     AUTORUN.DAT. Формат очень прост и в комментариях не нуждается.
6
;
7
;   Компилируйте с помощью FASM 1.52 и выше
8
;
1741 dunkaist 9
include "../../../macros.inc"
31 halyavin 10
 
11
  use32
12
  org    0x0
13
  db     'MENUET01'              ; 8 byte id
14
  dd     0x01                    ; header version
15
  dd     START                   ; start of code
16
  dd     I_END                   ; size of image
17
  dd     0x8000                 ; memory for app
18
  dd     0x8000                 ; esp
19
  dd     0x0 , 0x0               ; I_Param , I_Icon
20
 
21
;include "DEBUG.INC"
22
 
23
START:                           ; start of execution
24
 
132 diamond 25
;   mov  eax, 5
26
;   mov  ebx, 10
485 heavyiron 27
;   mcall
31 halyavin 28
 
1013 diamond 29
;   mcall 18,15
132 diamond 30
 
142 diamond 31
   mov  eax, 70               ; load AUTORUN.DAT
31 halyavin 32
   mov  ebx, autorun_dat_info
485 heavyiron 33
   mcall
1013 diamond 34
   add  ebx, file_data
35
   mov  [fileend], ebx
31 halyavin 36
 
1013 diamond 37
; this cycle does not contain an obvious exit condition,
38
; but auxiliary procedures (like "get_string") will exit
39
; at EOF
31 halyavin 40
 start_program:
1013 diamond 41
   call skip_spaces
42
   cmp  al,'#'
43
   jz   skip_this_string
31 halyavin 44
   call clear_strings
45
   mov  edi, program
46
   call get_string
47
   mov  edi, parameters
48
   call get_string
49
   call get_number
1013 diamond 50
;dps <"STARTING A PROGRAM",13,10>
31 halyavin 51
   call run_program
1013 diamond 52
 skip_this_string:
31 halyavin 53
   call next_line
1013 diamond 54
   jmp  start_program
31 halyavin 55
 
56
 exit:
57
   or   eax, -1
485 heavyiron 58
   mcall
31 halyavin 59
 
60
 
61
 run_program:     ; time to delay in eax
62
   push eax
142 diamond 63
   mcall 70, start_info
31 halyavin 64
   pop  ebx
65
 
1013 diamond 66
; if delay is negative, wait for termination
67
;   of the spawned process
68
   test ebx, ebx
69
   js   must_wait_for_termination
70
; otherwise, simply wait
31 halyavin 71
   mov  eax, 5
485 heavyiron 72
   mcall
1013 diamond 73
   ret
74
 must_wait_for_termination:
75
   mov  esi, eax  ; save slot for the future
76
; get process slot
77
   mov  ecx, eax
78
   mcall 18, 21
79
; if an error has occured, exit
80
   test eax, eax
81
   jz   child_exited
82
   mov  ecx, eax
83
; wait
84
 wait_for_termination:
85
   mcall 5, 1
86
   mov  ebx, processinfo
87
   mcall 9
88
   cmp  word [ebx+50], 9 ; the slot was freed?
89
   jz   child_exited
90
   cmp  dword [ebx+30], esi ; the slot is still occupied by our child?
91
   jz   wait_for_termination
92
 child_exited:
93
   ret
31 halyavin 94
 
95
 clear_strings:   ; clears buffers
96
   pushad
97
 
98
   mov  ecx, 60
99
   mov  edi, program
100
   xor  al, al ;mov  al, ' '
101
   rep  stosb
102
 
103
   mov  ecx, 60
104
   mov  edi, parameters
105
   rep  stosb
106
 
107
   popad
108
 ret
109
 
110
 
111
 get_string: ; pointer to destination buffer in edi
112
   pushad
113
   call skip_spaces
114
   mov  esi, [position]
115
;dpd esi
116
;dps <13,10>
117
   add  esi, file_data
118
  .start:
1013 diamond 119
   cmp  esi, [fileend]
120
   jae  exit
31 halyavin 121
   lodsb
122
   cmp  al, ' '
123
   je   .finish
124
   stosb
125
   inc  [position]
126
   jmp  .start
127
  .finish:
128
   popad
129
 ret
130
 
131
 
132
 get_number:
133
   push ebx esi
134
   call skip_spaces
135
   mov  esi, [position]
136
   add  esi, file_data
137
   xor  eax, eax
1013 diamond 138
   cmp  byte [esi], '-'
139
   jnz  @f
140
   inc  eax
141
   inc  esi
142
   inc  [position]
143
@@:
144
   push eax
145
   xor  eax, eax
31 halyavin 146
   xor  ebx, ebx
147
  .start:
1013 diamond 148
   cmp  esi, [fileend]
149
   jae  .finish
31 halyavin 150
   lodsb
142 diamond 151
   sub  al, '0'
152
   cmp  al, 9
31 halyavin 153
   ja   .finish
142 diamond 154
   lea  ebx,[ebx*4+ebx]
155
   lea  ebx,[ebx*2+eax]
31 halyavin 156
   inc  [position]
157
   jmp  .start
158
  .finish:
1013 diamond 159
   pop  eax
160
   dec  eax
161
   jnz  @f
162
   neg  ebx
163
@@:
31 halyavin 164
   mov  eax, ebx
165
   pop  esi ebx
166
 ret
167
 
168
 
169
 skip_spaces:
1013 diamond 170
   push esi
31 halyavin 171
   xor  eax, eax
172
   mov  esi, [position]
173
   add  esi, file_data
174
  .start:
1013 diamond 175
   cmp  esi, [fileend]
176
   jae  .finish
31 halyavin 177
   lodsb
178
   cmp  al, ' '
179
   jne  .finish
180
   inc  [position]
181
   jmp  .start
182
  .finish:
183
;dps "NOW AL = "
184
;mov [tmp],al
185
;mov edx, tmp
186
;call debug_outstr
187
;dps <13,10>
1013 diamond 188
   pop  esi
31 halyavin 189
 ret
190
 
191
 
192
 next_line:
193
   mov  esi, [position]
194
   add  esi, file_data
195
  .start:
1013 diamond 196
   cmp  esi, [fileend]
197
   jae  exit
31 halyavin 198
   lodsb
199
   cmp  al, 13
200
   je   .finish
1013 diamond 201
   cmp  al, 10
202
   je   .finish
31 halyavin 203
   inc  [position]
204
   jmp  .start
205
  .finish:
1013 diamond 206
   inc  [position]
207
   cmp  esi, [fileend]
208
   jae  exit
31 halyavin 209
   lodsb
210
   cmp  al, 13
1013 diamond 211
   je   .finish
212
   cmp  al, 10
213
   je   .finish
214
   ret
31 halyavin 215
 
216
 
217
 
218
; DATA:
219
 position          dd 0            ; position in file
220
 
221
 autorun_dat_info:                 ; AUTORUN.DAT
222
   .mode           dd 0            ; read file
223
   .start_block    dd 0            ; block to read
142 diamond 224
                   dd 0
225
   .blocks         dd 16*512       ; 16*512 bytes max
31 halyavin 226
   .address        dd file_data
529 spraid 227
   db "AUTORUN.DAT",0
31 halyavin 228
 
229
 start_info:
142 diamond 230
   .mode           dd 7
31 halyavin 231
                   dd 0
232
   .params         dd parameters
233
                   dd 0
142 diamond 234
                   dd 0
31 halyavin 235
   .path: ;      
236
 
237
I_END:
238
 
239
 program           rb 61 ; 60 + [0] char
240
 parameters        rb 61
241
 
1013 diamond 242
 processinfo       rb 1024
243
 fileend           dd ?
31 halyavin 244
 
245
 file_data         rb 16*512