diff --git a/kernel/driver/tty/vt.go b/kernel/driver/tty/vt.go index 20afa6e..8ecd2a5 100644 --- a/kernel/driver/tty/vt.go +++ b/kernel/driver/tty/vt.go @@ -12,7 +12,7 @@ const ( type Vt struct { // Go interfaces will not work before we can get memory allocation working. // Till then we need to use concrete types instead. - cons *console.Vga + cons *console.Ega width uint16 height uint16 @@ -22,7 +22,9 @@ type Vt struct { curAttr console.Attr } -func (t *Vt) Init(cons *console.Vga) { +// AttachTo links the terminal with the specified console device and updates +// the terminal's dimensions to match the ones reported by the attached device. +func (t *Vt) AttachTo(cons *console.Ega) { t.cons = cons t.width, t.height = cons.Dimensions() t.curX = 0 @@ -30,30 +32,20 @@ func (t *Vt) Init(cons *console.Vga) { // Default to lightgrey on black text. t.curAttr = makeAttr(defaultFg, defaultBg) - } // Clear clears the terminal. func (t *Vt) Clear() { - t.cons.Lock() - defer t.cons.Unlock() - t.clear() } // Position returns the current cursor position (x, y). func (t *Vt) Position() (uint16, uint16) { - t.cons.Lock() - defer t.cons.Unlock() - return t.curX, t.curY } // SetPosition sets the current cursor position to (x,y). func (t *Vt) SetPosition(x, y uint16) { - t.cons.Lock() - defer t.cons.Unlock() - if x >= t.width { x = t.width - 1 } @@ -67,9 +59,6 @@ func (t *Vt) SetPosition(x, y uint16) { // Write implements io.Writer. func (t *Vt) Write(data []byte) (int, error) { - t.cons.Lock() - defer t.cons.Unlock() - attr := t.curAttr for _, b := range data { switch b { diff --git a/kernel/driver/tty/vt_test.go b/kernel/driver/tty/vt_test.go index 9d6f4f9..19233b0 100644 --- a/kernel/driver/tty/vt_test.go +++ b/kernel/driver/tty/vt_test.go @@ -2,6 +2,7 @@ package tty import ( "testing" + "unsafe" "github.com/achilleasa/gopher-os/kernel/driver/video/console" ) @@ -18,11 +19,12 @@ func TestVtPosition(t *testing.T) { {100, 100, 79, 24}, } - var cons console.Vga - cons.Init() + fb := make([]uint16, 80*25) + var cons console.Ega + cons.Init(80, 25, uintptr(unsafe.Pointer(&fb[0]))) var vt Vt - vt.Init(&cons) + vt.AttachTo(&cons) for specIndex, spec := range specs { vt.SetPosition(spec.inX, spec.inY) @@ -34,12 +36,11 @@ func TestVtPosition(t *testing.T) { func TestWrite(t *testing.T) { fb := make([]uint16, 80*25) - cons := &console.Vga{} - cons.OverrideFb(fb) - cons.Init() + var cons console.Ega + cons.Init(80, 25, uintptr(unsafe.Pointer(&fb[0]))) var vt Vt - vt.Init(cons) + vt.AttachTo(&cons) vt.Clear() vt.SetPosition(0, 1) diff --git a/kernel/driver/video/console/console.go b/kernel/driver/video/console/console.go index 8762d70..0b2cf1f 100644 --- a/kernel/driver/video/console/console.go +++ b/kernel/driver/video/console/console.go @@ -1,7 +1,5 @@ package console -import "sync" - // Attr defines a color attribute. type Attr uint16 @@ -36,8 +34,6 @@ const ( // The Console interface is implemented by objects that can function as physical consoles. type Console interface { - sync.Locker - // Dimensions returns the width and height of the console in characters. Dimensions() (uint16, uint16) diff --git a/kernel/driver/video/console/ega.go b/kernel/driver/video/console/ega.go index 87a6d35..3ed939e 100644 --- a/kernel/driver/video/console/ega.go +++ b/kernel/driver/video/console/ega.go @@ -2,7 +2,6 @@ package console import ( "reflect" - "sync" "unsafe" ) @@ -16,8 +15,6 @@ const ( // allocator, each console will use its own framebuffer while the active console // will periodically sync its internal buffer with the physical screen buffer. type Ega struct { - sync.Mutex - width uint16 height uint16