start tok64 d64-FSDj0j 0 REM"{delete*7} ponzo*83*waterloo 1 REM"{delete*6} 10 POKE53281,15:POKE53280,12:PRINT"{black}" 11 PRINT"{clear}{space*14}{reverse on}{blue}c64 tutor-5 12 PRINT"{red}{cm a}{sh asterisk*37}{cm s}" 13 PRINT"{sh -} {reverse on}{blue}the adc's of 6510 machine language {red}{reverse off} {sh -}":ms$=" welcome! " 14 PRINT"{red}{cm z}{sh asterisk*37}{cm x}{black}" 30 GOSUB60000:GOSUB63100:GOSUB63000 31 PRINT"{clear}{down*2}the {reverse on}m{reverse off}icro{reverse on}p{reverse off}rocessor {reverse on}u{reverse off}nit (mpu)" 32 PRINT"{down}in the c64 is the {reverse on}6510{reverse off}." 33 PRINT"{down}he (she?) will obey your commands" 34 PRINT"{down}if you can speak the right language" 35 PRINT"{down}{.*3}and that's{space*2}{reverse on}machine language{reverse off}." 36 PRINT"{down}we'll learn some {reverse on}machine language" 37 PRINT"{down}in this tutorial." 38 PRINT"{down}but let's let the {reverse on}6510{reverse off} tell it{.*3}" 39 GOSUB63000 40 PRINT"{clear}{cm +*12}{reverse on}the 6510{reverse off}{cm +*14}" 45 PRINT"{down}Qwe've got a number of internal" 50 PRINT"{down}'registers' which hold 8-bit binary" 60 PRINT"{down}numbers(bytes) from $00 to $ff (in hex)." 65 PRINT"{down}Qwe call them 'a' and 'x' and 'y'." 66 PRINT"{down}(we have a few more..but wait..)" 70 PRINT"{down}Qyou may load them with numbers" 80 PRINT"{down}and perform addition,subtraction," 90 PRINT"{down}tests for zero , > , < etc.etc." 100 PRINT"{down}Qlet's go through some of these {reverse on}6510{reverse off}" 110 PRINT"{down}commands{.*3}":GOSUB63000 120 PRINT"{clear}"a$x$y$ 130 PRINTsd$"here are a few of the commands" 140 PRINT"{down}in my repertoire:" 150 GOSUB63200 160 PRINT"{reverse on}lda #$f3" 170 PRINT"{down}{reverse on}l{reverse off}oa{reverse on}d{reverse off} the {reverse on}a{reverse off}ccumulator with{space*2}the" 180 PRINT"{down}number f3 in hex..#$f3" 190 PRINT"{down}this is an {reverse on}immediate{reverse off} load." 200 ms$="{space*2}a=#$f3{space*2}":GOSUB63300:n$="{1*4}0011":GOSUB40110:GOSUB63200 210 PRINT"{reverse on}ldx #$ab":ms$="{space*2}x=#$ab{space*2}":GOSUB63300 215 n$="10101011":GOSUB40130:GOSUB63200 220 PRINT"{reverse on}ldy #$dd":ms$="{space*2}y=#$dd{space*2}":GOSUB63300:n$="110{1*3}01":GOSUB40140 230 GOSUB63200:PRINT"{reverse on}tax":PRINT"{down}{reverse on}t{reverse off}ransfer contents of {reverse on}a{reverse off} to {reverse on}x{reverse off}." 235 ms$="{space*3}x=a{space*4}":GOSUB63300:GOSUB41130:GOSUB63200 240 PRINT"{reverse on}tya":PRINT"{down}{reverse on}t{reverse off}ransfer contents of {reverse on}y{reverse off} to {reverse on}a{reverse off}.":ms$="{space*3}a=y{space*3}" 245 GOSUB63300:GOSUB41410:GOSUB63200 250 PRINT"..and there's {reverse on}txa{reverse off} and {reverse on}tay{reverse off}." 270 PRINT"{down*2}{reverse on}here are some more{reverse off}:":GOSUB63200 280 PRINT"{reverse on}inx{reverse off}":PRINT"{down}{reverse on}in{reverse off}crement the {reverse on}x{reverse off}-register by 1.":ms$="{space*2}x=x+1{space*3}" 290 GOSUB63300:n$="10101100":GOSUB40130:GOSUB63200 300 PRINT"{reverse on}dex{reverse off}":PRINT"{down}{reverse on}de{reverse off}crement the {reverse on}x{reverse off}-register by 1.":ms$="{space*2}x=x-1{space*2}" 310 GOSUB63300:n$="10101011":GOSUB40130:GOSUB63200 320 PRINT"and there's {reverse on}iny{reverse off} and {reverse on}dey{reverse off}.":GOSUB63200 330 PRINTm$:n$="10110101":pp=0:GOSUB40160:PRINTml$"$1234":pp=20 340 PRINTsd$"{reverse on}inc $1234{reverse off}":PRINT"{down}{reverse on}inc{reverse off}rements memory location $1234" 350 ms$="{space*2}m=m+1{space*2}":GOSUB63300:n$="10110110":GOSUB40160:GOSUB63200 360 PRINT"{reverse on}dec $1234{reverse off}":PRINT"{down}{reverse on}dec{reverse off}rements memory location $1234" 370 ms$="{space*3}m=m-1{space*2}":GOSUB63300:n$="10110101":GOSUB40160:GOSUB63200 380 PRINT"{reverse on}asl{reverse off}":PRINT"{down}{reverse on}a{reverse off}rithmetic {reverse on}s{reverse off}hift {reverse on}l{reverse off}eft" 390 PRINT"{down}all bits of the {reverse on}a{reverse off}-register move left." 400 PRINT"{down}a '0' comes into the 'lsb' and" 410 PRINT"{down}the 'msb' drops into the 'carry'." 420 PRINT"{down}Qlsb=least significant bit" 430 PRINT"{down}Qmsb=most significant bit" 435 ms$="{space*2}a=2*a{space*3}":GOSUB63300 440 PRINTc$:POKEc,49:n$="10{1*3}010":pp=500:GOSUB40098:GOSUB63200:pp=20 450 PRINTcc$:POKEc,32 460 PRINTsd$"{down}{reverse on}sec{reverse off}":PRINT"{down}{reverse on}se{reverse off}t the {reverse on}c{reverse off}arry bit." 470 PRINTcr$:ms$="{space*2}carry=1 ":GOSUB63300:POKEc,49:GOSUB63200 480 PRINTsd$"{down}{reverse on}clc{reverse off}":PRINT"{down}{reverse on}cl{reverse off}ear {reverse on}c{reverse off}arry bit.":ms$="{space*2}carry=0 " 490 GOSUB63300:PRINTcr$:POKEc,48:GOSUB63200:PRINTcc$ 500 PRINT"{reverse on}sta $1234{reverse off}":PRINT"{down}{reverse on}st{reverse off}ore the {reverse on}a{reverse off}-register" 510 PRINT"{down}in memory location $1234":ms$="{space*3}m=a{space*4}":GOSUB63300 520 n$="10{1*3}010":GOSUB41160:GOSUB63000 600 PRINT"{clear}that's enough. let's clear the screen.{down}" 610 PRINT"lda #$20{space*2}{arrow left}load a with #$20='space'." 620 PRINT"sta $0400 I":PRINT"sta $0401 {sh -}{arrow left}fills screen" 630 PRINT"sta $0402 {sh -}{arrow left}memory with #$20." 640 PRINT"{-*3} {-*5} .{-*16}":PRINT"sta $07ff K{arrow left}hence clear screen" 650 PRINT"{down}but we clearly need something like:":PRINT"{down}lda #$20" 660 PRINT"for x=0 to #$3ff":PRINT"sta $0400+x":PRINT"next x":GOSUB63000 670 PRINT"{clear}or{down}{left*2}{cm u*2}":PRINT"begin lda #$20 {arrow left}note statement label" 680 PRINT"{space*6}ldx #$00":PRINT"loop{space*2}sta $0400,x {arrow left}{reverse on}indexed addressing" 690 PRINT"{space*3}^{space*2}inx":PRINT"{space*3}{sh -}{space*2}?check for x=#$3ff?" 695 PRINT"{space*3}{cm z}{sh asterisk} if not,goto 'loop'" 700 PRINT"{down*2}we have {reverse on}compare{reverse off} & {reverse on}branch{reverse off} instructions!" 710 PRINT"{down}what we need above is:":PRINT"{down}{reverse on}c{reverse off}om{reverse on}p{reverse off}are {reverse on}x{reverse off} to #$3ff" 720 PRINT"{down}& {reverse on}b{reverse off}ranch if {reverse on}n{reverse off}ot {reverse on}e{reverse off}qual..to 'loop'":GOSUB63010 730 PRINT"{home}{down*2}{reverse on}begin lda #$20{space*3}{reverse off}{space*19}" 740 PRINT"{reverse on}{space*6}ldx #$00{space*3}":PRINT"{reverse on}loop{space*2}sta $0400,x" 750 PRINT"{reverse on}{space*3}^{space*2}inx{space*8}":PRINT"{reverse on}{space*3}{sh -}{space*2}cpx #$3ff{space*2}{reverse off}{space*22}" 760 PRINT"{reverse on}{space*3}{cm z}{sh asterisk} bne loop{space*3}{reverse off}{space*15}":GOSUB63200 770 PRINT"note{down}{left*4}{cm u*4}{up}:we will never {reverse on}sta{reverse off} in {reverse on}$07ff{reverse off}" 780 PRINT"{down}in the above program{.*3}so{.*3}":GOSUB63010 790 PRINT"{home}{down*6}{reverse on}{space*3}{sh -}{space*2}cpx #$400{space*2}":GOSUB63200 800 PRINT"also, we can {reverse on}cpx #$n{reverse off} only if n lies" 810 PRINT"{down}in the range $00 to $ff." 820 PRINT"{down}so we change the code to:":GOSUB63010 830 PRINT"{clear}{down*2}{reverse on}begin lda #$20{space*3}{reverse off}" 840 PRINT"{reverse on}{space*6}ldx #$00{space*3}":PRINT"{reverse on}loop{space*2}sta $0400,x" 850 PRINT"{reverse on}{space*6}sta $0500,x" 860 PRINT"{reverse on}{space*6}sta $0600,x" 870 PRINT"{reverse on}{space*6}sta $0700,x" 880 PRINT"{reverse on}{space*6}inx{space*8}":PRINT"{reverse on}{space*6}cpx #$ff{space*3}{reverse off}" 890 PRINT"{reverse on}{space*6}bne loop{space*3}{reverse off}":GOSUB63000 900 PRINTsd$"{down*4}";:FORt=1TO10:PRINTcl$:NEXT:PRINTsd$"{down*4}"; 910 PRINT"or, we can simplify this a little by" 920 PRINT"{down}counting {reverse on}down{reverse off} from x=$ff to $00":GOSUB63010 930 PRINT"{home}{down*2}{reverse on}begin lda #$20{space*3}{reverse off}" 940 PRINT"{reverse on}{space*6}ldx #$ff{space*3}":PRINT"{reverse on}loop{space*2}sta $0400,x" 950 PRINT"{reverse on}{space*6}sta $0500,x" 960 PRINT"{reverse on}{space*6}sta $0600,x" 970 PRINT"{reverse on}{space*6}sta $0700,x" 980 PRINT"{reverse on}{space*6}dex{space*8}" 990 PRINT"{reverse on}{space*6}bne loop{space*3}{reverse off}":PRINT"{space*19}":GOSUB63000 991 PRINTsd$"{down*4}";:FORt=1TO10:PRINTcl$:NEXT:PRINTsd$"{down*4}"; 995 PRINT"{down*3}how can we {reverse on}bne{reverse off} when we don't do any" 996 PRINT"{down}{reverse on}compare{reverse off}?":GOSUB63000 1000 PRINT"{clear}you see, {reverse on}bne{reverse off} really checks to see" 1010 PRINT"{down}if '0' is the result of an arithmetic" 1020 PRINT"{down}operation..including a {reverse on}compare{reverse off}." 1030 PRINT"{down}in the pair of instructions:" 1040 PRINT"{down}{reverse on}cpx #$ff":PRINT"{reverse on}bne loop":PRINT"{down}we subtract #$ff from the" 1050 PRINT"{down}value of x and {reverse on}branch{reverse off} to loop if" 1060 PRINT"{down}the result is not zero!":GOSUB63000 1070 PRINT"{clear}{reverse on}inx{space*5}":PRINT"{reverse on}bne loop" 1080 PRINT"{down}we branch to loop if the result of" 1090 PRINT"{down}incrementing x is {reverse on}not{reverse off} zero.":PRINT"{cm u*3}" 1100 PRINT"{down}{reverse on}dec $1234":PRINT"{reverse on}bne loop " 1110 PRINT"{down}here we branch to loop if" 1120 PRINT"{down}decrementing $1234 is not zero.":PRINT"{cm u*3}" 1130 PRINT"{down}{reverse on}note{reverse off}: {reverse on}cpx{reverse off}{space*2}involves a subtraction" 1140 PRINT"{down}(to check for zero result)" 1150 PRINT"{down}but it does not{down}{left*3}{cm u*3}{up} change any registers!":GOSUB63000 1160 PRINT"{clear}let's {reverse on}rvs{reverse off} the screen." 1170 PRINT"{down}this requires looking at every screen" 1180 PRINT"{down}memory location and checking the {reverse on}msb{reverse off}." 1190 PRINT"{down}if it's {reverse on}1{reverse off} then change it to {reverse on}0{reverse off}." 1200 PRINT"{down}if it's {reverse on}0{reverse off} then change it to {reverse on}1{reverse off}." 1300 PRINT"{down}(the msb determines if the character" 1310 PRINT"is in rvs-field)!" 1320 PRINT"{down}we'll:":PRINT"{down}{reverse on}lda $0400,x":PRINT"{reverse on}eor #$80{space*3}{reverse off} {arrow left*2}{?*3}":PRINT"{reverse on}sta $0400,x" 1330 PRINT"{down}{reverse on}eor{reverse off} is an {reverse on}e{reverse off}xclusive {reverse on}or{reverse off}!":GOSUB63000 1340 PRINT"{clear}if {reverse on}a{reverse off} contains {reverse on}10110101{reverse off} (after {reverse on}lda{reverse off})" 1350 PRINT"{down}then {reverse on}eor #$80{reverse off} does an exclusive-or" 1360 PRINT"{down}with {reverse on}1{0*7}{reverse off} ($80 in hex)" 1370 PRINT"{down}and gives {reverse on}00110101{reverse off}..very nice!" 1380 PRINT"{down}our program might go:" 1390 PRINT"{down}{reverse on}begin ldx #$ff{space*3}":PRINT"{reverse on}loop{space*2}lda $0400,x" 1400 PRINT"{reverse on}{space*6}eor #$80{space*3}":PRINT"{reverse on}{space*6}sta $0400,x" 1410 PRINT"{reverse on}{space*6}lda $0500,x":PRINT"{reverse on}{space*6}eor #$80{space*3}" 1420 PRINT"{reverse on}{space*6}sta $0500,x":PRINT"{reverse on}etc. etc..until..{reverse off}" 1430 PRINT"{reverse on}{space*6}sta $0700,x" 1440 PRINT"{reverse on}{space*6}dex{space*8}":PRINT"{reverse on}{space*6}bne loop{space*3}":GOSUB63000 1450 PRINT"{clear}it's clear that this will not do if" 1460 PRINT"{down}we want to go from $0400 to $0500 to" 1470 PRINT"{down}..to $0n00,instead of just to $0700." 1480 PRINT"{down}we need a loop-within-a-loop" 1490 PRINT"{down}for large n{.*3}something like:{down*3}" 1500 PRINT"{down}{space*5}m=$0400":PRINT"{space*5}x=n{space*5}{arrow left}{reverse on}n instead of 3" 1510 PRINT"lp1{space*2}y=#$ff":PRINT"lp2{space*2}lda m+y":PRINT"{space*5}eor #$80" 1511 PRINT"{space*5}sta m+y":PRINT"{space*5}y=y-1" 1512 PRINT"{space*5}if y<>0 goto lp2 ":PRINT"{space*5}m=m+$100":PRINT"{space*5}x=x-1" 1513 PRINT"{space*5}ifx<>0 goto lp1 ":GOSUB63000 1514 PRINT"{home}{down*20}"TAB(23)"{arrow left}{reverse on}won't do y=0{reverse off}!" 1515 PRINT"{down*2}"TAB(23)"{arrow left}{reverse on}won't do x=0{reverse off}!!{home}":GOSUB63000 1516 PRINT"{home}";:FORi=1TO10:PRINTcl$:NEXT:PRINT"{home}we'll {reverse on}change{reverse off} it to:" 1517 GOSUB63010:PRINT"{home}{down}{space*5}m=$0400":PRINT"{space*5}x=n" " 1518 PRINT"{reverse on}lp1{space*2}y=#$00{space*10}":PRINT"lp2{space*2}lda m+y":PRINT"{space*5}eor #$80" 1519 PRINT"{space*5}sta m+y":PRINT"{space*5}y=y-1" 1520 PRINT"{space*5}if y<>0 goto lp2 ":PRINT"{space*5}m=m+$100":PRINT"{space*5}x=x-1" 1521 PRINT"{reverse on}{space*5}ifx>=0 goto lp1 {reverse off}":GOSUB63000:PRINT"{home}{down*12}"; 1522 PRINT"we work on m+00 first,then {reverse on}y=y-1{reverse off}" 1523 PRINT"will change y=00 to y=ff(!) and we'll" 1524 PRINT"continue with m+ff then m+fe..to m+01" 1525 PRINT"and we stop the y-loop there!" 1526 PRINT"the x-loop starts with x=n and each" 1527 PRINT"{reverse on}x=x-1{reverse off} changes x to n-1,n-2,..2,1,0 {reverse on}then{reverse off}" 1528 PRINT"one more {reverse on}x=x-1{reverse off} changes x to ff(!) which" 1529 PRINT"is {reverse on}negative{reverse off}(!) and we stop the x-loop!" 1530 PRINT"{reverse on}note{reverse off}:the 6510 registers can hold{space*2}#'s" 1531 PRINT"from $00 to $ff.if we have {reverse on}00{reverse off} and" 1532 PRINT"{reverse on}decrement{reverse off},it changes to {reverse on}ff{reverse off}..and {reverse on}ff+1{reverse off}={reverse on}00{reverse off}" 1533 PRINT"finally,{reverse on}msb=1{reverse off} signifies a {reverse on}negative no.{reverse off}!";:GOSUB63000 1540 PRINT"{clear}let's try something like:" 1550 PRINT"{down}{reverse on}begin lda #$0400 {reverse off}{arrow left}??*!#$0400 too big!!" 1555 PRINT"{reverse on}{space*6}sta $b0{space*4}{reverse off}{arrow left}$b0 now has #$0400" 1560 PRINT"{reverse on}{space*6}ldx #$03{space*3}":PRINT"{reverse on}lp1{space*3}ldy #$00{space*3}" 1570 PRINT"{reverse on}lp2{space*3}lda ($b0),y{reverse off}{arrow left} indirect indexed?":PRINT"{reverse on}{space*6}eor #$80{space*3}" 1580 PRINT"{reverse on}{space*6}sta ($b0),y{reverse off}{arrow left} indirect indexed!":PRINT"{reverse on}{space*6}dey{space*8}" 1590 PRINT"{reverse on}{space*6}bne lp2{space*4}":PRINT"{reverse on}{space*6}inc $b0 by #$100{reverse off}{arrow left}??*!!how??" 1600 PRINT"{reverse on}{space*6}dex{space*8}":PRINT"{reverse on}{space*6}bpl lp1{space*4}{reverse off}{arrow left}branch on plus!!" 1610 PRINT"{down}{reverse on}lda ($b0),y{reverse off} takes the contents of" 1620 PRINT"{down}memory loc'n $b0, adds y, and this{down}{left*4}{cm u*4}" 1625 PRINT"gives the address of the byte which " 1626 PRINT"{down}gets loaded into 'a'!!":GOSUB63000 1630 PRINT"{clear}there are some new ideas..and problems!" 1635 PRINT"{down*3}but first let's agree that we'll" 1636 PRINT"{down}use $b0 to refer to the memory loc'n" 1637 PRINT"{down}and ($b0) to refer to the {reverse on}contents" 1638 PRINT"{down}of memory location $b0." 1640 PRINT"{down*3}{reverse on}let's look at addressing modes{reverse off}:":GOSUB63000 1650 PRINT"{clear}basic"TAB(20)"assembler" 1655 PRINT"{cm u*5}"TAB(20)"{cm u*9}" 1660 PRINT"{reverse on}a=5{reverse off}"TAB(20)"{reverse on}lda #$05{reverse off}" 1670 PRINT"{down}Qimmediate mode. the accumulator" 1680 PRINT"is loaded with the # 5." 1690 PRINT"{down}{reverse on}a=m(5){reverse off}"TAB(20)"{reverse on}lda $05{reverse off}" 1700 PRINT"{down}Qabsolute addressing. 'a' is" 1710 PRINT"loaded with the contents of" 1720 PRINT"memory location 5." 1730 PRINT"{down}{reverse on}a=m(5+x){reverse off}"TAB(20)"{reverse on}lda ${0*3}5,x" 1740 PRINT"{down}Qabsolute {reverse on}indexed{reverse off}. the contents" 1750 PRINT"of loc'n (5+x) are loaded into 'a'." 1760 PRINT"{down}{reverse on}a=m(m(5+x)){reverse off}"TAB(20)"{reverse on}lda (${0*3}5,x)" 1770 PRINT"{down}Qindexed {reverse on}indirect{reverse off}. the contents" 1780 PRINT"of loc'n (5+x) give the address of" 1790 PRINT"the byte to be loaded into 'a'.":GOSUB63000 1800 PRINT"{clear}then there's our friend:" 1810 PRINT"{down}{reverse on}a=m(m(5)+y){reverse off}"TAB(20)"{reverse on}lda ($05),y{reverse off}" 1820 PRINT"{down}Q{reverse on}indirect indexed{reverse off}. first, the contents" 1830 PRINT"{down}of loc'n 5 are extracted.then 'y'" 1840 PRINT"{down}is added and the result gives the" 1850 PRINT"{down}address of the byte loaded into 'a'.":GOSUB63000 1860 PRINT"{clear}Q{reverse on}indirect{reverse off} means we go to a memory loc'n" 1870 PRINT"{down}to get the address of the byte to be" 1880 PRINT"{down}loaded into the accumulator." 1890 PRINT"{down}Q{reverse on}indexed{reverse off} means we add the contents" 1900 PRINT"{down}of a {reverse on}6510{reverse off} register to an address." 1910 PRINT"{down}Qif we {reverse on}index{reverse off} then {reverse on}indirect{reverse off} it's" 1920 PRINT"{down}{reverse on}indexed indirect{reverse off}..as in {reverse on}lda ($0400,x)" 1930 PRINT"{down}Qif we {reverse on}indirect{reverse off} then {reverse on}index{reverse off} it's" 1940 PRINT"{down}{reverse on}indirect indexed{reverse off}..as in {reverse on}lda ($b0),y":GOSUB63000 1950 ms$="clear?!*$&":GOSUB63100:GOSUB63000 1960 PRINT"{clear}let's explain about {reverse on}memory{reverse off}." 1970 PRINT"{down}{reverse on}6510{reverse off} instructions are stored in memory" 1980 PRINT"as 1- or 2- or 3- hex bytes." 1990 PRINT"{down}{reverse on}inx{reverse off}={reverse on}e8{reverse off} is one byte long 2000 PRINT"{down}{reverse on}lda #$05{reverse off}={reverse on}ad 05{reverse off} is two bytes" 2010 PRINT"{down}{reverse on}lda $1234,x{reverse off}={reverse on}bd 34 12{reverse off} is three bytes." 2020 PRINT"{space*15}^^ ^^" 2030 PRINT"in general, 2-byte addresses are" 2040 PRINT"stored in memory in reverse order:" 2050 PRINT"{reverse on}lo-byte{reverse off} then {reverse on}hi-byte{reverse off}." 2060 PRINT"{down}so if you have:" 2070 PRINT"{reverse on}lda ($b0),y{reverse off}={reverse on}b1 ca{reverse off} the 6510 will" 2080 PRINT"get from $b0 the {reverse on}lo-byte{reverse off} of the" 2090 PRINT"address,and from $b1 the {reverse on}hi-byte{reverse off}!" 2100 PRINT"{down}Qbe sure to put both bytes in $b0/$b1" 2110 PRINT"before {reverse on}lda ($b0),y{reverse off}!!":GOSUB63000 2120 PRINT"{clear}let's get back to:" 2130 PRINT"{down}{reverse on}begin lda #$0400 {reverse off}{arrow left}??*!#$0400 too big!!" 2140 PRINT"{reverse on}{space*6}sta $b0{space*4}{reverse off}{arrow left}$b0 now has #$0400" 2150 PRINT"{reverse on}{space*6}ldx #$03{space*3}":PRINT"{reverse on}lp1{space*3}ldy #$00{space*3}" 2160 PRINT"{reverse on}lp2{space*3}lda ($b0),y{reverse off}{arrow left} indirect indexed?":PRINT"{reverse on}{space*6}eor #$80{space*3}" 2170 PRINT"{reverse on}{space*6}sta ($b0),y{reverse off}{arrow left} indirect indexed!":PRINT"{reverse on}{space*6}dey{space*8}" 2180 PRINT"{reverse on}{space*6}bne lp2{space*4}":PRINT"{reverse on}{space*6}inc $b0 by #$100{reverse off}{arrow left}??*!!how??" 2190 PRINT"{reverse on}{space*6}dex{space*8}":PRINT"{reverse on}{space*6}bpl lp1{space*4}{reverse off}{arrow left}branch on plus!!" 2200 PRINT"{down}we now must put $0400 into $b0/$b1" 2210 PRINT"with {reverse on}lda #$00{reverse off} {reverse on}sta $b0{reverse off} {reverse on}lda #$04{reverse off} {reverse on}sta $b1{reverse off}." 2220 PRINT"{down}also {reverse on}inc $b0 by #$100{reverse off} is changed to:" 2230 PRINT"{reverse on}inc $b1{reverse off}{.*3} we need only {reverse on}inc{reverse off} the" 2240 PRINT"hi-byte by '1'!":GOSUB63000 2250 PRINT"{clear}we'll change our program to:" 2260 PRINT"{down}{reverse on}begin lda #$00{space*3}{reverse off}":PRINT"{reverse on}{space*6}sta $b0{space*4}" 2270 PRINT"{reverse on}{space*6}lda #$04{space*3}":PRINT"{reverse on}{space*6}sta $b1{space*4}" 2280 PRINT"{reverse on}{space*6}ldx #$03{space*3}":PRINT"{reverse on}lp1{space*3}ldy #$00{space*3}" 2290 PRINT"{reverse on}lp2{space*3}lda ($b0),y{reverse off}":PRINT"{reverse on}{space*6}eor #$80{space*3}" 2300 PRINT"{reverse on}{space*6}sta ($b0),y{reverse off}":PRINT"{reverse on}{space*6}dey{space*8}" 2310 PRINT"{reverse on}{space*6}bne lp2{space*4}":PRINT"{reverse on}{space*6}inc $b1{space*4}" 2320 PRINT"{reverse on}{space*6}dex{space*8}":PRINT"{reverse on}{space*6}bpl lp1{space*4}{reverse off}":GOSUB63000 2330 PRINT"{home}{down*17}we needn't {reverse on}ldy #$00{reverse off} each" 2340 PRINT"{down}time we {reverse on}bpl lp1":PRINT"{down}y=0 already so:":GOSUB63010 2350 PRINT"{home}{down*7}{reverse on}{space*5}":PRINT"{reverse on}loop":PRINT"{down*3}{right*10}{reverse on}loop" 2355 PRINT"{down*2}{right*10}{reverse on}loop":GOSUB63000 2360 PRINT"{home}{down*16}":FORi=1TO6:PRINTcl$:NEXT 2370 PRINT"{home}{down*17}note that {reverse on}ldx #$03{reverse off} can" 2380 PRINT"{down}be changed to anything from" 2390 PRINT"{down}{reverse on}ldx #$01{reverse off} to {reverse on}ldx #$80{reverse off}.":GOSUB63000 2400 PRINT"{home}{down*16}":FORi=1TO6:PRINTcl$:NEXT 2410 PRINT"{home}{down*17}for {reverse on}ldx #$00{reverse off} we'll x-loop once anyway!" 2420 PRINT"for {reverse on}ldx #$81{reverse off},or higher,{reverse on}dex{reverse off}" 2430 PRINT"will leave 'msb'=1 in the x-register" 2440 PRINT"and x<0 will result and {reverse on}bpl{reverse off} will" 2450 PRINT"{reverse on}not{reverse off} take us back to 'loop'!":GOSUB63000 2460 PRINT"{home}{down*16}":FORi=1TO6:PRINTcl$:NEXT 2470 PRINT"{home}{down*17}note that ($b1) will not" 2480 PRINT"{reverse on}overflow{reverse off} after a number of {reverse on}inc $b1{reverse off}" 2490 PRINT"instr'ns. after all,memory only goes" 2500 PRINT"to ${f*4}, so, unless you goof" 2510 PRINT"($b1)<=ff will always be true!":GOSUB63000 2520 PRINT"{clear}note that incrementing the address" 2530 PRINT"in $b0/$b1 by $0100 only requires" 2540 PRINT"{reverse on}inc $b1{reverse off}. if you want to increment" 2550 PRINT"by ${0*3}1 you can do it this way:" 2560 PRINT"{down}{reverse on}{space*5}{-*7} " 2570 PRINT"{reverse on}{space*5}inc $b0 ":PRINT"{reverse on}{space*5}bne next":PRINT"{reverse on}{space*5}inc $b1 " 2580 PRINT"{reverse on}next {-*7} " 2590 PRINT"{down}this adds '1' to ($b0).if it doesn't" 2600 PRINT"{reverse on}overflow{reverse off} from ff to 00 we continue" 2610 PRINT"with the 'next' intruction." 2620 PRINT"{down}if it does overflow to {reverse on}00{reverse off}" 2630 PRINT"the {reverse on}bne next{reverse off} will not take us to" 2640 PRINT"'next', and we add '1' to the hi-byte" 2650 PRINT"with {reverse on}inc $b1{reverse off}.":GOSUB63000 2660 PRINT"{clear}if you want to increment by other than" 2670 PRINT"{down}${0*3}1 or $0100 ({reverse on}inc $b0{reverse off} or {reverse on}inc $b1{reverse off})" 2680 PRINT"{down}then you need to {reverse on}add{reverse off} the increment." 2685 PRINT"{down}suppose we want to add $1f:" 2690 PRINT"{down}{reverse on}lda $b0 {reverse off}{arrow left}get lo-byte" 2700 PRINT"{reverse on}adc #$1f{reverse off}{arrow left}add #$1f to lo-byte" 2710 PRINT"{reverse on}sta $b0 {reverse off}{arrow left}put it back" 2720 PRINT"{reverse on}lda $b1 {reverse off}{arrow left}get hi-byte" 2730 PRINT"{reverse on}adc #$00{reverse off}{arrow left}add zero(?!)":PRINT"{reverse on}sta $b1 {reverse off}{arrow left}put it back" 2740 PRINT"{down}you see..adding #$1f might just cause" 2750 PRINT"the contents of $b0 to {reverse on}overflow{reverse off} which" 2760 PRINT"causes {reverse on}carry{reverse off}=1. so we add the carry" 2770 PRINT"to ($b1) with {reverse on}lda $b1{reverse off} & {reverse on}adc #$00" 2780 PRINT"{down}note{down}{left*4}{cm u*4}{up}:{reverse on}adc{reverse off} means {reverse on}ad{reverse off}d with {reverse on}c{reverse off}arry.":GOSUB63000 2790 PRINT"{home}{down*14}":FORi=1TO8:PRINTcl$:NEXT:PRINT"{home}{down*14}" 2800 PRINT"of course the {reverse on}carry{reverse off} may be {reverse on}1{reverse off} when" 2810 PRINT"{down}the above piece of code starts, so" 2820 PRINT"{down}we must always{down}{left*6}{cm u*6}{up} {reverse on}clc{reverse off} before an {reverse on}adc{reverse off}!":GOSUB63010 2830 PRINT"{home}{down*7}{reverse on}clc{space*5}":GOSUB63000 2840 PRINT"{clear}if you want to {reverse on}subtract{reverse off} {reverse on}#$1f{reverse off} you:" 2850 PRINT"{down*2}{reverse on}lda $b0 ":PRINT"{reverse on}sbc #$1f{reverse off}{arrow left}subtract $1f":PRINT"{reverse on}sta $b0 " 2860 PRINT"{reverse on}lda $b1 ":PRINT"{reverse on}sbc #$00{reverse off}{arrow left}subtract $00!!":PRINT"{reverse on}sta $b1 " 2870 PRINT"{down}note{down}{left*4}{cm u*4}{up}:{reverse on}sbc{reverse off} means {reverse on}s{reverse off}u{reverse on}b{reverse off}tract with {reverse on}c{reverse off}arry." 2880 PRINT"{down}however, with {reverse on}sbc{reverse off} you must have" 2890 PRINT"{down}carry=1 to start with!!":ms$="*?ugh!*?!!":GOSUB63000:GOSUB63100 2900 GOSUB63010:PRINT"{home}{down*2}{reverse on}sec{space*5}":GOSUB63000 3000 PRINT"{clear}":ms$="{reverse on}au revoir!{reverse off}":GOSUB63100:PRINT"{home}{down*2}":END 9999 GOTO9999 40098 POKEa(0),32:FORtt=1TOpp:NEXT:FORi=0TO6:POKEa(i+1),32 40099 POKEa(i),VAL(MID$(n$,i+1,1))+48:FORtt=1TOpp:NEXT:NEXT:POKEa(7),48:RETURN 40110 FORi=0TO7:POKEa(i),160:FORtt=1TOpp:NEXT 40111 POKEa(i),VAL(MID$(n$,i+1,1))+48:NEXT:RETURN 40120 FORi=0TO7:POKEp(i),160:FORtt=1TOpp:NEXT 40121 POKEp(i),VAL(MID$(n$,i+1,1))+48:NEXT:RETURN 40130 FORi=0TO7:POKEx(i),160:FORtt=1TOpp:NEXT 40131 POKEx(i),VAL(MID$(n$,i+1,1))+48:NEXT:RETURN 40140 FORi=0TO7:POKEy(i),160:FORtt=1TOpp:NEXT 40141 POKEy(i),VAL(MID$(n$,i+1,1))+48:NEXT:RETURN 40160 FORi=0TO7:POKEm(i),160:FORtt=1TOpp:NEXT 40161 POKEm(i),VAL(MID$(n$,i+1,1))+48:NEXT:RETURN 41120 FORi=0TO7:POKEp(i),160:FORtt=1TOpp:NEXT 41121 POKEp(i),PEEK(a(i)):NEXT:RETURN 41130 FORi=0TO7:POKEx(i),160:FORtt=1TOpp:NEXT 41131 POKEx(i),PEEK(a(i)):NEXT:RETURN 41140 FORi=0TO7:POKEy(i),160:FORtt=1TOpp:NEXT 41141 POKEy(i),PEEK(a(i)):NEXT:RETURN 41160 FORi=0TO7:POKEm(i),160:FORtt=1TOpp:NEXT 41161 POKEm(i),PEEK(a(i)):NEXT:RETURN 41340 FORi=0TO7:POKEa(i),160:FORtt=1TOpp:NEXT 41341 POKEa(i),PEEK(x(i)):NEXT:RETURN 41360 FORi=0TO7:POKEm(i),160:FORtt=1TOpp:NEXT 41361 POKEm(i),PEEK(x(i)):NEXT:RETURN 41410 FORi=0TO7:POKEa(i),160:FORtt=1TOpp:NEXT 41411 POKEa(i),PEEK(y(i)):NEXT:RETURN 41460 FORi=0TO7:POKEm(i),160:FORtt=1TOpp:NEXT 41461 POKEm(i),PEEK(y(i)):NEXT:RETURN 60000 r$="{cm a}{sh asterisk}{cm r}{sh asterisk}{cm r}{sh asterisk}{cm r}{sh asterisk}{cm r}{sh asterisk}{cm r}{sh asterisk}{cm r}{sh asterisk}{cm r}{sh asterisk}{cm s}{down}{left*17}{sh -}{sh space}{sh -}{sh space}{sh -}{sh space}{sh -}{sh space}{sh -}{sh space}{sh -}{sh space}{sh -}{sh space}{sh -}{sh space}{sh -}{down}" 60001 r$=r$+"{left*17}{cm z}{sh asterisk}{cm e}{sh asterisk}{cm e}{sh asterisk}{cm e}{sh asterisk}{cm e}{sh asterisk}{cm e}{sh asterisk}{cm e}{sh asterisk}{cm e}{sh asterisk}{cm x}" 60002 a$="{home}{down} {reverse on}a{reverse off}{up}"+r$:p$="{home}{down}{right*20}{reverse on}p{reverse off}{up}"+r$ 60003 x$="{home}{down*4} {reverse on}x{reverse off}{up}"+r$:y$="{home}{down*4}{right*21}{reverse on}y{reverse off}{up}"+r$ 60004 m$="{home}{down*7}{right*21}{reverse on}m{reverse off}{up}"+r$ 60005 cr$="{home}{down*6}{cm a}{sh asterisk}{cm s}{down}{left*3}{sh -}{right}{sh -}{down}{left*3}{cm z}{sh asterisk}{cm x}" 60006 cc$="{home}{down} {reverse on}a{reverse off}{sh -}{down}{left*3} {down}{left} {down}{left} {down}{left} {down}{left}{space*3}{down}{left*3}{space*3}{down}{left*3}{space*3}{up}{space*12}" 60007 wd=40:crt=1024:PRINTCHR$(142) 60008 FORi=0TO7:a(i)=crt+wd+3+2*i:p(i)=a(i)+20:x(i)=a(i)+3*wd:y(i)=x(i)+20 60009 m(i)=y(i)+3*wd:NEXT:c=crt+7*wd+1 60010 sd$="{home}{down*9}":cl$="":FORi=1TOwd-2:cl$=cl$+" ":NEXT 60011 bt$="{home}":FORi=1TO24:bt$=bt$+"{down}":NEXT 60012 c$=cr$+"{home}{down}{cm a}{sh asterisk}{cm w}{down}{left*3}{sh -}{down}{left}{sh -}{down}{left}{sh -}{down}{left}{sh -}{down}{left}{cm q}{down}{right*4}{arrow left}carry bit" 60019 ml$="{home}{down*9}{right*27}" 60020 pp=20 60051 bt$="{home}":FORi=1TO24:bt$=bt$+"{down}":NEXT 60052 pt$="{red}{cm a}{sh asterisk*10}{cm s}{down}{left*12}{sh -}{right*10}{sh -}{down}{left*12}{cm z}{cm r}{sh asterisk*8}{cm r}{cm x}" 60053 pt$=pt$+"{down}{left*13}N{cm t*12}M{down}{left*14}{cm g}{=*12}{cm m}" 60054 pt$=pt$+"{down}{left*14}PO{cm t*10}PO{up*4}{left*12}" 60055 pt$=bt$+"{up*6}{right*26}"+pt$+"{black}" 60056 ml$="{home}{down*9}{right*27}" 60057 wd=40:crt=1024:PRINTCHR$(142) 60058 w2=wd/2:w3=wd-1:w1$=MID$(STR$(wd),2): 60059 w2$=MID$(STR$(w2),2):w3$=MID$(STR$(w3),2) 60100 RETURN 63000 PRINTbt$cl$; 63001 PRINTbt$"{reverse on}return{reverse off} to continue"; 63002 GETz$:IFz$<>""THEN63002 63003 GETz$:IFz$=""THEN63003 63004 RETURN 63010 PRINTbt$cl$; 63011 PRINTbt$"{cm +*8}{reverse on}return to see it happen{reverse off}{cm +*8}"; 63012 GETz$:IFz$<>""THEN63012 63013 GETz$:IFz$=""THEN63013 63014 RETURN 63100 FORt=1TO5:PRINTpt$ms$; 63101 PRINTpt$"{space*10}"; 63102 PRINTpt$ms$;:NEXT 63103 RETURN 63200 GOSUB63000 63201 PRINTsd$;:FORt=1TO10:PRINTcl$:NEXT:PRINTsd$;:RETURN 63300 GOSUB63100:GOSUB63010:RETURN 63999 GOSUB60000:PRINT"{clear}":GOTO1630 stop tok64 (bastext 1.0)