Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
31 halyavin 1
;
2
;   Modified from original icon editor
3
;
4
;   Compile with FASM for Menuet
5
;
6
   use32
485 heavyiron 7
   org	  0x0
8
   db	  'MENUET01'		  ; 8 byte id
9
   dd	  0x01			  ; header version
10
   dd	  START 		  ; start of code
11
   dd	  I_END 		  ; size of image
12
   dd	  0x100000		  ; memory for app
13
   dd	  0x7fff0		  ; esp
14
   dd	  0x0 , 0x0		  ; I_Param , I_Icon
31 halyavin 15
 
16
include 'lang.inc'
485 heavyiron 17
include '..\..\..\macros.inc'
31 halyavin 18
 
19
window_x_size  equ    346
20
window_y_size  equ    312
21
 
485 heavyiron 22
START:				; start of execution
31 halyavin 23
 
485 heavyiron 24
    call draw_window		; at first, draw the window
25
    call get_screen_size	; get screen x and y size
31 halyavin 26
 
27
check_mouse:
28
 
485 heavyiron 29
    call draw_mouse		; are we editing the icon
30
    call check_colour		; are we selecting a colour
31 halyavin 31
 
32
still:
33
 
485 heavyiron 34
    mov  eax,23 		; wait here for event
35
    mov  ebx,1			; for 1ms
36
    mcall
31 halyavin 37
 
485 heavyiron 38
    cmp  eax,1			; redraw request ?
39
    je	 red
40
    cmp  eax,2			; key in buffer ?
41
    je	 key
42
    cmp  eax,3			; button in buffer ?
43
    je	 button
31 halyavin 44
 
485 heavyiron 45
    jmp  check_mouse		; start loop again
31 halyavin 46
 
485 heavyiron 47
  red:				; redraw
48
    call draw_window		; draw our window
49
    jmp  check_mouse		; start the loop again
31 halyavin 50
    key:
51
 
485 heavyiron 52
    mov  eax,2			; get a key
53
    mcall			; do it
54
    shr  eax,8			; move it to al
55
    cmp  byte [editstate],0	; are we in edit mode
56
    je	 check_mouse		; if not start loop again
57
    cmp  al,8			; is it a backspace
58
    jne  no_bksp		; if no jump over backspace code
59
    cmp  byte [editpos],0	; is it the first character
60
    je	 no_del_last		; if yes jump over backspace code
61
    dec  byte [editpos] 	; decrement our position
62
    xor  ebx,ebx		; clear pointer
63
    mov  bl,byte [editpos]	; get our position
64
    add  ebx,icon		; add our offset
65
    mov  byte [ebx],0		; delete character
31 halyavin 66
no_del_last:
485 heavyiron 67
    call draw_filename		; update filename
68
    jmp  check_mouse		; start loop again
31 halyavin 69
no_bksp:
485 heavyiron 70
    cmp  al,13			; is it the enter key
71
    jne  no_enter		; no then jump over enter code
72
    mov  byte [editstate],0	; get out of edit mode
73
    call draw_filename		; update filename
74
    jmp check_mouse		; start loop again
31 halyavin 75
no_enter:
485 heavyiron 76
    cmp  al,31			; are we below character 31
77
    jbe  no_lit 		; then must be illegal
78
    cmp  al,97			; are we below character 97
79
    jb	 capital		; then must be ok
80
    sub  eax,32 		; else subtract 32 from it to make it legal
31 halyavin 81
capital:
485 heavyiron 82
    xor  ebx,ebx		; clear our pointer
83
    mov  bl,byte [editpos]	; get our position
84
    add  ebx,icon		; add our offset
85
    mov  byte [ebx],al		; move our character into buffer
86
    inc  byte [editpos] 	; increment our edit position
87
    cmp  byte [editpos],12	; are we at our last position
88
    jne  no_null_state		; no then jump over last position code
89
    mov  byte [editstate],0	; get out of edit mode
31 halyavin 90
no_null_state:
485 heavyiron 91
    call draw_filename		; update filename
31 halyavin 92
no_lit:
485 heavyiron 93
    jmp  check_mouse		; start loop again
31 halyavin 94
 
485 heavyiron 95
  button:			; button
96
    mov  eax,17 		; get id
97
    mcall
31 halyavin 98
 
485 heavyiron 99
    cmp  ah,1			; button id=1 ?
31 halyavin 100
    jne  button_3
485 heavyiron 101
    mov  eax,-1 		; close this program
102
    mcall
31 halyavin 103
  button_3:
485 heavyiron 104
    cmp  ah,3			; was it button 3 - FILENAME
105
    jne  button_4		; no then try button 4
106
    cld 			;
107
    mov  byte [editstate],1	; enter edit mode
108
    mov  edi,icon		; point to our buffer
109
    mov  eax,0x20202020 	; file reg with 4 spaces
110
    mov  ecx,3			; going to write it 3 times
111
    rep  stosd			; repeat giving 12 spaces
112
    mov  byte [editpos],0	; zero our edit position
113
    call draw_filename		; update filename
114
    jmp  check_mouse		; start loop again
31 halyavin 115
  button_4:
485 heavyiron 116
    cmp  ah,4			; was it button 4 - LOAD
117
    jne  button_5		; no then try button 5
118
    mov  byte [editstate],0	; dont want to be in edit mode
119
    call draw_filename		; update filename
120
    call load_file		; load the file
121
    call draw_icon		; update icon screen
122
    call draw_graph		; update edit screen
123
    jmp  check_mouse		; start loop again
31 halyavin 124
  button_5:
485 heavyiron 125
    cmp  ah,5			; was it button 5 - SAVE
126
    jne  button_6		; no then try button 6
127
    mov  byte [editstate],0	; dont want to be in edit mode
128
    call draw_filename		; update filename
129
    call save_file		; save the file
130
    jmp  check_mouse		; start loop again
31 halyavin 131
  button_6:
485 heavyiron 132
    cmp  ah,6			; was it button 6 - CLEAR ICON
133
    jne  button_7		; no then try button 7
134
    mov  byte [editstate],0	; dont want to be in edit mode
135
    call draw_filename		; update filename
136
    call clear_graph_icon      ; clear the icon and edit screens
137
    jmp  check_mouse
138
 
31 halyavin 139
  button_7:
485 heavyiron 140
    cmp  ah,7			; was it button 7 - FLIP ICON
141
    jne  button_8		; no then try button 8
142
    call flip_icon		; flip
143
    jmp  check_mouse
144
 
31 halyavin 145
  button_8:
485 heavyiron 146
    cmp  ah,8			; was it button 8 - MIRROR ICON
147
    jne  button_9		; no then try button 9
148
    call flip_diag		; flip L/R and U/D
149
    call flip_icon		; cheated now have to flip it
150
    jmp  check_mouse
151
 
31 halyavin 152
  button_9:
485 heavyiron 153
    cmp  ah,9			; was it button 9 - FLIP L/R and U/D
154
    jne  button_10		; no then try button 10
155
    call flip_diag		; flip L/R and U/D
156
    call draw_icon		; update icon
157
    call draw_graph		; update graph
158
    jmp  check_mouse
159
 
31 halyavin 160
  button_10:
485 heavyiron 161
    cmp  ah,10			; was it button 9 - SET AS BGR
162
    jne  check_mouse		; no then exit
163
    call set_background 	; set as background
31 halyavin 164
 
485 heavyiron 165
    jmp  check_mouse		; start loop again
31 halyavin 166
 
167
;   *********************************************
168
;   *******  WINDOW DEFINITIONS AND DRAW ********
169
;   *********************************************
170
draw_window:
171
 
485 heavyiron 172
    mov  eax,12 		; function 12:tell os about windowdraw
173
    mov  ebx,1			; 1, start of draw
174
    mcall
175
				; DRAW WINDOW
176
    mov  eax,0			; function 0 : define and draw window
177
    mov  ebx,100*65536+window_x_size	    ; [x start] *65536 + [x size]
178
    mov  ecx,100*65536+window_y_size	    ; [y start] *65536 + [y size]
551 spraid 179
    mov  edx,0x14ffffff 	; color of work area 0x00RRGGBB
485 heavyiron 180
    mov  edi,title 		; WINDOW LABEL
181
    mcall
182
 
183
    mov  eax,13 		; function 13 : draw bar
184
    mov  ebx,5*65536+window_x_size-9	    ; [x start] *65536 + [x size]
31 halyavin 185
    mov  ecx,(window_y_size-20)*65536+16    ; [y start] *65536 + [y size]
485 heavyiron 186
    mov  edx,0x7799bb		; colour 0x00RRGGBB
187
    mcall
188
				; DEFINE BUTTON 3 : FILENAME
189
    mov  eax,8			; function 8 : define button
190
    mov  ebx,5*65536+62 	; [x start] *65536 + [x size]
31 halyavin 191
    mov  ecx,(window_y_size-19)*65536+14     ; [y start] *65536 + [y size]
485 heavyiron 192
    mov  edx,3			; button id number
193
    mov  esi,0x7799bb		; button color 0x00RRGGBB
194
    mcall
195
				; BUTTON 3 TEXT
196
    mov  eax,4			; function 4 : write text to window
197
    mov  ebx,13*65536+window_y_size-15	     ; [x start] *65536 + [y start]
198
    mov  ecx,0xddeeff		; text color 0x00RRGGBB
199
    mov  edx,button_text_3	; pointer to text beginning
200
    mov  esi,8			; text length
201
    mcall
31 halyavin 202
 
485 heavyiron 203
    call draw_filename		; update filename
31 halyavin 204
 
485 heavyiron 205
				; DEFINE BUTTON 4 : LOAD
206
    mov  eax,8			; function 8 : define button
31 halyavin 207
    mov  ebx,(window_x_size-87)*65536+38     ; [x start] *65536 + [x size]
208
    mov  ecx,(window_y_size-19)*65536+14     ; [y start] *65536 + [y size]
485 heavyiron 209
    mov  edx,4			; button id number
210
    mov  esi,0x7799bb		; button color 0x00RRGGBB
211
    mcall
212
				; DEFINE BUTTON 5 : SAVE
31 halyavin 213
    mov  ebx,(window_x_size-43)*65536+38     ; [x start] *65536 + [x size]
485 heavyiron 214
    mov  edx,5			; button id number
215
    mcall
216
				; DEFINE BUTTON 6 : CLEAR ICON
217
    mov  ebx,268*65536+72	; [x start] *65536 + [x size]
218
    mov  ecx,65*65536+14	; [y start] *65536 + [y size]
219
    mov  edx,6			; button id number
220
    mcall
221
				; DEFINE BUTTON 7 : FLIP VERTICAL
222
    mov  ecx,85*65536+14	; [y start] *65536 + [y size]
223
    mov  edx,7			; button id number
224
    mcall
225
				; DEFINE BUTTON 8 : FLIP HORIZONTAL
226
    mov  ecx,105*65536+14	; [y start] *65536 + [y size]
227
    mov  edx,8			; button id number
228
    mcall
229
				; DEFINE BUTTON 9 : SET AS BACKGROUND
230
    mov  ecx,125*65536+14	; [y start] *65536 + [y size]
231
    mov  edx,9			; button id number
232
    mcall
233
				; DEFINE BUTTON 10 : SET AS BACKGROUND
234
    mov  ecx,145*65536+14	; [y start] *65536 + [y size]
235
    mov  edx,10 		; button id number
236
    mcall
237
				; BUTTON 4 TEXT
238
    mov  eax,4			; function 4 : write text to window
31 halyavin 239
    mov  ebx,267*65536+window_y_size-15      ; [x start] *65536 + [y start]
485 heavyiron 240
    mov  ecx,0xddeeff		; text color 0x00RRGGBB
241
    mov  edx,button_text_4	; pointer to text beginning
242
    mov  esi,4			; text length
243
    mcall
244
				; BUTTON 5 TEXT
31 halyavin 245
    mov  ebx,311*65536+window_y_size-15      ; [x start] *65536 + [y start]
485 heavyiron 246
    mov  edx,button_text_5	; pointer to text beginning
247
    mcall
248
				; BUTTON 6 TEXT
249
    mov  ebx,275*65536+69	; [x start] *65536 + [y start]
250
    mov  edx,button_text_6	; pointer to text beginning
251
    mov  esi,10 		; text length
252
    mcall
253
				; BUTTON 7 TEXT
254
    mov  ebx,275*65536+89	; [x start] *65536 + [y start]
255
    mov  edx,button_text_7	; pointer to text beginning
256
    mcall
257
				; BUTTON 8 TEXT
258
    mov  ebx,275*65536+109	; [x start] *65536 + [y start]
259
    mov  edx,button_text_8	; pointer to text beginning
260
    mcall
261
				; BUTTON 9 TEXT
262
    mov  ebx,275*65536+129	; [x start] *65536 + [y start]
263
    mov  edx,button_text_9	; pointer to text beginning
264
    mcall
265
				; BUTTON 10 TEXT
266
    mov  ebx,275*65536+149	; [x start] *65536 + [y start]
267
    mov  edx,button_text_10	; pointer to text beginning
268
    mcall
269
				; DRAW GRAPH BACKGROUND
270
    mov  eax,13 		; function 13 : draw bar
271
    mov  ebx,6*65536+257	; [x start] *65536 + [x size]
272
    mov  ecx,26*65536+257	; [y start] *65536 + [y size]
273
    mov  edx,0x7799bb		; colour 0x00RRGGBB
274
    mcall
275
				; DRAW ICON BACKGROUND
276
    mov  ebx,268*65536+34	; [x start] *65536 + [x size]
277
    mov  ecx,26*65536+34	; [y start] *65536 + [y size]
278
    mcall
279
				; DRAW PALETTE BACKGROUND
280
    mov  ebx,268*65536+34	; [x start] *65536 + [x size]
281
    mov  ecx,217*65536+33	; [y start] *65536 + [y size]
282
    mcall
283
				; DRAW PALETTE BACKGROUND
284
    mov  ebx,268*65536+33	; [x start] *65536 + [x size]
285
    mov  ecx,250*65536+33	; [y start] *65536 + [y size]
286
    mcall
287
				; DRAW PALETTE BACKGROUND
288
    mov  ebx,301*65536+33	; [x start] *65536 + [x size]
289
    mov  ecx,249*65536+34	; [y start] *65536 + [y size]
290
    mcall
291
				; DRAW GREYSCALE BACKGROUND
292
    mov  ebx,307*65536+34	; [x start] *65536 + [x size]
293
    mov  ecx,210*65536+34	; [y start] *65536 + [y size]
294
    mcall
295
				; DRAW SELECTED COLOUR BACKGROUND
296
    mov  ebx,268*65536+73	; [x start] *65536 + [x size]
297
    mov  ecx,171*65536+34	; [y start] *65536 + [y size]
298
    mcall
299
				; DRAW WHITE TO START
300
    mov  ebx,269*65536+71	; [x start] *65536 + [x size]
301
    mov  ecx,172*65536+32	; [y start] *65536 + [y size]
302
    mov  edx,0xffffff		; colour 0x00RRGGBB
303
    mcall
304
				; DRAW PALETTE RED + GREEN SECTION
305
    xor  edi,edi		; clear column loop count
31 halyavin 306
next_r_g_outer:
485 heavyiron 307
    xor  esi,esi		; clear line loop count
31 halyavin 308
next_r_g_inner:
485 heavyiron 309
    mov  eax,1			; function 1 : putpixel
310
    mov  ebx,edi		; get column count
311
    shr  ebx,3			; divide by 8
312
    add  ebx,269		; add our x offset
313
    mov  ecx,esi		; get our line count
314
    shr  ecx,3			; divide by 8
315
    add  ecx,218		; add our y offset
316
    mov  edx,255		; maximum red
317
    sub  edx,edi		; minus column count
318
    shl  edx,8			; into position 0x0000RR00
319
    add  edx,255		; maximum green
320
    sub  edx,esi		; minus line count
321
    shl  edx,8			; into position 0x00RRGG00
322
    mcall
323
    add  esi,5			; colour in steps of 5 to keep small
324
    cmp  esi,255		; have we done a line
325
    jne  next_r_g_inner 	; nop then do next pixel
326
    add  edi,5			; colour in steps of 5 to keep small
327
    cmp  edi,255		; have we done all columns
328
    jne  next_r_g_outer 	; no then start the next one
31 halyavin 329
 
485 heavyiron 330
				; DRAW PALETTE GREEN + BLUE SECTION
331
    mov  edi,0			; as above
31 halyavin 332
next_g_b_outer:
333
    mov  esi,0
334
next_g_b_inner:
335
    mov  eax,1
336
    mov  ebx,edi
337
    shr  ebx,3
338
    add  ebx,269
339
    mov  ecx,esi
340
    shr  ecx,3
341
    add  ecx,250
342
    mov  edx,255
343
    sub  edx,edi
344
    shl  edx,16
345
    add  edx,esi
485 heavyiron 346
    mcall
31 halyavin 347
    add  esi,5
348
    cmp  esi,255
349
    jne  next_g_b_inner
350
    add  edi,5
351
    cmp  edi,255
352
    jne  next_g_b_outer
353
 
485 heavyiron 354
				; DRAW PALETTE BLUE + RED SECTION
355
    mov  edi,0			; as above
31 halyavin 356
next_b_r_outer:
357
    mov  esi,0
358
next_b_r_inner:
359
    mov  eax,1
360
    mov  ebx,edi
361
    shr  ebx,3
362
    add  ebx,301
363
    mov  ecx,esi
364
    shr  ecx,3
365
    add  ecx,250
366
    mov  edx,edi
367
    shl  edx,8
368
    add  edx,esi
485 heavyiron 369
    mcall
31 halyavin 370
    add  esi,5
371
    cmp  esi,255
372
    jne  next_b_r_inner
373
    add  edi,5
374
    cmp  edi,255
375
    jne  next_b_r_outer
376
 
485 heavyiron 377
				; DRAW GREYSCALE
31 halyavin 378
    mov  edi,0
379
next_b_w_outer:
380
    mov  esi,0
381
next_b_w_inner:
382
    mov  eax,1
383
    mov  ebx,edi
384
    shr  ebx,3
385
    add  ebx,308
386
    mov  ecx,esi
387
    shr  ecx,3
388
    add  ecx,211
389
    mov  edx,esi
390
    shl  edx,8
391
    add  edx,esi
392
    shl  edx,8
393
    add  edx,esi
485 heavyiron 394
    mcall
31 halyavin 395
    add  esi,5
396
    cmp  esi,255
397
    jne  next_b_w_inner
398
    add  edi,5
399
    cmp  edi,255
400
    jne  next_b_w_outer
401
 
485 heavyiron 402
    cmp  [first_run],0		; is it the first window draw
403
    jne  dont_load		; no then dont reload the file
404
    call load_file		; load initial file
405
    mov  [first_run],1		; first window draw done
31 halyavin 406
dont_load:
485 heavyiron 407
    call draw_icon		; draw icon area
408
    call draw_graph		; draw edit area
31 halyavin 409
 
485 heavyiron 410
    mov  eax,12 		; function 12:tell os about windowdraw
411
    mov  ebx,2			; 2, end of draw
412
    mcall
31 halyavin 413
 
485 heavyiron 414
    ret 			; return
31 halyavin 415
 
416
;   *********************************************
417
;   *******  SET BACKGROUND              ********
418
;   *********************************************
419
set_background:
420
 
485 heavyiron 421
    mov  ecx,image+3600 	; point to our decode buffer
31 halyavin 422
    mov  edx,image+54+32*32*3-96    ; point to last line of bmp
423
 
485 heavyiron 424
    mov  edi,0			; zero line count
31 halyavin 425
decode_line:
485 heavyiron 426
    mov  esi,0			; zero column count
31 halyavin 427
decode_column:
485 heavyiron 428
    mov  ebx,[edx]		; get our data
429
    mov  [ecx],ebx		; store our data
430
    add  ecx,4			; add 4 bytes to pointer as using double word
431
    add  edx,4			; add 4 bytes to pointer
432
    inc  esi			; increment column count
433
    cmp  esi,24 		; have we done all columns
434
    jne  decode_column		; no then do some more
435
    sub  edx,192		; move back 2 lines of bmp data
436
    inc  edi			; increment line count
437
    cmp  edi,33 		; have we done all lines
438
    jne  decode_line		; no then do another one
31 halyavin 439
 
485 heavyiron 440
    mov  eax,15 		; background
441
    mov  ebx,1			; set background size
442
    mov  ecx,32 		; x size
443
    mov  edx,32 		; y size
444
    mcall			; do it
445
    mov  ebx,4			; type of background draw
446
    mov  ecx,1			; tile
447
    mcall			; do it
448
    mov  ebx,5			; blockmove image to os bgr memory
449
    mov  ecx,image+3600 	; point to image
450
    mov  edx,0			; start of bgr memory
451
    mov  esi,32*32*3		; byte count
452
    mcall			; do it
453
    mov  ebx,3			; draw background
454
    mcall			; do it
31 halyavin 455
 
485 heavyiron 456
    ret 			; return
31 halyavin 457
 
458
;   *********************************************
459
;   *******  GET SCREEN X and Y SIZE     ********
460
;   *********************************************
461
get_screen_size:
462
 
485 heavyiron 463
    mov  eax,14 		; function 14 : get screen max
464
    mcall			; returns eax : 0xXXXXYYYY
465
    push eax			; save reg
466
    and  eax,0x0000ffff 	; split out y size
467
    add  eax,1			; add 1 to remove zero base
468
    mov  [y_size],eax		; store for later
469
    pop  eax			; restore reg
470
    shr  eax,16 		; move x size down the reg
471
    add  eax,1			; add 1 to remove zero base
472
    mov  [x_size],eax		; store for later
31 halyavin 473
 
474
    ret
475
 
476
;   *********************************************
477
;   *******  LOAD FILE                   ********
478
;   *********************************************
479
load_file:
480
 
485 heavyiron 481
    mov  eax,6			; function 6 : load file
482
    mov  ebx,icon		; point to the name
483
    mov  ecx,0			; reserved
484
    mov  edx,200000		; reserved
485
    mov  esi,image		; point to image buffer
486
    mcall			; do it
31 halyavin 487
 
485 heavyiron 488
    ret 			; return
31 halyavin 489
 
490
;   *********************************************
491
;   *******  SAVE FILE                   ********
492
;   *********************************************
493
save_file:
494
 
485 heavyiron 495
    mov  eax,33 		; function 33 : save file
496
    mov  ebx,icon		; point to name
497
    mov  ecx,image		; point to our data
498
    mov  edx,54+32*32*3 	; how much data to transfer
499
    xor  esi,esi		; 0 - create a new file
500
    mcall			; do it
31 halyavin 501
 
485 heavyiron 502
    ret 			; return
31 halyavin 503
 
504
;   *********************************************
505
;   *******  DRAW FILENAME TO SCREEN     ********
506
;   *********************************************
507
draw_filename:
485 heavyiron 508
				; DRAW COLOUR BACKGROUND
509
    pusha			; save all registers on stack
510
    mov  eax,13 		; function 13 : draw bar
511
    mov  ebx,73*65536+81	; [x start] *65536 + [x size]
31 halyavin 512
    mov  ecx,(window_y_size-19)*65536+15     ; [y start] *65536 + [y size]
485 heavyiron 513
    mov  edx,0x557799		; colour 0x00RRGGBB
514
    mcall
31 halyavin 515
 
485 heavyiron 516
    mov  eax,4			; function 4 : write text to window
31 halyavin 517
    mov  ebx,78*65536+(window_y_size-15)     ; [y start] *65536 + [y size]
485 heavyiron 518
    xor  ecx,ecx		; colour 0x00RRGGBB = black
519
    mov  edx,icon		; point to text
520
    mov  esi,12 		; number of characters to write
521
    cmp  byte [editstate],1	; are we in edit mode
522
    jne  no_active_1		; no then jump over change colour
523
    mov  ecx,0x00112299 	; else change colour
31 halyavin 524
no_active_1:
485 heavyiron 525
    mcall			; do it
526
    popa			; return all registers to original
527
    ret 			; return
31 halyavin 528
 
529
;   *********************************************
530
;   *******  DRAW ICON FROM LOADED FILE  ********
531
;   *********************************************
532
draw_icon:
533
 
485 heavyiron 534
    mov  ecx,27 		; y start position
535
    mov  eax,image+51+32*32*3	; point to our bmp data
536
    mov  edi,0			; line count
31 halyavin 537
line:
485 heavyiron 538
    mov  esi,0			; column count
539
    mov  ebx,269+31		; x start position
31 halyavin 540
pixel:
485 heavyiron 541
    mov  edx,[eax]		; colour 0x00RRGGBB from image data
542
    push eax			; save our position
543
    mov  eax,1			; function 1 : put pixel
544
    mcall			; do it
545
    pop  eax			; restore our position
546
    sub  eax,3			; point to next pixel colour
547
    dec  ebx			; move our x position
548
    inc  esi			; increment our column count
549
    cmp  esi,32 		; have we done all columns
550
    jne  pixel			; no then do next pixel
551
    inc  ecx			; move our y position
552
    inc  edi			; increment line count
553
    cmp  edi,32 		; have we done all lines
554
    jne  line			; no then do next line
31 halyavin 555
 
485 heavyiron 556
    ret 			; return
31 halyavin 557
 
558
;   *********************************************
559
;   *******  DRAW GRAPH FROM LOADED FILE  *******
560
;   *********************************************
561
draw_graph:
562
 
485 heavyiron 563
    mov  edi,0			; line count
564
    mov  eax,image+51+32*32*3	; point to our bmp data
31 halyavin 565
next_lin:
485 heavyiron 566
    mov  ecx,edi		; use our line count for position
567
    shl  ecx,3			; multiply by eight
568
    add  ecx,27 		; add y start position
569
    shl  ecx,16 		; move into top eight bytes [y start]
570
    add  ecx,7			; add box height [y size]
571
    mov  esi,32 		; column count
31 halyavin 572
next_bo:
485 heavyiron 573
    mov  ebx,esi		; use our column count for position
574
    shl  ebx,3			; multiply by eight
575
    add  ebx,-1 		; add a correction
576
    shl  ebx,16 		; and move into top eight bytes [x start]
577
    add  ebx,7			; add box width [x size]
578
    mov  edx,[eax]		; point to bmp data
579
    push eax			; save our position
580
    mov  eax,13 		; function 13 : draw bar
581
    mcall			; do it
582
    pop  eax			; restore our position
583
    sub  eax,3			; point to next pixel colour
584
    dec  esi			; increment column count
585
    cmp  esi,0			; have we done all columns
586
    jne  next_bo		; no then do the next column
587
    inc  edi			; increment line count
588
    cmp  edi,32 		; have we done all lines
589
    jne  next_lin		; no then do the next line
31 halyavin 590
 
485 heavyiron 591
    ret 			; return
31 halyavin 592
 
593
;   *********************************************
594
;   *******  CLEAR GRAPH and ICON AREA   ********
595
;   *********************************************
596
clear_graph_icon:
597
 
485 heavyiron 598
				; CLEAR IMAGE DATA
599
    mov  edi,image+54		; point to our data
600
    mov  eax,0x00000000 	; data to write
601
    mov  ecx,(32*32*3)/4	; how much data
602
    rep  stosd			; repeat until all data transfered
603
    call draw_icon		; draw a blank icon
604
    call draw_graph		; draw a blank graph
31 halyavin 605
 
485 heavyiron 606
    ret 			; return
31 halyavin 607
 
608
;   *********************************************
609
;   *******  FLIP ICON TOP to BOTTOM     ********
610
;   *********************************************
611
flip_icon:
612
 
485 heavyiron 613
    mov  ecx,image+54		 ; point at first line
31 halyavin 614
    mov  edx,image+54+32*32*3+96 ; point 1 line past end
615
 
485 heavyiron 616
    mov  edi,0			 ; zero line count
31 halyavin 617
lines:
485 heavyiron 618
    mov  esi,0			 ; zero column count
619
    sub  edx,192		 ; move back 2 lines
31 halyavin 620
columns:
485 heavyiron 621
    mov  eax,[ecx]		 ; get bytes
622
    mov  ebx,[edx]		 ; get bytes
623
    mov  [ecx],ebx		 ; swap bytes
624
    mov  [edx],eax		 ; swap bytes
625
    add  ecx,4			 ; move pointer
626
    add  edx,4			 ; move pointer
627
    inc  esi			 ; increment column count
628
    cmp  esi,24 		 ; have we done all columns
629
    jne  columns		 ; no then do next column
630
    inc  edi			 ; increment line count
631
    cmp  edi,16 		 ; have we done all lines
632
    jne  lines			 ; no then do next line
633
    call draw_icon		 ; update icon
634
    call draw_graph		 ; update graph
31 halyavin 635
 
485 heavyiron 636
    ret 			 ; return
31 halyavin 637
 
638
;   *********************************************
639
;   *******  FLIP ICON DIAGONAL          ********
640
;   *********************************************
641
flip_diag:
642
 
485 heavyiron 643
    mov  ecx,image+54		 ; point line 1 first bytes
644
    mov  edx,image+3600 	 ; point to  buffer
645
    xor  esi,esi		 ; zero byte count
31 halyavin 646
 
485 heavyiron 647
    pusha			 ; save all registers
31 halyavin 648
copy_out:
485 heavyiron 649
    mov  eax,[ecx]		 ; get bytes
650
    mov  [edx],eax		 ; copy bytes
651
    add  ecx,4			 ; move pointer
652
    add  edx,4			 ; move pointer
653
    inc  esi			 ; increment byte count
654
    cmp  esi,24*32		 ; have we done all bytes
655
    jne  copy_out		 ; no then do the next
656
    popa			 ; restore all registers
31 halyavin 657
 
485 heavyiron 658
    mov  edx,image+3600+32*32*3-3	; point to last bytes
31 halyavin 659
copy_in:
485 heavyiron 660
    mov  eax,[edx]		 ; get bytes
661
    mov  [ecx],eax		 ; copy to image first bytes
662
    add  ecx,3			 ; move pointer 3 bytes
663
    sub  edx,3			 ; move pointer 3 bytes
664
    inc  esi			 ; increment byte count
665
    cmp  esi,32*32		 ; have we done all bytes
666
    jne  copy_in		 ; no then do next
31 halyavin 667
 
485 heavyiron 668
    ret 			 ; return
31 halyavin 669
 
670
;   *********************************************
671
;   *******  DRAW MOUSE ON GRAPH / ICON  ********
672
;   *********************************************
673
draw_mouse:
674
 
485 heavyiron 675
    mov  eax,37 		; function 37
676
    mov  ebx,2			; sub function 2 : check for mouse button
677
    mcall			; do it
678
    cmp  eax,0			; was a button pressed
679
    je	 exit_mouse		; no then jump to exit
680
    cmp  eax,1			; left hand button
681
    je	 colour_mouse		; we are using selected colour
31 halyavin 682
    mov  [draw_colour],0x000000 ; else draw with black
485 heavyiron 683
    jmp  blank			; jmp over colour select
31 halyavin 684
colour_mouse:
485 heavyiron 685
    mov  eax,[sel_colour]	; get our selected colour
686
    mov  [draw_colour],eax	; save our selected colour
31 halyavin 687
blank:
485 heavyiron 688
    mov  eax,37 		; function 37
689
    mov  ebx,1			; sub function 1 : get mouse position
690
    mcall			; do it
691
    push eax			; save our x/y position for later
692
    and  eax,0x0000ffff 	; y is in lower bytes
693
    add  eax,1			; add 1 because we are zero based
694
    mov  [my_pos],eax		; save y position
695
    pop  eax			; restore our x/y position
696
    shr  eax,16 		; shift x into lower bytes
697
    add  eax,1			; add 1 because we are zero based
698
    mov  [mx_pos],eax		; save x position
699
    cmp  [mx_pos],7		; check we are within x/y limits
31 halyavin 700
    jle   exit_mouse
701
    cmp  [mx_pos],263
702
    jge   exit_mouse
703
    cmp  [my_pos],27
704
    jle   exit_mouse
705
    cmp  [my_pos],283
706
    jge   exit_mouse
485 heavyiron 707
    mov  eax,[mx_pos]		; calculate nearest square and save
708
    sub  eax,7			; subtract 7 graph zero offset
709
    shr  eax,3			; divide by 8 (box size) loose remainder
710
    mov  [icon_x],eax		; save for use later in icon
711
    shl  eax,3			; multiply by 8 to get box position
712
    add  eax,7			; add 7 graph zero offset
713
    mov  [gx_pos],eax		; save graph x position
714
    mov  eax,[my_pos]		; repeat for y
715
    sub  eax,27 		;
716
    shr  eax,3			;
717
    mov  [icon_y],eax		;
718
    shl  eax,3			;
719
    add  eax,27 		;
720
    mov  [gy_pos],eax		;
721
    mov  eax,13 		; function 13 : draw bar
722
    mov  ebx,[gx_pos]		; load graph x position
723
    shl  ebx,16 		; shift into high bytes
724
    add  ebx,7			; add box size
725
    mov  ecx,[gy_pos]		; repeat for y
726
    shl  ecx,16 		;
727
    add  ecx,7			;
728
    mov  edx,[draw_colour]	; give it a colour
729
    mcall			; do it
730
    mov  eax,1			; function 1 : put pixel
731
    mov  ebx,[icon_x]		; icon x from above
732
    add  ebx,269		; add icon x offset
733
    mov  ecx,[icon_y]		; icon y from above
734
    add  ecx,27 		; add icon y offset
735
    mov  edx,[draw_colour]	; give it a colour
736
    mcall			; do it
737
    mov  ecx,image+54		; point to our data
738
    mov  ebx,31 		; 32 lines in image zero based
739
    sub  ebx,[icon_y]		; get the correct line
740
    mov  eax,96 		; 96 or 3 bytes per colour * 32 columns
741
    mul  ebx			; multiply by 96 result in eax
742
    add  ecx,eax		; add to our position
743
    mov  ebx,[icon_x]		; get the correct column
744
    mov  eax,3			; 3 bytes per colour
745
    mul  ebx			; multiply by 3 result in eax
746
    add  ecx,eax		; add to our position
747
    mov  ebx,[draw_colour]	; get our colour
748
    mov  [ecx],bl	      ; move blue into image data
749
    mov  [ecx+1],bh		; move green into image data
750
    shr  ebx,16 		; shift red down
751
    mov  [ecx+2],bl		  ; move red into image data
31 halyavin 752
exit_mouse:
753
 
485 heavyiron 754
    ret 			; return
31 halyavin 755
 
756
;   *********************************************
757
;   *******  GET COLOUR TO DRAW WITH     ********
758
;   *********************************************
759
check_colour:
760
 
485 heavyiron 761
    mov  eax,37 		; function 37
762
    mov  ebx,2			; sub function 2 : check for mouse button
763
    mcall			; do it
764
    cmp  eax,0			; was a button pressed
765
    je	 exit_draw		; no then jump to exit
766
    mov  eax,37 		; function 37
767
    mov  ebx,1			; sub function 1 : get mouse position
768
    mcall			; do it
769
    push eax			; save our x/y position for later
770
    and  eax,0x0000ffff 	; y is in lower bytes
771
    add  eax,1			; add 1 because we are zero based
772
    mov  [my_pos],eax		; save y position
773
    pop  eax			; restore our x/y position
774
    shr  eax,16 		; shift x into lower bytes
775
    add  eax,1			; add 1 because we are zero based
776
    mov  [mx_pos],eax		; save x position
777
    cmp  [mx_pos],270		; check we are within x/y limits
778
    jl	 check_rb
31 halyavin 779
    cmp  [mx_pos],301
485 heavyiron 780
    jg	 check_rb
31 halyavin 781
    cmp  [my_pos],219
485 heavyiron 782
    jl	 check_rb
31 halyavin 783
    cmp  [my_pos],250
485 heavyiron 784
    jg	 check_rb
31 halyavin 785
 
786
    call decode_mouse
787
 
788
    mov  edi,0
789
next_sel_rg_outer:
790
    mov  esi,0
791
next_sel_rg_inner:
792
    mov  eax,1
793
    mov  ebx,edi
794
    shr  ebx,3
795
    add  ebx,308
796
    mov  ecx,esi
797
    shr  ecx,3
798
    add  ecx,211
799
    mov  edx,[sel_colour]
800
    add  edx,esi
485 heavyiron 801
    mcall
31 halyavin 802
    add  esi,5
803
    cmp  esi,255
804
    jne  next_sel_rg_inner
805
    add  edi,5
806
    cmp  edi,255
807
    jne  next_sel_rg_outer
808
 
809
 
810
check_rb:
811
 
485 heavyiron 812
    cmp  [mx_pos],270		; check we are within x/y limits
813
    jl	 check_bg
31 halyavin 814
    cmp  [mx_pos],301
485 heavyiron 815
    jg	 check_bg
31 halyavin 816
    cmp  [my_pos],251
817
    jle  check_bg
818
    cmp  [my_pos],282
485 heavyiron 819
    jg	 check_bg
31 halyavin 820
 
821
    call decode_mouse
822
 
823
    mov  edi,0
824
next_sel_rb_outer:
825
    mov  esi,0
826
next_sel_rb_inner:
827
    mov  ebx,edi
828
    shr  ebx,3
829
    add  ebx,308
830
    mov  ecx,esi
831
    shr  ecx,3
832
    add  ecx,211
833
    mov  edx,[sel_colour]
834
    mov  eax,esi
835
    shl  eax,8
836
    add  edx,eax
837
    mov  eax,1
485 heavyiron 838
    mcall
31 halyavin 839
    add  esi,5
840
    cmp  esi,255
841
    jne  next_sel_rb_inner
842
    add  edi,5
843
    cmp  edi,255
844
    jne  next_sel_rb_outer
845
 
846
 
847
check_bg:
848
 
485 heavyiron 849
    cmp  [mx_pos],301		; check we are within x/y limits
850
    jl	 get_colour
31 halyavin 851
    cmp  [mx_pos],333
485 heavyiron 852
    jg	 get_colour
31 halyavin 853
    cmp  [my_pos],251
485 heavyiron 854
    jl	 get_colour
31 halyavin 855
    cmp  [my_pos],282
485 heavyiron 856
    jg	 get_colour
31 halyavin 857
 
858
    call decode_mouse
859
 
860
    mov  edi,0
861
next_sel_bg_outer:
862
    mov  esi,0
863
next_sel_bg_inner:
864
    mov  ebx,edi
865
    shr  ebx,3
866
    add  ebx,308
867
    mov  ecx,esi
868
    shr  ecx,3
869
    add  ecx,211
870
    mov  edx,[sel_colour]
871
    mov  eax,esi
872
    shl  eax,16
873
    add  edx,eax
874
    mov  eax,1
485 heavyiron 875
    mcall
31 halyavin 876
    add  esi,5
877
    cmp  esi,255
878
    jne  next_sel_bg_inner
879
    add  edi,5
880
    cmp  edi,255
881
    jne  next_sel_bg_outer
882
 
883
get_colour:
884
 
485 heavyiron 885
    cmp  [mx_pos],309		; check we are within x/y limits
886
    jl	 exit_draw
31 halyavin 887
    cmp  [mx_pos],340
485 heavyiron 888
    jg	 exit_draw
31 halyavin 889
    cmp  [my_pos],212
485 heavyiron 890
    jl	 exit_draw
31 halyavin 891
    cmp  [my_pos],243
485 heavyiron 892
    jg	 exit_draw
31 halyavin 893
 
894
    call decode_mouse
895
 
896
    mov  eax,13
897
    mov  ebx,269*65536+71
898
    mov  ecx,172*65536+32
899
    mov  edx,[sel_colour]
485 heavyiron 900
    mcall
31 halyavin 901
 
902
    mov  eax,[sel_colour]
903
    mov  [draw_colour],eax
904
 
905
    mov  eax,47
906
    xor  ebx,ebx
907
    mov  ebx,6
908
    shl  ebx,16
909
    mov  bh,1
910
    mov  ecx,[sel_colour]
911
    mov  edx,273*65536+176
912
    mov  esi,0x000000
485 heavyiron 913
    mcall
31 halyavin 914
 
915
exit_draw:
916
 
917
    ret
918
 
919
;   *********************************************
920
;   *******  DECODE MOUSE POSITION GET PIX  *****
921
;   *********************************************
922
 
923
decode_mouse:
924
 
925
    mov  eax,37
926
    xor  ebx,ebx
485 heavyiron 927
    mcall
31 halyavin 928
    mov  ebx,eax
929
    mov  ecx,eax
930
    and  ebx,0xffff0000
931
    shr  ebx,16
932
    and  ecx,0x0000ffff
933
    mov  eax,[x_size]
934
    imul ecx,eax
935
    add  ebx,ecx
936
    mov  eax,35
937
    dec  ebx
485 heavyiron 938
    mcall
31 halyavin 939
 
940
    mov  [sel_colour],eax
941
 
942
    ret
943
 
944
;   *********************************************
945
;   *******  DATA AREA                      *****
946
;   *********************************************
947
 
485 heavyiron 948
mx_pos		  dd  0x0
949
my_pos		  dd  0x0
31 halyavin 950
 
485 heavyiron 951
gx_pos		  dd  0x0
952
gy_pos		  dd  0x0
31 halyavin 953
 
485 heavyiron 954
icon_x		  dd  0x0
955
icon_y		  dd  0x0
31 halyavin 956
 
485 heavyiron 957
x_size		  dd  0x0
958
y_size		  dd  0x0
31 halyavin 959
 
485 heavyiron 960
sel_colour	  dd  0x00ffffff
961
draw_colour	  dd  0x00ffffff
31 halyavin 962
 
485 heavyiron 963
button_text_3	  db  'FILENAME'
964
button_text_4	  db  'LOAD'
965
button_text_5	  db  'SAVE'
966
button_text_6	  db  'CLEAR ICON'
967
button_text_7	  db  'FLIP VERT '
968
button_text_8	  db  'FLIP HORIZ'
969
button_text_9	  db  'FLIP DIAG '
970
button_text_10	  db  'SET AS BGR'
31 halyavin 971
 
485 heavyiron 972
title   	  db  'ICON EDITOR',0
31 halyavin 973
 
485 heavyiron 974
icon:		  db  'WRITE.BMP   '
31 halyavin 975
 
485 heavyiron 976
editpos 	  db  0
977
editstate	  db  0
31 halyavin 978
 
485 heavyiron 979
first_run	  db  0
31 halyavin 980
 
981
image:
982
 
983
I_END: