Updates from December, 2015 Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 5:58 pm on December 27, 2015 Permalink | Reply
    Tags:   

    Categories: Commodore ( 41 )   

    How to create relative data files on your Commodore 128 

    Commodore-Logo-PaddedThe CBM DOS can write “relative data” onto disk, based on individual records. The advantage is that all space is allocated once and then randomly accessed if and when it’s needed – much like the tracks on a CD.

    This approach is different from sequential files, which have to read or write the whole file in one go (Apple call this “reading and writing atomically”). So finding the 50th record in a sequential file can take some time, whereas retrieving record 50 from a relative file is just as fast as retrieving record 1 or record 157.

    Let’s see how we can deal with such relative files in CBM BASIC 7.0. This works with all physical disk drives (1541, 1571, etc) as well as the SD2IEC card reader – but not with your trusty old Datasette (for obvious reasons).

    This was revolutionary back in 1982!

    Creating Relative Files

    Here we create a new file with a REL extension using the DOPEN# keyword. When we do this for the first time, we need to tell the operating system how much data we’d like to allocate per record. Anything up to 255 bytes is fine. We’ll use 100 bytes in this example (the letter L followed by the length).

    10 dopen#1,"rel test",l100
    20 for i=1 to 100
    30 record#1,i
    40 a$="record"+str$(i)
    45 print "writing record ";i
    50 print#1,a$
    60 next
    70 close 1
    80 print "all done!"
    

    When we create a new file, CBM DOS doesn’t know how many records we’ll need, but it will create as many as necessary on the file. Here we create 100 entries using a for loop and write them to disk using the PRINT# statement.

    Notice that before saving a record, we must position the record pointer using RECORD#. That’s how our data is written to the correct position on disk. The whole loop will take a while to complete, but all space will be allocated on the disk as soon as we CLOSE the file.

    To add more records, we’ll simply position the record pointer to a later entry – even if one does not yet exist. CBM DOS will create the last record and all records leading up to it so they can be used later, up to a maximum of 65535 (space permitting obviously).

    Reading data from Relative Files

    Much like with sequential data, we can either use INPUT# or GET# to grab the data for an individual record. INPUT# reads everything until a CHR$(13) is found and works much faster, while GET# reads data one character at a time and is a lot slower.

    10 input"which record shall we retrieve";r$
    20 dopen#1,"rel test"
    30 record#1,val(r$)
    40 input#1,a$
    50 close 1
    60 print:print a$:print
    70 print"need another one? (y/n)"
    80 getkey k$:if k$="y" then goto 10:else end
    

    Here we ask the user which record we want to retrieve. Next we open our relative file using DOPEN#, position to the desired RECORD# and then read in its value using INPUT#. When we’re done we close the file and ask if the user wants to retrieve another record.

    While this type of data access is quick and convenient, it doesn’t help much unless you know which record is stored at which position. Think of an address book application: to find “Johnny Appleseed” can’t be done unless you sift through every single record until you find him.

    Commodore therefore suggest to use sequential files alongside relative files, in which things like a last name could be saved together with the record number. Likewise, another sequential file could hold all records for the first names, and appended accordingly when a new record is created, or replaced when updated.





     
  • Jay Versluis 5:36 pm on December 27, 2015 Permalink | Reply
    Tags:   

    Categories: Commodore ( 41 )   

    How to create sequential files on your Commodore C128 

    Commodore-Logo-PaddedSequential files are files to which we can write arbitrary data and read it back later. We can even append data to the file later without having to re-write the whole file.

    This works with the Datasette (tape drive) as well as floppy drives. Here’s how to do it in CBM BASIC 7.0:

    Creating Sequential Files

    The C128 has a few special commands up its sleeve to aid us in this task. Here we create a new file using the DOPEN keyword and write 100 statements to it.

    10 dopen#1,"@seq test",w
    20 for i=1 to 100
    30 a$="record"+str$(i)
    40 print#1,a$
    50 print "writing ";a$
    60 next
    70 close 1
    

    We’re creating a new sequential file (SEQ extension rather than the usual PRG), using the w after the filename so that BASIC knows to create the file. The @ sign in front of the file name makes sure this file is overwritten every time we run the programme – omit it if you don’t want that functionality.

    Next we create a loop and generate a variable spelling RECORD 1, RECORD 2, etc. That’s your data. Each entry may be up to 127 characters in length (I believe) and is saved to the file by using the PRINT# keyword. Anything we could print to the screen, we can also print to a file.

    With each new PRINT# command, a carriage return is saved to disk. This can come in handy when we’re reading the data back in. If you need special characters to separate your data, feel free to use them.

    Appending data to Sequential Files

    If we need to add anything to the file (much like Linux would add to the end of a text file using the “greater than” symbol), we can use the APPEND# keyword:

    10 append#1,"seq test"
    20 for i=101 to 150
    30 a$="record"+str$(i)
    40 print#1,a$
    50 print "appending ";a$
    60 next
    70 close 1
    

    APPEND# opens the file for adding data and positions the pointer after the last entry in our file. We’ll do something very similar as above, creating records 101 to 150 and adding them to the file. Make sure to CLOSE the file so all data is saved to disk.

    Reading Sequential Data

    Much like PRINT# can be used to write data to disk, we can use INPUT# to read data back – almost equivalent to the INPUT keyword get get user input from a keyboard. The only difference is that out input comes from a different device:

    10 dopen#1,"seq test"
    20 for i=1 to 150
    30 input#1,a$
    40 print a$
    50 next
    60 close 1
    

    Here we open our file with DOPEN# and grab each entry in the file using the INPUT# keyword. This will automatically position the next INPUT# when a carriage return is received (CHR$(13)).

    This will work just fine as long as the original data does not contain any special characters, like a scary comma. If you need such characters, or if you want to ignore the carriage return, you can also use the GET# command to read one character at a time from disk. This is dramatically slower though.

    Notice that there’s no “end of file” marker as such: right now we need to know how many entries there are and read them accordingly. Reading beyond the data in our file will simply repeat the last record (on real devices) or crash your system (on VICE).





     
  • Jay Versluis 10:30 am on December 24, 2015 Permalink | Reply
    Tags:   

    Categories: Commodore ( 41 )   

    How to switch the Commodore 1571 into 1541 mode and back 

    Commodore-Logo-PaddedThe Commodore 1571 floppy drive powers up in compatibility mode and behaves just like a 1541 drive – unless a C128 is connected and sends it a fast serial transfer.

    They did this because otherwise the drive wouldn’t be compatible with the C64 and Plus/4.

    The C128 speaks to its attached disk drive when we power it on, and that’s how a 1571 turns on its super fast magical properties. Holding down the Commodore key will boot into C64 mode, and the 1571 will in turn reset itself to 1541 emulation mode.

    Lucky for us, we can change this with a simple command, no matter what computer we’re using or which mode we’re currently in. This is done by first opening a command channel and then sending the 1571 the following switch command:

    // switch on 1571 mode
    OPEN 15,8,15,"U0>M1"
    CLOSE 15
    
    // switch on 1541 mode
    OPEN 15,8,15,"U0>M0"
    CLOSE 15
    

    This will let the 1571 behave like a 1571 even when attached to a C64 or Plus/4: format floppies on both sides and enjoy 1328 blocks without flipping disks. Sadly it won’t transfer data any faster because the attached computers just can’t handle it.

    Conversely, if we want to use a C128 and have our drive remain in 1541 mode for testing or compatibility, it works equally well.

    Rebooting your computer will reset this value. As far as I know, there is no way to test which mode the drive is in before issuing either of the above commands.





     
  • Jay Versluis 2:47 pm on December 12, 2015 Permalink | Reply
    Tags:   

    Categories: macOS ( 37 )   

    How to check the Fan Speed on your Mac 

    Sometimes you may want to know how fast your fans are spinning, more as a “number value” rather than a “noise value”. While you can hear when your Mac in front of you is working hard, it’s impossible to tell how fast those fans are spinning when you’re miles away from your Mac in a data centre.

    Thankfully there is an easy way to read out the fan speed with a small built-in utility we can access from the command line. Launch a terminal session and issue spindump as admin user:

    sudo spindump
    
    Password:
    Sampling all processes for 10 seconds with 10 milliseconds of run time between samples
    Sampling completed, processing symbols...
    Spindump analysis written to file /tmp/spindump.txt
    

    It’ll take a few seconds, at the end of which a file is produced that tells you a lot more than just the fan speed. To filter this info out, issue the following:

    cat /tmp/spindump.txt | grep "Fan speed"
    Fan speed:       3151 rpm (-317)
    

    And there you have it! Execute this command under low load, then try again under heavy load to see your low and high spin numbers to get an impression how how busy your Mac’s fans are.

    To remove that temporary file and avoid your hard disk from being clogged up, issue this when you’re done:

    sudo rm /tmp/spindump.txt
    

    This may not be the most elegant way to read out your fan speeds, but it works without installing additional utilities. The spindump command is computationally expensive, so don’t do it continuously – there are better tools for that (such as smcFanControl, or others – see the link below).





     
    • Tom Cooper 5:35 pm on August 8, 2017 Permalink | Reply

      correct usage of grep command
      grep “Fan speed” /tmp/spindump.txt

  • Jay Versluis 11:31 am on December 2, 2015 Permalink | Reply
    Tags:   

    Categories: macOS ( 37 )   

    How to disable System Integrity Protection on OS X El Capitan 

    System Integrity Protection was introduced in El Capitan to add another layer of security to OS X. The system prevents the root user from doing things that are potentially harmful. Apple did this because any app at any time may ask for the administrator password and execute commands with elevated permissions, which is a big security risk on single user systems.

    There are downsides to yet another layer of security, and much like Gate Keeper, System Integrity Protection brings us one step closer to a completely locked off system like iOS. I guess that’s the long term plan.

    Until then, and if you need it, you can disable System Integrity Protection. Here’s how to do it:

    • boot into the Recovery Partition (hold down CMD + R during boot)
    • this takes a little longer than usual
    • when the system is back, select Utilities – Terminal
    • now type “csrutil disable”
    • close Terminal and restart the system

    You can check at any time if this feature is on or off by typing

    csrutil status
    
    System Integrity Protection status: disabled.
    

    Enable it again during a Recovery session by typing “csrutil enable” and El Capitan is secured again.

    To see what else this command has to offer, type csrutil without parameters:

    csrutil
    
    usage: csrutil 
    Modify the System Integrity Protection configuration. All configuration changes apply to the entire machine.
    Available commands:
    
        clear
            Clear the existing configuration. Only available in Recovery OS.
        disable
            Disable the protection on the machine. Only available in Recovery OS.
        enable
            Enable the protection on the machine. Only available in Recovery OS.
        status
            Display the current configuration.
    
        netboot
            add 
    Insert a new IPv4 address in the list of allowed NetBoot sources. list Print the list of allowed NetBoot sources. remove
    Remove an IPv4 address from the list of allowed NetBoot sources.




     
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