start bastext 1025 start tok64 d64-yIsyoz 1 RUN00010 10 GOSUB63100:sn$="00100" 100 POKE53281,15:POKE53280,12:PRINT"{black}":PRINT"{clear}{space*11}{reverse on}{blue}micros'n'chips-4" 101 PRINT"{red}{cm a}{sh asterisk*37}{cm s}":GOSUB63100 102 PRINT"{sh -} {reverse on}{blue}{space*6}interfacing to the world{space*5}{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}":t$="some terminology":GOSUB63000" 1002 PRINT"{down*2}Q{reverse on}note{reverse off}: we will refer to signals as" 1003 PRINT"{down} jane{up}{left*4}{F*4}{down} or just plain 'jane'." 1004 PRINT"{down}Qa chip with a pin labelled ce{up}{left*2}FF{down} is" 1005 PRINT"{down} enabled when this pin is low{down}{left*3}{cm u*3}{up} (=0)." 1006 PRINT"{down}Qif a chip has a pin labelled something{up}{left*9}{F*9}{down}" 1007 PRINT"{down} then 'something' will happen when" 1008 PRINT"{down} this pin is low (=0)." 1009 PRINT"{down}Qa pin labelled 'enable'?":PRINT"{down} a '1' will enable!" 1010 ms$="{reverse on}{space*3}ok?{space*4}{reverse off}":GOSUB63200:GOSUB50000 1011 t$="more on the cia":GOSUB63000:PRINT"{home}{down*3}" 1015 GOSUB55000:ms$="b-half of":GOSUB63200 1020 GOSUB50000:ms$="{reverse on} cia #2{space*3}":GOSUB63200:GOSUB50000 1030 PRINT"{home}";:FORi=1TO4:PRINTbl$:NEXT 1040 PRINT"{home}";:t$="port b=parallel port=user port":GOSUB63001 1051 PRINTs$"{down*2}(this is at back of c64)":GOSUB50000 1052 PRINT"{clear}Qthis chip lives at addresses" 1053 PRINT"{down} starting at $dd00." 1054 PRINT"{down}":GOSUB56000 1057 PRINT"{down}..and 12 other registers:$dd04-$dd0f." 1058 PRINT"{down*3}Q{reverse on}poke56579,255{reverse off} and what happens:":GOSUB50000 1060 PRINT"{clear}":GOSUB56000 1063 PRINT"{down}{reverse on}{space*2}poke56579,255{space*5}" 1065 PRINT"{down}Qsince address is ${reverse on}dd{reverse off}03 then cia #2" 1070 PRINT"{down} gets a chip enable: ce{up}{left*2}RR{down}":GOSUB50000 1080 PRINT"{down}Qsince it's a {reverse on}poke{reverse off}={reverse on}write{reverse off} then r/w{up}{left}F{down}=0":GOSUB50000 1090 PRINT"{down}Qsince address is $dd{reverse on}03{reverse off} the last" 1100 PRINT"{down} 4 bits on the address bus are 0011" 1110 PRINT"{down} which selects the {reverse on}ddrb{reverse off} in the chip.":GOSUB50000 1120 PRINT"{down}Qthe data (255={1*8}) goes into {reverse on}ddrb" 1130 PRINT"{down} and port b is {reverse on}all output{reverse off}!":GOSUB50000 1140 PRINT"{clear}":GOSUB56000:PRINT"{down}Qnow we can:":PRINT"{down}{reverse on}{space*2}poke56{7*3},192{space*5}" 1150 PRINT"{down} and the data (192=";:x=192:n=7:GOSUB51001 1160 PRINTx$")":PRINT"{down} goes {reverse on}out{reverse off} port b!":GOSUB50000 1170 PRINT"{down}Qso we can turn {reverse on}on{reverse off}":PRINT"{down} 2 external devices.." 1180 FORi=1TO6:PRINT"{home}{down*10}{right*19}{reverse on}11":FORt=1TO50:NEXT 1185 PRINT"{home}{down*10}{right*19}11{reverse off}":FORt=1TO50:NEXT:NEXT:GOSUB50000 1190 PRINT"{home}{down*18}Qand turn {reverse on}off{reverse off} 6!": 1191 FORi=1TO6:PRINT"{home}{down*10}{right*21}{reverse on}{0*6}":FORt=1TO50:NEXT 1192 PRINT"{home}{down*10}{right*21}{0*6}{reverse off}":FORt=1TO50:NEXT:NEXT 1195 GOSUB50000:ms$="{space*2}slick!":GOSUB63300 1200 PRINT"{clear}Qwe may want to 'receive' outside" 1210 PRINT"{down} info thru the {reverse on}parallel port{reverse off}={reverse on}port b{reverse off}." 1220 PRINT"{down}{reverse on}{space*3}poke56577,0{space*4}{reverse off}" 1230 PRINT"{down} will make {reverse on}port b{reverse off} all input{down}{left*5}{cm u*5}{up}." 1240 PRINT"{down}Qthen we just:" 1250 PRINT"{down}{reverse on}{space*3}peek(56577){space*4}{reverse off}" 1260 PRINT"{down} to read {reverse on}prb{reverse off} which is connected" 1270 PRINT"{down} to the 'outside world'.":GOSUB50000 1280 PRINT"{clear}Qif {reverse on}parallel port{reverse off} is connected to" 1290 PRINT"{down} a printer or disk drive we don't want" 1300 PRINT"{down} the {reverse on}6510{reverse off} to spend all its time" 1310 PRINT"{down} peeking or poking this port." 1320 PRINT"{down}Qinstead we interrupt the {reverse on}6510{reverse off} only" 1330 PRINT"{down} when the 'external device' is ready" 1340 PRINT"{down} for the next data transfer." 1350 PRINT"{down}Qwe wait for the 'device' to":PRINT"{down} {reverse on}tell the cia{reverse off}!" 1360 GOSUB50000:ms$="{reverse on}{space*3}how?{space*3}":GOSUB63300 1370 PRINT"{clear}Qthere is an {reverse on}input{reverse off} pin which we can" 1380 PRINT"{down} connect to the 'external device'" 1390 PRINT"{down} called flag{up}{left*4}{F*4}{down}.":GOSUB50000 1400 PRINT"{down}Qwhen the 'device' is ready for the" 1410 PRINT"{down} next data transfer it can set flag{up}{left*4}{F*4}{down}=0" 1420 PRINT"{down} and the {reverse on}cia{reverse off} will interrupt the {reverse on}6510{reverse off}" 1430 PRINT"{down} by sending an {reverse on}i{reverse off}nterrupt {reverse on}r{reverse off}e{reverse on}q{reverse off}uest (irq{up}{left*3}{F*3}{down})" 1440 PRINT"{down}Qwhen the {reverse on}6510{reverse off} can oblige it will" 1450 PRINT"{down} read{down}{left*4}{cm u*4}{up} or write{down}{left*5}{cm u*5}{up} to the {reverse on}prb{reverse off}.":GOSUB50000 1460 PRINT"{down}Qthen the {reverse on}cia{reverse off} tells the 'device' that" 1470 PRINT"{down} it's ready for the 'next' transfer!":GOSUB50000 1480 PRINT"{down}Qit does this by setting {reverse on}pc{reverse off}=0":GOSUB50000 1490 PRINT"{clear}":ms$="{reverse on}{space*2}what?{space*3}":GOSUB63300 2000 GOSUB63100:REM micros-2 2001 sn$="02{0*3}" 2005 t$="the cia and the parallel port":GOSUB63000 2010 PRINT"{down}Qprocedure for 'recieving' data:":FORt=1TO1000:NEXT 2020 PRINT"{up}Qprocedure for 'rec{space*2}ving' data:":FORt=1TO300:NEXT 2021 PRINT"{up}Qprocedure for 'rec??ving' data:":FORt=1TO300:NEXT 2022 PRINT"{up}Qprocedure for 'receiving' data:" 2023 PRINT" {cm u*30}" 2030 PRINT"{down}1)wait for flag{up}{left*4}{F*4}{down}={reverse on}0{reverse off} from device" 2035 PRINT"{space*2}(meaning Qdata is valid).":GOSUB50000 2040 PRINT"{down}2)send interrupt to {reverse on}6510{reverse off}" 2050 PRINT"{space*2}(meaning Qdata is ready).":GOSUB50000 2060 PRINT"{down}3)when {reverse on}6510{reverse off} reads data send pc{up}{left*2}FF{down}={reverse on}0{reverse off}" 2070 PRINT"{space*2}to 'device'(Qready for next byte).":GOSUB50000 2080 PRINT"{down}{.*3}and repeat..":GOSUB50000 2090 PRINT"{clear}{down}Qprocedure for 'sending' data:" 2091 PRINT" {cm u*30}" 2100 PRINT"{down}1)put data on port b and set pc{up}{left*2}FF{down}={reverse on}0" 2105 PRINT"{space*2}Qdata is valid.":GOSUB50000 2110 PRINT"{down}2)wait for flag{up}{left*4}{F*4}{down}={reverse on}0{reverse off} from device" 2115 PRINT"{space*2}Qready for next data.":GOSUB50000 2120 PRINT"{down}3)send interrupt to {reverse on}6510{reverse off}" 2125 PRINT"{space*2}Qready for next data byte.":GOSUB50000 2130 PRINT"{down}4)when {reverse on}6510{reverse off} sends byte to port b{.*3}" 2135 PRINT"{space*2}repeat{.*3}":GOSUB50000 2140 PRINT"{clear}{down*2}Qthe little ritual of raising and" 2150 PRINT"{down} lowering the voltages on the wires" 2160 PRINT"{down} flag{up}{left*4}{F*4}{down} and pc{up}{left*2}FF{down} in order to" 2180 PRINT"{down} communicate with an external device" 2190 PRINT"{down} is called {reverse on}handshaking{reverse off}." 2200 PRINT"{down}Qif the data is sent not{down}{left*3}{cm u*3}{up} as {reverse on}bytes" 2210 PRINT"{down} (over 8 wires) but as {reverse on}bits{reverse off} (over a" 2220 PRINT"{down} single wire!) the ritual is sexier.":ms$=" sexier?":GOSUB50000 2230 GOSUB63200 3000 GOSUB63100:REM micros-3 3001 sn$="03{0*3}" 3005 t$="cereal communica":GOSUB63000 3006 t$="serial communication":GOSUB63000 3010 PRINT"{down} receiving serial bytes:" 3011 PRINT" {cm u*22}" 3020 PRINT"Qwait for {reverse on}cnt{reverse off} wire to go high {cm @}{sh @}{cm t*2}":ms$="cnt={reverse on}c{reverse off}ou{reverse on}nt{reverse off}" 3030 GOSUB63200:GOSUB50000 3040 PRINT"{home}{down*7}Qaccept bit from serial port wire ({reverse on}sp{reverse off}).":GOSUB50000 3050 PRINT"{down}Qwhen 8 such transfers take place" 3060 PRINT" interrupt the {reverse on}6510{reverse off} and give":PRINT" him the byte.":GOSUB50000 3070 PRINT"{up} her":PRINT"{down*2}..repeat..":GOSUB50000 3080 PRINT"{clear}{down*2}Qnote that we have introduced 2 {reverse on}new" 3090 PRINT"{down} pins on the 6526{down}{left*4}{cm u*4}{up} cia chip: {reverse on*2}cnt{reverse off} & {reverse on}sp{reverse off}." 3100 PRINT"{down}Qa wire from the {reverse on}cnt{reverse off} pin goes out to" 3110 PRINT"{down} the 'device' which raises and lowers" 3120 PRINT"{down} it to indicate 'data valid/invalid'." 3130 PRINT"{down}Qthe rate at which this {reverse on}cnt{reverse off} wire" 3140 PRINT"{down} oscillates between 0 and 1 gives the" 3150 PRINT"{down} baud rate.{down}{left*10}{cm u*9}" 3160 PRINT"{down}Qwhen sending serial data it's the" 3170 PRINT"{down} micro which must toggle this {reverse on}cnt{reverse off} line.":GOSUB50000 3180 PRINT"{clear}{down} sending serial bytes:" 3181 PRINT" {cm u*20}" 3190 PRINT"Qput a bit on {reverse on}sp{reverse off} pin and lower {reverse on}cnt{reverse off} P{cm @}":GOSUB50000 3200 PRINT"{down}Qdon't wait for the 'device'{.*3}just" 3210 PRINT"{down} keep putting on the bits, and toggling" 3220 PRINT"{down} the {reverse on}cnt{reverse off} line{.*3}at a specific baud rate.{down}{left*10}{cm u*9}" 3230 GOSUB50000:PRINT"{down}Qafter 8 such bit transfers send an" 3240 PRINT"{down} interrupt to {reverse on}6510{reverse off}{.*3}asking for" 3250 PRINT"{down} another byte.":PRINT"{down}Q{.*3}repeat{.*3}":ms$="baud rate?" 3260 GOSUB50000:GOSUB63300 3270 PRINT"{clear}{down*2}Qdont slow down the bit transfer" 3280 PRINT"{down} by waiting for an acknowledgement from" 3290 PRINT"{down} the receiving device (the micro" 3300 PRINT"{down} or external device). the bits get" 3310 PRINT"{down} moved at a 'specific rate'. 3320 PRINT"{down}Qit is the responsibility of the" 3330 PRINT"{down} receiver to accept the bit stream" 3335 PRINT"{down} at this rate!" 3340 PRINT"{down}Qsome 'standard' baud rates:" 3350 PRINT"{down}110,150,300,600,1200,2400,4800,9600.":GOSUB50000 4000 GOSUB63100:REM micros-4 4001 sn$="04{0*3}" 4005 t$="cia pinout":GOSUB63000 4010 GOSUB54000 4040 y=9:x=2:m$="{reverse on}ce":GOSUB54300 4041 PRINTp$"Qchip enable":PRINTp$"{down*2} (when address":PRINTp$"{down*4} is right)." 4042 GOSUB50000:GOSUB54310 4050 y=10:x=2:m$="{reverse on}r/w":GOSUB54300 4051 PRINTp$"Qread/write ":PRINTp$"{down*2}{space*2}read=1{space*6}":PRINTp$"{down*4}{space*2}write=0{space*2}" 4052 GOSUB50000:GOSUB54310 4060 y=11:x=2:m$="{reverse on}clock":GOSUB54300 4061 PRINTp$"Qphase 2{space*4}":PRINTp$"{down*2} clock{space*8}":PRINTp$"{down*4}{space*11}" 4062 GOSUB50000:GOSUB54310 4070 y=13:x=2:m$="{reverse on}irq":GOSUB54300 4071 PRINTp$"Qinterrupt{space*2}":PRINTp$"{down*2} the {reverse on}6510{reverse off}.{space*4}":PRINTp$"{down*4}{space*11}" 4072 GOSUB50000:GOSUB54310 4080 y=15:x=2:m$="{reverse on}a3":GOSUB54300 4081 y=16:x=2:m$="{reverse on}a2":GOSUB54300 4082 y=17:x=2:m$="{reverse on}a1":GOSUB54300 4083 y=18:x=2:m$="{reverse on}a0":GOSUB54300 4084 PRINTp$"Q4 pins to{space*2}":PRINTp$"{down*2} select a {reverse on}6526":PRINTp$"{down*4} register. " 4085 GOSUB50000:GOSUB54310 4086 y=15:x=2:m$="{reverse on}a3":GOSUB54310 4087 y=16:x=2:m$="{reverse on}a2":GOSUB54310 4088 y=17:x=2:m$="{reverse on}a1":GOSUB54310 4089 y=18:x=2:m$="{reverse on}a0":GOSUB54310 4090 y=22:x=1:m$="{reverse on}reset":GOSUB54300 4091 PRINTp$"Qset all{space*4}":PRINTp$"{down*2} registers to":PRINTp$"{down*4} zero.{space*5}" 4092 GOSUB50000:GOSUB54310 4100 y=5:x=8:m$="{reverse on}+5 volts":GOSUB54300 4101 PRINTp$"Qthe innards":PRINTp$"{down*2} need power!!":PRINTp$"{down*4}{space*11}" 4102 GOSUB50000:GOSUB54310 4110 y=21:x=7:m$="{reverse on}ground":GOSUB54300 4111 PRINTp$"Q{.*3}and{space*5}":PRINTp$"{down*2} ground!{space*5}":PRINTp$"{down*4}{space*11}" 4112 GOSUB50000:GOSUB54310 4120 y=12:x=13:m$="{reverse on}flag":GOSUB54300 4121 PRINTp$"Qfrom an{space*4}":PRINTp$"{down*2} external{space*4}":PRINTp$"{down*4} device{space*4}" 4122 GOSUB50000:GOSUB54310 4130 y=13:x=13:m$="{reverse on}sp":GOSUB54300 4131 PRINTp$"Qthe serial ":PRINTp$"{down*2} port.{space*7}":PRINTp$"{down*4}{space*11}" 4132 GOSUB50000:GOSUB54310 4140 y=14:x=13:m$="{reverse on}cnt":GOSUB54300 4141 PRINTp$"Qto time the":PRINTp$"{down*2} serial bit{space*2}":PRINTp$"{down*4} transfer. " 4142 GOSUB50000:GOSUB54310 4150 y=15:x=13:m$="{reverse on}pc":GOSUB54300 4151 PRINTp$"Qperipheral ":PRINTp$"{down*2} control{.*3}to":PRINTp$"{down*4} handshake." 4152 GOSUB50000:GOSUB54310 4160 y=4:x=1:m$="{reverse on}{left}data{down}{left*3}bus":GOSUB54300 4161 y=9:x=13:m$="{reverse on}port a":GOSUB54300 4162 y=17:x=13:m$="{reverse on}port b":GOSUB54300 4163 PRINTp$"Qand the{space*4}":PRINTp$"{down*2} data bus and":PRINTp$"{down*4} ports{.*3}{space*2}" 4164 GOSUB50000 4165 PRINTp$"Qwe said it ":PRINTp$"{down*2} was a 40-pin":PRINTp$"{down*4} chip.{space*5}" 4166 GOSUB50000 4167 PRINTp$"Q39 pins are":PRINTp$"{down*2} accounted{space*3}":PRINTp$"{down*4} for{.*3}{space*4}" 4168 GOSUB50000 4169 PRINTp$"Qwhere's{space*4}":PRINTp$"{down*2} the 40th pin":PRINTp$"{down*4} {?*6}{space*4}" 4170 GOSUB50000:PRINTLEFT$(d$,19)LEFT$(r$,9)"{cm r}{down}{left}{cm z}{sh asterisk*3}"; 4180 FORi=1TO10:PRINT"{reverse on}tod{left*3}";:FORt=1TO50:NEXT:PRINT"{reverse off}tod{left*3}";:FORt=1TO50 4190 NEXT:NEXT:ms$="{space*3}time":GOSUB63300:ms$="{space*2}of day":GOSUB63300 4200 PRINT"{clear}{down*2}Qif a 60 hertz signal":PRINT"{space*6}{cm u*8}" 4210 PRINT" is fed to the {reverse on}cia{reverse off} via the" 4230 PRINT"{down} {reverse on}t{reverse off}ime {reverse on}o{reverse off}f {reverse on}d{reverse off}ay (tod) pin{.*3}" 4240 PRINT"{down} and we ask nicely{.*3} then the {reverse on}6526":PRINT"{down} will keep track of:" 4250 PRINT"{down}{reverse on} hours,minutes,seconds and":PRINT"{reverse on} tenths of seconds!{space*7}" 4260 ms$="tick!tick!":GOSUB63200:GOSUB50000 4270 PRINT"{clear}{down*2}Qwe said the {reverse on}6526{reverse off} has 16 internal" 4280 PRINT"{down} registers{.*3}and we've mentioned only" 4290 PRINT"{down} four:" 4300 PRINT"{down}{reverse on}0{reverse off}:peripheral register a" 4301 PRINT"{reverse on}1{reverse off}:peripheral register b" 4302 PRINT"{reverse on}2{reverse off}:data direction register a" 4303 PRINT"{reverse on}3{reverse off}:data direction register b" 4304 PRINT"{down*2}{.*3}and the 12 others??":ms$="{space*2}{reverse on}4{reverse off} to {reverse on}f{reverse off}":GOSUB63200:GOSUB50000 5000 GOSUB63100:REM micros-5 5001 sn$="05{0*3}" 5005 t$="cia registers":GOSUB63000 5010 PRINT"{down*2}Qwe need a register or two to do" 5020 PRINT"{down} the {reverse on}cnt{reverse off} (baud rate) timing for the" 5030 PRINT"{down} serial port {reverse on}sp{reverse off}." 5040 PRINT"{down}Qhow about two 8-bit registers which" 5050 PRINT"{down} we can load with a 2-byte number from" 5060 PRINT"{down} 0 to 65535 (decimal).":PRINT"{down}Qthen we can have these" 5070 PRINT"{down} two registers count down to zero" 5080 PRINT"{down} ..counting down at the rate of the" 5090 PRINT"{down} phase 2 clock (1 megahertz).":GOSUB50000 5100 PRINT"{clear}{down}Qthis will give us a maximum time of" 5110 PRINT"{down} 65535 microseconds=65.5 milliseconds" 5120 PRINT"{down} which (by micro standards) is plenty!":GOSUB50000 5130 PRINT"{down}Qif we want larger time intervals we" 5140 PRINT"{down} can have two 2-byte timer registers." 5150 PRINT"{down}Qwhen the first counts down to zero" 5160 PRINT"{down} we start the second timer." 5170 PRINT"{down}Qwe may also want to have one of these" 5180 PRINT"{down} 2-byte timers count 'external' pulses" 5190 PRINT"{down} which come in on the {reverse on}cnt{reverse off} pin.":GOSUB50000 5200 PRINT"{down}Qcnt={reverse on}count{reverse off}..remember?":GOSUB50000 5210 PRINT"{clear}{down*2}Qthen, of course, we want 4 more" 5220 PRINT"{down} registers devoted to the {reverse on}time of day{reverse off}:" 5230 PRINT"{down}one register to hold hours.." 5231 PRINT"{down}one register to hold minutes.." 5232 PRINT"{down}one register to hold seconds.." 5233 PRINT"{down}one register to hold 10ths of seconds.":GOSUB50000 5235 ms$=" 4 to go!":GOSUB63300 5240 PRINT"{clear}{down}Qof course our hours{down}{left*5}{cm u*5}{up} register" 5250 PRINT"{down} need only hold hours from 0 to 23" 5255 PRINT"{down} and minute & seconds from 0 to 59.." 5256 PRINT"{space*5}{cm u*6}{space*3}{cm u*7}" 5260 PRINT" how about a 24 hour clock:":PRINT"{down} from" 5270 PRINT"{down} {reverse on}0{reverse off}hours {reverse on}0{reverse off}minutes {reverse on}0{reverse off}seconds {reverse on}0{reverse off}10ths" 5280 PRINT"{down} to:" 5290 PRINT"{down} {reverse on}23{reverse off}hours {reverse on}59{reverse off}minutes {reverse on}59{reverse off}seconds {reverse on}9{reverse off}10ths":GOSUB50000 5300 PRINT"{clear}{down*2}Qin fact it may be convenient for" 5310 PRINT"{down} the user of this clever chip if we" 5320 PRINT"{down} have the numbers (hours,minutes,etc.)" 5330 PRINT"{down} stored in the registers in the format:" 5340 PRINT"{down} {reverse on}first{reverse off} digit:{reverse on}second{reverse off} digit":GOSUB50000 5350 PRINT"{down}example: 23 would be stored as:":PRINT"{cm u*7}" 5360 PRINT" 0010 0011" 5361 PRINT"{space*3}^{space*4}^^" 5362 PRINT"{space*3}2{space*5}3":GOSUB50000 5370 PRINT"{clear}{down*8}Qthis slick format has a name{.*4}":GOSUB50000 5375 t$="binary coded decimal=bcd":GOSUB63000 5380 PRINT"{down*3}Q59=0101 1001":PRINT"{down}Q98=1001 1{0*3}":PRINT"{down}Q 2={0*4} 0010" 5390 PRINT"{down}Q11={0*3}1 {0*3}1":PRINT"{down}Q22=0010 0010":PRINT"{down}Q19={0*3}1 1001" 5400 GOSUB50000:ms$="very nice!":GOSUB63300 5410 PRINT"{clear}{down*2}Qof course we only need hours":PRINT"{down} from 0 to 23:" 5420 PRINT"{down} or {reverse on}{0*4}{reverse off} {reverse on}{0*4}{reverse off} to {reverse on}0010{reverse off} {reverse on}0011":GOSUB50000 5430 PRINT"{down*2}Qyou don't like 24 hour clocks?" 5440 PRINT"{down} how about hours from 0 to 12 with" 5450 PRINT"{down} {reverse on}am{reverse off} and {reverse on}pm{reverse off} indicators?":GOSUB50000 5460 PRINT"{down} {reverse on}0{reverse off}{0*3} {0*4} to {reverse on}0{reverse off}001 0010{reverse off} = {reverse on}am" 5470 PRINT"{down} {reverse on}1{reverse off}{0*3} {0*4} to {reverse on}1{reverse off}001 0010{reverse off} = {reverse on}pm" 5480 ms$="msb=am/pm":GOSUB63200:GOSUB50000 5490 PRINT"{clear}{down}Qwe also want to tell the {reverse on}6526{reverse off} chip" 5500 PRINT"{down} when{down}{left*4}{cm u*4}{up} to interrupt the {reverse on}6510{reverse off} via" 5510 PRINT"{down} the irq{up}{left*3}{F*3}{down} pin.":GOSUB50000 : 5520 PRINT"{down} ..when the timers count down to zero":GOSUB50000 5530 PRINT"{down} ..or a flag{up}{left*4}{F*4}{down} goes low..":GOSUB50000 5540 PRINT"{down} ..or the {reverse on}serial port{reverse off} has" 5550 PRINT"{down}{space*3}collected 8 bits=1 byte.":GOSUB50000 5560 PRINT"{down}Qall this info needs to be given to" 5570 PRINT"{down} the {reverse on}6526{reverse off}{.*3}by writing to the" 5580 PRINT"{down} {reverse on}i{reverse off}nterrupt {reverse on}c{reverse off}ontrol {reverse on}r{reverse off}egister (icr).":GOSUB50000 5590 PRINT"{clear}{down*2}Qif we are to collect 8 bits" 5600 PRINT"{down} (=1 byte) until the {reverse on}6510{reverse off} can read" 5610 PRINT"{down} it, then where should we store it?":GOSUB50000 5620 PRINT"{down}Qin yet another register, of course!" 5630 PRINT"{down} the {reverse on}serial data register{reverse off}.":GOSUB50000:ms$="finished?":GOSUB63300 5640 PRINT"{clear}{down}Qfinally (2 more registers to go!)" 5650 PRINT"{down} we need to tell the {reverse on}6526{reverse off} how we" 5660 PRINT"{down} want the two 2-byte timers to work.":GOSUB50000 5670 PRINT"{down}Qthings like:" 5680 PRINT"{down}Qwhen to start/stop them.":GOSUB50000 5681 PRINT"{down}Qsend timer output to a port pin.":GOSUB50000 5682 PRINT"{down}Qlet timer b count {reverse on}cnt{reverse off} pulses.":GOSUB50000 5683 PRINT"{down}Q..or maybe count {reverse on}phase 2 clock pulses.":GOSUB50000 5684 PRINT"{down}Q..or maybe count the times that" 5685 PRINT"{down}{space*3}timer a 'zeros out'..":GOSUB50000 5690 PRINT"{clear}{down*4}Qso{.*3}we have two more registers which" 5700 PRINT"{down} control these two timer operations:" 5710 PRINT"{down*3} {reverse on}control register a" 5711 PRINT"{down} {reverse on}control register b" 5720 ms$="{reverse on}altogether{reverse off}":GOSUB50000:GOSUB63300 6000 GOSUB63100:REM micros-6 6001 sn$="06{0*3}" 6005 t$="cia registers":GOSUB63000 6010 GOSUB54400:FORi=0TO15:PRINTr$(i):GOSUB50000:NEXT 6020 ms$="whattachip":GOSUB63300 7000 GOSUB63100:REM micros-7 7001 sn$="07{0*3}" 7005 t$="the tape drive":GOSUB63000 7010 PRINT"{down*2}Qthis is a serial port too," 7020 PRINT"{down} with each byte going to the tape unit" 7030 PRINT"{down} as 8 bits{.*3}one after the other." 7040 PRINT"{down}Qthe tape drive needs four control" 7050 PRINT"{down} signals:":GOSUB50000 7060 PRINT"{down}Qa signal to turn on/off the motor.":GOSUB50000 7070 PRINT"{down}Qa serial write{down}{left*5}{cm u*5}{up} line":GOSUB50000 7080 PRINT"{down}Qa line to read{down}{left*4}{cm u*4}{up}":GOSUB50000 7090 PRINT"{down}Qa line to sense if any button" 7100 PRINT"{down} has been pushed down!":GOSUB50000:GOSUB63000:PRINT"{down*2}" 7105 PRINTSPC(18)"{reverse on}p{down}{left}o{down}{left}r{down}{left}t" 7110 PRINT"{home}{down*4}{reverse on}cassette motor{reverse off}{sh asterisk*3}{cm w}":GOSUB50000 7111 PRINT"{reverse on}cassette sense{reverse off}{sh asterisk*3}{cm w}":GOSUB50000 7112 PRINT"{reverse on}cassette write{reverse off}{sh asterisk*3}{cm w}":GOSUB50000 7113 PRINT"{reverse on}cassette read {reverse off}{sh asterisk*3}{cm w}":GOSUB50000 7114 PRINT"{reverse on}..and +5 volts{reverse off}{sh asterisk*3}{cm w}":GOSUB50000 7115 PRINT"{reverse on}{.*3}ground{space*5}{reverse off}{sh asterisk*3}{cm w}":GOSUB50000 7120 PRINT"{down*3}Qand where do the{sh space}top 4 signals" 7130 PRINT"{down} go to{.*3}in the c64?":GOSUB50000 7140 PRINT"{down}{.*3}to the {reverse on}6510{reverse off}!!":GOSUB50000 7150 PRINT"{clear}{down*5}well{.*3}sort of{.*3}":FORt=1TO1000:NEXT 7160 PRINT"{clear}{down*2}the {reverse on}6510{reverse off} has (believe it or not)" 7170 PRINT"{down} an input/output port built right in!" 7175 PRINT"{down} (6 bits worth)":GOSUB50000 7180 PRINT"{down} and even a {reverse on}data direction register{reverse off}!" 7190 PRINT"{down}Qmotor control,sense and write lines" 7200 PRINT"{down} go to 3 pins of the {reverse on}6510{reverse off} i/o port." 7210 PRINT"{down}Qthe read{down}{left*4}{cm u*4}{up} line (an 'input'" 7220 PRINT"{down} from the tape drive) goes to a..":GOSUB50000:ms$="{space*2}ready?" 7230 PRINT"{home}{down*18} flag{up}{left*4}{F*4}{down} input of {reverse on}cia #1{reverse off}!":GOSUB50000 7235 t$="6510 i/o port":GOSUB63000:PRINT"{down}" 7236 PRINT"{sh asterisk*4}{cm s}" 7240 PRINT"{reverse on}6{reverse off}{space*2}5{cm q}{sh asterisk*2}" 7241 PRINT"{reverse on}5{reverse off}{space*2}4{cm q}{sh asterisk*2}" 7242 PRINT"{reverse on}1{reverse off}{space*2}3{cm q}{sh asterisk*2}" 7243 PRINT"{reverse on}0{reverse off}{space*2}2{cm q}{sh asterisk*2}" 7244 PRINT"{space*3}1{cm q}{sh asterisk*2}" 7245 PRINT"{space*3}0{cm q}{sh asterisk*2}" 7250 y=8:x=7:m$="{reverse on}cass. write":GOSUB54300:GOSUB50000:GOSUB54310 7260 y=7:x=6:m$="{reverse on}{arrow left}cass. sense":GOSUB54300:GOSUB50000:GOSUB54310 7270 y=6:x=7:m$="{reverse on}cass. motor":GOSUB54300:GOSUB50000:GOSUB54310 7280 PRINTp$"Qand the first":PRINTp$"{down}three pins":PRINTp$"{down*2}of this 6510 port?" 7285 GOSUB50000:m$="":GOSUB54310 7290 y=11:x=7:m$="{reverse on}loram":GOSUB54300:PRINTp$"Qenable/disable" 7300 PRINTp$"{down}the rom at":PRINTp$"{down*2}$8{0*3}-$9{f*3}!" 7305 ms$="remember?":GOSUB63200:GOSUB50000:GOSUB54310 7310 y=10:x=7:m$="{reverse on}hiram":GOSUB54300:PRINTp$"Qenable/disable" 7320 PRINTp$"{down}the rom at":PRINTp$"{down*2}$a{0*3} & $e{0*3}!" 7325 GOSUB63200:GOSUB50000:GOSUB54310 7330 y=9:x=7:m$="{reverse on}charen":GOSUB54300:PRINTp$"Qenable/disable" 7340 PRINTp$"{down}the character":PRINTp$"{down*2}rom!!":GOSUB63200:GOSUB50000 7360 PRINT"{home}{down*12}..and the data direction?":GOSUB50000:GOSUB55300 7365 PRINT"{home}{down*5}{right}"LEFT$(rg$,30)"{cm t*2}" 7370 PRINT"{home}{down*14}10{1*4}=out in out out out out":GOSUB50000 7375 t$="the 6510 i/o port":GOSUB63000 7380 PRINT"{down*2}Qand where is this i/o port 'inside'" 7390 PRINT"{down} the {reverse on}6510{reverse off}?":PRINT"{down}Qto read/write to this port we" 7400 PRINT"{down}{reverse on} poke 1 {reverse off} or {reverse on} peek 1 " 7410 PRINT"{down} (it 'responds' to location one).":GOSUB50000 7420 PRINT"{down}Qand the data direction register?":GOSUB50000 7430 PRINT"{down}{reverse on} poke 0{reverse off} or {reverse on}peek 0{reverse off}":PRINT"{down}(it 'responds' to location zero!)" 7440 PRINT"{down}10{1*4}=out in out out out out":PRINT"{down}Qso peek(0)=47" 7450 GOSUB50000:PRINT"{clear}{down*6}Qthis {reverse on}6510{reverse off} is some chip!":ms$="some chap" 7460 GOSUB50000:GOSUB63200 7470 PRINT"{clear}{down*6}Qbut that's{down}{left*6}{cm u*6}{up} another story!" 49000 ms$="au revoir!{home}":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 51120 PRINT"{down} which (by micro standards) is plenty" 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 54000 PRINT"{home}{down*3}"; 54010 PRINT"dataQ{sh asterisk*2} 54020 PRINT"{sh asterisk}bus{sh -} {cm a}{sh asterisk}+5 volts 54030 PRINT"{sh asterisk*2}Q.{sh -} {sh -} 54040 PRINT" {cm a}{cm e*3}{sh asterisk}{cm e}{sh asterisk*3}{cm s} 54050 PRINT" {sh -}FF{space*6}{cm q}{sh asterisk*2}" 54060 PRINT"{sh asterisk}{cm w}ceR{space*5}{cm q}..port a" 54070 PRINT"{sh asterisk}{cm w}r/w{space*5}{cm q}{sh asterisk*2}" 54080 PRINT"{sh asterisk}{cm w}clock{space*3}{sh -}{space*2}{F*4}" 54090 PRINT" {sh -}{F*3}{space*5}{cm q}{arrow left}{sh asterisk}flag" 54100 PRINT"{arrow left}{cm w}irq{space*5}{cm q}{sh asterisk*2}sp " 54110 PRINT" {sh -}{space*8}{cm q}{sh asterisk*2}cnt" 54120 PRINT"{sh asterisk}{cm w}a3{space*6}{cm q}{sh asterisk*2}pc" 54130 PRINT"{sh asterisk}{cm w}a2{space*6}{cm q}{sh asterisk*2}" 54140 PRINT"{sh asterisk}{cm w}a1{space*6}{cm q}..port b" 54150 PRINT"{sh asterisk}{cm w}a0{space*6}{cm q}{sh asterisk*2} 54160 PRINT" {cm z}{cm r}{sh asterisk*4}{cm r}{sh asterisk*2}{cm x} 54170 PRINT"{space*2}^{space*4}{sh -} 54180 PRINT" {F*5} ground" 54190 PRINT" reset 54200 RETURN 54300 PRINTLEFT$(d$,y)RIGHT$(r$,x)m$:RETURN 54310 PRINTp$;:FORi=1TO5:PRINTbl$;:NEXT 54320 m$=MID$(m$,2):GOSUB54300:RETURN 54400 DIM r$(15):r$(0)="{down}{reverse on}0{reverse off}:peripheral register a" 54401 r$(1)="{reverse on}1{reverse off}:peripheral register b" 54402 r$(2)="{reverse on}2{reverse off}:data direction register a" 54403 r$(3)="{reverse on}3{reverse off}:data direction register b" 54404 r$(4)="{reverse on}4{reverse off}:timer a:lo byte" 54405 r$(5)="{reverse on}5{reverse off}:timer a:hi byte" 54406 r$(6)="{reverse on}6{reverse off}:timer b:lo byte" 54407 r$(7)="{reverse on}7{reverse off}:timer b:hi byte" 54408 r$(8)="{reverse on}8{reverse off}:10ths of seconds" 54409 r$(9)="{reverse on}9{reverse off}:seconds" 54410 r$(10)="{reverse on}a{reverse off}:minutes" 54411 r$(11)="{reverse on}b{reverse off}:hours & am/pm" 54412 r$(12)="{reverse on}c{reverse off}:serial data register" 54413 r$(13)="{reverse on}d{reverse off}:interrupt control register" 54414 r$(14)="{reverse on}e{reverse off}:control register a" 54415 r$(15)="{reverse on}f{reverse off}:control register b" 54416 RETURN 55000 PRINT"{sh asterisk*9}Q{sh asterisk} 55010 PRINT"{sh asterisk*8}Q{sh +}{sh asterisk} 55020 PRINT"{sh asterisk}data{sh asterisk*2}Q{sh +*2}{sh asterisk} 55030 PRINT"{sh asterisk}bus {sh asterisk}Q{sh +*3}{sh asterisk} 55040 PRINT"{sh asterisk*5}Q{sh +*4}{sh asterisk} 55050 PRINT"{sh asterisk*4}Q{sh +*5}{sh asterisk} 55060 PRINT"{sh asterisk*3}Q{sh +*6}{sh asterisk} 55070 PRINT"{sh asterisk*2}Q{sh +*7}{sh asterisk} 55080 PRINT" {cm a}{cm e*8}{sh asterisk*5}{cm s} 55090 PRINT" {sh -}FF{space*11}{cm q}{sh asterisk*2} 55100 PRINT"{sh asterisk}{cm w}ce{space*11}{cm q}{sh asterisk*2} {reverse on}p" 55101 PRINT" {sh -}{space*2}F{space*10}{cm q}{sh asterisk*2} {reverse on}o" 55102 PRINT"{sh asterisk}{cm w}r/w{space*10}{cm q}{sh asterisk*2} {reverse on}r" 55103 PRINT" {sh -}{space*13}{cm q}{sh asterisk*2} {reverse on}t" 55104 PRINT" {sh -}{space*13}{cm q}{sh asterisk*2}" 55110 PRINT" {sh -}{space*13}{cm q}{sh asterisk*2} {reverse on}b" 55120 PRINT"{sh asterisk}{cm w}a3{space*11}{cm q}{sh asterisk*2}" 55150 PRINT"{sh asterisk}{cm w}a2{space*11}{sh -}" 55160 PRINT"{sh asterisk}{cm w}a1{space*11}{sh -}" 55170 PRINT"{sh asterisk}{cm w}a0{space*11}{sh -}{home}" 55200 bl$="":FORi=1TO39:bl$=bl$+" ":NEXT:GOSUB55300 55210 d$="{home}{down*13}":c$="{right*13}":PRINTd$c$rg$"{reverse on}prb" 55220 PRINTd$LEFT$(c$,9)rg$"{left}{reverse on}ddrb":s$="{home}{down*4}{right*15}":RETURN 55300 b$="OP{down}{left*2}":rg$="":FORi=1TO8:rg$=rg$+b$:NEXT:rg$=rg$+"{cm t*2}{down}{left*3}":RETURN 56000 PRINT" $dd00(56576)={reverse on}port a{reverse off}" 56001 PRINT" $dd01(56577)={reverse on}port b{reverse off}" 56002 PRINT" $dd02(56578)={reverse on}ddra{space*2}" 56003 PRINT" $dd03(56579)={reverse on}ddrb{space*2}" 56004 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 63110 d$="{home}":FORi=1TO25:d$=d$+"{down}":NEXT 63120 r$="":FORi=1TO40:r$=r$+"{right}":NEXT:p$="{home}{down*3}{right*20}" 63130 bl$="{space*18}{down}{left*18}" 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)