import mbdata
import framebuffer
import "font/font.ort"
type VGABox is packed
byte char
byte attrs
function(VGABox a, VGABox b) VGABox:__eq__ -> bool does
if a.char!=b.char do
return 0|bool
elif a.attrs!=b.attrs do
return 0|bool
done
return 1|bool
function(VGABox a, VGABox b) VGABox:__ne__ -> bool does
if a.char==b.char do
if a.attrs==b.attrs do
return 0|bool
done
done
return 1|bool
endtype
type VGATextModeEmulator is
ptr text_fb
ptr old_text_fb
int bufsz
Framebuffer out
int vga_w
int vga_h
int fontsz
function(Framebuffer screen) VGATextModeEmulator::new -> VGATextModeEmulator does
VGATextModeEmulator new=malloc(@sizeof(VGATextModeEmulator)@)|VGATextModeEmulator
new.fontsz=8
new.vga_w=screen.w/new.fontsz
new.vga_h=screen.h/new.fontsz
int bsz=new.vga_w*(new.vga_h+1)*2
new.bufsz=bsz
new.text_fb=malloc(bsz)
new.old_text_fb=malloc(bsz)
memset(new.text_fb, bsz, 0|byte)
memset(new.old_text_fb, bsz, 0|byte)
new.out=screen
return new
function(VGATextModeEmulator e) VGATextModeEmulator:clear -> void does
e.out:fill(0,0,0)
return
function(VGATextModeEmulator e) VGATextModeEmulator:update -> void does
int y=0
int x
int pos
ptr colors=get_colors()
int char
int bgcolor
int fgcolor
while y<e.vga_h do
x=0
while x<e.vga_w do
pos=(y*e.vga_w*2)+(x*2)
if (e.text_fb:offset(pos)|VGABox)!=(e.old_text_fb:offset(pos)|VGABox) do
char=e.text_fb[pos]|int
bgcolor=((e.text_fb[pos+1]|int)>>4)*3
fgcolor=((e.text_fb[pos+1]|int)&0b1111)*3
e.out:fillrect(x*(e.fontsz), y*e.fontsz, e.fontsz, e.fontsz, colors[bgcolor]|int, colors[bgcolor+1]|int, colors[bgcolor+2]|int)
e.out:drawchar(x*(e.fontsz), y*e.fontsz, e.fontsz, char, colors[fgcolor]|int, colors[fgcolor+1]|int, colors[fgcolor+2]|int)
done
x+=1
done
y+=1
done
memcpy(e.text_fb, e.old_text_fb, e.bufsz)
return
endtype
VGATextModeEmulator console_emulator
Framebuffer console_fb
function(MultibootInfo mbinfo) init_emulator -> void does
console_fb=Framebuffer::from_mbinfo(mbinfo)
console_emulator=VGATextModeEmulator::new(console_fb)
console_emulator:clear()
return
function() _update_framebuffer -> void does
console_emulator:update()
return