Thursday, October 20, 2022

Part 2d: Scanning for clues

A common technique that programmers use to disassemble code is to simply look for the ASCII text in the disassembly. This assumed that ASCII was around at the time of writing. Luckily for me ASCII first became a standard in 1963 and 8K ALTAIR 680 BASIC was written in 1976.

Just looking at the disassembled code from DASMx I can see lots of readable text, the first chunk appears at $015C through to $0233.

015B : 95 45 " E" bita X0045
;
015D : 4E "N" db $4E
;
015E : C4 46 " F" andb #$46
0160 : 4F "O" clra
0161 : D2 4E " N" sbcb X004E
;
0163 : 45 "E" db $45
;
0164 : 58 "X" aslb
0165 : D4 44 " D" andb X0044
;
0167 : 41 "A" db $41
;
0168 : 54 "T" lsrb
0169 : C1 49 " I" cmpb #$49
;
016B : 4E "N" db $4E
;
016C : 50 "P" negb
;
016D : 55 "U" db $55
;
016E : D4 44 " D" andb X0044
0170 : 49 "I" rola
;
0171 : CD " " db $CD
0172 : 52 "R" db $52
0173 : 45 "E" db $45
0174 : 41 "A" db $41
;
0175 : C4 4C " L" andb #$4C
;
0177 : 45 "E" db $45
.
.
.
;
0223 : A4 4C " L" anda $4C,x
;
0225 : 45 "E" db $45
;
0226 : 46 "F" rora
0227 : 54 "T" lsrb
0228 : A4 52 " R" anda $52,x
022A : 49 "I" rola
022B : 47 "G" asra
022C : 48 "H" asla
022D : 54 "T" lsrb
022E : A4 4D " M" anda $4D,x
0230 : 49 "I" rola
0231 : 44 "D" lsra
0232 : A4 00 "  " anda $00,x

Even though DASMx has mangled the listing I can still make out a lot of text in the hex data. I realised that the last byte of each keyword has it's high bit set. For example at $0172 we have $52, $45, $41, $C4, and if you drop the high bit on $C4 you get $44. So this now decodes as R E A D, a valid BASIC keyword.

It doesn't take long to decode the rest and after a bit of tidying up it now looks very readable. We have most if not all of our BASIC keywords listed here:

;last character has bit 7 set
;00.8k is used for EOL
015C : 45 4E C4 "END" ;80.8k Yes
015F : 46 4F D2 "FOR" ;81.8k Yes
0162 : 4E 45 58 D4 "NEXT" ;82.8k Yes
0166 : 44 41 54 C1 "DATA" ;83.8k Yes
016A : 49 4E 50 55 "INPUT" ;84.8k Yes
016E : D4
016F : 44 49 CD "DIM" ;85.8k Yes
0172 : 52 45 41 C4 "READ" ;86.8k Yes
0176 : 4C 45 D4 "LET" ;87.8k Yes
0179 : 47 4F 54 CF "GOTO" ;88.8k Yes
017D : 52 55 CE "RUN" ;89.8k Yes
0180 : 49 C6 "IF" ;8A.8k Yes
0182 : 52 45 53 54 "RESTORE" ;8B.8k Yes
0186 : 4F 52 C5
0189 : 47 4F 53 55 "GOSUB" ;8C.8k Yes
018D : C2
018E : 52 45 54 55 "RETURN" ;8D.8k Yes
0192 : 52 CE
0194 : 52 45 CD "REM" ;8E.8k Yes
0197 : 53 54 4F D0 "STOP" ;8F.8k Yes
019B : 4F CE "ON" ;90.8k Yes
019D : 4E 55 4C CC "NULL" ;91.8k Yes
01A1 : 57 41 49 D4 "WAIT" ;92.8k Yes
01A5 : 44 45 C6 "DEF" ;93.8k Yes
01A8 : 50 4F 4B C5 "POKE" ;94.8k Yes
01AC : 50 52 49 4E "PRINT" ;95.8k Yes
01B0 : D4
01B1 : 43 4F 4E D4 "CONT" ;96.8k Yes
01B5 : 4C 49 53 D4 "LIST" ;97.8k Yes
01B9 : 43 4C 45 41 "CLEAR" ;98.8k Yes
01BD : D2
01BE : 4E 45 D7 "NEW" ;99.8k Yes
01C1 : 54 41 42 A8 "TAB(" ;9A.8k Yes
01C5 : 54 CF "TO" ;9B.8k Yes
01C7 : 46 CE "FN" ;9C.8k Yes
01C9 : 53 50 43 A8 "SPC(" ;9D.8k Yes
01CD : 54 48 45 CE "THEN" ;9E.8k Yes
01D1 : 4E 4F D4 "NOT" ;9F.8k Yes
01D4 : 53 54 45 D0 "STEP" ;A0.8k Yes
01D8 : AB "+" ;A1.8k Yes
01D9 : AD "-" ;A2.8k Yes
01DA : AA "*" ;A3.8k Yes
01DB : AF "/" ;A4.8k Yes
01DC : DE "^" ;A5.8k Yes
01DD : 41 4E C4 "AND" ;A6.8k Yes
01E0 : 4F D2 "OR" ;A7.8k Yes
01E2 : BE ">" ;A8.8k Yes
01E3 : BD "=" ;A9.8k Yes
01E4 : BC "<" ;AA.8k Yes
01E5 : 53 47 CE "SGN" ;AB.8k Yes
01E8 : 49 4E D4 "INT" ;AC.8k Yes
01EB : 41 42 D3 "ABS" ;AD.8k Yes
01EE : 55 53 D2 "USR" ;AE.8k Yes
01F1 : 46 52 C5 "FRE" ;AF.8k Yes
01F4 : 50 4F D3 "POS" ;B0.8k Yes
01F7 : 53 51 D2 "SQR" ;B1.8k Yes
01FA : 52 4E C4 "RND" ;B2.8k Yes
01FD : 4C 4F C7 "LOG" ;B3.8k Yes
0200 : 45 58 D0 "EXP" ;B4.8k Yes
0203 : 43 4F D3 "COS" ;B5.8k Yes
0206 : 53 49 CE "SIN" ;B6.8k Yes
0209 : 54 41 CE "TAN" ;B7.8k Yes
020C : 41 54 CE "ATN" ;B8.8k Yes
020F : 50 45 45 CB "PEEK" ;B9.8k Yes
0213 : 4C 45 CE "LEN" ;BA.8k Yes
0216 : 53 54 52 A4 "STR$" ;BB.8k Yes
021A : 56 41 CC "VAL" ;BC.8k Yes
021D : 41 53 C3 "ASC" ;BD.8k Yes
0220 : 43 48 52 A4 "CHR$" ;BE.8k Yes
0224 : 4C 45 46 54 "LEFT$" ;BF.8k Yes
0228 : A4
0229 : 52 49 47 48 "RIGHT$" ;C0.8k Yes
022D : 54 A4
022F : 4D 49 44 A4 "MID$" ;C1.8k Yes
; NULL Terminator
0233 : 00 db $00 ;NULL (or DEL when inverted)

I find a few more small blocks of ASCII text throughout the ROM, but the main text blocks appear to be near the end of the ROM from $1A0B until $1AB7, then there seems to be some junk ASCII after $1AB8 that I later discover is not included in other dumps of the ALTAIR 680 interpreter, so I assume this is leftover and was not deleted from memory, or maybe the original source file I downloaded was not a clean dump and had leftover code that was re-saved to paper tape. For now I can ignore it.

1A0B ;WantSinCosTanAtn:
1A0B : 57 41 4E 54 db $57, $41, $4E, $54 ;"WANT"
1A0F : 20 53 49 4E db $20, $53, $49, $4E ;" SIN"
1A13 : 2D 43 4F 53 db $2D, $43, $4F, $53 ;"-COS"
1A17 : 2D 54 41 4E db $2D, $54, $41, $4E ;"-TAN"
1A1B : 2D 41 54 CE db $2D, $41, $54, $CE ;"-ATN"
1A1F : 00
1A20:
1A20 : 0D 0A 0C db $00, $0D, $0A, $0C ;CR, LF, FF
1A23 WrittenBy:
1A23 : 57 52 49 54 "WRIT" db "WRITTEN BY RICHARD W. WEILAND\xAE\x0D\x0A\x00"
       54 45 4E 20 "TEN "
       42 59 20 52 "BY R"
       49 43 48 41 "ICHA"
       52 44 20 57 "RD W"
       2E 20 57 45 ". WE"
       49 4C 41 4E "ILAN"
       44 AE 0D 0A "D.", CR, LF
       00 " "
1A44 TerminalWidth:
1A44 : 54 45 52 4D "TERM" db "TERMINAL WIDTH\x00"
       49 4E 41 4C "INAL"
       20 57 49 44 " WID"
       54 C8 00 "TH "
1A53 BytesFree:
1A53 : 20 42 59 54 " BYT" db " BYTES FREE\x0D\x0A\x0D\x0A"
       45 53 20 46 "ES F"
       52 45 C5 0D "REE "
       0A 0D 0A LF, CR, LF ;continued below...
1A62 VersionInfo:
1A62 : 4D 49 54 53 "MITS" db "MITS ALTAIR 680 BASIC VERSION 1.1 REV 3.2\x0D\x0ACOPYRIGHT 1976 BY MITS 
INC\xAE\x0D\x0A\x00"
       20 41 4C 54 " ALT"
       41 49 52 20 "AIR "
       36 38 30 20 "680 "
       42 41 53 49 "BASI"
       43 20 56 45 "C VE"
       52 53 49 4F "RSIO"
       4E 20 31 2E "N 1."
       31 20 52 45 "1 RE"
       56 20 33 2E "V 3."
       B2 0D 0A 43 "2  C"
       4F 50 59 52 "OPYR"
       49 47 48 54 "IGHT"
       20 31 39 37 " 197"
       36 20 42 59 "6 BY"
       20 4D 49 54 " MIT"
       53 20 49 4E "S IN"
       43 AE 0D 0A "C   "
       00 " "
1AAB MemorySize:
1AAB : 4D 45 4D 4F "MEMORY SIZE" db "MEMORY SIZE\x00\x00"
       52 59 20 53
       49 5A C5 00
1AB7 : 00 ;fill ?

;--------------------------------------------
; the following random data is not included in some punch tape downloads
;1AB8 Unknown:
;1AB8 : 20 49 53 20 " IS " db " IS IT RETURN\x0D BEQ OUT\x0D BRA INTAPE GET NEXT CHARACTER\x0D"
;       49 54 20 52 "IT R"
;       45 54 55 52 "ETUR"
;       4E 0D 20 42 "N  B"
;       45 51 20 4F "EQ O"
;       55 54 0D 20 "UT  "
;       42 52 41 20 "BRA "
;       49 4E 54 41 "INTA"
;       50 45 20 47 "PE G"
;       45 54 20 4E "ET N"
;       45 58 54 20 "EXT "
;       43 48 41 52 "CHAR"
;       41 43 54 45 "ACTE"
;       52 0D "R "
;1AEE End:
;1AEE : 20 45 4E 44 " END" db " END\x0D\x00"
;       0D 00 "  "
;1AF4 Fill:
1AF4 : 00 00 00 00 db $00, $00, $00, $00
       00 00 00 00 db $00, $00, $00, $00
       00 00 00 00 db $00, $00, $00, $00

A lot of good info here. I see the initialisation dialogue shown in Appendix B of the MITS ALTAIR BASIC REFERENCE MANUAL such as:

MEMORY SIZE?

TERMINAL WIDTH?

WANT SIN-COS-TAN-ATN?

Followed by the startup banner:

I assume there might be differences in the manual as the version is slightly different. I have Version 1.1 Revision 3.2 written in the ROM, whatever that means.

The manual is likely older as it's written for the ALTAIR 8800 4K, 8K and EXTENDED versions of BASIC rather than the ALTAIR 680 version. I later find a Supplement and Errata that describes the differences in ALTAIR 680 BASIC, which explains some of the differences.

That looks more like the 680 BASIC ROM in my disassembly.

Next I follow my nose...

No comments:

Post a Comment

Part 2o: The future of the ETA-3400X

You can find all the work I've done on the ETA-3400X and 8K ALTAIR 680 BASIC, except for the ETA-3400X Gerber files, on the ET-3400 grou...