Changeset 67031cd in avrstuff


Ignore:
Timestamp:
Nov 18, 2012, 10:09:19 PM (11 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
413443e
Parents:
7dcccbc
Message:

Try to erase and write a ROM (since we can't read the ID because of hardware limitations)

git-svn-id: svn://pulkomandy.tk/avrstuff@79 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CPC stuff/gordon/manager/gordon.z80

    r7dcccbc r67031cd  
    1010; get a bit messy so maybe we will need to use the screen at 4000 as a buffer
    1111; for the ROM data as well. Or just use a bank for that ?
     12        ; TODO
    1213
    1314; Map the ROM in
    14 ; TODO
     15        LD BC, 0x7F85
     16        OUT (C),C
    1517
    1618; ask the user to enable writing
    17 ; TODO
     19        ; TODO
    1820
    19 ; Check if we can read the ROM type
    20         LD A, 0x90
     21; Turns out with the MegaFlash design, we can't both read and write. When the
     22; memory is in write mode, reading is disabled. This means we can't identify
     23; the chip, or use the data polling features. And we have to go for the
     24; worst-case timing given in the datasheet :(
     25
     26; ... anyway, start with erasing the sectors we need.
     27        CALL 0xBD19
     28        LD B, 4
     29ERASE
     30        PUSH BC
     31
     32        LD A, 0x80 ; ERASE
    2133        CALL send_command
    2234
     35        CALL prepare_command
     36       
     37        LD B,0xDF
     38        LD C,5 ; ROM number to write (FIXME get it as a RSX param)
     39        OUT (C),C
     40
     41        ; Compute address near start of sector
     42        POP BC
     43        LD A,B
     44        DEC A
     45        SLA A
     46        SLA A
     47       
     48        ADD 0xC0
     49
     50        LD H,A
     51
     52        LD E, 0x30
     53        LD (HL), E
     54
     55        ; This will delay long enough - we need at least 25ms
     56        CALL 0xBD19
     57
     58        DJNZ ERASE
     59
     60; Ok, now that we erased the 4 sectors we needed, we can write data to them
    2361        LD HL, 0xC000
     62        LD IX, 0x4000
     63PROGRAM
     64        LD A, 0xA0 ; BYTE PROGRAM ;     2       10
     65        PUSH HL                                   ;     3       13
     66        CALL send_command                 ; 5   18
    2467
    25         LD A,(HL)
    26         CALL printhex
    27         INC L
    28         LD A,(HL)
    29         CALL printhex
     68        LD B,0xDF
     69        LD C,5 ; ROM number to write (FIXME get it as a RSX param)
     70        OUT (C),C
    3071
    31         ; We should get 0x8F 87
    32         ; TODO check that before continuing with writing the data
     72        POP HL
     73
     74        LD A,(IX + 0)
     75        LD (HL),A               ; Write occurs here. Need to wait 20 NOPs before next
     76                                        ; operation on ROM. Our code is slow enough already !
     77
     78        INC HL                                  ;       2       2
     79        INC IX                                  ;       3       5
     80        JR NC, PROGRAM                  ;       3       8
     81
    3382        JR $
    3483
    35         ; Now reuse and adapt the code from OUL guys !
     84; Now reuse and adapt the code from OUL guys !
     85        ; TODO
    3686
    3787; That's all folks !
     
    4191
    4292; Send a command to the ROM. The available commands are :
    43 ERASE           equ     0x80
     93;ERASE          equ     0x80
    4494IDENTIFY        equ     0x90
    4595BYTEPROG        equ 0xA0
     
    4898; Input: Commend to send in A register
    4999send_command:
     100        ; That code is shared with sector erase which has some tricks
     101        call prepare_command
     102
     103        ; Select ROM 1 again and write the command to address 0xEAAA
     104        DEC C
     105        OUT (C),C
     106        EX DE,HL
     107        LD (HL), A
     108
     109        RET
     110
     111prepare_command:
    50112        ; Select ROM 1
    51113        LD BC,0xDF01
     
    62124        EX DE,HL
    63125        LD (HL), E
    64 
    65         ; Select ROM 1 again and write the command to address 0xEAAA
    66         DEC C
    67         OUT (C),C
    68         EX DE,HL
    69         LD (HL), A
    70126
    71127        RET
Note: See TracChangeset for help on using the changeset viewer.