Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;   Modified from original icon editor
  3. ;
  4. ;   Compile with FASM for Menuet
  5. ;
  6.    use32
  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
  15.  
  16. include 'lang.inc'
  17. include 'macros.inc'
  18.  
  19. window_x_size  equ    346
  20. window_y_size  equ    312
  21.  
  22. START:                          ; start of execution
  23.  
  24.     call draw_window            ; at first, draw the window
  25.     call get_screen_size        ; get screen x and y size
  26.  
  27. check_mouse:
  28.  
  29.     call draw_mouse             ; are we editing the icon
  30.     call check_colour           ; are we selecting a colour
  31.  
  32. still:
  33.  
  34.     mov  eax,23                 ; wait here for event
  35.     mov  ebx,1                  ; for 1ms
  36.     int  0x40
  37.  
  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
  44.  
  45.     jmp  check_mouse            ; start loop again
  46.  
  47.   red:                          ; redraw
  48.     call draw_window            ; draw our window
  49.     jmp  check_mouse            ; start the loop again
  50.     key:
  51.  
  52.     mov  eax,2                  ; get a key
  53.     int  0x40                   ; 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
  66. no_del_last:
  67.     call draw_filename          ; update filename
  68.     jmp  check_mouse            ; start loop again
  69. no_bksp:
  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
  75. no_enter:
  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
  81. capital:
  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
  90. no_null_state:
  91.     call draw_filename          ; update filename
  92. no_lit:
  93.     jmp  check_mouse            ; start loop again
  94.  
  95.   button:                       ; button
  96.     mov  eax,17                 ; get id
  97.     int  0x40
  98.  
  99.     cmp  ah,1                   ; button id=1 ?
  100.     jne  button_3
  101.     mov  eax,-1                 ; close this program
  102.     int  0x40
  103.   button_3:
  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
  115.   button_4:
  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
  124.   button_5:
  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
  131.   button_6:
  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.   button_7:
  138.     cmp  ah,7                   ; was it button 7 - FLIP ICON
  139.     jne  button_8               ; no then try button 8
  140.     call flip_icon              ; flip
  141.   button_8:
  142.     cmp  ah,8                   ; was it button 8 - MIRROR ICON
  143.     jne  button_9               ; no then try button 9
  144.     call flip_diag              ; flip L/R and U/D
  145.     call flip_icon              ; cheated now have to flip it
  146.   button_9:
  147.     cmp  ah,9                   ; was it button 9 - FLIP L/R and U/D
  148.     jne  button_10              ; no then try button 10
  149.     call flip_diag              ; flip L/R and U/D
  150.     call draw_icon              ; update icon
  151.     call draw_graph             ; update graph
  152.   button_10:
  153.     cmp  ah,10                  ; was it button 9 - SET AS BGR
  154.     jne  check_mouse            ; no then exit
  155.     call set_background         ; set as background
  156.  
  157.     jmp  check_mouse            ; start loop again
  158.  
  159. ;   *********************************************
  160. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  161. ;   *********************************************
  162. draw_window:
  163.  
  164.     mov  eax,12                 ; function 12:tell os about windowdraw
  165.     mov  ebx,1                  ; 1, start of draw
  166.     int  0x40
  167.                                 ; DRAW WINDOW
  168.     mov  eax,0                  ; function 0 : define and draw window
  169.     mov  ebx,100*65536+window_x_size        ; [x start] *65536 + [x size]
  170.     mov  ecx,100*65536+window_y_size        ; [y start] *65536 + [y size]
  171.     mov  edx,0x03ffffff         ; color of work area 0x00RRGGBB
  172.     mov  esi,0x807799bb         ; color of grab bar  0x00RRGGBB
  173.     mov  edi,0x007799bb         ; color of frames    0x00RRGGBB
  174.     int  0x40
  175.                                 ; WINDOW LABEL
  176.     mov  eax,4                  ; function 4 : write text to window
  177.     mov  ebx,7*65536+7          ; [x start] *65536 + [y start]
  178.     mov  ecx,0xddeeff           ; color of text 0x00RRGGBB
  179.     mov  edx,labelt             ; pointer to text beginning
  180.     mov  esi,11                 ; text length
  181.     int  0x40
  182.                                 ; DRAW BUTTON BAR
  183.     mov  eax,13                 ; function 13 : draw bar
  184.     mov  ebx,5*65536+window_x_size-9        ; [x start] *65536 + [x size]
  185.     mov  ecx,(window_y_size-20)*65536+16    ; [y start] *65536 + [y size]
  186.     mov  edx,0x7799bb           ; colour 0x00RRGGBB
  187.     int  0x40
  188.                                 ; DEFINE BUTTON 3 : FILENAME
  189.     mov  eax,8                  ; function 8 : define button
  190.     mov  ebx,5*65536+62         ; [x start] *65536 + [x size]
  191.     mov  ecx,(window_y_size-19)*65536+14     ; [y start] *65536 + [y size]
  192.     mov  edx,3                  ; button id number
  193.     mov  esi,0x7799bb           ; button color 0x00RRGGBB
  194.     int  0x40
  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.     int  0x40
  202.  
  203.     call draw_filename          ; update filename
  204.  
  205.                                 ; DEFINE BUTTON 4 : LOAD
  206.     mov  eax,8                  ; function 8 : define button
  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]
  209.     mov  edx,4                  ; button id number
  210.     mov  esi,0x7799bb           ; button color 0x00RRGGBB
  211.     int  0x40
  212.                                 ; DEFINE BUTTON 5 : SAVE
  213.     mov  ebx,(window_x_size-43)*65536+38     ; [x start] *65536 + [x size]
  214.     mov  edx,5                  ; button id number
  215.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  237.                                 ; BUTTON 4 TEXT
  238.     mov  eax,4                  ; function 4 : write text to window
  239.     mov  ebx,267*65536+window_y_size-15      ; [x start] *65536 + [y start]
  240.     mov  ecx,0xddeeff           ; text color 0x00RRGGBB
  241.     mov  edx,button_text_4      ; pointer to text beginning
  242.     mov  esi,4                  ; text length
  243.     int  0x40
  244.                                 ; BUTTON 5 TEXT
  245.     mov  ebx,311*65536+window_y_size-15      ; [x start] *65536 + [y start]
  246.     mov  edx,button_text_5      ; pointer to text beginning
  247.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  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.     int  0x40
  304.                                 ; DRAW PALETTE RED + GREEN SECTION
  305.     xor  edi,edi                ; clear column loop count
  306. next_r_g_outer:
  307.     xor  esi,esi                ; clear line loop count
  308. next_r_g_inner:
  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.     int  0x40
  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
  329.  
  330.                                 ; DRAW PALETTE GREEN + BLUE SECTION
  331.     mov  edi,0                  ; as above
  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
  346.     int  0x40
  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.  
  354.                                 ; DRAW PALETTE BLUE + RED SECTION
  355.     mov  edi,0                  ; as above
  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
  369.     int  0x40
  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.  
  377.                                 ; DRAW GREYSCALE
  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
  394.     int  0x40
  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.  
  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
  406. dont_load:
  407.     call draw_icon              ; draw icon area
  408.     call draw_graph             ; draw edit area
  409.  
  410.     mov  eax,12                 ; function 12:tell os about windowdraw
  411.     mov  ebx,2                  ; 2, end of draw
  412.     int  0x40
  413.  
  414.     ret                         ; return
  415.  
  416. ;   *********************************************
  417. ;   *******  SET BACKGROUND              ********
  418. ;   *********************************************
  419. set_background:
  420.  
  421.     mov  ecx,image+3600         ; point to our decode buffer
  422.     mov  edx,image+54+32*32*3-96    ; point to last line of bmp
  423.  
  424.     mov  edi,0                  ; zero line count
  425. decode_line:
  426.     mov  esi,0                  ; zero column count
  427. decode_column:
  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
  439.  
  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.     int  0x40                   ; do it
  445.     mov  ebx,5                  ; blockmove image to os bgr memory
  446.     mov  ecx,image+3600         ; point to image
  447.     mov  edx,0                  ; start of bgr memory
  448.     mov  esi,32*32*3            ; byte count
  449.     int  0x40                   ; do it
  450.     mov  ebx,4                  ; type of background draw
  451.     mov  ecx,1                  ; tile
  452.     int  0x40                   ; do it
  453.     mov  ebx,3                  ; draw background
  454.     int  0x40                   ; do it
  455.  
  456.     ret                         ; return
  457.  
  458. ;   *********************************************
  459. ;   *******  GET SCREEN X and Y SIZE     ********
  460. ;   *********************************************
  461. get_screen_size:
  462.  
  463.     mov  eax,14                 ; function 14 : get screen max
  464.     int  0x40                   ; 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
  473.  
  474.     ret
  475.  
  476. ;   *********************************************
  477. ;   *******  LOAD FILE                   ********
  478. ;   *********************************************
  479. load_file:
  480.  
  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.     int  0x40                   ; do it
  487.  
  488.     ret                         ; return
  489.  
  490. ;   *********************************************
  491. ;   *******  SAVE FILE                   ********
  492. ;   *********************************************
  493. save_file:
  494.  
  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.     int  0x40                   ; do it
  501.  
  502.     ret                         ; return
  503.  
  504. ;   *********************************************
  505. ;   *******  DRAW FILENAME TO SCREEN     ********
  506. ;   *********************************************
  507. draw_filename:
  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]
  512.     mov  ecx,(window_y_size-19)*65536+15     ; [y start] *65536 + [y size]
  513.     mov  edx,0x557799           ; colour 0x00RRGGBB
  514.     int  0x40
  515.  
  516.     mov  eax,4                  ; function 4 : write text to window
  517.     mov  ebx,78*65536+(window_y_size-15)     ; [y start] *65536 + [y size]
  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
  524. no_active_1:
  525.     int  0x40                   ; do it
  526.     popa                        ; return all registers to original
  527.     ret                         ; return
  528.  
  529. ;   *********************************************
  530. ;   *******  DRAW ICON FROM LOADED FILE  ********
  531. ;   *********************************************
  532. draw_icon:
  533.  
  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
  537. line:
  538.     mov  esi,0                  ; column count
  539.     mov  ebx,269+31             ; x start position
  540. pixel:
  541.     mov  edx,[eax]              ; colour 0x00RRGGBB from image data
  542.     push eax                    ; save our position
  543.     mov  eax,1                  ; function 1 : put pixel
  544.     int  0x40                   ; 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
  555.  
  556.     ret                         ; return
  557.  
  558. ;   *********************************************
  559. ;   *******  DRAW GRAPH FROM LOADED FILE  *******
  560. ;   *********************************************
  561. draw_graph:
  562.  
  563.     mov  edi,0                  ; line count
  564.     mov  eax,image+51+32*32*3   ; point to our bmp data
  565. next_lin:
  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
  572. next_bo:
  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.     int  0x40                   ; 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
  590.  
  591.     ret                         ; return
  592.  
  593. ;   *********************************************
  594. ;   *******  CLEAR GRAPH and ICON AREA   ********
  595. ;   *********************************************
  596. clear_graph_icon:
  597.  
  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
  605.  
  606.     ret                         ; return
  607.  
  608. ;   *********************************************
  609. ;   *******  FLIP ICON TOP to BOTTOM     ********
  610. ;   *********************************************
  611. flip_icon:
  612.  
  613.     mov  ecx,image+54            ; point at first line
  614.     mov  edx,image+54+32*32*3+96 ; point 1 line past end
  615.  
  616.     mov  edi,0                   ; zero line count
  617. lines:
  618.     mov  esi,0                   ; zero column count
  619.     sub  edx,192                 ; move back 2 lines
  620. columns:
  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
  635.  
  636.     ret                          ; return
  637.  
  638. ;   *********************************************
  639. ;   *******  FLIP ICON DIAGONAL          ********
  640. ;   *********************************************
  641. flip_diag:
  642.  
  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
  646.  
  647.     pusha                        ; save all registers
  648. copy_out:
  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
  657.  
  658.     mov  edx,image+3600+32*32*3-3       ; point to last bytes
  659. copy_in:
  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
  667.  
  668.     ret                          ; return
  669.  
  670. ;   *********************************************
  671. ;   *******  DRAW MOUSE ON GRAPH / ICON  ********
  672. ;   *********************************************
  673. draw_mouse:
  674.  
  675.     mov  eax,37                 ; function 37
  676.     mov  ebx,2                  ; sub function 2 : check for mouse button
  677.     int  0x40                   ; 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
  682.     mov  [draw_colour],0x000000 ; else draw with black
  683.     jmp  blank                  ; jmp over colour select
  684. colour_mouse:
  685.     mov  eax,[sel_colour]       ; get our selected colour
  686.     mov  [draw_colour],eax      ; save our selected colour
  687. blank:
  688.     mov  eax,37                 ; function 37
  689.     mov  ebx,1                  ; sub function 1 : get mouse position
  690.     int  0x40                   ; 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
  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
  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.     int  0x40                   ; 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.     int  0x40                   ; 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
  752. exit_mouse:
  753.  
  754.     ret                         ; return
  755.  
  756. ;   *********************************************
  757. ;   *******  GET COLOUR TO DRAW WITH     ********
  758. ;   *********************************************
  759. check_colour:
  760.  
  761.     mov  eax,37                 ; function 37
  762.     mov  ebx,2                  ; sub function 2 : check for mouse button
  763.     int  0x40                   ; 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.     int  0x40                   ; 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
  779.     cmp  [mx_pos],301
  780.     jg   check_rb
  781.     cmp  [my_pos],219
  782.     jl   check_rb
  783.     cmp  [my_pos],250
  784.     jg   check_rb
  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
  801.     int  0x40
  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.  
  812.     cmp  [mx_pos],270           ; check we are within x/y limits
  813.     jl   check_bg
  814.     cmp  [mx_pos],301
  815.     jg   check_bg
  816.     cmp  [my_pos],251
  817.     jle  check_bg
  818.     cmp  [my_pos],282
  819.     jg   check_bg
  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
  838.     int  0x40
  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.  
  849.     cmp  [mx_pos],301           ; check we are within x/y limits
  850.     jl   get_colour
  851.     cmp  [mx_pos],333
  852.     jg   get_colour
  853.     cmp  [my_pos],251
  854.     jl   get_colour
  855.     cmp  [my_pos],282
  856.     jg   get_colour
  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
  875.     int  0x40
  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.  
  885.     cmp  [mx_pos],309           ; check we are within x/y limits
  886.     jl   exit_draw
  887.     cmp  [mx_pos],340
  888.     jg   exit_draw
  889.     cmp  [my_pos],212
  890.     jl   exit_draw
  891.     cmp  [my_pos],243
  892.     jg   exit_draw
  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]
  900.     int  0x40
  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
  913.     int  0x40
  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
  927.     int  0x40
  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
  938.     int  0x40
  939.  
  940.     mov  [sel_colour],eax
  941.  
  942.     ret
  943.  
  944. ;   *********************************************
  945. ;   *******  DATA AREA                      *****
  946. ;   *********************************************
  947.  
  948. mx_pos            dd  0x0
  949. my_pos            dd  0x0
  950.  
  951. gx_pos            dd  0x0
  952. gy_pos            dd  0x0
  953.  
  954. icon_x            dd  0x0
  955. icon_y            dd  0x0
  956.  
  957. x_size            dd  0x0
  958. y_size            dd  0x0
  959.  
  960. sel_colour        dd  0x00ffffff
  961. draw_colour       dd  0x00ffffff
  962.  
  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'
  971.  
  972. labelt:           db  'ICON EDITOR'
  973.  
  974. icon:             db  'WRITE.BMP   '
  975.  
  976. editpos           db  0
  977. editstate         db  0
  978.  
  979. first_run         db  0
  980.  
  981. image:
  982.  
  983. I_END:
  984.