Vice – autostart with a directory

Vice, the Commodore 64 emulator is a cross platform emulator that works on Windows, Linux, MacOS and other operating systems. It also allows you to emulate the Vic 20, C128 and other early Commodore machines.

Double clicking on a Commodore d64 disk image file will load x64, the Commodore 64 emulator and load the first programme on the disk image.

LOAD”*”,8,1

Quite often I want to look at a D64 image directory listing instead of running the first programme on the disk.

You can do this by unchecking the “autostart” box on the file open box of course but it’s not as convenient.

So, last Friday I asked on Twitter if it was possible to drag and drop a D64 image onto Vice to display the disk contents. Logiker replied and helped me by DM to handle double clicking on a C64 disk image.

What I needed to do was load the disk image and then feed the directory listing command to the C64.

LOAD"$",8
LIST
LOAD”$”,8

Getting MacOS to accept the command line was harder to achieve. In Windows you can change the start up parameters for a programme. In MacOS it should be possible to modify the emulator “package” with a script that calls the real executable but I couldn’t get that working.
In Linux I would have just created a shell script that called the emulator. 🙂

What did work in MacOS was using Automator. I created a “Run Shell Script” action and filled it in with the following. If you want to follow along at home you’ll have to change the path to x64.


/Applications/Vice64/x64.app/Contents/MacOS/x64 -8 "$@" -keybuf load\\"$\\",8\\nlist\\n

I saved that as a new app in ~/bin/ called “Vice64”, and associated all D64 images with that application. Now double clicking on a disk image shows me a directory listing!

It doesn’t work unfortunately when I have an Action Replay cartridge loaded. Maybe I need to add F3 or F7 to the keyboard buffer?

One of the advantages of looking at the directory structure is the directory art some demos have. Here’s one from Pearls for Pigs, a D64 I happened to use while testing this but there are loads of them. I saw that Logiker has a page dedicated to directory art!

Happy times! 🙂

WP Super Cache 1.6.3

WP Super Cache is a full page caching plugin for WordPress. When a page is cached almost all of WordPress is skipped and the page is sent to the browser with the minimum amount of code executed. This makes the page load much faster.

1.6.3 is the latest release and is mostly a bugfix release but it also adds some new features.

  • Added cookie helper functions (#580)
  • Added plugin helper functions (#574)
  • Added actions to modify cookie and plugin lists. (#582)
  • Really disable garbage collection when timeout = 0 (#571)
  • Added warnings about DISABLE_WP_CRON (#575)
  • Don’t clean expired cache files after preload if garbage collection is disabled (#572)
  • On preload, if deleting a post don’t delete the sub directories if it’s the homepage. (#573)
  • Fix generation of semaphores when using WP CLI (#576)
  • Fix deleting from the admin bar (#578)
  • Avoid a strpos() warning. (#579)
  • Improve deleting of cache in edit/delete/publish actions (#577)
  • Fixes to headers code (#496)

This release makes it much easier for plugin developers to interact with WP Super Cache. In the past a file had to be placed in the “WP Super Cache plugins directory” so that it would be loaded correctly but in this release I’ve added new actions that will allow you to load code from other directories too.

Use the wpsc_add_plugin action to add your plugin to a list loaded by WP Super Cache. Use it like this:

do_action( 'wpsc_add_plugin', WP_PLUGIN_DIR . '/wpsc.php' )

You can give it the full path, with or without ABSPATH. Use it after “init”. It only needs to be called once, but duplicates will not be stored.

In a similar fashion, use wpsc_delete_plugin to remove a plugin.

The release also makes it much simpler to modify the cookies used by WP Super Cache to identify “known users”. This is useful to identify particular types of pages such as translated pages that should only be shown to certain users. For example, visitors who have the English cookie will be shown cached pages in English. The German cookie will fetch German cached pages. The action wpsc_add_cookie makes this possible.

do_action( 'wpsc_add_cookie', 'language' );

Execute that in your plugin and WP Super Cache will watch out for the language cookie. The plugin will use the cookie name and value in determining what cached page to display. So “language = irish” will show a different page to “language = french”.

Use wpsc_delete_cookie to remove a cookie. Cache files won’t be deleted. It’s doubtful they’d be served however because of the hashed key used to name the filenames.

do_action( 'wpsc_delete_cookie', 'language' );

If you’re going to use either of the plugin or cookie actions here I recommend using Simple Caching. While the plugin will attempt to update mod_rewrite rules, it is much simpler to have PHP serve the files. Apart from that, any plugins loaded by WP Super Cache will be completely skipped if Expert mode is enabled.

WP Super Cache and Cookie Banners

More sites use cookie banners now that the GDPR is active but some are finding that their banners are misbehaving once they enable caching.

This is a similar issue to the one that happened to some page counter plugins in the past. The page counter wouldn’t increment.

When a cookie banner is clicked a cookie is set in the browser so the website knows this visitor has agreed to accept cookies. If the cookie is set then the cookie banner html is not sent to the browser.

I suspect the main issue is that the code that sets and checks if the cookie is set is PHP. Unfortunately because the page is cached then no PHP code is executed, and the cookie banner is displayed because it was originally cached that way.

Since WP Super Cache only knows about certain WordPress cookies it assumes everyone who doesn’t have those cookies is a first time “anonymous” visitor. It doesn’t know about your cookie banner cookie.

You have two options:

  1. Rewrite your cookie banner so it’s completely in Javascript. Do the cookie detection in Javascript and also set the cookie in Javascript. If the cookie banner has been clicked then you need to trigger an action, and other Javascript that is hooked on to that trigger will run and load the tracking cookies.
  2. Modify WP Super Cache so it knows about the cookie your cookie banner uses. Caching won’t work quite as well as before as it’ll be split between visitors who have clicked the cookie banner and those that haven’t. One cached file will display the cookie banner, and the other will not but it will have ad tracking Javascript.

Using Javascript completely is a better solution because it runs in the browser on every page load but that might not be possible every time.

Otherwise, use PHP to get WP Super Cache to play nicely with your existing code:

  1. You’ll need to write a WP Super Cache plugin.
  2. You need to hook into the wp_cache_get_cookies_values cacheaction and add the value of the cookie banner cookie to the end of that string.
  3. Caching can only be performed by simple caching now, unless you’re willing to edit mod_rewrite rules in your .htaccess file.

Something like this will do. Make sure you note the warning about $wp_cache_plugins_dir in the link above about writing these plugins.

function add_cookie_banner_to_cache_cookie( $string ) {
    if ( isset( $_COOKIE['cookie_banner'] ) ) {
        $string .= 'cb,';
    }
    return $string
}
add_cacheaction( 'wp_cache_get_cookies_values', 'add_cookie_banner_to_cache_cookie' );

Substitute the name of the cookie for your cookie name, change the name of the function, and the text it adds to the string. There is an intentional PHP fatal error in the code above to discourage copy/pasting.

Your cookie banner plugin could automate setting this up, but it may have unforeseen consequences if not done correctly. It should check if $wp_cache_plugins_dir is set already, and use that location, otherwise it will have to make a directory and update the WP Super Cache configuration, where ABC is the new location for the plugins.

wp_cache_setting( 'wp_cache_plugins_dir', ABSPATH . 'wp-content/ABC' );

The new code can be copied into a file in that directory. The files in the original WP Super Cache plugins directory (found at WPCACHEHOME . 'plugins') should be copied into that directory too and a warning shown to the user. They may need to set up one of those plugins again.

The reason it is this convoluted is because this code will run before all of WordPress loads. You can’t rely on blog options or most of the nice configuration tools WordPress provides.

When your plugin is uninstalled it should of course restore the plugins directory to the way it was before.

For future reference, since cookie banners will hopefully not be around forever, here’s what they looked like in the deep, distant past of 2018. 🙂

The LA Times just gave up and don’t show anything to EU visitors.

The Supernova in the East

The latest episode of Hardcore History is another amazing audio tour through history, even if Dan Carlin himself says he is unqualified and it might not be completely accurate. He’s a great story teller. This one covers the rise of Japan in the early twentieth century and beyond.

Dan’s coverage of the Manchurian Incident reminded me I have to re-read the Tintin story, “The Blue Lotus“. Hergé definitely applied his imagination when recounting how the train track was blown up but I’d never have known about that period of time if I had never read that book.

And similarly, I wouldn’t have known the railway track was barely damaged if I hadn’t listened to Hardcore History!

Why is our car all dusty?

I have no idea. It’s only parked outside our home, where it’s always been.

Yeah, that’s where it comes from. When you live across the road from a building site. Where trucks queue on the road. Where they blast their horns on the main road to alert the crew on the site of their imminent arrival. Where I felt the air in my kitchen vibrate and resonate with the sound of the jack hammers and trucks passing. We fought it, we should have won, but we lost.

I had a really bad headache today.

My S7Edge gets the April Update

My Samsung Galaxy S7 Edge is now installing the April 1st update. It got Oreo a few months back and a few updates since. Going by Samsung’s track record I expect those updates to dry up any time soon but it’s good to see them still handing out any sort of updates.

In case you’re wondering, this is the unlocked international variant.

Version installed: G935FXXU2EREM/G935FOXA2EREM/G935FXXU2ERD6

Unmount USB drives from a script in macOS

I have a number of external drives hanging off my laptop, but sometimes I want to disconnect them. I used to go into Finder and click the eject button but I have five drives now so that’s getting unwieldy.

There are a few different ways of doing this. I wrote a small BASH script based on information here.

I created a shell script on my Desktop, added the following, changing DRIVE to the volume path for each of my external drives:

osascript -e ‘do shell script “diskutil unmountDisk /Volumes/DRIVE”‘

After creating that script I made it executable with chmod +x and as I use iTerm2 as a terminal I associated .sh files with that (Finder, right click on script, Get Info->Open With).
Every time I double click the script a new tab opens in iTerm2 and I see the progress of the unmount commands!

CervicalCheck Protest in Cork

More than 800 people marched through Cork on Saturday to protest the CervicalCheck scandal where 209 smear tests were misread and 18 women have died already.

Terminally ill Emma Mhic Mhathúna appeared at a protest today in Kerry.

In a poignant protest in Tralee town centre on Monday evening, the very day that she was told that her cancer has spread even further to her vertebra, Emma, in a moving and emotional speech, said that she would continue to fight for reform of the health service. 
“I am sick of being treated like nothing. Our health is the last thing that these people care about. The Dáil needs to realise that if they are going to take responsibility for our lives they better do it well or they need to be fired,” she told the crowd. 
“I promise my death won’t go unnoticed. I will make sure that they pay for what they have done to every single family in Ireland, whether you are on a waiting list too long or whether you are not being treated fair. Tell them you’re my friend and I’ll come and sort them out.”
“I can’t save my life but at least I can save yours and your children’s lives.” 

https://www.independent.ie/regionals/kerryman/news/kerry-stands-together-in-solidarity-as-emma-faces-death-sentence-36910803.html

Bohemian Rhapsody Overload

Hyped for this. Don’t be bad. Don’t be bad. Don’t mess it up.

It’s kinda odd to think of Elliot from Mr. Robot as Freddie Mercury but this trailer is promising, unless you’re going to pick holes in every little bit of it.

I enjoyed this interview with Rami Malek on The Late Show, and here’s a video produced by the band Bulsara and His Queenies called ‘A Sheer Homage’. Wow.

If you still haven’t had enough of Queen, (and who can?) the official Queen Youtube Channel has a number of 1 hour long compilations.

Finally, and this is the coolest thing ever, User cmi on the QueenZone forum has made an expanded collection of Queen albums. You’ll probably find bits and pieces there that you’ve never heard.