1 # Some information about the default palette of 256 colors provided by the
2 # BIOS on x86 computers.
6 # Return the r/g/b for color [0, 256) in ecx/edx/ebx respectively.
7 color-rgb: # color: int -> _/ecx: int, _/edx: int, _/ebx: int
15 8b/-> *(ebp+8) 6/r32/esi
17 81 7/subop/compare %esi 0x100/imm32
19 7c/jump-if-< break/disp8
20 (abort "invalid color")
22 # var color/esi: int = Colors-rgb[color]
23 b8/copy-to-eax Colors-rgb/imm32
24 8b/-> *(eax+esi<<2+4) 6/r32/esi
25 # var red/ecx: int = color & 0xff
27 25/and-eax-with 0xff/imm32
29 # var green/edx: int = (color >> 8) & 0xff
31 c1 5/subop/shift-right-logical %eax 8/imm8
32 25/and-eax-with 0xff/imm32
34 # var blue/ebx: int = (color >> 16)
36 c1 5/subop/shift-right-logical %eax 0x10/imm8
52 (color-rgb 0x10) # => eax ecx edx
53 (check-ints-equal %ecx 0 "F - test-color-rgb/0x10/r")
54 (check-ints-equal %edx 0 "F - test-color-rgb/0x10/g")
55 (check-ints-equal %ebx 0 "F - test-color-rgb/0x10/b")
56 (color-rgb 1) # => eax ecx edx
57 (check-ints-equal %ecx 0 "F - test-color-rgb/1/r")
58 (check-ints-equal %edx 0 "F - test-color-rgb/1/g")
59 (check-ints-equal %ebx 0xaa "F - test-color-rgb/1/b")
60 (color-rgb 0xf) # => eax ecx edx
61 (check-ints-equal %ecx 0xff "F - test-color-rgb/0xf/r")
62 (check-ints-equal %edx 0xff "F - test-color-rgb/0xf/g")
63 (check-ints-equal %ebx 0xff "F - test-color-rgb/0xf/b")