home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / Information / REU-INFO < prev    next >
Encoding:
Text File  |  2019-04-13  |  11.8 KB  |  320 lines

  1.  
  2.   The following is based on the Commodore 1764 user's manual (german
  3. version) and my own experiences programming the 1764 Ram Expansion Unit
  4. (REU).
  5.  
  6.  
  7. Contents:
  8.  
  9.  1) External RAM Access With REUs
  10.  2) RAM Expansion Controller (REC) Registers
  11.  3) How To Recognize The REU
  12.  4) Simple RAM Transfer
  13.  5) Additional Features
  14.  6) Transfer Speed
  15.  7) Interrupts
  16.  8) Executing Code In Expanded Memory
  17.  9) Other Useful Applications Of The REU
  18. 10) Comparision Of Bank Switching and DMA
  19.  
  20.  
  21.  
  22. 1) _External RAM Access With REUs_
  23.  
  24.   The REUs provide additional RAM for the C64/128. Three types of REUs
  25. have been produced by Commodore. These are the 1700, 1764 and 1750 with
  26. 128, 256 and 512 KBytes built in RAM. However they can be extended up to
  27. several MBytes.
  28.   The external memory can not be addressed directly by the C64 with it's
  29. 16-bit address space. It has to be transferred from an to the main
  30. memory of the C64. For that purpose there is a built in RAM Expansion
  31. Controller (REC) which transfers memory between the C64 and the REU
  32. using Direct Memory Access (DMA). It can also be used for other
  33. purposes.
  34.  
  35. ---
  36. REU means Ram Expansion Unit. There are several different ones. The official
  37. Commodore REU's are the 1700, 1764 and 1750 which are respectively 128, 256
  38. and 512Kb of memory (not directly addressable of course). There seem to be
  39. hacks to expand these to 1Mb or even 2Mb. I myself have recently made 512K in
  40. the 256K cartridge without any difficulties. CLD, an american company makes
  41. clones of the 1750 and maybe others. These clones are smaller than the
  42. originals but probably not as expandable. I have a 1750 Clone (512Kb) and it
  43. seems to be 100% compatible (no, not 99.9% but really 100%).
  44.  
  45. Furthermore there is the Georam expansion. This cartridge is ugly as hell and
  46. only works with GEOS. I believe it's also 512K. In my opinion, the real REU
  47. is better in every respect.
  48.  
  49. W. Lamee
  50. ---
  51.  
  52.  
  53. 2) _RAM Expansion Controller (REC) Registers_
  54.  
  55.   The REC is programmed by accessing it's registers, that appear memory
  56. mapped in the I/O-area between $DF00 and $DF0A when a REU is connected
  57. through the expansion port of the C64. They can be read and written to
  58. like VIC- and SID-registers.
  59.  
  60. $DF00: STATUS REGISTER
  61.        various information can be obtained (read only)
  62.  
  63. Bit 7:     INTERRUPT PENDING  (1 = interrupt waiting to be served)
  64.            unnecessary
  65. Bit 6:     END OF BLOCK  (1 = transfer complete)
  66.            unnecessary
  67. Bit 5:     FAULT  (1 = block verify error)
  68.            Set if a difference between C64- and REU-memory areas was found
  69.            during a compare-command.
  70. Bit 4:     SIZE  (1 = 256 KB)
  71.            Seems to indicate the size of the RAM-chips. It is set on 1764
  72.            and 1750 and clear on 1700.
  73. Bits 3..0: VERSION
  74.            Contains 0 on my REU.
  75.  
  76. $DF01: COMMAND REGISTER
  77.        By writing to this register RAM transfer or comparision can be
  78.        executed.
  79.  
  80. Bit 7:     EXECUTE  (1 = transfer per current configuration)
  81.            This bit must be set to execute a command.
  82. Bit 6:     reserved  (normally 0)
  83. Bit 5:     LOAD  (1 = enable autoload option)
  84.            With autoload enabled the address and length registers (see
  85.            below) will be unchanged after a command execution.
  86.            Otherwise the address registers will be counted up to the
  87.            address off the last accessed byte of a DMA + 1,
  88.            and the length register will be changed (normally to 1).
  89. Bit 4:     FF00
  90.            If this bit is set command execution starts immediately
  91.            after setting the command register.
  92.            Otherwise command execution is delayed until write access to
  93.            memory position $FF00
  94. Bits 3..2: reserved  (normally 0)
  95. Bits 1..0: TRANSFER TYPE
  96.            00 = transfer C64 -> REU
  97.            01 = transfer REU -> C64
  98.            10 = swap C64 <-> REU
  99.            11 = compare C64 - REU
  100.  
  101. $DF02..$DF03: C64 BASE ADDRESS
  102.               A 16-bit C64 - base address in low/high order.
  103.  
  104. $DF04..$DF06: REU BASE ADDRESS
  105.               This is a three byte address consisting of a low and
  106.               high byte and an expansion bank number.
  107.               Normally only bits 2..0 of the expansion bank are valid
  108.               (for a maximum of 512 KByte), the other bits are always
  109.               set. This must be different if more than 512 KByte are
  110.               installed.
  111.  
  112. $DF07..$DF08: TRANSFER LENGTH
  113.               This is a 16-bit value containing the number of bytes to
  114.               transfer or compare.
  115.               The value 0 stands for 64 Kbytes.
  116.               If the transfer length plus the C64 base address exceeds
  117.               64K the C64 address will overflow and cause C64 memory
  118.               from 0 on to be accessed.
  119.               If the transfer length plus the REU base address exceeds
  120.               512K the REU address will overflow and cause REU memory
  121.               from 0 on to be accessed.
  122.  
  123. $DF09: INTERRUPT MASK REGISTER
  124.        unnecessary
  125.  
  126. Bit 7:     INTERRUPT ENABLE  (1 = interrupt enabled)
  127. Bit 6:     END OF BLOCK MASK  (1 = interrupt on end)
  128. Bit 5:     VERIFY ERROR  (1 = interrupt on verify error)
  129. Bits 4..0: unused (normally all set)
  130.  
  131. $DF0A: ADDRESS CONTROL REGISTER
  132.        Controlls the address counting during DMA.
  133.        If an address is fixed, not a memory block but always the same
  134.        byte addressed by the base address register is used for DMA.
  135.  
  136. Bit 7:     C64 ADDRESS CONTROL  (1 = fix C64 address)
  137. Bit 6:     REU ADDRESS CONTROL  (1 = fix REU address)
  138. Bits 5..0: unused (normally all set)
  139.  
  140.  
  141.   To access the REU-registers in assembly language it is convenient to
  142. define labels something like this:
  143.  
  144.     status   = $DF00
  145.     command  = $DF01
  146.     c64base  = $DF02
  147.     reubase  = $DF04
  148.     translen = $DF07
  149.     irqmask  = $DF09
  150.     control  = $DF0A
  151.  
  152.  
  153. 3) _How To Recognize The REU_
  154.  
  155.   Normally the addresses between $DF00 and $DF0A are unused. So normally
  156. if values are stored there they get lost. So if you write e.g. the
  157. values 1,2,3,... to $DF02..$DF08 and they don't stay there you can be
  158. sure that no REU is connected. However if the values are there it could
  159. be because another kind of module is connected that also uses these
  160. addresses.
  161.   Another problem is the recognition of the number of RAM banks (64
  162. KByte units) installed. The SIZE bit only tells that there are at least
  163. 2 (1700) or 4 (1764, 1750) banks installed. By trying to access & verify
  164. bytes in as many RAM banks as possible the real size can be determined.
  165. This can be seen in the source to "Dynamic memory allocation for the
  166. 128" in Commodore Hacking Issue 2.
  167.   I personally prefer to let the user choose if and which REU banks
  168. shall be used.
  169.  
  170.  
  171. 4) _Simple RAM Transfer_
  172.  
  173.   Very little options of the REU are necessary for the main purposes of
  174. RAM expanding.
  175.   Just set the base addresses, transfer length and then the command
  176. register.
  177.  
  178.   The following code transfers one KByte containing the screen
  179. memory ($0400..$07FF) to address 0 in the REU:
  180.  
  181.     lda #0
  182.     sta control ; to make sure both addresses are counted up
  183.     lda #<$0400
  184.     sta c64base
  185.     lda #>$0400
  186.     sta c64base + 1
  187.     lda #0
  188.     sta reubase
  189.     sta reubase + 1
  190.     sta reubase + 2
  191.     lda #<$0400
  192.     sta translen
  193.     lda #>$0400
  194.     sta translen + 1
  195.     lda #%10010000;  c64 -> REU with immediate execution
  196.     sta command
  197.  
  198.   To transfer the memory back to the C64 replace "lda #%10010000"
  199. by "lda #%10010001".
  200.  
  201.   I think that this subset of 17xx functions would be enough for a
  202. reasonable RAM expansion. However if full compatibility with 17xx REUs
  203. is desired also the more complicated functions have to be implemented.
  204.  
  205.  
  206. 5) _Additional Features_
  207.  
  208.  
  209. Swapping Memory
  210.  
  211.   With the swap-command memory between 17xx and C64 is exchanged. The
  212. programming is the same as in simple RAM transfer.
  213.  
  214.  
  215. Comparing Memory
  216.  
  217.   No RAM is transferred but the number of bytes specified in the
  218. transfer length register is compared. If there are differences the
  219. FAULT-bit of the status register is set. This bit is cleared by reading
  220. the status register which has to be done before comparing to get valid
  221. information.
  222.  
  223.  
  224. Using All C64 Memory
  225.  
  226.   C64 memory is accessed by the REU normally in the memory configuration
  227. existing during writing to the command register. However in order to be
  228. able to write to the command register the I/O-area has to be active.
  229.   If RAM between $D000 and $DFFF or character ROM shall be used it is
  230. possible to delay the execution of the command by storing a command byte
  231. with bit 4 ("FF00") cleared. The command will then be executed
  232. by writing any value to address $FF00.
  233.  
  234. Example:
  235.  
  236.     < Set base addresses and transfer length >
  237.     lda #%10000000 ; transfer C64 RAM -> REU delayed
  238.     sta command
  239.     sei
  240.     lda $01
  241.     and #$30
  242.     sta $01 ; switch on 64 KByte RAM
  243.     lda $FF00 ; to not change the contents of $FF00
  244.     sta $FF00 ; execute DMA
  245.     lda $01
  246.     ora #$37
  247.     sta $01 ; switch on normal configuration
  248.     cli
  249.  
  250.  
  251. 6) _Transfer Speed_
  252.  
  253.   During DMA the CPU is halted and the memory access cycles normally
  254. available for the CPU are now used to access one byte each. So with
  255. screen and sprites switched off in every clock cycle (985248 per second
  256. on PAL machines) a byte is transferred. If screen is on or sprites are
  257. enabled transfer is a bit slower, as the VIC exclusively accesses RAM
  258. sometimes. An exact description of those "missing cycles" can be found
  259. in Commodore Hacking Issue 3.
  260.   Comparing memory areas is as fast as transfers. (Comparison is stopped
  261. once the first difference is found.)
  262.   Swapping memory is only half as fast, as for every bytes two C64 memory
  263. accesses (read & write) are necessary.
  264.  
  265.  
  266. 7) _Interrupts_
  267.  
  268.   By setting certain bits in the interrupt mask register IRQs at the end
  269. of a DMA can be selected. However as the CPU is halted during DMA it
  270. will always be finished after the store instruction into the command
  271. register or $FF00. So there is no need to check for an "END OF BLOCK"
  272. (bit 6 of status register) or to enable an interrupt.
  273.  
  274.  
  275. 8) _Executing Code In Expanded Memory_
  276.  
  277.   Code in external memory has always to be copied into C64 memory to be
  278. executed. This is a disadvantage against bank switching systems. However
  279. bank switching can be simulated by the SWAP command. This is done e.g.
  280. in RAMDOS where only 256 bytes of C64 memory are occupied, the 6 KByte
  281. RAM disk driver is swapped in whenever needed. Probably too much
  282. swapping is the reason for RAMDOS to be not really fast at sequential
  283. file access.
  284.  
  285.  
  286. 9) _Other Useful Applications Of The REU_
  287.  
  288.   The REC is not only useful for RAM transfer and comparison.
  289.  
  290.   One other application (used in GEOS) is to copy C64 RAM areas
  291. by first transferring it to the REU and then transferring it back into
  292. the desired position in C64 memory. Due to the fast DMA this is about 5
  293. times faster than copying memory with machine language instructions.
  294.  
  295.   Interesting things can be done by fixing base addresses. Large C64
  296. areas can be filled very fast with a single byte value by fixing the REU
  297. base address. Thus it is also possible to find the end of an area
  298. containing equal bytes very fast e.g. for data compression.
  299.  
  300.   Fixing the C64 base address is interesting if an I/O-port is used, as
  301. data can be written out faster than normally possible.
  302.   It would be possible to use real bitmap graphics in the upper and lower
  303. screen border by changing the "magic byte" (highest by the VIC addressed
  304. byte) in every clock cycle during the border switched off.
  305.  
  306.   Generally the REC could be used as graphics accelerator e.g. to
  307. copy bitmap areas or to copy data fast into the VIC-addressable
  308. 16 KByte area.
  309.  
  310.  
  311. 10) _Comparision Of Bank Switching and DMA_
  312.  
  313.   When comparing bank switching and DMA for memory expansion I think DMA
  314. is the more comfortable methode to program and also is faster in most
  315. cases. The disadvantage with code execution not possible in external
  316. memory could be minimized by copying only the necessary parts into C64
  317. memory. Executing the code will take much more time than copying it
  318. into C64 memory.
  319.  
  320.