Basic data management

If you want to do this on a real Commodore 128, you will need a blank floppy disk, and if you are doing this from an emulator, you will need a blank floppy image. I have created a blank d64 image from the Vice emulator. To do that, click File, Attach disk image, and Drive 8 to display the Attach disk image dialog. There, type in a filename, click Create image, and finally click Attach.

You can make sure that your disk is correctly attached by typing DIRECTORY. This is what you should see:

To create a blank area of memory, enter the machine code monitor and fill a memory area with the value zero. Type:

MONITOR

F 1000 1100 0

To ensure that memory now is blank, type M 1000. Type X to leave the machine code monitor. Note that the monitor is using the hexadecimal, so the area that we have blanked out is from address 4096 to address 4352.

From the Basic parser (that is, outside the machine code monitor) the POKE command is used to set a byte and the PEEK function is used to get a byte. Commodore Basic uses the decimal number system but is equipped with functions to convert between the systems.

So, to set a byte at position 4096 (in this case, the value 5) type:

POKE 4096, 5

To read the same byte, type:

PRINT PEEK(4096)

Also, you can enter the monitor and type M 1000. This is what you should see:

The C128 has built in commands for saving memory to disk and loading memory to disk. Let’s say that we want to save our byte and some following bytes, use the BSAVE command (Binary Save). This will save 4 bytes to a file called TEST.DAT, where the first byte is our value 5. The second argument is the device (B0 is device 8), the third argument is the address range (the character P must occur before the number).

BSAVE "TEST.DAT", B0, P4096 TO P4100

Type DIRECTORY to make sure the file is located there.

To load this file, use BLOAD (Binary Load). This is a test you can do.

Type PRINT PEEK(4110) to ensure address 4110 is empty. Load the file into the address 4110 by typing:

BLOAD "TEST.DAT", B0, P4110

Type PRINT PEEK(4110) again to see that it now holds the value 5, as loaded from the file.

Skeptikerpodden och tillhörande forum

In short: The last week has been dedicated to the podcast and the Swedish skeptic movement.

Det var ett tag sedan jag uppdaterade något på WinSoft.se, vilket grämer mig. Tiden har gått till vår podcast, Skeptikerpodden. Dessutom lanserar vi strax ett nytt forum, som redan är uppsatt. Om du är intresserad av skepticism (eller om du är vidskeplig för den delen) och vill diskutera frågan, kan du redan nu registrera ett konto och hoppa in. Trots att det är lite tomt så här i början. Forumet heter Skeptikerforum.

The oddities: GO64 and sound

GO64
In some ways, GO64 behaves as a command (GO) with one argument (64). For example, you can type GO64, GO 64 or even GO 70-6 and all will set the C128 in C64 mode. But in some ways, GO64 behaves as a command on its own. For example, from the fact that GO 60+4 does the job, you would perhaps expect GO 65 to generate a ?ILLEGAL QUANTITY ERROR, but it generates a ?SYNTAX ERROR. The fact that typing GO 8*8 sets the machine in C64 mode is strange enough.

Sound
The PLAY command plays notes and the SOUND command audio in any frequency. PLAY can deal with notes and volume envelopes but not pitch bending. SOUND can pitch bend but not deal with volume envelopes. This plays three notes, C, D and E, with a volume envelope that emulates a piano:

PLAY "CDE"

This plays a C-maj chord:

PLAY "V1 C V2 E V3 G"

This plays a pitch bending sound without a volume envelope:

SOUND 1, 8000, 40, 2, 7000, 100

The arguments are channel, frequency, duration, direction (2 means oscillate) and stepvalue.

If I make a program with a PLAY command that is directly followed by a SOUND command that plays a sound in the same voice channel, they are combined! This gives a pitch bending sound with a volume envelope! T5 means that I use the predefined guitar volume envelope, and HC means half note of C (two quarters long C).

10 SOUND 1, 8000, 50, 7000, 100
20 PLAY "V1 T5 HC"

The sprite engine

One of the built in applications in the C128 is the sprite editor. Enter it by typing SPRDEF. Choose a sprite number, use the cursor keys to move the cursor and numeric keys to draw. 1 will delete a pixel, 2 will draw with the first color. In multicolor mode, you can also use 3 and 4. To save and close the editor, press SHIFT+ENTER followed by ENTER.

The sprite engine in Commodore Basic 7 lets you enable and disable sprites, and control sprite movement. The SPRITE command is used to turn sprites on or off and to set the sprite attributes. The arguments I have used is one-based sprite index (1), on (1), cyan color (4) in front of other graphics (0).

10 SPRITE 1, 1, 4, 0

My next line of code, will tell the sprite to move to the left using the MOVSPR command. The arguments I have used are one-based sprite index (1), 90 degrees at a speed of 4.

20 MOVSPR 1, 90 # 4

Type RUN to start the show.

Manipulate a byte

When you get a tweet like this thrown at you, the only thing to do is to take another visit to the wonderful world of the C128 monitor. Let’s say that we were to make a program using assembler. We will store it at address 4096. Enter the machine code monitor by typing MONITOR, and view the current disassembled instructions at 4096 by typing D 1000.

The command for entering a line of assembly code is called A. You have to keep in mind that the disassembled machine code that D is displaying, has a slightly different format than the assambly you type in. Basically you type A, followed by the target address, the name of the instruction, and an operand (if any).

To simply enter a byte into memory, use the F command. Like the POKE command in Commodore Basic, you use F to set a 8-bit value at a specific address. The difference between POKE and F, is that F takes two addresses, and fills the given range with the given value, while POKE only deals with one address at the time. You would need to make an iteration, perhaps using FOR, to have POKE to fill a range. Type F, followed by the start and end address, and concluded with the byte. This will change one single byte at the address 4096:

F 1000 1000 3

Type M 1000 to see the effect.

The built-in machine code monitor

The Commodore 128 features a few built in applications and one Easter egg. The egg is a list of the engineers that built the machine, with the word “hardware” intentionally misspelled as “herdware” after 8-bit computer designer Bil Herd. To reveal the egg, type this:

SYS 32800,123,45,6

The Commodore 128 tries to boot from floppy at startup. To start the CP/M operating system, you would make sure to have the boot disk inserted at startup. If you want to start the system without resetting the machine, you could just type BOOT and press enter. BOOT tries to load data from the floppy without generating an error if it fails.

The built in machine code monitor gives you the ability to view memory content (ROM and RAM) in binary format or as instructions. You choose the format that is best suited for the type of data you want to view. Also, the monitor lets you type in instructions in the RAM.

You enter the monitor by typing MONITOR.

While in the monitor, type M to dump 96 bytes on the screen. Type M again to dump the next 96 bytes. You can also specify a desired starting address after M.

By typing D, a disassembled version of the machine code is displayed. Just as with M, you can specify a starting address.

Type X to leave the monitor.

Hidden stuff in the C128

Here is some of the hidden stuff in my favorite computer, the Commodore 128.

There is a bug in the Basic interpretation that shows up when you tries to do an arithmetic calculation using a string. This is what’s supposed to happen:

When you add an integer to a string, the interpretator should say that you have mismatching types.

PRINT "10" + 3

The code above should result in an error, not 13 or “103″. So far so good. If you add a negative number to a string, you should get the same error, but instead, the Basic interpretator crashes. The first time, I don’t get any result at all, and when I move the operators together (which is perfectly alright according to the Commodore Basic 7 specification) the CPU goes mental.

You can see from the word BREAK that the Basic interpretator has stopped.

Bare with me, there is more fun to the C128. More posts to come.

Inserting a value in an identity column

In SQL Server 2008, when a column is set to auto increment (Identity Specification), you are normally not allowed to give that column a value. If you are copying data from one database to another in Visual Basic, perhaps by loading a DataSet object using one connection, and inserting it’s data using another, this can be a problem.

The table option you must set, to be allowed to insert a value in an identity column is called IDENTITY_INSERT. So add this line to your command object to make it work:

SET IDENTITY_INSERT dbo.Products ON;

The following INSERT statement can give a value to the identity column, if the value complies with the rules for that column. The line of code could look something like this:

Using X As New SqlClient.SqlCommand( _
    "SET IDENTITY_INSERT dbo.Products ON; INSERT...

PhotoName 2.0 is progressing

Now PhotoName 2.0 is working well but it must be completed with all the features that PhotoName 1.x has and the documents has to be updated. I am really excited about getting it out for download.

An early screenshot:

Noah’s calculator found!

Recently, we have read about some insane adventurers who have found NOAH’S ARK! Yes, the boat that Noah used to survive the flood together with seven pairs (14 animals) of each “clean” species (or bird) and one pair of each “unclean”. As you might guess, this is a huge project. The collecting itself must have been exhausting. However, now we have found his calculator!

Download it here.