[Z80-asm] Advise about tilemapping
Moderator: MaxCoderz Staff
- driesguldolf
- Extreme Poster
- Posts: 395
- Joined: Thu 17 May, 2007 4:49 pm
- Location: $4080
- Contact:
[Z80-asm] Advise about tilemapping
I made a proper tilemapper (took me about 2 weekends ), with proper tilemapping I mean with shifting the screen and only update a line.
But I'm wondering how to use it correctly:
-> The tilemap needs to be stored somewhere untouched because anything drawn on it will not be erased (just shifted as the rest)
-> You could use xor logic and erase everything before shifting the map but that's way too limited
-> The only option I see is to have a seperate buffer for the tilemap and copy everything every time you want to update the screen
The problem is that in the last case there's a huge overhead plus this doesn't allow for masked tilemaps (or multiple layers, depends how you look at it)
Any way to get around it? Or do I just have to live with it and be happy because completely redraw the tilemap is still waaaay slower?
for the curious I'll post my code soon^^
Btw Notepad has serious issues with word wrap...
But I'm wondering how to use it correctly:
-> The tilemap needs to be stored somewhere untouched because anything drawn on it will not be erased (just shifted as the rest)
-> You could use xor logic and erase everything before shifting the map but that's way too limited
-> The only option I see is to have a seperate buffer for the tilemap and copy everything every time you want to update the screen
The problem is that in the last case there's a huge overhead plus this doesn't allow for masked tilemaps (or multiple layers, depends how you look at it)
Any way to get around it? Or do I just have to live with it and be happy because completely redraw the tilemap is still waaaay slower?
for the curious I'll post my code soon^^
Btw Notepad has serious issues with word wrap...
- Jim e
- Calc King
- Posts: 2457
- Joined: Sun 26 Dec, 2004 5:27 am
- Location: SXIOPO = Infinite lives for both players
- Contact:
Re: [Z80-asm] Advise about tilemapping
Yup!driesguldolf wrote:The only option I see is to have a seperate buffer for the tilemap and copy everything every time you want to update the screen
Ha! LINKThe problem is that in the last case there's a huge overhead plus this doesn't allow for masked tilemaps (or multiple layers, depends how you look at it)
No redraw is the only way around. Depending on what your doing infusing your mapper with a fastcopy routine would be just as fast, saving it in a buffer.driesguldolf wrote:Any way to get around it? Or do I just have to live with it and be happy because completely redraw the tilemap is still waaaay slower?
I've had the same problem.driesguldolf wrote:Btw Notepad has serious issues with word wrap...
You should really drop by revsoft.
- driesguldolf
- Extreme Poster
- Posts: 395
- Joined: Thu 17 May, 2007 4:49 pm
- Location: $4080
- Contact:
Thanks Jim e
Side note: on a 15Mhz calc, should you use fastcopy but temporarily set speed to 8Mhz or just wait for the lcd?
Done^^Jim e wrote:You should really drop by revsoft.
You inspired me to make mine even betterJim e wrote:Ha! LINK
Hmmm rendering one map (without anything on it) is sooooo sweeeeet , thankfully the biggest issue stays the lcd so rendering 3 maps at the same time should be doable (though you can't really ldir the buffers together )Jim e wrote:Mean 1 map has 1 layer, and the 2nd map has 2 layers.
Side note: on a 15Mhz calc, should you use fastcopy but temporarily set speed to 8Mhz or just wait for the lcd?
- driesguldolf
- Extreme Poster
- Posts: 395
- Joined: Thu 17 May, 2007 4:49 pm
- Location: $4080
- Contact:
LINK
Don't you think Z80 code looks beautiful if watched from a distance? (I don't really like commented code for this reason )
More:
spencer's 40fps makes sense now ^^
Now if I just had a map editor... Isn't earlymorning some sort of map/tile-editor?
Don't you think Z80 code looks beautiful if watched from a distance? (I don't really like commented code for this reason )
More:
- Assemble with Brass, I know the example is WAAAY to small. It was for testing purposes only
- If you're going to use this code, I would appreciate it if you give me credit
- More info will be given if asked
Now that's one big fat smile on my facedriesguldolf wrote:; * Diagnostics *
;size: 555 bytes
;
; * The math (vertical scrolling) *
;movedown: 13,139-13,213 + _drawscanline (2nd value if shifting to new ypos)
;moveup: 13,040-13,115 + _drawscanline (2nd value if shifting to new ypos)
;_drawscanline: 1,461~3,430 (depends on xshift) (mean=2,446)
;
; * Conclusion (worst case scenario) *
;can shift a tilemap vertical
;~362 times per second (without updating lcd)
;~78 times per second with fastcopy per frame (~60,000 tstates)
;~906 times per second on 15Mhz calc (without updating lcd)
;
; * The math (horizontal scrolling) *
;moveleft: 20,358~22,197 (depends on xshift) (mean=21,278)
;moveright: 20,656~22,377 (depends on xshift/yshift) (mean=21,517)
;
; * Conclusion (worst case scenarios) *
;can shift a tilemap horizontal
;~269 times per second (without updating lcd)
;~73 times per second with fastcopy (~60,000 tstates)
;~673 times per second on 15Mhz calc (without updating lcd)
spencer's 40fps makes sense now ^^
Now if I just had a map editor... Isn't earlymorning some sort of map/tile-editor?
- driesguldolf
- Extreme Poster
- Posts: 395
- Joined: Thu 17 May, 2007 4:49 pm
- Location: $4080
- Contact:
I thought that it would be 'inconvienient' (however you write that) because it's quite a lot of text, and I'm not finished adding some explanation.Liazon wrote:why don't you upload as text?
This is still the very basics, now on to the more advanced stuff
Jim e would definately say that .Liazon wrote:jeez, that's another reminder how the LCD driver/fastcopy part is the major bottleneck of any mapper, as Jim e would say.
I first made a calculation error: it said that the horizontal scroller takes 133000tstates but luckily it isn't, still I think 75 pixels per second is better then nothing (though 300 would be soooo sweeeet)
- driesguldolf
- Extreme Poster
- Posts: 395
- Joined: Thu 17 May, 2007 4:49 pm
- Location: $4080
- Contact:
...WTH? lol...
Is it normal that pindurti 'crashes' and flashdebugger does not? Very weird... even more weird bugs have shown up... not... fun...
More specific: pti crashes when 'movedown' is executed as flashdebug does not...
EDIT: Errors fixed, I'll post new code when I have a better map to show off with
because I know how much you all like screenies:
Don't worry about the mess at the start, I'm not initializing gbuf
hmmmm, Jim e's is faster... *starts staring at code in an attempt to optimize it*
Is it normal that pindurti 'crashes' and flashdebugger does not? Very weird... even more weird bugs have shown up... not... fun...
More specific: pti crashes when 'movedown' is executed as flashdebug does not...
EDIT: Errors fixed, I'll post new code when I have a better map to show off with
because I know how much you all like screenies:
Don't worry about the mess at the start, I'm not initializing gbuf
hmmmm, Jim e's is faster... *starts staring at code in an attempt to optimize it*
- driesguldolf
- Extreme Poster
- Posts: 395
- Joined: Thu 17 May, 2007 4:49 pm
- Location: $4080
- Contact:
Pic made with PTI, it blurs to make gs programs look pretty (and BW ugly ^^)
Anyway Jim, could you explain how you do the fast scrolling?
My main loop for horiz scrolling is like this:
Anyway Jim, could you explain how you do the fast scrolling?
My main loop for horiz scrolling is like this:
Code: Select all
; DE, points at sprite data
; HL, points in buffer
; B, number of rows of gbuf to draw
; C, number of rows of the tile that are left to draw
; IX, points at the map
; HL', used to get the next sprite of the tile
; DE', base address of the sprites
; BC', get to next row in map data
-
; Get next byte of the tile
ld a, (de)
inc de
; Shift it the correct amount
rrca
_smc1 = $+1
jr $
rrca
rrca
rrca
rrca
rrca
rrca
rrca
; Rotate a scanline, input bit comes from the tile
rr (hl)\ inc hl
rr (hl)\ inc hl
rr (hl)\ inc hl
rr (hl)\ inc hl
rr (hl)\ inc hl
rr (hl)\ inc hl
rr (hl)\ inc hl
rr (hl)\ inc hl
rr (hl)\ inc hl
rr (hl)\ inc hl
rr (hl)\ inc hl
rr (hl)\ inc hl
; Check if all rows of the tile are drawn
dec c
jr nz, {+}
; Gets skipped most of the time
; Get new pointer to tile sprite
exx
add ix, bc
ld a, (ix)
ld h, 0
ld l, a
add hl, hl
add hl, hl
add hl, hl
add hl, de
push hl
exx
pop de
; All tiles are 8px high
ld c, 8
; End skipping
+
djnz {-}
- Jim e
- Calc King
- Posts: 2457
- Joined: Sun 26 Dec, 2004 5:27 am
- Location: SXIOPO = Infinite lives for both players
- Contact:
Neat idea, rotating sprite data straight into the buffer would be fast for single pixel scrolling.
Mine was made for multi-pixel scrolling. It makes it possible to set the pixel coordinates arbitrarily and the mapper would try to to use as much of the original buffer as possible.
When I want to scroll my code calls certain functions like this depending on the number of pixels to move
1: Scroll_Left_1
2: Scroll_Left_1,Scroll_Left_1
3: Scroll_Left_4,Scroll_Right_1
4: Scroll_Left_4,
5: Scroll_Left_4,Scroll_Left_1
6: Scroll_Left_4,Scroll_Left_1,Scroll_Left_1
7: Shift_Bytes_Left,Scroll_Right_1
Any value greater than 8, I simply shift the bytes. Scrolling 4 bytes I make use of the RRD and RLD opcodes.
The data in the blank areas is then filled with an optimized tile drawer.
Mine was made for multi-pixel scrolling. It makes it possible to set the pixel coordinates arbitrarily and the mapper would try to to use as much of the original buffer as possible.
When I want to scroll my code calls certain functions like this depending on the number of pixels to move
1: Scroll_Left_1
2: Scroll_Left_1,Scroll_Left_1
3: Scroll_Left_4,Scroll_Right_1
4: Scroll_Left_4,
5: Scroll_Left_4,Scroll_Left_1
6: Scroll_Left_4,Scroll_Left_1,Scroll_Left_1
7: Shift_Bytes_Left,Scroll_Right_1
Any value greater than 8, I simply shift the bytes. Scrolling 4 bytes I make use of the RRD and RLD opcodes.
The data in the blank areas is then filled with an optimized tile drawer.
- driesguldolf
- Extreme Poster
- Posts: 395
- Joined: Thu 17 May, 2007 4:49 pm
- Location: $4080
- Contact:
I knew that!kalan_vod wrote:Unless you change the settings >.>, via debug windowdriesguldolf wrote:Pic made with PTI, it blurs to make gs programs look pretty (and BW ugly ^^)
Jim e, you cheater! I thought those screenies (see link) gbuf was scrolled one pixel at the time
But still say that the whole screen are animated tiles, you still end up redrawing the whole screen? Even if you optimised the tile drawer...
One little question: Isn't it faster to make 16x16 tiles with a combination of 4 8x8 tiles? The map size would quadriple but there will be a lot more opportunities for RLE...
you forgot?Spencer wrote:I forget how Zelda's works, but its superior to jim's.
I don't believe there is a faster technique, but it may be better optimized
Maybe a combination of row and column major order in the gbuf?