A86: Commented Array Routine
[Prev][Next][Index][Thread]
A86: Commented Array Routine
I realized how hard to comprhend this was and that I forgot to comment
so I went back and commented it. And I also relaized since I didn't pop
or push anything everything in the used registers would've been
destroyed so I add pushes and popes to prevent that.
Save_Stuff:
push bc ;Save
push de ;The
push hl ;Registers
ld hl,Array ;this command moved due to bug explained below
ld e,41 ;used to find out which line we are on
Start_Filling:
ld d,b ;save first area's counter
ld b,40 ;create new counter for this part
ld a,41 ;used for comparing e to find out which line we are on
cp e ;compare e to a for afformentioned reason
jp z,First_Recursion ;if its the first time call this
dec e ;make it smaller
cp e ;compare again
jp nz,Rest_Of_Recursions ;if it isn't the first time go here
First_Recursion: ;used for first spot
ld a,2 ;your number is >=0 and also <A so a should = 2
call Random ;get random number
ld (Array),a ;put it to the array
Rest_Of_The_Recursions: ;used for the rest of them
ld a,2 ;same as above
call Random ;ditto
ld (Array+1),a ;add it to the next spot
djnz Rest_Of_The_Recursions ;recurse through if b<>0
Random: ; Creates a random number 0 <= x < A
push bc
push de ;I can't comment this
push hl ;part because I didn't write it
ld b,a ;sorry. And thanks Jimmy for this
ld a,r ;routine.
add a,a
ld hl,0
ld d,0
ld e,a
RMul:
add hl,de
djnz RMul
ld a,h
pop hl
pop de
pop bc
ret
Call_Area:
ld b,24 ;number of lines to create
call Start_Filling ;call part that fills the current line
ld b,d ;get our counter for this part back
inc hl ;move to next .db
djnz Call_Area ;see if counter is zero if not dec it once and repeat
Array:
.db 0,0,0,0,0,0,0,0 ;make 24 .db's each having 40 0's all seperated
;by commas like shown there
Use this one instead of the last one I posted. The last one wouldn't
have worked at all. It would've filled the first line 24 times and left
the rest blank. Also it now sees which line its on and goes to an
appropriate area. I'm confident this one will work.
Matt
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
Follow-Ups: