Commit 23047999 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

multiple write/add/sub opcodes added

parent 66d36f82
......@@ -153,6 +153,6 @@ Soon...
jmp jmz jlt jgt ldl lda ldi sta sti
add sub mul div abs scs atn dot crs
sqr len dup drp cmp shf bld ret dbg
nrm add.x add.y add.z swp rnd mull
nrm mst mad msb swp rnd mull
jmr ldlv lensq noise lds sts mulv
synth-crt synth-con synth-ply flr
synth-crt synth-con synth-ply flr
......@@ -10,7 +10,7 @@
(define sincos 15) (define atn 16) (define dot 17) (define crs 18) (define sqr 19)
(define len 20) (define dup 21) (define drp 22) (define cmp 23) (define shf 24)
(define bld 25) (define ret 26) (define _dbg 27) (define nrm 28)
(define add.x 29) (define add.y 30) (define add.z 31) (define end-check 999)
(define mst 29) (define mad 30) (define msb 31) (define end-check 999)
(define swp 32) (define rnd 33) (define mull 34) (define jmr 35) (define ldlv 36)
(define lensq 37) (define noise 38) (define lds 39) (define sts 40) (define mulv 41)
(define synth-crt 42) (define synth-con 43) (define synth-ply 44) (define flr 45)
......@@ -20,7 +20,7 @@
'(nop jmp jmz jlt jgt ldl lda ldi sta sti
add sub mul div abs scs atn dot crs
sqr len dup drp cmp shf bld ret dbg
nrm add.x add.y add.z swp rnd mull
nrm mst mad msb swp rnd mull
jmr ldlv lensq noise lds sts mulv
synth-crt synth-con synth-ply flr mod))
......@@ -168,68 +168,24 @@
;; (write! start-addr value value value ...)
(define (emit-write! x)
(append
(cadr
(foldl
(lambda (val r)
(list
(+ (car r) 1)
(append
(cadr r)
(emit-expr val) ;; data
(emit (vector ldl (car r) 0)) ;; offset
(emit-expr (cadr x)) ;; address
(emit (vector add 0 0)) ;; add offset
(emit (vector sts 0 0)))))
(list 0 '())
(cddr x)))
(emit (vector ldl 0 0))))
;; stick everything on the stack
(emit-expr-list-maintain-stack (reverse (cdr x)))
(emit (vector mst (length (cddr x)) 0))
(emit (vector ldl 0 0))))
(define (emit-write-add! x)
(append
(cadr
(foldl
(lambda (val r)
(list
(+ (car r) 1)
(append
(cadr r)
(emit-expr (cadr x)) ;; address
(emit (vector ldl (car r) 0)) ;; offset
(emit (vector add 0 0)) ;; add them
(emit (vector lds 0 0)) ;; load value
(emit-expr val) ;; data
(emit (vector add 0 0)) ;; add them
(emit (vector ldl (car r) 0)) ;; offset
(emit-expr (cadr x)) ;; address
(emit (vector add 0 0)) ;; add offset
(emit (vector sts 0 0)))))
(list 0 '())
(cddr x)))
(emit (vector ldl 0 0))))
;; stick everything on the stack
(emit-expr-list-maintain-stack (reverse (cdr x)))
(emit (vector mad (length (cddr x)) 0))
(emit (vector ldl 0 0))))
(define (emit-write-sub! x)
(append
(cadr
(foldl
(lambda (val r)
(list
(+ (car r) 1)
(append
(cadr r)
(emit-expr (cadr x)) ;; address
(emit (vector ldl (car r) 0)) ;; offset
(emit (vector add 0 0)) ;; add them
(emit (vector lds 0 0)) ;; load value
(emit-expr val) ;; data
(emit (vector sub 0 0)) ;; add them
(emit (vector ldl (car r) 0)) ;; offset
(emit-expr (cadr x)) ;; address
(emit (vector add 0 0)) ;; add offset
(emit (vector sts 0 0)))))
(list 0 '())
(cddr x)))
(emit (vector ldl 0 0))))
;; stick everything on the stack
(emit-expr-list-maintain-stack (reverse (cdr x)))
(emit (vector msb (length (cddr x)) 0))
(emit (vector ldl 0 0))))
(define (emit-read x)
(append
......@@ -503,9 +459,7 @@
((eq? (car x) 'let) (emit-let x))
((eq? (car x) 'define) (emit-define x))
((eq? (car x) 'cond) (emit-cond x))
((eq? (car x) 'if)
(display "emit if")(newline)
(emit-if x))
((eq? (car x) 'if) (emit-if x))
((eq? (car x) 'loop) (emit-loop x))
((eq? (car x) 'do) (emit-expr-list (cdr x)))
(else (emit-procedure x)))
......
......@@ -3,7 +3,11 @@
(define tests
'(let ((a 10))
(if (> a 0) (trace 1) (trace 0))
(if (< a 0) (trace 0) (trace 1))))
(if (< a 0) (trace 0) (trace 1))
(trace (read reg-control))
(write! 1000 (vector 999 999 999))
(trace (read reg-control))
))
(disassemble-compiled tests)
......
......@@ -92,7 +92,10 @@ vec3 jellyfish::pop()
// (float)data.y,
// (float)data.z);
if (peekiz(REG_CONTROL)<0) pokez(REG_CONTROL,0);
if (peekiz(REG_CONTROL)<0) {
//printf("stack ran out!\n");
pokez(REG_CONTROL,0);
}
return data;
}
......@@ -138,9 +141,34 @@ void jellyfish::run()
poke((int)addr.x,data);
} break;
case NRM: push(pop().normalise()); break;
case ADDX: { m_heap[argiy%m_heap_size].x+=c.z; } break;
// multiple store suck from stack, takes size
case MST: {
vec3 addr=pop();
for (int i=0; i<argiy; i++) {
vec3 t=pop();
poke((int)addr.x+i,t);
}
} break;
// multiple add
case MAD: {
vec3 addr=pop();
for (int i=0; i<argiy; i++) {
poke((int)addr.x+i,peek((int)addr.x+i)+pop());
}
} break;
// multople subtract
case MSB: {
vec3 addr=pop();
for (int i=0; i<argiy; i++) {
poke((int)addr.x+i,peek((int)addr.x+i)-pop());
}
} break;
// never used...
/* case ADDX: { m_heap[argiy%m_heap_size].x+=c.z; } break;
case ADDY: { m_heap[argiy%m_heap_size].y+=c.z; } break;
case ADDZ: { m_heap[argiy%m_heap_size].z+=c.z; } break;
case ADDZ: { m_heap[argiy%m_heap_size].z+=c.z; } break; */
case ADD: push(pop()+pop()); break;
case SUB:
{
......@@ -260,7 +288,7 @@ void jellyfish::run()
vec3 v=pop();
m_audio_graph->Play(v.x, (int)v.y, v.z);
} break;
case FLR:
case FLR:
{ vec3 t=pop(); push(vec3(floor((float)t.x),
floor((float)t.y),
floor((float)t.z)));
......@@ -391,9 +419,9 @@ void jellyfish::print_instr(s32 addr) const
case RET: printf("ret"); break;
case DBG: printf("dbg"); break;
case NRM: printf("nrm"); break;
case ADDX: printf("add.x"); break;
case ADDY: printf("add.y"); break;
case ADDZ: printf("add.z"); break;
case MST: printf("mst"); break;
case MAD: printf("mad"); break;
case MSB: printf("msb"); break;
case SWP: printf("swp"); break;
case RND: printf("rnd"); break;
case MULL: printf("mull"); break;
......
......@@ -54,9 +54,9 @@
#define RET 26
#define DBG 27
#define NRM 28
#define ADDX 29
#define ADDY 30
#define ADDZ 31
#define MST 29
#define MAD 30
#define MSB 31
#define SWP 32
#define RND 33
#define MULL 34
......
......@@ -55,7 +55,7 @@ jellyfish_primitive::~jellyfish_primitive()
void jellyfish_primitive::execute() {
for (int i=0; i<m_machine->peekiy(REG_CONTROL); i++) {
m_machine->run();
// m_machine->pretty_dump();
//m_machine->pretty_dump();
//char cmd_str[80];
//fgets( cmd_str, 80, stdin );
......
......@@ -13,16 +13,16 @@
(t 0)
(v 0)
(weft-direction (vector 2 0 0))
(weft-position (vector 0 0 0))
(weft-t 0)
(draft-pos 0)
(draft-size 4)
(draft 1) (d-b 0) (d-c 0) (d-d 1)
(d-e 1) (d-f 1) (d-g 0) (d-h 0)
(d-i 0) (d-j 1) (d-k 1) (d-l 0)
(d-m 0) (d-n 0) (d-o 1) (d-p 1)
(weft-z (vector 0 0 0))
(weft-count 0))
(weft-position (vector 0 0 0))
(weft-t 0)
(draft-pos 0)
(draft-size 4)
(draft 1) (d-b 0) (d-c 0) (d-d 1)
(d-e 1) (d-f 1) (d-g 0) (d-h 0)
(d-i 0) (d-j 1) (d-k 1) (d-l 0)
(d-m 0) (d-n 0) (d-o 1) (d-p 1)
(weft-z (vector 0 0 0))
(weft-count 0))
(define read-draft
(lambda ()
......@@ -33,101 +33,101 @@
(modulo weft-count (+ draft-size (vector 0 1 1)) )
(- draft-size (modulo weft-count (+ draft-size (vector 0 1 1)) ))))))))
(define calc-weft-z
(lambda ()
(set! weft-count (+ weft-count 1))
(if (> (read-draft) 0.5)
(set! weft-z (vector 0 0 0.01))
(set! weft-z (vector 0 0 -0.01)))
))
(define calc-weft-z
(lambda ()
(set! weft-count (+ weft-count 1))
(if (> (read-draft) 0.5)
(set! weft-z (vector 0 0 0.01))
(set! weft-z (vector 0 0 -0.01)))
))
(define right-selvedge
(lambda (gap)
;; top corner
(write! vertex
(- (+ weft-position (vector 2 0 0)) gap)
(- (+ weft-position (vector 3 1 0)) gap)
(- (+ weft-position (vector 2 1 0)) gap))
(set! vertex (+ vertex 3))
;; vertical connection
(write! vertex
(- (+ weft-position (vector 3 1 0)) gap)
(- (+ weft-position (vector 2 1 0)) gap)
(+ weft-position (vector 2 0 0))
(- (+ weft-position (vector 3 1 0)) gap)
(+ weft-position (vector 2 0 0))
(+ weft-position (vector 3 0 0)))
(set! vertex (+ vertex 6))
;; bottom corner
(write! vertex
(+ weft-position (vector 2 0 0))
(+ weft-position (vector 3 0 0))
(+ weft-position (vector 2 1 0)))
(set! vertex (+ vertex 3))
))
(define left-selvedge
(lambda (gap)
;; top corner
(write! vertex
(- (+ weft-position (vector 0 0 0)) gap)
(- (+ weft-position (vector -1 1 0)) gap)
(- (+ weft-position (vector 0 1 0)) gap))
(set! vertex (+ vertex 3))
;; vertical connection
(write! vertex
(- (+ weft-position (vector -1 1 0)) gap)
(- (+ weft-position (vector 0 1 0)) gap)
(+ weft-position (vector 0 0 0))
(- (+ weft-position (vector -1 1 0)) gap)
(+ weft-position (vector 0 0 0))
(+ weft-position (vector -1 0 0)))
(set! vertex (+ vertex 6))
;; bottom corner
(write! vertex
(+ weft-position (vector 0 0 0))
(+ weft-position (vector -1 0 0))
(+ weft-position (vector 0 1 0)))
(set! vertex (+ vertex 3))
))
(forever
(set! vertex positions-start)
(loop (< vertex positions-end)
(calc-weft-z)
(define right-selvedge
(lambda (gap)
;; top corner
(write! vertex
(- (+ weft-position (vector 2 0 0)) gap)
(- (+ weft-position (vector 3 1 0)) gap)
(- (+ weft-position (vector 2 1 0)) gap))
(set! vertex (+ vertex 3))
;; vertical connection
(write! vertex
(- (+ weft-position (vector 3 1 0)) gap)
(- (+ weft-position (vector 2 1 0)) gap)
(+ weft-position (vector 2 0 0))
(- (+ weft-position (vector 3 1 0)) gap)
(+ weft-position (vector 2 0 0))
(+ weft-position (vector 3 0 0)))
(set! vertex (+ vertex 6))
;; bottom corner
(write! vertex
(+ weft-position (vector 2 0 0))
(+ weft-position (vector 3 0 0))
(+ weft-position (vector 2 1 0)))
(set! vertex (+ vertex 3))
))
(define left-selvedge
(lambda (gap)
;; top corner
(write! vertex
(- (+ weft-position (vector 0 0 0)) gap)
(- (+ weft-position (vector -1 1 0)) gap)
(- (+ weft-position (vector 0 1 0)) gap))
(set! vertex (+ vertex 3))
;; vertical connection
(write! vertex
(- (+ weft-position (vector -1 1 0)) gap)
(- (+ weft-position (vector 0 1 0)) gap)
(+ weft-position (vector 0 0 0))
(- (+ weft-position (vector -1 1 0)) gap)
(+ weft-position (vector 0 0 0))
(+ weft-position (vector -1 0 0)))
(set! vertex (+ vertex 6))
;; bottom corner
(write! vertex
(+ weft-position (vector 0 0 0))
(+ weft-position (vector -1 0 0))
(+ weft-position (vector 0 1 0)))
(set! vertex (+ vertex 3))
))
(set! weft-position (+ weft-position weft-direction))
;; selvedge time?
(cond
((> (mag (*v weft-position (vector 1 0 0))) 22)
(forever
(set! vertex positions-start)
(loop (< vertex positions-end)
(calc-weft-z)
(set! weft-position (+ weft-position weft-direction))
;; selvedge time?
(cond
((> (mag (*v weft-position (vector 1 0 0))) 22)
(set! weft-count 0)
(set! draft-pos (+ draft-pos 1))
(cond ((> draft-pos draft-size)
(set! draft-pos 0)))
(trace draft-pos)
(set! weft-position (- (+ weft-position (vector 0 1.5 0))
weft-direction))
(set! weft-direction (* weft-direction -1))
(cond
((> 0 weft-direction) (right-selvedge (vector 0 1.5 0)))
((< 0 weft-direction) (left-selvedge (vector 0 1.5 0))))))
(write! vertex
(+ weft-z weft-position)
(+ weft-position (+ weft-z (vector 2 1 0)))
(+ weft-position (+ weft-z (vector 2 0 0)))
(+ weft-z weft-position)
(+ weft-position (+ weft-z (vector 2 1 0)))
(+ weft-position (+ weft-z (vector 0 1 0))))
(set! vertex (+ vertex 6)))
;;(set! t (+ t 0.01))
)))
(hint-unlit)
; (texture (load-texture "thread.png"))
(set! weft-count 0)
(set! draft-pos (+ draft-pos 1))
(cond ((> draft-pos draft-size)
(set! draft-pos 0)))
(trace draft-pos)
(set! weft-position (- (+ weft-position (vector 0 1.5 0))
weft-direction))
(set! weft-direction (* weft-direction -1))
(cond
((> 0 weft-direction) (right-selvedge (vector 0 1.5 0)))
((< 0 weft-direction) (left-selvedge (vector 0 1.5 0))))))
(write! vertex
(+ weft-z weft-position)
(+ weft-position (+ weft-z (vector 2 1 0)))
(+ weft-position (+ weft-z (vector 2 0 0)))
(+ weft-z weft-position)
(+ weft-position (+ weft-z (vector 2 1 0)))
(+ weft-position (+ weft-z (vector 0 1 0))))
(set! vertex (+ vertex 6)))
;;(set! t (+ t 0.01))
)))
(hint-unlit)
(texture (load-texture "thread.png"))
(scale weave-scale)
(pdata-index-map! (lambda (i t)
(cond
......@@ -183,8 +183,8 @@
(define animate-shed
(lambda (i v)
(set! v (if (< v 0.5)
(vector 0 0 3)
(vector 0 0 -3)))
(vector 0 0 1)
(vector 0 0 -1)))
(set! warp-end 0)
(loop (< warp-end 20)
(if (> (read-draft) 0.5)
......@@ -223,16 +223,16 @@
)))
(hint-unlit)
; (texture (load-texture "thread.png"))
(texture (load-texture "thread.png"))
(scale weave-scale)
(pdata-index-map! (lambda (i t)
(cond
((eqv? (modulo i 6) 0) (vector 0 0 0))
((eqv? (modulo i 6) 1) (vector 1 10 0))
((eqv? (modulo i 6) 2) (vector 1 0 0))
((eqv? (modulo i 6) 2) (vector 0 1 0))
((eqv? (modulo i 6) 3) (vector 0 0 0))
((eqv? (modulo i 6) 4) (vector 1 10 0))
((eqv? (modulo i 6) 5) (vector 0 10 0))
((eqv? (modulo i 6) 5) (vector 10 0 0))
)) "t")
(pdata-map! (lambda (c) (vector 1 0.5 0.2)) "c")
(pdata-map! (lambda (n) (vector 0 0 0)) "n")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment