source: avrstuff/CPC stuff/gordon/manager/gordon.z80@ 67031cd

main
Last change on this file since 67031cd was 67031cd, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

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

  • Property mode set to 100644
File size: 2.9 KB
Line 
1; FLASH GORDON driver
2; Copyright 2012, Adrien Destugues <pulkomandy@gmail.com>
3; This program is distributed under the terms of the MIT licence
4
5; Start here.
6 DI
7
8; Move the screen to $8000 or $0000 so we can display things to the user, while
9; C000 will write to the ROM and 4000 will hold the data to write... That could
10; get a bit messy so maybe we will need to use the screen at 4000 as a buffer
11; for the ROM data as well. Or just use a bank for that ?
12 ; TODO
13
14; Map the ROM in
15 LD BC, 0x7F85
16 OUT (C),C
17
18; ask the user to enable writing
19 ; TODO
20
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
33 CALL send_command
34
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
61 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
67
68 LD B,0xDF
69 LD C,5 ; ROM number to write (FIXME get it as a RSX param)
70 OUT (C),C
71
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
82 JR $
83
84; Now reuse and adapt the code from OUL guys !
85 ; TODO
86
87; That's all folks !
88 RET
89
90; Helper routines -----------------------------------------------------
91
92; Send a command to the ROM. The available commands are :
93;ERASE equ 0x80
94IDENTIFY equ 0x90
95BYTEPROG equ 0xA0
96RESET equ 0xF0
97
98; Input: Commend to send in A register
99send_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:
112 ; Select ROM 1
113 LD BC,0xDF01
114 LD HL,0xD555
115 LD DE,0xEAAA
116
117 ; Select ROM 1 and write 0xAA to address 0xD555
118 OUT (C),C
119 LD (HL),E
120
121 ; Select ROM 2 and write 0x55 to address 0xEAAA
122 INC C
123 OUT (C),C
124 EX DE,HL
125 LD (HL), E
126
127 RET
128
129
130; Print value of A, as 2 hex digits
131printhex
132 PUSH AF
133 RRA
134 RRA
135 RRA
136 RRA ;divise A par 8
137 CALL PRNHEX1 ;affiche le premier morceau
138 POP AF ;r{cup la valeur originale pour la suit
139PRNHEX1 ;affiche la valeur de A sur 1 chiffre
140;affiche A sur 1 chiffre en Hexa
141 AND 0xF ;ne prend que les unit{s
142 OR A
143 DAA ;convertit en d{cimal
144 ADD A,0xF0 ;ajoute 240
145 ADC A,0x40 ;ajoute 64+le carry (si >15)
146;on a le code ascii du chiffre @ afficher
147 JP 0xBB5A ;call-ret
148;
Note: See TracBrowser for help on using the repository browser.