start bastext 1025 start tok64 d64-caSLHI 1 RUN00010 10 GOSUB63100:sn$="00100" 100 POKE53281,15:POKE53280,12:PRINT"{black}":PRINT"{clear}{space*11}{reverse on}{blue}micros'n'chips-3" 101 PRINT"{red}{cm a}{sh asterisk*37}{cm s}":GOSUB63100 102 PRINT"{sh -} {reverse on}{blue}{space*9}outside the micro{space*9}{red}{reverse off} {sh -}":ms$="ponzotutor" 103 PRINT"{red}{cm z}{sh asterisk*37}{cm x}{black}":GOSUB63200 104 ms$=" welcome! ":GOSUB63200:POKE53280,15 105 PRINT"{home}{down*10}Qnote{down}{left*4}{cm u*4}{up}:hit the @-key at any" 106 PRINT"{down}{space*6}time to return to an":PRINT"{down}{space*6}earlier section{.*3}":GOSUB50000 1000 GOSUB63100:REM micros-1 1001 sn$="01{0*3}" 1010 t$="the expansion port":GOSUB63000 1020 PRINT"{down}Qrecall the magic decoder which" 1030 PRINT"{down} provides {reverse on}chip enable{reverse off}{space*2}signals" 1040 PRINT"{down} for enabling the basic roms and" 1050 PRINT"{down} the character rom and the kernal" 1060 PRINT"{down} rom and{down}{left*3}{cm u*3}{up} the input/output" 1070 PRINT"{down} stuff (two 'inside' chips called" 1080 PRINT"{down} cia #1 and cia #2..each a 6526.." 1090 PRINT"{down} and two {reverse on}enable{reverse off} signals which go" 1100 PRINT"{down} out the {reverse on}expansion port{reverse off} when the" 1110 PRINT"{down} address bus has an address in the" 1120 PRINT"{down} ranges {reverse on}$de00-$deff{reverse off} and {reverse on}$df00-$d{f*3}{reverse off}).":GOSUB50000 1130 PRINT"{clear}{down}Qthe two {reverse on}enable{reverse off} signals available" 1140 PRINT"{down} at the expansion port(=cartridge port)" 1150 PRINT"{down} are just in case you want to add some" 1160 PRINT"{down} external device which is to respond to" 1170 PRINT"{down} one of these address ranges." 1180 PRINT"{down} (the c64 has nothing 'inside' which" 1190 PRINT"{down} responds to these addresses..except" 1200 PRINT"{down} the everpresent ram-at-the-bottom" 1210 PRINT"{down} which is normally disabled.)":GOSUB50000 1215 PRINT"{clear}{down*2}Qthere are a variety of 'outside'" 1216 PRINT"{down} devices we want to accommodate." 1217 PRINT"{down}Qin addition to the 2 'enables' noted" 1218 PRINT"{down} above we want something special" 1219 PRINT"{down} for {reverse on}plug-in cartridges{reverse off}!":ms$="certainly!":GOSUB63200:GOSUB50000 1220 PRINT"{clear}{down*2}Qhow do we want the {reverse on}cartridge{reverse off}" 1230 PRINT"{down} to work?" 1260 PRINT"{down}Qwe want to slip the 'cartridge' into" 1270 PRINT"{down} the expansion port, turn on the micro" 1280 PRINT"{down} and have the program immediately in" 1290 PRINT"{down} control and running.":ms$="looks good":GOSUB63200:GOSUB50000 1300 PRINT"{clear}{down*3}Qsince the c64 micro already has about" 1310 PRINT"{down} as much memory as it can use, we need" 1320 PRINT"{down} to be able to replace some 'internal'" 1330 PRINT"{down} memory with the 'external' memory." 1340 PRINT"{down}Qthe 'external' cartridge will tell us" 1350 PRINT"{down} which memory it wants and we will" 1360 PRINT"{down} swap it into the address space.":GOSUB50000 1370 PRINT"{clear}{down*3}Qwe (the c64) ask for two signals from" 1380 PRINT"{down} the cartridge ({reverse on}exrom{reverse off} and {reverse on}game{reverse off})" 1390 PRINT"{down} and depending upon the 1/0 values of" 1400 PRINT"{down} these signals we supply an {reverse on}enable{reverse off}" 1410 PRINT"{down} for a certain address range and at" 1420 PRINT"{down} the same time disable the competing " 1430 PRINT"{down} 'internal' memory." 1440 PRINT"{down}Q{reverse on}game{reverse off} is (usually) for a game" 1450 PRINT"{down} cartridge and {reverse on}exrom{reverse off} is for" 1460 PRINT"{down} 'other' {reverse on}ex{reverse off}ternal {reverse on}rom{reverse off}.":GOSUB50000 1470 PRINT"{clear}{down*2}Qwhat 'internal' memory can we afford" 1480 PRINT"{down} to swap out{down}{left*8}{cm u*8}{up} when the" 1490 PRINT"{down} 'external' memory is added?" 1500 PRINT"{down}Q$8{0*3}-$9{f*3} is good. (that's free ram" 1510 PRINT"{down} which lives just under the basic roms" 1520 PRINT"{down} at $a{0*3}-$b{f*3})." 1530 PRINT"{down}Q$a{0*3}-$b{f*3} is good. (the cartridge" 1540 PRINT"{down} won't usually need {reverse on}basic{reverse off})." 1550 PRINT"{down}Q$e{0*3}-${f*4} is good. (the cartridge" 1560 PRINT"{down} may not need the {reverse on}kernal{reverse off} smarts).":GOSUB50000 2000 GOSUB63100:REM micros-2 2001 sn$="02{0*3}" 2010 t$="cartridge rom swaps":GOSUB63000 2020 PRINT"{down*2}Qthe two signals {reverse on}game{reverse off} and {reverse on}exrom{reverse off}" 2025 PRINT"{down} come from the cartridge and can have" 2030 PRINT"{down} one of {reverse on}4{reverse off} 1/0 configurations:" 2040 PRINT"{down}{space*3}{reverse on}game{reverse off}{space*3}{reverse on}exrom{reverse off}" 2041 PRINT"{down}{space*4}1{space*7}1" 2042 PRINT"{down}{space*4}1{space*7}0" 2043 PRINT"{down}{space*4}0{space*7}1" 2044 PRINT"{down}{space*4}0{space*7}0" 2050 PRINT"{down}Qwe (the c64) will":PRINT"{down}respond to each like so:" 2060 ms$="go!go!go!":GOSUB63200:GOSUB50000:PRINT"{clear}" 2070 PRINT"{reverse on}game{reverse off}{sh -}{reverse on}xrom{reverse off}{sh -}{reverse on}8{0*3}-9{f*3}{reverse off}{sh -}{reverse on}a{0*3}-b{f*3}{reverse off}{sh -}{reverse on}e{0*3}-{f*4}" 2080 PRINT"{sh asterisk*4}{sh +}{sh asterisk*4}{sh +}{sh asterisk*9}{sh +}{sh asterisk*9}{sh +}{sh asterisk*7}" 2090 b$="{space*2}1 {sh -}{space*2}1 {sh -} c64 ram {sh -}{space*2}basic{space*2}{sh -} kernal " 2100 c$="{space*2}1 {sh -}{space*2}0 {sh -}{reverse on}cartridge{reverse off}{sh -}{space*9}{sh -}{space*8}" 2110 d$="{space*2}0 {sh -}{space*2}1 {sh -}{reverse on}cartridge{reverse off}{sh -}{space*9}{sh -}{reverse on}cartridge{reverse off}" 2120 e$="{space*2}0 {sh -}{space*2}0 {sh -}{reverse on}cartridge{reverse off}{sh -}{reverse on}cartridge{reverse off}{sh -}{space*8}" 2130 PRINT"{home}{down*3}"b$:GOSUB50000:p$="{home}{down*8}" 2140 PRINT"{home}{down*3}{reverse on}"b$:PRINTp$"Qa normal c64 with all 'inside' memory." 2145 GOSUB50000:PRINT"{home}{down*3}"b$ 2150 PRINT"{home}{down*4}{reverse on}"c$:PRINTp$"{down*2}Qout goes ram at $8{0*3},in comes rom." 2155 GOSUB50000:PRINT"{home}{down*4}"c$ 2160 PRINT"{home}{down*5}{reverse on}"d$:PRINTp$"{down*4}Qthere goes the kernal too!" 2165 GOSUB50000:PRINT"{home}{down*5}"d$ 2170 PRINT"{home}{down*6}{reverse on}"e$:PRINTp$"{down*6}Qbasic gone..kernal back" 2175 GOSUB50000:PRINT"{home}{down*6}"e$ 2180 PRINTp$"{down*8} (for {reverse on}game{reverse off}={reverse on}exrom{reverse off}=0 there is 16k of" 2190 PRINT"{down} contiguous address space available" 2200 PRINT"{down} for the cartridge rom!!)":GOSUB50000 2210 PRINT"{clear}{down*2}Qnow we must supply a {reverse on}chip enable" 2220 PRINT"{down} for the cartridge{space*2}roms." 2230 PRINT"{down}Qthere are two of them depending upon" 2240 PRINT"{down} whether the 'external' memory is" 2250 PRINT"{down} is in a 'lo' address range" 2251 PRINT"{down} ($8{0*3}-$9{f*3}) or a 'hi' range" 2252 PRINT"{down} ($a{0*3}-$b{f*3}) or ($e{0*3}-${f*4})." 2260 PRINT"{down}Qthese two {reverse on}enable{reverse off} signals are:" 2270 PRINT"{down} {reverse on}roml{reverse off} and {reverse on}romh{reverse off}.":ms$="{space*2}romlo":GOSUB63200:GOSUB50000 2280 ms$="{space*2}romhi":GOSUB63300 3000 GOSUB63100:REM micros-3 3001 sn$="03{0*3}":t$="review":GOSUB63000:FORt=1TO1000:NEXT 3005 PRINT"{clear}":ms$="remember?":GOSUB63300 3010 PRINT"{home}{down}{space*6}{cm a}{sh asterisk*4}{cm s}":FORi=1TO10:PRINT"{space*5}{sh asterisk}{cm w}{space*4}{cm q}{sh asterisk}":NEXT 3015 PRINT"{space*3}{sh space}{space*2}{cm z}{sh asterisk*4}{cm x}":r$="{sh asterisk*2}":s$="{sh asterisk}" 3020 PRINT"{home}{down*2}{reverse on}a15{reverse off}"r$:PRINT"{reverse on}a14{reverse off}"r$:PRINT"{reverse on}a13{reverse off}"r$:PRINT"{reverse on}a12{reverse off}"r$ 3030 PRINT"r/w"r$:PRINT"{reverse on}bit0{reverse off}"s$:PRINT"{reverse on}bit1{reverse off}"s$:PRINT"{reverse on}bit2{reverse off}"s$ 3040 PRINT"{space*2}{cm a}{sh asterisk*3}{right*6}{sh asterisk*4}{cm s}" 3050 PRINT"{space*2}{sh -} {cm a}{sh asterisk}{right*6}{sh asterisk*2}{cm s} {sh -}" 3060 PRINT"{home}{down*6}{right*11}{sh -} {down}{left*2}{sh -} {down}{left*2}{sh -} {down}{left*2}{sh -} ":PRINT"{home}{down}" 3070 PRINTTAB(13)"to basic roms($a{0*3}-$b{f*3})":GOSUB50000 3080 PRINTTAB(13)"to char rom{space*2}($d{0*3}-$d{f*3})":GOSUB50000 3090 PRINTTAB(13)"to kernal rom($e{0*3}-${f*4})":GOSUB50000 3100 PRINTTAB(13)"to input/output enable=ce1{reverse on}!{reverse off}":GOSUB50000 3110 ms$="see {reverse on}ce1{reverse off}!":GOSUB63200:GOSUB50000 3120 PRINT"{home}{down*13} {reverse on}exrom{up}{left*4}^":ms$="{reverse on}{space*3}who?{space*2}":GOSUB63200:GOSUB50000 3130 PRINT"{home}{down*13}{space*3}{reverse on}game{up}{left*3}^":ms$="{reverse on}{space*3}what! ":GOSUB63200:GOSUB50000 3140 PRINT"{home}{down*13}{space*13}{reverse on}roml{up}{left*3}v{down*2}{left*3}$8{0*3}-" 3145 ms$="{reverse on}{space*3}{?*5} ":GOSUB63200:GOSUB50000 3150 PRINT"{home}{down*13}{space*15}{reverse on}romh{up}{left*3}v{down*2}{left*5}$a{0*3}- or $e{0*3}-" 3160 ms$="{reverse on} i see!! ":GOSUB63200:GOSUB50000 3170 PRINT"{clear}{down*5}Qnow{.*3}to turn over control to the" 3180 PRINT"{down} cartridge rom as soon as the micro" 3190 PRINT"{down} is turned on?":ms$="how? how?":GOSUB63200:GOSUB50000 3200 PRINT"{clear}{down*2}Qwhen the power is first turned on" 3210 PRINT"{down} a {reverse on}reset{reverse off} signal travels around the" 3220 PRINT"{down} circuitry. this signal goes to a" 3230 PRINT"{down} 'reset pin' on many of the chips which" 3240 PRINT"{down} live in the micro and serves to bring" 3250 PRINT"{down} up the chip in a known{down}{left*5}{cm u*5}{up} state" 3260 PRINT"{down} (with internal registers set to zero{down}{left*4}{cm u*4}{up}.":GOSUB50000 3270 PRINT"{clear}{down*2}Qthis {reverse on}reset{reverse off} signal also goes to the" 3280 PRINT"{down} {reverse on}6510{reverse off}! the microprocessor responds" 3290 PRINT"{down} to {reverse on}reset{reverse off} by going to a specific" 3300 PRINT"{down} memory location and extracting 2 bytes." 3310 PRINT"{down}Qthese two bytes give the {reverse on}6510{reverse off} an" 3320 PRINT"{down} address{.*3}and the {reverse on}6510{reverse off} goes to this" 3330 PRINT"{down} address for its instructions." 3340 PRINT"{down}Qwhere does the {reverse on}6510{reverse off} get this 2-byte" 3350 PRINT"{down} address?":ms$="{space*2}where?":GOSUB63200:GOSUB50000 3360 PRINT"{clear}{down*2}Q${f*3}c and ${f*3}d contain this magic" 3370 PRINT"{down} 'startup' address." 3380 PRINT"{down}Qsince ${f*3}c=15*4096+15*256+15*16+12" 3390 PRINT"{space*12}=65532" 3400 PRINT"{down} then the {reverse on}6510{reverse off} goes to location" 3410 PRINT"{down} peek(65532)+256*peek(65533)=64738" 3420 PRINT"{down} immediately after 'power-up'." 3430 PRINT"{down}Qand what do you think":PRINT"{down} the instructions" 3440 PRINT"{down} at 64738(decimal) say?":ms$="{space*2}what?":GOSUB63200 3450 GOSUB50000:t$="startup instructions for 6510":GOSUB63000 3455 PRINT"{down*2}1) extract 5 bytes from memory at" 3460 PRINT"{space*3}$8004-$8008.":PRINT"{down}2) if these 5 bytes contain" 3470 PRINT"{space*3}{reverse on}c3 c2 cd 38 30{reverse off} (in hex)" 3480 PRINT"{space*3}then extract an address from" 3490 PRINT"{space*3}$8{0*3}/$8001" 3495 PRINT"{down}3) goto this address and start" 3500 PRINT"{space*3}obeying the instructions there!" 3510 PRINT"{down}4) if the 5 bytes {reverse on}c3 c2 cd 38 30{reverse off} are" 3520 PRINT"{space*3}not{down}{left*3}{cm u*3}{up} present then continue" 3530 PRINT"{space*3}with the 'normal' start-up routine." 3540 ms$="c3c2cd3830":GOSUB63200:GOSUB50000:ms$="{space*4}says..":GOSUB63200 3550 ms$="{space*2}{reverse on}cbm80{reverse off}!":GOSUB63200:GOSUB50000 3560 t$="duties of a game cartridge":GOSUB63000dy. 3570 PRINT"{down}1) provide {reverse on}game{reverse off} and {reverse on}exrom{reverse off} signals" 3580 PRINT"{space*3}so $8{0*3}-$9{f*3} ram is disabled" 3590 PRINT"{space*3}(and cartridge rom is enabled via" 3600 PRINT"{space*3}{reverse on}roml{reverse off} in this address range)." 3610 PRINT"{down}2) have the 5 identifier bytes at" 3620 PRINT"{space*3}$8004-$8008." 3630 PRINT"{down}3) have the starting address of the" 3640 PRINT"{space*3}cartridge program at $8{0*3}-8001.":GOSUB50000 3650 PRINT"{down}{.*3}plus a few other duties{.*3}" 3660 PRINT"{space*3}which needn't concern us !":GOSUB50000 3670 ms$=" oh yeah!":GOSUB63300 3680 PRINT"{clear}{down*6}Q{reverse on}you{reverse off} can send the {reverse on}6510{reverse off} to the 'reset'" 3690 PRINT"{down} routine by saying:" 3700 PRINT"{down} {reverse on}sys64738{reverse off}":ms$="{.*3}later":GOSUB50000:GOSUB63300 4000 GOSUB63100:REM micros-4 4001 sn$="04{0*3}" 4010 t$="other outside stuff":GOSUB63000 4020 PRINT"{down*2}Qwe may want the micro to move some" 4030 PRINT"{down} {reverse on}sprite{reverse off} or other graphic gadget" 4040 PRINT"{down} to a specific point on the screen." 4050 PRINT"{down}Qwe could do this with a joystick{down}{left*8}{cm u*8}" 4060 PRINT" which contains 5 switches (either open" 4070 PRINT"{down} or closed depending upon whether you" 4080 PRINT"{down} push the stick up,down,left,right or" 4090 PRINT"{down} press the fire button.":GOSUB50000 4100 PRINT"{clear}{down*5}Qbut this requires the program to move" 4110 PRINT"{down} the graphic gadget in the appropriate" 4120 PRINT"{down} direction until you {reverse on}stop{reverse off} pushing the" 4130 PRINT"{down} the stick.":GOSUB50000 4140 PRINT"{clear}{down*2}Qa better way may be as follows:" 4150 PRINT"{down}Qwe plug a {reverse on}paddle{reverse off} into the 'port'" 4160 PRINT"{down} at the side of the micro." 4170 PRINT"{down}Qthe {reverse on}paddle{reverse off} has two knobs which" 4180 PRINT"{down} can rotate." 4190 PRINT"{down}Qone knob will move the graphic gadget" 4200 PRINT"{down} left-right and the other knob moves" 4210 PRINT"{down} it up-down." 4220 PRINT"{down}Qeach position of the knobs identifies" 4230 PRINT"{down} a specific position on the screen!" 4240 PRINT"{space*3}{cm u*17}":GOSUB50000 4250 PRINT"{clear}{down*4}Q{.*3}now comes some math and" 4260 PRINT"{down}{space*5}circuit stuff.." 4270 PRINT"{down*2}Qwant to skip it?":INPUT"{down*3}{space*4}no{down}{left*3}{cm u*3}{up}{left*4}";a$ 4280 IFLEFT$(a$,1)="y"THEN4800 4285 ms$="go!go!go!":GOSUB63300 4290 t$="paddles 'n' stuff":GOSUB63000 4300 PRINT"{down}{space*2}{cm a}{sh asterisk*5}to +5 volts from micro 4301 PRINT"{space*2}{sh -} 4302 PRINT"{space*2}M 4303 PRINT"{space*2}N 4304 PRINT"{space*2}M 4305 PRINT"{space*2}N{arrow left}{cm s} 4306 PRINT"{space*2}M {sh -} 4307 PRINT"{space*2}{sh -} {sh -} 4308 PRINT"{space*2}Q{sh asterisk}{cm x} 4309 PRINT"{space*2}{sh -} 4310 PRINT"{space*2}Q{sh asterisk*5}to sound chip in micro 4311 PRINT"{space*2}{sh -} 4312 PRINT" {cm u*3} 4313 PRINT" {cm d*3} 4314 PRINT"{space*2}{sh -} 4315 PRINT"{space*2}{cm z}{sh asterisk*5}to ground of micro":GOSUB50000 4320 FORi=1TO5:PRINT"{home}{down*5}{space*2}{reverse on}M{down}{left}N{down}{left}M{down}{left}N{down}{left}M":FORt=1TO100:NEXT 4330 PRINT"{home}{down*5}{space*2}M{down}{left}N{down}{left}M{down}{left}N{down}{left}M":FORt=1TO100:NEXT:NEXT 4340 p$="{home}{down*22}":PRINTp$"Qthis is a variable resistor" 4350 PRINT" controlled by a paddle.":GOSUB50000 4351 z$="{home}{down*5}{right*3}":b$(0)=z$+"{arrow left}{cm s}{down}{left*2} {sh -}{down}{left*2} {sh -}{down}{left*2} {sh -}{down}{left*2} {sh -}" 4352 b$(1)=z$+"{space*2}{down}{left*2}{arrow left}{cm s}{down}{left*2} {sh -}{down}{left*2} {sh -}{down}{left*2} {sh -}" 4353 b$(2)=z$+"{space*2}{down}{left*2}{space*2}{down}{left*2}{arrow left}{cm s}{down}{left*2} {sh -}{down}{left*2} {sh -}" 4354 b$(3)=z$+"{space*2}{down}{left*2}{space*2}{down}{left*2}{space*2}{down}{left*2}{arrow left}{cm s}{down}{left*2} {sh -}" 4355 FORi=0TO3:PRINTb$(i):FORt=1TO100:NEXT:NEXT 4356 FORi=3TO0STEP-1:PRINTb$(i):FORt=1TO100:NEXT:NEXT 4357 FORi=0TO3:PRINTb$(i):FORt=1TO100:NEXT:NEXT:GOSUB50000 4360 FORi=1TO5:PRINT"{home}{down*15} {reverse on}{cm u*3}{down}{left*3}{cm d*3}":FORt=1TO100:NEXT 4370 PRINT"{home}{down*15} {cm u*3}{down}{left*3}{cm d*3}":FORt=1TO100:NEXT:NEXT 4380 PRINTp$"Qthis is a capacitor{space*9}" 4390 PRINT"{space*31}":GOSUB50000 4400 PRINTp$"Qthe capacitor starts{space*7}" 4410 PRINT" charging towards 5 volts{space*5}":GOSUB50000 4420 PRINTp$"Qthe voltage across the{space*5}" 4430 PRINT" capacitor goes to the {reverse on}sid{reverse off}!!":GOSUB50000 4440 PRINTp$"Qthe {reverse on}sid{reverse off} chip starts counting." 4450 PRINT"{space*32}":GOSUB50000 4460 PRINTp$"Qwhen the voltage reaches 2.5 " 4470 PRINT" the {reverse on}sid{reverse off} stops counting{space*6}":GOSUB50000 4480 PRINT"{clear}{down*2}Qthe time taken to reach 2.5 volts" 4490 PRINT"{down} (starting at 0 volts and heading" 4500 PRINT"{down} toward 5 volts) depends upon the" 4510 PRINT"{down} value of the variable resistor{.*3}" 4520 PRINT"{down} which depends upon the position of" 4530 PRINT"{down} the paddle knob!" 4540 PRINT"{down}Qso the {reverse on}sid{reverse off} chip can 'read' the" 4560 PRINT"{down} position of the knob!":ms$="{space*2}clever!":GOSUB63200:GOSUB50000 4570 PRINT"{clear}{down}Qthe voltage across the capacitor is" 4580 PRINT"{down} v=5-5*exp(-t/rc) volts" 4590 PRINT"{down}Qrc=value of resistor*value of capacitor" 4600 PRINT"{down}Qv=2.5 when t=rc*log(2)=.693*rc" 4610 PRINT"{down}Qthis time is directly proportional" 4620 PRINT"{down} to the (variable) resistance!":GOSUB50000 4630 PRINT"{clear}{down*2}Qalthough {reverse on}r{reverse off} is in {reverse on}ohms{reverse off} and" 4640 PRINT"{down} {reverse on}c{reverse off} is in {reverse on}farads{reverse off}, the product" 4650 PRINT"{down} {reverse on}rc{reverse off} is measured in {reverse on}seconds{reverse off}!" 4660 PRINT"{down}Q'the book' says to choose:" 4670 PRINT"{down} {reverse on}rc=500 microseconds{reverse off}." 4680 PRINT"{down} (example: a 100k maximum resistance" 4690 PRINT" (and a 5{0*3} picofarad capacitor)." 4700 PRINT"{down}Qone of these rc-combinations is needed" 4710 PRINT"{down} for both the x-position and the" 4720 PRINT"{down} y-position{.*3}and the {reverse on}sid{reverse off}" 4730 PRINT"{down} has two pins devoted":PRINT"{down} to these!" 4740 ms$="smart sid!":GOSUB63200:GOSUB50000 4800 t$="paddles":GOSUB63000 4810 PRINT"{down*2}Qthe two 'paddle' voltages go to" 4820 PRINT"{down} the {reverse on}sid{reverse off} chip via pins 5 and 9 of" 4830 PRINT"{down} the joystick port." 4840 PRINT"{down}Qyou{down}{left*3}{cm u*3}{up} can 'read' the paddle positions" 4850 PRINT"{down} {reverse on}peek(54297)=x-position" 4860 PRINT"{down} {reverse on}peek(54298)=y-position" 4870 PRINT"{down}Qin each case you'll get a number" 4880 PRINT"{down} from 0 to 255.":ms$="what else!":GOSUB63200:GOSUB50000 5000 GOSUB63100:REM micros-5 5001 sn$="05{0*3}" 5010 t$="the sound (sid) chip":GOSUB63000 5030 PRINT"{down}{sh asterisk*9}Q{sh asterisk} 5031 PRINT"{sh asterisk*8}Q{sh +}{sh asterisk} 5032 PRINT"{sh asterisk*7}Q{sh +*2}{sh asterisk} 5033 PRINT"{sh asterisk*6}Q{sh +*3}{sh asterisk} 5034 PRINT"{sh asterisk*5}Q{sh +*4}{sh asterisk} 5035 PRINT"{sh asterisk*4}Q{sh +*5}{sh asterisk} 5036 PRINT"{sh asterisk*3}Q{sh +*6}{sh asterisk} 5037 PRINT"{sh asterisk*2}Q{sh +*7}{sh asterisk} 5038 PRINT" {cm a}{cm e*8}{cm s} 5039 PRINT" {sh -}FF{space*6}{sh -} 5040 PRINT"{sh asterisk}{cm w}ceR{space*5}{sh -} 5041 PRINT"{sh asterisk}{cm w}r/w{space*5}{sh -} 5042 PRINT"{sh asterisk}{cm w}potx{space*4}{cm q}{sh asterisk}Q{sh asterisk}sound output 5043 PRINT"{sh asterisk}{cm w}poty{space*4}{sh -} {sh -} (monitor) 5044 PRINT" {sh -}{space*8}{sh -} {sh -} 5045 PRINT"{sh asterisk}{cm w}a4{space*2}{reverse on}sid{reverse off} {sh -} {cm z}{sh asterisk}to rf modulator 5046 PRINT"{sh asterisk}{cm w}a3{space*6}{sh -}{space*3}(for tv set) 5047 PRINT"{sh asterisk}{cm w}a2{space*6}{sh -} 5048 PRINT"{sh asterisk}{cm w}a1{space*6}{sh -} 5049 PRINT"{sh asterisk}{cm w}a0{space*6}{sh -} 5050 PRINT" {cm z}{sh asterisk*8}{cm x} 5060 p1$="{home}{down*8}{right*13}":p2$="{home}{down*13}{right*2}":GOSUB50000 5070 PRINTp2$"{reverse on}ce":PRINTp1$"Qchip enable for":PRINTp1$"{down} addresses:$d4xx" 5071 GOSUB50000:PRINTp2$"ce" 5072 PRINTp1$"{space*16}":PRINTp1$"{down}{space*16}" 5080 PRINTp2$"{down}{reverse on}r/w":PRINTp1$"Qread/write line":PRINTp1$"{down} (1=read/0=write)" 5081 GOSUB50000:PRINTp2$"{down}r/w" 5082 PRINTp1$"{space*17}":PRINTp1$"{down}{space*17}" 5090 PRINTp2$"{down*2}{reverse on}potx":PRINTp1$"Qx-paddle pin.{space*2}":PRINTp1$"{down}{space*17}" 5091 GOSUB50000:PRINTp2$"{down*2}potx" 5092 PRINTp1$"{space*17}":PRINTp1$"{down}{space*17}" 5100 PRINTp2$"{down*3}{reverse on}poty":PRINTp1$"Qy-paddle pin.{space*2}":PRINTp1$"{down}{space*17}" 5101 GOSUB50000:PRINTp2$"{down*3}poty" 5102 PRINTp1$"{space*17}":PRINTp1$"{down}{space*17}":p2$=p2$+"{down*5}" 5110 PRINTp2$"{reverse on}a4{down}{left*2}a3{down}{left*2}a2{down}{left*2}a1{down}{left*2}a0":PRINTp1$"Q5 bits on address bus" 5111 PRINTp1$"{down} (to select one of 29" 5112 PRINTp1$"{down*2}{space*2}internal registers).":GOSUB50000 5113 PRINTp2$"a4{down}{left*2}a3{down}{left*2}a2{down}{left*2}a1{down}{left*2}a0" 5120 PRINT"{home}{down*4}{right}{reverse on}data{down}{left*4} bus":PRINTp1$"Q{.*3}of course{.*3}{space*6}" 5121 PRINTp1$"{down}{space*21}" 5122 PRINTp1$"{down*2}{space*22}":GOSUB50000 5130 p2$="{home}{down*15}{right*14}":PRINTp2$"{reverse on}sound" 5131 PRINTp1$"Qout comes some sound " 5132 PRINTp1$"{down} for a monitor or a{space*2}" 5133 PRINTp1$"{down*2} tv set (which needs{space*2}" 5134 PRINTp1$"{down*3} to receive it on a{space*3}" 5135 PRINTp1$"{down*4} particular 'channel').":GOSUB50000 5140 PRINT"{home}{down*22}{right*10}{cm q}{arrow left}reset{up}{left*5}{F*5}" 5150 PRINTp1$"Qand our friend {reverse on}reset{reverse off}!" 5151 PRINTp1$"{down} (which sets all the " 5152 PRINTp1$"{down*2} internal registers{space*3}" 5153 PRINTp1$"{down*3} to {reverse on}0{reverse off}).{space*14}" 5154 PRINTp1$"{down*4}{space*23}":GOSUB50000 5160 PRINT"{home}{down*13}{right*10}{cm q}{arrow left}clock" 5161 PRINTp1$"Qand the {reverse on}phase 2 clock{reverse off}{space*2}" 5162 PRINTp1$"{down} which {reverse on}sid{reverse off} uses to{space*4}" 5163 PRINTp1$"{down*2} 'time' the various{space*5}" 5164 PRINTp1$"{down*3} sound frequencies.{space*6}":GOSUB50000 5170 PRINTp1$"Qnote:only when {reverse on}clock=1{reverse off}{space*2}" 5171 PRINTp1$"{down}{space*6}will {reverse on}sid{reverse off} respond to " 5172 PRINTp1$"{down*2}{space*6}data,r/w,ce,etc.{space*3}" 5173 PRINTp1$"{down*3}{space*25}":GOSUB50000 6000 GOSUB63100:REM micros-6 6001 sn$="06{0*3}" 6005 t$="the central intell":GOSUB63000 6010 t$="the cia (input/output) chips":GOSUB63000 6020 PRINT"{down*2}Qwe've mentioned the 2 {reverse on}cia{reverse off} chips{.*3}" 6030 PRINT"{down} type {reverse on}6526{reverse off}{.*3}" 6035 PRINT"{down} ({reverse on}c{reverse off}omplex {reverse on}i{reverse off}nterface {reverse on}a{reverse off}dapter) 6040 PRINT"{down*2}Qlet's say a word or two about them.":ms$="please do":GOSUB63200 6050 GOSUB50000:PRINT"{clear}{down*2}Qthese 40 pin chips (..big as the {reverse on}6510{reverse off})" 6060 PRINT"{down} have 16 internal registers." 6070 PRINT"{down}Qthey must then receive {reverse on}4{reverse off} wires from" 6080 PRINT"{down} the address bus to identify one of" 6090 PRINT"{down} these 2^4 registers." 6100 PRINT"{down}Qthey're also connected to the {reverse on}data bus{reverse off}." 6110 PRINT"{down}Qthe data from the bus can be directed" 6120 PRINT"{down} to one of two 'input/output ports'." 6130 ms$="let's see":GOSUB63200:GOSUB50000 6140 PRINT"{clear}{down*4}{sh asterisk*9}Q{sh asterisk} 6141 PRINT"{sh asterisk*8}Q{sh +}{sh asterisk} 6142 PRINT"{sh asterisk}data{sh asterisk*2}Q{sh +*2}{sh asterisk} 6143 PRINT"{sh asterisk}bus {sh asterisk}Q{sh +*3}{sh asterisk} 6144 PRINT"{sh asterisk*5}Q{sh +*4}{sh asterisk} 6145 PRINT"{sh asterisk*4}Q{sh +*5}{sh asterisk} 6146 PRINT"{sh asterisk*3}Q{sh +*6}{sh asterisk} 6147 PRINT"{sh asterisk*2}Q{sh +*7}{sh asterisk} 6148 PRINT" {cm a}{cm e*8}{cm s} 6149 PRINT" {sh -}FF{space*6}{cm q}{sh asterisk*2} 6150 PRINT"{sh asterisk}{cm w}ceR{space*5}{cm q}{sh asterisk*2} {reverse on}port a" 6151 PRINT"{sh asterisk}{cm w}r/w{space*5}{cm q}..(8 pins) 6152 PRINT"{sh asterisk}{cm w}clock{space*3}{cm q}{sh asterisk*2} 6153 PRINT" {sh -}{space*8}{sh -} 6154 PRINT" {sh -}{space*3}{reverse on}cia{reverse off}{space*2}{sh -} 6155 PRINT"{sh asterisk}{cm w}a3{space*6}{cm q}{sh asterisk*2} 6156 PRINT"{sh asterisk}{cm w}a2{space*6}{cm q}{sh asterisk*2} {reverse on}port b 6158 PRINT"{sh asterisk}{cm w}a1{space*6}{cm q}..(8 pins) 6159 PRINT"{sh asterisk}{cm w}a0{space*6}{cm q}{sh asterisk*2} 6160 PRINT" {cm z}{sh asterisk*8}{cm x} 6170 GOSUB50000:PRINT"{home}{down}ce{up}{left*2}RR{down}=0 for addresses in" 6180 PRINT"the range:$dc00-$dcff (for cia #1)" 6190 PRINT"and for{space*2}:$dd00-$ddff (for cia #2)":GOSUB50000 6200 PRINT"{home}Qlet's talk about the {reverse on}a-half{reverse off}:" 6210 FORi=1TO3:PRINT"{space*34}":NEXT 6220 PRINT"{home}{down*18}{right*2}********":GOSUB50000 6240 PRINT"{clear}{down*4}{sh asterisk*9}Q{sh asterisk} 6241 PRINT"{sh asterisk*8}Q{sh +}{sh asterisk} 6242 PRINT"{sh asterisk}data{sh asterisk*2}Q{sh +*2}{sh asterisk} 6243 PRINT"{sh asterisk}bus {sh asterisk}Q{sh +*3}{sh asterisk} 6244 PRINT"{sh asterisk*5}Q{sh +*4}{sh asterisk} 6245 PRINT"{sh asterisk*4}Q{sh +*5}{sh asterisk} 6246 PRINT"{sh asterisk*3}Q{sh +*6}{sh asterisk} 6247 PRINT"{sh asterisk*2}Q{sh +*7}{sh asterisk} 6248 PRINT" {cm a}{cm e*8}{sh asterisk*5}{cm s} 6249 PRINT" {sh -}{space*13}{cm q}{sh asterisk*2} 6250 PRINT" {sh -} {reverse on}cia{reverse off}{space*9}{cm q}{sh asterisk*2} p" 6251 PRINT" {sh -}{space*13}{cm q}{sh asterisk*2} o" 6252 PRINT" {sh -}{space*13}{cm q}{sh asterisk*2} r" 6253 PRINT" {sh -}{space*13}{cm q}{sh asterisk*2} t 6254 PRINT" {sh -}{space*13}{cm q}{sh asterisk*2} 6255 PRINT" {sh -}{space*13}{cm q}{sh asterisk*2} a" 6256 PRINT" {sh -}{space*13}{cm q}{sh asterisk*2} 6258 PRINT" {sh -}{space*13}{sh -} 6259 PRINT" {sh -}{space*13}{sh -} 6260 PRINT" {sh -}{space*13}{sh -} 6270 bl$="":FORi=1TO39:bl$=bl$+" ":NEXT 6280 PRINT"{home}Qthe port may go to the 'outside'" 6290 PRINT" and communicate with a disk drive or a" 6300 PRINT" printer{.*3}":GOSUB50000:PRINT"{home}";:FORi=1TO4:PRINTbl$:NEXT 6310 PRINT"{home}Qor it may be connected to the" 6320 PRINT" keyboard to detect which key is" 6330 PRINT" depressed.":GOSUB50000:PRINT"{home}";:FORi=1TO4:PRINTbl$:NEXT 6340 PRINT"{home}Qin any case the {reverse on}data{reverse off} it receives or" 6350 PRINT" sends goes into an 'internal' register" 6355 PRINT" (a {reverse on}p{reverse off}eripheral data {reverse on}r{reverse off}egister)." 6360 b$="OP{down}{left*2}":r$="":FORi=1TO8:r$=r$+b$:NEXT:r$=r$+"{cm t*2}{down}{left*3}" 6370 d$="{home}{down*13}":c$="{right*13}":PRINTd$c$r$"{reverse on}pra":GOSUB50000 6380 PRINT"{home}";:FORi=1TO4:PRINTbl$:NEXT 6390 PRINT"{home}Qsince the pra ({.*3}there's a prb too!)" 6400 PRINT" may either 'receive' or 'send' data" 6410 PRINT" each port may be configured" 6420 PRINT" as an {reverse on}input{reverse off} or an {reverse on}output{reverse off}.":GOSUB50000 6430 PRINT"{home}";:FORi=1TO4:PRINTbl$:NEXT 6440 PRINT"{home}Qin fact each {reverse on}pin{reverse off} may be ":PRINT"{down} input{down}{left*5}{cm y*5}{up} or "; 6450 PRINT"output{down}{left*6}{cm y*6}{up}!{home}";:GOSUB50000:FORi=1TO4:PRINTbl$:NEXT 6460 PRINT"{home}Qto tell the chip which direction" 6470 PRINT" each {reverse on}bit{reverse off} is to move, there is also" 6480 PRINT" a {reverse on}d{reverse off}ata {reverse on}d{reverse off}irection {reverse on}r{reverse off}egister.":GOSUB50000 6490 PRINTd$LEFT$(c$,9)r$"{left}{reverse on}ddra":GOSUB50000:PRINT"{home}";:FORi=1TO4:PRINTbl$:NEXT 6500 PRINT"{home}Qif we put a {reverse on}0{reverse off} into a bit position" 6510 PRINT" of the {reverse on}ddra{reverse off} then the corresponding" 6520 PRINT" pin of the {reverse on}pra{reverse off} is an input{down}{left*5}{cm y*5}":GOSUB50000 6530 ms$=" 0=input":GOSUB63200:GOSUB50000:PRINT"{home}";:FORi=1TO4:PRINTbl$:NEXT 6540 PRINT"{home}Qif we put a {reverse on}1{reverse off} into a bit position" 6550 PRINT" of the {reverse on}ddra{reverse off} then the corresponding" 6560 PRINT" pin of the {reverse on}pra{reverse off} is an output{down}{left*6}{cm y*6}":GOSUB50000 6570 ms$=" {reverse on}1=output":GOSUB63200:GOSUB50000:PRINT"{home}";:FORi=1TO4:PRINTbl$:NEXT 6575 s$="{home}{down*4}{right*13}" 6580 PRINT"{home}Qthis makes sense{.*3}when the micro" 6590 PRINT" is turned on the {reverse on}reset{reverse off} puts {0*8}" 6600 PRINT" into all registers including the {reverse on}ddra{reverse off}." 6610 PRINTs$"Qhence 'port a' points {reverse on}in{reverse off}." 6620 PRINTs$"{down*2}Qno unwanted data gets out!":GOSUB50000 6630 PRINT"{home}";:FORi=1TO4:PRINTbl$:NEXT:PRINTs$"{space*26}" 6640 PRINTs$"{down*2}{space*27}" 6641 PRINT"{clear}{down*4}Qport a of {reverse on}cia #2{reverse off} is actually used" 6642 PRINT"{down} to communicate with the 'serial port'.":GOSUB50000 6643 PRINT"{down}Qexcept for 2 bits worth which is used" 6644 PRINT"{down} to supply the 'top two bits' on the" 6645 PRINT"{down} address bus{.*3}sometimes.":GOSUB50000 6650 ms$="{reverse on}{space*2}what!{space*3}{reverse off}":GOSUB63300 6660 PRINT"{clear}{down*4}Qwell that's{down}{left*6}{cm u*6}{up} another story.":ms$="au revoir!" 6670 GOSUB63200:sn$="{0*3}10":GOSUB63520:END 50000 GETa$:IFa$<>""THEN50000 50001 GETa$:IFa$=""THEN50001 50002 IFa$="@"THEN63500 50003 RETURN 51000 n=3 51001 x$="":FORu=nTO0STEP-1:x%=x/(2^u):x=x-x%*(2^u):x$=x$+CHR$(48+x%) 51002 NEXT:RETURN 52000 m=3 52001 y$="":FORv=mTO0STEP-1:y%=y/(16^v):y=y-y%*(16^v) 52002 y$=y$+CHR$(48+y%-7*(y%>9)):NEXT:RETURN 63000 PRINT"{clear}"; 63001 l=LEN(t$):uu$="":FORi=1TOl:uu$=uu$+" ":NEXT:tt$=uu$+t$ 63002 PRINT" {cm a}";:FORi=1TOl:PRINT"{sh asterisk}";:NEXT:PRINT"{cm s}" 63003 PRINT" {sh -}";:FORi=1TOl:PRINT" ";:NEXT:PRINT"{reverse off}{sh -}" 63004 PRINT" {cm z}";:FORi=1TOl:PRINT"{sh asterisk}";:NEXT:PRINT"{cm x}":PRINT"{up*2}{right*2}{reverse on}{red}"; 63005 FORi=1TOl:PRINTMID$(tt$,i+1,l):PRINT"{up}{right*2}{reverse on}";:FORt=1TO50:NEXT 63006 NEXT:PRINT"{black}":RETURN 63100 bt$="{home}{down*24}" 63101 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}" 63102 pt$=pt$+"{down}{left*13}N{cm t*12}M{down}{left*14}{cm g}{=*12}{cm m}" 63103 pt$=pt$+"{down}{left*14}PO{cm t*10}PO{up*4}{left*12}" 63104 pt$=bt$+"{up*6}{right*26}"+pt$+"{black}" 63105 sn=1030:IFPEEK(0)=47THENsn=2054 63199 RETURN 63200 FORi=1TO2:PRINTpt$"{space*10}" 63201 FORt=1TO50:NEXT 63202 PRINTpt$ms$ 63203 FORt=1TO50:NEXT:NEXT:RETURN 63300 GOSUB63200:FORt=1TO1000:NEXT:RETURN 63500 vs=VAL(sn$):vs=vs-1000:IFvs<1000THENvs=100 63510 sn$=MID$(STR$(vs),2):sn$=RIGHT$("{0*5}"+sn$,5):GOSUB63520:RUN 63520 FORi=1TO5:POKEsn+i-1,ASC(MID$(sn$,i,1)):NEXT:RETURN stop tok64 (bastext 1.0)