THE COMMODORE 128: THE FIXED AND UPGRADED COMMODORE 64 (PART 2)   Leave a comment

THE COMMODORE 128: THE FIXED AND UPGRADED COMMODORE 64 (PART 2)

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
JSR $FFD2
INX
CPX #$0D
BNE $1802
JMP $1800
BRK

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.

JSR $FFE1
BEQ $address of BRK instruction

Here’s how the revised program looks…

LDX #$00
LDA $1820,X
JSR $FFD2
INX
JSR $FFE1
BEQ $1815
CPX #$0D
BNE $1802
JMP $1800
BRK

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!

Advertisements

Posted October 29, 2013 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: