Changeset 0853bac in avrstuff


Ignore:
Timestamp:
Dec 1, 2012, 2:24:57 PM (11 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
9b0bfb3
Parents:
7c25c3e
Message:

Fix remaining problems. Now successfully flashing stuff, but only to ROM 5!

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

File:
1 edited

Legend:

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

    r7c25c3e r0853bac  
    4242        ; Save the interrupt vector and replace it with EI/RET
    4343        LD HL,(0x38)
    44           LD (inthandle),HL
     44    LD (inthandle),HL
    4545        LD HL,0xC9FB
    4646        LD (0x38),HL
    4747
     48        ; Now that we got the system out of the way, map the ROM
     49        ; (we stay in mode 1)
     50        LD BC, 0x7F85
     51        OUT (C),C
     52
    4853        ; TODO get the ROM number to burn somehow ?
    4954        ; (we can get it as a CALL parameter)
    5055
    5156        CALL ERASE
    52         CALL WRITE
     57        CALL CHECKBLANK
     58
     59        ; Load the "erase error" message. If erase actually succeded, we will go
     60        ; to the write function which will set something else.
     61        ; DE holds the error address
     62        EX DE,HL
     63        LD HL,MSG_ERASE_ERR
     64        LD (status),HL
     65        CALL Z,WRITE
    5366
    5467        ; Disconnect the Megaflash
     
    5871        ; Restore the firmware in working order now that we are done
    5972        LD SP,(stack)
    60           LD HL,(inthandle)
    61           LD (0x38),HL
     73    LD HL,(inthandle)
     74        LD (0x38),HL
    6275        EI
    6376
     
    6780        CALL screenmem
    6881
     82        ; TODO clear screen
     83
     84        ; Print the error/success message
     85        LD HL,(status)
     86        CALL puts
     87
     88        ; Print DE so we know where the problem was
     89        LD A,D
     90        CALL PRNHEX2
     91        LD A,E
     92        CALL PRNHEX2
     93
     94        ; Now user can safely disconnect the ROM
    6995        LD HL,MSG_WRITE_END
    7096        CALL puts
     
    76102        CALL screenmem
    77103
     104        ; TODO clear screen
     105        LD HL,0xC000
     106        CALL DUMP
     107        CALL 0xBB06
     108
     109        LD HL, 0xD000
     110        CALL DUMP
     111        CALL 0xBB06
     112
     113        LD HL, 0xE000
     114        CALL DUMP
     115        CALL 0xBB06
     116
     117        LD HL,0xF000
     118        CALL DUMP
     119        CALL 0xBB06
     120
    78121        ; TODO cleanly get out (and handle both calls by RUN and CALL)
    79122        JR $
     123
    80124
    81125; Erase a 16K ROM. Input:
     
    83127; Assumes we are in write mode, interrupts disabled.
    84128ERASE
    85           LD B,4
     129    LD B,4
    86130eraseloop
    87           PUSH BC
     131    PUSH BC
    88132
    89133        LD A, 0x80 ; ERASE
     
    98142        ; Compute address near start of sector
    99143        POP BC
    100         LD A,B
    101         DEC A
    102         SLA A
    103         SLA A
    104        
    105         ADD 0xC0
     144
     145        LD HL, addrmap-1
     146        LD D,0
     147        LD E,B
     148        ADD HL,DE
     149        LD A,(HL)
    106150
    107151        LD H,A
     
    119163        HALT
    120164        HALT
    121           HALT
     165        HALT
    122166        HALT
    123167        DI
     
    127171        RET
    128172
     173addrmap defb 0xC0, 0xD0, 0xE0, 0xF0
    129174
    130175; Write a 16K ROM
     
    137182        LD IX, 0x2000
    138183PROGRAM
    139           PUSH HL
     184        PUSH HL
    140185
    141186        LD A, 0xA0 ; BYTE PROGRAM
     
    161206        JR NZ, PROGRAM
    162207
    163         RET
    164 
     208        LD HL,MSG_WRITE_OK
     209        LD (status),HL
     210        RET
     211
     212
     213; Check if the ROM was erased properly and contains all FF bytes.
     214; Input: upper ROM is connected
     215; Output: Z flag set if all ok, else HL points to error
     216CHECKBLANK
     217        ; TODO select the right ROM
     218        LD BC,0xDF05
     219        OUT (C),C
     220       
     221        LD HL, 0xC000
     222.checkbyte
     223        LD A,(HL)
     224
     225        CP 0xFF
     226        RET NZ
     227
     228        INC HL
     229        LD A,H
     230        OR A
     231        RET Z
     232        JR .checkbyte
    165233; Helper routines -----------------------------------------------------
    166234
     
    218286        RET
    219287
    220 ; -----------------------------------------------------------------------------
    221 ; Messages
    222 MSG_WRITE_START string "Turn write switch ON and press a key...\r\n"
    223 MSG_WRITE_END string "Turn write switch OFF and press a key...\r\n"
    224 
    225 ; -----------------------------------------------------------------------------
    226         SECTION .uninit,"urw"
    227 
    228 stack   DEFW    1
    229 inthandle       DEFW    1
    230 
    231         end
    232 
    233 ; Very basic command prompt/monitor stuff for testing
    234         ; Print prompt
    235         LD A,'?'
    236         CALL 0xBB5A
    237         ; Wait for key
    238         CALL 0xBB06
    239         ; Parse commands
    240         CP A,'d'
    241         JP Z,DUMP
    242         CP A,'e'
    243         JP Z,ERASE
    244         CP A,'w'
    245         JP Z,WRITE
    246 
    247         ; Unhandled command
    248         LD A,'X'
    249         CALL 0xBB5A
    250 
    251         ; Start over
    252         JR _start
    253 
    254 
    255 ; Dump some bytes from beginning of ROM 5
    256 DUMP
    257         DI
    258 
    259 ; Map the ROM in (stay in mode 1 and get system rom out)
    260         LD BC, 0x7F85
    261         OUT (C),C
    262 
    263         LD BC,0xDF05
    264         OUT (C),C
    265 
    266 ; Copy the ROM to RAM
    267         LD DE, 0x4000
    268         LD BC, 0x4000
    269         LD HL, 0xC000
    270         LDIR
    271 
    272         EI
    273 
    274 ; Dump the RAM (we're safe if the system maps another ROM this way)
    275         LD HL,0x4000
    276 plop
    277         LD A,(HL)
    278         INC HL
    279         CALL PRNHEX2
    280         DJNZ plop
    281 
    282 ; Wait for next command
    283         JP _start
    284 
    285 
    286 PRNHEX2                 ;affiche la valeur de A sur 2 chiffres
    287 ;     en hexad{cimal
     288; Print A value as hexadecimal
     289; AF is corrupt
     290PRNHEX2
    288291        PUSH    AF
    289292        RRA     
     
    304307
    305308
    306 PRNHEX2                 ;affiche la valeur de A sur 2 chiffres
    307 ;     en hexad{cimal
    308         PUSH    AF
    309         RRA     
    310         RRA     
    311         RRA     
    312         RRA             ;divise A par 8
    313         CALL    PRNHEX1 ;affiche le premier morceau
    314         POP     AF      ;r{cup la valeur originale pour la suit
    315 PRNHEX1                 ;affiche la valeur de A sur 1 chiffre
    316 ;affiche A sur 1 chiffre en Hexa
    317         AND     0xF     ;ne prend que les unit{s
    318         OR      A
    319         DAA             ;convertit en d{cimal 
    320         ADD     A,0xF0  ;ajoute 240
    321         ADC     A,0x40  ;ajoute 64+le carry (si >15)
    322 ;on a le code ascii du chiffre @ afficher
    323         JP      0xBB5A  ;call-ret
    324 
    325 
     309; Dump some bytes from beginning of ROM 5
     310DUMP
     311        DI
     312
     313; Map the ROM in (stay in mode 1 and get system rom out)
     314        LD BC, 0x7F85
     315        OUT (C),C
     316
     317        LD BC,0xDF05
     318        OUT (C),C
     319
     320; Copy the ROM to RAM
     321        LD DE, 0x4000
     322        LD BC, 0x4000
     323        LDIR
     324
     325        EI
     326
     327; Dump the RAM (we're safe if the system maps another ROM this way)
     328        LD HL,0x4000
     329plop
     330        LD A,(HL)
     331        INC HL
     332        CALL PRNHEX2
     333        DJNZ plop
     334
     335; Wait for next command
     336        RET
     337
     338
     339; -----------------------------------------------------------------------------
     340; Messages
     341MSG_WRITE_START string "Turn write switch ON and press a key...\r\n"
     342MSG_WRITE_END   string "Turn write switch OFF and press a key...\r\n"
     343MSG_ERASE_ERR   string "Erasing memory failed at address "
     344MSG_WRITE_OK    string "Success!\r\n"
     345
     346; -----------------------------------------------------------------------------
     347        SECTION .uninit,"urw"
     348
     349stack           DEFW    1
     350inthandle       DEFW    1
     351status          DEFW    1
     352
     353        end
     354; END END END END END END END END END END END END END END END END END END END
     355
     356; Very basic command prompt/monitor stuff for testing
     357        ; Print prompt
     358        LD A,'?'
     359        CALL 0xBB5A
     360        ; Wait for key
     361        CALL 0xBB06
     362        ; Parse commands
     363        CP A,'d'
     364        JP Z,DUMP
     365        CP A,'e'
     366        JP Z,ERASE
     367        CP A,'w'
     368        JP Z,WRITE
     369
     370        ; Unhandled command
     371        LD A,'X'
     372        CALL 0xBB5A
     373
     374        ; Start over
     375        JR _start
     376
     377
Note: See TracChangeset for help on using the changeset viewer.