Because I have a laptop that needs it.

ok?

Index: dev/rasops/rasops.c
===================================================================
RCS file: /cvs/src/sys/dev/rasops/rasops.c,v
retrieving revision 1.46
diff -u -p -r1.46 rasops.c
--- dev/rasops/rasops.c 13 Aug 2017 22:28:23 -0000      1.46
+++ dev/rasops/rasops.c 13 Aug 2017 23:37:31 -0000
@@ -150,7 +150,7 @@ int rasops_copyrows_rotated(void *, int,
 int    rasops_erasecols_rotated(void *, int, int, int, long);
 int    rasops_eraserows_rotated(void *, int, int, long);
 int    rasops_putchar_rotated(void *, int, int, u_int, long);
-void   rasops_rotate_font(int *);
+void   rasops_rotate_font(int *, int);
 
 /*
  * List of all rotated fonts
@@ -218,8 +218,9 @@ rasops_init(struct rasops_info *ri, int 
                 * Pick the rotated version of this font. This will create it
                 * if necessary.
                 */
-               if (ri->ri_flg & RI_ROTATE_CW)
-                       rasops_rotate_font(&cookie);
+               if (ri->ri_flg & (RI_ROTATE_CW | RI_ROTATE_CCW))
+                       rasops_rotate_font(&cookie,
+                           ISSET(ri->ri_flg, RI_ROTATE_CCW));
 #endif
 
                if (wsfont_lock(cookie, &ri->ri_font,
@@ -341,7 +342,7 @@ rasops_reconfig(struct rasops_info *ri, 
                ri->ri_emuwidth--;
 
 #if NRASOPS_ROTATION > 0
-       if (ri->ri_flg & RI_ROTATE_CW) {
+       if (ri->ri_flg & (RI_ROTATE_CW | RI_ROTATE_CCW)) {
                ri->ri_rows = ri->ri_emuwidth / ri->ri_font->fontwidth;
                ri->ri_cols = ri->ri_emuheight / ri->ri_font->fontheight;
        } else
@@ -460,7 +461,7 @@ rasops_reconfig(struct rasops_info *ri, 
        }
 
 #if NRASOPS_ROTATION > 0
-       if (ri->ri_flg & RI_ROTATE_CW) {
+       if (ri->ri_flg & (RI_ROTATE_CW | RI_ROTATE_CCW)) {
                ri->ri_real_ops = ri->ri_ops;
                ri->ri_ops.copycols = rasops_copycols_rotated;
                ri->ri_ops.copyrows = rasops_copyrows_rotated;
@@ -958,7 +959,11 @@ rasops_do_cursor(struct rasops_info *ri)
                /* Rotate rows/columns */
                row = ri->ri_ccol;
                col = ri->ri_rows - ri->ri_crow - 1;
-       } else
+       } else if (ri->ri_flg & RI_ROTATE_CCW) {
+               /* Rotate rows/columns */
+               row = ri->ri_cols - ri->ri_ccol - 1;
+               col = ri->ri_crow;
+       } else          
 #endif
        {
                row = ri->ri_crow;
@@ -1153,7 +1158,7 @@ rasops_erasecols(void *cookie, int row, 
 #include <sys/malloc.h>
 
 void
-rasops_rotate_font(int *cookie)
+rasops_rotate_font(int *cookie, int ccw)
 {
        struct rotatedfont *f;
        int ncookie;
@@ -1169,7 +1174,7 @@ rasops_rotate_font(int *cookie)
         * We did not find a rotated version of this font. Ask the wsfont
         * code to compute one for us.
         */
-       if ((ncookie = wsfont_rotate(*cookie)) == -1)
+       if ((ncookie = wsfont_rotate(*cookie, ccw)) == -1)
                return;
 
        f = malloc(sizeof(struct rotatedfont), M_DEVBUF, M_WAITOK);
@@ -1230,15 +1235,18 @@ rasops_putchar_rotated(void *cookie, int
 
        ri = (struct rasops_info *)cookie;
 
+       if (ri->ri_flg & RI_ROTATE_CW)
+               row = ri->ri_rows - row - 1;
+       else
+               col = ri->ri_cols - col - 1;
+
        /* Do rotated char sans (side)underline */
-       rc = ri->ri_real_ops.putchar(cookie, col, ri->ri_rows - row - 1, uc,
-           attr & ~1);
+       rc = ri->ri_real_ops.putchar(cookie, col, row, uc, attr & ~1);
        if (rc != 0)
                return rc;
 
        /* Do rotated underline */
-       rp = ri->ri_bits + col * ri->ri_yscale + (ri->ri_rows - row - 1) * 
-           ri->ri_xscale;
+       rp = ri->ri_bits + col * ri->ri_yscale + row * ri->ri_xscale;
        height = ri->ri_font->fontheight;
 
        /* XXX this assumes 16-bit color depth */
Index: dev/rasops/rasops.h
===================================================================
RCS file: /cvs/src/sys/dev/rasops/rasops.h,v
retrieving revision 1.18
diff -u -p -r1.18 rasops.h
--- dev/rasops/rasops.h 15 Dec 2016 19:18:41 -0000      1.18
+++ dev/rasops/rasops.h 13 Aug 2017 23:37:31 -0000
@@ -52,10 +52,11 @@ struct wsdisplay_font;
 #define        RI_CLEARMARGINS 0x0020  /* clear display margins on startup */
 #define RI_CENTER      0x0040  /* center onscreen output */
 #define RI_CURSORCLIP  0x0080  /* cursor is currently clipped */
-#define        RI_ROTATE_CW    0x0100  /* display is rotated, quarter 
clockwise */
-#define RI_CFGDONE     0x0200  /* rasops_reconfig() completed successfully */
-#define RI_VCONS       0x0400  /* virtual consoles */
-#define RI_WRONLY      0x0800  /* avoid framebuffer reads */
+#define RI_ROTATE_CW   0x0100  /* display is rotated, 90 deg clockwise */
+#define RI_ROTATE_CCW  0x0200  /* display is rotated, 90 deg anti-clockwise */
+#define RI_CFGDONE     0x0400  /* rasops_reconfig() completed successfully */
+#define RI_VCONS       0x0800  /* virtual consoles */
+#define RI_WRONLY      0x1000  /* avoid framebuffer reads */
 
 struct rasops_screen;
 
Index: dev/wsfont/wsfont.c
===================================================================
RCS file: /cvs/src/sys/dev/wsfont/wsfont.c,v
retrieving revision 1.48
diff -u -p -r1.48 wsfont.c
--- dev/wsfont/wsfont.c 30 May 2017 13:14:44 -0000      1.48
+++ dev/wsfont/wsfont.c 13 Aug 2017 23:37:31 -0000
@@ -231,25 +231,14 @@ wsfont_enum(int (*cb)(void *, struct wsd
 
 #if NRASOPS_ROTATION > 0
 
-struct wsdisplay_font *wsfont_rotate_internal(struct wsdisplay_font *);
+void wsfont_rotate_cw(struct wsdisplay_font *, char *, int);
+void wsfont_rotate_ccw(struct wsdisplay_font *, char *, int);
+struct wsdisplay_font *wsfont_rotate_internal(struct wsdisplay_font *, int);
 
-struct wsdisplay_font *
-wsfont_rotate_internal(struct wsdisplay_font *font)
+void
+wsfont_rotate_cw(struct wsdisplay_font *font, char *newbits, int newstride)
 {
-       int b, n, r, newstride;
-       struct wsdisplay_font *newfont;
-       char *newbits;
-
-       /* Duplicate the existing font... */
-       newfont = malloc(sizeof *font, M_DEVBUF, M_WAITOK);
-
-       bcopy(font, newfont, sizeof *font);
-       newfont->cookie = NULL;
-
-       /* Allocate a buffer big enough for the rotated font. */
-       newstride = (font->fontheight + 7) / 8;
-       newbits = mallocarray(font->numchars, newstride * font->fontwidth,
-           M_DEVBUF, M_WAITOK | M_ZERO);
+       int b, n, r;
 
        /* Rotate the font a bit at a time. */
        for (n = 0; n < font->numchars; n++) {
@@ -271,6 +260,58 @@ wsfont_rotate_internal(struct wsdisplay_
                        }
                }
        }
+}
+
+void
+wsfont_rotate_ccw(struct wsdisplay_font *font, char *newbits, int newstride)
+{
+       int b, n, r;
+
+       /* Rotate the font a bit at a time. */
+       for (n = 0; n < font->numchars; n++) {
+               char *ch = font->data + (n * font->stride * font->fontheight);
+
+               for (r = 0; r < font->fontheight; r++) {
+                       for (b = 0; b < font->fontwidth; b++) {
+                               int bb = font->fontwidth - 1 - b;
+                               unsigned char *rb;
+
+                               rb = ch + (font->stride * r) + (b / 8);
+                               if (*rb & (0x80 >> (b % 8))) {
+                                       unsigned char *rrb;
+
+                                       rrb = newbits + (r / 8)
+                                           + (n * newstride * font->fontwidth)
+                                           + (newstride * bb);
+                                       *rrb |= (1 << (7 - (r % 8)));
+                               }
+                       }
+               }
+       }
+}
+
+struct wsdisplay_font *
+wsfont_rotate_internal(struct wsdisplay_font *font, int ccw)
+{
+       int newstride;
+       struct wsdisplay_font *newfont;
+       char *newbits;
+
+       /* Duplicate the existing font... */
+       newfont = malloc(sizeof *font, M_DEVBUF, M_WAITOK);
+
+       bcopy(font, newfont, sizeof *font);
+       newfont->cookie = NULL;
+
+       /* Allocate a buffer big enough for the rotated font. */
+       newstride = (font->fontheight + 7) / 8;
+       newbits = mallocarray(font->numchars, newstride * font->fontwidth,
+           M_DEVBUF, M_WAITOK | M_ZERO);
+
+       if (ccw)
+               wsfont_rotate_ccw(font, newbits, newstride);
+       else
+               wsfont_rotate_cw(font, newbits, newstride);
 
        newfont->data = newbits;
 
@@ -294,7 +335,7 @@ wsfont_rotate_internal(struct wsdisplay_
 }
 
 int
-wsfont_rotate(int cookie)
+wsfont_rotate(int cookie, int ccw)
 {
        int s, ncookie;
        struct wsdisplay_font *font;
@@ -304,7 +345,7 @@ wsfont_rotate(int cookie)
        origfont = wsfont_find0(cookie);
        splx(s);
 
-       font = wsfont_rotate_internal(origfont->font);
+       font = wsfont_rotate_internal(origfont->font, ccw);
        if (font == NULL)
                return (-1);
 
Index: dev/wsfont/wsfont.h
===================================================================
RCS file: /cvs/src/sys/dev/wsfont/wsfont.h,v
retrieving revision 1.10
diff -u -p -r1.10 wsfont.h
--- dev/wsfont/wsfont.h 20 Oct 2013 21:24:01 -0000      1.10
+++ dev/wsfont/wsfont.h 13 Aug 2017 23:37:31 -0000
@@ -73,6 +73,6 @@ void  wsfont_enum(int (*)(void *, struct 
 int    wsfont_lock(int, struct wsdisplay_font **, int, int);
 int    wsfont_unlock(int);
 int    wsfont_map_unichar(struct wsdisplay_font *, int);
-int    wsfont_rotate(int);
+int    wsfont_rotate(int, int);
 
 #endif /* !_WSFONT_H_ */

Reply via email to