|
| 1 | +.memorymap |
| 2 | +defaultslot 0 |
| 3 | +slotsize $1000 |
| 4 | +slot 0 $F000 ; eeprom |
| 5 | +.endme |
| 6 | + |
| 7 | +.rombankmap |
| 8 | +bankstotal 1 |
| 9 | +banksize $1000 ; EEPROM |
| 10 | +banks 1 |
| 11 | +.endro |
| 12 | + |
| 13 | +.emptyfill $FF |
| 14 | + |
| 15 | +.bank 0 slot 0 |
| 16 | +.org $0000 |
| 17 | + |
| 18 | +.db "--[[CABE:Thistle:" |
| 19 | + |
| 20 | +; |
| 21 | +fslist: .db 10,10,0,"filesystem",0 ; 14 |
| 22 | +umlist: .db 10,5,0,"drive",0 ; 9 |
| 23 | +secread: .db 10,10,0,"readSector",3,1,0 ; 16 |
| 24 | +fsopend: .db 10,4,0,"open",10,12,0,"Thistle/boot",0 ; 23 |
| 25 | +fsopenf: .db 10,4,0,"open",10,7,0,"Thistle",0 ; 18 |
| 26 | +fsclose: .db 10,5,0,"close" ; 8 |
| 27 | +fsread: .db 10,4,0,"read",14,0,0,0,0,4,0,1,0 ; 16 |
| 28 | + |
| 29 | +; Messages |
| 30 | +greeting: .db "Thistle Boot ROM",10,10 |
| 31 | +nomem: .db "No Memory installed" |
| 32 | +drives: .db "Checking drives ...",10 ; 20 |
| 33 | +fsmsg: .db 10,"Checking filesystems ...",10 ; 26 |
| 34 | +bootmsg .db "Booting ...",10 ; 12 |
| 35 | +noboot: .db "Nothing to boot from" |
| 36 | + |
| 37 | +hexlookup: .db "0123456789abcdef" |
| 38 | + |
| 39 | +.macro _copy_base_short |
| 40 | + lda #<\1 |
| 41 | + sta $E041 |
| 42 | + lda #>\1 |
| 43 | + sta $E042 |
| 44 | + lda #<\2 |
| 45 | + sta $E043 |
| 46 | + lda #>\2 |
| 47 | + sta $E044 |
| 48 | + lda #<\3 |
| 49 | + sta $E045 |
| 50 | +.endm |
| 51 | + |
| 52 | +.macro copys_pp |
| 53 | + _copy_base_short \1 \2 \3 |
| 54 | + lda #$00 |
| 55 | + sta $e040 |
| 56 | +.endm |
| 57 | + |
| 58 | +.macro copys_pu |
| 59 | + _copy_base_short \1 \2 \3 |
| 60 | + lda #$01 |
| 61 | + sta $e040 |
| 62 | +.endm |
| 63 | + |
| 64 | +.macro copys_up |
| 65 | + _copy_base_short \1 \2 \3 |
| 66 | + lda #$02 |
| 67 | + sta $e040 |
| 68 | +.endm |
| 69 | + |
| 70 | +.macro copys_uu |
| 71 | + _copy_base_short \1 \2 \3 |
| 72 | + lda #$03 |
| 73 | + sta $e040 |
| 74 | +.endm |
| 75 | + |
| 76 | +hexprint: |
| 77 | + ; Prints a byte to the screen |
| 78 | + ; A - byte to print |
| 79 | + ; Clobbers: X |
| 80 | + pha |
| 81 | + tax |
| 82 | + tya |
| 83 | + pha |
| 84 | + txa |
| 85 | + lsr |
| 86 | + lsr |
| 87 | + lsr |
| 88 | + lsr |
| 89 | + tay |
| 90 | + lda hexlookup,Y |
| 91 | + sta $E003 |
| 92 | + txa |
| 93 | + and #$0F |
| 94 | + tay |
| 95 | + lda hexlookup,Y |
| 96 | + sta $E003 |
| 97 | + pla |
| 98 | + tay |
| 99 | + pla |
| 100 | + rts |
| 101 | + |
| 102 | +uuidprint: |
| 103 | + ; Prints a UUID to the screen |
| 104 | + ; $00, $01 - Address of UUID |
| 105 | + ; Clobbers: A, X (hexprint), Y |
| 106 | + ldy #$00 |
| 107 | +-- lda ($00),Y |
| 108 | + jsr hexprint |
| 109 | + iny |
| 110 | + cpy #$10 |
| 111 | + beq ++ |
| 112 | + cpy #$03 |
| 113 | + beq + |
| 114 | + cpy #$05 |
| 115 | + beq + |
| 116 | + cpy #$07 |
| 117 | + beq + |
| 118 | + cpy #$09 |
| 119 | + beq + |
| 120 | + jmp -- |
| 121 | ++ lda #$2D |
| 122 | + sta $E003 |
| 123 | + jmp -- |
| 124 | +++ lda #$0a |
| 125 | + sta $E003 |
| 126 | + rts |
| 127 | + |
| 128 | +_readlist: |
| 129 | + ; Reads component list to $0200 |
| 130 | + ; $02 - Bytes to skip for component type |
| 131 | + ; Clobbers: A, X, Y, $00, $01 |
| 132 | + lda #$00 |
| 133 | + sta $00 |
| 134 | + tay |
| 135 | + lda #$02 |
| 136 | + sta $01 |
| 137 | +-- lda $E012 |
| 138 | + cmp #$00 ; TSF End Tag |
| 139 | + beq ++ |
| 140 | + |
| 141 | + ; Read UUID |
| 142 | + ldx #$10 |
| 143 | +- lda $E012 |
| 144 | + sta ($00),Y |
| 145 | + iny |
| 146 | + cpy #$00 |
| 147 | + bne + |
| 148 | + inc $01 ; Increment $01 when Y wraps to 0 |
| 149 | ++ dex |
| 150 | + cpx #$00 |
| 151 | + bne - |
| 152 | + |
| 153 | + ; Drop component name |
| 154 | + ldx $02 |
| 155 | +- lda $E012 |
| 156 | + dex |
| 157 | + cpx #$00 |
| 158 | + bne - |
| 159 | + jmp -- |
| 160 | +++ lda #$02 |
| 161 | + sta $01 |
| 162 | + rts |
| 163 | + |
| 164 | +.macro readlist |
| 165 | + lda #\1 |
| 166 | + sta $02 |
| 167 | + jsr _readlist |
| 168 | +.endm |
| 169 | + |
| 170 | +loaduuid: |
| 171 | + ; Load a UUID into the component selector buffer |
| 172 | + ; $00, $01 - Address to read from |
| 173 | + ; Clobbers: A, X, Y, (uuidprint) |
| 174 | + jsr uuidprint |
| 175 | + ldy $00 |
| 176 | + ldx #$10 |
| 177 | + lda #$0b ; UUID Tag |
| 178 | + sta $E012 |
| 179 | +- lda ($00),Y ; UUID Byte loop |
| 180 | + sta $E012 |
| 181 | + iny |
| 182 | + cpy #$00 |
| 183 | + bne + |
| 184 | + inc $01 |
| 185 | ++ dex |
| 186 | + cpx #$00 |
| 187 | + bne - |
| 188 | + sty $00 |
| 189 | + stx $E012 ; End Tag |
| 190 | + stx $E010 ; Map Component |
| 191 | + rts |
| 192 | + |
| 193 | +bootdrive: |
| 194 | + ; Checks and boots from a drive |
| 195 | + lda $D000 |
| 196 | + cmp #$00 |
| 197 | + beq + |
| 198 | + rts |
| 199 | ++ copys_up bootmsg $E003 12 |
| 200 | + lda #$01 ; Setup Copy Engine |
| 201 | + sta $E041 |
| 202 | + lda #$D0 |
| 203 | + sta $E042 |
| 204 | + lda #$00 |
| 205 | + sta $E043 |
| 206 | + lda #$02 |
| 207 | + sta $E044 |
| 208 | + |
| 209 | + lda $D001 ; Discard tag |
| 210 | + lda $D001 |
| 211 | + sta $E045 |
| 212 | + lda $D001 |
| 213 | + sta $E046 |
| 214 | + |
| 215 | + lda #$01 ; Copy |
| 216 | + sta $E040 |
| 217 | + |
| 218 | + lda #$00 |
| 219 | + sta $E046 |
| 220 | + jmp $0200 ; Boot |
| 221 | + |
| 222 | +bootfs: |
| 223 | + ; Boots from a file |
| 224 | + lda $D000 |
| 225 | + cmp #$00 |
| 226 | + beq + |
| 227 | + rts |
| 228 | ++ copys_up bootmsg $E003 12 |
| 229 | + lda #$02 ; Something to boot! |
| 230 | + sta $00 |
| 231 | + copys_uu fsread $0001 16 ; Copy read command |
| 232 | + copys_pu $D001 $0008 5 ; Inject handle |
| 233 | + |
| 234 | +- ldx #$00 |
| 235 | + cpx #$D0 |
| 236 | + beq ++ ; Too much data read |
| 237 | + stx $e046 |
| 238 | + copys_up $0001 $D001 16 ; Call "read" |
| 239 | + stx $D000 |
| 240 | + lda $D000 |
| 241 | + cmp #$00 |
| 242 | + bne ++ ; No more data to read |
| 243 | + |
| 244 | + ldx $D001 ; Discard Tag and length |
| 245 | + ldx $D001 |
| 246 | + ldx $D001 |
| 247 | + |
| 248 | + sta $E043 ; Setup Copy Engine |
| 249 | + lda #$01 |
| 250 | + sta $E041 |
| 251 | + lda #$D0 |
| 252 | + sta $E042 |
| 253 | + lda $00 |
| 254 | + sta $E044 |
| 255 | + lda #$00 |
| 256 | + sta $E045 |
| 257 | + lda #$01 |
| 258 | + sta $E046 |
| 259 | + sta $E040 |
| 260 | + inc $00 |
| 261 | + jmp - |
| 262 | + |
| 263 | +++ copys_up fsclose $D001 8 ; Call close |
| 264 | + copys_up $0008 $D001 5 |
| 265 | + stx $D001 |
| 266 | + stx $D000 |
| 267 | + copys_up $0008 $E012 5 ; Destroy value |
| 268 | + stx $E012 |
| 269 | + lda #$04 |
| 270 | + sta $E010 |
| 271 | + jmp $0200 ; Boot |
| 272 | + |
| 273 | +reset: |
| 274 | + ; Display boot greeting |
| 275 | + copys_up greeting $E003 18 |
| 276 | + |
| 277 | + ; Memory Check |
| 278 | + lda $E018 |
| 279 | + cmp #$00 |
| 280 | + bne havemem |
| 281 | + lda $E019 |
| 282 | + cmp #$00 |
| 283 | + bne havemem |
| 284 | + ; No Memory Installed |
| 285 | + copys_up nomem $E003 19 |
| 286 | +- jmp - |
| 287 | + |
| 288 | +havemem: |
| 289 | + copys_up drives $E003 20 |
| 290 | + ; Look for "drive" components |
| 291 | + copys_up umlist $E012 9 |
| 292 | + lda #$03 |
| 293 | + sta $E010 |
| 294 | + |
| 295 | + ; Store list to memory |
| 296 | + lda $E011 |
| 297 | + sta $03 |
| 298 | + readlist 5 |
| 299 | + |
| 300 | + ; Parse list |
| 301 | + lda $03 |
| 302 | + cmp #$00 |
| 303 | + beq fschk ; No "drive" componets left to check |
| 304 | + jsr loaduuid |
| 305 | + copys_up secread $D001 16 ; Call readSector |
| 306 | + lda #$00 |
| 307 | + sta $D000 |
| 308 | + jsr bootdrive |
| 309 | + dec $03 |
| 310 | + |
| 311 | + ; Check the drive components |
| 312 | + |
| 313 | +fschk: |
| 314 | + copys_up fsmsg $E003 26 |
| 315 | + ; Look for "filesystem" components |
| 316 | + copys_up fslist $E012 14 |
| 317 | + lda #$03 |
| 318 | + sta $E010 |
| 319 | + |
| 320 | + ; Store list to memory |
| 321 | + lda $E011 |
| 322 | + sta $03 |
| 323 | + readlist 10 |
| 324 | + |
| 325 | + ; Parse list |
| 326 | +- lda $03 |
| 327 | + cmp #$00 |
| 328 | + beq failboot ; No "filesystem" componets left to check |
| 329 | + jsr loaduuid |
| 330 | + copys_up fsopend $D001 23 ; open Thistle/boot |
| 331 | + lda #$00 |
| 332 | + sta $D000 |
| 333 | + jsr bootfs |
| 334 | + copys_up fsopenf $D001 18 ; open Thistle |
| 335 | + lda #$00 |
| 336 | + sta $D000 |
| 337 | + jsr bootfs |
| 338 | + dec $03 |
| 339 | + jmp - |
| 340 | + |
| 341 | +failboot: |
| 342 | + copys_up noboot $E003 20 |
| 343 | +- jmp - |
| 344 | + |
| 345 | +nmi: |
| 346 | + rti |
| 347 | + |
| 348 | +irq: |
| 349 | + rti |
| 350 | + |
| 351 | +.db "]]error\"Thistle architecture required\"--" |
| 352 | + |
| 353 | +.orga $FFFA |
| 354 | +.dw nmi |
| 355 | +.dw reset |
| 356 | +.dw irq |
0 commit comments