PROGRAMMING THE HARDWARE BY MIKE CROSS JULY 1990 ----------- --- -------- -- ---- ----- ---- ---- HORIZONTAL AND VERTICAL SCROLLING ---------- --- -------- --------- This article assumes you have some knowledge of 68000 programming. Well after last months graphical start to my series of articles for this disk mag, I am back. This month we will cover horizontal and vertical scrolling using the good old hardware chips but first a little history about me . . . Like most computer fanatics, my first computer was a humble ZX81. I was about 11 years old at the time and I was totally amazed by this little black box of wonders. Eventually Clive Sinclair releaed his best selling computer the good old spectrum 48, complete with dodgy power pack and rubber keyboard - WOW ! Upon seeing the Spectrum in my local computer shop I decided I must have one, I managed to convince my mum about the educational advantages of the spectrum so off we went to the shop. Upon arriving in the shop we noticed a new machine just arrived in stock, something called a Commodore 64, It had big chunky keys and a house brick for a power suply unit. We got the `64 and never regretted it since. I got through about 4 Commodore 64`s and one CBM 128. Then came the turning point in my life, I was about 16 years old and Hewson Consultants released a nice little game called `Paradroid' - It is still to this day the best game I have ever played on a home computer. It was Paradroid that made me think - `I wish I could do that.' I got a couple of 6502 programming books from the library and began to program assembly language on the `64, I was progressing quite well, I could do sprites and Gfx. In 1986 I left school and started working and did not have much time for programming, my `64 became redundant. In 1987 Commodore released the AMIGA and all those Paradroid days came back to me! I had to program again! Eventually I saved enough to buy an Amiga, I ordered it from Silica Shop and a week later it arrived. - WOW WOW WOW WOW - AMAZING I got the Jugler and all the brill demos and was over the moon with my mega machine, I soon expanded to 1 Meg and 2 drives and began to code, the rest, as they say is history. You are probably wondering what all that had to do with hardware scrolling ? Well, I intend to write a game on the Amiga that people can look at and say `WOW' - and what is one thing that is common in most games ? - yes you`ve got it - scrolling. Every month I will give you the sort of routine that can be used to make interseting demos, but also the sort of routine that could also be incorporated into a game. Vertical scrolling (Up and Down!) on the Amiga is simple. All you have to do is to set up your copper list as normal, and write a routine to add or subtract #40 form the pointers every frame. Well okay maybe it isn`t quite as simple as that, first of all you need some kind of counter or flag to tell you which direction the scroll is to be in, Up or Down. Then you need to decide on the scroll speed. The scroll speed is controlled by the value that you add or subtract from the plane pointers each frame. Take the following copper list for example : dc.w BPLCON0,$2200 * 2 Gfx Planes dc.w BPLCON1,$0000 * No Horizontal Offset dc.w DIWSTRT,$2281 * Window size - PAL dc.w DIWSTOP,$22C1 dc.w DDFSTRT,$0038 dc.w DDFSTOP,$00D0 dc.w BPLMOD1,$0000 * No Modulo dc.w BPL2MOD,$0000 dc.w BPL1PTH HiOne dc.w 0,BPL1PTL LoOne dc.w 0,BPL2PTH HiTwo dc.w 0,BPL2PTL LoTwo dc.w 0 The HiOne to LoTwo registers would hold the address of your current image, to move the image one scan line up the screen you would have a routine something like : cmpi.w #1,UpFlag1 * Are we going up ? beq.s UpRoutine * Yes rts * No UpRoutine addi.w #40,LoOne * Move pic one line addi.w #40,LoTwo * same for all planes rts As we all know the Lo-Res standard screen is 320 pixels wide, So by adding or subtracting 40 (words) to the low pointers the screen moves ! Obviousley if your screen was a different width you would add the required number of words for it. To move the screen back down at double speed you would : cmpi.w #1,DownFlag1 beq.s DownRoutine rts DownRoutine subi.w #80,LoOne subi.w #80,LoTwo rts Obviosley the bigger the increase you put in the pointers, the faster and jerkier the scrolling becomes. As an example of Vertical scrolling I have included the source to my Arnold-Intro that was featured on last months disk. The source first kills the operating system and then sets up a vertical blanking interrupt. The scroll routine is then executed every frame. All screen movements, such as sprites and bobs should be made in the vertical blanking gap. ---------- --------- HORIZONTAL SCROLLING ---------- --------- Smooth horizontal scrolling (Left and right!) is slightly more difficult than vertical scrolling, If you attempt to use the previous method for scrolling (by adding #1 to the pointers) the screen would scroll in a very jerky manor, (as it would be adding 15 pixels in each move). However there is a special hardware register to aid you with this task, the register has the original name of Bplcon1 ! - I bet Commodore took a long time coming up with that name! Here is a bit layout of the register. BPLCON1 ($DFF102) Bit No. : 15 - 8 7 6 5 4 3 2 1 0 ----------------------------------------------------------------- Function : unused P2H3 P2H2 P2H1 P2H0 P1H3 P1H2 P1H1 PIH0 P1H0 - P1H3 Position of the even planes (four bits) P2H0 - P2H3 Position of the odd planes (four bits) Layout reproduced from the Coding bible - Amiga Systems Programmers Guide. The method for smooth horizontal scrolling is something like : If you are scrolling left, place #$00 in BPLCON1, add #$11 to the register until it reaches #$ff. Upon reaching #$ff, #2 should be added to the plane low pointers, and BPLCON1 should be reset to zero. If you are scrolling right, BPLCON1 should start with #$ff, This value should then have #$11 subtracted each frame until it reaches zero, then #2 should be subtracted from the low plane pointers and BPLCON1 reset to #$ff. Did you understand that ? - what do you mean no! - Okay then, there is a source file somewhere on this disk that will show you how it works. The program sets up a 700 pixel wide screen, and moves the graphic back and to. The piece of code was part of a demo that I did a while ago for my group - Pendle Europa. (Plug Plug!) Thats all for this month, any queries or problems then please do let me know and I will do my best to put them right, until next time, bye. Next time I will show you the correct way to set up an intterupt, (Not the totally wrong Amiga Computing Jolyon Ralph way!) and also for all you library fans I will give you some very useful intuition source, such as requesters, pull down menus, custom screens and windows + lots more! I have already written most of the source for next time (including an EXACT replica of Genam2, called Genam3!) I would of included it on this disk but the acompanying article along with the source would have taken up too much of Marks precious disk space, and I have not actually written the article yet, but be warned! - It will be very heavy reading! Anyway I have babled on for enough now so Nanoo Nanoo, Mork out. Mike Cross 15.07.90 10.40pm