OH THAT WOULD BE VERY DIFFICULT! – PART 3   Leave a comment

OH THAT WOULD BE VERY DIFFICULT! – PART 3

After my previous revelations about moving and controlling sprites in Part 2 of this series, as well as detecting and reacting to the fire button or space bar, here’s an explanation about how the program actually works. For this it makes sense to use the same video and pics as in the lat installment of this series.

Don’t forget that I may not be able to carry on writing this blog much longer, because of reasons which will be revealed later in this post.

Meanwhile, my opponent TMR of the blog http://c64crapdebunk.wordpress.com has degenerated into creating demos for the Amstrad CPC computers as seen in his post https://c64crapdebunk.wordpress.com/2015/11/09/release-notes-hdm-clone/ ! Obviously, this is totally irrelevant. For people trying to defend the C64, they can only do this by programming the C64, showing other people how to program the C64, or an easy way how other people could have learnt how to program the C64. Learning how to program an Amstrad CPC has nothing to do with learning how to program a C64. The Amstrad CPC range of computers has over 150 BASIC commands, while the C64 has only about 72 BASIC commands. The Amstrad CPC computers came with a nice thick manual, bigger than the “Commodore 64 Programmers’ Reference Guide” mainly about Amstrad Locomotive BASIC, as well as the parts of the system, but not about Z80 Assembly Language/Machine Code.

Of course, this latest program with the caption “Oh, that would be very difficult!” (i.e. detecting and acting on sprite collisions on other computers compared with the C64) is in the amazing MSX2 BASIC or MSX BASIC 2.0. This is an astounding, extended 32K BASIC (compared with the totally crappy 8K Commodore BASIC V2), which is descended from GW-BASIC under MS-DOS, as well as Tandy Extended Color BASIC Level 3 and the 16K Dragon BASIC. It is a later version than or an upgrade to Microsoft BASIC V4.5. This version of BASIC still uses line numbers. They only started to be abolished in BASIC dialects such as its descendants AmigaBASIC and Microsoft BASIC for the original Apple MacIntosh, QBASIC for MS-DOS, as well as the unstable and a bit crap ST BASIC by Metacomco on the Atari ST commisioned by the evil miser Jack Tramiel. The Amiga started off with the similar AbasiC, also by Metacomco, but the post Tramiel era Commodore soon bundled the Amiga with AmigaBASIC by Microsoft instead. The program has had its lines constantly renumbered using the RENUM command, which of course doesn’t exist in Commodore BASIC V2, or even in Atari BASIC. If you want to program in MSX BASIC, MSX2 BASIC, or even a later version, then I recommend the emulator OpenMSX, which has a few versions, including one or two for the Raspberry Pi computer. Try the links below. 

http://openmsx.org/

http://misapuntesde.com/post.php?id=382

http://www.emulator-zone.com/doc.php/msx/

As for what any of the program would be in Z80 Assembly Language, you don’t need to worry about that. You learn in a high level language, namely MSX BASIC, or another reasonable BASIC, including commands for colour, graphics, and sound. With any MSX or MSX2 computer the lucky buyer received a manual branded by the manufacturer about the standard MSX BASIC, or standard MSX2 BASIC, not about Z80 Asssembly Language/Machine Code. After learning the fundamental principles of programming, then they may have liked to take things further by delving into Assembly Language/Machine Code, possibly starting off by incorporating some routines listed in books or magazines.

By now you should be all be familiar with BASIC commands such as PRINT, GOTO, GOSUB, INPUT, REM and RETURN, which even appeared in Commodore BASIC V2. There are lots of REM statements, but I’ll just confirm below what lines these cover, then explain in detail further down in this post what’s happening.

Lines 10-150 are to set up the screen display and the sprites.

Lines 160-350 make up the main game loop

Lines 360-520 are the sprite collision routine

Lines 530-620 plot the stars and print “Oh that would be very difficult!” on the graphics screen

Lines 630-650 are the sprite definitions

Lines 660-800 allow the user to select between joystick and keyboard control, where the cursor keys and the space bar automatically replace the joystick controls under MSX BASIC right from version 1.0.

As the program has been automatically renumbered in increments of ten and has lines numbered from 10 to 800, this tells us that it consists of 80 lines. There are a lot of REM statements on lines with commands, which have been left from the development of the program, because it’s still in development.

If you own one of the first generation MSX computers with MSX BASIC 1.0, then you’ll have to make a few changes to get a version of this program to run on your computer. You’ll have to replace SCREEN 7,3 with SCREEN 2,3 as well as deleting all occurences of COLOR=(N,R,G,B), SET BEEP N. The horizontal screen coordinates will also have to be divided by two in order to reduce their range from 0-511 to 0-255.

Program listing screen 1

Program listing screen 1

Lines 10-150 work as follows. Line 20 turns on the 32 column SCREEN 1 mode, sets the width to the maximum of 32 columns using WIDTH 32, turns off the function key display with KEY OFF, sets white text on a black background with COLOR 15,0,0 , then prints the message “SPRITE GAME DEMO” in the middle of the screen, before a GOSUB 660 to select joystick or keyboard control, from where it executes a RETURN and goes into the hires (512×256 with individual pixel clarity meaning no “attributes”/colour bleed) SCREEN 7, much better than the limited SCREEN 2 (256×192 with 16 colours and 8×1 attributes), which was the best the original version of MSX could do. The SCREEN command has several parameters, including mode, sprite size, key click, baud rate, and printer option . In this example SCREEN 7,3 means SCREEN 7 with the largest expanded sprites possible, meaning 16×16 pixels enlarged to 32×32. COLOR=(N,R,G,B) redefines the standard colour selected by the value of N as one of the total of 512 colours available in MSX2 defined by the values of R, G, and B. A FOR…NEXT loop reads values for S from the DATA statements. S is then referred to in line 60 the sequence S$=S$+CHR$(S) to build up a sprite definition. Once this has all been read in, it’s assigned in line 70 by SPRITE$(0)=S$. The same thing happens in lines 80 and 90 but with T$ and SPRITE$(1)=T$, as well as in lines 100 and 110 with U$ where SPRITE$(2)=U$. Line 120 uses PUT SPRITE(2) to position a missile sprite and just leave it there. This sprite doesn’t move at all. Line 140 ON STICK(N) GOSUB 750 means GOSUB 750 when the joystick or cursor keys are detected, but this hasn’t been activated with STICK ON.

Program listing screen 2

Program listing screen 2

Lines 160-350 is the main game loop. Here we turn on interrupts for the sprites and joystick fire button or space bar,, using the commands SPRITE ON and STRIG(N) ON. The joystick or cursor keys are checked using STICK(N) for the values 3 for right or 7 for left, but the interrupt command STICK ON isn’t used, only appearing after a few REM statements, then The Master’s Doric Greek column shaped TARDIS sprite is moved left or right accordingly. A FOR… NEXT loop runs from line 260-340. This uses the command PUT SPRITE in line 290 to move The Doctor’s TARDIS sprite from left to right across the screen, while line 310 uses another PUT SPRITE to move The Master’s TARDIS sprite left or right according to the latest input from the joystick or cursor keys. Line 350 says GOTO 170, which takes us back to the beginning of the main loop.

Program listing screen 3

Program listing screen 3

Lines 360-520 are the sprite collision routine, which isn’t actually being used in this version of the program. It’s only listed here because this is an edited version of the previous programs I’ve posted videos of, and it’s all ready for when I want to use it again. It starts with SPRITE OFF to turn sprite collision detection off. Lines 380, 390, and 400 each use COLOR=(1,R,G,B) to redefine colour 1, so this would make that colour change rapidly if this subroutine was called. Line 410 uses the SOUND command to control the 8910 Programmable Sound Generator’s (PSG) registers to produce a sound effect, which is used by the PLAY “<string>” command in line 420.

Program listing screen 4

Program listing screen 4

Lines 530-620 plot the stars and print “OH, THAT WOULD BE VERY DIFFICULT!” on a graphics screen. The command used to plot the stars is PSET(x,y),colour in a FOR…NEXT loop. A Commodore 64 fanatic might try printing asterisks or full stops at random positions on the text screen and pretend it didn’t matter that they were only character graphics. Printing text on a graphics screen is also quite easy in MSX BASIC, only requiring an OPEN “grp:” AS #1 command, before the command PSET(X,Y) to position the graphics cursor, followed by PRINT#1,”OH, THAT WOULD BE VERY DIFFICULT!” I have no idea how anyone could do this in Commodore BASIC V2 on the C64, but it would obviously be even more difficult than making two sprites bounce off each other! On the Commodore 128 under Commodore BASIC V7, as well as the Super Expander 64 cartridge, this is done with the CHAR command.

Program listing screen 5

Program listing screen 5

Lines 630-650 are the sprite definitions, listed here in hexadecimal numbers. It would also be possible to use binary, or decimal numbers instead, but Commodore BASIC V2 can only define them in decimal numbers. You should notice that each of these lines is up to 256 characters long, although the crappy Commodore BASIC V2 lines can only be up to 80 characters long.

Program listing screen 6

Program listing screen 6

Lines 660-800 allow the user to select between joystick and keyboard control, where the cursor keys and the space bar automatically replace the joystick controls under MSX BASIC. The user’s input to select this is handled by the INKEY$ command, which in this case has no real advantage over the ancient GET$ as used in Commodore BASIC V2 on the C64. It assigns the value of the variable N to be used in subsequent STICK(N) and STRIG(N) commands. If the user presses 1 then N=0 which means keyboard control, but if they press 2 then N=1 which means joystick control. That and the STICK(N) and STRIG(N) commands are all there is to it!

So, I’m feeling really pleased with myself now that I’ve finally managed to post and explain a program about the simple building blocks of a game. I now plan to quickly take things further while I still can.

Unfortunately, I’m being evicted from my flat by a nasty property speculator! At the moment, I’m just waiting for a letter telling me when the Bailiffs will come to carry out my eviction.

I live in London. Landlords have made things a lot more difficult for people in London now, causing what they call a “housing bubble”, so I’m worried I may never get another flat to live in. I am a city dweller and can’t bear to live anywhere except a city, but even if I did agree to move to a smaller town, I don’t know if I’d succeed, or how depressing my life would be there. I’ve visited Birmingham, which is definitely a major city, a few times recently, but didn’t find out anything about renting a flat there. All of this means I could die soon.

So far, I have viewed only one flat, which was tiny, like a Bed and Breakfast, as well as having a shared kitchen. Even if I find a new flat, there’s some kind of conspiracy to force me into a studio flat, meaning no seperate bedroom, usually just a shower instead of a bath, and it may not even be near a tube station. Depending on the size of the flat, I could be forced to throw away a lot of my belongings. I could arrive there with a removal van containing all my stuff, then find that half of my belongings won’t fit in to the new flat, and they get left on the pavement or in the communal area, which would be a disaster. One trick here is to pack the most important stuff last, so that it gets unloaded first. This or, something even more disastrous, could mean me losing my MSX2, Commodore 128, Atari 800XL, Atari 65XE, and/or two Amiga computers and a Commodore monitor! I’m actually hoping that the large widescreen CRT Philips TV I used for my last MSX2 video will blow out soon, so I don’t have to transport it anywhere. This is if I actually get a new flat, which I may not. My blog has no funding and I haven’t got enough money to ensure that I can get into a new flat, so things are touch and go.

That’s all for now! Look out for another post quite soon. It could even be the grand finale of the series “Drawing The Line”!!

This blog has no means of funding, I’m actually quite skint or broke, and my life is in danger from eviction by a property speculator, probably taking place in January 2016. If you’d like to make a donation, please send me an email on paul.londoner@gmail.com , then I’ll tell you how to do that.

Advertisements

Posted November 11, 2015 by C64hater in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: