home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / Information / 256KB.INSTUCTIONS < prev    next >
Encoding:
Text File  |  2019-04-13  |  59.0 KB  |  1,246 lines

  1.                256 kB memory expansion for Commodore 64
  2.                                    
  3.                    Pekka Pessi <Pekka.Pessi@HUT.FI>
  4.            Marko MΣkelΣ <Marko.Makela@Helsinki.FI>
  5.                                    
  6.                        January--February, 1987
  7.                             July 3rd, 1993 (*)
  8.  
  9. Commodore 64 becomes remarkably more efficient by adding memory to it.
  10. Then the worst slow-down, incredibly slow disk drive, can be worked
  11. around by using a part of the memory as a RAM disk.
  12.  
  13. In 1986, when the original article was written, there were no
  14. commercial memory extensions for sale in Finland. (Commodore's RAM
  15. Expansion Units came to our market in the year 1987.) Of course there
  16. were some in the USA, but they were quite useless, as they had only 64
  17. kB of memory, and the price was high as well. When built by oneself,
  18. the following memory expansion should have costed 300--400 Finnish marks.
  19.  
  20.   One American dollar (USD) is equivalent to five or six Finnish
  21.   marks (FIM). I constructed my expansion in 1993 March, and it
  22.   costed 111 FIM. It could easily have been about 20 FIM cheaper.
  23.  
  24. Many goals were set to the expansion. As many programs as possible
  25. should work also with it installed. This means that there could not be
  26. any radical changes to the memory map.
  27.  
  28. The memory space of an expanded machine really remains same for a
  29. usual programmer. After reset, the computer doesn't differ from an
  30. unexpanded one practically at all.
  31.  
  32. Even taking a look at the machine from outside doesn't reveal the
  33. expansion, as Pekka needed the expansion port for his IEEE-488
  34. interface module, also designed by himself.
  35.  
  36. The memory expansion is built in the machine on two add-on cards. As
  37. the mother board remains the same --- no traces are cut --- the
  38. expansion can be removed without a soldering iron.
  39.  
  40. The design aimed to a hardware that supports programming. While making
  41. the RAM disk program, Pekka changed the hardware several times, until
  42. he was satisfied with it.
  43. ---
  44. * This document is based on Pekka Pessi's two articles published in
  45.   the largest Nordic and Finnish home computer users' magazine,
  46.   MikroBITTI, in its first two issues of the year 1987.
  47.   Six years later, it was translated to English and edited by
  48.   Marko MΣkelΣ, with help from Pekka Pessi.
  49.  
  50. You can retrieve this document in PostScript format via anonymous FTP.
  51. The files are at FUNIC.FUnet.FI in the directory /pub/cbm/documents/256kB.
  52.  
  53. Contents
  54.  
  55. 1 Some basics
  56.   1.1 Expansion memory in 16 kB blocks
  57.   1.2 Memory chips
  58.   1.3 Dynamic headaches
  59.   1.4 Memory refresh
  60.  
  61. 2 Building the expansion
  62.   2.1 Removing the old memory chips
  63.   2.2 Adding the new address line
  64.   2.3 Prepare to the final step
  65.   2.4 Testing
  66.  
  67. 3 Using the expansion
  68.   3.1 The operation of the bank switcher
  69.    3.1.1 PIA's location in memory space
  70.    3.1.2 Block selection
  71.    3.1.3 Startup settings
  72.   3.2 Segmented memory
  73.   3.3 Critical addresses
  74.   3.4 Initializing the expansion
  75.   3.5 Programming in machine language
  76.    3.5.1 An exception: VIC memory
  77.   3.6 Programming in BASIC
  78.  
  79. 4 Programming examples
  80.   4.1 Processing a huge array
  81.   4.2 Storing graphics
  82.  
  83. 5 RAM disk and other programs
  84.   5.1 Memory test
  85.   5.2 Poor man's multitasking
  86.   5.3 Machine language monitor
  87.   5.4 RAM disk
  88.    5.4.1 Disk copiers
  89.  
  90. 6 Other expansions
  91.   6.1 New operating system
  92.  
  93. 7 Contacting the authors
  94.  
  95. 1 Some basics
  96.  
  97. 1.1 Expansion memory in 16 kB blocks
  98.  
  99. The processor of Commodore 64, MOS 6510, is a 8-bit one, and its
  100. address bus is 16 bits wide. As other 8-bit processors, it can address
  101. only 64 kB of memory at a time. In the most 8-bit computers, the
  102. memory is limited to these 64 kB. How could one add memory above this
  103. limit?
  104.  
  105. The solution is simple: the memory is divided into banks of not more
  106. than 64 kB, which are switched on and off. Some processors have been
  107. added a special circuit for this purpose, in which case the executing
  108. program can be in its own 64 kB block and the processed data in
  109. another block. For example, MOS 6509, a fellow processor of MOS 6510,
  110. works in this way, enabling access to one megabyte.
  111.  
  112. After trial and error Pekka decided to divide the extended memory to
  113. sixteen blocks of sixteen kilobytes each. The processor can address
  114. four of them at a time. Every four 16 kB segment of the memory space
  115. can be mapped to any 16 kB block. Figure 1 shows the mapping right
  116. after startup. A similar memory mapping is in MSX II computers.
  117.  
  118. However, the video chip VIC -- MOS 6567 (6566 for NTSC) -- retrieves
  119. its data from the memory outside the normal bus. The internal address
  120. registers of VIC are 14 bits wide, so it can address only 16 kB
  121. without external logic. The required two extra bits for accessing 64
  122. kB are provided from the second CIA chip. The extra logic provides
  123. additional two address bits for accessing the whole 256 kB of memory.
  124.  
  125.           6510's RAM           RAM pool            VIC's RAM
  126.  
  127.         +--$10000 --+       +-- $40000 --+       +--$10000 --+
  128.         |           |  /--->| Segment  F |<---\  |           |
  129.         |  Block 3  |-/     +-- $3C000 --+     \-|  Block 0  |
  130.         |           |  /--->| Segment  E |<---\  |           |
  131.         +-- $C000 --+  |    +-- $38000 --+    |  +-- $C000 --+
  132.         |           |  |/-->| Segment  D |<--\|  |           |
  133.         |  Block 2  |-/ |   +-- $34000 --+   | \-|  Block 1  |
  134.         |           |   |/->| Segment  C |<-\|   |           |
  135.         +-- $8000 --+   ||  +-- $30000 --+  ||   +-- $8000 --+
  136.         |           |   ||  | Segment  B |  ||   |           |
  137.         |  Block 1  |--/ |  +-- $2C000 --+  | \--|  Block 2  |
  138.         |           |    |  | Segment  A |  |    |           |
  139.         +-- $4000 --+    |  +-- $28000 --+  |    +-- $4000 --+
  140.         |           |    |  | Segment  9 |  |    |           |
  141.         |  Block 0  |---/   +-- $24000 --+   \---|  Block 3  |
  142.         |           |       | Segment  8 |       |           |
  143.         +-- $0000 --+       +-- $20000 --+       +-- $0000 --+
  144.                             | Segment  7 |
  145.                             +-- $1C000 --+
  146.                             | Segment  6 |
  147.                             +-- $18000 --+
  148.                             | Segment  5 |
  149.                             +-- $14000 --+
  150.                             | Segment  4 |
  151.                             +-- $10000 --+
  152.                             | Segment  3 |
  153.                             +-- $0C000 --+
  154.                             | Segment  2 |
  155.                             +-- $08000 --+
  156.                             | Segment  1 |
  157.                             +-- $04000 --+
  158.                             | Segment  0 |
  159.                             +-- $00000 --+
  160.  
  161.             Figure 1. Memory mapping right after power-up
  162.  
  163.                    4164                       41256
  164.                 +--------+                 +--------+
  165.              NC | 1 \/ 16| VSS         MA8 | 1 \/ 16| VSS
  166.               D | 2    15| -CAS          D | 2    15| -CAS
  167.              -W | 3    14| Q            -W | 3    14| Q
  168.            -RAS | 4    13| MA6        -RAS | 4    13| MA6
  169.             MA0 | 5    12| MA3         MA0 | 5    12| MA3
  170.             MA2 | 6    11| MA4         MA2 | 6    11| MA4
  171.             MA1 | 7    10| MA5         MA1 | 7    10| MA5
  172.             VDD | 8     9| MA7         VDD | 8     9| MA7
  173.                 +--------+                 +--------+
  174.  
  175.    Figure 2. The Dynamic Random Access Memory Chips 4164 and 41256
  176.  
  177. 1.2 Memory chips
  178.  
  179. Commodore 64 uses 64 kb dynamic RAM chips of JEDEC standard. In 1982,
  180. when the Commodore 64 was introduced, they were most modern
  181. technology, they needed only one operating voltage supply instead of
  182. traditional three.
  183.  
  184. The semiconductor memories have developed fast, however, and now a
  185. chip in a DIP of equal size can hold 256 kilobits. The pinout of these
  186. 256 kb chips differs minimally from the 64 kb ones. The smaller 64 kb
  187. chips, at least the ones used in Commodore 64, have one unused
  188. contact. The address line to handle three times bigger memory is tied
  189. to this pin. In the DRAMs the address lines are multiplexed: two
  190. address bits use successively the same pin.
  191.  
  192. In the MikroBITTI article Pekka wrote that 256 kb chips are rather
  193. cheap, and the price would lower as the production rate increases.
  194. Nowadays the production must have almost stopped. When Pekka bought
  195. his chips  between March and April of 1986, they costed about 50 FIM
  196. each. When the original article was published, they costed less than
  197. 20 FIM. After that the prices rised due to a memory shortage. But
  198. nowadays the chips don't cost practically anything, if you're lucky.
  199. Many users of IBM PC compatibles want to upgrade their system memory
  200. with 1 Mb chips or alike and would like to get rid of their old 256 kb
  201. chips. I bought my chips second-hand with total 35 FIM. The lowest
  202. price of unused chip I encountered was 13 FIM a piece and the highest
  203. was 30 FIM, almost 8 times the price I paid!
  204.  
  205. The 256 kb chips don't consume significantly more power, so there is
  206. no need for a bigger power supply. However, devices that take their
  207. power directly from the computer can cause problems. You can find this
  208. out by experimenting.
  209.  
  210. The speed of the chips doesn't prevent the replacement either.
  211. According to the Commodore 64 Programmer's Reference Guide, the
  212. computer can use chips with access time of 200 nanoseconds. Even the
  213. slowest 256 kb dynamic RAMs are not that slow.
  214.  
  215. However, the bypass capacitors near the memory chips should be
  216. replaced with bigger ones. The 100 nF capacitors specified in the
  217. original Commodore schematic diagram would be big enough. All shipped
  218. units seem to be equipped with only 10 nF capacitors. (My machine
  219. works well, even though I haven't replaced any capacitors.)
  220.  
  221. 1.3 Dynamic headaches
  222.  
  223. The dynamic RAM chips are organized in rows and columns. In 64 kb
  224. chips, a row is 256 bits wide, and in 256 kb ones it is 512 bits wide.
  225. Also the memory address is divided into row and column addresses. When
  226. we access a bit in the dynamic RAM, the row address is asserted before
  227. the column address. Fortunately the VIC chip generates needed -RAS 
  228. (Row Address select) and -CAS (Column Address Select) timing signals
  229. from the DOTCLOCK and PhiCOLOR signals.
  230.  
  231. 1.4 Memory refresh
  232.  
  233. A dynamic memory chip stores the data bits as charged tiny capacitors,
  234. which discharge among the time. The data must be refreshed
  235. periodically, every 2--4 milliseconds, by recharging the capacitors.
  236.  
  237. If the whole contents of the memory was refreshed simultaneously, the
  238. power peak would cause enormous problems. Only a block of one or two
  239. rows can be refreshed at a time. The 64 kb chips have 128 blocks to be
  240. refreshed, which implies a 7-bit refresh counter (2^7 equals 128).
  241.  
  242. In order to avoid disturbance, 256 kb chips must have more blocks.
  243. Thus they require a longer refresh counter (8 bits). As the amount of
  244. refresh cycles has increased, the capacitors' ability of keeping
  245. charge has been improved. The 64 kilobit DRAMs required 128 refresh
  246. cycles every 2 milliseconds, now the 256 kb chips need 256 cycles but
  247. every 4 ms.
  248.  
  249. 2 Building the expansion
  250.  
  251. Remember that the warranty expires if you start modifying the
  252. connections. If the warranty is still valid, consider and reconsider,
  253. before you expand the memory. You are doing the expansion at your own
  254. risk, we disclaim any warranties. You should have basic skills in
  255. electronics.
  256.  
  257. A termostate soldering iron, desoldering pump or other desoldering
  258. tool, a screwdriver and a spoon are the only tools needed. The spoon
  259. is for removing the chips. A bottle top remover is not suitable for
  260. that.
  261.  
  262.   A tiny screwdriver is equally good. Just insert the screwdriver tip
  263.   under one end of the chip and wound it a bit in upward angle so that
  264.   the chip moves slightly. Then insert it to the other end of the chip
  265.   and try to lift it a bit. You may have to repeat this procedure.
  266.  
  267. There are two PC (printed circuit) boards. They are single-sided and 
  268. relatively simple. The board A should suit all machines, also the
  269. new 64C.
  270.  
  271.   There is at least one new 64C board model which the boards do
  272.   not suit directly. In addition to that, the new 64s may use so
  273.   heavily integrated circuits that even modifying the add-on board 
  274.   layout slightly would not work.
  275.  
  276. Board B1 is for rather new machines, whose serial number is between
  277. 250 000 and 2 000 000. The other board B2 is for old machines with an
  278. old motherboard and a serial number usually less than 100 000. Such
  279. machines have usually been purchased in the beginning of 1983 or
  280. before that. If neither board suits, the board B can be easily made
  281. from a Vero board, as it is so simple.
  282.  
  283.   I used a single board, although the `new' board would have suited
  284.   well; the need for board B was eliminated by bending some feet of 
  285.   U13 and connecting wires from the other board directly to U12, 
  286.   U13 and U15.
  287.  
  288.   Even board A can be made from a Vero board, as we have done. But be
  289.   careful, an uncoppered Vero board is not so solid. Every time you
  290.   open the cover, some wires may get loose. I have had to re-solder
  291.   many wires, almost every time I have opened the lid. Soldering with
  292.   plenty of solder ought to cure this, but be careful to avoid short
  293.   circuits.
  294.  
  295. The installation begins of course by opening the machine and removing
  296. the keyboard and LED cables. It is useful to memorize, photograph or
  297. draw how the parts were initially connected.
  298.  
  299. After removing the cables, open the screws that hold the motherboard
  300. with the case, and remove the board.
  301.  
  302. 2.1 Removing the old memory chips
  303.  
  304. First you have to remove the memory chips U9, U10, U11, U12, U21, U22,
  305. U23 and U24. They are of type 4164 (or 6665 or 6664 or 8064 or...).
  306.  
  307.   Open your machine and take a look at its mother board, as if you
  308.   were typing. The board A is installed on the top of U2, a MOS 6526
  309.   CIA chip, the second chip at rear left. The memory chips are the
  310.   rightmost eight of the ten leftmost small chips at the front of your
  311.   computer. The board B is placed on U12, U13 and U15, which are at
  312.   the right of the RAM block.
  313.  
  314. If these memory chips are already on sockets, the most of the work is
  315. done for you. It helps a lot, if you remove the bypass capacitors
  316. before removing the chips. You should replace them with bigger ones,
  317. even with tantal capacitors. Removing the components is easiest with a
  318. desoldering pump. It becomes even easier, when you first solder the
  319. pins with fresh solder, so that the hartz from it makes the removal of
  320. old solder easier. Using much power is questionable, as the copper
  321. folio comes off the board in a surprisingly easy way.
  322.  
  323. After you have removed the 4164s, you can solder the 16-pin sockets
  324. into their places. You can solder the capacitors back as well, if you
  325. removed them.
  326.  
  327. 2.2 Adding the new address line
  328.  
  329. You must connect the pin 1 of each memory chip socket. It is the extra
  330. address line (MA8) to the switcher. The best way is to solder a
  331. Wire-Wrap wire to each contact under the mother board, but any thin
  332. and pliable uni-strand wire should do. The wire does not affect in any
  333. way the computer's operation with 64 kb chips.
  334.  
  335. After the pins have been connected together, they must be temporarily
  336. connected to +5 V, which is in the pin 8 of the memory chips.
  337. Comparing to TTL chips, the operating voltages are `reversed' in
  338. dynamic memories.
  339.  
  340. Now the new 256 kb memory chips can be installed to the sockets
  341. (preferably right-side forward), and you can try switching the power
  342. on.
  343.  
  344. 2.3 Prepare to the final step
  345.  
  346. You do not have to connect anything except the power cable and the
  347. cable to the TV set or monitor. If the screen shows up normally, you
  348. may not (yet) have made any mistakes. If it does not show up at all,
  349. you have to find possible cut-outs and shorts. Multi-colored
  350. `@'s show up usually because of too small bypass capacitors. Another
  351. cause is that the pin 1 is not connected to +5 V. In this case the
  352. screen may come up normally, but a little disturbance in the
  353. operating voltage locks the computer locks up.
  354.  
  355. Next you remove U13 (74LS257), U15 (74LS139) and U2 (M6526). Some of
  356. these chips may already be on sockets but you must remove the rest.
  357. After this step reinsert the chips and check if the machine boots up.
  358.  
  359. On the Board A the chip U2 (M6526) and on Board B chips U12 and U15
  360. can be installed into Wire-Wrap sockets. With them you can connect the
  361. chips to the motherboard handily and easily. The chip is then put in
  362. the socket, and it is on its normal place, although one and a half
  363. centimeters higher. However, inserting a Wire-Wrap socket in a normal
  364. socket destroys it so that you cannot insert a normal chip there any
  365. more. If you want to make your board removable, you would better use
  366. piggyback sockets everywhere.
  367.  
  368.   Piggyback sockets are a kind of IC sockets which have pins on
  369.   both sides. You can insert other pins to the socket on the
  370.   motherboard and solder another pins to the daughterboard.
  371.  
  372. U13 is put on a normal socket, and a 16-pin piggyback socket is installed
  373. next to it so that the pins of the piggyback socket reach the socket
  374. that is on the motherboard.
  375.  
  376. The boards can be connected together with a fixed cable, but the best
  377. way is using flat ribbon cable and connectors. (The worst way to use
  378. stiff uni-strand wires, as I did.)
  379.  
  380. 2.4 Testing
  381.  
  382. After you have installed the boards to your machine, it is time to
  383. test the connections. You can connect LED, keyboard and probably disk
  384. drive in addition to the power cable and the TV cable, but do not
  385. fasten the mounting screws yet. If the screen shows up and if the
  386. machine seems to operate, remove the jumper between MA8 and +5 V. Then
  387. you can input the following test program:
  388.  
  389.         10 PB=57282
  390.         20 POKE PB,255:POKE PB+1,4:POKE PB,255
  391.         30 PRINT"PRESS A KEY AFTER THIS HAS DISAPPEARED":
  392.            FOR I=0 TO 3000:NEXT
  393.         40 POKE PB,14:WAIT 198,15:GET A$:POKE PB,255
  394.  
  395. On the line 10 a variable PB is set up. It is the address of 6821's
  396. port B's peripheral register, data direction register, and the block
  397. selection register of segments 2 and 3 and VIC.
  398.  
  399. The line 20 contains initialization of PIA: the lines PB0--PB7 are set
  400. outputs, the data direction register is switched to data register with
  401. `POKE PB+1,4', and the PB lines are set high.
  402.  
  403. On the line 40 VIC is given block 0 ($00000--$0FFFF), and then the
  404. program waits for a keypress and restores the block F ($30000--$3FFFF).
  405.  
  406. If this test program works as expected, the screen is filled with 
  407. `@'s and other random characters.
  408.  
  409. After this test you may want to run the `TEST' program among the
  410. distribution files. (See Section 5.1.)
  411.  
  412. 3 Using the expansion
  413.  
  414. 3.1 The operation of the bank switcher
  415.  
  416. There are four new micro chips in the memory expansion. The most
  417. important of them is the PIA chip MC6821, which holds the values of
  418. block selections. PIA has two 8-bit ports set up in the addresses
  419. 57280 and 57282. The upper and lower four bits (nybbles) of each port
  420. determine, which 16 kB block is mapped to each 16 kB segment of C64's
  421. memory space. IC2 and IC3 participate in forming the memory block
  422. control signals.
  423.  
  424. There is a chip equivalent to PIA even in the processor's own 6500
  425. series, but it is not suitable for this connection, as it is not TTL 
  426. compatible. The 6821 from Motorola 6800 series, which contains also 
  427. processors reminding the 6502 and 6510, is bus compatible and suitable
  428. for this purpose.
  429.  
  430. Commodore 64 asserts the 16 bit addresses to the original 64 kb chips
  431. in two parts. First it asserts the lower eight bits, then the higher
  432. eight. The 256 kb chips require two additional address bits, so the 
  433. chips are given nine bits at a time. Due to this address multiplexing 
  434. the block selection bits cannot be directly input to the memory chips,
  435. but they must be lead through the multiplexer circuitry of IC2, IC3
  436. and U13.
  437.  
  438. IC4 contributes to the operation during power-up. It ensures that C64
  439. gets reasonable memory banks to its different segments. In the
  440. beginning the segments are filled with four upmost memory banks.
  441.  
  442. 3.1.1 PIA's location in memory space
  443.  
  444. PIA's data bus and E, -RESET and R/-W signals have been connected
  445. directly to the processor chip. (Pekka had made a prototype of board A
  446. that interfaces to the 6510 chip instead of the 6522.) Similarly are
  447. the RS0 and the RS1, which select a PIA register, connected to A0 and A1.
  448.  
  449. The I/O block decoder (U15) tells us when the second I/O block is
  450. selected. This block resides in the area $DF00--$DFFF. The signal
  451. -I/O2 is connected to PIA's chip selection pin -CS, and it forms most
  452. of PIA's addressing. The address lines A6 and A7 limit PIA's area in
  453. I/O2 to $DFC0--$DFFF, because they are tied to CS pins.
  454.  
  455. 3.1.2 Block selection
  456.  
  457. As the memory space has been divided to four blocks of 16 kB, the A14
  458. and A15 cannot be lead directly to the memory chips, but they
  459. participate in the block selection. These two address bits determine
  460. which of the four blocks is in use. For each block, the PIA ports tell
  461. which memory bank to map. Original A14 and A15 are connected to IC2
  462. and IC3, which select the right output lines of PIA. For each 16 kB
  463. segment there are 4 output lines which form the block address for the
  464. segment.
  465.  
  466. IC2 selects two lowest bits of the block address and feeds them to the
  467. address multiplexer chip U13 as B14 and B15. They are practically
  468. equivalent to the A14 and A15 signals. After the address bits A0--A7
  469. have been asserted during the first addressing cycle, IC2 asserts B14
  470. and B15 during the second (CAS) cycle.
  471.  
  472. The 256 kb memory chips still need two extra address bits. The
  473. expansion must multiplex them with IC3, which is a `one-of-eight'
  474. multiplexer. Its eight inputs are tied to the two upmost bits of the
  475. four block addresses. A14 and A15 are connected to the IC3, but it
  476. needs yet another control signal to handle all eight input bits. This
  477. signal is -CAS, which controls multiplexing other address bits
  478. (MA0--MA7) as well.
  479.  
  480. While the -CAS signal is low and the memory chips are fed the lowest
  481. bits (A0--A7) of the address, the IC3 selects the third bit of the
  482. block address determined by A14 and A15. This bit is called address
  483. bit A16, and it is asserted to the `extra' address line MA8
  484. simultaneously with the lowmost bits. When -CAS is high, the upper
  485. address bits are fed, and IC3 selects the fourth bit of the block
  486. address determined by A14 and A15. It corresponds to the address bit 
  487. A17 and is fed through the same MA8 during all the other upmost bits. 
  488.  
  489. The resistor on MA8 line protects IC3, because the inputs of dynamic
  490. memories are not fully TTL compatible.
  491.  
  492. 3.1.3 Startup settings
  493.  
  494. In order to enable the operation of the machine, each of the four
  495. segments must be mapped to a unique memory bank. The Commodore 64
  496. tests the lowmost continuous area of writeable memory and would hang
  497. up, if the same bank was mapped to both $0000 and to $4000, for
  498. instance. Modifying the startup routines would cure this problem, but
  499. in that case the Kernal ROM chip should be changed.
  500.  
  501. The bootup state can be achieved otherwise. -RESET signal sets all the
  502. PIA port lines to inputs. As input a line has an impedance of several
  503. megaohms. A TTL chip reads such a signal as a logical `1'. IC4 can
  504. force four bank selection pins (PA0, PA1, PA5 and PB0) low, so that
  505. the memory segments of C64 point to the four upmost memory banks in
  506. ascending order. The port A contains the bits 1101 1100 and the 
  507. port B 1111 1110. As the IC4 has open collector outputs, it doesn't
  508. disturb the port's operation when outputting high state. That is why the 
  509. initialization routines (see Section 3.4) write the value 52 to the
  510. address 57281, which forces the IC4 outputs high by lowering the CA2 line.
  511.  
  512. 3.2 Segmented memory
  513.  
  514. The memory space of Commodore 64 consists of four 16 kB segments:
  515. $0000--$3FFF, $4000--$7FFF, $8000--$BFFF and $C000--$FFFF. An expanded
  516. C64 uses the topmost four 16 kB banks after startup. It considers them
  517. as its whole world and does not know anything of the other memory
  518. banks. Figure 1 describes the situation. A total of twelve memory
  519. banks are left out of the 64's world.
  520.  
  521. With expanded memory we can cheat the C64 by POKEing a suitable number
  522. to a known address to consider the lowmost block as the second
  523. segment, for example. Then all the operation that the C64 does at the
  524. second segment's area alter in fact the lowmost bank, although the
  525. Toad has no idea of it. This is the idea behind the whole expansion
  526. circuit.
  527.  
  528. What is the benefit of it? The second segment (segment 1) is actually
  529. a good example of the function, because it resides in the middle of
  530. the RAM reserved for BASIC programs. If we make a little BASIC program
  531. that holds an array exactly in the third segment, we can switch
  532. another memory bank to that area while the program is running, and we 
  533. have another 16 kilobytes to expand our table. In this manner all the 
  534. free memory banks (12 * 16 kilobytes) can be taken in use, and 
  535. the memory holds enormous arrays, which can be accessed simply by 
  536. switching the memory bank. See Example 4.1 for an example of this
  537. technique.
  538.  
  539. Another and more useful way to exploit the extra banks is to keep them
  540. as a RAM disk. A RAM disk means that you can copy even a whole disk to
  541. these banks and consider it as a new disk drive, from which you can
  542. load program and data at a very fast speed. For a RAM disk you need a 
  543. smart program that redirects disk commands and executes them on the 
  544. expanded memory. (See Section 5.4.)
  545.  
  546. 3.3 Critical addresses
  547.  
  548. The critical addresses of the device are 57280--57343 ($DFC0--$DFFF).
  549. There is the PIA chip to which you POKE the values to switch memory
  550. banks. The PIA does not have 64 registers, as one might think. There
  551. are sixteen copies of its 4 addresses in that memory area. For
  552. instance, the addresses 57280, 57284, 57288 and 57340 are equivalent
  553. to each other.
  554.  
  555. 57280 is a memory place whose lowmost four bits (bits 0--3, low nybble) 
  556. determine, which of the sixteen memory banks is accessed through the 
  557. lowmost segment (segment 0) of Commodore 64. The upper four bits 
  558. (bits 4--7, high nybble) specify, which of the banks show up at the
  559. second segment (segment 1). In a similar manner the low nybble of the
  560. address 57282 determines which bank resides at segment 2, and the high
  561. nybble tells the bank addressed via the upmost segment.
  562.  
  563. These addresses have even another function. They can act as data
  564. direction registers as well, i.e. tell if the port lines are inputs or
  565. outputs. However, this application uses only some of the PIA's
  566. characteristics. For normal operation, all the port lines should be
  567. set to outputs. The function of these addresses depend on the bit 2 of
  568. the next address. For instance, the function of 57280 is defined with
  569. the address 57281. If you POKE there a value with its third bit set,
  570. the values written to 57280 will go to the data direction register.
  571. Inputs have the corresponding data direction register bits reset, and
  572. outputs have them set. See Tables 1--4 for a complete description of
  573. PIA registers.
  574.  
  575. 3.4 Initializing the expansion
  576.  
  577. Before using the expansion memory, you have to first initialize the
  578. PIA. Every time when a -RESET is issued, the PIA registers change to
  579. the default state. (See Section 3.1.3.) In the beginning of your
  580. program you will initialize the PIA registers so that the default
  581. memory banking remains:
  582.  
  583.         pia     .equ $DFC0
  584.  
  585.                 LDA pia+1       ; Select Peripheral Registers
  586.                 ORA #4
  587.                 STA pia+1
  588.                 TAX
  589.                 LDA pia+3
  590.                 ORA #4
  591.                 STA pia+3
  592.                 TAY
  593.  
  594.                 LDA #$FE        ; Set the default memory bank data
  595.                 STA pia
  596.                 LDA #$DC
  597.                 STA pia+2
  598.  
  599.                 TXA             ; Select Data Direction Registers
  600.                 AND #$FD
  601.                 STA pia+1
  602.                 TYA
  603.                 AND #$FD
  604.                 STA pia+3
  605.  
  606.                 LDA #$FF        ; Set the ports to output
  607.                 STA pia
  608.                 STA pia+2
  609.  
  610.                 TXA
  611.                 AND #$C7
  612.                 ORA #$30        ; Set CA1 and
  613.                 STA pia+1       ; select Peripheral Registers
  614.                 STY pia+3
  615.  
  616. You may want to use an array instead. That will save both space and 
  617. processing time but lose generality. Someone may have CA1, CB1 and CB2
  618. in use (see Section 6), and changing all the command register bits
  619. would cause side effects. However, here is a BASIC example of using an
  620. initialization table:
  621.  
  622.         10 PIA=57280
  623.         20 FOR I=11 to 1 STEP -1:READ A:POKE PIA+I,A:NEXT
  624.         30 DATA 4,254,4,220,0,255,0,255,4,254,52
  625.  
  626. 3.5 Programming in machine language
  627.  
  628. Think it in hexadecimal numbers. There are sixteen memory blocks,
  629. numbered from 0 to F. The address $DFC0 holds two hexadecimal digits.
  630. The less significant digit, the one at right, selects the memory block
  631. for the segment 0 ($0000--$3FFF), whereas the other digit is for
  632. segment 1. The other important PIA address, $DFC2, selects the banks
  633. for segments 2 and 3 with is low and high nybble, respectively.
  634.  
  635. For instance, if you want to switch bank E ($38000--$3BFFF) to segment 1,
  636. initialize the PIA and execute the following. Note that your program
  637. must run outside segment 1 ($4000--$7FFF).
  638.  
  639.         pia     .equ $DFC0
  640.  
  641.                 LDA pia         ; Segments 0 and 1
  642.                 AND #$0F        ; Preserve segment 0
  643.                 ORA #$E0        ; Select bank E for segment 1
  644.                 STA pia
  645.  
  646. If you used our initialization routine before this, the memory areas
  647. $4000--$7FFF and $8000--$BFFF should now mirror each other. This is an
  648. easy way to peek under ROMs and I/O with a simple machine language
  649. monitor that does not play with the 6510's I/O registers to switch
  650. ROMs and I/O temporarily out.
  651.  
  652. 3.5.1 An exception: VIC memory
  653.  
  654. As the video chip's address bus is only fourteen bits wide, it can
  655. access only sixteen kilobytes directly. The two additional lines
  656. needed to address 64 kB are provided by the second CIA. Its lines PA1
  657. and PA0 are the inverse of VIC's address lines VA15 and VA14.
  658.  
  659. The VIC needs another two address lines to see full 256 kB of RAM. The
  660. PIA lines PB7 and PB6 (the uppest two bits of $DFC2) serve as VA17 and
  661. VA16. So, the VIC memory does not necessarily have to be accessible to
  662. 6510, but there is a restriction: As the bank selector for the upmost
  663. segment uses the same two lines, both the VIC bank and the bank for
  664. segment 3 cannot be chosen freely.
  665.  
  666. For instance, if you want the VIC to `see' its RAM at $04000, the
  667. lines VA17--VA14 must be `0001'. You can select only banks 0--3 for
  668. segment 3 to fulfill this condition. Let's assume that you want bank 2
  669. to be mapped there:
  670.  
  671.         cia2    .equ $DD00
  672.         pia     .equ $DFC0
  673.  
  674.                 LDA cia2+1      ; First set the CIA2 lines
  675.                 ORA #$03        ; PA0 and PA1 to output.
  676.                 STA cia2+1
  677.  
  678.                 LDA cia2        ; Then set PA1 and reset PA0.
  679.                 AND #$FC        ; Remember, the lines VA15 and VA14
  680.                 ORA #$01        ; are the inverse of them.
  681.  
  682.                 LDA pia+2       ; Segments 2 and 3
  683.                 AND #$0F        ; Preserve segment 2
  684.                 ORA #$20        ; Select bank 2 for segment 3
  685.                 STA pia+2
  686.  
  687. If you want the video bank selection to work as usually, you have four
  688. alternative memory bank configurations. The addresses $DFC2 and $DFC0
  689. must contain one of the words $FEDC, $BA98, $7654 and $3210. You can
  690. use the expansion to debug or examine programs that occupy full 64
  691. kilobytes of memory. When you issue a -RESET, the program's memory
  692. will remain totally unaltered, if it is outside the topmost four
  693. blocks. There is no need for a `freezer' cartridge.
  694.  
  695. 3.6 Programming in BASIC
  696.  
  697. With BASIC the use of the extra memory is a bit limited. In the upmost
  698. segment (segment 3) there is operating system ROM, under which you can
  699. place different memory banks, but reading them with BASIC is naturally
  700. impossible. However, in some cases writing data to this segment
  701. partially under Kernal ROM and I/O area may be a working solution. The
  702. lowmost kilobytes are free RAM, and it can be utilized by switching
  703. memory banks. But the benefit of the extra memory lowers, as you can
  704. use only the lowmost four kilobytes of each bank.
  705.  
  706.   You can read and write the area $C000--$DFFF of this segment using
  707.   BASIC. Accessing the area $D000--$DFFF without machine language is
  708.   tricky but possible.
  709.  
  710. The highest segment but one, segment 2, is halfly under BASIC ROM,
  711. and only its lower half can be freely used. (You can always write
  712. under ROM.) When utilizing it, you have to take in consideration that
  713. those 8 kilobytes can be under a ROM module, if one is connected, or
  714. they could hold some of the variables and tables that are stored in
  715. the top of the BASIC memory. You have to construct your programs so
  716. that they do not collide with the segment's area.
  717.  
  718. The lowmost segment, segment 0, contains Kernal's and BASIC
  719. interpreter's system variables. Normally you cannot change its
  720. contents, since the operating system would not find its status
  721. information. This can be worked around by copying those vital bytes to
  722. the new memory bank and switching the bank with a machine language
  723. routine.
  724.  
  725. The only segment that can be wholly used with plain BASIC is the
  726. segment 1, the second one from the bottom ($4000--$7FFF). It resides
  727. in the middle of the space reserved for BASIC programs. If you
  728. construct your BASIC programs wisely, that is short enough, and ensure
  729. that the information used by BASIC are located exactly on this area,
  730. you can switch the banks in this segment freely and keep even all the
  731. twelwe extra banks as a huge data storage.
  732.  
  733. Example 4.1 shows how you can create a table on this area
  734. and keep its data simultaneously in all the extra memory banks.
  735.  
  736. 4 Programming examples
  737.  
  738. 4.1 Processing a huge array
  739.  
  740.         10 I=0:J=0:K=0:A=0
  741.         20 DD=56576:PIA=57280
  742.         30 FOR I=11 TO 0 STEP -1:READ A:POKE PIA,A:NEXT
  743.         31 DATA 4,254,4,220,0,255,0,255,4,254,52,220
  744.         40 K=16384-7:POKE 47,K AND 255:POKE 48,K/256:
  745.            POKE 49,K AND 255:POKE 50,K/256
  746.         50 DIM A%(8191)
  747.         60 FOR I=0 TO 15:POKE PIA,I*16+12
  748.         70 PRINT I":";:FOR J=0 TO 9:PRINT A%(J),:NEXT:PRINT:NEXT
  749.         80 POKE PIA,220:END
  750.  
  751. The program displays ten first integers of each memory bank. The
  752. table it reserves fills the whole segment 1, because each integer
  753. (notice the % sign) takes two bytes and 8192 of them are reserved.
  754. The contents of the table A% can be changed to another memory bank by
  755. simply POKEing PIA's corresponding register. On the line 40 the table
  756. is ensured to start at $4000 by changing the start and end addresses
  757. of tables in the addresses 47--50. Saving the name, size and
  758. dimensions of the table takes the seven bytes, which are subtracted
  759. from the start address.
  760.  
  761. Reserving the table to an arbitrary address has its drawbacks. The
  762. size of the program and its variables may not exceed 14 kilobytes so
  763. that they could fit to the memory before the beginning of the table.
  764. All variables must definitely be declared before allocating the table.
  765. If you do not declare them by giving them a value, the interpreter
  766. finds really exotic values for them or transfers the table off its
  767. position.
  768.  
  769. 4.2 Storing graphics
  770.  
  771.         10 I=0:J=0:A=0:A$=""
  772.         20 DD=56576:PIA=57280:V=53248:COLOUR=50176
  773.         30 FOR I=11 TO 0 STEP -1:READ A:POKE PIA,A:NEXT
  774.         31 DATA 4,254,4,220,0,255,0,255,4,254,52,220
  775.         40 POKE V+24,16+8:POKE V+17,59
  776.         50 FOR I=0 TO 11:POKE PIA+2,I*16+14:
  777.            POKE DD,PEEK(DD) AND 252 OR (NOT I AND 3)
  778.         60 FOR J=0 TO 999:POKE J+COLOUR,3:NEXT
  779.         70 GET A$:IF A$="" THEN 70
  780.         80 NEXT I
  781.         90 POKE PIA+2,254:POKE DD,PEEK(DD) OR 3:
  782.            POKE V+24,23:POKE V+17,27
  783.  
  784. The extra memory can be used as a store of high resolution pictures as
  785. well. This program shows all twelve memory areas that could contain
  786. reasonable pictures. The pictures can be created with a BASIC
  787. extension that resides in RAM and saves its graphics under Kernal ROM.
  788. In those memory blocks that contain no pictures, you see random memory
  789. contents.
  790.  
  791. High resolution graphics is enabled on the line 40. The beginning of
  792. the line 50 switches bank `I' to the segment 3 and switches the VIC
  793. chip to the same memory area. The second POKE statement selects the
  794. video bank. `(NOT I AND 3)' filters the extra bits off and inverts the
  795. essential ones so that they can be stored to the lowmost two bits of
  796. $DD00. The line 60 sets the picture's colour to black-cyan. The next
  797. line waits for a keystroke before showing another picture. After all
  798. blocks have been shown, the original state of the I/O chips is
  799. restored on the line 90.
  800.  
  801.        +------------------------------------------------------+
  802.        |                Peripheral Register A                 |
  803.        |             (Peripheral Lines PA7--PA0)              |
  804.        +------------------------------------------------------+
  805.        |  Bits   Description                                  |
  806.        |  7--4   Block Selection, Segment 1                   |
  807.        |  3--0   Block Selection, Segment 0                   |
  808.        +------------------------------------------------------+
  809.        +------------------------------------------------------+
  810.        |              Data Direction Register A               |
  811.        +------------------------------------------------------+
  812.        |  Bits   Description                                  |
  813.        |  7--0   Data Direction of Peripheral Lines PA7--PA0  |
  814.        |           When a bit is set, its corresponding       |
  815.        |           Port A line is an output. Otherwise        |
  816.        |           it is an input.                            |
  817.        +------------------------------------------------------+
  818.                 Table 1. The PIA address $DFC0 (57280)
  819.  
  820. +-------------------------------------------------------------------+
  821. |                         Control Register A                        |
  822. +-------------------------------------------------------------------+
  823. |Bit(s)                           Description                       |
  824. |  7     IRQA1 Interrupt Flag                                       |
  825. |          Goes high on active transition of CA1; Automatically     |
  826. |          cleared by MPU read of Peripheral Register A. May also   |
  827. |          be cleared by hardware -RESET.                           |
  828. |                                                                   |
  829. |  6     IRQA2 Interrupt Flag                                       |
  830. |          When CA2 is an input, IRQA2 goes high on active          |
  831. |          transition of CA2; Automatically cleared by MPU read of  |
  832. |          Peripheral Register A. May also be cleared by hardware   |
  833. |          -RESET.                                                  |
  834. |                                                                   |
  835. | 5--3   CA2 Control                                                |
  836. |        00x    Input, triggered on falling edge                    |
  837. |        01x    Input, triggered on rising edge                     |
  838. |          When x is 1, -IRQA Interrupts by CA2 active transition   |
  839. |          are enabled.                                             |
  840. |        10x    Output, Read Strobe for Peripheral Register A       |
  841. |          CA2 goes low on first high-to-low E transition following |
  842. |          a read of Peripheral Register A. When x is 0, it remains |
  843. |          low until next active CA1 transition. When x is 1, CA2   |
  844. |          remains low for one E cycle.                             |
  845. |        110    Reset CA2                                           |
  846. |        111    Set CA2                                             |
  847. |                                                                   |
  848. |  2     Register in address $DFC0                                  |
  849. |        0      Data Direction Register                             |
  850. |        1      Peripheral Register                                 |
  851. |                                                                   |
  852. |  1     Determine Active CA1 Transition                            |
  853. |        0      IRQA1 set by high-to-low transition on CA1          |
  854. |        1      IRQA1 set by low-to-high transition on CA1          |
  855. |                                                                   |
  856. |  0     CA1 Interrupt Request Enable/Disable                       |
  857. |        0      Disable -IRQA Interrupt by CA1 active transition.   |
  858. |        1      Enable -IRQA Interrupt by CA1 active transition.    |
  859. +-------------------------------------------------------------------+
  860.                 Table 2. The PIA address $DFC1 (57281)
  861.  
  862.        +------------------------------------------------------+
  863.        |                Peripheral Register B                 |
  864.        |             (Peripheral Lines PB7--PB0)              |
  865.        +------------------------------------------------------+
  866.        |  Bits   Description                                  |
  867.        |  7--4   Block Selection, Segment 3                   |
  868.        |  3--0   Block Selection, Segment 2                   |
  869.        +------------------------------------------------------+
  870.        +------------------------------------------------------+
  871.        |              Data Direction Register B               |
  872.        +------------------------------------------------------+
  873.        |  Bits   Description                                  |
  874.        |  7--0   Data Direction of Peripheral Lines PB7--PB0  |
  875.        |           When a bit is set, its corresponding       |
  876.        |           Port B line is an output. Otherwise        |
  877.        |           it is an input.                            |
  878.        +------------------------------------------------------+
  879.                 Table 3. The PIA address $DFC2 (57282)
  880.  
  881. +-------------------------------------------------------------------+
  882. |                         Control Register B                        |
  883. +-------------------------------------------------------------------+
  884. |Bit(s)                           Description                       |
  885. |  7     IRQB1 Interrupt Flag                                       |
  886. |          Goes high on active transition of CB1; Automatically     |
  887. |          cleared by MPU read of Peripheral Register B. May also   |
  888. |          be cleared by hardware -RESET.                           |
  889. |                                                                   |
  890. |  6     IRQB2 Interrupt Flag                                       |
  891. |          When CB2 is an input, IRQB2 goes high on active          |
  892. |          transition of CB2; Automatically cleared by MPU read of  |
  893. |          Peripheral Register B. May also be cleared by hardware   |
  894. |          -RESET.                                                  |
  895. |                                                                   |
  896. | 5--3   CB2 Control                                                |
  897. |        00x    Input, triggered on falling edge                    |
  898. |        01x    Input, triggered on rising edge                     |
  899. |          When x is 1, -IRQB Interrupts by CB2 active transition   |
  900. |          are enabled.                                             |
  901. |        10x    Output, Read Strobe for Peripheral Register B       |
  902. |          CB2 goes low on first high-to-low E transition following |
  903. |          a read of Peripheral Register B. When x is 0, it remains |
  904. |          low until next active CB1 transition. When x is 1, CB2   |
  905. |          remains low for one E cycle.                             |
  906. |        110    Reset CB2                                           |
  907. |        111    Set CB2                                             |
  908. |                                                                   |
  909. |  2     Register in address $DFC2                                  |
  910. |        0      Data Direction Register                             |
  911. |        1      Peripheral Register                                 |
  912. |                                                                   |
  913. |  1     Determine Active CB1 Transition                            |
  914. |        0      IRQB1 set by high-to-low transition on CB1          |
  915. |        1      IRQB1 set by low-to-high transition on CB1          |
  916. |                                                                   |
  917. |  0     CB1 Interrupt Request Enable/Disable                       |
  918. |        0      Disable -IRQB Interrupt by CB1 active transition.   |
  919. |        1      Enable -IRQB Interrupt by CB1 active transition.    |
  920. +-------------------------------------------------------------------+
  921.                 Table 4. The PIA address $DFC3 (57283)
  922.  
  923. 5 RAM disk and other programs
  924.  
  925. Because not even the manufacturer has taken a memory expansion into
  926. consideration, programs making use of extra memory are rare. However,
  927. it does not mean that you could not fully utilize the expansion. The
  928. most obvious utilization method is a RAM disk. When using VC-1541, it
  929. is not only luxury but almost vital condition.
  930.  
  931. Pekka Pessi has made a couple of programs that utilize the 256 kB
  932. expansion. The software is distributed in two self-extracting archive
  933. files (SFXes).
  934.   If you don't have got the files with this document, you can retrieve
  935.   them via anonymous FTP from the server FUNIC.FUnet.FI. The directory
  936.   /pub/cbm/documents/256kB contains files related to this expansion.
  937. The file ROS-V1.SFX (for RAM Operating System) holds the source code
  938. of the RAM disk program, and some miscellanous files. Order
  939. ``LOAD"ROS-V1.SFX", device'', and change a blank disk to the drive
  940. before RUNning. The second archive, UTIL256.SFX, has the following
  941. software:
  942.  
  943. 5.1 Memory test
  944.  
  945. The program TEST tests the block selection and the whole memory. If it
  946. jams before reporting ``Test passed'', something has gone wrong. Its
  947. source code is in the file TEST.A, which requires a library STRING.A.
  948. I translated the executable to English by patching the binary file.
  949.  
  950. 5.2 Poor man's multitasking
  951.  
  952. With the MULTI51200 program you can run four different programs. The
  953. program does no multitasking, it only keeps four environments in the
  954. memory, each in its own memory block. MULTI.A is the source code.
  955. After loading it with ``LOAD"MULTI51200", device,1'' and 
  956. initializing the BASIC pointers with ``NEW'', you can switch the
  957. environments with ``SYS51200, f, b''. The parameter f is a flag
  958. determining if the current block will be copied to the destination
  959. block (0) or not (1). The b selects the destination block (0--3). The
  960. initial block is 3.
  961.  
  962. 5.3 Machine language monitor
  963.  
  964. If you don't like to switch the memory banks manually in your
  965. favourite machine language monitor, the MON256 utility is for you. The
  966. memory is again divided to four 64 kB blocks, numbered from 0 to 3.
  967. The commands are as follows:
  968.  
  969. a nnnn cmd or            Assembles instruction cmd to 
  970. . nnnn cmd               memory address nnnn.
  971.  
  972. b bb ff                  Selects a block. The bb holds the block
  973.                          number, and ff is a flag. If it is 1, it
  974.                          directs all memory accessing to RAM. If it 
  975.                          is 0, you can access the  ROMs and I/O.
  976.  
  977. c hhhh iiii jjjj         Compares the memory area hhhh--iiii with the
  978.                          area beginning from jjjj.
  979.  
  980. d [hhhh [iiii]]          Disassembles memory.
  981.  
  982. f hhhh iiii nn           Fills the memory between hhhh and iiii with
  983.                          the byte pattern nn.
  984.  
  985. g [hhhh]                 Executes program until a BRK is encountered.
  986.  
  987. h hhhh iiii nn mm... or  Hunts the memory area hhhh--iiii
  988. h hhhh iiii 'text        for the byte sequence nn mm... or for `text'.
  989.  
  990. j [hhhh]                 Calls a subroutine.
  991.  
  992. l "filename"[,n]         Loads a program. Default device number is 8.
  993.  
  994. m [hhhh [iiii]]          Hexadecimal dump of memory.
  995.  
  996. > hhhh nn mm...          Stores bytes in memory.
  997.  
  998. r                        Dumps the registers (for `g' and `j').
  999.  
  1000. ;                        Modifies the register values.
  1001.  
  1002. s "filename",n,hhhh,jjjj Saves the memory area hhhh--jjjj to device n.
  1003.  
  1004. t hhhh iiii jjjj         Copies the memory area hhhh--iiii to jjjj.
  1005.  
  1006. v "filename"[,n]         Verifies a program. Default device number is 8.
  1007.  
  1008. x                        Exits the monitor.
  1009.  
  1010. @ [command]              Sends `command' to device 8. If it begins with
  1011.                          $, the disk directory will be read. If no
  1012.                          command is given, the disk drive's status will
  1013.                          be displayed. 
  1014.  
  1015. The source code for the monitor is split in the files MON.A, 
  1016. CONSOLE.A, COM.A, ROUTINES.A and TABELS.A.
  1017.  
  1018. 5.4 RAM disk
  1019.  
  1020. The most important utility is a RAM disk program, which occupies about
  1021. 9 kilobytes of memory. It transfers Kernal and BASIC interpreter to
  1022. RAM and patches the serial bus routines. The actual program is in the
  1023. area $00800--$03FFF.
  1024.  
  1025. It emulates all VC-1541 functions except relative files. For 
  1026. example, the commands U1, U2, B-A etc. work. UI+ and UI- make no
  1027. difference. The program also detects some fast loaders and works with
  1028. them installed.
  1029.  
  1030. The loader is called RAM DISC, and the patched Kernal is in RAM.K. You
  1031. need only patches to the low-level serial bus routines, so you may
  1032. want to restore the original colors and keyboard definitions. To
  1033. minimize incompatibility problems, you should replace the Kernal ROM
  1034. with an EPROM holding the patched Kernal. The RAM disk routines are in
  1035. RAM.C. 
  1036.  
  1037. 5.4.1 Disk copiers
  1038.  
  1039. The program RAM DISC COPY copies a regular 1541 disk to RAM. It
  1040. utilizes the slow U1 command, and it is included as an example only.
  1041. The source code DUP.A exposes the RAM disk's storage format.
  1042.  
  1043. A faster and more useful tool is FDUPLICATE. Using it, you can copy a
  1044. regular disk to the RAM disk or vice versa. You can make multiple
  1045. copies of a disk easily. This program's fast transfer routines are
  1046. designed for PAL systems, and the utility cannot be used in NTSC
  1047. machines without little modification. Its source code is in the two
  1048. files S/SUCK and S/DSUCK.
  1049.  
  1050. 6 Other expansions
  1051.  
  1052. There are a couple of unused contacts in the PIA. In addition to that,
  1053. two 7405 ports are not connected. The extra PIA lines include two
  1054. inputs, CA1 and CB1, an input/output line CB2, and two Interrupt
  1055. Request lines -IRQA and -IRQB.
  1056.  
  1057. If you connect the -IRQA and -IRQB lines to the -IRQ and -NMI inputs
  1058. of your system, you can have up to three new interrupt sources, useful
  1059. for interfacing your custom hardware. And if you are running out of
  1060. User Port pins, the three lines CA1, CB1 and CB2 can save you from
  1061. designing an I/O cartridge.
  1062.  
  1063. 6.1 New operating system
  1064.  
  1065. I had purchased a PC board that allows you to choose between the
  1066. Kernal ROM and a custom 8 kB EPROM (2764). I never added a fastloader
  1067. or other useful routines to the Kernal, since I should have deleted
  1068. some routines, i.e. the Datassette and RS-232 handling.
  1069.  
  1070. But if you had more ROM, you could keep your new Kernal fully
  1071. compatible with the old Kernal while adding new features to it.
  1072. A 32 kB EPROM would easily hold the RAM disk routines, the disk copier
  1073. and routines for adequately fast loading and saving. Still you would
  1074. have plenty of space for controlling your own expansions, like a
  1075. IEEE-488 interface or a SCSI bus.
  1076.  
  1077. Figure 3 shows the pinouts for the original Kernal ROM (2364) and the
  1078. replacement chip (27256). Connect the address lines A0--A12, the data
  1079. bus (D0--D7) and the power supply lines (VCC and GND) together, and
  1080. connect VPP to VCC.
  1081.  
  1082. The signals -CS, -CE and -OE are for chip selection. Connect -CE and
  1083. -OE together, and add 4.7 kilo-ohm resistors between both chips' VCC
  1084. and chip selection lines. Then add a ON-ON switch between 2364's -CS,
  1085. 27256's -CE and -OE, and the -KERNAL line that comes from the
  1086. motherboard originally to 2364's -CS pin.
  1087.  
  1088. Now you have only the lines A14 and A13 left. PIA's CB2 can control
  1089. one of them, but what about the other? No problem, let's just give
  1090. another function to CA2. The new operating system code can initialize
  1091. the PIA so that the CA2 line will be initially low. And it will be set
  1092. only when the operating system calls its internal routines.
  1093.  
  1094. Tie 6821's CB2 and 7405's unused output pins (2 and 12 by default)
  1095. to +5 V through 4.7 kilo-ohm resistors. This is because these pins are
  1096. open-collector and cannot otherwise output high voltage. Then connect
  1097. CB2 to 7405's pin 1 and 7405's pin 2 to 27256's A13. Lead CA2 through
  1098. the other unused 7405 port to 27256's A14.
  1099.  
  1100. Now those A14 and A13 lines are low upon start-up, and the computer
  1101. will see the EPROM area $0000--$1FFF instead of Kernal ROM, if the
  1102. switch is in right position. That part of the EPROM should initialize
  1103. the PIA. Note that lowering the CA2 line immediately causes jump to
  1104. another bank of the EPROM, i.e. to an address greater by $4000. If you
  1105. are interested in programming a new 32 kB operating system, contact
  1106. me. I may have done some preliminary work by then.
  1107.  
  1108. 7 Contacting the authors
  1109.  
  1110. If you have anything to ask or comment, feel free to contact us.
  1111. Marko MΣkelΣ's addresses are:
  1112.  
  1113.      Internet:  Marko.Makela@Helsinki.FI
  1114.        BitNet:  MSMakela@FinUH
  1115.  
  1116.          Mail:  Marko MΣkelΣ
  1117.                 Sillitie 10 A
  1118.                 FI-01480 Vantaa
  1119.                 Finland
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.                   2364                         27256
  1127.             +--------------+             +--------------+
  1128.          A7 |  1  \__/  24 | VCC     VPP |  1  \__/  28 | VCC
  1129.          A6 |  2        23 | A8      A12 |  2        27 | A14
  1130.          A5 |  3        22 | A9       A7 |  3        26 | A13
  1131.          A4 |  4        21 | -CS2     A6 |  4        25 | A8
  1132.          A3 |  5        20 | -CS1     A5 |  5        24 | A9
  1133.          A2 |  6        19 | A10      A4 |  6        23 | A11
  1134.          A1 |  7        18 | A11      A3 |  7        22 | -OE
  1135.          A0 |  8        17 | D7       A2 |  8        21 | A10
  1136.          D0 |  9        16 | D6       A1 |  9        20 | -CE
  1137.          D1 | 10        15 | D5       A0 | 10        19 | D7
  1138.          D2 | 11        14 | D4       D0 | 11        18 | D6
  1139.         GND | 12        13 | D3       D1 | 12        17 | D5
  1140.             +--------------+          D2 | 13        16 | D4
  1141.                                      GND | 14        15 | D3
  1142.                                          +--------------+
  1143.  
  1144.          Figure 3. The Read-Only Memory Chips 2364 and 27256
  1145.  
  1146.                                                 IC4          ^ IC2  74LS153
  1147.                          ^                  /--3-!-4----\    |    +-----+
  1148.           ^              |                  +-11-!-10--\|    \-16-| Vcc |
  1149.           | 20          === C1              +--5-!-6--+---------6-| I0a |
  1150.    +------+------+       |  100 nF          +--9-!-8-\|+--------5-| I1a | 
  1151.  2-| PA0 Vcc CNT |-40    V             ^    | 74LS05 ||||  /----4-| I2a |
  1152.  3-| PA1      SP |-39                  | 20 \-------\||||  |/---3-| I3a |
  1153.  4-| PA2    -IRQ |-21          +-------+-------+    |+-----||--10-| I0b |
  1154.  5-| PA3     RS0 |-38---\   38-| -IRQA Vcc CA1 |-40 ||||| /||--11-| I1b |
  1155.  6-| PA4     RS1 |-37-\ |   37-| -IRQB     CA2 |-39-/|||+-|||--12-| I2b |
  1156.  7-| PA5     RS2 |-36 | \---36-| RS0       PA0 |--2--/||| |||/-13-| I3b |   
  1157.  8-| PA6     RS3 |-35 \-----35-| RS1       PA1 |--3---/|| ||||    |  Ea |o-1-\
  1158.  9-| PA7  -RESET |-34-------34-| -RESET    PA2 |-4-PA2>|| ||||    |  Eb |o15-+
  1159. 10-| PB0      D0 |-33-------33-| D0        PA3 |-5-PA3>|| ||||    | GND |--8-+
  1160. 11-| PB1      D1 |-32-------32-| D1        PA4 |--6----||-/|||    |     |    V
  1161. 12-| PB2      D2 |-31-------31-| D2        PA5 |--7----/|  |||    |     |
  1162. 13-| PB3      D3 |-30-------30-| D3        PA6 |--8-PA6>|  |||    |S0 14|--<A14
  1163. 14-| PB4      D4 |-29-------29-| D4        PA7 |--9-PA7>|  |||    |S1  2|--<A15
  1164. 15-| PB5      D5 |-28-------28-| D5        PB0 |-10-----/  |||    |Za  7|--B15>
  1165. 16-| PB6      D6 |-27-------27-| D6        PB1 |-11--------/||    |Zb  9|o-B14>
  1166. 17-| PB7      D7 |-26-------26-| D7        PB2 |-12-PB2>    ||    +-----+
  1167. 24-| -FLAG  Phi2 |-25-------25-| E         PB3 |-13-PB3>    ||
  1168. 18-| -PC     -CS |-23   A7>-24-| CS        PB4 |-14---------|/
  1169.    |        R/-W |-22-\IO2>-23-| -CS       PB5 |-15---------/
  1170.    | U2  Vss TOD |-19 | A6>-22-| CS        PB6 |-16-PB6>
  1171.    +-------------+    \-----21-| R/-W      PB7 |-17-PB7>
  1172.         1 | M6526              |           CB1 |-18
  1173.           V                    | IC1  Vss  CB2 |-19
  1174.               ^                +---------------+
  1175.               | 16                   1 | MC6821
  1176.         +-----------+           J1     V
  1177.         |    Vcc    |          +--+
  1178. PA2>--4-| I0      Z |--5       | 1| CAS
  1179. PA3>--3-| I1      Z |o-6-MA8>  | 2| A15
  1180. PA6>--2-| I2        |          | 3| MA8
  1181. PA7>--1-| I3    IC3 |          | 4| A14
  1182. PB2>-15-| I4        |          | 5| A7
  1183. PB3>-14-| I5        |          | 6| B14
  1184. PB6>-13-| I6     S0 |-11-<CAS  | 7| IO2
  1185. PB5>-12-| I7     S1 |-10-<A14  | 8| B15
  1186.     /-7o| E      S2 |--9-<A15  | 9| A6
  1187.     |   |    GND    |          |10| GND
  1188.     V   +-----------+          +--+
  1189.             8 | 74LS151
  1190.               V  
  1191. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1192.          ^                         ^                                ^
  1193.          | 16                      | 8                              | 16
  1194.    +-----------+             +-----------+                    +-----------+
  1195.    |    Vcc    |             |    Vdd    |                    |    Vcc    |
  1196.  1o| IG    1Y0 |o-4        5-| MA0   Din |-2          <CAS--1-| SELECT 1Y |-4
  1197.  2-| 1A    1Y1 |o-5        6-| MA1  Dout |-14  <A14-* B14>--2-| 1A     2Y |-7
  1198.  3-| 1B    1Y2 |o-6        7-| MA2  -RAS |-4           <A6--3-| 1B     3Y |-9
  1199. 15o| 2G    1Y3 |o-7       12-| MA3  -CAS |-12               5-| 2A     4Y |-12
  1200. 14-| 2A    2Y0 |o12       11-| MA4   -WE |-3                6-| 2B      G |o15
  1201. 13-| 2B    2Y1 |o11       10-| MA5       |     <A15-* B15>-11-| 3A        |
  1202.    |       2Y2 |o10       13-| MA6       |             <A7-10-| 3B        |
  1203.    | U15   2Y3 |o-9-IO2>   9-| MA7   U12 |                 14-| 4A        |
  1204.    |    GND    |           1-| MA8       |                 13-| 4B        |
  1205.    +-----------+             |    Vss    |                    |    GND    |
  1206.        8 | 74LS139           +-----------+                    +-----------+
  1207.          V                      16 | 80256                        8 | 74LS257
  1208.                                    V                                V
  1209.  
  1210.             Figure 4. Schematics diagram of the expansion
  1211.  
  1212.            +----------------------------------------------+
  1213.            |            Electronic Components             |
  1214.            +----------+-----------------------------------+
  1215.            |  Symbol  |            Description            |
  1216.            +----------+-----------------------------------+
  1217.            | IC1      | MC6821                            |
  1218.            | IC2      | 74LS153 (or 74LS253)              |
  1219.            | IC3      | 74LS151 (or 74LS251)              |
  1220.            | IC4      | 74LS05                            |
  1221.            | U9--U12, | 80256 or                          |
  1222.            | U21--U24 | compatible                        |
  1223.            | C1       | 100 nF polyester capacitor        |
  1224.            | R1       | 33 ohm resistor                   |
  1225.            +----------+-----------------------------------+
  1226.            +----------------------------------------------+
  1227.            |                 Other Parts                  |
  1228.            +----------+-----------------------------------+
  1229.            | Quantity |              Quality              |
  1230.            +----------+-----------------------------------+
  1231.            | 2 pcs    | 10-pin flat cable connector pair  |
  1232.            | ca. 15 cm| 10-wire flat cable                |
  1233.            | 1 pc     | 16-pin piggyback socket           |
  1234.            | 2 pcs    | 16-pin WW-socket                  |
  1235.            | or       | one 16-pin piggyback socket and   |
  1236.            |          | two normal 16-pin sockets         |
  1237.            | 1 pc     | 40-pin WW-socket                  |
  1238.            | or       | one 40-pin piggyback socket and   |
  1239.            |          | a normal 40-pin socket            |
  1240.            | 10 pcs   | 16-pin socket                     |
  1241.            | 1 pc     | 14-pin socket                     |
  1242.            | 8 pcs    | 100 nF polyester capacitor (opt.) |
  1243.            | plenty of| connection wire                   |
  1244.            +----------+-----------------------------------+
  1245.                 Table 5. Parts list for the expansion
  1246.