| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: cgfourteen.c,v 1.91 2021/12/17 18:51:02 macallan Exp $ */ | | 1 | /* $NetBSD: cgfourteen.c,v 1.92 2021/12/17 19:27:57 macallan Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1996 | | 4 | * Copyright (c) 1996 |
5 | * The President and Fellows of Harvard College. All rights reserved. | | 5 | * The President and Fellows of Harvard College. All rights reserved. |
6 | * Copyright (c) 1992, 1993 | | 6 | * Copyright (c) 1992, 1993 |
7 | * The Regents of the University of California. All rights reserved. | | 7 | * The Regents of the University of California. All rights reserved. |
8 | * | | 8 | * |
9 | * This software was developed by the Computer Systems Engineering group | | 9 | * This software was developed by the Computer Systems Engineering group |
10 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and | | 10 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and |
11 | * contributed to Berkeley. | | 11 | * contributed to Berkeley. |
12 | * | | 12 | * |
13 | * All advertising materials mentioning features or use of this software | | 13 | * All advertising materials mentioning features or use of this software |
14 | * must display the following acknowledgement: | | 14 | * must display the following acknowledgement: |
| @@ -1032,26 +1032,32 @@ cg14_init_screen(void *cookie, struct vc | | | @@ -1032,26 +1032,32 @@ cg14_init_screen(void *cookie, struct vc |
1032 | if (FONT_IS_ALPHA(ri->ri_font)) { | | 1032 | if (FONT_IS_ALPHA(ri->ri_font)) { |
1033 | ri->ri_ops.putchar = cg14_putchar_aa; | | 1033 | ri->ri_ops.putchar = cg14_putchar_aa; |
1034 | } else | | 1034 | } else |
1035 | ri->ri_ops.putchar = cg14_putchar; | | 1035 | ri->ri_ops.putchar = cg14_putchar; |
1036 | } | | 1036 | } |
1037 | #endif /* NSX > 0 */ | | 1037 | #endif /* NSX > 0 */ |
1038 | } | | 1038 | } |
1039 | | | 1039 | |
1040 | static void | | 1040 | static void |
1041 | cg14_set_depth(struct cgfourteen_softc *sc, int depth) | | 1041 | cg14_set_depth(struct cgfourteen_softc *sc, int depth) |
1042 | { | | 1042 | { |
1043 | int i; | | 1043 | int i; |
1044 | | | 1044 | |
| | | 1045 | /* init mask */ |
| | | 1046 | if (sc->sc_sx != NULL) { |
| | | 1047 | sc->sc_mask = 0xffffffff; |
| | | 1048 | sx_write(sc->sc_sx, SX_QUEUED(R_MASK), sc->sc_mask); |
| | | 1049 | } |
| | | 1050 | |
1045 | if (sc->sc_depth == depth) | | 1051 | if (sc->sc_depth == depth) |
1046 | return; | | 1052 | return; |
1047 | | | 1053 | |
1048 | switch (depth) { | | 1054 | switch (depth) { |
1049 | case 8: | | 1055 | case 8: |
1050 | bus_space_write_1(sc->sc_bustag, sc->sc_regh, | | 1056 | bus_space_write_1(sc->sc_bustag, sc->sc_regh, |
1051 | CG14_MCTL, CG14_MCTL_ENABLEVID | | | 1057 | CG14_MCTL, CG14_MCTL_ENABLEVID | |
1052 | CG14_MCTL_PIXMODE_8 | CG14_MCTL_POWERCTL); | | 1058 | CG14_MCTL_PIXMODE_8 | CG14_MCTL_POWERCTL); |
1053 | sc->sc_depth = 8; | | 1059 | sc->sc_depth = 8; |
1054 | /* everything is CLUT1 */ | | 1060 | /* everything is CLUT1 */ |
1055 | for (i = 0; i < CG14_CLUT_SIZE; i++) | | 1061 | for (i = 0; i < CG14_CLUT_SIZE; i++) |
1056 | sc->sc_xlut->xlut_lut[i] = 0; | | 1062 | sc->sc_xlut->xlut_lut[i] = 0; |
1057 | break; | | 1063 | break; |
| @@ -1216,26 +1222,33 @@ cg14_rectfill(struct cgfourteen_softc *s | | | @@ -1216,26 +1222,33 @@ cg14_rectfill(struct cgfourteen_softc *s |
1216 | } | | 1222 | } |
1217 | } | | 1223 | } |
1218 | | | 1224 | |
1219 | static void | | 1225 | static void |
1220 | cg14_rectfill_a(void *cookie, int dstx, int dsty, | | 1226 | cg14_rectfill_a(void *cookie, int dstx, int dsty, |
1221 | int width, int height, long attr) | | 1227 | int width, int height, long attr) |
1222 | { | | 1228 | { |
1223 | struct cgfourteen_softc *sc = cookie; | | 1229 | struct cgfourteen_softc *sc = cookie; |
1224 | | | 1230 | |
1225 | cg14_rectfill(sc, dstx, dsty, width, height, | | 1231 | cg14_rectfill(sc, dstx, dsty, width, height, |
1226 | sc->sc_vd.active->scr_ri.ri_devcmap[(attr >> 24 & 0xf)]); | | 1232 | sc->sc_vd.active->scr_ri.ri_devcmap[(attr >> 24 & 0xf)]); |
1227 | } | | 1233 | } |
1228 | | | 1234 | |
| | | 1235 | static inline void |
| | | 1236 | cg14_set_mask(struct cgfourteen_softc *sc, uint32_t mask) |
| | | 1237 | { |
| | | 1238 | if (mask == sc->sc_mask) return; |
| | | 1239 | sc->sc_mask = mask; |
| | | 1240 | sx_write(sc->sc_sx, SX_QUEUED(R_MASK), mask); |
| | | 1241 | } |
1229 | /* | | 1242 | /* |
1230 | * invert a rectangle, used only to (un)draw the cursor. | | 1243 | * invert a rectangle, used only to (un)draw the cursor. |
1231 | * - does a scanline at a time | | 1244 | * - does a scanline at a time |
1232 | * - does not handle wi > 64 or wi < 4, not that we need it for our fonts | | 1245 | * - does not handle wi > 64 or wi < 4, not that we need it for our fonts |
1233 | * - uses all 32bit accesses | | 1246 | * - uses all 32bit accesses |
1234 | */ | | 1247 | */ |
1235 | static void | | 1248 | static void |
1236 | cg14_invert(struct cgfourteen_softc *sc, int x, int y, int wi, int he) | | 1249 | cg14_invert(struct cgfourteen_softc *sc, int x, int y, int wi, int he) |
1237 | { | | 1250 | { |
1238 | uint32_t addr, pptr, lmask, rmask; | | 1251 | uint32_t addr, pptr, lmask, rmask; |
1239 | int line, cnt, pre, words, pwrds = 0, post, reg; | | 1252 | int line, cnt, pre, words, pwrds = 0, post, reg; |
1240 | int stride = sc->sc_fb.fb_type.fb_width; | | 1253 | int stride = sc->sc_fb.fb_type.fb_width; |
1241 | | | 1254 | |
| @@ -1248,47 +1261,47 @@ cg14_invert(struct cgfourteen_softc *sc, | | | @@ -1248,47 +1261,47 @@ cg14_invert(struct cgfourteen_softc *sc, |
1248 | pre = x & 3; | | 1261 | pre = x & 3; |
1249 | if (pre != 0) { | | 1262 | if (pre != 0) { |
1250 | lmask = 0xffffffff >> pre; | | 1263 | lmask = 0xffffffff >> pre; |
1251 | pre = 4 - pre; | | 1264 | pre = 4 - pre; |
1252 | pwrds++; | | 1265 | pwrds++; |
1253 | } | | 1266 | } |
1254 | post = (x + wi) & 3; | | 1267 | post = (x + wi) & 3; |
1255 | if (post != 0) { | | 1268 | if (post != 0) { |
1256 | rmask = ~(0xffffffff >> post); | | 1269 | rmask = ~(0xffffffff >> post); |
1257 | pwrds++; | | 1270 | pwrds++; |
1258 | } | | 1271 | } |
1259 | words = (wi + pre + 3) >> 2; | | 1272 | words = (wi + pre + 3) >> 2; |
1260 | cnt = words - pwrds; | | 1273 | cnt = words - pwrds; |
1261 | sx_write(sc->sc_sx, SX_QUEUED(7), 0xe0e0e0e0); /* four red pixels */ | | 1274 | |
1262 | for (line = 0; line < he; line++) { | | 1275 | for (line = 0; line < he; line++) { |
1263 | pptr = addr; | | 1276 | pptr = addr; |
1264 | /* load a whole scanline */ | | 1277 | /* load a whole scanline */ |
1265 | sta(pptr & ~7, ASI_SX, SX_LD(8, words - 1, pptr & 7)); | | 1278 | sta(pptr & ~7, ASI_SX, SX_LD(8, words - 1, pptr & 7)); |
1266 | reg = 8; | | 1279 | reg = 8; |
1267 | if (pre) { | | 1280 | if (pre) { |
1268 | sx_write(sc->sc_sx, SX_QUEUED(R_MASK), lmask); | | 1281 | cg14_set_mask(sc, lmask); |
1269 | sx_write(sc->sc_sx, SX_INSTRUCTIONS, | | 1282 | sx_write(sc->sc_sx, SX_INSTRUCTIONS, |
1270 | SX_ROPB(8, 8, 40, 0)); | | 1283 | SX_ROPB(8, 8, 40, 0)); |
1271 | reg++; | | 1284 | reg++; |
1272 | } | | 1285 | } |
1273 | if (cnt > 0) { | | 1286 | if (cnt > 0) { |
1274 | sx_write(sc->sc_sx, SX_QUEUED(R_MASK), 0xffffffff); | | 1287 | cg14_set_mask(sc, 0xffffffff); |
1275 | /* XXX handle cnt > 16 */ | | 1288 | /* XXX handle cnt > 16 */ |
1276 | sx_write(sc->sc_sx, SX_INSTRUCTIONS, | | 1289 | sx_write(sc->sc_sx, SX_INSTRUCTIONS, |
1277 | SX_ROP(reg, reg, reg + 32, cnt - 1)); | | 1290 | SX_ROP(reg, reg, reg + 32, cnt - 1)); |
1278 | reg += cnt; | | 1291 | reg += cnt; |
1279 | } | | 1292 | } |
1280 | if (post) { | | 1293 | if (post) { |
1281 | sx_write(sc->sc_sx, SX_QUEUED(R_MASK), rmask); | | 1294 | cg14_set_mask(sc, rmask); |
1282 | sx_write(sc->sc_sx, SX_INSTRUCTIONS, | | 1295 | sx_write(sc->sc_sx, SX_INSTRUCTIONS, |
1283 | SX_ROPB(reg, 7, reg + 32, 0)); | | 1296 | SX_ROPB(reg, 7, reg + 32, 0)); |
1284 | reg++; | | 1297 | reg++; |
1285 | } | | 1298 | } |
1286 | sta(pptr & ~7, ASI_SX, SX_ST(40, words - 1, pptr & 7)); | | 1299 | sta(pptr & ~7, ASI_SX, SX_ST(40, words - 1, pptr & 7)); |
1287 | addr += stride; | | 1300 | addr += stride; |
1288 | } | | 1301 | } |
1289 | } | | 1302 | } |
1290 | | | 1303 | |
1291 | static inline void | | 1304 | static inline void |
1292 | cg14_slurp(int reg, uint32_t addr, int cnt) | | 1305 | cg14_slurp(int reg, uint32_t addr, int cnt) |
1293 | { | | 1306 | { |
1294 | int num; | | 1307 | int num; |
| @@ -1490,41 +1503,39 @@ cg14_putchar(void *cookie, int row, int | | | @@ -1490,41 +1503,39 @@ cg14_putchar(void *cookie, int row, int |
1490 | | | 1503 | |
1491 | sx_write(sc->sc_sx, SX_QUEUED(8), bg); | | 1504 | sx_write(sc->sc_sx, SX_QUEUED(8), bg); |
1492 | sx_write(sc->sc_sx, SX_QUEUED(9), fg); | | 1505 | sx_write(sc->sc_sx, SX_QUEUED(9), fg); |
1493 | | | 1506 | |
1494 | data = WSFONT_GLYPH(c, font); | | 1507 | data = WSFONT_GLYPH(c, font); |
1495 | addr = sc->sc_fb_paddr + x + stride * y; | | 1508 | addr = sc->sc_fb_paddr + x + stride * y; |
1496 | | | 1509 | |
1497 | switch (font->stride) { | | 1510 | switch (font->stride) { |
1498 | case 1: { | | 1511 | case 1: { |
1499 | uint8_t *data8 = data; | | 1512 | uint8_t *data8 = data; |
1500 | uint32_t reg; | | 1513 | uint32_t reg; |
1501 | for (i = 0; i < he; i++) { | | 1514 | for (i = 0; i < he; i++) { |
1502 | reg = *data8; | | 1515 | reg = *data8; |
1503 | sx_write(sc->sc_sx, SX_QUEUED(R_MASK), | | 1516 | cg14_set_mask(sc, reg << 24); |
1504 | reg << 24); | | | |
1505 | sta(addr & ~7, ASI_SX, SX_STBS(8, wi - 1, addr & 7)); | | 1517 | sta(addr & ~7, ASI_SX, SX_STBS(8, wi - 1, addr & 7)); |
1506 | data8++; | | 1518 | data8++; |
1507 | addr += stride; | | 1519 | addr += stride; |
1508 | } | | 1520 | } |
1509 | break; | | 1521 | break; |
1510 | } | | 1522 | } |
1511 | case 2: { | | 1523 | case 2: { |
1512 | uint16_t *data16 = data; | | 1524 | uint16_t *data16 = data; |
1513 | uint32_t reg; | | 1525 | uint32_t reg; |
1514 | for (i = 0; i < he; i++) { | | 1526 | for (i = 0; i < he; i++) { |
1515 | reg = *data16; | | 1527 | reg = *data16; |
1516 | sx_write(sc->sc_sx, SX_QUEUED(R_MASK), | | 1528 | cg14_set_mask(sc, reg << 16); |
1517 | reg << 16); | | | |
1518 | sta(addr & ~7, ASI_SX, SX_STBS(8, wi - 1, addr & 7)); | | 1529 | sta(addr & ~7, ASI_SX, SX_STBS(8, wi - 1, addr & 7)); |
1519 | data16++; | | 1530 | data16++; |
1520 | addr += stride; | | 1531 | addr += stride; |
1521 | } | | 1532 | } |
1522 | break; | | 1533 | break; |
1523 | } | | 1534 | } |
1524 | } | | 1535 | } |
1525 | if (attr & 1) | | 1536 | if (attr & 1) |
1526 | cg14_rectfill(sc, x, y + he - 2, wi, 1, fg); | | 1537 | cg14_rectfill(sc, x, y + he - 2, wi, 1, fg); |
1527 | } | | 1538 | } |
1528 | | | 1539 | |
1529 | static void | | 1540 | static void |
1530 | cg14_cursor(void *cookie, int on, int row, int col) | | 1541 | cg14_cursor(void *cookie, int on, int row, int col) |