|
| 1 | +#include "sq.h" |
| 2 | +#include "framebuffer.h" |
| 3 | +#include "types.h" |
| 4 | +#include "barrier.h" |
| 5 | + |
| 6 | +#define BytesPerComponent (ScreenDepth / 8) |
| 7 | + |
| 8 | +int ioScreenSize(void) { |
| 9 | + return (fb_x << 16) | (fb_y & 0xFFFF); /* w is high 16 bits; h is low 16 bits */ |
| 10 | +} |
| 11 | + |
| 12 | +/*** Display stubs ***/ |
| 13 | +unsigned char underCursorData[16 * 16 * BytesPerComponent]; |
| 14 | +int lastCursorX, lastCursorY; |
| 15 | + |
| 16 | +struct SqCursor { |
| 17 | + unsigned char size, depth, y, x; |
| 18 | + unsigned short data[16], mask[16]; |
| 19 | +}; |
| 20 | + |
| 21 | +struct SqCursor SqueakCursor; |
| 22 | + |
| 23 | +void hideCursor(void) { |
| 24 | + int bytesPerComponent = BytesPerComponent; //depth/8; |
| 25 | + int bytesPerRow = bytesPerComponent * fb_x; |
| 26 | + int rowLength = SqueakCursor.size * bytesPerComponent; |
| 27 | + |
| 28 | + for (int y=0; y<SqueakCursor.size; y++) { |
| 29 | + int row = (lastCursorY + y) * bytesPerRow; |
| 30 | + int col = lastCursorX * bytesPerComponent; |
| 31 | + unsigned char *oldScreen = &underCursorData[y * rowLength]; |
| 32 | + memcpy((unsigned char *)screenbase + row + col, oldScreen, rowLength); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +void showCursor(void) { |
| 37 | + int bytesPerComponent = BytesPerComponent; //depth/8; |
| 38 | + int bytesPerRow = bytesPerComponent * fb_x; |
| 39 | + int rowLength = SqueakCursor.size * bytesPerComponent; |
| 40 | + |
| 41 | + for (int y=0; y<SqueakCursor.size; y++) { |
| 42 | + int row = (lastCursorY + y) * bytesPerRow; |
| 43 | + int col = lastCursorX * bytesPerComponent; |
| 44 | + |
| 45 | + unsigned char *rowData = (unsigned char *)screenbase + row + col; |
| 46 | + unsigned char *oldScreen = &underCursorData[y * rowLength]; |
| 47 | + memcpy(oldScreen, rowData, rowLength); |
| 48 | + for (int x=SqueakCursor.size; x>0; x--) { |
| 49 | + int cursor = SqueakCursor.data[y] & 1<<x; |
| 50 | + if (cursor) { |
| 51 | + if (bytesPerComponent > 3) { |
| 52 | + *rowData++ = 0xff; |
| 53 | + } |
| 54 | + if (bytesPerComponent > 2) { |
| 55 | + *rowData++ = 0x00; |
| 56 | + } |
| 57 | + *rowData++ = 0x00; |
| 58 | + *rowData++ = 0x00; |
| 59 | + } |
| 60 | + else { |
| 61 | + rowData+=bytesPerComponent; |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +void moveCursor(int x, int y) { |
| 68 | + if (x == lastCursorX && y == lastCursorY) { |
| 69 | + return; |
| 70 | + } |
| 71 | + hideCursor(); |
| 72 | + lastCursorX = x; |
| 73 | + lastCursorY = y; |
| 74 | + showCursor(); |
| 75 | +} |
| 76 | + |
| 77 | +int ioSetCursor(int cursorBitsIndex, int offsetX, int offsetY) { |
| 78 | + return ioSetCursorWithMask(cursorBitsIndex, 0, offsetX, offsetY); |
| 79 | +} |
| 80 | + |
| 81 | +int ioSetCursorWithMask(int cursorBitsIndex, int cursorMaskIndex, int offsetX, int offsetY) |
| 82 | +{ |
| 83 | + //printf("%s cursorBitsIndex=%i, cursorMaskIndex=%i, offsetX=%i, offsetY=%i\n", __PRETTY_FUNCTION__, cursorBitsIndex, cursorMaskIndex, offsetX, offsetY); |
| 84 | + |
| 85 | + hideCursor(); |
| 86 | + |
| 87 | + /* Set the 16x16 cursor bitmap. If cursorMaskIndex is nil, then make the mask the same as |
| 88 | + the cursor bitmap. If not, then mask and cursor bits combined determine how cursor is |
| 89 | + displayed: |
| 90 | + mask cursor effect |
| 91 | + 0 0 transparent (underlying pixel shows through) |
| 92 | + 1 1 opaque black |
| 93 | + 1 0 opaque white |
| 94 | + 0 1 invert the underlying pixel |
| 95 | + */ |
| 96 | + SqueakCursor.size = 16; |
| 97 | + SqueakCursor.depth = 1; |
| 98 | + SqueakCursor.x = -offsetX; |
| 99 | + SqueakCursor.y = -offsetY; |
| 100 | + |
| 101 | + for (int i = 0; i < SqueakCursor.size; i++) { |
| 102 | + SqueakCursor.data[i] = (checkedLongAt(cursorBitsIndex + (4 * i)) >> 16) & 0xFFFF; |
| 103 | + |
| 104 | + if (cursorMaskIndex == 0) { |
| 105 | + SqueakCursor.mask[i] = SqueakCursor.data[i]; |
| 106 | + } |
| 107 | + else { |
| 108 | + SqueakCursor.mask[i] = (checkedLongAt(cursorMaskIndex + (4 * i)) >> 16) & 0xFFFF; |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + showCursor(); |
| 113 | + return true; |
| 114 | +} |
| 115 | + |
| 116 | +int ioSetDisplayMode(int width, int height, int depth, int fullscreenFlag) { |
| 117 | + printf("%s width=%i, height=%i, depth=%i, fullscreenFlag=%i\n", __PRETTY_FUNCTION__, width, height, depth, fullscreenFlag); |
| 118 | + return 0; |
| 119 | +} |
| 120 | + |
| 121 | +int ioSetFullScreen(int fullScreen) { |
| 122 | + printf("%s fullScreen=%i\n", __PRETTY_FUNCTION__, fullScreen); |
| 123 | + return 0; |
| 124 | +} |
| 125 | + |
| 126 | +int ioHasDisplayDepth(int depth) { |
| 127 | + printf("%s depth=%i\n", __PRETTY_FUNCTION__, depth); |
| 128 | + if (depth == ScreenDepth) { |
| 129 | + return true; |
| 130 | + } |
| 131 | + return false; |
| 132 | +} |
| 133 | + |
| 134 | +int ioShowDisplay( |
| 135 | + int dispBitsIndex, int width, int height, int depth, |
| 136 | + int affectedL, int affectedR, int affectedT, int affectedB) |
| 137 | +{ |
| 138 | + if(affectedR <= affectedL || affectedT >= affectedB) { |
| 139 | + return 1; |
| 140 | + } |
| 141 | + |
| 142 | + bool clippedCursor = false; |
| 143 | + if ((lastCursorX >= affectedL || lastCursorX + SqueakCursor.size >= affectedL) && (lastCursorX <= affectedR || lastCursorX + SqueakCursor.size <= affectedR) && |
| 144 | + (lastCursorY >= affectedT || lastCursorY + SqueakCursor.size >= affectedT) && (lastCursorY <= affectedB || lastCursorY + SqueakCursor.size <= affectedB)) |
| 145 | + { |
| 146 | + clippedCursor = true; |
| 147 | + } |
| 148 | + |
| 149 | + if (clippedCursor == true) { |
| 150 | + hideCursor(); |
| 151 | + } |
| 152 | + |
| 153 | + int bytesPerComponent = depth/8; |
| 154 | + int rowLength = (affectedR - affectedL) * bytesPerComponent; |
| 155 | + |
| 156 | + int x,y; |
| 157 | + int sourceRow, sourceCol; |
| 158 | + int destRow, destCol; |
| 159 | + |
| 160 | + for (y = affectedT; y < affectedB; y++) { |
| 161 | + destRow = y * bytesPerComponent * fb_x; |
| 162 | + destCol = affectedL * bytesPerComponent; |
| 163 | + |
| 164 | + sourceRow = y * bytesPerComponent * width; |
| 165 | + sourceCol = affectedL * bytesPerComponent; |
| 166 | +#if 1 |
| 167 | + if (bytesPerComponent == 4) { |
| 168 | + uint32_t *toData = (uint32_t*)(screenbase + destRow + destCol); |
| 169 | + uint32_t *fromData = (uint32_t *)(dispBitsIndex + sourceRow + sourceCol); |
| 170 | + for (x = affectedL; x<affectedR; x++) { |
| 171 | + *toData = |
| 172 | + 0xff << 24 | // alpha |
| 173 | + (((*fromData ) & 0xff) << 16) | // blue |
| 174 | + (((*fromData >> 8) & 0xff) << 8) | // green |
| 175 | + (((*fromData >> 16) & 0xff) ) ; // red |
| 176 | + toData++,fromData++; |
| 177 | + } |
| 178 | + } |
| 179 | + else if (bytesPerComponent == 2) { |
| 180 | + uint16_t *toData = (uint16_t*)(screenbase + destRow + destCol); |
| 181 | + uint16_t *fromData = (uint16_t *)(dispBitsIndex + sourceRow + sourceCol); |
| 182 | + |
| 183 | + // Use 16 bits to store each pixel: |
| 184 | + // the first 5 bit representing the intensity of the red channel |
| 185 | + // the next 6 bits representing the intensity of the green channel and |
| 186 | + // the final 5 bits representing the intensity of the blue channel. |
| 187 | + for (x = affectedL; x<affectedR; x++) { |
| 188 | + *toData = |
| 189 | + (((((*fromData & 0x7C00) >> 10) << 3) >> 3) << 11) | // Red |
| 190 | + (((((*fromData & 0x3E0) >> 5) << 3) >> 2) << 5) | // Green |
| 191 | + (((((*fromData & 0x1F) ) << 3) >> 3) << 0); // Blue |
| 192 | + |
| 193 | + toData++,fromData++; |
| 194 | + } |
| 195 | + } |
| 196 | +#else |
| 197 | + memcpy((unsigned char *)screenbase + row + col, (unsigned char *)dispBitsIndex + row + col, rowLength); |
| 198 | +#endif |
| 199 | + } |
| 200 | + |
| 201 | + if (clippedCursor == true) { |
| 202 | + showCursor(); |
| 203 | + } |
| 204 | + dmb(); |
| 205 | + success(true); |
| 206 | +} |
| 207 | + |
| 208 | +int ioForceDisplayUpdate(void) { |
| 209 | + return true; |
| 210 | +} |
| 211 | + |
| 212 | +int ioFormPrint(int bitsAddr, int width, int height, int depth, double hScale, double vScale, int landscapeFlag) { |
| 213 | + /* experimental: print a form with the given bitmap, width, height, and depth at |
| 214 | + the given horizontal and vertical scales in the given orientation */ |
| 215 | + |
| 216 | + printf("%s\n", __PRETTY_FUNCTION__); |
| 217 | + success(false); |
| 218 | +} |
0 commit comments