static void
set_cursor_pos(struct cursorpos cp)
{
+ u8 page = cp.page, x = cp.x, y = cp.y;
+
// Should not happen...
- if (cp.page > 7)
+ if (page > 7)
return;
// Bios cursor pos
- SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
+ SET_BDA(cursor_pos[page], (y << 8) | x);
// Set the hardware cursor
u8 current = GET_BDA(video_page);
return;
// Calculate the memory address
- int address = (GET_BDA(video_pagesize) * cp.page
- + (cp.x + cp.y * GET_BDA(video_cols)) * 2);
+ int address = (GET_BDA(video_pagesize) * page
+ + (x + y * GET_BDA(video_cols)) * 2);
stdvga_set_cursor_pos(address);
}
cp.y++;
break;
case '\t':
+ ca.car = ' ';
do {
- struct carattr dummyca = {' ', ca.attr, ca.use_attr};
- vgafb_write_char(cp, dummyca);
+ vgafb_write_char(cp, ca);
cp.x++;
} while (cp.x < nbcols && cp.x % 8);
break;
scroll_one(nbrows, nbcols, cp.page);
}
-// Write out a buffer of alternating characters and attributes.
-static void
-write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
-{
- while (count--) {
- u8 car = GET_FARVAR(seg, *offset_far);
- offset_far++;
- u8 attr = GET_FARVAR(seg, *offset_far);
- offset_far++;
-
- struct carattr ca = {car, attr, 1};
- write_teletype(pcp, ca);
- }
-}
-
-// Write out a buffer of characters.
-static void
-write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
-{
- while (count--) {
- u8 car = GET_FARVAR(seg, *offset_far);
- offset_far++;
-
- struct carattr ca = {car, attr, 1};
- write_teletype(pcp, ca);
- }
-}
-
/****************************************************************
* Save and restore bda state
static void
verify_scroll(struct bregs *regs, int dir)
{
- u8 page = GET_BDA(video_page);
- struct cursorpos ul = {regs->cl, regs->ch, page};
- struct cursorpos lr = {regs->dl, regs->dh, page};
-
+ u8 ulx = regs->cl, uly = regs->ch, lrx = regs->dl, lry = regs->dh;
u16 nbrows = GET_BDA(video_rows) + 1;
- if (lr.y >= nbrows)
- lr.y = nbrows - 1;
+ if (lry >= nbrows)
+ lry = nbrows - 1;
u16 nbcols = GET_BDA(video_cols);
- if (lr.x >= nbcols)
- lr.x = nbcols - 1;
+ if (lrx >= nbcols)
+ lrx = nbcols - 1;
- if (ul.x > lr.x || ul.y > lr.y)
+ if (ulx > lrx || uly > lry)
return;
- u16 nblines = regs->al;
- if (!nblines || nblines > lr.y - ul.y + 1)
- nblines = lr.y - ul.y + 1;
+ int nblines = regs->al;
+ if (!nblines || nblines > lry - uly + 1)
+ nblines = lry - uly + 1;
+ u8 page = GET_BDA(video_page);
+ struct cursorpos ul = {ulx, uly, page};
+ struct cursorpos lr = {lrx, lry, page};
vgafb_scroll(dir * nblines, regs->bh, ul, lr);
}
static void noinline
handle_1013(struct bregs *regs)
{
- struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
- // if row=0xff special case : use current cursor position
- if (cp.y == 0xff)
- cp = get_cursor_pos(cp.page);
- u8 flag = regs->al;
- if (flag & 2)
- write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
+ struct cursorpos cp;
+ if (regs->dh == 0xff)
+ // if row=0xff special case : use current cursor position
+ cp = get_cursor_pos(regs->bh);
else
- write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
+ cp = (struct cursorpos) {regs->dl, regs->dh, regs->bh};
+
+ u16 count = regs->cx;
+ u8 *offset_far = (void*)(regs->bp + 0);
+ u8 attr = regs->bl;
+ while (count--) {
+ u8 car = GET_FARVAR(regs->es, *offset_far);
+ offset_far++;
+ if (regs->al & 2) {
+ attr = GET_FARVAR(regs->es, *offset_far);
+ offset_far++;
+ }
+
+ struct carattr ca = {car, attr, 1};
+ write_teletype(&cp, ca);
+ }
- if (flag & 1)
+ if (regs->al & 1)
set_cursor_pos(cp);
}