Bob’s Notebook: Peeking and Poking About

Authors

Publication

Pub Details

Date

Pages

See all articles from Sinc-Link v5 n6

One of the fun things about using the T52068 is the ability to PEEK and POKE about in amongst the machine code and particularly when using the BASIC compiler “Timachine“.

Recently, I had compiled (for the nth time) the Indexer program which I use to keep track of all the programs on my disks. In the process I had decided to do all the input/output routines in a loader program rather than inside the code. This would increase the flexibility and usefulness of the program which is limited to 1000 records. Now it can be used ad infinitum no matter how many programs I end up with simply by breaking the listings into smaller parts. So I ended up with a file of current records and another file of what I choose to call “archives”. Then I wanted to keep a listing sorted by names and another by disk in each of the two parts.

My SAVES then became:

  • indexn.CM (current by name)
  • indexd.CM (current by disk)
  • indexr. CM (archives by name)
  • indexk. C (archives by disk)
  • index0. CM (no data — ready for new file)

In my i/o loader I found that I needed to know which file I had in situ at any time: I needed a current status of file and sort type. Well I could have put that into the BASIC before I compiled it but being BASICally lazy, I chose to try to put the information in the loader and so avoid recompiling.

One thing I usually do when I compile a program is to take a copy of the runtime and variable locations by using REM ! LIST. I had done this with “Index” and examining this and my hardcopy of the BASIC program, I located the variable that held the sort type value, in this case “D” for disk and “N” for name. The variable was V$ located at 49333 in the compiled code. Now the string length was shown as 2 but there were four bytes set aside, the first two to hold the string length. So the value I wanted was at 49335. I could, by PEEKING this address find which sort was in effect at SAVE time and, in fact, i could POKE in a different value if I wanted to. So all I had to do in the loader was tell it to print “name” if PEEK 49335 was 110 (code for “n”) or “disk” if it was 100 (code for “d”). It will print “nil” if the value was 32 (code for a space). See line 605 in the extract of my loader, below. Earlier in the program I had LET v1=PEEK 49335.

But I wanted to show the program name on the loader menu and nowhere in the Indexer was the name already in storage. By a stroke of good luck (and not good management) I had some spare space in y$ which should have been set to a length of 6 but which I had overlooked in the REM ! LEN $ line and which was now 255 bytes long (by default). 0h well! Dark clouds and silver linings and all that. Y$ started at 49371 so the first 8 bytes were used for its true function: two bytes for the string the string length and six for the date when the index file was SAVED. So, from 49380 on was free for me to use as I wished.

In the loader, I entered lines which prompted me for a file name each time I used SAVE and LOAD. That name was POKED into the nine bytes starting at 49380. So now that program name was SAVED inside the compiled code and later could be LOADED and displayed in the loader program. See line 560 for the SAVE (encode and line 580 for the LOAD (decode) sub-routines.

Here is a sample of what the loader menu looks like with some explanations at the right:

Bob’s Notebook: Peeking and Poking About

:enter the file name
:to start a new file
:enter the file name
:end a session
:return to file in situ

:3=loaded + prog name
:sort type

Here is a sample of the Status when SAVING:

:5=restart + prog name
:enter prog name to SAVE
:this prog being saved

This shows that you can SAVE a file under a new name if you choose, but lets you keep track of what you have LOADED so that you do not SAVE it under a wrong name accidentally.

550 REM ##status## 
560 FOR k=1 TO 9: POKE 49379+k, CODE l$(k): NEXT k: RETURN
580 FOR k=1 TO 9: LET l$(k)=CHR$ PEEK (49379+k): NEXT k : RETURN
600 GO SUB 580
602 PRINT AT 10,0; INK 5;"Current Status"' INVERSE 1;d$ ; INVERSE 0;" ";l$;TAB 30
605 PRINT AT 12,0; INK 6;"Sorted by "; INVERSE 1; ("name " AND v1=110)+("disk" AND v1=100)+("nil" AND v1=32); INVERSE 0;TAB 30
610 RETURN
Scroll to Top