Hacking Apple Basic
2007年7月4日
Making compiler is a fun for me. So I started making a basic-compiler for Apple1. First, what I need to do is to hack the Apple Basic. In 30 years old computer, the program is NEVER stored as simple text but stored as binary code.
To find where the Basic program is stored, I made a simple program as follows:

I run this program, then a line was added (5 REM *** TEST ***). Again run the program and checked where the differences were.

The difference was only found between addresses 0 and 4095. This is a matter of course because the original Apple1 just contained memory in this area (the other 4 kb is used for Basic interpreter).
Further hacking showed that addresses 202 and 203 contains the starting address of Basic program. Following program was used to investigate the Basic code (there was another one, but I forgot taking a photo of that program).

The line #100 is used to check the binary code of program. You can put any statement (even if it causes an error) here. As a result following table was obtained:
To find where the Basic program is stored, I made a simple program as follows:

I run this program, then a line was added (5 REM *** TEST ***). Again run the program and checked where the differences were.

The difference was only found between addresses 0 and 4095. This is a matter of course because the original Apple1 just contained memory in this area (the other 4 kb is used for Basic interpreter).
Further hacking showed that addresses 202 and 203 contains the starting address of Basic program. Following program was used to investigate the Basic code (there was another one, but I forgot taking a photo of that program).

The line #100 is used to check the binary code of program. You can put any statement (even if it causes an error) here. As a result following table was obtained:
| 0 , 1 end of line 2 _ (?) 3 : 4 LIST 5 , 6 LIST 7 RUN 8 RUN 9 DEL | 10 , 11 SCR 12 CLR 13 AUTO 14 , 15 OFF 16 HIMEM= 17 LOMEM= (# 4-17 cannot be used in program) 18 + 19 - | 20 * 21 / 22 = 23 # 24 >= 25 > 26 <= 27 <> 28 < 29 AND | 30 OR 31 MOD 32 ^ (n/a) 33 + 34 ( 35 , 36 THEN 37 THEN 38 , 39 , 40 " | 41 " 42 ( 43 ! (?) 44 ! (?) 45 ( 46 PEEK 47 RND 48 SGN 49 ABS |
| 50 USR (n/a) 51 RNDX (n/a) 52 ( 53 + 54 - 55 NOT 56 ( 57 = 58 # 59 LENC (n/a) | 60 COLOR (n/a) 61 HIMEM (n/a) 62 LOMEM (n/a) 63 ( 64 $ 65 $ 66 ( 67 , 68 , 69 ; | 70 ; 71 ; 72 , 73 , 74 ! (?) 75 ? (?) 76 ? (?) 77 CALL 78 DIM 79 DIM | 80 TAB 81 END 82 INPUT 83 INPUT 84 INPUT 85 FOR 86 = 87 TO 88 STEP 89 NEXT | 90 , 91RETURN 92 GOSUB 93 REM 94 LET 95 GOTO 96 IF 97 PRINT 98 PRINT 99 PRINT |
| 100 POKE 101 , 102 COLOR= (n/a) 103 PLOT (n/a) 104 , 105 HLIN (n/a) 106 , 107 AT 108 - 109 , | 110 + 111 - 112 = 113 = 114 , 115 , 116 _ 117 , 118 + 119 - | 120 O 121 ) 122 + 123 5 (?) 124 O 125 ) 126 O 127 ) | 128-255 ASCII + 80h |