Archive for October 2013



IWASHHEREOUTHow to do this in 6502/6510/8502 Assembly Language!

Here’s part two of my experiences so far with my new/old Commodore 128! I feel I should point out first of all that, unlike TMR has recently claimed, when I bought a Commodore 64 in 1984 it wasn’t well known that it had crap, “Neanderthal”, or standard PET BASIC with no commands for colour, graphics, or sound. I only found this out from reading C64 magazines and the course “An Introduction to BASIC”. I think they should have had a warning sticker on them!

In John Lewis, Oxford St, London, In 1984 or 1985, where at least their sign warned people that the Commodore 64 had only 38K (i.e. that they could actually use in their BASIC programs), I once inputted and ran a print loop on a C64 saying “BASIC V2 WARNING! THE LATEST VERSION IS 4.5.”, which was referring to the latest version of Microsoft BASIC on MSX computers, that were on display there at the time. An important victory of mine recently is managing to add two contradictions to the Commodore 64 propaganda on its Wikipedia page backed up by quotes from sources, and not having them deleted. See if you can spot them. I hope you enjoy it! Now back to the Commodore 128.

IWASHERE1Here goes!

Below is a listing of my Assembly Language program which prints “I WAS HERE!” and scrolls vertically, but first of all I must tell you how to type it into the C128 MONITOR. You must start by finding a safe place to put your program, which for some reason is $1800 on the C128, although this may not be safe on earlier Commodore computers. Some safe addresses on the C64 are $1000 or 4096 in decimal and $C000 or 49152 in decimal, where there’s 4K of space. Based on my attempts, it seems that the C128 doesn’t like Assembly Language/Machine Code programs to start at $C000, though. It exits the MONITOR to BASIC and prints ?SYNTAX ERROR. This seems to be because the RAM starting at $C000 49152 is the BASIC screen editor, which is somehow better than the Commodore 64. You can stop the cursor from flashing by pressing ESC followed by E, as well as some other editing commands which may have been copied from CP/M, or the Spectrum 128K. You just type MONITOR, followed by A1800 to Assemble starting at the address $1800, then press SPACE and input the first line, as listed below, leaving one space between the opcodes and the numbers. After this, you press the RETURN key, which will allow you to type in the next line. You continue like this until after inputting the final instruction, which is BRK. After typing BRK you press the RETURN key as usual, then press it again to let the MONITOR know that’s the end of your program. You should eventually have the following program, which I’ll explain in a moment. It seems this program doesn’t run on a C64, or would need to be relocated to run. I could only get it to LOAD when using the C128 in C64 mode.

LDX #$00
LDA $1820,X
CPX #$0D
BNE $1802
JMP $1800

You can check what you’ve typed by giving the command D1800. If there are any errors you can correct them by typing A, followed by the address of the line where they are, then retyping that whole line. We also need some data for this program to work with. When it comes to inputting data instead of Assembly Language instructions, different assemblers have different ways of doing it. I think these are called directives. Luckily, in this case, we’re using the standard Commodore MONITOR for the C128, but which dates back to the PET. This is fine when it comes to an old fashioned MONITOR with an Assembler, because you can access any part of the computer with it, but obviously not fine when it comes to an old version of BASIC. I think this MONITOR includes what Your 64 magazine called a “simple Assembler”, meaning that you just input Assembly Language and each line is assembled when you press RETURN, instead of typing source code into a text editor.

IWASHEREDATA2 The message itself in Hexadecimal codes as well as ASCII/PETSCII

In this case, we can use the command M to display Memory, then when it’s displayed we can use the cursor keys to position the cursor over the locations where we want our data to be and to replace whatever is already there with the message we want. An ASCII dump appears on the right hand side. This message will be in PET ASCII or PETSCII character codes, as follows. The message is (where CR=RETURN or character 13) CR, I, , W, A, S, , H, E, R, E, !, CR, CR . To input this you first type M1820 followed by followed by the numbers for your message, each separated by a . This method dates back to the PET MONITOR. The message translates into PETSCII as the following sequence of hexadecimal numbers…

0D 49 20 57 41 53 20 48 (type RETURN here)

45 52 45 21 0D 00 00 00 (type RETURN here)

It doesn’t actually matter what numbers follow your last 0D, because my program is designed only to take notice of the data up to that point. To check your data, you can type M1820 and press RETURN. The ASCII dump on the right should say .I WAS H for the first line, followed by ERE!…. for the second line. If there’s a mistake, then you can easily edit it as described above. After this, to RUN the program you just type G F1800 and press RETURN. If you want to print your initial on the screen, you can do that instead, but unless your name is only one character long, then to print that you”ll have to alter the number following your CPX instruction, as well as key in the PETSCII codes for your name, then follow this with the codes for WAS HERE!, some of which you’ll have overwritten. These codes in hexadecimal are as follows – 20 57 41 53 20 48 45 52 21 0D 0D . Unfortunately, according to more than one book about this, the Commodore 64 is so badly designed that at least two different authors suggest storing your data in the cassette buffer, which obviously disables people from saving their program or other data to cassette! I hear it also affects the disk drive! Lots of people or even most people couldn’t afford the expensive disk drives when these books came out, so it’s hard to believe that it was so difficult to find any free RAM to store short programs like this or sprite data. The most popular location is $C000 OR 49152, where there’s 4K free. You can also reduce the amount of RAM available to BASIC and have about 30K for your Machine Code program. According to the ads in Your 64 magazine in 1984 a 1541 disk drive cost at least £195.95. Of course, there’s no problem saving my program to cassette using the C128. All you do is type the following line –

S”filename”,1,$1800,$1831 (then press RETURN)

To save your program to disk, all you need do is replace the number 1 following the filename with the number 8, the same as with Commodore BASIC V2.

What do these 6502 Assembly Language instructions actually mean and what do they do? Surely it can’t be that complicated, because there aren’t many of them. The 6502 CPU, as well as compatible processors such as the 6510, 8502, etc hasn’t got many registers. All it has are the accumulator (A), Stack Pointer (SP), Program Counter (PC), X index register, Y index register, Status Register (P), and that’s ALL! Due to the low number of registers, 6502 Assembly Language often uses the instruction STA $address meaning store the contents of the Accumulator or A register in the following memory location, although the Z80 CPU would copy it into one of its other registers. LDA means LoaD Accumulator with the following number, LDX is LoaD X register with the following number. Here’s a list of all these instructions.

LDX – load X index register with the following data
LDA – load A accumulator register with the following data
JSR – Jump to SubRoutine at the following address
INX – increment X index register by 1
CPX -compare X register with the following data, then set a particular flag, depending on the result
BNE – if a certain flag isn’t set, then branch or go to the part of the program at the following address
JMP – JuMP to the following address
BRK – BreaK out of this program

Unfortunately the program as listed above takes over the C128, disabling the RUN STOP key. To re enable this key, you need to add the following instructions.

BEQ $address of BRK instruction

Here’s how the revised program looks…

LDX #$00
LDA $1820,X
BEQ $1815
CPX #$0D
BNE $1802
JMP $1800

I think that’s enough for now. Just go over the contents of this post and look forward to reading my next post about the Commodore 128, which is coming up very soon!

Posted October 29, 2013 by C64hater in Uncategorized



commodore_128A Commodore 128 computer

I’m taking a break from the series “Drawing The Line”, which will continue for a little while at least, but posts about other subjects will also be made. I plan to try and draw lines from ANY points on the screen to ANY other points on the screen, but there’s no way of knowing how long this may take me to work out.

Now it’s time for a post about the Commodore 128 or C128 for short, especially as I’ve recently bought one! In this article I always type MONITOR in capitals, because it’s a Commodore BASIC V7 command. Some other words also appear in capitals for emphasis.

The Commodore 128, as well as almost every other computer of the time has graphics commands which can draw quite complicated pictures. Of course, you could draw graphics in a graphics editor or paint program, but first of all you had to buy one of these programs, and secondly, various people didn’t want to just draw graphics like this, but to calculate where the graphics would appear, as well as to produce animation. Each graphics screen on the Commodore 64 would normally take up 8K, although it could be compressed slightly, so depending on how much of the 64K could actually be used, you wouldn’t be able to produce much animation like that. Level 9 graphic adventures had the graphics drawn as the player entered each location. This seemed to be the same on all 8 bit computers they were released for. There was no way all those graphics could have fitted into amounts of RAM such as 48K or even 64K otherwise.

Unfortunately, there was a lot of brainwashing going on at the time. This brainwashing said something like “Computers?! You don’t want or need to program them! All you should do is use them to play and copy games!” I don’t know where this brainwashing came from. Atari started off with arcade machines and games consoles, but were keen to bring out computers and encouraged people to PROGRAM them. As I mentioned some time ago, there was INPUT magazine. This was a publication made up of 52 issues, which built up into a programming course. Various programs in this course weren’t listed for the Commodore 64, or only in versions under Simons’ BASIC, which cost £50. I think this was more money than I ever had at any one time in 1984. In the near future, I hope to post versions of some of these programs translated into Commodore BASIC V7.

I posted previously that no one should have to learn Assembly Language to program a computer. On the Commodore 128 you don’t HAVE to learn Assembly Language to program it, but the built in MONITOR, which includes an Assembler and Disassembler is there to offer everyone an introduction to 6502/6510/8502 Assembly Language. All three variations on this are basically the same type of Assembly Language, although the 6510 may have a few more instructions than the 6502 and the 8502 may have a few more instructions than the 6510.

With the Commodore 128, here is a machine that deals with everything lacking in the Commodore 64. To sum up, it has Commodore BASIC V7, instead of Commodore BASIC V2. This interpreter, which is 27K long instead of just 9K, includes lots of commands for colour, graphics, sound, and structured programming! As if that wasn’t enough, Commodore even included a built in MONITOR (4K?) which allows people to input programs in 6502/6510/8502 Assembly Language!! This facility had already been available on all but the earliest PET computers, but wasn’t included with the Commodore 64 or the earlier VIC-20. This makes Jack Tramiel guilty as Hell on TWO counts! Not only did the Commodore 64 have no BASIC commands for colour, graphics, or sound, BUT no Machine Code MONITOR to fall back on either! I’m surprised he didn’t get the electric chair or a lethal injection for the number of lives this has affected. Murderers often only kill one person, though, so fewer people are affected than have been by the lack of a reasonable BASIC and MONITOR on the Commodore 64. I recently found out that the reason Commodore disk drives are so slow is for the simple reason that they aren’t true disk drives, but serial devices! That makes a third crime he’s committed. If these acts were all legally recognised as crimes, then that means he could’ve got LIFE imprisonment at least. Bill Herd was the hero who led the engineering team behind the C128, continuing from his earlier success on the Commodore 16 and Plus 4, but bad marketing techniques by Commodore turned the C16 and C Plus 4 into failures, while the C128 was only a moderate success. Commodore marketing also led to the downfall of the Amiga.

The Commodore 128 isn’t all that different from the Commodore 64, it’s the built in software or firmware that makes it different, like with the android “brothers” Data and Lore in Star Trek: The Next Generation , as well as KITT and KARR in the classic series of Knight Rider . What these examples make clear is that two devices can use similar, compatible hardware, but be very different due to the software or firmware they contain. The Commodore 64 is like Lore and KARR, being the flawed or evil prototype. However, the Commodore 128 BASIC V7 and built in MONITOR make its Commodore 64 compatible hardware of VIC-II and SID chips accessible and easy to program. It does have at least 128K (upgradeable to 512K or even 1Mb), as well as the higher resolution 80 column VDC video chip approaching 16 bit graphics quality, but unless Machine Code programs use the extra RAM or the VDC, then they should run on the C64 as well. I’ve recently read that when programming in Assembly Language on the C128, most things are the same as on the C64. I’ve even managed to type some Assembly Language programs into the C128 MONITOR, then SAVE them to cassette and LOAD them in C64 mode. They usually run, but the reason any of them don’t run in C64 mode may be to do with what address they’re assembled at. You must also end your programs with RTS (Return To Subroutine) instead of BRK (BReaK) if you want to call them from BASIC, otherwise they won’t work in BASIC V2 or in C128 mode unless run from the MONITOR or an Assembler. The whole experience is quite schizophrenic, with me often thinking what computer or what kind of computer it is. All this and I haven’t even tried the CP/M side of it yet!


I think Jack Tramiel deserved a good PEEK and POKE AND 32 OR 8! People often read or heard the phrase “You really need to learn Machine Code!”, and software houses bragging about their programs being written in 100% Machine Code, but this usually actually meant Assembly Language. People’s usual usual response to being told they had to learn Machine Code was something like a nod, the response “Right” and a false smile. I was thinking something like “OMG, how could I ever do that and how long would it take?!” You could write a program in Assembly Language, then look up all the hexadecimal numbers which represented the opcodes, and write them, as well as your data, down as Machine Code. This is called “assembling by hand”, but is very tedious. The decision about whether or not to buy an Assembler, which one, for how much money, or to buy another book about BASIC V2, or another game, meant that only a small minority of C64 owners had an Assembler, but 100% of C128 owners had one at their disposal. This situation is mirrored nowadays by most people not having any programming language installed on their Windows PCs or Macs, because no programming language was supplied with them and isn’t featured in the manuals.

I think that the Commodore 128 was something like a “Super Commodore”, a bit like the concept of a “Super Spectrum”. Various Commodore users, such as members of ICPUG (Independent Commodore Products User Group) wanted a Commodore computer with a modern BASIC instead of an antique BASIC, an 80 column display and which could run the operating system CP/M. Sinclair Spectrum users also wanted a more powerful, but similar machine to the Spectrum. Sinclair made a drastic departure with their QL, based round a 68008 CPU instead of a Z80, allegedly only 8 colours instead of the Spectrum’s 16, and aimed at the business market instead of home users, but its SuperBASIC language was totally brilliant! It was in a similar vein to BBC BASIC or COMAL. Amstrad with their CPC range (called Schneider in Germany, as well as mentions in the ROM of Solavox and other names for use in various countries), Elan with their Enterprise, and MGT with their Sam Coupé, stepped in to fill this demand, but only Amstrad was successful, while the others were too little, and/or too late. The Commodore 128 was the ultimate Commodore computer, using an extended version of the earlier Super Expander 64 BASIC or Commodore BASIC 3.5 called Commodore BASIC V7, continuing with the Commodore “Kernal” ROM, the VIC-II video chip, and the SID music synthesizer chip. All Commodore 64 peripherals were supposed to be compatible with the C128.

After the Commodore 128, the company didn’t take their own design of computers any further, but built PCs, as well as buying the rights to the Amiga. This was like a “Super Atari” computer, a progression of the Atari 8 bit, both partly designed by Jay Miner, but based round the 68000 CPU instead of the older 6502, 6510, or 8502 CPU. I don’t think the 68000 family of CPUs bears any real similarity to the 6502, 6510, or 8502 CPUs. I know that they were originally based on the Motorola 6800, but then Motorola took a different path with their 6809, which is the ancestor of the 68000 series chips. IMHO the 68000 series of chips has more in common with the Z80 CPU, because the Z80 has several 8 bit registers called B, C, D, E, H, and L, which can also double up to become the 16 bit registers BC, DE, and HL, while the 68000 has a lot more registers, and can work on bytes or words (i.e. 2 bytes=1 word), but the 68000 family of CPUs can also work on long words (32 bits or 4 bytes) as well.

Commodore BASIC V7 on the C128, as it says on startup, is still based on the BASIC Commodore bought from Microsoft back in 1977. However, over the years numerous extensions were added to this by Commodore themselves, creating their own unique commands, so they didn’t have to pay Microsoft any more money until they bought a Microsoft BASIC for the Amiga in 1985 or 1986 after Jack Tramiel had left. It also seems that most or even all Commodore BASIC 3.5 programs as on the Commodore 16 and Commodore Plus 4 will RUN under Commodore BASIC V7, which makes a mockery of the Commodore statement to ICPUG that BASIC V2 was chosen as the built in Commodore 64 BASIC to cater for the large user base which still used BASIC V2. Of course, on the C128 you can only use 16 colours instead of about 121 (COLOR is followed by 3 parameters in BASIC 3.5 instead of 2 in BASIC 7), and any sound effects or music in Commodore BASIC 3.5 may have to be rewritten. Any claims of generating more than 16 colours are probably due to stipple effects.

Commodore BASIC V7 was the culmination of a series of upgrades to Commodore BASIC V2, which had begun with the VIC Super Expander cartridge, continued with the Super Expander 64 cartridge, and a further upgrade was even built in to the Commodore 16 and Commodore Plus 4 computers called Commodore BASIC 3.5. This doesn’t use the same commands as Simons’ BASIC, which is quite different. Unfortunately, the Commodore 64 still carried on being sold with only Commodore BASIC V2 on board for its roughly 12 year period in production, which as I said previously, ENDED 17 years after Jack Tramiel originally bought Microsoft BASIC for the 6502 processor! Sinclair, who were forced out of their North American joint venture with Timex by Jack Tramiel’s price war, upgraded the Spectrum ROM on their 128K models, by dropping their quirky BASIC keyword entry system with 128K BASIC, while retaining it in 48K BASIC, as well as a simple loader and 128K BASIC support for a new sound chip. Some Commodore 64 computers and/or disk drives were later bundled with the software GEOS to try and make up for Commodore BASIC V2. GEOS is designed to look and feel quite like the early Apple MacIntosh OS, but this seems to have been allowed on the C64 and C128, although Apple sued Digital Research over their GEM software for PCs, forcing them to change its look and feel, but this didn’t affect the continued use of the pre court case version of GEM on the Atari ST, which they didn’t feel was a threat to their mainly business market. Amazingly enough, I’ve just found out that GEOS switched out (i.e. turned off) the Commodore 64 BASIC ROM, as well as the Kernal ROM. This means it was almost like turning it into a totally different computer, or fixing it! Of course, it all depends on the price of disk drives in those days, possibly bundled with the C64, whether or not this was an option for most people. I may write some more about GEOS after reading up on it. The first disk drive I owned came built in to my Amstrad CPC664, which made disk drives cheaper and more accessible, but the Commodore 64 disk drives cost about the same as or more than the Commodore 64 itself. I’ve recently searched through early issues of Your 64 magazine to check up on this and found that the cheapest 1541 disk drive advertised in 1984 was £195.95. I haven’t found anyone who was selling them cheaper in the magazines Commodore Horizons, or Your Commodore either. I remember that the Commodore 64 was usually selling at the recommended retail price of £199. I haven’t got any exchange rates for 1984, so I don’t know what this price was in any other currency, but I have found ads in 1984 issues of the US magazine Compute!, offering the Commodore 64 itself for $199. Alternatively, you could buy a nice Acorn Electron with advanced BBC BASIC with its inline Assembler for the same price as the Commodore 64, of £199.

Here’s a list of just some of the amazing Commodore BASIC V7 commands which the Commodore 128 had built in to avoid C64 style stress, high blood pressure, and nervous breakdowns. Some of these commands had already been supplied with the Commodore 16 and Commodore Plus 4, though.

BOX [colour source],X1 Y1,[X2,Y2], [angle],[paint]

CIRCLE [colour source],X, Y,Xradius,Yradius,[start angle[,[end angle],rotation, increment (can draw circles, elipses, octagons, diamonds, or triangles!)

COLLISION type, line number (checks for SPRITE collisions)

COLOR source, colour

DRAW colour source,x1, y1 TO x2, y2

ENVELOPE number, attack, decay, sustain, release, waveform, pulse width

GRAPHIC screen mode, clear or not, split screen option

HELP (display program line and section containing error)

HEX$(number) – using this command preceded by PRINT converts decimal memory locations into hexadecimal, as used in Assemblers!

KEY function key number, string

MOVSPR number, X, Y (positions or moves sprite)

PAINT , X, Y, [mode]

PLAY “musical string”

SCALE on or off, Xmax, Ymax (rescales graphics commands output, reducing the size of any graphics drawn in size, by specifying maximum screen cartesian coordinates, which are larger than the default coordinates. This command could simulate the BBC or Acorn Electron screen coordinates, or produce simple resizing effects, like when I was drooling over a Sinclair QL rescaling concentric circles at the computer club)

SOUND voice, frequency, duration, [step direction],[minimum frequency],[step size],[waveform],[pulse width]

SPRDEF (calls up built in sprite designer)

SPRITE number, on=1 off=0

TEMPO number (for music)

The command PLAY makes playing musical notes quite easy. I posted some time ago that I found it impossible to play more than one note at a time using the crappy Commodore BASIC V2 on the C64. Here’s how to play a chord in Commodore BASIC V7 –

PLAY “V1 C V2 E V3 G”

You can easily put this into a program to play a sequence of chords. Here’s how.

10 PLAY “V1 C V2 E V3 G”
20 PLAY “V1 D V2 $G V3 A”
30 PLAY “V1 C V2 E V3 G”
40 SLEEP 2
50 GOTO 10

Try doing THAT in Commodore BASIC V2! I’m looking forward to it, TMR.

Commodore, as well as various other people, wrote manuals and books about the C128 and the facilities it had built in or came with it, such as Commodore BASIC V7 and its MONITOR, because everyone who bought a C128 had those facilities. In comparison, not much was ever written about the early Super Expander upgrades to Commodore BASIC V2, not much was written about any later version of Commodore BASIC until the Commodore 16 and Commodore Plus 4 came out, because they weren’t supplied with the computers and not that many people realised they needed them. I remember reading instructions in the Commodore 64 Programmer’s Reference Guide about using the 64MON cartridge, wondering how much it cost and what alternatives there were.

As for me actually doing any Machine Code programming on the Commodore 64, it was limited to reading the Machine Code series in Your 64 magazine, and typing in various listings from a few magazines, some of which didn’t even work. Although Assembly language on any particular computer is standard, each Assembler has its own commands and directives, so that makes it more difficult to explain how to program in Assembly Language, unless everyone has access to the same Assembler, such as one built in to or supplied with the computer.

Using the Commodore 128 MONITOR recently, I soon managed to type in and modify one 6502 Assembly Language listing and then even worked out how to reproduce the game loader screen effect of cycling through various colours very fast, creating multicolour ripples. I’ve also managed to learn how to stay in the monitor and run programs from inside it, by using BRK, instead of using RTS and having to return to BASIC and run them. In spite of this, the MONITOR is limited in that it doesn’t use labels. By this I mean text such as LOOP: followed by an instruction later such as JMP LOOP, meaning jump to the address labelled as LOOP. Instead of this you’d have to type JMP $1802 for example if your loop which you wanted to jump back to was at address $1802. I think the MONITOR requires having to look up or remember memory locations, similar to using Commodore BASIC V2 POKEs, but at least the addresses are in hexadecimal with 4 digits including the letters A-F, which I think is easier than 5 digit decimal numbers. It was quite easy for me to generate a game loader type screen by using the memory locations 53280 (border colour) and 53281 (screen background colour), then I got a lot of satisfaction in “taking over” the computer, sometimes disabling the RUN STOP/RESTORE keys’ effect, making it lock up, sometimes causing a RESET, and often having to press the RESET button myself. I soon found out how to call $FFE1 to check for the RUN STOP key, though. Each time the C128 locked up or crashed, my program was left intact in RAM, in spite of warnings in Commodore 128 manuals that my program would be wiped out by pressing RESET. This may be due to an upgrade ROM fitted to my Commodore 128, but I can’t be sure. I’ve also found, as suspected, that at least simple Assembly Language/Machine Code programs written for various earlier Commodore computers can also be typed in and RUN from this MONITOR because they use the same Commodore “Kernal” OS routines, such as CHROUT at $FFD2 which prints a character to the screen, although I’ve used the location $1800 to begin these programs at or the ORG, as it’s called in more sophisticated Assemblers! I’ve managed to print a vertically scrolling message “I WAS HERE!” which continues until I break out of the program by pressing RUN STOP and RESTORE! The program uses the X register to create a loop to read in the message, but I haven’t yet worked out how to create another loop to print this message a certain number of times, so the only ways out are to press RUN STOP and RESTORE or the RESET button. I can hardly believe it. It’s yet another crime by Jack Tramiel that he failed to include a MONITOR in the Commodore 64! I wonder how much money that saved him per Commodore 64 sold?! The BBC Micro and Acorn Electron even had an Assembler built in to their BBC BASIC, which allowed programmers to mix lines of Assembly Language with BASIC!

I think that’s enough about the Commodore 128 for the moment. This will be continued very very soon. Look forward to that.

Posted October 25, 2013 by C64hater in Uncategorized

DRAWING THE LINE (PART 3)   4 comments


Part of my latest program listing

Now it’s time for the next part of this series exposing just how difficult it is to draw lines in Commodore BASIC V2 on the Commodore 64 graphics screen! I have actually drawn a line across the C64 screen, but it took me 29 years to solve the problem! This series will continue, but there will be other posts made about various subjects inbetween the posts in the series “DRAWING THE LINE”. In this instalment, I’ll be extending, as well as tidying up, the line drawing program from last time. I felt I needed to write out in full everything I’d done the way I’d developed it POKE by POKE, instead of using FOR…NEXT loops or READ and DATA statements. I’m writing this sentence a few hours after receiving my Commodore 128 from eBay, although I started this article a few days before that and didn’t finish it til weeks after receiving the C128. I have no way to SAVE any programs at time of writing, but a Commodore 1530 C2N cassette data recorder is on its way to me. My opponent TMR tried to claim this wouldn’t work, but the C128 manuals say otherwise. I plan to buy a floppy drive emulator ASAP. Of course, drawing the line I’m doing in this series can be achieved quite easily in Commodore BASIC V7 on the Commodore 128 as follows.


20 GRAPHIC 1,1

30 DRAW 1,0,0 TO 319,199

No more than the lines above are needed, but I added the two following lines to wait a few seconds, then return to a text screen

40 SLEEP 4


In the original program I adapted from the “Commodore 64 Programmer’s Reference Guide”, the background colour was cyan and the drawing colour was black. The screen background colour can be set to cyan and colour 1 to black with this line


As the DRAW command in line 30 starts with the number 1, this means it will draw in colour source 1. You can RENUMBER the program if you wish. All this without a PEEK or POKE in sight! I’ll try to keep mentions of the Commodore 128 to a minimum in this post, but that computer will be covered in some posts scheduled for the very near future.

Last time, when I finally cracked the problem of drawing a line in Commodore BASIC V2, I found it hard to believe what I’d done! I was left with a sense of total defeat in 1984-1985, wondering how some people could actually program the Commodore 64, while I had failed miserably. This has affected my confidence ever since then. I tried to get a refund from the lying little shit of a shopkeeper, whose last words to me about using the synthesizer chip, before I left the shop with the Commodore 64 were “It’s EASY! You just use PEEK and POKE commands”. Later on, when I went back to ask for a refund, he said “You’re JOKING!” and I was verbally abused by him and his assistant. He even had the cheek to say that he didn’t sell computers any more (he sold various electronic goods), but obviously this was irrelevant, because when I bought the C64 from him there was no sign saying he was going to stop selling computers and he didn’t tell me this either. My Dad was totally defeatist and didn’t even bother coming to the shop with me to help fix the mess he’d got me into. I think we may have saved £20-£40 by buying from that shop, but the misery it caused me was beyond belief. Of course, it was Jack Tramiel who set both of us up for this, but my Dad was quite gullible and liked to think he knew it all. His preference for the Commodore 64 was based on the name Commodore BUSINESS Machines instead of Atari’s games background, learning word processing (before we’d heard of replacement Spectrum keyboards), and “It’s 64K!”, although it turned out that the Sinclair Spectrum 48K had more RAM free to BASIC. After my success last time, I’ve started feeling that I could achieve anything. There’s this course about BASIC V2 which doesn’t even cover hires graphics!

I’m coming back to this and other problems after later experience programming or even just attempting to program the Amstrad CPC, MSX, Amiga, and Atari 8 bit computers. I think this proves that the Commodore 64 isn’t for beginners, but requires previous knowledge of computing on other machines. I’m sure that PET fanatics loved it! At this stage I’d like to thank Amstrad PLC and Locomotive Software for the BASIC on the Amstrad CPC, Acorn Computer for BBC BASIC, Bill Gates and Microsoft for MSX BASIC and AmigaBASIC, Kay Nishi and the MSX Consortium for creating MSX computers, as well as Atari computers (Warner Bros era), Shepherdson Microsystems for Atari BASIC, and last but not least Jay Miner for helping to design the original Atari 400 and 800 computers AND the Amiga computer. I wouldn’t have been able to get back to this problem and make any progress on it with the antique, crippled Commodore BASIC V2 on the Commodore 64 if it hadn’t been for these people and others I may have forgotten to mention helping me to understand more about computers!

My opponent TMR started programming on the less complicated Commodore VIC-20, which also has Commodore BASIC V2, but no hires graphics and limited sound. I also suspect he understands quadratic equations, whatever THEY are! I’m artistic and creative, but I hate maths. This means I approach this problem from a completely different angle to TMR and his mates! David Simons, programmer of Simons’ BASIC started on a PET and also had a VIC-20 before moving on to the Commodore 64. Paul Roper, author of the book “Machine Code Games Routines for the Commodore 64” said he was programming in 6502 Assembly Language long before the Commodore 64 came out, and mentioned the Acorn Atom. This is a very user friendly 6502 based computer, which is the predecessor to the BBC Micro. Jim Butterfield wrote or co wrote various books about programming the Commodore 64 in 6502 Assembly Language. I’m currently reading his book “Machine Language for Commodore Machines” as printed on the pages, or “Machine Language for the Commodore 64 and other Commodore Computers” as it’s titled on the cover. This book lists programs which make use of Commodore “Kernal” OS routines which are included on the PET, VIC-20 and Commodore 64. He was an Editor of Compute magazine in the USA and it turns out he was a VERY early computer user who started programming on a company Collins C8401 mainframe computer in 1963!!!! Obviously this was 14 years before even the PET was released. He may have built homebrew computers more primitive than the PET. He had spent some time programming the PET before the Commodore 64 came out. As for me, I was thrown in at the deep end with the Commodore 64! It would probably have been better to start off on a Sinclair ZX81. Commodore KNEW that most of their customers were first time computer buyers, as Gail Wellington of Commodore UK Ltd mentions in this video just after 9 minutes in , so in that case they knew that they’d had no experience of using earlier Commodore computers to prepare them for the Commodore 64.

I later read in Amstrad CPC magazines and books that the Amstrad CPC had lots of useful ROM based routines, and I even managed to write some programs in Z80 Assembly Language to use some of these. Unfortunately, although the Commodore 64 has various routines in ROM, which are listed in the Commodore 64 Programmer’s Reference Guide, I think these have mainly been copied from the Commodore PET and VIC-20. I think this is the reason I’ve never heard any mention of a SYS call to enter the hires or lores graphics mode and clear the screen. Perhaps two POKEs and PEEKS, as well as an AND and an OR may do it. The PET and VIC-20 had NO bitmapped graphics screens, only text screens. I remember reading various Commodore 64 manuals by Commodore and third party books, then thinking “WTF is all this?! Why can’t I just type a few commands for a program to do some amazing graphic art, like on the BBC Micro or Acorn Electron?” I got a 5.25 inch/13.34cm disk, formatted it on a BBC Micro, then typed in and saved various short BBC BASIC graphics demo programs. Some of my favourites were “Persian” a well known program which produces a woven carpet design, and “Nightmare”, which produces various shapes and discordant notes. I think this was the start of the demo scene, or perhaps it started with Atari dealer demo disks before that. I doubt if it would be possible to recreate “Persian” in Commodore BASIC V2 at all, even at a resolution of 160×200 with 16 colours, instead of 320×256 on the BBC Micro with 4 colours. “Nightmare” included various filled shapes, probably made up of filled triangles, done with a BBC BASIC command PLOT 69. The famous “Rotating Squares” program, as used in classic Doctor Who on the TARDIS console screen to represent the time vortex used logical colour switching, to create an effect like a flashing neon sign. Logical colour switching means that although your colours are numbered 0-15, each numbered colour can be ANY actual colour available in your palette, so by changing the actual colours of these numbered colours, you can produce animation. The BBC Micro used the 6845 video chip. I was able to recreate this effect on an Amstrad CPC, using the knowledge gained from the BASIC conversion course in “MSX User” magazine, because it used the same 6845 graphics chip and Amstrad’s Locomotive BASIC also had this colour switching facility. I don’t think, although I’m not sure, this is possible with the VIC-II chip, because although the Commodore 64 has colours numbered 0-15, these colours are fixed at least in Commodore BASIC V2. Looking at the Commodore BASIC V7 graphics commands with their colour “sources” parameters, I’m beginning to think that option may exist. Perhaps this effect could be simulated if a fast enough routine could be developed. Unfortunately, this would probably need to be in Machine Code, especially as the Commodore 64 is much slower than the Atari 8 bit and the BBC Micro Model B.

To sum up the techniques of plotting points and drawing lines in Commodore BASIC V2, here we go. All computer graphics screens are bitmapped, meaning that the data for each dot or pixel is held by a particular bit, which may be short for binary digit, or just the smallest amount of RAM which can’t be subdivided any further, possibly from when Spanish coins called “Pieces of Eight” (i.e. 8 Reales) were cut into 8 bits to make small change. RAM stands for Random Access Memory, actually meaning Read/Write Memory, because RWM would be hard to pronounce.

Different computers have different ways of bitmapping their graphics screens, like different street layouts in towns or cities. The screen RAM could be arranged to start on the top line, going all the way horizontally across the screen, before continuing on the next line down, then the following line, etc. Instead of this, the screen could be arranged in horizontal lines, each one 8 lines lower than the previous line, creating a Venetian blind effect when loading a screen, as on the Sinclair Spectrum, copied for the Amstrad CPC to make games conversions easier. While loading from cassette, the Commodore 64 blanks the screen, but I’m not sure about loading from its S-L-O-W disk drives, such as the 1541. If you could see a Commodore 64 graphics screen loading slowly, then it should load in a character cell by character cell order, from left to right, filling each horizontal line in each square before moving onto the next square!

Now back to my really messy program from last time…

5 BASE=2*4096:POKE 53272,PEEK(53272) OR 8:REM PUT BITMAP AT 8192



30 FOR C=0 TO 15

40 FOR I=1024 TO 2023:POKE I,C:NEXT C

50 POKE 53280,C

60 POKE 8192,128:POKE 8193,64:POKE 8194,32:POKE 8195,16:POKE 8196,8:POKE 8197,4

70 POKE 8198,2:POKE 8199,1:POKE 8200,128:POKE 8201,64:POKE 8202,32:POKE 8203,16

75 POKE 8204,8:POKE 8205,4:POKE 8206,2:POKE 8207,1

80 POKE 8520,128:POKE 8521,64:POKE 8522,32:POKE 8523.16:POKE 8524,8:POKE 8525,4

85 POKE 8526,2:POKE 8527,1

90 POKE 8848,128:POKE 8849,64:POKE 8850,32:POKE8851,16:POKE9952,8:POKE 8853,4

95 POKE 8854,2:POKE 8855,1:POKE 9176,128:POKE 9177,64:POKE 9178,32:POKE 9179,16

96 POKE 9180,8:POKE 9181,4:POKE 9182,2:POKE 9183,1:POKE 9504,128:POKE 9505,64

97 POKE 9506,32:POKE 9507,16:POKE 9508,8:POKE 9509,4:POKE 9510,2:POKE 9511,1

98 POKE 9832,128:POKE 9833,64:POKE 9834,32:POKE 9835,16:POKE 9836,8:POKE 9837,4

99 POKE 9838,2:POKE 9839,1

100 POKE 10160,128:POKE 10161,64:POKE 10162,32:POKE 10163,16:POKE 10164,8

110 POKE 10165,4:POKE 10166,2:POKE 10167,1

1000 NEXT C

1010 GOTO 30

1020 GOTO 50

Continuing in the same vein, here’s what we do. We need to pass through a total of 25 character cells in our screen. The end of the screen RAM which starts at 8192 is 7999 bytes higher up. As 8192+7999=16191, we know not to POKE to any addresses higher than that. Continuing to add 328 bytes for the beginning of each new character cell, we get the following start locations – 10488, 10816, 11144, 11472, 11800, 12128, 12456, 12784, 13112, 13440, 13768, 14096, 14424, 14752, 15080, 15408, 15736, 16064. The next number in this sequence would be 16392, but because this is higher than the end of our screen RAM at 16191, we know our list of starting positions is now complete! To refresh your memory, here are all the starting positions from the beginning of screen RAM 8192, 8520, 8848, 9176, 9504, 9832, 10160. This gives us a total of 25 addresses in our screen RAM, which are each the top line of a character cell. These could either be placed in lines of DATA statements, or just calculated by adding 328 in FOR…NEXT loops. As for an algorithm or equation, that would be more complicated, so I won’t attempt that at least for the moment. Apart from this I’m an ARTIST, not a MATHEMATICIAN!!!!

I think I should renumber the lines and insert some lines with the following commands somewhere into the program,

DATA 128,64,32,16,8,4,2,1

BASE=8192:GOSUB [line number]

So, here goes! (don’t type this in)

10 BASE=2*4096:POKE 53272,PEEK(53272) OR 8:REM PUT BITMAP AT 8192



40 REM FOR C=0 TO 15

50 FOR I=1024 TO 2023:POKE I,C:NEXT C

60 REM POKE 53280,C


80 FOR NUM=1 TO 8




120 DATA 128,64,32,16,8,4,2,1


140 BASE=BASE+328

150 IF BASE>16191 THEN END

160 REM POKE 8192,128:POKE 8193,64:POKE 8194,32:POKE 8195,16:POKE 8196,8:POKE 8197,4

170 REM POKE 8198,2:POKE 8199,1:POKE 8200,128:POKE 8201,64:POKE 8202,32:POKE 8203,16

180 REM POKE 8204,8:POKE 8205,4:POKE 8206,2:POKE 8207,1

190 REM POKE 8520,128:POKE 8521,64:POKE 8522,32:POKE 8523.16:POKE 8524,8:POKE 8525,4

200 REM POKE 8526,2:POKE 8527,1

210 REM POKE 8848,128:POKE 8849,64:POKE 8850,32:POKE8851,16:POKE9952,8:POKE 8853,4

220 REM POKE 8854,2:POKE 8855,1:POKE 9176,128:POKE 9177,64:POKE 9178,32:POKE 9179,16

230 REM POKE 9180,8:POKE 9181,4:POKE 9182,2:POKE 9183,1:POKE 9504,128:POKE 9505,64

240 REM POKE 9506,32:POKE 9507,16:POKE 9508,8:POKE 9509,4:POKE 9510,2:POKE 9511,1

250 REM POKE 9832,128:POKE 9833,64:POKE 9834,32:POKE 9835,16:POKE 9836,8:POKE 9837,4

260 REM POKE 9838,2:POKE 9839,1

270 REM POKE 10160,128:POKE 10161,64:POKE 10162,32:POKE 10163,16:POKE 10164,8

280 REM POKE 10165,4:POKE 10166,2:POKE 10167,1


1010 REM GOTO 40

1020 REM GOTO 60

As you can see from the various lines beginning with REM statements, a lot of these lines can be deleted. Unfortunately, while editing this program to make a shorter version with FOR…NEXT loops DATA statements, etc I managed to get an error. This was just like the original program from Your 64 magazine Issue No. 1, which plotted a single dot in the middle of the screen, which could be turned off by pressing a key, then turned on again by pressing a key again. This program only opened and cleared a graphics screen before stopping with an error message. Unfortunately, when you get a error message in a graphics program in Commodore BASIC V2 on the C64 you can’t read it! This is because the C64 prints the error message as coloured squares on the graphics screen! I think that any non Commodore computer would print a readable message, helping you to debug the program. As for that program published in 1984, I had no idea what was wrong with it, I don’t think any correction was ever published and I’ve only just managed to debug it, by adding a right hand bracket to the last line. At the time I was strictly following advice to type in exactly what was listed. I’ve even managed to take the program further, by plotting lots of random pixels and in various colours. Of course, a Sinclair Spectrum or an Atari would even have prevented me from entering the line with the error. As for the program I’ve been developing here, I got the same kind of unreadable message made up of coloured blocks, I worked out that the memory location to POKE was 53265, but there was no easy way back to the text screen which also preserved the error message. Even typing in a line from the Commodore 64 Programmer’s Reference Guide which clearly said that this sequence of commands will turn off bitmap mode just left me with a blank screen! Of course, this line also appeared as coloured squares, but I’m sure I typed what it said. Pressing RUN STOP and RESTORE resets the C64 and the C128 both in C64 and C128 modes, and the error message appears for a fraction of a second, but it’s not for long enough to read it. Of course, there’s no command to enable a function key to print any commands, like in BBC BASIC, Commodore BASIC V7, Amstrad Locomotive BASIC, Microsoft Extended BASICs, or MSX BASIC.

This leaves us with the following program.


20 BASE=2*4096:POKE 53272,PEEK(53272) OR 8:REM PUT BITMAP AT 8192








90 FOR NUM=1 TO 8



115 CL=CL+1





150 GOTO 90


200 GOTO 200


1000 DATA 128,64,32,16,8,4,2,1

The output of this program

Unfortunately, although the program draws a line across the screen it doesn’t draw a line from the top left hand corner to the bottom right hand corner, but reaches the bottom of the screen somewhere to the left of the bottom right hand corner. I think this is because the screen has more columns than rows. At the moment, I don’t know how to edit the program to achieve the desired result and I don’t think I’ll live long enough to work that out anyway, so I think I’ll have to leave it.

Here’s some more stuff I’ve managed to work out from the “Commodore 64 Programmer’s Reference Guide”. I first read it in 1984, then bought another copy several years ago from eBay, eventually lost it, then recently re read parts of it online. I think learning Japanese may be easier. When drawing lines on a Commodore 64 graphics screen, you have a few choices of where to put this screen in RAM. One of these choices is at location 8192, but wherever it is, let’s call it BASE for the moment, while not forgetting that only the first two letters BA will be taken any notice of by the crappy Commodore BASIC V2. Perhaps you’d be better off calling it TL for Top Left, or SS for Screen Start. Unfortunately, although Commodore BASIC V7 has over 140 commands, it’s still limited to variable names with only the first 2 characters being significant!

To draw horizontal lines on the Commodore 64, here’s what you MAY be able to do.

1. Choose a RAM location between BASE and BASE+7999.
2. POKE that RAM location with 255.
3. Add 8 to the last RAM location which you’ve just POKEd
4. POKE this location with 255 as well
5. Repeat steps 3, 4, and 5

To draw vertical lines on the Commodore 64, here’s what you MAY be able to do.

1. Choose a RAM location between BASE and BASE+7999
2. POKE that RAM location and each subsequent location with one of the following numbers – 1,2,4,8,16,32,64,or 128. Once you choose a number to POKE, stick with the same number for each RAM location which you POKE until you finish drawing your line.
3. Add 1 to the last RAM location which you’ve just POKEd, until you’ve POKEd 8 pixels, then add 320 to the RAM location where you started
4. Repeat steps 2 and 3


1. Generate a random RAM location between BASE and BASE+7999, using the RND and INT commands.
2. Assign the random RAM location to a variable, then POKE that variable with the number 1,2,4,8,16,32,64,or 128, chosen at random
3. Repeat steps 1 and 2

You already know that the start of the hires graphics screen RAM can be placed at location 8192. There are a few other locations where it can be placed, but not all of them are available from BASIC and 8192 may be the only available location in BASIC, or without relocating BASIC. Due to the choice of locations, it’s best to assign the start of screen RAM to a variable such as BASE, BS TL, or SS. Whatever you decide to call it, you can calculate all the parts of the screen RAM from that starting address. I think this is called relative coordinates or relative addressing, instead of absolute coordinates or absolute addressing. To do this, carry out the following calculations.

Next character cell to the right, on first row=BASE+8, next=BASE+16, next=BASE+24, next=BASE+32, etc
Next character cell down, on second row=BASE+320, ON third row=BASE+640, on fourth row=BASE+960, etc

Now I’m taking a break from this series “Drawing The Line” to study Commodore BASIC V7 and enjoy my new/old Commodore 128. After this I could learn Japanese before returning to the more difficult task of BASIC V2 programming on the Commodore 64. With the C128 I plan to show people what the Commodore 64 SHOULD have been like, but how Commodore RUINED it! I didn’t manage to get one with a massive, old 5 ¼ inch disk drive, but these are really bulky, plus blank disks of that size are very hard to buy nowadays. I’ve also bought a Commodore 1530 C2N cassette data recorder on eBay. This is compatible with the C128, which CAN use a datasette or cassette data recorder from Commodore BASIC V7, not just from C64 mode with Commodore BASIC V2. This enables me to SAVE and LOAD various short Commodore BASIC V7 programs I’ve been writing. These programs all SAVE and LOAD quite quickly. I plan to buy a device soon which allows me to use SD cards to store floppy disk images. This is called an SD2IEC. I think it will also boot from CP/M disk image files. I’ve already got a similar device for the Atari 8 bit, but the plug and possibly some other parts make it incompatible. The cheapest versions of this are available from Poland. I’ve now also bought a Commodore 1541 II disk drive, which matches the C128 and C64C casing and looks quite like the 1571 disk drive! I bought one without a PSU, so it’s just sitting there for the moment while I wait for an original PSU to arrive from Germany. I’ve bought 10 blank disks from eBay UK. Modern replacement PSUs with the right output which may be laptop PSUs which have had their connectors cut off, then replaced with a 4 pin DIN plug are available from eBay but are all from the USA, so would take much longer to arrive here.

That’s all for now! Sayonara!

Posted October 18, 2013 by C64hater in Uncategorized

WHAT NEXT?   Leave a comment


How can you do this on the Commodore 64?

I had to make this post to tell everyone why I haven’t yet continued with Part 3 of my series “Drawing The Line”, otherwise people may lose interest in my blog.

Over the last few weeks I’ve been hard at work on two different themes. These are completing and shortening the quite messy program I wrote to draw a line part of the way across the Commodore 64 graphics screen, as well as exploring my new/old Commodore 128 computer and finding out the differences and similarities between it and the Commodore 64. I’ve found out a lot about both these subjects, which has really amazed me! I’ve also managed to debug a program listing from 1984 to PLOT a point on the screen, turn it off when the user presses a key, then turn it back on when a key is pressed again, etc! I’ve even succeeded in taking the program further. I never thought I’d be able to do anything like this. Of course, most Commodore 64 owners never managed to.

At the computer club I mentioned in an earlier post, games were discouraged, although even the organisers sometimes played games. There were usually just a handful of Commodore 64 owners there, totally outnumbered by Spectrum owners, as well as BBC owners and almost outnumbered by Apple II owners as well. This was in spite of the fact that the Commodore 64 was the second most popular computer in Britain at that time. I think this was probably because the Commodore 64 owners had realised that they couldn’t program it.

I’ve recently written a total of about 7,000 words on the subjects of “Drawing The Line” on the Commodore 64, as well as about the Commodore 128. These could be split into 4 separate posts, so look forward to reading them in the very near future! I’ve made some fantastic discoveries about programming the Commodore 64 and the Commodore 128, so prepare to be amazed!

Posted October 9, 2013 by C64hater in Uncategorized