USR18.S (2886B)
1 lst off 2 3 org = $2FF 4 5 floppyslot = 6 6 floppydrive = 2 7 8 * 9 * Merlin 2.52 --> RW18 "USR" interface routine. 10 * by Roland Gustafsson 11 * 12 * Merlin USR routine for writing out 18 sector data. 13 * This is the code that gets executed when the USR 14 * pseudo-op is specified. The parameters passed are: 15 * 16 * usr <BbundID>,<track>,<byte offset 0-$11FF>,<byte length> 17 * 18 * An easy way to specify length is to allocate X number 19 * of bytes for each module and use that number for len. 20 * To specify exact length, use org = $(org) at top of 21 * your source code, then "org org" instead of usual 22 * org (origin). That way you specify length by simply 23 * using "*-org". 24 * 25 26 *------------------------------- 27 * 28 * Stuff in aux memory: 29 * 30 rw18 = $6900 ;uses $1000-1AFF for tables 31 temp18buf = $6E00 32 obj_buf = $8000 33 34 * zpage 35 dum $60 36 obj_lo ds 1 37 obj_hi ds 1 38 dst_lo ds 1 39 dst_hi ds 1 40 len_lo ds 1 41 len_hi ds 1 42 flushflag ds 1 43 dend 44 slot = $FD 45 46 * Merlin stuff 47 48 usrads = $B6DA ;vector set up by INSTALL18 49 eval = $E5F9 50 passnum = $02 51 value = $55 52 *------------------------------- 53 org org 54 db eof-*-1 55 *------------------------------- 56 * 57 * This routine at $300 must be in both main and aux! 58 * 59 *------------------------------- 60 * 61 * Here is the USR routine: 62 * 63 user lda passnum 64 bne :0 65 rts 66 67 * Pass 2 so do your stuff! 68 69 :0 ldx #0 70 ldy #<obj_buf 71 lda #>obj_buf 72 sty obj_lo 73 sta obj_hi 74 75 * Get BbundID 76 77 jsr get16bit 78 tya 79 pha 80 81 * Get track number 82 83 jsr get16bit 84 tya 85 pha 86 87 * get offset into track data 88 89 jsr get16bit 90 sty dst_lo 91 clc 92 adc #>temp18buf 93 sta dst_hi 94 95 * get length of data to be written out 96 97 jsr get16bit 98 sty len_lo 99 sta len_hi 100 101 pla 102 sta $C003 ;aux mem 103 sta $C005 104 sta track 105 106 pla 107 sta BbundID 108 109 * Turn off any interupts and save status 110 111 php 112 sei 113 114 jsr rw18 115 db 7 116 BbundID db $a9 117 118 * turn on drive and delay .5 seconds 119 120 ldx #floppyslot*16 121 stx slot 122 ldx #floppydrive 123 stx drive 124 125 jsr rw18 126 db 0 127 drive db 2,5 128 129 * seek desired track 130 131 jsr rw18 132 db 2,1 133 track db 0 134 135 * read in current data 136 137 jsr rw18 138 db $83,>temp18buf 139 140 :movebyte ldy #0 141 sty flushflag 142 lda (obj_lo),y 143 sta (dst_lo),y 144 145 inc obj_lo 146 bne *+4 147 inc obj_hi 148 149 inc dst_lo 150 bne *+4 151 inc dst_hi 152 153 lda len_lo 154 bne *+4 155 dec len_hi 156 dec len_lo 157 158 lda dst_hi 159 cmp #>temp18buf+$1200 160 bne *+5 161 jsr flush? 162 163 lda len_lo 164 ora len_hi 165 bne :movebyte 166 167 jsr flush? 168 169 * turn off drive and get out of here! 170 171 jsr rw18 172 db 1 173 174 sta $C002 175 sta $C004 176 plp 177 rts 178 179 *------------------------------- 180 * 181 * If data has been written to temp18buf, 182 * then flush the buffer! 183 * 184 flush? lda flushflag 185 bne :nodata 186 187 ldy #<temp18buf 188 lda #>temp18buf 189 sty dst_lo 190 sta dst_hi 191 jsr rw18 192 db $C5,>temp18buf 193 194 lda len_lo 195 ora len_hi 196 beq :nodata 197 198 * read in current data 199 200 jsr rw18 201 db $83,>temp18buf 202 203 inc flushflag 204 205 :nodata rts 206 *------------------------------- 207 * 208 * Get 16bit number from source code 209 * 210 get16bit jsr eval 211 ldy value 212 lda value+1 213 inx 214 rts 215 eof 216 *------------------------------- end of file! 217 sav usr18