diff options
author | Richard Braun <rbraun@sceen.net> | 2017-06-23 23:24:10 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-06-23 23:24:10 +0200 |
commit | eb68987d17b97e1f9e7a387e962bfcc8114873a3 (patch) | |
tree | e3493cac7473da0e8e6d0252f5e71e96afdf9776 | |
parent | f880f11cfa1d0c309b63a19e71c0033f45dc3122 (diff) |
x86/cga: minor checks and improvements
-rw-r--r-- | arch/x86/machine/cga.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/arch/x86/machine/cga.c b/arch/x86/machine/cga.c index 7dca6edd..b59c40f5 100644 --- a/arch/x86/machine/cga.c +++ b/arch/x86/machine/cga.c @@ -82,6 +82,10 @@ static void *cga_memory __read_mostly; #define CGA_BACK_BUFFER_SIZE (64 * 1024) +#if CGA_BACK_BUFFER_SIZE < CGA_MEMORY_SIZE +#error "back buffer size must be at least as large as video memory" +#endif + #define CGA_SCROLL_PAGE ((CGA_LINES / 2) * CGA_MEMORY_LINE_SIZE) /* @@ -115,11 +119,9 @@ cga_get_cursor_position(void) { uint16_t tmp; - io_write_byte(CGA_PORT_CRTC_ADDR, - CGA_CRTC_CURSOR_LOC_HIGH_REG); + io_write_byte(CGA_PORT_CRTC_ADDR, CGA_CRTC_CURSOR_LOC_HIGH_REG); tmp = io_read_byte(CGA_PORT_CRTC_DATA) << 8; - io_write_byte(CGA_PORT_CRTC_ADDR, - CGA_CRTC_CURSOR_LOC_LOW_REG); + io_write_byte(CGA_PORT_CRTC_ADDR, CGA_CRTC_CURSOR_LOC_LOW_REG); tmp |= io_read_byte(CGA_PORT_CRTC_DATA); return tmp; @@ -394,10 +396,9 @@ cga_bbuf_scroll_down(struct cga_bbuf *bbuf) size_t end; bbuf->view += CGA_SCROLL_PAGE; + end = bbuf->view + CGA_MEMORY_SIZE; - end = bbuf->view + CGA_MEMORY_SIZE - cbuf_start(&bbuf->cbuf); - - if (end > cbuf_size(&bbuf->cbuf)) { + if (!cbuf_range_valid(&bbuf->cbuf, bbuf->view, end)) { bbuf->view = cbuf_end(&bbuf->cbuf) - CGA_MEMORY_SIZE; } |