About tunnels and skyscrapers Alone Coder The rectangular tunnel appeared in hairy year in the Sega gameGalaxy Force II. On Spectrum we are on it for the first time─ watched in the demo Yes (1997). Of course, to draw such a tone─ You don't need to draw rectangles. He is built line by line. Usually in one line─ a projection of no more than one is added th rectangle. But if it’s more, no scary. The main thing is that nothing is visible in the entire frame more than N different lines, where N is the total number─ lo of rectangles in the tunnel (including outside) the one that is full screen).Effect with skyscrapers when viewed from above is also drawn with a limited number of lines (in this case 2*N, where N is the number of layers). There is also a zoom of chess grids running lines, etc. So. 1. Nedotunnel In the demo Yes the tunnel was black and white, but nothing prevents you from coloring it. For example, in multicolor 8x2 (just a stack of re─ put between the lines). But I'm like that the tunnel was needed inNedodemo 2,and demo this sub ATM-Turbo 2+ (recommended ZX Evo baseconf ), so I built this tunnel in hardware multicolor with a volume of as much as 32000 byte. The task is broken down into the following steps: - generate coordinates N rectangular─ lnikov; -generate N lines from sequence─ by adding rectangles; - create an array where for each line screen indicates which graphics to use; - display the screen based on this array (in the context of─ in multicolor tea - trivial, but in case a bold ATM screen needs to be considered). Since the lines contain a lot of one─ kovy bytes in a row, you can generate not the graphics of the lines, and the code for their output. But We will not output all 32000 bytes, conclusion─ we will only look at attributes, as for pro─ gram multicolor. Also note that in hardware multi─ color ATM-Turbo there are two alternating screen layer. You can display both layers within one procedures: dup 20 [ld de/d/e,...] push de edup ld sp,ix dup 20 [ld de/d/e,...] push de edup jp (iy) To generate such an optimized bath procedure (and let me remind you, there are N of them in total), it is convenient to first have the line graphics in li─ in any form. The caller might look like this (you can combine with the calculation of an array of strings, like this that the array will not be needed): ld sp,scr+#2000 ld ix,scr ld iy,$+ /ld ly,$+ jp (hl) and so on for each line. Logic just watches to see if we've crossed the upper (or lower) border of the next rectangle, if so, did they intersect for next, etc., changing each time number of the line graphics to be drawn. Calculating coordinates is also nothing special. can’t imagine - I’ll describe it in a nutshell, You can see the details in the sources Nedodemo 2. Each rectangle has a virtual─ real X,Y,Z and virtual dimensions (in this case is the same for everyone). In theory, the size of the layers decreases as 1/N. But with smooth zoom N will be fractional. So it's better to have an array of all visible sizes of rectangles and walk along it array in big steps. Rectangles are not onlyare approaching but also fluctuate in X and Y (for example, in si─ nusam). Shifts rectangles in X and Y directions screen projections must be consistent with their scale. That's the whole effect. 2. Skyscrappers Bird's eye view of skyscrapers flight I wrote forThe Board II(this demo written earlier than the previous one). There's also an app─ parallel multicolorATM-Turboand there was also two options: A) prepare all the lines in advance and use them B) we will update the line as drawing progresses. I figured it out and decided to generate everything─ possible lines, and optimize them inld: push.All possible lines for case 4 layers (there are so many of them in the deme, not more, then─ why couldn’t we get a beautiful color otherwise─ transition): empty 0 01 012 0123 123 23 3 a total of 8 lines. One can imagine an intermediate string format as byte per point, each bit - the presence of a certain layer of the skyscraper. To generate these bitplanes, you need start a buzzer for each of the 4 bitplanes and every byte is either left untouched or discarded─ insert the required bit into each of the bitplanes. From such a byte with bitplanes can be calculated visible color according to the table, and at the same time recalculate─ two pixels in a byte and two in a row─ layer. We managed to implement this without interruption─ a new buffer, two pixels per byte at once. The layers are applied by the palette itself, and the zoomer od─ The bitplane consists of a skip cycle and cycle of drawing the filled part. Skip cycle (b=skip width): ZOOMSKIP _=0 dup wid/2 _=_+42 djnz $+26 ;bypass the entry and jp ;pass ended ld h,c ld d,ly dup 4 ld a,(hl) or d ld (hl),a ;right pixel inc h edup org $-1 inc l ld b,hx ;width of the filled part-1 jp ZOOMWRITE+_ ;let's go to drawing ;+26 - this is here inc l djnz $+7 ;pass ended ld b,lx ;width of the filled part jp ZOOMWRITE+_ edup Drawing cycle (b=width of the filled part): ZOOMWRITE _=0 dup wid/2 _=_+34 djnz $+26 ;bypass the entry and jp ld h,c ld d,hy dup 4 ld a,(hl) or d ld (hl),a ;левый пиксель inc h edup org $-1 inc l ld b,hx ;ширина пропуска-1 jp ZOOMSKIP+_ ;+26 - это сюда ld h,c dup 4 ld (hl),e ;левый+правый пиксель inc h edup org $-1 inc l djnz $+7 ld b,lx ;ширина пропуска jp ZOOMSKIP+_ edup В любом случае, надо будет пересчитать сгенерированные строки (кроме пустой) в ld:push. Вот таким кодом (для упрощения считаем, что d и e одновременно не меняются): pop af ;two pixels from the buzzer ;(we skip the second layer) cp b jr z,$+10 exd ld (hl),#16 ;"ld d," exd inc e ld (de),a inc e ld b,a pop af ;two pixels from the buzzer ;(we skip the second layer) cp c jr z,$+10 exd ld (hl),#1e ;"ld e," exd inc e ld (de),a inc e ld c,a ld a,#d5 ;"push de" ld (de),a inc e Summonerld:push (it calculates itself─ No, which layers are active in a given line - the code is similar to a 4 channel player on a beeper :)) exx dec h jr nz,$+5 xor 8 ld h,l dec d jr nz,$+5 xor 4 ld d,e djnz $+5 xor 2 ld b,c exx djnz $+5 xor 1 ld b,c ld h,a ;%1111EDCB ld h,(hl) ld sp, first layer ld ix, second layer ld iy/ly, next caller jp (hl) ... ld:push *20 ld sp,ix ld:push *20 jp (iy) ;to the next call InThe Board IIlines are repeated (all equally attribute “pixels” are wide, and so will turn out square), so on each There is no calculation in the second line, but it says again: ld sp, first layer ld ix, second layer ld iy/ly, next caller jp (hl) You can write challenges in this spirit for zoom, scroll or something else, but I don't usually do that. The main thing is that work─ no! :)
Share your thoughts about the article