What's Commodore PET BASIC Going From $ 00C2?
Pet page zero memory cards that I have found claim that address range zero is $00C2..$00D9
used for static data, for example. http://www.classiccmp.org/dunfield/pet/petmem.txt says:
RIDATA 00C2 Cassette Temp (64#00AA) read flags: 0=scan,
1-15=count, $40=load, $80=end of tape marker
RIPRTY 00C3 Cassette Short Cnt (64#00AB): counter of seconds
before tape write / checksum
PNT 00C4-00C5 Pointer: Current Screen Line Address
PNTR 00C6 Cursor Column on Current Line
SAL 00C7-00C8 Pointer: Tape Buffer/ Screen Scrolling
EAL 00C9-00CA Tape End Addresses/End of Program
CMP0 00CB-00CC Tape Timing Constants
QTSW 00CD Flag: Editor in Quote Mode, $00 = NO
BITTS 00CE Cassette Temp (64#00B4): Tape read timer flag
=IRQ enabled for Timer 1
00CF End of tape read
00D0 Read character error
FNLEN 00D1 Length of Current File Name
LA 00D2 Current Logical File Number
SA 00D3 Current Secondary Address
FA 00D4 Current Device Number
LNMX 00D5 Physical Screen Line Length
00D5 4.80: right side of window
TAPE1 00D6-00D7 Pointer: Start of Tape Buffer
TBLX 00D8 Current Cursor Physical Line Number
DATAX 00D9 Current Character to Print
However, by looking at the disassembly of the ROM, one can find the places where the address will move $00C2
, for example. http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/d/rom-1.html#C70A :
C70A 4C C2 00 JMP iC2
Taking a look at the disassembly starting from $00C2
after loading the PET, I see sane code:
.C:00c2 E6 C9 INC $C9
.C:00c4 D0 02 BNE $00C8
.C:00c6 E6 CA INC $CA
.C:00c8 AD 00 04 LDA $0400
.C:00cb C9 3A CMP #$3A
.C:00cd B0 0A BCS $00D9
.C:00cf C9 20 CMP #$20
.C:00d1 F0 EF BEQ $00C2
.C:00d3 38 SEC
.C:00d4 E9 30 SBC #$30
.C:00d6 38 SEC
.C:00d7 E9 D0 SBC #$D0
.C:00d9 60 RTS
What is this area for? Where is the code that collects this program in this area? What should this code do? (It seems the area scan starts with $0400
for :
and
symbols?)
source to share
This is part of the BASIC interpreter cycle. It reads one byte of the tokenized BASIC program, setting the flag to zero if it has a colon or zero byte, and releases carry if it is a number. You can see that it is used in the main part of the interpreter loop at address C6B5 .
I am not sure why this procedure was placed in page zero. It's a loop (or rarely two) is faster to use LDA $0400
over LDA ($C9),Y
, but I don't see it actually make a lot of difference.
It should also be noted that the ROM disassembly you are looking for is for BASIC 1.0 ROM, while the memory card you referenced is for versions 2.0 and 4.0.
Here's The Commodore 64 Mapping by Sheldon Leemon talks about the equivalent C64 procedure:
115-138 $ 73- $ 8A CHRGET
Subroutine: Get Next BASIC Text Character...
CHRGET is a key routine that BASIC uses to read text characters such as the text of a BASIC program that is being interpreted. This is put on page zero to make the program run faster. Since it keeps track of the address of the character being read in the routine, the procedure itself must be in RAM to update this pointer. The pointer to the byte address that is currently being read is indeed the operand of the LDA instruction. On input from CHRGET, the routine increments the pointer by changing the operand to TXTPTR (122, $ 7A), which allows the next character to be read.
Writing to CHRGOT (121, $ 79) allows you to read the current character again. CHRGET skips whitespace, sets various flags or (.P) to indicate whether the character read was a digit, operator terminator, or other type of character, and returns with the extracted character in Accumulator (.A).
...
Since this is such a central procedure, a dismantling list is provided below to better understand how it works.
115 $73 CHRGET INC TXTPTR ; increment low byte of TXTPTR 117 $75 BNE CHRGOT ; if low byte isn't 0, skip next 119 $77 INC TXTPTR+1 ; increment high byte of TXTPTR 121 $79 CHRGOT LDA ; load byte from where TXTPTR points ; entry here does not update TXTPTR, ; allowing you to readl the old byte again 122 $7A TXTPTR $0207 ; pointer is really the LDA operand ; TXTPTR+1 points to 512-580 ($200-$250) ; when reading from the input buffer ; in direct mode 124 $7C POINTB CMP #$3A ; carry flag set if > ASCII numeral 9 126 $7E BCS EXIT ; character is not a numeral--exit 128 $80 CMP #$20 ; if it is an ASCII space... 130 $82 BEQ CHRGET ; ignore it and get next character 132 $84 SEC ; prepare to subtract 133 $85 SBC #$30 ; ASCII 0-9 are between 48-57 ($30-$39) 135 $87 SEC ; prepare to subtract again 136 $88 SBC #$D0 ; if < ASCII 0 (57, $39) then carry is set 138 $8A EXIT RTS ; carry is clear only for numeral on return
The accumulator (register .A) contains the character that was read out of the routine. Status register bits (.P) that can be tested for output:
Carry Clear if the character was an ASCII digit 0-9. Carry Set, otherwise. Zero Set only if the character was an operator terminator 0 or ASCII, 58 ($ 3A). Otherwise Zero Clear.
source to share
Self-modifying code, notice the built-in pointer to $C9
. The source for him is in $E0B4
, and he copied the code page zero to $E0E5
.
It looks like this is indeed scanning the text and classifying the current character. It will set ZF
if the character is a space, but it CF
will be clear if it is a digit. Basically, this is useful for converting a string to a number, but this is just an assumption.
Update: An example procedure using this code is in $C863
. Of course, this is a string to number conversion, you can recognize the pattern that the result = result * 10 + (current_char - '0')
loop evaluates .
source to share