I only had one block instead of 20 blocksCopy this part 20x into the deleted part.Code: Select all
block 20,128 ; BLOCK places 20x character 128,inverted space db 118
Up/Down working
I only had one block instead of 20 blocksCopy this part 20x into the deleted part.Code: Select all
block 20,128 ; BLOCK places 20x character 128,inverted space db 118
Code: Select all
rnd ld de,0 ; get the pointer in ROM
ld hl,(frames) ; for randomness get framecounter
add hl,de ; add framecounter
dec hl ; when framecounter is unchanged make sure a change is done
ld a,h ; H can have any value, but ROM is #0000-#1FFF
and #0f ; only #0000-#0f00 is what we use
ld h,a ; set pointer back within ROM
ld (rnd+1),hl ; save current pointer (selfmodifying code!!!)
ld a,(hl) ; get value in ROM
range sub 20 ; we need 0-19 only
jr nc,range
adc a,20 ; undo last subtraction, range 1-20
ret ; back to mainprogram
Code: Select all
; free codeable memory
gamecode ld bc,#0101 ; B=1, C=1, first position on the screen
newdot push bc ; save xy player
call rnd ; get a random number
ld b,a ; set as Y
call rnd ; get a next random number
ld c,a ; st as X
call field
ld (hl),27+128 ; place an inverted dot
pop bc ; get xy player
moveloop call field
ld (hl),"O"-27+128 ; we write a "O" INVERTED on the screen
Code: Select all
gamecode ld bc,#0101 ; B=1, C=1, first position on the screen
newdot push bc ; save xy player
call rnd ; get a random number
ld b,a ; set as Y
call rnd ; get a next random number
ld c,a ; set as X
call field
ld (hl),27+128 ; place an inverted dot
pop bc ; get xy player
moveloop call field
ld a,(hl) ; get current screen value
cp 27+128 ; is it a dot
jr nz,test2
ld (hl),128 ; erase the dot
jr newdot ;
test2 nop ; now NOP, added for later.
ld (hl),"O"-27+128 ; we write a "O" on the screen
Code: Select all
push hl
ld hl,frames ; make hl point to the timecounter
ld a,(hl) ; get the timecounter in A
sub 4 ; take of 4, the number we want to test
wfr cp (hl) ; test if the value is the same
jr nz,wfr ; NOW WE WAIT UNTIL FRAMES MATCHES A!
pop hl
Code: Select all
; the display file, Code the lines needed.
dfile db 118
; each line has text and a Newline
db 0,0,0,0,0,"D"+101,"O"+101,"T"+101,"B"+101,"U"+101,"S"+101,"T"+101,"E"+101,"R"+101,"S"+101,118
score db 28,28,28,28,28,0,0,0,0
timer db 28,28,0,0,0,0
hiscore db 28,28,28,28,28,118
screen block 20,128 ; BLOCK places 20x character 128,inverted space
Code: Select all
; free codeable memory
gamecode ld a,(lastk) ; get inport from lastkey
sub 191 ; is it HJKL-NL?
jr nz,gamecode ; if not we wait until pressed
[/ccode]
Now we start with a keypress.... next to do, reset score and add timer
Code: Select all
newdot push bc ; save xy player
call rnd ; get a random number
ld b,a ; set as Y
call rnd ; get a next random number
ld c,a ; set as X
call field
ld (hl),27+128 ; place an inverted dot
call rnd ; a number between 1 and 20
add a,10 ; at least 10 moves to get on the place
ld (timecnt+1),a ; we use SELFMODIFYINGCODE, explained at timecnt-label
pop bc ; get xy player
moveloop call field
Code: Select all
test2 nop ; now NOP, added for later.
ld (hl),"O"-27+128 ; we write a "O" on the screen
timecnt ld a,0 ; value changes in every move. shorter than LD A,(TIMECNT)
dec a ; take off a loop
ld (timecnt+1),a ; save counter
push af ; save counter for test after display
call dispnr ; show the number time left
pop af ; get counter
or a ; test for zero, shorter than CP 0 !!!
jr nz,playon ; we still can play
jp gamecode ; temporary end of game
playon push hl
ld hl,frames ; make hl point to the timecounter
ld a,(hl) ; get the timecounter in A
sub 4 ; take of 2, the number we want to test
wfr cp (hl) ; test if the value is the same
Code: Select all
okmove jr moveloop ; stay in playloop
; Show remaining time on screen, value in A
dispnr push hl ; keep originl HL needed later
ld hl,timer ; the 10-digit on the screen
ld (hl),27 ; we preset this with "-10"
timset inc (hl) ; add 10 points
sub 10 ; take of 10 from the value we have
jr nc,timset ; keep doing the 10-counter
inc hl ; now go to units
add a,38 ; we are 10 under 0 and we need range ascii "0"="9"
ld (hl),a ; display units
pop hl ; retrieve HL
ret
; BC = XY, return HL=field on screen
Code: Select all
wkey ld bc,(lastk) ; get key information
ld a,c ; copy C in A to keep C
inc a ; Test if NOKEY pressed
; jr z,wkey ; NO KEY, wait for key
ld (hl),128 ; we pressed a key, so we erase the old position
call nz,#7bd ; BC holds info about key, ROM can translated this here
Code: Select all
gamecode ld a,(lastk)
sub 191
jr nz,gamecode
cls ld hl,screen ; start of screen
cl1 ld (hl),128 ; set inverted space
inc hl ; go to next field
ld a,(hl) ; test end of line
cp #76
jr nz,cl1 ; do full line
inc hl ; go to next field
ld a,(hl) ; test end of screen
cp #e9
jr nz,cl1 ; if not, do next field
Code: Select all
ld (hl),128 ; erase the dot
ld a,(timecnt+1) ; we get the remaining time
push bc ; we save coordinates
ld b,a ; loop counter in B
addtime ld hl,score+4 ; start at units of score
call addpoint ; add 1 point
djnz addtime ; add all remaining time
pop bc ; get coordinates back
jr newdot ; make a new dot
ten ld (hl),28
dec hl
addpoint inc (hl) ; add a point to the score
ld a,(hl)
cp 38 ; test if "9" goes to "A"
jr z,ten ; if so, alter score to add points to 10/100/1000
ret ; 1 point added
the source of digg it has a routine to move and drop boulders, similar to your question.Spinnetti wrote: ↑Fri Apr 16, 2021 3:28 am I feel really dumb when I see what you guys can do! Me and my best buddy are just finishing up our rendition of Donkey Kong. We started it in 1983, so we aren't the fastest coders lol. While "done", some sections are really inelegant and I want to rewrite those. If its ok to ask here (just delete or move if not) How do I manage an array of addresses? In Donkey Kong (not an exact copy, but our flavor), I want to use a couple 1D arrays to manage the data.
Like this
Barrels: $nnnn, $nn, $nnnn, $nn.... where the two bytes are the location and the next byte is a direction variable (or they could be two arrays_
What I'm trying to do conceptually is:
LD B,Number of barrels (fixed)
Loop:
LD Barrels ;first barrel address in "Barrels"
LD direction ;first direction byte
<do some stuff>
LD (current barrel),$1C ;print out a barrel
INC pointer to the next barrel/direction triad
DJNZ loop
I'm sure this is simple, but I'm stumped!
Thanks!