Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
485 heavyiron 1
@^ fix macro comment {
2
^@ fix }
3
 
4
 
5
macro m2m dest,src {
6
 push src
7
 pop  dest
8
}
9
 
10
 
11
macro iglobal {
12
  IGlobals equ IGlobals,
13
  macro __IGlobalBlock { }
14
 
15
macro uglobal {
16
  UGlobals equ UGlobals,
17
  macro __UGlobalBlock { }
18
 
19
endg fix }      ; Use endg for ending iglobal and uglobal blocks.
20
 
21
 
22
macro IncludeIGlobals{
23
  macro IGlobals dummy,[n] \{ __IGlobalBlock
24
     purge __IGlobalBlock  \}
25
  match I, IGlobals \{ I \} }
26
 
27
macro IncludeUGlobals{
28
  macro UGlobals dummy,[n] \{
29
    \common
30
      \local begin, size
31
      begin = $
32
      virtual at $
33
    \forward
34
      __UGlobalBlock
35
      purge __UGlobalBlock
36
    \common
37
      size = $ - begin
38
    end virtual
39
    rb size
40
  \}
41
  match U, UGlobals \{ U \} }
42
 
43
uglobal
44
endg
45
 
46
iglobal
47
endg
48
 
49
 
50
; new application structure
51
macro meos_app_start
52
 {
53
  use32
54
  org 0x0
55
 
56
  db 'MENUET01'
57
  dd 0x01
58
  dd __start
59
  dd __end
60
  dd __memory
61
  dd __stack
62
 
63
  if used __params & ~defined __params
64
    dd __params
65
  else
66
    dd 0x0
67
  end if
68
 
69
  dd 0x0
70
 }
71
MEOS_APP_START fix meos_app_start
72
 
73
macro code
74
 {
75
  __start:
76
 }
77
CODE fix code
78
 
79
macro data
80
 {
81
  __data:
82
  IncludeIGlobals
83
 }
84
DATA fix data
85
 
86
macro udata
87
 {
88
  if used __params & ~defined __params
89
    __params:
90
      db 0
91
    __end:
92
      rb 255
93
  else
94
    __end:
95
  end if
96
  __udata:
97
  IncludeUGlobals
98
 }
99
UDATA fix udata
100
 
101
macro meos_app_end
102
 {
103
  align 32
104
  rb 2048
105
  __stack:
106
  __memory:
107
 }
108
MEOS_APP_END fix meos_app_end
109
 
110
 
111
; macro for defining multiline text data
112
struc mstr [sstring]
113
 {
114
  forward
115
    local ssize
116
    virtual at 0
117
      db sstring
118
      ssize = $
119
    end virtual
120
    dd ssize
121
    db sstring
122
  common
123
    dd -1
124
 }
125
 
126
; macro for defining multiline text data
127
struc mls [sstring]
128
 {
129
  forward
130
    local ssize
131
    virtual at 0
132
      db sstring  ; mod
133
      ssize = $
134
    end virtual
135
    db ssize
136
    db sstring
137
  common
138
    db -1         ; mod
139
 }
140
 
141
 
142
 
143
; strings
144
macro sz name,[data] {	     ; from MFAR [mike.dld]
145
 common
146
  if used name
147
   name db data
148
   .size = $-name
149
  end if
150
}
151
 
152
macro lsz name,[lng,data] {  ; from MFAR [mike.dld]
153
 common
154
  if used name
155
   label name
156
 forward
157
  if lang eq lng
158
   db data
159
  end if
160
 common
161
   .size = $-name
162
  end if
163
}
164
 
165
macro szc name,elsz,[data] {	     ; from MFAR [mike.dld]
166
 common
167
  local s,m
168
  m = 0
169
  if used name
170
   label name
171
 forward
172
   virtual at 0
173
    db data
174
    s = $
175
   end virtual
176
   d#elsz s
177
   if m < s
178
    m = s
179
   end if
180
   db data
181
 common
182
   .size = $-name
183
   .maxl = m
184
  end if
185
}
186
 
187
macro lszc name,elsz,[lng,data] {  ; from MFAR [mike.dld]
188
 common
189
  local s,m,c
190
  m = 0
191
  c = 0
192
  if used name
193
   label name
194
 forward
195
  if lang eq lng
196
   virtual at 0
197
    db data
198
    s = $
199
   end virtual
200
   d#elsz s
201
   if m < s
202
    m = s
203
   end if
204
   db data
205
   c = c+1
206
  end if
207
 common
208
   .size  = $-name
209
   .maxl  = m
210
   .count = c
211
  end if
212
}
213
 
214
 
215
; easy system call macro
216
macro mpack dest, hsrc, lsrc
217
{
218
  if (hsrc eqtype 0) & (lsrc eqtype 0)
219
    mov dest, (hsrc) shl 16 + lsrc
220
  else
221
    if (hsrc eqtype 0) & (~lsrc eqtype 0)
222
      mov dest, (hsrc) shl 16
223
      add dest, lsrc
224
    else
225
      mov dest, hsrc
226
      shl dest, 16
227
      add dest, lsrc
228
    end if
229
  end if
230
}
231
 
232
macro __mov reg,a,b {	    ; mike.dld
233
 if (~a eq)&(~b eq)
234
   mpack reg,a,b
235
 else if (~a eq)&(b eq)
236
   mov reg,a
237
 end if
238
}
239
 
240
 
241
include 'config.inc'
242
;__CPU_type	equ	p5
243
SYSENTER_VAR	equ	0
244
 
245
macro mcall a,b,c,d,e,f {   ; mike.dld, updated by Ghost for Fast System Calls
246
 local	..ret_point
247
 __mov eax,a
248
 __mov ebx,b
249
 __mov ecx,c
250
 __mov edx,d
251
 __mov esi,e
252
 __mov edi,f
253
 
254
 if __CPU_type eq p5
255
	int	0x40
256
 else
257
  if __CPU_type eq p6
258
	push	ebp
259
	mov	ebp, esp
260
	push	..ret_point	; it may be 2 or 5 byte
261
	sysenter
262
 ..ret_point:
263
	pop	edx
264
	pop	ecx
265
 
266
  else
267
   if __CPU_type eq k6
268
	push	ecx
269
	syscall
270
	pop	ecx
271
   else
510 Ghost 272
	display 'ERROR : unknown CPU type (set to p5)', 10, 13
273
	__CPU_type equ p5
485 heavyiron 274
	int	0x40
275
   end if
276
  end if
277
 end if
278
}
279
 
280
 
281
; -------------------------
282
macro header a,[b] {
283
 common
284
  use32
285
  org 0
286
  db 'MENUET',a
287
 forward
288
  if b eq
289
   dd 0
290
  else
291
   dd b
292
  end if }
293
macro section name { align 16
294
 label name }
295
macro func name {
296
 if ~used name
297
  display 'FUNC NOT USED: ',`name,13,10
298
 else
299
  align 4
300
  name:
301
  ;diff16 `name,0,name
302
;pushad
303
;pushfd
304
;dps `name
305
;newline
306
;mcall 5,1
307
;popfd
308
;popad
309
}
310
macro endf { end if }
311
 
312
macro diff16 title,l1,l2
313
 {
314
  local s,d
315
  s = l2-l1
316
  display title,': 0x'
317
  repeat 8
318
   d = '0' + s shr ((8-%) shl 2) and $0F
319
   if d > '9'
320
    d = d + 'A'-'9'-1
321
   end if
322
   display d
323
  end repeat
324
  display 13,10
325
 }
326
 
327
macro diff10 title,l1,l2
328
 {
329
  local s,d,z,m
330
  s = l2-l1
331
  z = 0
332
  m = 1000000000
333
  display title,': '
334
  repeat 10
335
   d = '0' + s / m
336
   s = s - (s/m)*m
337
   m = m / 10
338
   if d <> '0'
339
    z = 1
340
   end if
341
   if z <> 0
342
    display d
343
   end if
344
  end repeat
345
  display 13,10
346
 }
347
 
348
; optimize the code for size
349
__regs fix 
350
 
351
macro add arg1,arg2
352
 {
353
   if (arg2 eqtype 0)
354
      if (arg2) = 1
355
	 inc arg1
356
      else
357
	 add arg1,arg2
358
      end if
359
   else
360
      add arg1,arg2
361
   end if
362
 }
363
 
364
macro sub arg1,arg2
365
 {
366
   if (arg2 eqtype 0)
367
      if (arg2) = 1
368
	 dec arg1
369
      else
370
	 sub arg1,arg2
371
      end if
372
   else
373
      sub arg1,arg2
374
   end if
375
 }
376
 
377
macro mov arg1,arg2
378
 {
379
   if (arg1 in __regs) & ((arg2 eqtype 0) | (arg2 eqtype '0'))
380
      if (arg2) = 0
381
	 xor arg1,arg1
382
      else if (arg2) = 1
383
	 xor arg1,arg1
384
	 inc arg1
385
      else if (arg2) = -1
386
	 or  arg1,-1
387
      else if (arg2) > -128 & (arg2) < 128
388
	 push arg2
389
	 pop  arg1
390
      else
391
	 mov  arg1,arg2
392
      end if
393
   else
394
      mov arg1,arg2
395
   end if
396
 }
397
 
398
 
399
macro RGB [a] {
400
 common
401
  match (r=,g=,b),a \{
402
   \dd ((r) shl 16) or ((g) shl 8) or (b)
403
  \}
404
}
405
 
406
 
407
struc POINT _t,_dx,_dy {
408
 .x _t _dx
409
 .y _t _dy
410
}
411
 
412
; structure definition helper
413
include 'struct.inc'
414
 
415
struct RECT
416
  left	 dd ?
417
  top	 dd ?
418
  right  dd ?
419
  bottom dd ?
420
ends
421
 
422
struct BOX
423
  left	 dd ?
424
  top	 dd ?
425
  width  dd ?
426
  height dd ?
427
ends
428
 
429
; structures used in MeOS
430
struct process_information
431
  cpu_usage		  dd ?	; +0
432
  window_stack_position   dw ?	; +4
433
  window_stack_value	  dw ?	; +6
434
			  dw ?	; +8
435
  process_name		  rb 12 ; +10
436
  memory_start		  dd ?	; +22
437
  used_memory		  dd ?	; +26
438
  PID			  dd ?	; +30
439
  box			  BOX	; +34
440
  slot_state		  dw ?	; +50
441
			  dw ?	; +52
442
  client_box		  BOX	; +54
443
  wnd_state               db ?  ; +70
444
  rb (1024-71)
445
ends
446
 
447
struct system_colors
448
  frame 	   dd ?
449
  grab		   dd ?
450
  grab_button	   dd ?
451
  grab_button_text dd ?
452
  grab_text	   dd ?
453
  work		   dd ?
454
  work_button	   dd ?
455
  work_button_text dd ?
456
  work_text	   dd ?
457
  work_graph	   dd ?
458
ends
459
 
460
struct FILEDATE
461
  Second db ?
462
  Minute db ?
463
  Hour	 db ?
464
	 db ?
465
  Day	 db ?
466
  Month  db ?
467
  Year	 dw ?
468
ends
469
 
470
struct FILEINFO
471
  Attributes dd ?
472
  IsUnicode  db ?
473
	     db 3 dup(?)
474
  DateCreate FILEDATE
475
  DateAccess FILEDATE
476
  DateModify FILEDATE
477
  Size	     dq ?
478
ends
479
 
480
; constants
481
 
482
; events
483
EV_IDLE        = 0
484
EV_TIMER       = 0
485
EV_REDRAW      = 1
486
EV_KEY	       = 2
487
EV_BUTTON      = 3
488
EV_EXIT        = 4
489
EV_BACKGROUND  = 5
490
EV_MOUSE       = 6
491
EV_IPC	       = 7
492
EV_STACK       = 8
493
 
494
; event mask bits for function 40
495
EVM_REDRAW     =	1b
496
EVM_KEY        =       10b
497
EVM_BUTTON     =      100b
498
EVM_EXIT       =     1000b
499
EVM_BACKGROUND =    10000b
500
EVM_MOUSE      =   100000b
501
EVM_IPC        =  1000000b
502
EVM_STACK      = 10000000b