Wednesday, 12 February 2020

Fooling around some more with THEC64 Microcomputer


I already made some (premature) notes about THE C64 emulator machine. Here are some of the things I have been doing with it.

Before I go further, just to wrap up:
  • Just a teeny bit laggy, but the framerate seemed smooth
  • But be mindful of the 50hz - 60hz capability of your display (60hz PAL is unreal)
  • Can do VIC-20 mode too
  • The joystick is bit clunky but has those nice extra mappable buttons & the useful menu key
  • Does only HDMI, not even separate audio
  • ... but a HDMI-VGA adapter with audio split can help, but obviously a 50hz display is needed for smooth and correct speed.
By the way I have not opened my THE C64 yet, I've seen the pictures and it's unlikely I will do any mods in the near future so I'll let it be.


CJM file-specific parameter text files

Just saying what the manual says. If you insert a memory stick into THE C64, you can load disk images (.d64) and program files (.prg) directly from the stick.

If you put rambo.d64 disk image on your memory stick, and have a rambo.cjm text file at the same folder, you can create a joystick configuration that maps the weapon change key (space) with the extra joystick buttons.

X:64,pal,accuratedisk,driveicon
J:1*:JU,JD,JL,JR,JF,JF,SP,SP,JF,SP,B,C,JF,4,5
J:2:JU,JD,JL,JR,JF,JF,F1,F2,JF,1,2,3,JF,F3,F4

Games such as Mercenary, Elite and any flight simulators can be obviously enhanced by this feature, even if these games often have far more buttons than the joystick has.

My palette is a bit iffy today, can't care to fix it
But certainly speed controls in Elite, missile target, launch & unarm keys could be configured this way. (It's just that C64 Elite is a bit crap.)

I also found the joystick a bit physically clumsy for these extra buttons, so it wasn't so enjoyable with Rambo. But there's no stopping using a proper 2000s USB gamepad with four-button cluster and shoulder buttons. How authentic is that... well, there were gamepads back in the day too.

For Twin Tornado, I tried this:

X:64,pal
J:1:JU,JD,JL,JR,JF,JF,F1,F2,JF,1,2,3,JF,F3,F4
J:2*:JU,JD,JL,JR,JF,JF,CO,/,JF,H,Y,A,JF,4,5

I put throttle controls to triangle buttons and wing adjust to the two leftmost of the tiny buttons. Third tiny button turns on the combat sights. Note that for "comma" I used CO, as obviously a real comma might mess the syntax.

Twin Tornado has serial head-to-head mode but this can't be done with THEC64
The simulator boasts surprisingly fast wireframe 3D. To fly the Tornado, Increase throttle to max, release wheel brake with SPACE. Pull up when appropriate. Once in air, switch gear and flaps with T and R respectively.

As a variable-sweep wing fighter, the Panavia Tornado can pull its wings back. Switch them to a position of 68 degrees and then you can reach Mach 1.0+ speeds. The wings can't be switched back unless you drop speed.

To get Digital Integration's Tomahawk to respond, I tried this:

X:64,pal
J:1:JU,JD,JL,JR,JF,JF,F1,F2,JF,1,2,3,JF,F3,F4
J:2*:JU,JD,JL,JR,JF,JF,A,Q,JF,S,W,P,JF,4,5

The throttle and collective controls are mapped to the triangle buttons and the two first tiny buttons. The third tiny button swaps between weapon systems, once they have been activated with key C on the keyboard.

To get that Apache up in the air, increase both collective and throttle until the copter starts to rise. Then you can turn the nose down a bit so it begins to move forward. Then re-adjust the throttle/collective to maintain level flight.

It's a bit hard to tell 8-bit flight simulators apart.
I noticed that trying to use the mapped keys and joystick in very complex motions, it may inadvertently activate a key that's not involved at all. Such as Pause in the case of Tomahawk. This might have happened with the real keyboard too, it's just that back in the day the keys did not receive these combinations so easily.

I have also felt the joystick gets a bit stuck once in a while. Perhaps it will loosen up a bit over time.

They really added some weight to it! Should have weighted the shaft, though.



Cartridge & Disk images

I was interested in whether THE C64 can accept cartridges, not just games but things like Action Replay VI or Final Cartridge III.

Long story short, AVI did not seem to work whereas FCIII did. It's one way to access a machine code monitor. I'd prefer the AVI monitor, though.

I encountered some hiccups with more complex disk loaders. I was a bit saddened that the Ultima IV remaster D81 image (a large-capacity disk image) would not run further than the intro screen.

So, the utility cart support in THE C64 is a bit more haphazard and might not behave entirely as one would wish, but it's not all a loss.

On the plus side, "easyflash" carts work and many important multi-disk games have been modded to work on these images, so welcome Project Firestart and Ultima IV remastered after all!

I felt that the savestates are unlikely to work on anything that sounds a bit non-standard, such as these cart image games.

The few demoscene intros I tried appeared fine, though borders were cropped at times. There is another display mode in THE C64 that shows more of the borders, but may result in a smaller mid-screen area for games.

I perhaps wouldn't use THE C64 for running demoscene demos anyway, as there is no support for CRT display and the SID emulation is what it is.


Disk image file handling

You can have C64-compatible .PRG files directly on the memory stick, but many games come in the .D64 disk image format, which can be a container for multiple C64 files.

THE C64 facilitates loading these disk contents directly from the menus (the first file will be loaded), but to have more sophisticated handling of these virtual floppies you need to use BASIC.

As THE C64 by default mounts an empty C64 floppy image in the .D64 format, it's easy to save BASIC code snippets to the disk using

SAVE "MYPROG",8

and load them back with

LOAD "MYPROG",8

It may make sense to backup that disk image once in a while.

You can check the contents of a disk image with

LOAD "$",8

followed with

LIST

Remember that reading the directory with LOAD "$",8 will destroy the current BASIC program in memory!

Removing files is a bit trickier, and you can't simply overwrite a file by saving it with the same filename. Three commands are required (each followed with return):

OPEN 15,8,15
PRINT #15,"S0:MYPROG"
CLOSE 15

S0 stands for SCRATCH0.



BASIC

Transferring code from PC over to THE C64 is not a very exciting prospect, you have to use the USB stick and that kind of slows things down a bit.

Once in a while it is fun to play around with the BASIC, although I rarely have patience to do anything large with it.

The trade-off with the 8-bit interpreted BASIC is that it's very easy to start a program and get things going, but as the program gets larger it becomes slow and difficult to organize.

So it might be good to have some kind of rough paper plan for the program as it grows. Experience with other languages is also a good teacher.

There are also ways to embed forethought into your program. Although you can always clear the screen and set the colors with a PRINT statement...


a subroutine could be called instead.

10 GOSUB 9000
100 REM main loop
200 GOTO 100
9000 REM clear screen subroutine
9010 PRINT "[clrhome][white]"; : REM use the real characters
9020 POKE 53280,0 : REM border black
9030 POKE 53281,0 : REM background black
9100 RETURN

So, every time you want to clear the screen and reset the colors, use GOSUB 9000.

The downside here is that you might not remember what GOSUB 9000 stands for, and the program becomes less readable. Unlike ZX Spectrum, C64 BASIC does not allow the use of variables as label names (which might slow down the calls besides).

So, use discretion!

Remember that editor screen codes can be inserted in the BASIC " quotes.
So, if normally pressing SHIFT+CLR/HOME clears the screen immediately, typing it after a " will enter the character code instead. Again closing the quote with " will again make the key work directly. Cursor keys, home/clr cursor and reverse on/off can be used this way.

So it's one way of positioning the cursor:

PRINT "[clrhome][down][down][down][down][right][right][right]HELLO"

[clrhome] implies pressing the key clr/home and so on. This would position the text down 4 rows and right 3 columns from the top left corner.

Then, later you can consider whether the screen-clearing has some kind of effect in it or not. Only changing the contents of that one subroutine you can change all screen clears in your program. Or replace it with a machine code call, etc.

There might be subroutine for "press any key", so it could always be called the same way and display that message too.

The subroutine call overhead is significant in BASIC, so it might be better avoided inside the main loop of an action game.

For displaying characters more directly, sometimes POKEing the display may be better than PRINTING character codes.

10 X=20
20 Y=12
30 POKE 1024+X+Y*40,1

This should display an 'A' at roughly at the middle of the screen. Bear in mind that generally PRINTing is faster than trying to combine many characters through POKEs.

Reading the joystick from BASIC is not hard. You have to decipher all the directions one at a time in case there are multiple directions and buttons pressed at once.

10 J=PEEK(56320)
20 IF (J AND 1)=0 THEN PRINT"UP"
30 IF (J AND 2)=0 THEN PRINT"DOWN"
40 IF (J AND 4)=0 THEN PRINT"LEFT"
50 IF (J AND 8)=0 THEN PRINT"RIGHT"
60 IF (J AND 16)=0 THEN PRINT"FIRE"
70 GOTO 10

In case you only need two opposite directions and no fire button, direct values can be used:

10 J=PEEK(56320)
20 IF J=119 THEN PRINT "RIGHT"
30 IF J=111 THEN PRINT "LEFT"
40 GOTO 10

This would spare the interpreter from making more calculations than needed.

The additional keys (and keyboard altogether) of THE C64 Joystick can be read like this:

10 GET A$
20 IF A$="Y" THEN PRINT "THEC64 EXTRA BUTTON 1"
30 IF A$="N" THEN PRINT "THEC64 EXTRA BUTTON 2"
40 IF A$<>"" THEN IF ASC(A$)=13 THEN PRINT "THEC64 EXTRA BUTTON 3"
50 GOTO 10

This assumes a THEC64 joystick with the default config of Y, N and RETURN. Of course the keys can be used too. I'm unsure if the RETURN key could be done with some other means, but at least that works.

Unless the joystick has been configured to other keys, the triangular buttons do nothing.

No comments:

Post a Comment