[A86] Re: Some ideas?
[Prev][Next][Index][Thread]
[A86] Re: Some ideas?
Okay, here's the main part of the routine -
#define offsetx 36 ;\____ used in the TileMap to tell how large map is
#define offsety 24 ;/
;TileMap by Joe Stegner
; uses MapDraw to display a 16 tiles x 8 tiles section of map data, variable
amount
; inputs:
; x = e
; y = b
; all registers except ix are changed, make sure to save important ones
; make sure to change the offset (in the MapDraw routine), to go with your
map
; it should be (# of tiles in one row)
; I think the maximum size of your map has to be 256x256 tiles
;
TileMap:
xor a ;clear a
cp b ;compare with b
jp z, Skip_it ;if y = 0, skip offsetting
push de ;else, save de and load it with the offset
ld de, offsetx ;<-- change that too
AddLoop:
add ix, de ; skips down a row, according to the y coord given in b
djnz AddLoop ; loops y times
pop de ; restore de
Skip_it: ;end if
ld b, e ;load b with e
cp b ;if x = 0
jp z, Skip_that ; skip
LoopIt: ;else
inc ix ; increase the pointer x times
djnz LoopIt ; until loop is done
Skip_that: ;end if
ld a, (ix + 0) ;load a with the first sprite to be drawn on the screen
;inc ix
call MapDraw ;call mapdraw routine to draw it
ret
;MapDraw by Joe Stegner
; displays a 16 tile x 8 tile map of a section of a map data
; registers a,b,c,d,e,h,l changed
; ix stays the same
; input: ix = map location
; maximum amount of different types blocks you can have = 256
MapDraw:
ld d, 0 ;load 0 into d
Start_Loop: ;when we loop back here, e will keep resetting to 0 every
; time it hits 16, so you can go 16 columns every row, then
; increase the row you're on and go 16 more, then blah blah
ld e, 0
sub_loop:
ld a, (ix + 0) ;load a byte from the map into a
inc ix ;move the pointer to the next byte
cp 0 ;check if the byte is 0
jp z, b0 ;if so, draw b0
cp 1 ;check if the byte is 1
jp z, b1 ;if so, draw b1
cp 2 ;check if the byte is 2
jp z, b2 ;if so, draw b2
cp 3
jp z, b3
cp 4
jp z, b4
cp 5
jp z, b5
cp -1 ;the way I am planning to do this is to make all positives
jp z, b_1 ; solid (unpassable) and the rest clear (passable)
cp -2
jp z, b_2
cp 8
jp z, b8
Return_here:
ld b, d ;load y into b
ld c, e ; " x into c
call GridPutSprite ;call modified GridPutSprite
inc e ;increase the column we're on
ld a, e ;check if it equals 16
cp 16
jp nz, sub_loop ;if not, loop, else...
inc d ;...increase the row we're on
ld bc, offsetx-16;<----this is as far as the map goes
add ix, bc
ld a, d ;check if the row = 8
cp 8
jp nz, Start_Loop ;if not, loop back to where the current column we're on
; is 0 again, to repeat this process
;else, we're done
ret ;return to whence we came
GridPutSprite: ;b = y, c = x, ix is saved, de is saved
push ix ;save the pointer to the map
push hl ; push hl to stack...
pop ix ; ...and pop it into iy
srl b ; bc = (128 * y) + x
rra ; carry flag -< msb of a
and $80 ; a is either $00 or $80
or c ; add x offset (remember x <= 15)
ld c,a ; bc = (128 * y) + (x * 8)
ld hl,$fc00 ; hl-> video memory
add hl,bc ; hl-> video memory + offset
ld b,8 ; initialize loop counter
push de ;save the x and y coords
ld de,16 ; screen is 16 bytes wide
GPS_Loop:
ld a,(ix + 0) ; get byte from sprite
ld (hl),a ; put byte on screen
inc ix ; move to next byte in sprite
add hl,de ; move to next line on screen
djnz GPS_Loop ; loop until sprite is drawn
pop de ;restore the x and y coords
pop ix ;restore the pointer to the map
ret ; return
b0:
ld hl, block0 ;load hl with the block we wish to draw
jp Return_here
b1:
ld hl, block1 ; "
jp Return_here
b2:
ld hl, block2 ; "
jp Return_here
b3:
ld hl, block3
jp Return_here
b4:
ld hl, block4
jp Return_here
b5:
ld hl, block5
jp Return_here
b_1:
ld hl, block_1
jp Return_here
b_2:
ld hl, block_2
jp Return_here
b8:
ld hl, block8
jp Return_here
References: