.main. hcd65xx v3.1 6june87 page 1 0:ramexp.src,s,r error addr code seq source statement 1 ; 2 ; =1800 3 *=$1800 4 ; 5 ; 6 ;======================================== 7 ; equates 8 ;======================================== 9 ; 10 ; =1700 11 buffer = $1700 =00fb 12 numbank = $fb =df00 13 ramexp = $df00 =d506 14 rcr = $d506 15 ; 16 ; 17 ;======================================== 18 ; jump table 19 ;======================================== 20 ; 21 ; 1800 4c 1813 22 start jmp howbig 1803 4c 187e 23 jmp stash 1806 4c 187b 24 jmp fetch 25 ; 26 ; 27 ;=========================================== 28 ; DMA parameters 29 ;=========================================== 30 ; 31 ; 1809 0000 32 params .word $0000 ; Host address, lo, hi 180b 0000 33 .word $0000 ; Exp address, lo, hi 180d 00 34 expbank .byte $00 ; Expansion bank no. 180e 0100 35 .word $0100 ; # bytes to move, lo, hi 1810 00 36 .byte $00 ; Interrupt mask reg. 1811 00 37 .byte $00 ; Adress control reg. 38 ; 1812 00 39 bnk128 .byte $00 ; Bank of 128 to work with 1813 40 pend 41 ; 42 ; 43 ;=========================================== 44 ; Test ram expander to determine size 45 ;=========================================== 46 ; 47 ; Number of banks is returned in .A 48 ; and in numbank. 49 ; 50 ; .A = 8 for the 1750 512K expander 51 ; .A = 2 for the 1700 128K expander 52 ; .A = 4 for the 1764 256K expander 53 ; .A = 1 for no RAM expander 54 ; 55 ;=========================================== 56 ; 57 ; .main. hcd65xx v3.1 6june87 page 2 0:ramexp.src,s,r error addr code seq source statement 58 ; 59 ; Here are the 8 parameters we 1813 a2 17 60 howbig ldx #>buffer ; must set for stash and fetch: 1815 8e 180a 61 stx params+1 ; First, set up the hi bytes of 1818 8e 180c 62 stx params+3 ; the cpu and expansion address. 181b a2 01 63 ldx #$01 181d 8e 180f 64 stx params+6 ; Set up the byte count hi 1820 ca 65 dex ; and the byte count lo. 1821 8e 180e 66 stx params+5 1824 8e 180d 67 stx expbank ; Set up the expansion bank to 1827 8e 1809 68 stx params+0 ; use and the lo bytes of the 182a 8e 180b 69 stx params+2 ; cpu and expansion address. 182d 8e 1812 70 stx bnk128 ; Set the 128 bank to work with. 71 ; 1830 8a 72 20$ txa ; Generate a 1 block 1831 49 5a 73 eor #$5a ; test pattern in 1833 9d 1700 74 sta buffer,x ; buffer. 1836 ca 75 dex 1837 d0 f7 76 bne 20$ 77 ; 1839 20 187e 78 30$ jsr stash ; Now write the test 183c ee 180d 79 inc expbank ; pattern in buffer 183f ad 180d 80 lda expbank ; to each of the 8 1842 c9 08 81 cmp #8 ; possible exp. banks. 1844 d0 f3 82 bne 30$ 83 ; 1846 a2 00 84 ldx #0 1848 8e 180d 85 stx expbank 86 ; 184b a2 00 87 40$ ldx #0 ; OK, now change 184d 8a 88 50$ txa ; the 1 block test 184e 49 3c 89 eor #$3c ; pattern in the buffer 1850 9d 1700 90 sta buffer,x ; to a new pattern. 1853 ca 91 dex 1854 d0 f7 92 bne 50$ 93 ; 1856 20 187e 94 jsr stash ; Now write the new 1859 ee 180d 95 inc expbank ; pattern to bank (x)... 96 185c ad 180d 97 lda expbank ; (check to see 185f c9 08 98 cmp #8 ; if we are done) 1861 f0 12 99 beq 90$ 100 1863 20 187b 101 jsr fetch ; ...and read the pattern 1866 a2 00 102 ldx #0 ; from bank (x+1). 1868 8a 103 60$ txa ; 1869 49 5a 104 eor #$5a ; We should see the old pattern 186b dd 1700 105 cmp buffer,x ; here. If we don't then the data 186e d0 05 106 bne 90$ ; changed and we have found the end. 1870 ca 107 dex 1871 d0 f5 108 bne 60$ ; Bytes match so all is well. 1873 f0 d6 109 beq 40$ ; Loop back for next bank. 110 ; 1875 ad 180d 111 90$ lda expbank ; Number of banks is returned in 1878 85 fb 112 sta numbank ; the accumulator and in numbank. 187a 60 113 rts 114 ; .main. hcd65xx v3.1 6june87 page 3 0:ramexp.src,s,r error addr code seq source statement 115 ; 116 ;=============================================== 117 ; stash & fetch subroutines 118 ;=============================================== 119 ; 120 ; These routines will transfer RAM between the 121 ; cpu and expansion unit on the c64 and c128. 122 ; Before calling, you must set up 8 parameters 123 ; for the DMA as follows: 124 ; 125 ; source address (lo, hi) 126 ; destination address (lo, hi) 127 ; exapnsion bank 128 ; number of bytes (lo, hi) 129 ; 128 bank to use 130 ; 131 ; (parameters are located at "params") 132 ; 133 ; You may stash or fetch at any address. 134 ; These routines will bank out ROMs and I/O 135 ; before starting the DMA. 136 ; 137 ; If you want to fetch or stash RAM bank 1 138 ; on the C128 be sure to make a copy of this 139 ; code in bank 1 too. 140 ; 141 ;=============================================== 142 ; 143 ; 187b a0 ed 144 fetch ldy #$ed ; Command to read from expander 187d 2c 145 .byte $2c ; with FF00 option enabled. 146 ; (skip 2 bytes) 147 187e a0 ec 148 stash ldy #$ec ; Command to write to expander 149 ; with FF00 option enabled. 1880 a2 08 150 ldx #pend-params-2 1882 bd 1809 151 10$ lda params,x ; Initialize the DMA 1885 9d df02 152 sta $df02,x ; contoller with our 1888 ca 153 dex ; parameters, 1889 10 f7 154 bpl 10$ ; 188b 8c df01 155 sty $df01 ; and issue command. 156 188e ac 1812 157 ldy bnk128 ; Set the .y register to the 158 ; 128 bank we want (0 or 1). 159 ; 160 ; 161 ;=============================== 162 ; turn off ROMS and start DMA 163 ;=============================== 164 ; 165 ; 1891 166 dmarom 1891 ad fffd 167 lda $fffd ; The high byte of the 1894 c9 fc 168 cmp #$fc ; reset vector on all C64s 1896 f0 2a 169 beq xfer64 ; is equal to $fc. 170 ; 171 ; .main. hcd65xx v3.1 6june87 page 4 0:ramexp.src,s,r error addr code seq source statement 172 ;============================ 173 ; c128: turn off all ROMs 174 ;============================ 175 ; 1898 78 176 sei 1899 ad d506 177 lda rcr ; Save the old value of 189c 48 178 pha ; the 128 rcr. Now convert 189d 98 179 tya ; the 128 bank number to a 189e f0 07 180 beq bk0128 ; mask for the VIC/DMA 18a0 a9 40 181 lda #$40 ; pointer in the rcr. 18a2 0d d506 182 ora rcr ; This allows a stash or 18a5 d0 05 183 bne bangit ; fetch to bank 0 or bank 1 18a7 a9 3f 184 bk0128 lda #$3f ; of the 128. When using 18a9 2d d506 185 and rcr ; bank 1, be sure to make a copy 18ac 8d d506 186 bangit sta rcr ; of this code in both banks. 187 ; 18af ad ff00 188 lda $ff00 ; Save the 128 configuration 18b2 48 189 pha ; now kill ROMs and I/O. 18b3 09 3f 190 ora #$3f ; When we write to FF00 18b5 8d ff00 191 sta $ff00 ; DMA execution begins. 18b8 68 192 pla 18b9 8d ff00 193 sta $ff00 ; Restore the old 18bc 68 194 pla ; configuration and 18bd 8d d506 195 sta rcr ; restore the old VIC 18c0 58 196 cli ; pointer in the rcr. 18c1 60 197 rts 198 ; 199 ;============================ 200 ; c64: turn off all ROMs 201 ;============================ 202 ; 18c2 78 203 xfer64 sei ; Save the value of the 18c3 a5 01 204 lda $01 ; the c64 control port 18c5 48 205 pha ; and turn on lower 3 bits 18c6 09 03 206 ora #$03 ; to bank out ROMs, I/O. 18c8 85 01 207 sta $01 18ca 8d ff00 208 sta $ff00 ; Now start transfer... 209 ; 18cd 68 210 pla ; Restore the old 18ce 85 01 211 sta $01 ; configuration 18d0 58 212 cli ; and return. 18d1 60 213 rts 214 ; 18d2 215 end 216 ; 217 .end 0 errors detected .main. hcd65xx v3.1 6june87 page 5 symbol table = label, <=> = symbol, <+>= multibly defined bangit 18ac bk0128 18a7 bnk128 1812 buffer =1700 dmarom 1891 end 18d2 expbank 180d fetch 187b howbig 1813 numbank =00fb params 1809 pend 1813 ramexp =df00 rcr =d506 start 1800 stash 187e xfer64 18c2 .main. hcd65xx v3.1 6june87 page 6 cross reference ( <#> = definition, <$> = write, = read ) bangit 18ac 183 186# bk0128 18a7 180 184# bnk128 1812 39# 70$ 157 buffer =1700 11# 60 74$ 90$ 105 dmarom 1891 166# end 18d2 215# expbank 180d 34# 67$ 79$ 80 85$ 95$ 97 111 fetch 187b 24 101 144# howbig 1813 22 60# numbank =00fb 12# 112$ params 1809 32# 61$ 62$ 64$ 66$ 68$ 69$ 150 151 pend 1813 40# 150 ramexp =df00 13# rcr =d506 14# 177 182 185 186$ 195$ start 1800 22# stash 187e 23 78 94 148# xfer64 18c2 169 203#