commit c3da35149ed08e395fc6680c071d43d38377ef8f
parent da927d2f98bc788bfa2543bf8fac7b7e40d8a7e5
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sun, 9 May 2021 21:49:03 +0000
do commit devfs.c, refactor richterm.c a bit
Diffstat:
M | devfs.c | | | 53 | +++++++++++++++++++++++++++++++++-------------------- |
M | richterm.c | | | 46 | +++++++++++++++++++++++++--------------------- |
2 files changed, 58 insertions(+), 41 deletions(-)
diff --git a/devfs.c b/devfs.c
@@ -6,34 +6,47 @@
#include "richterm.h"
+File *cons, *consctl;
+
void
devfs_read(Req *r)
{
+ File *f;
Devfsctl *dctl;
int kv;
- dctl = r->fid->file->aux;
- recv(dctl->rc, &kv);
- r->ofcall.count = 1; //sizeof(int);
- memcpy(r->ofcall.data, &kv, 1);
- respond(r, nil);
+ f = r->fid->file;
+ dctl = f->aux;
+ if (f == cons) {
+ recv(dctl->rc, &kv);
+ r->ofcall.count = 1; //sizeof(int);
+ memcpy(r->ofcall.data, &kv, 1);
+ respond(r, nil);
+ } else if (f == consctl) {
+ respond(r, "not implemented");
+ }
+ else respond(r, "what");
}
void
devfs_write(Req *r)
{
+ File *f;
Devfsctl *dctl;
Object obj;
- dctl = r->fid->file->aux;
- if (dctl == nil) sysfatal("dctl is nil");
- if (dctl->wc == nil) sysfatal("dctl->wc is nil");
- obj.type = strdup("text");
- obj.opts = strdup("");
- obj.count = r->ifcall.count + 1;
- obj.data = mallocz(obj.count, 1);
- memcpy(obj.data, r->ifcall.data, r->ifcall.count);
- send(dctl->wc, &obj);
- r->ofcall.count = r->ifcall.count;
- respond(r, nil);
+ f = r->fid->file;
+ dctl = f->aux;
+ if (f == cons){
+ obj.type = strdup("text");
+ obj.opts = strdup("");
+ obj.count = r->ifcall.count;
+ obj.data = mallocz(obj.count + 1, 1);
+ memcpy(obj.data, r->ifcall.data, r->ifcall.count);
+ send(dctl->wc, &obj);
+ r->ofcall.count = r->ifcall.count;
+ respond(r, nil);
+ } else if (f == consctl) {
+ respond(r, "not implemented");
+ } else respond(r, "what");
}
Devfsctl *
@@ -51,10 +64,10 @@ initdevfs(void)
srv.tree = alloctree("richterm", "richterm", DMDIR|0555, nil);
if (srv.tree == nil)
return nil;
- if (createfile(srv.tree->root, "cons", "richterm", 0666, dctl) == nil)
- return nil;
- if (createfile(srv.tree->root, "consctl", "richterm", 0666, dctl) == nil)
- return nil;
+ cons = createfile(srv.tree->root, "cons", "richterm", 0666, dctl);
+ if (cons == nil) return nil;
+ consctl = createfile(srv.tree->root, "consctl", "richterm", 0666, dctl);
+ if (consctl == nil) return nil;
threadpostmountsrv(&srv, nil, "/dev", MBEFORE);
return dctl;
}
diff --git a/richterm.c b/richterm.c
@@ -37,7 +37,8 @@ Font* getfont(Fonts *, char *);
void addfont(Fonts *, Font *);
void shutdown(void);
void send_interrupt(void);
-void runcmd(void *args);
+void runcmd(void *);
+void scroll(Point, Rich *);
void
runcmd(void *args)
@@ -175,33 +176,19 @@ threadmain(int argc, char **argv)
case KBD:
if (kv == 0x7f) shutdown();
if (kv == 0xf00e) { /* d-pad up */
- rich.page.scroll.y -= Dy(screen->r) / 8;
- if (rich.page.scroll.y <= 0) rich.page.scroll.y = 0;
- draw(screen, screen->r, display->white, nil, ZP);
- drawpage(screen, &rich.page);
- flushimage(display, 1);
+ scroll(Pt(0, rich.page.scroll.y - Dy(screen->r) / 8), &rich);
break;
}
if (kv == 0xf800) { /* d-pad down */
- rich.page.scroll.y += Dy(screen->r) / 8;
- draw(screen, screen->r, display->white, nil, ZP);
- drawpage(screen, &rich.page);
- flushimage(display, 1);
+ scroll(Pt(0, rich.page.scroll.y + Dy(screen->r) / 8), &rich);
break;
}
if (kv == 0xf00f) { /* page up */
- rich.page.scroll.y -= Dy(screen->r) / 4;
- if (rich.page.scroll.y <= 0) rich.page.scroll.y = 0;
- draw(screen, screen->r, display->white, nil, ZP);
- drawpage(screen, &rich.page);
- flushimage(display, 1);
+ scroll(Pt(0, rich.page.scroll.y - Dy(screen->r) / 4), &rich);
break;
}
if (kv == 0xf013) { /* page down */
- rich.page.scroll.y += Dy(screen->r) / 4;
- draw(screen, screen->r, display->white, nil, ZP);
- drawpage(screen, &rich.page);
- flushimage(display, 1);
+ scroll(Pt(0, rich.page.scroll.y + Dy(screen->r) / 4), &rich);
break;
}
olast = rich.obj + rich.count - 1;
@@ -333,6 +320,9 @@ generatepage(Rectangle r, Rich *rich)
sp = obj->data;
}
}
+ rich->page.max.y = ymax;
+ rich->page.max.x = 0;
+
}
Font *
@@ -365,4 +355,19 @@ addfont(struct Fonts *fonts, Font *font)
}
fonts->data[fonts->count] = font;
fonts->count++;
-}
-\ No newline at end of file
+}
+
+void
+scroll(Point p, Rich *r)
+{
+ if (p.x < 0) p.x = 0;
+ if (p.x > r->page.max.x) p.x = r->page.max.x;
+ if (p.y < 0) p.y = 0;
+ if (p.y > r->page.max.y) p.y = r->page.max.y;
+
+ r->page.scroll = p;
+
+ draw(screen, screen->r, display->white, nil, ZP);
+ drawpage(screen, &r->page);
+ flushimage(display, 1);
+}