; Copyright 2018 faddenSoft. All Rights Reserved. ; See the LICENSE.txt file for distribution terms (Apache 2.0). ; ; Sources: ; What's Where in the Apple, by William F. Luebbert ; S-C DocuMentor: Applesoft, by Bob Sander-Cederlof *SYNOPSIS Applesoft BASIC addresses and constants BAS_USRVEC @ $0A 3 ;USR() command vector BAS_CHARAC @ $0D ;used by string utility BAS_ENDCHR @ $0E ;used by string utility BAS_VALTYP @ $11 2 ;flag for last FAC operation ($00=num, $FF=str) BAS_SUBFLG @ $14 ;subscript flag ($00=allowed, $80=not) BAS_HCOLOR1 @ $1C ;hi-res color mask BAS_COUNTH @ $1D ;hi-res high-order byte of step for line BAS_HBASL @ $26 ;base address for hi-res drawing (lo part) BAS_HBASH @ $27 ;base address for hi-res drawing (hi part) BAS_HMASK @ $30 ;hi-res graphics on-the-fly bit mask BAS_LINNUM @ $50 2 ;line number (2b) BAS_TEMPPT @ $52 2 ;temporary point (2b) BAS_INDEX @ $5E 2 ;temp (stack) pointer for moving strings (2b) BAS_TEXTTAB @ $67 2 ;pointer to start of Applesoft program (2b) BAS_VARTAB @ $69 2 ;pointer to start of Applesoft variables (2b) BAS_ARYTAB @ $6B 2 ;pointer to start of Applesoft array space (2b) BAS_STREND @ $6D 2 ;pointer to end of numeric storage (2b) BAS_FRETOP @ $6F 2 ;pointer to end of string storage (2b) BAS_MEMSIZE @ $73 2 ;HIMEM (2b) BAS_CURLIN @ $75 2 ;current line number (2b) BAS_OLDLIN @ $77 2 ;last line executed (2b) BAS_OLDTEXT @ $79 2 ;old text pointer (2b) BAS_DATLIN @ $7B 2 ;current line # from which data is being read (2b) BAS_DATPTR @ $7D 2 ;points to mem from which data is being read (2b) BAS_VARNAM @ $81 2 ;holds last-used variable's name (2b) BAS_VARPNT @ $83 2 ;pointer to last-used variable's value (2b) BAS_FORPNT @ $85 2 ;general pointer (2b) BAS_JMPADRS @ $90 3 ;jump address; $90 is set to $4C (3b) BAS_TEMP1 @ $93 ;fp math register BAS_HIGHDS @ $94 2 ;block copy pointer (2b) BAS_HIGHTR @ $96 2 ;block copy pointer (2b) BAS_TEMP2 @ $98 ;fp math register BAS_LOWTR @ $9B 2 ;general pointer (2b) BAS_FAC @ $9D 6 ;floating point accumulator (6b) BAS_FACMO = $A0 ;middle-order byte of mantissa of FAC BAS_FACLO = $A1 ;low-order byte of mantissa of FAC BAS_FACSIGN @ $A2 ;single byte sign of FAC BAS_ARG @ $A5 6 ;secondary floating point accumulator (6b) BAS_STRNG1 @ $AB 2 ;pointer to a string (2b) BAS_STRNG2 @ $AD 2 ;pointer to a string (2b) BAS_PRGEND @ $AF 2 ;pointer to end of program (2b) BAS_CHRGET @ $B1 ;get next character or Applesoft token BAS_CHRGOT @ $B7 ;get next, but don't advance TXTPTR BAS_TXTPTR @ $B8 2 ;points at next char or token (2b) BAS_RND @ $C9 5 ;floating point random number (5b) BAS_AUTORUN @ $D6 ;set to $80 to auto-run BAS_ERRFLG @ $D8 ;$80 if onerr active BAS_HPAG @ $E6 ;hi-res page to draw on ($20 or $40) BAS_SCALE @ $E7 ;hi-res graphics scale factor BAS_HSHAPE @ $E8 2 ;hi-res shape table pointer (2b) BAS_FIRST @ $F0 ;used for lo-res plot coordinates BAS_SPEEDZ @ $F1 ;controls text output speed BAS_ORMASK @ $F3 ;mask for output control BAS_REMSTK @ $F8 ;stack pointer saved before each statement BAS_AMPERV @ $03F5 3 ;JMP to function that handles Applesoft '&' cmds ; ; Useful Applesoft routines. ; TODO: there are many more ; BAS_ERROR @ $D412 ;print error based on X-reg BAS_FRMNUM @ $DD67 ;call FRMEVL, confirm expr is numeric BAS_FRMEVL @ $DD7B ;eval expr at TXTPTR (num/str), result into FAC BAS_SYN_ERROR @ $DEC9 ;throw SYNTAX ERROR BAS_CHKCOM @ $DEBE ;checks TXTPTR for comma BAS_ILLQ_ERROR @ $E199 ;throw ILLEGAL QUANTITY ERROR BAS_GIVAYF @ $E2F2 ;convert 16-bit (A,Y) to float, store in FAC BAS_SNGFLT @ $E301 ;convert 8-bit int (Y) to FLOAT BAS_GETBYT @ $E6F8 ;gets byte, in X/FACLO BAS_GETADR @ $E752 ;convert FAC to 2-byte integer in LINNUM BAS_FSUB @ $E7A7 ;FAC = (Y,A) - FAC BAS_FADD @ $E7BE ;FAC = (Y,A) + FAC BAS_CON_ONE @ $E913 ;constant value 1.0 BAS_FMULT @ $E97F ;FAC = (Y,A) * FAC BAS_LOAD_ARG_FROM_YA @ $E9E3 ;unpack 5-byte val at (Y,A) into ARG BAS_MUL10 @ $EA39 ;multiply FAC by 10 BAS_CON_TEN @ $EA50 ;constant value 10.0 BAS_FDIV @ $EA66 ;FAC = (Y,A) / FAC BAS_LOAD_FAC_FROM_YA @ $EAF9 ;unpack 5-byte val at (Y,A) into FAC BAS_STORE_FAC_AT_YX_ROUNDED @ $EB2B ;round FAC, store at (Y,X) BAS_SIGN @ $EB82 ;test FAC sign; <,=,> 0 -> A={-1,0,1} BAS_FLOAT @ $EB93 ;convert value in A to float in FAC BAS_ABS @ $EBAF ;changes sign of FAC to + BAS_FCOMP @ $EBB2 ;cmp (Y,A) with FAC; <,=,> -> A={1,0,-1} BAS_QINT @ $EBF2 ;convert FAC to big-endian int in FAC+1..FAC+4 BAS_INT @ $EC23 ;FAC = floor(FAC) BAS_LINPRT @ $ED24 ;print float at (A,X) as decimal integer BAS_PRINT_FAC @ $ED2E ;print FAC to screen BAS_CON_HALF @ $EE64 ;constant value 0.5 BAS_FPWRT @ $EE97 ;compute exponentiation BAS_NEGOP @ $EED0 ;negate value in FAC BAS_RND @ $EFAE ;generate random number BAS_CON_PI_HALF @ $F066 ;constant value PI/2 BAS_CON_PI_DOUB @ $F06B ;constant value PI*2 BAS_QUARTER @ $F070 ;constant value 0.25 BAS_HGR @ $F3E2 ;switch to hi-res mixed-mode and clear BAS_HPOSN @ $F411 ;set hi-res position; horiz=(Y,X) vert=A BAS_HPLOT0 @ $F457 ;plot point; horiz=(Y,X), vert=A BAS_HGLIN @ $F53A ;draw line from last point to (A,X),Y BAS_DRAW0 @ $F601 ;draw a shape from addr (Y,X) BAS_HFNS @ $F6B9 ;get hi-res x/y for hplot BAS_HCOLOR @ $F6E9 ;set hi-res color ; ; Applesoft BASIC tokens. ; *TAG Applesoft-Tokens TOK_END = $80 TOK_FOR = $81 TOK_NEXT = $82 TOK_DATA = $83 TOK_INPUT = $84 TOK_DEL = $85 TOK_DIM = $86 TOK_READ = $87 TOK_GR = $88 TOK_TEXT = $89 TOK_PR = $8a TOK_IN = $8b TOK_CALL = $8c TOK_PLOT = $8d TOK_HLIN = $8e TOK_VLIN = $8f TOK_HGR2 = $90 TOK_HGR = $91 TOK_HCOLOR = $92 TOK_HPLOT = $93 TOK_DRAW = $94 TOK_XDRAW = $95 TOK_HTAB = $96 TOK_HOME = $97 TOK_ROT = $98 TOK_SCALE = $99 TOK_SHLOAD = $9a TOK_TRACE = $9b TOK_NOTRACE = $9c TOK_NORMAL = $9d TOK_INVERSE = $9e TOK_FLASH = $9f TOK_COLOR = $a0 TOK_POP = $a1 TOK_VTAB = $a2 TOK_HIMEM = $a3 TOK_LOMEM = $a4 TOK_ONERR = $a5 TOK_RESUME = $a6 TOK_RECALL = $a7 TOK_STORE = $a8 TOK_SPEED = $a9 TOK_LET = $aa TOK_GOTO = $ab TOK_RUN = $ac TOK_IF = $ad TOK_RESTORE = $ae TOK_AMPER = $af TOK_GOSUB = $b0 TOK_RETURN = $b1 TOK_REM = $b2 TOK_STOP = $b3 TOK_ON = $b4 TOK_WAIT = $b5 TOK_LOAD = $b6 TOK_SAVE = $b7 TOK_DEF = $b8 TOK_POKE = $b9 TOK_PRINT = $ba TOK_CONT = $bb TOK_LIST = $bc TOK_CLEAR = $bd TOK_GET = $be TOK_NEW = $bf TOK_TAB = $c0 TOK_TO = $c1 TOK_FN = $c2 TOK_SPC = $c3 TOK_THEN = $c4 TOK_AT = $c5 TOK_NOT = $c6 TOK_STEP = $c7 TOK_PLUS = $c8 TOK_MINUS = $c9 TOK_MULT = $ca TOK_DIV = $cb TOK_EXPOP = $cc TOK_AND = $cd TOK_OR = $ce TOK_GREATER = $cf TOK_EQUAL = $d0 TOK_LESSER = $d1 TOK_SGN = $d2 TOK_INT = $d3 TOK_ABS = $d4 TOK_USR = $d5 TOK_FRE = $d6 TOK_SCRN = $d7 TOK_PDL = $d8 TOK_POS = $d9 TOK_SQR = $da TOK_RND = $db TOK_LOG = $dc TOK_EXP = $dd TOK_COS = $de TOK_SIN = $df TOK_TAN = $e0 TOK_ATN = $e1 TOK_PEEK = $e2 TOK_LEN = $e3 TOK_STR = $e4 TOK_VAL = $e5 TOK_ASC = $e6 TOK_CHR = $e7 TOK_LEFT = $e8 TOK_RIGHT = $e9 TOK_MID = $ea ; end of tokens