I recently got a CompactFlash card working on my Planck computer, and for some reason, I've been trying to create the smallest possible bootstrap code, that will copy code and data from the CF card into RAM and jump to it.
I'm down to 81 bytes (excluding reset vectors) and I thought it would be fun / interesting to see how this community would make it even smaller. Here is the code in question:
Code: Select all
reset:
cf_init:
jsr cf_wait
lda #$E0
sta CF_ADDRESS + 6
lda #$1
sta CF_ADDRESS + 1
inc
sta io_buffer_ptr + 1 ; store 2 in high byte of pointer
stz io_buffer_ptr ; store 0 in low byte of pointer
lda #$EF
sta CF_ADDRESS + 7
jsr cf_wait
set_lba:
; start load at sector 0
stz CF_ADDRESS + 3
stz CF_ADDRESS + 4
stz CF_ADDRESS + 5
lda #$E0
sta CF_ADDRESS + 6
read_sectors:
; Load enough sectors to fill the RAM
lda #(((RAM_END-CODE_START)/$200)-1)
sta CF_ADDRESS + 2
lda #CF_READ_SECTOR_COMMAND
sta CF_ADDRESS + 7
cf_read:
lda CF_ADDRESS + 7
bmi cf_read ; wait if not ready
and #$08
beq start ; nothing left to read
lda CF_ADDRESS
sta (io_buffer_ptr)
inc io_buffer_ptr
bne cf_read
inc io_buffer_ptr + 1
bra cf_read
start:
jmp (CODE_START) ; The first two bytes of CF data contain an address to jump to
cf_wait:
lda CF_ADDRESS + 7
bmi cf_wait ; wait FOR RDY to become unset
rts
Code: Select all
00000000 20 4b e0 a9 e0 8d d6 ff a9 01 8d d1 ff 1a 85 01 | K..............|
00000010 64 00 a9 ef 8d d7 ff 20 4b e0 9c d3 ff 9c d4 ff |d...... K.......|
00000020 9c d5 ff a9 e0 8d d6 ff a9 3e 8d d2 ff a9 20 8d |.........>.... .|
00000030 d7 ff ad d7 ff 30 fb 29 08 f0 0d ad d0 ff 92 00 |.....0.)........|
00000040 e6 00 d0 ee e6 01 80 ea 6c 00 02 ad d7 ff 30 fb |........l.....0.|
00000050 60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |`...............|