Skip to content

High Score writeable ATR example in BASIC

Bill Kendrick edited this page Oct 14, 2022 · 3 revisions

So you want to experiment with FujiNet's https://github.com/FujiNetWIFI/fujinet-platformio/wiki/High-Score-storage-for-Legacy-Games? Here's how you can experiment with it on an Atari with BASIC.

A hex editor (e.g., hexedit on Linux) is required, though you could also be clever with tools like dd to automate modification of ATR files (e.g., as part of a Makefile build process). Determining how to find the sector of a file (e.g., on an Atari DOS or MyDOS formatted disk image) from a host system like Linux is left as an exercise to the reader. (Once you've figured it out, please update this wiki page to explain the process!)

A simple program

  • Create a new blank disk image. (You can do this directly on your FujiNet. Navigate to "SD", and press [N] to create a new disk image.)
  • Boot into your favorite DOS, format the new disk image (thus creating a filesystem), and write DOS to it (thus making it bootable).
  • Boot the Atari into BASIC, with the new disk image mounted on drive 1 (D1:) in READ/WRITE mode.
  • Input this program and save it to the disk image:
0 REM SAVE"D:WRITER.BAS":RUN
5 TRAP 50
10 DIM A$(128)
20 OPEN #1,4,0,"D:WRITABLE.DAT"
30 INPUT #1,A$
40 ? "CURRENT TEXT:":? A$
50 CLOSE #1:TRAP 100
60 OPEN #1,8,0,"D:WRITABLE.DAT"
70 ? "ENTER TEXT"
80 INPUT A$
90 ? #1;A$
100 CLOSE #1

Testing writable vs not-writable

RUN the program, and enter some text (e.g., "HELLO, WORLD"). It will be saved in the text file WRITABLE.DAT. If you RUN again, you'll see your text (and be prompted to change it; hit [Break] to abort).

You may now try rebooting, but with the disk image mounted in READ-ONLY mode. RUN the program; you will see the text you entered before, but you cannot change it. (The OPEN-for-write (mode 8) command on line 60 will fail, and the error is TRAP-ed to line 100, where the program ends.)

Finding the sector

In BASIC, you can issue the following commands to determine the sector of the WRITABLE.DAT data file:

OPEN #1,4,0,"D:WRITABLE.DAT"
NOTE #1,SECT,BYT
? SECT

Updating the ATR

Say for example, the data file ended up on sector 94.

Use a hex editor to change bytes 12, 13, and 14 (0x000C, 0x000D, and 0x000E) of the ATR disk image file. Place 0x01 in position 12, representing the fact that only one sector will be writable. And place 0x5E and 0x00 in positions 13 and 14, representing the low byte and high byte of the sector that should be writable.

Try it out

Reboot with the modified disk image file, again in READ-ONLY mode. Now, when you RUN it, you should be able to modify the contents of the data file (and only the data file).

If you watch the serial output logs of your FujiNet over the USB cable, you'll see this following the "ATR WRTIE" log line: "High score mode activated, attempting write open". (At least, per 2022-10-12's 0.5.7eb55adb firmware version.)

Clone this wiki locally