Tagged: Plus/4 Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 4:27 pm on September 1, 2014 Permalink | Reply
    Tags: , , Plus/4   

    Categories: Commodore ( 38 )

    The evolution of Flow Control in Commodore BASIC 

    Commodore-Logo-PaddedWhen I had a C64 back in the days, the only IF/THEN statement we could create in BASIC v2 was just that: IF and THEN.

    There was no ELSE, and everything had to be on a single line. It was the only flow control we had back in those days, and it was a severe limitation compared to what we can do with higher level languages today.

    Here’s an example:

    10 input x
    20 if x=1 then print"x is one" : goto 100
    

    Such constructs weren’t very convenient when you wanted to react to anything other than the tested value. Instead you had to write an IF statement for every possible other outcome which could make the code very cluttered with several GOTO statements.

    When the Plus/4 came out Commodore added the ELSE statement. It still had to be on the same line as the IF and THEN, but at least we had ELSE as an option:

    10 input x
    20 if x=1 then print "x is one" : else print "x is not one"
    

    ELSE needs to be on the same line as the IF/THEN statement and separated by a colon.

    ELSE was a very handy addition to the BASIC arsenal, but it still didn’t solve the problem that your evaluation had to be cramped into a single line. This was improved on the C128 with the introduction of BEGIN/BEND.

    BEGIN and BEND allowed you to execute as many lines of code as you wanted between those statements when a condition was true (or false). Used together with IF, THEN and ELSE it was a very useful thing to have:

    10 input x
    20 if x=1 then begin
    30 print "x is one"
    40 print "which is like totally awesome"
    50 rem more code here
    60 bend : else begin
    70 print "x was obviously not one"
    80 print "which is a shame"
    90 print "but that's life"
    100 bend
    

    BEGIN means that everything starting from now until BEND is met will be executed as part of the IF/THEN statement – as many lines of code you like.

    When BEND is met the code continues as normal – but we can also use ELSE after a colon on the same line, indicating that this is still part of the first IF/THEN statement. Here we can use BEGIN again for as many lines as we like, until we finish with BEND again.

    It was very very cool!

     

    Herdware

    sys 32800,123,45,6 to show these credits (thanks, team!)





     
  • Jay Versluis 1:42 pm on August 30, 2014 Permalink | Reply
    Tags: , , Plus/4, sd2iec   

    Categories: Commodore ( 38 )

    How to use SD2IEC: a quick command reference 

    Photo 28-08-2014 19 30 57
    I’ve ordered an SD2IEC a few weeks ago from Nic over at http://sd2iec.co.uk. It’s an SD card reader for Commodre computers and emulates many features of the 1541 Floppy Disk Drive.

    I went for the Limited Edition made from authentic recycled C64 plastic – so this little critter used to be a real C64! This has to be one of the coolest gadgets for any Commodore fan in the 21st century. And we know many people like gadgets of any kinds, to do many different things, that’s why we have lists of Electronics & Gadgets – Top9Rated.

    Nic and several other sellers on eBay build the hardware, while the software was developed by Ingo Korb with contributions from others. In this article I’ll explain how you can get the most out of the SD2IEC.

    Reading and Writing Files

    The SD2IEC works out of the box with standard disk commands (such as LOAD and SAVE). This will save a BASIC programme as PRG just like your Commodore would save it to floppy disk.

    You can create, switch into and remove directories on the SD card with your SD2IEC (or your “contemporary” computer of course). You can also read from and write to D64/D71/D81 image files and I’ll explain how this works further down.

    When you’re in a subdirectory (or a disk image) all read/write operations are performed there until you switch images or directories. We can do this by communicating with the SD2IEC via the command channel, as if we’re speaking to a 1541.

    Looks like the SD card is hot-swappable without the need to “safe-eject” as long as none of the lights are on, indicating read/write access.

    Speaking to your SD2IEC

    To issue commands on your SD2IEC we must open that trusty old command channel on the device (number 15), PRINT# the command and then optionally close the channel again. Here’s how to do that:

    OPEN 15,8,15
    PRINT#15,”your command here”
    CLOSE 15
    

    You can also write this on a single line:

    OPEN 15,8,15,”your command”:CLOSE 15
    

    You can also leave channel 15 open and issue more commands. Notice though that if you use any other disk command after opening channel 15 (such as LOAD or SAVE) all channels including 15 are closed automatically. Commands such as DIRECTORY do not close the channel.

    I find it helpful to add these things to one my my programmable keys (C128 and Plus/4) via the KEY command:

    // open command with trailing quotes
    KEY 1,"OPEN 15,8,15,"+CHR$(34)
    

    Hit F1, then type one of the commands below. If the channel is already open, simply issue the command via PRINT#15,”command”.

    Directories

    The CD command lets you navigate the directory structure much like you would in Linux and Windows from the command line.

    // change into the root directory
    CD//
    
    // enter directory “mydir” (relative to where you are)
    CD/mydir/
    
    // enter directory “mydir” (absolute from root directory)
    CD//mydir/
    
    // navigate up one level (like the Linux cd .. command)
    CD:←
    

    You can also create directories to stay organised without the need for other tools. That’s where the MD command comes in handy:

    // create directory in the current location
    MD:mydir
    
    // create directory inside another directory
    MD/mydir/:otherdir
    
    // create a directory absolute to root
    MD//mydir/:otherdir
    

    When you’re done with a directory you can delete it with RD. Note that only empty directories can be deleted, otherwise you’ll get a FILE EXISTS error:

    // remove in current directory
    RD:mydir
    
    // remove directory absolute to root
    RD//mydir/:otherdir
    

    Mounting Disk Images

    The CD command can also be used to mount D64/D71/D81 image files, just as if they were standard directories. The same syntax applies as with switching directories:

    // mount “myimage.d64” in current directory
    CD:myimage.d64
    
    // mount “myimage.d64” in subdirectory /mydir (relative)
    CD/mydir/myimage.d64
    
    // or absolute
    CD//mydir/myimage.d64
    
    // unmount a disk image (go back SD card directory in which the image resides)
    CD:←
    

    You don’t have to mount disk images of course and can instead use a FAT or FAT32 formatted SD card just like it was a floppy disk. However, CBM DOS can only address a maximum of 144 files in a directory which means that a cheap 4GB SD card will be exhausted by this limitation before it’s anywhere near full.

    Changing the Device Address

    By default the SD2IEC is set to be drive number 8. But like its vintage counterpart you can change this to 9,10 or 11 using the following command:

    // change from drive 8 to drive 9
    OPEN 15,8,15
    PRINT#15,“U0>"+CHR$(9)
    CLOSE 15
    

    Replace the CHR$ value with the desired drive number. Just like a real 1541 drive, the SD2IEC will not remember this change upon reset. You can however save the above to its internal EEPROM which will survive subsequent reboots:

    // save drive number to EEPROM
    OPEN 15,9,15
    PRINT#15,“XW"
    CLOSE 15
    

    Replace 9 with your actual drive number.

    Troubleshooting

    If you encounter flashing lights on your device, then the SD2IEC is trying to tell you something. On the C128 and Plus/4 you can read out the disk error channel by looking at the DS$ system variable:

    // print disk error channel on C128 and Plus/4
    PRINT DS$
    

    This will show you what went wrong (FILE EXISTS, FILE NOT FOUND, etc). On the C64 this is a little harder and requires you to write a small programme to read those values out. This is necessary because the INPUT# command can not be used in direct mode:

    // read disk error channel on C64
    10 open 15,8,15
    20 input#15,a,b$,c,d
    30 print a;b$,c,d
    40 close 15
    

    There’s a lot more you can do with this device – check out the full documentation in the README file at Ingo Korb’s website:





     
  • Jay Versluis 9:01 am on July 25, 2014 Permalink | Reply
    Tags: , , Plus/4   

    Categories: Commodore ( 38 )

    How to merge BASIC programmes on your Commodore C64, C128 and Plus/4 

    Commodore LogoYou can merge / combine / concatenate BASIC programmes on a Commodore computer. It’s often useful to develop shorter chunks of code and put them together for a larger app.

    Sadly there’s no built-in command that lets you do this, even though the C128 user guide hints that the CONCAT command can do this (if you’ve ever tried you know that this is not the case and only works for sequential data files).

    With a few peeks and pokes we can accomplish what we need. Here’s how:

    • after loading the fist programme, we’ll set the start of BASIC to the end of programme 1
    • then we’ll load the second programme
    • and finally return the start of BASIC to the first one

    We’re left with both programmes in memory – without any changes in line numbers. Depending on how you write the code a quick RENUMBER command may be necessary here. Even though you can run a programme when the line numbers are out of sequence, GOSUB and GOTO routines may not work as expected.

    The commands are slightly different for each machine.

    On the C64

    The start of BASIC is stored in 43/44, and ends just before the variables begin – which is stored in 45/46. Load your first programme, then type this:

    n=(peek(45)+256*peek(46))-2
    poke 44,n/256
    poke 43,n-256*peek(46)
    

    Load the second part, then reset the BASIC pointers to where the first part resides:

    poke 43,1
    poke 44,8
    clr
    

    On the Plus/4

    The Plus/4 works almost identical to the C64 in regards to storing the BASIC pointers, however the start of BASIC is at a different address. Load your first programme, then type this (just like on the C64):

    n=(peek(45)+256*peek(46))-2
    poke 44,n/256
    poke 43,n-256*peek(46)
    

    Load the second part, then reset the BASIC pointers:

    poke 43,1
    poke 44,16
    clr
    

    On the C128

    The C128 stores variables in a different memory bank. Therefore it has a dedicated pointer to the end of BASIC which is missing on the other computers. The memory map is slightly different, and the start of BASIC is stored in 45/46. Load your first programme, then type this:

    n=peek(174)+256*peek(175)-2
    poke 46,n/256
    poke 45,n-256*peek(46)
    

    Load the second part, then reset the BASIC pointers:

    poke 45,1
    poke 46,28
    clr
    

    And there you have it! Run any of these routines right after a reset or restart.

    Thanks to Rick Kephart for this tip. You may also be interested in another (more complex) solution to this puzzle by Jim Butterfield in which he reads each byte and merges them back on disk.





     
  • Jay Versluis 9:20 pm on July 16, 2014 Permalink | Reply
    Tags: Plus/4   

    Categories: Commodore ( 38 )

    How to listen to your Commodore Datasette 

    datasetteDid you know that there’s a way to “listen” to a Datasette Drive, even though it’s not meant to play back the latest top twenty mixtapes?

    I’ve recently acquired a Commodore Plus/4 with 1531 Datasette. I remember having one of those in the eighties (with an adaptor to connect it to my C64 back then).

    The datasette is misbehaving, allegedly saving programmes but never loading them back in. Power is working fine, but as I no longer have a “cassette player” as such, I have no idea if it’s actually recording anything on the tape, or hearing what’s on it.

    I needed a way to playback the tape when I found this super short and very useful machine code snippet:

    0600 LDA $01 
    0602 ADC #$38 
    0604 STA $FF11 
    0607 STA $FF19 
    060A JMP $0600 
    

    When started with SYS 1536 the outer border of the Plus/4 will change according to what’s coming from the tape when you press play, and audio is quasi-modulated to the speaker output. It sounds rather distorted, but nevertheless you can hear what’s on the tape!

    To enter the programme, first type MONITOR which will take your out of BASIC and into the machine language monitor. Then type A 0600 followed by the first command (LDA $01). Now TEDMON will give you the next hex address, so just type the next command.

    When you’re done hit return, then type X (and return) to exit to BASIC. Here you can start the programme with SYS 1536, then PRESS PLAY ON TAPE. Enjoy!

    Note that this will not work on the C64, but you can hunt around for several “tape alignment” programmes which will work with similar principles – but I couldn’t find one for the Plus/4.

    Thanks for Marton for the code:





     
  • Jay Versluis 1:33 pm on July 8, 2014 Permalink | Reply
    Tags: , Plus/4   

    Categories: Commodore ( 38 )

    How to load and save binary data on the C128 and Plus/4 

    Commodore LogoThanks to BASIC 7.0’s powerful commands we can load and save arbitrary sections of memory to disk using BLOAD and BSAVE.

    This was useful for dealing with machine code as well as raw image data. Both commands work on the C128 and Plus/4, but sadly the C64 was lacking in this area.

    BLOAD and BSAVE work much like DLOAD and DSAVE with the addition that you can specify a section of memory – like this:

    // save contents of the 40 column display
    BSAVE "FILENAME", P1024 TO P2023
    
    // save the contents of hi-res graphics and colour separately
    BSAVE "IMAGE", P8192 TO P16181
    BSAVE "COLOURS", P7168 TO P8167
    
    // save graphics and colour information together
    BSAVE "FULL IMAGE", P7168 TO P16181
    

    BLOAD doesn’t need additional parameters and will load a file back into memory where it originally resided – just like the standard LOAD “FILE”,8,1 (with the 1 at the end). You can however provide the starting memory and make the file load somewhere else instead:

    // load file to a different place in memory
    BLOAD "FILENAME", P10000
    




     
  • Jay Versluis 8:29 pm on July 6, 2014 Permalink | Reply
    Tags: , , Plus/4   

    Categories: Commodore ( 38 )

    How to set the time on your Commodore C64 / C128 

    Commodore LogoDid you know that the Commodore computers had a built-in clock? It wasn’t an exact science, and it didn’t show the date, but it was able to display a 24hr clock.

    It did this by counting how many seconds your machine was switched on, accessible in two variables TI and TI$ (short for TIME).

    TI$ is a string value in the format HHMMss, counting seconds. 112347 would mean 11:23am and 47 seconds. TI$ will be 000000 when you switch on the system. You can set it just like any other variable to set the time:

    TI$ = "094500"
    

    TI counts the number of 60th seconds since the system was switched on (don’t ask):

    print int(ti/60);" seconds since startup"
    

    Both values reset when you reset the system. Like all internal computer clocks it is relatively accurate, but does drift a second or two per day (we don’t notice this on modern systems because those talk to an NTP server once every day and sync themselves).

    TI and TI$ are present on the C64, C128, Plus/4 and many other Commodore variants.





     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel