Compare commits
	
		
			No commits in common. "32c0c5611fc0dd791ac4f7cbc24e4a2f3b541c3b" and "47d5bdd1d9e93a37974aa9bdd494480a8b84f14b" have entirely different histories.
		
	
	
		
			32c0c5611f
			...
			47d5bdd1d9
		
	
		
							
								
								
									
										
											BIN
										
									
								
								docs/favicon.ico
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								docs/favicon.ico
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 298 KiB After Width: | Height: | Size: 298 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								docs/undar.png
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								docs/undar.png
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 1.8 KiB  | 
| 
						 | 
					@ -8,7 +8,7 @@
 | 
				
			||||||
   version="1.1"
 | 
					   version="1.1"
 | 
				
			||||||
   id="svg1"
 | 
					   id="svg1"
 | 
				
			||||||
   inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
 | 
					   inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
 | 
				
			||||||
   sodipodi:docname="undar.svg"
 | 
					   sodipodi:docname="undâr.svg"
 | 
				
			||||||
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
 | 
					   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
 | 
				
			||||||
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
 | 
					   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
 | 
				
			||||||
   xmlns="http://www.w3.org/2000/svg"
 | 
					   xmlns="http://www.w3.org/2000/svg"
 | 
				
			||||||
| 
						 | 
					@ -24,9 +24,9 @@
 | 
				
			||||||
     inkscape:deskcolor="#d1d1d1"
 | 
					     inkscape:deskcolor="#d1d1d1"
 | 
				
			||||||
     inkscape:document-units="mm"
 | 
					     inkscape:document-units="mm"
 | 
				
			||||||
     showguides="false"
 | 
					     showguides="false"
 | 
				
			||||||
     inkscape:zoom="5.252469"
 | 
					     inkscape:zoom="10.504938"
 | 
				
			||||||
     inkscape:cx="31.413798"
 | 
					     inkscape:cx="69.062756"
 | 
				
			||||||
     inkscape:cy="77.392175"
 | 
					     inkscape:cy="50.880831"
 | 
				
			||||||
     inkscape:window-width="1939"
 | 
					     inkscape:window-width="1939"
 | 
				
			||||||
     inkscape:window-height="932"
 | 
					     inkscape:window-height="932"
 | 
				
			||||||
     inkscape:window-x="0"
 | 
					     inkscape:window-x="0"
 | 
				
			||||||
| 
						 | 
					@ -40,16 +40,16 @@
 | 
				
			||||||
     inkscape:groupmode="layer"
 | 
					     inkscape:groupmode="layer"
 | 
				
			||||||
     id="layer1">
 | 
					     id="layer1">
 | 
				
			||||||
    <path
 | 
					    <path
 | 
				
			||||||
       style="fill:#000000;stroke:#ffffff;stroke-width:0.259677;stroke-opacity:0.80000001"
 | 
					       style="fill:#000000;stroke:#ffffff;stroke-width:0.259677;stroke-opacity:0.5"
 | 
				
			||||||
       d="M 9.8701612,2.1298382 H 2.1298382 V 29.870162 h 7.740323 V 27.874455 H 3.9914349 V 4.0257595 h 5.8787263 z"
 | 
					       d="M 9.8701612,2.1298382 H 2.1298382 V 29.870162 h 7.740323 V 27.874455 H 3.9914349 V 4.0257595 h 5.8787263 z"
 | 
				
			||||||
       id="path1" />
 | 
					       id="path1" />
 | 
				
			||||||
    <path
 | 
					    <path
 | 
				
			||||||
       style="fill:#000000;stroke:#ffffff;stroke-width:0.259677;stroke-opacity:0.80000001"
 | 
					       style="fill:#000000;stroke:#ffffff;stroke-width:0.259677;stroke-opacity:0.5"
 | 
				
			||||||
       d="m 22.129839,2.1298386 h 7.740323 V 29.870161 h -7.740323 v -1.995707 h 5.878726 V 4.02576 h -5.878726 z"
 | 
					       d="m 22.129839,2.1298386 h 7.740323 V 29.870161 h -7.740323 v -1.995707 h 5.878726 V 4.02576 h -5.878726 z"
 | 
				
			||||||
       id="path1-3" />
 | 
					       id="path1-3" />
 | 
				
			||||||
    <path
 | 
					    <path
 | 
				
			||||||
       d="m 9.9966523,7.2192166 c 0.00192,1.1921857 0,17.6324454 0,17.6324454 H 11.947933 V 10.838 c 0,0 6.10676,1.037363 7.80512,3.238279 0.180102,0.233395 0,10.775383 0,10.775383 h 1.951281 L 21.704,13.017 C 21.719643,11.169234 18.492009,9.5084126 16.302239,8.6458806 13.47112,7.5307272 9.9947373,6.0270309 9.9966523,7.2192166 Z"
 | 
					       d="m 9.9966523,7.2192166 c 0.00192,1.1921857 0,17.6324454 0,17.6324454 H 11.947933 V 10.838 c 0,0 6.10676,1.037363 7.80512,3.238279 0.180102,0.233395 0,10.775383 0,10.775383 h 1.951281 L 21.704,13.017 C 21.719643,11.169234 18.492009,9.5084126 16.302239,8.6458806 13.47112,7.5307272 9.9947373,6.0270309 9.9966523,7.2192166 Z"
 | 
				
			||||||
       style="stroke:#ffffff;stroke-width:0.292319;stroke-opacity:0.80000001"
 | 
					       style="stroke:#ffffff;stroke-width:0.292319;stroke-opacity:0.5"
 | 
				
			||||||
       id="path3"
 | 
					       id="path3"
 | 
				
			||||||
       sodipodi:nodetypes="zcccscccsz" />
 | 
					       sodipodi:nodetypes="zcccscccsz" />
 | 
				
			||||||
  </g>
 | 
					  </g>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
		 Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB  | 
| 
						 | 
					@ -140,15 +140,11 @@ i32 mouse_open(void *data, u32 mode, u32 handle, u8 *buffer, u32 size) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
i32 mouse_read(void *data, u8 *buffer, u32 size) {
 | 
					i32 mouse_read(void *data, u8 *buffer, u32 size) {
 | 
				
			||||||
  USED(data);
 | 
					 | 
				
			||||||
  USED(buffer);
 | 
					 | 
				
			||||||
  USED(size);
 | 
					 | 
				
			||||||
  return -1;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
i32 mouse_refresh(void *data, u8 *buffer) {
 | 
					 | 
				
			||||||
  MouseDeviceData *mouse_data = (MouseDeviceData *)data;
 | 
					  MouseDeviceData *mouse_data = (MouseDeviceData *)data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (size < 12)
 | 
				
			||||||
 | 
					    return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  u8 *info = (u8 *)buffer;
 | 
					  u8 *info = (u8 *)buffer;
 | 
				
			||||||
  memcpy(&info[4], &mouse_data->x, sizeof(u32));
 | 
					  memcpy(&info[4], &mouse_data->x, sizeof(u32));
 | 
				
			||||||
  memcpy(&info[8], &mouse_data->y, sizeof(u32));
 | 
					  memcpy(&info[8], &mouse_data->y, sizeof(u32));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,7 +52,6 @@ i32 screen_ioctl(void *data, u32 cmd, const u8 *buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
i32 mouse_open(void *data, u32 mode, u32 handle, u8 *buffer, u32 size);
 | 
					i32 mouse_open(void *data, u32 mode, u32 handle, u8 *buffer, u32 size);
 | 
				
			||||||
i32 mouse_read(void *data, u8 *buffer, u32 size);
 | 
					i32 mouse_read(void *data, u8 *buffer, u32 size);
 | 
				
			||||||
i32 mouse_refresh(void *data, u8 *buffer);
 | 
					 | 
				
			||||||
i32 mouse_write(void *data, const u8 *buffer, u32 size);
 | 
					i32 mouse_write(void *data, const u8 *buffer, u32 size);
 | 
				
			||||||
i32 mouse_close(void *data);
 | 
					i32 mouse_close(void *data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,22 +15,19 @@ static DeviceOps screen_ops = {.open = screen_open,
 | 
				
			||||||
                               .read = screen_read,
 | 
					                               .read = screen_read,
 | 
				
			||||||
                               .write = screen_write,
 | 
					                               .write = screen_write,
 | 
				
			||||||
                               .close = screen_close,
 | 
					                               .close = screen_close,
 | 
				
			||||||
                               .ioctl = screen_ioctl,
 | 
					                               .ioctl = screen_ioctl};
 | 
				
			||||||
                               .refresh = nil};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static DeviceOps mouse_ops = {.open = mouse_open,
 | 
					static DeviceOps mouse_ops = {.open = mouse_open,
 | 
				
			||||||
                              .read = mouse_read,
 | 
					                              .read = mouse_read,
 | 
				
			||||||
                              .write = mouse_write,
 | 
					                              .write = mouse_write,
 | 
				
			||||||
                              .close = mouse_close,
 | 
					                              .close = mouse_close,
 | 
				
			||||||
                              .ioctl = nil,
 | 
					                              .ioctl = nil};
 | 
				
			||||||
                              .refresh = mouse_refresh};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static DeviceOps keyboard_ops = {.open = keyboard_open,
 | 
					static DeviceOps keyboard_ops = {.open = keyboard_open,
 | 
				
			||||||
                                 .read = keyboard_read,
 | 
					                                 .read = keyboard_read,
 | 
				
			||||||
                                 .write = keyboard_write,
 | 
					                                 .write = keyboard_write,
 | 
				
			||||||
                                 .close = keyboard_close,
 | 
					                                 .close = keyboard_close,
 | 
				
			||||||
                                 .ioctl = nil,
 | 
					                                 .ioctl = nil};
 | 
				
			||||||
                                 .refresh = nil};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static DeviceOps console_device_ops = {
 | 
					static DeviceOps console_device_ops = {
 | 
				
			||||||
    .open = console_open,
 | 
					    .open = console_open,
 | 
				
			||||||
| 
						 | 
					@ -38,7 +35,6 @@ static DeviceOps console_device_ops = {
 | 
				
			||||||
    .write = console_write,
 | 
					    .write = console_write,
 | 
				
			||||||
    .close = console_close,
 | 
					    .close = console_close,
 | 
				
			||||||
    .ioctl = console_ioctl,
 | 
					    .ioctl = console_ioctl,
 | 
				
			||||||
    .refresh = nil
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static ScreenDeviceData screen_data = {0};
 | 
					static ScreenDeviceData screen_data = {0};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -721,8 +721,6 @@ void process_code_expr(VM *vm, SymbolTable *table, ExprNode *node) {
 | 
				
			||||||
      syscall_id = SYSCALL_DEVICE_CLOSE;
 | 
					      syscall_id = SYSCALL_DEVICE_CLOSE;
 | 
				
			||||||
    else if (strcmp(syscall_name, "IOCTL") == 0)
 | 
					    else if (strcmp(syscall_name, "IOCTL") == 0)
 | 
				
			||||||
      syscall_id = SYSCALL_DEVICE_IOCTL;
 | 
					      syscall_id = SYSCALL_DEVICE_IOCTL;
 | 
				
			||||||
    else if (strcmp(syscall_name, "REFRESH") == 0)
 | 
					 | 
				
			||||||
      syscall_id = SYSCALL_DEVICE_REFRESH;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    emit_u32(vm, syscall_id);
 | 
					    emit_u32(vm, syscall_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -103,8 +103,7 @@ typedef enum {
 | 
				
			||||||
  SYSCALL_DEVICE_READ, 
 | 
					  SYSCALL_DEVICE_READ, 
 | 
				
			||||||
  SYSCALL_DEVICE_WRITE,
 | 
					  SYSCALL_DEVICE_WRITE,
 | 
				
			||||||
  SYSCALL_DEVICE_CLOSE,
 | 
					  SYSCALL_DEVICE_CLOSE,
 | 
				
			||||||
  SYSCALL_DEVICE_IOCTL, 
 | 
					  SYSCALL_DEVICE_IOCTL 
 | 
				
			||||||
  SYSCALL_DEVICE_REFRESH
 | 
					 | 
				
			||||||
} SyscallID;
 | 
					} SyscallID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct device_ops_s {
 | 
					typedef struct device_ops_s {
 | 
				
			||||||
| 
						 | 
					@ -114,7 +113,6 @@ typedef struct device_ops_s {
 | 
				
			||||||
  i32 (*close)(void *device_data);
 | 
					  i32 (*close)(void *device_data);
 | 
				
			||||||
  i32 (*ioctl)(void *device_data, u32 cmd,
 | 
					  i32 (*ioctl)(void *device_data, u32 cmd,
 | 
				
			||||||
               const u8 *buffer); /* optional control */
 | 
					               const u8 *buffer); /* optional control */
 | 
				
			||||||
  i32 (*refresh)(void *device_data, u8 *buffer);
 | 
					 | 
				
			||||||
} DeviceOps;
 | 
					} DeviceOps;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define DEVICE_TYPE_MAX_LENGTH 16 /* 15 chars + null terminator */
 | 
					#define DEVICE_TYPE_MAX_LENGTH 16 /* 15 chars + null terminator */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										71
									
								
								src/vm/vm.c
								
								
								
								
							
							
						
						
									
										71
									
								
								src/vm/vm.c
								
								
								
								
							| 
						 | 
					@ -556,7 +556,7 @@ bool step_vm(VM *vm) {
 | 
				
			||||||
    switch (syscall_id) {
 | 
					    switch (syscall_id) {
 | 
				
			||||||
    case SYSCALL_DEVICE_OPEN: {
 | 
					    case SYSCALL_DEVICE_OPEN: {
 | 
				
			||||||
      Device *dev;
 | 
					      Device *dev;
 | 
				
			||||||
      u32 path_ptr, mode, device_ptr;
 | 
					      u32 path_ptr, mode, buffer_ptr;
 | 
				
			||||||
      u8 path_reg, mode_reg, dest_reg;
 | 
					      u8 path_reg, mode_reg, dest_reg;
 | 
				
			||||||
      dest_reg = read_u8(vm, code, vm->pc);
 | 
					      dest_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
| 
						 | 
					@ -571,14 +571,14 @@ bool step_vm(VM *vm) {
 | 
				
			||||||
      if (dev) {
 | 
					      if (dev) {
 | 
				
			||||||
        if (dev->ops->open) {
 | 
					        if (dev->ops->open) {
 | 
				
			||||||
          /* return device plex to user */
 | 
					          /* return device plex to user */
 | 
				
			||||||
          device_ptr = vm->mp;
 | 
					          buffer_ptr = vm->mp;
 | 
				
			||||||
          frame->registers[dest_reg] = device_ptr;
 | 
					          frame->registers[dest_reg] = buffer_ptr;
 | 
				
			||||||
          /* malloc size for device */
 | 
					          /* malloc size for device */
 | 
				
			||||||
          write_u32(vm, memory, device_ptr, dev->size);
 | 
					          write_u32(vm, memory, buffer_ptr, dev->size);
 | 
				
			||||||
          vm->mp += (dev->size + 4);
 | 
					          vm->mp += (dev->size + 4);
 | 
				
			||||||
          /* set flag from user */
 | 
					          /* set flag from user */
 | 
				
			||||||
          vm->flag = dev->ops->open(dev->data, mode, dev->handle,
 | 
					          vm->flag = dev->ops->open(dev->data, mode, dev->handle,
 | 
				
			||||||
                                    &vm->memory[device_ptr + 4], dev->size);
 | 
					                                    &vm->memory[buffer_ptr + 4], dev->size);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
          vm->flag = 1; /* success, no open needed */
 | 
					          vm->flag = 1; /* success, no open needed */
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -591,23 +591,25 @@ bool step_vm(VM *vm) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case SYSCALL_DEVICE_READ: {
 | 
					    case SYSCALL_DEVICE_READ: {
 | 
				
			||||||
      Device *dev;
 | 
					      Device *dev;
 | 
				
			||||||
      u32 device_ptr, buffer_ptr, size;
 | 
					      u32 handle, buffer_ptr, size;
 | 
				
			||||||
      u8 device_reg, buffer_reg, size_reg, handle;
 | 
					      u16 handle_reg, buffer_reg, size_reg;
 | 
				
			||||||
      device_reg = read_u8(vm, code, vm->pc);
 | 
					      handle_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
      buffer_reg = read_u8(vm, code, vm->pc);
 | 
					      buffer_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
      size_reg = read_u8(vm, code, vm->pc);
 | 
					      size_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
 | 
					      dest = read_u8(vm, code, vm->pc);
 | 
				
			||||||
 | 
					      vm->pc++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      device_ptr = frame->registers[device_reg]; /* device pointer */
 | 
					      handle = frame->registers[handle_reg]; /* path pointer */
 | 
				
			||||||
      buffer_ptr = frame->registers[buffer_reg];
 | 
					 | 
				
			||||||
      size = frame->registers[size_reg];     /* size */
 | 
					      size = frame->registers[size_reg];     /* size */
 | 
				
			||||||
 | 
					      buffer_ptr = frame->registers[dest];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      handle = vm->memory[device_ptr + 4]; /* get device handle */
 | 
					 | 
				
			||||||
      dev = &vm->devices[handle];
 | 
					      dev = &vm->devices[handle];
 | 
				
			||||||
      if (dev && dev->ops->read) {
 | 
					      if (dev && dev->ops->read) {
 | 
				
			||||||
        vm->flag = dev->ops->read(dev->data, &vm->memory[buffer_ptr + 4], size);
 | 
					        vm->flag = dev->ops->read(dev->data, &vm->memory[buffer_ptr + 4], size);
 | 
				
			||||||
 | 
					        frame->registers[buffer_reg] = buffer_ptr;
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        vm->flag = 0;
 | 
					        vm->flag = 0;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -615,42 +617,21 @@ bool step_vm(VM *vm) {
 | 
				
			||||||
      return true;
 | 
					      return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case SYSCALL_DEVICE_REFRESH: {
 | 
					 | 
				
			||||||
      Device *dev;
 | 
					 | 
				
			||||||
      u32 handle, device_ptr;
 | 
					 | 
				
			||||||
      u8 device_reg;
 | 
					 | 
				
			||||||
      device_reg = read_u8(vm, code, vm->pc);
 | 
					 | 
				
			||||||
      vm->pc++;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      device_ptr = frame->registers[device_reg]; /* device pointer */
 | 
					 | 
				
			||||||
      handle = vm->memory[device_ptr + 4]; /* get device handle */
 | 
					 | 
				
			||||||
      dev = &vm->devices[handle];
 | 
					 | 
				
			||||||
      if (dev && dev->ops->refresh) {
 | 
					 | 
				
			||||||
        vm->flag = dev->ops->refresh(dev->data, &vm->memory[device_ptr + 4]);
 | 
					 | 
				
			||||||
      } else {
 | 
					 | 
				
			||||||
        vm->flag = 0;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    case SYSCALL_DEVICE_WRITE: {
 | 
					    case SYSCALL_DEVICE_WRITE: {
 | 
				
			||||||
      Device *dev;
 | 
					      Device *dev;
 | 
				
			||||||
      u32 handle, buffer_ptr, size, device_ptr;
 | 
					      u32 handle, buffer_ptr, size;
 | 
				
			||||||
      u8 device_reg, buffer_reg, size_reg;
 | 
					      u16 handle_reg, buffer_reg, size_reg;
 | 
				
			||||||
      device_reg = read_u8(vm, code, vm->pc);
 | 
					      handle_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
      buffer_reg = read_u8(vm, code, vm->pc);
 | 
					      buffer_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
      size_reg = read_u8(vm, code, vm->pc);
 | 
					      size_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      device_ptr = frame->registers[device_reg]; /* device pointer */
 | 
					      handle = frame->registers[handle_reg];     /* R0: path pointer */
 | 
				
			||||||
      buffer_ptr = frame->registers[buffer_reg]; /* R1: buffer pointer */
 | 
					      buffer_ptr = frame->registers[buffer_reg]; /* R1: buffer pointer */
 | 
				
			||||||
      size = frame->registers[size_reg];         /* R2: size */
 | 
					      size = frame->registers[size_reg];         /* R2: size */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      handle = vm->memory[device_ptr + 4]; /* get device handle */
 | 
					 | 
				
			||||||
      dev = &vm->devices[handle];
 | 
					      dev = &vm->devices[handle];
 | 
				
			||||||
      if (dev && dev->ops->write) {
 | 
					      if (dev && dev->ops->write) {
 | 
				
			||||||
        vm->flag = dev->ops->write(
 | 
					        vm->flag = dev->ops->write(
 | 
				
			||||||
| 
						 | 
					@ -664,14 +645,13 @@ bool step_vm(VM *vm) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case SYSCALL_DEVICE_CLOSE: {
 | 
					    case SYSCALL_DEVICE_CLOSE: {
 | 
				
			||||||
      Device *dev;
 | 
					      Device *dev;
 | 
				
			||||||
      u32 handle, device_ptr;
 | 
					      u32 handle;
 | 
				
			||||||
      u8 device_reg;
 | 
					      u8 handle_reg;
 | 
				
			||||||
      device_reg = read_u8(vm, code, vm->pc);
 | 
					      handle_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      device_ptr = frame->registers[device_reg]; /* device pointer */
 | 
					      handle = frame->registers[handle_reg]; /* R0: path pointer */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      handle = vm->memory[device_ptr + 4]; /* get device handle */
 | 
					 | 
				
			||||||
      dev = &vm->devices[handle];
 | 
					      dev = &vm->devices[handle];
 | 
				
			||||||
      if (dev && dev->ops->close) {
 | 
					      if (dev && dev->ops->close) {
 | 
				
			||||||
        i32 result = dev->ops->close(dev->data);
 | 
					        i32 result = dev->ops->close(dev->data);
 | 
				
			||||||
| 
						 | 
					@ -685,20 +665,19 @@ bool step_vm(VM *vm) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case SYSCALL_DEVICE_IOCTL: {
 | 
					    case SYSCALL_DEVICE_IOCTL: {
 | 
				
			||||||
      Device *dev;
 | 
					      Device *dev;
 | 
				
			||||||
      u32 handle, args_ptr, cmd, device_ptr;
 | 
					      u32 handle, args_ptr, cmd;
 | 
				
			||||||
      u8 device_reg, cmd_reg, args_ptr_reg;
 | 
					      u8 handle_reg, cmd_reg, args_ptr_reg;
 | 
				
			||||||
      device_reg = read_u8(vm, code, vm->pc);
 | 
					      handle_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
      cmd_reg = read_u8(vm, code, vm->pc);
 | 
					      cmd_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
      args_ptr_reg = read_u8(vm, code, vm->pc);
 | 
					      args_ptr_reg = read_u8(vm, code, vm->pc);
 | 
				
			||||||
      vm->pc++;
 | 
					      vm->pc++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      device_ptr = frame->registers[device_reg]; /* device pointer */
 | 
					      handle = frame->registers[handle_reg];     /* R0: device path */
 | 
				
			||||||
      cmd = frame->registers[cmd_reg];           /* R1: ioctl command */
 | 
					      cmd = frame->registers[cmd_reg];           /* R1: ioctl command */
 | 
				
			||||||
      args_ptr = frame->registers[args_ptr_reg]; /* R2: args pointer */
 | 
					      args_ptr = frame->registers[args_ptr_reg]; /* R2: args pointer */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      handle = vm->memory[device_ptr + 4]; /* get device handle */
 | 
					 | 
				
			||||||
      dev = &vm->devices[handle];
 | 
					      dev = &vm->devices[handle];
 | 
				
			||||||
      if (dev && dev->ops && dev->ops->ioctl) {
 | 
					      if (dev && dev->ops && dev->ops->ioctl) {
 | 
				
			||||||
        i32 result = dev->ops->ioctl(dev->data, cmd, &vm->memory[args_ptr]);
 | 
					        i32 result = dev->ops->ioctl(dev->data, cmd, &vm->memory[args_ptr]);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,10 +16,11 @@
 | 
				
			||||||
		(load-immediate $11 0)
 | 
							(load-immediate $11 0)
 | 
				
			||||||
		(syscall OPEN $1 $1 $11)	
 | 
							(syscall OPEN $1 $1 $11)	
 | 
				
			||||||
		(load-immediate $3 &new-line)
 | 
							(load-immediate $3 &new-line)
 | 
				
			||||||
 | 
					    	(load-offset-32 $7 $1 4) ; load handle
 | 
				
			||||||
		(string-length $2 $0)
 | 
							(string-length $2 $0)
 | 
				
			||||||
		(syscall WRITE $1 $0 $2)
 | 
							(syscall WRITE $7 $0 $2)
 | 
				
			||||||
		(string-length $4 $3)
 | 
							(string-length $4 $3)
 | 
				
			||||||
		(syscall WRITE $1 $3 $4)
 | 
							(syscall WRITE $7 $3 $4)
 | 
				
			||||||
		(return nil)))
 | 
							(return nil)))
 | 
				
			||||||
(data 
 | 
					(data 
 | 
				
			||||||
	(label terminal-namespace "/dev/term/0")
 | 
						(label terminal-namespace "/dev/term/0")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/add.rom
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								test/add.rom
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -23,10 +23,11 @@
 | 
				
			||||||
		(load-immediate $11 0)
 | 
							(load-immediate $11 0)
 | 
				
			||||||
		(syscall OPEN $1 $1 $11)	
 | 
							(syscall OPEN $1 $1 $11)	
 | 
				
			||||||
		(load-immediate $3 &new-line)
 | 
							(load-immediate $3 &new-line)
 | 
				
			||||||
 | 
							(load-offset-32 $7 $1 4) ; load handle
 | 
				
			||||||
		(string-length $2 $0)
 | 
							(string-length $2 $0)
 | 
				
			||||||
		(syscall WRITE $1 $0 $2)
 | 
							(syscall WRITE $7 $0 $2)
 | 
				
			||||||
		(string-length $4 $3)
 | 
							(string-length $4 $3)
 | 
				
			||||||
		(syscall WRITE $1 $3 $4)
 | 
							(syscall WRITE $7 $3 $4)
 | 
				
			||||||
		(return nil)))
 | 
							(return nil)))
 | 
				
			||||||
(data 
 | 
					(data 
 | 
				
			||||||
	(label terminal-namespace "/dev/term/0")
 | 
						(label terminal-namespace "/dev/term/0")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/fib.rom
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								test/fib.rom
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -8,10 +8,11 @@
 | 
				
			||||||
		(load-immediate $11 0)
 | 
							(load-immediate $11 0)
 | 
				
			||||||
		(syscall OPEN $1 $1 $11)	
 | 
							(syscall OPEN $1 $1 $11)	
 | 
				
			||||||
		(load-immediate $3 &new-line)
 | 
							(load-immediate $3 &new-line)
 | 
				
			||||||
 | 
					    	(load-offset-32 $7 $1 4) ; load handle
 | 
				
			||||||
		(string-length $2 $0)
 | 
							(string-length $2 $0)
 | 
				
			||||||
		(syscall WRITE $1 $0 $2)
 | 
							(syscall WRITE $7 $0 $2)
 | 
				
			||||||
		(string-length $4 $3)
 | 
							(string-length $4 $3)
 | 
				
			||||||
		(syscall WRITE $1 $3 $4)
 | 
							(syscall WRITE $7 $3 $4)
 | 
				
			||||||
		(return nil)))
 | 
							(return nil)))
 | 
				
			||||||
(data 
 | 
					(data 
 | 
				
			||||||
	(label terminal-namespace "/dev/term/0")
 | 
						(label terminal-namespace "/dev/term/0")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/hello.rom
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								test/hello.rom
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -10,19 +10,15 @@
 | 
				
			||||||
			(add-int $1 $1 $3)
 | 
								(add-int $1 $1 $3)
 | 
				
			||||||
			(jump-ge-int &loop-body $1 $2))
 | 
								(jump-ge-int &loop-body $1 $2))
 | 
				
			||||||
		(load-immediate $10 &terminal-namespace)
 | 
							(load-immediate $10 &terminal-namespace)
 | 
				
			||||||
    	(load-immediate $11 0)
 | 
					 | 
				
			||||||
    	(syscall OPEN $10 $10 $11) ; Terminal term = open(namespace, flags)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		(real-to-nat $1 $0)
 | 
							(real-to-nat $1 $0)
 | 
				
			||||||
		(load-immediate $7 &prompt)
 | 
							(load-immediate $7 &help)
 | 
				
			||||||
		(string-length $8 $7)
 | 
							(string-length $8 $7)
 | 
				
			||||||
		(syscall WRITE $10 $7 $8) ; print prompt
 | 
							(syscall WRITE $10 $7 $8)
 | 
				
			||||||
 | 
					 | 
				
			||||||
		(load-immediate $8 32)
 | 
							(load-immediate $8 32)
 | 
				
			||||||
		(malloc $11 $8)
 | 
					 | 
				
			||||||
		(syscall READ $10 $11 $8) ; read in max 32 byte string
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		(call &pln ($11) nil)
 | 
							(malloc $11 $8)
 | 
				
			||||||
 | 
							(syscall READ $10 $2 $8 $11)
 | 
				
			||||||
 | 
							(call &pln ($2) nil)
 | 
				
			||||||
		(nat-to-string $4 $1)
 | 
							(nat-to-string $4 $1)
 | 
				
			||||||
		(call &pln ($4) nil)
 | 
							(call &pln ($4) nil)
 | 
				
			||||||
		(real-to-string $3 $0)
 | 
							(real-to-string $3 $0)
 | 
				
			||||||
| 
						 | 
					@ -33,12 +29,13 @@
 | 
				
			||||||
		(load-immediate $11 0)
 | 
							(load-immediate $11 0)
 | 
				
			||||||
		(syscall OPEN $1 $1 $11)	
 | 
							(syscall OPEN $1 $1 $11)	
 | 
				
			||||||
		(load-immediate $3 &new-line)
 | 
							(load-immediate $3 &new-line)
 | 
				
			||||||
 | 
					    	(load-offset-32 $7 $1 4) ; load handle
 | 
				
			||||||
		(string-length $2 $0)
 | 
							(string-length $2 $0)
 | 
				
			||||||
		(syscall WRITE $1 $0 $2)
 | 
							(syscall WRITE $7 $0 $2)
 | 
				
			||||||
		(string-length $4 $3)
 | 
							(string-length $4 $3)
 | 
				
			||||||
		(syscall WRITE $1 $3 $4)
 | 
							(syscall WRITE $7 $3 $4)
 | 
				
			||||||
		(return nil)))
 | 
							(return nil)))
 | 
				
			||||||
(data 
 | 
					(data 
 | 
				
			||||||
	(label terminal-namespace "/dev/term/0")
 | 
						(label terminal-namespace "/dev/term/0")
 | 
				
			||||||
    (label prompt "Enter a string: ")
 | 
					    (label help "Enter a string: ")
 | 
				
			||||||
	(label new-line "\n")))
 | 
						(label new-line "\n")))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/loop.rom
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								test/loop.rom
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -9,16 +9,18 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		(load-immediate $1 32) ; read in a string of max 32 char length 
 | 
							(load-immediate $1 32) ; read in a string of max 32 char length 
 | 
				
			||||||
		(malloc $4 $1) ; allocate memory for the string
 | 
							(malloc $4 $1) ; allocate memory for the string
 | 
				
			||||||
		(syscall READ $0 $4 $1) ; read the string
 | 
							(load-offset-32 $7 $0 4) ; load handle
 | 
				
			||||||
 | 
							(syscall READ $7 $2 $1 $4) ; read the string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		(call &pln ($0 $4) nil) ; print the string
 | 
							(call &pln ($0 $4) nil) ; print the string
 | 
				
			||||||
		(halt))
 | 
							(halt))
 | 
				
			||||||
  	(label pln 
 | 
					  	(label pln 
 | 
				
			||||||
		(load-immediate $3 &new-line)
 | 
							(load-immediate $3 &new-line)
 | 
				
			||||||
 | 
					    	(load-offset-32 $7 $0 4) ; load handle
 | 
				
			||||||
		(string-length $2 $1)
 | 
							(string-length $2 $1)
 | 
				
			||||||
		(syscall WRITE $0 $1 $2)
 | 
							(syscall WRITE $7 $1 $2)
 | 
				
			||||||
		(string-length $4 $3)
 | 
							(string-length $4 $3)
 | 
				
			||||||
		(syscall WRITE $0 $3 $4)
 | 
							(syscall WRITE $7 $3 $4)
 | 
				
			||||||
		(return nil)))
 | 
							(return nil)))
 | 
				
			||||||
(data 
 | 
					(data 
 | 
				
			||||||
	(label terminal-namespace "/dev/term/0")
 | 
						(label terminal-namespace "/dev/term/0")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/malloc.rom
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								test/malloc.rom
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -4,17 +4,20 @@
 | 
				
			||||||
    ; use load immediate because it is a pointer to a string, not a value
 | 
					    ; use load immediate because it is a pointer to a string, not a value
 | 
				
			||||||
    (load-immediate $0 &screen-namespace)
 | 
					    (load-immediate $0 &screen-namespace)
 | 
				
			||||||
    (load-immediate $11 0)
 | 
					    (load-immediate $11 0)
 | 
				
			||||||
    (syscall OPEN $0 $18 $11) ; open(out Plex screen, in namespace, in flags)
 | 
					    (syscall OPEN $18 $0 $11) ; open(out Plex screen, in namespace, in flags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (load-offset-32 $20 $0 8) ; load width
 | 
					    (load-offset-32 $0 $18 4) ; load handle
 | 
				
			||||||
    (load-offset-32 $22 $0 12) ; load size
 | 
					    (load-offset-32 $20 $18 8) ; load width
 | 
				
			||||||
 | 
					    (load-offset-32 $22 $18 12) ; load size
 | 
				
			||||||
    (load-immediate $1 16) ; offset for screen buffer
 | 
					    (load-immediate $1 16) ; offset for screen buffer
 | 
				
			||||||
    (add-nat $21 $0 $1)
 | 
					    (add-nat $21 $18 $1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ; open mouse
 | 
					    ; open mouse
 | 
				
			||||||
    (load-immediate $16 &mouse-namespace)
 | 
					    (load-immediate $16 &mouse-namespace)
 | 
				
			||||||
    (syscall OPEN $15 $16 $11) ; open(out Plex mouse, in namespace, in flags)
 | 
					    (syscall OPEN $15 $16 $11) ; open(out Plex mouse, in namespace, in flags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (load-offset-32 $16 $15 4) ; load handle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ; outline_swatch(screen, BLACK, 1, 1);
 | 
					    ; outline_swatch(screen, BLACK, 1, 1);
 | 
				
			||||||
    (load-absolute-32 $1 &BLACK)
 | 
					    (load-absolute-32 $1 &BLACK)
 | 
				
			||||||
    (load-immediate $12 1)
 | 
					    (load-immediate $12 1)
 | 
				
			||||||
| 
						 | 
					@ -30,15 +33,16 @@
 | 
				
			||||||
    ; screen.draw();
 | 
					    ; screen.draw();
 | 
				
			||||||
    (syscall WRITE $0 $21 $22)
 | 
					    (syscall WRITE $0 $21 $22)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (load-immediate $3 16)
 | 
				
			||||||
    (label draw-loop
 | 
					    (label draw-loop
 | 
				
			||||||
      ; load mouse click data
 | 
					      ; load mouse click data
 | 
				
			||||||
      (syscall REFRESH $15)
 | 
						  	(syscall READ $16 $2 $3 $15)
 | 
				
			||||||
      (load-offset-8 $9 $15 16) ; load btn1 pressed
 | 
					      (load-offset-8 $9 $15 16) ; load btn1 pressed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      (jump-eq-nat &draw-loop $9 $11)
 | 
					      (jump-eq-nat &draw-loop $9 $11)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      (load-offset-32 $7 $15 8)  ; load x
 | 
					      (load-offset-32 $7 $2 8)  ; load x
 | 
				
			||||||
      (load-offset-32 $8 $15 12) ; load y
 | 
					      (load-offset-32 $8 $2 12) ; load y
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      (load-immediate $14 20) ; box size
 | 
					      (load-immediate $14 20) ; box size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -4,17 +4,20 @@
 | 
				
			||||||
    ; use load immediate because it is a pointer to a string, not a value
 | 
					    ; use load immediate because it is a pointer to a string, not a value
 | 
				
			||||||
    (load-immediate $0 &screen-namespace)
 | 
					    (load-immediate $0 &screen-namespace)
 | 
				
			||||||
    (load-immediate $11 0)
 | 
					    (load-immediate $11 0)
 | 
				
			||||||
    (syscall OPEN $0 $0 $11) ; Screen screen = open(namespace, flags)
 | 
					    (syscall OPEN $18 $0 $11) ; Screen screen = open(namespace, flags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (load-offset-32 $20 $0 8) ; load width
 | 
					    (load-offset-32 $0 $18 4) ; load handle
 | 
				
			||||||
    (load-offset-32 $22 $0 12) ; load size
 | 
					    (load-offset-32 $20 $18 8) ; load width
 | 
				
			||||||
    (load-immediate $1 16) ; pointer offset for screen buffer
 | 
					    (load-offset-32 $22 $18 12) ; load size
 | 
				
			||||||
    (add-nat $21 $0 $1)
 | 
					    (load-immediate $1 16) ; offset for screen buffer
 | 
				
			||||||
 | 
					    (add-nat $21 $18 $1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ; open mouse
 | 
					    ; open mouse
 | 
				
			||||||
    (load-immediate $16 &mouse-namespace)
 | 
					    (load-immediate $16 &mouse-namespace)
 | 
				
			||||||
    (syscall OPEN $15 $16 $11) ; Mouse mouse = open(namespace, flags)
 | 
					    (syscall OPEN $15 $16 $11) ; Mouse mouse = open(namespace, flags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (load-offset-32 $16 $15 4) ; load handle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ; outline_swatch(screen, BLACK, 1, 1);
 | 
					    ; outline_swatch(screen, BLACK, 1, 1);
 | 
				
			||||||
    (load-absolute-32 $1 &BLACK)
 | 
					    (load-absolute-32 $1 &BLACK)
 | 
				
			||||||
    (load-immediate $12 1)
 | 
					    (load-immediate $12 1)
 | 
				
			||||||
| 
						 | 
					@ -70,15 +73,16 @@
 | 
				
			||||||
    ; screen.draw();
 | 
					    ; screen.draw();
 | 
				
			||||||
    (syscall WRITE $0 $21 $22)
 | 
					    (syscall WRITE $0 $21 $22)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (load-immediate $3 16)
 | 
				
			||||||
    (label draw-loop
 | 
					    (label draw-loop
 | 
				
			||||||
      ; load mouse click data
 | 
					      ; load mouse click data
 | 
				
			||||||
      (syscall REFRESH $15)
 | 
						  	(syscall READ $16 $2 $3 $15)
 | 
				
			||||||
      (load-offset-8 $9 $15 16) ; load btn1 pressed
 | 
					      (load-offset-8 $9 $15 16) ; load btn1 pressed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      (jump-eq-nat &draw-loop $9 $11)
 | 
					      (jump-eq-nat &draw-loop $9 $11)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      (load-offset-32 $7 $15 8)  ; load x
 | 
					      (load-offset-32 $7 $2 8)  ; load x
 | 
				
			||||||
      (load-offset-32 $8 $15 12) ; load y
 | 
					      (load-offset-32 $8 $2 12) ; load y
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      (load-immediate $14 20) ; box size
 | 
					      (load-immediate $14 20) ; box size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -225,8 +229,8 @@
 | 
				
			||||||
    (return nil)))
 | 
					    (return nil)))
 | 
				
			||||||
(data
 | 
					(data
 | 
				
			||||||
	(label screen-namespace "/dev/screen/0")
 | 
						(label screen-namespace "/dev/screen/0")
 | 
				
			||||||
	(label mouse-namespace "/dev/mouse/0")
 | 
					  (label mouse-namespace "/dev/mouse/0")
 | 
				
			||||||
	(label SELECTED-COLOR 255)
 | 
					  (label SELECTED-COLOR 255)
 | 
				
			||||||
	(label BLACK 0)
 | 
						(label BLACK 0)
 | 
				
			||||||
	(label WHITE 255)
 | 
						(label WHITE 255)
 | 
				
			||||||
	(label CHARCOAL 36)
 | 
						(label CHARCOAL 36)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/paint.rom
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								test/paint.rom
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -1,6 +1,8 @@
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Constants
 | 
					 * Constants
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					const str screen_namespace = "/dev/screen/0";
 | 
				
			||||||
 | 
					const str mouse_namespace = "/dev/mouse/0";
 | 
				
			||||||
const byte BLACK = 0;
 | 
					const byte BLACK = 0;
 | 
				
			||||||
const byte WHITE = 255;
 | 
					const byte WHITE = 255;
 | 
				
			||||||
const byte DARK_GRAY = 73;
 | 
					const byte DARK_GRAY = 73;
 | 
				
			||||||
| 
						 | 
					@ -20,10 +22,8 @@ plex Screen implements Device {
 | 
				
			||||||
  nat buffer_size;
 | 
					  nat buffer_size;
 | 
				
			||||||
  byte[] screen_buffer;
 | 
					  byte[] screen_buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  draw() {
 | 
					  init(str namespace) {
 | 
				
			||||||
    unsafe {
 | 
					    this.handle = open(namespace); 
 | 
				
			||||||
      write(this.handle, &this.screen_buffer, this.buffer_size);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,21 +35,29 @@ plex Mouse implements Device {
 | 
				
			||||||
  bool right;
 | 
					  bool right;
 | 
				
			||||||
  bool middle;
 | 
					  bool middle;
 | 
				
			||||||
  bool btn4;
 | 
					  bool btn4;
 | 
				
			||||||
 | 
					  nat size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  init(str namespace) {
 | 
				
			||||||
 | 
					    this.handle = open(namespace); 
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Main function
 | 
					 * Main function
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function main() {
 | 
					function main() {
 | 
				
			||||||
    Screen screen = open("/dev/screen/0", 0);
 | 
					    Screen screen(screen_namespace);
 | 
				
			||||||
    Mouse mouse = open("/dev/mouse/0", 0);
 | 
					    screen.open(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Mouse mouse(mouse_namespace);
 | 
				
			||||||
 | 
					    mouse.open(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    outline_swatch(screen, BLACK, 1, 1);
 | 
					    outline_swatch(screen, BLACK, 1, 1);
 | 
				
			||||||
    outline_swatch(screen, WHITE, 21, 1);
 | 
					    outline_swatch(screen, WHITE, 21, 1);
 | 
				
			||||||
    screen.draw();
 | 
					    screen.draw();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    loop {
 | 
					    loop {
 | 
				
			||||||
      mouse.refresh();
 | 
						    mouse.read();
 | 
				
			||||||
	    if (not mouse.left) continue; 
 | 
						    if (not mouse.left) continue; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    int box_size = 20;
 | 
						    int box_size = 20;
 | 
				
			||||||
| 
						 | 
					@ -90,7 +98,7 @@ function set_color(int box_size, int bx, int by, int mx, int my, byte color) {
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Draw a color box with a grey outline, if selected use a darker color
 | 
					 * Draw a color box with a grey outline, if selected use a darker color
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function outline_swatch(Device screen, byte color, int x, int y) {
 | 
					function outline_swatch(ref Device screen, byte color, int x, int y) {
 | 
				
			||||||
    byte bg_color = GRAY;
 | 
					    byte bg_color = GRAY;
 | 
				
			||||||
    if (selected_color == color) {
 | 
					    if (selected_color == color) {
 | 
				
			||||||
	    bg_color = DARK_GRAY;
 | 
						    bg_color = DARK_GRAY;
 | 
				
			||||||
| 
						 | 
					@ -104,7 +112,7 @@ function outline_swatch(Device screen, byte color, int x, int y) {
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Draw a rectangle
 | 
					 * Draw a rectangle
 | 
				
			||||||
 */ 
 | 
					 */ 
 | 
				
			||||||
function rectangle(Device screen, byte color, int x, int y, int width, int height) {
 | 
					function rectangle(ref Device screen, byte color, int x, int y, int width, int height) {
 | 
				
			||||||
   // we need unsafe because we are using `ptr` and `memset` directly
 | 
					   // we need unsafe because we are using `ptr` and `memset` directly
 | 
				
			||||||
   // unsafe takes the guardrails off and allows you to access/modify memory directly
 | 
					   // unsafe takes the guardrails off and allows you to access/modify memory directly
 | 
				
			||||||
   unsafe {
 | 
					   unsafe {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,10 +11,11 @@
 | 
				
			||||||
		(load-immediate $11 0)
 | 
							(load-immediate $11 0)
 | 
				
			||||||
		(syscall OPEN $1 $1 $11)	
 | 
							(syscall OPEN $1 $1 $11)	
 | 
				
			||||||
		(load-immediate $3 &new-line)
 | 
							(load-immediate $3 &new-line)
 | 
				
			||||||
 | 
					    	(load-offset-32 $7 $1 4) ; load handle
 | 
				
			||||||
		(string-length $2 $0)
 | 
							(string-length $2 $0)
 | 
				
			||||||
		(syscall WRITE $1 $0 $2)
 | 
							(syscall WRITE $7 $0 $2)
 | 
				
			||||||
		(string-length $4 $3)
 | 
							(string-length $4 $3)
 | 
				
			||||||
		(syscall WRITE $1 $3 $4)
 | 
							(syscall WRITE $7 $3 $4)
 | 
				
			||||||
		(return nil)))
 | 
							(return nil)))
 | 
				
			||||||
(data (label terminal-namespace "/dev/term/0")
 | 
					(data (label terminal-namespace "/dev/term/0")
 | 
				
			||||||
	(label new-line "\n")
 | 
						(label new-line "\n")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/simple.rom
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								test/simple.rom
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -2,14 +2,12 @@
 | 
				
			||||||
 * Constants
 | 
					 * Constants
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
const str nl = "\n";
 | 
					const str nl = "\n";
 | 
				
			||||||
const real x = 1.0;
 | 
					 | 
				
			||||||
const real y = 1.0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
plex Terminal {
 | 
					plex Terminal {
 | 
				
			||||||
  nat handle;
 | 
					  nat handle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  init() {
 | 
					  init() {
 | 
				
			||||||
    this.handle = open("/dev/term/0", 0);
 | 
					    handle = open("/dev/term/0", 0);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,7 +15,7 @@ plex Terminal {
 | 
				
			||||||
 * Main function
 | 
					 * Main function
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function main() {
 | 
					function main() {
 | 
				
			||||||
    pln((x + y).str);
 | 
					    pln((1 + 2).str);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,24 +2,26 @@
 | 
				
			||||||
  (label main
 | 
					  (label main
 | 
				
			||||||
    ; Open screen
 | 
					    ; Open screen
 | 
				
			||||||
    ; use load immediate because it is a pointer to a string, not a value
 | 
					    ; use load immediate because it is a pointer to a string, not a value
 | 
				
			||||||
    (load-immediate $18 &screen-namespace)
 | 
					    (load-immediate $0 &screen-namespace)
 | 
				
			||||||
    (syscall OPEN $0 $18 $11) ; open(out Plex screen, in namespace, in flags)
 | 
					    (syscall OPEN $18 $0 $11) ; open(out Plex screen, in namespace, in flags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (load-offset-32 $0 $18 4) ; load handle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (nat-to-string $5 $0)
 | 
					    (nat-to-string $5 $0)
 | 
				
			||||||
    (call &pln ($5) nil)
 | 
					    (call &pln ($5) nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (load-offset-32 $20 $0 8) ; load width
 | 
					    (load-offset-32 $20 $18 8) ; load width
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (nat-to-string $5 $20)
 | 
					    (nat-to-string $5 $20)
 | 
				
			||||||
    (call &pln ($5) nil)
 | 
					    (call &pln ($5) nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (load-offset-32 $22 $0 12) ; load size   
 | 
					    (load-offset-32 $22 $18 12) ; load size   
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (nat-to-string $5 $22)
 | 
					    (nat-to-string $5 $22)
 | 
				
			||||||
    (call &pln ($5) nil)
 | 
					    (call &pln ($5) nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (load-immediate $1 16) ; offset for screen buffer
 | 
					    (load-immediate $1 16) ; offset for screen buffer
 | 
				
			||||||
    (add-nat $21 $0 $1)
 | 
					    (add-nat $21 $18 $1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (nat-to-string $5 $21)
 | 
					    (nat-to-string $5 $21)
 | 
				
			||||||
    (call &pln ($5) nil)
 | 
					    (call &pln ($5) nil)
 | 
				
			||||||
| 
						 | 
					@ -28,17 +30,21 @@
 | 
				
			||||||
    (load-immediate $16 &mouse-namespace)
 | 
					    (load-immediate $16 &mouse-namespace)
 | 
				
			||||||
    (syscall OPEN $15 $16 $11) ; open(out Plex mouse, in namespace, in flags)
 | 
					    (syscall OPEN $15 $16 $11) ; open(out Plex mouse, in namespace, in flags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (load-offset-32 $16 $15 4) ; load handle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (syscall WRITE $0 $21 $22) ; redraw
 | 
					    (syscall WRITE $0 $21 $22) ; redraw
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (load-immediate $3 16)
 | 
				
			||||||
    (label draw-loop
 | 
					    (label draw-loop
 | 
				
			||||||
      ; load mouse click data
 | 
					      ; load mouse click data
 | 
				
			||||||
      (syscall REFRESH $15)
 | 
						  	(syscall READ $16 $2 $3 $15)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      (load-offset-8 $9 $15 16) ; load btn1 pressed
 | 
					      (load-offset-8 $9 $15 16) ; load btn1 pressed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      (jump-eq-nat &draw-loop $9 $11)
 | 
					      (jump-eq-nat &draw-loop $9 $11)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      (load-offset-32 $7 $15 8)  ; load x
 | 
					      (load-offset-32 $7 $2 8) ; load x
 | 
				
			||||||
      (load-offset-32 $8 $15 12) ; load y
 | 
					      (load-offset-32 $8 $2 12) ; load y
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      ; Compute start address: y*width + x
 | 
					      ; Compute start address: y*width + x
 | 
				
			||||||
      (mul-nat $30 $8 $20)        ; $15 = y * width
 | 
					      (mul-nat $30 $8 $20)        ; $15 = y * width
 | 
				
			||||||
| 
						 | 
					@ -58,10 +64,11 @@
 | 
				
			||||||
		  (load-immediate $11 0)
 | 
							  (load-immediate $11 0)
 | 
				
			||||||
		  (syscall OPEN $1 $1 $11)	
 | 
							  (syscall OPEN $1 $1 $11)	
 | 
				
			||||||
		  (load-immediate $3 &new-line)
 | 
							  (load-immediate $3 &new-line)
 | 
				
			||||||
 | 
					      (load-offset-32 $7 $1 4) ; load handle
 | 
				
			||||||
		  (string-length $2 $0)
 | 
							  (string-length $2 $0)
 | 
				
			||||||
		  (syscall WRITE $1 $0 $2)
 | 
							  (syscall WRITE $7 $0 $2)
 | 
				
			||||||
		  (string-length $4 $3)
 | 
							  (string-length $4 $3)
 | 
				
			||||||
		  (syscall WRITE $1 $3 $4)
 | 
							  (syscall WRITE $7 $3 $4)
 | 
				
			||||||
		  (return nil)))
 | 
							  (return nil)))
 | 
				
			||||||
(data
 | 
					(data
 | 
				
			||||||
  (label screen-namespace "/dev/screen/0")
 | 
					  (label screen-namespace "/dev/screen/0")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/window.rom
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								test/window.rom
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in New Issue