[A86] Escape Time Algorithm


[Next][Index][Thread]

[A86] Escape Time Algorithm



I'm having trouble with this code I wrote to generate a 60x60 picture based 
on an escape time algorithm. I copied the BASIC code from a book, and it 
works fine (although it took hours to finish drawing the picture). My asm 
code draws a full column (8 pixels wide by 60 pixels tall) of the desired 
picture, then goes back over the same area very slowly, drawing all black 
pixels, then advances to the next 8-pixels-wide column and does the same 
thing. Why should it be doing that? Help!

By the way, the desired picture is basically an inverted and tilted 
Sierpinski triangle. Remember, though, that this is not the method shown in 
the calc manuals; there is no randomness in this method whatsoever.

Here's the basic code. I've attached a picture (.86i) to this email so you 
can see what the finished thing looks like without waiting for it to be 
drawn. (The attached file also contains the basic .86p and the .asm source.)

<tt>

PROGRAM:ETA
20\->\NUMITS
0\->\A
0\->\B
1\->\C
1\->\D
60\->\M
120\->\R
ClDrw
For(P,1,M)
   For(Q,1,M)
      A+(C-A)*P/M\->\X
      B+(D-B)*Q/M\->\Y
      For(N,1,NUMITS)
         If Y>.5:Then
            2X\->\X
            2Y-1\->\Y
         Else
            If X>.5:Then
               2X-1\->\X
               2Y\->\Y
            Else
               2X\->\X
               2Y\->\Y
            End
         End
         If X^2+Y^2>R:Then
            PxOn(Q,P)
            NUMITS\->\N
         End
      End
   End
End

</tt>

And here's the asm code:

<tt>

;The following ROM routines in this code are actually routines of
; my own: _movfrop1, _MOV10TOOP1, _MOV10TOOP2, and _MOV10B.
;I did that because I'm neurotic about saving registers.
;(Also, _movfrop2 is a routine I included at the bottom.)
;I haven't included all the replacement routines, because I wanted
;to keep this short. Just trust me: they're very simple, they work
;right, and they save af, bc, de, hl, and any OPs they work with.

#include mAsm86    ; all your ASMIDE are belong to us...

.org _asm_exec_ram
 call _runindicoff

numits =20
v_a =0
v_b =0
v_c =1
v_d =1
v_m =60
v_r =120

 call _clrScrn
p_loop:
 ld a,1
 ld (v_q),a
q_loop:
 ld a,v_a           ; This is all just done so that
 call _setXXop2     ; the values can be easily changed around.
 ld a,v_c
 call _setXXop1
 call _FPSUB
 ld a,(v_p)
 call _setXXop2
 call _FPMULT
 ld a,v_m
 call _setXXop2
 call _FPDIV
 ld a,v_a
 call _setXXop2
 call _FPADD
 ld de,v_x
 call _movfrop1
 ld a,v_d
 call _setXXop1
 ld a,v_b
 call _setXXop2
 call _FPSUB
 ld a,(v_q)
 call _setXXop2
 call _FPMULT
 ld a,v_m
 call _setXXop2
 call _FPDIV
 ld a,v_b
 call _setXXop2
 call _FPADD
 ld de,v_y
 call _movfrop1
 ld a,1
 ld (v_n),a
n_loop:
 call _getcsc
 cp K_EXIT
 jp z,exit
 ld hl,v_x
 call var_times_2 ; x * 2 -> x
 ld hl,v_y
 call var_times_2 ; y * 2 -> y
 call _op1toop2
 call _OP1SET1
 call _TIMESPT5   ; op1 = .5
 ex de,hl
 call _cpop1op2   ; if y > .5 then
 jp c,sub_one     ;  decrement y
 ld hl,v_x
 call _MOV10TOOP2
 call _cpop1op2   ; if x > .5 then decrement x
 jp nc,no_sub     ; otherwise neither one gets dec'd
sub_one:          ; either x or y will be in op2 at this point
 call _op2toop1
 call _OP2SET1
 call _FPSUB
 call _movfrop1
no_sub:
 ld hl,v_x
 call _MOV10TOOP1
 call _FPSQUARE
 call _op1toop2
 ld hl,v_y
 call _MOV10TOOP1
 call _FPSQUARE
 call _FPADD
 call _op1toop2
 ld a,v_r
 call _setXXop1
 call _cpop1op2
 jr c,pxl_done
 ld d,1
 ld a,(v_p)
 ld b,a           ;x-coord
 ld a,(v_q)
 ld c,a           ;y-coord
 call _IPoint
 ld a,numits
 ld (v_n),a
pxl_done:
 ld hl,v_n
 ld a,numits
 cp (hl)
 jr z,next_n
 inc (hl)
 jp n_loop
next_n:
 ld hl,v_q
 ld a,v_m
 cp (hl)
 jr z,next_q
 inc (hl)
 jp q_loop
next_q:
 ld hl,v_p
 ld a,v_m
 cp (hl)
 jr z,next_p
 inc (hl)
 jp p_loop
next_p:
exit:
 call _runindicon
 jp _getkey

var_times_2:
 call _MOV10TOOP1
 call times_2
 ex de,hl
 jp _movfrop1

v_p: .db 1
v_q: .db 1
v_n: .db 1
v_x:
 .db 0,0,0,0,0,0,0,0,0,0
v_y:
 .db 0,0,0,0,0,0,0,0,0,0

_movfrop2:
 push hl
 ld hl,_OP2
 call _MOV10B
 pop hl
 ret

times_2:
 push de
 push hl
 ld de,op_save
 call _movfrop2
 call _OP2SET2
 call _FPMULT
 ex de,hl
 call _MOV10TOOP2
 pop hl
 pop de
 ret

op_save:
 .db 0,0,0,0,0,0,0,0,0,0

.end

</tt>

-- Jonathan Marcus
Appelkore@aol.com


-- Binary/unsupported file stripped by Listar --
-- Type: application/zip
-- File: ETA.zip





Follow-Ups: