The ROM Disassembly
The Oric contains a ROM (Read Only Memory) which contains all the machine code programs needed to implement Basic. This large machine code program is permanent and is not erased when the power to the computer is turned off. When the Oric is powered up, this program will run automatically and it enables user programs to be typed in and run.
On the Oric, the routines are divided into two main sections, those that comprise the Basic language, which lies towards the front of the ROM (between #C000 and #ECC3) and those that make up the operating system (which lies between #ECC4 and #FFFF).
The Basic language acts like a large and powerful microprocessor. It can handle real numbers, strings and loops, perform complicated mathematical functions, draw on the screen, generate sounds and make complicated decisions. Such commands cannot be given to the 6502 directly, they have to be broken down into instructions which it can execute. The purpose of the machine code routines in which Basic is written is to break down the statements of a program into instructions that can be run on the 6502.
Real numbers and results of mathematical operations are stored in F1oating Point Accumulators (FPA) as though they were registers used by Basic. Each floating point accumulator consists of 6 bytes of memory, one to hold a signed exponent, four to hold the mantissa and the last to hold the sign of the mantissa (see section 6.2.8). Basic has two FPAs in which mathematical operations such as add and divide are performed. The main and work FPAs each hold an operand at the start of each mathematical operation and the result is left in the main FPA. Other locations in memory are used as temporary storage for the FPAs when complicated expressions are being evaluated.
The same FPAs are used when handling integers and strings but the format of data within each is different.
Many of the other many memory locations used by Basic are used to store information about the program it is running and where all the current variables are.
The other major part of the ROM, the operating system, consists of a series of routines which are used by Basic to input and output data. The operating system routines are specific to the Oric and handle such things as input from the keyboard, writing to the screen or printer and loading or saving from the cassette system. It also requires a section of memory to hold all its variables, most of which are in page 2 of memory.
The listing below is that of the Oric Atmos ROM (V1.1) which is an updated version of that used in the Oric 1 (V1.0). The only differences between the two are the correcting of errors and the addition of two new keywords. For example, the original version did not allow the POKEing of hexadecimal numbers into memory and that 13 had to be added to the argument in the TAB statement. The two new keywords, STORE and RECALL allow the saving and loading of arrays from cassette. Their tokens respectively replace those of INVERSE and NORMAL on the
Oric 1 which both give 'SYNTAX ERROR'.
Note that standard 6502 assembly syntax has been used in which a '$' before a number is used to represent a hexadecimal argument and a '#' is used to represent an immediate argument.
C0004C CC ECJMP $ECCCJump to START BASIC
C0034C 71 C4JMP $C471Jump to RESTART BASIC
C00672 C9 91 C6 86 E9 D0 E9JUMP TABLE for each of the
C00E15 CD 18 CD 11 CA 50 DAcommands, in token order. The
C016A0 DA DD D9 66 D9 84 DAtable is in two halves, firstly
C01EA0 DA 54 C8 FC C7 08 C8for those commands which may
C02697 CE 3B CA 54 CD 7D D1start a statement and secondly
C02ECD CC 88 CD 1B CB E4 C9for those which may not. Some
C036BC C9 6F CA 51 C9 C7 C9tokens do not have start
C03E11 CA 98 CA CD EB E6 EBaddresses - see Appendix A.
C0460B EC 20 EC 32 EC B4 FAThe values in the first part of
C04ECA FA E0 FA 9E FA FB EAthe table are one less than the
C056FB EA FB EA EF EA EF EAstart address of the routines.
C05EEF EA EF EA EF EA EF EAThis is because the RTS
C066EF EA FB EA FB EA 70 C9instruction is used as an
C06EC1 CA 57 D9 5A E8 08 E9indirect jump which
C076B9 D4 4E D9 AA CB 9F C9automatically increments the
C07E47 C7 0C C7 45 CD 45 E9address by 1.
C08612 CD ED C6 21 DF BD DF
C0BE49 DF 21 00 7E D4 A6 D4
C096B5 D9 FB 02 2E E2 4F E3
C09EAF DC AA E2 8B E3 92 E3
C0A6DB E3 3F E4 38 D9 83 D9
C0AED4 DD A6 D8 93 D5 D7 D8
C0B6B5 D8 16 D8 77 DE 0F DF
C0BE0B DF DA DA 3F DA 45 EC
C0C62A D8 56 D8 61 D8 79 24
C0CEDB 79 0D DB 7B EF DC 7B
C0D6E6 DD 7F 37 E2 50 E5 D0
C0DE46 E2 D0 7D 70 E2 5A 3B
C0E6D0 64 12 D1 45 4E C4 45 ENDEBASIC KEYWORDS
C0EE44 49 D4 53 54 4F 52 C5DITSTORE
C0F652 45 43 41 4C CC 54 52RECALLTRThe last character
C0FE4F CE 54 52 4F 46 C6 50ONTROFFPof a keyword has bit
C1064F D0 50 4C 4F D4 50 55OPPLOTPU7 set.
C10E4C CC 4C 4F 52 45 D3 44LLLORESD
C1164F 4B C5 52 45 50 45 41OKEREPEA
C11ED4 55 4E 54 49 CC 46 4FTUNTILFO
C126D2 4C 4C 49 53 D4 4C 50RLLISTLP
C12E52 49 4E D4 4E 45 58 D4RINTNEXT
C13644 41 54 C1 49 4E 50 55DATAINPU
C13ED4 44 49 CD 43 4C D3 52TDIMCLSR
C14645 41 C4 4C 45 D4 47 4FEADLETCO
C14E54 CF 52 55 CE 49 C6 52TORUNIFR
C15645 53 54 4F 52 C5 47 4FESTOREGO
C15E53 55 C2 52 45 54 55 52SUBRETUR
C166CE 52 45 CD 48 49 4D 45NREMHIME
C16ECD 47 52 41 C2 52 45 4CMGRABREL
C17645 41 53 C5 54 45 58 D4EASETEXT
C17E48 49 52 45 D3 53 48 4FHIRESSHO
C1864F D4 45 58 50 4C 4F 44OTEXPLOD
C18EC5 5A 41 D0 50 49 4E C7EZAPPING
C19653 4F 55 4E C4 4D 55 53SOUNDMUS
C19E49 C3 50 4C 41 D9 43 55ICPLAYCU
C1A652 53 45 D4 43 55 52 4DRSETCURM
C1AE4F D6 44 52 41 D7 43 49OVDRAWCI
C1B652 43 4C C5 50 41 54 54RCLEPATT
C1BE45 52 CE 46 49 4C CC 43ERNFILLC
C1C648 41 D2 50 41 50 45 D2HARPAPER
C1CE49 4E CB 53 54 4F D0 4FINKSTOPO
C1D6CE 57 41 49 D4 43 4C 4FNWAITCLO
C1DE41 C4 43 53 41 56 C5 44ADCSAVED
C1E645 C6 50 4F 4B C5 50 52EFPOKEPR
C1EE49 4E D4 43 4F 4E D4 4CINTCONTL
C1F649 53 D4 43 4C 45 41 D2ISTCLEAR
C1FE47 45 D4 43 41 4C CC A1CETCALL!
C2064E 45 D7 54 41 42 A8 54NEWTAB(T
C20ECF 46 CE 53 50 43 A8 C0OFNSPC(@
C21641 55 54 CF 45 4C 53 C5AUTOELSE
C21E54 48 45 CE 4E 4F D4 53THENNOTS
C22654 45 D0 AB AD AA AF DETEP+-*/A
C22E41 4E C4 4F D2 BE BD BCANDOR)=<
C23653 47 CE 49 4E D4 41 42SGNINTAB
C23ED3 55 53 D2 46 52 C5 50SUSRFREP
C2464F D3 48 45 58 A4 A6 53OSHEX$&S
C24E51 D2 52 4E C4 4C CE 45QRRNDLNE
C25658 D0 43 4F D3 53 49 CEXPCOSSIN
C25E54 41 CE 41 54 CE 50 45TANATNPE
C26645 CB 44 45 45 CB 4C 4FEKDEEKLO
C26EC7 4C 45 CE 53 54 52 A4GLENSTR$
C27656 41 CC 41 53 C3 43 48VALASCCH
C27E52 A4 50 C9 54 52 55 C5R$PITRUE
C28646 41 4C 53 C5 4B 45 59FALSEKEY
C28EA4 53 43 52 CE 50 4F 49$5CRNPOI
C2964E D4 4C 45 46 54 A4 52NTLEFT$R
C29E49 47 48 54 A4 4D 49 44IGHT$MID
C2A6A4 00 4E 45 58 54 20 57$ NEXT WERROR MESSAGES
C2AE49 54 48 4F 55 54 20 46ITHOUT F
C2B64F D2 53 59 4E 54 41 D8ORSYNTAX
C2BE52 45 54 55 52 4E 20 57RETURN W
C2C649 54 48 4F 55 54 20 47ITHOUT G
C2CE4F 53 55 C2 4F 55 54 20OSUBOUT
C2D64F 46 20 44 41 54 C1 49OF DATAI
C2DE4C 4C 45 47 41 4C 20 51LLEGAL Q
C2E655 41 4E 54 49 54 D9 4FUANTITYO
C2EE56 45 52 46 4C 4F D7 4FVERFLOWO
C2F655 54 20 4F 46 20 4D 45UT OF ME
C2FE4D 4F 52 D9 55 4E 44 45MORYUNDE
C30646 27 44 20 53 54 41 54F'D STAT
C30E45 4D 45 4E D4 42 41 44EMENTBAD
C31620 53 55 42 53 43 52 49 SUBSCRI
C31E50 D4 52 45 44 49 4D 27PTREDIM'
C32644 20 41 52 52 41 D9 44D ARRAYD
C32E49 56 49 53 49 4F 4E 20IVISION
C33642 59 20 5A 45 52 CF 49BY ZEROI
C33E4C 4C 45 47 41 4C 20 44LLEGAL D
C34649 52 45 43 D4 44 49 53IRECTDIS
C34E50 20 54 59 50 45 20 4DP TYPE M
C35649 53 4D 41 54 43 C8 53ISMATCHS
C35E54 52 49 4E 47 20 54 4FTRING TO
C3664F 20 4C 4F 4E C7 46 4FO LONGFO
C36E52 4D 55 4C 41 20 54 4FRMULA TO
C3764F 20 43 4F 4D 50 4C 45O COMPLE
C37ED8 43 41 4E 27 54 20 43XCAN'T C
C3864F 4E 54 49 4E 55 C5 55ONTINUEU
C38E4E 44 45 46 27 44 20 46NDEF'D F
C39655 4E 43 54 49 4F CE 42UNCTIONB
C39E41 44 20 55 4E 54 49 CCAD UNTIL
C3A620 45 52 52 4F 52 00 20 ERROR
C3AE49 4E 20 00 0D 0A 52 65IN Re
C3B661 64 79 20 0D 0A 00 0Dady
C3BE0A 20 42 52 45 41 4B 00 BREAK
C3C6BATSXSearch for a variable match in
C3C7E8INXFOR-NEXT loop.
C3C8E8INX
C3C9E8INXSuccessive FOR-NEXT loops are
C3CAE8INXpulled off the stack until a
C3CBBD 01 01LDA $0101,Xvariable match is made.
C3CEC9 8DCMP #$8D
C3D0D0 21BNE $C3F3If a match is made then the Z
C3D2A5 B9LDA $B9flag in the status register is
C3D4D0 0ABNE $C3E0set to 1; otherwise it is set
C3D6BD 02 01LDA $0102,Xto 0.
C3D985 B8STA $B8
C3DBBD 03 01LDA $0103,X
C3DE85 B9STA $B9
C3E0DD 03 01CMP $0103,X
C3E3D0 07BNE $C3EC
C3E5A5 B8LDA $B8
C3E7DD 02 01CMP $0102,X
C3EAF0 07BEQ $C3F3
C3EC8ATXA
C3ED18CLC
C3EE69 12ADC #$12
C3F0AATAX
C3F1D0 D8BNE $C3CB
C3F360RTS
C3F420 44 C4JSR $C444This routine opens up new
C3F785 A0STA $A0space in memory to store
C3F984 A1STY $A1new variables.
C3FB38SEC($CE/$CF points to start of
C3FCA5 C9LDA $C9block, $C9/$CA points to end
C3FEE5 CESBC $CEof block, $C7/$C8 points to
C40085 91STA $91new end of block).
C402A8TAYX(MSB) and Y (LSB) hold the
C403A5 CALDA $CAsize of block.
C405E5 CFSBC $CF
C407AATAX
C408E8INXBranch if block is a whole
C40998TYAnumber of pages.
C40AF0 23BEQ $C42F
C40CA5 C9LDA $C9Point $C9/$CA and $C7/$C8 to
C40E38SECthe bottom of the pages that
C40FE5 91SBC $91they were pointing to.
C41185 C9STA $C9
C413B0 03BCS $C418
C415C6 CADEC $CA
C41738SEC
C418A5 C7LDA $C7
C41AE5 91SBC $91
C41C85 C7STA $C7
C41EB0 08BCS $C428
C420C6 C8DEC $C8
C42290 04BCC $C428
C424B1 C9LDA ($C9),YShift whole page up in memory.
C42691 C7STA ($C7),Y
C42888DEY
C429D0 F9BNE $C424
C42BB1 C9LDA ($C9),YShift last byte (when Y=0)
C42D91 C7STA ($C7),Y
C42FC6 CADEC $CADecrement pointer page numbers
C431C6 C8DEC $C8
C433CADEXContinue until all pages have
C434D0 F2BNE $C428been moved.
C43660RTS
C4370AASL ACheck for 2 x content of A
C43869 3EADC #$3Efree bytes on stack. C is set
C43AB0 40BCS $C47Cat end of routine if enough
C43C85 91STA $91space is free.
C43EBATSX
C43FE4 91CPX $91
C44190 39BCC $C47C
C44360RTS
C444C4 A3CPY $A3CHECK FOR FREE MEMORY.
C44690 28BCC $C470A (low) & Y (high) hold new
C448D0 04BNE $C44Eend of arrays address. Test
C44AC5 A2CMP $A2and branch if above start of
C44C90 22BCC $C470string memory.
C44E48PHA
C44FA2 09LDX #$09Save A, Y on stack, also
C45198TYAcontents of $CF to $C7
C45248PHAinclusive.
C453B5 C6LDA $C6,X
C455CADEX
C45610 FABPL $C452
C45820 50 D6JSR $D650Attempt Garbage collection.
C45BA2 F7LDX #$F7
C45D68PLA
C45E95 D0STA $D0,XRestore $C7 to $CF from the
C460E8INXstack.
C46130 FABMI $C45D
C46368PLARestore A, Y from stack.
C464A8TAY
C46568PLA
C466C4 A3CPY $A3If the end of the block is
C46890 06BCC $C470still above bottom of string
C46AD0 10BNE $C47Cspace then jump to print "OUT
C46CC5 A2CMP $A2OF MEMORY ERROR"
C46EB0 0CBCS $C47C
C47060RTSNormal finish A, Y unaltered.
C471AD C0 02LDA $02C0NMI routine ends up here.
C47429 FEAND #$FERemove GRAB status and then
C4768D C0 02STA $02C0restart Basic.
C4794C A8 C4JMP $C4A8
C47CA2 4DLDX #$4DPRINT ERROR MESSAGES.
C47E20 2F C8JSR $C82FReset output to screen.
C48146 2ELSR $2EReset CTRL 0.
C48320 F0 CBJSR $CBF0Move to start of next line.
C48620 D7 CCJSR $CCD7Print "?" on screen.
C489BD A8 C2LDA $C2A8,XPrint error message on screen
C48C48PHAuntil last char which has bit
C48D29 7FAND #$7F7 set. X holds initial offset
C48F20 D9 CCJSR $CCD9into error table at start of
C492E8INXroutine.
C49368PLA
C49410 F3BPL $C489
C49620 26 C7JSR $C726Reset 6502 stack etc.
C499A9 A6LDA #$A6Print "ERROR" after the
C49BA0 C3LDY #$C3message.
C49D20 B0 CCJSR $CCB0
C4A0A4 A9LDY $A9If high byte of line number
C4A2C8INYis #FF then the computer is in
C4A3F0 03BEQ $C4A8immediate mode (not program).
C4A520 BA E0JSR $E0BAPrint "IN (line number>"
C4A84E 52 02LSR $0252RESTART BASIC
C4AB46 2ELSR $2EClear pending ELSE, CTRL O
C4AD4E F2 02LSR $02F2and LIST/EDIT flags.
C4B0A9 B2LDA #$B2
C4B2A0 C3LDY #$C3
C4B420 1A 00JSR $001APrint "Ready"
C4B720 2F C8JSR $C82FReset output to screen.
C4BA20 92 C5JSR $C592Input line from keyboard.
C4BD86 E9STX $E9Save start of line.
C4BF84 EASTY $EA
C4C120 E2 00JSR $00E2Get next non space char.
C4C4AATAXIf end of line, go back to
C4C5F0 F0BEQ $C4B7get another.
C4C7A2 FFLDX #$FFSet immediate mode.
C4C986 A9STX $A9
C4CB90 06BCC $C4D3
C4CD20 FA C5JSR $C5FATokenise the line.
C4D04C 0C C9JMP $C90CExecute the line.
C4D320 E2 CAJSR $CAE2INSERT / DELETE LINE
C4D620 FA C5JSR $C5FAGet line and tokenise it.
C4D984 26STY $26Save line length.
C4DB20 B3 C6JSR $C6B3Look for that line in memory.
C4DE90 44BCC $C524If not found skip line delete
C4E0A0 01LDY #$01DELETE LINE.
C4E2B1 CELDA ($CE),YGet MSB of end of line.
C4E485 92STA $92
C4E6A5 9CLDA $9CGet LSB of end of Basic.
C4E885 91STA $91
C4EAA5 CFLDA $CFMSB of start of line.
C4EC85 94STA $94
C4EEA5 CELDA $CEThe new end of Basic is the
C4F088DEYold one plus the start address
C4F1F1 CESBC ($CE),Yof line being deleted minus
C4F318CLCits end address. Calculation
C4F465 9CADC $9Cis done for LSB for each
C4F685 9CSTA $9Cparameter and then MSB is
C4F885 93STA $93adjusted accordingly.
C4FAA5 9DLDA $9D
C4FC69 FFADC #$FF
C4FE85 9DSTA $9D
C500E5 CFSBC $CFX holds number of pages of
C502AATAXmemory to be shifted down.
C50338SEC
C504A5 CELDA $CE
C506E5 9CSBC $9CY holds number of bytes to be
C508A8TAYmoved as well as whole pages.
C509B0 03BCS $C50E
C50BE8INX
C50CC6 94DEC $94
C50E18CLCSet up 'from' pointer for
C50F65 91ADC $91block.
C51190 03BCC $C516
C513C6 92DEC $92
C51518CLC
C516B1 91LDA ($91),YCopy rest of page down.
C51891 93STA ($93),Y
C51AC8INY
C51BD0 F9BNE $C516
C51DE6 92INC $92Advance block pointers to the
C51FE6 94INC $94next page.
C521CADEXContinue until all pages done.
C522D0 F2BNE $C516
C52420 08 C7JSR $C708INSERT LINE
C52720 5F C5JSR $C55FSet text pointer and set up
C52AA5 35LDA $35link pointers. If no line to
C52CF0 89BEQ $C4B7insert branch to immediate
C52E18CLCmode.
C52FA5 9CLDA $9CCalculate the number of bytes
C53185 C9STA $C9to be shifted and by how far
C53365 26ADC $26so that new line can be
C53585 C7STA $C7inserted.
C537A4 9DLDY $9D
C53984 CASTY $CA
C53B90 01BCC $C53E
C53DC8INY
C53E84 C8STY $C8
C54020 F4 C3JSR $C3F40pen up space for new line.
C543A5 A0LDA $A0Set end of Basic to end of
C545A4 A1LDY $A1Arrays (end of block).
C54785 9CSTA $9C
C54984 9DSTY $9D
C54BA4 26LDY $26Get number of bytes to insert.
C54D88DEY
C54EB9 31 00LDA $0031,YTransfer new line into the
C55191 CESTA ($CE),Yprogram.
C55388DEY
C55410 F8BPL $C54E
C55620 08 C7JSR $C708Set text pointer to start.
C55920 5F C5JSR $C55FSet up line link pointers.
C55C4C B7 C4JMP $C4B7Jump to immediate mode
C55FA5 9ALDA $9ASET LINE LINK POINTERS
C561A4 9BLDY $9BCopy start of Basic into a
C56385 91STA $91pointer.
C56584 92STY $92
C56718CLC
C568A0 01LDY #$01
C56AB1 91LDA ($91),YTest if at end of program.
C56CF0 1DBEQ $C58B
C56EA0 04LDY #$04
C570C8INY
C571B1 91LDA ($91),YStep through program until
C573D0 FBBNE $C570end of line is reached.
C575C8INY
C57698TYAAdd length of line to its
C57765 91ADC $91own start address to get
C579AATAXstart address of next line.
C57AA0 00LDY #$00
C57C91 91STA ($91),YSet pointer to next line (low
C57EA5 92LDA $92byte).
C58069 00ADC #$00
C582C8INYSet pointer to next line
C58391 91STA ($91),Y(high byte).
C58586 91STX $91Set pointer to start of
C58785 92STA $92following line.
C58990 DDBCC $C568Do next line.
C58B60RTSExit.
C58CCADEX"DEL" - go back one char.
C58D10 05BPL $C594
C58F20 F0 CBJSR $CBF0
C592A2 00LDX #$00INPUT LINE FROM KEYBOARD.
C59420 E8 C5JSR $C5E8X holds char count. Read key.
C597C9 01CMP #$01
C599D0 0DBNE $C5A8Branch if key not CTRL A.
C59BAC 69 02LDY $0269Load char from screen, clear
C59EB1 12LDA ($12),Ybit 7. If it is a CTRL char
C5A029 7FAND #$7Fthen replace it by a char to
C5A2C9 20CMP #$20move cursor one place to
C5A4B0 02BCS $C5A8right.
C5A6A9 09LDA #$09
C5A848PHASave character and print it to
C5A920 D9 CCJSR $CCD9the screen.
C5AC68PLA
C5ADC9 7FCMP #$7FBranch if char is DEL - go
C5AFF0 DBBEQ $C58Cback one character.
C5B1C9 0DCMP #$0DIf char is RETURN then finish
C5B3F0 30BEQ $C5E5off current input buffer.
C5B5C9 03CMP #$03If CTRL C then set flag, clear
C5B7F0 28BEQ $C5E1line and exit.
C5B9C9 18CMP #$18If CTRL X then print "Q" and
C5BBF0 0BBEQ $C5C8restart the line.
C5BDC9 20CMP #$20Ignore any other control
C5BF90 D3BCC $C594characters.
C5C195 35STA $35,XSave char in buffer.
C5C3E8INX
C5C4E0 4FCPX #$4FIf input buffer is full then
C5C690 07BCC $C5CFprint "Q" and start again
C5C8A9 5CLDA #$5Cwith a new line.
C5CA20 D9 CCJSR $CCD9
C5CDD0 C0BNE $C58F
C5CFE0 4CCPX #$4C
C5D190 C1BCC $C594
C5D38ATXAIf the line is close to max
C5D448PHAnumber of chars then give a
C5D598TYAwarning PING.
C5D648PHA
C5D720 9F FAJSR $FA9FWarning PING.
C5DA68PLA
C5DBA8TAY
C5DC68PLA
C5DDAATAX
C5DE4C 94 C5JMP $C594Go back for next character.
C5E1E6 17INC $17CTRL C pressed, set flag and
C5E3A2 00LDX #$00finish off input buffer.
C5E54C EA CBJMP $CBEA
C5E820 3B 02JSR $023BREAD KEY FROM KEYBOARD.
C5EB10 FBBPL $C5E8Wait until valid key is
C5EDC9 0FCMP #$0Fpressed (bit 7 set).
C5EFD0 08BNE $C5F9If key is CTRL O then invert
C5F148PHAflag.
C5F2A5 2ELDA $2E
C5F449 FFEOR #$FF
C5F685 2ESTA $2E
C5F868PLAReturn with char in A.
C5F960RTS
C5FAA6 E9LDX $E9TOKENISE LINE.
C5FCA0 04LDY #$04Set initial line counters and
C5FE84 2ASTY $2Aflag.
C600B5 00LDA $00,XGet character.
C602C9 20CMP #$20If space char then put it in
C604F0 41BEQ $C647line.
C60685 25STA $25Save character.
C608C9 22CMP #$22If character is " then handle
C60AF0 5FBEQ $C66Bstring in quotes.
C60C24 2ABIT $2ADon't tokenise if in middle of
C60E70 37BVS $C647a 'DATA' statement.
C610C9 3FCMP #$3FIf char is '?' then substitute
C612D0 04BNE $C618the 'PRINT' token.
C614A9 BALDA #$BA
C616D0 2FBNE $C647
C618C9 30CMP #$30If char is 0-9 or ; or : then
C61A90 04BCC $C620put it in line and go on to
C61CC9 3CCMP #$3Cnext char.
C61E90 27BCC $C647
C62084 E0STY $E0Save pointer.
C622A0 00LDY #$00
C62484 26STY $26Zero Y and reset token number.
C626A9 E9LDA #$E9Set tokenising pointer to
C62885 18STA $18point to byte before start of
C62AA9 C0LDA #$C0keyword list.
C62C85 19STA $19
C62E86 E9STX $E9Save pointer.
C630CADEX
C631E8INXAdvance input pointer.
C632E6 18INC $18Advance keyword list pointer.
C634D0 02BNE $C638
C636E6 19INC $19
C638B5 00LDA $00,X
C63A38SEC
C63BF1 18SBC ($18),YTest for char match and do
C63DF0 F2BEQ $C631next one if chars matched.
C63FC9 80CMP #$80Test for end of keyword.
C641D0 2FBNE $C672Branch if not end.
C64305 26ORA $26Create token.
C645A4 E0LDY $E0Restore pointer.
C647E8INXMove up pointers and put out
C648C8INYchar.
C64999 30 00STA $0030,Y
C64CB9 30 00LDA $0030,YIf char is zero, i.e. end of
C64FF0 39BEQ $C68Aline then exit.
C65138SEC
C652E9 3ASBC #$3AIf ":" then clear 'DATA' flag.
C654F0 04BEQ $C65A
C656C9 57CMP #$57If 'DATA' token then set flag.
C658D0 02BNE $C65C
C65A85 2ASTA $2A
C65C38SEC
C65DE9 63SBC #$63If not 'REM' then loop to get
C65FD0 9FBNE $C600next char.
C66185 25STA $25Transfer chars until same char
C663B5 00LDA $00,Xis found again i.e. another "
C665F0 E0BEQ $C647in a string. Or until end of
C667C5 25CMP $25line.
C669F0 DCBEQ $C647
C66BC8INY
C66C99 30 00STA $0030,Y
C66FE8INX
C670D0 F1BNE $C663
C672A6 E9LDX $E9Token match has failed,
C674E6 26INC $26restore X, increment token no.
C676B1 18LDA ($18),Y
C67808PHPSave char of current char.
C679E6 18INC $18
C67BD0 02BNE $C67FMove to next one.
C67DE6 19INC $19
C67F28PLP
C68010 F4BPL $C676If not end, loop to another.
C682B1 18LDA ($18),YIf more tokens left, try
C684D0 B2BNE $C638another match.
C686B5 00LDA $00,XNo tokens left so just use
C68810 BBBPL $C645char from line.
C68A99 32 00STA $0032,Y
C68DA9 34LDA #$34Point $E9/$EA at start of line
C68F85 E9STA $E9and exit.
C69160RTS
C69220 E2 CAJSR $CAE2EDIT Get integer from text.
C69520 B3 C6JSR $C6B3Look for line number in text.
C69890 16BCC $C6B0Branch if failed.
C69A6E F2 02ROR $02F2Set Edit flag.
C69D20 6C C7JSR $C76CPrint line.
C6A04E F2 02LSR $02F2Clear Edit flag.
C6A320 F0 CBJSR $CBF0New line.
C6A6A9 0BLDA #$0BSend cursor up one line.
C6A820 D9 CCJSR $CCD9
C6AB68PLA
C6AC68PLA
C6AD4C B7 C4JMP $C4B7Immediate mode.
C6B04C 23 CAJMP $CA23Print "UNDEF'D STATEMENT .."
C6B3A9 00LDA #$00LOOK FOR LINE NUMBER.
C6B585 1DSTA $1DReset line count.
C6B785 1ESTA $1E
C6B9A5 9ALDA $9AGet begin Basic.
C6BBA6 9BLDX $9B
C6BDA0 01LDY #$01
C6BF85 CESTA $CESet up pointer into line.
C6C186 CFSTX $CF
C6C3B1 CELDA ($CE),YExit if end of program (C=0)
C6C5F0 25BEQ $C6EC
C6C7C8INYMove pointer to line number
C6C8C8INY(MSB).
C6C9E6 1DINC $1DIncrement line count.
C6CBD0 02BNE $C6CF
C6CDE6 1EINC $1E
C6CFA5 34LDA $34Compare MSB of line number
C6D1D1 CECMP ($CE),Ywith one wanted.
C6D390 18BCC $C6EDBranch if beyond prog line no.
C6D5F0 03BEQ $C6DAMatch in MSB made otherwise
C6D788DEYtry next line.
C6D8D0 09BNE $C6E3
C6DAA5 33LDA $33Compare LSB of line number.
C6DC88DEY
C6DDD1 CECMP ($CE),Y
C6DF90 0CBCC $C6EDLine number too big.
C6E1F0 0ABEQ $C6EDLine number match made.
C6E388DEYGet line link bytes into A
C6E4B1 CELDA ($CE),Yand X. $CE/$CF left pointing
C6E6AATAXto start of line.
C6E788DEY
C6E8B1 CELDA ($CE),Y
C6EAB0 D1BCS $C6BD
C6EC18CLCLine not found exit.
C6ED60RTS
C6EED0 FDBNE $C6EDNEW
C6F0A9 00LDA #$00Set trace to off.
C6F24E F4 02LSR $02F4
C6F5A8TAYSet End of Basic pointer to 2
C6F691 9ASTA ($9A),Ybeyond Start Basic and clear
C6F8C8INYthe bytes inbetween - empty
C6F991 9ASTA ($9A),Yprogram.
C6FBA5 9ALDA $9A
C6FD18CLC
C6FE69 02ADC #$02
C70085 9CSTA $9C
C702A5 9BLDA $9B
C70469 00ADC #$00
C70685 9DSTA $9D
C70820 3A C7JSR $C73AReset program pointer.
C70BA9 00LDA #$00
C70DD0 2ABNE $C739CLEAR
C70FA5 A6LDA $A6Set last string allocated to
C711A4 A7LDY $A7the current value in Himem.
C71385 A2STA $A2
C71584 A3STY $A3
C717A5 9CLDA $9CSet End Variables pointer and
C719A4 9DLDY $9DEnd Arrays pointer to value
C71B85 9ESTA $9Eheld in End Basic Pointer.
C71D84 9FSTY $9FThis deletes all variables and
C71F85 A0STA $A0arrays.
C72184 A1STY $A1
C72320 52 C9JSR $C952Reset 'DATA' pointer.
C726A2 88LDX #$88
C72886 85STX $85
C72A68PLAPlace calling routine on top
C72BA8TAYof the stack.
C72C68PLA
C72DA2 FELDX #$FE
C72F9ATXS
C73048PHA
C73198TYA
C73248PHA
C733A9 00LDA #$00Reset high byte of End of
C73585 ADSTA $ADExecuted Program pointer.
C73785 2BSTA $2B
C73960RTS
C73A18CLCThis routine sets the current
C73BA5 9ALDA $9Aprogram position pointer to
C73D69 FFADC #$FFthe byte before the Start of
C73F85 E9STA $E9Basic.
C741A5 9BLDA $9B
C74369 FFADC #$FF
C74585 EASTA $EA
C74760RTS
C74808PHPLIST
C74920 E2 CAJSR $CAE2Get line number and look for
C74C20 B3 C6JSR $C6B3it in program.
C74F28PLP
C750F0 14BEQ $C766If no number, list whole prog
C75220 E8 00JSR $00E8If only one line number then
C755F0 15BEQ $C76Cjust list it.
C757C9 CDCMP #$CDIf no "-" then exit.
C759D0 92BNE $C6ED
C75B20 E2 00JSR $00E2Get next non space char.
C75EF0 06BEQ $C766
C76020 E2 CAJSR $CAE2Get line number.
C763F0 07BEQ $C76CIf end, list between the two
C76560RTSnumbers else exit.
C766A9 FFLDA #$FFSet upper line limit to #FFFF
C76885 33STA $33
C76A85 34STA $34
C76CA0 01LDY #$01
C76EB1 CELDA ($CE),YExit if end of program.
C770F0 4DBEQ $C7BF
C77220 62 C9JSR $C962Test for CTRL C.
C775C9 20CMP #$20If not space then skip next
C777D0 0EBNE $C787section.
C7794E DF 02LSR $02DFClear key pressed flag.
C77CAD DF 02LDA $02DFWait until key is pressed.
C77F10 FBBPL $C77C
C78120 62 C9JSR $C962Test for CTRL C.
C7844E DF 02LSR $02DFC1ear key pressed flag.
C787C8INY
C788B1 CELDA ($CE),YGet line number into X (LSB)
C78AAATAXand A (MSB).
C78BC8INY
C78CB1 CELDA ($CE),Y
C78EC5 34CMP $34If line number is at limit
C790D0 04BNE $C796then skip test.
C792E4 33CPX $33
C794F0 02BEQ $C798
C796B0 27BCS $C7BFExit if over line no. limit.
C79884 B8STY $B8save A and Y.
C79A48PHA
C79B20 F0 CBJSR $CBF0Newline.
C79E68PLA
C79F20 C5 E0JSR $E0C5Print line number.
C7A2A9 20LDA #$20Get space.
C7A4A4 B8LDY $B8
C7A629 7FAND #$7F
C7A820 D9 CCJSR $CCD9Print character.
C7ABC8INY
C7ACF0 11BEQ $C7BFExit if line too long.
C7AEB1 CELDA ($CE),Y
C7B0D0 1EBNE $C7D0If not end of line print char
C7B2A8TAYor token.
C7B3B1 CELDA ($CE),Y
C7B5AATAX
C7B6C8INY
C7B7B1 CELDA ($CE),Y
C7B986 CESTX $CEPoint to next line.
C7BB85 CFSTA $CF
C7BDD0 ADBNE $C76CGo round and list next line.
C7BF2C F2 02BIT $02F2If 'test return1 flag is set
C7C210 01BPL $C7C5then exit.
C7C460RTS
C7C520 F0 CBJSR $CBF0Newline.
C7C820 2F C8JSR $C82FReset output to screen.
C7CB68PLARemove address of calling
C7CC68PLAroutine and restart Basic.
C7CD4C A8 C4JMP $C4A8
C7D010 D6BPL $C7A8Print char if not a token.
C7D238SEC
C7D3E9 7FSBC #$7FGet token count into X.
C7D5AATAX
C7D684 B8STY $B8Save Y.
C7D8A0 00LDY #$00Clear Y.
C7DAA9 E9LDA #$E9Set pointer to point to start
C7DC85 18STA $181 byte before keyword list.
C7DEA9 C0LDA #$C0
C7E085 19STA $19Increment the pointer at $18/
C7E2CADEX$19 until correct keyword is
C7E3F0 0DBEQ $C7F2found.
C7E5E6 18INC $18
C7E7D0 02BNE $C7EB
C7E9E6 19INC $19
C7EBB1 18LDA ($18),Y
C7ED10 F6BPL $C7E5
C7EF4C E2 C7JMP $C7E2
C7F2C8INYGet next char.
C7F3B1 18LDA ($18),Y
C7F530 ADBMI $C7A4Another token.
C7F720 D9 CCJSR $CCD9Print char.
C7FA4C F2 C7JMP $C7F2Go round again.
C7FD20 16 C8JSR $C816LLIST
C8004E F2 02LSR $02F2Set output to printer, clear
C80320 E8 00JSR $00E8"list return" flag and perform
C8064C 48 C7JMP $C748list.
C80920 16 C8JSR $C816LPRINT
C80C20 E8 00JSR $00E8Set output to printer, perform
C80F20 AB CBJSR $CBABPRINT and set output back to
C81220 2F C8JSR $C82Fscreen.
C81560RTS
C8162C F1 02BIT $02F1SET OUTPUT TO PRINTER.
C81930 39BMI $C854Exit if printer is on.
C81BA5 30LDA $30Save Basic Screen cursor
C81D8D 59 02STA $0259position.
C820AD 58 02LDA $0258Transfer Printer cursor
C82385 30STA $30position.
C82538SEC
C8266E F1 02ROR $02F1Set printer to on.
C829AD 56 02LDA $0256Get printer line width and set
C82C4C 44 C8JMP $C844up linewidth.
C82F2C F1 02BIT $02F1SET OUTPUT TO SCREEN.
C83210 20BPL $C854
C834A5 30LDA $30Save Basic printer cursor
C8368D 58 02STA $0258position.
C839AD 59 02LDA $0259Transfer Basic screen
C83C85 30STA $30position.
C83E4E F1 02LSR $02F1Clear printer flag.
C841AD 57 02LDA $0257Transfer screen width to $31
C84485 31STA $31and set content of $32 to the
C84638SECmultiple of 8 that is less
C847E9 08SBC #$08than or equal to content of
C849B0 FBBCS $C846$31.
C84B49 FFEOR #$FF
C84DE9 06SBC #$06
C84F18CLC
C85065 31ADC $31
C85285 32STA $32
C85460RTS
C855A9 80LDA #$80FOR Set 'no integer
C85785 2BSTA $2Bvariables' flag.
C85920 1C CBJSR $CB1CCall 'LET' to assign loop var.
C85C20 C6 C3JSR $C3C6Test & branch if that loop
C85FD0 05BNE $C866doesn't already exist.
C8618ATXAWrite over the old loop which
C86269 0FADC #$0Fhas the same variable name -
C864AATAXold loop is lost.
C8659ATXS
C86668PLA
C86768PLA
C868A9 09LDA #$09Check for 18 free bytes of
C86A20 37 C4JSR $C437space on the stack.
C86D20 4E CAJSR $CA4EFind end of statement.
C87018CLC
C87198TYASave end of statement
C87265 E9ADC $E9address on the stack, low
C87448PHAbyte first.
C875A5 EALDA $EA
C87769 00ADC #$00
C87948PHA
C87AA5 A9LDA $A9Save current line number on
C87C48PHAstack.
C87DA5 A8LDA $A8
C87F48PHA
C880A9 C3LDA #$C3Search for a 'TO' token, give
C88220 67 D0JSR $D067error if not found.
C88520 06 CFJSR $CF06Check numeric type.
C88820 03 CFJSR $CF03Evaluate expression.
C88BA5 D5LDA $D5
C88D09 7FORA #$7F
C88F25 D1AND $D1
C89185 D1STA $D1
C893A9 9ELDA #$9ERound off the value in the
C895A0 C8LDY #$C8main F1oating Point
C89785 91STA $91Accumulator and then push it
C89984 92STY $92on to the stack.
C89B4C C0 CFJMP $CFC0
C89EA9 81LDA #$81Unpack the floating point
C8A0A0 DCLDY #$DCnumber at $DC81 which is
C8A220 7B DEJSR $DE7Bdefault STEP size (1).
C8A520 E8 00JSR $00E8Get next text character.
C8A8C9 CBCMP #$CBTest and branch if next char
C8AAD0 06BNE $C8B2is not a 'STEP' token.
C8AC20 E2 00JSR $00E2Get next text character.
C8AF20 03 CFJSR $CF03Evaluate expression.
C8B220 13 DFJSR $DF13Get sign of STEP into A.
C8B520 B1 CFJSR $CFB1Put FPA on stack etc.
C8B8A5 B9LDA $B9Put variable address and FOR
C8BA48PHAtoken on the stack. Structure
C8BBA5 B8LDA $B8on stack for this loop is now
C8BD48PHAcomplete.
C8BEA9 8DLDA #$8D
C8C048PHA
C8C120 62 C9JSR $C962EXECUTE NEXT LINE.
C8C4A5 E9LDA $E9Test for CTRL C
C8C6A4 EALDY $EA
C8C8F0 06BEQ $C8D0Immediate mode.
C8CA85 ACSTA $ACSave current position in
C8CC84 ADSTY $ADprogram.
C8CEA0 00LDY #$00Branch if next char in program
C8D0B1 E9LDA ($E9),Yis not a null (end of line).
C8D2D0 5BBNE $C92F
C8D44E 52 02LSR $0252Clear pending E1se flag.
C8D7A0 02LDY #$02Test if the address of next
C8D9B1 E9LDA ($E9),Yline is not a null. If it is,
C8DB18CLCthen end program.
C8DCD0 03BNE $C8E1
C8DE4C 8A C9JMP $C98A
C8E1C8INY
C8E2B1 E9LDA ($E9),YLoad the next line number to
C8E485 A8STA $A8be executed. This is now the
C8E6C8INYcurrent line number.
C8E7B1 E9LDA ($E9),Y
C8E985 A9STA $A9
C8EB98TYA
C8EC65 E9ADC $E9Update program position ptr.
C8EE85 E9STA $E9
C8F090 02BCC $C8F4
C8F2E6 EAINC $EA
C8F42C F4 02BIT $02F4
C8F710 13BPL $C90CTRACE is off.
C8F948PHA
C8FAA9 5BLDA #$5B
C8FC20 FB CCJSR $CCFBPrint '['to screen.
C8FFA5 A9LDA $A9
C901A6 A8LDX $A8Print the current line number
C90320 C5 E0JSR $E0C5on the screen.
C906A9 5DLDA #$5D
C90820 FB CCJSR $CCFBPrint ']' to screen.
C90B68PLA
C90C20 E2 00JSR $00E2Step through spaces in program.
C90F20 15 C9JSR $C915Execute statement.
C9124C C1 C8JMP $C8C1
C915F0 49BEQ $C960EXECUTE STATEMENT. Exit if end
C917E9 80SBC #$80of line. Branch if not a token
C91990 11BCC $C92C- try an assignment.
C91BC9 42CMP #$42If it is not a statement token
C91DB0 30BCS $C94Fthen "SYNTAX ERROR"
C91F0AASL AGet start address of token
C920A8TAYroutine and put it on stack.
C921B9 07 C0LDA $C007,Y
C92448PHA
C925B9 06 C0LDA $C006,Y
C92848PHA
C9294C E2 00JMP $00E2Clear spaces & enter routine.
C92C4C 1C CBJMP $CB1CJump to 'LET' routine.
C92FC9 3ACMP #$3AIf ":" then do next statement.
C931F0 C1BEQ $C8F4
C933C9 C8CMP #$C8If not 'ELSE' token then check
C935D0 0EBNE $C945for ""'
C9372C 52 02BIT $0252If no 'ELSE' pending then give
C93A10 13BPL $C94F"SYNTAX ERROR".
C93C20 B1 CAJSR $CAB1Set text ptr to end of
C93F4E 52 02LSR $0252statement & clear ELSE pending
C9424C C1 C8JMP $C8C1flag. Jump to next line.
C945C9 27CMP #$27Error if character is not a
C947D0 06BNE $C94F""'.
C94920 99 CAJSR $CA99Skip rest of line.
C94C4C C1 C8JMP $C8C1Go back to next line.
C94F4C 70 D0JMP $D070Print "SYNTAX ERROR"
C95238SECRESTORE
C953A5 9ALDA $9AThis routine sets the 'DATA'
C955E9 01SBC #$01pointer to the address 1 byte
C957A4 9BLDY $9Bbelow the Start of Basic.
C959B0 01BCS $C95C
C95B88DEY
C95C85 B0STA $B0
C95E84 B1STY $B1
C96060RTS
C96160RTS
C962AD DF 02LDA $02DFLoad next char from keyboard
C96510 F9BPL $C960and test for CTRL C.
C96729 7FAND #$7F
C969A2 08LDX #$08
C96BC9 03CMP #$03
C96DD0 F2BNE $C961Exit if not CTRL C.
C96FC9 03CMP #$03Set C to act like 'STOP'.
C971B0 01BCS $C974STOP
C97318CLCEND
C974D0 43BNE $C9B9
C976A5 E9LDA $E9
C978A4 EALDY $EA
C97AF0 0CBEQ $C988In immediate mode.
C97C85 ACSTA $ACSave current position in the
C97E84 ADSTY $ADprogram.
C980A5 A8LDA $A8Save the current line number.
C982A4 A9LDY $A9
C98485 AASTA $AA
C98684 ABSTY $AB
C98868PLARemove address of calling
C98968PLAroutine.
C98AA9 BDLDA #$BDSet up parameters for jumping
C98CA0 C3LDY #$C3back into command mode.
C98EA2 00LDX #$00
C9908E F1 02STX $02F1Clear printer flag.
C9938E DF 02STX $02DFClear input char from keyboard
C99686 2ESTX $2EClear CTRL O flag.
C99890 03BCC $C99DC=l if "BREAK AT ..." is to be
C99A4C 9D C4JMP $C49Dprinted before going back to
C99D4C A8 C4JMP $C4A8command mode.
C9A0D0 17BNE $C9B9CONT
C9A2A2 D7LDX #$D7
C9A4A4 ADLDY $ADLoad the saved current program
C9A6D0 03BNE $C9ABposition. Print "CAN'T CONT.."
C9A84C 7E C4JMP $C47Eerror if in immediate mode.
C9ABA5 ACLDA $ACPut saved program position
C9AD85 E9STA $E9pointer into current position
C9AF84 EASTY $EApointer. Do the same for the
C9B1A5 AALDA $AAline numbers.
C9B3A4 ABLDY $AB
C9B585 A8STA $A8
C9B784 A9STY $A9
C9B960RTSContinue with program.
C9BA4C 36 D3JMP $D336Print "ILLEGAL QUANTITY ERROR"
C9BDD0 03BNE $C9C2RUN If not end of statement
C9BF4C 08 C7JMP $C708then execute from start.
C9C220 0F C7JSR $C70FPerform 'CLEAR' and then
C9C54C DC C9JMP $C9DCgo to line number.
C9C8A9 03LDA #$03GOSUB
C9CA20 37 C4JSR $C437Test free space left on stack.
C9CDA5 EALDA $EAPut current position pointer
C9CF48PHAon the stack.
C9D0A5 E9LDA $E9
C9D248PHA
C9D3A5 A9LDA $A9Put current line number on the
C9D548PHAstack.
C9D6A5 A8LDA $A8
C9D848PHA
C9D9A9 9BLDA #$9BPut GOSUB token on stack.
C9DB48PHA
C9DC20 E8 00JSR $00E8Step through spaces in prog'm.
C9DF20 E5 C9JSR $C9E5Perform 'GOTO'.
C9E24C C1 C8JMP $C8C1Execute next statement/line.
C9E520 53 E8JSR $E853GOTO Get +ve integer in $33/
C9E820 51 CAJSR $CA51$34 & find offset of line end.
C9EBA5 A9LDA $A9If going to a previous line in
C9EDC5 34CMP $34program then search from start
C9EFB0 0BBCS $C9FCof program.
C9F198TYA
C9F238SEC
C9F365 E9ADC $E9Set A (LSB) and X to point to
C9F5A6 EALDX $EAnext line.
C9F790 07BCC $CA00
C9F9E8INX
C9FAB0 04BCS $CA00
C9FCA5 9ALDA $9ASet A (LSB) and X to start of
C9FEA6 9BLDX $9BBasic program.
CA0020 BD C6JSR $C6BDSearch for a line.
CA0390 1EBCC $CA23Print error if not found.
CA05A5 CELDA $CESet program position to 1
CA07E9 01SBC #$01byte before start of that
CA0985 E9STA $E9line.
CA0BA5 CFLDA $CF
CA0DE9 00SBC #$00
CA0F85 EASTA $EA
CA1160RTSExit.
CA12D0 FDBNE $CA11POP & RETURN
CA14A9 FFLDA #$FF
CA1685 B9STA $B9Set stack to position where
CA1820 C6 C3JSR $C3C6the GOSUB token is expected.
CA1B9ATXS
CA1CC9 9BCMP #$9B
CA1EF0 0BBEQ $CA2BBranch if GOSUB token found.
CA20A2 16LDX #$16Print "RETURN WITHOUT GOSUB.."
CA222C A2 5ABIT $5AA2Hides a print "UNDEF'D STAT.."
CA254C 7E C4JMP $C47EGoto print error message.
CA284C 70 D0JMP $D070Print "SYNTAX ERROR"
CA2B68PLA
CA2C68PLA
CA2DC0 0CCPY #$0C
CA2FF0 19BEQ $CA4AToken is that of 'POP'.
CA3185 A8STA $A8Returning from GOSUB so
CA3368PLArestore old line number and
CA3485 A9STA $A9program position counter.
CA3668PLA
CA3785 E9STA $E9
CA3968PLA
CA3A85 EASTA $EA
CA3C20 4E CAJSR $CA4EDATA Find end of line.
CA3F98TYA
CA4018CLCAdjust program position to
CA4165 E9ADC $E9end of the line.
CA4385 E9STA $E9
CA4590 02BCC $CA49
CA47E6 EAINC $EA
CA4960RTS
CA4A68PLACorrect stack pointer for POP
CA4B68PLAcommand.
CA4C68PLA
CA4D60RTS
CA4EA2 3ALDX #$3AFIND END OF STATEMENT
CA502C A2 00BIT $00A2FIND END OF LINE
CA5386 24STX $24
CA55A0 00LDY #$00
CA5784 25STY $25Swap match characters - colon
CA59A5 25LDA $25for end of statement, null for
CA5BA6 24LDX $24end of line.
CA5D85 24STA $24
CA5F86 25STX $25
CA61B1 E9LDA ($E9),Y
CA63F0 E4BEQ $CA49Exit if end of line.
CA65C5 25CMP $25
CA67F0 E0BEQ $CA49Exit if match made.
CA69C8INY
CA6AC9 22CMP #$22If " then swap match chars.
CA6CD0 F3BNE $CA61Loop again
CA6EF0 E9BEQ $CA59
CA7020 17 CFJSR $CF17IF Evaluate expression.
CA7320 E8 00JSR $00E8Clear spaces in text.
CA76C9 97CMP #$97
CA78F0 05BEQ $CA7FToken is that of 'GOTO'.
CA7AA9 C9LDA #$C9Search for 'THEN' token.
CA7C20 67 D0JSR $D067
CA7FA5 D0LDA $D0
CA81D0 05BNE $CA88Condition is true.
CA8320 9E CAJSR $CA9ECondition is false.
CA86F0 B7BEQ $CA3F
CA8820 E8 00JSR $00E8Get next text character.
CA8BB0 03BCS $CA90
CA8D4C E5 C9JMP $C9E5Jump to 'GOTO'
CA9008PHP
CA9138SEC
CA926E 52 02ROR $0252Set Else pending flag.
CA9528PLP
CA964C 15 C9JMP $C915Execute statement.
CA9920 51 CAJSR $CA51REM Find end of line.
CA9CF0 A1BEQ $CA3FBranch always.
CA9EA0 00LDY #$00
CAA0B1 E9LDA ($E9),YIf at end of line no 'THEN's
CAA2F0 0CBEQ $CAB0or 'ELSE's to deal with.
CAA4C8INY
CAA5C9 C9CMP #$C9Test for 'THEN' token.
CAA7F0 F0BEQ $CA99'THEN' token found.
CAA9C9 C8CMP #$C8Test for 'ELSE' token.
CAABD0 F3BNE $CAA0'ELSE' token not found.
CAAD4C 3F CAJMP $CA3FSet program pos'n to line end.
CAB060RTSExit.
CAB1A0 FFLDY #$FFSet program position pointer
CAB3C8INYto end of line.
CAB4B1 E9LDA ($E9),Y
CAB6F0 04BEQ $CABCStep through program until a
CAB8C9 3ACMP #$3Anull or colon is found. Then
CABAD0 F7BNE $CAB3jump to update program
CABC4C 3F CAJMP $CA3Fposition pointer.
CABF4C 70 D0JMP $D070Print "SYNTAX ERROR".
CAC220 C8 D8JSR $D8C8ON Get single byte expr'n
CAC548PHAwhich returns in X and $D4.
CAC6C9 9BCMP #$9B
CAC8F0 04BEQ $CACEFound a 'GOSUB' token.
CACAC9 97CMP #$97Error if character is not a
CACCD0 F1BNE $CABF'GOTO' token.
CACEC6 D4DEC $D4Step through arguments until
CAD0D0 04BNE $CAD6correct line number is found.
CAD268PLA
CAD34C 17 C9JMP $C917Execute statement.
CAD620 E2 00JSR $00E2Step through spaces in text.
CAD920 E2 CAJSR $CAE2Get 2 byte integer from text.
CADCC9 2CCMP #$2C
CADEF0 EEBEQ $CACECharacter is a comma.
CAE068PLAExit if char was not a comma.
CAE160RTS
CAE2A2 00LDX #$00GET 2 BYTE INTEGER FROM TEXT.
CAE486 33STX $33Zero result.
CAE686 34STX $34
CAE8B0 F7BCS $CAE1Exit if no more digits.
CAEAE9 2FSBC #$2FPut value of digit into $24.
CAEC85 24STA $24
CAEEA5 34LDA $34Transfer MSB to temporary
CAF085 91STA $91work byte.
CAF2C9 19CMP #$19Syntax error if MSB is over
CAF4B0 D4BCS $CACA25 - result will be too big.
CAF6A5 33LDA $33Multiply original number by
CAF80AASL A10, firstly adding itself to
CAF926 91ROL $914 times itself to give 5 times
CAFB0AASL Aitself. Then double result.
CAFC26 91ROL $91
CAFE65 33ADC $33
CB0085 33STA $33
CB02A5 91LDA $91
CB0465 34ADC $34
CB0685 34STA $34
CB0806 33ASL $33
CB0A26 34ROL $34
CB0CA5 33LDA $33
CB0E65 24ADC $24Add in next digit.
CB1085 33STA $33
CB1290 02BCC $CB16
CB14E6 34INC $34Overflow from LSB into MSB.
CB1620 E2 00JSR $00E2Get next non space character.
CB194C E8 CAJMP $CAE8Jump to do next number.
CB1C20 88 D1JSR $D188LET Get variable.
CB1F85 B8STA $B8Save location.
CB2184 B9STY $B9
CB23A9 D4LDA #$D4Give error if "=" is not next
CB2520 67 D0JSR $D067character.
CB28A5 29LDA $29Save integer variable flag.
CB2A48PHA
CB2BA5 28LDA $28Save string variable flag.
CB2D48PHA
CB2E20 17 CFJSR $CF17Evaluate expression.
CB3168PLA
CB322AROL ACheck type matches.
CB3320 09 CFJSR $CF09
CB36D0 18BNE $CB50Do string assignment.
CB3868PLA