| | 1 | /* |
| | 2 | * PicoDrive |
| | 3 | * (C) notaz, 2006,2009 |
| | 4 | * (C) irixxxx, 2022 |
| | 5 | * |
| | 6 | * This work is licensed under the terms of MAME license. |
| | 7 | * See COPYING file in the top-level directory. |
| | 8 | */ |
| | 9 | |
| | 10 | #include <string.h> |
| | 11 | |
| | 12 | // Convert 0000bbb0 ggg0rrr0 0000bbb0 ggg0rrr0 |
| | 13 | // to 00000000 rrr00000 ggg00000 bbb00000 ... |
| | 14 | // TODO: rm when gp2x/emu.c is no longer used |
| | 15 | |
| | 16 | void bgr444_to_rgb32(void *to, void *from, unsigned entries) |
| | 17 | { |
| | 18 | unsigned short *ps = from; |
| | 19 | unsigned int *pd = to; |
| | 20 | int pixels; |
| | 21 | |
| | 22 | for (pixels = entries; pixels; pixels--, ps++, pd++) |
| | 23 | { |
| | 24 | *pd = ((*ps<<20)&0xe00000) | ((*ps<<8)&0xe000) | ((*ps>>4)&0xe0); |
| | 25 | *pd |= *pd >> 3; |
| | 26 | } |
| | 27 | } |
| | 28 | |
| | 29 | void bgr444_to_rgb32_sh(void *to, void *from) |
| | 30 | { |
| | 31 | unsigned short *ps = from; |
| | 32 | unsigned int *pd = to; |
| | 33 | int pixels; |
| | 34 | |
| | 35 | pd += 0x40; |
| | 36 | for (pixels = 0x40; pixels; pixels--, ps++, pd++) |
| | 37 | { |
| | 38 | *pd = ((*ps<<20)&0xe00000) | ((*ps<<8)&0xe000) | ((*ps>>4)&0xe0); |
| | 39 | *pd >>= 1; |
| | 40 | *pd |= *pd >> 3; |
| | 41 | pd[0x40*2] = *pd; |
| | 42 | } |
| | 43 | |
| | 44 | ps -= 0x40; |
| | 45 | for (pixels = 0x40; pixels; pixels--, ps++, pd++) |
| | 46 | { |
| | 47 | *pd = ((*ps<<20)&0xe00000) | ((*ps<<8)&0xe000) | ((*ps>>4)&0xe0); |
| | 48 | continue; |
| | 49 | *pd += 0x00404040; |
| | 50 | if (*pd & 0x01000000) *pd |= 0x00e00000; |
| | 51 | if (*pd & 0x00010000) *pd |= 0x0000e000; |
| | 52 | if (*pd & 0x00000100) *pd |= 0x000000e0; |
| | 53 | *pd &= 0x00e0e0e0; |
| | 54 | *pd |= *pd >> 3; |
| | 55 | } |
| | 56 | } |
| | 57 | |
| | 58 | #define X (x_y >> 16) |
| | 59 | #define Y (x_y & 0xffff) |
| | 60 | #define W (w_h >> 16) |
| | 61 | #define H (w_h & 0xffff) |
| | 62 | |
| | 63 | // gp2x: 0-> X wiz: Y <-0 |
| | 64 | // | | |
| | 65 | // v v |
| | 66 | // |
| | 67 | // Y X |
| | 68 | |
| | 69 | void vidcpy_8bit(void *dest, void *src, int x_y, int w_h) |
| | 70 | { |
| | 71 | unsigned char *pd = dest, *ps = src; |
| | 72 | int i; |
| | 73 | |
| | 74 | pd += X + Y*320; |
| | 75 | ps += X + Y*328 + 8; |
| | 76 | for (i = 0; i < H; i++) { |
| | 77 | memcpy(pd, ps, W); |
| | 78 | ps += 328; pd += 320; |
| | 79 | } |
| | 80 | } |
| | 81 | |
| | 82 | void vidcpy_8bit_rot(void *dest, void *src, int x_y, int w_h) |
| | 83 | { |
| | 84 | unsigned char *pd = dest, *ps = src; |
| | 85 | int i, u; |
| | 86 | |
| | 87 | pd += Y + (319-X)*240; |
| | 88 | ps += X + Y*328 + 8; |
| | 89 | for (i = 0; i < H; i += 4) { |
| | 90 | unsigned char *p = (void *)ps; |
| | 91 | unsigned int *q = (void *)pd; |
| | 92 | for (u = 0; u < W; u++) { |
| | 93 | *q = (p[3*328]<<24) + (p[2*328]<<16) + (p[1*328]<<8) + p[0*328]; |
| | 94 | p += 1; |
| | 95 | q -= 240/4; |
| | 96 | } |
| | 97 | ps += 4*328; pd += 4; |
| | 98 | } |
| | 99 | } |
| | 100 | |
| | 101 | void rotated_blit8 (void *dst, void *linesx4, int y, int is_32col) |
| | 102 | { |
| | 103 | unsigned char *pd = dst, *ps = linesx4; |
| | 104 | int x, w, u; |
| | 105 | |
| | 106 | x = (is_32col ? 32 : 0); |
| | 107 | w = (is_32col ? 256 : 320); |
| | 108 | y -= 4; |
| | 109 | |
| | 110 | pd += y + (319-x)*240; |
| | 111 | ps += x; |
| | 112 | |
| | 113 | unsigned char *p = (void *)ps; |
| | 114 | unsigned int *q = (void *)pd; |
| | 115 | for (u = 0; u < w; u++) { |
| | 116 | *q = (p[3*328]<<24) + (p[2*328]<<16) + (p[1*328]<<8) + p[0*328]; |
| | 117 | p += 1; |
| | 118 | q -= 240/4; |
| | 119 | } |
| | 120 | } |
| | 121 | |
| | 122 | void rotated_blit16(void *dst, void *linesx4, int y, int is_32col) |
| | 123 | { |
| | 124 | unsigned short *pd = dst, *ps = linesx4; |
| | 125 | int x, w, u; |
| | 126 | |
| | 127 | x = (is_32col ? 32 : 0); |
| | 128 | w = (is_32col ? 256 : 320); |
| | 129 | y -= 4; |
| | 130 | |
| | 131 | pd += y + (319-x)*240; |
| | 132 | ps += x; |
| | 133 | |
| | 134 | unsigned short *p = (void *)ps; |
| | 135 | unsigned int *q = (void *)pd; |
| | 136 | for (u = 0; u < w; u++) { |
| | 137 | q[0] = (p[1*328]<<16) + p[0*328]; |
| | 138 | q[1] = (p[3*328]<<16) + p[2*328]; |
| | 139 | p += 1; |
| | 140 | q -= 2*240/4; |
| | 141 | } |
| | 142 | } |