.importzp sp, ptr1, ptr2, ptr3, ptr4, tmp1, tmp2, tmp3, sreg .autoimport on .feature string_escapes .MACPACK generic _console_clear = $0 _console_read_char = $2 _console_write_char = $4 _sd_readblock = $6 buf = $8200 addrh = $0000 addrl = $0000 .segment "BOOTSECTOR" _start: jmp _main .byte "SUPR6502" _preamble: .res (11+_start-_preamble) _bpb: .res 60 _main: lda #str jsr _cputs ; we need to read from data segment 0, that will be the first directory entry ; that has sector offset $00ef_e000 lda #$00 sta sreg lda #$00 sta sreg+1 lda #$f0 ldx #$77 jsr pusheax lda #buf jsr pushax lda #ptr1 jsr _SD_readSingleBlock lda #buf jsr _SD_printBuf lda #$20 sta ptr3 lda #$82 sta ptr3 + 1 ldy #$0b @1: lda (ptr3),y cmp #$0f bne @2 clc lda ptr3 adc #$20 sta ptr3 bra @1 @2: ldy #11 lda #$00 sta (ptr3),y lda ptr3 pha ldx ptr3 + 1 phx lda #<_boot2_str ldx #>_boot2_str jsr pushax plx pla jsr _strcmp bne @fail lda #<_good ldx #>_good jsr _cputs lda #<_cluster ldx #>_cluster jsr pushax ldy #$15 lda (ptr3),y tax dey lda (ptr3),y jsr pushax ldy #$1b lda (ptr3),y tax dey lda (ptr3),y jsr pushax ldy #$6 jsr _cprintf bra @end ; Now we have the cluster number of the bootloader @fail: lda #<_fail ldx #>_fail jsr _cputs @end: bra @end str: .asciiz "boot\r\n" _boot2_str: .asciiz "BOOT2 BIN" _fail: .asciiz "not bootloader\r\n" _good: .asciiz "found bootloader!\r\n" _cluster: .asciiz "cluster: %lx\r\n" _end: .res (440+_start-_end) .res 6 .res 16 .res 16 .res 16 .res 16 .byte $55 .byte $AA