Hello.
About my problem with not being able to correctly write to the Flash Rom,
here is some sample code. For reasons unknown to me, this one seems to
cause the program to _hang_ when calling the write_flash function, while
in the real program I'm working on it only seemed to refuse to write to
addresses not divisable by $100 (e.g. $180, $280 etc.).
Therefore I think I'm probably doing something _generally_ wrong (stupid
me). So, if someone could please explain to me *EVERY* step needed to
write to the Flash Rom, *IN DETAIL*, I would highly appreciate it...
BTW, people, when you post source code or new tricks, *PLEASE* add as many
comments as possible. Write down after each line of code what the given
command does, and why it needs to be done this way. Even though the code
may be perfectly obvious for you, for many others it is *NOT*. So for
God's sake, please _comment_ your stuff! I really can't point this out
often enough.
Ok, now let's get to the code sample. If anyone can show me what I'm
doing wrong, I would highly appreciate it:
------------------------------------------------------------------------
lev_offs_lo = $30 ; define variables to store address
lev_offs_hi = $31
[...]
.org $100
write_flash:
not1 ext,0 ; VMS Firmware call, "write Flash Rom"
jmpf write_flash
;
ret
[...]
start:
mov #$a1,ocr ; the usual program init stuff
mov #$09,mcr
mov #$80,vccr
clr1 p3int,0
clr1 p1,7
mov #$ff,p3
;
; ---------------------------------------------------------------
; fill Ram from $80 - $ff with %10101010 (test data to write)
; ---------------------------------------------------------------
;
mov #$80,1 ; we start at Ram location $80
mov #$aa,acc ; byte to write
.fill_block:
st @R1 ; write byte (@R0 & @R1 always access Ram half)
inc 1 ; increase pointer
ld 1
bnz .fill_block ; already 128 byte written?
;
; ---------------------------------------------------------------
; now write the test data to the Flash Rom
; ---------------------------------------------------------------
;
mov #<write_location,lev_offs_lo ; write-address in Flash (lo)
mov #>write_location,lev_offs_hi ; write-address in Flash (hi)
;
mov #4,c ; c = counter (we write 4 * 128 byte)
;
.write_next_part:
push 0 ; save what gets scratched by flash write
push b
push c
push trl
push trh
push xbnk
;
push ie
push ocr
;
clr1 ie,7 ; clear IE bit 7 (disable all interrupts)
mov #$81,ocr ; switch to 600 kHz when writing to Flash
;
mov #1,$7c ; set Finalize Flag (1 = wait indefinitely
; for last byte to stabilize)
ld lev_offs_lo
st $7d ; $7d = lo-offset current write-address
ld lev_offs_hi
st $7e ; $7e = hi-offset current write-address
mov #0,$7f ; $7f = 0 (24 bit big endian)
;
call write_flash ; write to Flash Rom
;
pop ocr
pop ie
;
pop xbnk ; restore what got scratched by flash write
pop trh
pop trl
pop c
pop b
pop 0
;
; ---------------------------------------------------------------
; add 128 to write address, so next chunk of data will be placed
; after the data we just wrote
; ---------------------------------------------------------------
;
ld lev_offs_lo
add #$80 ; add #$80 to lo-byte
st lev_offs_lo
ld lev_offs_hi
addc #0 ; add carry to hi-byte, if result > 255
st lev_offs_hi
;
dbnz c,.write_next_part ; already 4 * 128 byte written?
;
; ---------------------------------------------------------------
; now show what we wrote on the LCD screen
; ---------------------------------------------------------------
;
mov #<write_location,trl
mov #>write_location,trh
call setscr ; standard 'display screen' routine
; as found in "Tetris", "Bounce" etc.
[...]
.cnop 0,$80 ; address must be divisable by $80
write_location:
;
; 512 (4 * 128) byte to overwrite
;
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
------------------------------------------------------------------------
Bye
Alesssandro
---
You get what anyone gets. You get a lifetime.