vgabios: Unify page size calculations; remove page size from vgamode_s.
The previous code could obtain the page size in different ways - from
vmode_g->sslength, from SCREEN_MEM_START, or by manually multiplying
cols and rows. Add a new func (calc_page_size) and use that in areas
that need to calculate the page size.
Convert readers of the page size to read it from the "video_pagesize"
entry in the BDA instead of recalculating it.
Remove the page size from struct vgamode_s (slength) as it is now
calculated dynamically. The new calculated versions are different
from the existing values exported in video_param_table. However, the
existing values (for CGA) did not look correct - I compared the values
to those exported by two other VGA BIOS manufacturers and used the
values that look more standard.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
diff --git a/vgasrc/vgafb.c b/vgasrc/vgafb.c
index eb4ced8..b933738 100644
--- a/vgasrc/vgafb.c
+++ b/vgasrc/vgafb.c
@@ -139,10 +139,8 @@
{
int cheight = 1;
int cwidth = 2;
- u16 nbrows = GET_BDA(video_rows) + 1;
- u16 nbcols = GET_BDA(video_cols);
- int stride = nbcols * cwidth;
- void *src_far, *dest_far = (void*)SCREEN_MEM_START(nbcols, nbrows, ul.page);
+ int stride = GET_BDA(video_cols) * cwidth;
+ void *src_far, *dest_far = (void*)(GET_BDA(video_pagesize) * ul.page);
if (nblines >= 0) {
dest_far += ul.y * cheight * stride + ul.x * cwidth;
src_far = dest_far + nblines * cheight * stride;
@@ -330,12 +328,9 @@
write_text_char(struct vgamode_s *vmode_g
, struct cursorpos cp, struct carattr ca)
{
- // Get the dimensions
- u16 nbrows = GET_BDA(video_rows) + 1;
- u16 nbcols = GET_BDA(video_cols);
-
// Compute the address
- void *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, cp.page)
+ u16 nbcols = GET_BDA(video_cols);
+ void *address_far = (void*)(GET_BDA(video_pagesize) * cp.page
+ (cp.x + cp.y * nbcols) * 2);
if (ca.use_attr) {
@@ -386,12 +381,9 @@
goto fail;
}
- // Get the dimensions
- u16 nbrows = GET_BDA(video_rows) + 1;
- u16 nbcols = GET_BDA(video_cols);
-
// Compute the address
- u16 *address_far = (void*)(SCREEN_MEM_START(nbcols, nbrows, cp.page)
+ u16 nbcols = GET_BDA(video_cols);
+ u16 *address_far = (void*)(GET_BDA(video_pagesize) * cp.page
+ (cp.x + cp.y * nbcols) * 2);
u16 v = GET_FARVAR(GET_GLOBAL(vmode_g->sstart), *address_far);
struct carattr ca = {v, v>>8, 0};