diff --git a/src/gopheros/device/tty/vt.go b/src/gopheros/device/tty/vt.go index 9acadf3..71b85bf 100644 --- a/src/gopheros/device/tty/vt.go +++ b/src/gopheros/device/tty/vt.go @@ -61,7 +61,7 @@ func (t *VT) AttachTo(cons console.Device) { } t.cons = cons - t.viewportWidth, t.viewportHeight = cons.Dimensions() + t.viewportWidth, t.viewportHeight = cons.Dimensions(console.Characters) t.viewportY = 0 t.defaultFg, t.defaultBg = cons.DefaultColors() t.curFg, t.curBg = t.defaultFg, t.defaultBg diff --git a/src/gopheros/device/tty/vt_test.go b/src/gopheros/device/tty/vt_test.go index 066d25f..856e563 100644 --- a/src/gopheros/device/tty/vt_test.go +++ b/src/gopheros/device/tty/vt_test.go @@ -366,7 +366,7 @@ func newMockConsole(w, h uint32) *mockConsole { } } -func (cons *mockConsole) Dimensions() (uint32, uint32) { +func (cons *mockConsole) Dimensions(_ console.Dimension) (uint32, uint32) { return cons.width, cons.height } diff --git a/src/gopheros/device/video/console/device.go b/src/gopheros/device/video/console/device.go index c4891f1..c64c8b7 100644 --- a/src/gopheros/device/video/console/device.go +++ b/src/gopheros/device/video/console/device.go @@ -14,11 +14,25 @@ const ( ScrollDirDown ) +// Dimension defines the types of dimensions that can be queried off a device. +type Dimension uint8 + +const ( + // Characters describes the number of characters in + // the console depending on the currently active + // font. + Characters Dimension = iota + + // Pixels describes the number of pixels in the console framebuffer. + Pixels +) + // The Device interface is implemented by objects that can function as system // consoles. type Device interface { - // Dimensions returns the width and height of the console in characters. - Dimensions() (uint32, uint32) + // Pixel returns the width and height of the console + // using a particual dimension. + Dimensions(Dimension) (uint32, uint32) // DefaultColors returns the default foreground and background colors // used by this console. diff --git a/src/gopheros/device/video/console/vga_text.go b/src/gopheros/device/video/console/vga_text.go index 0215363..eee6737 100644 --- a/src/gopheros/device/video/console/vga_text.go +++ b/src/gopheros/device/video/console/vga_text.go @@ -70,9 +70,14 @@ func NewVgaTextConsole(columns, rows uint32, fbPhysAddr uintptr) *VgaTextConsole } } -// Dimensions returns the console width and height in characters. -func (cons *VgaTextConsole) Dimensions() (uint32, uint32) { - return cons.width, cons.height +// Dimensions returns the console width and height in the specified dimension. +func (cons *VgaTextConsole) Dimensions(dim Dimension) (uint32, uint32) { + switch dim { + case Characters: + return cons.width, cons.height + default: + return cons.width * 8, cons.height * 16 + } } // DefaultColors returns the default foreground and background colors diff --git a/src/gopheros/device/video/console/vga_text_test.go b/src/gopheros/device/video/console/vga_text_test.go index d18b9be..3cbb69d 100644 --- a/src/gopheros/device/video/console/vga_text_test.go +++ b/src/gopheros/device/video/console/vga_text_test.go @@ -15,9 +15,18 @@ import ( func TestVgaTextDimensions(t *testing.T) { var cons Device = NewVgaTextConsole(40, 50, 0) - if w, h := cons.Dimensions(); w != 40 || h != 50 { + if w, h := cons.Dimensions(Characters); w != 40 || h != 50 { t.Fatalf("expected console dimensions to be 80x25; got %dx%d", w, h) } + + var ( + expW uint32 = 40 * 8 + expH uint32 = 50 * 16 + ) + + if w, h := cons.Dimensions(Pixels); w != expW || h != expH { + t.Fatalf("expected console dimensions to be %dx%d; got %dx%d", expW, expH, w, h) + } } func TestVgaTextDefaultColors(t *testing.T) { @@ -68,7 +77,7 @@ func TestVgaTextFill(t *testing.T) { fb := make([]uint16, 80*25) cons := NewVgaTextConsole(80, 25, uintptr(unsafe.Pointer(&fb[0]))) cons.fb = fb - cw, ch := cons.Dimensions() + cw, ch := cons.Dimensions(Characters) testPat := uint16(0xDEAD) clearPat := uint16(cons.clearChar) @@ -107,7 +116,7 @@ func TestVgaTextScroll(t *testing.T) { fb := make([]uint16, 80*25) cons := NewVgaTextConsole(80, 25, uintptr(unsafe.Pointer(&fb[0]))) cons.fb = fb - cw, ch := cons.Dimensions() + cw, ch := cons.Dimensions(Characters) t.Run("up", func(t *testing.T) { specs := []uint32{