Hello,
KnightOS's flash writing routines are not working, and I need some help with them. Here is the code, any help would be appriciated:

Code:
WriteFlashByte:
    push hl
    push af
    ld bc, ProgramRoutineEnd - ProgramFlashRoutine
    call AllocateExecutableMem ; Allocates executable RAM, accepts BC as size, outputs hl is pointer to free RAM
    ex hl, de
    push de
    ld hl, ProgramFlashRoutine
    ldir
    pop de
    pop af
    pop hl
    ex hl, de
    ld bc, WriteFlashRet
    push bc
    ;di
    ;halt
    jp (hl)
    WriteFlashRet:
    ret
ProgramFlashRoutine:
; a = value, hl = address
; Flash program sequence
; This is being done according to how the datasheet says it should be done.
; The standard interrupt must not trigger during this sequence or the flash chip
; will not get the write command.
; At 6MHz, one clock cycle will be 167ns
; At 15MHz, one clock cycle will be 67ns
    ex hl, de
    push af
    push hl
    di
    ; reset bus (not needed by the books)
    ;ld    a, 0F0h
    ;ld    (4000h), a
    ; First bus cycle---unlock
    ld    a, 0AAh
    ld    (4AAAh), a
    ; Second bus cycle---unlock
    ld    a, 55h
    ld    (4555h), a
    ; Third bus cycle---write command
    ld    a, 0A0h
    ld    (4AAAh), a
    ; Fourth bus cycle---program data
    pop    hl
    pop    af
    ld    (hl), a
; Wait for data to be good
; "During the Embedded Program Algorithm, an attempt to read the devices will
; produce the complement of the data last written to DQ7. Upon completion of the
; Embedded Program Algorithm, an attempt to read the device will produce the
; true data last written to DQ7"
; "DQ5 will indicate if the program or erase time has exceeded the specified
; limits (internal pulse count).  If this occurs, reset the device with command
; sequence."---Fujitsu documentation
programWaitLoop:
    ld    b, a
    ld    a, 0FDh        ; This checks for the CLEAR key.
    out    (1), a        ; If pressed, it aborts.
    in    a, (1)
    cp    0BFh
    jr    z, abortProgram
    xor    (hl)
    bit    7, a
    ld    a, b
    jr    z, programDone
    bit    5, (hl)
    jr    z, programWaitLoop
abortProgram:
    ld    a, 0F0h
    ld    (4000h), a
    ret
programDone:
    ei
    ret
ProgramRoutineEnd:


Edit: x.x Figured it out
The test data I was passing in was setting bits, not resetting them Razz
Well, glad that you figured it out on your own. Razz I was going to recommend you wait to see what BrandonW or DrDnar had to say on the subject.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement