Browse Source

some refactoring; fix amiga file ops and basic amiga keyboard

mntmn 8 years ago
parent
commit
70f90f9cde

+ 1 - 9
build_amiga.sh

@@ -4,15 +4,7 @@ export PATH=$CROSSPATH/bin:$GCCLIBPATH:$PATH
 export GCC_EXEC_PREFIX=m68k-amigaos
 export LIBS=$CROSSPATH/lib
 
-echo $SEARCH_DIR
-
-# m68k-amigaos-gcc -dM -E - < /dev/null
-
-m68k-amigaos-gcc -o build/interim.amiga --std=c9x -noixemul -I$CROSSPATH/m68k-amigaos/sys-include -I$CROSSPATH/os-include  -Isledge -L$LIBS/libnix -L$LIBS -L$LIBS/gcc-lib/m68k-amigaos/2.95.3/ -DCPU_M86K sledge/strmap.c sledge/reader.c sledge/alloc.c sledge/writer.c sledge/sledge.c sledge/stream.c devices/debug_util.c devices/amiga.c devices/posixfs.c
-
-#sledge/writer.c sledge/alloc.c sledge/strmap.c sledge/stream.c sledge/sledge.c
-
-#gcc -T devices/bios.ld -m32 -o build/interim.bin -ffreestanding -nostdlib build/interim.o
+m68k-amigaos-gcc -o build/interim.amiga --std=c9x -noixemul -I$CROSSPATH/m68k-amigaos/sys-include -I$CROSSPATH/os-include  -Isledge -L$LIBS/libnix -L$LIBS -L$LIBS/gcc-lib/m68k-amigaos/2.95.3/ -DCPU_M86K sledge/strmap.c sledge/reader.c sledge/alloc.c sledge/writer.c sledge/sledge.c sledge/stream.c devices/debug_util.c devices/amiga.c devices/posixfs.c $LIBS/libnix/swapstack.o
 
 cp build/interim.amiga ~/amiga/interim/
 

+ 55 - 1
devices/amiga.c

@@ -1,5 +1,8 @@
 #include <stdio.h>
 #include <exec/types.h>
+#include <exec/io.h>
+#include <exec/ports.h>
+#include <exec/memory.h>
 #include <intuition/intuition.h>
 #include <intuition/intuitionbase.h>
 #include <intuition/screens.h>
@@ -7,6 +10,9 @@
 #include <proto/dos.h>
 #include <proto/intuition.h>
 
+#include <devices/inputevent.h>
+#include <devices/keyboard.h>
+
 #include "minilisp.h"
 #include "alloc.h"
 
@@ -15,6 +21,9 @@
 #define BPP 1
 #define DEPTH 8
 
+// http://cahirwpz.users.sourceforge.net/libnix/swapstack.html#swapstack
+unsigned long __stack=128000; // stack requirements (bytes) for swapstack.o from libnix
+
 struct Library *intuition_base;
 struct Library *gfx_base;
 struct Window *window;
@@ -101,6 +110,50 @@ Cell* amiga_fbfs_mmap(Cell* arg) {
   return buffer_cell;
 }
 
+Cell* amiga_keyfs_open() {
+  return alloc_int(1);
+}
+
+char key_to_rune[] = {
+  0,
+  0,
+  '1','2','3','4','5','6','7','8','9','0','/','"',9,9,
+  '\t','q','w','e','r','t','z','u','i','o','p','-','+',9,0,0,
+  0,'a','s','d','f','g','h','j','k','l','(',')',0,0,'*',0,0,'<',
+  'y','x','c','v','b','n','m',',','.','-',0,0,0,0,
+  0,' ',9,0,0,10,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0
+};
+
+Cell* amiga_keyfs_read() {
+  
+  Cell* key = alloc_string_copy(" ");
+  uint8_t* magic = (void*)0xbfec01;
+  uint8_t k = *magic;
+  ((char*)key->ar.addr)[0] = 0;
+  if (!(k&1)) {
+    // keyup
+    return key;
+  }
+  k>>=1;
+  k=128-k;
+  printf("keyin: %d\r\n",k);
+  ((char*)key->ar.addr)[0] = key_to_rune[k];
+  return key;
+}
+
+void mount_amiga_keyfs() {
+  fs_mount_builtin("/keyboard", amiga_keyfs_open, amiga_keyfs_read, 0, 0, 0);
+}
+
 void mount_posixfs();
 
 void mount_amiga_fbfs() {
@@ -108,7 +161,8 @@ void mount_amiga_fbfs() {
   insert_global_symbol(alloc_sym("screen-width"),alloc_int(512));
   insert_global_symbol(alloc_sym("screen-height"),alloc_int(250));
   insert_global_symbol(alloc_sym("screen-bpp"),alloc_int(1));
-  
+
+  mount_amiga_keyfs();
   mount_posixfs();
 }
 

+ 2 - 3
devices/linux/dev_consolekeys.c

@@ -7,7 +7,6 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-
 Cell* consolefs_open() {
   system("stty raw -echo");
   return alloc_int(1);
@@ -17,12 +16,12 @@ Cell* consolefs_read() {
   int c = fgetc(stdin);
   if (c==13) c=10; // CR/LF
   Cell* str = alloc_string_copy(" ");
-  ((char*)str->addr)[0] = c;
+  ((char*)str->ar.addr)[0] = c;
   return str;
 }
 
 Cell* consolefs_write(Cell* a1,Cell* arg) {
-  fputc(arg->value, stdout);
+  fputc(arg->ar.value, stdout);
   return arg;
 }
 

+ 3 - 3
devices/linux/dev_linuxfb.c

@@ -32,10 +32,10 @@ Cell* linux_fbfs_mmap(Cell* arg) {
 
   if (fd>-1) {
     Cell* buffer_cell = alloc_int(0);
-    buffer_cell->addr = mmap(NULL, sz, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
-    buffer_cell->size = sz;
+    buffer_cell->ar.addr = mmap(NULL, sz, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
+    buffer_cell->dr.size = sz;
     buffer_cell->tag = TAG_BYTES;
-    printf("[linux_fbfs_mmap] buffer_cell->addr: %p\n",buffer_cell->addr);
+    printf("[linux_fbfs_mmap] buffer_cell->addr: %p\n",buffer_cell->ar.addr);
   
     return buffer_cell;
   } else {

+ 16 - 8
devices/posixfs.c

@@ -4,6 +4,7 @@
 #include "stream.h"
 #include "compiler_new.h"
 #include <sys/mman.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <dirent.h>
@@ -34,8 +35,17 @@ Cell* posixfs_open(Cell* cpath) {
     printf("filename: %s\r\n",filename);
     
     if (filename) {
+      struct stat src_stat;
       DIR* dirp;
-      FILE* f;
+      int f;
+      off_t len;
+      
+      if (stat(filename, &src_stat)) {
+        _file_cell = alloc_string_copy("<file not found>");
+        return _file_cell;
+      }
+      len = src_stat.st_size;
+
       if ((dirp = opendir(filename))) {
         struct dirent *dp;
         Cell* nl = alloc_string_copy("\n");
@@ -49,17 +59,15 @@ Cell* posixfs_open(Cell* cpath) {
         return _file_cell;
       }
 
-      f = fopen(filename, "rb");
-      if (f) {
+      f = open(filename, O_RDONLY);
+      if (f>-1) {
         Cell* res;
-        int len, read_len;
-        fseek(f, 0L, SEEK_END);
-        len = ftell(f);
-        fseek(f, 0L, SEEK_SET);
+        int read_len;
         
         printf("[posixfs] trying to read file of len %d…\r\n",len);
         res = alloc_num_bytes(len);
-        read_len = fread(res->ar.addr, 1, len, f);
+        read_len = read(f, res->ar.addr, len);
+        close(f);
         // TODO: close?
         _file_cell = res;
         return res;

+ 0 - 0
sledge/mksprite.sh → notes/mksprite.sh


+ 1 - 0
sledge/compiler_arm_hosted.c

@@ -1,6 +1,7 @@
 #define CODESZ 8192
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/mman.h>
 
 int compile_for_platform(Cell* expr, Cell** res) {
   code = mmap(0, CODESZ, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);

+ 1 - 0
sledge/compiler_new.h

@@ -128,5 +128,6 @@ Cell* insert_global_symbol(Cell* symbol, Cell* cell);
 env_entry* lookup_global_symbol(char* name);
 
 extern Cell* platform_debug();
+Cell* platform_eval(Cell* expr);
 
 #endif

+ 2 - 2
sledge/os/shell.l

@@ -631,11 +631,11 @@
 
     (if (lt term-x 32) (def term-x minx) 0)
     
-    (if (eq blink 9)
+    (if (eq blink 3)
         (blit-char 0x2588 term-x term-y) 0)
     (if (eq blink 0)
         (blit-char 32 term-x term-y) 0)
-    (let blink (% (+ blink 1) 20))
+    (let blink (% (+ blink 1) 5))
 
     (run-tasks)
     (send scr 0)

+ 14 - 18
sledge/sledge.c

@@ -1,12 +1,11 @@
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <stdio.h>
+#include <fcntl.h>
 #include "minilisp.h"
 #include <stdlib.h>
 #include "alloc.h"
 
-Cell* platform_eval(Cell* expr); // FIXME
-
 #include "compiler_new.c"
 
 #define BUFSZ 2048
@@ -31,14 +30,10 @@ Cell* platform_eval(Cell* expr); // FIXME
 #include "../devices/macosx.c"
 #endif
 
-//ssize_t getline(char **lineptr, size_t *n, FILE *stream);
-
 void terminal_writestring(const char* data);
 
 int main(int argc, char *argv[])
 {
-  //create_shared_application();
-
   Cell* expr = NULL;
   char* in_line = malloc(BUFSZ);
   char* in_buffer = malloc(64*BUFSZ);
@@ -48,7 +43,8 @@ int main(int argc, char *argv[])
   int parens = 0;
   size_t len = 0;
   int i;
-  FILE* in_file = stdin;
+  int in_fd = 0;
+  FILE* in_f;
 
   init_compiler();
   filesystems_init();
@@ -88,8 +84,11 @@ int main(int argc, char *argv[])
 #endif
   
   if (argc==2) {
-    in_file = fopen(argv[1],"r");
-    if (!in_file) in_file = stdin;
+    in_fd = open(argv[1],O_RDONLY);
+    in_f = fdopen(in_fd,"r");
+    if (!in_f) in_f = stdin;
+  } else {
+    in_f = stdin;
   }
 
   while (1) {
@@ -97,7 +96,7 @@ int main(int argc, char *argv[])
     expr = NULL;
     len = 0;
 
-    res = fgets(in_line, BUFSZ, in_file);
+    res = fgets(in_line, BUFSZ, in_f);
     if (res) {
       len = strlen(in_line);
     }
@@ -115,8 +114,6 @@ int main(int argc, char *argv[])
         }
       }
 
-      //printf("in_offset: %d, i: %d\r\n");
-
       strncpy(in_buffer+in_offset, in_line, i);
       in_buffer[in_offset+i]='\n';
       in_buffer[in_offset+i+1]=0;
@@ -134,11 +131,11 @@ int main(int argc, char *argv[])
       }
     }
 
-    if (feof(in_file) || len==0) {
-      if (in_file!=stdin) fclose(in_file);
-      in_file = stdin;
+    if (feof(in_f) || len==0) {
+      if (in_f!=stdin) close(in_fd);
+      in_f = stdin;
+      in_fd = 0;
       in_offset=0;
-      clearerr(stdin);
       printf("stdin status: %d\r\n",feof(stdin));
     }
     
@@ -147,7 +144,6 @@ int main(int argc, char *argv[])
       int success = compile_for_platform(expr, &res);
       
       if (success) {
-        // OK
         if (!res) {
           printf("invalid cell (%p)\r\n",res);
         } else {
@@ -187,7 +183,7 @@ Cell* platform_eval(Cell* expr) {
       printf("[platform_eval] stopped at expression %d: %s\r\n",i,buf);
       break;
     }
-    // when to free the code? -> when no bound lambdas involved
+    // TOOD: when to free the code blocks? -> when no bound lambdas involved
     
     i++;
     expr = cdr(expr);