Post Reply 
(PC-1211) Engineering format
05-13-2022, 05:43 PM (This post was last modified: 05-13-2022 08:01 PM by robve.)
Post: #10
RE: (PC-1211) Engineering format
(05-11-2022 11:19 PM)Dave Britten Wrote:  That would be extremely handy to have. How do the Sharp computers distinguish between MERGEd programs? Do they just look for out-of-order line numbers?\

I dusted off some of my old PC-1350 notes. The following is for S-BASIC for most Sharp PCs. I don't know for sure if this also holds for the earlier PC-1211 BASIC, probably not. Also the PC-1500, PC-1600, PC-E500 and PC-G850 use variations of this memory layout.

MERGEd programs are separated by 255 byte markers:

255 <- BASIC START ADDRESS
hi <- hi line number byte
lo <- lo line number byte
len <- line length, including 0xD (13)
BASIC tokenized line
13 <- 0xD end of line (carriage return)
hi
lo
len
... etc ...
255 <- MARGE MARKER
hi <- hi line number byte
lo <- lo line number byte
len <- line length, including 0xD (13)
BASIC tokenized line
13 <- 0xD
hi
lo
len
... etc ...
255 <- LAST MERGE MARKER AT BASIC MERGE ADDRESS
hi <- hi line number byte
lo <- lo line number byte
len <- line length, including 0xD (13)
BASIC tokenized line
13 <- 0xD
hi
lo
len
... etc ...
255 <- BASIC END ADDRESS


A program ends when the next hi byte of the line number is 255, which is either the next MERGEd program or the BASIC END ADDRESS with marker.

The last MERGEd program is editable, stored in memory starting at the BASIC MERGE ADDRESS.

For the PC-1360 there are two pairs of addresses for START, END and MARGE. One extra set resides on the RAM card, so RAM card with BASIC (merged) programs can be swapped. The internal START, END and MERGE are copies that must be synched.

PC-1360 BASIC addresses with low/high address byte pairs pointers are stored at the following locations in RAM:
  • 65495 BASIC START
  • 65497 BASIC END
  • 65499 BASIC MERGE
  • 32775 RAM BASIC START
  • 32777 RAM BASIC END
  • 32779 RAM BASIC MERGE
Other relevant addresses with pointers:
  • 65266 BASIC LAST LINE
  • 65268 BASIC BREAK POINT
  • 65270 BASIC ERROR POINT
For example, PEEK 65495+256*PEEK 65496 gives the BASIC START ADDRESS. The other addresses are not relevant, unless the locations of BASIC programs are changed by moving code in memory, which means that these pointers are no longer valid e.g. with cursor up to show the last executed line. Shift-CLS (CA) prevents that.

So all that we need to do to create a new "MERGEd" program is manipulate these pointers and POKE a small new program in memory with this 3 liner:

Code:
1 "NEW" L=PEEK 65497,H=PEEK 65498,E=L+256*H: POKE 65499,L,H: POKE 32779,L,H
2 POKE E,255,0,1,5,34,42,42,34,13,255: E=E+9,H=INT(E/256),L=E-256*H
3 POKE 65497,L,H: POKE 32777,L,H: END

To create a new "MERGEd" program:
  • RUN "NEW
  • then edit the label "**" at line 1 to define a new label for the program of your liking
To delete the last program MERGEd:
  • DELETE 1,
  • WARNING: DELETE has a bug that deletes the last program that was RUN or edited, instead of the last program merged. To avoid this, delete one line of the program first, then execute DELETE 1,
A machine code routine to rotate MERGEd programs in memory would be handy indeed. That would allow for any of the programs to be rotated to the top so it can be edited. I will work on that later.

(05-11-2022 11:19 PM)Dave Britten Wrote:  Some kind of catalog command to list all the labels in memory would be nice too.

Here you go:

Code:
1 "CAT" WAIT 0: A=PEEK 65495+256*PEEK 65496+1,E=PEEK 65497+256*PEEK 65498
2 IF PEEK A<>255 IF PEEK(A+3)<>34 LET A=A+PEEK(A+2)+3: GOTO 2
3 IF A>=E END
4 IF PEEK A=255 LET A=A+1: PRINT "/ ";: GOTO 2
5 FOR B=A+4 TO E:C=PEEK B:IF C>31 IF C<127 IF C<>34 PRINT CHR$ C;: NEXT B
6 B=E: NEXT B: PRINT " ";: A=A+PEEK(A+2)+3: GOTO 2

It would be a whole lot faster in machine code, but this works reasonably quickly.

These two programs work for most Sharp PC, if you can find the BASIC START and BASIC END addresses with the pointers to manipulate. The above was for the PC-1360.

For the PC-1350:
28417 BASIC START
28419 BASIC END
28421 BASIC MERGE
But the RAM card BASIC pointers differ depending on the RAM card size:
RAM card address + 7: RAM BASIC START
RAM card address + 9: RAM BASIC END
RAM card address + 11: RAM BASIC MERGE
No RAM card address = &6000, 8K RAM card address = &4000, 16K RAM card address = &2000

For the PC-1403 (no RAM cards):
65281 BASIC START
65283 BASIC END
65285 BASIC MERGE

For the PC-1262 (no RAM cards):
26337 BASIC START
26339 BASIC END
26341 BASIC MERGE

I've tested this on the PC-1360 without any issues so far. Feedback is appreciated if you encounter a problem. The "NEW" program assumes that at least a 9 bytes are available to POKE the new program in memory. It does not check for available space (adding a MEM check might be useful).

Minor edit: changed "LIST" to "CAT" as suggested to catalog labels.

- Rob

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (PC-1211) Engineering format - Dan C - 05-10-2022, 05:15 PM
RE: (PC-1211) Engineering format - robve - 05-10-2022, 08:47 PM
RE: (PC-1211) Engineering format - robve - 05-11-2022, 10:38 PM
RE: (PC-1211) Engineering format - robve - 05-10-2022, 05:19 PM
RE: (PC-1211) Engineering format - robve - 05-10-2022, 09:16 PM
RE: (PC-1211) Engineering format - robve - 05-13-2022 05:43 PM
RE: (PC-1211) Engineering format - robve - 05-15-2022, 09:24 PM
RE: (PC-1211) Engineering format - robve - 05-20-2022, 02:23 AM
RE: (PC-1211) Engineering format - robve - 05-13-2022, 08:12 PM
RE: (PC-1211) Engineering format - robve - 05-13-2022, 11:26 PM
RE: (PC-1211) Engineering format - robve - 05-16-2022, 12:38 AM
RE: (PC-1211) Engineering format - robve - 05-21-2022, 09:44 PM



User(s) browsing this thread: 11 Guest(s)