79 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Common Lisp
		
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Common Lisp
		
	
	
	
| ((code
 | |
|   (label main
 | |
|     ; Open screen
 | |
|     ; use load immediate because it is a pointer to a string, not a value
 | |
|     (load-immediate $0 &screen-namespace)
 | |
|     (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)
 | |
|     (call &pln ($5) nil)
 | |
| 
 | |
|     (load-offset-32 $20 $18 8) ; load width
 | |
| 
 | |
|     (nat-to-string $5 $20)
 | |
|     (call &pln ($5) nil)
 | |
| 
 | |
|     (load-offset-32 $22 $18 12) ; load size   
 | |
| 
 | |
|     (nat-to-string $5 $22)
 | |
|     (call &pln ($5) nil)
 | |
| 
 | |
|     (load-immediate $1 16) ; offset for screen buffer
 | |
|     (add-nat $21 $18 $1)
 | |
| 
 | |
|     (nat-to-string $5 $21)
 | |
|     (call &pln ($5) nil)
 | |
| 
 | |
|     ; open mouse
 | |
|     (load-immediate $16 &mouse-namespace)
 | |
|     (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
 | |
| 
 | |
|     (load-immediate $3 16)
 | |
|     (label draw-loop
 | |
|       ; load mouse click data
 | |
| 	  	(syscall READ $16 $2 $3 $15)
 | |
| 
 | |
|       (load-offset-8 $9 $15 16) ; load btn1 pressed
 | |
| 
 | |
|       (jump-eq-nat &draw-loop $9 $11)
 | |
| 
 | |
|       (load-offset-32 $7 $2 8) ; load x
 | |
|       (load-offset-32 $8 $2 12) ; load y
 | |
| 
 | |
|       ; Compute start address: y*width + x
 | |
|       (mul-nat $30 $8 $20)        ; $15 = y * width
 | |
|       (add-nat $30 $30 $7)        ; $15 += x
 | |
|       (add-nat $30 $30 $21)       ; $15 += pixel_offset
 | |
|       (load-immediate $1 4) ; need to add offset for fat pointer size
 | |
|       (add-nat $30 $30 $1)
 | |
| 
 | |
|       (load-absolute-32 $3 &WHITE) ; color
 | |
|       (store-absolute-8 $30 $3) ; draw color at screen [x,y]
 | |
|       (syscall WRITE $0 $21 $22) ; redraw
 | |
| 
 | |
|       (jump &draw-loop))
 | |
|     (halt))
 | |
|   	(label pln 
 | |
| 		  (load-immediate $1 &terminal-namespace) ; get terminal device
 | |
| 		  (load-immediate $11 0)
 | |
| 		  (syscall OPEN $1 $1 $11)	
 | |
| 		  (load-immediate $3 &new-line)
 | |
|       (load-offset-32 $7 $1 4) ; load handle
 | |
| 		  (string-length $2 $0)
 | |
| 		  (syscall WRITE $7 $0 $2)
 | |
| 		  (string-length $4 $3)
 | |
| 		  (syscall WRITE $7 $3 $4)
 | |
| 		  (return nil)))
 | |
| (data
 | |
|   (label screen-namespace "/dev/screen/0")
 | |
|   (label mouse-namespace "/dev/mouse/0")
 | |
|   (label terminal-namespace "/dev/term/0")
 | |
| 	(label new-line "\n")
 | |
| 	(label WHITE 255)))
 |