Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | 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   0x100000             ; memory for app
  14.          dd   0x7fff0              ; 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,0x02000000            ; 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.     mov  eax,8                     ; CLOSE BUTTON
  162.     mov  ebx,(200-19)*65536+12     ; [x start] *65536 + [x size]
  163.     mov  ecx,5*65536+12            ; [y start] *65536 + [y size]
  164.     mov  edx,1                     ; button id
  165.     mov  esi,0xaaaaaa              ; button color (light grey)
  166.     int  0x40
  167.  
  168.     call palette                   ; display color palette
  169.  
  170.     mov  eax,12                    ; tell os about windowdraw
  171.     mov  ebx,2                     ; 2, end of draw
  172.     int  0x40
  173.  
  174.     ret
  175.  
  176.  
  177. ;   *********************************************
  178. ;   *******  COLOR PALETTE LAYOUT ROUTINES ******
  179. ;   *********************************************
  180.  
  181.  
  182. palette:
  183.     mov  ebx,15*65536+18           ; LAYOUT: start x and width
  184.     mov  edx,32*65536+18           ; LAYOUT: start y and depth
  185.     mov  ecx,8                     ; 8 rows
  186.     mov  ebp,colors                ; color table
  187. p1: push ecx
  188.     mov  ecx,9                     ; 9 columns
  189. p2: push ecx
  190.     push edx
  191.     mov  ecx,edx                   ; y coord
  192.     mov  edx,[ebp]                 ; color
  193.     mov  eax,13                    ; draw bar function
  194.     int  0x40
  195.     pop  edx
  196.     pop  ecx
  197.     add  ebx,19*65536              ; next column
  198.     add  ebp,4                     ; next color
  199. p3: loop p2
  200.     pop  ecx
  201.     mov  ebx,15*65536+18           ; restart x
  202.     add  edx,19*65536              ; next row
  203.     loop p1
  204.     call draw_picks
  205.  
  206.     ret
  207.  
  208. draw_picks:
  209.     mov  ebx,64*65536+24           ; draw x and width
  210.     mov  ecx,188*65536+42          ; draw y and depth
  211.     mov  edx,0xc0c0c0              ; color grey
  212.     mov  eax,13                    ; draw bar function
  213.     int  0x40
  214.     mov  eax,[picks]               ; first picked color
  215.     mov  esi,22*65536+196          ; print at x and y
  216.     call do_hex                    ; print color number
  217.     mov  eax,[picks+4]             ; second picked color
  218.     mov  esi,22*65536+215          ; print at x and y
  219.     call do_hex                    ; print color number
  220.     mov  eax,[picks]               ; first picked color
  221.     mov  ebx,67*65536+18           ; x and width
  222.     mov  esi,191*65536+18          ; y and depth
  223.     call do_color                  ; paint color 1 square
  224.     mov  eax,[picks+4]             ; second picked color
  225.     mov  ebx,67*65536+18           ; x and width
  226.     mov  esi,209*65536+18          ; y and depth
  227.     call do_color                  ; paint color 2 square
  228.     mov  eax,[picks]               ; first picked color
  229.     mov  ebx,96*65536+196          ; x and y
  230.     call do_name                   ; print color's name
  231.     mov  eax,[picks+4]             ; second picked color
  232.     mov  ebx,96*65536+215          ; x and y
  233.     call do_name                   ; print color's name
  234.  
  235.     ret
  236.  
  237. do_hex:
  238.     dec  eax                       ; use 0 base
  239.     mov  ecx,4                     ; dword length
  240.     mul  ecx                       ; calc pointer
  241.     mov  edi,colors                ; color table
  242.     add  edi,eax                   ; add offset
  243.     mov  ecx,[edi]                 ; save color 1
  244.     mov  ebx,0x60100               ; print 6 hex digits
  245.     mov  edx,esi                   ; copy color
  246.     mov  esi,0xe1e1e1              ; use white
  247.     mov  eax,47                    ; print number function
  248.     int  0x40
  249.  
  250.     ret
  251.  
  252. do_color:
  253.     dec  eax                       ; use 0 base
  254.     mov  ecx,4                     ; dword length
  255.     mul  ecx                       ; calc pointer
  256.     mov  edi,colors                ; color table
  257.     add  edi,eax                   ; add offset
  258.     mov  edx,[edi]                 ; color
  259.     mov  ecx,esi                   ; recover y an depth
  260.     mov  eax,13                    ; draw bar function
  261.     int  0x40
  262.  
  263.     ret
  264.  
  265. do_name:
  266.     dec  eax                       ; use 0 base
  267.     mov  ecx,15                    ; string length
  268.     mul  ecx                       ; calc pointer
  269.     mov  edx,names                 ; color table
  270.     add  edx,eax                   ; add offset
  271.     mov  ecx,0xe1e1e1              ; color
  272.     mov  esi,15
  273.     mov  eax,4                     ; print text function
  274.     int  0x40
  275.  
  276.     ret
  277.  
  278. clear:
  279.     mov  ebx,22*65536+36           ; x and width
  280.     mov  ecx,196*65536+26          ; y and depth
  281.     mov  edx,0x000000              ; color
  282.     mov  eax,13                    ; draw bar funx
  283.     int  0x40
  284.     mov  ebx,96*65536+90           ; x and width
  285.     mov  ecx,196*65536+26          ; y and depth
  286.     mov  edx,0x000000              ; color
  287.     mov  eax,13                    ; draw bar funx
  288.     int  0x40
  289.  
  290.     ret
  291.  
  292. help:
  293.     mov  ebx,4*65536+192           ; x and width
  294.     mov  ecx,20*65536+216          ; y and depth
  295.     mov  edx,0x465e8f              ; dark denim color
  296.     mov  eax,13                    ; write text funx
  297.     int  0x40
  298.     mov  ebx,20*65536+40           ; starting x and y
  299.     mov  edx,text                  ; start of text
  300.     mov  esi,27                    ; width of text
  301.     mov  ecx,14                    ; 14 text lines to do
  302.     mov  eax,4                     ; write text funx
  303. h1: push ecx
  304.     sub  ebx,65537                 ; drop shadow x and y
  305.     mov  ecx,0x000000              ; black shadow
  306.     int  0x40
  307.     add  ebx,65537                 ; original x and y
  308.     mov  ecx,0xefefef              ; white text
  309.     int  0x40
  310.     add  edx,27                    ; next line of text
  311.     add  bx,12                     ; next row
  312.     pop  ecx
  313.     loop h1
  314.     mov  eax,10                    ; wait on event
  315.     int  0x40
  316.     cmp  eax,2                     ; got a key?
  317.     jne  h2                        ; nope
  318.     mov  eax,2                     ; yep, burn it
  319.     int  0x40
  320. h2: mov  ebx,4*65536+192           ; y and width
  321.     mov  ecx,20*65536+216          ; x and depth
  322.     mov  edx,0x00000               ; restore black bkg
  323.     mov  eax,13                    ; draw bar funx
  324.     int  0x40
  325.     call palette                   ; redraw color palette
  326.  
  327.     ret
  328.  
  329.  
  330. ;   *********************************************
  331. ;   **********  DATA DEFINITIONS AREA ***********
  332. ;   *********************************************
  333.  
  334. prog_name:
  335.     db   'COLOR REFERENCE     H>HELP'
  336. namelen:
  337.  
  338. picks:
  339.     dd   31,2           ; selected top/bot colors
  340.  
  341. colors:
  342.     dd   0xe0e0e0       ; white
  343.     dd   0xe7e6a0       ; pale yellow
  344.     dd   0xe7e05a       ; lemon yellow
  345.     dd   0xe7c750       ; mustard
  346.     dd   0xe7b850       ; cadium yellow
  347.     dd   0xbfa461       ; yellow ocre
  348.     dd   0xe0c090       ; cream
  349.     dd   0xe0b27b       ; peach
  350.     dd   0xe2986d       ; dark peach
  351.     dd   0xebb2c0       ; pink
  352.     dd   0xe0b0a0       ; flesh
  353.     dd   0xc79790       ; artificial arm
  354.     dd   0xb88688       ; deep blush
  355.     dd   0xc4a077       ; washed khaki
  356.     dd   0xb69269       ; khaki
  357.     dd   0xa8845b       ; dark khaki
  358.     dd   0xab937a       ; beige
  359.     dd   0xa39370       ; poupon
  360.     dd   0x988c00       ; camouflage
  361.     dd   0x98a024       ; pale olive
  362.     dd   0x838b00       ; olive
  363.     dd   0x6d7600       ; dark olive
  364.     dd   0x5b6200       ; black olive
  365.     dd   0x94946a       ; washed army
  366.     dd   0x74744a       ; army
  367.     dd   0x66a696       ; pale teal
  368.     dd   0x409b90       ; faded teal
  369.     dd   0x008d8d       ; pastel teal
  370.     dd   0x007c7c       ; teal
  371.     dd   0x006464       ; dark teal
  372.     dd   0x00b8ca       ; light turquoise
  373.     dd   0x00a0b2       ; turquoise
  374.     dd   0x00889a       ; dark turquoise
  375.     dd   0x575f8c       ; medium cobalt
  376.     dd   0x4e4e7c       ; cobalt
  377.     dd   0x00459a       ; ultramarine
  378.     dd   0x400088       ; navy blue
  379.     dd   0x4e00e7       ; true blue
  380.     dd   0x508cec       ; sky blue
  381.     dd   0x6a73d0       ; mountain blue
  382.     dd   0x677ab0       ; faded jeans
  383.     dd   0x576fa0       ; denim
  384.     dd   0xd048c8       ; fuschia
  385.     dd   0xb800e7       ; lavendar
  386.     dd   0xa800a8       ; light violet
  387.     dd   0x780078       ; violet
  388.     dd   0x520064       ; purple
  389.     dd   0xb800b8       ; magenta
  390.     dd   0xa4307a       ; rose
  391.     dd   0x90207f       ; mauve
  392.     dd   0xe76e83       ; salmon
  393.     dd   0xea7a7d       ; pastel orange
  394.     dd   0xe26830       ; orange
  395.     dd   0xac5800       ; burnt sienna
  396.     dd   0xcc0000       ; red orange
  397.     dd   0xac0000       ; cadium red
  398.     dd   0x880040       ; brick red
  399.     dd   0x780000       ; rust
  400.     dd   0x683020       ; terra cotta
  401.     dd   0x7f4658       ; light maroon
  402.     dd   0x702050       ; maroon
  403.     dd   0x7a5b5f       ; umber blush
  404.     dd   0x584838       ; burnt umber
  405.     dd   0x8a5d1a       ; cigar brown
  406.     dd   0x64504a       ; ice brown
  407.     dd   0x564242       ; dark chocolate
  408.     dd   0x00aa66       ; celery stalk
  409.     dd   0x107a30       ; forest green
  410.     dd   0x365800       ; hooker's green
  411.     dd   0x8beb88       ; pastel lime
  412.     dd   0x7bbb64       ; lime
  413.     dd   0x4ba010       ; dark lime
  414.  
  415. names:
  416.     db   'WHITE          '
  417.     db   'PALE YELLOW    '
  418.     db   'LEMON YELLOW   '
  419.     db   'MUSTARD        '
  420.     db   'CADIUM YELLOW  '
  421.     db   'YELLOW OCRE    '
  422.     db   'CREAM          '
  423.     db   'PEACH          '
  424.     db   'DARK PEACH     '
  425.     db   'PINK           '
  426.     db   'FLESH          '
  427.     db   'ARTIFICIAL ARM '
  428.     db   'DEEP BLUSH     '
  429.     db   'WASHED KHAKI   '
  430.     db   'KHAKI          '
  431.     db   'DARK KHAKI     '
  432.     db   'BEIGE          '
  433.     db   'POUPON         '
  434.     db   'CAMOUFLAGE     '
  435.     db   'PALE OLIVE     '
  436.     db   'OLIVE          '
  437.     db   'DARK OLIVE     '
  438.     db   'BLACK OLIVE    '
  439.     db   'WASHED ARMY    '
  440.     db   'ARMY           '
  441.     db   'PALE TEAL      '
  442.     db   'FADED TEAL     '
  443.     db   'PASTEL TEAL    '
  444.     db   'TEAL           '
  445.     db   'DARK TEAL      '
  446.     db   'LIGHT TURQUOISE'
  447.     db   'TURQUOISE      '
  448.     db   'DARK TURQUOISE '
  449.     db   'MEDIUM COBALT  '
  450.     db   'COBALT         '
  451.     db   'ULTRAMARINE    '
  452.     db   'NAVY BLUE      '
  453.     db   'TRUE BLUE      '
  454.     db   'SKY BLUE       '
  455.     db   'MOUNTAIN BLUE  '
  456.     db   'FADED JEANS    '
  457.     db   'DENIM          '
  458.     db   'FUSHIA         '
  459.     db   'LAVENDAR       '
  460.     db   'LIGHT VIOLET   '
  461.     db   'VIOLET         '
  462.     db   'PURPLE         '
  463.     db   'MAGENTA        '
  464.     db   'ROSE           '
  465.     db   'MAUVE          '
  466.     db   'SALMON         '
  467.     db   'PASTEL ORANGE  '
  468.     db   'ORANGE         '
  469.     db   'BURNT SIENNA   '
  470.     db   'RED ORANGE     '
  471.     db   'CADIUM RED     '
  472.     db   'BRICK RED      '
  473.     db   'RUST           '
  474.     db   'TERRA COTTA    '
  475.     db   'LIGHT MAROON   '
  476.     db   'MAROON         '
  477.     db   'UMBER BLUSH    '
  478.     db   'BURNT UMBER    '
  479.     db   'CIGAR BROWN    '
  480.     db   'ICE BROWN      '
  481.     db   'DARK CHOCOLATE '
  482.     db   'CELERY STALK   '
  483.     db   'FOREST GREEN   '
  484.     db   "HOOKER'S GREEN "
  485.     db   'PASTEL LIME    '
  486.     db   'LIME           '
  487.     db   'DARK LIME      '
  488.  
  489.  
  490. text:
  491.     db   'TO SEE HOW COLORS COMPARE  '
  492.     db   'TO ONE ANOTHER, LEFT CLICK '
  493.     db   'THE FIRST COLOR AND RIGHT  '
  494.     db   'CLICK THE SECOND. TO GET   '
  495.     db   "A SENSE OF A COLOR'S TRUE  "
  496.     db   'HUE, RIGHT AND LEFT CLICK  '
  497.     db   'THE SAME COLOR TO SEE IT   '
  498.     db   'ON THE NEUTRAL BACKGROUND. '
  499.     db   'TO USE A LIGHTER OR DARKER '
  500.     db   'VALUE OF A COLOR, ADD OR   '
  501.     db   'SUBTRACT 0x10 OR 0x20 FROM '
  502.     db   'EACH BYTE OF ITS HEX VALUE.'
  503.     db   '                           '
  504.     db   '       ANY KEY ...         '
  505.  
  506. stat_table:
  507.  
  508.  
  509. finis: