base:reu_detect
REU Detect
;ACME 0.97 !addr reu_command = $df01 REUCOMMAND_STASH = $90 ; immediately, no reload REUCOMMAND_FETCH = $91 ; immediately, no reload !addr { reu_c64addr_lo = $df02 reu_c64addr_hi = $df03 reu_extaddr_lo = $df04 reu_extaddr_hi = $df05 reu_extaddr_bank = $df06 reu_len_lo = $df07 reu_len_hi = $df08 } ; returns: ; Carry = 0, A = 0 NO REU detected ; Carry = 1, A = 0 256 Banks (16MB) ; else Carry = 0, A = number of RAM banks found in REU detect_capacity ldx #0 ; pre-init ; first write signatures to banks in *descending* order (banks 255..0): ---- dex stx banknum lda #<signature_start ldx #>signature_start ldy #REUCOMMAND_STASH jsr set_registers_AXY ; all banks written? ldx banknum bne ---- ; now check signatures in *ascending* order: ; (checking signatures could be shortened by using the REC's "verify" command, ; but I'm reluctant to use this function in a "REU detect" routine: it could ; be buggy in modern FPGA implementations because it is so seldomly used) ; banknum just became zero so no need to init it ---- lda #<sig_candidate_start ldx #>sig_candidate_start ldy #REUCOMMAND_FETCH jsr set_registers_AXY ; compare data ldx #SIGNATURE_LENGTH_LOW - 1 -- lda sig_candidate_start, x cmp signature_start, x bne @failed dex bpl -- ; bank has correct signature inc banknum ; next bank (== number of banks already found) bne ---- ; there are actually 256 banks! sec lda banknum rts @failed clc lda banknum rts set_registers_AXY ; setup REU registers (used for both reading and writing) ; A/X: c64 address ; Y: REU command sta reu_c64addr_lo stx reu_c64addr_hi ldx #0 stx reu_extaddr_lo stx reu_extaddr_hi lda banknum sta reu_extaddr_bank lda #SIGNATURE_LENGTH_LOW sta reu_len_lo stx reu_len_hi sty reu_command rts ; signature we write to REU banks, first byte is bank number signature_start banknum !tx 0, "bliblablub" SIGNATURE_LENGTH_LOW = * - signature_start ; target buffer when reading signatures back from REU sig_candidate_start !tx "XBLIBLABLUB" ; must be same length as signature above, obviously sig_candidate_end SIGNATURE_LENGTH_LOW = * - sig_candidate_start
base/reu_detect.txt · Last modified: 2023-10-26 20:24 by groepaz