| 1 |
;ACME 0.97 |
| 2 |
|
| 3 |
!src <cbm/c64/reu.a> ; include REU/REC definitions |
| 4 |
; define commands to use: |
| 5 |
REUCOMMAND_STASH = rec_COMMAND_EXECUTE | rec_COMMAND_IMMEDIATELY | rec_COMMAND_MODE_STASH ; no reload |
| 6 |
REUCOMMAND_FETCH = rec_COMMAND_EXECUTE | rec_COMMAND_IMMEDIATELY | rec_COMMAND_MODE_FETCH ; no reload |
| 7 |
|
| 8 |
*=$0801 |
| 9 |
!src "misc/basicstub.a" |
| 10 |
; basic stub jumps here |
| 11 |
; start by printing "found " right away, that way we do not |
| 12 |
; need to buffer the return values of the detection routine |
| 13 |
; just to output a string. |
| 14 |
ldy #<found |
| 15 |
lda #>found |
| 16 |
jsr print_string_AAYY |
| 17 |
; now check REU capacity (see below for actual code) |
| 18 |
jsr detect_reu_capacity |
| 19 |
; now C and A hold number of banks. |
| 20 |
; in theory all values from 0 up to and including 256 are |
| 21 |
; possible, but here we're just checking the highest bit, so |
| 22 |
; only the highest multiple of 2 is actually output: |
| 23 |
ldx #8 ; offset to output "16 MiB" message |
| 24 |
bcs @out |
| 25 |
-- dex ; next message |
| 26 |
bmi found_nothing ; no banks at all |
| 27 |
asl ; highest bit set? |
| 28 |
bcc -- |
| 29 |
@out ; now X says which message to output, so output it |
| 30 |
ldy messages_low, x ; get correct low byte |
| 31 |
lda #>messages ; get high byte (same for all messages) |
| 32 |
jsr print_string_AAYY |
| 33 |
; output common end (" of reu memory." + CR) |
| 34 |
ldy #<end |
| 35 |
lda #>end |
| 36 |
jmp print_string_AAYY ; ...aaand we're done! |
| 37 |
|
| 38 |
; all the strings to output: |
| 39 |
found !pet "found ", 0 |
| 40 |
messages ; helper label for making sure everything is in one page of memory |
| 41 |
msg_64K !pet "64kb", 0 |
| 42 |
msg_128K !pet "128kb", 0 |
| 43 |
msg_256K !pet "256kb", 0 |
| 44 |
msg_512K !pet "512kb", 0 |
| 45 |
msg_1M !pet "1mb", 0 |
| 46 |
msg_2M !pet "2mb", 0 |
| 47 |
msg_4M !pet "4mb", 0 |
| 48 |
msg_8M !pet "8mb", 0 |
| 49 |
msg_16M !pet "16mb", 0 |
| 50 |
; make sure all messages share the same high byte |
| 51 |
!if >* != >messages { !error "messages span page border, fix code!" } |
| 52 |
; other strings: |
| 53 |
end !pet " of reu memory.", 13, 0 |
| 54 |
msg_nothing !pet "no reu memory at all.", 13, 0 |
| 55 |
|
| 56 |
; table of low bytes of message adresses |
| 57 |
messages_low !by <msg_64K, <msg_128K, <msg_256K, <msg_512K |
| 58 |
!by <msg_1M, <msg_2M, <msg_4M, <msg_8M, <msg_16M |
| 59 |
|
| 60 |
; if no reu memory has been found, output a different message |
| 61 |
found_nothing ldy #<msg_nothing |
| 62 |
lda #>msg_nothing |
| 63 |
jmp print_string_AAYY |
| 64 |
|
| 65 |
; include code for string output |
| 66 |
!src "misc/print_string.a" |
| 67 |
|
| 68 |
; actual code to check for REU and find out RAM capacity: |
| 69 |
detect_reu_capacity ; returns: C,A = number of RAM banks found in REU |
| 70 |
; examples: |
| 71 |
; C=0, A=0: 0 banks found (no REU) |
| 72 |
; C=0, A=2: 2 banks found (128 KiB, CBM 1700) |
| 73 |
; C=0, A=4: 4 banks found (256 KiB, CBM 1764) |
| 74 |
; C=0, A=8: 8 banks found (512 KiB, CBM 1750) |
| 75 |
; C=0, A=16: 16 banks found (1 MiB) |
| 76 |
; C=0, A=32: 32 banks found (2 MiB) |
| 77 |
; C=0, A=64: 64 banks found (4 MiB) |
| 78 |
; C=0, A=128: 128 banks found (8 MiB) |
| 79 |
; C=1, A=0: 256 banks found (16 MiB) |
| 80 |
; bear in mind these are just example values. it is still possible someone has |
| 81 |
; upgraded their REU to 1.5 MiB so you would get a A=24 result! |
| 82 |
ldx #0 ; pre-init |
| 83 |
; first write signatures to banks in *descending* order (banks 255..0): |
| 84 |
---- dex |
| 85 |
stx banknum |
| 86 |
lda #<signature_start |
| 87 |
ldx #>signature_start |
| 88 |
ldy #REUCOMMAND_STASH |
| 89 |
jsr set_registers_AXY |
| 90 |
; all banks written? |
| 91 |
ldx banknum |
| 92 |
bne ---- |
| 93 |
; now check signatures in *ascending* order: |
| 94 |
; (checking signatures could be shortened by using the REC's "verify" command, |
| 95 |
; but I'm reluctant to use this function in a "REU detect" routine: it could |
| 96 |
; be buggy in modern FPGA implementations because it is so seldomly used) |
| 97 |
; banknum just became zero so no need to init it |
| 98 |
---- lda #<sig_candidate_start |
| 99 |
ldx #>sig_candidate_start |
| 100 |
ldy #REUCOMMAND_FETCH |
| 101 |
jsr set_registers_AXY |
| 102 |
; compare data |
| 103 |
ldx #SIGNATURE_LENGTH_LOW - 1 |
| 104 |
-- lda sig_candidate_start, x |
| 105 |
cmp signature_start, x |
| 106 |
bne @failed |
| 107 |
dex |
| 108 |
bpl -- |
| 109 |
; bank has correct signature |
| 110 |
inc banknum ; next bank (== number of banks already found) |
| 111 |
bne ---- |
| 112 |
; there are actually 256 banks! |
| 113 |
sec |
| 114 |
lda banknum ; A = 0, C = 1 -> 256 banks found |
| 115 |
rts |
| 116 |
|
| 117 |
@failed clc |
| 118 |
lda banknum ; A = number of banks found, C = 0 |
| 119 |
rts |
| 120 |
|
| 121 |
set_registers_AXY ; setup REU registers (used for both reading and writing) |
| 122 |
; A/X: c64 address |
| 123 |
; Y: REU command |
| 124 |
sta rec_int_low ; c64 address |
| 125 |
stx rec_int_high |
| 126 |
ldx #0 |
| 127 |
stx rec_ext_low ; reu address |
| 128 |
stx rec_ext_high |
| 129 |
lda banknum |
| 130 |
sta rec_ext_bank |
| 131 |
lda #SIGNATURE_LENGTH_LOW |
| 132 |
sta rec_amount_low |
| 133 |
stx rec_amount_high |
| 134 |
sty rec_command |
| 135 |
rts |
| 136 |
|
| 137 |
; signature we write to REU banks, first byte is bank number |
| 138 |
signature_start |
| 139 |
banknum !tx 0, "bliblablub" |
| 140 |
SIGNATURE_LENGTH_LOW = * - signature_start |
| 141 |
|
| 142 |
; target buffer when reading signatures back from REU |
| 143 |
sig_candidate_start |
| 144 |
!tx "XBLIBLABLUB" ; must be same length as signature above, obviously |
| 145 |
sig_candidate_end |
| 146 |
SIGNATURE_LENGTH_LOW = * - sig_candidate_start |