Subversion Repositories Kolibri OS

Rev

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

  1. ;  COLORREF.ASM - COLOR REFERENCE
  2. ;
  3. ;  Compile with FASM for Menuet
  4. ;
  5.  
  6. use32
  7.          org  0x0
  8.  
  9.          db  'MENUET01'            ; 8 byte id
  10.          dd   0x01                 ; header version
  11.          dd   start                ; start of code
  12.          dd   finis                ; size of image
  13.          dd   0x1000               ; memory for app
  14.          dd   0x1000               ; esp
  15.          dd   0x0,0x0              ; I_Param , I_Icon
  16.  
  17. include 'lang.inc'
  18. wide:    dd   0                    ; screen pixels width
  19. mouse:   dd   0                    ; 1=right,2=left [mouse click]
  20.  
  21.  
  22. start:
  23.  
  24.     mov  eax,14                    ; get screen size
  25.     int  0x40
  26.     shr  eax,16                    ; get width into AX
  27.     inc  eax                       ; not 0 based
  28.     mov  [wide],eax
  29.  
  30.     call draw_window
  31.  
  32. still:
  33.     mov  eax,23                    ; wait for event w/timeout
  34.     mov  ebx,5                     ; delay in hundredths
  35.     int  0x40
  36.  
  37.     cmp  eax,1                     ; redraw request ?
  38.     jne  s1
  39.     jmp  red
  40. s1: cmp  eax,2                     ; key in buffer ?
  41.     jne  s2
  42.     jmp  key
  43. s2: cmp  eax,3                     ; button in buffer ?
  44.     jne  s3
  45.     jmp   button
  46. s3: mov  eax,9                     ; process info function
  47.     mov  ebx,stat_table            ; return data table
  48.     mov  ecx,-1                    ; who am i
  49.     int  0x40
  50.     cmp  ax,[stat_table+4]         ; are we active?
  51.     je   active                    ; yep
  52.     jmp  still
  53.  
  54.   active:
  55.     mov  eax,37                    ; mouse info function
  56.     mov  ebx,2                     ; get buttons
  57.     int  0x40
  58.     cmp  eax,0                     ; mouse click?
  59.     jne  click
  60.     jmp  still
  61.   click:
  62.     mov  [mouse],eax               ; save mouse click
  63.     mov  eax,37                    ; mouse info
  64.     xor  ebx,ebx                   ; get screen pos for mouse
  65.     int  0x40                      ; into EAX
  66.     xor  ebx,ebx
  67.     mov  bx,ax                     ; BX=y screen position
  68.     shr  eax,16                    ; AX=x screen position
  69.     xchg eax,ebx                   ; EAX=y, EBX=x
  70.     dec  eax                       ; don't calc mouse scanline
  71.     mov  ecx,[wide]                ; get pixels wide
  72.     mul  ecx
  73.     add  ebx,eax                   ; add x
  74.     mov  eax,35                    ; get mouse pos pixel
  75.     int  0x40                      ; EAX=mouse pixel color
  76.     mov  ebx,eax                   ; EBX has color
  77.     mov  esi,colors                ; color table
  78.     mov  ecx,72                    ; total colors
  79.     xor  edx,edx                   ; init a counter
  80.   check:
  81.     lodsd
  82.     inc  edx                       ; update counter
  83.     cmp  ebx,eax                   ; color match?
  84.     je   _match                     ; yep
  85.     loop check                     ; check all colors
  86.     jmp still                      ; no match
  87.   _match:
  88.     cmp  [mouse],dword 1           ; right click?
  89.     je   right                     ; yep
  90.   left:
  91.     cmp  [picks],edx               ; changed left color yet?
  92.     jne  l1                        ; no, do it
  93.     jmp  still
  94. l1: mov  [picks],edx               ; update left pick color
  95.     call clear                     ; erase old text
  96.     call draw_picks                ; redraw colors and text
  97.     jmp  still
  98.   right:
  99.     cmp  [picks+4],edx             ; changed right color yet?
  100.     jne  r1                        ; no, do it
  101.     jmp  still
  102. r1: mov  [picks+4],edx             ; update right pick color
  103.     call clear                     ; erase old text
  104.     call draw_picks                ; redraw colors and text
  105.     jmp  still
  106.  
  107.   red:                             ; redraw
  108.     call draw_window
  109.     jmp  still
  110.  
  111.   key:                             ; key
  112.     mov  eax,2                     ; just read it and ignore
  113.     int  0x40
  114.     cmp  al,0                      ; key in buffer?
  115.     je   k1                        ; yep
  116.     jmp  still
  117. k1: cmp  ah,'H'                    ; cap H ?
  118.     je   k2                        ; yep
  119.     cmp  ah,'h'                    ; locase h ?
  120.     je   k2                        ; yep
  121.     jmp  still
  122. k2: call help                      ; show help screen
  123.     jmp  still
  124.  
  125.   button:                          ; button
  126.     mov  eax,17                    ; get id
  127.     int  0x40
  128.     cmp  ah,1                      ; button id=1 ?
  129.     je   close
  130.     jmp  still
  131.  
  132.   close:
  133.     mov  eax,-1                    ; close this program
  134.     int  0x40
  135.  
  136.  
  137. ;   *********************************************
  138. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  139. ;   *********************************************
  140.  
  141.  
  142. draw_window:
  143.  
  144.     mov  eax,12                    ; tell os about windowdraw
  145.     mov  ebx,1                     ; 1, start of draw
  146.     int  0x40
  147.  
  148.     mov  eax,0                     ; DRAW WINDOW
  149.     mov  ebx,1*65536+200           ; [x start] *65536 + [x size]
  150.     mov  ecx,200*65536+240         ; [y start] *65536 + [y size]
  151.     mov  edx,0x03000000            ; work area color (type II)
  152.     mov  esi,0x82a0a0a0            ; grab bar color (w/glide)
  153.     mov  edi,0x82bbbbbb            ; frame color
  154.     int  0x40
  155.     mov  eax,4                     ; WINDOW LABEL
  156.     mov  ebx,8*65536+8             ; [x start] *65536 + [y start]
  157.     mov  ecx,0xeeeeee              ; color of text (white)
  158.     mov  edx,prog_name             ; pointer to header
  159.     mov  esi,namelen-prog_name     ; text length
  160.     int  0x40
  161.    
  162.     call palette                   ; display color palette
  163.  
  164.     mov  eax,12                    ; tell os about windowdraw
  165.     mov  ebx,2                     ; 2, end of draw
  166.     int  0x40
  167.  
  168.     ret
  169.  
  170.  
  171. ;   *********************************************
  172. ;   *******  COLOR PALETTE LAYOUT ROUTINES ******
  173. ;   *********************************************
  174.  
  175.  
  176. palette:
  177.     mov  ebx,15*65536+18           ; LAYOUT: start x and width
  178.     mov  edx,32*65536+18           ; LAYOUT: start y and depth
  179.     mov  ecx,8                     ; 8 rows
  180.     mov  ebp,colors                ; color table
  181. p1: push ecx
  182.     mov  ecx,9                     ; 9 columns
  183. p2: push ecx
  184.     push edx
  185.     mov  ecx,edx                   ; y coord
  186.     mov  edx,[ebp]                 ; color
  187.     mov  eax,13                    ; draw bar function
  188.     int  0x40
  189.     pop  edx
  190.     pop  ecx
  191.     add  ebx,19*65536              ; next column
  192.     add  ebp,4                     ; next color
  193. p3: loop p2
  194.     pop  ecx
  195.     mov  ebx,15*65536+18           ; restart x
  196.     add  edx,19*65536              ; next row
  197.     loop p1
  198.     call draw_picks
  199.  
  200.     ret
  201.  
  202. draw_picks:
  203.     mov  ebx,64*65536+24           ; draw x and width
  204.     mov  ecx,188*65536+42          ; draw y and depth
  205.     mov  edx,0xc0c0c0              ; color grey
  206.     mov  eax,13                    ; draw bar function
  207.     int  0x40
  208.     mov  eax,[picks]               ; first picked color
  209.     mov  esi,22*65536+196          ; print at x and y
  210.     call do_hex                    ; print color number
  211.     mov  eax,[picks+4]             ; second picked color
  212.     mov  esi,22*65536+215          ; print at x and y
  213.     call do_hex                    ; print color number
  214.     mov  eax,[picks]               ; first picked color
  215.     mov  ebx,67*65536+18           ; x and width
  216.     mov  esi,191*65536+18          ; y and depth
  217.     call do_color                  ; paint color 1 square
  218.     mov  eax,[picks+4]             ; second picked color
  219.     mov  ebx,67*65536+18           ; x and width
  220.     mov  esi,209*65536+18          ; y and depth
  221.     call do_color                  ; paint color 2 square
  222.     mov  eax,[picks]               ; first picked color
  223.     mov  ebx,96*65536+196          ; x and y
  224.     call do_name                   ; print color's name
  225.     mov  eax,[picks+4]             ; second picked color
  226.     mov  ebx,96*65536+215          ; x and y
  227.     call do_name                   ; print color's name
  228.  
  229.     ret
  230.  
  231. do_hex:
  232.     dec  eax                       ; use 0 base
  233.     mov  ecx,4                     ; dword length
  234.     mul  ecx                       ; calc pointer
  235.     mov  edi,colors                ; color table
  236.     add  edi,eax                   ; add offset
  237.     mov  ecx,[edi]                 ; save color 1
  238.     mov  ebx,0x60100               ; print 6 hex digits
  239.     mov  edx,esi                   ; copy color
  240.     mov  esi,0xe1e1e1              ; use white
  241.     mov  eax,47                    ; print number function
  242.     int  0x40
  243.  
  244.     ret
  245.  
  246. do_color:
  247.     dec  eax                       ; use 0 base
  248.     mov  ecx,4                     ; dword length
  249.     mul  ecx                       ; calc pointer
  250.     mov  edi,colors                ; color table
  251.     add  edi,eax                   ; add offset
  252.     mov  edx,[edi]                 ; color
  253.     mov  ecx,esi                   ; recover y an depth
  254.     mov  eax,13                    ; draw bar function
  255.     int  0x40
  256.  
  257.     ret
  258.  
  259. do_name:
  260.     dec  eax                       ; use 0 base
  261.     mov  ecx,15                    ; string length
  262.     mul  ecx                       ; calc pointer
  263.     mov  edx,names                 ; color table
  264.     add  edx,eax                   ; add offset
  265.     mov  ecx,0xe1e1e1              ; color
  266.     mov  esi,15
  267.     mov  eax,4                     ; print text function
  268.     int  0x40
  269.  
  270.     ret
  271.  
  272. clear:
  273.     mov  ebx,22*65536+36           ; x and width
  274.     mov  ecx,196*65536+26          ; y and depth
  275.     mov  edx,0x000000              ; color
  276.     mov  eax,13                    ; draw bar funx
  277.     int  0x40
  278.     mov  ebx,96*65536+90           ; x and width
  279.     mov  ecx,196*65536+26          ; y and depth
  280.     mov  edx,0x000000              ; color
  281.     mov  eax,13                    ; draw bar funx
  282.     int  0x40
  283.  
  284.     ret
  285.  
  286. help:
  287.     mov  ebx,4*65536+192           ; x and width
  288.     mov  ecx,20*65536+216          ; y and depth
  289.     mov  edx,0x465e8f              ; dark denim color
  290.     mov  eax,13                    ; write text funx
  291.     int  0x40
  292.     mov  ebx,20*65536+40           ; starting x and y
  293.     mov  edx,text                  ; start of text
  294.     mov  esi,27                    ; width of text
  295.     mov  ecx,14                    ; 14 text lines to do
  296.     mov  eax,4                     ; write text funx
  297. h1: push ecx
  298.     sub  ebx,65537                 ; drop shadow x and y
  299.     mov  ecx,0x000000              ; black shadow
  300.     int  0x40
  301.     add  ebx,65537                 ; original x and y
  302.     mov  ecx,0xefefef              ; white text
  303.     int  0x40
  304.     add  edx,27                    ; next line of text
  305.     add  bx,12                     ; next row
  306.     pop  ecx
  307.     loop h1
  308.     mov  eax,10                    ; wait on event
  309.     int  0x40
  310.     cmp  eax,2                     ; got a key?
  311.     jne  h2                        ; nope
  312.     mov  eax,2                     ; yep, burn it
  313.     int  0x40
  314. h2: mov  ebx,4*65536+192           ; y and width
  315.     mov  ecx,20*65536+216          ; x and depth
  316.     mov  edx,0x00000               ; restore black bkg
  317.     mov  eax,13                    ; draw bar funx
  318.     int  0x40
  319.     call palette                   ; redraw color palette
  320.  
  321.     ret
  322.  
  323.  
  324. ;   *********************************************
  325. ;   **********  DATA DEFINITIONS AREA ***********
  326. ;   *********************************************
  327.  
  328. prog_name:
  329.     db   'COLOR REFERENCE     H>HELP'
  330. namelen:
  331.  
  332. picks:
  333.     dd   31,2           ; selected top/bot colors
  334.  
  335. colors:
  336.     dd   0xe0e0e0       ; white
  337.     dd   0xe7e6a0       ; pale yellow
  338.     dd   0xe7e05a       ; lemon yellow
  339.     dd   0xe7c750       ; mustard
  340.     dd   0xe7b850       ; cadium yellow
  341.     dd   0xbfa461       ; yellow ocre
  342.     dd   0xe0c090       ; cream
  343.     dd   0xe0b27b       ; peach
  344.     dd   0xe2986d       ; dark peach
  345.     dd   0xebb2c0       ; pink
  346.     dd   0xe0b0a0       ; flesh
  347.     dd   0xc79790       ; artificial arm
  348.     dd   0xb88688       ; deep blush
  349.     dd   0xc4a077       ; washed khaki
  350.     dd   0xb69269       ; khaki
  351.     dd   0xa8845b       ; dark khaki
  352.     dd   0xab937a       ; beige
  353.     dd   0xa39370       ; poupon
  354.     dd   0x988c00       ; camouflage
  355.     dd   0x98a024       ; pale olive
  356.     dd   0x838b00       ; olive
  357.     dd   0x6d7600       ; dark olive
  358.     dd   0x5b6200       ; black olive
  359.     dd   0x94946a       ; washed army
  360.     dd   0x74744a       ; army
  361.     dd   0x66a696       ; pale teal
  362.     dd   0x409b90       ; faded teal
  363.     dd   0x008d8d       ; pastel teal
  364.     dd   0x007c7c       ; teal
  365.     dd   0x006464       ; dark teal
  366.     dd   0x00b8ca       ; light turquoise
  367.     dd   0x00a0b2       ; turquoise
  368.     dd   0x00889a       ; dark turquoise
  369.     dd   0x575f8c       ; medium cobalt
  370.     dd   0x4e4e7c       ; cobalt
  371.     dd   0x00459a       ; ultramarine
  372.     dd   0x400088       ; navy blue
  373.     dd   0x4e00e7       ; true blue
  374.     dd   0x508cec       ; sky blue
  375.     dd   0x6a73d0       ; mountain blue
  376.     dd   0x677ab0       ; faded jeans
  377.     dd   0x576fa0       ; denim
  378.     dd   0xd048c8       ; fuschia
  379.     dd   0xb800e7       ; lavendar
  380.     dd   0xa800a8       ; light violet
  381.     dd   0x780078       ; violet
  382.     dd   0x520064       ; purple
  383.     dd   0xb800b8       ; magenta
  384.     dd   0xa4307a       ; rose
  385.     dd   0x90207f       ; mauve
  386.     dd   0xe76e83       ; salmon
  387.     dd   0xea7a7d       ; pastel orange
  388.     dd   0xe26830       ; orange
  389.     dd   0xac5800       ; burnt sienna
  390.     dd   0xcc0000       ; red orange
  391.     dd   0xac0000       ; cadium red
  392.     dd   0x880040       ; brick red
  393.     dd   0x780000       ; rust
  394.     dd   0x683020       ; terra cotta
  395.     dd   0x7f4658       ; light maroon
  396.     dd   0x702050       ; maroon
  397.     dd   0x7a5b5f       ; umber blush
  398.     dd   0x584838       ; burnt umber
  399.     dd   0x8a5d1a       ; cigar brown
  400.     dd   0x64504a       ; ice brown
  401.     dd   0x564242       ; dark chocolate
  402.     dd   0x00aa66       ; celery stalk
  403.     dd   0x107a30       ; forest green
  404.     dd   0x365800       ; hooker's green
  405.     dd   0x8beb88       ; pastel lime
  406.     dd   0x7bbb64       ; lime
  407.     dd   0x4ba010       ; dark lime
  408.  
  409. names:
  410.     db   'WHITE          '
  411.     db   'PALE YELLOW    '
  412.     db   'LEMON YELLOW   '
  413.     db   'MUSTARD        '
  414.     db   'CADIUM YELLOW  '
  415.     db   'YELLOW OCRE    '
  416.     db   'CREAM          '
  417.     db   'PEACH          '
  418.     db   'DARK PEACH     '
  419.     db   'PINK           '
  420.     db   'FLESH          '
  421.     db   'ARTIFICIAL ARM '
  422.     db   'DEEP BLUSH     '
  423.     db   'WASHED KHAKI   '
  424.     db   'KHAKI          '
  425.     db   'DARK KHAKI     '
  426.     db   'BEIGE          '
  427.     db   'POUPON         '
  428.     db   'CAMOUFLAGE     '
  429.     db   'PALE OLIVE     '
  430.     db   'OLIVE          '
  431.     db   'DARK OLIVE     '
  432.     db   'BLACK OLIVE    '
  433.     db   'WASHED ARMY    '
  434.     db   'ARMY           '
  435.     db   'PALE TEAL      '
  436.     db   'FADED TEAL     '
  437.     db   'PASTEL TEAL    '
  438.     db   'TEAL           '
  439.     db   'DARK TEAL      '
  440.     db   'LIGHT TURQUOISE'
  441.     db   'TURQUOISE      '
  442.     db   'DARK TURQUOISE '
  443.     db   'MEDIUM COBALT  '
  444.     db   'COBALT         '
  445.     db   'ULTRAMARINE    '
  446.     db   'NAVY BLUE      '
  447.     db   'TRUE BLUE      '
  448.     db   'SKY BLUE       '
  449.     db   'MOUNTAIN BLUE  '
  450.     db   'FADED JEANS    '
  451.     db   'DENIM          '
  452.     db   'FUSHIA         '
  453.     db   'LAVENDAR       '
  454.     db   'LIGHT VIOLET   '
  455.     db   'VIOLET         '
  456.     db   'PURPLE         '
  457.     db   'MAGENTA        '
  458.     db   'ROSE           '
  459.     db   'MAUVE          '
  460.     db   'SALMON         '
  461.     db   'PASTEL ORANGE  '
  462.     db   'ORANGE         '
  463.     db   'BURNT SIENNA   '
  464.     db   'RED ORANGE     '
  465.     db   'CADIUM RED     '
  466.     db   'BRICK RED      '
  467.     db   'RUST           '
  468.     db   'TERRA COTTA    '
  469.     db   'LIGHT MAROON   '
  470.     db   'MAROON         '
  471.     db   'UMBER BLUSH    '
  472.     db   'BURNT UMBER    '
  473.     db   'CIGAR BROWN    '
  474.     db   'ICE BROWN      '
  475.     db   'DARK CHOCOLATE '
  476.     db   'CELERY STALK   '
  477.     db   'FOREST GREEN   '
  478.     db   "HOOKER'S GREEN "
  479.     db   'PASTEL LIME    '
  480.     db   'LIME           '
  481.     db   'DARK LIME      '
  482.  
  483.  
  484. text:
  485.     db   'TO SEE HOW COLORS COMPARE  '
  486.     db   'TO ONE ANOTHER, LEFT CLICK '
  487.     db   'THE FIRST COLOR AND RIGHT  '
  488.     db   'CLICK THE SECOND. TO GET   '
  489.     db   "A SENSE OF A COLOR'S TRUE  "
  490.     db   'HUE, RIGHT AND LEFT CLICK  '
  491.     db   'THE SAME COLOR TO SEE IT   '
  492.     db   'ON THE NEUTRAL BACKGROUND. '
  493.     db   'TO USE A LIGHTER OR DARKER '
  494.     db   'VALUE OF A COLOR, ADD OR   '
  495.     db   'SUBTRACT 0x10 OR 0x20 FROM '
  496.     db   'EACH BYTE OF ITS HEX VALUE.'
  497.     db   '                           '
  498.     db   '       ANY KEY ...         '
  499.  
  500. stat_table:
  501.  
  502.  
  503. finis: